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