#!/local/bin/perl #### # # (c) 1998 Bruce Jakeway # # This prints out the definitions of a particular word. It can use Perl # wildcards too. # # Sample run: # ./dict 'theocr.*' # #### $pathname = '/nfs/v2/jakeway/custard/w1913/result/newdefs/'; sub findword { local (@file); local ($foundhw) = 0; local ($foundpos) = 0; local (@hw) = (); local ($notfirst) = 0; local ($word) = "\L$ARGV[0]\E"; local ($letter) = substr ($word, 0, 1); $word = "\u$word"; if ($letter !~ /[a-z]/) { foreach $letter ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'pq', 'r', 's', 't', 'u', 'v', 'w', 'xyz') { push (@file, $pathname . $letter . '.defs'); } } else { if ($letter eq 'p' || $letter eq 'q') { $letter = 'pq'; } elsif ($letter eq 'x' || $letter eq 'y' || $letter eq 'z') { $letter = 'xyz'; } @file = ($pathname . $letter . '.defs'); } foreach $f (@file, $pathname . 'new.defs') { open (DICT, $f); while () { if (($hw) = m#^(.*)#) { $foundhw = $foundhw || $hw =~ m/\b$word\b/; push (@hw, $hw); $pos = ''; $sn = 0; } if (m#^(.*)#) { $hw[$#hw] = $1; } if ($foundhw) { if (m#^(.*)\n#) { if ($sn != $1) { printf " %2d. ", $1; $sn = $1; } else { print " "; } } elsif (m#^(.*)\n#) { print "($1) "; } elsif (m#^(.*)# && $1 ne $pos) { $pos = $1; if ($notfirst) { print "\n"; } else { $notfirst = 1; } foreach $hw (@hw) { print "$hw $pos\n"; } } elsif (m#^(.*)#) { print "$1\n"; } } if (m#^#) { $foundhw = 0; @hw = (); } } close (DICT); } } while ($#ARGV >= 0) { &findword; printf "\n" if ($#ARGV); shift; }