#!/bin/ksh
if [ "X${EPARSER_DEBUG}" != "X" ]; then	
	set -x
fi

if [ $# -eq 0 ]; then
	echo "usage:"
	echo "      $0 <make.err>"
	exit
fi

#
# The following grep command will extract numbered lines
#
grep -E "^[^ ]+:[0-9]+:" $1 |&

# Initialize the temp file
	
TMP_FILE="${TMPDIR:-/tmp}/efiles.$$"

if [ -r $TMP_FILE ] ; then
	printf "" >$TMP_FILE
else
	touch $TMP_FILE
fi
	
# This is the command mode
IFS=$(echo ":\t ");
while read SRC_FILE LINE_NO MSG <&p
do
	#
	# If this is the very first msg to be written into the
	# *.err file, we initialize the *.err file.
	#
	if grep -q "$SRC_FILE" $TMP_FILE >/dev/null 2>&1 ; then
		true;
	else
		echo $SRC_FILE >>$TMP_FILE
		if [ ! -r "$SRC_FILE" ]; then
			SRC_FILE="${SRC_FILE##.}"
		fi
		rm -f "$SRC_FILE.err" >/dev/null 2>&1
	fi
	if [ ! -r "$SRC_FILE" ]; then
		SRC_FILE="${SRC_FILE##.}"
	fi

	# We ignore all errors that are enclosed into ()
	case "$MSG" in
	\(*)
		while read SRC_FILE LINE_NO MSG <&p; do
			if echo "$MSG" | grep -q ")$"; then
				break;
			fi
		done
		continue
		;;
	esac
	
	echo "$LINE_NO: $MSG" >>"$SRC_FILE.err"
done
#
# Delete the TMP file.
#
rm -f "$TMP_FILE" >/dev/null 2>&1
exit 0
