Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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