xref: /original-bsd/local/local.cmd/Correct.sh (revision e59fb703)
1#! /bin/sh
2
3: 'correct: create a spelling correction editor script'
4: 'usage:'
5:		correct file1 file2 file3 file4 file5
6:
7: 'list of words in file1 are queried for corrections'
8: 'correction script is placed in file2'
9: 'file3 gets list of exceptions, sorted'
10: 'file4 gets list of questionable corrections'
11: 'file5 is name of original source file, for grepping'
12:
13FIXES=/usr/tmp/$$fixes
14QUEST=/usr/tmp/$$quest
15EXCEPT=$3
16rm -f $2
17if [ ! -t 1 ]
18then
19	exit
20fi
21DICT=/usr/share/dict/words
22trap "echo This set of corrections not made.;rm -f $FIXES $QUEST; exit 1"  1 2 15
23for WORD in `cat $1`
24do
25	echo -n $WORD "?"
26	read FIX
27	RESP=new
28	while [ "$RESP" != "ok" ]
29	do
30		case "$FIX" in
31
32		"&"|"-")
33			RESP=ok ;;
34		"?"*)
35			echo 'Try one of these:'
36			grep `expr "$FIX" : "? \(.*\)"` $DICT
37			echo -n "$WORD ?"
38			read FIX
39			RESP=incomplete
40			;;
41		"^"*|*"$"|*"."*|*"*"*)
42			echo 'Try one of these:'
43			grep "$FIX" $DICT
44			echo -n "$WORD ?"
45			read FIX
46			RESP=incomplete
47			;;
48		/)
49			grep -w $WORD $5
50			echo -n "$WORD ?"
51			read FIX
52			RESP=incomplete
53			;;
54		""|"!")
55			echo $WORD >> $EXCEPT
56			RESP=ok
57			;;
58		*)
59			echo "$FIX" >> $FIXES
60			echo "g/\<$WORD\>/s::$FIX:g" >> $2
61			RESP=ok
62			;;
63		esac
64	done
65done
66echo w >> $2
67echo q >> $2
68if [ -s $FIXES ]
69then
70	spell <$FIXES >$QUEST
71	if [ -s $QUEST ]
72	then
73		echo "Some questionable corrections:"
74		cat $QUEST | sed -e "s/./	&/"
75		sort $QUEST -o $4
76	else
77		echo "Corrections appear ok."
78		rm -f $4; touch $4
79	fi
80	rm -f $FIXES $QUEST
81else
82	rm -f $4; touch $4;
83fi
84