#!/usr/local/bin/perl
#
# age - mark killed entries as gone
#
$deleteMonths = 10;		# really delete people this old
$fieldName = "left_uiuc";	# name of field to use
if ($#ARGV<2 || $#ARGV>3)
{
  print STDERR "Usage: age prod.cnf sf.kill [sf.kill.dead]\n"; 
  exit 1;
}

($config,$stiffFile,$killFile) = @ARGV;

#
# let's find out any bad news right away
#
open(CONFIG,"<$config") || die "$config: $!\n";
open(STIFFFILE,"<$stiffFile") || die "$studentFile: $!\n";
if ($killFile ne "") {open(KILLFILE,">$killFile") || die "$killFile: $!\n";}

#
# find the number of the left field
$lnum = -1;
while (<CONFIG>)
{
  if (/:$fieldName:/) {($lnum)=(split(':'))[0];last;}
}
if ($lnum<0) {die "Couldn't find $fieldName in $config.\n";}

#
# figure out today's number
($month,$year) = (split(' ',`date`))[1,5];
$m = 0;
foreach $monthName ("Jan","Feb","Mar","Apr","May","Jun",
                    "Jul","Aug","Sep","Oct","Nov","Dec")
{
  if ($month eq $monthName) {$month=$m;last;}
  $m++;
}
$now = $year*12+$month;
$month++;

while (<STIFFFILE>)
{
  chop;
  if (/\t$lnum:/)
  {
    $tmp = $_;
    $tmp =~ s/.*\t$lnum://;
    $tmp =~ s/\t.*//;
    ($m,$y) = split('/',$tmp);
    if ($y*12+$m-1 < $now-$deleteMonths)
    {
      if ($killFile ne "") {print KILLFILE "$_\n";}
    }
    else
    {
      print "$_\n";
    }
  }
  else
  {
    print "$_\t$lnum:$month/$year\n";
  }
}
