view usr/src/cmd/lp/filter/slow.filter @ 0:c9caec207d52 b86

Initial porting based on b86
author Koji Uno <koji.uno@sun.com>
date Tue, 02 Jun 2009 18:56:50 +0900
parents
children 1a15d5aaf794
line wrap: on
line source

#ident	"@(#)slow.filter	1.3	05/06/08 SMI"	/* SVr4.0 1.7	*/
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

###########
##
## Simple shell script that saves the Spooler alot of headaches.
## This routine invokes a slow filter on each of the files in a
## user's print request, sending the output to separate files.
## The Spooler will take ANYTHING that goes to standard error
## and give it to the user. Non-empty standard error or non-zero
## exit code cause cancellation of the print request.
##
## Calling sequence:
##
##	slow.filter prefix file1 file2 ... fileN
##
## "prefix" is prefix of full path name for output files. All we
## do is append a ``-k'' for k = 1, 2, ..., N.
##########

#####
#
# Most of the time we don't want the standard error to be captured
# by the Spooler, mainly to avoid "Terminated" messages that the
# shell puts out when we get a SIGTERM. We'll save the standard
# error channel under another number, so we can use it when it
# should be captured.
#####
exec 5>&2 2>/dev/null

#####
# Error message formatter:
#
# Invoke as
#
#	errmsg severity message-number problem help
#
# where severity is "ERROR" or "WARNING", message-number is
# a unique identifier, problem is a short description of the
# problem, and help is a short suggestion for fixing the problem.
#####

LP_ERR_LABEL="UX:lp"

E_IP_ARGS=1
E_IP_OPTS=2
E_IP_FILTER=3
E_IP_STTY=4
E_IP_UNKNOWN=5
E_IP_BADFILE=6
E_IP_BADCHARSET=7
E_IP_BADCPI=8
E_IP_BADLPI=9
E_IP_BADWIDTH=10
E_IP_BADLENGTH=11
E_IP_ERRORS=12

errmsg () {
	case $1 in
	ERROR )
		sev="  ERROR";
		;;
	WARNING )
		sev="WARNING";
		;;
	esac
#	tag=`expr "${LP_ERR_LABEL}" : "\(.*\):"``expr "${LP_ERR_LABEL}" : ".*:\(.*\)"`
	echo "${LP_ERR_LABEL}: ${sev}: $3
        TO FIX: $4" >&5
}

prefix=$1
shift

k=1
for file in "$@"
do
	if [ ! -r "${file}" ]
	then
		errmsg ERROR ${E_IP_BADFILE} \
			"Cannot read the file \"${file}\"." \
			"See if it still exists and is readable, or
		consult your system administrator."
	else
		0<${file} 1>${prefix}-${k} eval "2>&5 ${FILTER}" || {
			exit_code=$?
			while [ 127 -lt "${exit_code}" ]
			do
				exit_code=`expr "${exit_code}" - 128`
			done
			exit ${exit_code}
		}
	fi
	k=`expr "${k}" + 1`
done