tchrist@convex.com (Tom Christiansen) (01/07/91)
Here is a set of little perl programs I whipped up to fetch entries from the jargon file of Eric Raymond's which he recently posted to alt.folklore.computers and comp.unix.internals (or whatever it gets called lately): jlook -- get just the name of the entry jcat -- cat the full entry jfort -- cat random entry They are all really just links to each other. Here are some example uses: % jfort <nybble> /nib'l/ [from v. `nibble' by analogy with `bite' -> `byte'] n. Four bits; one hexadecimal digit; a half-byte. Though `byte' is now accepted technical jargon found in dictionaries, this useful relative is still slang. Compare <crumb>, <taste>, <dynner>, see also <bit>. Note: a correspondent in England alleges that this spelling is never used on his side of the pond, as British orthography would suggest the pronunciation /niebl/. % jcat sex <SEX> [Sun User's Group & elsewhere] n. 1. Software EXchange. A technique invented by the blue-green algae hundreds of millions of years ago to speed up their evolution, which had been terribly slow up until then. Today, SEX parties are popular among hackers and others. 2. The rather Freudian mnemonic often used for Sign Extend, a machine instruction found in many architectures. Amusingly, the Intel 8048 (the microcontroller used in IBM PC keyboards) was missing straight SEX but had logical-or and logical-and instructions ORL and ANL. % jlook unix UNIX UNIX conspiracy UNIX weenie unixism % jlook -a sex bytesexual SEX So, matches are by default anchored at the front, but the -a relaxes that. There is a -x flag for exact matches. jfort just counts the all the fortunes and selects a random one to call jcat on. -l triggers look mode, -r triggers random fortune mode. It will also find all the dangling references in the jargon file, that is, things that are referenced but never defined. This should help Eric in perparing his manuscript. To set all this up: First, you need a copy of the jargon file in this directory: e.g. ln -s /usr/local/etc/jargon/jargon . Now, if your perl isn't in /usr/local/bin/perl or if your kernel doesn't like to #!exec things, fix the headers on jcat and the mk* scripts. Finally, type 'make all'. This will build everything for you, and run a few simple test cases. If that runs and you like the definitions of SYSDIR in jcat and BIN and LIB in Makefile, run make install. Problems, of course, to me. Someday I will write a man page. This is just an afternoon/evening hack, but I like it. Tom Christiansen tchrist@convex.com #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # jargon # This archive created: Sun Jan 6 21:16:46 1991 export PATH; PATH=/bin:/usr/bin:$PATH if test ! -d 'jargon' then echo shar: "creating directory 'jargon'" mkdir 'jargon' fi echo shar: "entering directory 'jargon'" cd 'jargon' if test ! -d 't' then echo shar: "creating directory 't'" mkdir 't' fi echo shar: "entering directory 't'" cd 't' echo shar: "extracting 'INPUT'" '(79 characters)' if test -f 'INPUT' then echo shar: "will not over-write existing file 'INPUT'" else sed 's/^ X//' << \SHAR_EOF > 'INPUT' Xjlook Xjcat Xjlook unix Xjlook -x unix Xjcat -x unix Xjcat unix Xjcat -a unix SHAR_EOF if test 79 -ne "`wc -c < 'INPUT'`" then echo shar: "error transmitting 'INPUT'" '(should have been 79 characters)' fi chmod 664 'INPUT' fi echo shar: "extracting 'o1'" '(46 characters)' if test -f 'o1' then echo shar: "will not over-write existing file 'o1'" else sed 's/^ X//' << \SHAR_EOF > 'o1' Xusage: /usr/local/bin/jlook [-raxl] entry ... SHAR_EOF if test 46 -ne "`wc -c < 'o1'`" then echo shar: "error transmitting 'o1'" '(should have been 46 characters)' fi chmod 664 'o1' fi echo shar: "extracting 'o2'" '(45 characters)' if test -f 'o2' then echo shar: "will not over-write existing file 'o2'" else sed 's/^ X//' << \SHAR_EOF > 'o2' Xusage: /usr/local/bin/jcat [-raxl] entry ... SHAR_EOF if test 45 -ne "`wc -c < 'o2'`" then echo shar: "error transmitting 'o2'" '(should have been 45 characters)' fi chmod 664 'o2' fi echo shar: "extracting 'o3'" '(41 characters)' if test -f 'o3' then echo shar: "will not over-write existing file 'o3'" else sed 's/^ X//' << \SHAR_EOF > 'o3' XUNIX XUNIX conspiracy XUNIX weenie Xunixism SHAR_EOF if test 41 -ne "`wc -c < 'o3'`" then echo shar: "error transmitting 'o3'" '(should have been 41 characters)' fi chmod 664 'o3' fi echo shar: "extracting 'o4'" '(5 characters)' if test -f 'o4' then echo shar: "will not over-write existing file 'o4'" else sed 's/^ X//' << \SHAR_EOF > 'o4' XUNIX SHAR_EOF if test 5 -ne "`wc -c < 'o4'`" then echo shar: "error transmitting 'o4'" '(should have been 5 characters)' fi chmod 664 'o4' fi echo shar: "extracting 'o5'" '(811 characters)' if test -f 'o5' then echo shar: "will not over-write existing file 'o5'" else sed 's/^ X//' << \SHAR_EOF > 'o5' X<UNIX> /yoo'niks/ [In the authors' words, "A weak pun on MULTICS"] X n. A popular interactive time-sharing system originally invented in X 1969 by Ken Thompson after Bell Labs left the MULTICS project, X mostly so he could play SPACEWAR on a scavenged PDP7. Dennis X Ritchie, the inventor of C, is considered a co-author of the X system. The turning point in UNIX's history came when it was X reimplemented almost entirely in C in 1974, making it the first X source-portable operating system. Fifteen years and a lot of X changes later UNIX is the most widely used multiuser X general-purpose operating system in the world. Many people (q.v. X <UNIX weenie>) consider this the single most important victory yet X of hackerdom over industry opposition. See <Version 7>, <BSD X UNIX>, <USG UNIX>. SHAR_EOF if test 811 -ne "`wc -c < 'o5'`" then echo shar: "error transmitting 'o5'" '(should have been 811 characters)' fi chmod 664 'o5' fi echo shar: "extracting 'o6'" '(3205 characters)' if test -f 'o6' then echo shar: "will not over-write existing file 'o6'" else sed 's/^ X//' << \SHAR_EOF > 'o6' X<UNIX> /yoo'niks/ [In the authors' words, "A weak pun on MULTICS"] X n. A popular interactive time-sharing system originally invented in X 1969 by Ken Thompson after Bell Labs left the MULTICS project, X mostly so he could play SPACEWAR on a scavenged PDP7. Dennis X Ritchie, the inventor of C, is considered a co-author of the X system. The turning point in UNIX's history came when it was X reimplemented almost entirely in C in 1974, making it the first X source-portable operating system. Fifteen years and a lot of X changes later UNIX is the most widely used multiuser X general-purpose operating system in the world. Many people (q.v. X <UNIX weenie>) consider this the single most important victory yet X of hackerdom over industry opposition. See <Version 7>, <BSD X UNIX>, <USG UNIX>. X X<UNIX conspiracy> [ITS] n. According to a conspiracy theory long X popular among <ITS> and <TOPS-20> fans, UNIX's growth is the result X of a plot hatched during the 70s at Bell Labs, whose intent was to X hobble AT&T's competitors by making them dependent upon a system X whose future evolution was to be under AT&T control. This would be X accomplished by disseminating an operating system that is seemingly X inexpensive and easily portable, but relatively unreliable and X insecure. In this view, UNIX was designed to be one of the first X computer viruses (see <virus>), but a virus spread to computers X indirectly by people and market forces, rather than directly X through disks and networks. Adherents of this "UNIX virus" X theory like to cite the fact that the well-known quotation "UNIX X is snake oil" was uttered by DEC president Kenneth Olsen shortly X before DEC began actively promoting its own family of UNIX X workstations. X X<UNIX weenie> [ITS] n. 1. A derogatory pun on "UNIX wizard", common X among hackers who use UNIX by necessity, but would prefer X alternatives. The implication is that, while the person in X question may consider mastery of UNIX arcana to be a wizardly X skill, the only real skill involved is the ability to tolerate, and X the bad taste to wallow in, the incoherence and needless complexity X that are alleged to infest many UNIX programs. "This shell script X tries to parse its arguments in 69 bletcherous ways. It must have X been written by a real UNIX weenie." 2. A derogatory term for X anyone who engages in uncritical praise of UNIX. Often appearing X in the context "stupid UNIX weenie". See <Weenix>, <UNIX X conspiracy>. X X<unixism> n. A piece of code or coding technique that depends on of X the protected multi-tasking environment with relatively low X process-spawn overhead that exists on UNIX systems. Common X <unixism>s include: gratuitous use of `fork(2)'; the assumption that X certain undocumented but well-known features of UNIX libraries like X `stdio(3)' are supported elsewhere; reliance on <obscure> X side-effects of system calls (use of `sleep(2)' with a zero argument X to clue the scheduler that you're willing to give up your X time-slice, for example); the assumption that freshly-allocated X memory is empty, the assumption that it's safe to never free() X memory, etc. SHAR_EOF if test 3205 -ne "`wc -c < 'o6'`" then echo shar: "error transmitting 'o6'" '(should have been 3205 characters)' fi chmod 664 'o6' fi echo shar: "extracting 'o7'" '(3461 characters)' if test -f 'o7' then echo shar: "will not over-write existing file 'o7'" else sed 's/^ X//' << \SHAR_EOF > 'o7' X<UNIX> /yoo'niks/ [In the authors' words, "A weak pun on MULTICS"] X n. A popular interactive time-sharing system originally invented in X 1969 by Ken Thompson after Bell Labs left the MULTICS project, X mostly so he could play SPACEWAR on a scavenged PDP7. Dennis X Ritchie, the inventor of C, is considered a co-author of the X system. The turning point in UNIX's history came when it was X reimplemented almost entirely in C in 1974, making it the first X source-portable operating system. Fifteen years and a lot of X changes later UNIX is the most widely used multiuser X general-purpose operating system in the world. Many people (q.v. X <UNIX weenie>) consider this the single most important victory yet X of hackerdom over industry opposition. See <Version 7>, <BSD X UNIX>, <USG UNIX>. X X<UNIX conspiracy> [ITS] n. According to a conspiracy theory long X popular among <ITS> and <TOPS-20> fans, UNIX's growth is the result X of a plot hatched during the 70s at Bell Labs, whose intent was to X hobble AT&T's competitors by making them dependent upon a system X whose future evolution was to be under AT&T control. This would be X accomplished by disseminating an operating system that is seemingly X inexpensive and easily portable, but relatively unreliable and X insecure. In this view, UNIX was designed to be one of the first X computer viruses (see <virus>), but a virus spread to computers X indirectly by people and market forces, rather than directly X through disks and networks. Adherents of this "UNIX virus" X theory like to cite the fact that the well-known quotation "UNIX X is snake oil" was uttered by DEC president Kenneth Olsen shortly X before DEC began actively promoting its own family of UNIX X workstations. X X<UNIX weenie> [ITS] n. 1. A derogatory pun on "UNIX wizard", common X among hackers who use UNIX by necessity, but would prefer X alternatives. The implication is that, while the person in X question may consider mastery of UNIX arcana to be a wizardly X skill, the only real skill involved is the ability to tolerate, and X the bad taste to wallow in, the incoherence and needless complexity X that are alleged to infest many UNIX programs. "This shell script X tries to parse its arguments in 69 bletcherous ways. It must have X been written by a real UNIX weenie." 2. A derogatory term for X anyone who engages in uncritical praise of UNIX. Often appearing X in the context "stupid UNIX weenie". See <Weenix>, <UNIX X conspiracy>. X X<unixism> n. A piece of code or coding technique that depends on of X the protected multi-tasking environment with relatively low X process-spawn overhead that exists on UNIX systems. Common X <unixism>s include: gratuitous use of `fork(2)'; the assumption that X certain undocumented but well-known features of UNIX libraries like X `stdio(3)' are supported elsewhere; reliance on <obscure> X side-effects of system calls (use of `sleep(2)' with a zero argument X to clue the scheduler that you're willing to give up your X time-slice, for example); the assumption that freshly-allocated X memory is empty, the assumption that it's safe to never free() X memory, etc. X X<USG UNIX> /yoo-ess-jee yoo'niks/ n. Refers to AT&T UNIX versions X after <Version 7>, especially System III and System V releases 1, 2 X and 3. So called because at that time AT&T's support crew was X called the `UNIX Support Group'. See <BSD UNIX>. SHAR_EOF if test 3461 -ne "`wc -c < 'o7'`" then echo shar: "error transmitting 'o7'" '(should have been 3461 characters)' fi chmod 664 'o7' fi chmod 775 . echo shar: "done with directory 't'" cd .. echo shar: "extracting 'mkdangle'" '(247 characters)' if test -f 'mkdangle' then echo shar: "will not over-write existing file 'mkdangle'" else sed 's/^ X//' << \SHAR_EOF > 'mkdangle' X#!/usr/local/bin/perl X X@ARGV = ('-xi'); Xrequire 'jcat'; X$| = 1; X Xif (open (CHILD, "|-")) { X open (STDOUT, ">&CHILD"); X open (STDERR, ">&STDOUT"); X while (<>) { X chop; X &lookup($_); X } X} else { X print /<([^>]*)>/, "\n" while <>; X} SHAR_EOF if test 247 -ne "`wc -c < 'mkdangle'`" then echo shar: "error transmitting 'mkdangle'" '(should have been 247 characters)' fi chmod 775 'mkdangle' fi echo shar: "extracting 'Makefile'" '(749 characters)' if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else sed 's/^ X//' << \SHAR_EOF > 'Makefile' XLIB=/usr/local/etc/jargon XBIN=/usr/local/bin X Xall: dict idx jargon refs dangling jlook test jfort X Xjargon: X @echo You forgot to link the jargon file! X @sh -c exit 1 X Xdict: jargon X ./mkdict < jargon > dict X Xidx: dict X ./mkidx < dict > idx X Xrefs: dict X ./mkrefs < dict > refs X Xdangling: refs X ./mkdangle < refs > dangling & X Xtest: mktest dict X ./mktest | tee test X Xclean:; rm -f dict idx all refs dangling jlook test install jfort X Xjlook: jcat X ln jcat jlook X Xjfort: jcat X ln jcat jfort X Xinstall: all X for i in dict idx; do install -c $$i $(LIB); done X for i in jcat; do install -c $$i $(BIN); done X rm -f $(BIN)/jlook $(BIN)/jfort X for i in jlook jfort; \ X do \ X rm -f $(BIN)/$$i; \ X ln $(BIN)/jcat $(BIN)/$$i; \ X done X touch install SHAR_EOF if test 749 -ne "`wc -c < 'Makefile'`" then echo shar: "error transmitting 'Makefile'" '(should have been 749 characters)' fi chmod 664 'Makefile' fi echo shar: "extracting 'mkdict'" '(87 characters)' if test -f 'mkdict' then echo shar: "will not over-write existing file 'mkdict'" else sed 's/^ X//' << \SHAR_EOF > 'mkdict' X#!/usr/local/bin/perl -n Xnext if 1../^\s*\{=\s+=\}\s*$/; Xlast if /^Appendix A/; Xprint; SHAR_EOF if test 87 -ne "`wc -c < 'mkdict'`" then echo shar: "error transmitting 'mkdict'" '(should have been 87 characters)' fi chmod 775 'mkdict' fi echo shar: "extracting 'mkrefs'" '(198 characters)' if test -f 'mkrefs' then echo shar: "will not over-write existing file 'mkrefs'" else sed 's/^ X//' << \SHAR_EOF > 'mkrefs' X#!/usr/local/bin/perl X Xopen (OUT, "|sort -dfu"); Xselect(OUT); X Xundef $/; X$_ = <>; Xs/[^<]*<([^>]*)[^<]*/$1\n/g; Xs/\s\s+/ /g; X$, = "\n"; Xprint grep (60 > length, split(/\n/)); Xprint "\n"; X Xclose OUT; SHAR_EOF if test 198 -ne "`wc -c < 'mkrefs'`" then echo shar: "error transmitting 'mkrefs'" '(should have been 198 characters)' fi chmod 775 'mkrefs' fi echo shar: "extracting 'mktest'" '(301 characters)' if test -f 'mktest' then echo shar: "will not over-write existing file 'mktest'" else sed 's/^ X//' << \SHAR_EOF > 'mktest' X#!/usr/local/bin/perl X Xopen(TESTS, "t/INPUT") || die "can't open t/INPUT: $!"; X X$ENV{'PATH'} .= ':.'; X Xwhile (<TESTS>) { X if (!-e "t/o$.") { X warn "no expected output for line $.\n"; X next; X } X chop; X print STDERR "test $. ", X (`$_ 2>&1` eq `cat t/o$.`) ? "passed" : "failed", "\n"; X} SHAR_EOF if test 301 -ne "`wc -c < 'mktest'`" then echo shar: "error transmitting 'mktest'" '(should have been 301 characters)' fi chmod 775 'mktest' fi echo shar: "extracting 'mkidx'" '(168 characters)' if test -f 'mkidx' then echo shar: "will not over-write existing file 'mkidx'" else sed 's/^ X//' << \SHAR_EOF > 'mkidx' X#!/usr/local/bin/perl X Xopen (PIPE, "|sort -df -"); Xwhile (<>) { X if (/^<([^>]+)>/) { X $term = $1; X printf PIPE "%s %d\n", $term, tell - length; X } X} Xclose PIPE; SHAR_EOF if test 168 -ne "`wc -c < 'mkidx'`" then echo shar: "error transmitting 'mkidx'" '(should have been 168 characters)' fi chmod 775 'mkidx' fi echo shar: "extracting 'jcat'" '(1827 characters)' if test -f 'jcat' then echo shar: "will not over-write existing file 'jcat'" else sed 's/^ X//' << \SHAR_EOF > 'jcat' X#!/usr/local/bin/perl X X$SYSDIR = '/usr/local/etc/jargon'; X$SYSDIR = "." unless -d $SYSDIR; X Xchdir $SYSDIR || die "can't chdir $SYSDIR: $!"; X X$JARGON = 'dict'; X$IDX = 'idx'; X Xrequire 'getopts.pl'; X X$0 =~ /(ook|ls)$/ && $opt_l++; X$0 =~ /fort/ && $opt_r++; X Xunless ( &Getopts('rdialx') && X (@ARGV > 0 || $opt_i || $opt_r) ) { X die "usage: $0 [-raxl] entry ...\n"; X} X X Xopen JARGON || die "can't open $JARGON: $!"; Xopen IDX || die "can't open $IDX: $!"; X Xopen(TTY, ">/dev/tty") if $opt_d; X Xif ($opt_r) { X $opt_x++; X while (<IDX>) { X s/\s+\d+\n//; X push(@IDX, $_); X } X srand(time); X @ARGV = $IDX[rand $#IDX]; X} X Xprint &lookup(@ARGV); X X Xsub lookup { X local(@want) = @_; X local ($_, $addr, $code, @entries, $entry, %entry, $found, X @found, @names, $return, $seen, $starg, $targ ); X X foreach $targ (@want) { X seek(IDX,0,0); X ($starg = $targ) =~ s/(\W)/\\$1/g; X $code = "while (<IDX>) {\n"; X if ($opt_a) { X $code .= "\tnext unless m|^.*$starg.*\\d+\$|i;\n"; X } elsif (!$opt_x) { X $code .= "\tnext unless m|^$starg.*\\d+\$|i;\n"; X } else { X $code .= "\tnext unless m|^$starg\\s+\\d+\$|i;\n"; X } X $code .= <<EO_EVAL; X \$found++; X push(\@found, \$_); X } XEO_EVAL X print TTY $code if $opt_d; X eval $code; X die $@ if $@; X warn "$0: no entry for <$targ>\n" unless $found; X } X X for (@found) { X @names = split; X $entry = "@names"; X $addr = pop(@names); X if ($opt_l) { X $entry =~ s/\s\d+$//; X print "$entry\n"; X next; X } X $entry{$entry} = $addr; X push(@entries,$entry); X } X X foreach $entry ( @entries ) { X $addr = $entry{$entry}; X seek(JARGON, $addr, 0) || die "can't seek $addr: $!"; X $seen = 0; X while (<JARGON>) { X last if (/^</ || /^\s*{= (. )?=}\s*$/) && $seen++; X $return .= $next; X $next = chop; X $return .= $_; X } X } X $return; X} SHAR_EOF if test 1827 -ne "`wc -c < 'jcat'`" then echo shar: "error transmitting 'jcat'" '(should have been 1827 characters)' fi chmod 775 'jcat' fi chmod 775 . echo shar: "done with directory 'jargon'" cd .. exit 0 # End of shell archive -- Tom Christiansen tchrist@convex.com convex!tchrist "EMACS belongs in <sys/errno.h>: Editor Too Big!" -me