xref: /illumos-gate/usr/src/cmd/lp/filter/slow.filter (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate
24*7c478bd9Sstevel@tonic-gate###########
25*7c478bd9Sstevel@tonic-gate##
26*7c478bd9Sstevel@tonic-gate## Simple shell script that saves the Spooler alot of headaches.
27*7c478bd9Sstevel@tonic-gate## This routine invokes a slow filter on each of the files in a
28*7c478bd9Sstevel@tonic-gate## user's print request, sending the output to separate files.
29*7c478bd9Sstevel@tonic-gate## The Spooler will take ANYTHING that goes to standard error
30*7c478bd9Sstevel@tonic-gate## and give it to the user. Non-empty standard error or non-zero
31*7c478bd9Sstevel@tonic-gate## exit code cause cancellation of the print request.
32*7c478bd9Sstevel@tonic-gate##
33*7c478bd9Sstevel@tonic-gate## Calling sequence:
34*7c478bd9Sstevel@tonic-gate##
35*7c478bd9Sstevel@tonic-gate##	slow.filter prefix file1 file2 ... fileN
36*7c478bd9Sstevel@tonic-gate##
37*7c478bd9Sstevel@tonic-gate## "prefix" is prefix of full path name for output files. All we
38*7c478bd9Sstevel@tonic-gate## do is append a ``-k'' for k = 1, 2, ..., N.
39*7c478bd9Sstevel@tonic-gate##########
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate#####
42*7c478bd9Sstevel@tonic-gate#
43*7c478bd9Sstevel@tonic-gate# Most of the time we don't want the standard error to be captured
44*7c478bd9Sstevel@tonic-gate# by the Spooler, mainly to avoid "Terminated" messages that the
45*7c478bd9Sstevel@tonic-gate# shell puts out when we get a SIGTERM. We'll save the standard
46*7c478bd9Sstevel@tonic-gate# error channel under another number, so we can use it when it
47*7c478bd9Sstevel@tonic-gate# should be captured.
48*7c478bd9Sstevel@tonic-gate#####
49*7c478bd9Sstevel@tonic-gateexec 5>&2 2>/dev/null
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate#####
52*7c478bd9Sstevel@tonic-gate# Error message formatter:
53*7c478bd9Sstevel@tonic-gate#
54*7c478bd9Sstevel@tonic-gate# Invoke as
55*7c478bd9Sstevel@tonic-gate#
56*7c478bd9Sstevel@tonic-gate#	errmsg severity message-number problem help
57*7c478bd9Sstevel@tonic-gate#
58*7c478bd9Sstevel@tonic-gate# where severity is "ERROR" or "WARNING", message-number is
59*7c478bd9Sstevel@tonic-gate# a unique identifier, problem is a short description of the
60*7c478bd9Sstevel@tonic-gate# problem, and help is a short suggestion for fixing the problem.
61*7c478bd9Sstevel@tonic-gate#####
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gateLP_ERR_LABEL="UX:lp"
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gateE_IP_ARGS=1
66*7c478bd9Sstevel@tonic-gateE_IP_OPTS=2
67*7c478bd9Sstevel@tonic-gateE_IP_FILTER=3
68*7c478bd9Sstevel@tonic-gateE_IP_STTY=4
69*7c478bd9Sstevel@tonic-gateE_IP_UNKNOWN=5
70*7c478bd9Sstevel@tonic-gateE_IP_BADFILE=6
71*7c478bd9Sstevel@tonic-gateE_IP_BADCHARSET=7
72*7c478bd9Sstevel@tonic-gateE_IP_BADCPI=8
73*7c478bd9Sstevel@tonic-gateE_IP_BADLPI=9
74*7c478bd9Sstevel@tonic-gateE_IP_BADWIDTH=10
75*7c478bd9Sstevel@tonic-gateE_IP_BADLENGTH=11
76*7c478bd9Sstevel@tonic-gateE_IP_ERRORS=12
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gateerrmsg () {
79*7c478bd9Sstevel@tonic-gate	case $1 in
80*7c478bd9Sstevel@tonic-gate	ERROR )
81*7c478bd9Sstevel@tonic-gate		sev="  ERROR";
82*7c478bd9Sstevel@tonic-gate		;;
83*7c478bd9Sstevel@tonic-gate	WARNING )
84*7c478bd9Sstevel@tonic-gate		sev="WARNING";
85*7c478bd9Sstevel@tonic-gate		;;
86*7c478bd9Sstevel@tonic-gate	esac
87*7c478bd9Sstevel@tonic-gate#	tag=`expr "${LP_ERR_LABEL}" : "\(.*\):"``expr "${LP_ERR_LABEL}" : ".*:\(.*\)"`
88*7c478bd9Sstevel@tonic-gate	echo "${LP_ERR_LABEL}: ${sev}: $3
89*7c478bd9Sstevel@tonic-gate        TO FIX: $4" >&5
90*7c478bd9Sstevel@tonic-gate}
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gateprefix=$1
93*7c478bd9Sstevel@tonic-gateshift
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gatek=1
96*7c478bd9Sstevel@tonic-gatefor file in "$@"
97*7c478bd9Sstevel@tonic-gatedo
98*7c478bd9Sstevel@tonic-gate	if [ ! -r "${file}" ]
99*7c478bd9Sstevel@tonic-gate	then
100*7c478bd9Sstevel@tonic-gate		errmsg ERROR ${E_IP_BADFILE} \
101*7c478bd9Sstevel@tonic-gate			"Cannot read the file \"${file}\"." \
102*7c478bd9Sstevel@tonic-gate			"See if it still exists and is readable, or
103*7c478bd9Sstevel@tonic-gate		consult your system administrator."
104*7c478bd9Sstevel@tonic-gate	else
105*7c478bd9Sstevel@tonic-gate		0<${file} 1>${prefix}-${k} eval "2>&5 ${FILTER}" || {
106*7c478bd9Sstevel@tonic-gate			exit_code=$?
107*7c478bd9Sstevel@tonic-gate			while [ 127 -lt "${exit_code}" ]
108*7c478bd9Sstevel@tonic-gate			do
109*7c478bd9Sstevel@tonic-gate				exit_code=`expr "${exit_code}" - 128`
110*7c478bd9Sstevel@tonic-gate			done
111*7c478bd9Sstevel@tonic-gate			exit ${exit_code}
112*7c478bd9Sstevel@tonic-gate		}
113*7c478bd9Sstevel@tonic-gate	fi
114*7c478bd9Sstevel@tonic-gate	k=`expr "${k}" + 1`
115*7c478bd9Sstevel@tonic-gatedone
116