📄 if-pcl3
字号:
w) width="$OPTARG";; *) echo "? $name"": Illegal option specification. The call was:" >&2 printf ' %s\n' "$*" >&2 exit 2;; esacdonetest 1 = "$OPTIND" || shift `expr $OPTIND - 1`# Deal with non-option argumentsif [ $# -gt 1 ]; then echo "? $name"": More than one non-option argument in the call:" >&2 printf ' %s\n' "$*" >&2 exit 2fiif [ $# -gt 0 ]; then accounting_file="$1"else accounting_file=fi# Starting here, any errors occurring are sent to the job's ownerif [ '' != "$user" ]; then notify_user="$user" test '' = "$host" || notify_host="$host"fi#******************************************************************************# Set up default values.# These are the parameters which can be redefined in the configuration file.# You might also have to use GS_OPTIONS, for example for the media type.GS=gsSUBDEVICE=unspecCOLOURMODEL=Gray # Americans note the "U"! Britons note the "a"! :-)RESOLUTION=QUALITY=normalPSCONFIGFILE=if-pcl3.psPAGECOUNTFILE=gs-pages.countINIT_TRANS=USE_INTERMEDIATE_FILE=yes# Default accounting: count the number of files printed or, if supported, the# number of pages.acct_start(){ test '' = "$PAGECOUNTFILE" -o ! -f "$PAGECOUNTFILE" || cat "$PAGECOUNTFILE" return}acct_stop(){ pages_before="$1" test '' != "$pages_before" || pages_before=0 if [ '' != "$PAGECOUNTFILE" -a -f "$PAGECOUNTFILE" ]; then pages_after=`cat "$PAGECOUNTFILE"` pages=`expr $pages_after - $pages_before` if [ '' = "$pages" -o 0 -ge "$pages" ]; then test 0 -ne "$rc" || echo "? $name"": Wrong value for number of pages" \ "printed: \`$pages'." >&2 pages=1 # count files instead fi else pages=1 # count files fi echo $pages return}#******************************************************************************# Read the configuration file for the filter if present in the spool directorytruecfg=if-pcl3.cfgtest ! -f $cfg -o ! -r $cfg || . ./$cfgtest $? -eq 0 || exit 2# RESOLUTION and PSCONFIGFILE must not contain field separatorsif expr "x$RESOLUTION$PSCONFIGFILE" : "x.*[$IFS]" > /dev/null; then printf '? %s: Shell field separator(s) in RESOLUTION (%s)\n' \ "$name" "$RESOLUTION" >&2 printf ' or PSCONFIGFILE (%s).\n' "$PSCONFIGFILE" >&2 exit 2fi#******************************************************************************# Initialize accountingLC_NUMERIC=C; export LC_NUMERICacct_saved=`acct_start`# stdin is the input file, stdout the printer.rc=0if [ '' = "$GS" ]; then # Transparent queue printf '\033E\033&k2G' # PCL: Printer Reset, Line Termination (LF -> CR+LF) test '' = "$INIT_TRANS" || printf "$INIT_TRANS" cat rc=$?else # An empty specifications for RESOLUTION means "use the default". test '' = "$RESOLUTION" || RESOLUTION="-r$RESOLUTION" # Remove the PostScript configuration file from the command line if it does # not exist or is not readable test '' != "$PSCONFIGFILE" -a -f "$PSCONFIGFILE" -a -r "$PSCONFIGFILE" || \ PSCONFIGFILE= # If PAGECOUNTFILE is non-empty, insert an option with it in the call. pcf_option= test '' = "$PAGECOUNTFILE" || pcf_option=-sPageCountFile="$PAGECOUNTFILE" # We have to pass the resulting PCL file to standard output. Unfortunately, # if one does this directly from ghostscript (via "-sOutputFile=-"), the # output can contain unwanted data: error messages and data written to what # is standard output for PostScript. (I consider this behaviour to be a bug # in gs.) The latter feature is for example used by some MS Windows drivers # for PostScript printers in order to report the current processing state # back to the host. # If we want neither error messages nor statements like "%%[ Page: 1 ]%%" to # be intermixed with what is to be printed, we have to create a file first # and copy it to stdout in a second step. This might require substantial disk # space. # Hence I provide both solutions. Choose the one you like best by setting # USE_INTERMEDIATE_FILE. if [ no = "$USE_INTERMEDIATE_FILE" ]; then # Directly to stdout, hoping that other data will not appear. However, # in order not to loose the error message text, the following command is # used to ensure that this output will be printed properly and in # particular without a "staircase effect" provided the error occurs on the # first page. # This is for example what happens if the input file is not PostScript. printf '\033E\033&k2G\033&s0C' # PCL: Printer Reset, Line Termination (LF -> CR+LF), End-of-Line-Wrap (ON). # Call ghostscript ${GS:-gs} -q -dNOPAUSE -dSAFER -sDEVICE=pcl3 -sSubdevice="$SUBDEVICE" \ -sColourModel="$COLOURMODEL" $RESOLUTION -sPrintQuality="$QUALITY" \ $pcf_option -sOutputFile=- $PSCONFIGFILE - rc=$? test 0 -eq $rc || \ printf '\n? %s: %s returned an exit code of %s.\n' "$name" "$GS" "$rc" >&2 else # Two-step process with an intermediate file tmp="${TMPDIR:-/tmp}/$$-2.tmp" rm -f "$tmp" # Call ghostscript, redirecting stdout to stderr. Note that permissible # output (e.g., from "=") will be redirected to stderr as well, hence # we can't use the size of the resulting file as the sole indication that # an error has occurred. prev_umask=`umask` umask 027 # Ensure privacy. The group should be lp. ${GS:-gs} -q -dNOPAUSE -dSAFER -sDEVICE=pcl3 -sSubdevice="$SUBDEVICE" \ -sColourModel="$COLOURMODEL" $RESOLUTION -sPrintQuality="$QUALITY" \ $pcf_option -sOutputFile="$tmp" $PSCONFIGFILE - >&2 rc=$? test 0 -eq $rc || \ printf '\n? %s: %s returned an exit code of %s.\n' "$name" "$GS" "$rc" >&2 umask "$prev_umask" # If an error occurred, don't bother printing. if [ 0 -eq $rc ]; then cat "$tmp" rc=$? test $rc -eq 0 || printf \ '? %s: Error copying the generated file to stdout.\n' "$name" >&2 fi rm -f "$tmp" fifi# Reset the printer to its default state. This also ejects any unfinished pages# which is needed if the transparent queue is used for printing ordinary text.# It is superfluous when printing with pcl3 because pcl3 generates this at the# end of its output already, but a second reset is harmless (unless the printer# knows more than one command language and PCL-3+ is not the default) and it# works even if gs crashes.printf '\033E' # PCL: Printer Reset# Terminate accountingpages=`acct_stop "$acct_saved"`# Exit on errortest 0 -eq $rc || exit 2#******************************************************************************# User-specific accounting on successif [ '' != "$accounting_file" ]; then printf '%7.2f\t%s:%s\n' "$pages" "$host" "$user" >> "$accounting_file"fi# Remove the trap for finish() in case the stderr log is non-empty although# everything worked.trap - 0 2exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -