#!/bin/sh
#
# Check the command line args, and suggest changes for possibly misspelled words
#
# Ispell command line switches-handling added by David Frey <david@eos.lugs.ch>

WORDCHARS=""
# XXX Latin1-centric

ARGS=""
while getopts aAbBcCd:Def:lLMN:p:PsStTw:vV s; do
  case $s in
   a|A|c|e|f|l|L|M|N)	;; # ignored
   b|B|C|n|m|P|S|t|x|V)	ARGS="$ARGS -$s" ;; # pass these options through
   d|p|W|T)         	ARGS="$ARGS -$s $OPTARG" ;; # options with params
   w)			WORDCHARS="$OPTARG" ;; 
  esac
done
shift `expr $OPTIND - 1`

res=`echo "$*" | ispell -a -w $WORDCHARS $ARGS| grep "^& " | \
	sed -e "s/^& \([^ ]*\) [0-9][0-9]* [0-9][0-9]*: /\1: /"`	

if [ "$res" ]; then
	echo "$res"
	exit 1
fi

exit 0
