"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "susefilter-1.5/apsfilter.script" of archive susefilter-1.5.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 #! /bin/bash
2 #
3 # apsfilter Line Printer Input Filter
4 # Version: @@version@@
5 #
6 # Copyright 1996-98 S.u.S.E. GmbH
7 # Author: Werner Fink <werner@suse.de>
8 #
9 # NOTE: You really NEED bash to run this script
10 #
11 # Heavily based on apsfilter-4.9
12
13 ## Copyright by Andreas Klemm <andreas@knobel.gun.de> 1993, 1994, 1995
14 ## co-author: Thomas Bueschgens <sledge@hammer.oche.de>
15 ##
16 ## You are permitted to modify and distribute apsfilter in the
17 ## terms of the GNU Public License (GPL) see below.
18 ##
19 ## For Unix Systems With BSD Alike Print Mechanism (lpd, /etc/printcap)
20 ##
21 ## Supports The Following File Types:
22 ##
23 ## Ascii, DVI, PS, Data (PCL,...), GIFF, TIFF, PBM,
24 ## Sun Raster, X11 Bitmap
25 ##
26 ## Supports The Following Compression Types:
27 ##
28 ## Compress, Gzip, Freeze
29 ##
30 ## and various contributors
31
32 #
33 # Avoid troubel with bash-2.0.x; hash shell functions; export variables.
34 # No core dump in our spool queues. Random key for accounting.
35 #
36 set +o posix
37 set -h
38 set -a
39 ulimit -c 0 2> /dev/null
40 declare -r key="$$:$RANDOM"
41
42 #
43 # Fore debugging --- see for stderr in /var/spool/.../log
44 # for output see under /tmp/ in aps_out.<num>
45 #
46 #set -x
47 #PRINT_TO_FILE="true"
48
49 #
50 # Using a remote Printer: The printer queue with the choosen name
51 # should be defined in /etc/printcap
52 # or a binary file with full path name.
53 #
54 #REMOTE_PRINTER="remote"
55
56 #
57 # Global environment
58 #
59 PATH=/bin:/usr/bin:/usr/local/bin
60 PATH=${PATH}:/usr/bin/TeX:/usr/X11R6/bin
61 PATH=${PATH}:/sbin:/usr/sbin
62 export PATH
63
64 NOTIFY=root
65 FAULTMSG="apsfilter: printer fault"
66 MAILX=mailx
67 XDOTS=0
68 YDOTS=0
69 SPOOL=/var/spool
70 APSFILTER=@@/var/lib/apsfilter@@
71 REWINDSTDIN=${APSFILTER}/rewindstdin
72 GIFTOPXM=giftopnm
73 SUNRAST=pnm
74
75 TMP_FILE=/tmp/aps.$$
76
77 #
78 # Ignore hangup, keyboard interrupt, quit from keyboard, and broken pipes.
79 # Other signals for abort and on exit we should remove our temp file
80 #
81 trap "echo" SIGHUP SIGINT SIGQUIT SIGPIPE
82 trap "rm -f $TMP_FILE" EXIT SIGTRAP SIGBUS SIGKILL SIGUSR1 SIGUSR2 SIGTERM
83
84 for d in /usr/lib/teTeX /usr/lib/texmf /usr/local/texmf /usr/lib/TeX \
85 /usr/local/TeX /usr/local/teTeX /usr/local/tetex /usr/teTeX \
86 /usr/TeX /usr/tex /usr/local/tex /usr/lib/tex
87 do
88 if [ -f $d/texmf.cnf ] ; then
89 : ${TETEXDIR="$d"}
90 break
91 fi
92 done
93 [ -n "$TETEXDIR" ] && export TETEXDIR
94
95 #
96 # Load some handler
97 #
98 . ${APSFILTER}/handler/functions
99
100 #
101 # Why not use the options given by lpd or plp (LPRng?)?
102 # Parse options given by the printer Daemon!
103 #
104 while getopts ":P:w:l:i:x:y:cN:S:Y:J:Z:C:R:n:h:F:" y ; do
105 case $y in
106 P) PRNAME="$OPTARG" ;; # Ignored
107 w) WIDTH="$OPTARG" ;; # Ignored
108 l) LENGTH="$OPTARG" ;; # Ignored
109 i) INDENT="$OPTARG" ;; # Ignored
110 x) XDOTS="$OPTARG" ;; # Ignored
111 y) YDOTS="$OPTARG" ;; # Ignored
112 c) LITERAL="true" ;; # Ignored
113 N) NAME="$OPTARG" ;; # Used if set
114 S) SCOMMENT="$OPTARG" ;; # Ignored
115 Y) CALLS="$OPTARG" ;; # Ignored
116 J) JOB="$OPTARG" ;; # Used if set
117 Z) ZOPTIONS="$OPTARG" ;; # Used if set
118 C) PRIORITY="$OPTARG" ;; # Ignored
119 R) RACCOUNT="$OPTARG" ;; # Ignored
120 n) PERSON="$OPTARG" ;; # Used if set
121 h) HOST="$OPTARG" ;; # Used if set
122 F) FILTER="$OPTARG" ;; # Used if set
123 *) ;; # Ignored
124 esac
125 done
126
127 eval y="\${$#}"
128 [ -n "$y" -a "$y" != "$0" ] && ACCTFILE="$y"
129 unset y
130
131 #
132 # Are there any Z options? Handel this
133 #
134 if [ -n "$ZOPTIONS" ]; then
135 for z in $(echo "$ZOPTIONS"|tr ',' ' '); do
136 case "$z" in
137 duplex=off) ZDUPLEX=off ;;
138 duplex=on) ZDUPLEX=on ;;
139 duplex=tumble) ZDUPLEX=tumble ;;
140 tray=[0-9]) ZTRAY=${z#tray=} ;;
141 feature=1) ZFEATURE=1 ;;
142 feature=2) ZFEATURE=2 ;;
143 feature=1n) ZFEATURE=1n ;;
144 feature=2n) ZFEATURE=2n ;;
145 feature=1l) ZFEATURE=1l ;;
146 feature=1ln) ZFEATURE=1ln ;;
147 *) ;; # Ignore
148 esac
149 done
150 fi
151
152 #
153 # if apsfilter is called as:
154 #
155 # djet500-a4-{auto,ascii,raw}-{color,mono}-dpi
156 # $1 $2 $3 $4 $5
157 # then we get printer type and papersize from the apsfilter call itself
158 # METHOD=auto enables filetype auto recognition
159 # METHOD=ascii force printing method print ascii
160 # METHOD=raw write to print device unfiltered ....
161 # COLOR=color use color-postscript
162 # COLOR=mono transform color to b&w postscript... so one is
163 # able to save colored pens on a colorprinter
164 # DPI=<NUM>x<NUM>
165 # DPI=<NUM> Resolution of the printer type
166 #
167 set -- `echo ${0##*/} | tr '-' ' '`
168
169 : ${compat="false"}
170 [ "$1" = "aps" ] && { shift; compat=true; }
171
172 PRINTER="$1"; PAPERSIZE="$2"; METHOD="$3"; COLOR="$4"; DPI="$5"
173
174 #
175 # Do we additional informations: look into cf file
176 # lpd will change into spool directory before locking
177 #
178 if [ -n "$PWD" -a -e "${PWD}/lock" ] ; then
179 LOCK="${PWD}/lock"
180 elif [ -n "${ACCTFILE}" -a -e "${ACCTFILE}" ] ; then
181 LOCK="${ACCTFILE%/*}/lock"
182 else
183 if [ "$compat" = "true" ] ; then
184 LOCK="${SPOOL}/${PRINTER}-${PAPERSIZE}-${METHOD}-${COLOR}/lock"
185 [ "$METHOD" = "raw" ] && LOCK="${SPOOL}/${PRINTER}-raw/lock"
186 else
187 LOCK="${SPOOL}/lpd/${PRINTER}-${PAPERSIZE}-${METHOD}-${COLOR}-${DPI}/lock"
188 [ "$METHOD" = "raw" ] && LOCK="${SPOOL}/lpd/${PRINTER}-${PAPERSIZE}-raw/lock"
189 fi
190 fi
191 CF=$(tail -1 ${LOCK})
192 #
193 # Now scan cf file, therefore the inode of the
194 # open file for standard in is useful.
195 #
196 set -- $(ls -L -i /dev/fd/0)
197 inodeofstdin=$1
198 declare -i count=0
199 declare -i nname=0
200 while read line ; do
201 case "$line" in
202 J*) : ${JOB="${line#?}"} ;; # Used if set
203 C*) : ${CLASS="${line#?}"} ;; # Ignored
204 D*) : ${UNKOWN="${line#?}"} ;; # Ignored
205 L*) : ${LPERSON="${line#?}"} ;; # Used if set
206 T*) : ${TITLE="${line#?}"} ;; # Used if set
207 H*) : ${HOST="${line#?}"} ;; # Used if set
208 P*) : ${PERSON="${line#?}"} ;; # Used if set
209 M*) : ${MAILTO="${line#?}"} ;; # Ignored
210 f*) set -- $(ls -L -i ${line#?})
211 count=$((count+1))
212 if [ $inodeofstdin -eq $1 ] ; then
213 : ${FMTFILE="${line#?}"} # Ignored
214 nname=$count
215 fi ;;
216 l*) : ${RAWFILE="${line#?}"} ;; # Ignored
217 p*) : ${PRFILE="${line#?}"} ;; # Ignored
218 t*) : ${TFFILE="${line#?}"} ;; # Ignored
219 d*) : ${DVIFILE="${line#?}"} ;; # Ignored
220 n*) : ${DITFILE="${line#?}"} ;; # Ignored
221 g*) : ${GRFILE="${line#?}"} ;; # Ignored
222 c*) : ${CIFFILE="${line#?}"} ;; # Ignored
223 v*) : ${IMGFILE="${line#?}"} ;; # Ignored
224 r*) : ${FORFILE="${line#?}"} ;; # Ignored
225 1*) : ${TFFONTR="${line#?}"} ;; # Ignored
226 2*) : ${TFFONTI="${line#?}"} ;; # Ignored
227 3*) : ${TFFONTB="${line#?}"} ;; # Ignored
228 4*) : ${TFFONTS="${line#?}"} ;; # Ignored
229 W*) : ${WIDTH="${line#?}"} ;; # Ignored
230 I*) : ${INDENT="${line#?}"} ;; # Ignored
231 U*) : ${SPOOLED="${line#?}"} ;; # Ignored
232 #
233 # Note that the first name wins if NAME is
234 # not set by the command line given by the lpd.
235 # The old BSD-lpd does not ... plp and LPRng
236 # does give the name of every sub printing job
237 # by command line. Now determine the right
238 # NAME out of the cf file for BSD case.
239 #
240 N*) if [ $count -eq $nname ] ; then
241 : ${NAME="${line#?}"} # Used if set
242 fi ;;
243 S*) : ${INODES="${line#?}"} ;; # Ignored
244 *) ;; # Ignored
245 esac
246 done < ${CF}
247 [ "$DPI" = "default" ] && DPI=""
248 [ -z "$NAME" ] && NAME="$JOB"
249 [ -n "$JOB" ] && FAULTMSG="$FAULTMSG during job $JOB"
250
251 #
252 # Users home dir ... check nis domain
253 # if there is a nis domain we will use yp interface
254 # Note: domainname gives NOT dns domain but nis domain,
255 # this is a common rule under UNIX[tm]!
256 #
257 YPD="`domainname`"
258 YPS="`grep -E '^\+' /etc/passwd|head -1c`"
259
260 if [ -n "$YPD" -a "$YPS" = "+" ] ; then
261 set -- `(cat /etc/passwd; ypcat passwd)|grep "^$PERSON:"|cut -d':' -f6`
262 else
263 set -- `grep "^$PERSON:" /etc/passwd |cut -d':' -f6`
264 fi
265 HOMEDIR="$1"
266
267 #
268 # The user should know what's happen
269 #
270 [ "$PERSON" != "$NOTIFY" ] && NOTIFY="-c $NOTIFY $PERSON"
271
272 #
273 # Now check first temporary files
274 #
275 rm -f $TMP_FILE
276 if [ -e $TMP_FILE ]; then
277 cat > /dev/console <<EOF
278 apsfilter:
279 Our temporary file $TMP_FILE already exists!
280 EOF
281
282 $MAILX -s "$" $NOTIFY 2> /dev/null <<EOF
283 apsfilter:
284 Our temporary file $TMP_FILE already exists!
285 EOF
286 exit 2
287 fi
288
289 #
290 # FILE TYPE AUTO_RECOGNITION
291 # first set output of the ``file'' command to new script arguments:
292 # $1, $2, ..., $n ; then throw away $1 and $2 since that is the
293 # "file name" = "standard input:" ; the rest is a "string" which
294 # consist of one or multiple words describing the file type.
295 # For example: "Korn Shell Script"
296 #
297 FILE_TYPE=""
298 HAVE_UNPACK=""
299 DECOMPRESS=""
300
301 set_type () { (grep -Ev '^$' 2>/dev/null |file - |tr 'A-Z' 'a-z'); }
302 #
303 # Reset stdin for security
304 #
305 $REWINDSTDIN
306 #
307 case $METHOD in
308 ascii|auto)
309 set -- `set_type; $REWINDSTDIN`
310 shift ; shift
311 FILE_TYPE="$*"
312 #
313 # check if we have to uncompress something
314 case "$FILE_TYPE" in
315 *gzip*) { . ${APSFILTER}/unpack/gzip ; } ;;
316 *compress*) { . ${APSFILTER}/unpack/compress ; } ;;
317 *frozen*) { . ${APSFILTER}/unpack/melt ; } ;;
318 *packed*) { . ${APSFILTER}/unpack/gzip ; } ;;
319 *) # it's not compressed !
320 esac ;;
321 *) # raw method: nothing to do
322 esac
323 #
324 # For method auto we want to known file type of contents
325 #
326 if [ -n "$HAVE_UNPACK" ] ; then
327 set_type () { ($HAVE_UNPACK|grep -Ev '^$' 2>/dev/null |file - |tr 'A-Z' 'a-z'); }
328 case $METHOD in
329 auto)
330 set -- `set_type; $REWINDSTDIN`
331 shift ; shift
332 FILE_TYPE="$*"
333 DECOMPRESS="eval $HAVE_UNPACK|" ;;
334 *)
335 DECOMPRESS="eval $HAVE_UNPACK|" ;;
336 esac
337 fi
338
339 #
340 # No color in ascii method!
341 #
342 [ "$METHOD" = "ascii" ] && COLOR="mono"
343 case $COLOR in
344 color) # color-mode! set some options so color makes it to
345 # the postscript-printer!
346 RAS2PS_OPTS="-C"
347 DJPEG_OPTS="-colors 256"
348 ;;
349 *) # mono-printer or mono-mode
350 # Unset all color-dependent flags
351 ## Does not work with all gs drivers
352 ## GS_FEATURES="-dBitsPerPixel=1"
353 DJPEG_OPTS="-grayscale"
354 ;;
355 esac
356
357 #
358 # Set some useful(?) defaults for printing and then read
359 # the systemwide resource file /etc/apsfilterrc
360 #
361 [ "$REMOTE_PRINTER" = "true" ] && REMOTE_PRINTER="remote"
362 DVIPS_MODE=""
363 GS_RESOL="$DPI"
364 [ "$compat" = "true" ] && GS_RESOL=""
365
366 #
367 # Usefull settings for raw printing, e.g. LF -> CR+LF
368 #
369 case $PRINTER in
370 cdj*|*desk*|[dl]jet*|laserjet|lj4*|dnj*|paintjet|pj*)
371 #Translate LF to CR+LF and FF to CR+FF
372 CRLF='\033&k2G'
373 # Perforation Skip Mode off (DIN A4: 66 lines/page)
374 SKIPOFF='\033&l0L'
375 PRINT_RAW_SETUP_PRINTER="${CRLF}${SKIPOFF}"
376 ;;
377 *)
378 # Anybody knows some good initialisation for some
379 # printers ?
380 PRINT_RAW_SETUP_PRINTER=""
381 ;;
382 esac
383
384 #
385 # Here we are: the systemwide resource file
386 # Note: Maybe we need some special setups for special printers.
387 # Therefore a /etc/apsfilterrc.${PRINTER} is useful!?
388 #
389 [ -f /etc/apsfilterrc ] && { . /etc/apsfilterrc ; }
390 [ -f /etc/apsfilterrc.${PRINTER} ] && { . /etc/apsfilterrc.${PRINTER} ; }
391
392 #
393 # The user apsfilterrc setup ... parsing and reading only allowed syntax
394 #
395 userrc=$HOMEDIR/.apsfilterrc
396 if [ -n "$HOMEDIR" -a -r $userrc ] ; then
397 #
398 # We only allow this few VARIABLES in user space
399 #
400 allowed="TEXINPUTS|PRINT_DVI|GS_FEATURES|USE_RECODE_NOT_A2PS"
401 allowed="$allowed|FEATURE|A2PS_OPTS|DVIPS_MODE|GS_RESOL|PRELOADS"
402
403 #
404 # $badchar contains the forbidden characters ... those
405 # maybe break this script or fore instance make it insecure
406 # notation is given in manual ascii(7)
407 #
408 badchar="$(echo -e ' \000\003\b\t\n\r\033')"
409 extract=$(grep -E "^($allowed)\=[^$badchar]+$" $userrc)
410
411 for line in $extract; do
412 eval "$line"
413 done
414 unset badchar extract line allowed
415 fi
416 unset userrc
417
418 #
419 # Overwrite FEATURE if we are called with the Z option feature={1,2,1n,2n,1l,1ln}
420 #
421 [ -n "$ZFEATURE" ] && FEATURE="$ZFEATURE"
422
423 #
424 # If TEXINPUTS is set we have to export it
425 #
426 if [ -n "$TEXINPUTS" ] ; then
427 [ -n "${TEXINPUTS#*:}" ] && TEXINPUTS=${TEXINPUTS}:
428 export TEXINPUTS
429 fi
430 #
431 # Make dvips happy
432 #
433 if [ -n "$TETEXDIR" ] ; then
434 TEXPICTS=""
435 [ -n "$TEXINPUTS" ] && TEXPICTS=${TEXINPUTS#*:}
436 TEXPICTS=${TEXPICTS}:${TETEXDIR}/texmf/doc//:/usr/doc/Books//:
437 export TEXPICTS
438 fi
439
440 #
441 # Options for dvips
442 #
443 # -M Don't create fonts automatically using MakeTeXPK
444 # since there is a bug in it causing apsfilter to exit
445 # after creating the first missing Font.
446 # -q Quiet mode
447 # -r Print last page first
448 # -t <papertype> Have a look into /usr/lib/teTeX/texmf/dvips/config.ps
449 # And use command texconfig for default
450 # -D <num> Horizontal and vertical resolution in dpi
451 # -P <name> Alternated config file
452 # /usr/lib/teTeX/texmf/dvips/config.<name>
453 # -X <num> Horizontal resolution in dpi
454 # -Y <num> Vertical resolution in dpi
455 # -Z Compress bitmap fonts
456 #
457
458 setres ()
459 {
460 # $1 is default resolution
461 # ignore this one if it is given by our link name
462 if [ -n "$GS_RESOL" ]; then
463 shift; set -- $GS_RESOL $@
464 fi
465 RES="-D $1"
466 [ ${1%x*} -ne ${1#*x} ] && RES="-D ${1%x*} -X ${1%x*} -Y ${1#*x}"
467 shift
468 RES="$RES $@"
469 }
470
471 case $PRINTER in
472 PS_*dpi)
473 r="${PRINTER#PS_}" ; r="${r%dpi}" ; setres $r
474 [ `echo $r|grep -cE '^([0-9]+|[0-9]+x[0-9]+)$'` -eq 0 ] && setres 300
475 [ -n "$DPI" ] && setres $DPI
476 ;;
477 PS_*) setres 300 ;;
478 cdj*|*desk*|djet*) setres 300 -r ;;
479 dnj*c) setres 300 -r ;;
480 hpdj) setres 300 -r ;;
481 ljet4l) setres 300 ;;
482 ljet4) setres 600 ;;
483 lj4dith) setres 600 ;;
484 laserjet|ljet[23]*) setres 300 ;;
485 paintjet|pj*) setres 300 ;;
486 necp6) setres 360 ;;
487 bj10e|bj200|bjc[68]00) setres 360 -r ;;
488 stcolor|st800) setres 360 -r ;;
489 eps9*) setres 240x216 -r ;;
490 epson) setres 360x180 -r ;;
491 epsonc) setres 360x180 -r ;;
492 *\.upp) setres 300 -r ;;
493 ppa1000|ppa[87]20) setres 600 -r ;;
494 *) setres 300 -r ;;
495 esac
496
497 #
498 # The light version of ljet4 acts like a ljet4 at 300dpi
499 #
500 [ "$PRINTER" = "ljet4l" ] && PRINTER=ljet4
501
502 #
503 # Quiet (-q) and compresssed fonts (-Z) set to default
504 #
505 DVIPS_OPTS="-q -Z $DVIPS_MODE $RES"
506 case $PAPERSIZE in
507 letter|legal|ledger) DVIPS_OPTS="$DVIPS_OPTS -t $PAPERSIZE" ;;
508 tabloid|11x17) DVIPS_OPTS="$DVIPS_OPTS -t Tabloid" ;;
509 a3) DVIPS_OPTS="$DVIPS_OPTS -t A3" ;;
510 a4) DVIPS_OPTS="$DVIPS_OPTS -t A4" ;;
511 *) DVIPS_OPTS="$DVIPS_OPTS -t Letter" ;;
512 esac
513 [ "$PAPERSIZE" = "tabloid" ] && PAPERSIZE=11x17
514
515 #
516 # Remote printer:
517 # We handel file types local an put the result to a remote queue.
518 # Therefore we test if `remote' is set _and_ if the requested
519 # remote queue is available.
520 #
521 # First set default to local (for using named pipes, which allows
522 # us to split ghostscript messages from ghostscript results).
523 #
524 PRINT_RAW="cat - "
525 bypass=0
526 #
527 [ "$REMOTE_PRINTER" = "true" ] && REMOTE_PRINTER="remote"
528 if [ -n "$REMOTE_PRINTER" ] ; then
529 #
530 # Handle remote queue or script/programm which is given
531 # with its full patch name and some arguments.
532 #
533 case "$REMOTE_PRINTER" in
534 /*) #
535 # A programm or script which should handle the stream
536 #
537 set -- $REMOTE_PRINTER
538 findfilter $1 DUMMY
539 bypass=1
540 PRINT_RAW="$@"
541 ;;
542 *) #
543 # Queue for a remote printer or printer server
544 #
545 bypass=$(grep -cE "^$REMOTE_PRINTER(\||:)" /etc/printcap)
546 if [ $bypass -ge 1 ] ; then
547 LPR_OPTIONS="-P$REMOTE_PRINTER"
548 LPR_NAME=""
549 # Not supported by old bsd lpr
550 #[ -n "$RACCOUNT" ] && LPR_OPTIONS="$LPR_OPTIONS -R$RACCOUNT"
551 [ -n "$JOB" ] && LPR_OPTIONS="$LPR_OPTIONS -J '$JOB'"
552 [ -n "$NAME" ] && LPR_NAME="-T '$NAME'"
553 [ -n "$TITLE" ] && LPR_NAME="-T '$TITLE'"
554 LPR_OPTIONS="$LPR_OPTIONS $LPR_NAME"
555 # Some plp lprs do not change uid if we are user lp
556 [ ! -e /etc/plp.conf -a \
557 -n "$PERSON" ] && LPR_OPTIONS="$LPR_OPTIONS -U '$PERSON'"
558 PRINT_RAW="lpr $LPR_OPTIONS"
559 fi
560 ;;
561 esac
562 fi
563
564 #
565 # Now let's see how to print PostScript
566 #
567 case $PRINTER in
568 PS_*)
569 # our printer is a PS printer...
570 PRINT_PS="$PRINT_RAW"
571 #
572 PS_PRELOADS=""
573 for pre in ${PRELOADS}; do
574 if [ -r "${APSFILTER}/preloads/$pre" ]; then
575 PS_PRELOADS="$PS_PRELOADS ${APSFILTER}/preloads/$pre"
576 elif [ -r "$pre" ]; then
577 PS_PRELOADS="$PS_PRELOADS $pre"
578 fi
579 done
580 [ -n "${PS_PRELOADS}" ] && PS_PRELOADS="$(cat $PS_PRELOADS|grep -v '^%!')"
581 #
582 download=""
583 if [ -n "$ZDUPLEX" -o -n "$ZTRAY" ] ; then
584 . ${APSFILTER}/handler/psheads
585 [ "$ZDUPLEX" = on ] && download="${duplexon}\\n${tumbleoff}"
586 [ "$ZDUPLEX" = tumble ] && download="${duplexon}\\n${tumbleon}"
587 [ "$ZDUPLEX" = off ] && download="${duplexoff}"
588 [ -n "$ZTRAY" ] && download="${download}\\n${settray}"
589 fi
590 #
591 if [ -n "$download" -o -n "${PS_PRELOADS}" ] ; then
592 PRINT_PS="\
593 (read first; echo \"\$first\";\
594 echo -e \"${beginsec}\";\
595 echo -e \"${PS_PRELOADS}\";\
596 echo -e \"${download}\";\
597 echo -e \"${endsec}\";\
598 cat - ) > >($PRINT_RAW)"
599 fi
600 ;;
601 *) # we have a nice non ps printer
602 findfilter gs GS
603 [ -n "$GS_RESOL" ] && GS_RESOL="-r${GS_RESOL}"
604 OUTPIPE="$PRINT_RAW"
605 case $PRINTER in
606 *\.upp) # PRINTER = option file (e.g. unified printer driver)
607 # Note: A resolution in the option file overwrites
608 # the given resolution. This is a `must be'.
609 HAVE_GS="$HAVE_GS ${GS_RESOL} @${PRINTER}"
610 ;;
611 ppa1000|ppa[87]20)
612 # PRINTER = pbm ghostscript device
613 # + post filter pbm2ppa
614 #
615 HAVE_GS="$HAVE_GS -sDEVICE=pbm ${GS_RESOL}"
616 #
617 findfilter pbm2ppa PBMTOPPA
618 OUTPIPE="$HAVE_PBMTOPPA -v ${PRINTER#ppa}"
619 [ $bypass -ge 1 ] && $OUTPIPE="$OUTPIPE|$PRINT_RAW"
620 #
621 ;;
622 *) # PRINTER = ghostscript device
623 HAVE_GS="$HAVE_GS -sDEVICE=${PRINTER} ${GS_RESOL}"
624 ;;
625 esac
626 #
627 # Some X11 PostScript fonts
628 #
629 if [ -d /usr/X11R6/lib/X11/fonts/Type1 ] ; then
630 GS_FONTPATH=/usr/X11R6/lib/X11/fonts/Type1
631 fi
632 #
633 # gs4.03 has max mem size of 65k, default for unix is 50k.
634 #
635 GS_OPTIONS=""
636 if [ "$(uname -s)" = "Linux" ] ; then
637 set -- $(cat /proc/meminfo| grep -E '^MemTotal:')
638 mem="$2"
639 gs_mem=32
640 [ $mem -gt 7750 ] && gs_mem=48
641 [ $mem -gt 15500 ] && gs_mem=65
642 [ $mem -gt 31000 ] && gs_mem=82
643 [ $mem -gt 62000 ] && gs_mem=98
644 GS_OPTIONS="-M${gs_mem}"
645 unset mem gs_mem
646 fi
647 #
648 # Common options
649 GS_OPTIONS="${GS_OPTIONS} -q -dQUIET -dNOPAUSE -dBATCH -dSAFER -dSHORTERRORS"
650 #
651 # Preloads
652 GS_LIB=${APSFILTER}/preloads
653 #
654 export GS_OPTIONS GS_LIB GS_FONTPATH
655 #
656 GS_PRELOADS=""
657 for pre in ${PRELOADS}; do
658 if [ -r "${APSFILTER}/preloads/$pre" ]; then
659 PS_PRELOADS="$PS_PRELOADS ${APSFILTER}/preloads/$pre"
660 elif [ -r "$pre" ]; then
661 PS_PRELOADS="$PS_PRELOADS $pre"
662 fi
663 done
664 #
665 # Accounting for and with gs
666 # Note: plp or LPRng do their own (wrong: page always 1) accounting
667 # therefore `la@' should be set in /etc/printcap
668 DOEND="-c quit"
669 if [ "$DO_ACCOUNTING" = "yes" -a -w ${ACCTFILE=acct} ] ; then
670 acc_page="currentdevice /PageCount gsgetdeviceprop"
671 # acc_file is defined in handler/functions
672 DOEND="-c \"($key:) print $acc_page == flush quit\"|acc_file"
673 fi
674 #
675 # Note: standard out is fd 3 (done by lpd), therefore `>(cat -)' works here.
676 #
677 PRINT_PS="$HAVE_GS -sPAPERSIZE=${PAPERSIZE} ${GS_FEATURES} \
678 -sOutputFile=>($OUTPIPE) ${GS_PRELOADS} - ${DOEND} 1>&2"
679 ;;
680 esac
681
682 #
683 # Debugging: Overwrite all print commands
684 #
685 if [ "$PRINT_TO_FILE" = "true" ] ; then
686 rm -f /tmp/aps_out.$$
687 [ -e /tmp/aps_out.$$ ] && exit 2
688 PRINT_PS="(cat 1> /tmp/aps_out.$$)"
689 PRINT_RAW="(cat 1> /tmp/aps_out.$$)"
690 fi
691
692 #
693 # And now ... we choose a method
694 #
695 case $METHOD in
696 raw) { . $APSFILTER/filter/raw ; } ;;
697 ascii) { . $APSFILTER/filter/ascii ; } ;;
698 auto)
699 #
700 # Maybe we should do this dynamical
701 # for f in $APSFILTER/filter/* ; do ... done
702 #
703 case "$FILE_TYPE" in
704 *fig*image*text*)
705 { . $APSFILTER/filter/fig ; } ;;
706 *pc*bitmap*data*)
707 { . $APSFILTER/filter/bmp ; } ;;
708 *tiff*image*data*)
709 { . $APSFILTER/filter/tiff ; } ;;
710 *gif*image*data*)
711 { . $APSFILTER/filter/gif ; } ;;
712 *jpeg*image*data*)
713 { . $APSFILTER/filter/jpeg ; } ;;
714 *pgm*|*pbm*|*ppm*)
715 { . $APSFILTER/filter/pnm ; } ;;
716 *sun*raster*image*data*)
717 { . $APSFILTER/filter/sunraster ; } ;;
718 postscript*)
719 { . $APSFILTER/filter/postscript ; } ;;
720 *pdf*document*)
721 { . $APSFILTER/filter/pdf ; } ;;
722 *tex*dvi*file*)
723 { . $APSFILTER/filter/dvi ; } ;;
724 *raw*g3*data*|*group*3*fax*)
725 { . $APSFILTER/filter/g3 ; } ;;
726 *data*|*escape*|*pcl*|*pjl*|*printer*job*language*)
727 # that's certainly not critical,
728 # you're on your own ;-)
729 { . $APSFILTER/filter/data ; } ;;
730 *troff*preprocessor*)
731 { . $APSFILTER/filter/troff ; } ;;
732 *ascii*|*text*|*english*|*script*)
733 { . $APSFILTER/filter/ascii ; } ;;
734 *)
735 # data we - I'm so sorry - don't know
736 fault_filetype
737 exit 2 ;;
738 esac ;;
739 *)
740 fault_method
741 exit 2 ;;
742 esac
743 $REWINDSTDIN
744
745 #
746 # Just do it
747 #
748 print_stdin
749
750 #
751 # Puh ... done
752 #
753 exit 0