#!/s/std/bin/perl

use Time::CTime;
while(@ARGV)
{
    $_ = shift;
    push(@FILES, $_);
}

print "* = not successful.   M = Madison, B = Bologna\n";


# method:
# create a hash of all the start entries.
# create a hash of all the end entries.

# walk through the start entries, and don't print if there is a coresponding
# end entry

foreach $file (@FILES)
{
    open(DNLD, $file);
    while(<DNLD>)
    {
		chop;
		($date_num, $StartStop, $filename, $filesize, $ip,
		 $name, $email, $org, undef, $pid, $site) = split /\t+/;
		
		$thetime =  ctime($date_num);
		chop($thetime);
		$thetime =~ s/^([^ ]+) ([^ ]+) (..) (..):(..):(..) ([^ ]+) (..)(..)$/\2\/\3\/\9 at \4:\5/;
		$basename = $filename;
		$basename =~ s!^.*/([^/]*)$!\1!;
		$basename =~ /^([^-]+)-([^\.]+)\.([^\.]+)\.([^\.-]+)\.*-*([^-]+)-([^-]+)(-libc5)*(-glibc.{0,2})*(-dynamic)*\..+$/;
		$condor = $1;
		$majorv = $2;
		$minorv = $3;
		$releasev = $4;
		$opsys = $5;
		$arch = $6;
		$glibc = $7;
		$dynamic = $8;

		if ($site eq "Madison") { $mb = "M"; }
		elsif ($site eq "Bologna") { $mb = "B"; }
		else { $mb = "?$site?"; }

		if ($StartStop eq "START") {
			$starthash{"$pid $ip"} = $date_num;
		} elsif ($StartStop eq "END") {
			$stophash{"$pid $ip"} = $date_num;
		}

		#print "$thetime:  $ip\t$name\t$email\t$org\n";
		$infohash{"$pid $ip"} = "$mb $thetime: $filename $name\t$email\t$org\tv$majorv.$minorv.$releasev\n";
		#print "($date_num, $StartStop, $filename, $filesize, $ip, $name, $email, $org, $pid)\n";
	}

}

foreach $key (keys %starthash) {
	if (!defined($stophash{$key})) {
		$newline = "*";
	} else {
		$newline = " ";
	}

	$newline .= $infohash{$key};
	$timehash{$starthash{$key}} = $newline;
}

#foreach $key (sort keys %timehash) {
	#print $timehash{$key};
#}

foreach $key (sort { $a <=> $b } keys %timehash) {
	print $timehash{$key};
}

