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

#lp interface for postscript printer

#several print modes are available
#raw:	will print out a raw postscript image, if you have a "postscript"
#	file then use this option
#port:	will translate a text file to a postscript image and print it
#	on a postscript printer in portrait mode
#land:	will translate a text file to a postscript image and print it
#	on a postscript printer in landscape mode

#stty exta clocal hupcl cs8 cread icanon ixon icrnl 0<&1
#stty exta -opost onlcr tab3 ixon -echo ixany -ixoff -parity -hupcl 0<&1
#stty 9600 clocal hupcl cs8 cread icanon ixon ixoff icrnl 0<&1
stty ixon ixoff 0<&1

if [ -x "/usr/spool/lp/bin/drain.output" ]
then
	DRAIN="/usr/spool/lp/bin/drain.output 1"
else
	DRAIN=
fi

#find the printmode
MODE=port
RAW="off"
if [ $5 ];then
	for i in $5
	do
		case "$i" in
        	-raw | -RAW | raw)  RAW="on"
		;;
        	-land | -LAND | land)  MODE=land
		;;
        	-land2 | -LAND2 | land2)  MODE=land2
		;;
        	-port | -PORT | port)  MODE=port
		;;
        	esac
	done
fi
export MODE

filter=/usr/spool/lp/bin/text2post
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

if [ $RAW = "on" ];then
	(
	echo "$x\n$x\n$x\n$x\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"
	date
	echo "\n"
	if [ -n "$3" ]
	then
		banner $3
	fi
	copies=$4
	#echo "\014"
	) | $filter
	shift; shift; shift; shift; shift
	files="$*"
	if [ $copies ];then
		numcopies=$copies
	else
		numcopies=1
	fi
	i=1
	while [ $i -le $numcopies ]
	do
		for file in $files
		do
			cat "$file" 2>&1
			echo "\014"
		done
		i=`expr $i + 1`
	done
else
	(
	echo "$x\n$x\n$x\n$x\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"
	date
	echo "\n"
	if [ -n "$3" ]
	then
		banner $3
	fi
	copies=$4
	echo "\014"
	shift; shift; shift; shift; shift
	files="$*"
	if [ $copies ];then
		numcopies=$copies
	else
		numcopies=1
	fi
	i=1
	while [ $i -le $numcopies ]
	do
		j=1
		for file in $files
		do
#this junk it to keep an extra
#page from being printed with multiple files
			if [ $j -eq "1" ];then
				cat "$file" 2>&1
			else
				echo "\014"
				cat "$file" 2>&1
			fi
			j=`expr $j + 1`
		done
		i=`expr $i + 1`
	done
	) | $filter
fi

#Draining characters might be necessary.
${DRAIN}

exit 0
