#!/afs/athena/contrib/perl/perl
# 
# $Source: /afs/athena.mit.edu/user/t/o/tompalka/perl/RCS/synctree-process.pl,v $
# $Revision: 1.1 $
# $Date: 92/02/29 17:39:15 $
# $State: Exp $
# $Author: tompalka $
# $Locker: tompalka $
#

($WHOAMI) = ( $0 =~ /^[^ ]*\/([^\/]*)$/ );

$tmpfile = "/tmp/synctree.output";

if( @ARGV != 0)
{
    if($ARGV[0] =~ /-olc/)
    {
	$OLC = 1;
    }
    else
    {
	die <<EOH;

 usage:

   $WHOAMI [-olcstock]

 takes synctree output as stdin and outputs a summary of it
 to file $tmpfile.  if -olcstock is specified, then some 
 additional processing is done.

EOH
}
}

open(out,">$tmpfile") || die "cannot write to $tmpfile: $!\n";

while(<STDIN>)
{
    next unless /^[CU]/;	# we only want to process lines that
				# begin with Copying or Updating
    chop;

    ($filename) = ( $_ =~ /^[^\/]*([^ ,]*)/ );

    if( $OLC )
    {
	$filename =~ s:/mit/olc-backup/stock_answers/::g;
	$filename =~ s:\.$::g;
	if($filename =~ /\.index/) { next; }

	if( /^U/ )
	{
	    $updated{$filename} = 1;
	}
	else
	{
	    $copied{$filename} = 1;
	}
    }
    else
    {
	$copied{$filename} = 1;
    }
}

# for each file (key) check if it was copied or what, and
# output right info

foreach $key (sort (keys %copied))
{
    if( $OLC )
    {
	if( $updated{$key} )
	{
	    print out "modified ",$key,"\n";
	}
	else
	{
	    print out "     new ",$key,"\n";
	}
    }
    else
    {
	print out $key,"\n";
    }
}

close(out);

print "the output is in $tmpfile\n";
