Browse Source

Plan 9 from Bell Labs 2003-02-11

David du Colombier 18 years ago
parent
commit
a871b3944f

+ 44 - 43
dist/replica/plan9.db

@@ -132,7 +132,7 @@
 386/bin/aux/vga - 775 sys sys 1039758547 299452
 386/bin/aux/vmmousepoll - 775 sys sys 1032480572 41434
 386/bin/aux/vmware - 775 sys sys 1032486041 249
-386/bin/aux/vmwarefs - 775 sys sys 1032486792 100531
+386/bin/aux/vmwarefs - 775 sys sys 1044930180 102172
 386/bin/aux/write - 775 sys sys 1038443108 4198
 386/bin/awd - 775 sys sys 1038443108 5033
 386/bin/awk - 775 sys sys 1038443109 319625
@@ -2970,6 +2970,7 @@ rc/bin/tlsclienttunnel - 775 sys sys 1024375633 153
 rc/bin/tlssrvtunnel - 775 sys sys 1024375634 175
 rc/bin/troff2gif - 775 sys sys 1032539305 161
 rc/bin/ups - 775 sys sys 1042567965 989
+rc/bin/usbstart - 775 sys sys 1044894155 81
 rc/bin/usps - 775 sys sys 1016826030 450
 rc/bin/vwhois - 775 sys sys 953999875 294
 rc/bin/wdoc2txt - 755 sys sys 1017431153 277
@@ -2979,7 +2980,7 @@ rc/bin/whois - 775 sys sys 945617210 189
 rc/bin/window - 775 sys sys 947527128 1711
 rc/bin/wloc - 775 sys sys 969512017 191
 rc/bin/wurl2txt - 755 sys sys 1017431148 296
-rc/bin/yesterday - 775 sys sys 958838209 2104
+rc/bin/yesterday - 775 sys sys 1044909161 2408
 rc/lib - 20000000775 sys sys 948037639 0
 rc/lib/rcmain - 664 sys sys 984696976 579
 sparc - 20000000775 sys sys 947991046 0
@@ -4453,7 +4454,7 @@ sys/man/1/grep - 664 sys sys 969512677 2224
 sys/man/1/gs - 664 sys sys 1032054727 6906
 sys/man/1/gzip - 664 sys sys 969499884 3073
 sys/man/1/hget - 664 sys sys 969499885 1174
-sys/man/1/history - 664 sys sys 1015024739 1384
+sys/man/1/history - 664 sys sys 1044909169 1709
 sys/man/1/hoc - 664 sys sys 944959676 2357
 sys/man/1/idiff - 664 sys sys 1018386774 927
 sys/man/1/join - 664 sys sys 957920006 2562
@@ -4541,7 +4542,7 @@ sys/man/1/wc - 664 sys sys 944959675 908
 sys/man/1/who - 664 sys sys 944959674 332
 sys/man/1/xd - 664 sys sys 944959674 1517
 sys/man/1/yacc - 664 sys sys 944959676 3273
-sys/man/1/yesterday - 664 sys sys 959299265 2045
+sys/man/1/yesterday - 664 sys sys 1044909169 2202
 sys/man/2 - 20000000775 sys sys 1017423721 0
 sys/man/2/0intro - 664 sys sys 1044724217 11574
 sys/man/2/9p - 664 sys sys 1044430182 15044
@@ -4760,7 +4761,7 @@ sys/man/4/tapefs - 664 sys sys 944959699 1731
 sys/man/4/telco - 664 sys sys 1015024814 4359
 sys/man/4/u9fs - 664 sys sys 1043769139 4748
 sys/man/4/upasfs - 664 sys sys 1034348505 6212
-sys/man/4/usb - 664 sys sys 1019828742 3272
+sys/man/4/usb - 664 sys sys 1044894160 3371
 sys/man/4/usbd - 664 sys sys 1018386778 731
 sys/man/4/vacfs - 664 sys sys 1022112155 1419
 sys/man/4/webcookies - 664 sys sys 1019828742 3525
@@ -5041,7 +5042,7 @@ sys/src/9/ip/nullmedium.c - 664 sys sys 1022588099 491
 sys/src/9/ip/pktmedium.c - 664 sys sys 1044630559 1357
 sys/src/9/ip/ptclbsum.c - 664 sys sys 1022588099 1243
 sys/src/9/ip/rudp.c - 664 sys sys 1026847569 21413
-sys/src/9/ip/tcp.c - 664 sys sys 1044630563 61645
+sys/src/9/ip/tcp.c - 664 sys sys 1044906740 61753
 sys/src/9/ip/tripmedium.c - 664 sys sys 1022588099 7141
 sys/src/9/ip/udp.c - 664 sys sys 1026847570 13046
 sys/src/9/mkfile - 664 sys sys 1017795039 191
@@ -7002,7 +7003,7 @@ sys/src/cmd/fossil/9auth.c - 664 sys sys 1042311686 3023
 sys/src/cmd/fossil/9dir.c - 664 sys sys 1042005502 1995
 sys/src/cmd/fossil/9excl.c - 664 sys sys 1042005502 1887
 sys/src/cmd/fossil/9fid.c - 664 sys sys 1042005502 5236
-sys/src/cmd/fossil/9fsys.c - 664 sys sys 1042311686 26805
+sys/src/cmd/fossil/9fsys.c - 664 sys sys 1044906157 26913
 sys/src/cmd/fossil/9lstn.c - 664 sys sys 1042005503 2865
 sys/src/cmd/fossil/9p.c - 664 sys sys 1042005503 21328
 sys/src/cmd/fossil/9ping.c - 664 sys sys 1042005503 1563
@@ -7024,7 +7025,7 @@ sys/src/cmd/fossil/disk.c - 664 sys sys 1042497769 5736
 sys/src/cmd/fossil/dump.c - 664 sys sys 1042005506 1340
 sys/src/cmd/fossil/error.c - 664 sys sys 1042005507 1367
 sys/src/cmd/fossil/error.h - 664 sys sys 1042005507 744
-sys/src/cmd/fossil/file.c - 664 sys sys 1042311690 27520
+sys/src/cmd/fossil/file.c - 664 sys sys 1044906157 27633
 sys/src/cmd/fossil/flchk.c - 664 sys sys 1042005507 13670
 sys/src/cmd/fossil/flfmt.c - 664 sys sys 1042005507 10314
 sys/src/cmd/fossil/flproto - 664 sys sys 1042005508 210
@@ -8838,7 +8839,7 @@ sys/src/cmd/gzip/unzip.c - 664 sys sys 1014924864 13591
 sys/src/cmd/gzip/zip.c - 664 sys sys 1033183074 7054
 sys/src/cmd/gzip/zip.h - 664 sys sys 954778719 1428
 sys/src/cmd/hget.c - 664 sys sys 1042940715 21870
-sys/src/cmd/history.c - 664 sys sys 1044498757 5157
+sys/src/cmd/history.c - 664 sys sys 1044909166 5810
 sys/src/cmd/hoc - 20000000775 sys sys 954036932 0
 sys/src/cmd/hoc/code.c - 664 sys sys 944961000 10041
 sys/src/cmd/hoc/hoc.h - 664 sys sys 944960999 2358
@@ -8857,7 +8858,7 @@ sys/src/cmd/htmlfmt/mkfile - 664 sys sys 1034015650 297
 sys/src/cmd/htmlfmt/util.c - 664 sys sys 1015364025 1765
 sys/src/cmd/iconv.c - 664 sys sys 1039753035 1801
 sys/src/cmd/idiff.c - 664 sys sys 1014926695 6896
-sys/src/cmd/import.c - 664 sys sys 1034195354 6191
+sys/src/cmd/import.c - 664 sys sys 1044893799 6192
 sys/src/cmd/init.c - 664 sys sys 1016833880 4254
 sys/src/cmd/iostats - 20000000775 sys sys 944962001 0
 sys/src/cmd/iostats/iostats.c - 664 sys sys 1014925727 9691
@@ -10406,6 +10407,7 @@ sys/src/cmd/venti/dat.h - 664 sys sys 1043176100 15228
 sys/src/cmd/venti/dcache.c - 664 sys sys 1019678878 7374
 sys/src/cmd/venti/dump.c - 664 sys sys 1043176101 1565
 sys/src/cmd/venti/dumparena.c - 664 sys sys 1019678878 6381
+sys/src/cmd/venti/dumpvacroots - 775 sys sys 1044904736 467
 sys/src/cmd/venti/findscore.c - 664 sys sys 1019678878 2607
 sys/src/cmd/venti/fmtarenas.c - 664 sys sys 1036793323 2438
 sys/src/cmd/venti/fmtindex.c - 664 sys sys 1019678878 2529
@@ -10475,38 +10477,37 @@ sys/src/cmd/vl/pass.c - 664 sys sys 1015701231 8726
 sys/src/cmd/vl/sched.c - 664 sys sys 1014936060 11363
 sys/src/cmd/vl/span.c - 664 sys sys 1015701233 12029
 sys/src/cmd/vnc - 20000000775 sys sys 1014926000 0
-sys/src/cmd/vnc/auth.c - 664 sys sys 1034430138 4101
-sys/src/cmd/vnc/chan.c - 664 sys sys 1014925997 2616
-sys/src/cmd/vnc/color.c - 664 sys sys 1014925997 3097
-sys/src/cmd/vnc/compat.c - 664 sys sys 1017854326 3126
-sys/src/cmd/vnc/compat.h - 664 sys sys 1014925997 3401
-sys/src/cmd/vnc/dev.c - 664 sys sys 1014925997 5502
-sys/src/cmd/vnc/devcons.c - 664 sys sys 1034430139 6915
-sys/src/cmd/vnc/devdraw.c - 664 sys sys 1039753056 42068
-sys/src/cmd/vnc/devmouse.c - 664 sys sys 1034430139 7386
-sys/src/cmd/vnc/draw.c - 664 sys sys 1042391341 6958
-sys/src/cmd/vnc/error.h - 664 sys sys 1014925998 2482
-sys/src/cmd/vnc/errstr.h - 664 sys sys 1014925998 2018
-sys/src/cmd/vnc/exporter.c - 664 sys sys 1014925998 1312
-sys/src/cmd/vnc/exportfs.c - 664 sys sys 1014925998 13552
-sys/src/cmd/vnc/kbd.c - 664 sys sys 1014925998 3256
-sys/src/cmd/vnc/kbd.h - 664 sys sys 1034430141 301
-sys/src/cmd/vnc/kbd_vwr.c - 664 sys sys 1039889837 2389
-sys/src/cmd/vnc/latin1.c - 664 sys sys 1014925999 1410
-sys/src/cmd/vnc/latin1.h - 664 sys sys 1014925999 3524
-sys/src/cmd/vnc/mkfile - 664 sys sys 1034430146 649
-sys/src/cmd/vnc/proto.c - 664 sys sys 1014925999 4369
-sys/src/cmd/vnc/region.c - 664 sys sys 1014925999 6370
-sys/src/cmd/vnc/region.h - 664 sys sys 1014925999 530
-sys/src/cmd/vnc/rre.c - 664 sys sys 1014925999 11036
-sys/src/cmd/vnc/screen.c - 664 sys sys 1041115189 7434
-sys/src/cmd/vnc/screen.h - 664 sys sys 1014926000 880
-sys/src/cmd/vnc/vnc.h - 664 sys sys 1034430143 2616
-sys/src/cmd/vnc/vncs.c - 664 sys sys 1043764390 21001
-sys/src/cmd/vnc/vncs.h - 664 sys sys 1034430144 501
-sys/src/cmd/vnc/vncv.c - 664 sys sys 1034430145 5154
-sys/src/cmd/vnc/vncv.h - 664 sys sys 1014926000 643
-sys/src/cmd/vnc/wsys.c - 664 sys sys 1034430145 4076
+sys/src/cmd/vnc/auth.c - 664 sys sys 1044880749 4245
+sys/src/cmd/vnc/chan.c - 664 sys sys 1044880749 2624
+sys/src/cmd/vnc/color.c - 664 sys sys 1044880749 3088
+sys/src/cmd/vnc/compat.c - 664 sys sys 1044880749 3122
+sys/src/cmd/vnc/compat.h - 664 sys sys 1044880749 3401
+sys/src/cmd/vnc/dev.c - 664 sys sys 1044880749 5496
+sys/src/cmd/vnc/devcons.c - 664 sys sys 1044880749 6955
+sys/src/cmd/vnc/devdraw.c - 664 sys sys 1044880749 42068
+sys/src/cmd/vnc/devmouse.c - 664 sys sys 1044880749 7384
+sys/src/cmd/vnc/draw.c - 664 sys sys 1044880749 6974
+sys/src/cmd/vnc/error.h - 664 sys sys 1044880749 2482
+sys/src/cmd/vnc/errstr.h - 664 sys sys 1044880749 2018
+sys/src/cmd/vnc/exporter.c - 664 sys sys 1044880749 1312
+sys/src/cmd/vnc/exportfs.c - 664 sys sys 1044880749 13549
+sys/src/cmd/vnc/kbd.h - 664 sys sys 1044880749 301
+sys/src/cmd/vnc/kbds.c - 664 sys sys 1044880749 3254
+sys/src/cmd/vnc/kbdv.c - 664 sys sys 1044880749 2383
+sys/src/cmd/vnc/latin1.c - 664 sys sys 1044880749 1410
+sys/src/cmd/vnc/latin1.h - 664 sys sys 1044880750 3524
+sys/src/cmd/vnc/mkfile - 664 sys sys 1044880750 684
+sys/src/cmd/vnc/proto.c - 664 sys sys 1044880750 4365
+sys/src/cmd/vnc/rlist.c - 664 sys sys 1044880750 5300
+sys/src/cmd/vnc/rre.c - 664 sys sys 1044880750 11496
+sys/src/cmd/vnc/screen.c - 664 sys sys 1044880750 7537
+sys/src/cmd/vnc/screen.h - 664 sys sys 1044880750 880
+sys/src/cmd/vnc/vnc.h - 664 sys sys 1044880750 2626
+sys/src/cmd/vnc/vncs.c - 664 sys sys 1044880750 20915
+sys/src/cmd/vnc/vncs.h - 664 sys sys 1044880750 890
+sys/src/cmd/vnc/vncv.c - 664 sys sys 1044880750 3093
+sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
+sys/src/cmd/vnc/wsys.c - 664 sys sys 1044880750 4065
 sys/src/cmd/vt - 20000000775 sys sys 954038635 0
 sys/src/cmd/vt/cons.h - 664 sys sys 984718311 1660
 sys/src/cmd/vt/consctl.c - 664 sys sys 952627639 1815
@@ -11584,7 +11585,7 @@ sys/src/libsec/port/md4test.c - 664 sys sys 984710522 537
 sys/src/libsec/port/md5.c - 664 sys sys 985124885 3298
 sys/src/libsec/port/md5block.c - 664 sys sys 985124885 5015
 sys/src/libsec/port/md5pickle.c - 664 sys sys 988225292 657
-sys/src/libsec/port/mkfile - 664 sys sys 1035832900 869
+sys/src/libsec/port/mkfile - 664 sys sys 1044931345 879
 sys/src/libsec/port/nfastrand.c - 664 sys sys 1035832901 327
 sys/src/libsec/port/primetest.c - 664 sys sys 984710523 2486
 sys/src/libsec/port/prng.c - 664 sys sys 984710523 187

+ 48 - 0
dist/replica/plan9.log

@@ -17220,3 +17220,51 @@
 1044837096 0 c sys/include/9p.h - 664 sys sys 1044836327 4309
 1044837096 1 c sys/src/lib9p/_post.c - 664 sys sys 1044836326 1641
 1044839704 0 c sys/src/cmd/auth/debug.c - 664 sys sys 1044839697 7324
+1044882152 0 c sys/src/cmd/vnc/auth.c - 664 sys sys 1044880749 4245
+1044882152 1 c sys/src/cmd/vnc/chan.c - 664 sys sys 1044880749 2624
+1044882152 2 c sys/src/cmd/vnc/color.c - 664 sys sys 1044880749 3088
+1044882152 3 c sys/src/cmd/vnc/compat.c - 664 sys sys 1044880749 3122
+1044882152 4 c sys/src/cmd/vnc/compat.h - 664 sys sys 1044880749 3401
+1044882152 5 c sys/src/cmd/vnc/dev.c - 664 sys sys 1044880749 5496
+1044882152 6 c sys/src/cmd/vnc/devcons.c - 664 sys sys 1044880749 6955
+1044882152 7 c sys/src/cmd/vnc/devdraw.c - 664 sys sys 1044880749 42068
+1044882152 8 c sys/src/cmd/vnc/devmouse.c - 664 sys sys 1044880749 7384
+1044882152 9 c sys/src/cmd/vnc/draw.c - 664 sys sys 1044880749 6974
+1044882152 10 c sys/src/cmd/vnc/error.h - 664 sys sys 1044880749 2482
+1044882152 11 c sys/src/cmd/vnc/errstr.h - 664 sys sys 1044880749 2018
+1044882152 12 c sys/src/cmd/vnc/exporter.c - 664 sys sys 1044880749 1312
+1044882152 13 c sys/src/cmd/vnc/exportfs.c - 664 sys sys 1044880749 13549
+1044882152 14 c sys/src/cmd/vnc/kbd.h - 664 sys sys 1044880749 301
+1044882152 15 a sys/src/cmd/vnc/kbds.c - 664 sys sys 1044880749 3254
+1044882152 16 a sys/src/cmd/vnc/kbdv.c - 664 sys sys 1044880749 2383
+1044882152 17 c sys/src/cmd/vnc/latin1.c - 664 sys sys 1044880749 1410
+1044882152 18 c sys/src/cmd/vnc/latin1.h - 664 sys sys 1044880750 3524
+1044882152 19 c sys/src/cmd/vnc/mkfile - 664 sys sys 1044880750 684
+1044882152 20 c sys/src/cmd/vnc/proto.c - 664 sys sys 1044880750 4365
+1044882152 21 a sys/src/cmd/vnc/rlist.c - 664 sys sys 1044880750 5300
+1044882152 22 c sys/src/cmd/vnc/rre.c - 664 sys sys 1044880750 11496
+1044882152 23 c sys/src/cmd/vnc/screen.c - 664 sys sys 1044880750 7537
+1044882152 24 c sys/src/cmd/vnc/screen.h - 664 sys sys 1044880750 880
+1044882152 25 c sys/src/cmd/vnc/vnc.h - 664 sys sys 1044880750 2626
+1044882152 26 c sys/src/cmd/vnc/vncs.c - 664 sys sys 1044880750 20915
+1044882152 27 c sys/src/cmd/vnc/vncs.h - 664 sys sys 1044880750 890
+1044882152 28 c sys/src/cmd/vnc/vncv.c - 664 sys sys 1044880750 3093
+1044882152 29 c sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
+1044882152 30 c sys/src/cmd/vnc/wsys.c - 664 sys sys 1044880750 4065
+1044882152 31 d sys/src/cmd/vnc/kbd.c - 664 sys sys 1014925998 0
+1044882152 32 d sys/src/cmd/vnc/kbd_vwr.c - 664 sys sys 1039889837 0
+1044882152 33 d sys/src/cmd/vnc/region.c - 664 sys sys 1014925999 0
+1044882152 34 d sys/src/cmd/vnc/region.h - 664 sys sys 1014925999 0
+1044894022 0 c sys/src/cmd/import.c - 664 sys sys 1044893799 6192
+1044894757 0 a rc/bin/usbstart - 775 sys sys 1044894155 81
+1044894757 1 c sys/man/4/usb - 664 sys sys 1044894160 3371
+1044905567 0 a sys/src/cmd/venti/dumpvacroots - 775 sys sys 1044904736 467
+1044907368 0 c sys/src/9/ip/tcp.c - 664 sys sys 1044906740 61753
+1044907368 1 c sys/src/cmd/fossil/9fsys.c - 664 sys sys 1044906157 26913
+1044907368 2 c sys/src/cmd/fossil/file.c - 664 sys sys 1044906157 27633
+1044909169 0 c rc/bin/yesterday - 775 sys sys 1044909161 2408
+1044909169 1 c sys/man/1/yesterday - 664 sys sys 1044909169 2202
+1044909169 2 c sys/man/1/history - 664 sys sys 1044909169 1709
+1044909169 3 c sys/src/cmd/history.c - 664 sys sys 1044909166 5810
+1044930778 0 c 386/bin/aux/vmwarefs - 775 sys sys 1044930180 102172
+1044932578 0 c sys/src/libsec/port/mkfile - 664 sys sys 1044931345 879

+ 7 - 0
rc/bin/usbstart

@@ -0,0 +1,7 @@
+#!/bin/rc
+
+if (test -r '#U'/usb0) {
+	usb/usbd
+	usb/usbmouse -a 2
+	usb/usbaudio
+}

+ 36 - 20
rc/bin/yesterday

@@ -1,8 +1,8 @@
 #!/bin/rc
 
 rfork e
-if(! test -e /n/dump/1997)
-	9fs dump
+
+slashnhack=yes
 
 smon='s/Jan/01/
 	s/Feb/02/
@@ -18,7 +18,7 @@ smon='s/Jan/01/
 	s/Dec/12/'
 
 fn usage {
-	echo 'usage: yesterday [-abcCdD] [-[[[yy]yy]mm]dd] [-n daysago] file ...' >[1=2]
+	echo 'usage: yesterday [-abcCdDN] [-[[[yy]yy]mm]dd] [-n daysago] file ...' >[1=2]
 	exit 'usage'
 }
 
@@ -76,6 +76,10 @@ while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
 	case -C
 		copy=Xcarefulcp
 		shift
+# The slashnhack is always right.
+#	case -N
+#		slashnhack=no
+#		shift
 	case -n*
 		if(~ $1 -n){
 			if(~ $#* 1)
@@ -86,24 +90,24 @@ while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
 		if not
 			days=`{echo $1 | sed 's/^-.//'}
 		last=`{date `{hoc -e `{date -n} ^ '-'$days'*60*60*24'} | \
-				sed -e 's%... (...) (..) ..:..:.. ... (....)%/n/dump/\3/\1\2%' -e 'y/ /0/' -e $smon}
+				sed -e 's%... (...) (..) ..:..:.. ... (....)%\3/\1\2%' -e 'y/ /0/' -e $smon}
 		shift
 	case -?
 		mon=`{date|sed -e 's/^....(...).*/\1/' -e $smon}
-		last=/n/dump/$year/$mon ^`{echo $1|sed 's/^-/0/'}
+		last=$year/$mon ^`{echo $1|sed 's/^-/0/'}
 		shift
 	case -??
 		mon=`{date|sed -e 's/^....(...).*/\1/' -e $smon}
-		last=/n/dump/$year/$mon ^`{echo $1|sed 's/^-//'}
+		last=$year/$mon ^`{echo $1|sed 's/^-//'}
 		shift
 	case -????
-		last=/n/dump/$year/ ^ `{echo $1|sed 's/^-//'}
+		last=$year/ ^ `{echo $1|sed 's/^-//'}
 		shift
 	case -??????
-		last=/n/dump/ ^ `{echo $year|sed 's/..$//'} ^ `{echo $1|sed 's/^-(..)/\1\//'}
+		last=`{echo $year|sed 's/..$//'} ^ `{echo $1|sed 's/^-(..)/\1\//'}
 		shift
 	case -????????
-		last=/n/dump/ ^ `{echo $1|sed 's/^-(....)/\1\//'}
+		last=`{echo $1|sed 's/^-(....)/\1\//'}
 		shift
 	case *
 		usage
@@ -115,16 +119,6 @@ if(! ~ $#* 0 && ~ $1 --)
 if(~ $#* 0)
 	usage
 
-if(~ $#last 0)
-	last=`{ls -t /n/dump/$year|sed 1q}
-
-if(! test -e $last){
-	echo 'yesterday:' \
-		`{echo $last|sed 's/.n.dump.(....).(..)(..)/\1 \2 \3/'} \
-		'is not a backup day' >[1=2]
-	exit 'bad date'
-}
-
 dir=`{pwd}
 if(! ~ $status ''){
 	echo 'yesterday: can''t find directory' >[1=2]
@@ -132,6 +126,28 @@ if(! ~ $status ''){
 }
 
 for(i){
-	$copy $last^`{cleanname -d $dir -- $i} $i
+	xpath=`{cleanname -d $dir -- $i}
+	xdump=dump
+	dumppath=$xpath
+	if(~ $slashnhack yes && ~ $xpath /n/*/*){
+		xdump=`{echo $xpath | sed 's:/n/([^/]+)/.*:\1dump:'}
+		dumppath=`{echo $xpath | sed 's:/n/[^/]+(/.*):\1:'}
+	}
+	if(! test -e /n/$xdump/$year)
+		9fs $xdump
+
+	if(~ $#last 0)
+		xlast=`{ls -t /n/$xdump/$year|sed 1q}
+	if not
+		xlast=/n/$xdump/$last
+
+	if(! test -e $xlast){
+		echo 'yesterday:' \
+			`{echo $xlast|sed 's/.n.dump.(....).(..)(..)/\1 \2 \3/'} \
+			'is not a backup day for' $xdump >[1=2]
+		exit 'bad date'
+	}
+	
+	$copy $xlast^$dumppath $xpath
 }
 exit ''

+ 16 - 2
sys/man/1/history

@@ -4,7 +4,7 @@ history \- print file names from the dump
 .SH SYNOPSIS
 .B history
 [
-.B -vDu
+.B -vDufN
 ] [
 .B -d
 .I dumpfilesystem
@@ -36,6 +36,14 @@ May 10 16:40:51 EDT 2001 /n/dump/2001/0511/adm/users 10476 [adm]
 	...
 .EE
 .PP
+When presented with a path of the form
+.BI /n/ fs / path \fR,
+.I history
+will use
+.IB fs dump
+as the name of the dump file system, and will print a history of
+.IR path .
+.PP
 The
 .B -v
 option enables verbose debugging printout.
@@ -57,9 +65,15 @@ option causes times to be printed in GMT (UT) rather than local time.
 .PP
 The
 .B -d
-option selects some other dump filesystem such as
+option selects some other dump file system such as
 .IR /n/bootesdump .
 .PP
+The
+.B -f
+option forces the search to continue even when the
+file in question does not exist (useful for files that only
+exist intermittently).
+.PP
 Finally, the
 .B -s
 option

+ 7 - 0
sys/man/1/yesterday

@@ -34,6 +34,13 @@ prints
 In fact, the implementation is to select the most recent dump in
 the current year, so the dump selected may not be from today.
 .PP
+When presented with a path of the form
+.BI /n/ fs / path \fR,
+.I yesterday
+will look for
+dump files of the form
+.BI /n/ fs dump/ yyyy / hhmm / path \fR.
+.PP
 By default, 
 .I yesterday
 prints the names of the dump files corresponding to the named files.

+ 10 - 2
sys/man/4/usb

@@ -22,6 +22,9 @@ usbaudio
 .B -m
 .I mountpoint
 ] [
+.B -s
+.I srvname
+] [
 .I ctrlno
 .I n
 ]
@@ -39,7 +42,7 @@ The script
 .B usbstart
 checks whether a USB driver is present, and if so, starts usbd
 followed by the support programs listed below.
-.SS USB MICE
+.SS Mice
 .B Usbmouse
 sends mouse events from a USB mouse to
 .B #m/mousein
@@ -54,7 +57,7 @@ The
 flag runs
 .B usbmouse
 in the foreground.
-.SS USB AUDIO DEVICES
+.SS Audio devices
 .B Usbaudio
 configures and manages a usb audio device.  It implements a file system,
 normally mounted in
@@ -73,6 +76,11 @@ and
 .I /audio
 maintain backward compatibility with the soundblaster driver.
 .PP
+The
+.B \-s
+flag specifies a name for a file descriptor to be posted in
+.CW /srv .
+.PP
 Reading
 .I /volume
 or

+ 4 - 0
sys/src/9/ip/tcp.c

@@ -2171,6 +2171,10 @@ reset:
 						panic("tcp packblock");
 					qpassnolim(s->rq, bp);
 					bp = nil;
+
+ 					/* force an ack every 2 data messages */
+ 					if(++(tcb->rcv.una) >= 2)
+ 						tcb->flags |= FORCE;
 				}
 				tcb->rcv.nxt += length;
 

+ 32 - 20
sys/src/cmd/fossil/9fsys.c

@@ -108,7 +108,7 @@ fsysGet(char* name)
 }
 
 char*
-fsysGetName(Fsys *fsys)
+fsysGetName(Fsys* fsys)
 {
 	return fsys->name;
 }
@@ -202,7 +202,7 @@ fsysModeString(ulong mode, char *buf)
 }
 
 int
-fsysParseMode(char *s, ulong *mode)
+fsysParseMode(char* s, ulong* mode)
 {
 	ulong x, y;
 	char *p;
@@ -815,10 +815,7 @@ fsysEsearch1(File* f, char* s, u32int elo)
 			if((ff = fileWalk(f, de.elem)) == nil)
 				consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
 			else{
-				t = vtMemAlloc(strlen(s)+1+strlen(de.elem)+1);
-				strcpy(t, s);
-				strcat(t, "/");
-				strcat(t, de.elem);
+				t = smprint("%s/%s", s, de.elem);
 				n += fsysEsearch1(ff, t, elo);
 				vtMemFree(t);
 				fileDecRef(ff);
@@ -953,23 +950,38 @@ fsysCreate(Fsys* fsys, int argc, char* argv[])
 		p = "/";
 		elem = path;
 	}
+
 	r = 0;
-	if((parent = fileOpen(fsys->fs, p)) != nil){
-		file = fileCreate(parent, elem, mode, argv[1]);
-		fileDecRef(parent);
-		if(file != nil){
-			if(fileGetDir(file, &de)){
-				r = 1;
-				if(strcmp(de.gid, argv[2]) != 0){
-					vtMemFree(de.gid);
-					de.gid = vtStrDup(argv[2]);
-					r = fileSetDir(file, &de, argv[1]);
-				}
-				deCleanup(&de);
-			}
-			fileDecRef(file);
+	if((parent = fileOpen(fsys->fs, p)) == nil)
+		goto out;
+
+	file = fileCreate(parent, elem, mode, argv[1]);
+	fileDecRef(parent);
+	if(file == nil){
+		vtSetError("create %s/%s: %R", p, elem);
+		goto out;
+	}
+
+	if(!fileGetDir(file, &de)){
+		vtSetError("stat failed after create: %R");
+		goto out1;
+	}
+
+	if(strcmp(de.gid, argv[2]) != 0){
+		vtMemFree(de.gid);		
+		de.gid = vtStrDup(argv[2]);
+		if(!fileSetDir(file, &de, argv[1])){
+			vtSetError("wstat failed after create: %R");
+			goto out2;
 		}
 	}
+	r = 1;
+
+out2:
+	deCleanup(&de);
+out1:
+	fileDecRef(file);
+out:
 	vtMemFree(path);	
 	vtRUnlock(fsys->fs->elk);
 

+ 6 - 3
sys/src/cmd/fossil/file.c

@@ -314,25 +314,28 @@ File *
 _fileOpen(Fs *fs, char *path, int partial)
 {
 	File *f, *ff;
-	char *p, elem[VtMaxStringSize];
+	char *p, elem[VtMaxStringSize], *opath;
 	int n;
 
 	f = fs->file;
 	fileIncRef(f);
+	opath = path;
 	while(*path != 0){
 		for(p = path; *p && *p != '/'; p++)
 			;
 		n = p - path;
 		if(n > 0){
 			if(n > VtMaxStringSize){
-				vtSetError(EBadPath);
+				vtSetError("%s: element too long", EBadPath);
 				goto Err;
 			}
 			memmove(elem, path, n);
 			elem[n] = 0;
 			ff = _fileWalk(f, elem, partial && *p=='\0');
-			if(ff == nil)
+			if(ff == nil){
+				vtSetError("%.*s: %R", utfnlen(opath, p-opath), opath);
 				goto Err;
+			}
 			fileDecRef(f);
 			f = ff;
 		}

+ 51 - 24
sys/src/cmd/history.c

@@ -10,26 +10,29 @@ int	uflag;
 int	force;
 int	diff;
 int	diffb;
-char*	ndump;
+int	slashnhack = 1;
 char*	sflag;
 
-void	ysearch(char*);
+void	ysearch(char*, char*);
 long	starttime(char*);
-void	lastbefore(ulong, char*, char*);
+void	lastbefore(ulong, char*, char*, char*);
 char*	prtime(ulong);
 
 void
 main(int argc, char *argv[])
 {
-	char buf[100];
-	Tm *tm;
-	Waitmsg *w;
 	int i;
+	char *ndump;
 
-	ndump = "dump";
+	ndump = nil;
 	ARGBEGIN {
 	default:
 		goto usage;
+/* The slashnhack is always right.
+	case 'N':
+		slashnhack = 0;
+		break;
+*/
 	case 'v':
 		verb = 1;
 		break;
@@ -59,11 +62,43 @@ main(int argc, char *argv[])
 		exits(0);
 	}
 
+	for(i=0; i<argc; i++)
+		ysearch(argv[i], ndump);
+	exits(0);
+}
+
+void
+ysearch(char *file, char *ndump)
+{
+	char fil[400], buf[500], nbuf[100], pair[2][500], *p;
+	Tm *tm;
+	Waitmsg *w;
+	Dir *dir, *d;
+	ulong otime, dt;
+	int toggle, started, missing;
+
+	if(ndump == nil){
+		if(slashnhack && memcmp(file, "/n/", 3) == 0){
+			p = strchr(file+3, '/');
+			if(p == nil)
+				p = file+strlen(file);
+			if(p-file >= sizeof nbuf-10){
+				fprint(2, "%s: dump name too long", file);
+				return;
+			}
+			memmove(nbuf, file+3, p-(file+3));
+			nbuf[p-(file+3)] = 0;
+			strcat(nbuf, "dump");
+			ndump = nbuf;
+		}else
+			ndump = "dump";
+	}
+
 	tm = localtime(time(0));
 	sprint(buf, "/n/%s/%.4d/", ndump, tm->year+1900);
 	if(access(buf, AREAD) < 0) {
 		if(verb)
-			print("mounting dump\n");
+			print("mounting dump %s\n", ndump);
 		if(rfork(RFFDG|RFPROC) == 0) {
 			execl("/bin/rc", "rc", "9fs", ndump, 0);
 			exits(0);
@@ -80,19 +115,6 @@ main(int argc, char *argv[])
 		free(w);
 	}
 
-	for(i=0; i<argc; i++)
-		ysearch(argv[i]);
-	exits(0);
-}
-
-void
-ysearch(char *file)
-{
-	char fil[400], buf[500], pair[2][500];
-	Dir *dir, *d;
-	ulong otime, dt;
-	int toggle, started, missing;
-
 	started = 0;
 	dir = dirstat(file);
 	if(dir == nil)
@@ -109,10 +131,15 @@ ysearch(char *file)
 		strcat(fil, "/");
 	}
 	strcat(fil, file);
+	if(slashnhack && memcmp(fil, "/n/", 3) == 0){
+		p = strchr(fil+3, '/');
+		if(p)
+			memmove(fil, p, strlen(p)+1);
+	}
 	otime = starttime(sflag);
 	toggle = 0;
 	for(;;) {
-		lastbefore(otime, fil, buf);
+		lastbefore(otime, fil, buf, ndump);
 		dir = dirstat(buf);
 		if(dir == nil) {
 			if(!force)
@@ -126,7 +153,7 @@ ysearch(char *file)
 		while(otime <= dir->mtime){
 			if(verb)
 				print("backup %ld, %ld\n", dir->mtime, otime-dt);
-			lastbefore(otime-dt, fil, buf);
+			lastbefore(otime-dt, fil, buf, ndump);
 			d = dirstat(buf);
 			if(d == nil){
 				if(!force)
@@ -168,7 +195,7 @@ ysearch(char *file)
 }
 
 void
-lastbefore(ulong t, char *f, char *b)
+lastbefore(ulong t, char *f, char *b, char *ndump)
 {
 	Tm *tm;
 	Dir *dir;

+ 1 - 1
sys/src/cmd/import.c

@@ -288,7 +288,7 @@ filter(int fd, char *cmd, char *host)
 	if ((s = strchr(newport, '!')) == nil)
 		sysfatal("filter: illegally formatted port %s\n", newport);
 
-	strcpy(buf, netmkaddr(host, "il", "0"));
+	strcpy(buf, netmkaddr(host, "tcp", "0"));
 	pbuf = strrchr(buf, '!');
 	strcpy(pbuf, s);
 

+ 14 - 0
sys/src/cmd/venti/dumpvacroots

@@ -0,0 +1,14 @@
+#!/bin/rc
+
+# this dumps all the vac scores ever stored to the venti server
+# if nothing else, this illustrates that you have to control access
+# to the physical disks storing the archive!
+
+ventihttp=your-server:8000
+hget http://$ventihttp/index | 
+awk '
+ /^index=/ { blockSize=0+substr($3, 11); }
+ /^arena=/ { arena=substr($1, 7); }
+ /^	arena=/ { start=0+substr($5, 2)-blockSize; printf("./8.printarena -o %d %s\n", start, $3); }' |
+rc |
+sed -n 's/^(.*) 1$/vac:\1/p'

+ 22 - 18
sys/src/cmd/vnc/auth.c

@@ -28,10 +28,10 @@ mktab(void)
 		return;
 	once = 1;
 
-	for(i=0; i<256; i++) {
+	for(i=0; i<256; i++){
 		j=i;
 		tab[i] = 0;
-		for(k=0; k<8; k++) {
+		for(k=0; k<8; k++){
 			tab[i] = (tab[i]<<1) | (j&1);
 			j >>= 1;
 		}
@@ -108,13 +108,13 @@ readln(char *prompt, char *line, int len)
 }
 
 int
-vnchandshake_srv(Vnc *v)
+vncsrvhandshake(Vnc *v)
 {
 	char msg[VerLen+1];
 
-	strcpy(msg, version);
+	strecpy(msg, msg+sizeof msg, version);
 	if(verbose)
-		fprint(2, "server version: %s\n", msg);
+		fprint(2, "server version: %s", msg);
 	vncwrbytes(v, msg, VerLen);
 	vncflush(v);
 
@@ -129,13 +129,14 @@ vnchandshake(Vnc *v)
 {
 	char msg[VerLen+1];
 
+	msg[VerLen] = 0;
 	vncrdbytes(v, msg, VerLen);
 	if(strncmp(msg, "RFB ", 4) != 0){
 		werrstr("bad rfb version \"%s\"", msg);
 		return -1;
 	}
 	if(verbose)
-		fprint(2, "server version %s\n", msg);
+		fprint(2, "server version: %s", msg);
 	strcpy(msg, version);
 	vncwrbytes(v, msg, VerLen);
 	vncflush(v);
@@ -151,7 +152,7 @@ vncauth(Vnc *v)
 	char *p, *server;
 
 	auth = vncrdlong(v);
-	switch(auth) {
+	switch(auth){
 	default:
 		werrstr("unknown auth type 0x%lux", auth);
 		if(verbose)
@@ -178,7 +179,7 @@ vncauth(Vnc *v)
 			*p = 0;
 		if(auth_respond(chal, VncChalLen, nil, 0, chal, VncChalLen, auth_getkey,
 			"proto=vnc role=client server=%s", server) != VncChalLen){
-			/* BUG: rip this out once people have new kernels */
+			/* BUG This is for drawterm users who don't start their own factotums */
 			readln("password: ", pw, sizeof(pw));
 			vncencrypt(chal, VncChalLen, pw);
 			memset(pw, 0, sizeof pw);
@@ -188,15 +189,15 @@ vncauth(Vnc *v)
 		vncflush(v);
 
 		auth = vncrdlong(v);
-		switch(auth) {
+		switch(auth){
 		default:
-			werrstr("unknown auth response 0x%lux", auth);
+			werrstr("unknown server response 0x%lux", auth);
 			return -1;
 		case VncAuthFailed:
-			werrstr("authentication failed");
+			werrstr("server says authentication failed");
 			return -1;
 		case VncAuthTooMany:
-			werrstr("authentication failed - too many tries");
+			werrstr("server says too many tries");
 			return -1;
 		case VncAuthOK:
 			break;
@@ -207,13 +208,15 @@ vncauth(Vnc *v)
 }
 
 int
-vncauth_srv(Vnc *v)
+vncsrvauth(Vnc *v)
 {
 	Chalstate *c;
-	struct AuthInfo * ai;
+	AuthInfo *ai;
 
-	if((c = auth_challenge("proto=vnc role=server user=%q", getuser()))==nil || c->nchal != VncChalLen)
-		sysfatal("vncchal returned with error\n");
+	if((c = auth_challenge("proto=vnc role=server user=%q", getuser()))==nil)
+		sysfatal("vncchal: %r");
+	if(c->nchal != VncChalLen)
+		sysfatal("vncchal got %d bytes wanted %d", c->nchal, VncChalLen);
 	vncwrlong(v, AVncAuth);
 	vncwrbytes(v, c->chal, VncChalLen);
 	vncflush(v);
@@ -224,8 +227,9 @@ vncauth_srv(Vnc *v)
 	ai = auth_response(c);
 	auth_freechal(c);
 	if(ai == nil){
-		if(verbose)
-			fprint(2, "VNC auth failed\n");
+		fprint(2, "vnc auth failed: server factotum: %r\n");
+		vncwrlong(v, VncAuthFailed);
+		vncflush(v);
 		return -1;
 	}
 	auth_freeAI(ai);

+ 2 - 2
sys/src/cmd/vnc/chan.c

@@ -29,7 +29,7 @@ chanfree(Chan *c)
 	c->flag = CFREE;
 
 	cnameclose(c->name);
-
+	free(c);
 }
 
 void
@@ -40,7 +40,7 @@ cclose(Chan *c)
 	if(decref(c))
 		return;
 
-	if(!waserror()) {
+	if(!waserror()){
 		devtab[c->type]->close(c);
 		poperror();
 	}

+ 8 - 8
sys/src/cmd/vnc/color.c

@@ -15,7 +15,7 @@ chan2fmt(Pixfmt *fmt, ulong chan)
 	ulong c, rc, shift;
 
 	shift = 0;
-	for(rc = chan; rc; rc >>=8) {
+	for(rc = chan; rc; rc >>=8){
 		c = rc & 0xFF;
 		switch(TYPE(c)){
 		case CRed:
@@ -42,7 +42,7 @@ cvt32to24(uchar *dst, uchar *src, int npixel)
 {
 	int i;
 
-	for(i=0; i<npixel; i++) {
+	for(i=0; i<npixel; i++){
 		*dst++ = *src++;
 		*dst++ = *src++;
 		*dst++ = *src++;
@@ -70,7 +70,7 @@ cvtrgb12tocmap8(uchar *dst, uchar *src, int npixel)
 {
 	int i, s;
 
-	for(i=0; i<npixel; i++) {
+	for(i=0; i<npixel; i++){
 		s = (src[0] | (src[1]<<8)) & 0xFFF;
 		*dst++ = rgb12[s];
 		src += 2;
@@ -87,7 +87,7 @@ mkbgrtab(void)
 {
 	int i, r, g, b;
 
-	for(i=0; i<256; i++) {
+	for(i=0; i<256; i++){
 		b = i>>6;
 		b = (b<<6)|(b<<4)|(b<<2)|b;
 		g = (i>>3) & 7;
@@ -121,15 +121,15 @@ choosecolor(Vnc *v)
 	depth = screen->depth;
 	chan = screen->chan;
 
-	if(bpp == 24) {
+	if(bpp == 24){
 		if(verbose)
 			fprint(2, "24bit emulation using 32bpp\n");
 		bpp = 32;
 		cvtpixels = cvt32to24;
 	}
 
-	if(chan == CMAP8) {
-		if(bpp12) {
+	if(chan == CMAP8){
+		if(bpp12){
 			if(verbose)
 				fprint(2, "8bit emulation using 12bpp\n");
 			bpp = 16;
@@ -137,7 +137,7 @@ choosecolor(Vnc *v)
 			chan = RGB12;
 			cvtpixels = cvtrgb12tocmap8;
 			mkrgbtab();
-		} else {
+		}else{
 			if(verbose)
 				fprint(2, "8bit emulation using 6bpp\n");	/* 6: we throw away 1 r, g bit */
 			bpp = 8;

+ 4 - 4
sys/src/cmd/vnc/compat.c

@@ -147,7 +147,7 @@ _rendsleep(ulong tag)
 {
 	ulong value;
 
-	for(;;) {
+	for(;;){
 		value = rendezvous(tag, 0x22a891b8);
 		if(value == 0x7f7713f9)
 			break;
@@ -161,7 +161,7 @@ _rendwakeup(ulong tag)
 {
 	ulong value;
 
-	for(;;) {
+	for(;;){
 		value = rendezvous(tag, 0x7f7713f9);
 		if(value == 0x22a891b8)
 			break;
@@ -201,7 +201,7 @@ rendsleep(Rendez *r, int (*f)(void*), void *arg)
 Done:
 	lock(&up->rlock);
 	up->r = 0;
-	if(up->intr) {
+	if(up->intr){
 		up->intr = 0;
 		unlock(&up->rlock);
 		error(Eintr);
@@ -218,7 +218,7 @@ rendwakeup(Rendez *r)
 	lock(r);
 	p = r->p;
 	rv = 0;
-	if(p) {
+	if(p){
 		r->p = nil;
 		_rendwakeup((ulong)r);
 		rv = 1;

+ 6 - 6
sys/src/cmd/vnc/dev.c

@@ -19,7 +19,7 @@ devno(int c, int user)
 {
 	int i;
 
-	for(i = 0; devtab[i] != nil; i++) {
+	for(i = 0; devtab[i] != nil; i++){
 		if(devtab[i]->dc == c)
 			return i;
 	}
@@ -149,7 +149,7 @@ devwalk(Chan *c, Chan *nc, char **name, int nname, Dirtab *tab, int ntab, Devgen
 			nc->qid = dir.qid;
 			goto Accept;
 		}
-		for(i=0;; i++) {
+		for(i=0;; i++){
 			switch((*gen)(nc, tab, ntab, i, &dir)){
 			case -1:
 				if(j == 0)
@@ -212,7 +212,7 @@ devstat(Chan *c, uchar *db, int n, Dirtab *tab, int ntab, Devgen *gen)
 		case 0:
 			break;
 		case 1:
-			if(c->qid.path == dir.qid.path) {
+			if(c->qid.path == dir.qid.path){
 				return convD2M(&dir, db, n);
 			}
 			break;
@@ -230,7 +230,7 @@ devdirread(Chan *c, char *d, long n, Dirtab *tab, int ntab, Devgen *gen)
 	}dir;
 
 	k = c->offset;
-	for(m=0; m<n; k++) {
+	for(m=0; m<n; k++){
 		switch((*gen)(c, tab, ntab, k, &dir)){
 		case -1:
 			return m;
@@ -283,14 +283,14 @@ devopen(Chan *c, int omode, Dirtab *tab, int ntab, Devgen *gen)
 	int i;
 	Dir dir;
 
-	for(i=0;; i++) {
+	for(i=0;; i++){
 		switch((*gen)(c, tab, ntab, i, &dir)){
 		case -1:
 			goto Return;
 		case 0:
 			break;
 		case 1:
-			if(c->qid.path == dir.qid.path) {
+			if(c->qid.path == dir.qid.path){
 				devpermcheck(dir.uid, dir.mode, omode);
 				goto Return;
 			}

+ 6 - 3
sys/src/cmd/vnc/devcons.c

@@ -279,6 +279,9 @@ consclose(Chan *c)
 		if(t == nil)
 			break;
 		setsnarf(t->buf, t->n, 0);
+		free(t->buf);
+		free(t);
+		c->aux = nil;
 		break;
 	}
 }
@@ -308,11 +311,11 @@ consread(Chan *c, void *buf, long n, vlong off)
 
 	case Qcons:
 		qlock(&kbd);
-		if(waserror()) {
+		if(waserror()){
 			qunlock(&kbd);
 			nexterror();
 		}
-		if(kbd.raw) {
+		if(kbd.raw){
 			cbuf = buf;
 			if(qcanread(lineq))
 				n = qread(lineq, buf, n);
@@ -326,7 +329,7 @@ consread(Chan *c, void *buf, long n, vlong off)
 				n = cbuf - (char*)buf;
 			}
 		} else {
-			while(!qcanread(lineq)) {
+			while(!qcanread(lineq)){
 				qread(kbdq, &kbd.line[kbd.x], 1);
 				ch = kbd.line[kbd.x];
 				eol = 0;

+ 2 - 2
sys/src/cmd/vnc/devmouse.c

@@ -199,7 +199,7 @@ mouseread(Chan *c, void *va, long n, vlong off)
 		 * is degenerate and already violates the calling
 		 * conventions for sleep above.
 		 */
-		if(mouse.ri != mouse.wi) {
+		if(mouse.ri != mouse.wi){
 			m = mouse.queue[mouse.ri];
 			if(++mouse.ri == nelem(mouse.queue))
 				mouse.ri = 0;
@@ -312,7 +312,7 @@ mousewrite(Chan *c, void *va, long n, vlong)
 			error(Eshort);
 		pt.y = strtoul(p, 0, 0);
 		qlock(&mouse);
-		if(ptinrect(pt, gscreen->r)) {
+		if(ptinrect(pt, gscreen->r)){
 			mousetrack(pt.x, pt.y, mouse.buttons, nsec()/(1000*1000LL));
 			mousewarpnote(pt);
 		}

+ 12 - 9
sys/src/cmd/vnc/draw.c

@@ -36,11 +36,11 @@ sendencodings(Vnc *v)
 
 	nf = tokenize(encodings, f, nelem(f));
 	nenc = 0;
-	for(i=0; i<nf; i++) {
+	for(i=0; i<nf; i++){
 		for(j=0; j<nelem(enctab); j++)
 			if(strcmp(f[i], enctab[j].name) == 0)
 				break;
-		if(j == nelem(enctab)) {
+		if(j == nelem(enctab)){
 			print("warning: unknown encoding %s\n", f[i]);
 			continue;
 		}
@@ -200,7 +200,7 @@ dohextile(Vnc *v, Rectangle r, int stride)
 
 			sr = Rect(sx, sy, sx + tw, sy + th);
 			enc = vncrdchar(v);
-			if(enc & HextileRaw) {
+			if(enc & HextileRaw){
 				loadbuf(v, sr, stride);
 				continue;
 			}
@@ -212,10 +212,10 @@ dohextile(Vnc *v, Rectangle r, int stride)
 			if(enc & HextileFore)
 				vncrdcolor(v, (uchar*)&fg);
 
-			if(enc & HextileRects) {
+			if(enc & HextileRects){
 				nsub = vncrdchar(v);
 				(*pixcp)((uchar*)&c, (uchar*)&fg);
-				while(nsub-- > 0) {
+				while(nsub-- > 0){
 					if(enc & HextileCols)
 						vncrdcolor(v, (uchar*)&c);
 					ssr = rectaddpt(hexrect(vncrdshort(v)), sr.min);
@@ -242,7 +242,7 @@ dorectangle(Vnc *v)
 		sysfatal("bad rectangle from server: %R not in %R", r, Rpt(ZP, v->dim));
 	stride = Dx(r) * pixb;
 	type = vncrdlong(v);
-	switch(type) {
+	switch(type){
 	default:
 		sysfatal("bad rectangle encoding from server");
 		break;
@@ -266,7 +266,7 @@ dorectangle(Vnc *v)
 		n = vncrdlong(v);
 		vncrdcolor(v, (uchar*)&color);
 		fillrect(maxr, stride, (uchar*)&color);
-		while(n-- > 0) {
+		while(n-- > 0){
 			vncrdcolor(v, (uchar*)&color);
 			if(type == EncRre)
 				subr = vncrdrect(v);
@@ -353,9 +353,9 @@ readfromserver(Vnc *v)
 	pixbuf = malloc(v->dim.x * pixb * v->dim.y);
 	if(linebuf == nil || pixbuf == nil)
 		sysfatal("can't allocate pix decompression storage");
-	for(;;) {
+	for(;;){
 		type = vncrdchar(v);
-		switch(type) {
+		switch(type){
 		default:
 			sysfatal("bad message from server");
 			break;
@@ -377,6 +377,9 @@ readfromserver(Vnc *v)
 		case MBell:
 			break;
 
+		case MSAck:
+			break;
+
 		case MSCut:
 			vncrdbytes(v, junk, 3);
 			n = vncrdlong(v);

+ 3 - 3
sys/src/cmd/vnc/exportfs.c

@@ -116,7 +116,7 @@ exportinit(void)
 {
 	lock(&exq.l);
 	exq.ref++;
-	if(fcalls[Tversion] != nil) {
+	if(fcalls[Tversion] != nil){
 		unlock(&exq.l);
 		return;
 	}
@@ -465,7 +465,7 @@ Exgetfid(Export *fs, int fid)
 
 	lock(&fs->fidlock);
 	h = fid % Nfidhash;
-	for(f = fs->fid[h]; f; f = f->next) {
+	for(f = fs->fid[h]; f; f = f->next){
 		if(f->fid == fid){
 			if(f->attached == 0)
 				break;
@@ -693,7 +693,7 @@ Exread(Export *fs, Fcall *rpc, uchar *buf)
 
 	c = f->chan;
 
-	if(waserror()) {
+	if(waserror()){
 		Exputfid(fs, f);
 		return up->error;
 	}

+ 1 - 1
sys/src/cmd/vnc/kbd.c → sys/src/cmd/vnc/kbds.c

@@ -143,7 +143,7 @@ vncputc(int keyup, int c)
 		nk = 0;
 		collecting = 0;
 		return;
-	} else {
+	}else{
 		switch(c){
 		case Caps:
 			caps ^= 1;

+ 6 - 6
sys/src/cmd/vnc/kbd_vwr.c → sys/src/cmd/vnc/kbdv.c

@@ -83,7 +83,7 @@ readkbd(Vnc *v)
 
 	kn = 0;
 	shift = alt = ctl = 0;
-	for(;;) {
+	for(;;){
 		while(!fullrune(k, kn)){
 			kr = read(fd, k+kn, sizeof k - kn);
 			if(kr <= 0)
@@ -95,7 +95,7 @@ readkbd(Vnc *v)
 		memmove(k, &k[w], kn);
 		ks = runetoksym(r);
 
-		switch(r) {
+		switch(r){
 		case Kalt:
 			alt = !alt;
 			keyevent(v, Xalt, alt);
@@ -109,7 +109,7 @@ readkbd(Vnc *v)
 			keyevent(v, Xshift, shift);
 			break;
 		default:
-			if(r == ks && r < 0x1A) {	/* control key */
+			if(r == ks && r < 0x1A){	/* control key */
 				keyevent(v, Xctl, 1);
 				keyevent(v, r+0x60, 1);	/* 0x60: make capital letter */
 				keyevent(v, r+0x60, 0);
@@ -121,15 +121,15 @@ readkbd(Vnc *v)
 							*/
 			}
 
-			if(alt) {
+			if(alt){
 				keyevent(v, Xalt, 0);
 				alt = 0;
 			}
-			if(ctl) {
+			if(ctl){
 				keyevent(v, Xctl, 0);
 				ctl = 0;
 			}
-			if(shift) {
+			if(shift){
 				keyevent(v, Xshift, 0);
 				shift = 0;
 			}

+ 12 - 5
sys/src/cmd/vnc/mkfile

@@ -17,14 +17,14 @@ SOFILES=\
 	chan.$O\
 	compat.$O\
 	exportfs.$O\
-	kbd.$O\
+	kbds.$O\
 	latin1.$O\
 	rre.$O\
-	region.$O\
+	rlist.$O\
 
 COFILES=\
 	draw.$O\
-	kbd_vwr.$O\
+	kbdv.$O\
 	color.$O\
 	wsys.$O\
 
@@ -35,11 +35,18 @@ HFILES=\
 	errstr.h\
 	kbd.h\
 	latin1.h\
-	region.h\
 	vncv.h\
 	vncs.h\
 
-UPDATE=`{echo *.[ch] mkfile} `{echo $TARG |sed 's/([^ $]*)( |$)/\/386\/bin\/\1 /g'}
+UPDATE=\
+	mkfile\
+	$HFILES\
+	${OFILES:%.$O=%.c}\
+	${SOFILES:%.$O=%.c}\
+	${COFILES:%.$O=%.c}\
+	${TARG:%=%.c}\
+	${TARG:%=/386/bin/%}\
+
 
 default:V:	all
 

+ 4 - 4
sys/src/cmd/vnc/proto.c

@@ -27,7 +27,7 @@ vncterm(Vnc *v)
 void
 vncflush(Vnc *v)
 {
-	if(Bflush(&v->out) < 0) {
+	if(Bflush(&v->out) < 0){
 		if(verbose > 1)
 			fprint(2, "hungup while sending flush: %r\n");
 		vnchungup(v);
@@ -98,7 +98,7 @@ vncrdcorect(Vnc *v)
 void
 vncrdbytes(Vnc *v, void *a, int n)
 {
-	if(Bread(&v->in, a, n) != n) {
+	if(Bread(&v->in, a, n) != n){
 		if(verbose > 1)
 			fprint(2, "hungup while reading\n");
 		vnchungup(v);
@@ -186,7 +186,7 @@ vncwrstring(Vnc *v, char *s)
 void
 vncwrbytes(Vnc *v, void *a, int n)
 {
-	if(Bwrite(&v->out, a, n) < 0) {
+	if(Bwrite(&v->out, a, n) < 0){
 		if(verbose > 1) 
 			fprint(2, "hungup while writing bytes\n");
 		vnchungup(v);
@@ -284,7 +284,7 @@ vncgobble(Vnc *v, long n)
 	uchar buf[8192];
 	long m;
 
-	while(n > 0) {
+	while(n > 0){
 		m = n;
 		if(m > sizeof(buf))
 			m = sizeof(buf);

+ 0 - 306
sys/src/cmd/vnc/region.c

@@ -1,306 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <draw.h>
-
-#include "region.h"
-
-extern int verbose;
-
-#define OKRECT(r) ((r).min.x < (r).max.x && (r).min.y < (r).max.y)
-
-extern void region_print(Region *);
-
-static tot_rects = 0;
-
-static void region_alloc(RegData * pReg, int howmany)
-{
-	int old = pReg->size;
-
-	if(  pReg->nrects + howmany <= pReg->size )
-		return;
-
-	do {
-		if( pReg->size == 0 ) 
-			pReg->size = 16;
-		else
-			pReg->size <<= 1;
-	} while( pReg->nrects + howmany >= pReg->size );
-
-	tot_rects += pReg->size - old;
-	if( tot_rects > 10000 ) {
-		fprint(2, "too many rectangles\n");
-		while(1) sleep(10000);
-		abort();
-	}
-	pReg->rects = realloc( pReg->rects, pReg->size*sizeof(Rectangle) );
-
-	if( pReg->rects == nil )
-		sysfatal("region_apprend: realloc failed %r\n");
-}
-
-static void region_append(Region * pReg, Rectangle r)
-{
-	region_alloc(&pReg->RegData, 1);
-	pReg->rects[ pReg->nrects++ ] = r;
-}
-
-void region_init(Region * pReg)
-{
-	pReg->extents = Rect(0,0,0,0);
-	pReg->size = pReg->nrects = 0;
-	pReg->rects = nil;
-}
-
-/* trim the ith item */
-int region_trim(Region * pReg, int i)
-{
-	int last = pReg->nrects-1;
-
-	if( last < 0 || i < 0 || i > last )
-		return 0;
-	// assert( last >=0 && && i >= 0 && i <= last );
-
-	if( i != last )
-		pReg->rects[i] = pReg->rects[last];
-	pReg->nrects--;
-	return 1;
-}
-
-/* adjacency check, differ from rectXrect by one pixel */
-static int
-rectadjacent(Rectangle r, Rectangle s)
-{
-	return r.min.x<=s.max.x && s.min.x<=r.max.x &&
-	       r.min.y<=s.max.y && s.min.y<=r.max.y;
-}
-
-/* s is inside of nr share one edge.
- * if Dz(s) == Dz(*nr), then
- * compute *nr = *nr - s
-*/
-static int
-rectsubr(Rectangle *nr, Rectangle s)
-{
-	if( nr->min.y == s.min.y && nr->max.y == s.max.y ) {
-		if( nr->min.x == s.min.x ) {
-			nr->min.x = s.max.x;
-			assert(nr->max.x > nr->min.x);
-			return 1;
-		}
-		if( nr->max.x == s.max.x ) {
-			nr->max.x = s.min.x;
-			assert(nr->max.x > nr->min.x);
-			return 1;
-		}
-	}
-	if( nr->min.x == s.min.x && nr->max.x == s.max.x ) {
-		if( nr->min.y == s.min.y ) {
-			nr->min.y = s.max.y;
-			assert(nr->max.y > nr->min.y);
-			return 1;
-		}
-		if( nr->max.y == s.max.y ) {
-			nr->max.y = s.min.y;
-			assert(nr->max.y > nr->min.y);
-			return 1;
-		}
-	}
-	return 0;
-}
-
-#define UPRIGHT(r) Pt((r).max.x, (r).min.y)
-#define LOWLEFT(r) Pt((r).min.x, (r).max.y)
-
-/* s is a corner of nr, Dz(s) < Dz(*nr) for z=x,y
- * cut it so that *nr = (*nr - s - *rr)
- * cut along Y, *nr holds the left part
- */
-static int
-rectcornersubr(Rectangle *nr, Rectangle s, Rectangle *rr)
-{
-	*rr = *nr;
-
-	if( s.min.x == nr->min.x ) {  
-		if( s.min.y == nr->min.y ) {  // upper left
-			*rr = Rpt(UPRIGHT(s), nr->max);
-			*nr = Rpt(LOWLEFT(s), LOWLEFT(*rr));
-			return 1;
-		}
-		if( s.max.y == nr->max.y ) { // lower left
-			*rr = Rpt(Pt(s.max.x, nr->min.y), nr->max);
-			*nr = Rpt(nr->min, UPRIGHT(s));
-			return 1;
-		}
-	}
-	if( s.max.x == nr->max.x ) {
-		if( s.max.y == nr->max.y ) { // lower right
-			*rr = Rpt(Pt(s.min.x, nr->min.y), UPRIGHT(s));
-			*nr = Rpt(nr->min, LOWLEFT(s));
-			return 1;
-		}
-		if( s.min.y == nr->min.y ) { // upper right
-			*rr = Rpt(LOWLEFT(s), nr->max);
-			*nr = Rpt(nr->min, LOWLEFT(*rr));
-			return 1;
-		}
-	}
-	return 0;
-}
-
-/* check if s is a band cutting nr in two pieces, Dz(s) == Dz(*nr) for *one* of x and y
- * if so, cut it so that *nr = (*nr - s - *rr)
- */
-
-static int
-rectstridesubr(Rectangle *nr, Rectangle s, Rectangle *rr)
-{
-	*rr = *nr;
-	if( (nr->min.x == s.min.x && nr->max.x == s.max.x) &&
-	    (nr->min.y < s.min.y && s.max.y < nr->max.y) ) {
-		nr->max.y = s.min.y;
-		rr->min.y = s.max.y;
-		return 1;
-	}
-
-	if( (nr->min.y == s.min.y && nr->max.y == s.max.y) &&
-	    (nr->min.x < s.min.x && s.max.x < nr->max.x) ) {
-		nr->max.x = s.min.x;
-		rr->min.x = s.max.x;
-		return 1;
-	}
-	return 0;
-}
-
-/* allow partial overlaping */
-void region_union(Region * pReg, Rectangle r, Rectangle clipr)
-{
-	int i, j;
-	Rectangle ir, cr, rr;
-	Region rreg;
-
-	if( ! OKRECT(r) )
-		return;
-	if( !rectclip(&r, clipr) )
-		return;
-
-	if( verbose > 5 )
-		fprint(2, "region union add %R:\n", r);
-
-	region_init(&rreg);
-	region_append(&rreg, r);
-
-	combinerect(&pReg->extents, r); // must do this first
-	for(j = 0; j < rreg.nrects; j++) {
-		r = rreg.rects[j];
-
-		for(i=0; i < pReg->nrects; i++) {
-			ir = pReg->rects[i];
-
-			if(verbose > 5)
-				fprint(2, "checking %R against %R\n", r, ir);
-			if( ! rectadjacent(ir, r) )
-				continue;
-
-			if( rectinrect(r, ir) ) // r is covered
-				break;
-
- 			if( rectinrect(ir, r) ) { // r covers
-				region_trim(pReg, i);
-				i--;  // scan the new item in i or breakout
-				continue;
-			}
-
-			// X/Y aligned and overlaping
-			if( (ir.min.y == r.min.y && ir.max.y == r.max.y ) ||
-		    	(ir.min.x == r.min.x && ir.max.x == r.max.x ) ) {
-				combinerect(&r, ir);
-				region_trim(pReg, i);
-				i--;
-				continue;
-			}
-
-			// not aligned 
-if( verbose > 5 ) fprint(2, "break up rect %R and %R\n", ir, r);
-			// 2 -> 2 breakup
-			cr = ir;
-			if ( !rectclip(&cr, r) )  // share one point only
-				continue;
-
-			if( rectsubr(&r, cr) )
-				continue;
-
-			if( rectsubr(&pReg->rects[i], cr) )
-				continue;
-
-			// 2 -> 3 breakup
-			// stride across
-			if( rectstridesubr(&r, cr, &rr) ) {
-				region_append(&rreg, rr);
-				continue;
-			}
-
-			// corner overlap
-			if( rectcornersubr(&r, cr, &rr) ) {
-				region_append(&rreg, rr);
-				continue;
-			}
-			sysfatal("should not be here\n");
-		}
-		if( i == pReg->nrects )
-			region_append(pReg, r);
-	}
-	region_reset(&rreg);
-	if(verbose > 5)
-		region_print(pReg);
-}
-
-void region_reset(Region * pReg)
-{
-	tot_rects -= pReg->size;
-
-	if( pReg->size )
-		free(pReg->rects);
-	region_init(pReg);
-}
-
-/* make a copy, override dst */
-void region_copy(Region * dst, Region *src)
-{
-	region_alloc(&dst->RegData, src->nrects - dst->nrects);
-
-	memcpy(dst->rects, src->rects, src->nrects * sizeof(Rectangle));
-	dst->extents = src->extents;
-	dst->nrects = src->nrects;
-}
-
-
-void region_print(Region * pReg)
-{
-	int i;
-
-	fprint(2, "region %p: ", pReg);
-	for(i = 0; i < pReg->nrects; i++) {
-		fprint(2, "%R ", pReg->rects[i]);
-	}
-	fprint(2, "\n");
-}
-
-#ifdef REGION_DEBUG
-
-int verbose = 10;
-
-void main(int argc, char * argv[])
-{
-	Rectangle r1 = Rect(0, 0, 300, 200);
-	Rectangle r2 = Rect(100, 100, 400, 300);
-	Rectangle r3 = Rect(200, 100, 500, 300);
-	Region reg;
-
-	initdraw(0, 0, "vncviewer");
-	region_init(&reg);
-	region_union(&reg, r1, r1);
-	region_union(&reg, r2, r2);
-	region_union(&reg, r3, r3);
-}
-
-#endif

+ 0 - 28
sys/src/cmd/vnc/region.h

@@ -1,28 +0,0 @@
-
-#ifndef REGION_H
-#define REGION_H
-
-typedef struct Region Region;
-typedef struct RegData RegData;
-
-struct RegData {
-	int size;		/* # of rects it can hold */
-	int nrects;		/* # used */
-	Rectangle * rects;
-};
-
-struct Region {
-	Rectangle extents;		/* the bounding box */
-
-	RegData;
-};
-
-#define REGION_EMPTY(reg) ((reg)->nrects == 0)
-
-extern void region_init(Region *);
-extern void region_union(Region *, Rectangle, Rectangle);
-extern void region_reset(Region *);
-extern void region_copy(Region *, Region *);
-
-
-#endif /* !REGION_H */

+ 283 - 0
sys/src/cmd/vnc/rlist.c

@@ -0,0 +1,283 @@
+#include "vnc.h"
+#include "vncs.h"
+
+static int tot;
+static void rprint(Rlist*);
+
+static void
+growrlist(Rlist *rlist, int n)
+{
+	int old;
+
+	if(rlist->nrect+n <= rlist->maxrect)
+		return;
+
+	old = rlist->maxrect;
+	while(rlist->nrect+n > rlist->maxrect){
+		if(rlist->maxrect == 0)
+			rlist->maxrect = 16;
+		else
+			rlist->maxrect *= 2;
+	}
+
+	tot += rlist->maxrect - old;
+	if(tot > 10000)
+		sysfatal("too many rectangles");
+
+	rlist->rect = realloc(rlist->rect, rlist->maxrect*sizeof(rlist->rect[0]));
+	if(rlist->rect == nil)
+		sysfatal("realloc failed in growrlist");
+}
+
+static void
+rappend(Rlist *rl, Rectangle r)
+{
+	growrlist(rl, 1);
+	rl->rect[rl->nrect++] = r;
+}
+
+/* remove rectangle i from the list */
+static int
+rtrim(Rlist *r, int i)
+{
+	if(i < 0 || i >= r->nrect)
+		return 0;
+	if(i == r->nrect-1){
+		r->nrect--;
+		return 1;
+	}
+	r->rect[i] = r->rect[--r->nrect];
+	return 1;
+}
+
+static int
+rectadjacent(Rectangle r, Rectangle s)
+{
+	return r.min.x<=s.max.x && s.min.x<=r.max.x &&
+	       r.min.y<=s.max.y && s.min.y<=r.max.y;
+}
+
+/*
+ * If s shares three edges with r, compute the
+ * rectangle r - s and return 1.
+ * Else return 0.
+ */
+static int
+rectubr(Rectangle *r, Rectangle s)
+{
+	if(r->min.y==s.min.y && r->max.y==s.max.y){
+		if(r->min.x == s.min.x){
+			r->min.x = s.max.x;
+			assert(r->max.x > r->min.x);
+			return 1;
+		}
+		if(r->max.x == s.max.x){
+			r->max.x = s.min.x;
+			assert(r->max.x > r->min.x);
+			return 1;
+		}
+	}
+	if(r->min.x==s.min.x && r->max.x==s.max.x){
+		if(r->min.y == s.min.y){
+			r->min.y = s.max.y;
+			assert(r->max.y > r->min.y);
+			return 1;
+		}
+		if(r->max.y == s.max.y){
+			r->max.y = s.min.y;
+			assert(r->max.y > r->min.y);
+			return 1;
+		}
+	}
+	return 0;
+}
+
+/*
+ * If s is a corner of r, remove s from r, yielding
+ * two rectangles r and rr.  R holds the part with
+ * smaller coordinates.
+ */
+static int
+rectcornersubr(Rectangle *r, Rectangle s, Rectangle *rr)
+{
+#	define UPRIGHT(r) Pt((r).max.x, (r).min.y)
+#	define LOWLEFT(r) Pt((r).min.x, (r).max.y)
+
+	*rr = *r;
+
+	if(s.min.x == r->min.x){  
+		if(s.min.y == r->min.y){  // upper left
+			*rr = Rpt(UPRIGHT(s), r->max);
+			*r = Rpt(LOWLEFT(s), LOWLEFT(*rr));
+			return 1;
+		}
+		if(s.max.y == r->max.y){ // lower left
+			*rr = Rpt(Pt(s.max.x, r->min.y), r->max);
+			*r = Rpt(r->min, UPRIGHT(s));
+			return 1;
+		}
+	}
+	if(s.max.x == r->max.x){
+		if(s.max.y == r->max.y){ // lower right
+			*rr = Rpt(Pt(s.min.x, r->min.y), UPRIGHT(s));
+			*r = Rpt(r->min, LOWLEFT(s));
+			return 1;
+		}
+		if(s.min.y == r->min.y){ // upper right
+			*rr = Rpt(LOWLEFT(s), r->max);
+			*r = Rpt(r->min, LOWLEFT(*rr));
+			return 1;
+		}
+	}
+	return 0;
+}
+
+/*
+ * If s is a band cutting r into two pieces, set r to one piece
+ * and rr to the other.
+ */
+static int
+recttridesubr(Rectangle *nr, Rectangle s, Rectangle *rr)
+{
+	*rr = *nr;
+	if((nr->min.x == s.min.x && nr->max.x == s.max.x) &&
+	    (nr->min.y < s.min.y && s.max.y < nr->max.y)){
+		nr->max.y = s.min.y;
+		rr->min.y = s.max.y;
+		return 1;
+	}
+
+	if((nr->min.y == s.min.y && nr->max.y == s.max.y) &&
+	    (nr->min.x < s.min.x && s.max.x < nr->max.x)){
+		nr->max.x = s.min.x;
+		rr->min.x = s.max.x;
+		return 1;
+	}
+	return 0;
+}
+
+void
+addtorlist(Rlist *rlist, Rectangle r)
+{
+	int i, j;
+	Rectangle ir, cr, rr;
+	Rlist tmp;
+
+	if(r.min.x >= r.max.x || r.min.y >= r.max.y)
+		return;
+
+	memset(&tmp, 0, sizeof tmp);
+	rappend(&tmp, r);
+	
+	if(verbose > 5)
+		fprint(2, "region union add %R:\n", r);
+
+	combinerect(&rlist->bbox, r); // must do this first
+	for(j = 0; j < tmp.nrect; j++){
+		r = tmp.rect[j];
+
+		for(i=0; i < rlist->nrect; i++){
+			ir = rlist->rect[i];
+
+			if(verbose > 5)
+				fprint(2, "checking %R against %R\n", r, ir);
+			if(!rectadjacent(ir, r))
+				continue;
+
+			/* r is covered by ir? */
+			if(rectinrect(r, ir))
+				break;
+
+			/* r covers ir? */
+ 			if(rectinrect(ir, r)){
+				rtrim(rlist, i);
+				i--;
+				continue;
+			}
+
+			/* aligned and overlapping? */
+			if((ir.min.y == r.min.y && ir.max.y == r.max.y) ||
+		    	(ir.min.x == r.min.x && ir.max.x == r.max.x)){
+				combinerect(&r, ir);
+				rtrim(rlist, i);
+				i--;
+				continue;
+			}
+
+			/* not aligned */ 
+			if(verbose > 5)
+				fprint(2, "break up rect %R and %R\n", ir, r);
+			/* 2->2 breakup */
+			cr = ir;
+			if (!rectclip(&cr, r))	/* share only one point */
+				continue;
+
+			if(rectubr(&r, cr))
+				continue;
+
+			if(rectubr(&rlist->rect[i], cr))
+				continue;
+
+			/* 2 -> 3 breakup */
+			/* stride across */
+			if(recttridesubr(&r, cr, &rr)){
+				rappend(&tmp, rr);
+				continue;
+			}
+
+			/* corner overlap */
+			if(rectcornersubr(&r, cr, &rr)){
+				rappend(&tmp, rr);
+				continue;
+			}
+			abort();
+		}
+		if(i == rlist->nrect)
+			rappend(rlist, r);
+	}
+	freerlist(&tmp);
+	if(verbose > 5)
+		rprint(rlist);
+}
+
+void
+freerlist(Rlist *r)
+{
+	free(r->rect);
+	tot -= r->maxrect;
+	r->nrect = 0;
+	r->maxrect = 0;
+	r->rect = nil;
+}
+
+static void
+rprint(Rlist *r)
+{
+	int i;
+
+	fprint(2, "rlist %p:", r);
+	for(i=0; i<r->nrect; i++)
+		fprint(2, " %R", r->rect[i]);
+	fprint(2, "\n");
+}
+
+
+#ifdef REGION_DEBUG
+
+int verbose = 10;
+
+void main(int argc, char * argv[])
+{
+	Rectangle r1 = Rect(0, 0, 300, 200);
+	Rectangle r2 = Rect(100, 100, 400, 300);
+	Rectangle r3 = Rect(200, 100, 500, 300);
+	Region reg;
+
+	initdraw(0, 0, "vncviewer");
+	region_init(&reg);
+	region_union(&reg, r1, r1);
+	region_union(&reg, r2, r2);
+	region_union(&reg, r3, r3);
+}
+
+#endif

+ 66 - 20
sys/src/cmd/vnc/rre.c

@@ -32,35 +32,42 @@ static void	sendtraw(Vnc *v, uchar *raw, int pixb, int stride, int w, int h);
 /*
  * default routine, no compression, just the pixels
  */
-void
+int
 sendraw(Vncs *v, Rectangle r)
 {
 	int pixb, stride;
 	uchar *raw;
 
-	if(!rectinrect(r, v->clientimage->r))
+	if(!rectinrect(r, v->image->r))
 		sysfatal("sending bad rectangle");
 
 	pixb = v->bpp >> 3;
 	if((pixb << 3) != v->bpp)
 		sysfatal("bad pixel math in sendraw");
-	stride = v->clientimage->width*sizeof(ulong);
+	stride = v->image->width*sizeof(ulong);
 	if(((stride / pixb) * pixb) != stride)
 		sysfatal("bad pixel math in sendraw");
 	stride /= pixb;
 
-	raw = byteaddr(v->clientimage, r.min);
+	raw = byteaddr(v->image, r.min);
 
 	vncwrrect(v, r);
 	vncwrlong(v, EncRaw);
 	sendtraw(v, raw, pixb, stride, Dx(r), Dy(r));
+	return 1;
+}
+
+int
+countraw(Vncs*, Rectangle)
+{
+	return 1;
 }
 
 /*
  * grab the image for the entire rectangle,
  * then encode each tile
  */
-void
+int
 sendhextile(Vncs *v, Rectangle r)
 {
 	uchar *(*putr)(uchar*, uchar*, int, int, int, int, int, int);
@@ -71,8 +78,8 @@ sendhextile(Vncs *v, Rectangle r)
 
 	h = Dy(r);
 	w = Dx(r);
-	if(h == 0 || w == 0 || !rectinrect(r, v->clientimage->r))
-		sysfatal("bad rectangle in sendhextile");
+	if(h == 0 || w == 0 || !rectinrect(r, v->image->r))
+		sysfatal("bad rectangle %R in sendhextile %R", r, v->image->r);
 
 	switch(v->bpp){
 	case  8:	pixlg = 0;	eq = eqpix8;	break;
@@ -80,13 +87,13 @@ sendhextile(Vncs *v, Rectangle r)
 	case 32:	pixlg = 2;	eq = eqpix32;	break;
 	default:
 		sendraw(v, r);
-		return;
+		return 1;
 	}
 	pixb = 1 << pixlg;
-	stride = v->clientimage->width*sizeof(ulong);
+	stride = v->image->width*sizeof(ulong);
 	if(((stride >> pixlg) << pixlg) != stride){
 		sendraw(v, r);
-		return;
+		return 1;
 	}
 	stride >>= pixlg;
 
@@ -96,9 +103,9 @@ sendhextile(Vncs *v, Rectangle r)
 		free(buf);
 		free(done);
 		sendraw(v, r);
-		return;
+		return 1;
 	}
-	raw = byteaddr(v->clientimage, r.min);
+	raw = byteaddr(v->image, r.min);
 
 	vncwrrect(v, r);
 	vncwrlong(v, EncHextile);
@@ -173,6 +180,13 @@ sendhextile(Vncs *v, Rectangle r)
 	}
 	free(buf);
 	free(done);
+	return 1;
+}
+
+int
+counthextile(Vncs*, Rectangle)
+{
+	return 1;
 }
 
 static int
@@ -229,14 +243,32 @@ sendtraw(Vnc *v, uchar *raw, int pixb, int stride, int w, int h)
 		vncwrbytes(v, &raw[y * stride * pixb], w * pixb);
 }
 
-int
+static int
 rrerects(Rectangle r, int split)
 {
 	return ((Dy(r) + split - 1) / split) * ((Dx(r) + split - 1) / split);
 }
 
+enum
+{
+	MaxCorreDim	= 48,
+	MaxRreDim	= 64,
+};
+
 int
-sendrre(Vncs *v, Rectangle r, int split, int compact)
+countrre(Vncs*, Rectangle r)
+{
+	return rrerects(r, MaxRreDim);
+}
+
+int
+countcorre(Vncs*, Rectangle r)
+{
+	return rrerects(r, MaxCorreDim);
+}
+
+static int
+_sendrre(Vncs *v, Rectangle r, int split, int compact)
 {
 	uchar *raw, *buf, *done;
 	int w, h, stride, pixb, pixlg, nraw, nr, bpr, back, totr;
@@ -247,7 +279,7 @@ sendrre(Vncs *v, Rectangle r, int split, int compact)
 	while(h > split){
 		h = r.max.y;
 		r.max.y = r.min.y + split;
-		totr += sendrre(v, r, split, compact);
+		totr += _sendrre(v, r, split, compact);
 		r.min.y = r.max.y;
 		r.max.y = h;
 		h = Dy(r);
@@ -256,12 +288,12 @@ sendrre(Vncs *v, Rectangle r, int split, int compact)
 	while(w > split){
 		w = r.max.x;
 		r.max.x = r.min.x + split;
-		totr += sendrre(v, r, split, compact);
+		totr += _sendrre(v, r, split, compact);
 		r.min.x = r.max.x;
 		r.max.x = w;
 		w = Dx(r);
 	}
-	if(h == 0 || w == 0 || !rectinrect(r, v->clientimage->r))
+	if(h == 0 || w == 0 || !rectinrect(r, v->image->r))
 		sysfatal("bad rectangle in sendrre");
 
 	switch(v->bpp){
@@ -273,7 +305,7 @@ sendrre(Vncs *v, Rectangle r, int split, int compact)
 		return totr + 1;
 	}
 	pixb = 1 << pixlg;
-	stride = v->clientimage->width*sizeof(ulong);
+	stride = v->image->width*sizeof(ulong);
 	if(((stride >> pixlg) << pixlg) != stride){
 		sendraw(v, r);
 		return totr + 1;
@@ -291,7 +323,7 @@ sendrre(Vncs *v, Rectangle r, int split, int compact)
 	}
 	memset(done, 0, w * h);
 
-	raw = byteaddr(v->clientimage, r.min);
+	raw = byteaddr(v->image, r.min);
 
 	if(compact)
 		bpr = 4 * 1 + pixb;
@@ -323,8 +355,22 @@ sendrre(Vncs *v, Rectangle r, int split, int compact)
 	return totr + 1;
 }
 
+int
+sendrre(Vncs *v, Rectangle r)
+{
+	return _sendrre(v, r, MaxRreDim, 0);
+}
+
+int
+sendcorre(Vncs *v, Rectangle r)
+{
+	return _sendrre(v, r, MaxCorreDim, 1);
+}
+
 static int
-encrre(uchar *raw, int stride, int w, int h, int back, int pixb, uchar *buf, int maxr, uchar *done, int (*eqpix)(uchar*, int, int), uchar *(*putr)(uchar*, uchar*, int, int, int, int, int, int))
+encrre(uchar *raw, int stride, int w, int h, int back, int pixb, uchar *buf,
+	int maxr, uchar *done, int (*eqpix)(uchar*, int, int),
+	uchar *(*putr)(uchar*, uchar*, int, int, int, int, int, int))
 {
 	int s, es, sx, esx, sy, syx, esyx, rh, rw, y, nr, dsy, dp;
 

+ 10 - 6
sys/src/cmd/vnc/screen.c

@@ -58,6 +58,7 @@ screeninit(int x, int y, char *chanstr)
 {
 	Point p, q;
 	char *greet;
+	char buf[128];
 	Memimage *grey;
 	Rectangle r;
 	int chan;
@@ -71,8 +72,10 @@ screeninit(int x, int y, char *chanstr)
 
 	r = Rect(0, 0, x, y);
 	gscreen = allocmemimage(r, chan);
-	if(gscreen == nil)
-		error("can't allocate screen image: %r");
+	if(gscreen == nil){
+		snprint(buf, sizeof buf, "can't allocate screen image: %r");
+		error(buf);
+	}
 
 	offscreen = Pt(x + 100, y + 100);
 	cursorr = Rect(0, 0, CURSORDIM, CURSORDIM);
@@ -85,7 +88,8 @@ screeninit(int x, int y, char *chanstr)
 		gscreen = nil;
 		cursorset = nil;
 		cursorclear = nil;
-		error("can't allocate cursor images: %r");
+		snprint(buf, sizeof buf, "can't allocate cursor images: %r");
+		error(buf);
 	}
 
 	drawlock();
@@ -201,7 +205,7 @@ cursordraw(Memimage *dst, Rectangle r)
 }
 
 /*
- * called with cursor locked, drawlock unlocked
+ * called with cursor locked, drawlock possibly unlocked
  */
 Rectangle
 cursorrect(void)
@@ -216,7 +220,7 @@ cursorrect(void)
 }
 
 /*
- * called with cursor locked, drawlock unlocked
+ * called with cursor locked, drawlock possibly unlocked
  */
 void
 setcursor(Cursor* curs)
@@ -300,7 +304,7 @@ screenputc(char *buf)
 	if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
 		xp = xbuf;
 
-	switch(buf[0]) {
+	switch(buf[0]){
 	case '\n':
 		if(curpos.y+h >= window.max.y)
 			scroll();

+ 4 - 5
sys/src/cmd/vnc/vnc.h

@@ -33,9 +33,7 @@ struct Vnc {
 
 	Point		dim;
 	Pixfmt;
-	char		*name;
-
-	Vnc		*next;
+	char		*name;	/* client only */
 };
 
 enum {
@@ -55,6 +53,7 @@ enum {
 	MSetCmap,
 	MBell,
 	MSCut,
+	MSAck,
 
 	/* client to server */
 	MPixFmt		= 0,
@@ -94,9 +93,9 @@ typedef ulong Color;
 
 /* auth.c */
 extern	int		vncauth(Vnc*);
-extern	int		vncauth_srv(Vnc*);
-extern	int		vnchandshake_srv(Vnc*);
 extern	int		vnchandshake(Vnc*);
+extern	int		vncsrvauth(Vnc*);
+extern	int		vncsrvhandshake(Vnc*);
 
 /* proto.c */
 extern	Vnc*		vncinit(int, int, Vnc*);

File diff suppressed because it is too large
+ 594 - 507
sys/src/cmd/vnc/vncs.c


+ 36 - 13
sys/src/cmd/vnc/vncs.h

@@ -1,29 +1,52 @@
+typedef struct	Rlist Rlist;
 typedef struct	Vncs	Vncs;
 
-#include "region.h"
+struct Rlist
+{
+	Rectangle	bbox;
+	int	maxrect;
+	int	nrect;
+	Rectangle *rect;
+};
 
-struct Vncs {
+struct Vncs
+{
 	Vnc;
 
-	int		preferredencoding;
-	int		usecopyrect;
+	Vncs	*next;
+	char		remote[NETPATHLEN];
+	char		netpath[NETPATHLEN];
+
+	char		*encname;
+	int		(*countrect)(Vncs*, Rectangle);
+	int		(*sendrect)(Vncs*, Rectangle);
+	int		copyrect;
 	int		canwarp;
 	int		needwarp;
 	Point		warppt;
-	int		updaterequested;
-	Region		updateregion;
-	int		ndeadprocs;
-	int		nprocs;
+
+	int		updaterequest;
+	Rlist		rlist;
+	int		ndead;
+	int		nproc;
 	int		cursorver;
 	Point		cursorpos;
 	Rectangle	cursorr;
 	int		snarfvers;
 
-        Memimage	*clientimage;
+	Memimage	*image;
 };
 
 /* rre.c */
-void	sendraw(Vncs *, Rectangle);
-int	sendrre(Vncs *, Rectangle, int, int);
-int	rrerects(Rectangle, int);
-void	sendhextile(Vncs *, Rectangle);
+int	countcorre(Vncs*, Rectangle);
+int	counthextile(Vncs*, Rectangle);
+int	countraw(Vncs*, Rectangle);
+int	countrre(Vncs*, Rectangle);
+int	sendcorre(Vncs*, Rectangle);
+int	sendhextile(Vncs*, Rectangle);
+int	sendraw(Vncs*, Rectangle);
+int	sendrre(Vncs*, Rectangle);
+
+/* rlist.c */
+void addtorlist(Rlist*, Rectangle);
+void freerlist(Rlist*);

+ 16 - 133
sys/src/cmd/vnc/vncv.c

@@ -1,5 +1,6 @@
 #include "vnc.h"
 #include "vncv.h"
+#include <libsec.h>
 
 char*	encodings = "copyrect hextile corre rre raw mousewarp";
 int		bpp12;
@@ -7,9 +8,10 @@ int		shared;
 int		verbose;
 Vnc*		vnc;
 int		mousefd;
+int		tls;
 
 static int	vncstart(Vnc*, int);
-static int	vncnegotiate(Vnc*);
+
 enum
 {
 	NProcs	= 4
@@ -48,6 +50,8 @@ netmkvncaddr(char *inserver)
 	assert(server != nil);
 
 	port = 5900;
+	if(tls)
+		port = 35729;
 	if(p = strchr(server, ':')) {
 		*p++ = '\0';
 		port += atoi(p);
@@ -78,6 +82,7 @@ main(int argc, char **argv)
 	int p, dfd, cfd, shared;
 	char *addr;
 	Point d;
+	TLSconn conn;
 
 	shared = 0;
 	ARGBEGIN{
@@ -90,6 +95,9 @@ main(int argc, char **argv)
 	case 's':
 		shared = 1;
 		break;
+	case 't':
+		tls = 1;
+		break;
 	case 'v':
 		verbose = 1;
 		break;
@@ -105,7 +113,12 @@ main(int argc, char **argv)
 	dfd = dial(addr, nil, nil, &cfd);
 	if(dfd < 0)
 		sysfatal("cannot dial %s: %r", addr);
-
+	if(tls){
+		dfd = tlsClient(dfd, &conn);
+		if(dfd < 0)
+			sysfatal("tlsClient: %r");
+		/* XXX check thumbprint */
+	}
 	vnc = vncinit(dfd, cfd, nil);
 
 	if(vnchandshake(vnc) < 0)
@@ -155,7 +168,7 @@ main(int argc, char **argv)
 	}
 	pids[2] = p;
 
-	if( access("/dev/snarf", AEXIST) == 0 ) {
+	if(access("/dev/snarf", AEXIST) >= 0){
 		switch(p = rfork(RFPROC|RFMEM)){
 		case -1:
 			sysfatal("rfork: %r");
@@ -173,136 +186,6 @@ main(int argc, char **argv)
 	exits(nil);
 }
 
-static int
-clienttlscrypt(Vnc *v)
-{
-	int p[2], netfd;
-
-	if(pipe(p) < 0){
-		fprint(2, "pipe: %r\n");
-		return -1;
-	}
-
-	netfd = v->datafd;
-	switch(rfork(RFMEM|RFPROC|RFFDG|RFNOWAIT)){
-	case -1:
-		fprint(2, "fork: %r\n");
-		return -1;
-	case 0:
-		dup(p[0], 0);
-		dup(netfd, 1);
-		close(v->ctlfd);
-		close(netfd);
-		close(p[0]);
-		close(p[1]);
-		execl("/bin/tlsrelay", "tlsrelay", nil);
-		fprint(2, "exec: %r\n");
-		_exits(nil);
-	default:
-		close(netfd);
-		v->datafd = p[1];
-		close(p[0]);
-		Binit(&v->in, v->datafd, OREAD);
-		Binit(&v->out, v->datafd, OWRITE);
-		return 0;
-	}
-}
-
-static int
-clientnocrypt(Vnc*)
-{
-	return 0;
-}
-
-static int
-clientvncauth(Vnc *v)
-{
-	return vncauth(v);
-}
-
-static int
-clientnoauth(Vnc*)
-{
-	return 0;
-}
-
-typedef struct Option Option;
-typedef struct Choice Choice;
-
-struct Choice {
-	char *s;
-	int (*fn)(Vnc*);
-};
-
-struct Option {
-	char *s;
-	Choice *c;
-	int nc;
-};
-
-static Choice clientcryptchoice[] = {
-	"tlsv1",	clienttlscrypt,
-	"none",	clientnocrypt,
-};
-
-static Choice clientauthchoice[] = {
-	"vnc",	clientvncauth,
-	"none",	clientnoauth,
-};
-
-static Option options[] = {
-	"crypt",	clientcryptchoice,	nelem(clientcryptchoice),
-	"auth",	clientauthchoice,	nelem(clientauthchoice),
-};
-
-static int
-vncnegotiate(Vnc *v)
-{
-	char *optstr, reply[256], *f[16];
-	int i, j, nf;
-	Option *o;
-
-	for(;;){
-		optstr = vncrdstringx(v);
-		if(strcmp(optstr, "start") == 0)
-			return 0;
-		nf = getfields(optstr, f, nelem(f), 0, " ");
-		if(nf == nelem(f)){
-			fprint(2, "too many choices for %s\n", f[0]);
-			return -1;
-		}
-		for(i=0; i<nelem(options); i++)
-			if(strcmp(f[0], options[i].s) == 0)
-				break;
-		if(i==nelem(options)){
-			fprint(2, "unknown option %s\n", f[0]);
-			vncwrstring(v, "error unknown option");
-			vncflush(v);
-			free(optstr);
-			continue;
-		}
-		o = &options[i];
-		for(i=0; i<o->nc; i++)
-			for(j=1; j<nf; j++)
-				if(strcmp(o->c[i].s, f[j]) == 0)
-					goto Break2;
-		fprint(2, "no common choice for %s\n", f[0]);
-		vncwrstring(v, "error no common choice");
-		vncflush(v);
-		free(optstr);
-		continue;
-Break2:
-		snprint(reply, sizeof reply, "%s %s", f[0], f[j]);
-		vncwrstring(v, reply);
-		vncflush(v);
-		if((*o->c[i].fn)(v) < 0)
-			fprint(2, "%s %s failed: %r\n", f[0], f[j]);
-		free(optstr);
-	}
-	abort();
-	return -1;
-}
-
 static int
 vncstart(Vnc *v, int shared)
 {

+ 10 - 10
sys/src/cmd/vnc/wsys.c

@@ -135,14 +135,14 @@ readmouse(Vnc *v)
 	requestupdate(vnc, 0);
 	start = end = buf;
 	len = 0;
-	for(;;) {
+	for(;;){
 		if((n = read(mousefd, end, sizeof(buf) - (end - buf))) < 0)
 			sysfatal("read mouse failed");
 
 		len += n;
 		end += n;
-		while(len >= EventSize) {
-			if(*start == 'm') {
+		while(len >= EventSize){
+			if(*start == 'm'){
 				m.xy.x = atoi(start+1);
 				m.xy.y = atoi(start+1+12);
 				m.buttons = atoi(start+1+2*12) & 7;
@@ -155,7 +155,7 @@ readmouse(Vnc *v)
 			start += EventSize;
 			len -= EventSize;
 		}
-		if(start - buf > sizeof(buf) - EventSize) {
+		if(start - buf > sizeof(buf) - EventSize){
 			memmove(buf, start, len);
 			start = buf;
 			end = start+len;
@@ -173,12 +173,12 @@ writesnarf(Vnc *v, long n)
 	long m;
 	Biobuf * fd;
 
-	if( (fd = Bopen("/dev/snarf", OWRITE)) == nil ) {
+	if( (fd = Bopen("/dev/snarf", OWRITE)) == nil ){
 		vncgobble(v, n);
 		return;
 	}
 
-	while(n > 0) {
+	while(n > 0){
 		m = n;
 		if(m > sizeof(buf))
 			m = sizeof(buf);
@@ -202,11 +202,11 @@ getsnarf(int * sz)
 	p = snarf = malloc(n);
 
 	seek(snarffd, 0, 0);
-	while ((c = read(snarffd, p, n)) > 0) {
+	while ((c = read(snarffd, p, n)) > 0){
 		p += c;
 		n -= c;
 		*sz += c;
-		if ( n == 0 ) {
+		if ( n == 0 ){
 			snarf = realloc(snarf, *sz + 8192);
 			n = 8192;
 		}
@@ -227,13 +227,13 @@ checksnarf(Vnc *v)
 			sysfatal("can't open /dev/snarf: %r");
 	}
 
-	while(1) {
+	for(;;){
 		sleep(1000);
 
 		dir = dirstat("/dev/snarf");
 		if(dir == nil)	/* this happens under old drawterm */
 			continue;
-		if(dir->qid.vers > snarf_vers) {
+		if(dir->qid.vers > snarf_vers){
 			snarf = getsnarf(&len);
 
 			vnclock(v);

+ 1 - 1
sys/src/libsec/port/mkfile

@@ -9,7 +9,7 @@ CFILES = des.c desmodes.c desECB.c desCBC.c des3ECB.c des3CBC.c\
 	rc4.c\
 	genrandom.c prng.c fastrand.c nfastrand.c\
 	probably_prime.c smallprimetest.c genprime.c dsaprimes.c gensafeprime.c genstrongprime.c\
-	rsagen.c rsaencrypt.c rsadecrypt.c rsaalloc.c rsaprivtopub.c x509.c decodepem.c \
+	rsagen.c rsafill.c rsaencrypt.c rsadecrypt.c rsaalloc.c rsaprivtopub.c x509.c decodepem.c \
 	eggen.c egencrypt.c egdecrypt.c egalloc.c egprivtopub.c egsign.c egverify.c \
 	dsagen.c dsaalloc.c dsaprivtopub.c dsasign.c dsaverify.c \
 	tlshand.c thumb.c readcert.c \

Some files were not shown because too many files changed in this diff