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

# lp interface for Imagen serial page printer
#
#  Note:  Imagen setup is for
#            eof char = 4
#            quoting char = 2

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

copies=$4
options=$5
raw=$6
shift 5
if [ "$1" = "-raw" ]
then
	stty $SPEED -opost ixon <&1
	shift
else
	stty $SPEED -tabs ixon <&1
fi
files="$*"
i=1


while [ $i -le $copies ]
do
	for file in $files
	do
		##  Send all data through an Imagen filter to perform
		##  necessary quoting

		if [ "x$options" = "x" ]
		then
			cat "$file" | imagfilt 2>&1
		else
			cat "$file" | $options | imagfilt 2>&1
		fi
		if [ "$raw" != "-raw" ]
		then
			echo "\014\c"
		fi
	done
	i=`expr $i + 1`
done

if [ "$1" = "-raw" ]
then
	stty $SPEED -opost ixon <&1
	shift
else
	##  ECHO END OF DOCUMENT BEFORE BEGINNING NEXT
	echo "\004\c"
	stty $SPEED -tabs ixon <&1
fi

exit 0
