:
#	@(#) emulator 23.2 91/08/29 
#
#	Copyright (C) 1988-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.
#
#	lp interface for Tandy Printers in IBM Emulation Mode
#
#	This interface assumes that the LF code DIP switch is ON (LF = NL),
#	the Emulation Mode DIP switch of the Tandy printer is ON, and that
#	all other DIP switches are OFF. 
#
#	See your printer manual for details on how to use these options.
#	Notice that some options are not compatible with others and that
#	all options are not available on every printer;  check
#	your printer manual for details.
#	
#
#	Tandy Emulator 1.0
#
#	Options for lp -o:
#
#	compress	Standard Compressed 12 Characters per inch
#	condense	Standard Condensed 17 Characters per inch
#	corresp		Correspondence Quality 10 CPI
#	corresp.12	Correspondence Quality 12 CPI
#	prop		Proportional Spacing
#	prop.comp	Compressed Proportional
#	dblwidth	Double Width Characters
#	emphasize	Emphasized Characters
#	dblstrike	Double Strike Characters
#	normal		Normal Printout.  Default if no options are chosen.
#	
#!	Tandy Printer in IBM Emulation Mode

trap  'echo "$fixup$fix" ; echo "\f\c" ; exit 144' 1 2 3 15

#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

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

copies="$4"
user=`grep "^$2:" /etc/passwd | line | awk -F: '{ print $5 }'`

if	nhead=`grep "^BANNERS=" /etc/default/lpd 2>/dev/null	|
	      line						|
	      awk -F= '{ print $2 }'`
	[ "N$nhead" = "N" ]
then
	nhead=1
fi

while	[ $nhead -gt 0 ]
do
	echo "\014\c"
	banner "$2"
	echo "\n"
	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
	nhead=`expr $nhead - 1`
done

fixup=
for option in $5
do
	case "$option" in
	    compress)			# Compressed , (12 CPI)
                   fix="\022"
	       	   echo "\033:";;
            condense)                        # Condensed , (17 CPI)
                   fix="\022"
		   echo "\017";;
            corresp)                     # Correspondence Quality, 10 CPI
                   fix="\033I\001\022"
		   echo "\033I\002";;
            corresp.12)                    # Correspondence Quality, 12 CPI
                   fix="\033I\001\022"
		   echo "\033I\002\033:";;
            prop)                      # Proportional Spacing
                   fix="\033P\000\033I\001\022"
		   echo "\033I\002\033P\001";;
            prop.comp)                       # Compressed Proportional
                   fix="\033P\000\033I\001\022"
		   echo "\033I\002\033:\033P\001";;
            emphasize)                       # Emphasized Characters
                   fix="\033F"
		   echo "\033E";;
	    dblwidth)				# Double Width Characters
		   fix="\033W\000"
		   echo "\033W\001";;
	    dblstrike)				# Double Strike Characters
		   fix="\033H"
		   echo "\033G";;
	    normal)			# Normal, Default
		   fix="\033P\000\033I\001\022"
		   echo "\033P\000\033I\001\022";;
             *)                         # Illegal Option
                   echo "Illegal printer option $option ignored" >&2 ;;
        esac
        fixup="$fixup$fix"
done



echo "\014\c"
shift; shift; shift; shift; shift
files="$*"
i=1
while	[ $i -le $copies ]
do
	for file in $files
	do
		0<${file} eval ${FILTER} 2>&1
		echo "\014\c"
	done
	i=`expr $i + 1`
done
echo "$fixup\c"

#Draining characters might be necessary.
${DRAIN}

exit 0
