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

if (!@ARGV) {
    print STDERR <<EOU;
Usage: $0 regexp ...

Any definition name matching any regexp are printed.  If the regexp
ends in :, only exact entries (words or topic entries) are matched.
If the regexp ends in ::, only exact topic entries are matched.

EOU
    exit;
}

$jargon = '/afs/athena.mit.edu/user/m/a/marc/stuff/jargon/jargon';

for (@ARGV) {
    $_ = "^".$_."+\$" if /:$/;
    $_ = '($word =~ /'.$_.'/i)';
}

$cond = join(" || ",@ARGV);

open(JARGON,$jargon) || die "Couldn't open dictionary $jargon: $!\n";

1 while(<JARGON> !~ /^The Jargon Lexicon$/);

eval '
while(<JARGON>) {
# pre 2.9.9 format
#    next if /^ /;
#    next if !/^([^ ][^:]+:+)/;

    study;

    while ((($word) = (/^:([^:]+:+)/)) && ('.$cond.')) {
	&printdef;
    }
}
';
die $@ if $@;

sub printdef {
    print;
    while (<JARGON>) {
	last if /^:/;
	print;
    }
}
