spellfix - interactive spelling checker and fixer

Bill Silvert silvert at dalcs.UUCP
Sat May 4 03:23:13 AEST 1985


Here is an enhanced version of spellfix with the following features:
menu driven rather than requiring editing of spell.errors in vi;
supports user dictionary $HOME/dict/words and menu allows user to
	add words to this dictionary;
option for automatic correction of words.

This was created by modifying Rex Saunders' script, and he gets most
of the credit for it.  My changes are inspired mainly by the CP/M
spelling checker "The Word Plus", which is a superb utility with
these and more features.

It has been suggested that spellfix check for complete words.
That is too messy for my taste -- my spelling isn't that bad!
Also, a recent item in net.sources.bugs points out that you can
get into trouble with troff commands.

Another problem which I haven't a fix for is case differences.
I have chosen to ignore all words with embedded numerals (this
includes 2nd) and anything which is all in capitals (since I
write a lot of stuff with embedded Fortran code).
---------------------------cut here-------------------------------
#! /bin/sh
# run through /bin/sh to create script and manual entry
cat > spellfix << xxSHELLxx
#! /bin/sh
# <@(#)spellfix	Ver. 1.6, 85/04/29 12:03:48> - interactive spelling checker and fixer
#   Rex Sanders, USGS Pacific Marine Geology
#   Modifications by Bill Silvert, MEL
t1=/tmp/spf$$.1
t2=/tmp/spf$$.2
t3=/tmp/spf$$.3
prog=`basename $0`
udict=$HOME/dict
uwords=$udict/words

case $# in
1)	trap 'rm -f $t1 $t2 $t3; exit' 0 1 2 15 ;;
*)	echo "Usage: $prog filename" >&2
	exit 1 ;;
esac

echo "Looking for spelling errors in $1 ..."
# ignore upper-case 'words' and alphnumerics
spell $1 | grep "[a-z]" | grep -v "[0-9]" | sort > $t2
if test -s $uwords
then	sort -u $uwords -o $uwords # clean up user's dictionary
	comm -23 $t2 $uwords > $t1
else	mv $t2 $t1
fi
test -s $t1 || exit 0

test -d $udict || mkdir $udict

echo "Found `wc -l <$t1` misspellings"
echo "Responses:	A=add to user dictionary, B=bypass"
echo "		C=correct, M=mark for correction"

for word in `cat $t1`
do
	grep $word $1
	while :
	do
		echo -n "${word}: (A/B/C/M?) "
		read response
		case $response in
		A|a)	echo $word >> $uwords
			break ;;
		B|b)	break ;;
		C|c)	echo -n "Correct spelling: "
			read response
			echo "s/${word}/${response}/" >> $t3
			break ;;
		M|m)	echo "/${word}/i\\" >> $t3
			echo "### spell: ${word} %%%" >> $t3
			break ;;
		*)	;;
		esac
	done
done

test -s $t3 || exit 0

if (sed -f $t3 < $1 > $t2 2> /dev/null)
then
  echo "Here is a temporary copy of $1 to edit: use n to find next error"
  sleep 3
  vi +/###/ $t2
  sed -e '/^### spell: .* %%%$/d' $t2 > $t3
  cp -i $t3 $1
else
  echo "spellfix: error marking misspelled words - file $1 unchanged." >&2
fi
xxSHELLxx
chmod +x spellfix
cat >spellfix.1 <<xxMANxx
.TH SPELLFIX 1 "Local Utility"
.SH NAME
spellfix - interactively fix spelling errors
.SH SYNOPSIS
.B spellfix
file
.SH DESCRIPTION
.PP
.I spellfix
is an interactive spelling checker and fixer.
It calls
.I spell
and also uses a local word list of the user.
Using
.I spellfix
is a 4 step process:
.TP
1.
Type:
.sp
.B
          spellfix
.I file
.sp
where
.I file
is the name of your manuscript.
.I spellfix
only handles one file at a time.
.TP
2.
.I spellfix
will list all apparent misspellings in your manuscript,
along with all lines in which each occurs.
Respond to each with A if you want it added to your local
dictionary file, ~/dict/words; B to bypass the word;
C to correct it; and M to mark it in the file for later correction.
If you respond with C,
.I spellfix
will prompt you for the corrected spelling.
Make sure that you want this correction made in all lines shown!
.TP
3.
Edit the temporary copy of your original file.
The words you marked in step 2 will be flagged with lines like:
.br
.sp
.ec +
        ###  spell:  foobar  %%%
.ec
.br
.sp
where
.I foobar
is a misspelled word.
You should correct the misspellings on the text lines that follow.
The flag lines will be removed automatically before the next step.
.TP
4.
Answer
.IR spellfix 's
question:
.sp
          overwrite
.I file
?
.sp
with
.B yes
or
.BR no .
If your answer is yes,
.I spellfix
will replace your original file with the file you created in step 3.
.SH NOTES
In step 3, the search string for
.IR vi (1)
is set to "###";
you can conveniently search for the next spelling error with the
"n" request.
.PP
.I spellfix
was inspired by
.IR error (1).
.SH FILES
~/dict/words	user dictionary
.SH SEE ALSO
sed(1), spell(1), vi(1), troff(1), error(1).
.SH BUGS
.PP
.I spellfix
can change more lines than needed.
For example, if
.I spell
rejects 'teache',
lines with 'teacher' will be marked as erroneous.
.SH AUTHOR
Rex Sanders, U.S. Geological Survey, Pacific Marine Geology.
Modifications by William Silvert, Marine Ecology Laboratory.
xxMANxx
-- 
Bill Silvert
Marine Ecology Lab.
Dartmouth, NS
dalcs!biomel!bill



More information about the Comp.sources.unix mailing list