# hplaser: lp model interface for HP LaserJet Series II
#
# command arguments are:
#	request-id user-name title copies printer-options file1 [file2 ...]
#	$1         $2        $3    $4     $5
#
# options are:
#	-otroff		#No cr/lf mapping (for JetRoff, etc.)
#	-oraw		#Same
#	-oland		#Landscape orientation for unformatted text
#	-o2on1		#Two pages on one page for unformatted text
#	-oi		#Indent 8 characters for unformatted text
#	-o17cpi		#17 CPI for unformatted text
#
# Configuration:
speed=19200	#Serial interface speed (19.2)
speed=		#Parallel interface leave blank
banner=0	#Enable printing of banner page
picture=0	#Enable printing of $HOME/.mugshot on banner page
		#.mugshot is any PCL, typically a scanned picture of the user
#
#
noraw="\033&k2G"
raw="\033&k0G"
if [ "$speed" != "" ]
then
	stty $speed clocal cs8 ixon ixoff -ixany -parenb onlcr -tabs -opost <&1
fi
# character sequence to initialize printer before printing
SET=""
# character sequence to reset printer after printing done
RESET="\033E"
#
#	First, get printer banner page out in portrait, courier
#
if [ $banner = 1 ]
then
	PCOURIER=	#"\033&l66p2e7.6c66F"
	GRAY="\033*c2400a150b30g2P"
	TLOC="\033*p0x0Y"
	echo "$RESET$noraw$PCOURIER$TLOC$GRAY\n\n\n\n"
	banner "  $2"
	echo "\n"
	user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
	if [ -n "$user" ]
	then
		echo "                User: $user\n"
	else
		echo "\n"
	fi
	echo "                Request id: $1    Printer: `basename $0`\n"
	echo "                Options: $5\n"
	echo "                `date`"
	echo "\n"
	if [ -n "$3" ]
	then
		banner $3
	fi
	if [ $picture = 1 ]
	then
		home=`grep "^$2:" /etc/passwd | line | cut -d: -f6`
		if [ -f "$home/.mugshot" ]
		then
			echo "$raw\c"
			echo "                \c"
			cat $home/.mugshot
			echo "$noraw\c"
		fi
	fi
	echo "\014\c"
else
	echo "$RESET\c"
fi
#
#	Now process user options
#
trap 'echo $RESET\\c; exit' 0 2 3 15
copies=$4
opts=$5
shift 5
files="$*"
two_on_one=0
i=1
ifraw="$noraw"
for o in $opts
do
	case $o in
	troff|raw)
		SET="$SET\033E"
		ifraw="$raw"
		;;
	land)
		#	&l1O		-	landscape orientation
		#	(s16.66H	-	primary font pitch
		#	&l5.4		-	vert motion index 48ths/in
		#	&l6E		-	Top margin
		#	&l66F		-	text length
	SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
		;;
	17cpi)
		#	(s16.66H	-	primary font pitch
		#	&l5.4		-	vert motion index 48ths/in
		#	&l6E		-	Top margin
		#	&l66F		-	text length
		SET="$SET\033(s16.66H"
		;;
	i)	# indent 8 characters
		SET="$SET\033&a8L"
		;;
	2on1)
	SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
		two_on_one=1;
		;;
	esac
done
while [ $i -le $copies ]
do
	for file in $files
	do
		echo "$SET$ifraw\c"
		if [ $two_on_one = 1 ]
		then
			cat "$file" | newform -i | \
				sed "s/^/| /" | pr -2 -w175 -t
			echo "$RESET\c"
		else
			cat "$file" 2>&1
			echo "$RESET\c"
		fi
	done
	i=`expr $i + 1`
done
exit 0
