#!/bin/sh
##########################
#
# Unix Printing Interface Program for SCO OpenServer.
# COPYRIGHT (C) 1999-2011 RICOH COMPANY,LTD.
# All rights reserved
#
##########################

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

##########################
## Parse arguments passed as -o option of lp command
##########################
parse () {
	echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
}

##########################
# This program is invoked as
#
# ${SPOOLDIR}/.../printer request-id user title copies options files...
#
# The first three arguments are simply reprinted on the banner page,
# the fourth (copies) is used to control the number of copies to print,
# the fifth (options) is a blank separated list (in a single argument)
# of user or Spooler supplied options (without the -o prefix),
# and the last arguments are the files to print.
##########################

printer=`basename $0`
request_id=$1
user_name=$2
title=$3
copies=$4
option_list=$5

shift 5
files="$*"

nobanner="no"
inlist=

Custom_Banner=0
Orientation=0
fontsize=0
papersize=0
duplex_type=0
layout=0
height=0
width=0
pitch=0
lpi=0
vmi=0
hmi=0
vsi=0
hsi=0

Text_type=0
PS_type=0
Other_type=0
is_DSC=0
is_PRNFile=0
is_PDFFile=0
NoFilter_type=0
need_file_type_detection=1
host=`hostname`

##########################
# Change the following line to match to
# the remote printer's name
##########################
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
####################################################
##########################
#
# Update 05/18/2006
#
##########################
prt_date=`date +%y%m%d%H%M%S`

device_tmp="/tmp/afcdev_$prt_date$$.tmp"
prtout_tmp="/tmp/afcprt_$prt_date$$.tmp"
ps_tmp="/tmp/afcps_$prt_date$$"
pjl_tmp="/tmp/afcpjl_$prt_date$$"
#ps_pjl_tmp="/tmp/afcpspjl_$prt_date$$"
pcl_tmp="/tmp/afcpcl_$prt_date$$"
banner_text_tmp="/tmp/afcbanner_text_$prt_date$$"
banner_ps_tmp="/tmp/afcbanner_ps_$prt_date$$"

##########################
#
# Update 07/28/2005
# add buffers for Banner page
#
##########################
banner_pjl_tmp="/tmp/afcbanner_pjl_$prt_date$$"
banner_pcl_tmp="/tmp/afcbanner_pcl_$prt_date$$"
banner_page_tmp="/tmp/afcbanner_page_$prt_date$$"

##########################
#
# Store some default values
#
##########################
PRINTER_NAME=
PRINTER_CONFIG_PATH=/var/spool/lpd/$printer/
PRINTER_CONFIG=$PRINTER_CONFIG_PATH/$printer.config

if [ -f "$PRINTER_CONFIG" ]
then
	. "$PRINTER_CONFIG"
fi
##########################
# Set default # of copies
##########################
#echo "<</NumCopies $copies >>setpagedevice" >> $device_tmp
printf "\033&l%dx" $copies >> $pcl_tmp

##########################
# Device options (e.g. -o value=a) are identified
# and processed here.
##########################
for i in ${option_list}
do
    case "${inlist}${i}" in
	nobanner|nb )
	    nobanner="yes"
            ;;

	banner|yb )
		nobanner="no"
		;;

	nofilebreak )
		nofilebreak="yes"
		;;

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

##########################
# Use Filter Banner Page
##########################
	fbanner )
	    Custom_Banner=1
	    ;;

##########################
# Text File Type option
##########################
	text|a|ascii )
	    Text_type=1
	    PS_type=0
	    NoFilter_type=0
	    need_file_type_detection=0
	    ;;

##########################
# PS File Type option
##########################
	ps|postscript|post )
	    Text_type=0
	    PS_type=1
	    NoFilter_type=0
	    need_file_type_detection=0
	    ;;

##########################
# Other Files Type option
##########################
	nofilter|pcl|relay|pdf|raw )
	    Text_type=0
	    PS_type=0
	    NoFilter_type=1
	    need_file_type_detection=0
	    ;;

##########################
# End of sco_head
##########################
