0){
+ if(/^;/) continue
+ if(/^[0-9a-fA-F]/){
+ vid=lower($1)
+ vendor[vid] = $2
+ }
+ if(/^ [0-9a-fA-F]/){
+ did=lower($2)
+ id[vid "/" did] = $3
+ }
+ }
+ FS = " "
+ }
+
+ {
+ print $0
+ vid = $4
+ sub(/\/.*/, "", vid)
+ if(vid in vendor){
+ s = vendor[vid]
+ if($4 in id)
+ s = s " " id[$4]
+ print "\t" s
+ }
+ }
+'
+}
+fn usage {
+ echo usage: $1 '[-bv]' >[1=2]
+ exit usage
+}
+
+filter=cat
+bridges=yes
+done=0
+while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
+ if (~ $1 -*b*)
+ bridges=no
+ if (~ $1 -*v*)
+ filter=verbose
+ switch ($1) {
+ case --
+ done = 1 # no break in rc, alas
+ case -*[~bv]*
+ usage $0
+ }
+ shift
+}
+if (! ~ $#* 0)
+ usage $0
+
+builtin cd '#$/pci' && grep . *ctl | {
+ if (~ $bridges no)
+ sed /:06/d
+ if not
+ cat
+ } |
+ sed '
+ s/ctl:/: /
+ t noop
+: noop
+ s/: 01/: disk 01/
+ s/: 02/: net 02/
+ s/: 03/: vid 03/
+ s/: 04/: aud 04/
+ s/: 05/: mem 05/
+ s/: 06/: brg 06/
+ s/: 07/: ser 07/
+ s/: 0c\.03/: usb 0c.03/
+ s/: 0c\.05/: smb 0c.05/
+ s/: 0d/: rad 0d/
+ s/: 10/: cryp 10/
+ t
+ s/ / --- /
+' | $filter
diff --git a/rc/bin/pdf2ps b/rc/bin/pdf2ps
new file mode 100755
index 000000000..9dfc200bb
--- /dev/null
+++ b/rc/bin/pdf2ps
@@ -0,0 +1,53 @@
+#!/bin/rc
+# pdf2ps [gs-options] [input.pdf] [output.ps] - generate PS from PDF
+rfork e
+
+fn cleanup { }
+fn usage {
+ echo 'usage: pdf2ps [gs-options] [input.pdf] [output.ps]' >[1=2]
+ exit usage
+}
+
+lang=(-'dLanguageLevel=2')
+opt=()
+while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
+ if(~ $1 '-dLanguageLevel='*)
+ lang=()
+ opt=($opt $1)
+ shift
+}
+if(~ $1 --)
+ shift
+
+switch($#*){
+case 0
+ fin=-
+ fout=-
+case 1
+ fin=$1
+ fout=-
+case 2
+ fin=$1
+ fout=$2
+case *
+ usage
+}
+
+if(~ $fin -){
+ # fin=/tmp/pdf2ps.$pid.^`{date -n}
+ # fn cleanup { rm -f $fin }
+ # cat >$tmp
+ fin=/fd/0
+}
+if(~ $fout -)
+ fout=/fd/1
+
+# Doing an inital `save' helps keep fonts from being flushed between
+# pages. We have to include the options twice because -I only takes
+# effect if it appears before other options.
+
+gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pswrite' \
+ $opt $lang \
+ -s'OutputFile='$fout -c save pop -f $fin
+
+cleanup
diff --git a/rc/bin/printfont b/rc/bin/printfont
new file mode 100755
index 000000000..266102f9d
--- /dev/null
+++ b/rc/bin/printfont
@@ -0,0 +1,105 @@
+#!/bin/rc
+# Formatted dump of encoded characters in one or more PostScript fonts.
+# Arguments should be PostScript font names or the word all, which dumps
+# all ROM and disk based fonts.
+#
+
+POSTLIB=/sys/lib/postscript/prologues
+PROLOGUE=$POSTLIB/printfont.ps
+
+OPTIONS=''
+COPYFILE=''
+MODE=portrait
+FONTENCODING=Default
+
+NONCONFORMING='%!PS'
+ENDPROLOG='%%EndProlog'
+BEGINSETUP='%%BeginSetup'
+ENDSETUP='%%EndSetup'
+TRAILER='%%Trailer'
+
+SETUP=setup
+
+while (! ~ $#* 0 && ~ $1 -*) {
+ switch ($1) {
+ case -a; shift; OPTIONS=$OPTIONS' /axescount $1 def'
+ case -a*; OPTIONS=$OPTIONS' /axescount '`{echo $1 | sed s/-a//}' def'
+
+ case -b; shift; OPTIONS=$OPTIONS' /radix '$1' def'
+ case -b*; OPTIONS=$OPTIONS' /radix '`{echo $1 | sed s/-b//}' def'
+
+ case -c; shift; OPTIONS=$OPTIONS' /#copies '$1' store'
+ case -c*; OPTIONS=$OPTIONS' /#copies '`{echo $1 | sed s/-c//}' store'
+
+ case -f; shift; OPTIONS=$OPTIONS' /labelfont /'$1' def'
+ case -f*; OPTIONS=$OPTIONS' /labelfont /'`{echo $1 | sed s/-f//}' def'
+
+ case -g; shift; OPTIONS=$OPTIONS' /graynotdef '$1' def'
+ case -g*; OPTIONS=$OPTIONS' /graynotdef '`{echo $1 | sed s/-g//}' def'
+
+ case -p; shift; MODE=$1
+ case -p*; MODE=`{echo $1 | sed s/-p//}
+
+ case -q; OPTIONS=$OPTIONS' /longnames false def /charwidth false def'
+
+ case -m; shift; OPTIONS=$OPTIONS' /magnification '$1' def'
+ case -m*; OPTIONS=$OPTIONS' /magnification '`{echo $1 | sed s/-m//}' def'
+
+ case -v; OPTIONS=$OPTIONS' /longnames true def /charwidth true def'
+
+ case -w; shift; OPTIONS=$OPTIONS' /linewidth '$1' def'
+ case -w*; OPTIONS=$OPTIONS' /linewidth '`{echo $1 | sed s/-w//}' def'
+
+ case -x; shift; OPTIONS=$OPTIONS' /xoffset '$1' def'
+ case -x*; OPTIONS=$OPTIONS' /xoffset '`{echo $1 | sed s/-x//}' def'
+
+ case -y; shift; OPTIONS=$OPTIONS' /yoffset '$1' def'
+ case -y*; OPTIONS=$OPTIONS' /yoffset '`{echo $1 | sed s/-y//}' def'
+
+ case -z; shift; OPTIONS=$OPTIONS' /zerocell '$1' def'
+ case -z*; OPTIONS=$OPTIONS' /zerocell '`{echo $1 | sed s/-z//}' def'
+
+ case -C; shift; COPYFILE=$COPYFILE' '$1
+ case -C*; COPYFILE=$COPYFILE' '`{echo $1 | sed s/-C//}
+
+ case -E; shift; FONTENCODING=$1
+ case -E*; FONTENCODING=`{echo $1 | sed s/-E//}
+
+ case -L; shift; PROLOGUE=$1
+ case -L*; PROLOGUE=`{echo $1 | sed s/-L//}
+
+ case -*; echo $0:' illegal option '$1 >[1=2]; exit 1
+ }
+ shift
+}
+
+switch ($MODE) {
+case l*; OPTIONS=$OPTIONS' /landscape true def'
+case *; OPTIONS=$OPTIONS' /landscape false def'
+}
+
+echo $NONCONFORMING
+cat $PROLOGUE
+echo $ENDPROLOG
+echo $BEGINSETUP
+if (~ $#COPYFILE 0 || ~ $COPYFILE '') COPYFILE=/dev/null
+cat $COPYFILE
+echo $OPTIONS
+
+switch ($FONTENCODING) {
+case /*; cat $FONTENCODING
+case ?*; cat $POSTLIB^/$FONTENCODING^.enc >[2]/dev/null
+}
+
+echo $SETUP
+echo $ENDSETUP
+
+for (i) {
+ switch ($i) {
+ case all; echo AllFonts
+ case /*; echo $i' PrintFont'
+ case ?*; echo /$i' PrintFont'
+ }
+}
+
+echo $TRAILER
diff --git a/rc/bin/ps2gif b/rc/bin/ps2gif
new file mode 100755
index 000000000..2e547a146
--- /dev/null
+++ b/rc/bin/ps2gif
@@ -0,0 +1,2 @@
+#!/bin/rc
+cat $1|/bin/gs -dNOPAUSE -dQUIET '-sOUTPUTFILE='/fd/1 '-sDEVICE=inferno' - quit.ps| crop | togif
diff --git a/rc/bin/ps2pdf b/rc/bin/ps2pdf
new file mode 100755
index 000000000..9942b161a
--- /dev/null
+++ b/rc/bin/ps2pdf
@@ -0,0 +1,43 @@
+#!/bin/rc
+# ps2pdf - convert PostScript to PDF
+rfork e
+
+fn usage {
+ echo 'usage: ps2pdf [gs-options] [input.ps [output.pdf]]' >[1=2]
+ exit usage
+}
+
+# gs's pdfwrite sometimes emits bad pdf at level 1.2,
+# but 1.4 seems to work fine.
+compat=(-'dCompatibilityLevel=1.2')
+opt=()
+while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
+ if(~ $1 '-dCompatibilityLevel='*)
+ compat=()
+ opt=($opt $1)
+ shift
+}
+if(~ $1 --)
+ shift
+
+switch($#*){
+case 0
+ fin='-'
+ fout='-'
+case 1
+ fin=$1
+ fout='-'
+case 2
+ fin=$1
+ fout=$2
+case *
+ usage
+}
+
+# We have to include the options twice because -I only takes effect
+# if it appears before other options.
+
+gscmd=( gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pdfwrite' \
+ $opt $compat \
+ -s'OutputFile='$fout -c .setpdfwrite -f $fin)
+exec $gscmd
diff --git a/rc/bin/psfax b/rc/bin/psfax
new file mode 100755
index 000000000..720b9cefd
--- /dev/null
+++ b/rc/bin/psfax
@@ -0,0 +1,90 @@
+#!/bin/rc
+view=no
+stdin=no
+
+switch($1){
+case -v
+ view=yes
+ shift
+}
+
+switch($#*){
+case 0 1
+ echo usage: $0 telephone-number recipient [files]
+ exit 0
+case 2
+ stdin=yes
+}
+
+telno=$1
+shift
+
+recip=$1
+shift
+
+script=/tmp/fax.$pid
+header=/tmp/faxh.$pid
+user=`{cat /dev/user}
+tmp=/tmp/page.$pid
+tmpin=/tmp/page.in.$pid
+tel=`{grep '\) '$user /lib/tel}
+myname=`{echo $tel | sed 's/ \(.*//'}
+ext=`{echo $tel | sed 's/.*\) [^ ]* [^ ]* ([^ ]*).*/\1/'}
+
+fn sigint{
+ #rm -f $tmp.* $tmpin.* $script $header $header.*
+ exit interrupt
+
+}
+
+# gs insists on reading its standard input, so we read quit.ps to cut it off.
+switch($stdin){
+case yes
+ cat > $tmpin
+ gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.%.3d' -dNOPAUSE -dQUIET $tmpin quit.ps
+case *
+ gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.%.3d' -dNOPAUSE -dQUIET $* quit.ps
+}
+
+pages=`{echo $tmp.*|wc -w}
+
+# use delimiters that are unlikely to be supplied in arguments
+echo -n s∮FAXddd∮ >$script
+echo -n `{date} >>$script
+echo ∮ >>$script
+echo -n s∮FAXFFF∮ >>$script
+echo -n $myname >>$script
+echo ∮ >>$script
+echo -n s∮FAXEEE∮ >>$script
+echo -n $user >>$script
+echo ∮ >>$script
+echo -n s∮FAXVVV∮ >>$script
+echo -n $ext >>$script
+echo ∮ >>$script
+echo -n s∮FAXTTT∮ >>$script
+echo -n $recip >>$script
+echo ∮ >>$script
+echo -n s∮FAXfff∮ >>$script
+echo -n $telno >>$script
+echo ∮ >>$script
+echo -n s∮FAXPPP∮ >>$script
+echo -n $pages >>$script
+echo ∮ >>$script
+sed -f $script /sys/lib/fax/h.ps > $header
+
+gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$header'.%.3d' -dNOPAUSE -dQUIET $header quit.ps
+
+files=()
+for(i in $header.* $tmp.*){
+ files=($files -f $i)
+}
+
+switch($view){
+case no
+ upas/qer $files /mail/faxoutqueue fax $user $telno < /dev/null
+ rx fax /sys/lib/fax/faxgoose
+case yes
+ page $header.* $tmp.*
+}
+
+#rm -f $tmp.* $header $script $header.* $tmpin
diff --git a/rc/bin/psu b/rc/bin/psu
new file mode 100755
index 000000000..d9f63fef8
--- /dev/null
+++ b/rc/bin/psu
@@ -0,0 +1,20 @@
+#!/bin/rc
+# psu - ps for just one user
+rfork e
+flags=()
+while (! ~ $#* 0 && ~ $1 -*) {
+ flags = ($flags $1)
+ shift
+}
+
+# sed -n p rather than grep so that we get buffered writes.
+# this is a huge difference in drawterm.
+switch($#*){
+case 0
+ ps $flags | sed -n '/^'$user' /p'
+case 1
+ ps $flags | sed -n '/^'$1' /p'
+case *
+ echo Usage: psu '[ps-flags] [ user ]' >[1=2]
+ exit usage
+}
diff --git a/rc/bin/readweb b/rc/bin/readweb
new file mode 100755
index 000000000..9290fd62e
--- /dev/null
+++ b/rc/bin/readweb
@@ -0,0 +1,10 @@
+#!/bin/rc
+# start abaco and its prerequisites
+rfork n
+
+# outside && bind /net.alt /net
+
+webfs
+webcookies
+echo useragent netscape 1.0 >/mnt/web/ctl
+exec /$cputype/bin/abaco $*
diff --git a/rc/bin/reboot b/rc/bin/reboot
new file mode 100755
index 000000000..7d2ea79c1
--- /dev/null
+++ b/rc/bin/reboot
@@ -0,0 +1,2 @@
+#!/bin/rc
+echo reboot $* > /dev/reboot
diff --git a/rc/bin/replica/changes b/rc/bin/replica/changes
new file mode 100755
index 000000000..469fce866
--- /dev/null
+++ b/rc/bin/replica/changes
@@ -0,0 +1,15 @@
+#!/bin/rc
+
+rfork en
+
+fn usage {
+ echo 'usage: replica/changes replica-name [paths]' >[1=2]
+ exit usage
+}
+
+. /rc/bin/replica/defs $*
+
+need clientdb clientroot clientproto
+
+must clientmount
+exec replica/updatedb -p $clientproto -l -r $clientroot $clientexclude $clientdb $paths
diff --git a/rc/bin/replica/defs b/rc/bin/replica/defs
new file mode 100755
index 000000000..45b36419f
--- /dev/null
+++ b/rc/bin/replica/defs
@@ -0,0 +1,55 @@
+tmp=()
+
+fn fatal {
+ if(! ~ $#tmp 0)
+ rm -f $tmp
+ echo $* >[1=2]
+ exit $"*
+}
+
+fn must {
+ $* || fatal $"*^': '^$status
+}
+
+fn need {
+ for(i)
+ if(~ $$i UNCONFIGURED)
+ fatal $name^' does not set $'^$i
+}
+
+opt=()
+while(! ~ $#* 0 && ~ $1 -*){
+ if(~ $1 -s -c){ # take one argument
+ opt=($opt $1)
+ shift
+ }
+ opt=($opt $1)
+ shift
+}
+if(~ $1 --)
+ shift
+if(~ $#* 0)
+ usage
+name=$1
+shift
+paths=($*)
+
+if(! ~ $name /* ./* ../*)
+ name=$home/lib/replica/$name
+
+if(! test -x $name)
+ fatal no such replica $name
+
+cfgopt=()
+applyopt=()
+fn servermount { status='' }
+fn clientmount { status='' }
+fn serverupdate { status='' }
+for (i in clientroot clientproto clientdb clientexclude serverroot serverlog serverproto)
+ $i=UNCONFIGURED
+. $name
+
+if(! ~ $#serverexclude 0)
+ serverexclude=-x^$serverexclude
+if(! ~ $#clientexclude 0)
+ clientexclude=-x^$clientexclude
diff --git a/rc/bin/replica/pull b/rc/bin/replica/pull
new file mode 100755
index 000000000..5b1fcc1e2
--- /dev/null
+++ b/rc/bin/replica/pull
@@ -0,0 +1,58 @@
+#!/bin/rc
+
+rfork en
+
+fn usage {
+ echo 'usage: replica/pull [-nv] [-c name] [-s name] replica-name [paths]' >[1=2]
+ exit usage
+}
+
+. /rc/bin/replica/defs $*
+
+need clientlog serverlog clientdb clientroot serverroot
+
+# mount the server file system, update the log
+must servermount
+must serverupdate
+must clientmount
+
+# download the log
+n=`{ls -l $clientlog >[2]/dev/null |awk '{print $6}'}
+s=`{ls -l $serverlog >[2]/dev/null |awk '{print $6}'}
+if(~ $n 0 || ~ $#n 0 || test $s -lt $n){
+ if(test -e $clientlog) must rm $clientlog
+ must fcp $serverlog $clientlog
+}
+if not{
+ m=`{echo $n-1024 | hoc}
+ if(~ $m -*)
+ m=0
+ cmp -s $serverlog $clientlog $m $m
+ x=$status
+ switch($x){
+ case *': EOF'
+ must tail +^$n^c $serverlog >>$clientlog
+ case *': differ'
+ must rm $clientlog
+ must fcp $serverlog $clientlog
+ case ''
+ ;
+ case *
+ fatal cmp: $x
+ }
+}
+
+# normally we'd do this after applylog, but we want
+# applylog to be the last thing in this script, so we'll
+# do it here instead, compacting changes from the
+# _last_ applylog.
+
+ndb=`{echo $clientdb | sed 's;(.*)/(.*);\1/_\2;'}
+must replica/compactdb $clientdb >$ndb
+mv $ndb $clientdb
+
+# mount the client file system, apply the log
+# this is the last thing in the script and is execed so that
+# if replica/pull is overwritten nothing bad will happen.
+# applylog takes care of itself as far as protection against being overwritten.
+exec replica/applylog $opt $applyopt $clientdb $clientroot $serverroot $paths <$clientlog
diff --git a/rc/bin/replica/push b/rc/bin/replica/push
new file mode 100755
index 000000000..635bc6b2c
--- /dev/null
+++ b/rc/bin/replica/push
@@ -0,0 +1,18 @@
+#!/bin/rc
+
+rfork en
+
+fn usage {
+ echo 'usage: replica/push [-nv] replica-name [paths]' >[1=2]
+ exit usage
+}
+
+. /rc/bin/replica/defs $*
+
+need clientproto clientexclude cfgopt clientdb clientroot serverroot paths
+
+must servermount
+must clientmount
+exec replica/applychanges -p $clientproto $clientexclude $opt $cfgopt \
+ $clientdb $clientroot $serverroot $paths
+
diff --git a/rc/bin/replica/scan b/rc/bin/replica/scan
new file mode 100755
index 000000000..c827eca92
--- /dev/null
+++ b/rc/bin/replica/scan
@@ -0,0 +1,18 @@
+#!/bin/rc
+
+rfork en
+
+fn usage {
+ echo 'usage: replica/scan replica-name [paths]' >[1=2]
+ exit usage
+}
+
+. /rc/bin/replica/defs $*
+
+need serverroot serverexclude serverproto serverdb serverlog
+
+must servermount
+replica/updatedb -r^$serverroot $serverexclude -p^$serverproto $serverdb >>$serverlog
+ndb=`{echo $serverdb | sed 's;(.*)/(.*);\1/n\2;'}
+odb=`{echo $serverdb | sed 's;(.*)/(.*);\1/_\2;'}
+replica/compactdb $serverdb >$ndb && mv $serverdb $odb && mv $ndb $serverdb
diff --git a/rc/bin/replica/setupdirs b/rc/bin/replica/setupdirs
new file mode 100755
index 000000000..75d47da47
--- /dev/null
+++ b/rc/bin/replica/setupdirs
@@ -0,0 +1,34 @@
+#!/bin/rc
+
+rfork en
+
+if(! ~ $#libreplica 1)
+ libreplica=$home/lib/replica
+
+fn usage {
+ echo 'usage: replica/setupdirs' >[1=2]
+ exit usage
+}
+
+fn fatal {
+ echo $* >[1=2]
+ exit $"*
+}
+
+fn must {
+ $* || fatal $"*^': '^$status
+}
+
+if(! ~ $#* 0)
+ usage
+
+for (i in \
+ $libreplica\
+ $libreplica/db\
+ $libreplica/db/client\
+ $libreplica/db/server\
+ $libreplica/log\
+ $libreplica/cfg)
+ if(! test -d $i)
+ must mkdir -p $i
+
diff --git a/rc/bin/rwd b/rc/bin/rwd
new file mode 100755
index 000000000..9e90de719
--- /dev/null
+++ b/rc/bin/rwd
@@ -0,0 +1,23 @@
+#!/bin/rc
+
+rfork e
+if(! ~ $#* 1){
+ echo 'usage: remotesys=xxx rwd dir' >[1=2]
+ exit usage
+}
+
+suf=''
+if(~ $#remotesys 1)
+ suf = @$remotesys
+if not
+ remotesys=''
+
+echo -n $1 >/dev/wdir
+b=`{basename $1}
+if(! ~ $#b 1)
+ b=/
+echo -n $b^$suf >/dev/label
+if(test -f /dev/acme/ctl){
+ echo name $1/-$remotesys >/dev/acme/ctl
+ echo dumpdir $1 >/dev/acme/ctl
+}
diff --git a/rc/bin/seemail b/rc/bin/seemail
new file mode 100755
index 000000000..0fea22e2b
--- /dev/null
+++ b/rc/bin/seemail
@@ -0,0 +1,4 @@
+#!/bin/rc
+
+if(~ $1 -i) exec faces -hi
+if not exec faces -h
diff --git a/rc/bin/service.auth/authsrv.il566 b/rc/bin/service.auth/authsrv.il566
new file mode 100755
index 000000000..8bcf54a26
--- /dev/null
+++ b/rc/bin/service.auth/authsrv.il566
@@ -0,0 +1,2 @@
+#!/bin/rc
+/bin/auth/authsrv -d $3
diff --git a/rc/bin/service.auth/authsrv.tcp567 b/rc/bin/service.auth/authsrv.tcp567
new file mode 100755
index 000000000..8bcf54a26
--- /dev/null
+++ b/rc/bin/service.auth/authsrv.tcp567
@@ -0,0 +1,2 @@
+#!/bin/rc
+/bin/auth/authsrv -d $3
diff --git a/rc/bin/service/!il17007 b/rc/bin/service/!il17007
new file mode 100755
index 000000000..e3398fdde
--- /dev/null
+++ b/rc/bin/service/!il17007
@@ -0,0 +1,4 @@
+#!/bin/rc
+
+netdir=`{echo $3 | sed 's;/[0-9]+$;!*!0;'}
+exec exportfs -a -A $netdir
diff --git a/rc/bin/service/!il17008 b/rc/bin/service/!il17008
new file mode 100755
index 000000000..87a149037
--- /dev/null
+++ b/rc/bin/service/!il17008
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/exportfs -s
diff --git a/rc/bin/service/!il17031 b/rc/bin/service/!il17031
new file mode 100755
index 000000000..91d9a7db9
--- /dev/null
+++ b/rc/bin/service/!il17031
@@ -0,0 +1,3 @@
+#!/bin/rc
+exec ramfs -i
+
diff --git a/rc/bin/service/!tcp515 b/rc/bin/service/!tcp515
new file mode 100755
index 000000000..a20168e71
--- /dev/null
+++ b/rc/bin/service/!tcp515
@@ -0,0 +1,5 @@
+#!/bin/rc
+
+if(/sys/lib/lp/bin/lpscratch){
+ exec /$cputype/bin/aux/lpdaemon >>[2] `{cat /env/LPSCRATCH}^/log/lpdaemonl
+}
diff --git a/rc/bin/service/!tcp564 b/rc/bin/service/!tcp564
new file mode 100755
index 000000000..5ca07adfd
--- /dev/null
+++ b/rc/bin/service/!tcp564
@@ -0,0 +1,3 @@
+#!/bin/rc
+mount '#s/boot' /root $rootspec
+exec /bin/exportfs -r /root
diff --git a/rc/bin/service/startcifs b/rc/bin/service/startcifs
new file mode 100755
index 000000000..34d6048cc
--- /dev/null
+++ b/rc/bin/service/startcifs
@@ -0,0 +1,14 @@
+#!/bin/rc
+# startcifs - (re)start cifs (smb) server
+echo killing old cifs server
+Kill aquarela | rc
+
+echo starting new cifs server
+@ {
+ echo 'srv -A local' >>/srv/fscons
+ sleep 2
+ chmod 666 /srv/local
+ 9fs local
+ cd /sys/log
+ aquarela
+} &
diff --git a/rc/bin/service/startnfs b/rc/bin/service/startnfs
new file mode 100755
index 000000000..c68cfa155
--- /dev/null
+++ b/rc/bin/service/startnfs
@@ -0,0 +1,9 @@
+#!/bin/rc
+9fs nslocum
+9fs alice
+Kill portmapper|rc
+Kill nfsserver|rc
+rm -f /srv/nfsserver.chat /srv/portmapper.chat
+aux/nfsserver -a il!emelie -a il!choline -c /lib/ndb/nfs >>[2] /sys/log/nfsserver
+aux/portmapper >>[2] /sys/log/portmapper
+aux/portmapper -t >>[2] /sys/log/portmapper
diff --git a/rc/bin/service/tcp110 b/rc/bin/service/tcp110
new file mode 100755
index 000000000..9a2836fad
--- /dev/null
+++ b/rc/bin/service/tcp110
@@ -0,0 +1,3 @@
+#!/bin/rc
+
+exec /$cputype/bin/upas/pop3 -t /sys/lib/ssl/cert.pem >>[2] /sys/log/pop3
diff --git a/rc/bin/service/tcp113 b/rc/bin/service/tcp113
new file mode 100755
index 000000000..4b60820fc
--- /dev/null
+++ b/rc/bin/service/tcp113
@@ -0,0 +1,4 @@
+#!/bin/rc
+x=`{read|sed 's/
//'}
+y=`{echo -n $x | sed 's/ //g'}
+echo $y^:USERID:UNIX:none
diff --git a/rc/bin/service/tcp143 b/rc/bin/service/tcp143
new file mode 100755
index 000000000..b784508fd
--- /dev/null
+++ b/rc/bin/service/tcp143
@@ -0,0 +1,3 @@
+#!/bin/rc
+
+exec /bin/ip/imap4d >[2]/sys/log/imap4d
diff --git a/rc/bin/service/tcp17005 b/rc/bin/service/tcp17005
new file mode 100755
index 000000000..97397558e
--- /dev/null
+++ b/rc/bin/service/tcp17005
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/ocpu -f -R
diff --git a/rc/bin/service/tcp17006 b/rc/bin/service/tcp17006
new file mode 100755
index 000000000..97101fe03
--- /dev/null
+++ b/rc/bin/service/tcp17006
@@ -0,0 +1 @@
+#!/bin/ocpu -N
diff --git a/rc/bin/service/tcp17007 b/rc/bin/service/tcp17007
new file mode 100755
index 000000000..915d78ae7
--- /dev/null
+++ b/rc/bin/service/tcp17007
@@ -0,0 +1,3 @@
+#!/bin/rc
+netdir=`{echo $3 | sed 's;/[0-9]+$;!*!0;'}
+exec /bin/exportfs -a -A $netdir
diff --git a/rc/bin/service/tcp17009 b/rc/bin/service/tcp17009
new file mode 100755
index 000000000..a8ba52cd7
--- /dev/null
+++ b/rc/bin/service/tcp17009
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/ip/rexexec
diff --git a/rc/bin/service/tcp17010 b/rc/bin/service/tcp17010
new file mode 100755
index 000000000..3cecd716b
--- /dev/null
+++ b/rc/bin/service/tcp17010
@@ -0,0 +1 @@
+#!/bin/cpu -R
diff --git a/rc/bin/service/tcp17013 b/rc/bin/service/tcp17013
new file mode 100755
index 000000000..b39d51b94
--- /dev/null
+++ b/rc/bin/service/tcp17013
@@ -0,0 +1 @@
+#!/bin/cpu -O
diff --git a/rc/bin/service/tcp19 b/rc/bin/service/tcp19
new file mode 100755
index 000000000..8f999ebd2
--- /dev/null
+++ b/rc/bin/service/tcp19
@@ -0,0 +1,2 @@
+#!/bin/rc
+/bin/aux/write 4096
diff --git a/rc/bin/service/tcp21 b/rc/bin/service/tcp21
new file mode 100755
index 000000000..54de9890e
--- /dev/null
+++ b/rc/bin/service/tcp21
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/ip/ftpd $*
diff --git a/rc/bin/service/tcp22 b/rc/bin/service/tcp22
new file mode 100755
index 000000000..899dc2a91
--- /dev/null
+++ b/rc/bin/service/tcp22
@@ -0,0 +1,3 @@
+#!/bin/rc
+
+exec /bin/aux/sshserve -A 'tis password' `{cat $3/remote} >>[2]/sys/log/ssh
diff --git a/rc/bin/service/tcp23 b/rc/bin/service/tcp23
new file mode 100755
index 000000000..3cdfd7b5c
--- /dev/null
+++ b/rc/bin/service/tcp23
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/ip/telnetd $*
diff --git a/rc/bin/service/tcp25 b/rc/bin/service/tcp25
new file mode 100755
index 000000000..0f32d6fba
--- /dev/null
+++ b/rc/bin/service/tcp25
@@ -0,0 +1,5 @@
+#!/bin/rc
+#smtp serv net incalldir user
+
+user=`{cat /dev/user}
+exec upas/smtpd -n $3
diff --git a/rc/bin/service/tcp513 b/rc/bin/service/tcp513
new file mode 100755
index 000000000..3a99855d1
--- /dev/null
+++ b/rc/bin/service/tcp513
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec /bin/ip/rlogind
diff --git a/rc/bin/service/tcp53 b/rc/bin/service/tcp53
new file mode 100755
index 000000000..0dbd836d5
--- /dev/null
+++ b/rc/bin/service/tcp53
@@ -0,0 +1,2 @@
+#!/bin/rc
+/bin/ndb/dnstcp $3
diff --git a/rc/bin/service/tcp565 b/rc/bin/service/tcp565
new file mode 100755
index 000000000..171ebcc76
--- /dev/null
+++ b/rc/bin/service/tcp565
@@ -0,0 +1,7 @@
+#!/bin/rc
+#whoami service net dir
+loc=`{cat $3/local|sed 's/!.*//'}
+rem=`{cat $3/remote}
+port=`{echo $rem|sed 's/^[^!]*!//'}
+rem=`{echo $rem|sed 's/!.*//'}
+echo i am $loc sysname $sysname you are $rem port $port
diff --git a/rc/bin/service/tcp7 b/rc/bin/service/tcp7
new file mode 100755
index 000000000..7f9b57f19
--- /dev/null
+++ b/rc/bin/service/tcp7
@@ -0,0 +1,2 @@
+#!/bin/rc
+/bin/cat
diff --git a/rc/bin/service/tcp9 b/rc/bin/service/tcp9
new file mode 100755
index 000000000..316ec0f17
--- /dev/null
+++ b/rc/bin/service/tcp9
@@ -0,0 +1,2 @@
+#!/bin/rc
+cat > /dev/null
diff --git a/rc/bin/service/tcp993 b/rc/bin/service/tcp993
new file mode 100755
index 000000000..e9bc42cdb
--- /dev/null
+++ b/rc/bin/service/tcp993
@@ -0,0 +1,3 @@
+#!/bin/rc
+
+exec tlssrv -c/sys/lib/ssl/cert.pem -limap4d -r`{cat $3/remote} /bin/ip/imap4d -pdplan9.bell-labs.com -r`{cat $3/remote}>[2]/sys/log/imap4d
diff --git a/rc/bin/service/tcp995 b/rc/bin/service/tcp995
new file mode 100755
index 000000000..b32a090a5
--- /dev/null
+++ b/rc/bin/service/tcp995
@@ -0,0 +1,3 @@
+#!/bin/rc
+
+exec tlssrv -lpop3 -c/sys/lib/ssl/cert.pem -r`{cat $3/remote} /bin/upas/pop3 -p -r`{cat $3/remote} >[2]/sys/log/pop3
diff --git a/rc/bin/service/telcodata b/rc/bin/service/telcodata
new file mode 100755
index 000000000..e03efd646
--- /dev/null
+++ b/rc/bin/service/telcodata
@@ -0,0 +1,3 @@
+#!/bin/rc
+echo This is the plan 9 incoming fax line.
+echo Please do not make data calls to us.
diff --git a/rc/bin/service/telcofax b/rc/bin/service/telcofax
new file mode 100755
index 000000000..6003e4441
--- /dev/null
+++ b/rc/bin/service/telcofax
@@ -0,0 +1,4 @@
+#!/bin/rc
+9fs emelie
+bind -c /n/emelie/mail/faxqueue /mail/faxqueue
+exec /bin/aux/faxreceive
diff --git a/rc/bin/setrtc b/rc/bin/setrtc
new file mode 100755
index 000000000..43ccdc09e
--- /dev/null
+++ b/rc/bin/setrtc
@@ -0,0 +1,4 @@
+#!/bin/rc
+# setrtc - set real-time clock to current system time
+if (test -e '#r/rtc')
+ awk '{print $1}' /dev/time >'#r/rtc'
diff --git a/rc/bin/sig b/rc/bin/sig
new file mode 100755
index 000000000..56125ab17
--- /dev/null
+++ b/rc/bin/sig
@@ -0,0 +1,29 @@
+#!/bin/rc
+# Usage: sig key ...
+# prints out function signatures by grepping the manual
+
+
+*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_ \012'} # fold case, delete funny chars
+if(~ $#* 0){
+ echo Usage: sig function ... >/fd/2
+ exit 1
+}
+
+for (i) {
+ files=`{grep -il '[ ]\*?'$i'\(' /sys/man/2/*}
+ for(j in $files) {
+ {echo .nr LL 20i; sed -n '/^.SH SYNOPSIS/,/^.SH.*DESCR/p' $j } |
+ nroff -man |
+ sed '
+ :a
+ /,$/ {
+ N
+ s/\n//
+ }
+ ta
+ s/[ ]+/ /g' |
+ grep -i -e '[ *]'$i'\(' | sed 's/^[ +]/ /'
+ }
+}
+
+exit 0
diff --git a/rc/bin/slay b/rc/bin/slay
new file mode 100755
index 000000000..b452b512b
--- /dev/null
+++ b/rc/bin/slay
@@ -0,0 +1,7 @@
+#!/bin/rc
+U=`{cat /dev/user}
+for(i){
+ ps | sed -n '/^'$U' .* '$i'$/s%[^ ]* *%~>/proc/%
+ s% *.* (.*)%/ctl # \1%
+ s%~%echo kill%p'
+}
diff --git a/rc/bin/spell b/rc/bin/spell
new file mode 100755
index 000000000..073ab2df2
--- /dev/null
+++ b/rc/bin/spell
@@ -0,0 +1,21 @@
+#!/bin/rc
+
+spellflags=()
+deroffargs=()
+fflag=''
+for(x){
+ switch($x){
+ case -[abcvx]
+ spellflags=($spellflags $x)
+ case -f
+ fflag=$x
+ case *
+ if(~ $fflag -f) {
+ spellflags=($spellflags -f $x)
+ fflag=''
+ }
+ if not deroffargs=($deroffargs $x)
+ }
+}
+
+deroff -w $deroffargs | sort -u | aux/sprog $spellflags
diff --git a/rc/bin/src b/rc/bin/src
new file mode 100755
index 000000000..b2de4dc4c
--- /dev/null
+++ b/rc/bin/src
@@ -0,0 +1,55 @@
+#!/bin/rc
+
+rfork e
+path=(/bin/)
+
+sym = 'threadmain?z
+ main?z'
+
+fn dbsrc{
+ echo $sym | db $1 | sed '1d;/symbol not found/d;s/.*\(\) //'
+}
+
+fn go{
+ type=`{file <$1 | sed 's/stdin: //'}
+ switch($type){
+ case 'rc executable file'
+ plumbit $1 '(rc executable)'
+ case *executable* *'plan 9 boot image'*
+ plumbit `{dbsrc $1} '(executable)'
+ case *
+ echo 'src: can''t find source for '$1 - unrecognized type $type >[1=2]
+ }
+}
+
+fn plumbit{B $1}
+
+fn usage{
+ echo usage: 'src [-n] [-s symbol] executable ...'>[1=2]
+ exit usage
+}
+
+while(~ $1 -*)
+ switch($1){
+ case -n
+ shift
+ fn plumbit {echo $1}
+ case -s
+ shift
+ # add main in case symbol is undefined
+ sym=$1'?z
+ main?z'
+ shift
+ case -*
+ usage
+ }
+
+if(~ $#* 0) usage
+
+for(i){
+ if(test -f $i) go $i
+ if not if(test -f /bin/$i) go /bin/$i
+ if not if(test -f /bin/*/$i) go /bin/*/$i
+ if not if(test -f /bin/*/*/$i) go /bin/*/*/$i
+ if not echo 'src: can''t find '$i
+}
diff --git a/rc/bin/srvssh b/rc/bin/srvssh
new file mode 100755
index 000000000..8a57125a7
--- /dev/null
+++ b/rc/bin/srvssh
@@ -0,0 +1,101 @@
+#!/bin/rc
+
+# Serve Unix u9fs over SSH
+#
+# Basically, try each of the following until you find one that works:
+#
+# srvssh unix
+# srvssh -r unix
+# srvssh -R unix
+# srvssh -r -s unix
+# srvssh -R -s unix
+#
+# and then never look back. Note that "srvssh unix" should always
+# work. It's just that if you're talking with certain sshd's, you'll get
+# hit by Nagle's algorithm and need to explore the other flags.
+
+# When using ssh to start u9fs, the only way to turn off
+# Nagle's algorithm (which kills the performance of RPC-based
+# protocols like 9P) is to allocate a pseudo-terminal. The
+# command ssh -Rmp attempts to allocate a pseudo-terminal and
+# then put it in a transparent mode. Especially when
+# connected to older SSH daemons, the connection ends up not
+# quite transparent. To get around this, we explicity set the tty
+# mode on the command line as well. The hope is that -Rmp makes
+# the connection transparent enough for the Tversion, and the stty
+# command will do the rest. If -Rmp doesn't make the connection
+# transparent enough for the Tversion (but the stty commands do
+# make the connection fully transparent) then add "-s 5" to the srv
+# command to tell it to wait 5 seconds before sending the Tversion.
+# That should be enough time for the stty to take effect.
+
+rfork e
+
+fn usage {
+ echo 'usage: srvssh [-R] [-r] [-s] [-u u9fspath] system [srvname [mtpt]]' >[1=2]
+ exit usage
+}
+
+rawhack=''
+sleephack=()
+u9fspath=u9fs
+rawflags=''
+
+while(~ $1 -*){
+ switch($1){
+ case -r
+ rawflags='-Rmp'
+ shift
+ case -R
+ rawflags='-Rmp'
+ rawhack=('stty raw -echo '';''')
+ shift
+ case -s
+ sleephack=(-s 5)
+ shift
+ case -u
+ shift
+ u9fspath=$1
+ shift
+ case -u*
+ u9fspath=`{echo $1 | sed s/-u//}
+ shift
+ case *
+ usage
+ }
+}
+
+if(! ~ $#* 1 2 3)
+ usage
+
+switch($#*){
+case 1
+ srv=$1
+ mtpt=/n/$1
+case 2
+ srv=$2
+ mtpt=/n/$1
+case 3
+ srv=$2
+ mtpt=$3
+}
+
+x=(srv $sleephack -e \
+ 'ssh '$rawflags' '$1' '$rawhack' '$u9fspath' -na none -u ''$''USER -l ''$''HOME/u9fs.log' \
+ $srv $mtpt)
+$x
+
+# Sometimes /srv/whatever can be a closed pipe, in which case
+# srv will have been killed for writing to it, without a chance to
+# defend itself. Rerun it in this case.
+
+ss=$status
+if(~ $ss *'write on closed pipe'*){
+ rm -f /srv/$srv
+ $x
+ ss=$status
+}
+
+if(! ~ $ss '')
+ echo srvssh: $ss >[1=2]
+exit $ss
diff --git a/rc/bin/start b/rc/bin/start
new file mode 100755
index 000000000..f8d423c6e
--- /dev/null
+++ b/rc/bin/start
@@ -0,0 +1,5 @@
+#!/bin/rc
+U=`{cat /dev/user}
+ps | sed -n '/^'$U' .*Stopped.* '$1'$/s%[^ ]* *%~>/proc/%
+s% *.*%/ctl%
+s%~%echo start%p'
diff --git a/rc/bin/startupasfs b/rc/bin/startupasfs
new file mode 100755
index 000000000..720d63094
--- /dev/null
+++ b/rc/bin/startupasfs
@@ -0,0 +1,5 @@
+#!/bin/rc
+# startupasfs - start upas/fs if needed, mainly for lib/profile
+if (! test -e /srv/upasfs.$user)
+ upas/fs -s
+mount -c /srv/upasfs.$user /mail/fs
diff --git a/rc/bin/stock b/rc/bin/stock
new file mode 100755
index 000000000..b2db7d27c
--- /dev/null
+++ b/rc/bin/stock
@@ -0,0 +1,14 @@
+#!/bin/rc
+
+stock=ALU
+
+if(! ~ $#* 0) stock=`{echo $*|tr a-z A-Z|sed 's/ /+/g'}
+
+hget 'http://download.finance.yahoo.com/d/quotes.csv?s='^$stock^'&f=snl1d1c1v&e=.exe' |
+ sed 's/ +"/"/;s/
//' |
+ switch(`{date}){
+ case *'Apr 1 '*
+ sed 's/("ALU","ALCATEL LUCENT"),([^,]*),(.*)$/\1,72.35,\3/'
+ case *
+ cat
+ }
diff --git a/rc/bin/stop b/rc/bin/stop
new file mode 100755
index 000000000..c7f9f9a51
--- /dev/null
+++ b/rc/bin/stop
@@ -0,0 +1,5 @@
+#!/bin/rc
+U=`{cat /dev/user}
+ps | sed -n '/^'$U' .* '$1'$/s%[^ ]* *%~>/proc/%
+s% *.*%/ctl%
+s%~%echo stop%p'
diff --git a/rc/bin/tel b/rc/bin/tel
new file mode 100755
index 000000000..adea1e16f
--- /dev/null
+++ b/rc/bin/tel
@@ -0,0 +1,8 @@
+#!/bin/rc
+rfork e
+for(i){
+ if (test -f $home/lib/tel)
+ grep -i $i $home/lib/tel
+ grep -hi $i /lib/tel /lib/areacodes
+}
+exit ''
diff --git a/rc/bin/termrc b/rc/bin/termrc
new file mode 100755
index 000000000..5de208a55
--- /dev/null
+++ b/rc/bin/termrc
@@ -0,0 +1,106 @@
+#!/bin/rc
+# terminal startup
+TIMESYNCARGS=(-rLa1000000)
+NDBFILE=/lib/ndb/local
+
+mntgen -s slashn && chmod 666 /srv/slashn
+
+# bind all likely devices (#S was bound in boot)
+for(i in f t m v L P u U '$' Σ κ)
+ /bin/bind -a '#'^$i /dev >/dev/null >[2=1]
+
+# set up any partitions
+diskparts
+
+# start up local swapping
+disk=`{ls /dev/sd*/swap >[2]/dev/null}
+if (! ~ $#disk 0)
+ swap $disk(1) >/dev/null >[2=1]
+rm /env/disk
+
+# we do this before we have a name. we may need to do network
+# setup so that we can get a name.
+if(test -e /rc/bin/termrc.local)
+ . /rc/bin/termrc.local
+
+# cs sets sysname (termrc.local may already have started it so check)
+if(! test -e /srv/cs && ! test -e /net/cs)
+ ndb/cs -f $NDBFILE
+sysname=`{cat /dev/sysname}
+if (~ $#sysname 0 || ~ $sysname '') {
+ sysname = gnot # default
+ echo -n $sysname >/dev/sysname
+}
+
+# machine specific startup (e.g., for devices not probed)
+if(test -e /cfg/$sysname/termrc)
+ . /cfg/$sysname/termrc
+
+# start IP on the LAN, if not already configured. diskless terminals
+# are already configured by now. It's commented out to avoid a long timeout
+# on startup waiting for DHCP.
+#
+# If your site provides DHCP service,
+#
+#if(! test -e /net/ipifc/0/ctl)
+# ip/ipconfig
+#
+# Otherwise, see /cfg/$sysname/termrc (/cfg/example/termrc is an example).
+
+# start dns if we have an internet
+if(test -e /net/ipifc/0/ctl && ! test -e /srv/dns)
+ ndb/dns -r
+
+if(! ~ $terminal *vx32*){
+ # start timesync if it isn't running and we weren't told not to
+ if(! ps|grep -s timesync)
+ if(! ~ $TIMESYNCARGS '')
+ aux/timesync $TIMESYNCARGS
+
+ # add the loop-back medium
+ if(! grep -s 127.0.0.1 /net/ipselftab)
+ ip/ipconfig loopback /dev/null 127.1
+
+ # set things up for vmware
+ if(! ~ `{cat /dev/user} none)
+ if(test -e /bin/aux/vmware)
+ aux/vmware
+}
+
+# query user if terminal isn't adequately configured yet
+if(~ $mouseport ask){
+ echo -n 'mouseport is (ps2, ps2intellimouse, 0, 1, 2)[ps2]: '
+ mouseport=`{read}
+ if(~ $#mouseport 0)
+ mouseport=ps2
+}
+if(~ $vgasize ask){
+ echo -n 'vgasize [640x480x8]: '
+ vgasize=`{read}
+ if(~ $#vgasize 0)
+ vgasize=640x480x8
+}
+if(~ $monitor ask){
+ echo -n 'monitor is [xga]: '
+ monitor=`{read}
+ if(~ $#monitor 0)
+ monitor=xga
+}
+if(test -f /dev/mousectl){
+ switch($mouseport){
+ case ps2 ps2intellimouse 0 1 2
+ aux/mouse $mouseport
+ # parse vgasize into fields
+ vgasize=`{echo $vgasize}
+ if(! ~ $"monitor '' && ! ~ `{cat /dev/user} none)
+ aux/vga -l $vgasize
+ if(~ $accupoint 1)
+ pipefile -dr /bin/aux/accupoint /dev/mouse
+ }
+}
+
+usbstart
+if (test -f /dev/apm)
+ aux/apm
+
+dontkill '^(ipconfig|factotum|mntgen|fossil|cs|dns|listen|reboot)$'
diff --git a/rc/bin/termrc.local b/rc/bin/termrc.local
new file mode 100755
index 000000000..962c77c01
--- /dev/null
+++ b/rc/bin/termrc.local
@@ -0,0 +1,13 @@
+#!/bin/rc
+# local terminal startup
+
+# used only by upas, as default return domain appended to all unqualified
+# return addresses, even local ones
+site=plan9
+# replace FILESERVER with the name of your file server
+# here we start with kfs, your local disk file system
+fileserver=kfs
+# replace FACEDOM with the local domain to be used in the faces database
+facedom=FACEDOM
+# replace CPU with the name of your cpu server
+cpu=CPU
diff --git a/rc/bin/thesaurus b/rc/bin/thesaurus
new file mode 100755
index 000000000..1f4707c5d
--- /dev/null
+++ b/rc/bin/thesaurus
@@ -0,0 +1,29 @@
+#!/bin/rc
+
+hget 'http://thesaurus.reference.com/search?q='^$1 |
+ htmlfmt -l 1000 |
+ sed -n '/^Main Entry:/,/^Source/ {
+ /^Source/ q
+ /^[A-Z].*:/ {
+ N
+ s/\n/ /g
+ }
+ p
+ }' | awk -F', ' '{
+ if(length($0)<=70){
+ print
+ next
+ }
+ l = 0
+ for(i = 1; i < NF; i++){
+ printf "%s ", $i
+ l += length($i)+1
+ if(l > 70){
+ printf "\n\t\t"
+ l = 2*ENVIRON["tabstop"]
+ }
+ }
+ if(l>0)
+ printf "\n"
+ next
+ }'
diff --git a/rc/bin/tlsclienttunnel b/rc/bin/tlsclienttunnel
new file mode 100755
index 000000000..0f76a4faa
--- /dev/null
+++ b/rc/bin/tlsclienttunnel
@@ -0,0 +1,7 @@
+#!/bin/rc
+
+if(! ~ $#* 3){
+ echo 'usage: tlsclienttunnel cryptaddr plainaddr cert.thumb' >[1=2]
+ exit usage
+}
+aux/listen1 -t $2 /bin/tlsclient -t $3 $1 &
diff --git a/rc/bin/tlssrvtunnel b/rc/bin/tlssrvtunnel
new file mode 100755
index 000000000..a9e79a658
--- /dev/null
+++ b/rc/bin/tlssrvtunnel
@@ -0,0 +1,7 @@
+#!/bin/rc
+
+if(! ~ $#* 3){
+ echo 'usage: tlssrvtunnel plainaddr cryptaddr cert.pem' >[1=2]
+ exit usage
+}
+aux/listen1 -tv $2 /bin/tlssrv -c $3 -llisten /bin/aux/trampoline $1 &
diff --git a/rc/bin/troff2gif b/rc/bin/troff2gif
new file mode 100755
index 000000000..4be4aca0f
--- /dev/null
+++ b/rc/bin/troff2gif
@@ -0,0 +1,2 @@
+#!/bin/rc
+{/bin/troff $*|/bin/lp -dstdout|/bin/gs -dNOPAUSE -dQUIET '-sOUTPUTFILE='/fd/1 '-sDEVICE=plan9bm' - quit.ps| crop -c 255 255 255 | togif} >[2] /dev/null
diff --git a/rc/bin/troff2png b/rc/bin/troff2png
new file mode 100755
index 000000000..1aca866c9
--- /dev/null
+++ b/rc/bin/troff2png
@@ -0,0 +1,9 @@
+#!/bin/rc
+
+troff -ms $* | aux/tr2post |
+ gs -g1000x1600 -r100 -dNOPAUSE -dQUIET \
+ '-dGraphicsAlphaBits=4' '-dTextAlphaBits=4' \
+ '-sOUTPUTFILE=-' '-sDEVICE=plan9' - quit.ps |
+ {crop -c 255 255 255; cat >/dev/null} |
+ topng
+
diff --git a/rc/bin/umem b/rc/bin/umem
new file mode 100755
index 000000000..2886b1aaa
--- /dev/null
+++ b/rc/bin/umem
@@ -0,0 +1,33 @@
+#!/bin/rc
+# umem pid [binary] - print summary of allocate blocks in a running process
+rfork e
+if(! ~ $#* 1 2){
+ echo 'usage: umem pid [binary]' >[1=2]
+ exit usage
+}
+
+p=$1
+binary=()
+if(~ $#* 2)
+ binary=$2
+
+echo 'blocksummary()' | acid -lpool -lleak $p $binary | awk '
+ $1 == "block" {
+ addr=$6
+ size=$3
+ alloc=$4
+ total[alloc] += size
+ count[alloc]++
+ }
+ $1 == "summary" {
+ alloc=$2
+ cnt=$3
+ size=$4
+ total[alloc] += size
+ count[alloc] += cnt
+ }
+ END{
+ for(i in count)
+ printf("%6d %11d %s\n", count[i], total[i], i);
+ }
+' | sort -nr
diff --git a/rc/bin/uncompress b/rc/bin/uncompress
new file mode 100755
index 000000000..8e228dcb7
--- /dev/null
+++ b/rc/bin/uncompress
@@ -0,0 +1,2 @@
+#!/bin/rc
+exec compress -d $*
diff --git a/rc/bin/ups b/rc/bin/ups
new file mode 100755
index 000000000..e1ad56ca6
--- /dev/null
+++ b/rc/bin/ups
@@ -0,0 +1,32 @@
+#!/bin/rc
+# ups - look up a UPS tracking number
+rfork en
+
+if(! ~ $#* 1) {
+ echo usage: ups 1ZA41W190338680961 >[1=2]
+ exit usage
+}
+
+hget 'http://wwwapps.ups.com/WebTracking/processInputRequest?tracknum='^$1^ \
+ '&TypeOfInquiryNumber=T' >/tmp/ups.1
+
+sed 's/<[Tt][Dd]>/& «TD»/g; s/<[Tt][Rr]>/& «TR» /g' /tmp/ups.1 |
+ htmlfmt >/tmp/ups.2
+sam -d /tmp/ups.2 >[2] /dev/null <<'!'
+/^Tracking results.*/p
+.,$d
+/Help/d
+1,.d
+$-2,$d
+/Status:/+1
+.,/«TR»/-2d
+,s/\n/ /g
+,s/«TR»/\n/g
+,s/«TD»/ /g
+,s/ * */ /g
+,s/^[ ]*//g
+,s/[ ]*$//g
+,s/\n\n+/\n\n/g
+,p
+!
+echo
diff --git a/rc/bin/uptime b/rc/bin/uptime
new file mode 100755
index 000000000..eba92367b
--- /dev/null
+++ b/rc/bin/uptime
@@ -0,0 +1,8 @@
+#!/bin/rc
+clock=`{cat /dev/time}
+xx=`{{echo $clock(3) / $clock(4); echo '_/86400'}|hoc|sed 's/^\./0./g;s/\..*//g'}
+sec=$xx(1)
+days=$xx(2)
+cat /dev/sysname
+echo -n ' up '$days' days, '
+timezone='MDT -21600' date $sec |awk '{print $4}'
diff --git a/rc/bin/usbeject b/rc/bin/usbeject
new file mode 100755
index 000000000..cae9d0394
--- /dev/null
+++ b/rc/bin/usbeject
@@ -0,0 +1,41 @@
+#!/bin/rc
+# usbeject - unmount usb disks given as arguments
+# unmount all of them if no arguments given
+rfork e
+disk = ()
+mtpt = /n/usb
+
+test -e /dev/fs/ctl || bind -b '#k' /dev >[2]/dev/null
+
+test -e /dev/usb || bind -a '#u' /dev || {
+ echo $0: no '#u/usb' >[1=2]
+ exit nousb
+}
+test -e /dev/usbdctl || mount -a /srv/usb /dev || {
+ echo $0: cannot mount /srv/usb >[1=2]
+ exit nousbd
+}
+
+disks=()
+mtpt=()
+switch ($#*) {
+case 0
+ disks=`{ls -pd /n/sdU*}
+case *
+ disks=()
+ for (a) {
+ if(~ $a sd??)
+ disk=`{ls -pd /n/^$*^*}
+ if not
+ disk=$a
+ disks=($disks $disk)
+ }
+}
+if (~ $disks '''sdU*''')
+ exit ''
+for (disk in $disks) {
+ unmount /n/$disk >[2]/dev/null && echo $disk unmounted
+ if (test -e /dev/fs/ctl)
+ echo del $disk^parts/^'*' >/dev/fs/ctl >[2]/dev/null
+}
+exit ''
diff --git a/rc/bin/usbstart b/rc/bin/usbstart
new file mode 100755
index 000000000..46d734cfa
--- /dev/null
+++ b/rc/bin/usbstart
@@ -0,0 +1,24 @@
+#!/bin/rc
+# usbstart - start appropriate usb flavour
+if(test -r '#u'/usb) {
+ if(! test -r /dev/usb)
+ bind -a '#u' /dev
+
+ # /boot/boot may have started usbd, which starts all usb drivers
+ if (! ps | grep -s ' usbd$')
+ usb/usbd
+}
+if not if(test -r '#U'/usb0) {
+ if(! test -r /dev/usb0)
+ bind -a '#U' /dev
+
+ # /boot/boot may have started usbd, usb/kb or usb/disk
+ if (! ps | grep -s ' usbd$')
+ usb/usbd
+ usb/usbmouse -a 2
+ if (! ps | grep -s ' kb$')
+ usb/kb -k
+ usb/usbaudio -s usbaudio.$sysname -V
+ # usb/print
+}
+exit ''
diff --git a/rc/bin/usps b/rc/bin/usps
new file mode 100755
index 000000000..7c7cf1921
--- /dev/null
+++ b/rc/bin/usps
@@ -0,0 +1,20 @@
+#!/bin/rc
+rfork en
+
+
+if(! ~ $#* 1) {
+ echo usage: usps 01601531218002685498 >[1=2]
+ exit usage
+}
+
+rfork e
+
+hget -p 'origTrackNum='^$1 http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do |
+ htmlfmt > /tmp/usps.$pid
+
+sam -d /tmp/usps.$pid >[2] /dev/null <<'!'
+0,/Label/-1d
+/^Enter Label/,$d
+,p
+!
+rm /tmp/usps.$pid
diff --git a/rc/bin/vwhois b/rc/bin/vwhois
new file mode 100755
index 000000000..ff8c04fb9
--- /dev/null
+++ b/rc/bin/vwhois
@@ -0,0 +1,17 @@
+#!/bin/rc
+
+rfork e
+
+box=mbox
+if(! test -d /mail/fs/$box)
+ box=`{ls -p /mail/fs | grep -v ctl | sed 1q}
+if(~ $#box 0)
+ box=mbox # we tried
+
+if(~ $#box 1 && test -f /mnt/plumb/seemail || test -f /mnt/term/mnt/plumb/seemail){
+ for(i)
+ plumb -dseemail -a 'filetype=vwhois digest='$i.$pid' mailtype=new sender='$i /mail/fs/$box/XXXvwhois
+}
+if not for (i){
+ echo vwhois: vwhois: vwhois: delivered `{cat /dev/user} From $i '(vwho)' >> /sys/log/mail
+}
diff --git a/rc/bin/wdoc2txt b/rc/bin/wdoc2txt
new file mode 100755
index 000000000..bfb31fd93
--- /dev/null
+++ b/rc/bin/wdoc2txt
@@ -0,0 +1,17 @@
+#!/bin/rc
+
+switch($#*){
+case 0
+ exit
+case 1
+ switch($1){
+ case *.rtf
+ pub/rtf2text $1 >[2]/dev/null | plumb -i -d edit -a 'action=showdata filename='$1
+ case *.doc *
+ doc2txt $1 | plumb -i -d edit -a 'action=showdata filename='$1
+ }
+ exit
+case *
+ for(i in *)
+ wdoc2txt $i
+}
diff --git a/rc/bin/weather b/rc/bin/weather
new file mode 100755
index 000000000..5261495bf
--- /dev/null
+++ b/rc/bin/weather
@@ -0,0 +1,46 @@
+#!/bin/rc
+
+rfork e
+
+DEFAULT=ewr
+
+fn usage{
+ echo 'usage: weather 3-letter-city-code' >[1=2]
+ echo 'for a list of cities in new york, say' >[1=2]
+ echo ' weather ny' >[1=2]
+ exit usage
+}
+
+switch($#*){
+case 0
+ arg=$DEFAULT
+ if(~ $#weather 1)
+ arg=$weather
+case 1
+ arg=$1
+case *
+ usage
+}
+
+switch($arg){
+case [a-zA-Z][a-zA-Z][a-zA-Z]
+ script=('' '' 'C' '4' '1' '1' $arg '' '' '' '' 'X')
+case [a-zA-Z][a-zA-Z]
+ script=('' '' 'C' '4' '1' '3' $arg '' '' '' '' 'X')
+case *
+ usage
+}
+
+{
+ for(i in $script)
+ echo $i
+} |
+con -nrl tcp!rainmaker.wunderground.com!telnet |
+sed -n '/Enter .-letter .* code:/,/CITY FORECAST MENU/p' |
+sed 's/Enter .-letter .* code: //' |
+sed 's/ Press Return to continue, M to return to menu, X to exit: //' |
+grep -v 'CITY FORECAST MENU' |
+tr -d '
' |
+sed 's/ *$//' |
+uniq
+
diff --git a/rc/bin/who b/rc/bin/who
new file mode 100755
index 000000000..a85441637
--- /dev/null
+++ b/rc/bin/who
@@ -0,0 +1,4 @@
+#!/bin/rc
+ps | sed '/Broken/d
+/Exiting/d
+s% .*$%%' | sort -u
diff --git a/rc/bin/whois b/rc/bin/whois
new file mode 100755
index 000000000..8308e4b60
--- /dev/null
+++ b/rc/bin/whois
@@ -0,0 +1,9 @@
+#!/bin/rc
+
+for(i in $*)
+ grep '^'$i' ' /adm/whois ||
+ grep -i $i /adm/keys.who ||
+ grep -i $i /adm/netkeys.who ||
+ grep -i $i /adm/whois ||
+ grep -i $i /adm/users ||
+ echo who indeed is $i
diff --git a/rc/bin/window b/rc/bin/window
new file mode 100755
index 000000000..e6dce9262
--- /dev/null
+++ b/rc/bin/window
@@ -0,0 +1,100 @@
+#!/bin/rc
+# window [many options] cmd [arg...] - create new window and run cmd in it
+rfork e
+fn checkwsys{
+ if(~ $wsys ''){
+ echo 'window: $wsys not defined'
+ exit bad
+ }
+}
+
+# original version used mount to do the work
+fn oldway{
+ switch($#*){
+ case 0 1
+ echo usage: window '''minx miny maxx maxy''' cmd args ...
+ exit usage
+ }
+
+ checkwsys
+
+ dir = /mnt/wsys
+ srv = $wsys
+
+ rfork ne
+ {
+ if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
+ shift
+ bind -b $dir /dev
+ echo -n `{basename $1} > /dev/label >[2] /dev/null
+ exec $* < /dev/cons > /dev/cons >[2] /dev/cons
+ }
+ }&
+}
+
+# if argument is of form '100 100 200 200' or '100,100,200,200' use old way
+if(~ $1 *[0-9][' ,'][0-9]*){
+ oldway $*
+ exit
+}
+
+# geometry parameters are:
+# -r 0 0 100 100
+# -dx n
+# -dy n
+# -minx n
+# -miny n
+# -maxx n
+# -maxy n
+# where n can be a number, to set the value, or +number or -number to change it
+
+# find wctl file
+fn getwctl{
+ if(~ $wctl ''){
+ if(test -f /dev/wctl) echo /dev/wctl
+ if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
+ if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
+ if not {
+ echo window: '$wctl' not defined >[1=2]
+ exit usage
+ }
+ }
+ if not echo $wctl
+}
+
+# use mount to make local window
+if(~ $1 -m){
+ shift
+
+ checkwsys
+
+ dir = /mnt/wsys
+ srv = $wsys
+ rfork ne
+ {
+ unmount /mnt/acme /dev >[2]/dev/null
+ if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
+ bind -b $dir /dev
+ # toss geometry parameters to find command
+ while(~ $1 -*)
+ switch($1){
+ case -dx -dy -minx -miny -maxx -maxy
+ shift 2
+ case -r
+ shift 5
+ case -scroll
+ shift
+ case -noscroll
+ shift
+ case -hide
+ shift
+ }
+ if(~ $#* 0) cmd = rc
+ if not cmd = $*
+ echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
+ exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
+ }
+ }&
+}
+
+if not echo new -cd `{pwd} $* >> `{getwctl}
diff --git a/rc/bin/wloc b/rc/bin/wloc
new file mode 100755
index 000000000..cd743d2ae
--- /dev/null
+++ b/rc/bin/wloc
@@ -0,0 +1,10 @@
+#!/bin/rc
+
+rfork e
+ifs='
+'
+
+for(i in `{ls /dev/wsys}) {
+ echo window -r `{syscall -o read 0 buf 59 < $i/window >[2] /dev/null |
+ sed 's/............//; s/^ *//; s/ */ /g'} `{cat $i/label}
+}
diff --git a/rc/bin/wurl2txt b/rc/bin/wurl2txt
new file mode 100755
index 000000000..19dad7b6f
--- /dev/null
+++ b/rc/bin/wurl2txt
@@ -0,0 +1,15 @@
+#!/bin/rc
+
+switch($#*){
+case 0
+ exit
+case 1
+ name = /`{echo $1 | sed 's;.*//;;
+ s;/.*;;'}^/webpage
+ # send hget errors to 2 so they appear in window
+ hget $1 >[2=1]| {echo $1; echo; htmlfmt} >[2=1] | plumb -i -d edit -a 'action=showdata filename='$name
+ exit
+case *
+ for(i in *)
+ wurl2txt $i
+}
diff --git a/rc/bin/xls2txt b/rc/bin/xls2txt
new file mode 100755
index 000000000..9d72c238b
--- /dev/null
+++ b/rc/bin/xls2txt
@@ -0,0 +1,32 @@
+#!/bin/rc
+
+rfork en
+
+if(! ~ $#* 0 1) {
+ echo 'usage: xls2txt [file.xls]' >[1=2]
+ exit usage
+}
+
+switch($#*){
+case 0
+ cat >/tmp/xls2txt.$pid
+ file=/tmp/xls2txt.$pid
+case 1
+ file=$1
+}
+aux/olefs $file || {
+ echo 'xls2txt: couldn''t mount excel document' >[1=2]
+ rm -f /tmp/xls2txt.$pid
+ exit word
+}
+
+if(! test -f /mnt/doc/Workbook) {
+ echo 'xls2txt: is an MSoffice doc but not an Excel document' >[1=2]
+ rm -f /tmp/xls2txt.$pid
+ exit wordxls
+}
+
+aux/msexceltables /mnt/doc/Workbook
+unmount /mnt/doc
+rm -f /tmp/xls2txt.$pid
+
diff --git a/rc/bin/yesterday b/rc/bin/yesterday
new file mode 100755
index 000000000..0daad30c9
--- /dev/null
+++ b/rc/bin/yesterday
@@ -0,0 +1,157 @@
+#!/bin/rc
+
+rfork e
+
+
+smon='s/Jan/01/
+ s/Feb/02/
+ s/Mar/03/
+ s/Apr/04/
+ s/May/05/
+ s/Jun/06/
+ s/Jul/07/
+ s/Aug/08/
+ s/Sep/09/
+ s/Oct/10/
+ s/Nov/11/
+ s/Dec/12/'
+
+fn usage {
+ echo 'usage: yesterday [-abcCdDs] [-[[[yy]yy]mm]dd] [-n daysago] file ...' >[1=2]
+ exit 'usage'
+}
+
+fn Xcp {
+ echo cp $1 $2
+ cp $1 $2
+}
+
+fn Xdiff {
+ echo diff $1 $2
+ diff $1 $2
+}
+fn Xdiffn {
+ echo diff -n $1 $2
+ diff -n $1 $2
+}
+fn Xadiff {
+ echo /acme/bin/adiff $1 $2
+ /acme/bin/adiff $1 $2
+}
+
+fn Xcarefulcp {
+ if(! cmp -s $1 $2) Xcp $1 $2
+}
+
+fn Xecho {
+ echo $1
+}
+
+fn Xbind {
+ echo bind $1 $2
+ bind $1 $2
+}
+
+year=`{date|sed 's/.* //'}
+copy=Xecho
+last=()
+defdump=dump
+while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
+ switch($1){
+ case -a
+ copy=Xadiff
+ shift
+ case -b
+ copy=Xbind
+ shift
+ case -c
+ copy=Xcp
+ shift
+ case -d
+ copy=Xdiff
+ shift
+ case -D
+ copy=Xdiffn
+ shift
+ case -C
+ copy=Xcarefulcp
+ shift
+ case -s
+ defdump=snap
+ shift
+ case -n*
+ if(~ $1 -n){
+ if(~ $#* 1)
+ usage
+ shift
+ days=$1
+ }
+ if not
+ days=`{echo $1 | sed 's/^-.//'}
+ last=`{date `{hoc -e `{date -n} ^ '-'$days'*60*60*24'} | \
+ sed -e 's%... (...) (..) ..:..:.. ... (....)%\3/\1\2%' -e 'y/ /0/' -e $smon}
+ shift
+ case -?
+ mon=`{date|sed -e 's/^....(...).*/\1/' -e $smon}
+ last=$year/$mon ^`{echo $1|sed 's/^-/0/'}
+ shift
+ case -??
+ mon=`{date|sed -e 's/^....(...).*/\1/' -e $smon}
+ last=$year/$mon ^`{echo $1|sed 's/^-//'}
+ shift
+ case -????
+ last=$year/ ^ `{echo $1|sed 's/^-//'}
+ shift
+ case -??????
+ last=`{echo $year|sed 's/..$//'} ^ `{echo $1|sed 's/^-(..)/\1\//'}
+ shift
+ case -????????
+ last=`{echo $1|sed 's/^-(....)/\1\//'}
+ shift
+ case *
+ usage
+ }
+}
+if(! ~ $#* 0 && ~ $1 --)
+ shift
+
+if(~ $#* 0)
+ usage
+
+dir=`{pwd}
+if(! ~ $status ''){
+ echo 'yesterday: can''t find directory' >[1=2]
+ exit 'pwd failed'
+}
+
+for(i){
+ xpath=`{cleanname -d $dir -- $i}
+ xdump=$defdump
+ dumppath=$xpath
+ if(~ $xpath /n/*/*){
+ xdump=`{echo $xpath | sed 's:/n/([^/]+)/.*:\1'$defdump':'}
+ dumppath=`{echo $xpath | sed 's:/n/[^/]+(/.*):\1:'}
+ }
+ if(! test -e /n/$xdump/$year)
+ 9fs $xdump
+
+ if(~ $#last 0){
+ xlast=`{ls /n/$xdump/$year|sed -n '$p'}
+ switch($defdump){
+ case snap
+ xlast=`{ls $xlast|sed -n '$p'}
+ }
+ }
+ if not
+ xlast=/n/$xdump/$last
+
+ if(! test -e $xlast){
+ echo 'yesterday:' \
+ `{echo $xlast|sed 's/.n.'$defdump'.(....).(..)(..)/\1 \2 \3/'} \
+ 'is not a backup day for' $xdump >[1=2]
+ exit 'bad date'
+ }
+
+ $copy $xlast^$dumppath $xpath
+}
+exit ''
diff --git a/rc/lib/rcmain b/rc/lib/rcmain
new file mode 100755
index 000000000..44dd5670a
--- /dev/null
+++ b/rc/lib/rcmain
@@ -0,0 +1,34 @@
+# rcmain: Plan 9 version
+if(~ $#home 0) home=/
+if(~ $#ifs 0) ifs='
+'
+switch($#prompt){
+case 0
+ prompt=('% ' ' ')
+case 1
+ prompt=($prompt ' ')
+}
+if(~ $rcname ?.out) prompt=('broken! ' ' ')
+if(flag p) path=/bin
+if not{
+ finit
+ if(~ $#path 0) path=(. /bin)
+}
+fn sigexit
+if(! ~ $#cflag 0){
+ if(flag l && /bin/test -r $home/lib/profile) . $home/lib/profile
+ status=''
+ eval $cflag
+}
+if not if(flag i){
+ if(flag l && /bin/test -r $home/lib/profile) . $home/lib/profile
+ status=''
+ if(! ~ $#* 0) . $*
+ . -i '#d/0'
+}
+if not if(~ $#* 0) . '#d/0'
+if not{
+ status=''
+ . $*
+}
+exit $status
|