changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/lp

changeset 7243: 34f64dcbbc25
parent: 503a936f838c
author: cinap_lenrek@felloff.net
date: Fri, 17 May 2019 18:14:10 +0200
permissions: -rwxr-xr-x
description: 7l: don't hardcode 4k pagesize, use INITRND
1 #!/bin/rc
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.
5 
6 rfork en # so that environment and name space are not polluted
7 #
8 # put 'fn sigexit { rm /tmp/lpcrap; exit interrupted }' into processes that create /tmp/lpcrap.
9 
10 ifs='
11 ' # set ifs in case it is munged in user's environment
12 
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
17 
18 $LPLIB/bin/lpscratch
19 x=$status
20 if(! ~ $x '') exit $x
21 
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
28 path=(/bin)
29 
30 USAGE='usage: lp [-d printer] [-p process] [options] [files]
31  lp [-d printer] -q
32  lp [-d printer] -k jobnos
33 
34  options include:
35  -D turn on debugging output
36  -H no header
37  -L landscape mode
38  -M<mach> print on machine <mach>
39  -Q put task only into the queue
40  -R restart printer daemon
41  -c<n> make <n> copies
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
48  -r reverse pages
49  -u<userid> print as <userid>
50  -x<n> x page offset in inches
51  -y<n> y page offset in inches
52 '
53 
54 # umask 000 # this doesn't work in plan 9
55 if (~ $#sysname 0)
56  THIS_HOST=plan9
57 if not {
58  THIS_HOST=`{ndb/query sys $sysname dom}
59  if(~ $#THIS_HOST 0)
60  THIS_HOST=$sysname
61 }
62 
63 LPMACHID=$THIS_HOST
64 THIS_USERID=$user
65 LPUSERID=$THIS_USERID
66 LPLOC=''
67 
68 # Set default printer to be output device
69 if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
70 
71 # option parameters
72 COPIES=1
73 FONT=''
74 IBIN=''
75 KILLFLAG=0
76 LAND=''
77 LINES=''
78 LPQ=0
79 MAG=''
80 NOHEAD=''
81 NPAG=''
82 OLIST=''
83 POINT=''
84 RESET=''
85 REVERSE=''
86 QONLY=''
87 TRAY=''
88 XOFF=''
89 YOFF=''
90 
91 # Process options
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'
93 argv0=lp
94 
95 if(! ifs=() eval `{aux/getflags $*}) {
96  echo $USAGE
97  exit usage
98 }
99 if(~ $flagd '?'){
100  awk 'BEGIN {print "device location host class"}
101 /^[^#]/ { printf "%-12s %-9s %-22s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
102  exit
103 }
104 if(~ $flagp '?'){
105  ls $LPLIB/process
106  exit
107 }
108 
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
130 
131 if (~ $#LPDEST 0) {
132  echo 'Set environment variable LPDEST or use the
133 ''-d printer'' option to set the destination.' >[1=2]
134  exit 'LPDEST not set'
135 }
136 if (~ $LPDEST */*) { # handles MHCC destinations like mh/lino
137  LPLOC=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\1/'}
138  LPDEST=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\2/'}
139 }
140 
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]
145  exit 'LPDEST is bad'
146 }
147 LOC=$LPDLINE(2)
148 DEST_HOST=$LPDLINE(3)
149 OUTDEV=$LPDLINE(4)
150 SPEED=$LPDLINE(5)
151 LPCLASS=$LPDLINE(6)
152 if (~ $#LPPROC 0) LPPROC=$LPDLINE(7)
153 SPOOLER=$LPDLINE(8)
154 STAT=$LPDLINE(9)
155 KILL=$LPDLINE(10)
156 DAEMON=$LPDLINE(11)
157 SCHED=$LPDLINE(12)
158 
159 if (~ $LPCLASS *nohead*)
160  NOHEAD=1
161 if (~ $LPCLASS *duplex*)
162  DUPLEX=1
163 
164 if (~ $#SCHED 0) SCHED=FIFO # everyone uses FIFO
165 if (~ $KILLFLAG 1)
166  switch ($KILL) {
167  case -; echo kill option not available on $LPDEST >[1=2]
168  exit 'kill n/a'
169  case *; bind -b $LPLIB/kill /bin
170  exec $KILL $*
171  exit 'kill command '"$KILL"' not found'
172  }
173 if (~ $LPQ 1)
174  switch ($STAT) {
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'
180  }
181 DATE=`{date}
182 LPLOG=$LPLOGDIR/$LPDEST
183 if (! test -e $LPLOG) {
184  >$LPLOG
185  chmod +rwa $LPLOG >[2]/dev/null
186 }
187 
188 if (~ $RESET '') {
189  switch ($SPOOLER) {
190  case -; echo spooler does not exist for $LPDEST >[1=2]
191  exit 'no spooler'
192  case *; bind -b $LPLIB/spooler /bin
193  if (~ $#* 0) $SPOOLER
194  if not $SPOOLER $*
195  }
196 }
197 if not {
198  echo restarting daemon for printer $LPDEST >[1=2]
199  UNLOCK $LPSPOOL/$LPDEST
200  sleep 5
201 }
202 
203 # run daemon
204 if (~ $QONLY '') {
205  if (! ~ $DAEMON -) {
206  bind -b $LPLIB/daemon /bin
207  $DAEMON $* >>$LPLOG >[2=1] &
208  }
209 }
210 exit ''