#!/bin/ksh
##########################
##
## Unix Printing Interface Program for IBM AIX.
## Last Update 10/31/2001
## Copyright 1999-2001
## All rights reserved
## Ricoh Engineering
##
##########################

##########################
##
## Update History
##
## 10/31/2001 First Release
##
##########################

##########################
##
## Debug Flag, set to y to leave temp files in /tmp
##
##########################

DEBUG=

##########################
##
## Parse arguments passed as [attribute]=[value]
##
##########################

parse () {
	echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
}

##########################
#
# This program is invoked as
#
# [name-of-this-filter] option1, option2, option3 ... filename
#
##########################

printer=`basename \`expr $0 : '\(.*\)\.'\``
request_id=
user_name=`whoami`
title=
copies=
option_list=

nobanner="no"
nofilebreak="no"
stty=
inlist=

device_tmp=
prtout_tmp=
ps_tmp=
pjl_tmp=
pcl_tmp=
TXT=
PS=
PCL=
is_PS=
is_DSC=
is_TXT=
copies=1

REMOTE_PRINTER=

##########################
#
# device_tmp stores device option commands
# prtout_tmp holds actual printout to the printer
# ps_tmp is used to hold pre-processed input PS file
#
##########################

device_tmp="/tmp/afcdev_$$.tmp"
prtout_tmp="/tmp/afcprt_$$.tmp"
ps_tmp="/tmp/afcps_$$"
pjl_tmp="/tmp/afcpjl_$$"
pcl_tmp="/tmp/afcpcl_$$"

##########################
#
# Auto-detect input file type here
#
# If is_PS=1, input file is PostScript
# If is_PS=0, input file is text
# is_PS is overwritten, if user specified 
#	input file type with "-o text" or "-o ps" option
#
##########################

#OS_NAME=`uname -s`

#is_PS=1
#is_PS=`file $* | grep -c PostScript`

##########################
##########################
#
# Device options (e.g. -o value=a) are identified 
# and processed here.
#
##########################

#for i in ${option_list}
until [ -z "$2" ]
do
	if [ -f "$1" ]
	then
		break;
	fi
	
	i=$1;
	shift
	#case "${inlist}${i}" in
	case "$i" in

	nobanner )
		nobanner="yes"
		;;

	nofilebreak )
		nofilebreak="yes"
		;;

##########################
#
# Debug option
#
##########################

	debug ) 
		DEBUG=Y
		;;
		
##########################
#
# Text option
#
##########################

	text ) 
		TXT=1
		;;

##########################
#
# PS option
#
##########################

	ps )
		PS=1
		;;
##########################
#
# PCL option
#
##########################

	pcl|nofilter )
		PCL=1
		;;
##########################
#
# number of copies
#

	nn=* )
		copies=`parse ${i}`

		echo "<</NumCopies $copies>>setpagedevice" >> $device_tmp
		printf "\033&l%dx" $copies >> $pcl_tmp
		;;
#end of copies
##############################
