xref: /csrg-svn/local/local.cmd/Correct.sh (revision 40330)
140329Sbostic#! /bin/sh
240329Sbostic
340329Sbostic: 'correct: create a spelling correction editor script'
440329Sbostic: 'usage:'
540329Sbostic:		correct file1 file2 file3 file4 file5
640329Sbostic:
740329Sbostic: 'list of words in file1 are queried for corrections'
840329Sbostic: 'correction script is placed in file2'
940329Sbostic: 'file3 gets list of exceptions, sorted'
1040329Sbostic: 'file4 gets list of questionable corrections'
1140329Sbostic: 'file5 is name of original source file, for grepping'
1240329Sbostic:
1340329SbosticFIXES=/usr/tmp/$$fixes
1440329SbosticQUEST=/usr/tmp/$$quest
1540329SbosticEXCEPT=$3
1640329Sbosticrm -f $2
1740329Sbosticif [ ! -t 1 ]
1840329Sbosticthen
1940329Sbostic	exit
2040329Sbosticfi
21*40330SbosticDICT=/usr/share/dict/words
2240329Sbostictrap "echo This set of corrections not made.;rm -f $FIXES $QUEST; exit 1"  1 2 15
2340329Sbosticfor WORD in `cat $1`
2440329Sbosticdo
2540329Sbostic	echo -n $WORD "?"
2640329Sbostic	read FIX
2740329Sbostic	RESP=new
2840329Sbostic	while [ "$RESP" != "ok" ]
2940329Sbostic	do
3040329Sbostic		case "$FIX" in
3140329Sbostic
3240329Sbostic		"&"|"-")
3340329Sbostic			RESP=ok ;;
3440329Sbostic		"?"*)
3540329Sbostic			echo 'Try one of these:'
3640329Sbostic			grep `expr "$FIX" : "? \(.*\)"` $DICT
3740329Sbostic			echo -n "$WORD ?"
3840329Sbostic			read FIX
3940329Sbostic			RESP=incomplete
4040329Sbostic			;;
4140329Sbostic		"^"*|*"$"|*"."*|*"*"*)
4240329Sbostic			echo 'Try one of these:'
4340329Sbostic			grep "$FIX" $DICT
4440329Sbostic			echo -n "$WORD ?"
4540329Sbostic			read FIX
4640329Sbostic			RESP=incomplete
4740329Sbostic			;;
4840329Sbostic		/)
4940329Sbostic			grep -w $WORD $5
5040329Sbostic			echo -n "$WORD ?"
5140329Sbostic			read FIX
5240329Sbostic			RESP=incomplete
5340329Sbostic			;;
5440329Sbostic		""|"!")
5540329Sbostic			echo $WORD >> $EXCEPT
5640329Sbostic			RESP=ok
5740329Sbostic			;;
5840329Sbostic		*)
5940329Sbostic			echo "$FIX" >> $FIXES
6040329Sbostic			echo "g/\<$WORD\>/s::$FIX:g" >> $2
6140329Sbostic			RESP=ok
6240329Sbostic			;;
6340329Sbostic		esac
6440329Sbostic	done
6540329Sbosticdone
6640329Sbosticecho w >> $2
6740329Sbosticecho q >> $2
6840329Sbosticif [ -s $FIXES ]
6940329Sbosticthen
7040329Sbostic	spell <$FIXES >$QUEST
7140329Sbostic	if [ -s $QUEST ]
7240329Sbostic	then
7340329Sbostic		echo "Some questionable corrections:"
7440329Sbostic		cat $QUEST | sed -e "s/./	&/"
7540329Sbostic		sort $QUEST -o $4
7640329Sbostic	else
7740329Sbostic		echo "Corrections appear ok."
7840329Sbostic		rm -f $4; touch $4
7940329Sbostic	fi
8040329Sbostic	rm -f $FIXES $QUEST
8140329Sbosticelse
8240329Sbostic	rm -f $4; touch $4;
8340329Sbosticfi
84