[net.sources] sh script - interactive spelling checker

waynet@tolerant.UUCP (Wayne Thompson) (12/19/86)

#! /bin/sh
# To extract, remove mail header lines and type "sh filename"
echo x - spellck
sed -e 's/^X//' > spellck << '!FaR!OuT!'
X#! /bin/sh
X#
X#	@(#)spellck	2.0 (Tolerant) 12/18/86
X#
XPATHNAME=/b/mfg/waynet/bin/spellck
X#
X# Author: Wayne Thompson
X#
X# Interactive spelling checker
X#
X# Dependencies:
X#
X# Bugs:
X#
XUSEAGE='Useage: spellck [-d directory] [-u] [file] ...'
XTRUE=1
XFALSE=0
Xif [ -f $HOME/.spellckrc ]
Xthen
X   case `grep -c '^key' $HOME/.spellckrc` in
X      0)
X         ;;
X      1)
X         KEY=`awk '/^key/ { print $2 }' $HOME/.spellckrc`
X         ;;
X      *)
X         echo "Only one key define allowed in $HOME/.spellckrc"
X         exit
X         ;;
X   esac
X   case `grep -c '^dir' $HOME/.spellckrc` in
X      0)
X         ;;
X      1) DIR=`awk '/^dir/ { print $2 }' $HOME/.spellckrc`
X         ;;
X      *) echo "Only one dictionary directory define allowed in \
X            $HOME/.spellckrc"
X         exit
X         ;;
X   esac
Xfi
Xif [ -n "$SPELLKEY" ]
Xthen
X   KEY="$SPELLKEY"
Xelse
X   KEY="'"
Xfi
Xif [ -n "$SPELLDIR" ]
Xthen
X   DIR="$SPELLDIR"
Xelse
X   DIR="$HOME"
Xfi
Xif [ $# -eq 0 ]
Xthen
X   echo $USEAGE
X   cat << EOF
X   This is an interactive spelling checker. It will pass a file of words
Xthat don't appear in the dictionary to vi. Select a word to change or
Xexamine by placing the cursor on the word and press the "'" key (the key
Xmay be redefined, see files or variables). The file will be passed to vi
Xwith the cursor on the first line containing the selected word. You may
Xsearch for additional occurrences of the word with the "n" key. Continue
Xin this manner, a word at a time, until you are satisfied that all words
Xare correctly spelled. When you indicate that you are done, spell will be
Xre-run if the file has been modified. If the file has not been modified,
Xyou will be asked if you like to update your personal dictionary with those
Xwords you have chosen not to "correct" (acronyms, technical terms, etc.).
X
Xflags: -d	dictionary directory (default ~)
X       -u	update dictionary only
X
Xfiles: ~/.lista (ascii list of words you have added to your dictionary)
X       ~/.hlista (hashed dictionary)
X       ~/.spellckrc (define key other than "'" e.g. key \ or define
X          dictionary directory other than ~ e.g. dir /b/mfg/waynet)
X
Xvariables: \$SPELLKEY
X           \$SPELLDIR
XEOF
X   exit
Xelse
X   for i
X   do case $i in
X      -u) UPDATE=$TRUE
X          ;;
X      -d) ISDIR=$TRUE
X          shift
X          ;;
X      -*) echo "unknown flag '$i'"
X          echo $USEAGE
X          exit
X          ;;
X      *)  if [ "$ISDIR" = $TRUE ]
X          then
X             DIR=$i
X             if [ ! -d $DIR ]
X             then
X                echo "'$DIR' not a valid directory"
X                exit
X             fi
X             ISDIR=$FALSE
X          elif [ ! -f $i ]
X          then
X             echo "file '$i' does not exist"
X             exit
X          else
X             FILES=$FILES" "$i
X          fi
X          ;;
X      esac
X   done
Xfi
XLIST=$DIR/.lista
XHLIST=$DIR/.hlista
Xtouch .$$
Xtrap 'rm .*$$; exit' 2 15
Xif [ "$UPDATE" != $TRUE ]
Xthen
X   if [ ! -f $HLIST ]
X   then
X      cp /usr/dict/hlista $HLIST
X   fi
X   for i in $FILES
X   do
X      spell -d $HLIST $i > .spell.$i$$
X      if [ ! -s .spell.$i$$ ]
X      then
X         echo "No spelling errors in $i."
X         continue
X      fi
X      EXINIT="map $KEY :.w! .$i$$
X      export EXINIT
X      lastmod=`ls -l $i`
X      patn=""
X      while true
X      do
X         if [ -n "$patn" ]
X         then
X            vi +/$patn .spell.$i$$
X         else
X            vi .spell.$i$$
X         fi
X         if [ -f .$i$$ ]
X         then
X            patn=`cat .$i$$`
X            rm .$i$$
X            vi +/$patn $i
X         fi
X         echo -n "Done with $i" '(N) ? '
X         read ans
X         if [ "$ans" = "y" ]
X         then
X            if [ "$lastmod" != "`ls -l $i`" ]
X            then
X               echo "$i has been modified. Rerunning spell."
X               spell -d $HLIST $i > .spell.$i$$
X               if [ ! -s .spell.$i$$ ]
X               then
X                  echo "No spelling errors in $i."
X                  break
X               fi
X               patn=""
X               lastmod=`ls -l $i`
X            else
X               break
X            fi
X         fi
X      done
X   done
X   cat .spell.* > .$$
Xfi
Xif [ -s .$$ ]
Xthen
X   echo -n "Update $HLIST" '(N) ? '
X   read ans
X   if [ "$ans" = "y" ]
X   then
X      UPDATE=$TRUE
X   fi
Xfi
Xif [ "$UPDATE" = $TRUE ]
Xthen
X   if [ -f $LIST ]
X   then
X      cat $LIST >> .$$
X   fi
X   sort -u .$$ > $LIST
X   spellin /usr/dict/hlista < $LIST > $HLIST
Xfi
Xrm .*$$
!FaR!OuT!
chmod ugo+x spellck
exit
-- 
Which is worse, ignorance or apathy? Who knows, who cares.

Wayne Thompson
..{bene,mordor,nsc,oliveb,pyramid,ucbvax}!tolerant!waynet

Your mission, should you decide to accept it, is to discern who is
responsible for these opinions, the poster or the company he works for.
Good luck!!