#!/bin/rc # This program enqueues the file to be printed and starts the daemon, when necessary. # Make changes to /sys/src/cmd/lp/lp.rc. Changes made directly to /rc/bin/lp will be lost. newpgrp # so that environment is not polluted ifs=' ' # set ifs in case it is munged in user's environment LPSPOOL=/sys/lib/lp/queue LPLIB=/sys/lib/lp # develop /bin from scratch bind /$cputype/bin /bin bind -b /rc/bin /bin bind -b $LPLIB/bin/$cputype /bin bind -b $LPLIB/bin/rc /bin path=(/bin) USAGE='usage: lp [-d printer] [-p process] [options] [files] lp [-d printer] -q lp [-d printer] -k jobnos options include: -H no header -L landscape mode -c make copies -f specify font and size -i take media from input bin -l print lines per logical page -m magnify times -n print logical pages per physical page -o print only pages i-j and k -r reverse pages -x x page offset in inches -y y page offset in inches' # umask 000 # this doesn't work in plan 9 if (~ $#sysname 0) THIS_HOST=plan9 if not THIS_HOST=$sysname LPMACHID=$THIS_HOST THIS_USERID=$user LPUSERID=$THIS_USERID # Set default printer to be output device if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice} # option parameters XOFF='' YOFF='' POINT='' FONT='' LINES='' LAND='' COPIES='' MAG='' NPAG='' OLIST='' IBIN='' REVERSE='' NOHEAD='' TRAY='' # remove FLAGS from environment FLAGD=();FLAGH=();FLAGL=();FLAGM=();FLAGQ=();FLAGc=();FLAGd=();FLAGf=() FLAGi=();FLAGk=();FLAGl=();FLAGm=();FLAGn=();FLAGo=();FLAGp=();FLAGq=() FLAGr=();FLAGt=();FLAGu=();FLAGx=();FLAGy=() # Process options eval `{getflags DHLM:1Qc:1d:1f:1i:1kl:1m:1n:1o:1p:1qrt:1u:1x:1y:1 $*} if (! ~ $status '') exit $status if (! ~ $#FLAGD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - } if (! ~ $#FLAGH 0) NOHEAD=1; if not NOHEAD='' if (! ~ $#FLAGL 0) LAND=1; if not LAND='' # originating machine id (for information only) if (! ~ $#FLAGM 0 && ~ $LPUSERID daemon) LPMACHID=$FLAGM if (! ~ $#FLAGQ 0) QONLY=1; if not QONLY='' if (! ~ $#FLAGc 0) COPIES=$FLAGc; if not COPIES=1 if (! ~ $#FLAGd 0) { switch ($FLAGd) { case '?'; exec awk 'BEGIN{printf "device location host class\n"} /^[^#]/ {printf "%-12s %-9s %-20s %s\n", $1, $2, $3, $6 }' $LPLIB/devices case *; LPDEST=$FLAGd } } if (! ~ $#FLAGf 0) eval `{echo $FLAGf | sed -e 's/([^.]*)\.([0-9.]*)/FONT=\1;POINT=\2;/'} if (! ~ $#FLAGi 0) IBIN=$FLAGi if (! ~ $#FLAGk 0) KILLFLAG=1; if not KILLFLAG=0 if (! ~ $#FLAGl 0) LINES=$FLAGl if (! ~ $#FLAGm 0) MAG=$FLAGm if (! ~ $#FLAGn 0) NPAG=$FLAGn if (! ~ $#FLAGo 0) NPAG=-o$FLAGo if (! ~ $#FLAGp 0) { switch (FLAGp) { case '?';exec ls $LPLIB/process case *; LPPROC=$FLAGp } } if (! ~ $#FLAGq 0) LPQ=1; if not LPQ=0 if (! ~ $#FLAGr 0) { switch ($REVERSE) { case '';REVERSE=1 case 1; REVERSE='' } } if (! ~ $#FLAGt 0) TRAY=$FLAGt # originating user id if (! ~ $#FLAGu 0) LPUSERID=$FLAGu if (! ~ $#FLAGx 0) XOFF=$FLAGx if (! ~ $#FLAGy 0) YOFF=$FLAGy if (~ $#LPDEST 0) { echo 'set environment variable LPDEST or '$USAGE >[1=2] exit 'LPDEST not set' } LPDLINE=`{grep '^'$LPDEST'[ ]' $LPLIB/devices} if (! ~ $status '') { echo 'device '$LPDEST' is not in '$LPLIB'/devices' >[1=2] exit 'LPDEST is bad' } LOC=$LPDLINE(2) DEST_HOST=$LPDLINE(3) OUTDEV=$LPDLINE(4) SPEED=$LPDLINE(5) LPCLASS=$LPDLINE(6) if (~ $#LPPROC 0) LPPROC=$LPDLINE(7) SPOOLER=$LPDLINE(8) STAT=$LPDLINE(9) KILL=$LPDLINE(10) DAEMON=$LPDLINE(11) SCHED=$LPDLINE(12) if (~ $KILLFLAG 1) switch ($KILL) { case -; echo kill option not available on $LPDEST >[1=2] exit 'kill n/a' case *; bind -b $LPLIB/kill /bin exec $KILL $* exit 'kill command not found' } if (~ $LPQ 1) switch ($STAT) { case -; echo queue status option not available on $LPDEST >[1=2] exit 'stat option not available' case *; bind -b $LPLIB/stat /bin exec $STAT $* < /dev/null exit 'stat command not found' } DATE=`{date} LPLOG=$LPLIB/log/$LPDEST.$DATE(1) if (! test -w $LPLOG) { >$LPLOG chmod 666 $LPLOG } switch ($SPOOLER) { case -; echo spooler does not exist for $LPDEST >[1=2] exit 'no spooler' case *; bind -b $LPLIB/spooler /bin if (~ $#* 0) $SPOOLER if not $SPOOLER $* } LSLINE=`{ls -l $LPLOG}; if (! ~ $LSLINE(7) $DATE(2) || ! ~ $LSLINE(8) $DATE(3)) cp /dev/null $LPLOG # run daemon if (~ $QONLY '') { if (! ~ $DAEMON -) { bind -b $LPLIB/daemon /bin $DAEMON $* >>$LPLOG >[1=2] & } } exit