aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-08-31 02:15:26 +0000
committerrsc <devnull@localhost>2005-08-31 02:15:26 +0000
commit6174642093bdcef4116ae78dbdf4f2e608494258 (patch)
treeb916d25347295ee15b35434b92011b31fd76862c
parent9f1d53a09bdd8f99e9f81a344c7fa6b5161e1359 (diff)
downloadplan9port-6174642093bdcef4116ae78dbdf4f2e608494258.tar.gz
plan9port-6174642093bdcef4116ae78dbdf4f2e608494258.tar.bz2
plan9port-6174642093bdcef4116ae78dbdf4f2e608494258.zip
Initial lp.
-rw-r--r--lp/bin/.cvsignore0
-rwxr-xr-xlp/bin/UNLOCK3
-rwxr-xr-xlp/bin/lpsend.rc18
-rwxr-xr-xlp/daemon/generic138
-rwxr-xr-xlp/daemon/gsdev19
-rwxr-xr-xlp/daemon/psdev14
-rw-r--r--lp/devices80
-rw-r--r--lp/log/.placeholder0
-rw-r--r--lp/log/lpdaemonl0
-rw-r--r--lp/perm/.placeholder0
-rw-r--r--lp/prob/.placeholder0
-rwxr-xr-xlp/process/dvipost120
-rwxr-xr-xlp/process/g3post82
-rwxr-xr-xlp/process/generic108
-rwxr-xr-xlp/process/gifpost83
-rwxr-xr-xlp/process/hpost143
-rwxr-xr-xlp/process/jpgpost82
-rwxr-xr-xlp/process/noproc3
-rwxr-xr-xlp/process/p9bitpost83
-rwxr-xr-xlp/process/pdfgs78
-rwxr-xr-xlp/process/pdfpost76
-rwxr-xr-xlp/process/post68
-rwxr-xr-xlp/process/ppost98
-rwxr-xr-xlp/process/psextract60
-rwxr-xr-xlp/process/tr2post86
-rw-r--r--lp/queue/.placeholder0
-rwxr-xr-xlp/sched/FIFO2
-rwxr-xr-xlp/spooler/generic48
-rwxr-xr-xlp/spooler/lpdspool15
-rwxr-xr-xlp/spooler/nospool21
30 files changed, 1528 insertions, 0 deletions
diff --git a/lp/bin/.cvsignore b/lp/bin/.cvsignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/bin/.cvsignore
diff --git a/lp/bin/UNLOCK b/lp/bin/UNLOCK
new file mode 100755
index 00000000..fadddf76
--- /dev/null
+++ b/lp/bin/UNLOCK
@@ -0,0 +1,3 @@
+#!/usr/local/plan9/bin/rc
+
+>$1/LOCK && rm -f $1/LOCK
diff --git a/lp/bin/lpsend.rc b/lp/bin/lpsend.rc
new file mode 100755
index 00000000..bf64787c
--- /dev/null
+++ b/lp/bin/lpsend.rc
@@ -0,0 +1,18 @@
+#!/usr/local/plan9/bin/rc
+if (! ~ $DEBUG '') { flag x + }
+if (test -e /net/tcp/clone) {
+ dialstring=`{ndb/query sys $1 dom}
+ network=tcp
+ if (~ $#dialstring 0 || ! ~ $dialstring '') {
+ dialstring=$1
+ }
+ if(lpsend $network^!^$dialstring^!printer) exit ''
+ rv='tcp failed'
+}
+if not rv='no tcp'
+
+
+if (! ~ $dialstring '')
+ exit 'lpsend: no dialstring'
+if not
+ exit 'lpsend: '^$rv
diff --git a/lp/daemon/generic b/lp/daemon/generic
new file mode 100755
index 00000000..938c40a0
--- /dev/null
+++ b/lp/daemon/generic
@@ -0,0 +1,138 @@
+#!/usr/local/plan9/bin/rc
+
+rfork s
+
+if (! ~ $DEBUG '') flag x +
+
+LPDELAY=60
+
+if (! ~ $#* 2 && ! ~ $#* 3) {
+ echo 'usage generic local_cmd _remote_cmd [ success_cmd ]' >[1=2]
+ exit 'argument count'
+}
+LOCAL_CMD=$1
+REMOTE_CMD=$2
+SUCCESS_CMD=$3
+
+# we don't want to make a LOCK file unless we are at the destination
+# let the spooler take care of moving it there
+# this is necessary for clients and servers that share the
+# same lp queue directory
+if (! ~ $THIS_HOST $DEST_HOST || ! LOCK $LPSPOOL/$LPDEST/LOCK $THIS_HOST $pid) exit ''
+
+cd $LPSPOOL
+
+MAXTRY=2
+PRINTLOG=$LPLOGDIR/$LPDEST^.st
+
+fn schedule{
+ FILE=`{lpsub sched $SCHED $LPDEST}
+}
+
+while (schedule; ! ~ $#FILE 0) {
+ SCHEDLINE=`{cat $LPDEST/$FILE(1)^id}
+ LSLINE=`{ls -l $LPDEST/$FILE(1)}
+ echo `{date} start $SCHEDLINE
+ if (! test -s $LPDEST/.seqno) {
+ echo 0 > $LPDEST/.seqno
+ }
+ if not {
+ LPSEQNO = `{cat $LPDEST/.seqno | awk '{seqno = $1 + 1; if (seqno > 999) seqno = 0; print seqno}'}
+ echo $LPSEQNO > $LPDEST/.seqno
+ }
+ STARTIME=`{date}
+ if (! test -s $LPDEST/$FILE(1)) {
+ echo `{date} file $LPDEST/$FILE(1) disappeared or is empty
+ ls -l $LPDEST
+ echo $SCHEDLINE(2)$SCHEDLINE(4)' '$SCHEDLINE(3) $SCHEDLINE(5)' ! '$LSLINE(6) $STARTIME(4) >> $LPLOG
+ rm -f $LPDEST/$FILE $LPDEST/$FILE^id
+ }
+ if not {
+ if (~ $THIS_HOST $DEST_HOST) {
+ if (test -f $LPLIB/perm/$LPDEST && grep -s $SCHEDLINE(2) $LPLIB/perm/$LPDEST) {
+ echo `{date} permission denied
+ echo you are not allowed to use printer $LPDEST | mail $SCHEDLINE(2)
+ rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
+ }
+ if not {
+ echo `{date} sending to printer
+ > $PRINTLOG
+ STARTIME=`{date}
+ @{eval $LOCAL_CMD}
+ rv=$status
+ ENDTIME=`{date}
+ status=$rv
+ if () {
+ echo $SCHEDLINE(1)^$SCHEDLINE(3)' '$SCHEDLINE(2)' '$SCHEDLINE(4)' + '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
+ eval $SUCCESS_CMD
+ rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
+ }
+ if not {
+ echo $SCHEDLINE(1)^$SCHEDLINE(3)' '$SCHEDLINE(2)' '$SCHEDLINE(4)' - '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)' status='$rv
+ THISTRY=`{echo $SCHEDLINE(4) + 1|hoc}
+ echo $SCHEDLINE(1) $SCHEDLINE(2) $SCHEDLINE(3) $THISTRY >$LPDEST/$FILE(1)^id
+ if (test $THISTRY -ge $MAXTRY) {
+ if (test -d $LPLIB/prob/$LPDEST) {
+ cp $LPDEST/$FILE(1) $LPLIB/prob/$LPDEST
+ cp $LPDEST/$FILE(1)^id $LPLIB/prob/$LPDEST
+ cp $PRINTLOG $LPLIB/prob/$LPDEST/$FILE(1)^log
+ }
+ upasname=daemon
+ mail $SCHEDLINE(2) <<endmail1
+ rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
+ }
+ if not {
+ touch $LPDEST/$FILE(1)
+ sleep $LPDELAY
+ }
+ }
+ }
+ }
+ if not {
+# we don't want to be here
+# trap '' 13 # temp hack: ignore SIGPIPE
+ echo `{date} queuing - should not get here
+ STARTIME=`{date}
+ eval $REMOTE_CMD
+ rv=$status
+ ENDTIME=`{date}
+ if (~ $rv '') {
+ echo $SCHEDLINE(1)^$SCHEDLINE(3)' '$SCHEDLINE(2)' '$SCHEDLINE(4)' + '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
+ rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
+ }
+ if not {
+ echo $SCHEDLINE(1)^$SCHEDLINE(3)' '$SCHEDLINE(2)' '$SCHEDLINE(4)' - '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
+ echo status $rv from '$REMOTE_CMD'
+ THISTRY=`{echo $SCHEDLINE(4) + 1|hoc}
+ echo $SCHEDLINE(1) $SCHEDLINE(2) $SCHEDLINE(3) $THISTRY >$LPDEST/$FILE(1)^id
+ if (~ $THISTRY $MAXTRY) {
+ upasname=daemon
+ mail $SCHEDLINE(2) <<endmail2
+ }
+ if not {
+ touch $LPDEST/$FILE(1)
+ sleep $LPDELAY
+
+ # this is here to deal with running out of
+ # Datakit channels or other stupid problems
+ # backoff connection attempts but not too long
+ LPDELAY=`{echo $LPDELAY '*' 2|hoc}
+ if (test $LPDELAY -gt 960)
+ LPDELAY=60
+ }
+ }
+ }
+ }
+}
+Your job has failed to print on $LPDEST after $MAXTRY attempt(s).
+If the directory $LPLIB/prob/$LPDEST exists on $DEST_HOST,
+the file has been put there along with the printer log file.
+ Your friendly printer daemon
+endmail1
+Your job has failed to print on $LPDEST after $MAXTRY attempt(s).
+There is a problem in sending the job to $DEST_HOST,
+but I'll keep trying. Have a nice day.
+ Your enthusiastic printer daemon
+endmail2
+UNLOCK $LPSPOOL/$LPDEST
+rm $LPSPOOL/$LPDEST >[2]/dev/null
diff --git a/lp/daemon/gsdev b/lp/daemon/gsdev
new file mode 100755
index 00000000..bb48edd9
--- /dev/null
+++ b/lp/daemon/gsdev
@@ -0,0 +1,19 @@
+#!/usr/local/plan9/bin/rc
+
+fn local {
+ GSDEVICE=`{echo $LPCLASS | 9 sed 's/(.*\+)?gs!([^+]*)(\+.*)?/\2/'}
+ echo gs $GSDEVICE
+ {
+ psdownload -f -H$PLAN9/postscript/font -mfontmap -plw+ \
+ < $LPDEST/$FILE(1) |
+ gs -sDEVICE'='$GSDEVICE -s'OUTPUTFILE='$OUTDEV -dSAFER -dNOPAUSE -dQUIET -dBATCH -
+ } >[2]$PRINTLOG
+}
+fn remote {
+ {
+ echo -d$LPDEST -pnoproc -M$SCHEDLINE(1) -u$SCHEDLINE(2)
+ cat $LPDEST/$FILE
+ sleep 5
+ } | lpsend.rc $DEST_HOST
+}
+generic local remote ''
diff --git a/lp/daemon/psdev b/lp/daemon/psdev
new file mode 100755
index 00000000..895db8a3
--- /dev/null
+++ b/lp/daemon/psdev
@@ -0,0 +1,14 @@
+#!/usr/local/plan9/bin/rc
+
+fn local {
+ psdownload -f -H$PLAN9/postscript/font -mfontmap -plw+ \
+ < $LPDEST/$FILE(1) >$OUTDEV >[2]$PRINTLOG
+}
+fn remote {
+ {
+ echo -d$LPDEST -pnoproc -M$SCHEDLINE(1) -u$SCHEDLINE(2)
+ cat $LPDEST/$FILE
+ sleep 5
+ } | lpsend.rc $DEST_HOST
+}
+generic local remote ''
diff --git a/lp/devices b/lp/devices
new file mode 100644
index 00000000..a9bb8a3e
--- /dev/null
+++ b/lp/devices
@@ -0,0 +1,80 @@
+# Here is a sample printer devices file where
+# some of the printers have been commented out.
+#
+# The fields are:
+#
+# $1 printer name
+# $2 printer location - just a comment for lp -d'?'
+# $3 destination host - machine that manages print queue
+# $4 devname - device name used by destination host or physical device file
+# $5 speed - for printers on serial ports
+# $6 class - describes printer, e.g., postscript vs pcl
+# $7 process - how to process file to produce printable output
+# $8 spooler - how to spool that output for printing
+# $9 stat - how to query device status
+# $10 kill - how to remove print jobs
+# $11 daemon - how to start the print daemon to serve queue
+# $12 sched - scheduling order
+#
+# HP LaserJet 4M connected to serial port on an Annex terminal server.
+# 2c254 2C-254 rice tcp!annex!7035 19200 post+600dpi generic generic generic generic tcppost FIFO
+#
+# HP LaserJet 4M connected to Ethernet via a JetDirect card.
+# The speed field is used to set the bufffer size in the tcpostio program run from tcppost.
+# 2c307 2C-307 alice tcp!mh2c307!9100 81920 post+600dpi generic generic generic generic tcppost FIFO
+#
+# HP LaserJet 4M connected to serial port on a Cisco terminal server.
+# 2t4 2T-402 pyxis tcp!ts!4010 19200 post+600dpi generic generic generic generic tcppost FIFO
+#
+# HP LaserJet 4Si/MX connected to Ethernet via a JetDirect card.
+# This printer has a duplexing option.
+# See /sys/lib/postscript/prologues/hpsimx.ps for a fix to make it default
+# to the large paper tray at postion 1.
+# fn 2C-501 helix tcp!fn!9100 81920 post2+600dpi+duplex generic generic generic generic tcppost FIFO
+#
+# Tektronix Phaser 200i connected to Ethernet.
+# Using Xinet K-Talk software from a UNIX host. This software is not recommended.
+# We do not want to waste stock on the color printer so we do not print header pages.
+# peacock 2C-501 cetus peacock - post2+300dpi+nohead+color generic generic generic generic appletalk FIFO
+#
+# Any PostScript printer connected to the LPT1 port on my 486 pc running Plan 9 as a terminal.
+pcclone - - /dev/lpt1data - post+nohead generic pcclone - - - -
+#
+# QMS-410 connected to the serial port of an NCD terminal.
+# math34 2T-102 rice tcp!math34!87 9600 post+600dpi generic generic generic generic tcppost FIFO
+#
+# QMS-410 connected to the serial port of an AT&T 630/730 terminal
+# ps630 printer-on-630 - - - post+300dpi+nohead generic ps630 - - - -
+#
+# Xante Accel-a-Writer-8200. 1200dpi printer that uses a BSD lpr print daemon protocol
+# psu 2C-501 cetus psu - post+1200dpi generic generic xante generic lpddaemon FIFO
+#
+# 'stdout' sends the output to the standard output of the lp command.
+# if the 'phys_dev_name' field is set to a file or device, the output will go to it instead.
+# if '+sendEOT' is added to the 'class' field, an EOT character will be sent at the end of the output.
+#
+stdout - - - - post+nohead generic nospool - - - -
+#
+# sends the output to the standard output of the lp command.
+# used for generating output suitable for 100 dpi.
+100dpi - - - - post+100dpi+nohead generic nospool - - - -
+#
+# same as above for generating output suitable for 300 dpi.
+300dpi - - - - post+300dpi+nohead generic nospool - - - -
+#
+# same as above for generating output suitable for 600 dpi.
+#
+600dpi - - - - post+600dpi+nohead generic nospool - - - -
+#
+# same as above for generating output suitable for Linotronics phototypesetter.
+1270dpi - - - - post+lino+nohead generic nospool - - - -
+
+# 600dpi postscript printer named vogon via BSD LPD printer queue on alice
+vogon printer-room t23 /dev/atibm - post+600dpi generic generic generic generic dumb FIFO
+
+# HP DeskJet and Canon BJC-240
+hpdeskjet - - /dev/lpt1data - gs!cdj670+nohead generic nospool - - - -
+canonbjc240l - - /dev/lpt1data - gs!bjc600+nohead generic nospool - - - -
+
+# LaserJet4-compatible printer on Linux parallel port
+laser 2D t23 /dev/par0 - post+gs!ljet4+nohead generic generic generic generic gsdev FIFO
diff --git a/lp/log/.placeholder b/lp/log/.placeholder
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/log/.placeholder
diff --git a/lp/log/lpdaemonl b/lp/log/lpdaemonl
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/log/lpdaemonl
diff --git a/lp/perm/.placeholder b/lp/perm/.placeholder
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/perm/.placeholder
diff --git a/lp/prob/.placeholder b/lp/prob/.placeholder
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/prob/.placeholder
diff --git a/lp/process/dvipost b/lp/process/dvipost
new file mode 100755
index 00000000..520aa395
--- /dev/null
+++ b/lp/process/dvipost
@@ -0,0 +1,120 @@
+#!/usr/local/plan9/bin/rc
+if (~ $DEBUG 1) flag x +
+# convert Tex dvi to PostScript
+PATCH='%!PS-Adobe-2.0'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ switch ($LPCLASS) {
+ case *post2*;
+ switch ($i) {
+ case 0; PATCH=$PATCH'
+systemdict/languagelevel known {languagelevel 2 eq {true (0) startjob dup not
+{/exitserver errordict/invalidaccess get exec}if}{false}ifelse}{false}ifelse
+{
+ currentpagedevice/InputAttributes get {0 get} stopped
+ {pop pop} {2 dict dup /InputAttributes 1 dict dup
+ /Priority[0] put put dup /TraySwitch false put setpagedevice} ifelse
+ false (0) startjob pop
+} if'
+ case 1; PATCH=$PATCH'
+systemdict/languagelevel known {languagelevel 2 eq {true (0) startjob dup not
+{/exitserver errordict/invalidaccess get exec}if}{false}ifelse}{false}ifelse
+{
+ currentpagedevice/InputAttributes get {1 get} stopped
+ {pop pop} {2 dict dup /InputAttributes 1 dict dup
+ /Priority[1] put put dup /TraySwitch false put setpagedevice} ifelse
+ false (0) startjob pop
+} if'
+ }
+ case *; PATCH=$PATCH'
+statusdict begin $i setpapertray end'
+ }
+ case 11x17 ledger; PATCH=$PATCH'
+statusdict begin '$i'tray end'
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+if (! ~ $#LAND 0 && ~ $LAND 1)
+ LAND='-tlandscape'
+if (~ $LPCLASS *reverse*) {
+ switch ($REVERSE) {
+ case '';
+ REVFLAG=1
+ case 1;
+ REVFLAG=''
+ }
+}
+switch ($LPCLASS) {
+case *post100*;
+ DPI='-Z -D100'
+case *600dpi*;
+ DPI='-Z -D600'
+case *1200dpi*;
+ DPI='-Z -D1200'
+case *;
+ DPI=''
+}
+if (! ~ $COPIES '' -c*) COPIES=-c^$COPIES
+if (! ~ $OLIST '' '='*) OLIST=`{echo $OLIST | sed 's/-o/=/' | sed 's/-/:/g' }
+switch ($REVFLAG) {
+case 1;
+ echo $PATCH
+ switch ($OLIST) {
+ case '';
+ eval dvips -q -f $DPI -r $LAND $COPIES $1
+ case *;
+ DVIFILE=/tmp/dv$pid.dvi
+ dviselect -s $OLIST $1 > $DVIFILE
+ eval dvips -q -f $DPI -r $LAND $COPIES $DVIFILE
+ rm -f $DVIFILE
+ }
+ $LPLIB/process/hpost </dev/null
+case '';
+ $LPLIB/process/hpost </dev/null
+ echo $PATCH
+ switch ($OLIST) {
+ case '';
+ eval dvips -q -f $DPI $LAND $COPIES $1
+ case *;
+ DVIFILE=/tmp/dv$pid.dvi
+ dviselect -s $OLIST $1 > $DVIFILE
+ eval dvips -q -f $DPI $LAND $COPIES $DVIFILE
+ rm -f $DVIFILE
+ }
+}
+exit
diff --git a/lp/process/g3post b/lp/process/g3post
new file mode 100755
index 00000000..64063fed
--- /dev/null
+++ b/lp/process/g3post
@@ -0,0 +1,82 @@
+#!/usr/local/plan9/bin/rc
+# convert CCITT G3 Fax format to PostScript
+if (! ~ $DEBUG '') flag x +
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P$PATCH;
+
+if (~ $MAG '') MAG=1
+if (~ $MAG [.0-9]*) MAG=-m^$MAG^,^`{echo $MAG '*' 2 | hoc}
+
+if (! ~ $LAND '') LAND=-L
+if not LAND=()
+
+g3p9bit | p9bitpost $MAG $LAND $PATCH | $LPLIB/process/hpost
+exit
diff --git a/lp/process/generic b/lp/process/generic
new file mode 100755
index 00000000..3b793d2f
--- /dev/null
+++ b/lp/process/generic
@@ -0,0 +1,108 @@
+#!/usr/local/plan9/bin/rc
+# Tries to determine what type of file you are printing and do the correct
+# thing with it.
+# It currently knows about images, troff intermediate, and ascii files.
+TMPFILE=/tmp/lp$pid
+fn sigexit { rm -f $TMPFILE; }
+if (! ~ $DEBUG '') flag x +
+if (~ $LPCLASS *nohead*) NOHEAD=1
+if (~ $LPCLASS *duplex*) DUPLEX=1
+cat >$TMPFILE
+FILETYPE=`{file $TMPFILE}
+switch ($FILETYPE(2)) {
+case troff;
+ switch ($LPCLASS) {
+ case *Latin1* *post* *opost*; switch ($FILETYPE(5)) {
+ # Latin1 is for compatibility with old research UNIX systems, doesn't work on Plan 9
+ case Latin1 post; tcs -s -f utf -t latin1 < $TMPFILE |$LPLIB/process/dpost
+
+ case UTF; $LPLIB/process/tr2post < $TMPFILE
+ }
+
+ case *; echo $FILETYPE(2) -T$FILETYPE(5) output is improper for $LPDEST >[1=2]
+ }
+case special;
+ switch ($FILETYPE(4)) {
+ case '#b'; switch ($LPCLASS) {
+ case *post*; $LPLIB/process/p9bitpost < $TMPFILE
+ }
+
+ case *; echo $FILETYPE file is improper for $LPDEST >[1=2]
+ }
+case Compressed plan old; # type is really 'Compressed image' or 'plan 9 image'
+ # or 'old plan 9 image'
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/p9bitpost < $TMPFILE
+ }
+case jpeg;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/jpgpost < $TMPFILE
+ }
+
+case GIF;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/gifpost < $TMPFILE
+ }
+
+case ccitt-g31;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/g3post < $TMPFILE
+ }
+
+# bitmap for research UNIX compatibility, does not work on Plan 9.
+case bitmap;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/bpost < $TMPFILE
+ case *mhcc*; $LPLIB/process/bpost < $TMPFILE | $LPLIB/process/mhcc
+ case *; echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+ }
+case tex;
+ mv $TMPFILE $TMPFILE.dvi
+ TMPFILE=$TMPFILE.dvi
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/dvipost $TMPFILE
+ case *; echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+ }
+case postscript;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/post < $TMPFILE
+ case *; echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+ }
+case HPJCL;
+ switch ($LPCLASS) {
+ case *HPJCL*; $LPLIB/process/noproc < $TMPFILE
+ case *; echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+ }
+case daisy;
+ switch ($LPDEST) {
+ case *; echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+ }
+case English short extended alef limbo [Aa]scii ASCII assembler c latin rc sh as mail email message/rfc822;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/ppost < $TMPFILE
+ case *canon*; $LPLIB/process/can $* < $TMPFILE
+ case *; echo Unrecognized class of line printer for $LPDEST >[1=2]
+ }
+
+case tiff;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/tiffpost $TMPFILE
+ case *; echo Unrecognized class of line printer for $LPDEST >[1=2]
+ }
+case PDF;
+ switch ($LPCLASS) {
+ case *post*; $LPLIB/process/pdfpost $TMPFILE
+ case *; echo Unrecognized class of line printer for $LPDEST >[1=2]
+ }
+case empty;
+ echo file is empty >[1=2]
+case cannot;
+ echo cannot open file >[1=2]
+case *;
+ echo $FILETYPE(2) file is improper for $LPDEST >[1=2]
+}
+wait
+rv=$status
+rm -f $TMPFILE
+#exit $status
+exit
diff --git a/lp/process/gifpost b/lp/process/gifpost
new file mode 100755
index 00000000..d6afee29
--- /dev/null
+++ b/lp/process/gifpost
@@ -0,0 +1,83 @@
+#!/usr/local/plan9/bin/rc
+# convert CCITT G3 Fax format to PostScript
+if (! ~ $DEBUG '') flag x +
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P$PATCH;
+
+if (~ $MAG '') MAG=1
+if (~ $MAG [.0-9]*) MAG=-m^$MAG
+
+if (! ~ $LAND '') LAND=-L
+if not LAND=()
+
+/$cputype/bin/gif -t | /$cputype/bin/aux/p9bitpost $MAG $LAND $PATCH | $LPLIB/process/hpost
+exit
+
diff --git a/lp/process/hpost b/lp/process/hpost
new file mode 100755
index 00000000..169cb2ac
--- /dev/null
+++ b/lp/process/hpost
@@ -0,0 +1,143 @@
+#!/usr/local/plan9/bin/rc
+if (! ~ $DEBUG '') flag x +
+REVFLAG=''
+if (~ $LPCLASS *reverse*) {
+ switch ($REVERSE) {
+ case '';
+ REVFLAG=1
+ case 1;
+ REVFLAG=''
+ }
+}
+if (! ~ $REVFLAG '')
+ postreverse
+
+if (~ $NOHEAD '') {
+ DATE=`{date}
+ face='FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
+ facedom=`{awk '{ if(match("'$LPMACHID'", $1)) {print $2; exit}}' $PLAN9/face/.machinelist}
+ if (~ $#facedom 0) facedom=$LPMACHID
+
+ facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x4/.dict}
+ facedepth=4
+
+ if (~ $#facefile 0) {
+ facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x2/.dict}
+ facedepth=2
+ }
+
+ if (~ $#facefile 0) {
+ facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x1/.dict}
+ facedepth=1
+ }
+
+ if (~ $#facefile 0) {facefile=u/unknown.1; facedepth=1}
+ facefile=$PLAN9/face/48x48x$facedepth/$facefile
+
+ if (! ~ $#facefile 0 1)
+ facefile=$facefile(1)
+
+ if (~ $#facefile 0 || ! test -f $facefile ) {facefile=$PLAN9/face/48x48x2/u/unknown.1; facedepth=2}
+ if (test -r $facefile ) {
+ switch($facedepth){
+ case 1 2
+ face=`{cat $facefile |
+ sed -e 's/0x//g' -e 's/, *//g' |
+ tr 0123456789abcdef fedcba9876543210 };
+ case 4
+ face=`{iconv -u -c k4 $facefile |
+ dd -bs 60 -skip 1 >[2]/dev/null |
+ xd -b | sed 's/^[^ ]+ //;s/ //g' }
+ }
+ }
+}
+
+# We have to make sure the face information is set before rc sees the HERE file
+# so the cat has to be in a separate if statement. This is an rc bug.
+if (~ $NOHEAD '') cat <<EOF
+%!PS-Adobe-2.0 div 112 page header - research!pg
+/banner {
+ /saveobj save def
+ erasepage initgraphics
+ /#copies 1 def
+ /inch {72 mul} bind def
+ /pageborder {
+ 25 747 moveto
+ 590 747 lineto
+ 590 25 lineto
+ 25 25 lineto
+ closepath
+ 2 setlinewidth
+ 0 setgray
+ stroke
+ } def
+
+ /topborder {
+ 25 773 moveto
+ 590 773 lineto
+ 590 747 lineto
+ 25 747 lineto
+ closepath
+ 2 setlinewidth
+ 0 setgray
+ stroke
+ } def
+
+ /toptext {
+ 120 756 moveto
+ /Courier-Bold findfont 14 scalefont setfont
+ ($LPUSERID $DATE) show
+ } def
+
+ /prface {
+ gsave
+ translate rotate scale
+ setgray
+ 48 48 $facedepth [48 0 0 -48 0 48] {<$face>} image
+ grestore
+ } def
+EOF
+if (~ $NOHEAD '') switch ($LPCLASS) {
+case *hp4simx*;
+ echo '
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+if (~ $NOHEAD '') cat <<EOF
+ statusdict /setduplexmode known {statusdict begin false setduplexmode end} if
+ statusdict begin /manualfeed false def end
+ pageborder
+ topborder
+ toptext
+ 0 14 14 0 94 752 prface
+ .3 180 180 -90 3.0 inch 10.2 inch prface
+ showpage
+ saveobj
+ restore
+} bind def
+banner
+EOF
+
+if (~ $REVFLAG '') cat
+exit ''
diff --git a/lp/process/jpgpost b/lp/process/jpgpost
new file mode 100755
index 00000000..0212ce89
--- /dev/null
+++ b/lp/process/jpgpost
@@ -0,0 +1,82 @@
+#!/usr/local/plan9/bin/rc
+# convert JPG to PostScript
+if (! ~ $DEBUG '') flag x +
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P$PATCH;
+
+if (~ $MAG '') MAG=1
+if (~ $MAG [.0-9]*) MAG=-m^$MAG
+
+if (! ~ $LAND '') LAND=-L
+if not LAND=()
+
+9 jpg -t9 | p9bitpost $MAG $LAND $PATCH -p 32 26.17 | $LPLIB/process/hpost
+exit
diff --git a/lp/process/noproc b/lp/process/noproc
new file mode 100755
index 00000000..c5cf1a8c
--- /dev/null
+++ b/lp/process/noproc
@@ -0,0 +1,3 @@
+#!/usr/local/plan9/bin/rc
+# No processing, copy file from input to output
+cat
diff --git a/lp/process/p9bitpost b/lp/process/p9bitpost
new file mode 100755
index 00000000..78b7de56
--- /dev/null
+++ b/lp/process/p9bitpost
@@ -0,0 +1,83 @@
+#!/usr/local/plan9/bin/rc
+# convert plan 9 image to PostScript
+if (~ $DEBUG 1) flag x +
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P$PATCH;
+if (! ~ $LAND '') LAND=-L
+if not LAND=()
+# if (! ~ $COPIES '' -c*) COPIES=-c^$COPIES
+if (! ~ $MAG '') MAG=-m^$MAG
+if (~ $MAG '') MAG=()
+# if (! ~ $NPAG '' -n*) NPAG=-n^$NPAG
+# if (! ~ $XOFF '' -x*) XOFF=-x^$XOFF
+# if (! ~ $YOFF '' -y*) YOFF=-y^$YOFF
+p9bitpost $MAG $LAND $PATCH | $LPLIB/process/hpost
+exit
diff --git a/lp/process/pdfgs b/lp/process/pdfgs
new file mode 100755
index 00000000..90c00c07
--- /dev/null
+++ b/lp/process/pdfgs
@@ -0,0 +1,78 @@
+#!/usr/local/plan9/bin/rc
+
+#
+# we don't go through postscript, because to
+# get to postscript, we send the pdf through gs!
+# much easier to just go directly.
+#
+
+# usage: pdfgs pdffile [gsdev]
+
+switch($#*) {
+case 2
+ GSDEVICE=$2
+case 1
+ GSDEVICE=`{echo $LPCLASS | sed 's/(.*\+)?gs!([^+]*)(\+.*)?/\2/'}
+case *
+ echo 'usage: pdfgs pdffile [gsdev]' >[1=2]
+}
+
+GSTMPFILE=/tmp/pdf^$pid
+GSOPT=('-sDEVICE='$GSDEVICE '-sOutputFile='^$GSTMPFILE -dSAFER -dNOPAUSE -dQUIET -dBATCH -dNOPAUSE)
+
+#
+# RSC: pswrite produces weird overbars on various
+# letters, most notably Times-Roman A and h, unless
+# we use LanguageLevel=1. This doesn't seem to be
+# constrained to hp4simx printers, so just use LanguageLevel 1
+# all the time.
+#
+
+#if(~ $dev pswrite && ~ $LPCLASS *hp4simx*)
+# GSOPT=($GSOPT '-dLanguageLevel=1')
+if(~ $GSDEVICE pswrite)
+ GSOPT=($GSOPT '-dLanguageLevel=1')
+
+if(~ $OLIST '')
+ gs $GSOPT $1
+if not {
+ PGLIST=`{echo $OLIST | sed 's/-o//;s/,/ /g;s/ / /g' | tr -cd '0-9 -'}
+ GSPGLIST=()
+ for(i in $PGLIST){
+ switch($i){
+ case -*
+ GSPGLIST=($GSPGLIST `{seq 1 `{echo $i|tr -d '-'}})
+ case *-
+ # BUG assume 100 >= number of pages
+ GSPGLIST=($GSPGLIST `{seq `{echo $i|tr -d '-'} 100})
+ case *-*
+ GSPGLIST=($GSPGLIST `{seq `{echo $i|tr '-' ' '}})
+ case *
+ GSPGLIST=($GSPGLIST $i)
+ }
+ }
+ GSPGLIST=$"GSPGLIST
+ echo '
+ /Page null def
+ /Page# 0 def
+ /PDFSave null def
+ /DSCPageCount 0 def
+ /DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage} def
+ GS_PDF_ProcSet begin
+ pdfdict begin
+ ('^$1^') (r) file pdfopen begin
+ /npage pdfpagecount def
+ ['^$GSPGLIST^']
+ {
+ dup dup
+ 1 ge exch npage le and
+ { DoPDFPage }
+ { pop }
+ ifelse
+ } forall
+ ' | gs $GSOPT - >/dev/null >[2=1]
+}
+
+cat $GSTMPFILE
+rm -f $GSTMPFILE
+exit ''
diff --git a/lp/process/pdfpost b/lp/process/pdfpost
new file mode 100755
index 00000000..3abde800
--- /dev/null
+++ b/lp/process/pdfpost
@@ -0,0 +1,76 @@
+#!/usr/local/plan9/bin/rc
+# convert PDF output to PostScript
+if (! ~ $DEBUG '') flag x +
+PATCH='%!PS
+%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp
+'
+echo $PATCH
+
+pdfgs $1 pswrite | $LPLIB/process/hpost
+exit ''
diff --git a/lp/process/post b/lp/process/post
new file mode 100755
index 00000000..63bf036b
--- /dev/null
+++ b/lp/process/post
@@ -0,0 +1,68 @@
+#!/usr/local/plan9/bin/rc
+if (! ~ $DEBUG '') flag x +
+PATCH='%!PS
+%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' ignored >[1=2]
+ }
+}
+#if (! ~ $#DUPLEX 0) {
+# if (~ $DUPLEX 1 )
+# PATCH=$PATCH'
+#statusdict /setduplexmode known {statusdict begin true setduplexmode end} if';
+# if (~ $DUPLEX 0 )
+# PATCH=$PATCH'
+#statusdict /setduplexmode known {statusdict begin false setduplexmode end} if';
+#}
+PATCH=$PATCH'
+%%EndPatch from lp
+'
+
+{ echo $PATCH; psextract } | $LPLIB/process/hpost
+
diff --git a/lp/process/ppost b/lp/process/ppost
new file mode 100755
index 00000000..67436d3c
--- /dev/null
+++ b/lp/process/ppost
@@ -0,0 +1,98 @@
+#!/usr/local/plan9/bin/rc
+# converts a regular ascii file to PostScript
+if (! ~ $DEBUG '') flag x +
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN | awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp
+'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P''''$PATCH'''';
+switch ($LAND) {
+case -p*;
+case ''; LAND=-pp
+case 1; LAND=-pl
+}
+if (! ~ $COPIES '' -c*) COPIES=-c^$COPIES
+switch ($FONT) {
+case ''; FONT=-f'Courier'
+case -f*;
+case *; FONT=-f$FONT
+}
+switch ($POINT) {
+case ''; POINT=-s10
+case -s*;
+case *; POINT=-s$POINT
+}
+if (! ~ $LINES '' -l*) LINES=-l^$LINES;
+if (! ~ $MAG '' -m*) MAG=-m^$MAG;
+if (! ~ $NPAG '' -n*) NPAG=-n^$NPAG;
+if (! ~ $XOFF '' -x*) XOFF=-x`{echo $XOFF + .4|hoc};
+if not XOFF=-x.4
+if (! ~ $YOFF '' -y*) YOFF=-y^$YOFF;
+eval $PLAN9/bin/text2post $FONT $XOFF $YOFF $COPIES $LINES $MAG $NPAG $POINT $LAND $OLIST $PATCH | $LPLIB/process/hpost
+exit
diff --git a/lp/process/psextract b/lp/process/psextract
new file mode 100755
index 00000000..55695a1c
--- /dev/null
+++ b/lp/process/psextract
@@ -0,0 +1,60 @@
+#!/usr/local/plan9/bin/rc
+
+# extract pages $OLIST from postscript on stdin
+
+if(~ $OLIST '')
+ exec cat
+
+awk '
+BEGIN {
+ x=ENVIRON["OLIST"];
+ gsub(/^-o/, "", x);
+ na = split(x, a, ",");
+ header = 1;
+ goodpage = 0;
+}
+
+header || goodpage {
+ print
+}
+
+/^%%EndSetup[ ]*$/ { header = 0; next }
+
+/^%%Page:/ {
+ header = 0;
+ p=$2+0;
+ goodpage = 0;
+ for(i=1; i<=na; i++){
+ if(aa=match(a[i], "-")){
+ low=substr(a[i], 1, RSTART);
+ high=substr(a[i], RSTART+RLENGTH);
+ if(low == "")
+ low = 0;
+ else
+ low = low+0;
+ if(high == "")
+ high = 100000;
+ else
+ high = high+0;
+ if(low <= p && p <= high){
+ goodpage = 1;
+ break;
+ }
+ }else{
+ if(a[i] == p){
+ goodpage = 1;
+ break;
+ }
+ }
+ }
+}
+
+/^%%EndPage[ ]*$/ {
+ goodpage = 0;
+}
+
+/^%%Trailer[ ]*$/ {
+ goodpage = 1;
+}
+
+'
diff --git a/lp/process/tr2post b/lp/process/tr2post
new file mode 100755
index 00000000..23d45ad3
--- /dev/null
+++ b/lp/process/tr2post
@@ -0,0 +1,86 @@
+#!/usr/local/plan9/bin/rc
+if (~ $DEBUG 1) flag x +
+# convert troff output to PostScript
+PATCH='%%Patch from lp'
+switch ($LPCLASS) {
+case *hp4simx*;
+ PATCH=$PATCH'
+%% set the default papertray to be the lower tray for HP4siMX printers
+ statusdict begin defaultpapertray end 1 ne {
+ statusdict begin
+ 1 setdefaultpapertray
+ end
+ } if'
+}
+for (i in `{echo $IBIN|awk -F, '{ n=split($0, a, ","); for (i=1;i<=n;i++) print a[i]; }'}) {
+ switch ($i) {
+ case -P*;
+ case man manual manualfeed;
+ PATCH=$PATCH'
+%%BeginFeature: *Select ManualFeed
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /ManualFeed true >> setpagedevice
+ } {statusdict begin /manualfeed true def end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case simplex;
+ DUPLEX=0
+ case [0-9];
+ PATCH=$PATCH'
+%%BeginFeature: *Select InputTray
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << '$i' << /MediaType (tray'$i') >> >>
+ << /MediaType (tray'$i') >> setpagedevice
+ } {statusdict begin '$i' setpapertray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case 11x17 [Ll]edger;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Ledger
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /PageSize [792 1224] >> setpagedevice
+ } {statusdict begin '$i'tray end} ifelse
+ } stopped cleartomark
+%%EndFeature'
+ case transparency vg viewgraph;
+ PATCH=$PATCH'
+%%BeginFeature: *Select Transparency
+[{ << /MediaType (Transparency) >> setpagedevice
+ } stopped cleartomark
+%%EndFeature'
+ case *;
+ echo illegal option ''''-i $i'''' >[1=2]
+ }
+}
+if (! ~ $#DUPLEX 0) {
+ switch ($DUPLEX) {
+ case 0;
+ DUPLEX=false
+ case 1;
+ DUPLEX=true
+ }
+ PATCH=$PATCH'
+%%BeginFeature: *Set DuplexMode
+[{ systemdict /languagelevel known {languagelevel 1 gt product (HP LaserJet 4Si) ne and} if {
+ << /Duplex '$DUPLEX' >> setpagedevice
+ } {statusdict /setduplexmode known {statusdict begin '$DUPLEX' setduplexmode end} if} ifelse
+ } stopped cleartomark
+%%EndFeature'
+}
+PATCH=$PATCH'
+%%EndPatch from lp
+'
+if (! ~ $PATCH '' -P*)
+ PATCH=-P''''$PATCH'''';
+switch ($LAND) {
+case -p*;
+case ''; LAND=-pp
+case 1; LAND=-pl
+}
+if (! ~ $COPIES '' -c*) COPIES=-c^$COPIES
+if (! ~ $MAG '' -m*) MAG=-m^$MAG
+if (! ~ $NPAG '' -n*) NPAG=-n^$NPAG
+if (! ~ $XOFF '' -x*) XOFF=-x^$XOFF
+if (! ~ $YOFF '' -y*) YOFF=-y^$YOFF
+eval tr2post $XOFF $YOFF $COPIES $MAG $NPAG $LAND $OLIST $PATCH | $LPLIB/process/hpost
+exit
diff --git a/lp/queue/.placeholder b/lp/queue/.placeholder
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/lp/queue/.placeholder
diff --git a/lp/sched/FIFO b/lp/sched/FIFO
new file mode 100755
index 00000000..702e9155
--- /dev/null
+++ b/lp/sched/FIFO
@@ -0,0 +1,2 @@
+#!/usr/local/plan9/bin/rc
+9 ls -ptr $* | 9 sed -n -e '/^[0-9][0-9]*\.[1-9][0-9]*$/p'
diff --git a/lp/spooler/generic b/lp/spooler/generic
new file mode 100755
index 00000000..83ee13ff
--- /dev/null
+++ b/lp/spooler/generic
@@ -0,0 +1,48 @@
+#!/usr/local/plan9/bin/rc
+# fn sigexit { rm -f $LPSPOOL/$LPDEST/.$pid.* $LPSPOOL/$LPDEST/$pid.* $LPSPOOL/$LPDEST }
+if (! ~ $DEBUG '') flag x +
+
+echo $THIS_HOST $DEST_HOST
+if (~ $THIS_HOST $DEST_HOST) {
+ if (! test -d $LPSPOOL/$LPDEST) {
+ mkdir $LPSPOOL/$LPDEST
+ chmod 777 $LPSPOOL/$LPDEST >[2]/dev/null
+ chmod +t $LPSPOOL/$LPDEST >[2]/dev/null
+ }
+}
+# Process and enqueue files to be printed
+# take arguments as input files
+i=0
+if (~ $#* 0) *=''
+for (j in $*) {
+ i= `{echo $i + 1|hoc}
+
+# check access to the file so that you know that a failure in the
+# processing is a drastic error which will cause an exit from lp.
+
+ if (~ $j '' || test -f $j) {
+ if (~ $THIS_HOST $DEST_HOST) {
+ echo $LPMACHID $LPUSERID $pid.$i 0 > $LPSPOOL/$LPDEST/.$pid.$i^id
+ lpinput $j lpsub process $LPPROC >$LPSPOOL/$LPDEST/.$pid.$i
+ if (~ $status '') {
+ mv $LPSPOOL/$LPDEST/.$pid.$i $LPSPOOL/$LPDEST/$pid.$i
+ mv $LPSPOOL/$LPDEST/.$pid.$i^id $LPSPOOL/$LPDEST/$pid.$i^id
+ }
+ if not {
+ rval='preprocessing failed'
+ rm -f $LPSPOOL/$LPDEST/.$pid.$i $LPSPOOL/queue/$LPDEST/.$pid.$i^id
+ exit $rval
+ }
+ }
+ if not {
+ {
+ echo -d^$LPDEST -pnoproc -M^$LPMACHID -u^$LPUSERID
+ lpinput $j lpsub process $LPPROC
+ } | lpsend.rc $DEST_HOST
+ rval=$status
+ }
+ }
+ if not {
+ echo $j cannot be opened >[1=2]
+ }
+}
diff --git a/lp/spooler/lpdspool b/lp/spooler/lpdspool
new file mode 100755
index 00000000..3f14eaed
--- /dev/null
+++ b/lp/spooler/lpdspool
@@ -0,0 +1,15 @@
+#!/usr/local/plan9/bin/rc
+
+if (! ~ $DEBUG '') flag x +
+
+if (~ $#* 0) *=''
+
+for (j in $*) {
+ if (~ $j '' || test -f $j) {
+ lpinput $j lpsub process $LPPROC |
+ lpdsend -d$OUTDEV -tf -H$LPMACHID -P$LPUSERID $DEST_HOST >[2]$LPLOGDIR/$LPDEST^.st
+ }
+ if not {
+ echo $j cannot be opened >[1=2]
+ }
+}
diff --git a/lp/spooler/nospool b/lp/spooler/nospool
new file mode 100755
index 00000000..4d019983
--- /dev/null
+++ b/lp/spooler/nospool
@@ -0,0 +1,21 @@
+#!/usr/local/plan9/bin/rc
+if (! ~ $DEBUG '') flag x +
+
+if (~ $LPCLASS *sendEOT*) SENDEOT=1
+if not SENDEOT=0
+
+if (~ $OUTDEV -) OUTDEV=/dev/stdout
+if (~ $#* 0) {
+ if (! ~ $DEBUG '') echo input file is stdin >[1=2]
+ lpsub process $LPPROC >$OUTDEV
+ if (~ $SENDEOT 1) echo -n `{ascii -t 4} > $OUTDEV
+}
+if not {
+ if (! ~ $DEBUG '') echo input files $* >[1=2]
+ for (i in $*) {
+ if (! ~ $DEBUG '') echo processing $i >[1=2]
+ lpsub process $LPPROC < $i > $OUTDEV
+ if (~ $SENDEOT 1) echo -n `{ascii -t 4} > $OUTDEV
+ }
+}
+exit ''