Browse Source

Plan 9 from Bell Labs 2006-02-13

David du Colombier 18 years ago
parent
commit
f1f3163a45

+ 12 - 14
dist/replica/_plan9.db

@@ -5399,7 +5399,7 @@ rc/bin/Kill - 775 sys sys 1018637942 115
 rc/bin/a: - 775 sys sys 1063856406 255
 rc/bin/ap - 775 sys sys 1123163734 733
 rc/bin/ape - 20000000775 sys sys 954039414 0
-rc/bin/ape/ar89 - 775 sys sys 945617285 308
+rc/bin/ape/ar89 - 775 sys sys 1139744263 240
 rc/bin/ape/c89 - 775 sys sys 945617285 39
 rc/bin/ape/chown - 775 sys sys 945617285 43
 rc/bin/ape/false - 775 sys sys 945617285 17
@@ -5411,7 +5411,7 @@ rc/bin/ape/ranlib - 775 sys sys 1099176402 18
 rc/bin/ape/rmdir - 775 sys sys 945617286 16
 rc/bin/ape/true - 775 sys sys 945617286 17
 rc/bin/ape/umask - 775 sys sys 945617286 34
-rc/bin/ape/yacc - 775 sys sys 945617286 205
+rc/bin/ape/yacc - 775 sys sys 1139744263 280
 rc/bin/b: - 775 sys sys 1015089510 204
 rc/bin/broke - 775 sys sys 945617206 132
 rc/bin/bundle - 775 sys sys 945617206 173
@@ -5440,9 +5440,9 @@ rc/bin/juke - 775 sys sys 1105565140 1131
 rc/bin/kill - 775 sys sys 1018387014 132
 rc/bin/label - 775 sys sys 945617207 34
 rc/bin/lc - 775 sys sys 945617207 24
-rc/bin/leak - 775 sys sys 1032057948 1005
+rc/bin/leak - 775 sys sys 1139744263 1052
 rc/bin/lookman - 775 sys sys 1017679344 686
-rc/bin/lp - 775 sys sys 962679927 5357
+rc/bin/lp - 775 sys sys 1139744262 5119
 rc/bin/mail - 775 sys sys 1045504003 138
 rc/bin/man - 775 sys sys 1138555265 2520
 rc/bin/map - 775 sys sys 945617207 1576
@@ -5742,7 +5742,7 @@ sys/games - 20000000775 sys sys 952648872 0
 sys/games/lib - 20000000775 sys sys 952648879 0
 sys/games/lib/4scores - 10000000664 sys sys 1118680448 0
 sys/games/lib/5scores - 10000000664 sys sys 1118680453 0
-sys/games/lib/fortunes - 664 sys sys 1138566736 257323
+sys/games/lib/fortunes - 664 sys sys 1139760252 257379
 sys/games/lib/mahjongg - 20000000775 sys sys 1095792278 0
 sys/games/lib/mahjongg/backgrounds - 20000000775 sys sys 1095792293 0
 sys/games/lib/mahjongg/backgrounds/default.bit - 664 sys sys 1095792293 346803
@@ -7405,7 +7405,7 @@ sys/man/2/access - 664 sys sys 1046657167 1102
 sys/man/2/addpt - 664 sys sys 958249501 2964
 sys/man/2/aes - 664 sys sys 1032058672 997
 sys/man/2/allocimage - 664 sys sys 1046787977 7304
-sys/man/2/arg - 664 sys sys 1030711189 2154
+sys/man/2/arg - 664 sys sys 1139744263 2184
 sys/man/2/arith3 - 664 sys sys 969499887 4397
 sys/man/2/assert - 664 sys sys 1102868467 377
 sys/man/2/atof - 664 sys sys 1015091517 2766
@@ -7695,6 +7695,7 @@ sys/man/8/drawterm - 664 sys sys 1135901219 1741
 sys/man/8/fossilcons - 664 sys sys 1138466274 18276
 sys/man/8/fs - 664 sys sys 1055701170 15029
 sys/man/8/fsconfig - 664 sys sys 1045501600 8142
+sys/man/8/getflags - 664 sys sys 1139744263 1703
 sys/man/8/gpsfs - 664 sys sys 1123643451 4924
 sys/man/8/httpd - 664 sys sys 1121198377 6675
 sys/man/8/init - 664 sys sys 944959679 1430
@@ -9626,6 +9627,7 @@ sys/src/cmd/aux/flashfs/mkit - 775 sys sys 1015009082 86
 sys/src/cmd/aux/flashfs/request.c - 664 sys sys 1019507619 5739
 sys/src/cmd/aux/flashfs/testld.c - 664 sys sys 1015009082 1043
 sys/src/cmd/aux/flashfs/utils.c - 664 sys sys 1135487936 1094
+sys/src/cmd/aux/getflags.c - 664 sys sys 1139744276 1360
 sys/src/cmd/aux/gps - 20000000775 sys sys 1107448949 0
 sys/src/cmd/aux/gps/dat.h - 664 sys sys 1107448949 287
 sys/src/cmd/aux/gps/gpsevermore.c - 664 sys sys 1107448815 4501
@@ -9636,7 +9638,7 @@ sys/src/cmd/aux/lines.c - 664 sys sys 1015008782 546
 sys/src/cmd/aux/lis - 775 sys sys 944960794 45
 sys/src/cmd/aux/listen.c - 664 sys sys 1122127534 8153
 sys/src/cmd/aux/listen1.c - 664 sys sys 1093452955 2018
-sys/src/cmd/aux/mkfile - 664 sys sys 1131110489 992
+sys/src/cmd/aux/mkfile - 664 sys sys 1139744302 1011
 sys/src/cmd/aux/mklatinkbd.c - 664 sys sys 953253425 3813
 sys/src/cmd/aux/mnihongo - 20000000775 sys sys 944960789 0
 sys/src/cmd/aux/mnihongo/README - 664 sys sys 944960789 475
@@ -9664,6 +9666,7 @@ sys/src/cmd/aux/timesync.c - 664 sys sys 1107448970 25758
 sys/src/cmd/aux/trampoline.c - 664 sys sys 1126104850 3790
 sys/src/cmd/aux/typepasswd.c - 664 sys sys 1014925091 1761
 sys/src/cmd/aux/unlock - 664 sys sys 944960793 0
+sys/src/cmd/aux/usage.c - 664 sys sys 1139744276 1095
 sys/src/cmd/aux/vga - 20000000775 sys sys 1018723175 0
 sys/src/cmd/aux/vga/3dfx.c - 664 sys sys 1026337537 6886
 sys/src/cmd/aux/vga/adventure - 664 sys sys 1048274168 14869
@@ -10179,11 +10182,6 @@ sys/src/cmd/fossil/vac.h - 664 sys sys 1061530727 2779
 sys/src/cmd/fossil/view.c - 664 sys sys 1089299187 19664
 sys/src/cmd/fossil/walk.c - 664 sys sys 1042005512 963
 sys/src/cmd/freq.c - 664 sys sys 1136378273 1728
-sys/src/cmd/getflags - 20000000775 sys sys 954036865 0
-sys/src/cmd/getflags/funcgetflags.c - 664 sys sys 944960998 4621
-sys/src/cmd/getflags/getflags.c - 664 sys sys 964540723 3621
-sys/src/cmd/getflags/getflags.h - 664 sys sys 944960998 272
-sys/src/cmd/getflags/mkfile - 664 sys sys 944960998 117
 sys/src/cmd/getmap.c - 664 sys sys 954468786 3290
 sys/src/cmd/grap - 20000000775 sys sys 944960999 0
 sys/src/cmd/grap/coord.c - 664 sys sys 944960999 1559
@@ -12514,7 +12512,7 @@ sys/src/cmd/look.c - 664 sys sys 944961619 5994
 sys/src/cmd/lp - 20000000775 sys sys 953344617 0
 sys/src/cmd/lp/LOCK.c - 664 sys sys 1015090023 1066
 sys/src/cmd/lp/ipcopen.c - 664 sys sys 944961017 1607
-sys/src/cmd/lp/lp.rc - 775 sys sys 1022050028 5357
+sys/src/cmd/lp/lp.rc - 775 sys sys 1139744263 5119
 sys/src/cmd/lp/lpdaemon.c - 664 sys sys 1032060412 10000
 sys/src/cmd/lp/lpdsend.c - 664 sys sys 1116770113 9583
 sys/src/cmd/lp/lpsend.c - 664 sys sys 1015090024 6180
@@ -13392,7 +13390,7 @@ sys/src/cmd/test.c - 664 sys sys 1079372543 5409
 sys/src/cmd/time.c - 664 sys sys 1014926662 1546
 sys/src/cmd/tlsclient.c - 664 sys sys 1024375149 1631
 sys/src/cmd/tlssrv.c - 664 sys sys 1134498997 3426
-sys/src/cmd/touch.c - 664 sys sys 1099760670 899
+sys/src/cmd/touch.c - 664 sys sys 1139758085 960
 sys/src/cmd/tprof.c - 664 sys sys 1124305452 2731
 sys/src/cmd/tr.c - 664 sys sys 944961464 6008
 sys/src/cmd/trace.c - 664 sys sys 1121367076 17928

+ 12 - 14
dist/replica/plan9.db

@@ -5399,7 +5399,7 @@ rc/bin/Kill - 775 sys sys 1018637942 115
 rc/bin/a: - 775 sys sys 1063856406 255
 rc/bin/ap - 775 sys sys 1123163734 733
 rc/bin/ape - 20000000775 sys sys 954039414 0
-rc/bin/ape/ar89 - 775 sys sys 945617285 308
+rc/bin/ape/ar89 - 775 sys sys 1139744263 240
 rc/bin/ape/c89 - 775 sys sys 945617285 39
 rc/bin/ape/chown - 775 sys sys 945617285 43
 rc/bin/ape/false - 775 sys sys 945617285 17
@@ -5411,7 +5411,7 @@ rc/bin/ape/ranlib - 775 sys sys 1099176402 18
 rc/bin/ape/rmdir - 775 sys sys 945617286 16
 rc/bin/ape/true - 775 sys sys 945617286 17
 rc/bin/ape/umask - 775 sys sys 945617286 34
-rc/bin/ape/yacc - 775 sys sys 945617286 205
+rc/bin/ape/yacc - 775 sys sys 1139744263 280
 rc/bin/b: - 775 sys sys 1015089510 204
 rc/bin/broke - 775 sys sys 945617206 132
 rc/bin/bundle - 775 sys sys 945617206 173
@@ -5440,9 +5440,9 @@ rc/bin/juke - 775 sys sys 1105565140 1131
 rc/bin/kill - 775 sys sys 1018387014 132
 rc/bin/label - 775 sys sys 945617207 34
 rc/bin/lc - 775 sys sys 945617207 24
-rc/bin/leak - 775 sys sys 1032057948 1005
+rc/bin/leak - 775 sys sys 1139744263 1052
 rc/bin/lookman - 775 sys sys 1017679344 686
-rc/bin/lp - 775 sys sys 962679927 5357
+rc/bin/lp - 775 sys sys 1139744262 5119
 rc/bin/mail - 775 sys sys 1045504003 138
 rc/bin/man - 775 sys sys 1138555265 2520
 rc/bin/map - 775 sys sys 945617207 1576
@@ -5742,7 +5742,7 @@ sys/games - 20000000775 sys sys 952648872 0
 sys/games/lib - 20000000775 sys sys 952648879 0
 sys/games/lib/4scores - 10000000664 sys sys 1118680448 0
 sys/games/lib/5scores - 10000000664 sys sys 1118680453 0
-sys/games/lib/fortunes - 664 sys sys 1138566736 257323
+sys/games/lib/fortunes - 664 sys sys 1139760252 257379
 sys/games/lib/mahjongg - 20000000775 sys sys 1095792278 0
 sys/games/lib/mahjongg/backgrounds - 20000000775 sys sys 1095792293 0
 sys/games/lib/mahjongg/backgrounds/default.bit - 664 sys sys 1095792293 346803
@@ -7405,7 +7405,7 @@ sys/man/2/access - 664 sys sys 1046657167 1102
 sys/man/2/addpt - 664 sys sys 958249501 2964
 sys/man/2/aes - 664 sys sys 1032058672 997
 sys/man/2/allocimage - 664 sys sys 1046787977 7304
-sys/man/2/arg - 664 sys sys 1030711189 2154
+sys/man/2/arg - 664 sys sys 1139744263 2184
 sys/man/2/arith3 - 664 sys sys 969499887 4397
 sys/man/2/assert - 664 sys sys 1102868467 377
 sys/man/2/atof - 664 sys sys 1015091517 2766
@@ -7695,6 +7695,7 @@ sys/man/8/drawterm - 664 sys sys 1135901219 1741
 sys/man/8/fossilcons - 664 sys sys 1138466274 18276
 sys/man/8/fs - 664 sys sys 1055701170 15029
 sys/man/8/fsconfig - 664 sys sys 1045501600 8142
+sys/man/8/getflags - 664 sys sys 1139744263 1703
 sys/man/8/gpsfs - 664 sys sys 1123643451 4924
 sys/man/8/httpd - 664 sys sys 1121198377 6675
 sys/man/8/init - 664 sys sys 944959679 1430
@@ -9626,6 +9627,7 @@ sys/src/cmd/aux/flashfs/mkit - 775 sys sys 1015009082 86
 sys/src/cmd/aux/flashfs/request.c - 664 sys sys 1019507619 5739
 sys/src/cmd/aux/flashfs/testld.c - 664 sys sys 1015009082 1043
 sys/src/cmd/aux/flashfs/utils.c - 664 sys sys 1135487936 1094
+sys/src/cmd/aux/getflags.c - 664 sys sys 1139744276 1360
 sys/src/cmd/aux/gps - 20000000775 sys sys 1107448949 0
 sys/src/cmd/aux/gps/dat.h - 664 sys sys 1107448949 287
 sys/src/cmd/aux/gps/gpsevermore.c - 664 sys sys 1107448815 4501
@@ -9636,7 +9638,7 @@ sys/src/cmd/aux/lines.c - 664 sys sys 1015008782 546
 sys/src/cmd/aux/lis - 775 sys sys 944960794 45
 sys/src/cmd/aux/listen.c - 664 sys sys 1122127534 8153
 sys/src/cmd/aux/listen1.c - 664 sys sys 1093452955 2018
-sys/src/cmd/aux/mkfile - 664 sys sys 1131110489 992
+sys/src/cmd/aux/mkfile - 664 sys sys 1139744302 1011
 sys/src/cmd/aux/mklatinkbd.c - 664 sys sys 953253425 3813
 sys/src/cmd/aux/mnihongo - 20000000775 sys sys 944960789 0
 sys/src/cmd/aux/mnihongo/README - 664 sys sys 944960789 475
@@ -9664,6 +9666,7 @@ sys/src/cmd/aux/timesync.c - 664 sys sys 1107448970 25758
 sys/src/cmd/aux/trampoline.c - 664 sys sys 1126104850 3790
 sys/src/cmd/aux/typepasswd.c - 664 sys sys 1014925091 1761
 sys/src/cmd/aux/unlock - 664 sys sys 944960793 0
+sys/src/cmd/aux/usage.c - 664 sys sys 1139744276 1095
 sys/src/cmd/aux/vga - 20000000775 sys sys 1018723175 0
 sys/src/cmd/aux/vga/3dfx.c - 664 sys sys 1026337537 6886
 sys/src/cmd/aux/vga/adventure - 664 sys sys 1048274168 14869
@@ -10179,11 +10182,6 @@ sys/src/cmd/fossil/vac.h - 664 sys sys 1061530727 2779
 sys/src/cmd/fossil/view.c - 664 sys sys 1089299187 19664
 sys/src/cmd/fossil/walk.c - 664 sys sys 1042005512 963
 sys/src/cmd/freq.c - 664 sys sys 1136378273 1728
-sys/src/cmd/getflags - 20000000775 sys sys 954036865 0
-sys/src/cmd/getflags/funcgetflags.c - 664 sys sys 944960998 4621
-sys/src/cmd/getflags/getflags.c - 664 sys sys 964540723 3621
-sys/src/cmd/getflags/getflags.h - 664 sys sys 944960998 272
-sys/src/cmd/getflags/mkfile - 664 sys sys 944960998 117
 sys/src/cmd/getmap.c - 664 sys sys 954468786 3290
 sys/src/cmd/grap - 20000000775 sys sys 944960999 0
 sys/src/cmd/grap/coord.c - 664 sys sys 944960999 1559
@@ -12514,7 +12512,7 @@ sys/src/cmd/look.c - 664 sys sys 944961619 5994
 sys/src/cmd/lp - 20000000775 sys sys 953344617 0
 sys/src/cmd/lp/LOCK.c - 664 sys sys 1015090023 1066
 sys/src/cmd/lp/ipcopen.c - 664 sys sys 944961017 1607
-sys/src/cmd/lp/lp.rc - 775 sys sys 1022050028 5357
+sys/src/cmd/lp/lp.rc - 775 sys sys 1139744263 5119
 sys/src/cmd/lp/lpdaemon.c - 664 sys sys 1032060412 10000
 sys/src/cmd/lp/lpdsend.c - 664 sys sys 1116770113 9583
 sys/src/cmd/lp/lpsend.c - 664 sys sys 1015090024 6180
@@ -13392,7 +13390,7 @@ sys/src/cmd/test.c - 664 sys sys 1079372543 5409
 sys/src/cmd/time.c - 664 sys sys 1014926662 1546
 sys/src/cmd/tlsclient.c - 664 sys sys 1024375149 1631
 sys/src/cmd/tlssrv.c - 664 sys sys 1134498997 3426
-sys/src/cmd/touch.c - 664 sys sys 1099760670 899
+sys/src/cmd/touch.c - 664 sys sys 1139758085 960
 sys/src/cmd/tprof.c - 664 sys sys 1124305452 2731
 sys/src/cmd/tr.c - 664 sys sys 944961464 6008
 sys/src/cmd/trace.c - 664 sys sys 1121367076 17928

+ 18 - 0
dist/replica/plan9.log

@@ -27571,3 +27571,21 @@
 1139691689 0 c sys/man/1/grep - 664 sys sys 1139690020 2257
 1139691689 1 c sys/src/ape/lib/ap/syscall/mkfile - 664 sys sys 1139690286 2667
 1139700692 0 c sys/src/cmd/upas/smtp/spam.c - 664 sys sys 1139699502 10238
+1139745706 0 c rc/bin/ape/ar89 - 775 sys sys 1139744263 240
+1139745706 1 c rc/bin/ape/yacc - 775 sys sys 1139744263 280
+1139745706 2 c rc/bin/leak - 775 sys sys 1139744263 1052
+1139745706 3 c rc/bin/lp - 775 sys sys 1139744262 5119
+1139745706 4 c sys/man/2/arg - 664 sys sys 1139744263 2184
+1139745706 5 a sys/man/8/getflags - 664 sys sys 1139744263 1703
+1139745706 6 a sys/src/cmd/aux/getflags.c - 664 sys sys 1139744276 1360
+1139745706 7 c sys/src/cmd/aux/mkfile - 664 sys sys 1139744302 1011
+1139745706 8 a sys/src/cmd/aux/usage.c - 664 sys sys 1139744276 1095
+1139745706 9 c sys/src/cmd/lp/lp.rc - 775 sys sys 1139744263 5119
+1139745706 10 c sys/src/cmd/touch.c - 664 sys sys 1139744317 964
+1139745706 11 d sys/src/cmd/getflags/mkfile - 664 sys sys 944960998 0
+1139745706 12 d sys/src/cmd/getflags/getflags.h - 664 sys sys 944960998 0
+1139745706 13 d sys/src/cmd/getflags/getflags.c - 664 sys sys 964540723 0
+1139745706 14 d sys/src/cmd/getflags/funcgetflags.c - 664 sys sys 944960998 0
+1139745706 15 d sys/src/cmd/getflags - 20000000775 sys sys 954036865 0
+1139758310 0 c sys/src/cmd/touch.c - 664 sys sys 1139758085 960
+1139761911 0 c sys/games/lib/fortunes - 664 sys sys 1139760252 257379

+ 11 - 9
rc/bin/ape/ar89

@@ -1,13 +1,15 @@
 #!/bin/rc
-ifs='' eval `{getflags cdprtxuv $*}
+
+flagfmt='c,d,p,r,t,u,v,x'
+args='archive [files ...]'
+
+if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0) {
+	aux/usage
+	exit usage
+}
 
 key=''
-if (~ $#FLAGc 1) key=$key^c
-if (~ $#FLAGd 1) key=$key^d
-if (~ $#FLAGp 1) key=$key^p
-if (~ $#FLAGr 1) key=$key^r
-if (~ $#FLAGt 1) key=$key^t
-if (~ $#FLAGx 1) key=$key^x
-if (~ $#FLAGu 1) key=$key^u
-if (~ $#FLAGv 1) key=$key^v
+for(i in c d p r t x u v)
+	if(f=flag$i ~ $#$f 1)
+		key=$key$i
 exec /$cputype/bin/ar $key $*

+ 13 - 5
rc/bin/ape/yacc

@@ -1,8 +1,16 @@
 #!/bin/rc
-# ifs='' eval `{getflags dltvb:1p:1 $*}
+
+flagfmt='d,l,t,v,b stem'
+args='grammar'
+
+if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 1){
+	aux/usage
+	exit usage
+}
+
 y=-S
-#if (~ $#FLAGd 1) y=($y -d)
-#if (~ $#FLAGt 1) y=($y -D2)
-#if (~ $#FLAGv 1) y=($y -v)
-#if (~ $#FLAGb 1) y=($y -s $FLAGb)
+if (~ $#flagb 1) y=($y -s $flagb)
+if (~ $#flagd 1) y=($y -d)
+if (~ $#flagt 1) y=($y -D2)
+if (~ $#flagv 1) y=($y -v)
 exec /$cputype/bin/yacc $y $*

+ 33 - 37
rc/bin/leak

@@ -2,36 +2,31 @@
 
 rfork e
 
-usage='prog-or-pid'
-FLAGs=()
-FLAGb=()
-FLAGr=()
-FLAGx=()
-eval `{aux/getflags bsx:1r:1f:1 $*}
-
-if(~ $#* 0) {
-	echo 'usage: leak [-s] [-f binary] [-b [-r res] [-x width]] '$usage >[1=2]
+flagfmt='b,s,f binary,r res,x width'
+args='name | pid list'
+if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
+	aux/usage
 	exit usage
 }
 
-sflag=()
-xflag=()
-if(~ $#FLAGs 1)
-	sflag=($sflag -s)
-if(~ $#FLAGf 1)
-	sflag=($sflag -f $FLAGf)
-if(~ $#FLAGb 1)
-	xflag=($xflag -b)
-if(~ $#FLAGr 1)
-	xflag=($xflag -r $FLAGr)
-if(~ $#FLAGx 1)
-	xflag=($xflag -x $FLAGx)
-
-if(~ $#FLAGs 1 && ~ $#FLAGb 1){
-	echo 'cannot use both -s and -b' >[1=2]
+if(~ $#flags 1 && ~ $#flagb 1){
+	echo 'cannot use both -b and -s' >[1=2]
 	exit usage
 }
 
+leakflags=()
+if(~ $#flags 1)
+	leakflags=($leakflags -s)
+if(~ $#flagf 1)
+	leakflags=($leakflags -f $flagf)
+
+acidleakflags=()
+if(~ $#flagb 1)
+	acidleakflags=($acidleakflags -b)
+if(~ $#flagr 1)
+	acidleakflags=($acidleakflags -r $flagr)
+if(~ $#flagx 1)
+	acidleakflags=($acidleakflags -x $flagx)
 
 if(! test -d /proc/$1) {
 	# x=`{psu | awk '$NF=="'$1'" {print $2}'}
@@ -40,19 +35,20 @@ if(! test -d /proc/$1) {
 		echo 'no processes named '$1 >[1=2]
 		exit usage
 	}
-	x=($sflag $xflag $x)
-	echo leak $"x
+	echo leak $leakflags $acidleakflags $x
 	exit
 }
 
-x=`{echo $"* | tr ' ' ,}
-
-echo 'leakdump({'$x'})' | acid -lpool -lleak $1 $FLAGf | aux/acidleak $xflag $binary |
-{
-	if(~ $#FLAGs 1)
-		awk '{print $4}' |
-			sort | uniq -c | sort -nr |
-			sed 's! *(.*) (0x.*)!src(\2); // \1!'
-	if not
-		cat
-}
+pidlist=`{echo $"* | tr ' ' ,}
+
+echo 'leakdump({'$pidlist'})' | 
+	acid -lpool -lleak $1 $flagf | 
+	aux/acidleak $acidleakflags $flagf |
+	{
+		if(~ $#flags 1)
+			awk '{print $4}' |
+				sort | uniq -c | sort -nr |
+				sed 's! *(.*) (0x.*)!src(\2); // \1!'
+		if not
+			cat
+	}

+ 58 - 54
rc/bin/lp

@@ -33,8 +33,12 @@ USAGE='usage:	lp [-d printer] [-p process] [options] [files]
 		lp [-d printer] -k jobnos
 
 		options include:
-		-H		no header
-		-L		landscape mode
+		-D			turn on debugging output
+		-H			no header
+		-L			landscape mode
+		-M<mach>	print on machine <mach>
+		-Q			put task only into the queue
+		-R			restart printer daemon
 		-c<n>		make <n> copies
 		-f<font.size>	specify font and size
 		-i<src>		take media from <src> input bin
@@ -42,9 +46,12 @@ USAGE='usage:	lp [-d printer] [-p process] [options] [files]
 		-m<n>		magnify <n> times
 		-n<n>		print <n> logical pages per physical page
 		-o<i-j,k>	print only pages i-j and k
-		-r		reverse pages
+		-r			reverse pages
+		-u<userid>	print as <userid>
 		-x<n>		x page offset in inches
-		-y<n>		y page offset in inches'
+		-y<n>		y page offset in inches
+'
+
 # umask 000	# this doesn't work in plan 9
 if (~ $#sysname 0)
 	THIS_HOST=plan9
@@ -63,67 +70,64 @@ LPLOC=''
 if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
 
 # option parameters
-XOFF=''
-YOFF=''
-POINT=''
+COPIES=1
 FONT=''
-LINES=''
+IBIN=''
+KILLFLAG=0
 LAND=''
-COPIES=''
+LINES=''
+LPQ=0
 MAG=''
+NOHEAD=''
 NPAG=''
 OLIST=''
-IBIN=''
+POINT=''
+RESET=''
 REVERSE=''
-NOHEAD=''
+QONLY=''
 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=()
+XOFF=''
+YOFF=''
+
 # Process options
-eval `{aux/getflags DHLM:1QRc: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 (! ~ $#FLAGR 0) RESET=1; if not RESET=''
-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
-	}
+flagfmt='D,H,L,Q,R,r,q,c copies,d printer,f font.size,i src,k jobnos,l lines,m magnify,n lpages,o pages,u userid,x offset,y offset'
+argv0=lp
+
+if(! ifs=() eval `{aux/getflags $*}) {
+	echo $USAGE
+	exit usage
 }
-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) OLIST=-o$FLAGo
-if (! ~ $#FLAGp 0) {
-	switch (FLAGp) {
-	case '?';exec ls $LPLIB/process
-	case *;	LPPROC=$FLAGp
-	}
+if(~ $flagd '?'){
+	awk 'BEGIN{printf "device       location  host                 class\n"}
+			/^[^#]/	{printf "%-12s %-9s %-20s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
+	exit
 }
-if (! ~ $#FLAGq 0) LPQ=1; if not LPQ=0
-if (! ~ $#FLAGr 0) {
-	switch ($REVERSE) {
-	case '';REVERSE=1
-	case 1;	REVERSE=''
-	}
+if(~ $flagp '?'){
+	ls $LPLIB/process
+	exit
 }
-if (! ~ $#FLAGt 0) TRAY=$FLAGt
-# originating user id
-if (! ~ $#FLAGu 0) LPUSERID=$FLAGu
-if (! ~ $#FLAGx 0) XOFF=$FLAGx
-if (! ~ $#FLAGy 0) YOFF=$FLAGy
+
+if (! ~ $#flagD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - }
+if (! ~ $#flagH 0) NOHEAD=1
+if (! ~ $#flagL 0) LAND=1
+if (! ~ $#flagM 0 && ~ $LPUSERID daemon) LPMACHID=$flagM
+if (! ~ $#flagQ 0) QONLY=1
+if (! ~ $#flagR 0) RESET=1
+if (! ~ $#flagc 0) COPIES=$flagc
+if(! ~ $#flagd 0) 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 (! ~ $#flagl 0) LINES=$flagl
+if (! ~ $#flagm 0) MAG=$flagm
+if (! ~ $#flagn 0) NPAG=$flagn
+if (! ~ $#flago 0) OLIST=-o^$flago
+if (! ~ $#flagp 0) LPPROC=$flagp
+if (! ~ $#flagq 0) LPQ=1
+if (! ~ $#flagr 0) REVERSE=1
+if (! ~ $#flagu 0) LPUSERID=$flagu
+if (! ~ $#flagx 0) XOFF=$flagx
+if (! ~ $#flagy 0) YOFF=$flagy
 
 if (~ $#LPDEST 0) {
 	echo 'Set environment variable LPDEST or use the

+ 1 - 0
sys/games/lib/fortunes

@@ -4102,3 +4102,4 @@ Google does not appear to be in the kludge-making business ...  - Ashlee Vance,
 Revision control is like any other form of accountancy -- worthy but dull. -forsyth
 There are but 10 types of people in the world. Those who understand the binary numbering system and those who don't.
 we live in a world of dogmas, probably trying to fight it with a stronger dogma is a bad idea, but trying to fight it with preumpted objectivism clearly doesn't work.  - uriel
+Equations are the devil's sentences.  - Stephen Colbert

+ 2 - 0
sys/man/2/arg

@@ -122,3 +122,5 @@ prog -b -f(file1) badflag('r') -f(file2) 2 args: 'arg1' 'arg2'
 .PP
 .SH SOURCE
 .B /sys/include/libc.h
+.SH SEE ALSO
+.IR getflags (8)

+ 71 - 0
sys/man/8/getflags

@@ -0,0 +1,71 @@
+.TH GETFLAGS 8
+getflags, usage \- command-line parsing for shell scripts
+.SH SYNOPSIS
+.B aux/getflags $*
+.PP
+.B aux/usage
+.SH DESCRIPTION
+.I Getflags
+parses the options in its command-line arguments
+according to the environment variable
+.BR $flagfmt .
+This variable should be a list of comma-separated options.
+Each option can be a single letter, indicating that it does
+not take arguments, or a letter followed by the space-separated
+names of its arguments.
+.I Getflags 
+prints an 
+.I rc (1)
+script on standard output which initializes the
+environment variable
+.BI $flag x
+for every option mentioned in 
+.BR $flagfmt .
+If the option is not present on the command-line, the script
+sets that option's flag variable to an empty list.
+Otherwise, the script sets that option's flag variable with
+a list containing the option's arguments or, 
+if the option takes no arguments,
+with the string
+.BR 1 .
+The script also sets the variable
+.B $*
+to the list of arguments following the options.
+The final line in the script sets the
+.B $status
+variable, to the empty string on success
+and to the string
+.B usage
+when there is an error parsing the command line.
+.PP
+.I Usage
+prints a usage message to standard error.
+It creates the message using
+.BR $flagfmt ,
+as described above,
+.BR $args ,
+which should contain the string to be printed explaining
+non-option arguments,
+and
+.BR $0 ,
+the program name
+(see
+.IR rc (1)).
+.SH EXAMPLE
+Parse the arguments for
+.IR leak (1):
+.IP
+.EX
+flagfmt='b,s,f binary,r res,x width'
+args='name | pid list'
+if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
+	aux/usage
+	exit usage
+}
+.EE
+.SH SOURCE
+.B /sys/src/cmd/aux/getflags.c
+.PP
+.B /sys/src/cmd/aux/usage.c
+.SH SEE ALSO
+.IR arg (2)

+ 82 - 0
sys/src/cmd/aux/getflags.c

@@ -0,0 +1,82 @@
+#include <u.h>
+#include <libc.h>
+
+void
+usage(void)
+{
+	print("status=usage\n");
+	exits(0);
+}
+
+char*
+findarg(char *flags, Rune r)
+{
+	char *p;
+	Rune rr;
+	
+	for(p=flags; p!=(char*)1; p=strchr(p, ',')+1){
+		chartorune(&rr, p);
+		if(rr == r)
+			return p;
+	}
+	return nil;	
+}
+
+int
+countargs(char *p)
+{
+	int n;
+
+	n = 1;
+	while(*p == ' ')
+		p++;
+	for(; *p && *p != ','; p++)
+		if(*p == ' ' && *(p-1) != ' ')
+			n++;
+	return n;
+}
+
+void
+main(int argc, char *argv[])
+{
+	char *flags, *p, buf[512];
+	int i, n;
+	Fmt fmt;
+	
+	quotefmtinstall();
+	argv0 = argv[0];	/* for sysfatal */
+	
+	flags = getenv("flagfmt");
+	if(flags == nil){
+		fprint(2, "$flagfmt not set\n");
+		print("exit 'missing flagfmt'");
+		exits(0);
+	}
+
+	fmtfdinit(&fmt, 1, buf, sizeof buf);
+	for(p=flags; p!=(char*)1; p=strchr(p, ',')+1)
+		fmtprint(&fmt, "flag%.1s=()\n", p);
+	ARGBEGIN{
+	default:
+		if((p = findarg(flags, ARGC())) == nil)
+			usage();
+		p += runelen(ARGC());
+		if(*p == ',' || *p == 0){
+			fmtprint(&fmt, "flag%C=1\n", ARGC());
+			break;
+		}
+		n = countargs(p);
+		fmtprint(&fmt, "flag%C=(", ARGC());
+		for(i=0; i<n; i++)
+			fmtprint(&fmt, "%s%q", i ? " " : "", EARGF(usage()));
+		fmtprint(&fmt, ")\n");
+	}ARGEND
+	
+	fmtprint(&fmt, "*=(");
+	for(i=0; i<argc; i++)
+		fmtprint(&fmt, "%s%q", i ? " " : "", argv[i]);
+	fmtprint(&fmt, ")\n");
+	fmtprint(&fmt, "status=''\n");
+	fmtfdflush(&fmt);
+	exits(0);
+}

+ 2 - 0
sys/src/cmd/aux/mkfile

@@ -12,6 +12,7 @@ TARG=\
 	data2s\
 	depend\
 	disksim\
+	getflags\
 	lines\
 	listen\
 	listen1\
@@ -32,6 +33,7 @@ TARG=\
 	timesync\
 	trampoline\
 	typepasswd\
+	usage\
 	write\
 	zerotrunc\
 

+ 66 - 0
sys/src/cmd/aux/usage.c

@@ -0,0 +1,66 @@
+#include <u.h>
+#include <libc.h>
+
+void
+main(void)
+{
+	Fmt fmt;
+	char buf[512];
+	char *argv0, *args, *flags, *p, *p0;
+	int single;
+	Rune r;
+	
+	argv0 = getenv("0");
+	if((p = strrchr(argv0, '/')) != nil)
+		argv0 = p+1;
+	flags = getenv("flagfmt");
+	args = getenv("args");
+	
+	if(argv0 == nil){
+		fprint(2, "aux/usage: $0 not set\n");
+		exits("$0");
+	}
+	if(flags == nil)
+		flags = "";
+	if(args == nil)
+		args = "";
+
+	fmtfdinit(&fmt, 2, buf, sizeof buf);
+	fmtprint(&fmt, "usage: %s", argv0);
+	if(flags[0]){
+		single = 0;
+		for(p=flags; *p; ){
+			p += chartorune(&r, p);
+			if(*p == ',' || *p == 0){
+				if(!single){
+					fmtprint(&fmt, " [-");
+					single = 1;
+				}
+				fmtprint(&fmt, "%C", r);
+				if(*p == ',')
+					p++;
+				continue;
+			}
+			while(*p == ' ')
+				p++;
+			if(single){
+				fmtprint(&fmt, "]");
+				single = 0;
+			}
+			p0 = p;
+			p = strchr(p0, ',');
+			if(p == nil)
+				p = "";
+			else
+				*p++ = 0;
+			fmtprint(&fmt, " [-%C %s]", r, p0);
+		}
+		if(single)
+			fmtprint(&fmt, "]");
+	}
+	if(args)
+		fmtprint(&fmt, " %s", args);
+	fmtprint(&fmt, "\n");
+	fmtfdflush(&fmt);
+	exits("usage");
+}

+ 0 - 267
sys/src/cmd/getflags/funcgetflags.c

@@ -1,267 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <ctype.h>
-#include "getflags.h"
-
-char **flag[NFLAG];
-char cmdline[NCMDLINE+1];
-char *cmdname;
-char *flagset[];
-char *flagset[]={"<flag>"};
-static char *flagarg="";
-static void reverse(char **, char **);
-static int scanflag(int, char *);
-static int reason;
-#define	RESET	1
-#define	ARGCCOUNT	2
-#define	FLAGSYN	3
-#define	BADFLAG	4
-static int badflag;
-char *getflagsargv[NGETFLAGSARGV+2];	/* original argv stored here for people who need it */
-
-int
-getflags(int argc, char *argv[], char *flags)
-{
-	char *s, *t;
-	int i, j, c, count;
-	flagarg=flags;
-	if(cmdname==0){
-		cmdname=argv[0];
-		for(i=0;i!=argc && i!=NGETFLAGSARGV;i++) getflagsargv[i]=argv[i];
-		if(argc>NGETFLAGSARGV) getflagsargv[i++]="...";
-		getflagsargv[i]=0;
-	}
-	s=cmdline;
-	for(i=0;i!=argc;i++){
-		for(t=argv[i];*t;)
-			if(s!=&cmdline[NCMDLINE])
-				*s++=*t++;
-			else
-				break;
-		if(i!=argc-1 && s!=&cmdline[NCMDLINE])
-			*s++=' ';
-	}
-	*s='\0';
-	i=1;
-	while(i!=argc && argv[i][0]=='-'){
-		s=argv[i]+1;
-		if(*s=='\0'){	/* if argument is "-", stop scanning and delete it */
-			for(j=i+1;j<=argc;j++)
-				argv[j-1]=argv[j];
-			return argc-1;
-		}
-		while(*s){
-			c=*s++;
-			count=scanflag(c, flags);
-			if(count==-1) return -1;
-			if(flag[c]){ reason=RESET; badflag=c; return -1; }
-			if(count==0){
-				flag[c]=flagset;
-				if(*s=='\0'){
-					for(j=i+1;j<=argc;j++)
-						argv[j-1]=argv[j];
-					--argc;
-				}
-			}
-			else{
-				if(*s=='\0'){
-					for(j=i+1;j<=argc;j++)
-						argv[j-1]=argv[j];
-					--argc;
-					s=argv[i];
-				}
-				if(argc-i<count){
-					reason=ARGCCOUNT;
-					badflag=c;
-					return -1;
-				}
-				reverse(argv+i, argv+argc);
-				reverse(argv+i, argv+argc-count);
-				reverse(argv+argc-count+1, argv+argc);
-				argc-=count;
-				flag[c]=argv+argc+1;
-				flag[c][0]=s;
-				s="";
-			}
-		}
-	}
-	return argc;
-}
-
-void
-static reverse(char **p, char **q)
-{
-	register char *t;
-	for(;p<q;p++,--q){ t=*p; *p=*q; *q=t; }
-}
-
-static int
-scanflag(int c, char *f)
-{
-	int fc, count;
-	if(0<=c && c<NFLAG) while(*f){
-		if(*f==' '){
-			f++;
-			continue;
-		}
-		fc=*f++;
-		if(*f==':'){
-			f++;
-			if(!isdigit(*f)){ reason=FLAGSYN; return -1; }
-			count=strtol(f, &f, 10);
-		}
-		else
-			count=0;
-		if(*f=='['){
-			int depth=1;
-			do{
-				f++;
-				if(*f=='\0'){ reason=FLAGSYN; return -1; }
-				if(*f=='[') depth++;
-				if(*f==']') depth--;
-			}while(depth>0);
-			f++;
-		}
-		if(c==fc) return count;
-	}
-	reason=BADFLAG;
-	badflag=c;
-	return -1;
-}
-
-static void errn(char *, int), errs(char *), errc(int);
-
-void
-usage(char *tail)
-{
-	char *s, *t, c;
-	int count, nflag=0;
-	switch(reason){
-	case RESET:
-		errs("Flag -");
-		errc(badflag);
-		errs(": set twice\n");
-		break;
-	case ARGCCOUNT:
-		errs("Flag -");
-		errc(badflag);
-		errs(": too few arguments\n");
-		break;
-	case FLAGSYN:
-		errs("Bad argument to getflags!\n");
-		break;
-	case BADFLAG:
-		errs("Illegal flag -");
-		errc(badflag);
-		errc('\n');
-		break;
-	}
-	errs("Usage: ");
-	errs(cmdname);
-	for(s=flagarg;*s;){
-		c=*s;
-		if(*s++==' ') continue;
-		if(*s==':'){
-			s++;
-			count=strtol(s, &s, 10);
-		}
-		else count=0;
-		if(count==0){
-			if(nflag==0) errs(" [-");
-			nflag++;
-			errc(c);
-		}
-		if(*s=='['){
-			int depth=1;
-			s++;
-			for(;*s!='\0' && depth>0; s++)
-				if (*s==']') depth--;
-				else if (*s=='[') depth++;
-		}
-	}
-	if(nflag) errs("]");
-	for(s=flagarg;*s;){
-		c=*s;
-		if(*s++==' ') continue;
-		if(*s==':'){
-			s++;
-			count=strtol(s, &s, 10);
-		}
-		else count=0;
-		if(count!=0){
-			errs(" [-");
-			errc(c);
-			if(*s=='['){
-				int depth=1;
-				s++;
-				t=s;
-				for(;*s!='\0' && depth>0; s++)
-					if (*s==']') depth--;
-					else if (*s=='[') depth++;
-				errs(" ");
-				errn(t, s-t);
-			}
-			else
-				while(count--) errs(" arg");
-			errs("]");
-		}
-		else if(*s=='['){
-			int depth=1;
-			s++;
-			for(;*s!='\0' && depth>0; s++)
-				if (*s==']') depth--;
-				else if (*s=='[') depth++;
-		}
-	}
-	if(tail){
-		errs(" ");
-		errs(tail);
-	}
-	errs("\n");
-	exits("usage");
-}
-
-static void
-errn(char *s, int count)
-{
-	while(count){ errc(*s++); --count; }
-}
-
-static void
-errs(char *s)
-{
-	while(*s) errc(*s++);
-}
-
-#define	NBUF	80
-static char buf[NBUF], *bufp=buf;
-
-static void
-errc(int c){
-	*bufp++=c;
-	if(bufp==&buf[NBUF] || c=='\n'){
-		write(2, buf, bufp-buf);
-		bufp=buf;
-	}
-}
-
-#ifdef TEST
-#include <stdio.h>
-main(int argc, char *argv[])
-{
-	int c, i, n;
-	if(argc<3){
-		fprint(2, "Usage: %s flags cmd ...\n", argv[0]);
-		exits("usage");
-	}
-	n=getflags(argc-2, argv+2, argv[1]);
-	if(n<0) usage("...");
-	putchar('\n');
-	for(c=0;c!=128;c++) if(flag[c]){
-		print("\t-.%c. ", c);
-		n=scanflag(c, argv[1]);
-		for(i=0;i!=n;i++) print(" <%s>", flag[c][i]);
-		putchar('\n');
-	}
-}
-#endif

+ 0 - 199
sys/src/cmd/getflags/getflags.c

@@ -1,199 +0,0 @@
-/*% cyntax % && cc -go # %
- * getflags: process flags for command files
- * Usage: ifs='' eval `{getflags [-s] flagfmt [arg ...]}	# rc
- * Usage: IFS=   eval `getflags -b [-s] flagfmt [arg...]`	# Bourne shell
- *	-b means give Bourne-shell compatible output
- */
-#include <u.h>
-#include <libc.h>
-#include "getflags.h"
-
-/* predefine functions */
-void bourneprint(int, char *[]);
-void bournearg(char *);
-void rcprint(int, char *[]);
-void usmsg(char *);
-int count(int, char *);
-void rcarg(char *);
-
-void
-main(int argc, char *argv[])
-{
-	int bourne;
-	argc=getflags(argc, argv, "b");
-	if(argc<2) usage("flagfmt [arg ...]");
-	bourne=flag['b']!=0;
-	flag['b']=0;
-	if((argc=getflags(argc-1, argv+1, argv[1]))<0){
-		usmsg(argv[1]);
-		exits(0);
-	}
-	if(bourne) bourneprint(argc, argv);
-	else rcprint(argc, argv);
-	exits(0);
-}
-void
-bourneprint(int argc, char *argv[])
-{
-	register int c, i, n;
-	for(c=0;c!=NFLAG;c++) if(flag[c]){
-		print("FLAG%c=", c);		/* bug -- c could be a bad char */
-		n=count(c, argv[1]);
-		if(n==0)
-			print("1\n");
-		else{
-			print("'");
-			bournearg(flag[c][0]);
-			for(i=1;i!=n;i++){
-				print(" ");
-				bournearg(flag[c][i]);
-			}
-			print("'\n");
-		}
-	}
-	print("set --");
-	for(c=1;c!=argc;c++){
-		print(" ");
-		bournearg(argv[c+1]);
-	}
-	print("\n");
-}
-void
-bournearg(char *s)
-{
-	for(;*s;s++)
-		if(*s=='\'')
-			print("'\\''");
-		else
-			print("%c", *s);
-}
-void
-rcprint(int argc, char *argv[])
-{
-	register c, i, n;
-	for(c=0;c!=NFLAG;c++) if(flag[c]){
-		print("FLAG%c=", c);		/* bug -- c could be a bad char */
-		n=count(c, argv[1]);
-		if(n==0)
-			print("''");
-		else if(n==1)
-			rcarg(flag[c][0]);
-		else{
-			print("(");
-			rcarg(flag[c][0]);
-			for(i=1;i!=n;i++){
-				print(" ");
-				rcarg(flag[c][i]);
-			}
-			print(")");
-		}
-		print("\n");
-	}
-	print("*=");
-	if(argc==1) print("()");
-	else if(argc==2) rcarg(argv[2]);
-	else{
-		print("(");
-		rcarg(argv[2]);
-		for(c=2;c!=argc;c++){
-			print(" ");
-			rcarg(argv[c+1]);
-		}
-		print(")");
-	}
-	print("\n");
-}
-void
-usmsg(char *flagarg)
-{
-	register char *s, *t, c;
-	register count, nflag=0;
-	print("echo Usage: $0'");
-	for(s=flagarg;*s;){
-		c=*s;
-		if(*s++==' ') continue;
-		if(*s==':')
-			count = strtol(++s, &s, 10);
-		else count=0;
-		if(count==0){
-			if(nflag==0) print(" [-");
-			nflag++;
-			print("%c", c);
-		}
-		if(*s=='['){
-			int depth=1;
-			s++;
-			for(;*s!='\0' && depth>0; s++)
-				if (*s==']') depth--;
-				else if (*s=='[') depth++;
-		}
-	}
-	if(nflag) print("]");
-	for(s=flagarg;*s;){
-		c=*s;
-		if(*s++==' ') continue;
-		if(*s==':')
-			count = strtol(++s, &s, 10);
-		else count=0;
-		if(count!=0){
-			print(" [-");
-			print("%c", c);
-			if(*s=='['){
-				int depth=1;
-				s++;
-				t=s;
-				for(;*s!='\0' && depth>0; s++)
-					if (*s==']') depth--;
-					else if (*s=='[') depth++;
-				print(" ");
-				write(1, t, s - t);
-			}
-			else
-				while(count--) print(" arg");
-			print("]");
-		}
-		else if(*s=='['){
-			int depth=1;
-			s++;
-			for(;*s!='\0' && depth>0; s++)
-				if (*s==']') depth--;
-				else if (*s=='[') depth++;
-		}
-	}
-	print("' $usage;\n");
-	print("exit 'usage'\n");
-}
-int
-count(int flag, char *flagarg)
-{
-	register char *s, c;
-	register n;
-	for(s=flagarg;*s;){
-		c=*s;
-		if(*s++==' ') continue;
-		if(*s==':')
-			n = strtol(++s, &s, 10);
-		else n=0;
-		if(*s=='['){
-			int depth=1;
-			s++;
-			for(;*s!='\0' && depth>0; s++)
-				if (*s==']') depth--;
-				else if (*s=='[') depth++;
-		}
-		if(c==flag) return n;
-	}
-	return -1;		/* never happens */
-}
-void
-rcarg(char *s)
-{
-	if(*s=='\0' || strpbrk(s, "\n \t#;&|^$=`'{}()<>?")){
-		print("\'");
-		for(;*s;s++)
-			if(*s=='\'') print("''");
-			else print("%c", *s);
-		print("\'");
-	}
-	else	print("%s", s);
-}

+ 0 - 10
sys/src/cmd/getflags/getflags.h

@@ -1,10 +0,0 @@
-#define	NFLAG	128
-#define	NCMDLINE	512
-#define	NGETFLAGSARGV	256
-extern char **flag[NFLAG];
-extern char cmdline[NCMDLINE+1];
-extern char *cmdname;
-extern char *flagset[];
-extern char *getflagsargv[NGETFLAGSARGV+2];
-int getflags(int, char *[], char *);
-void usage(char *);

+ 0 - 9
sys/src/cmd/getflags/mkfile

@@ -1,9 +0,0 @@
-</$objtype/mkfile
-
-TARG=aux/getflags
-OFILES=\
-	getflags.$O\
-	funcgetflags.$O\
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone

+ 58 - 54
sys/src/cmd/lp/lp.rc

@@ -33,8 +33,12 @@ USAGE='usage:	lp [-d printer] [-p process] [options] [files]
 		lp [-d printer] -k jobnos
 
 		options include:
-		-H		no header
-		-L		landscape mode
+		-D			turn on debugging output
+		-H			no header
+		-L			landscape mode
+		-M<mach>	print on machine <mach>
+		-Q			put task only into the queue
+		-R			restart printer daemon
 		-c<n>		make <n> copies
 		-f<font.size>	specify font and size
 		-i<src>		take media from <src> input bin
@@ -42,9 +46,12 @@ USAGE='usage:	lp [-d printer] [-p process] [options] [files]
 		-m<n>		magnify <n> times
 		-n<n>		print <n> logical pages per physical page
 		-o<i-j,k>	print only pages i-j and k
-		-r		reverse pages
+		-r			reverse pages
+		-u<userid>	print as <userid>
 		-x<n>		x page offset in inches
-		-y<n>		y page offset in inches'
+		-y<n>		y page offset in inches
+'
+
 # umask 000	# this doesn't work in plan 9
 if (~ $#sysname 0)
 	THIS_HOST=plan9
@@ -63,67 +70,64 @@ LPLOC=''
 if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
 
 # option parameters
-XOFF=''
-YOFF=''
-POINT=''
+COPIES=1
 FONT=''
-LINES=''
+IBIN=''
+KILLFLAG=0
 LAND=''
-COPIES=''
+LINES=''
+LPQ=0
 MAG=''
+NOHEAD=''
 NPAG=''
 OLIST=''
-IBIN=''
+POINT=''
+RESET=''
 REVERSE=''
-NOHEAD=''
+QONLY=''
 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=()
+XOFF=''
+YOFF=''
+
 # Process options
-eval `{aux/getflags DHLM:1QRc: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 (! ~ $#FLAGR 0) RESET=1; if not RESET=''
-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
-	}
+flagfmt='D,H,L,Q,R,r,q,c copies,d printer,f font.size,i src,k jobnos,l lines,m magnify,n lpages,o pages,u userid,x offset,y offset'
+argv0=lp
+
+if(! ifs=() eval `{aux/getflags $*}) {
+	echo $USAGE
+	exit usage
 }
-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) OLIST=-o$FLAGo
-if (! ~ $#FLAGp 0) {
-	switch (FLAGp) {
-	case '?';exec ls $LPLIB/process
-	case *;	LPPROC=$FLAGp
-	}
+if(~ $flagd '?'){
+	awk 'BEGIN{printf "device       location  host                 class\n"}
+			/^[^#]/	{printf "%-12s %-9s %-20s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
+	exit
 }
-if (! ~ $#FLAGq 0) LPQ=1; if not LPQ=0
-if (! ~ $#FLAGr 0) {
-	switch ($REVERSE) {
-	case '';REVERSE=1
-	case 1;	REVERSE=''
-	}
+if(~ $flagp '?'){
+	ls $LPLIB/process
+	exit
 }
-if (! ~ $#FLAGt 0) TRAY=$FLAGt
-# originating user id
-if (! ~ $#FLAGu 0) LPUSERID=$FLAGu
-if (! ~ $#FLAGx 0) XOFF=$FLAGx
-if (! ~ $#FLAGy 0) YOFF=$FLAGy
+
+if (! ~ $#flagD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - }
+if (! ~ $#flagH 0) NOHEAD=1
+if (! ~ $#flagL 0) LAND=1
+if (! ~ $#flagM 0 && ~ $LPUSERID daemon) LPMACHID=$flagM
+if (! ~ $#flagQ 0) QONLY=1
+if (! ~ $#flagR 0) RESET=1
+if (! ~ $#flagc 0) COPIES=$flagc
+if(! ~ $#flagd 0) 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 (! ~ $#flagl 0) LINES=$flagl
+if (! ~ $#flagm 0) MAG=$flagm
+if (! ~ $#flagn 0) NPAG=$flagn
+if (! ~ $#flago 0) OLIST=-o^$flago
+if (! ~ $#flagp 0) LPPROC=$flagp
+if (! ~ $#flagq 0) LPQ=1
+if (! ~ $#flagr 0) REVERSE=1
+if (! ~ $#flagu 0) LPUSERID=$flagu
+if (! ~ $#flagx 0) XOFF=$flagx
+if (! ~ $#flagy 0) YOFF=$flagy
 
 if (~ $#LPDEST 0) {
 	echo 'Set environment variable LPDEST or use the

+ 6 - 2
sys/src/cmd/touch.c

@@ -14,13 +14,17 @@ usage(void)
 void
 main(int argc, char **argv)
 {
+	char *t, *s;
 	int nocreate = 0;
 	int status = 0;
 
 	now = time(0);
 	ARGBEGIN{
 	case 't':
-		now = strtoul(EARGF(usage()), 0, 0);
+		t = EARGF(usage());
+		now = strtoul(t, &s, 0);
+		if(s == t || *s != '\0')
+			usage();
 		break;
 	case 'c':
 		nocreate = 1;
@@ -51,7 +55,7 @@ touch(int nocreate, char *name)
 		fprint(2, "touch: %s: cannot wstat: %r\n", name);
 		return 1;
 	}
-	if ((fd = create(name, OREAD|OEXCL, 0666)) < 0) {
+	if((fd = create(name, OREAD|OEXCL, 0666)) < 0){
 		fprint(2, "touch: %s: cannot create: %r\n", name);
 		return 1;
 	}