#! /bin/sh
# Filter a PostScript file for printing on a Lexmark
# printer, drawing letterhead bond paper from Tray 1
# for the first page, and printing in simplex mode
# for the remaining pages from other trays.
#
# Usage:
#	print-lexmark-letterhead [-P printername] PSfile
#	print-lexmark-letterhead [-Pprintername] PSfile
#
#
# NB: This will only work properly on Lexmark printers.
#
# [17-Jul-1998] -- Update to support -P option
# [18-May-1998]

case $1 in
-P)	
	shift
	PRINTER=$1
	shift
	;;

-P*)
	PRINTER=`echo $1 | awk '{sub(/^-P/,"");print}'`
	shift
	;;

*)
	;;
esac

case $PRINTER in
	lcb115|lcb331|lex*|inscc300) 
		;;
	*)	
		echo The printer $PRINTER is not a Lexmark printer with letterhead paper support
		exit 1
		;;
esac

/usr/local/bin/gawk '
/%%Page: 1 / {
		print 
		print "statusdict begin 0 setpapertray end"
		next
	     }

/%%Page: 2 / {
		print 
		print "statusdict begin 1 setpapertray end" 
		print "statusdict begin false setduplexmode end"
		next
	     }

	     { print }
' "$@" | lpr
