#ident "@(#)serial	1.2"
# lp interface for serial line printer
#
# This script is identical to the "dumb" model, except that it does
# an stty that sets apprpriate serial port characteristics:
#
#       8-bits, no parity, 9600 baud
#       XON/XOFF
#       pass tabs through to printer
#
# AND it does a dummy stty at the end of the script to force waiting
# for the output to drain.  This depends upon the fact that stty(1)
# does a TCSETAW ioctl().  If you do not wait for output to drain,
# the line discipline close will resume output even though the printer
# has done an XOFF, overflowing the printer's buffer.
#

stty -parenb -parodd cs8 9600 -hupcl -cstopb cread clocal -loblk \
 ignbrk -brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc \
 ixon -ixany -ixoff \
 -isig icanon -xcase -echo -echoe -echok -echonl noflsh \
 opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab0 \
 line 0 \
 0<&1

x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "\014\c"
echo "$x\n$x\n$x\n$x\n"
banner "$2"
echo "\n"
user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
if [ -n "$user" ]
then
	echo "User: $user\n"
else
	echo "\n"
fi
echo "Request id: $1    Printer: `basename $0`\n"
date
echo "\n"
if [ -n "$3" ]
then
	banner $3
fi
copies=$4
echo "\014\c"
shift; shift; shift; shift; shift
files="$*"
i=1
while [ $i -le $copies ]
do
	for file in $files
	do
		cat "$file" 2>&1
		echo "\014\c"
	done
	i=`expr $i + 1`
done
echo "$x\n$x\n$x\n$x\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n$x\n$x\n$x\n$x"
echo "$x\n$x\n$x\n$x\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
echo "$x\n$x\n$x\n$x\n$x\n$x\n$x\n$x\n"

# do a dummy stty to wait for output to drain.
stty erase '^h'

exit 0
