:
#	@(#) ti800 23.2 91/08/29 
#
#	Copyright (C) 1985-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
#!	Texas Instruments 855 printer
#	Options: lp -oc   compressed print
#		    -on   font module select (n=1,2,3)
#		    -oq   quality mode
#		    -oz   12/15 cpi
#		    -ob   no banner
#

#Set up some global variables.
: ${SPOOLDIR:=/usr/spool/lp}
: ${LOCALPATH:=${SPOOLDIR}/bin}

#Set up the default filter.
if [  -x "${LOCALPATH}/lp.cat" ]
then
	LPCAT="${LOCALPATH}/lp.cat 0"
else
	LPCAT="cat"
fi

#If we are not using a filter, use the default one.
if [ -z "${FILTER}" ]
then
	FILTER="${LPCAT}"
fi

FILTER="$FILTER|pr -t -e"

if [ -x "${LOCALPATH}/drain.output" ]
then
	DRAIN="${LOCALPATH}/drain.output 1"
else
	DRAIN=
fi

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

# use following line for TI855 serial printers
stty ixon 9600 0<&1

# use following line for TI850 serial printers
# stty 300 0<&1

# select DP mode, draft mode, 10 cpi, and font module 1
echo "\033@\033d\033y\033f1"

# border around the banner
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

banner=yes
for i in $options; do
	case $i in
	b)	banner=no ;;
	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
for i in $options
do
    case $i in
    c)
	echo "\033P"
	;;
    1)
	echo "\033f1"
	;;
    2)
	echo "\033f2"
	;;
    3)
	echo "\033f3"
	;;
    q)
	echo "\033q"
	;;
    z)
	echo "\033z"
	;;
    esac
done

while	[ "$copies" -gt 0 ]
do
	for file
	do
		0<${file} eval ${FILTER} 2>&1
		echo "\f\c"
	done
	copies=`expr $copies - 1`
done
echo "\033@\033d\033y\033f1"

#Draining characters might be necessary.
${DRAIN}

exit 0
