xref: /onnv-gate/usr/src/cmd/lp/model/tsol_netstandard (revision 4746:0bc0c48f4304)
1*4746Srica#
2*4746Srica# CDDL HEADER START
3*4746Srica#
4*4746Srica# The contents of this file are subject to the terms of the
5*4746Srica# Common Development and Distribution License (the "License").
6*4746Srica# You may not use this file except in compliance with the License.
7*4746Srica#
8*4746Srica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*4746Srica# or http://www.opensolaris.org/os/licensing.
10*4746Srica# See the License for the specific language governing permissions
11*4746Srica# and limitations under the License.
12*4746Srica#
13*4746Srica# When distributing Covered Code, include this CDDL HEADER in each
14*4746Srica# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*4746Srica# If applicable, add the following below this CDDL HEADER, with the
16*4746Srica# fields enclosed by brackets "[]" replaced with your own identifying
17*4746Srica# information: Portions Copyright [yyyy] [name of copyright owner]
18*4746Srica#
19*4746Srica# CDDL HEADER END
20*4746Srica#
21*4746Srica#
22*4746Srica# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*4746Srica# Use is subject to license terms.
24*4746Srica#
25*4746Srica#pragma ident	"%Z%%M%	%I%	%E% SMI"
26*4746Srica
27*4746Srica###########
28*4746Srica##
29*4746Srica## Network Standard printer interface program.
30*4746Srica##
31*4746Srica###########
32*4746Srica
33*4746Srica#####
34*4746Srica# We can't do much except exit if spooler/scheduler
35*4746Srica# cancels us.
36*4746Srica#####
37*4746Sricatrap 'eval exit_clean 15' 15
38*4746Srica
39*4746Srica####
40*4746Srica#
41*4746Srica# Send standard error messages to /dev/null rather than to
42*4746Srica# the spooler. Avoids "Terminated" messages that shell puts out
43*4746Srica# when gets SIGTERM. Save standard error so it can be used
44*4746Srica# when we need it
45*4746Srica####
46*4746Sricaexec 5>&2 2>/dev/null 3>&1
47*4746Srica
48*4746Srica####
49*4746Srica# set some global variables
50*4746Srica####
51*4746Srica
52*4746Srica: ${LPTMPDIR:=/tmp}
53*4746Srica: ${SPOOLDIR:=/usr/spool/lp}
54*4746Srica: ${LOCALPATH:=${SPOOLDIR}/bin}
55*4746SricaPATH="/bin:/usr/bin:${LOCALPATH}"
56*4746Sricaexit_code=0
57*4746Srica
58*4746Srica
59*4746Srica# ${LPTELL} is the name of a program that will send its
60*4746Srica# standard input to the Spooler. It is used to forward
61*4746Srica# the description of a printer fault to the Spooler,
62*4746Srica# which uses it in an alert to the administrator.
63*4746Srica#####
64*4746Sricaif [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ]
65*4746Sricathen
66*4746Srica        fake_lptell () {
67*4746Srica                header="no"
68*4746Srica                while read line
69*4746Srica                do
70*4746Srica                        if [ "no" = "${header}" ]
71*4746Srica                        then
72*4746Srica                                errmsg ERROR ${E_IP_UNKNOWN} \
73*4746Srica                "unknown printer/interface failure" \
74*4746Srica                "consult your system administrator;
75*4746Srica                reasons for failure (if any) follow:"
76*4746Srica                                header=yes
77*4746Srica                        fi
78*4746Srica                        echo "${line}" >&2
79*4746Srica                done
80*4746Srica                return 1
81*4746Srica        }
82*4746Srica        LPTELL=fake_lptell
83*4746Sricafi
84*4746Srica
85*4746Srica#####
86*4746Srica# ${LPTSOLSEPARATOR} is the name of a program to put banner and trailer
87*4746Srica# pages around the job.
88*4746Srica#####
89*4746Sricaif [ -x ${LOCALPATH}/lp.tsol_separator ]
90*4746Sricathen
91*4746Srica	LPTSOLSEPARATOR=${LOCALPATH}/lp.tsol_separator
92*4746Sricaelse
93*4746Srica	echo "${LOCALPATH}/lp.tsol_separator not found." >&2
94*4746Srica	exit 1
95*4746Sricafi
96*4746Srica
97*4746Srica#####
98*4746Srica# Error message formatter:
99*4746Srica#
100*4746Srica# Invoke as
101*4746Srica#
102*4746Srica#       errmsg severity message-number problem help
103*4746Srica#
104*4746Srica# where severity is "ERROR" or "WARNING", message-number is
105*4746Srica# a unique identifier, problem is a short description of the
106*4746Srica# problem, and help is a short suggestion for fixing the problem.
107*4746Srica#####
108*4746Srica
109*4746SricaLP_ERR_LABEL="UX:lp"
110*4746SricaE_IP_ARGS=1
111*4746SricaE_IP_OPTS=2
112*4746Srica#E_IP_FILTER=3
113*4746SricaE_IP_UNKNOWN=5
114*4746SricaE_IP_BADFILE=6
115*4746SricaE_IP_ERRORS=12 	# (in slow.filter)
116*4746Srica
117*4746Sricaerrmsg () {
118*4746Srica
119*4746Srica        case $1 in
120*4746Srica        ERROR )
121*4746Srica                sev="  ERROR";
122*4746Srica                ;;
123*4746Srica        WARNING )
124*4746Srica                sev="WARNING";
125*4746Srica                ;;
126*4746Srica        esac
127*4746Srica
128*4746Srica        echo "${LP_ERR_LABEL}:$2 ${sev}: $3
129*4746Srica        TO FIX: $4" >&5
130*4746Srica}
131*4746Srica
132*4746Srica###########
133*4746Srica##
134*4746Srica## Check arguments
135*4746Srica###########
136*4746Srica
137*4746Sricaparse () {
138*4746Srica        echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
139*4746Srica}
140*4746Srica
141*4746Srica#####
142*4746Srica##
143*4746Srica## Error Cleanup and Exit
144*4746Srica##
145*4746Srica#####
146*4746Srica
147*4746Sricaexit_clean()
148*4746Srica{
149*4746Srica
150*4746Srica	if [ -f "${LPTMPDIR}/pr_eexit_code.$$" ]
151*4746Srica	then
152*4746Srica		/bin/rm ${LPTMPDIR}/pr_eexit_code.$$
153*4746Srica	fi
154*4746Srica
155*4746Srica	if [ -f "${LPTMPDIR}/small_banner.$$" ]
156*4746Srica	then
157*4746Srica		/bin/rm ${LPTMPDIR}/small_banner.$$
158*4746Srica	fi
159*4746Srica
160*4746Srica	if [ -f "${LPTMPDIR}/banner.exit_code.$$" ]
161*4746Srica	then
162*4746Srica		/bin/rm ${LPTMPDIR}/banner.exit_code.$$
163*4746Srica	fi
164*4746Srica
165*4746Srica	if [ -f "${LPTMPDIR}/banner.errmsg.$$" ]
166*4746Srica	then
167*4746Srica		/bin/rm ${LPTMPDIR}/banner.errmsg.$$
168*4746Srica	fi
169*4746Srica
170*4746Srica	if [ -f "${tmpfile}" ]
171*4746Srica	then
172*4746Srica		/bin/rm "${tmpfile}"
173*4746Srica	fi
174*4746Srica
175*4746Srica	exit $1
176*4746Srica}
177*4746Srica
178*4746Srica#####
179*4746Srica#
180*4746Srica# This program is invoked as
181*4746Srica#
182*4746Srica# ${SPOOLDIR}/.../printer request-id user title copies options files...
183*4746Srica#
184*4746Srica# The first three arguments are simply reprinted on the banner page,
185*4746Srica# the fourth (copies) is used to control the number of copies to print,
186*4746Srica# the fifth (options) is a blank separated list (in a single argument)
187*4746Srica# of user or Spooler supplied options (without the -o prefix),
188*4746Srica# and the last arguments are the files to print.
189*4746Srica#####
190*4746Srica
191*4746Sricaif [ $# -lt 5 ]
192*4746Sricathen
193*4746Srica
194*4746Srica        errmsg ERROR ${E_IP_ARGS} \
195*4746Srica                "wrong number of arguments to interface program" \
196*4746Srica                "consult your system administrator"
197*4746Srica        exit 1
198*4746Sricafi
199*4746Srica
200*4746Sricaprinter=`basename $0`
201*4746Sricarequest_id=$1
202*4746Sricauser_name=$2
203*4746Sricatitle=$3
204*4746Sricacopies=$4
205*4746Sricaoption_list=$5
206*4746Srica
207*4746Sricashift 5
208*4746Sricafiles="$*"
209*4746Srica
210*4746Srica
211*4746Srica#
212*4746Srica# debug sent to file if defined in /etc/syslog.conf
213*4746Srica# syslog.conf entry:
214*4746Srica#	lpr.debug	/path/filename
215*4746Srica#
216*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" " "
217*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "INPUT"
218*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    \
219*4746Srica    printer : ${printer}"
220*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    \
221*4746Srica    request_id : ${request_id}"
222*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    \
223*4746Srica    user_name : ${user_name}"
224*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    title : ${title}"
225*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    \
226*4746Srica    copies : ${copies}"
227*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    \
228*4746Srica    option_list : ${option_list}"
229*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "    files : ${files}"
230*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "	 \
231*4746Srica    spooler_key ${SPOOLER_KEY}"
232*4746Srica
233*4746Srica####
234*4746Srica# default: do print a banner
235*4746Srica####
236*4746Sricanobanner=no
237*4746Sricanolabels="no"
238*4746Sricanofilebreak="no"
239*4746Sricainlist=
240*4746Sricadata_file_flag=
241*4746Srica
242*4746Sricafor i in ${option_list}
243*4746Sricado
244*4746Srica        case "${inlist}${i}" in
245*4746Srica
246*4746Srica        nobanner )
247*4746Srica                nobanner="yes"
248*4746Srica                ;;
249*4746Srica
250*4746Srica        nofilebreak )
251*4746Srica                nofilebreak="yes"
252*4746Srica                ;;
253*4746Srica
254*4746Srica	nolabels )
255*4746Srica		nolabels="yes"
256*4746Srica		;;
257*4746Srica
258*4746Srica        #####
259*4746Srica        #
260*4746Srica        # If you want to add simple options (e.g. -o simple)
261*4746Srica        # identify them here.
262*4746Srica        #####
263*4746Srica#       simple )
264*4746Srica#               simple="yes"
265*4746Srica# 		;;
266*4746Srica
267*4746Srica        cpi=pica )
268*4746Srica                cpi=10
269*4746Srica                ;;
270*4746Srica        cpi=elite )
271*4746Srica                cpi=12
272*4746Srica                ;;
273*4746Srica        cpi=* )
274*4746Srica                cpi=`parse ${i}`
275*4746Srica                ;;
276*4746Srica
277*4746Srica        lpi=* )
278*4746Srica                lpi=`parse ${i}`
279*4746Srica                ;;
280*4746Srica
281*4746Srica        length=* )
282*4746Srica                length=`parse ${i}`
283*4746Srica                ;;
284*4746Srica
285*4746Srica        width=* )
286*4746Srica                width=`parse ${i}`
287*4746Srica                ;;
288*4746Srica        dest=* )
289*4746Srica                dest="-d `parse ${i}`"
290*4746Srica                ;;
291*4746Srica
292*4746Srica        protocol=* )
293*4746Srica                protocol="-P `parse ${i}`"
294*4746Srica                ;;
295*4746Srica        bsdctrl=* )
296*4746Srica		controlfile="-c `parse ${i}`"
297*4746Srica                ;;
298*4746Srica        timeout=* )
299*4746Srica                timeout="-t `parse ${i}`"
300*4746Srica                ;;
301*4746Srica
302*4746Srica        data-file-type=* )
303*4746Srica                data_file_flag="-f `parse ${i}`"
304*4746Srica                ;;
305*4746Srica
306*4746Srica        #####
307*4746Srica        #
308*4746Srica        # If you want to add simple-value options (e.g. -o value=a)
309*4746Srica        # identify them here.
310*4746Srica        #####
311*4746Srica#       value=* )
312*4746Srica#		value=`parse ${i}`
313*4746Srica#		;;
314*4746Srica
315*4746Srica        #####
316*4746Srica        #
317*4746Srica        # If you want to add options that,
318*4746Srica        # take a list (e.g. -o lopt='a b c'), identif
319*4746Srica        # them here and below (look for LOPT).
320*4746Srica        #####
321*4746Srica
322*4746Srica#	flist=* | lpd=* | options=* )
323*4746Srica        flist=* | lpd=* )
324*4746Srica#LOPT   stty=* | flist=* | lpd=* | lopt=* )
325*4746Srica
326*4746Srica                inlist=`expr "${inlist}${i}" : "^\([^=]*=\)"`
327*4746Srica                case "${i}" in
328*4746Srica                ${inlist}\'*\' )
329*4746Srica                        item=`expr "${i}" : "^[^=]*='*\(.*\)'\$"`
330*4746Srica                        ;;
331*4746Srica                ${inlist}\' )
332*4746Srica                        continue
333*4746Srica                        ;;
334*4746Srica                ${inlist}\'* )
335*4746Srica                        item=`expr "${i}" : "^[^=]*='*\(.*\)\$"`
336*4746Srica                        ;;
337*4746Srica                ${inlist}* )
338*4746Srica                        item=`expr "${i}" : "^[^=]*=\(.*\)\$"`
339*4746Srica                        ;;
340*4746Srica                *\' )
341*4746Srica                        item=`expr "${i}" : "^\(.*\)'\$"`
342*4746Srica                        ;;
343*4746Srica                * )
344*4746Srica                        item="${i}"
345*4746Srica                        ;;
346*4746Srica                esac
347*4746Srica
348*4746Srica                #####
349*4746Srica                #
350*4746Srica                # We don't dare use "eval" because a clever user could
351*4746Srica                # put something in an option value that we'd end up
352*4746Srica                # exec'ing.
353*4746Srica                #####
354*4746Srica                case "${inlist}" in
355*4746Srica                flist= )
356*4746Srica                        flist="${flist} ${item}"
357*4746Srica                        ;;
358*4746Srica                lpd= )
359*4746Srica                        lpd="${lpd} ${item}"
360*4746Srica                        ;;
361*4746Srica#LOPT		lopt= )
362*4746Srica#LOPT                   lopt="${lopt} ${item}"
363*4746Srica#LOPT			;;
364*4746Srica#		options= )
365*4746Srica#			options="${options} ${item}"
366*4746Srica#			;;
367*4746Srica                esac
368*4746Srica
369*4746Srica                case "${i}" in
370*4746Srica                ${inlist}\'*\' )
371*4746Srica                        inlist=
372*4746Srica                        ;;
373*4746Srica                ${inlist}\'* )
374*4746Srica                        ;;
375*4746Srica                *\' | ${inlist}* )
376*4746Srica                        inlist=
377*4746Srica                        ;;
378*4746Srica                esac
379*4746Srica                ;;
380*4746Srica
381*4746Srica        * )
382*4746Srica                errmsg WARNING ${E_IP_OPTS} \
383*4746Srica                        "unrecognized \"-o ${i}\" option" \
384*4746Srica                        "check the option, resubmit if necessary
385*4746Srica                printing continues"
386*4746Srica                ;;
387*4746Srica        esac
388*4746Sricadone
389*4746Srica
390*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}"  "term : ${TERM}"
391*4746Srica
392*4746Sricaif [ -z "${FILTER}" ]
393*4746Sricathen
394*4746Srica        #####
395*4746Srica        #
396*4746Srica        # If no filter is being used, we use netpr to push the
397*4746Srica	# file to the printer.
398*4746Srica        # (QUOTES ARE IMPORTANT!)
399*4746Srica        #####
400*4746Srica
401*4746Srica        case "$TERM" in
402*4746Srica                PS )
403*4746Srica                        # make the "postscript" printers use cat
404*4746Srica			# (TSOL banners are added during filtering, so we have
405*4746Srica			# to use some filter.)
406*4746Srica                        FILTER=/bin/cat
407*4746Srica                ;;
408*4746Srica                PSR )
409*4746Srica                        # make the "reverse postscript" printers reverse the
410*4746Srica                        # output and the use postio to talk to the printer
411*4746Srica                        #FILTER="/usr/lib/lp/postscript/postreverse "
412*4746Srica                        #FILTER=
413*4746Srica                        FILTER="/usr/lib/lp/postscript/postreverse "
414*4746Srica                ;;
415*4746Srica                * )
416*4746Srica                        # We don't know the type, so just assume that the
417*4746Srica                        # input and output are the same. Use netpr.
418*4746Srica                        #FILTER=/bin/cat
419*4746Srica			FILTER=
420*4746Srica                ;;
421*4746Srica        esac
422*4746Sricafi
423*4746Srica
424*4746Srica####
425*4746Srica# sets default value for ordering of data and control files with
426*4746Srica# bsd protocol. Default: data files first. Administrator
427*4746Srica# may set to control file first with lpadmin -o bsdctrl=first
428*4746Srica####
429*4746Srica
430*4746Sricabanner_flag=""
431*4746Sricacase "${nobanner}" in
432*4746Srica	yes )
433*4746Srica		banner_flag="-b"
434*4746Srica	;;
435*4746Sricaesac
436*4746Srica
437*4746SricaNETPR="/usr/lib/lp/bin/netpr ${banner_flag} ${data_file_flag} \
438*4746Srica	-I ${request_id} -U ${user_name} \
439*4746Srica	-p ${printer} ${dest} -T \"${title}\"  \
440*4746Srica	${timeout}  ${protocol} ${controlfile} "
441*4746SricaLPTELL_OPTS="-l"        # netpr sends LaserWriter style messages back
442*4746Srica
443*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "NETPR= ${NETPR}"
444*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "filter : ${FILTER}"
445*4746Srica
446*4746Sricanode=`uname -n`
447*4746Sricapid=$$
448*4746Sricatmpfile=${LPTMPDIR}/${node}.${pid}
449*4746Srica
450*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" "tmpfile : ${tmpfile}"
451*4746Srica
452*4746Srica#####
453*4746Srica#
454*4746Srica# Set up filter for banner page
455*4746Srica#
456*4746Srica#####
457*4746Sricabanner_filter=
458*4746Sricacase "${TERM}" in
459*4746SricaPS | PSR )
460*4746Srica	banner_filter=" | /usr/lib/lp/postscript/postprint "
461*4746Srica	LPTELL_OPTS="-l"
462*4746Srica	;;
463*4746Sricaesac
464*4746Srica
465*4746Srica#####
466*4746Srica#
467*4746Srica# Build temporary file that is the banner page
468*4746Srica#
469*4746Srica#####
470*4746SricaPAD="#####${NL}"
471*4746SricaCR="\r"
472*4746SricaNL="${CR}\n"
473*4746SricaFF=
474*4746Srica
475*4746Sricasmall_banner() {
476*4746Srica        echo "${CR}\c"
477*4746Srica        echo "${PAD}\c"
478*4746Srica        echo "#####  User: ${user_name}${NL}\c"
479*4746Srica        if [ -n "${title}" ]
480*4746Srica        then
481*4746Srica                echo "##### Title: ${title}${NL}\c"
482*4746Srica        fi
483*4746Srica        echo "#####  Date: `LANG=C date '+%a %H:%M %h %d, %Y'`${NL}\c"
484*4746Srica        echo "#####   Job: ${request_id}${NL}\c"
485*4746Srica        echo "${PAD}\c"
486*4746Srica        if [ -n "${FF}" ]
487*4746Srica        then
488*4746Srica                echo "${CR}${FF}\c"
489*4746Srica        fi
490*4746Srica}
491*4746Srica
492*4746Srica#####
493*4746Srica#
494*4746Srica# Doing small banner as we don't know what printer is out there
495*4746Srica#
496*4746Srica#####
497*4746Sricabanner=small_banner
498*4746Srica
499*4746Srica## Skip this for PS/PSR printers, since lp.tsol_separator handles the banners
500*4746Sricaif [ "no" = "${nobanner}" -a "${TERM}" != "PSR" -a "${TERM}" != "PS" ]
501*4746Sricathen
502*4746Srica	eval "${banner} ${banner_filter}" 2>&1 1>${LPTMPDIR}/small_banner.$$
503*4746Sricafi
504*4746Srica
505*4746Srica###########
506*4746Srica##
507*4746Srica## Surround the job by PostScript code to produce banner
508*4746Srica## and trailerpages and page headers and footers.
509*4746Srica##
510*4746Srica###########
511*4746Srica
512*4746SricaBANNER_EXIT_CODE=${LPTMPDIR}/banner.exit_code.$$
513*4746Sricaecho 0 > ${BANNER_EXIT_CODE}
514*4746SricaTSOLSEPARATOR_LOG=${LPTMPDIR}/banner.errmsg.$$
515*4746Srica
516*4746Sricatsol_bannerize () {
517*4746Srica	TSOLSEPARATOR_OPTS="-e ${TSOLSEPARATOR_LOG}"
518*4746Srica
519*4746Srica	if [ "yes" = "${nolabels}" ]
520*4746Srica	then
521*4746Srica		TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -l"
522*4746Srica	fi
523*4746Srica
524*4746Srica	if [ "yes" = "${nobanner}" ]
525*4746Srica	then
526*4746Srica		TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -t /dev/null -b /dev/null"
527*4746Srica	fi
528*4746Srica
529*4746Srica	if [ "${TERM}" = "PSR" ]
530*4746Srica	then
531*4746Srica		TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -r"
532*4746Srica	fi
533*4746Srica
534*4746Srica	# Get rid of the #, TAB and NL characters in the title
535*4746Srica	tsol_title=`echo $title`
536*4746Srica	tsol_title=`echo $tsol_title | sed 's/#//g'`
537*4746Srica
538*4746Srica	logger -p lpr.debug -t "tsol_netstandard: ${request_id}" \
539*4746Srica	    "banner command: ${LPTSOLSEPARATOR} ${TSOLSEPARATOR_OPTS} \
540*4746Srica	    ${printer} ${request_id} ${user_name} \"${tsol_title}\" ${file}"
541*4746Srica	${LPTSOLSEPARATOR} ${TSOLSEPARATOR_OPTS} ${printer} \
542*4746Srica	    ${request_id} ${user_name} "${tsol_title}" ${file}
543*4746Srica
544*4746Srica	echo $? > ${BANNER_EXIT_CODE}
545*4746Srica	true
546*4746Srica}
547*4746Srica
548*4746Sricabannerize=tsol_bannerize
549*4746Srica
550*4746Sricaif [ "yes" = "${nobanner}" -a  "yes" = "${nolabels}" ]
551*4746Sricathen
552*4746Srica	bannerize=cat
553*4746Sricafi
554*4746Srica
555*4746Sricaif [ "${TERM}" != "PSR" -a "${TERM}" != "PS" ]
556*4746Sricathen
557*4746Srica	bannerize=cat
558*4746Sricafi
559*4746Srica
560*4746Srica#####
561*4746Srica#
562*4746Srica# Print banner page before job unless PS or PSR.
563*4746Srica#
564*4746Srica#####
565*4746Srica
566*4746Sricaif [ "no" = "${nobanner}" -a "${TERM}" != "PSR" -a "${TERM}" != "PS" ]
567*4746Sricathen
568*4746Srica	(
569*4746Srica		eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1
570*4746Srica		echo $? > ${LPTMPDIR}/pr_eexit_code.$$
571*4746Srica	) | ${LPTELL} ${LPTELL_OPTS} ${printer}
572*4746Srica
573*4746Srica	exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
574*4746Srica	logger -p lpr.debug -t "tsol_netstandard: ${request_id}"	\
575*4746Srica		"banner page exit code : ${exit_code}"
576*4746Srica
577*4746Sricafi
578*4746Srica
579*4746Sricai=1
580*4746Sricawhile [ $i -le $copies ]
581*4746Sricado
582*4746Srica        for file in ${files}
583*4746Srica        do
584*4746Srica                if [ -r "${file}" ]
585*4746Srica                then
586*4746Srica
587*4746Srica			if [ ! -z "${FILTER}" ]
588*4746Srica			then
589*4746Srica 				(
590*4746Srica					#####
591*4746Srica					# There is a filter, use it
592*4746Srica					#
593*4746Srica					# Put 0<${file} before the "eval" to keep
594*4746Srica					# clever users from giving a file name that
595*4746Srica					# evaluates as something to execute.
596*4746Srica					# Redirect stderr to stdout so LPTELL will
597*4746Srica					# get error messages from pipe.
598*4746Srica					#####
599*4746Srica					0<${file} $bannerize | eval ${FILTER} 2>&1 1>${tmpfile}
600*4746Srica					echo $? > ${LPTMPDIR}/pr_eexit_code.$$
601*4746Srica				) | ${LPTELL} ${LPTELL_OPTS} ${printer}
602*4746Srica
603*4746Srica				# if lp.tsol_separator had an error, send its logged
604*4746Srica				# error message to LPTELL.
605*4746Srica				banner_exit_code=`cat ${BANNER_EXIT_CODE}`
606*4746Srica				if [ -n "${banner_exit_code}" -a \
607*4746Srica					0 -ne "${banner_exit_code}" -a \
608*4746Srica					 -n "${LPTELL}" -a \
609*4746Srica					-r "${TSOLSEPARATOR_LOG}" ]
610*4746Srica				then
611*4746Srica					cat ${TSOLSEPARATOR_LOG} | ${LPTELL} ${printer}
612*4746Srica					echo 77 > ${LPTMPDIR}/pr_eexit_code
613*4746Srica				fi
614*4746Srica
615*4746Srica				exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
616*4746Srica				logger -p lpr.debug \
617*4746Srica				    -t "tsol_netstandard: ${request_id}" \
618*4746Srica					"filter exit_code : ${exit_code}"
619*4746Srica
620*4746Srica 			 	if [ -n "${exit_code}" ]
621*4746Srica 				then
622*4746Srica					if [ "${exit_code}" -eq 0 ]
623*4746Srica					then
624*4746Srica						printfile=${tmpfile}
625*4746Srica					else
626*4746Srica						####
627*4746Srica						# The filter did not succeed, so don't try to print
628*4746Srica						####
629*4746Srica							printfile=
630*4746Srica					fi
631*4746Srica				fi
632*4746Srica
633*4746Srica			else
634*4746Srica				printfile=${file}
635*4746Srica			fi
636*4746Srica
637*4746Srica			logger -p lpr.debug \
638*4746Srica			    -t "tsol_netstandard: ${request_id}" \
639*4746Srica				"printfile : ${printfile}"
640*4746Srica
641*4746Srica			#####
642*4746Srica			# Print the file
643*4746Srica			#####
644*4746Srica
645*4746Srica			if [ -r "${printfile}" ]
646*4746Srica			then
647*4746Srica				(
648*4746Srica					eval ${NETPR} ${printfile} 2>&1
649*4746Srica					echo $? > ${LPTMPDIR}/pr_eexit_code.$$
650*4746Srica				) | ${LPTELL} ${LPTELL_OPTS} ${printer}
651*4746Srica
652*4746Srica				exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
653*4746Srica				logger -p lpr.debug \
654*4746Srica				    -t "tsol_netstandard: ${request_id}" \
655*4746Srica					"netpr exit_code : ${exit_code}"
656*4746Srica
657*4746Srica#				if [ -f "${tmpfile}" ]
658*4746Srica#				then
659*4746Srica#					/bin/rm "${tmpfile}"
660*4746Srica#				fi
661*4746Srica
662*4746Srica				if [ -n "${exit_code}" ]
663*4746Srica				then
664*4746Srica					if [ "${exit_code}" -eq 0 ]
665*4746Srica					then
666*4746Srica						printone=yes
667*4746Srica					else
668*4746Srica						if [ "${exit_code}" -lt 128 ]
669*4746Srica						then
670*4746Srica							noprint=yes
671*4746Srica						else
672*4746Srica							retry=yes
673*4746Srica						fi
674*4746Srica					fi
675*4746Srica				fi
676*4746Srica
677*4746Srica
678*4746Srica			else
679*4746Srica
680*4746Srica				errmsg WARNING ${E_IP_BADFILE} \
681*4746Srica				"cannot read temporary file \"${printfile}\""\
682*4746Srica					"see if file still exists,
683*4746Srica			or consult your system administrator;
684*4746Srica			printing continues"
685*4746Srica
686*4746Srica			fi
687*4746Srica		else
688*4746Srica
689*4746Srica                        #####
690*4746Srica                        #
691*4746Srica                        # Don't complain about not being able to read
692*4746Srica                        # a file on second and subsequent copies, unless
693*4746Srica                        # we've not complained yet. This removes repeated
694*4746Srica                        # messages about the same file yet reduces the
695*4746Srica                        # chance that the user can remove a file and not
696*4746Srica                        # know that we had trouble finding it.
697*4746Srica                        #####
698*4746Srica
699*4746Srica                        if [ "${i}" -le 1 -o -z "${badfileyet}" ]
700*4746Srica                        then
701*4746Srica                                errmsg WARNING ${E_IP_BADFILE} \
702*4746Srica                                        "cannot read file \"${file}\"" \
703*4746Srica                                        "see if the file still exists and is readable,
704*4746Srica                or consult your system administrator;
705*4746Srica                printing continues"
706*4746Srica                                badfileyet=yes
707*4746Srica                        fi
708*4746Srica
709*4746Srica		fi
710*4746Srica
711*4746Srica# for file in ${files}
712*4746Srica	done
713*4746Srica	i=`expr $i + 1`
714*4746Sricadone
715*4746Srica
716*4746Srica#####
717*4746Srica#
718*4746Srica# If printing in reverse order, print the banner page now
719*4746Srica# Skip this for TSOL, since lp.tsol_separator handles the banners
720*4746Srica#
721*4746Srica#####
722*4746Srica
723*4746Srica#
724*4746Srica# if [ "no" = "${nobanner}" -a "${TERM}" = "PSR" ]
725*4746Srica# then
726*4746Srica# (
727*4746Srica# 	eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1
728*4746Srica#	echo $? > ${LPTMPDIR}/pr_eexit_code.$$
729*4746Srica# ) | ${LPTELL} ${LPTELL_OPTS} ${printer}
730*4746Srica# fi
731*4746Srica
732*4746Sricaexit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
733*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}"     \
734*4746Srica                "banner page exit code : ${exit_code}"
735*4746Srica
736*4746Sricaif [ -n "${printone}" -a -z "${retry}" -a -z "${noprint}" ]
737*4746Sricathen
738*4746Srica       	exit_code=`expr 0`
739*4746Sricaelse
740*4746Srica        if [ -n "${retry}" -a -z "${printone}" -a -z "${noprint}" ]
741*4746Srica        then
742*4746Srica                exit_code=`expr 129`
743*4746Srica        else
744*4746Srica		exit_code=`expr 1`
745*4746Srica	fi
746*4746Sricafi
747*4746Srica
748*4746Sricalogger -p lpr.debug -t "tsol_netstandard: ${request_id}" \
749*4746Srica	"FINAL exit_code : ${exit_code}"
750*4746Srica
751*4746Sricaexit_clean ${exit_code}
752