#!/usr/athena/bin/perl
#
# Snoop
#
# Foreach file in the arglist, sum up the number of ful, par, and ppr
# data sent in, and then give a total at the end for all files.
#
# Created by:	Derek Atkins <warlord@MIT.EDU>
#
# $Source$
# $Author$
#

# The csh script is:
# foreach i (O*)
# echo $i '	' `grep from $i | wc -l` '	' `grep 'ful ' $i | \
#   wc -l` `grep 'par ' $i | wc -l` `grep 'ppr ' $i | wc -l` 
# end
# echo 'total' '		' `grep from O* | \
#   wc -l` '	'  `grep 'ful ' O* | wc -l` `grep 'par ' O* | \
#   wc -l` `grep 'ppr ' O* | wc -l` 

# init some variables
$fuls = 0;
$pars = 0;
$pprs = 0;

print "Parsing files...\n";
print "File                    rels	ful	par	ppr\n";

foreach $file (@ARGV) {
    $file_fuls = 0;
    $file_pars = 0;
    $file_pprs = 0;
    
    open(INPUT, $file);
    
    # read the input from the file
    while (<INPUT>) {
	
	# If there is a from line, then let's see what it is...
	if (/from/) {
	    
	    # Split it into parts...
	    ($type,$num,$from,$id) = split(' ', $_);
	    
	    # ...and compare the types
	    if ($type eq "ful") {
		$file_fuls++;
	    }
	    
	    if ($type eq "par") {
		$file_pars++;
	    }
	    
	    if ($type eq "ppr") {
		$file_pprs++;
	    }
	    
	}
    } # while

    # We're done with this file.  Output the information
    $tot = $file_fuls + $file_pars + $file_pprs;
    printf ("%-24s%d	%d	%d	%d\n", $file, $tot, $file_fuls,
	    $file_pars, $file_pprs);
    
    $fuls += $file_fuls;
    $pars += $file_pars;
    $pprs += $file_pprs;
    
    close(INPUT);
}

# Final totals.
$tot = $fuls + $pars + $pprs;
print "total                   $tot	$fuls	$pars	$pprs\n";
