#!/afs/athena/contrib/perl5/perl

$pat = shift @ARGV;

while(<>){
    split;
    $uri = $_[6];
    next if ($uri=~/\.gif$/i);
    next if ($uri=~/\.jpg$/i);
    next if ($uri=~/\.jpeg$/i);
    next if ($uri=~/\.xbm$/i);
    next if ($uri=~/^\/cgi\/counter/);
    $ref = $_[10];
    $ip = $_[0];

    if(!$first{$ip}){
	$first{$ip} = $uri;
	$firstref{$ip} = $ref;
    }

    if($uri =~ /$pat/){
	print "$first{$ip} <- $firstref{$ip}\n";
    }

}

sub report {
    print "--------------------------------------\n";
    print "--------------------- $ct -------------\n";
    print "--------------------------------------\n";
    @entrypoints = sort {$entry{$b} <=> $entry{$a}} keys %entry;
    for $i (0..19){
	$entries = $entry{$entrypoints[$i]};
	$pct = int(100*$entries/$ct);
	print "$entries ($pct %)\t$entrypoints[$i]\n";
    }
}
