#! /usr/bin/perl -w

use strict;

my(@Avant, @Apres, $i);

if (@ARGV == 0) {
  print STDERR "doublons: Syntaxe : doublons fichier [fichier ...]\n";
  exit (1);
}

foreach (@ARGV) {
  unless (open(ENTREE,$_)) {
    print STDERR "doublons: Impossible de trouver le fichier $_ !\n";
    next;
  }
  unless (open(SORTIE,">$_-nodoubl")) {
   print STDERR "doublons: Impossible de crer le fichier $_-nodoubl !\n";
   print STDERR "doublons: Impossible de continuer !\n";
   close (ENTREE);
   exit (2);
 }
  print "Traitement du fichier $_ en cours...\n";
  @Avant = <ENTREE>;
  close(ENTREE);
  @Apres = "TOP\n";
  foreach (@Avant) {
    unless (&EstDans($_)) {
      push @Apres, $_;
    }
  }
  shift @Apres;
  foreach (@Apres) {
    print SORTIE $_;
  }
  close(SORTIE);
}

sub EstDans {
  local ($::Bool);
  $::Bool = 0;
  foreach (@Apres) {
    if ($_[0] eq $_) {
      $::Bool = 1;
      last;
    }
  }
  $::Bool;
}
