:
#	@(#) epson 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.
#
#!	Epson serial or parallel printer
#	Options: lp -ob   no banner
#	Z001 - reset to defaults before printing
#	Z002 - add support for Epson quality, fonts, & effects
#	New Options:
#		-obold			bold font (emphasized mode)
#		-oitalic		italic font
#		-ocondensed		condensed mode
#		-oelite			Elite pitch (Pica is default)
#		-odraft			draft mode
#		-onlq			NLQ mode, Roman font
#		-oroman			NLQ mode, Roman font
#		-osansserif		NLQ mode, Sans Serif font
#
#

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 opost -ixany 0<&1

# border around the banner
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

echo "\033@\c"				# Z001 - reset to default mode

banner=yes
# draft=yes
# compress=no
# elite=no
# bold=no
# italic=no

for i in $options; do
	case $i in
	b|nobanner)		banner=no ;;
# Z002 begin \/\/\/\/
	bold)		bold=yes 
			echo "\033E\c" 
			;;
	italic|i)		italic=yes 
			echo "\033\064\c" 
			;;
	elite|e)	elite=yes 
 			echo "\033M\c" 
			;;
	condensed|c)	condensed=yes 
 			echo "\033\017\c" 
			;;
	draft|d)	draft=yes 
 			echo "\033\0170\00\c" 
			;;
	nlq|roman|n|r)	draft=no 
 			echo "\033\0170\061\033\0153\00\c" 
			;;
	sansserif|ss)	draft=no 
 			echo "\033\0170\061\033\0153\01\c" 
			;;
# Z002 end ^^^^^^^^^
	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
}

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

#Draining characters might be necessary.
${DRAIN}

exit 0

