2 # lp - enqueues the file to be printed and starts the daemon, when necessary.
3 # Make changes to /sys/src/cmd/lp/lp.rc;
4 # changes made directly to /rc/bin/lp will be lost.
6 rfork en # so that environment and name space are not polluted
8 # put 'fn sigexit { rm /tmp/lpcrap; exit interrupted }' into processes that create /tmp/lpcrap.
11 ' # set ifs in case it is munged in user's environment
13 LPLIB=/sys/lib/lp # lp scripts directories and configuration file are here
14 LPBIN=/$cputype/bin/aux # lp specific binaries are here
15 LPSPOOL=$LPLIB/queue # lp queues
16 LPLOGDIR=$LPLIB/log # lp logs
22 # build /bin from the ground up
23 bind /$cputype/bin /bin # general compiled binaries
24 bind -a /rc/bin /bin # general rc scripts
25 # This needs to be fixed for the real thing
26 bind -a $LPLIB/bin /bin # lp specific rc scripts
27 bind -a $LPBIN /bin # lp specific compiled binaries
30 USAGE='usage: lp [-d printer] [-p process] [options] [files]
32 lp [-d printer] -k jobnos
35 -D turn on debugging output
38 -M<mach> print on machine <mach>
39 -Q put task only into the queue
40 -R restart printer daemon
42 -f<font.size> specify font and size
43 -i<src> take media from <src> input bin
44 -l<n> print <n> lines per logical page
45 -m<n> magnify <n> times
46 -n<n> print <n> logical pages per physical page
47 -o<i-j,k> print only pages i-j and k
49 -u<userid> print as <userid>
50 -x<n> x page offset in inches
51 -y<n> y page offset in inches
54 # umask 000 # this doesn't work in plan 9
58 THIS_HOST=`{ndb/query sys $sysname dom}
68 # Set default printer to be output device
69 if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
92 flagfmt='D,H,L,Q,R,r,q,M mach,c copies,d printer,f font.size,i src,k jobnos,l lines,m magnify,n lpages,o pages,p proc,u userid,x offset,y offset'
95 if(! ifs=() eval `{aux/getflags $*}) {
100 awk 'BEGIN {print "device location host class"}
101 /^[^#]/ { printf "%-12s %-9s %-22s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
109 if (! ~ $#flagD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - }
110 if (! ~ $#flagH 0) NOHEAD=1
111 if (! ~ $#flagL 0) LAND=1
112 if (! ~ $#flagM 0 && ~ $LPUSERID daemon) LPMACHID=$flagM
113 if (! ~ $#flagQ 0) QONLY=1
114 if (! ~ $#flagR 0) RESET=1
115 if (! ~ $#flagc 0) COPIES=$flagc
116 if(! ~ $#flagd 0) LPDEST=$flagd
117 if (! ~ $#flagf 0) eval `{echo $flagf | sed -e 's/([^.]*)\.([0-9.]*)/FONT=\1;POINT=\2;/'}
118 if (! ~ $#flagi 0) IBIN=$flagi
119 if (! ~ $#flagk 0) KILLFLAG=1
120 if (! ~ $#flagl 0) LINES=$flagl
121 if (! ~ $#flagm 0) MAG=$flagm
122 if (! ~ $#flagn 0) NPAG=$flagn
123 if (! ~ $#flago 0) OLIST=-o^$flago
124 if (! ~ $#flagp 0) LPPROC=$flagp
125 if (! ~ $#flagq 0) LPQ=1
126 if (! ~ $#flagr 0) REVERSE=1
127 if (! ~ $#flagu 0) LPUSERID=$flagu
128 if (! ~ $#flagx 0) XOFF=$flagx
129 if (! ~ $#flagy 0) YOFF=$flagy
132 echo 'Set environment variable LPDEST or use the
133 ''-d printer'' option to set the destination.' >[1=2]
134 exit 'LPDEST not set'
136 if (~ $LPDEST */*) { # handles MHCC destinations like mh/lino
137 LPLOC=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\1/'}
138 LPDEST=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\2/'}
141 # look up device, get info
142 LPDLINE=`{grep '^'$LPDEST'[ ]' $LPLIB/devices}
143 if (! ~ $status '') {
144 echo 'device '$LPDEST' is not in '$LPLIB'/devices' >[1=2]
148 DEST_HOST=$LPDLINE(3)
152 if (~ $#LPPROC 0) LPPROC=$LPDLINE(7)
159 if (~ $LPCLASS *nohead*)
161 if (~ $LPCLASS *duplex*)
164 if (~ $#SCHED 0) SCHED=FIFO # everyone uses FIFO
167 case -; echo kill option not available on $LPDEST >[1=2]
169 case *; bind -b $LPLIB/kill /bin
171 exit 'kill command '"$KILL"' not found'
175 case -; echo queue status option not available on $LPDEST >[1=2]
176 exit 'stat option not available'
177 case *; bind -b $LPLIB/stat /bin
178 exec $STAT $* < /dev/null
179 exit 'stat command '"$STAT"' not found'
182 LPLOG=$LPLOGDIR/$LPDEST
183 if (! test -e $LPLOG) {
185 chmod +rwa $LPLOG >[2]/dev/null
190 case -; echo spooler does not exist for $LPDEST >[1=2]
192 case *; bind -b $LPLIB/spooler /bin
193 if (~ $#* 0) $SPOOLER
198 echo restarting daemon for printer $LPDEST >[1=2]
199 UNLOCK $LPSPOOL/$LPDEST
206 bind -b $LPLIB/daemon /bin
207 $DAEMON $* >>$LPLOG >[2=1] &