#!/usr/bin/perl -w
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  ScanCount -
#
#SYNOPSIS
#  ScanCount [host]..
#
#REQUIRES
#
#DESCRIPTION
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
 
$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2; # Verbose level.

@hosts = ();	# List of host records 
@files = ();	# List of host files

for $a (@ARGV) {
	if (-f ($f = "hst/$a")) {
		push @hosts, $a;
		push @files, $f;
	}
}
unless (@hosts) {
	@files = glob("hst/*");
	for $f (@files) {
		($h = $f) =~ s"hst/"";
		push @hosts, $h;
	}
}

host:
	for ($i = 0; $h = $hosts[$i]; $i++) {
		$f = $files[$i];
		unless (open(F,$f)) {
			print STDERR "$0: Can't read \"$f\" [$?]\n";
			next host;
		}
		$scans = $lastX = $lastF = $frstT = $lastT = 0;
		while ($l = <F>) {
			if (($T,$X,$G,$F,$H) = ($l =~ /^(\d+) T X:(\d+) T:(\d+) F:(\d+) H:(.*)$/)) {
				print "$P: T=\"$T\" X=\"$X\" G=\"$G\" F=\"$F\" H=\"$H\"\n" if $V>8;
				++$scans;
				$frstT = $T unless $frstT;
				$lastT = $T;	# Remember time of last scan
				$lastX = $X;	# Remember the ABC tunes found
				$lastF = $F;	# Remember the files with tunes
			}
		}
		close F;
		printf("%4d scans %8d tunes %8d files %s\n",$scans,$lastX,$lastF,$h);
	}

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;
 
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
