4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
22 #ident "%Z%%M% %I% %E% SMI"
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
30 ## Standard printer interface program.
36 # Until we get to the point below where the printer port
37 # and physical printer are initialized, we can't do much
38 # except exit if the Spooler/Scheduler cancels us.
44 # We can be clever about getting a hangup or interrupt, though, at least
45 # until the filter runs. Do this early, even though $LPTELL
46 # isn't defined, so that we're covered.
52 "The connection to the printer dropped; perhaps the printer went off-line?" \
53 | ${LPTELL} ${printer}
61 "Received an interrupt from the printer. The reason is unknown,
62 although a common cause is that the baud rate is too high." \
63 | ${LPTELL} ${printer}
67 trap 'catch_hangup; exit_code=129 exit 129' 1
68 trap 'catch_interrupt; exit_code=129 exit 129' 2 3
72 # Most of the time we don't want the standard error to be captured
73 # by the Spooler, mainly to avoid "Terminated" messages that the
74 # shell puts out when we get a SIGTERM. We'll save the standard
75 # error channel under another number, so we can use it when it
78 # Open another channel to the printer port, for use when the
79 # regular standard output won't be directed there, such as in
80 # command substitution (`cmd`).
82 exec 5>&2 2>/dev/null 3>&1
86 # Set some globally used variables and functions.
90 : ${SPOOLDIR:=/usr/spool/lp}
91 : ${TERMINFO:=/usr/lib/terminfo}
92 : ${CHARSETDIR:=/usr/lib/charsets}
94 : ${LOCALPATH:=${SPOOLDIR}/bin}
95 PATH="/bin:/usr/bin:${LOCALPATH}"
97 MAX_COLS_SMALL_BANNER=40
101 # On the 3.2 release of the 386unix product, the parallel port does
102 # not support any ioctl calls. As a result, we cannot set the opost
103 # and onlcr attributes to have <NL>'s expanded to <CR><NL>. This
104 # "filter" gets the job done for us.
106 : ${FIX386BD:=${LOCALPATH}/386parallel}
107 if [ -n "${FIX386BD}" -a -x "${FIX386BD}" ]
109 FIX386BD="| ${FIX386BD}"
115 # Use ${TMPPREFIX} as the prefix for all temporary files, so
116 # that cleanup is easy. The prefix may be up to 13 characters
117 # long, so you only have space for one more character to make
118 # a file name. If necessary, make a directory using this prefix
119 # for better management of unique temporary file names.
121 TMPPREFIX=${TMPDIR}/`uname -n`$$
124 # Before exiting, set ${exit_code} to the value with which to exit.
125 # Otherwise, the exit from this script will be 0.
127 trap 'rm -fr ${TMPPREFIX}*; exit ${exit_code}' 0
130 # ${LPTELL} is the name of a program that will send its
131 # standard input to the Spooler. It is used to forward
132 # the description of a printer fault to the Spooler,
133 # which uses it in an alert to the administrator.
135 if [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ]
141 if [ "no" = "${header}" ]
143 errmsg ERROR ${E_IP_UNKNOWN} \
144 "unknown printer/interface failure" \
145 "consult your system administrator;
146 reasons for failure (if any) follow:"
157 # ${DRAIN} is the name of a program that will wait
158 # long enough for data sent to the printer to print.
160 if [ -x "${LOCALPATH}/drain.output" ]
162 DRAIN="${LOCALPATH}/drain.output 5" # wait only five seconds
168 # ${LPTSOLSEPARATOR} is the name of a program to put banner and trailer
169 # pages around the job.
171 if [ -x ${LOCALPATH}/lp.tsol_separator ]
173 LPTSOLSEPARATOR=${LOCALPATH}/lp.tsol_separator
175 echo "${LOCALPATH}/lp.tsol_separator not found." >&2
180 # ${LPCAT} is the name of a program to use as a default
181 # filter. Minimally it should copy its standard input to
182 # the standard output, but it should also trap printer
183 # faults. The current LPCAT traps hangups (DCD dropping, SIGHUP),
184 # interrupts (SIGINT, SIGQUIT), broken pipe (SIGPIPE), and
185 # excess delays in sending data to the printer, interpreting all
188 if [ ! -x "${LPCAT:=${LOCALPATH}/lp.cat}" ]
194 # ${LPSET} is the name of a program that will set the
195 # character pitch, line pitch, page width, page length,
196 # and character set. It helps to have this in a single
197 # binary program so that (1) it's faster than calls
198 # to "tput"; and (2) it can access the new Terminfo
199 # capabilities for printers (on pre SVR3.2 machines, tput can't).
201 if [ ! -x "${LPSET:=${LOCALPATH}/lp.set}" ]
213 # The funny business with the "2>&1 1>&3" is to let us capture
214 # the standard ERROR, not the standard OUTPUT as is the usual case
215 # with foo=`cmd`. The standard output will go to the printer.
217 [ -n "${stty1}" ] && stty ${stty1} 0<&1
218 chk=`${LPSET} "$1" "$2" "$3" "$4" "$5" 2>&1 1>&3`
219 [ -n "${stty2}" ] && stty ${stty2} 0<&1
223 # The standard error of the delivered ${LPSET} program
224 # is a string of letters, H, V, W, L, S, which correspond
225 # to cpi, lpi, width, length, and character set. A letter
226 # is present only if the corresponding attribute could not
233 errmsg WARNING ${E_IP_BADCPI} \
234 "can't select the character pitch \"${cpi}\"" \
235 "check the valid pitches for the printer,
236 or consult your system administrator;
240 errmsg WARNING ${E_IP_BADLPI} \
241 "can't select the line pitch \"${lpi}\"" \
242 "check the valid pitches for the printer,
243 or consult your system administrator;
248 errmsg WARNING ${E_IP_BADWIDTH} \
249 "can't select the page width \"${width}\"" \
250 "check the valid widths for the printer,
251 or consult your system administrator;
256 errmsg WARNING ${E_IP_BADLENGTH} \
257 "can't select the page length \"${length}\"" \
258 "check the valid lengths for the printer,
259 or consult your system administrator;
263 errmsg WARNING ${E_IP_BADCHARSET} \
264 "can't select the character set \"${CHARSET}\"" \
265 "check the name given in the -S option,
266 or consult your system administrator;
275 # ${TPUT} is "tput" IF it works. We'll disable it if we get an
276 # ugly error message the first time we use it. See the TERM variable
277 # later in the script.
279 # NOTE: The check we use to see if "tput" works is to use an OLD
280 # Terminfo capability, like "lines". If it works with that it may
281 # still fail with some of the newer capabilities like "init" (SVR3.0)
282 # or "swidm" (SVR3.2), because the version of "tput" we have on your
283 # machine is older. Thus, on some of the code where ${TPUT} is used
284 # you'll see "2>/dev/null" being used to avoid ugly error messages.
289 # Error message formatter:
293 # errmsg severity message-number problem help
295 # where severity is "ERROR" or "WARNING", message-number is
296 # a unique identifier, problem is a short description of the
297 # problem, and help is a short suggestion for fixing the problem.
313 E_IP_ERRORS=12 # (in slow.filter)
324 # tag=`expr "${LP_ERR_LABEL}" : "\(.*\):"``expr "${LP_ERR_LABEL}" : ".*:\(.*\)"`
325 echo "${LP_ERR_LABEL}: ${sev}: $3
336 echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
341 # This program is invoked as
343 # ${SPOOLDIR}/.../printer request-id user title copies options files...
345 # The first three arguments are simply reprinted on the banner page,
346 # the fourth (copies) is used to control the number of copies to print,
347 # the fifth (options) is a blank separated list (in a single argument)
348 # of user or Spooler supplied options (without the -o prefix),
349 # and the last arguments are the files to print.
354 errmsg ERROR ${E_IP_ARGS} \
355 "wrong number of arguments to interface program" \
356 "consult your system administrator"
360 printer=`basename $0`
376 for i in ${option_list}
378 case "${inlist}${i}" in
394 # The IPP/PAPI attributes are handled by the foomatic-rip filter so
395 # all we need to do here is ignore them so that they don't invoke the
396 # "unrecognized option" message.
399 finishing=* | page-ranges=* | sides=* )
401 number-up=* | orientation-requested=* | media=* )
403 printer-resolution=* | print-quality=* )
408 # If you want to add simple options (e.g. -o simple)
409 # identify them here.
440 # If you want to add simple-value options (e.g. -o value=a)
441 # identify them here.
450 # If you want to add options that, like "stty",
451 # take a list (e.g. -o lopt='a b c'), identify
452 # them here and below (look for LOPT).
454 stty=* | flist=* | lpd=* )
455 #LOPT stty=* | flist=* | lpd=* | lopt=* )
457 inlist=`expr "${inlist}${i}" : "^\([^=]*=\)"`
460 item=`expr "${i}" : "^[^=]*='*\(.*\)'\$"`
466 item=`expr "${i}" : "^[^=]*='*\(.*\)\$"`
469 item=`expr "${i}" : "^[^=]*=\(.*\)\$"`
472 item=`expr "${i}" : "^\(.*\)'\$"`
481 # We don't dare use "eval" because a clever user could
482 # put something in an option value that we'd end up
487 stty="${stty} ${item}"
490 flist="${flist} ${item}"
496 #LOPT lopt="${lopt} ${item}"
513 errmsg WARNING ${E_IP_OPTS} \
514 "unrecognized \"-o ${i}\" option" \
515 "check the option, resubmit if necessary
523 # Additional ``parameters'' are passed via Shell environment
526 # TERM The printer type (used for Terminfo access)
527 # CHARSET The character set to choose
528 # FILTER The filter to run
532 # Set defaults for unset variables.
536 tput lines 1>/dev/null 2>&1 || TPUT=:
540 PPDFILTER=/usr/lib/lp/bin/foomatic-rip
541 PPDFILTERA="${PPDFILTER} ${request_id} ${user_name} \"${title}\" ${copies} \"${option_list}\""
543 if [ -z "${FILTER}" ]
547 # If no filter is being used, we have a little routine that
548 # will push the data to the printer. It traps hangups (loss
549 # of carrier) and checks for excessive delays in sending the
550 # data to the printer. The lesser of the print rate of the printer
551 # (obtained from Terminfo) or the baud rate is used to compute
552 # the expected delay. If neither of these is correct, you
553 # may be experiencing false alarms. If so, give the correct
554 # rate, in characters per second, as a single argument.
555 # An argument of 0 means don't check for delays.
556 # Give an -r option to get a printout of actual delays.
557 # (QUOTES ARE IMPORTANT!)
561 # make the "postscript" printers use postio to
562 # talk to the printer and periodically get a
564 FILTER="/usr/lib/lp/postscript/postio"
567 # make the "reverse postscript" printers reverse the
568 # output and the use postio to talk to the printer
569 FILTER="/usr/lib/lp/postscript/postreverse | \
570 /usr/lib/lp/postscript/postio"
573 # we don't know the type, so just assume that the
574 # input and output are the same
575 if [ `basename "${LPCAT}"` = "lp.cat" ] ; then
576 FILTER="${LPCAT} 0" # infinite delays
577 # FILTER="${LPCAT} 120" # e.g. 120 CPS
578 # FILTER="${LPCAT} -r 0 2>/tmp/delays"
585 logger -p lpr.debug -t "tsol_standard_foomatic: ${request_id}" "filter : ${FILTER}"
586 logger -p lpr.debug -t "tsol_standard_foomatic: ${request_id}" "ppdfilter : ${PPDFILTERA}"
589 # Append the PPD foomatic-rip filter
591 FILTER="${FILTER} | ${PPDFILTERA}"
595 ## Initialize the printer port
601 # Initialize everything.
604 # Don't initialize baud rate.
606 # It's not obvious how to tell if a port is parallel or serial.
607 # However, by splitting the initialization into two steps and letting
608 # the serial-only part fail nicely, it'll work.
610 # Another point: The output must be a ``tty'' device. If not, don't
611 # bother with any of this.
614 tty 0<&1 1>/dev/null 2>&1 && {
618 # First set the default parameters,
619 # then the requested parameters.
624 0<&1 2>/dev/null 1>&2
626 cs8 -cstopb -parenb -parodd \
628 opost -olcuc onlcr -ocrnl -onocr -onlret -ofill \
629 nl0 cr0 tab0 bs0 vt0 ff0 \
630 0<&1 2>/dev/null 1>&2
634 if stty ${stty} 0<&1 1>/dev/null 2>&5
638 errmsg ERROR ${E_IP_STTY} \
639 "stty option list failed" \
640 "check the \"-o stty\" option you used,
641 or consult your system administrator"
648 # Here you may want to add other port initialization code.
651 # estty # for printer needing hardware flow control (3B2/EPORTS)
652 # fctty # for printer needing hardware flow control (3B15,3B20)
660 # Find out if we have to turn off opost before initializing the
661 # printer and on after. Likewise, check clocal.
663 # Turning OFF opost (output postprocessing) keeps the UNIX system
664 # from changing what we try to send to the printer. Turning ON
665 # clocal keeps the UNIX system from dropping what we are trying to
666 # send if the printer drops DTR. An example of the former is the
667 # AT&T 479, which wants to send a linefeed (ASCII 10) when a page
668 # width of 10 is set; with opost on, this COULD BE turned into a
669 # carriage-return/linefeed pair. An example of the latter is the
670 # AT&T 455, which momentarily drops DTR when it gets the
671 # initialization string, is2; with clocal off, the UNIX system
672 # stops sending the rest of the initialization sequence at that
675 # THIS CODE MUST FOLLOW THE REST OF THE PORT INITIALIZATION CODE.
677 cur_stty=`stty -a 0<&3`
678 expr "${cur_stty}" : '.*-opost' 1>/dev/null 2>&1 \
679 || stty1="${stty1} -opost" stty2="${stty2} opost"
680 expr "${cur_stty}" : '.*-clocal' 1>/dev/null 2>&1 \
681 && stty1="${stty1} clocal" stty2="${stty2} -clocal"
682 expr "${cur_stty}" : '.* opost.*' 1>/dev/null 2>&1 \
683 || banner_filter=${FIX386BD}
690 ## Initialize the physical printer (Part I).
691 ## Here we bring the printer to a sane state and set the page size.
696 # WARNING! The "echo" command will catch backslashes (\) and
697 # try to interpret the characters following it. Thus, using
698 # "echo" to print string values obtained from "tput" is dangerous.
702 # We're confident that most printers don't have backslashes
703 # in the control sequences for carriage return and form-feed.
704 # We're also confident that these don't contain newlines.
705 # We're also confident that most printers have a linefeed
706 # in the control sequence for doing a newline (move to beginning
707 # of next line), but we can't capture it like we do the
708 # carriage return or form-feed. Thus we set it unconditionally.
709 # We don't set form-feed if it isn't defined, however, because
710 # maybe the printer doesn't have a formfeed. If not set, we're
715 [ -z "${CR}" ] && CR="\r"
719 [ -z "${BFF}" ] && BFF="\f"
723 lines=`${TPUT} lines`
724 [ -z "${lines}" -o 0 -ge "${lines}" ] && lines=66
727 [ -z "${cols}" -o 0 -ge "${cols}" ] && cols=132
731 # Basic initialization. The ``else'' clause is equivalent,
732 # but covers cases where old Terminal Information Utilities are present.
734 [ -n "${stty1}" ] && stty ${stty1} 0<&1
737 # "tput init" will return an "^M" in many cases to "stdout", i.e., printer!
738 # This creates problems for some PS printers
740 if [ "${TERM}" = "PS" -o "${TERM}" = "PSR" ]
743 elif ${TPUT} init 2>/dev/null
757 if [ "8" != "`${TPUT} it`" ]
759 stty tab3 0<&1 1>/dev/null 2>&1
761 elif `${TPUT} ht >/dev/null`
763 tabset="/usr/lib/tabset/${TERM}"
768 stty tab3 0<&1 1>/dev/null 2>&1
772 if [ "${tabset}" != "${file}" -a -r "${file}" ]
780 [ -n "${stty2}" ] && stty ${stty2} 0<&1
784 # Set the page size and print spacing, but not the character set.
785 # We will be doing the character set later (after the header).
787 internal_lpset "${cpi}" "${lpi}" "${width}" "${length}" ""
791 # The banner page (and cancellation page) will
792 # use double width characters if they're available.
794 WIDE_CS=`${TPUT} swidm 2>/dev/null` && NORM_CS=`${TPUT} rwidm 2>/dev/null`
799 # Some printers need to have the banner page filtered.
804 banner_filter="/usr/lib/lp/postscript/postprint | /usr/lib/lp/postscript/postio"
809 if [ -n "${banner_filter}" ]
811 banner_filter="| ${banner_filter}"
816 # Now that the printer is ready for printing, we're able
817 # to record on paper a cancellation.
821 echo "${PAD}${PAD}\c"
822 echo "#####${WIDE_CS} Job ${request_id}${NORM_CS}${NL}\c"
823 echo "#####${WIDE_CS} suspended or canceled${NORM_CS}${NL}\c"
824 echo "${PAD}${PAD}\c"
828 ${TPUT} scs 0 2>/dev/null
830 if [ "${width:-${cols}}" -lt "${MAX_COLS_SMALL_BANNER}" ]
841 trap 'eval canceled ${banner_filter}; exit_code=0 exit' 15
846 ## Print the banner page
851 # You may want to change the following code to get a custom banner.
856 echo "${PAD}${PAD}${PAD}${PAD}${PAD}\c"
857 echo "#####${WIDE_CS} User: ${user_name}${NORM_CS}${NL}\c"
858 if [ -n "$ALIAS_USERNAME" ]
861 echo "#####${WIDE_CS} Alias: ${ALIAS_USERNAME}${NORM_CS}${NL}\c"
866 echo "#####${WIDE_CS} Title: ${title}${NORM_CS}${NL}\c"
869 echo "#####${WIDE_CS} Printed: `LANG=C date '+%a %H:%M %h %d, %Y'`${NORM_CS}${NL}\c"
871 echo "#####${WIDE_CS} Job number: ${request_id}${NORM_CS}${NL}\c"
872 echo "${PAD}${PAD}${PAD}${PAD}${PAD}\c"
882 echo "##### User: ${user_name}${NL}\c"
885 echo "##### Title: ${title}${NL}\c"
887 echo "##### Date: `LANG=C date '+%a %H:%M %h %d, %Y'`${NL}\c"
888 echo "##### Job: ${request_id}${NL}\c"
896 if [ "${width:-${cols}}" -lt "${MAX_COLS_SMALL_BANNER}" ]
900 banner=regular_banner
903 ## Skip this for PS/PSR in TSOL, since lp.tsol_separator handles the banners
904 if [ "no" = "${nobanner}" -a "${TERM}" != "PSR" -a "${TERM}" != "PS" ]
906 ( eval "${banner} ${banner_filter}" 2>&1 1>&3 ) \
907 | ${LPTELL} ${LPTELL_OPTS} ${printer}
912 ## Surround the job by PostScript code to produce banner
913 ## and trailerpages and page headers and footers.
917 BANNER_EXIT_CODE=${TMPPREFIX}.banner.exit_code
918 echo 0 > ${BANNER_EXIT_CODE}
919 TSOLSEPARATOR_LOG=${TMPPREFIX}.banner.errmsg
922 TSOLSEPARATOR_OPTS="-e ${TSOLSEPARATOR_LOG}"
924 if [ "yes" = "${nolabels}" ]
926 TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -l"
929 if [ "yes" = "${nobanner}" ]
931 TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -t /dev/null -b /dev/null"
934 if [ "${TERM}" = "PSR" ]
936 TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -r"
939 # Get rid of the #, TAB and NL characters in the title
940 tsol_title=`echo $title`
941 tsol_title=`echo $tsol_title | sed 's/#//g'`
943 LC_TIME=C ${LPTSOLSEPARATOR} ${TSOLSEPARATOR_OPTS} "${printer}" \
944 "${request_id}" "${user_name}" "${tsol_title}" "${file}"
945 echo $? > ${BANNER_EXIT_CODE}
949 bannerize=tsol_bannerize
951 if [ "yes" = "${nobanner}" -a "yes" = "${nolabels}" ]
956 if [ "${TERM}" != "PSR" -a "${TERM}" != "PS" ]
964 ## Initialize the physical printer (Part II)
965 ## Here we select the character set.
966 ## One could argue that this should be done before the banner is printed,
967 ## but we don't, to keep the banner page looking consistent for the
968 ## operator. You can move this code before the banner code if you
969 ## disagree. If you do, combine it with the other call to "internal_lpset"
970 ## to do everything in one shot.
972 internal_lpset "" "" "" "" "${CHARSET}"
976 ## Print some copies of the file(s)
981 # The protocol between the interface program and the Spooler
984 # All standard error output is assumed to indicate a
985 # fault WITH THE REQUEST. The output is mailed to the
986 # user who submitted the print request and the print
987 # request is finished.
989 # If the interface program sets a zero exit code,
990 # it is assumed that the file printed correctly.
991 # If the interface program sets a non-zero exit code
992 # less than 128, it is assumed that the file did not
993 # print correctly, and the user will be notified.
994 # In either case the print request is finished.
996 # If the interface program sets an exit code greater
997 # than 128, it is assumed that the file did not print
998 # because of a printer fault. If an alert isn't already
999 # active (see below) one will be activated. (Exit code
1000 # 128 should not be used at all. The shell, which executes
1001 # this program, turns SIGTERM, used to kill this program
1002 # for a cancellation or disabling, into exit 128. The
1003 # Spooler thus interpretes 128 as SIGTERM.)
1005 # A message sent to the standard input of the ${LPTELL}
1006 # program is assumed to describe a fault WITH THE PRINTER.
1007 # The output is used in an alert (if alerts are defined).
1008 # If the fault recovery is "wait" or "begin", the printer
1009 # is disabled (killing the interface program if need be),
1010 # and the print request is left on the queue.
1011 # If the fault recovery is "continue", the interface program
1012 # is allowed to wait for the printer fault to be cleared so
1013 # it can resume printing.
1015 # This interface program relies on filters to detect printer faults.
1016 # In absence of a filter provided by the customer, it uses a simple
1017 # filter (${LPCAT}) to detect the class of faults that cause DCD
1018 # (``carrier'') drop. The protocol between the interface program and
1021 # The filter should exit with zero if printing was
1022 # successful and non-zero if printing failed because
1023 # of a printer fault. This interface program turns a
1024 # non-zero exit of the filter into an "exit 129" from
1025 # itself, thus telling the Spooler that a printer fault
1028 # The filter should report printer faults via a message
1029 # to its standard error. This interface program takes all
1030 # standard error output from the filter and feeds it as
1031 # standard input to the ${LPTELL} program.
1033 # The filter should wait for a printer fault to clear,
1034 # and should resume printing when the fault clears.
1035 # Preferably it should resume at the top of the page
1036 # that was being printed when the fault occurred.
1037 # If it waits and finishes printing, it should exit
1038 # with a 0 exit code. If it can't wait, it should exit
1039 # with a non-zero exit code.
1041 # The interface program expects that ANY message on the
1042 # standard error from the filter indicates a printer fault.
1043 # Therefore, a filter should not put user (input) error
1044 # messages on the standard error, but on the standard output
1045 # (where the user can read them when he or she examines
1052 while [ $i -le $copies ]
1054 for file in ${files}
1060 # Here's where we set up the $LPTELL program to
1061 # capture fault messages, and...
1063 # Here's where we print the file.
1065 # We set up a pipeline to $LPTELL, but play a trick
1066 # to get the filter's standard ERROR piped instead of
1067 # its standard OUTPUT: Divert the standard error (#2) to
1068 # the standard output (#1) IN THE PIPELINE. The shell
1069 # will have changed #1 to be the pipe, not the
1070 # printer, so diverting #2 connects it to the pipe.
1071 # We then change the filter's #1 to a copy of the real
1072 # standard output (the printer port) made earlier,
1073 # so that is connected back to the printer again.
1075 # We do all this inside a parenthesized expression
1076 # so that we can get the exit code; this is necessary
1077 # because the exit code of a pipeline is the exit
1078 # code of the right-most command, which isn't the
1081 # These two tricks could be avoided by using a named
1082 # pipe to connect the standard error to $LPTELL. In
1083 # fact an early prototype of this script did just
1084 # that; however, the named pipe introduced a timing
1085 # problem. The processes that open a named pipe hang
1086 # until both ends of the pipe are opened. Cancelling
1087 # a request or disabling the printer often killed one
1088 # of the processes, causing the other process to hang
1089 # forever waiting for the other end of the pipe to
1092 EXIT_CODE=${TMPPREFIX}e
1093 trap '' 1 # Let the filter handle a hangup
1094 trap '' 2 3 # and interrupts
1097 # Put the 0<${file} before the "eval" to keep
1098 # clever users from giving a file name that
1099 # evaluates as something to execute.
1101 0<${file} $bannerize | eval ${FILTER} 2>&1 1>&3
1102 echo $? >${EXIT_CODE}
1103 ) | ${LPTELL} ${LPTELL_OPTS} ${printer}
1105 # if lp.tsol_separator had an error, send its logged
1106 # error message to LPTELL.
1107 banner_exit_code=`cat ${BANNER_EXIT_CODE}`
1108 if [ -n "${banner_exit_code}" -a \
1109 0 -ne "${banner_exit_code}" -a \
1111 -r "${TSOLSEPARATOR_LOG}" ]
1113 cat ${TSOLSEPARATOR_LOG} | ${LPTELL} ${printer}
1114 echo 77 > ${EXIT_CODE}
1117 trap 'catch_hangup; exit_code=129 exit 129' 1
1118 trap 'catch_interrupt; exit_code=129 exit 129' 2 3
1119 exit_code=`cat ${EXIT_CODE}`
1121 if [ -n "${exit_code}" -a 0 -ne "${exit_code}" ]
1123 trap '' 15 # Avoid dying from disable
1124 sleep 4 # Give $LPTELL a chance to tell
1128 if [ -n "${FF}" -a "no" = "${nofilebreak}" ]
1137 # Don't complain about not being able to read
1138 # a file on second and subsequent copies, unless
1139 # we've not complained yet. This removes repeated
1140 # messages about the same file yet reduces the
1141 # chance that the user can remove a file and not
1142 # know that we had trouble finding it.
1144 if [ "${i}" -le 1 -o -z "${badfileyet}" ]
1146 errmsg WARNING ${E_IP_BADFILE} \
1147 "cannot read file \"${file}\"" \
1148 "see if the file still exists and is readable,
1149 or consult your system administrator;
1161 # Skip this for TSOL, since lp.tsol_separator handles the banners
1163 # if [ "no" = "${nobanner}" -a "${TERM}" = "PSR" ]
1165 # ( eval "${banner} ${banner_filter}" 2>&1 1>&3 ) \
1166 # | ${LPTELL} ${LPTELL_OPTS} ${printer}
1169 if [ -n "${exit_code}" -a 0 -ne "${exit_code}" ]
1176 # Always ensure the complete job ends with a ``formfeed'', to
1177 # let the next job start on a new page. (If someone wants to
1178 # concatenate files, they can give them in one job.)
1179 # So, if we haven't been putting out a ``formfeed'' between files,
1180 # it means we haven't followed the last file with a formfeed,
1183 if [ -n "${FF}" -a "yes" = "${nofilebreak}" ]