#!/usr/bin/perl -w

while (<>) {
    if (/FinalFrontierHallOfFameEntry/) {
	$foo=$_;
	do {
	    $foo .= <>;
	} until ($foo=~/\n\s*\}\s*$/); 
	$foo=~/name\s*\=\s*(\S.*\S)\s*$/m;
	$name=$1;
	$foo=~/time\s*\=\s*([\d\.]+)\s*$/m;
	$time=$1;
	$foo=~/code\s*\=\s*(\S*)/;
	$code=$1;
	if ($code eq "L+") {
	    print STDERR "$name landed at $time.\n";
	    if (!defined($onmission{$name}) or
		!$onmission{$name}) {
		print "\t\tFinalFrontierHallOfFameEntry
\t\t{
\t\t\ttime = ",$time-1,"
\t\t\tname = $name
\t\t\tcode = M+
\t\t\tdata = 
\t\t}\n";
		print STDERR "... while not on a mission.\n";
	    }
	    $onmission{$name}=0;
	} elsif ($code eq "M+") {
	    print STDERR "$name took off at $time.\n";
	    if (defined($onmission{$name}) and
		$onmission{$name}) {
		print "\t\tFinalFrontierHallOfFameEntry
\t\t{
\t\t\ttime = ",$time-1,"
\t\t\tname = $name
\t\t\tcode = L+
\t\t\tdata = 
\t\t}\n";
		print STDERR "... while already on a mission.\n";
	    }
	    $onmission{$name}=1;
	}
	print $foo;
    } else {
	print;
    }
}
