:
#	@(#) TandyDMP 22.2 90/04/24 
#
#	Copyright (C) The Santa Cruz Operation, 1987, 1988, 1989.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#

#	lp interface for Tandy DMP Printers
#
#	This interface assumes that all 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 Tandy DMP printer; check 
#	your printer manual for details.
#	
#
#	Tandy DMP 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
#	elongate	Elongated Characters
#	bold		Bold Characters
#	italic		Italic Characters
#	dblheight	Double Height Characters
#	microfont	Microfont Printout
#	normal		Normal Printout.  Default if no options are chosen.
#	
#!	Tandy DMP Printer

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

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="\033\023"
	       	   echo "\033\027";;
            condense)                        # Condensed , (17 CPI)
                   fix="\033\023"
		   echo "\033\024";;
            corresp)                     # Correspondence Quality, 10 CPI
                   fix="\033\023"
		   echo "\033\022";;
            corresp.12)                    # Correspondence Quality, 12 CPI
                   fix="\033\023"
		   echo "\033\035";;
            prop)                      # Proportional Spacing
                   fix="\033\023"
		   echo "\033\021";;
            prop.comp)                       # Compressed Proportional
                   fix="\033\023"
		   echo "\033\057";;
            elongate)                       # Elongated Characters
                   fix="\033\017"
		   echo "\033\016";;
            bold)                       # Bold Characters
                   fix="\033\040"
		   echo "\033\037";;
            italic)                       # Italic Characters
                   fix="\033B\000\033\023"
		   echo "\033B\001";;
            dblheight)                       # Double Height
                   fix="\033\027\033\023"
		   echo "\033W";;
            microfont)                       # Microfont
                   fix="\033\027\033\023"
		   echo "\033M";;
	    normal)			# Normal, Default
		   fix="\033\023"
		   echo "\033\023";;
             *)                         # Illegal Option
                   echo "Illegal printer option $option ignored\n" >&2 ;;
        esac
        fixup="$fixup$fix"
done

copies="$4"
shift; shift; shift; shift; shift
files="$*"

echo "\014\c"
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 the characters might be necessary.
${DRAIN}

exit 0
