#!/usr/bin/perl
# =========================================================
# I wrote this little Perl script to convert the output
# of H. Sattlers scmxx into a printable LaTeX phonebook.
# The output will be in alphabetical order.
#    -- J. Stein -     stein@ph-cip.uni-koeln.de                
# =========================================================

sub error
{
   print <STDERR>, "scm2tex converts the output of scmxx into a LaTeX file\n";
   print <STDERR>, " Usage:\n";
   print <STDERR>, "scmxx --get --pbook=SM -f - | scm2tex > telbook.tex\n";
}

sub tex_header
{
   print '\documentclass[a4paper,twocolumn]{article}',"\n";
   print '\begin{document}',"\n";
   print '\begin{description}',"\n";
}

sub tex_footer
{
   print '\end{description}',"\n";
   print '\end{document}',"\n";
}


sub convert
{
while ($zeile = <STDIN>) 
{
   $zeile =~ tr/"//d;     # remove " 
   $zeile =~ tr/\n//d;    # remove \n 
   $zeile =~ tr/!//d;     # remove ! 
   
   # TODO: Umlaute muessen noch umgewandelt werden
    
   ($index, $nummer, $name) = split /,/, $zeile;
   %person = (%person, $name => $nummer);
}
  
@namenliste = keys %person;
tex_header;

foreach $namenliste (sort keys %person) 
{
 print '\item[', $namenliste, ']', $person{$namenliste}, "\n";
}

tex_footer;	
}

# ==================== here starts the main part


if (not $ARGV[0])  
   {       
        convert;
   }  

else  {
	  error; 
	  # warn if an argument was given to scm2tex
      };
   


