#sccs	"@(#)lp/model:n450	1.3"

#
# lp interface for dumb serial line printer
#


if [ "$3" ]
then
	echo
	echo
	echo
	echo
	x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
	echo "\014\c"
	echo "$x\n$x\n$x\n$x\n"
	banner $3
	echo "$x\n$x\n$x\n$x\n"
	echo "\014\c"
fi


PRINTER=`echo $0 | cut -d/ -f2 `
SPEED=9600
if [ -r /usr/spool/lp/baudrates ]
then
	SPEED=`grep $PRINTER /usr/spool/lp/baudrates | cut -c1-4`
fi


COPIES=$4
OPTIONS=$5
RAW=$6
shift; shift; shift; shift; shift
if [ "$RAW" = "-raw" ]
then
	shift
fi
RAWOPT=`echo $OPTIONS | grep -c "RAW"`
if [ "$RAWOPT" != "0" ]
then
	OPTIONS=`echo $OPTIONS | sed "s/RAW//"`
	RAW="-raw"
fi
if [ "$RAW" = "-raw" ]
then
	stty $SPEED -opost ixon <&1
else
	stty $SPEED -onlcr -tabs ixon <&1
fi
FILES="$*"
I=1
while [ $I -le $COPIES ]
do
	for F in $FILES
	do
		if [ "$OPTIONS" = "" ]
		then
			cat "$F" 2>&1
		else
			cat "$F" | $OPTIONS 2>&1
		fi
		if [ "$RAW" != "-raw" ]
		then
			echo "\014\c"
		fi
	done
	I=`expr $I + 1`
done
if [ "$RAW" = "-raw" ]
then
	stty $SPEED -opost ixon <&1
	shift
else
	stty $SPEED onlcr -tabs ixon <&1
fi
exit 0
