#!/afs/athena/contrib/perl/p

$commonwords = ' the to of and a is or at in on are can about you if please also comments information for document link that by here an from heres this your problems do with have be work when will as use it ';

require('find.pl');
open(IDX, ">>/mit/mkgray/afs/saindex/all.idx");
select(IDX);$|=1;
select(STDOUT);

&find('/mit/olc-stock/stock_answers');

sub wanted {
    return if (-d $_);
    $curfile = $_;
    $keywords = '';

    open(FILE, $_);
    while(<FILE>){
	s/[\.\,\?\!\'\(\)\*\-\`\{\}\\]/ /g;
	@words=split;
        foreach $word (@words)
	{
	    $tot++;
	    $word =~ tr/A-Z/a-z/;
#               if(!defined($INST{$word})){print(".");}
	    $INST{$word}++;
	}
    }

    $num = $tot/200;
    $num = $num < 2 ? 2:$num;
    $min = 2;			# 

    foreach (sort byvalue keys %INST)
    {				# 
	$times = $INST{$_};		# 
	if($times >= $num)		# 
	{				# 
	    if(length >= $min)	# 
	    {
		if($commonwords !~/ $_ /i){
		    $keywords .= $_.' ';
		    print("$_\n") unless $keyw{$_};
		    $keyw{$_}=1;
		}			# 
	    }			# 
	}
	# 
    }		
    print(IDX "$dir/$curfile~$keywords\n");
}		# 
sub byvalue { $INST{$b} <=> $INST{$a}; }


sub listen {
        local($secs) = @_;
        local($return,$tmp) = "";
        while (length($tmp = &chat'expect($secs, '(.|\n)+', '$&'))) {
                print $tmp if $trace;
                $return .= $tmp;
		(return $return) if (length($return) > 100000);
        }
        $return;
}

