home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume2
/
correct
< prev
next >
Wrap
Internet Message Format
|
1991-08-07
|
8KB
From: powell@ole.UUCP (Gary Powell)
Newsgroups: comp.sources.misc
Subject: v02i071: shell script to manage personal dictionary and correct text
Message-ID: <7474@ncoast.UUCP>
Date: 5 Mar 88 23:52:35 GMT
Approved: allbery@ncoast.UUCP
Comp.sources.misc: Volume 2, Issue 71
Submitted-By: "Gary Powell" <powell@ole.UUCP>
Archive-Name: correct
#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive. Save this into a file, edit it
# and delete all lines above this comment. Then give this
# file to sh by executing the command "sh file". The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r--r-- 1 allbery System 5303 Mar 5 18:32 correct.csh
# -rw-rw-rw- 1 allbery uucp 829 Mar 5 18:33 correct.l
#
echo 'x - correct.csh'
if test -f correct.csh; then echo 'shar: not overwriting correct.csh'; else
sed 's/^X//' << '________This_Is_The_END________' > correct.csh
X#! /bin/csh -f
X
X#
X# This script takes a file name as an argument and looks for misspellings.
X# If you want to change the file, a sed script is provided, or you
X# can change your personal dictionary. It will add one if you need it.
X#
X# Author : G. Powell Seattle Silicon Co. 11/3/87
X#
X
X# extract the file name from the command line.
Xset text = $1
X
X# Your personal dictionary, and lookup table file names.
Xset mylist = ~/.myhdict
Xset mylook = ~/.mylook
X
X# Temp files for use while this script is running
Xset temptext = /tmp/$1.$$
Xset tempfile = /tmp/tmp_file.$$
Xset tmplist = /tmp/myhdict_tmp.$$
Xset tmplook = /tmp/mylook_tmp.$$
Xset sedfile = /tmp/sed_spell.$$
X
X# Delilimaters of a "word"
Xset delim = '\([\.,?\!(){}\[\]""";: ]\)'
X
Xecho "Checking spelling in $text."
X
X#
X# if you have a personal dictionary use it.
X#
Xif (-e $mylist) then
X set list = $mylist
Xelse
X set list = /usr/dict/hlista
Xendif
X
Xset llook = $mylook
X
Xecho "Type h for help"
X
Xforeach i (`spell -d $list $text`)
X set word = $i
X Query:
X echo -n "< $word > ? "
X switch ($<)
X case 'a':
X Addword:
X echo "Adding $word to list $mylist."
X#
X# Add word to your personal dictionary
X#
X if (! -e $tmplist) then
X cp $list $tmplist
X set list = $tmplist
X endif
X echo $word | spellin $list > $tempfile
X mv -f $tempfile $list
X#
X# Add word to your personal lookup list
X#
X if (! -e $tmplook && -e $mylook) then
X cp $mylook $tmplook
X endif
X set llook = $tmplook
X echo $word >> $tmplook
X cat $tmplook | sort | uniq > $tempfile
X mv -f $tempfile $tmplook
X breaksw
X case 'c':
X echo -n "New spelling? "
X set neword = ($<)
X echo "-> Changing occurances of $word to $neword in $text."
X#
X# Look for new word word in dictionary
X#
X @ change = 0
X set foundword = `echo $neword | spellout $list`
X if ($foundword == $neword) then
X echo "$neword was not found in your dictionary."
X echo -n "Do you still want to change it? [y/n] "
X if ('y' != $<) then
X goto Query
X endif
X @ change = 1
X endif
X
X if (! -e $temptext) then
X cp $text $temptext
X endif
X echo /$word/s/'^'$word"$delim"/$neword'\1'/g > sedfile
X echo /$word/s/"$delim"$word'$'/'\1'$neword/g >> sedfile
X echo /$word/s/"$delim"$word"$delim"/'\1'$neword'\2'/g >> sedfile
X mv $temptext $tempfile
X sed -f sedfile $tempfile > $temptext
X /bin/rm sedfile
X /bin/rm $tempfile
X
X if ( $change == 1) then
X echo -n "Do you want add $neword to your dictionary? [y/n] "
X if ('y' == $<) then
X set word = $neword
X goto Addword
X endif
X endif
X breaksw
X case 'd':
X if (-e $temptext) then
X diff $text $temptext | less -emQ
X else
X echo "You haven't made any changes yet."
X endif
X goto Query
X breaksw
X case 'h':
X echo " a - add this word to your personal directory $mylist"
X echo " c - change all occurances of this word in the file $text"
X echo " d - diff file $text and the tempfile changes."
X echo " h - help (this command)"
X echo " l - look up the word for near spellings"
X echo " p - print the context of the words."
X echo " q - quit (you can save current changes.)"
X echo " r - remove a word from your dictionary, $mylist."
X echo " s - look up an entered word for near spellings"
X echo "<cr> - skip to the next word."
X goto Query
X breaksw
X case 'l':
X set lookup = $word
X Lookup:
X @ ccount = `echo $lookup | wc -c`
X Lookagain:
X look $lookup > $tempfile
X if (-e $llook) then
X look $lookup $llook >> $tempfile
X endif
X @ wcount = `cat $tempfile | wc -l`
X if ( $wcount <= 0 ) then
X if ($ccount > 3) then
X @ ccount --
X set lookup = `echo $lookup | colrm $ccount`
X echo "Nothing found yet, trying...$lookup"
X goto Lookagain
X else
X echo "No words found."
X /bin/rm $tempfile
X goto Query
X endif
X endif
X cat $tempfile | sort | uniq | less -emQ
X /bin/rm $tempfile
X goto Query
X breaksw
X case 'p':
X set search = '\<'$word'\>'
X if (-e $temptext) then
X grep "$search" $temptext | less -emQ
X else
X grep "$search" $text | less -emQ
X endif
X goto Query
X breaksw
X case 'q':
X echo "quit."
X goto Done
X breaksw
X case 'r':
X if (-e $tmplook) then
X /bin/rm $list
X cp $mylist $list
X else
X if (-e $mylook && -e $mydict) then
X cp $mylook $tmplook
X set llook = $tmplook
X cp /usr/dict/hlista $tmplist
X set list = $tmplist
X else
X echo "You don't have a personal word list."
X goto Query
X endif
X endif
X echo -n "Enter word to remove : "
X sed -e "/$</d" $llook > $tempfile
X mv -f $tempfile $llook
X foreach k (`cat $llook`)
X echo $k | spellin $list > $tempfile
X mv -f $tempfile $list
X end
X goto Query
X breaksw
X case 's':
X echo -n "Enter word to find near derivations : "
X set lookup = $<
X goto Lookup
X breaksw
X endsw
Xend
X
X#
X# Save changes
X#
XDone:
Xset answer = y
Xif (-e $temptext) then
X echo -n "Would you like to see your changes? "
X if ('y' == $<) then
X diff $text $temptext | less -emQ
X endif
X echo -n "Do you want to keep your changes? "
X set answer = $<
X if ('y' == $answer) then
X mv -f $temptext $text
X else
X /bin/rm $temptext
X endif
Xendif
X
X#
X# Save new Dictionary
X#
Xif (-e $tmplist && $answer == 'y') then
X echo -n "Do You want to save your updated dictionary? [y/n] "
X if ('n' == $<) then
X /bin/rm $tmplist
X /bin/rm $tmplook
X else
X mv -f $tmplist $mylist
X mv -f $tmplook $mylook
X endif
Xendif
X
Xecho "Done."
________This_Is_The_END________
if test `wc -c < correct.csh` -ne 5303; then
echo 'shar: correct.csh was damaged during transit (should have been 5303 bytes)'
fi
fi ; : end of overwriting check
echo 'x - correct.l'
if test -f correct.l; then echo 'shar: not overwriting correct.l'; else
sed 's/^X//' << '________This_Is_The_END________' > correct.l
X.TH CORRECT l "2 FEBRUARY 1988"
X.UC 4
X.SH NAME
Xcorrect - Correct the spelling in a ascii text file.
X.SH SYNOPSIS
X.LP
X.nf
Xcorrect filename
X.fi
X.SH DESCRIPION
X.PP
Xcorrect is a shell script which runs interactively to
Xhelp you correct your spelling and manage a personal dictionary
Xand word list. It uses the UNIX calls to spell, list, and grep
Xto perform the work.
X.PP
X.SH FILES
X.nf
X /usr/local/bin/correct shell script
X
X ~/.myhdict personal dictionary
X ~/.mylook personal word list
X
XTemp files for use while this script is runs
X /tmp/$1.$$
X /tmp/tmp_file.$$
X /tmp/myhdict_tmp.$$
X /tmp/mylook_tmp.$$
X /tmp/sed_spell.$$
X
X.fi
X.SH AUTHOR
X.nf
X Gary Powell
X.fi
X.SH BUGS
X.PP
XIf you attempt to substitute two words for one the script dies.
________This_Is_The_END________
if test `wc -c < correct.l` -ne 829; then
echo 'shar: correct.l was damaged during transit (should have been 829 bytes)'
fi
fi ; : end of overwriting check
exit 0
--
_Q _Q _Q _Q _Q_Q _Q _Q _Q
/_\) /_\) /_\) /_\)/_/\\) /_\) /_\) Gary Powell /_\)
_O|/O_O|/O__O|/O___O|/O_OO|/O__O|/O__O|/O__________________________________O|/O_
UUCP!uw-beaver!tikal!ole!powell Seattle Silicon Corp. (206) 828-4422