#! /usr/bin/perl -w

# Ce petit programme permet de convertir une liste de mots du type
#
# ...
# mot
# mots
# ...
#
# en :
#
# ...
# mot/S
# ...

use strict;

my ($Mot_preced);

# Vrification de la syntaxe
unless (@ARGV == 2) {
  print STDERR "auto-pluriels: SYNTAXE : dansdico liste-orig liste-conv\n";
  exit (1);
}

# Ouverture des fichiers

unless (open LORIG, $ARGV[0]) {
  print STDERR "auto-pluriels: impossible d'ouvrir le fichier $ARGV[0] !\n";
  exit (2);
}

unless (open LCONV, ">$ARGV[1]") {
  print STDERR "auto-pluriels: impossible de (re)crer le fichier ". 
    "$ARGV[1] !\n";
  close (LORIG);
  exit (2);
}


# Traitement du fichier

$Mot_preced = "";

foreach (<LORIG>) {
  chop;
  if ($Mot_preced . "s" eq $_) {
    print LCONV "$Mot_preced/S\n";
    $Mot_preced = "";
  } else {
    unless ($Mot_preced eq "") {
      print LCONV $Mot_preced, "\n";
    }
    $Mot_preced = $_;
  }
}

unless ($Mot_preced eq "") {
  print LCONV $Mot_preced;
}

close (LCONV);
close (LORIG);
