#! /bin/ksh
#
# might be nice to add check for subject specific dict in `pwd`
#

PATH=/usr/bin:/bin:/usr/local/bin:$PATH
export PATH

LIB=$HOME/lib
DICT=$LIB/dict
PGM=`basename $0`

if test ! -d $LIB
then
	echo "$PGM: creating library directory: $LIB"
	mkdir $LIB
fi

if test ! -r  $DICT
then
	echo "$PGM: creating personal spelling file: $DICT"
	/bin/cp /dev/null $DICT
fi

if test $#
then
	badfile=0
	for i
	do
		if test ! -f "$i"
		then
			echo "$PGM: file $i not found"
			badfile=1
		fi
	done
	if test $badfile -ne 0
	then
		exit 1
	fi
fi

function nohtml
{
	sed '
		s/^/ /g
		s/&nbsp;/ /g
		s/&gt;/>/g
		s/&lt;/</g
		s/&amp;/ /g
		s/&\(.\)acute;/\1/g
		s/&\(.\)grave;/\1/g
		s/&\(.\)circ;/\1/g
		s/&\(.\)cedil;/\1/g
		s/&\(.\)uml;/\1/g
		s/&\(..\)lig;/\1/g
		s/&/ /g
		s/http:\/\/[a-zA-Z.-\/\~&+?=]*/ /g
		s/[:;,.]/ /g
		s/tr>/ /g
		s/th>/ /g
		s/td>/ /g
		s/<td / /g
		s/ul>/ /g
		s/ol>/ /g
		s/dl>/ /g
		s/dd>/ /g
		s/dt>/ /g
		s/[Ll][Ii]>/ /g
		s/[Bb][Rr]>/ /g
		s/hr>/ /g
		' $*
}

#echo "$PGM: Possible Spelling Errors: $*"
nohtml $* |
	spell |
		sort |
		comm -23 - $DICT |
		abut -f -10 - - - - - -
#echo "$PGM: Use spadd to add correct words to your list."
exit 0

