Browse Source

Plan 9 from Bell Labs 2007-06-27

David du Colombier 17 years ago
parent
commit
af485cf916

+ 30 - 28
dist/replica/_plan9.db

@@ -5267,7 +5267,7 @@ lib/tftpd - 20000000775 sys sys 1020895767 0
 lib/unicode - 664 sys sys 958440028 223312
 lib/unicode.notice - 664 sys sys 958504386 1398
 lib/units - 664 sys sys 1071415518 9997
-lib/vgadb - 664 sys sys 1179427249 30622
+lib/vgadb - 664 sys sys 1182876665 31152
 lib/video.specs - 664 sys sys 1175869533 2942
 lib/volcanoes - 664 sys sys 944944024 119831
 lib/words - 664 sys sys 1014923442 247097
@@ -7348,7 +7348,7 @@ sys/man/1/cmp - 664 sys sys 1134330626 1069
 sys/man/1/col - 664 sys sys 1172005089 962
 sys/man/1/colors - 664 sys sys 1134330626 1438
 sys/man/1/comm - 664 sys sys 944959675 665
-sys/man/1/con - 664 sys sys 1155994747 4310
+sys/man/1/con - 664 sys sys 1182908614 4447
 sys/man/1/cp - 664 sys sys 1110816882 1947
 sys/man/1/cpp - 664 sys sys 944959674 2105
 sys/man/1/cpu - 664 sys sys 1128483118 3804
@@ -12783,7 +12783,7 @@ sys/src/cmd/mk/acid - 664 sys sys 1055698806 10395
 sys/src/cmd/mk/arc.c - 664 sys sys 1131289508 826
 sys/src/cmd/mk/archive.c - 664 sys sys 1131289509 3071
 sys/src/cmd/mk/bufblock.c - 664 sys sys 944961024 1338
-sys/src/cmd/mk/env.c - 664 sys sys 1131289509 2281
+sys/src/cmd/mk/env.c - 664 sys sys 1182892953 2307
 sys/src/cmd/mk/file.c - 664 sys sys 1131289509 1299
 sys/src/cmd/mk/fns.h - 664 sys sys 1055698809 2199
 sys/src/cmd/mk/graph.c - 664 sys sys 1131289509 5822
@@ -12791,17 +12791,17 @@ sys/src/cmd/mk/job.c - 664 sys sys 944961025 692
 sys/src/cmd/mk/lex.c - 664 sys sys 1143759343 2304
 sys/src/cmd/mk/main.c - 664 sys sys 1123094366 4790
 sys/src/cmd/mk/match.c - 664 sys sys 1014926073 856
-sys/src/cmd/mk/mk.c - 664 sys sys 1131289509 5330
+sys/src/cmd/mk/mk.c - 664 sys sys 1182894020 5360
 sys/src/cmd/mk/mk.h - 664 sys sys 1131289508 3765
 sys/src/cmd/mk/mkconv - 775 sys sys 944961025 555
 sys/src/cmd/mk/mkfile - 664 sys sys 1055698812 376
 sys/src/cmd/mk/parse.c - 664 sys sys 944961025 5310
-sys/src/cmd/mk/plan9.c - 664 sys sys 1131289511 6941
+sys/src/cmd/mk/plan9.c - 664 sys sys 1182905824 6968
 sys/src/cmd/mk/rc.c - 664 sys sys 944961025 3206
-sys/src/cmd/mk/recipe.c - 664 sys sys 1131289510 2543
+sys/src/cmd/mk/recipe.c - 664 sys sys 1182894011 2557
 sys/src/cmd/mk/rule.c - 664 sys sys 1131289510 1946
-sys/src/cmd/mk/run.c - 664 sys sys 1131289510 5063
-sys/src/cmd/mk/shprint.c - 664 sys sys 952627588 1515
+sys/src/cmd/mk/run.c - 664 sys sys 1182895178 5085
+sys/src/cmd/mk/shprint.c - 664 sys sys 1182892889 1531
 sys/src/cmd/mk/symtab.c - 664 sys sys 1131289510 1581
 sys/src/cmd/mk/var.c - 664 sys sys 1131289510 530
 sys/src/cmd/mk/varsub.c - 664 sys sys 1174930010 4297
@@ -13260,34 +13260,34 @@ sys/src/cmd/ratfs/mkfile - 664 sys sys 1016943965 142
 sys/src/cmd/ratfs/proto.c - 664 sys sys 1016943965 8528
 sys/src/cmd/ratfs/ratfs.h - 664 sys sys 1016943965 2743
 sys/src/cmd/rc - 20000000775 sys sys 1071884773 0
-sys/src/cmd/rc/code.c - 664 sys sys 1100894086 8215
+sys/src/cmd/rc/code.c - 664 sys sys 1182906211 8218
 sys/src/cmd/rc/compiling.on.unix - 664 sys sys 1071884773 37638
-sys/src/cmd/rc/exec.c - 664 sys sys 1174915671 16567
-sys/src/cmd/rc/exec.h - 664 sys sys 1174915671 2828
+sys/src/cmd/rc/exec.c - 664 sys sys 1182906270 16611
+sys/src/cmd/rc/exec.h - 664 sys sys 1182906260 2824
 sys/src/cmd/rc/fmtquote.c - 664 sys sys 1055698768 3609
-sys/src/cmd/rc/fns.h - 664 sys sys 1174919213 1490
-sys/src/cmd/rc/getflags.c - 664 sys sys 1174915671 3962
-sys/src/cmd/rc/getflags.h - 664 sys sys 944961082 185
-sys/src/cmd/rc/glob.c - 664 sys sys 1055698770 4540
-sys/src/cmd/rc/havefork.c - 664 sys sys 1174919214 3714
-sys/src/cmd/rc/haventfork.c - 664 sys sys 1055698771 3122
-sys/src/cmd/rc/here.c - 664 sys sys 1135080780 2504
-sys/src/cmd/rc/io.c - 664 sys sys 1132448641 3752
-sys/src/cmd/rc/io.h - 664 sys sys 1174915672 513
+sys/src/cmd/rc/fns.h - 664 sys sys 1182906276 1490
+sys/src/cmd/rc/getflags.c - 664 sys sys 1182890772 3863
+sys/src/cmd/rc/getflags.h - 664 sys sys 1182890781 133
+sys/src/cmd/rc/glob.c - 664 sys sys 1182906303 4710
+sys/src/cmd/rc/havefork.c - 664 sys sys 1182890728 3751
+sys/src/cmd/rc/haventfork.c - 664 sys sys 1182890808 3149
+sys/src/cmd/rc/here.c - 664 sys sys 1182906323 2575
+sys/src/cmd/rc/io.c - 664 sys sys 1182906364 3856
+sys/src/cmd/rc/io.h - 664 sys sys 1182906342 523
 sys/src/cmd/rc/lex.c - 664 sys sys 1174915672 6203
-sys/src/cmd/rc/mkfile - 664 sys sys 1055698774 812
+sys/src/cmd/rc/mkfile - 664 sys sys 1182890797 825
 sys/src/cmd/rc/pcmd.c - 664 sys sys 1100894086 2681
 sys/src/cmd/rc/pfnc.c - 664 sys sys 1100894087 1320
-sys/src/cmd/rc/plan9.c - 664 sys sys 1174919214 9934
-sys/src/cmd/rc/rc.h - 664 sys sys 1100894086 3329
-sys/src/cmd/rc/simple.c - 664 sys sys 1174915673 9018
-sys/src/cmd/rc/subr.c - 664 sys sys 1055698779 1206
+sys/src/cmd/rc/plan9.c - 664 sys sys 1182906491 10154
+sys/src/cmd/rc/rc.h - 664 sys sys 1182906172 3326
+sys/src/cmd/rc/simple.c - 664 sys sys 1182890831 9219
+sys/src/cmd/rc/subr.c - 664 sys sys 1182906242 1210
 sys/src/cmd/rc/syn.y - 664 sys sys 944961083 3128
 sys/src/cmd/rc/trap.c - 664 sys sys 1174915673 878
-sys/src/cmd/rc/tree.c - 664 sys sys 1055698780 2071
-sys/src/cmd/rc/unix.c - 664 sys sys 1055698781 8726
+sys/src/cmd/rc/tree.c - 664 sys sys 1182906201 2081
+sys/src/cmd/rc/unix.c - 664 sys sys 1182906186 8708
 sys/src/cmd/rc/var.c - 664 sys sys 1055698781 1298
-sys/src/cmd/rc/win32.c - 664 sys sys 1132448675 8697
+sys/src/cmd/rc/win32.c - 664 sys sys 1182906181 8691
 sys/src/cmd/rdbfs.c - 664 sys sys 1142342219 7633
 sys/src/cmd/read.c - 664 sys sys 1022047660 1278
 sys/src/cmd/replica - 20000000775 sys sys 1053210813 0
@@ -15844,3 +15844,5 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+386/bin/mk - 775 sys sys 1182914525 143314
+386/bin/rc - 775 sys sys 1182914526 145398

+ 30 - 30
dist/replica/plan9.db

@@ -331,7 +331,7 @@
 386/bin/ls - 775 sys sys 1178568291 81002
 386/bin/mc - 775 sys sys 1179372098 134354
 386/bin/md5sum - 775 sys sys 1168402334 61498
-386/bin/mk - 775 sys sys 1181507268 143420
+386/bin/mk - 775 sys sys 1182914525 143314
 386/bin/mkdir - 775 sys sys 1168402334 61205
 386/bin/mkpaqfs - 775 sys sys 1178568292 93268
 386/bin/mntgen - 775 sys sys 1179372098 144046
@@ -379,7 +379,7 @@
 386/bin/ps - 775 sys sys 1168402346 68812
 386/bin/pwd - 775 sys sys 1148500685 36932
 386/bin/ramfs - 775 sys sys 1178568298 88610
-386/bin/rc - 775 sys sys 1174933356 144261
+386/bin/rc - 775 sys sys 1182914526 145398
 386/bin/rdbfs - 775 sys sys 1179548031 173192
 386/bin/read - 775 sys sys 1168402347 58283
 386/bin/replica - 20000000775 sys sys 1018321168 0
@@ -5267,7 +5267,7 @@ lib/tftpd - 20000000775 sys sys 1020895767 0
 lib/unicode - 664 sys sys 958440028 223312
 lib/unicode.notice - 664 sys sys 958504386 1398
 lib/units - 664 sys sys 1071415518 9997
-lib/vgadb - 664 sys sys 1179427249 30622
+lib/vgadb - 664 sys sys 1182876665 31152
 lib/video.specs - 664 sys sys 1175869533 2942
 lib/volcanoes - 664 sys sys 944944024 119831
 lib/words - 664 sys sys 1014923442 247097
@@ -7348,7 +7348,7 @@ sys/man/1/cmp - 664 sys sys 1134330626 1069
 sys/man/1/col - 664 sys sys 1172005089 962
 sys/man/1/colors - 664 sys sys 1134330626 1438
 sys/man/1/comm - 664 sys sys 944959675 665
-sys/man/1/con - 664 sys sys 1155994747 4310
+sys/man/1/con - 664 sys sys 1182908614 4447
 sys/man/1/cp - 664 sys sys 1110816882 1947
 sys/man/1/cpp - 664 sys sys 944959674 2105
 sys/man/1/cpu - 664 sys sys 1128483118 3804
@@ -12783,7 +12783,7 @@ sys/src/cmd/mk/acid - 664 sys sys 1055698806 10395
 sys/src/cmd/mk/arc.c - 664 sys sys 1131289508 826
 sys/src/cmd/mk/archive.c - 664 sys sys 1131289509 3071
 sys/src/cmd/mk/bufblock.c - 664 sys sys 944961024 1338
-sys/src/cmd/mk/env.c - 664 sys sys 1131289509 2281
+sys/src/cmd/mk/env.c - 664 sys sys 1182892953 2307
 sys/src/cmd/mk/file.c - 664 sys sys 1131289509 1299
 sys/src/cmd/mk/fns.h - 664 sys sys 1055698809 2199
 sys/src/cmd/mk/graph.c - 664 sys sys 1131289509 5822
@@ -12791,17 +12791,17 @@ sys/src/cmd/mk/job.c - 664 sys sys 944961025 692
 sys/src/cmd/mk/lex.c - 664 sys sys 1143759343 2304
 sys/src/cmd/mk/main.c - 664 sys sys 1123094366 4790
 sys/src/cmd/mk/match.c - 664 sys sys 1014926073 856
-sys/src/cmd/mk/mk.c - 664 sys sys 1131289509 5330
+sys/src/cmd/mk/mk.c - 664 sys sys 1182894020 5360
 sys/src/cmd/mk/mk.h - 664 sys sys 1131289508 3765
 sys/src/cmd/mk/mkconv - 775 sys sys 944961025 555
 sys/src/cmd/mk/mkfile - 664 sys sys 1055698812 376
 sys/src/cmd/mk/parse.c - 664 sys sys 944961025 5310
-sys/src/cmd/mk/plan9.c - 664 sys sys 1131289511 6941
+sys/src/cmd/mk/plan9.c - 664 sys sys 1182905824 6968
 sys/src/cmd/mk/rc.c - 664 sys sys 944961025 3206
-sys/src/cmd/mk/recipe.c - 664 sys sys 1131289510 2543
+sys/src/cmd/mk/recipe.c - 664 sys sys 1182894011 2557
 sys/src/cmd/mk/rule.c - 664 sys sys 1131289510 1946
-sys/src/cmd/mk/run.c - 664 sys sys 1131289510 5063
-sys/src/cmd/mk/shprint.c - 664 sys sys 952627588 1515
+sys/src/cmd/mk/run.c - 664 sys sys 1182895178 5085
+sys/src/cmd/mk/shprint.c - 664 sys sys 1182892889 1531
 sys/src/cmd/mk/symtab.c - 664 sys sys 1131289510 1581
 sys/src/cmd/mk/var.c - 664 sys sys 1131289510 530
 sys/src/cmd/mk/varsub.c - 664 sys sys 1174930010 4297
@@ -13260,34 +13260,34 @@ sys/src/cmd/ratfs/mkfile - 664 sys sys 1016943965 142
 sys/src/cmd/ratfs/proto.c - 664 sys sys 1016943965 8528
 sys/src/cmd/ratfs/ratfs.h - 664 sys sys 1016943965 2743
 sys/src/cmd/rc - 20000000775 sys sys 1071884773 0
-sys/src/cmd/rc/code.c - 664 sys sys 1100894086 8215
+sys/src/cmd/rc/code.c - 664 sys sys 1182906211 8218
 sys/src/cmd/rc/compiling.on.unix - 664 sys sys 1071884773 37638
-sys/src/cmd/rc/exec.c - 664 sys sys 1174915671 16567
-sys/src/cmd/rc/exec.h - 664 sys sys 1174915671 2828
+sys/src/cmd/rc/exec.c - 664 sys sys 1182906270 16611
+sys/src/cmd/rc/exec.h - 664 sys sys 1182906260 2824
 sys/src/cmd/rc/fmtquote.c - 664 sys sys 1055698768 3609
-sys/src/cmd/rc/fns.h - 664 sys sys 1174919213 1490
-sys/src/cmd/rc/getflags.c - 664 sys sys 1174915671 3962
-sys/src/cmd/rc/getflags.h - 664 sys sys 944961082 185
-sys/src/cmd/rc/glob.c - 664 sys sys 1055698770 4540
-sys/src/cmd/rc/havefork.c - 664 sys sys 1174919214 3714
-sys/src/cmd/rc/haventfork.c - 664 sys sys 1055698771 3122
-sys/src/cmd/rc/here.c - 664 sys sys 1135080780 2504
-sys/src/cmd/rc/io.c - 664 sys sys 1132448641 3752
-sys/src/cmd/rc/io.h - 664 sys sys 1174915672 513
+sys/src/cmd/rc/fns.h - 664 sys sys 1182906276 1490
+sys/src/cmd/rc/getflags.c - 664 sys sys 1182890772 3863
+sys/src/cmd/rc/getflags.h - 664 sys sys 1182890781 133
+sys/src/cmd/rc/glob.c - 664 sys sys 1182906303 4710
+sys/src/cmd/rc/havefork.c - 664 sys sys 1182890728 3751
+sys/src/cmd/rc/haventfork.c - 664 sys sys 1182890808 3149
+sys/src/cmd/rc/here.c - 664 sys sys 1182906323 2575
+sys/src/cmd/rc/io.c - 664 sys sys 1182906364 3856
+sys/src/cmd/rc/io.h - 664 sys sys 1182906342 523
 sys/src/cmd/rc/lex.c - 664 sys sys 1174915672 6203
-sys/src/cmd/rc/mkfile - 664 sys sys 1055698774 812
+sys/src/cmd/rc/mkfile - 664 sys sys 1182890797 825
 sys/src/cmd/rc/pcmd.c - 664 sys sys 1100894086 2681
 sys/src/cmd/rc/pfnc.c - 664 sys sys 1100894087 1320
-sys/src/cmd/rc/plan9.c - 664 sys sys 1174919214 9934
-sys/src/cmd/rc/rc.h - 664 sys sys 1100894086 3329
-sys/src/cmd/rc/simple.c - 664 sys sys 1174915673 9018
-sys/src/cmd/rc/subr.c - 664 sys sys 1055698779 1206
+sys/src/cmd/rc/plan9.c - 664 sys sys 1182906491 10154
+sys/src/cmd/rc/rc.h - 664 sys sys 1182906172 3326
+sys/src/cmd/rc/simple.c - 664 sys sys 1182890831 9219
+sys/src/cmd/rc/subr.c - 664 sys sys 1182906242 1210
 sys/src/cmd/rc/syn.y - 664 sys sys 944961083 3128
 sys/src/cmd/rc/trap.c - 664 sys sys 1174915673 878
-sys/src/cmd/rc/tree.c - 664 sys sys 1055698780 2071
-sys/src/cmd/rc/unix.c - 664 sys sys 1055698781 8726
+sys/src/cmd/rc/tree.c - 664 sys sys 1182906201 2081
+sys/src/cmd/rc/unix.c - 664 sys sys 1182906186 8708
 sys/src/cmd/rc/var.c - 664 sys sys 1055698781 1298
-sys/src/cmd/rc/win32.c - 664 sys sys 1132448675 8697
+sys/src/cmd/rc/win32.c - 664 sys sys 1182906181 8691
 sys/src/cmd/rdbfs.c - 664 sys sys 1142342219 7633
 sys/src/cmd/read.c - 664 sys sys 1022047660 1278
 sys/src/cmd/replica - 20000000775 sys sys 1053210813 0

+ 34 - 0
dist/replica/plan9.log

@@ -49297,3 +49297,37 @@
 1182583841 0 c sys/src/cmd/ip/pptp.c - 664 sys sys 1182582403 16596
 1182628838 0 c 386/bin/ip/pptp - 775 sys sys 1182628779 127172
 1182749434 0 c sys/man/8/smtp - 664 sys sys 1182748396 4590
+1182877224 0 c lib/vgadb - 664 sys sys 1182876665 31152
+1182891623 0 c sys/src/cmd/rc/getflags.c - 664 sys sys 1182890772 3863
+1182891623 1 c sys/src/cmd/rc/getflags.h - 664 sys sys 1182890781 133
+1182891623 2 c sys/src/cmd/rc/havefork.c - 664 sys sys 1182890728 3751
+1182891623 3 c sys/src/cmd/rc/haventfork.c - 664 sys sys 1182890808 3149
+1182891623 4 c sys/src/cmd/rc/io.c - 664 sys sys 1182890746 3883
+1182891623 5 c sys/src/cmd/rc/mkfile - 664 sys sys 1182890797 825
+1182891623 6 c sys/src/cmd/rc/plan9.c - 664 sys sys 1182890700 10079
+1182891623 7 c sys/src/cmd/rc/simple.c - 664 sys sys 1182890831 9219
+1182893423 0 c sys/src/cmd/mk/env.c - 664 sys sys 1182892953 2307
+1182893423 1 c sys/src/cmd/mk/plan9.c - 664 sys sys 1182892902 6969
+1182893423 2 c sys/src/cmd/mk/shprint.c - 664 sys sys 1182892889 1531
+1182895222 0 c sys/src/cmd/mk/mk.c - 664 sys sys 1182894020 5360
+1182895222 1 c sys/src/cmd/mk/recipe.c - 664 sys sys 1182894011 2557
+1182895222 2 c sys/src/cmd/mk/run.c - 664 sys sys 1182895178 5085
+1182898823 0 c sys/src/cmd/rc/plan9.c - 664 sys sys 1182897449 10151
+1182906021 0 c sys/src/cmd/mk/plan9.c - 664 sys sys 1182905824 6968
+1182907824 0 c sys/src/cmd/rc/code.c - 664 sys sys 1182906211 8218
+1182907824 1 c sys/src/cmd/rc/exec.c - 664 sys sys 1182906270 16611
+1182907824 2 c sys/src/cmd/rc/exec.h - 664 sys sys 1182906260 2824
+1182907824 3 c sys/src/cmd/rc/fns.h - 664 sys sys 1182906276 1490
+1182907824 4 c sys/src/cmd/rc/glob.c - 664 sys sys 1182906303 4710
+1182907824 5 c sys/src/cmd/rc/here.c - 664 sys sys 1182906323 2575
+1182907824 6 c sys/src/cmd/rc/io.c - 664 sys sys 1182906364 3856
+1182907824 7 c sys/src/cmd/rc/io.h - 664 sys sys 1182906342 523
+1182907824 8 c sys/src/cmd/rc/plan9.c - 664 sys sys 1182906491 10154
+1182907824 9 c sys/src/cmd/rc/rc.h - 664 sys sys 1182906172 3326
+1182907824 10 c sys/src/cmd/rc/subr.c - 664 sys sys 1182906242 1210
+1182907824 11 c sys/src/cmd/rc/tree.c - 664 sys sys 1182906201 2081
+1182907824 12 c sys/src/cmd/rc/unix.c - 664 sys sys 1182906186 8708
+1182907824 13 c sys/src/cmd/rc/win32.c - 664 sys sys 1182906181 8691
+1182909624 0 c sys/man/1/con - 664 sys sys 1182908614 4447
+1182915022 0 c 386/bin/mk - 775 sys sys 1182914525 143314
+1182915022 1 c 386/bin/rc - 775 sys sys 1182914526 145398

+ 26 - 0
lib/vgadb

@@ -1266,6 +1266,32 @@ planar=1280x1024
 	vrs=1203 vre=1209 vt=1235
 	hsync=+ vsync=- 
 
+#
+# Viewsonic VP201(b) at 1600x1200 
+#
+vp201
+	videobw=200
+	alias=multisync
+
+vp201=1600x1200
+	defaultclock=162
+	shb=1664 ehb=1856 ht=2160
+	vrs=1201 vre=1204 vt=1250
+	hsync=+ vsync=+
+
+#
+#	HP A1097C fixed sync (Hitachi)
+#
+a1097c=1280x1024		#	78.125 kHz / 72.005 Hz,	a bit flat since the tube is 4:3
+	clock=135
+	shb=1344 ehb=1536 ht=1728
+	vrs=1027 vre=1030 vt=1085
+
+a1097c=1360x1024		#	78.125 kHz / 72.005 Hz, 4:3 resolution
+	clock=143.4375	#	tube is rated at 135MHz, so beware.
+	shb=1428 ehb=1632 ht=1836
+	vrs=1027 vre=1030 vt=1085
+
 #
 # QVGA		320x240		Quarter Video Graphics Array
 # VGA		640x480		Video Graphics Array

+ 5 - 0
sys/man/1/con

@@ -261,3 +261,8 @@ Also under
 .IR rx ,
 the remote standard error and standard output are combined 
 and go inseparably to the local standard output.
+.I Rx
+will consume its standard input by copying it to the remote system,
+so redirect it from
+.BR /dev/null
+if that's not what you want.

+ 2 - 2
sys/src/cmd/mk/env.c

@@ -109,9 +109,9 @@ buildenv(Job *j, int slot)
 	else
 		envupd("stem", newword(j->stem));
 	envupd("prereq", wdup(j->p));
-	sprint(buf, "%d", getpid());
+	snprint(buf, sizeof buf, "%d", getpid());
 	envupd("pid", newword(buf));
-	sprint(buf, "%d", slot);
+	snprint(buf, sizeof buf, "%d", slot);
 	envupd("nproc", newword(buf));
 	envupd("newprereq", wdup(j->np));
 	envupd("alltarget", wdup(j->at));

+ 6 - 5
sys/src/cmd/mk/mk.c

@@ -67,7 +67,7 @@ work(Node *node, Node *p, Arc *parc)
 	int weoutofdate;
 	int ready;
 	int did = 0;
-	char cwd[128];
+	char cwd[256];
 
 	/*print("work(%s) flags=0x%x time=%ld\n", node->name, node->flags, node->time);/**/
 	if(node->flags&BEINGMADE)
@@ -194,7 +194,7 @@ pcmp(char *prog, char *p, char *q)
 	int pid;
 
 	Bflush(&bout);
-	sprint(buf, "%s '%s' '%s'\n", prog, p, q);
+	snprint(buf, sizeof buf, "%s '%s' '%s'\n", prog, p, q);
 	pid = pipecmd(buf, 0, 0);
 	while(waitup(-3, &pid) >= 0)
 		;
@@ -210,7 +210,8 @@ outofdate(Node *node, Arc *arc, int eval)
 
 	str = 0;
 	if(arc->prog){
-		sprint(buf, "%s%c%s", node->name, 0377, arc->n->name);
+		snprint(buf, sizeof buf, "%s%c%s", node->name, 0377,
+			arc->n->name);
 		sym = symlook(buf, S_OUTOFDATE, 0);
 		if(sym == 0 || eval){
 			if(sym == 0)
@@ -223,8 +224,8 @@ outofdate(Node *node, Arc *arc, int eval)
 		} else
 			ret = sym->u.value;
 		return(ret-1);
-	} else if(strchr(arc->n->name, '(') && arc->n->time == 0)  /* missing archive member */
-		return 1;
+	} else if(strchr(arc->n->name, '(') && arc->n->time == 0)
+		return 1;			/* missing archive member */
 	else
 		/*
 		 * Treat equal times as out-of-date.

+ 10 - 11
sys/src/cmd/mk/plan9.c

@@ -30,7 +30,7 @@ readenv(void)
 				continue;
 			if (symlook(e[i].name, S_INTERNAL, 0))
 				continue;
-			sprint(nam, "/env/%s", e[i].name);
+			snprint(nam, sizeof nam, "/env/%s", e[i].name);
 			f = open(nam, OREAD);
 			if(f < 0)
 				continue;
@@ -99,12 +99,13 @@ exportenv(Envy *e)
 			hasvalue = 1;
 		if(sy == 0 && !hasvalue)	/* non-existant null symbol */
 			continue;
-		sprint(nam, "/env/%s", e->name);
+		snprint(nam, sizeof nam, "/env/%s", e->name);
 		if (sy != 0 && !hasvalue) {	/* Remove from environment */
-				/* we could remove it from the symbol table
-				 * too, but we're in the child copy, and it
-				 * would still remain in the parent's table.
-				 */
+			/*
+			 * we could remove it from the symbol table
+			 * too, but we're in the child copy, and it
+			 * would still remain in the parent's table.
+			 */
 			remove(nam);
 			delword(e->values);
 			e->values = 0;		/* memory leak */
@@ -201,12 +202,10 @@ execsh(char *args, char *cmd, Bufblock *buf, Envy *e)
 		}
 		close(out[1]);
 		close(in[0]);
-		p = cmd+strlen(cmd);
-		while(cmd < p){
-			n = write(in[1], cmd, p-cmd);
+		for(p = cmd + strlen(cmd); cmd < p; cmd += n){
+			n = write(in[1], cmd, p - cmd);
 			if(n < 0)
 				break;
-			cmd += n;
 		}
 		close(in[1]);
 		_exits(0);
@@ -217,7 +216,7 @@ execsh(char *args, char *cmd, Bufblock *buf, Envy *e)
 		for(;;){
 			if (buf->current >= buf->end)
 				growbuf(buf);
-			n = read(out[0], buf->current, buf->end-buf->current);
+			n = read(out[0], buf->current, buf->end - buf->current);
 			if(n <= 0)
 				break;
 			buf->current += n;

+ 18 - 13
sys/src/cmd/mk/recipe.c

@@ -3,14 +3,13 @@
 int
 dorecipe(Node *node)
 {
-	char buf[BIGBLOCK];
-	register Node *n;
-	Rule *r = 0;
+	int did = 0;
+	char buf[BIGBLOCK], cwd[256];
 	Arc *a, *aa;
-	Word head, ahead, lp, ln, *w, *ww, *aw;
+	Node *n;
+	Rule *r = 0;
 	Symtab *s;
-	int did = 0;
-	char cwd[128];
+	Word head, ahead, lp, ln, *w, *ww, *aw;
 
 	aa = 0;
 	/*
@@ -25,9 +24,11 @@ dorecipe(Node *node)
 	if(r == 0){
 		if(!(node->flags&VIRTUAL) && !(node->flags&NORECIPE)){
 			if(getwd(cwd, sizeof cwd))
-				fprint(2, "mk: no recipe to make '%s' in directory %s\n", node->name, cwd);
+				fprint(2, "mk: no recipe to make '%s' in directory %s\n",
+					node->name, cwd);
 			else
-				fprint(2, "mk: no recipe to make '%s'\n", node->name);
+				fprint(2, "mk: no recipe to make '%s'\n",
+					node->name);
 			Exit();
 		}
 		if(strchr(node->name, '(') && node->time == 0)
@@ -38,7 +39,8 @@ dorecipe(Node *node)
 			if(!(node->flags&VIRTUAL))
 				touch(node->name);
 			else if(explain)
-				Bprint(&bout, "no touch of virtual '%s'\n", node->name);
+				Bprint(&bout, "no touch of virtual '%s'\n",
+					node->name);
 		}
 		return(did);
 	}
@@ -73,7 +75,8 @@ dorecipe(Node *node)
 			}
 			ww->next = newword(buf);
 			ww = ww->next;
-			if(n == node) continue;
+			if(n == node)
+				continue;
 			n->next = node->next;
 			node->next = n;
 		}
@@ -93,7 +96,8 @@ dorecipe(Node *node)
 					addw(&ln, a->n->name);
 					if(explain)
 						fprint(1, "%s(%ld) < %s(%ld)\n",
-							n->name, n->time, a->n->name, a->n->time);
+							n->name, n->time,
+							a->n->name, a->n->time);
 				}
 			} else {
 				if(explain)
@@ -103,8 +107,9 @@ dorecipe(Node *node)
 		}
 		MADESET(n, BEINGMADE);
 	}
-/*	print("lt=%s ln=%s lp=%s\n",wtos(head.next, ' '),wtos(ln.next, ' '),wtos(lp.next, ' '));/**/
-	run(newjob(r, node, aa->stem, aa->match, lp.next, ln.next, head.next, ahead.next));
+/*	print("lt=%s ln=%s lp=%s\n",wtos(head.next, ' '),wtos(ln.next, ' '),wtos(lp.next, ' ')); /**/
+	run(newjob(r, node, aa->stem, aa->match, lp.next, ln.next, head.next,
+		ahead.next));
 	return(1);
 }
 

+ 18 - 12
sys/src/cmd/mk/run.c

@@ -2,19 +2,20 @@
 
 typedef struct Event
 {
-	int pid;
-	Job *job;
+	int	pid;
+	Job	*job;
 } Event;
 static Event *events;
 static int nevents, nrunning, nproclimit;
 
 typedef struct Process
 {
-	int pid;
-	int status;
+	int	pid;
+	int	status;
 	struct Process *b, *f;
 } Process;
 static Process *phead, *pfree;
+
 static void sched(void);
 static void pnew(int, int), pdelete(Process *);
 
@@ -69,14 +70,15 @@ sched(void)
 				if(!(n->flags&VIRTUAL))
 					touch(n->name);
 				else if(explain)
-					Bprint(&bout, "no touch of virtual '%s'\n", n->name);
+					Bprint(&bout, "no touch of virtual '%s'\n",
+						n->name);
 			}
 			n->time = time((long *)0);
 			MADESET(n, MADE);
 		}
 	} else {
 		if(DEBUG(D_EXEC))
-			fprint(1, "recipe='%s'", j->r->recipe);/**/
+			fprint(1, "recipe='%s'\n", j->r->recipe);	/**/
 		Bflush(&bout);
 		if(j->r->attr&NOMINUSE)
 			flags = 0;
@@ -86,7 +88,8 @@ sched(void)
 		usage();
 		nrunning++;
 		if(DEBUG(D_EXEC))
-			fprint(1, "pid for target %s = %d\n", wtos(j->t, ' '), events[slot].pid);
+			fprint(1, "pid for target %s = %d\n", wtos(j->t, ' '),
+				events[slot].pid);
 	}
 }
 
@@ -193,7 +196,8 @@ nproc(void)
 		fprint(1, "nprocs = %d\n", nproclimit);
 	if(nproclimit > nevents){
 		if(nevents)
-			events = (Event *)Realloc((char *)events, nproclimit*sizeof(Event));
+			events = (Event *)Realloc((char *)events,
+				nproclimit*sizeof(Event));
 		else
 			events = (Event *)Malloc(nproclimit*sizeof(Event));
 		while(nevents < nproclimit)
@@ -207,7 +211,8 @@ nextslot(void)
 	int i;
 
 	for(i = 0; i < nproclimit; i++)
-		if(events[i].pid <= 0) return i;
+		if(events[i].pid <= 0)
+			return i;
 	assert(/*out of slots!!*/ 0);
 	return 0;	/* cyntax */
 }
@@ -218,10 +223,11 @@ pidslot(int pid)
 	int i;
 
 	for(i = 0; i < nevents; i++)
-		if(events[i].pid == pid) return(i);
+		if(events[i].pid == pid)
+			return i;
 	if(DEBUG(D_EXEC))
 		fprint(2, "mk: wait returned unexpected process %d\n", pid);
-	return(-1);
+	return -1;
 }
 
 
@@ -282,7 +288,7 @@ usage(void)
 
 	time(&t);
 	if(tick)
-		tslot[nrunning] += (t-tick);
+		tslot[nrunning] += t - tick;
 	tick = t;
 }
 

+ 7 - 6
sys/src/cmd/mk/shprint.c

@@ -17,7 +17,7 @@ shprint(char *s, Envy *env, Bufblock *buf)
 		else {
 			rinsert(buf, r);
 			s += n;
-			s = copyq(s, r, buf);	/*handle quoted strings*/
+			s = copyq(s, r, buf);	/* handle quoted strings */
 		}
 	}
 	insert(buf, 0);
@@ -44,7 +44,7 @@ vexpand(char *w, Envy *env, Bufblock *buf)
 	char *s, carry, *p, *q;
 
 	assert(/*vexpand no $*/ *w == '$');
-	p = w+1;	/* skip dollar sign */
+	p = w+1;		/* skip dollar sign */
 	if(*p == '{') {
 		p++;
 		q = utfrune(p, '}');
@@ -61,7 +61,7 @@ vexpand(char *w, Envy *env, Bufblock *buf)
 	if (s) {
 		bufcpy(buf, s, strlen(s));
 		free(s);
-	} else 		/* copy name intact*/
+	} else 			/* copy name intact*/
 		bufcpy(buf, w, q-w);
 	return(q);
 }
@@ -69,12 +69,12 @@ vexpand(char *w, Envy *env, Bufblock *buf)
 void
 front(char *s)
 {
-	char *t, *q;
 	int i, j;
+	char *t, *q;
 	char *flds[512];
 
 	q = strdup(s);
-	i = getfields(q, flds, 512, 0, " \t\n");
+	i = getfields(q, flds, nelem(flds), 0, " \t\n");
 	if(i > 5){
 		flds[4] = flds[i-1];
 		flds[3] = "...";
@@ -82,7 +82,8 @@ front(char *s)
 	}
 	t = s;
 	for(j = 0; j < i; j++){
-		for(s = flds[j]; *s; *t++ = *s++);
+		for(s = flds[j]; *s; *t++ = *s++)
+			;
 		*t++ = ' ';
 	}
 	*t = 0;

+ 3 - 2
sys/src/cmd/rc/code.c

@@ -66,10 +66,11 @@ char*
 fnstr(tree *t)
 {
 	io *f = openstr();
-	char *v;
+	void *v;
 	extern char nl;
 	char svnl = nl;
-	nl=';';
+
+	nl = ';';
 	pfmt(f, "%t", t);
 	nl = svnl;
 	v = f->strp;

+ 23 - 7
sys/src/cmd/rc/exec.c

@@ -530,6 +530,7 @@ Xcase(void)
 	word *p;
 	char *s;
 	int ok = 0;
+
 	s = list2str(runq->argv->next->words);
 	for(p = runq->argv->words;p;p = p->next){
 		if(match(s, p->word, '\0')){
@@ -550,10 +551,11 @@ conclist(word *lp, word *rp, word *tail)
 {
 	char *buf;
 	word *v;
+
 	if(lp->next || rp->next)
-		tail = conclist(lp->next==0?lp:lp->next, rp->next==0?rp:rp->next,
-			tail);
-	buf = emalloc(strlen(lp->word)+strlen(rp->word)+1);
+		tail = conclist(lp->next==0? lp: lp->next,
+			rp->next==0? rp: rp->next, tail);
+	buf = emalloc(strlen(lp->word)+strlen((char *)rp->word)+1);
 	strcpy(buf, lp->word);
 	strcat(buf, rp->word);
 	v = newword(buf, tail);
@@ -568,6 +570,7 @@ Xconc(void)
 	word *rp = runq->argv->next->words;
 	word *vp = runq->argv->next->next->words;
 	int lc = count(lp), rc = count(rp);
+
 	if(lc!=0 || rc!=0){
 		if(lc==0 || rc==0){
 			Xerror1("null list in concatenation");
@@ -588,6 +591,7 @@ void
 Xassign(void)
 {
 	var *v;
+
 	if(count(runq->argv->words)!=1){
 		Xerror1("variable name not singleton!");
 		return;
@@ -610,6 +614,7 @@ word*
 copywords(word *a, word *tail)
 {
 	word *v = 0, **end;
+
 	for(end=&v;a;a = a->next,end=&(*end)->next)
 		*end = newword(a->word, 0);
 	*end = tail;
@@ -622,6 +627,7 @@ Xdol(void)
 	word *a, *star;
 	char *s, *t;
 	int n;
+
 	if(count(runq->argv->words)!=1){
 		Xerror1("variable name not singleton!");
 		return;
@@ -629,14 +635,16 @@ Xdol(void)
 	s = runq->argv->words->word;
 	deglob(s);
 	n = 0;
-	for(t = s;'0'<=*t && *t<='9';t++) n = n*10+*t-'0';
+	for(t = s; '0'<=*t && *t<='9'; t++)
+		n = n*10 + *t - '0';
 	a = runq->argv->next->words;
 	if(n==0 || *t)
 		a = copywords(vlook(s)->val, a);
 	else{
 		star = vlook("*")->val;
 		if(star && 1<=n && n<=count(star)){
-			while(--n) star = star->next;
+			while(--n)
+				star = star->next;
 			a = newword(star->word, a);
 		}
 	}
@@ -650,6 +658,7 @@ Xqdol(void)
 	word *a, *p;
 	char *s;
 	int n;
+
 	if(count(runq->argv->words)!=1){
 		Xerror1("variable name not singleton!");
 		return;
@@ -683,16 +692,19 @@ subwords(word *val, int len, word *sub, word *a)
 {
 	int n;
 	char *s;
+
 	if(!sub)
 		return a;
 	a = subwords(val, len, sub->next, a);
 	s = sub->word;
 	deglob(s);
 	n = 0;
-	while('0'<=*s && *s<='9') n = n*10+ *s++ -'0';
+	while('0'<=*s && *s<='9')
+		n = n*10 + *s++ - '0';
 	if(n<1 || len<n)
 		return a;
-	for(;n!=1;--n) val = val->next;
+	for(; n!=1; --n)
+		val = val->next;
 	return newword(val->word, a);
 }
 
@@ -701,6 +713,7 @@ Xsub(void)
 {
 	word *a, *v;
 	char *s;
+
 	if(count(runq->argv->next->words)!=1){
 		Xerror1("variable name not singleton!");
 		return;
@@ -761,6 +774,7 @@ void
 Xunlocal(void)
 {
 	var *v = runq->local, *hid;
+
 	if(v==0)
 		panic("Xunlocal: no locals!", 0);
 	runq->local = v->next;
@@ -775,6 +789,7 @@ void
 freewords(word *w)
 {
 	word *nw;
+
 	while(w){
 		efree(w->word);
 		nw = w->next;
@@ -789,6 +804,7 @@ Xfn(void)
 	var *v;
 	word *a;
 	int end;
+
 	end = runq->code[runq->pc].i;
 	for(a = runq->argv->words;a;a = a->next){
 		v = gvlook(a->word);

+ 30 - 21
sys/src/cmd/rc/exec.h

@@ -18,55 +18,64 @@ extern void Xerror1(char*);
  * i.e. word0->word1->word2->word3->0
  */
 struct word{
-	char *word;
-	word *next;
+	char	*word;
+	word	*next;
 };
 struct list{
-	word *words;
-	list *next;
+	word	*words;
+	list	*next;
 };
+
 word *newword(char *, word *), *copywords(word *, word *);
+
 struct redir{
-	char type;			/* what to do */
-	short from, to;			/* what to do it to */
+	char	type;			/* what to do */
+	short	from, to;			/* what to do it to */
 	struct redir *next;		/* what else to do (reverse order) */
 };
+
 #define	NSTATUS	ERRMAX			/* length of status (from plan 9) */
+
 /*
  * redir types
  */
 #define	ROPEN	1			/* dup2(from, to); close(from); */
 #define	RDUP	2			/* dup2(from, to); */
 #define	RCLOSE	3			/* close(from); */
+
 struct thread{
 	union code *code;		/* code for this thread */
-	int pc;				/* code[pc] is the next instruction */
+	int	pc;			/* code[pc] is the next instruction */
 	struct list *argv;		/* argument stack */
 	struct redir *redir;		/* redirection stack */
 	struct redir *startredir;	/* redir inheritance point */
 	struct var *local;		/* list of local variables */
-	char *cmdfile;			/* file name in Xrdcmd */
+	char	*cmdfile;		/* file name in Xrdcmd */
 	struct io *cmdfd;		/* file descriptor for Xrdcmd */
-	int iflast;			/* static `if not' checking */
-	int eof;			/* is cmdfd at eof? */
-	int iflag;			/* interactive? */
-	int lineno;			/* linenumber */
-	int pid;			/* process for Xpipewait to wait for */
-	char status[NSTATUS];		/* status for Xpipewait */
-	tree *treenodes;		/* tree nodes created by this process */
-	thread *ret;		/* who continues when this finishes */
+	int	iflast;			/* static `if not' checking */
+	int	eof;			/* is cmdfd at eof? */
+	int	iflag;			/* interactive? */
+	int	lineno;			/* linenumber */
+	int	pid;			/* process for Xpipewait to wait for */
+	char	status[NSTATUS];	/* status for Xpipewait */
+	tree	*treenodes;		/* tree nodes created by this process */
+	thread	*ret;			/* who continues when this finishes */
 };
 thread *runq;
+
 code *codecopy(code*);
+
 code *codebuf;				/* compiler output */
-int ntrap;				/* number of outstanding traps */
-int trap[NSIG];				/* number of outstanding traps per type */
+int ntrap;				/* # of outstanding traps */
+int trap[NSIG];				/* # of outstanding traps per type */
+
 struct builtin{
-	char *name;
-	void (*fnc)(void);
+	char	*name;
+	void	(*fnc)(void);
 };
+
 extern struct builtin Builtin[];
-int eflagok;			/* kludge flag so that -e doesn't exit in startup */
+int eflagok;		/* kludge flag so that -e doesn't exit in startup */
 int havefork;
 
 void execcd(void), execwhatis(void), execeval(void), execexec(void);

+ 7 - 7
sys/src/cmd/rc/fns.h

@@ -10,18 +10,18 @@ void	Exit(char*);
 int	ForkExecute(char*, char**, int, int, int);
 int	Globsize(char*);
 int	Isatty(int);
-void	Memcpy(char*, char*, long);
+void	Memcpy(void*, void*, long);
 void	Noerror(void);
 int	Opendir(char*);
-long	Read(int, char*, long);
-int	Readdir(int, char*, int);
+long	Read(int, void*, long);
+int	Readdir(int, void*, int);
 long	Seek(int, long, long);
 void	Trapinit(void);
 void	Unlink(char*);
 void	Updenv(void);
 void	Vinit(void);
 int	Waitfor(int, int);
-long	Write(int, char*, long);
+long	Write(int, void*, long);
 void	addwaitpid(int);
 int	advance(void);
 int	back(int);
@@ -30,7 +30,7 @@ void	codefree(code*);
 int	compile(tree*);
 char *	list2str(word*);
 int	count(word*);
-void	deglob(char*);
+void	deglob(void*);
 void	delwaitpid(int);
 void	dotrap(void);
 void	freenodes(void);
@@ -41,8 +41,8 @@ int	idchr(int);
 void	inttoascii(char*, long);
 void	kinit(void);
 int	mapfd(int);
-int	match(char*, char*, int);
-int	matchfn(char*, char*);
+int	match(void*, void*, int);
+int	matchfn(void*, void*);
 char**	mkargv(word*);
 void	clearwaitpids(void);
 void	panic(char*, int);

+ 55 - 37
sys/src/cmd/rc/getflags.c

@@ -1,68 +1,67 @@
-/*% cyntax -DTEST % && cc -DTEST -go # %
- */
 #include "rc.h"
 #include "getflags.h"
 #include "fns.h"
+
 char *flagset[] = {"<flag>"};
 char **flag[NFLAG];
-char cmdline[NCMDLINE+1];
 char *cmdname;
-static char *flagarg="";
-static void reverse(char**, char**);
-static int scanflag(int, char*);
-static void errn(char*, int);
-static void errs(char*);
-static void errc(int);
+
+static char *flagarg = "";
 static int reason;
+
 #define	RESET	1
 #define	FEWARGS	2
 #define	FLAGSYN	3
 #define	BADFLAG	4
+
 static int badflag;
 
+static void reverse(char**, char**);
+static int scanflag(int, char*);
+static void errn(char*, int);
+static void errs(char*);
+static void errc(int);
+
 int
 getflags(int argc, char *argv[], char *flags, int stop)
 {
-	char *s, *t;
+	char *s;
 	int i, j, c, count;
+
 	flagarg = flags;
 	if(cmdname==0)
 		cmdname = argv[0];
-	s = cmdline;
-	for(i = 0;i!=argc;i++){
-		for(t = argv[i];*t;t++)
-			if(s!=&cmdline[NCMDLINE])
-				*s++=*t;
-		if(i!=argc-1 && s!=&cmdline[NCMDLINE])
-			*s++=' ';
-	}
-	*s='\0';
+
 	i = 1;
 	while(i!=argc){
-		if(argv[i][0]!='-' || argv[i][1]=='\0'){
-			if(stop)
+		if(argv[i][0] != '-' || argv[i][1] == '\0'){
+			if(stop)		/* always true in rc */
 				return argc;
 			i++;
 			continue;
 		}
 		s = argv[i]+1;
 		while(*s){
-			c=*s++;
+			c = *s++;
 			count = scanflag(c, flags);
-			if(count==-1)
+			if(count == -1)
 				return -1;
-			if(flag[c]){ reason = RESET; badflag = c; 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++)
+					for(j = i+1; j <= argc; j++)
 						argv[j-1] = argv[j];
 					--argc;
 				}
 			}
 			else{
 				if(*s=='\0'){
-					for(j = i+1;j<=argc;j++)
+					for(j = i+1; j <= argc; j++)
 						argv[j-1] = argv[j];
 					--argc;
 					s = argv[i];
@@ -75,10 +74,10 @@ getflags(int argc, char *argv[], char *flags, int stop)
 				reverse(argv+i, argv+argc);
 				reverse(argv+i, argv+argc-count);
 				reverse(argv+argc-count+1, argv+argc);
-				argc-=count;
+				argc -= count;
 				flag[c] = argv+argc+1;
 				flag[c][0] = s;
-				s="";
+				s = "";
 			}
 		}
 	}
@@ -89,33 +88,46 @@ static void
 reverse(char **p, char **q)
 {
 	char *t;
-	for(;p<q;p++,--q){ t=*p; *p=*q; *q = 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++;
+			fc = *f++;
 			if(*f==':'){
 				f++;
-				if(*f<'0' || '9'<*f){ reason = FLAGSYN; return -1; }
+				if(*f < '0' || '9' < *f){
+					reason = FLAGSYN;
+					return -1;
+				}
 				count = 0;
-				while('0'<=*f && *f<='9') count = count*10+*f++-'0';
+				while('0' <= *f && *f <= '9')
+					count = count*10 + *f++ - '0';
 			}
 			else
 				count = 0;
 			if(*f=='['){
 				do{
 					f++;
-					if(*f=='\0'){ reason = FLAGSYN; return -1; }
-				}while(*f!=']');
+					if(*f=='\0'){
+						reason = FLAGSYN;
+						return -1;
+					}
+				}while(*f != ']');
 				f++;
 			}
 			if(c==fc)
@@ -222,21 +234,27 @@ usage(char *tail)
 static void
 errn(char *s, int count)
 {
-	while(count){ errc(*s++); --count; }
+	while(count){
+		errc(*s++);
+		--count;
+	}
 }
 
 static void
 errs(char *s)
 {
-	while(*s) errc(*s++);
+	while(*s)
+		errc(*s++);
 }
+
 #define	NBUF	80
+
 static char buf[NBUF], *bufp = buf;
 
 static void
 errc(int c)
 {
-	*bufp++=c;
+	*bufp++ = c;
 	if(bufp==&buf[NBUF] || c=='\n'){
 		Write(2, buf, bufp-buf);
 		bufp = buf;

+ 2 - 2
sys/src/cmd/rc/getflags.h

@@ -1,7 +1,7 @@
 #define	NFLAG	128
-#define	NCMDLINE	512
+
 extern char **flag[NFLAG];
-extern char cmdline[NCMDLINE+1];
 extern char *cmdname;
 extern char *flagset[];
+
 int getflags(int, char*[], char*, int);

+ 53 - 29
sys/src/cmd/rc/glob.c

@@ -1,20 +1,24 @@
 #include "rc.h"
 #include "exec.h"
 #include "fns.h"
+
 char *globname;
 struct word *globv;
+
 /*
  * delete all the GLOB marks from s, in place
  */
 
 void
-deglob(char *s)
+deglob(void *as)
 {
+	char *s = as;
 	char *t = s;
+	
 	do{
 		if(*t==GLOB)
 			t++;
-		*s++=*t;
+		*s++ = *t;
 	}while(*t++);
 }
 
@@ -30,11 +34,15 @@ globsort(word *left, word *right)
 	char **list;
 	word *a;
 	int n = 0;
-	for(a = left;a!=right;a = a->next) n++;
+
+	for(a = left;a!=right;a = a->next)
+		n++;
 	list = (char **)emalloc(n*sizeof(char *));
-	for(a = left,n = 0;a!=right;a = a->next,n++) list[n] = a->word;
+	for(a = left,n = 0;a!=right;a = a->next,n++)
+		list[n] = a->word;
 	qsort((void *)list, n, sizeof(void *), globcmp);
-	for(a = left,n = 0;a!=right;a = a->next,n++) a->word = list[n];
+	for(a = left,n = 0;a!=right;a = a->next,n++)
+		a->word = list[n];
 	efree((char *)list);
 }
 /*
@@ -43,9 +51,9 @@ globsort(word *left, word *right)
  */
 
 void
-globdir(char *p, char *namep)
+globdir(uchar *p, uchar *namep)
 {
-	char *t, *newp;
+	uchar *t, *newp;
 	int f;
 	/* scan the pattern looking for a component with a metacharacter in it */
 	if(*p=='\0'){
@@ -72,38 +80,44 @@ globdir(char *p, char *namep)
 	}
 	/* read the directory and recur for any entry that matches */
 	*namep='\0';
-	if((f = Opendir(globname[0]?globname:"."))<0) return;
-	while(*newp!='/' && *newp!='\0') newp++;
+	if((f = Opendir(globname[0]? globname: ".")) < 0)
+		return;
+	while(*newp!='/' && *newp!='\0')
+		newp++;
 	while(Readdir(f, namep, *newp=='/')){
 		if(matchfn(namep, p)){
-			for(t = namep;*t;t++);
+			for(t = namep;*t;t++)
+				;
 			globdir(newp, t);
 		}
 	}
 	Closedir(f);
 }
+
 /*
  * Push all file names matched by p on the current thread's stack.
  * If there are no matches, the list consists of p.
  */
 
 void
-glob(char *p)
+glob(void *ap)
 {
+	uchar *p = ap;
 	word *svglobv = globv;
-	int globlen = Globsize(p);
+	int globlen = Globsize(ap);
+
 	if(!globlen){
 		deglob(p);
-		globv = newword(p, globv);
+		globv = newword((char *)p, globv);
 		return;
 	}
 	globname = emalloc(globlen);
 	globname[0]='\0';
-	globdir(p, globname);
+	globdir(p, (uchar *)globname);
 	efree(globname);
 	if(svglobv==globv){
 		deglob(p);
-		globv = newword(p, globv);
+		globv = newword((char *)p, globv);
 	}
 	else
 		globsort(globv, svglobv);
@@ -113,11 +127,12 @@ glob(char *p)
  */
 
 int
-equtf(char *p, char *q)
+equtf(uchar *p, uchar *q)
 {
-	if(*p!=*q)
+	if(*p != *q)
 		return 0;
-	if(twobyte(*p)) return p[1]==q[1];
+	if(twobyte(*p))
+		return p[1]==q[1];
 	if(threebyte(*p)){
 		if(p[1]!=q[1])
 			return 0;
@@ -132,11 +147,13 @@ equtf(char *p, char *q)
  * not jumping past nuls in broken utf codes!
  */
 
-char*
-nextutf(char *p)
+uchar*
+nextutf(uchar *p)
 {
-	if(twobyte(*p)) return p[1]=='\0'?p+1:p+2;
-	if(threebyte(*p)) return p[1]=='\0'?p+1:p[2]=='\0'?p+2:p+3;
+	if(twobyte(*p))
+		return p[1]=='\0'? p+1: p+2;
+	if(threebyte(*p))
+		return p[1]=='\0'? p+1: p[2]=='\0'? p+2: p+3;
 	return p+1;
 }
 /*
@@ -144,11 +161,14 @@ nextutf(char *p)
  */
 
 int
-unicode(char *p)
+unicode(uchar *p)
 {
-	int u=*p&0xff;
-	if(twobyte(u)) return ((u&0x1f)<<6)|(p[1]&0x3f);
-	if(threebyte(u)) return (u<<12)|((p[1]&0x3f)<<6)|(p[2]&0x3f);
+	int u = *p;
+
+	if(twobyte(u))
+		return ((u&0x1f)<<6)|(p[1]&0x3f);
+	if(threebyte(u))
+		return (u<<12)|((p[1]&0x3f)<<6)|(p[2]&0x3f);
 	return u;
 }
 /*
@@ -160,18 +180,22 @@ unicode(char *p)
  */
 
 int
-matchfn(char *s, char *p)
+matchfn(void *as, void *ap)
 {
+	uchar *s = as, *p = ap;
+
 	if(s[0]=='.' && (s[1]=='\0' || s[1]=='.' && s[2]=='\0') && p[0]!='.')
 		return 0;
 	return match(s, p, '/');
 }
 
 int
-match(char *s, char *p, int stop)
+match(void *as, void *ap, int stop)
 {
 	int compl, hit, lo, hi, t, c;
-	for(;*p!=stop && *p!='\0';s = nextutf(s),p = nextutf(p)){
+	uchar *s = as, *p = ap;
+
+	for(; *p!=stop && *p!='\0'; s = nextutf(s), p = nextutf(p)){
 		if(*p!=GLOB){
 			if(!equtf(p, s)) return 0;
 		}

+ 13 - 10
sys/src/cmd/rc/havefork.c

@@ -71,21 +71,23 @@ Xpipe(void)
 	}
 }
 
+enum { Wordmax = 8192, };
+
 /*
  * Who should wait for the exit from the fork?
  */
 void
 Xbackq(void)
 {
-	char wd[8193];
-	int c;
-	char *s, *ewd=&wd[8192], *stop;
+	int c, pid;
+	int pfd[2];
+	char wd[Wordmax + 1];
+	char *s, *ewd = &wd[Wordmax], *stop;
 	struct io *f;
 	var *ifs = vlook("ifs");
 	word *v, *nextv;
-	int pfd[2];
-	int pid;
-	stop = ifs->val?ifs->val->word:"";
+
+	stop = ifs->val? ifs->val->word: "";
 	if(pipe(pfd)<0){
 		Xerror("can't make pipe");
 		return;
@@ -116,7 +118,8 @@ Xbackq(void)
 					s = wd;
 				}
 			}
-			else *s++=c;
+			else
+				*s++=c;
 		}
 		if(s!=wd){
 			*s='\0';
@@ -140,10 +143,10 @@ void
 Xpipefd(void)
 {
 	struct thread *p = runq;
-	int pc = p->pc, pid;
-	char name[40];
+	int pc = p->pc, pid, sidefd, mainfd;
 	int pfd[2];
-	int sidefd, mainfd;
+	char name[40];
+
 	if(pipe(pfd)<0){
 		Xerror("can't get pipe");
 		return;

+ 4 - 3
sys/src/cmd/rc/haventfork.c

@@ -190,15 +190,16 @@ execforkexec(void)
 
 	for(path = searchpath(runq->argv->words->word);path;path = path->next){
 		nc = strlen(path->word);
-		if(nc<sizeof(file)){
+		if(nc < sizeof file - 1){	/* 1 for / */
 			strcpy(file, path->word);
 			if(file[0]){
 				strcat(file, "/");
 				nc++;
 			}
-			if(nc+strlen(argv[1])<sizeof(file)){
+			if(nc + strlen(argv[1]) < sizeof file){
 				strcat(file, argv[1]);
-				pid = ForkExecute(file, argv+1, mapfd(0), mapfd(1), mapfd(2));
+				pid = ForkExecute(file, argv+1, mapfd(0),
+					mapfd(1), mapfd(2));
 				if(pid >= 0){
 					free(argv);
 					return pid;

+ 40 - 26
sys/src/cmd/rc/here.c

@@ -2,26 +2,30 @@
 #include "exec.h"
 #include "io.h"
 #include "fns.h"
+
 struct here *here, **ehere;
+
 int ser = 0;
 char tmp[]="/tmp/here0000.0000";
 char hex[]="0123456789abcdef";
-void psubst(io*, char*);
+
+void psubst(io*, uchar*);
 void pstrs(io*, word*);
 
 void
 hexnum(char *p, int n)
 {
-	*p++=hex[(n>>12)&0xF];
-	*p++=hex[(n>>8)&0xF];
-	*p++=hex[(n>>4)&0xF];
-	*p = hex[n&0xF];
+	*p++ = hex[(n>>12)&0xF];
+	*p++ = hex[(n>>8)&0xF];
+	*p++ = hex[(n>>4)&0xF];
+	*p   = hex[n&0xF];
 }
 
 tree*
 heredoc(tree *tag)
 {
 	struct here *h = new(struct here);
+
 	if(tag->type!=WORD)
 		yyerror("Bad here tag");
 	h->next = 0;
@@ -36,6 +40,7 @@ heredoc(tree *tag)
 	h->name = strdup(tmp);
 	return token(tmp, WORD);
 }
+
 /*
  * bug: lines longer than NLINE get split -- this can cause spurious
  * missubstitution, or a misrecognized EOF marker.
@@ -45,13 +50,14 @@ heredoc(tree *tag)
 void
 readhere(void)
 {
+	int c, subst;
 	struct here *h, *nexth;
 	io *f;
 	char *s, *tag;
-	int c, subst;
 	char line[NLINE+1];
+
 	for(h = here;h;h = nexth){
-		subst=!h->tag->quoted;
+		subst = !h->tag->quoted;
 		tag = h->tag->str;
 		c = Creat(h->name);
 		if(c<0)
@@ -59,21 +65,25 @@ readhere(void)
 		f = openfd(c);
 		s = line;
 		pprompt();
-		while((c = rchr(runq->cmdfd))!=EOF){
-			if(c=='\n' || s==&line[NLINE]){
+		while((c = rchr(runq->cmdfd)) != EOF){
+			if(c == '\n' || s == &line[NLINE]){
 				*s='\0';
-				if(tag && strcmp(line, tag)==0) break;
+				if(tag && strcmp(line, tag)==0)
+					break;
 				if(subst)
-					psubst(f, line);
-				else pstr(f, line);
+					psubst(f, (uchar *)line);
+				else
+					pstr(f, line);
 				s = line;
 				if(c=='\n'){
 					pprompt();
 					pchr(f, c);
 				}
-				else *s++=c;
+				else
+					*s++=c;
 			}
-			else *s++=c;
+			else
+				*s++=c;
 		}
 		flush(f);
 		closeio(f);
@@ -86,19 +96,20 @@ readhere(void)
 }
 
 void
-psubst(io *f, char *s)
+psubst(io *f, uchar *s)
 {
-	char *t, *u;
 	int savec, n;
+	uchar *t, *u;
 	word *star;
+
 	while(*s){
 		if(*s!='$'){
-			if(0xa0<=(*s&0xff) && (*s&0xff)<=0xf5){
+			if(0xa0 <= *s && *s <= 0xf5){
 				pchr(f, *s++);
 				if(*s=='\0')
 					break;
 			}
-			else if(0xf6<=(*s&0xff) && (*s&0xff)<=0xf7){
+			else if(0xf6 <= *s && *s <= 0xf7){
 				pchr(f, *s++);
 				if(*s=='\0')
 					break;
@@ -109,24 +120,27 @@ psubst(io *f, char *s)
 			pchr(f, *s++);
 		}
 		else{
-			t=++s;
+			t = ++s;
 			if(*t=='$')
 				pchr(f, *t++);
 			else{
-				while(*t && idchr(*t)) t++;
-				savec=*t;
-				*t='\0';
+				while(*t && idchr(*t))
+					t++;
+				savec = *t;
+				*t = '\0';
 				n = 0;
-				for(u = s;*u && '0'<=*u && *u<='9';u++) n = n*10+*u-'0';
+				for(u = s;*u && '0'<=*u && *u<='9';u++)
+					n = n*10 + *u-'0';
 				if(n && *u=='\0'){
 					star = vlook("*")->val;
-					if(star && 1<=n && n<=count(star)){
-						while(--n) star = star->next;
+					if(star && 1 <= n && n <= count(star)){
+						while(--n)
+							star = star->next;
 						pstr(f, star->word);
 					}
 				}
 				else
-					pstrs(f, vlook(s)->val);
+					pstrs(f, vlook((char *)s)->val);
 				*t = savec;
 				if(savec=='^')
 					t++;

+ 58 - 40
sys/src/cmd/rc/io.c

@@ -2,6 +2,9 @@
 #include "exec.h"
 #include "io.h"
 #include "fns.h"
+
+enum { Stralloc = 100, };
+
 int pfmtnest = 0;
 
 void
@@ -9,10 +12,11 @@ pfmt(io *f, char *fmt, ...)
 {
 	va_list ap;
 	char err[ERRMAX];
+
 	va_start(ap, fmt);
 	pfmtnest++;
-	for(;*fmt;fmt++)
-		if(*fmt!='%')
+	for(; *fmt; fmt++)
+		if(*fmt != '%')
 			pchr(f, *fmt);
 		else switch(*++fmt){
 		case '\0':
@@ -62,7 +66,8 @@ pchr(io *b, int c)
 {
 	if(b->bufp==b->ebuf)
 		fullbuf(b, c);
-	else *b->bufp++=c;
+	else
+		*b->bufp++ = c;
 }
 
 int
@@ -70,17 +75,18 @@ rchr(io *b)
 {
 	if(b->bufp==b->ebuf)
 		return emptybuf(b);
-	return *b->bufp++ & 0xFF;
+	return *b->bufp++;
 }
 
 void
 pquo(io *f, char *s)
 {
 	pchr(f, '\'');
-	for(;*s;s++)
+	for(; *s; s++)
 		if(*s=='\'')
 			pfmt(f, "''");
-		else pchr(f, *s);
+		else
+			pchr(f, *s);
 	pchr(f, '\'');
 }
 
@@ -88,10 +94,14 @@ void
 pwrd(io *f, char *s)
 {
 	char *t;
-	for(t = s;*t;t++) if(!wordchr(*t)) break;
+
+	for(t = s; *t; t++)
+		if(!wordchr(*t))
+			break;
 	if(t==s || *t)
 		pquo(f, s);
-	else pstr(f, s);
+	else
+		pstr(f, s);
 }
 
 void
@@ -102,9 +112,11 @@ pptr(io *f, void *v)
 
 	p = (uintptr)v;
 	if(sizeof(uintptr) == sizeof(uvlong) && p>>32)
-		for(n = 60;n>=32;n-=4) pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
+		for(n = 60; n >= 32; n -= 4)
+			pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
 
-	for(n = 28;n>=0;n-=4) pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
+	for(n = 28; n >= 0; n -= 4)
+		pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
 }
 
 void
@@ -112,14 +124,15 @@ pstr(io *f, char *s)
 {
 	if(s==0)
 		s="(null)";
-	while(*s) pchr(f, *s++);
+	while(*s)
+		pchr(f, *s++);
 }
 
 void
 pdec(io *f, int n)
 {
 	if(n<0){
-		n=-n;
+		n = -n;
 		if(n>=0){
 			pchr(f, '-');
 			pdec(f, n);
@@ -150,11 +163,11 @@ pval(io *f, word *a)
 {
 	if(a){
 		while(a->next && a->next->word){
-			pwrd(f, a->word);
+			pwrd(f, (char *)a->word);
 			pchr(f, ' ');
 			a = a->next;
 		}
-		pwrd(f, a->word);
+		pwrd(f, (char *)a->word);
 	}
 }
 
@@ -162,32 +175,32 @@ int
 fullbuf(io *f, int c)
 {
 	flush(f);
-	return *f->bufp++=c;
+	return *f->bufp++ = c;
 }
 
 void
 flush(io *f)
 {
 	int n;
-	char *s;
+
 	if(f->strp){
-		n = f->ebuf-f->strp;
-		f->strp = realloc(f->strp, n+101);
+		n = f->ebuf - f->strp;
+		f->strp = realloc(f->strp, n+Stralloc+1);
 		if(f->strp==0)
-			panic("Can't realloc %d bytes in flush!", n+101);
-		f->bufp = f->strp+n;
-		f->ebuf = f->bufp+100;
-		for(s = f->bufp;s<=f->ebuf;s++) *s='\0';
+			panic("Can't realloc %d bytes in flush!", n+Stralloc+1);
+		f->bufp = f->strp + n;
+		f->ebuf = f->bufp + Stralloc;
+		memset(f->bufp, '\0', Stralloc+1);
 	}
 	else{
 		n = f->bufp-f->buf;
-		if(n && Write(f->fd, f->buf, n) < 0){
-			Write(3, "Write error\n", 12);
+		if(n && Write(f->fd, f->buf, n) != n){
+			Write(2, "Write error\n", 12);
 			if(ntrap)
 				dotrap();
 		}
 		f->bufp = f->buf;
-		f->ebuf = f->buf+NBUF;
+		f->ebuf = f->buf + NBUF;
 	}
 }
 
@@ -195,6 +208,7 @@ io*
 openfd(int fd)
 {
 	io *f = new(struct io);
+
 	f->fd = fd;
 	f->bufp = f->ebuf = f->buf;
 	f->strp = 0;
@@ -205,13 +219,14 @@ io*
 openstr(void)
 {
 	io *f = new(struct io);
-	char *s;
-	f->fd=-1;
-	f->bufp = f->strp = emalloc(101);
-	f->ebuf = f->bufp+100;
-	for(s = f->bufp;s<=f->ebuf;s++) *s='\0';
+
+	f->fd = -1;
+	f->bufp = f->strp = emalloc(Stralloc+1);
+	f->ebuf = f->bufp + Stralloc;
+	memset(f->bufp, '\0', Stralloc+1);
 	return f;
 }
+
 /*
  * Open a corebuffer to read.  EOF occurs after reading len
  * characters from buf.
@@ -221,10 +236,11 @@ io*
 opencore(char *s, int len)
 {
 	io *f = new(struct io);
-	char *buf = emalloc(len);
-	f->fd= -1 /*open("/dev/null", 0)*/;
+	uchar *buf = emalloc(len);
+
+	f->fd = -1 /*open("/dev/null", 0)*/;
 	f->bufp = f->strp = buf;
-	f->ebuf = buf+len;
+	f->ebuf = buf + len;
 	Memcpy(buf, s, len);
 	return f;
 }
@@ -232,30 +248,32 @@ opencore(char *s, int len)
 void
 rewind(io *io)
 {
-	if(io->fd==-1)
+	if(io->fd == -1)
 		io->bufp = io->strp;
 	else{
 		io->bufp = io->ebuf = io->buf;
-		Seek(io->fd, 0L, 0);
+		Seek(io->fd, 0, 0);
 	}
 }
 
 void
 closeio(io *io)
 {
-	if(io->fd>=0)
+	if(io->fd >= 0)
 		close(io->fd);
 	if(io->strp)
 		efree(io->strp);
-	efree((char *)io);
+	efree(io);
 }
 
 int
 emptybuf(io *f)
 {
 	int n;
-	if(f->fd==-1 || (n = Read(f->fd, f->buf, NBUF))<=0) return EOF;
+
+	if(f->fd == -1 || (n = Read(f->fd, f->buf, NBUF)) <= 0)
+		return EOF;
 	f->bufp = f->buf;
-	f->ebuf = f->buf+n;
-	return *f->bufp++&0xff;
+	f->ebuf = f->buf + n;
+	return *f->bufp++;
 }

+ 5 - 2
sys/src/cmd/rc/io.h

@@ -1,10 +1,13 @@
 #define	EOF	(-1)
 #define	NBUF	512
+
 struct io{
-	int fd;
-	char *bufp, *ebuf, *strp, buf[NBUF];
+	int	fd;
+	uchar	*bufp, *ebuf, *strp;
+	uchar	buf[NBUF];
 };
 io *err;
+
 io *openfd(int), *openstr(void), *opencore(char *, int);
 int emptybuf(io*);
 void pchr(io*, int);

+ 1 - 0
sys/src/cmd/rc/mkfile

@@ -29,6 +29,7 @@ HFILES=rc.h\
 	io.h\
 	exec.h\
 	fns.h\
+	getflags.h\
 
 YFILES=syn.y
 

+ 74 - 41
sys/src/cmd/rc/plan9.c

@@ -8,6 +8,11 @@
 #include "io.h"
 #include "fns.h"
 #include "getflags.h"
+
+enum {
+	Maxenvname = 256,	/* undocumented limit */
+};
+
 char *Signame[] = {
 	"sigexit",	"sighup",	"sigint",	"sigquit",
 	"sigalrm",	"sigkill",	"sigfpe",	"sigterm",
@@ -26,10 +31,12 @@ char *syssigname[] = {
 };
 char Rcmain[]="/rc/lib/rcmain";
 char Fdprefix[]="/fd/";
+
 void execfinit(void);
 void execbind(void);
 void execmount(void);
 void execnewpgrp(void);
+
 builtin Builtin[] = {
 	"cd",		execcd,
 	"whatis",	execwhatis,
@@ -50,6 +57,7 @@ execnewpgrp(void)
 {
 	int arg;
 	char *s;
+
 	switch(count(runq->argv->words)){
 	case 1:
 		arg = RFENVG|RFNAMEG|RFNOTEG;
@@ -97,12 +105,12 @@ execnewpgrp(void)
 void
 Vinit(void)
 {
-	int dir, f, len;
-	word *val;
+	int dir, f, len, i, n, nent;
 	char *buf, *s;
+	char envname[Maxenvname];
+	word *val;
 	Dir *ent;
-	int i, nent;
-	char envname[256];
+
 	dir = open("/env", OREAD);
 	if(dir<0){
 		pfmt(err, "rc: can't open /env: %r\n");
@@ -116,17 +124,23 @@ Vinit(void)
 		for(i = 0; i<nent; i++){
 			len = ent[i].length;
 			if(len && strncmp(ent[i].name, "fn#", 3)!=0){
-				snprint(envname, sizeof envname, "/env/%s", ent[i].name);
+				snprint(envname, sizeof envname, "/env/%s",
+					ent[i].name);
 				if((f = open(envname, 0))>=0){
-					buf = emalloc((int)len+1);
-					read(f, buf, (long)len);
+					buf = emalloc(len+1);
+					n = readn(f, buf, len);
+					if (n <= 0)
+						buf[0] = '\0';
+					else
+						buf[n] = '\0';
 					val = 0;
 					/* Charitably add a 0 at the end if need be */
 					if(buf[len-1])
 						buf[len++]='\0';
 					s = buf+len-1;
 					for(;;){
-						while(s!=buf && s[-1]!='\0') --s;
+						while(s!=buf && s[-1]!='\0')
+							--s;
 						val = newword(s, val);
 						if(s==buf)
 							break;
@@ -143,16 +157,17 @@ Vinit(void)
 	}
 	close(dir);
 }
+
 int envdir;
 
 void
 Xrdfn(void)
 {
 	int f, len;
+	Dir *e;
+	char envname[Maxenvname];
 	static Dir *ent, *allocent;
 	static int nent;
-	Dir *e;
-	char envname[256];
 
 	for(;;){
 		if(nent == 0){
@@ -167,7 +182,8 @@ Xrdfn(void)
 			nent--;
 			len = e->length;
 			if(len && strncmp(e->name, "fn#", 3)==0){
-				snprint(envname, sizeof envname, "/env/%s", e->name);
+				snprint(envname, sizeof envname, "/env/%s",
+					e->name);
 				if((f = open(envname, 0))>=0){
 					execcmds(openfd(f));
 					return;
@@ -178,6 +194,7 @@ Xrdfn(void)
 	close(envdir);
 	Xreturn();
 }
+
 union code rdfns[4];
 
 void
@@ -226,16 +243,19 @@ Waitfor(int pid, int)
 	}
 
 	errstr(errbuf, sizeof errbuf);
-	if(strcmp(errbuf, "interrupted")==0) return -1;
+	if(strcmp(errbuf, "interrupted")==0)
+		return -1;
 	return 0;
 }
 
-char*
-*mkargv(word *a)
+char **
+mkargv(word *a)
 {
 	char **argv = (char **)emalloc((count(a)+2)*sizeof(char *));
 	char **argp = argv+1;	/* leave one at front for runcoms */
-	for(;a;a = a->next) *argp++=a->word;
+
+	for(; a; a = a->next)
+		*argp++ = a->word;
 	*argp = 0;
 	return argv;
 }
@@ -243,18 +263,19 @@ char*
 void
 addenv(var *v)
 {
-	char envname[256];
+	char envname[Maxenvname];
 	word *w;
 	int f;
 	io *fd;
+
 	if(v->changed){
 		v->changed = 0;
 		snprint(envname, sizeof envname, "/env/%s", v->name);
 		if((f = Creat(envname))<0)
 			pfmt(err, "rc: can't open %s: %r\n", envname);
 		else{
-			for(w = v->val;w;w = w->next)
-				write(f, w->word, strlen(w->word)+1L);
+			for(w = v->val; w; w = w->next)
+				write(f, w->word, strlen(w->word) + 1);
 			close(f);
 		}
 	}
@@ -287,8 +308,9 @@ void
 Updenv(void)
 {
 	var *v, **h;
-	for(h = gvar;h!=&gvar[NVAR];h++)
-		for(v=*h;v;v = v->next)
+
+	for(h = gvar; h != &gvar[NVAR]; h++)
+		for(v = *h; v; v = v->next)
 			addenv(v);
 	if(runq)
 		updenvlocal(runq->local);
@@ -329,32 +351,36 @@ Execute(word *args, word *path)
 	char **argv = mkargv(args);
 	char file[1024];
 	int nc;
+
 	Updenv();
-	for(;path;path = path->next){
+	for(; path; path = path->next){
 		nc = strlen(path->word);
-		if(nc<1024){
+		if(nc < sizeof file - 1){	/* 1 for / */
 			strcpy(file, path->word);
 			if(file[0]){
 				strcat(file, "/");
 				nc++;
 			}
-			if(nc+strlen(argv[1])<1024){
+			if(nc + strlen(argv[1]) < sizeof file){
 				strcat(file, argv[1]);
 				exec(file, argv+1);
 			}
-			else werrstr("command name too long");
+			else
+				werrstr("command name too long");
 		}
 	}
 	rerrstr(file, sizeof file);
 	pfmt(err, "%s: %s\n", argv[1], file);
 	efree((char *)argv);
 }
-#define	NDIR	256		/* shoud be a better way */
+
+#define	NDIR	256		/* should be a better way */
 
 int
 Globsize(char *p)
 {
 	int isglob = 0, globlen = NDIR+1;
+
 	for(;*p;p++){
 		if(*p==GLOB){
 			p++;
@@ -367,8 +393,9 @@ Globsize(char *p)
 	}
 	return isglob?globlen:0;
 }
+
 #define	NFD	50
-#define	NDBUF	32
+
 struct{
 	Dir	*dbuf;
 	int	i;
@@ -380,6 +407,7 @@ Opendir(char *name)
 {
 	Dir *db;
 	int f;
+
 	f = open(name, 0);
 	if(f==-1)
 		return f;
@@ -412,11 +440,11 @@ trimdirs(Dir *d, int nd)
  * onlydirs is advisory -- it means you only
  * need to return the directories.  it's okay to
  * return files too (e.g., on unix where you can't
- * tell during the readdir), but that just makes 
+ * tell during the readdir), but that just makes
  * the globber work harder.
  */
 int
-Readdir(int f, char *p, int onlydirs)
+Readdir(int f, void *p, int onlydirs)
 {
 	int n;
 
@@ -432,7 +460,7 @@ Again:
 				n = trimdirs(dir[f].dbuf, n);
 				if(n == 0)
 					goto Again;
-			}	
+			}
 			dir[f].n = n;
 		}else
 			dir[f].n = 0;
@@ -456,15 +484,20 @@ Closedir(int f)
 	}
 	close(f);
 }
+
 int interrupted = 0;
+
 void
 notifyf(void*, char *s)
 {
 	int i;
-	for(i = 0;syssigname[i];i++) if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){
-		if(strncmp(s, "sys: ", 5)!=0) interrupted = 1;
-		goto Out;
-	}
+
+	for(i = 0; syssigname[i]; i++)
+		if(strncmp(s, syssigname[i], strlen(syssigname[i])) == 0){
+			if(strncmp(s, "sys: ", 5) != 0)
+				interrupted = 1;
+			goto Out;
+		}
 	pfmt(err, "rc: note: %s\n", s);
 	noted(NDFLT);
 	return;
@@ -493,13 +526,13 @@ Unlink(char *name)
 }
 
 long
-Write(int fd, char *buf, long cnt)
+Write(int fd, void *buf, long cnt)
 {
-	return write(fd, buf, (long)cnt);
+	return write(fd, buf, cnt);
 }
 
 long
-Read(int fd, char *buf, long cnt)
+Read(int fd, void *buf, long cnt)
 {
 	return read(fd, buf, cnt);
 }
@@ -519,7 +552,7 @@ Executable(char *file)
 	statbuf = dirstat(file);
 	if(statbuf == nil)
 		return 0;
-	ret = ((statbuf->mode&0111)!=0 && (statbuf->mode&DMDIR)==0);
+	ret = ((statbuf->mode&0111) != 0 && !(statbuf->mode&DMDIR));
 	free(statbuf);
 	return ret;
 }
@@ -527,7 +560,7 @@ Executable(char *file)
 int
 Creat(char *file)
 {
-	return create(file, 1, 0666L);
+	return create(file, 1, 0666);
 }
 
 int
@@ -587,9 +620,9 @@ Abort(void)
 }
 
 void
-Memcpy(char *a, char *b, long n)
+Memcpy(void *a, void *b, long n)
 {
-	memmove(a, b, (long)n);
+	memmove(a, b, n);
 }
 
 void*
@@ -614,7 +647,7 @@ void
 delwaitpid(int pid)
 {
 	int r, w;
-	
+
 	for(r=w=0; r<nwaitpids; r++)
 		if(waitpids[r] != pid)
 			waitpids[w++] = waitpids[r];

+ 34 - 22
sys/src/cmd/rc/rc.h

@@ -38,13 +38,13 @@ typedef struct builtin builtin;
 #pragma incomplete io
 
 struct tree{
-	int type;
-	int rtype, fd0, fd1;		/* details of REDIR PIPE DUP tokens */
-	char *str;
-	int quoted;
-	int iskw;
-	tree *child[3];
-	tree *next;
+	int	type;
+	int	rtype, fd0, fd1;	/* details of REDIR PIPE DUP tokens */
+	char	*str;
+	int	quoted;
+	int	iskw;
+	tree	*child[3];
+	tree	*next;
 };
 tree *newtree(void);
 tree *token(char*, int), *klook(char*), *tree1(int, tree*);
@@ -60,14 +60,18 @@ tree *cmdtree;
  * Always call codefree(.) when deleting a reference.
  */
 union code{
-	void (*f)(void);
-	int i;
-	char *s;
+	void	(*f)(void);
+	int	i;
+	char	*s;
 };
+
 char *promptstr;
 int doprompt;
+
 #define	NTOK	8192
+
 char tok[NTOK];
+
 #define	APPEND	1
 #define	WRITE	2
 #define	READ	3
@@ -75,29 +79,37 @@ char tok[NTOK];
 #define	DUPFD	5
 #define	CLOSE	6
 #define RDWR	7
+
 struct var{
-	char *name;		/* ascii name */
-	word *val;	/* value */
-	int changed;
-	code *fn;		/* pointer to function's code vector */
-	int fnchanged;
-	int pc;			/* pc of start of function */
-	var *next;	/* next on hash or local list */
+	char	*name;		/* ascii name */
+	word	*val;		/* value */
+	int	changed;
+	code	*fn;		/* pointer to function's code vector */
+	int	fnchanged;
+	int	pc;		/* pc of start of function */
+	var	*next;		/* next on hash or local list */
 };
 var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
+
 #define	NVAR	521
+
 var *gvar[NVAR];				/* hash for globals */
+
 #define	new(type)	((type *)emalloc(sizeof(type)))
-char *emalloc(long);
+
+void *emalloc(long);
 void *Malloc(ulong);
-void efree(char*);
+void efree(void *);
+
 #define	NOFILE	128		/* should come from <param.h> */
+
 struct here{
-	tree *tag;
-	char *name;
+	tree	*tag;
+	char	*name;
 	struct here *next;
 };
 int mypid;
+
 /*
  * Glob character escape in strings:
  *	In a string, GLOB must be followed by *?[ or GLOB.
@@ -114,6 +126,7 @@ int mypid;
 #define	onebyte(c)	((c&0x80)==0x00)
 #define	twobyte(c)	((c&0xe0)==0xc0)
 #define	threebyte(c)	((c&0xf0)==0xe0)
+
 char **argp;
 char **args;
 int nerror;		/* number of errors encountered during compilation */
@@ -127,7 +140,6 @@ int doprompt;		/* is it time for a prompt? */
 #define	PRD	0
 #define	PWR	1
 char Rcmain[], Fdprefix[];
-#define	register
 /*
  * How many dot commands have we executed?
  * Used to ensure that -v flag doesn't print rcmain.

+ 51 - 31
sys/src/cmd/rc/simple.c

@@ -10,10 +10,13 @@
  * Search through the following code to see if we're just going to exit.
  */
 int
-exitnext(void){
-	union code *c=&runq->code[runq->pc];
-	while(c->f==Xpopredir) c++;
-	return c->f==Xexit;
+exitnext(void)
+{
+	union code *c = &runq->code[runq->pc];
+
+	while(c->f == Xpopredir)
+		c++;
+	return c->f == Xexit;
 }
 
 void
@@ -24,6 +27,7 @@ Xsimple(void)
 	var *v;
 	struct builtin *bp;
 	int pid;
+
 	globlist();
 	a = runq->argv->words;
 	if(a==0){
@@ -156,7 +160,8 @@ execcd(void)
 {
 	word *a = runq->argv->words;
 	word *cdpath;
-	char dir[512];
+	char *dir;
+
 	setstatus("can't cd");
 	cdpath = vlook("cdpath")->val;
 	switch(count(a)){
@@ -165,19 +170,23 @@ execcd(void)
 		break;
 	case 2:
 		if(a->next->word[0]=='/' || cdpath==0)
-			cdpath=&nullpath;
-		for(;cdpath;cdpath = cdpath->next){
-			strcpy(dir, cdpath->word);
-			if(dir[0])
-				strcat(dir, "/");
-			strcat(dir, a->next->word);
-			if(dochdir(dir)>=0){
-				if(strlen(cdpath->word)
-				&& strcmp(cdpath->word, ".")!=0)
+			cdpath = &nullpath;
+		for(; cdpath; cdpath = cdpath->next){
+			if(cdpath->word[0] != '\0')
+				dir = smprint("%s/%s", cdpath->word,
+					a->next->word);
+			else
+				dir = strdup(a->next->word);
+
+			if(dochdir(dir) >= 0){
+				if(cdpath->word[0] != '\0' &&
+				    strcmp(cdpath->word, ".") != 0)
 					pfmt(err, "%s\n", dir);
+				free(dir);
 				setstatus("");
 				break;
 			}
+			free(dir);
 		}
 		if(cdpath==0)
 			pfmt(err, "Can't cd %s: %r\n", a->next->word);
@@ -309,6 +318,7 @@ execeval(void)
 	execcmds(opencore(cmdline, len));
 	efree(cmdline);
 }
+
 union code dotcmds[14];
 
 void
@@ -318,10 +328,10 @@ execdot(void)
 	int fd;
 	list *av;
 	thread *p = runq;
-	char *zero;
-	static int first = 1;
-	char file[512];
+	char *zero, *file;
 	word *path;
+	static int first = 1;
+
 	if(first){
 		dotcmds[0].i = 1;
 		dotcmds[1].f = Xmark;
@@ -352,13 +362,17 @@ execdot(void)
 	}
 	zero = strdup(p->argv->words->word);
 	popword();
-	fd=-1;
-	for(path = searchpath(zero);path;path = path->next){
-		strcpy(file, path->word);
-		if(file[0])
-			strcat(file, "/");
-		strcat(file, zero);
-		if((fd = open(file, 0))>=0) break;
+	fd = -1;
+	for(path = searchpath(zero); path; path = path->next){
+		if(path->word[0] != '\0')
+			file = smprint("%s/%s", path->word, zero);
+		else
+			file = strdup(zero);
+
+		fd = open(file, 0);
+		free(file);
+		if(fd >= 0)
+			break;
 		if(strcmp(file, "/dev/stdin")==0){	/* for sun & ucb */
 			fd = Dup1(0);
 			if(fd>=0)
@@ -420,13 +434,15 @@ execflag(void)
 }
 
 void
-execwhatis(void){	/* mildly wrong -- should fork before writing */
+execwhatis(void)	/* mildly wrong -- should fork before writing */
+{
 	word *a, *b, *path;
 	var *v;
 	struct builtin *bp;
-	char file[512];
+	char *file;
 	struct io out[1];
 	int found, sep;
+
 	a = runq->argv->words->next;
 	if(a==0){
 		Xerror1("Usage: whatis name ...");
@@ -465,15 +481,19 @@ execwhatis(void){	/* mildly wrong -- should fork before writing */
 					break;
 				}
 			if(!bp->name){
-				for(path = searchpath(a->word);path;path = path->next){
-					strcpy(file, path->word);
-					if(file[0])
-						strcat(file, "/");
-					strcat(file, a->word);
+				for(path = searchpath(a->word); path;
+				    path = path->next){
+					if(path->word[0] != '\0')
+						file = smprint("%s/%s",
+							path->word, a->word);
+					else
+						file = strdup(a->word);
 					if(Executable(file)){
 						pfmt(out, "%s\n", file);
+						free(file);
 						break;
 					}
+					free(file);
 				}
 				if(!path && !found){
 					pfmt(err, "%s: not found\n", a->word);

+ 12 - 7
sys/src/cmd/rc/subr.c

@@ -3,10 +3,11 @@
 #include "io.h"
 #include "fns.h"
 
-char*
+void *
 emalloc(long n)
 {
-	char *p = (char *)Malloc(n);
+	void *p = Malloc(n);
+
 	if(p==0)
 		panic("Can't malloc %d bytes", n);
 /*	if(err){ pfmt(err, "malloc %d->%p\n", n, p); flush(err); } /**/
@@ -14,13 +15,15 @@ emalloc(long n)
 }
 
 void
-efree(char *p)
+efree(void *p)
 {
 /*	pfmt(err, "free %p\n", p); flush(err); /**/
 	if(p)
 		free(p);
-	else pfmt(err, "free 0\n");
+	else
+		pfmt(err, "free 0\n");
 }
+
 extern int lastword, lastdol;
 
 void
@@ -39,18 +42,20 @@ yyerror(char *m)
 	flush(err);
 	lastword = 0;
 	lastdol = 0;
-	while(lastc!='\n' && lastc!=EOF) advance();
+	while(lastc!='\n' && lastc!=EOF)
+		advance();
 	nerror++;
 	setvar("status", newword(m, (word *)0));
 }
+
 char *bp;
 
 static void
 iacvt(int n)
 {
 	if(n<0){
-		*bp++='-';
-		n=-n;	/* doesn't work for n==-inf */
+		*bp++ = '-';
+		n = -n;	/* doesn't work for n==-inf */
 	}
 	if(n/10)
 		iacvt(n/10);

+ 3 - 1
sys/src/cmd/rc/tree.c

@@ -107,10 +107,11 @@ simplemung(tree *t)
 {
 	tree *u;
 	struct io *s;
+
 	t = tree1(SIMPLE, t);
 	s = openstr();
 	pfmt(s, "%t", t);
-	t->str = strdup(s->strp);
+	t->str = strdup((char *)s->strp);
 	closeio(s);
 	for(u = t->child[0];u->type==ARGLIST;u = u->child[0]){
 		if(u->child[1]->type==DUP
@@ -127,6 +128,7 @@ tree*
 token(char *str, int type)
 {
 	tree *t = newtree();
+
 	t->type = type;
 	t->str = strdup(str);
 	return t;

+ 7 - 6
sys/src/cmd/rc/unix.c

@@ -312,9 +312,9 @@ char *name;
 	return -1;
 }
 Readdir(f, p, onlydirs)
-register int f;
-register char *p;
-register int onlydirs;	/* ignored, just advisory */
+int f;
+void *p;
+int onlydirs;		/* ignored, just advisory */
 {
 	struct direct *dp = readdir(dirlist[f]);
 	if(dp==0)
@@ -372,12 +372,12 @@ char *name;
 	return unlink(name);
 }
 Write(fd, buf, cnt)
-char *buf;
+void *buf;
 {
 	return write(fd, buf, cnt);
 }
 Read(fd, buf, cnt)
-char *buf;
+void *buf;
 {
 	return read(fd, buf, cnt);
 }
@@ -456,7 +456,8 @@ execumask(){		/* wrong -- should fork before writing */
 	poplist();
 }
 Memcpy(a, b, n)
-char *a, *b;
+void *a, *b;
+long n;
 {
 	memmove(a, b, n);
 }

+ 5 - 5
sys/src/cmd/rc/win32.c

@@ -369,7 +369,7 @@ trimdirs(Dir *d, int nd)
  * the globber work harder.
  */
 int
-Readdir(int f, char *p, int onlydirs)
+Readdir(int f, void *p, int onlydirs)
 {
 	int n;
 
@@ -446,13 +446,13 @@ Unlink(char *name)
 }
 
 long
-Write(int fd, char *buf, long cnt)
+Write(int fd, void *buf, long cnt)
 {
 	return write(fd, buf, (long)cnt);
 }
 
 long
-Read(int fd, char *buf, long cnt)
+Read(int fd, void *buf, long cnt)
 {
 	return read(fd, buf, cnt);
 }
@@ -548,9 +548,9 @@ Abort(void)
 }
 
 void
-Memcpy(char *a, char *b, long n)
+Memcpy(void *a, void *b, long n)
 {
-	memmove(a, b, (long)n);
+	memmove(a, b, n);
 }
 
 void*