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 if (! test -w /tmp) bind -bc $LPLIB/tmp /tmp
32 USAGE='usage: lp [-d printer] [-p process] [options] [files]
34 lp [-d printer] -k jobnos
37 -D turn on debugging output
40 -M<mach> print on machine <mach>
41 -Q put task only into the queue
42 -R restart printer daemon
44 -f<font.size> specify font and size
45 -i<src> take media from <src> input bin
46 -l<n> print <n> lines per logical page
47 -m<n> magnify <n> times
48 -n<n> print <n> logical pages per physical page
49 -o<i-j,k> print only pages i-j and k
51 -u<userid> print as <userid>
52 -x<n> x page offset in inches
53 -y<n> y page offset in inches
56 # umask 000 # this doesn't work in plan 9
60 THIS_HOST=`{ndb/query sys $sysname dom}
70 # Set default printer to be output device
71 if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
94 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'
97 if(! ifs=() eval `{aux/getflags $*}) {
102 awk 'BEGIN {print "device location host class"}
103 /^[^#]/ { printf "%-12s %-9s %-22s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
111 if (! ~ $#flagD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - }
112 if (! ~ $#flagH 0) NOHEAD=1
113 if (! ~ $#flagL 0) LAND=1
114 if (! ~ $#flagM 0 && ~ $LPUSERID daemon) LPMACHID=$flagM
115 if (! ~ $#flagQ 0) QONLY=1
116 if (! ~ $#flagR 0) RESET=1
117 if (! ~ $#flagc 0) COPIES=$flagc
118 if(! ~ $#flagd 0) LPDEST=$flagd
119 if (! ~ $#flagf 0) eval `{echo $flagf | sed -e 's/([^.]*)\.([0-9.]*)/FONT=\1;POINT=\2;/'}
120 if (! ~ $#flagi 0) IBIN=$flagi
121 if (! ~ $#flagk 0) KILLFLAG=1
122 if (! ~ $#flagl 0) LINES=$flagl
123 if (! ~ $#flagm 0) MAG=$flagm
124 if (! ~ $#flagn 0) NPAG=$flagn
125 if (! ~ $#flago 0) OLIST=-o^$flago
126 if (! ~ $#flagp 0) LPPROC=$flagp
127 if (! ~ $#flagq 0) LPQ=1
128 if (! ~ $#flagr 0) REVERSE=1
129 if (! ~ $#flagu 0) LPUSERID=$flagu
130 if (! ~ $#flagx 0) XOFF=$flagx
131 if (! ~ $#flagy 0) YOFF=$flagy
134 echo 'Set environment variable LPDEST or use the
135 ''-d printer'' option to set the destination.' >[1=2]
136 exit 'LPDEST not set'
138 if (~ $LPDEST */*) { # handles MHCC destinations like mh/lino
139 LPLOC=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\1/'}
140 LPDEST=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\2/'}
143 # look up device, get info
144 LPDLINE=`{grep '^'$LPDEST'[ ]' $LPLIB/devices}
145 if (! ~ $status '') {
146 echo 'device '$LPDEST' is not in '$LPLIB'/devices' >[1=2]
150 DEST_HOST=$LPDLINE(3)
154 if (~ $#LPPROC 0) LPPROC=$LPDLINE(7)
161 if (~ $LPCLASS *nohead*)
163 if (~ $LPCLASS *duplex*)
166 if (~ $#SCHED 0) SCHED=FIFO # everyone uses FIFO
169 case -; echo kill option not available on $LPDEST >[1=2]
171 case *; bind -b $LPLIB/kill /bin
173 exit 'kill command '"$KILL"' not found'
177 case -; echo queue status option not available on $LPDEST >[1=2]
178 exit 'stat option not available'
179 case *; bind -b $LPLIB/stat /bin
180 exec $STAT $* < /dev/null
181 exit 'stat command '"$STAT"' not found'
184 LPLOG=$LPLOGDIR/$LPDEST
185 if (! test -e $LPLOG) {
187 chmod +rwa $LPLOG >[2]/dev/null
192 case -; echo spooler does not exist for $LPDEST >[1=2]
194 case *; bind -b $LPLIB/spooler /bin
195 if (~ $#* 0) $SPOOLER
200 echo restarting daemon for printer $LPDEST >[1=2]
201 UNLOCK $LPSPOOL/$LPDEST
208 bind -b $LPLIB/daemon /bin
209 $DAEMON $* >>$LPLOG >[2=1] &