#!/usr/local/bin/perl
#
#$Id: reminder.pl,v 1.3 2005/02/15 19:27:51 boris Exp $
#
# Читаем файл и шлем e-mail
#
#
# Исходные файлы и параметры
#

    use Getopt::Std; 

$usage = 'reminder.pl $Revision: 1.3 $, $Date: 2005/02/15 19:27:51 $'. "\n".
"Usage: reminder.pl [-d] [-r round]  [-o results] \n";

require 'parameters.pl';
require 'subroutines.pl';

die $usage unless getopts('r:o:d');

$DEBUG=$opt_d;

my %teams;

#
# Читаем ответы команд
#
$round=0;
if ($opt_r)
{
    $round=$opt_r;
    foreach my $file (split /\s+/, $FILES[$opt_r]) {
	open (INFILE, $file);
	readmail(\%teams);
	close (INFILE);
    }
}
else
{
    *INFILE=*STDIN;
}
readmail(\%teams);
close(INFILE);
#
# Пишем мейл
#
if ($opt_o)
{ 
    die "Cannot open $opt_o\n" unless open(OUTFILE,">$opt_o");
}
else
{
    open(OUTFILE,"|/usr/lib/sendmail -oi -t");
}
select OUTFILE;
&printheader;
foreach $team (keys %teams)
{
    my $num=$teams{$team}->{'numletters'};
    print  "$team [$num]\n";
}

&printfooter;

