1 | #!/bin/sh
|
---|
2 | # $Id: unix-lpr.sh 6300 2005-12-28 19:56:24Z giles $
|
---|
3 | #
|
---|
4 | # Unix lpr filter. The default setup sends output directly to a pipe,
|
---|
5 | # which requires the Ghostscript process to fork, and thus may cause
|
---|
6 | # small systems to run out of memory/swap space. An alternative strategy,
|
---|
7 | # based on a suggestion by Andy Fyfe ([email protected]), uses a named
|
---|
8 | # pipe for output, which avoids the fork and can thus save a lot of memory.
|
---|
9 | #
|
---|
10 | # Unfortunately this approach can cause problems when a print job is aborted,
|
---|
11 | # as the abort can cause one of the processes to die, leaving the process
|
---|
12 | # at the other end of the pipe hanging forever.
|
---|
13 | #
|
---|
14 | # Because of this, the named pipe method has not been made the default,
|
---|
15 | # but it may be restored by commenting out the lines referring to
|
---|
16 | # 'gsoutput' and uncommenting the lines referring to 'gspipe'.
|
---|
17 | #
|
---|
18 |
|
---|
19 | # This definition is changed on install to match the
|
---|
20 | # executable name set in the makefile
|
---|
21 | GS_EXECUTABLE=gs
|
---|
22 |
|
---|
23 | PBMPLUSPATH=/usr/local/bin
|
---|
24 | PSFILTERPATH=/usr/local/lib/ghostscript
|
---|
25 | LOCALPATH=/usr/local/bin
|
---|
26 | X11HOME=/usr/X11R6
|
---|
27 |
|
---|
28 | PATH=/bin:/usr/bin:/usr/ucb:/usr/etc
|
---|
29 | PATH=${PATH}\:${LOCALPATH}\:${PBMPLUSPATH}\:${PSFILTERPATH}
|
---|
30 | LD_LIBRARY_PATH=${X11HOME}/lib
|
---|
31 |
|
---|
32 | export PATH LD_LIBRARY_PATH acctfile host user
|
---|
33 |
|
---|
34 | user= host= acctfile=/dev/null
|
---|
35 |
|
---|
36 | #
|
---|
37 | # Redirect stdout to stderr (for the logfile) and open a new channel
|
---|
38 | # connected to stdout for the raw data. This enables us to keep the
|
---|
39 | # raw data separate from programmed postscript output and error messages.
|
---|
40 | #
|
---|
41 | exec 3>&1 1>&2
|
---|
42 |
|
---|
43 | #
|
---|
44 | # Get username and hostname from filter parameters
|
---|
45 | #
|
---|
46 | while [ $# != 0 ]
|
---|
47 | do case "$1" in
|
---|
48 | -n) user=$2 ; shift ;;
|
---|
49 | -h) host=$2 ; shift ;;
|
---|
50 | -*) ;;
|
---|
51 | *) acctfile=$1 ;;
|
---|
52 | esac
|
---|
53 | shift
|
---|
54 | done
|
---|
55 |
|
---|
56 | #
|
---|
57 | # Get the filter, printer device and queue type (direct/indirect)
|
---|
58 | #
|
---|
59 | filter=`basename $0`
|
---|
60 | device=`dirname $0`
|
---|
61 | type=`dirname ${device}`
|
---|
62 | device=`basename ${device}`
|
---|
63 | fdevname=$device
|
---|
64 | type=`basename ${type}`
|
---|
65 |
|
---|
66 | #
|
---|
67 | # Find the bpp and number of colors, if specified
|
---|
68 | #
|
---|
69 |
|
---|
70 | colorspec="`echo ${device} | sed 's/.*\.[0-9][0-9]*\.\([0-9][0-9]*\)$/\1/'`"
|
---|
71 | if test "$colorspec" = "${device}"
|
---|
72 | then
|
---|
73 | colorspec=""
|
---|
74 | else
|
---|
75 | device=`basename ${device} .$colorspec`
|
---|
76 | colorspec="-dColors=$colorspec"
|
---|
77 | fi
|
---|
78 |
|
---|
79 | bpp="`echo ${device} | sed 's/.*\.\([0-9][0-9]*\)$/\1/'`"
|
---|
80 | if test "$bpp" = "${device}"
|
---|
81 | then
|
---|
82 | bpp=1
|
---|
83 | else
|
---|
84 | device=`basename ${device} .$bpp`
|
---|
85 | fi
|
---|
86 |
|
---|
87 | #
|
---|
88 | # Information for the logfile
|
---|
89 | #
|
---|
90 | lock=`dirname ${acctfile}`/lock
|
---|
91 | cf=`sed -n '$p' ${lock}`
|
---|
92 | job=`sed -n 's/^J//p' ${cf}`
|
---|
93 |
|
---|
94 | echo "gsbanner: ${host}:${user} Job: ${job} Date: `date`"
|
---|
95 | echo "gsif: ${host}:${user} ${fdevname} start - `date`"
|
---|
96 |
|
---|
97 | #
|
---|
98 | # Set the direct or indirect output destinations
|
---|
99 | #
|
---|
100 | #gspipe=/tmp/gspipe.$$
|
---|
101 | #mknod ${gspipe} p
|
---|
102 |
|
---|
103 | case "${type}" in
|
---|
104 | direct)
|
---|
105 | gsoutput="cat 1>&3" ;;
|
---|
106 | # cat ${gspipe} 1>&3 & ;;
|
---|
107 | indirect)
|
---|
108 | gsoutput="lpr -P${device}.raw" ;;
|
---|
109 | # cat ${gspipe} | lpr -P${device}.raw & ;;
|
---|
110 | esac
|
---|
111 |
|
---|
112 | (
|
---|
113 | #
|
---|
114 | # Any setup required may be done here (eg. setting gamma for colour printing)
|
---|
115 | #
|
---|
116 | #echo "{0.333 exp} dup dup currenttransfer setcolortransfer"
|
---|
117 |
|
---|
118 | #
|
---|
119 | # The input data is filtered here, before being passed on to Ghostscript
|
---|
120 | #
|
---|
121 | case "${filter}" in
|
---|
122 | gsif) cat ;;
|
---|
123 | gsnf) psdit ;;
|
---|
124 | gstf) pscat ;;
|
---|
125 | gsgf) psplot ;;
|
---|
126 | gsvf) rasttopnm | pnmtops ;;
|
---|
127 | gsdf) dvi2ps -sqlw ;;
|
---|
128 | gscf|gsrf) echo "${filter}: filter not available" 1>&2 ; exit 0 ;;
|
---|
129 | esac
|
---|
130 |
|
---|
131 | #
|
---|
132 | # This is the postlude which does the accounting
|
---|
133 | #
|
---|
134 | echo "\
|
---|
135 | (acctfile) getenv
|
---|
136 | { currentdevice /PageCount gsgetdeviceprop dup cvi 0 gt
|
---|
137 | { exch (a) file /acctfile exch def
|
---|
138 | /string 20 string def
|
---|
139 | string cvs dup length dup
|
---|
140 | 4 lt
|
---|
141 | { 4 exch sub
|
---|
142 | { acctfile ( ) writestring } repeat
|
---|
143 | } { pop } ifelse
|
---|
144 | acctfile exch writestring
|
---|
145 | acctfile (.00 ) writestring
|
---|
146 | acctfile (host) getenv
|
---|
147 | { string cvs } { (NOHOST) } ifelse writestring
|
---|
148 | acctfile (:) writestring
|
---|
149 | acctfile (user) getenv
|
---|
150 | { string cvs } { (NOUSER) } ifelse writestring
|
---|
151 | acctfile (\n) writestring
|
---|
152 | acctfile closefile
|
---|
153 | } { pop } ifelse
|
---|
154 | } if
|
---|
155 | quit"
|
---|
156 | ) | $GS_EXECUTABLE -q -dNOPAUSE -sDEVICE=${device} \
|
---|
157 | -dBitsPerPixel=${bpp} $colorspec \
|
---|
158 | -sOutputFile=\|"${gsoutput}" -
|
---|
159 | # -sOutputFile=${gspipe} -
|
---|
160 |
|
---|
161 | rm -f ${gspipe}
|
---|
162 | #
|
---|
163 | # End the logfile entry
|
---|
164 | #
|
---|
165 | echo "gsif: end - `date`"
|
---|
166 |
|
---|