#!/bin/rc rfork e words = /lib/words map = /tmp/s7r.map min = 4 flagfmt='w words,m map,l length' if(! ifs=() eval `{aux/getflags $*}) { aux/usage exit usage } if (! ~ $flagw '') words=$flagw if (! ~ $flagm '') map=$flagm if (! ~ $flagl '') { if (test $flagl -gt 0) words=$flagl if not echo 'length must be greater than 0; ignoring -l.' >[1=2] } fn mkmap { if (! test -r $words) { echo $0': cannot read' $words >[1=2] exit words } > $map for (i in `{cat $words}) { n = `{hoc -e `{echo -n $i | wc -c}^'-2'} if (test $n -ge $min) echo $i $n >> $map } } # Build the map if we don't have one. # TODO: re-build the map if the user specifies $min. if (! test -r $map) mkmap while (line=`{read}) { n = $#line for (i in `{seq 1 $n}) { word = `{echo $line($i) | sed 's/[^a-zA-Z]*([a-zA-Z]*)[^a-zA-Z]*/\1/'} short = `{grep -i '^'$word' ' $map} if (~ $#short 2) echo -n `{echo $line($i) |\ sed 's/^([^a-zA-Z]*[a-zA-Z]).*([a-zA-Z][^a-zA-Z]*)/\1'^$short(2)^'\2/'} if not echo -n $line($i) if (! ~ $i $n) echo -n ' ' } echo '' }