:
#	@(#) emulator 22.2 90/04/24 
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#
#	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

if [ -x "/usr/spool/lp/bin/drain.output" ]
then
	DRAIN="/usr/spool/lp/bin/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
		cat "$file" 2>&1
		echo "\014\c"
	done
	i=`expr $i + 1`
done
echo "$fixup\c"

#Draining characters might be necessary.
${DRAIN}

exit 0
