#!/bin/sh -
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin
IFS=" 	
"

LibDir=__LIBDIR__
TmpDir=__TMPDIR__
TmpFile=$TmpDir/xnews$$
AWK=__AWK__
Uncompress=__UNCOMPRESS__
Mailer=__MAIL__
Rm=__RM__
Cat=__CAT__
Nice=nice 

$Cat > $TmpFile

$AWK '
/^#![ \t]*cunbatch/ {exit 1}

/^IHAVE[ \t]+/ {exit 2}

{exit 3}
' < $TmpFile
status=$?

case $status in
  1)	# A compressed batch
	($Nice $LibDir/cunbatch < $TmpFile | $Nice $Uncompress | \
		$Nice $LibDir/newsinput $*) >> $LibDir/rnews.log 2>&1
	keep=1
  ;;
  2)	# A stray IHAVE list
	# If you are using NNTP, you can do something about this.
	# Uncomment the rest of this section and set NNTPfeed to the host
	# which feeds you articles through NNTP:
	# NNTPfeed=accuvax.nwu.edu
	# ($AWK '$1=="IHAVE" {print $2}' < $TmpFile | \
	#	$LibDir/nntpgimme -v $NNTPfeed) >> $LibDir/rnews.nntp.log 2>&1
	keep=0
  ;;
  3)	# A regular batch or a single article
	$Nice $LibDir/newsinput $* < $TmpFile >> $LibDir/rnews.log 2>&1
	keep=0
  ;;
esac
status=$?

if [ $status -eq 0 -a keep -eq 0 ]
then
	$Rm $TmpFile
elif [ -s $TmpFile ]
then
	$Mailer notes -s "newsinput: failure"<<xx
	A bad news header was received with command line:
	$0 $*
	and was saved in $TmpFile
	exit status was $status
xx
else
	$Rm $TmpFile
	$Mailer notes -s "newsinput: zero-length batch" <<xx
	A zero-sized file was received and discarded.
	This may be caused by a full file system.
xx
fi
exit $status
