#!/bin/sh
# article -- Print any ``an foo'' or ``a object'' mistakes in a text file.
#
# BUGS:  This doesn't know about "h" and thinks "u" doesn't need "an".
#        should also work with quotations better...
#
# AUTHOR:	Gary T. Leavens
article()
{
USAGE="Usage: $0 file ..."

# no arguments?
if test $# -eq 0
then
	echo "$USAGE" >&2
	exit 1
fi

awk 'BEGIN	{ prev = "" }
	{ for (i=1; i<=NF; i++) {
		if ((prev ~ /^[Aa]n$/) && ($i ~ /^[^AaEeIiOo].*$/)) {
			print prev, $i }
		if ((prev ~ /^[Aa]$/) && ($i ~ /^[AaEeIiOo].*$/)) {
			print prev, $i }
		prev = $i } }
' $*
}

[ -n "$echo" ] && set -x

article $*

