#!/usr/bin/perl

$|=1;

$pat = "Auth:";
if($ARGV[0] eq "-sipb"){
    shift;
    $pat = "Instance:";
}

while(<>){
    if(/^$pat/){
	&analyze($zeph);
	$zeph = "";
	next;
    }
    if(/^From:/){
	next;
    }
    $zeph .= $_;
}

sub analyze {
    $z = shift;
    $z =~ s/\n\r/ /g;
    $z =~ y/A-Z/a-z/;
    @w = split(" ", $z);
    foreach $w (@w){
	$wct{$w}++;
	$tot++;
    }
    $ct++;
    if($ct%1000 == 0){
	%newct = ();
	print "*************************\n";
	for $w (sort {$wct{$b} <=> $wct{$a}; } keys %wct){
	    $act = int(10000*$wct{$w}/$tot);
	    last if ($act < 3);
	    $newct{$w} = $wct{$w} if ($wct{$w} > ($tot/30000));
	    print "$w $act\n";
	}
	%wct = %newct;
    }
}

%whitemagic = ("the", 44,
	       "to", 24,
	       "a", 23,
	       "i", 20,
	       "of", 18,
	       "and", 14,
	       "that", 14,
	       "in", 13,
	       "is", 12,
	       "it", 11,
	       "was", 8,
	       "you", 8,
	       "for", 8,
	       "on", 6,
	       "they", 6,
	       "be", 5,
	       "have", 5,
	       "not", 5,
	       "but", 5,
	       "with", 4,
	       "are", 4,
	       "if", 4,
	       "my", 4,
	       "from", 4,
	       "this", 4);
