#!/opt/p9p/bin/rc rfork e words = $PLAN9/lib/words map = $home/tmp/s7r.map min = 2 flagfmt='w words,m map,l min' if(! ifs=() eval `{getflags $*}) { echo wtf 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] } . 9.rc 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} # repl = `{echo $i | sed 's/^([a-zA-Z]).+([a-zA-Z])$/\1'$n'\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 '' }