:
#	@(#) proprinter 22.2 90/04/24 
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989, 1990.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#
#!	I.B.M. Proprinter XL
#	Options: lp -ob  no banner  Please see ibmlpopt
#	for added font options for the IBM Proprinter XL.
#

if [ -x "/usr/spool/lp/bin/drain.output" ]
then
	DRAIN="/usr/spool/lp/bin/drain.output 1"
else
	DRAIN=
fi

printer=`basename $0`
request=$1
name=$2
title=$3
copies=$4
options=$5
shift; shift; shift; shift; shift

# If it is necessary to change the baud rate or other stty settings for
# your serial printer modify the following line:

stty ixon ixoff -ixany opost 0<&1

# border around the banner
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
banner=yes
ff=no    # default no extra form feed at end of print job
nff=no   # default form feed after each file
lpi=lpi6 # default 6 lines per inch
#****************************************************************************
#	case of options  default is 10 cpi draft mode
#
for i in $options; do
	case $i in
		# no banner
   b|nobanner)	banner=no ;;
		# draft mode 10 cpi  default
	10)	pfont=ten ;;
		# near letter quality  10 cpi
    nlq|nlq10)	pfont=nlq10 ;;
		# emphasized print 10 cpi
    emp|emp10)	pfont=emp10 ;;
		# draft mode 12 cpi
	12)	pfont=twelve ;;
		# emphasized print 12 cpi
	emp12)	pfont=emp12 ;;
		# near letter quality  12 cpi
	nlq12)	pfont=nlq12 ;;
		# condenced print
	cdn)	pfont=cdn ;;
		# set lines per inch to 8 instead of 6.
	lpi8)   lpi=lpi8 ;;
		#  set both condenced and 8 lines per inch
     8x17|17x8)	lpi=lpi8
	        pfont=cdn ;;
		# extra form feed at the end of last file.
      ff|xff)	ff=yes ;;
		# do not add form feed between multiple file print jobs
		# such as checks. (ie no form feed at the end of a single job)
	nff)	nff=yes ;;
	esac
done
#
#************************************************************************
#
[ "$banner" = yes ] && {
	# get the local system id
	if test -r /etc/systemid; then
		sysid=`sed 1q /etc/systemid`
	else
		sysid=`uname -n`
	fi

	# user = fifth field of /etc/passwd
	user=`sed -n "s/^$name:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`

	# nhead gets the value of BANNERS or 1 by default
	nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
	[ "$nhead" -ge 0 -a "$nhead" -le 5 ] || nhead=1

	# print the banner $nhead times
	while	[ "$nhead" -gt 0 ]
	do
		echo "$x\n"
		banner "$name"
		echo "$x\n"
		[ "$user" ] && echo "User: $user\n"
		echo "Request id: $request\n"
		echo "Printer: $printer\n"
		date
		echo "\nMachine: $sysid\n"
		[ "$title" ] && banner $title
		echo "\f\c"
		nhead=`expr $nhead - 1`
	done
}
#
#		SET printer fonts
#
#*************************************************************************
case $pfont in
		# draft mode 10 cpi  default
	ten)	echo "\022\007\c" ;;
		# near letter quality  10 cpi
	nlq10)	echo "\033G\c" ;;
		# emphasized print
	emp10) echo "\033E\c" ;;
		# draft mode 12 cpi
	twelve)	echo "\033:\c" ;;
		# emphasized print 12 cpi
	emp12)	echo "\033:\033E\c" ;;
		# near letter quality  12 cpi
	nlq12)  echo "\033:\033G\c" ;;
		# condenced print  17 cpi
	cdn)    echo "\033\017\c" ;;
esac

[ ${lpi} = "lpi8" ] && echo "\033\060\c"

# send the file(s) to the standard out $copies times
while	[ "$copies" -gt 0 ]
do
	for file
	do
		cat "$file" 2>&1
		[ ${nff} = "no" ] && echo "\f\c"
	done
	copies=`expr $copies - 1`
done

[ ${ff} = "yes" ] && echo "\f\c"

#
#		RESET printer fonts to draft mode 10 CPI 6 LPI
#
#*************************************************************************
case $pfont in
		# near letter quality  10 cpi
	nlq10)	echo "\033H\c" ;;
		# emphasized print
	emp10)  echo "\033F\c" ;;
		# draft mode 12 cpi
	twelve)	echo "\022\c" ;;
		# emphasized print 12 cpi
	emp12)	echo "\022\033F\c" ;;
		# near letter quality  12 cpi
	nlq12)  echo "\022\033H\c" ;;
		# condenced print  17 cpi
	cdn)    echo "\022\c" ;;
esac
[ ${lpi} = "lpi8" ] && echo "\033\062\033A\014\c"

#Draining characters might be necessary.
${DRAIN}

exit 0
