Browse Source

Plan 9 from Bell Labs 2003-12-02

David du Colombier 17 years ago
parent
commit
d9ed3607cc
96 changed files with 7770 additions and 127 deletions
  1. 108 26
      dist/replica/plan9.db
  2. 110 0
      dist/replica/plan9.log
  3. 13 4
      rc/bin/yesterday
  4. 6 0
      sys/include/ape/cursor.h
  5. 521 0
      sys/include/ape/draw.h
  6. 1 0
      sys/include/ape/errno.h
  7. 6 0
      sys/include/ape/event.h
  8. 107 0
      sys/include/ape/fmt.h
  9. 6 0
      sys/include/ape/keyboard.h
  10. 6 0
      sys/include/ape/mouse.h
  11. 36 0
      sys/include/ape/qlock.h
  12. 60 0
      sys/include/ape/utf.h
  13. 2 2
      sys/lib/plumb/basic
  14. 3 0
      sys/man/1/tar
  15. 7 1
      sys/man/1/yesterday
  16. 16 8
      sys/src/9/ip/tcp.c
  17. 7 2
      sys/src/9/port/qio.c
  18. 4 0
      sys/src/ape/lib/ap/plan9/9errstr.c
  19. 14 0
      sys/src/ape/lib/ap/plan9/9mallocz.c
  20. 21 0
      sys/src/ape/lib/ap/plan9/9readn.c
  21. 3 0
      sys/src/ape/lib/ap/plan9/mkfile
  22. 365 0
      sys/src/ape/lib/ap/plan9/qlock.c
  23. 203 0
      sys/src/ape/lib/draw/colors.c
  24. 135 0
      sys/src/ape/lib/draw/libc.h
  25. 78 0
      sys/src/ape/lib/draw/mkfile
  26. 85 0
      sys/src/ape/lib/fmt/charstod.c
  27. 558 0
      sys/src/ape/lib/fmt/dofmt.c
  28. 61 0
      sys/src/ape/lib/fmt/dorfmt.c
  29. 28 0
      sys/src/ape/lib/fmt/errfmt.c
  30. 610 0
      sys/src/ape/lib/fmt/fltfmt.c
  31. 221 0
      sys/src/ape/lib/fmt/fmt.c
  32. 121 0
      sys/src/ape/lib/fmt/fmtdef.h
  33. 46 0
      sys/src/ape/lib/fmt/fmtfd.c
  34. 33 0
      sys/src/ape/lib/fmt/fmtfdflush.c
  35. 28 0
      sys/src/ape/lib/fmt/fmtlock.c
  36. 47 0
      sys/src/ape/lib/fmt/fmtprint.c
  37. 262 0
      sys/src/ape/lib/fmt/fmtquote.c
  38. 40 0
      sys/src/ape/lib/fmt/fmtrune.c
  39. 65 0
      sys/src/ape/lib/fmt/fmtstr.c
  40. 46 0
      sys/src/ape/lib/fmt/fmtvprint.c
  41. 28 0
      sys/src/ape/lib/fmt/fprint.c
  42. 59 0
      sys/src/ape/lib/fmt/mkfile
  43. 4 0
      sys/src/ape/lib/fmt/nan.h
  44. 76 0
      sys/src/ape/lib/fmt/nan64.c
  45. 57 0
      sys/src/ape/lib/fmt/pow10.c
  46. 28 0
      sys/src/ape/lib/fmt/print.c
  47. 65 0
      sys/src/ape/lib/fmt/runefmtstr.c
  48. 30 0
      sys/src/ape/lib/fmt/runeseprint.c
  49. 30 0
      sys/src/ape/lib/fmt/runesmprint.c
  50. 31 0
      sys/src/ape/lib/fmt/runesnprint.c
  51. 30 0
      sys/src/ape/lib/fmt/runesprint.c
  52. 39 0
      sys/src/ape/lib/fmt/runevseprint.c
  53. 37 0
      sys/src/ape/lib/fmt/runevsmprint.c
  54. 38 0
      sys/src/ape/lib/fmt/runevsnprint.c
  55. 27 0
      sys/src/ape/lib/fmt/seprint.c
  56. 27 0
      sys/src/ape/lib/fmt/smprint.c
  57. 28 0
      sys/src/ape/lib/fmt/snprint.c
  58. 27 0
      sys/src/ape/lib/fmt/sprint.c
  59. 539 0
      sys/src/ape/lib/fmt/strtod.c
  60. 4 0
      sys/src/ape/lib/fmt/strtod.h
  61. 39 0
      sys/src/ape/lib/fmt/test.c
  62. 31 0
      sys/src/ape/lib/fmt/vfprint.c
  63. 37 0
      sys/src/ape/lib/fmt/vseprint.c
  64. 36 0
      sys/src/ape/lib/fmt/vsmprint.c
  65. 37 0
      sys/src/ape/lib/fmt/vsnprint.c
  66. 16 0
      sys/src/ape/lib/fmt/werrstr.c
  67. 1 1
      sys/src/ape/lib/mkfile
  68. 17 0
      sys/src/ape/lib/utf/lib9.h
  69. 37 0
      sys/src/ape/lib/utf/mkfile
  70. 177 0
      sys/src/ape/lib/utf/rune.c
  71. 25 0
      sys/src/ape/lib/utf/runestrcat.c
  72. 35 0
      sys/src/ape/lib/utf/runestrchr.c
  73. 35 0
      sys/src/ape/lib/utf/runestrcmp.c
  74. 28 0
      sys/src/ape/lib/utf/runestrcpy.c
  75. 30 0
      sys/src/ape/lib/utf/runestrdup.c
  76. 32 0
      sys/src/ape/lib/utf/runestrecpy.c
  77. 24 0
      sys/src/ape/lib/utf/runestrlen.c
  78. 32 0
      sys/src/ape/lib/utf/runestrncat.c
  79. 37 0
      sys/src/ape/lib/utf/runestrncmp.c
  80. 33 0
      sys/src/ape/lib/utf/runestrncpy.c
  81. 30 0
      sys/src/ape/lib/utf/runestrrchr.c
  82. 44 0
      sys/src/ape/lib/utf/runestrstr.c
  83. 1152 0
      sys/src/ape/lib/utf/runetype.c
  84. 14 0
      sys/src/ape/lib/utf/utfdef.h
  85. 51 0
      sys/src/ape/lib/utf/utfecpy.c
  86. 38 0
      sys/src/ape/lib/utf/utflen.c
  87. 41 0
      sys/src/ape/lib/utf/utfnlen.c
  88. 46 0
      sys/src/ape/lib/utf/utfrrune.c
  89. 45 0
      sys/src/ape/lib/utf/utfrune.c
  90. 41 0
      sys/src/ape/lib/utf/utfutf.c
  91. 1 1
      sys/src/cmd/disk/mkext.c
  92. 2 2
      sys/src/cmd/hget.c
  93. 1 1
      sys/src/cmd/ip/httpd/webls.c
  94. 2 2
      sys/src/cmd/ratfs/misc.c
  95. 198 56
      sys/src/cmd/tar.c
  96. 32 21
      sys/src/cmd/upas/common/libsys.c

+ 108 - 26
dist/replica/plan9.db

@@ -90,7 +90,7 @@
 386/bin/aux/X509gen - 775 sys sys 1048341826 129186
 386/bin/aux/accupoint - 775 sys sys 1064598059 40841
 386/bin/aux/acidleak - 775 sys sys 1064598060 67816
-386/bin/aux/antiword - 775 sys sys 1069793954 511478
+386/bin/aux/antiword - 775 sys sys 1070288096 511478
 386/bin/aux/apm - 775 sys sys 1064598061 175778
 386/bin/aux/astarld - 775 sys sys 1064598061 63276
 386/bin/aux/cddb - 775 sys sys 1064598062 70192
@@ -230,9 +230,9 @@
 386/bin/fortune - 775 sys sys 1064598140 66084
 386/bin/fossil - 20000000775 sys sys 1042005470 0
 386/bin/fossil/conf - 775 sys sys 1056364255 1497
-386/bin/fossil/flchk - 775 sys sys 1068717500 232696
-386/bin/fossil/flfmt - 775 sys sys 1068717501 230661
-386/bin/fossil/fossil - 775 sys sys 1068717502 345764
+386/bin/fossil/flchk - 775 sys sys 1070288097 232862
+386/bin/fossil/flfmt - 775 sys sys 1070288098 230827
+386/bin/fossil/fossil - 775 sys sys 1070288099 345606
 386/bin/freq - 775 sys sys 1064598145 60197
 386/bin/fs - 20000000775 sys sys 954380769 0
 386/bin/fs/32vfs - 775 sys sys 1064598146 95907
@@ -252,7 +252,7 @@
 386/bin/gunzip - 775 sys sys 1064598211 79675
 386/bin/gzip - 775 sys sys 1064598211 83770
 386/bin/hayes - 775 sys sys 1064598212 63307
-386/bin/hget - 775 sys sys 1068385800 222506
+386/bin/hget - 775 sys sys 1070286807 222506
 386/bin/history - 775 sys sys 1064598214 71890
 386/bin/hoc - 775 sys sys 1064598215 98708
 386/bin/html2ms - 775 sys sys 1064598215 64484
@@ -284,8 +284,8 @@
 386/bin/ip/ppp - 775 sys sys 1069592368 217323
 386/bin/ip/pppoe - 775 sys sys 1064598236 75233
 386/bin/ip/pptp - 775 sys sys 1064598237 123773
-386/bin/ip/pptpd - 775 sys sys 1064598238 124288
-386/bin/ip/rarpd - 775 sys sys 1069592368 107845
+386/bin/ip/pptpd - 775 sys sys 1070288105 124153
+386/bin/ip/rarpd - 775 sys sys 1070288105 107748
 386/bin/ip/rexexec - 775 sys sys 1064598240 87398
 386/bin/ip/rip - 775 sys sys 1064598241 89573
 386/bin/ip/rlogind - 775 sys sys 1064598241 66139
@@ -316,10 +316,10 @@
 386/bin/ndb - 20000000775 sys sys 985743147 0
 386/bin/ndb/cs - 775 sys sys 1069766560 144581
 386/bin/ndb/csquery - 775 sys sys 1064598259 59890
-386/bin/ndb/dns - 775 sys sys 1069592370 218704
-386/bin/ndb/dnsdebug - 775 sys sys 1069592371 191053
+386/bin/ndb/dns - 775 sys sys 1070288106 218607
+386/bin/ndb/dnsdebug - 775 sys sys 1070288107 190956
 386/bin/ndb/dnsquery - 775 sys sys 1064598263 62194
-386/bin/ndb/dnstcp - 775 sys sys 1069592372 189767
+386/bin/ndb/dnstcp - 775 sys sys 1070288108 189670
 386/bin/ndb/ipquery - 775 sys sys 1069592372 91891
 386/bin/ndb/mkdb - 775 sys sys 1064598265 62386
 386/bin/ndb/mkhash - 775 sys sys 1069592372 82479
@@ -527,7 +527,7 @@
 386/lib/libgeometry.a - 664 sys sys 1068385839 50806
 386/lib/libhtml.a - 664 sys sys 1068385840 220944
 386/lib/libhttpd.a - 664 sys sys 1068385841 98914
-386/lib/libip.a - 664 sys sys 1069766546 34142
+386/lib/libip.a - 664 sys sys 1070288108 34142
 386/lib/libl.a - 664 sys sys 1068385841 5412
 386/lib/libmach.a - 664 sys sys 1068558293 748290
 386/lib/libmemdraw.a - 664 sys sys 1068385844 292604
@@ -3098,7 +3098,7 @@ rc/bin/whois - 775 sys sys 945617210 189
 rc/bin/window - 775 sys sys 1045504108 1742
 rc/bin/wloc - 775 sys sys 969512017 191
 rc/bin/wurl2txt - 755 sys sys 1017431148 296
-rc/bin/yesterday - 775 sys sys 1044909161 2408
+rc/bin/yesterday - 775 sys sys 1070288432 2541
 rc/lib - 20000000775 sys sys 948037639 0
 rc/lib/rcmain - 664 sys sys 984696976 579
 sparc - 20000000775 sys sys 947991046 0
@@ -3319,12 +3319,17 @@ sys/include/ape/arpa/inet.h - 664 sys sys 944948760 4717
 sys/include/ape/assert.h - 664 sys sys 944948760 287
 sys/include/ape/bsd.h - 664 sys sys 944948760 1087
 sys/include/ape/ctype.h - 664 sys sys 1014927763 1654
+sys/include/ape/cursor.h - 664 sys sys 1070327358 118
 sys/include/ape/dirent.h - 664 sys sys 1035117682 717
-sys/include/ape/errno.h - 664 sys sys 944948760 1505
+sys/include/ape/draw.h - 664 sys sys 1070327359 15998
+sys/include/ape/errno.h - 664 sys sys 1070327359 1525
 sys/include/ape/error.h - 664 sys sys 944948759 356
+sys/include/ape/event.h - 664 sys sys 1070327358 117
 sys/include/ape/fcntl.h - 664 sys sys 969500385 1231
+sys/include/ape/fmt.h - 664 sys sys 1070327361 3276
 sys/include/ape/grp.h - 664 sys sys 944948759 389
 sys/include/ape/inttypes.h - 664 sys sys 1038237535 452
+sys/include/ape/keyboard.h - 664 sys sys 1070327358 120
 sys/include/ape/lib9.h - 664 sys sys 1014927764 1626
 sys/include/ape/libl.h - 664 sys sys 944948760 331
 sys/include/ape/libnet.h - 664 sys sys 944948760 487
@@ -3332,11 +3337,13 @@ sys/include/ape/libv.h - 664 sys sys 944948760 716
 sys/include/ape/limits.h - 664 sys sys 1014927764 2491
 sys/include/ape/locale.h - 664 sys sys 944948759 796
 sys/include/ape/lock.h - 664 sys sys 946054014 363
+sys/include/ape/mouse.h - 664 sys sys 1070327358 117
 sys/include/ape/netdb.h - 664 sys sys 1014927764 3907
 sys/include/ape/netinet - 20000000775 sys sys 944948759 0
 sys/include/ape/netinet/in.h - 664 sys sys 944948759 4717
 sys/include/ape/netinet/tcp.h - 664 sys sys 944948759 0
 sys/include/ape/pwd.h - 664 sys sys 944948759 423
+sys/include/ape/qlock.h - 664 sys sys 1070327358 474
 sys/include/ape/regexp.h - 664 sys sys 988225292 1559
 sys/include/ape/select.h - 664 sys sys 944948760 779
 sys/include/ape/setjmp.h - 664 sys sys 944948760 421
@@ -3365,6 +3372,7 @@ sys/include/ape/termios.h - 664 sys sys 944948760 2745
 sys/include/ape/time.h - 664 sys sys 944948760 1016
 sys/include/ape/u.h - 664 sys sys 1038237538 399
 sys/include/ape/unistd.h - 664 sys sys 944948760 3917
+sys/include/ape/utf.h - 664 sys sys 1070327359 1595
 sys/include/ape/utime.h - 664 sys sys 944948760 259
 sys/include/ar.h - 664 sys sys 1014929061 244
 sys/include/auth.h - 664 sys sys 1048614957 3469
@@ -3939,7 +3947,7 @@ sys/lib/man/trademarks - 664 sys sys 958527089 1838
 sys/lib/mimetype - 664 sys sys 1064393944 5563
 sys/lib/newuser - 775 sys sys 1018386991 1229
 sys/lib/plumb - 20000000775 sys sys 944957365 0
-sys/lib/plumb/basic - 664 sys sys 1069794119 2906
+sys/lib/plumb/basic - 664 sys sys 1070330856 2930
 sys/lib/plumb/fileaddr - 664 sys sys 944957365 88
 sys/lib/postscript - 20000000775 sys sys 950322802 0
 sys/lib/postscript/afm - 20000000775 sys sys 950322802 0
@@ -4690,7 +4698,7 @@ sys/man/1/sum - 664 sys sys 984772442 1390
 sys/man/1/syscall - 664 sys sys 1016466457 1439
 sys/man/1/tail - 664 sys sys 1017679307 1413
 sys/man/1/tapefs - 664 sys sys 944959675 1731
-sys/man/1/tar - 664 sys sys 988225296 2317
+sys/man/1/tar - 664 sys sys 1070287474 2363
 sys/man/1/tbl - 664 sys sys 944959674 4308
 sys/man/1/tcs - 664 sys sys 952627441 2575
 sys/man/1/tee - 664 sys sys 969499886 351
@@ -4713,7 +4721,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 1044909169 2202
+sys/man/1/yesterday - 664 sys sys 1070288431 2348
 sys/man/2 - 20000000775 sys sys 1017423721 0
 sys/man/2/0intro - 664 sys sys 1044724217 11574
 sys/man/2/9p - 664 sys sys 1046886431 15221
@@ -5215,7 +5223,7 @@ sys/src/9/ip/nullmedium.c - 664 sys sys 1022588099 491
 sys/src/9/ip/pktmedium.c - 664 sys sys 1045063516 1355
 sys/src/9/ip/ptclbsum.c - 664 sys sys 1022588099 1243
 sys/src/9/ip/rudp.c - 664 sys sys 1055700790 21415
-sys/src/9/ip/tcp.c - 664 sys sys 1067722615 65141
+sys/src/9/ip/tcp.c - 664 sys sys 1070287819 65399
 sys/src/9/ip/tripmedium.c - 664 sys sys 1045063515 7136
 sys/src/9/ip/udp.c - 664 sys sys 1055700791 13069
 sys/src/9/mkfile - 664 sys sys 1063857477 205
@@ -5439,7 +5447,7 @@ sys/src/9/port/portfns.h - 664 sys sys 1068215525 11376
 sys/src/9/port/portmkfile - 664 sys sys 1067722766 2098
 sys/src/9/port/print.c - 664 sys sys 1014931178 227
 sys/src/9/port/proc.c - 664 sys sys 1068393121 24882
-sys/src/9/port/qio.c - 664 sys sys 1067953182 23406
+sys/src/9/port/qio.c - 664 sys sys 1070287837 23562
 sys/src/9/port/qlock.c - 664 sys sys 1067722765 3196
 sys/src/9/port/rdb.c - 664 sys sys 1018721202 1698
 sys/src/9/port/realtimesub.c - 664 sys sys 1055688540 9185
@@ -5984,7 +5992,10 @@ sys/src/ape/lib/ap/mips/vlop.s - 664 sys sys 1014921989 239
 sys/src/ape/lib/ap/mips/vlrt.c - 664 sys sys 1014921989 9001
 sys/src/ape/lib/ap/mkfile - 664 sys sys 1014921988 244
 sys/src/ape/lib/ap/plan9 - 20000000775 sys sys 1014921986 0
+sys/src/ape/lib/ap/plan9/9errstr.c - 664 sys sys 1070330880 31
+sys/src/ape/lib/ap/plan9/9mallocz.c - 664 sys sys 1070330880 148
 sys/src/ape/lib/ap/plan9/9read.c - 664 sys sys 1014921986 169
+sys/src/ape/lib/ap/plan9/9readn.c - 664 sys sys 1070330880 221
 sys/src/ape/lib/ap/plan9/9wait.c - 664 sys sys 1014921986 1517
 sys/src/ape/lib/ap/plan9/9write.c - 664 sys sys 1014921986 171
 sys/src/ape/lib/ap/plan9/_buf.c - 664 sys sys 1048644332 9661
@@ -6050,13 +6061,14 @@ sys/src/ape/lib/ap/plan9/link.c - 664 sys sys 1014921984 168
 sys/src/ape/lib/ap/plan9/lseek.c - 664 sys sys 1038237526 358
 sys/src/ape/lib/ap/plan9/malloc.c - 664 sys sys 1014921985 1957
 sys/src/ape/lib/ap/plan9/mkdir.c - 664 sys sys 1014921984 353
-sys/src/ape/lib/ap/plan9/mkfile - 664 sys sys 1030558746 1320
+sys/src/ape/lib/ap/plan9/mkfile - 664 sys sys 1070330880 1357
 sys/src/ape/lib/ap/plan9/nan.c - 664 sys sys 1014921985 614
 sys/src/ape/lib/ap/plan9/open.c - 664 sys sys 1048644335 1088
 sys/src/ape/lib/ap/plan9/opendir.c - 664 sys sys 1014921984 1881
 sys/src/ape/lib/ap/plan9/pause.c - 664 sys sys 1014921985 124
 sys/src/ape/lib/ap/plan9/pipe.c - 664 sys sys 1014921984 476
 sys/src/ape/lib/ap/plan9/profile.c - 664 sys sys 1014921985 2521
+sys/src/ape/lib/ap/plan9/qlock.c - 664 sys sys 1070330880 5124
 sys/src/ape/lib/ap/plan9/raise.c - 664 sys sys 1014921985 120
 sys/src/ape/lib/ap/plan9/read.c - 664 sys sys 1014921984 767
 sys/src/ape/lib/ap/plan9/rename.c - 664 sys sys 1046643006 1282
@@ -6243,6 +6255,52 @@ sys/src/ape/lib/bsd/strcasecmp.c - 664 sys sys 1051635385 343
 sys/src/ape/lib/bsd/strdup.c - 664 sys sys 1014921995 182
 sys/src/ape/lib/bsd/strncasecmp.c - 664 sys sys 1051635385 385
 sys/src/ape/lib/bsd/writev.c - 664 sys sys 1014921995 908
+sys/src/ape/lib/draw - 20000000775 sys sys 1070327097 0
+sys/src/ape/lib/draw/colors.c - 664 sys sys 1070327097 3607
+sys/src/ape/lib/draw/libc.h - 664 sys sys 1070327097 3476
+sys/src/ape/lib/draw/mkfile - 664 sys sys 1070327097 1176
+sys/src/ape/lib/fmt - 20000000775 sys sys 1070327381 0
+sys/src/ape/lib/fmt/charstod.c - 664 sys sys 1070327066 1995
+sys/src/ape/lib/fmt/dofmt.c - 664 sys sys 1070327066 10020
+sys/src/ape/lib/fmt/dorfmt.c - 664 sys sys 1070327066 1576
+sys/src/ape/lib/fmt/errfmt.c - 664 sys sys 1070327066 948
+sys/src/ape/lib/fmt/fltfmt.c - 664 sys sys 1070327066 10300
+sys/src/ape/lib/fmt/fmt.c - 664 sys sys 1070327067 4131
+sys/src/ape/lib/fmt/fmtdef.h - 664 sys sys 1070327067 3100
+sys/src/ape/lib/fmt/fmtfd.c - 664 sys sys 1070327067 1302
+sys/src/ape/lib/fmt/fmtfdflush.c - 664 sys sys 1070327067 1077
+sys/src/ape/lib/fmt/fmtlock.c - 664 sys sys 1070327067 868
+sys/src/ape/lib/fmt/fmtprint.c - 664 sys sys 1070327068 1257
+sys/src/ape/lib/fmt/fmtquote.c - 664 sys sys 1070327068 5582
+sys/src/ape/lib/fmt/fmtrune.c - 664 sys sys 1070327068 1120
+sys/src/ape/lib/fmt/fmtstr.c - 664 sys sys 1070327068 1509
+sys/src/ape/lib/fmt/fmtvprint.c - 664 sys sys 1070327068 1241
+sys/src/ape/lib/fmt/fprint.c - 664 sys sys 1070327069 946
+sys/src/ape/lib/fmt/mkfile - 664 sys sys 1070327069 794
+sys/src/ape/lib/fmt/nan.h - 664 sys sys 1070327069 114
+sys/src/ape/lib/fmt/nan64.c - 664 sys sys 1070327069 1176
+sys/src/ape/lib/fmt/pow10.c - 664 sys sys 1070327069 1987
+sys/src/ape/lib/fmt/print.c - 664 sys sys 1070327069 936
+sys/src/ape/lib/fmt/runefmtstr.c - 664 sys sys 1070327070 1544
+sys/src/ape/lib/fmt/runeseprint.c - 664 sys sys 1070327070 1016
+sys/src/ape/lib/fmt/runesmprint.c - 664 sys sys 1070327070 988
+sys/src/ape/lib/fmt/runesnprint.c - 664 sys sys 1070327070 1015
+sys/src/ape/lib/fmt/runesprint.c - 664 sys sys 1070327070 1004
+sys/src/ape/lib/fmt/runevseprint.c - 664 sys sys 1070327071 1132
+sys/src/ape/lib/fmt/runevsmprint.c - 664 sys sys 1070327071 1109
+sys/src/ape/lib/fmt/runevsnprint.c - 664 sys sys 1070327071 1142
+sys/src/ape/lib/fmt/seprint.c - 664 sys sys 1070327071 951
+sys/src/ape/lib/fmt/smprint.c - 664 sys sys 1070327071 923
+sys/src/ape/lib/fmt/snprint.c - 664 sys sys 1070327071 950
+sys/src/ape/lib/fmt/sprint.c - 664 sys sys 1070327072 991
+sys/src/ape/lib/fmt/strtod.c - 664 sys sys 1070327072 9359
+sys/src/ape/lib/fmt/strtod.h - 664 sys sys 1070327072 120
+sys/src/ape/lib/fmt/test.c - 664 sys sys 1070327072 1423
+sys/src/ape/lib/fmt/vfprint.c - 664 sys sys 1070327072 1026
+sys/src/ape/lib/fmt/vseprint.c - 664 sys sys 1070327072 1089
+sys/src/ape/lib/fmt/vsmprint.c - 664 sys sys 1070327073 1084
+sys/src/ape/lib/fmt/vsnprint.c - 664 sys sys 1070327073 1119
+sys/src/ape/lib/fmt/werrstr.c - 664 sys sys 1070330902 241
 sys/src/ape/lib/l - 20000000775 sys sys 1014921994 0
 sys/src/ape/lib/l/allprint.c - 664 sys sys 1014921994 458
 sys/src/ape/lib/l/main.c - 664 sys sys 1014921994 128
@@ -6250,7 +6308,7 @@ sys/src/ape/lib/l/mkfile - 664 sys sys 1014921994 180
 sys/src/ape/lib/l/reject.c - 664 sys sys 1014921994 985
 sys/src/ape/lib/l/yyless.c - 664 sys sys 1014921994 387
 sys/src/ape/lib/l/yywrap.c - 664 sys sys 1014921994 70
-sys/src/ape/lib/mkfile - 664 sys sys 1014921994 190
+sys/src/ape/lib/mkfile - 664 sys sys 1070330862 203
 sys/src/ape/lib/net - 20000000775 sys sys 1014921993 0
 sys/src/ape/lib/net/announce.c - 664 sys sys 1014921993 3549
 sys/src/ape/lib/net/dial.c - 664 sys sys 1014921993 2411
@@ -6265,6 +6323,30 @@ sys/src/ape/lib/regexp/regexec.c - 664 sys sys 1014921993 4339
 sys/src/ape/lib/regexp/regsub.c - 664 sys sys 1014921993 1153
 sys/src/ape/lib/regexp/rregexec.c - 664 sys sys 1014921993 4189
 sys/src/ape/lib/regexp/rregsub.c - 664 sys sys 1014921993 1188
+sys/src/ape/lib/utf - 20000000775 sys sys 1070327378 0
+sys/src/ape/lib/utf/lib9.h - 664 sys sys 1070327090 330
+sys/src/ape/lib/utf/mkfile - 664 sys sys 1070327090 529
+sys/src/ape/lib/utf/rune.c - 664 sys sys 1070327090 3101
+sys/src/ape/lib/utf/runestrcat.c - 664 sys sys 1070327090 919
+sys/src/ape/lib/utf/runestrchr.c - 664 sys sys 1070327090 1002
+sys/src/ape/lib/utf/runestrcmp.c - 664 sys sys 1070327090 1016
+sys/src/ape/lib/utf/runestrcpy.c - 664 sys sys 1070327090 933
+sys/src/ape/lib/utf/runestrdup.c - 664 sys sys 1070327091 995
+sys/src/ape/lib/utf/runestrecpy.c - 664 sys sys 1070327091 997
+sys/src/ape/lib/utf/runestrlen.c - 664 sys sys 1070327091 889
+sys/src/ape/lib/utf/runestrncat.c - 664 sys sys 1070327091 1008
+sys/src/ape/lib/utf/runestrncmp.c - 664 sys sys 1070327091 1045
+sys/src/ape/lib/utf/runestrncpy.c - 664 sys sys 1070327093 1029
+sys/src/ape/lib/utf/runestrrchr.c - 664 sys sys 1070327093 977
+sys/src/ape/lib/utf/runestrstr.c - 664 sys sys 1070327093 1192
+sys/src/ape/lib/utf/runetype.c - 664 sys sys 1070327093 30457
+sys/src/ape/lib/utf/utfdef.h - 664 sys sys 1070327093 335
+sys/src/ape/lib/utf/utfecpy.c - 664 sys sys 1070327093 1268
+sys/src/ape/lib/utf/utflen.c - 664 sys sys 1070327094 1037
+sys/src/ape/lib/utf/utfnlen.c - 664 sys sys 1070327094 1112
+sys/src/ape/lib/utf/utfrrune.c - 664 sys sys 1070327094 1209
+sys/src/ape/lib/utf/utfrune.c - 664 sys sys 1070327094 1196
+sys/src/ape/lib/utf/utfutf.c - 664 sys sys 1070327094 1184
 sys/src/ape/lib/v - 20000000775 sys sys 1014921993 0
 sys/src/ape/lib/v/error.c - 664 sys sys 1014921993 197
 sys/src/ape/lib/v/getfields.c - 664 sys sys 1014921993 3721
@@ -7300,7 +7382,7 @@ sys/src/cmd/disk/kfs/sub.c - 664 sys sys 1022008488 10804
 sys/src/cmd/disk/kfs/uid.c - 664 sys sys 1022008489 6719
 sys/src/cmd/disk/kfscmd.c - 664 sys sys 1015009135 1109
 sys/src/cmd/disk/mbr.c - 664 sys sys 1063855285 4325
-sys/src/cmd/disk/mkext.c - 664 sys sys 1069818199 5500
+sys/src/cmd/disk/mkext.c - 664 sys sys 1070287646 5506
 sys/src/cmd/disk/mkfile - 664 sys sys 1022385851 500
 sys/src/cmd/disk/mkfs.c - 664 sys sys 1032059493 14298
 sys/src/cmd/disk/prep - 20000000775 sys sys 988249968 0
@@ -9262,7 +9344,7 @@ sys/src/cmd/gzip/mkfile - 664 sys sys 984758036 125
 sys/src/cmd/gzip/unzip.c - 664 sys sys 1050689595 13603
 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 1067722871 22715
+sys/src/cmd/hget.c - 664 sys sys 1070286807 22715
 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
@@ -9335,7 +9417,7 @@ sys/src/cmd/ip/httpd/netlib_history.c - 664 sys sys 1015096252 4744
 sys/src/cmd/ip/httpd/redirect.c - 664 sys sys 1042522766 2978
 sys/src/cmd/ip/httpd/save.c - 664 sys sys 1015090172 3175
 sys/src/cmd/ip/httpd/sendfd.c - 664 sys sys 1017679317 12134
-sys/src/cmd/ip/httpd/webls.c - 664 sys sys 1065646625 7233
+sys/src/cmd/ip/httpd/webls.c - 664 sys sys 1070288192 7269
 sys/src/cmd/ip/httpd/webls.denied - 664 sys sys 1064887847 3
 sys/src/cmd/ip/httpd/wikipost.c - 664 sys sys 1019678647 5917
 sys/src/cmd/ip/imap4d - 20000000775 sys sys 988249981 0
@@ -10039,7 +10121,7 @@ sys/src/cmd/ramfs.c - 664 sys sys 1062759940 15377
 sys/src/cmd/ratfs - 20000000775 sys sys 1016943965 0
 sys/src/cmd/ratfs/ctlfiles.c - 664 sys sys 1016943964 6694
 sys/src/cmd/ratfs/main.c - 664 sys sys 1016943964 6516
-sys/src/cmd/ratfs/misc.c - 664 sys sys 1016943965 8560
+sys/src/cmd/ratfs/misc.c - 664 sys sys 1070288056 8563
 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
@@ -10296,7 +10378,7 @@ sys/src/cmd/tapefs/tpfs.c - 664 sys sys 953243008 1966
 sys/src/cmd/tapefs/util.c - 664 sys sys 1014926385 2653
 sys/src/cmd/tapefs/v10fs.c - 664 sys sys 1014926385 3754
 sys/src/cmd/tapefs/v6fs.c - 664 sys sys 1014926385 3971
-sys/src/cmd/tar.c - 664 sys sys 1029161018 12143
+sys/src/cmd/tar.c - 664 sys sys 1070287474 15531
 sys/src/cmd/tbl - 20000000775 sys sys 954038038 0
 sys/src/cmd/tbl/mkfile - 664 sys sys 944961243 268
 sys/src/cmd/tbl/t.h - 664 sys sys 944961244 3987
@@ -10667,7 +10749,7 @@ sys/src/cmd/upas/common/aux.c - 664 sys sys 1019498851 2300
 sys/src/cmd/upas/common/become.c - 664 sys sys 1015009623 430
 sys/src/cmd/upas/common/common.h - 664 sys sys 1015009623 1921
 sys/src/cmd/upas/common/config.c - 664 sys sys 944961316 254
-sys/src/cmd/upas/common/libsys.c - 664 sys sys 1055699577 14010
+sys/src/cmd/upas/common/libsys.c - 664 sys sys 1070287921 14107
 sys/src/cmd/upas/common/mail.c - 664 sys sys 944961315 1346
 sys/src/cmd/upas/common/makefile - 664 sys sys 944961315 366
 sys/src/cmd/upas/common/mkfile - 664 sys sys 1031707285 251

+ 110 - 0
dist/replica/plan9.log

@@ -12817,3 +12817,113 @@
 1070033454 0 c 386/bin/fmt - 775 sys sys 1070032020 63683
 1070033454 1 c sys/man/1/fmt - 664 sys sys 1070032221 1557
 1070033454 2 c sys/src/cmd/fmt.c - 664 sys sys 1070032009 4088
+1070287300 0 c 386/bin/hget - 775 sys sys 1070286807 222506
+1070287300 1 c sys/src/cmd/hget.c - 664 sys sys 1070286807 22715
+1070289103 0 c 386/bin/aux/antiword - 775 sys sys 1070288096 511478
+1070289103 1 c 386/bin/fossil/flchk - 775 sys sys 1070288097 232862
+1070289103 2 c 386/bin/fossil/flfmt - 775 sys sys 1070288098 230827
+1070289103 3 c 386/bin/fossil/fossil - 775 sys sys 1070288099 345606
+1070289103 4 c 386/bin/ip/pptpd - 775 sys sys 1070288105 124153
+1070289103 5 c 386/bin/ip/rarpd - 775 sys sys 1070288105 107748
+1070289103 6 c 386/bin/ndb/dns - 775 sys sys 1070288106 218607
+1070289103 7 c 386/bin/ndb/dnsdebug - 775 sys sys 1070288107 190956
+1070289103 8 c 386/bin/ndb/dnstcp - 775 sys sys 1070288108 189670
+1070289103 9 c 386/lib/libip.a - 664 sys sys 1070288108 34142
+1070289103 10 c rc/bin/yesterday - 775 sys sys 1070288432 2541
+1070289103 11 c sys/man/1/tar - 664 sys sys 1070287474 2363
+1070289103 12 c sys/man/1/yesterday - 664 sys sys 1070288431 2348
+1070289103 13 c sys/src/9/ip/tcp.c - 664 sys sys 1070287819 65399
+1070289103 14 c sys/src/9/port/qio.c - 664 sys sys 1070287837 23562
+1070289103 15 c sys/src/cmd/disk/mkext.c - 664 sys sys 1070287646 5506
+1070289103 16 c sys/src/cmd/ip/httpd/webls.c - 664 sys sys 1070288192 7269
+1070289103 17 c sys/src/cmd/ratfs/misc.c - 664 sys sys 1070288056 8563
+1070289103 18 c sys/src/cmd/upas/common/libsys.c - 664 sys sys 1070287921 14107
+1070289103 19 c sys/src/cmd/tar.c - 664 sys sys 1070287474 15531
+1070327406 0 a sys/include/ape/cursor.h - 664 sys sys 1070327358 118
+1070327406 1 a sys/include/ape/draw.h - 664 sys sys 1070327359 15998
+1070327406 2 c sys/include/ape/errno.h - 664 sys sys 1070327359 1525
+1070327406 3 a sys/include/ape/event.h - 664 sys sys 1070327358 117
+1070327406 4 a sys/include/ape/fmt.h - 664 sys sys 1070327361 3276
+1070327406 5 a sys/include/ape/keyboard.h - 664 sys sys 1070327358 120
+1070327406 6 a sys/include/ape/mouse.h - 664 sys sys 1070327358 117
+1070327406 7 a sys/include/ape/qlock.h - 664 sys sys 1070327358 474
+1070327406 8 a sys/include/ape/utf.h - 664 sys sys 1070327359 1595
+1070327406 9 a sys/src/ape/lib/draw - 20000000775 sys sys 1070327097 0
+1070327406 10 a sys/src/ape/lib/draw/colors.c - 664 sys sys 1070327097 3607
+1070327406 11 a sys/src/ape/lib/draw/libc.h - 664 sys sys 1070327097 3476
+1070327406 12 a sys/src/ape/lib/draw/mkfile - 664 sys sys 1070327097 1176
+1070327406 13 a sys/src/ape/lib/fmt - 20000000775 sys sys 1070327381 0
+1070327406 14 a sys/src/ape/lib/fmt/charstod.c - 664 sys sys 1070327066 1995
+1070327406 15 a sys/src/ape/lib/fmt/dofmt.c - 664 sys sys 1070327066 10020
+1070327406 16 a sys/src/ape/lib/fmt/dorfmt.c - 664 sys sys 1070327066 1576
+1070327406 17 a sys/src/ape/lib/fmt/errfmt.c - 664 sys sys 1070327066 948
+1070327406 18 a sys/src/ape/lib/fmt/fltfmt.c - 664 sys sys 1070327066 10300
+1070327406 19 a sys/src/ape/lib/fmt/fmt.c - 664 sys sys 1070327067 4131
+1070327406 20 a sys/src/ape/lib/fmt/fmtdef.h - 664 sys sys 1070327067 3100
+1070327406 21 a sys/src/ape/lib/fmt/fmtfd.c - 664 sys sys 1070327067 1302
+1070327406 22 a sys/src/ape/lib/fmt/fmtfdflush.c - 664 sys sys 1070327067 1077
+1070327406 23 a sys/src/ape/lib/fmt/fmtlock.c - 664 sys sys 1070327067 868
+1070327406 24 a sys/src/ape/lib/fmt/fmtprint.c - 664 sys sys 1070327068 1257
+1070327406 25 a sys/src/ape/lib/fmt/fmtquote.c - 664 sys sys 1070327068 5582
+1070327406 26 a sys/src/ape/lib/fmt/fmtrune.c - 664 sys sys 1070327068 1120
+1070327406 27 a sys/src/ape/lib/fmt/fmtstr.c - 664 sys sys 1070327068 1509
+1070327406 28 a sys/src/ape/lib/fmt/fmtvprint.c - 664 sys sys 1070327068 1241
+1070327406 29 a sys/src/ape/lib/fmt/fprint.c - 664 sys sys 1070327069 946
+1070327406 30 a sys/src/ape/lib/fmt/mkfile - 664 sys sys 1070327069 794
+1070327406 31 a sys/src/ape/lib/fmt/nan.h - 664 sys sys 1070327069 114
+1070327406 32 a sys/src/ape/lib/fmt/nan64.c - 664 sys sys 1070327069 1176
+1070327406 33 a sys/src/ape/lib/fmt/pow10.c - 664 sys sys 1070327069 1987
+1070327406 34 a sys/src/ape/lib/fmt/print.c - 664 sys sys 1070327069 936
+1070327406 35 a sys/src/ape/lib/fmt/runefmtstr.c - 664 sys sys 1070327070 1544
+1070327406 36 a sys/src/ape/lib/fmt/runeseprint.c - 664 sys sys 1070327070 1016
+1070327406 37 a sys/src/ape/lib/fmt/runesmprint.c - 664 sys sys 1070327070 988
+1070327406 38 a sys/src/ape/lib/fmt/runesnprint.c - 664 sys sys 1070327070 1015
+1070327406 39 a sys/src/ape/lib/fmt/runesprint.c - 664 sys sys 1070327070 1004
+1070327406 40 a sys/src/ape/lib/fmt/runevseprint.c - 664 sys sys 1070327071 1132
+1070327406 41 a sys/src/ape/lib/fmt/runevsmprint.c - 664 sys sys 1070327071 1109
+1070327406 42 a sys/src/ape/lib/fmt/runevsnprint.c - 664 sys sys 1070327071 1142
+1070327406 43 a sys/src/ape/lib/fmt/seprint.c - 664 sys sys 1070327071 951
+1070327406 44 a sys/src/ape/lib/fmt/smprint.c - 664 sys sys 1070327071 923
+1070327406 45 a sys/src/ape/lib/fmt/snprint.c - 664 sys sys 1070327071 950
+1070327406 46 a sys/src/ape/lib/fmt/sprint.c - 664 sys sys 1070327072 991
+1070327406 47 a sys/src/ape/lib/fmt/strtod.c - 664 sys sys 1070327072 9359
+1070327406 48 a sys/src/ape/lib/fmt/strtod.h - 664 sys sys 1070327072 120
+1070327406 49 a sys/src/ape/lib/fmt/test.c - 664 sys sys 1070327072 1423
+1070327406 50 a sys/src/ape/lib/fmt/vfprint.c - 664 sys sys 1070327072 1026
+1070327406 51 a sys/src/ape/lib/fmt/vseprint.c - 664 sys sys 1070327072 1089
+1070327406 52 a sys/src/ape/lib/fmt/vsmprint.c - 664 sys sys 1070327073 1084
+1070327406 53 a sys/src/ape/lib/fmt/vsnprint.c - 664 sys sys 1070327073 1119
+1070327406 54 a sys/src/ape/lib/fmt/werrstr.c - 664 sys sys 1070327073 235
+1070327406 55 a sys/src/ape/lib/utf - 20000000775 sys sys 1070327378 0
+1070327406 56 a sys/src/ape/lib/utf/lib9.h - 664 sys sys 1070327090 330
+1070327406 57 a sys/src/ape/lib/utf/mkfile - 664 sys sys 1070327090 529
+1070327406 58 a sys/src/ape/lib/utf/rune.c - 664 sys sys 1070327090 3101
+1070327406 59 a sys/src/ape/lib/utf/runestrcat.c - 664 sys sys 1070327090 919
+1070327406 60 a sys/src/ape/lib/utf/runestrchr.c - 664 sys sys 1070327090 1002
+1070327406 61 a sys/src/ape/lib/utf/runestrcmp.c - 664 sys sys 1070327090 1016
+1070327406 62 a sys/src/ape/lib/utf/runestrcpy.c - 664 sys sys 1070327090 933
+1070327406 63 a sys/src/ape/lib/utf/runestrdup.c - 664 sys sys 1070327091 995
+1070327406 64 a sys/src/ape/lib/utf/runestrecpy.c - 664 sys sys 1070327091 997
+1070327406 65 a sys/src/ape/lib/utf/runestrlen.c - 664 sys sys 1070327091 889
+1070327406 66 a sys/src/ape/lib/utf/runestrncat.c - 664 sys sys 1070327091 1008
+1070327406 67 a sys/src/ape/lib/utf/runestrncmp.c - 664 sys sys 1070327091 1045
+1070327406 68 a sys/src/ape/lib/utf/runestrncpy.c - 664 sys sys 1070327093 1029
+1070327406 69 a sys/src/ape/lib/utf/runestrrchr.c - 664 sys sys 1070327093 977
+1070327406 70 a sys/src/ape/lib/utf/runestrstr.c - 664 sys sys 1070327093 1192
+1070327406 71 a sys/src/ape/lib/utf/runetype.c - 664 sys sys 1070327093 30457
+1070327406 72 a sys/src/ape/lib/utf/utfdef.h - 664 sys sys 1070327093 335
+1070327406 73 a sys/src/ape/lib/utf/utfecpy.c - 664 sys sys 1070327093 1268
+1070327406 74 a sys/src/ape/lib/utf/utflen.c - 664 sys sys 1070327094 1037
+1070327406 75 a sys/src/ape/lib/utf/utfnlen.c - 664 sys sys 1070327094 1112
+1070327406 76 a sys/src/ape/lib/utf/utfrrune.c - 664 sys sys 1070327094 1209
+1070327406 77 a sys/src/ape/lib/utf/utfrune.c - 664 sys sys 1070327094 1196
+1070327406 78 a sys/src/ape/lib/utf/utfutf.c - 664 sys sys 1070327094 1184
+1070328706 0 c sys/lib/plumb/basic - 664 sys sys 1070327744 2922
+1070330908 0 c sys/lib/plumb/basic - 664 sys sys 1070330856 2930
+1070330908 1 a sys/src/ape/lib/ap/plan9/9errstr.c - 664 sys sys 1070330880 31
+1070330908 2 a sys/src/ape/lib/ap/plan9/9mallocz.c - 664 sys sys 1070330880 148
+1070330908 3 a sys/src/ape/lib/ap/plan9/9readn.c - 664 sys sys 1070330880 221
+1070330908 4 c sys/src/ape/lib/ap/plan9/mkfile - 664 sys sys 1070330880 1357
+1070330908 5 a sys/src/ape/lib/ap/plan9/qlock.c - 664 sys sys 1070330880 5124
+1070330908 6 c sys/src/ape/lib/fmt/werrstr.c - 664 sys sys 1070330902 241
+1070330908 7 c sys/src/ape/lib/mkfile - 664 sys sys 1070330862 203

+ 13 - 4
rc/bin/yesterday

@@ -56,6 +56,7 @@ fn Xbind {
 year=`{date|sed 's/.* //'}
 copy=Xecho
 last=()
+defdump=dump
 while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
 	switch($1){
 	case -a
@@ -76,6 +77,9 @@ while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
 	case -C
 		copy=Xcarefulcp
 		shift
+	case -s
+		defdump=snap
+		shift
 # The slashnhack is always right.
 #	case -N
 #		slashnhack=no
@@ -127,23 +131,28 @@ if(! ~ $status ''){
 
 for(i){
 	xpath=`{cleanname -d $dir -- $i}
-	xdump=dump
+	xdump=$defdump
 	dumppath=$xpath
 	if(~ $slashnhack yes && ~ $xpath /n/*/*){
-		xdump=`{echo $xpath | sed 's:/n/([^/]+)/.*:\1dump:'}
+		xdump=`{echo $xpath | sed 's:/n/([^/]+)/.*:\1'$defdump':'}
 		dumppath=`{echo $xpath | sed 's:/n/[^/]+(/.*):\1:'}
 	}
 	if(! test -e /n/$xdump/$year)
 		9fs $xdump
 
-	if(~ $#last 0)
+	if(~ $#last 0){
 		xlast=`{ls -t /n/$xdump/$year|sed 1q}
+		switch($defdump){
+		case snap
+			xlast=`{ls -t $xlast|sed 1q}
+		}
+	}
 	if not
 		xlast=/n/$xdump/$last
 
 	if(! test -e $xlast){
 		echo 'yesterday:' \
-			`{echo $xlast|sed 's/.n.dump.(....).(..)(..)/\1 \2 \3/'} \
+			`{echo $xlast|sed 's/.n.'$defdump'.(....).(..)(..)/\1 \2 \3/'} \
 			'is not a backup day for' $xdump >[1=2]
 		exit 'bad date'
 	}

+ 6 - 0
sys/include/ape/cursor.h

@@ -0,0 +1,6 @@
+#ifndef _RESEARCH_SOURCE
+  This header file is not defined in ANSI or POSIX
+#endif
+
+#include "/sys/include/cursor.h"
+

+ 521 - 0
sys/include/ape/draw.h

@@ -0,0 +1,521 @@
+#ifndef _RESEARCH_SOURCE
+  This header file is not defined in ANSI or POSIX
+#endif
+
+#pragma src "/sys/src/ape/lib/draw"
+#pragma lib "/$M/lib/ape/libdraw.a"
+
+typedef struct	Cachefont Cachefont;
+typedef struct	Cacheinfo Cacheinfo;
+typedef struct	Cachesubf Cachesubf;
+typedef struct	Display Display;
+typedef struct	Font Font;
+typedef struct	Fontchar Fontchar;
+typedef struct	Image Image;
+typedef struct	Mouse Mouse;
+typedef struct	Point Point;
+typedef struct	Rectangle Rectangle;
+typedef struct	RGB RGB;
+typedef struct	Screen Screen;
+typedef struct	Subfont Subfont;
+
+#pragma varargck	type	"R"	Rectangle
+#pragma varargck	type	"P"	Point
+extern	int	Rfmt(Fmt*);
+extern	int	Pfmt(Fmt*);
+
+enum
+{
+	DOpaque		= 0xFFFFFFFF,
+	DTransparent	= 0x00000000,		/* only useful for allocimage, memfillcolor */
+	DBlack		= 0x000000FF,
+	DWhite		= 0xFFFFFFFF,
+	DRed		= 0xFF0000FF,
+	DGreen		= 0x00FF00FF,
+	DBlue		= 0x0000FFFF,
+	DCyan		= 0x00FFFFFF,
+	DMagenta		= 0xFF00FFFF,
+	DYellow		= 0xFFFF00FF,
+	DPaleyellow	= 0xFFFFAAFF,
+	DDarkyellow	= 0xEEEE9EFF,
+	DDarkgreen	= 0x448844FF,
+	DPalegreen	= 0xAAFFAAFF,
+	DMedgreen	= 0x88CC88FF,
+	DDarkblue	= 0x000055FF,
+	DPalebluegreen= 0xAAFFFFFF,
+	DPaleblue		= 0x0000BBFF,
+	DBluegreen	= 0x008888FF,
+	DGreygreen	= 0x55AAAAFF,
+	DPalegreygreen	= 0x9EEEEEFF,
+	DYellowgreen	= 0x99994CFF,
+	DMedblue		= 0x000099FF,
+	DGreyblue	= 0x005DBBFF,
+	DPalegreyblue	= 0x4993DDFF,
+	DPurpleblue	= 0x8888CCFF,
+
+	DNotacolor	= 0xFFFFFF00,
+	DNofill		= DNotacolor,
+	
+};
+
+enum
+{
+	Displaybufsize	= 8000,
+	ICOSSCALE	= 1024,
+	Borderwidth =	4,
+};
+
+enum
+{
+	/* refresh methods */
+	Refbackup	= 0,
+	Refnone		= 1,
+	Refmesg		= 2
+};
+#define	NOREFRESH	((void*)-1)
+
+enum
+{
+	/* line ends */
+	Endsquare	= 0,
+	Enddisc		= 1,
+	Endarrow	= 2,
+	Endmask		= 0x1F
+};
+
+#define	ARROW(a, b, c)	(Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
+
+typedef enum
+{
+	/* Porter-Duff compositing operators */
+	Clear	= 0,
+
+	SinD	= 8,
+	DinS	= 4,
+	SoutD	= 2,
+	DoutS	= 1,
+
+	S		= SinD|SoutD,
+	SoverD	= SinD|SoutD|DoutS,
+	SatopD	= SinD|DoutS,
+	SxorD	= SoutD|DoutS,
+
+	D		= DinS|DoutS,
+	DoverS	= DinS|DoutS|SoutD,
+	DatopS	= DinS|SoutD,
+	DxorS	= DoutS|SoutD,	/* == SxorD */
+
+	Ncomp = 12,
+} Drawop;
+
+/*
+ * image channel descriptors 
+ */
+enum {
+	CRed = 0,
+	CGreen,
+	CBlue,
+	CGrey,
+	CAlpha,
+	CMap,
+	CIgnore,
+	NChan,
+};
+
+#define __DC(type, nbits)	((((type)&15)<<4)|((nbits)&15))
+#define CHAN1(a,b)	__DC(a,b)
+#define CHAN2(a,b,c,d)	(CHAN1((a),(b))<<8|__DC((c),(d)))
+#define CHAN3(a,b,c,d,e,f)	(CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
+#define CHAN4(a,b,c,d,e,f,g,h)	(CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
+
+#define NBITS(c) ((c)&15)
+#define TYPE(c) (((c)>>4)&15)
+
+enum {
+	GREY1	= CHAN1(CGrey, 1),
+	GREY2	= CHAN1(CGrey, 2),
+	GREY4	= CHAN1(CGrey, 4),
+	GREY8	= CHAN1(CGrey, 8),
+	CMAP8	= CHAN1(CMap, 8),
+	RGB15	= CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
+	RGB16	= CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
+	RGB24	= CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
+	RGBA32	= CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
+	ARGB32	= CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8),	/* stupid VGAs */
+	XRGB32  = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
+};
+
+extern	char*	chantostr(char*, ulong);
+extern	ulong	strtochan(char*);
+extern	int		chantodepth(ulong);
+
+struct	Point
+{
+	int	x;
+	int	y;
+};
+
+struct Rectangle
+{
+	Point	min;
+	Point	max;
+};
+
+typedef void	(*Reffn)(Image*, Rectangle, void*);
+
+struct Screen
+{
+	Display	*display;	/* display holding data */
+	int	id;		/* id of system-held Screen */
+	Image	*image;		/* unused; for reference only */
+	Image	*fill;		/* color to paint behind windows */
+};
+
+struct Display
+{
+	QLock	qlock;
+	int		locking;	/*program is using lockdisplay */
+	int		dirno;
+	int		fd;
+	int		reffd;
+	int		ctlfd;
+	int		imageid;
+	int		local;
+	void		(*error)(Display*, char*);
+	char		*devdir;
+	char		*windir;
+	char		oldlabel[64];
+	ulong		dataqid;
+	Image		*white;
+	Image		*black;
+	Image		*opaque;
+	Image		*transparent;
+	Image		*image;
+	uchar		*buf;
+	int			bufsize;
+	uchar		*bufp;
+	Font		*defaultfont;
+	Subfont		*defaultsubfont;
+	Image		*windows;
+	Image		*screenimage;
+	int			_isnewdisplay;
+};
+
+struct Image
+{
+	Display		*display;	/* display holding data */
+	int		id;		/* id of system-held Image */
+	Rectangle	r;		/* rectangle in data area, local coords */
+	Rectangle 	clipr;		/* clipping region */
+	int		depth;		/* number of bits per pixel */
+	ulong	chan;
+	int		repl;		/* flag: data replicates to tile clipr */
+	Screen		*screen;	/* 0 if not a window */
+	Image		*next;	/* next in list of windows */
+};
+
+struct RGB
+{
+	ulong	red;
+	ulong	green;
+	ulong	blue;
+};
+
+/*
+ * Subfonts
+ *
+ * given char c, Subfont *f, Fontchar *i, and Point p, one says
+ *	i = f->info+c;
+ *	draw(b, Rect(p.x+i->left, p.y+i->top,
+ *		p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
+ *		color, f->bits, Pt(i->x, i->top));
+ *	p.x += i->width;
+ * to draw characters in the specified color (itself an Image) in Image b.
+ */
+
+struct	Fontchar
+{
+	int		x;		/* left edge of bits */
+	uchar		top;		/* first non-zero scan-line */
+	uchar		bottom;		/* last non-zero scan-line + 1 */
+	char		left;		/* offset of baseline */
+	uchar		width;		/* width of baseline */
+};
+
+struct	Subfont
+{
+	char		*name;
+	short		n;		/* number of chars in font */
+	uchar		height;		/* height of image */
+	char		ascent;		/* top of image to baseline */
+	Fontchar 	*info;		/* n+1 character descriptors */
+	Image		*bits;		/* of font */
+	int		ref;
+};
+
+enum
+{
+	/* starting values */
+	LOG2NFCACHE =	6,
+	NFCACHE =	(1<<LOG2NFCACHE),	/* #chars cached */
+	NFLOOK =	5,			/* #chars to scan in cache */
+	NFSUBF =	2,			/* #subfonts to cache */
+	/* max value */
+	MAXFCACHE =	1024+NFLOOK,		/* upper limit */
+	MAXSUBF =	50,			/* generous upper limit */
+	/* deltas */
+	DSUBF = 	4,
+	/* expiry ages */
+	SUBFAGE	=	10000,
+	CACHEAGE =	10000
+};
+
+struct Cachefont
+{
+	Rune		min;	/* lowest rune value to be taken from subfont */
+	Rune		max;	/* highest rune value+1 to be taken from subfont */
+	int		offset;	/* position in subfont of character at min */
+	char		*name;			/* stored in font */
+	char		*subfontname;		/* to access subfont */
+};
+
+struct Cacheinfo
+{
+	ushort		x;		/* left edge of bits */
+	uchar		width;		/* width of baseline */
+	schar		left;		/* offset of baseline */
+	Rune		value;	/* value of character at this slot in cache */
+	ushort		age;
+};
+
+struct Cachesubf
+{
+	ulong		age;	/* for replacement */
+	Cachefont	*cf;	/* font info that owns us */
+	Subfont		*f;	/* attached subfont */
+};
+
+struct Font
+{
+	char		*name;
+	Display		*display;
+	short		height;	/* max height of image, interline spacing */
+	short		ascent;	/* top of image to baseline */
+	short		width;	/* widest so far; used in caching only */	
+	short		nsub;	/* number of subfonts */
+	ulong		age;	/* increasing counter; used for LRU */
+	int		maxdepth;	/* maximum depth of all loaded subfonts */
+	int		ncache;	/* size of cache */
+	int		nsubf;	/* size of subfont list */
+	Cacheinfo	*cache;
+	Cachesubf	*subf;
+	Cachefont	**sub;	/* as read from file */
+	Image		*cacheimage;
+};
+
+#define	Dx(r)	((r).max.x-(r).min.x)
+#define	Dy(r)	((r).max.y-(r).min.y)
+
+/*
+ * Image management
+ */
+extern Image*	_allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
+extern Image*	allocimage(Display*, Rectangle, ulong, int, ulong);
+extern uchar*	bufimage(Display*, int);
+extern int	bytesperline(Rectangle, int);
+extern void	closedisplay(Display*);
+extern void	drawerror(Display*, char*);
+extern int	flushimage(Display*, int);
+extern int	freeimage(Image*);
+extern int	_freeimage1(Image*);
+extern int	geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
+extern int	initdraw(void(*)(Display*, char*), char*, char*);
+extern int	newwindow(char*);
+extern Display*	initdisplay(char*, char*, void(*)(Display*, char*));
+extern int	loadimage(Image*, Rectangle, uchar*, int);
+extern int	cloadimage(Image*, Rectangle, uchar*, int);
+extern int	getwindow(Display*, int);
+extern int	gengetwindow(Display*, char*, Image**, Screen**, int);
+extern Image* readimage(Display*, int, int);
+extern Image* creadimage(Display*, int, int);
+extern int	unloadimage(Image*, Rectangle, uchar*, int);
+extern int	wordsperline(Rectangle, int);
+extern int	writeimage(int, Image*, int);
+extern Image*	namedimage(Display*, char*);
+extern int	nameimage(Image*, char*, int);
+extern Image* allocimagemix(Display*, ulong, ulong);
+
+/*
+ * Colors
+ */
+extern	void	readcolmap(Display*, RGB*);
+extern	void	writecolmap(Display*, RGB*);
+extern	ulong	setalpha(ulong, uchar);
+
+/*
+ * Windows
+ */
+extern Screen*	allocscreen(Image*, Image*, int);
+extern Image*	_allocwindow(Image*, Screen*, Rectangle, int, ulong);
+extern Image*	allocwindow(Screen*, Rectangle, int, ulong);
+extern void	bottomnwindows(Image**, int);
+extern void	bottomwindow(Image*);
+extern int	freescreen(Screen*);
+extern Screen*	publicscreen(Display*, int, ulong);
+extern void	topnwindows(Image**, int);
+extern void	topwindow(Image*);
+extern int	originwindow(Image*, Point, Point);
+
+/*
+ * Geometry
+ */
+extern Point		Pt(int, int);
+extern Rectangle	Rect(int, int, int, int);
+extern Rectangle	Rpt(Point, Point);
+extern Point		addpt(Point, Point);
+extern Point		subpt(Point, Point);
+extern Point		divpt(Point, int);
+extern Point		mulpt(Point, int);
+extern int		eqpt(Point, Point);
+extern int		eqrect(Rectangle, Rectangle);
+extern Rectangle	insetrect(Rectangle, int);
+extern Rectangle	rectaddpt(Rectangle, Point);
+extern Rectangle	rectsubpt(Rectangle, Point);
+extern Rectangle	canonrect(Rectangle);
+extern int		rectXrect(Rectangle, Rectangle);
+extern int		rectinrect(Rectangle, Rectangle);
+extern void		combinerect(Rectangle*, Rectangle);
+extern int		rectclip(Rectangle*, Rectangle);
+extern int		ptinrect(Point, Rectangle);
+extern void		replclipr(Image*, int, Rectangle);
+extern int		drawreplxy(int, int, int);	/* used to be drawsetxy */
+extern Point	drawrepl(Rectangle, Point);
+extern int		rgb2cmap(int, int, int);
+extern int		cmap2rgb(int);
+extern int		cmap2rgba(int);
+extern void		icossin(int, int*, int*);
+extern void		icossin2(int, int, int*, int*);
+
+/*
+ * Graphics
+ */
+extern void	draw(Image*, Rectangle, Image*, Image*, Point);
+extern void	drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
+extern void	gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
+extern void	gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
+extern void	line(Image*, Point, Point, int, int, int, Image*, Point);
+extern void	lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
+extern void	poly(Image*, Point*, int, int, int, int, Image*, Point);
+extern void	polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
+extern void	fillpoly(Image*, Point*, int, int, Image*, Point);
+extern void	fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
+extern Point	string(Image*, Point, Image*, Point, Font*, char*);
+extern Point	stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
+extern Point	stringn(Image*, Point, Image*, Point, Font*, char*, int);
+extern Point	stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
+extern Point	runestring(Image*, Point, Image*, Point, Font*, Rune*);
+extern Point	runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
+extern Point	runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
+extern Point	runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
+extern Point	stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
+extern Point	stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
+extern Point	stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
+extern Point	stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
+extern Point	runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
+extern Point	runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
+extern Point	runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
+extern Point	runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
+extern Point	_string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
+extern Point	stringsubfont(Image*, Point, Image*, Subfont*, char*);
+extern int		bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
+extern int		bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
+extern int		bezspline(Image*, Point*, int, int, int, int, Image*, Point);
+extern int		bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
+extern int		bezsplinepts(Point*, int, Point**);
+extern int		fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
+extern int		fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
+extern int		fillbezspline(Image*, Point*, int, int, Image*, Point);
+extern int		fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
+extern void	ellipse(Image*, Point, int, int, int, Image*, Point);
+extern void	ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
+extern void	fillellipse(Image*, Point, int, int, Image*, Point);
+extern void	fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
+extern void	arc(Image*, Point, int, int, int, Image*, Point, int, int);
+extern void	arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
+extern void	fillarc(Image*, Point, int, int, Image*, Point, int, int);
+extern void	fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
+extern void	border(Image*, Rectangle, int, Image*, Point);
+extern void	borderop(Image*, Rectangle, int, Image*, Point, Drawop);
+
+/*
+ * Font management
+ */
+extern Font*	openfont(Display*, char*);
+extern Font*	buildfont(Display*, char*, char*);
+extern void	freefont(Font*);
+extern Font*	mkfont(Subfont*, Rune);
+extern int	cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
+extern void	agefont(Font*);
+extern Subfont*	allocsubfont(char*, int, int, int, Fontchar*, Image*);
+extern Subfont*	lookupsubfont(Display*, char*);
+extern void	installsubfont(char*, Subfont*);
+extern void	uninstallsubfont(Subfont*);
+extern void	freesubfont(Subfont*);
+extern Subfont*	readsubfont(Display*, char*, int, int);
+extern Subfont*	readsubfonti(Display*, char*, int, Image*, int);
+extern int	writesubfont(int, Subfont*);
+extern void	_unpackinfo(Fontchar*, uchar*, int);
+extern Point	stringsize(Font*, char*);
+extern int	stringwidth(Font*, char*);
+extern int	stringnwidth(Font*, char*, int);
+extern Point	runestringsize(Font*, Rune*);
+extern int	runestringwidth(Font*, Rune*);
+extern int	runestringnwidth(Font*, Rune*, int);
+extern Point	strsubfontwidth(Subfont*, char*);
+extern int	loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
+extern char*	subfontname(char*, char*, int);
+extern Subfont*	_getsubfont(Display*, char*);
+extern Subfont*	getdefont(Display*);
+extern void		lockdisplay(Display*);
+extern void	unlockdisplay(Display*);
+extern int		drawlsetrefresh(ulong, int, void*, void*);
+
+/*
+ * Predefined 
+ */
+extern	uchar	defontdata[];
+extern	int		sizeofdefont;
+extern	Point		ZP;
+extern	Rectangle	ZR;
+
+/*
+ * Set up by initdraw()
+ */
+extern	Display	*display;
+extern	Font		*font;
+extern	Image	*screen;
+extern	Screen	*_screen;
+extern	int	_cursorfd;
+extern	int	_drawdebug;	/* set to 1 to see errors from flushimage */
+extern	void	_setdrawop(Display*, Drawop);
+
+#define	BGSHORT(p)		(((p)[0]<<0) | ((p)[1]<<8))
+#define	BGLONG(p)		((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
+#define	BPSHORT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
+#define	BPLONG(p, v)		(BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
+
+/*
+ * Compressed image file parameters and helper routines
+ */
+#define	NMATCH	3		/* shortest match possible */
+#define	NRUN	(NMATCH+31)	/* longest match possible */
+#define	NMEM	1024		/* window size */
+#define	NDUMP	128		/* maximum length of dump */
+#define	NCBLOCK	6000		/* size of compressed blocks */
+extern	void	_twiddlecompressed(uchar*, int);
+extern	int	_compblocksize(Rectangle, int);
+
+/* XXX backwards helps; should go */
+extern	int		log2[];
+extern	ulong	drawld2chan[];
+extern	void		drawsetdebug(int);

+ 1 - 0
sys/include/ape/errno.h

@@ -6,6 +6,7 @@ extern int errno;
 
 #define EDOM	1000
 #define ERANGE	1001
+#define EPLAN9	1002
 
 #ifdef _POSIX_SOURCE
 

+ 6 - 0
sys/include/ape/event.h

@@ -0,0 +1,6 @@
+#ifndef _RESEARCH_SOURCE
+  This header file is not defined in ANSI or POSIX
+#endif
+
+#include "/sys/include/event.h"
+

+ 107 - 0
sys/include/ape/fmt.h

@@ -0,0 +1,107 @@
+#ifndef _FMT_H_
+#define _FMT_H_ 1
+#pragma lib "/$M/lib/ape/libfmt.a"
+#pragma src "/sys/src/ape/lib/fmt"
+
+#if defined(__cplusplus)
+extern "C" { 
+#endif
+
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ *              Copyright (c) 2002 by Lucent Technologies.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+
+#include <stdarg.h>
+#include <utf.h>
+
+typedef struct Fmt	Fmt;
+struct Fmt{
+	unsigned char	runes;		/* output buffer is runes or chars? */
+	void	*start;			/* of buffer */
+	void	*to;			/* current place in the buffer */
+	void	*stop;			/* end of the buffer; overwritten if flush fails */
+	int	(*flush)(Fmt *);	/* called when to == stop */
+	void	*farg;			/* to make flush a closure */
+	int	nfmt;			/* num chars formatted so far */
+	va_list	args;			/* args passed to dofmt */
+	int	r;			/* % format Rune */
+	int	width;
+	int	prec;
+	unsigned long	flags;
+};
+
+enum{
+	FmtWidth	= 1,
+	FmtLeft		= FmtWidth << 1,
+	FmtPrec		= FmtLeft << 1,
+	FmtSharp	= FmtPrec << 1,
+	FmtSpace	= FmtSharp << 1,
+	FmtSign		= FmtSpace << 1,
+	FmtZero		= FmtSign << 1,
+	FmtUnsigned	= FmtZero << 1,
+	FmtShort	= FmtUnsigned << 1,
+	FmtLong		= FmtShort << 1,
+	FmtVLong	= FmtLong << 1,
+	FmtComma	= FmtVLong << 1,
+	FmtByte		= FmtComma << 1,
+	FmtLDouble	= FmtByte << 1,
+
+	FmtFlag		= FmtLDouble << 1
+};
+
+extern	int	print(char*, ...);
+extern	char*	seprint(char*, char*, char*, ...);
+extern	char*	vseprint(char*, char*, char*, va_list);
+extern	int	snprint(char*, int, char*, ...);
+extern	int	vsnprint(char*, int, char*, va_list);
+extern	char*	smprint(char*, ...);
+extern	char*	vsmprint(char*, va_list);
+extern	int	sprint(char*, char*, ...);
+extern	int	fprint(int, char*, ...);
+extern	int	vfprint(int, char*, va_list);
+
+extern	int	runesprint(Rune*, char*, ...);
+extern	int	runesnprint(Rune*, int, char*, ...);
+extern	int	runevsnprint(Rune*, int, char*, va_list);
+extern	Rune*	runeseprint(Rune*, Rune*, char*, ...);
+extern	Rune*	runevseprint(Rune*, Rune*, char*, va_list);
+extern	Rune*	runesmprint(char*, ...);
+extern	Rune*	runevsmprint(char*, va_list);
+
+extern	int	fmtfdinit(Fmt*, int, char*, int);
+extern	int	fmtfdflush(Fmt*);
+extern	int	fmtstrinit(Fmt*);
+extern	char*	fmtstrflush(Fmt*);
+extern	int	runefmtstrinit(Fmt*);
+
+extern	int	quotestrfmt(Fmt *f);
+extern	void	quotefmtinstall(void);
+extern	int	(*fmtdoquote)(int);
+
+
+extern	int	fmtinstall(int, int (*)(Fmt*));
+extern	int	dofmt(Fmt*, char*);
+extern	int	fmtprint(Fmt*, char*, ...);
+extern	int	fmtvprint(Fmt*, char*, va_list);
+extern	int	fmtrune(Fmt*, int);
+extern	int	fmtstrcpy(Fmt*, char*);
+
+extern	double	fmtstrtod(const char *, char **);
+extern	double	fmtcharstod(int(*)(void*), void*);
+
+extern	int	werrstr(const char*, ...);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif

+ 6 - 0
sys/include/ape/keyboard.h

@@ -0,0 +1,6 @@
+#ifndef _RESEARCH_SOURCE
+  This header file is not defined in ANSI or POSIX
+#endif
+
+#include "/sys/include/keyboard.h"
+

+ 6 - 0
sys/include/ape/mouse.h

@@ -0,0 +1,6 @@
+#ifndef _RESEARCH_SOURCE
+  This header file is not defined in ANSI or POSIX
+#endif
+
+#include "/sys/include/mouse.h"
+

+ 36 - 0
sys/include/ape/qlock.h

@@ -0,0 +1,36 @@
+#ifndef __QLOCK_H_
+#define __QLOCK_H
+#ifndef _QLOCK_EXTENSION
+  This header file is an extension to ANSI/POSIX
+#endif
+#pragma lib "/$M/lib/ape/lib9.a"
+
+typedef struct QLp QLp;
+struct QLp
+{
+	int	inuse;
+	QLp	*next;
+	char	state;
+};
+
+typedef
+struct QLock
+{
+	Lock	lock;
+	int	locked;
+	QLp	*head;
+	QLp 	*tail;
+} QLock;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern	void	qlock(QLock*);
+extern	void	qunlock(QLock*);
+extern	int	canqlock(QLock*);
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 60 - 0
sys/include/ape/utf.h

@@ -0,0 +1,60 @@
+#ifndef _UTF_H_
+#define _UTF_H_ 1
+#pragma lib "/$M/lib/ape/libutf.a"
+#pragma src "/sys/src/ape/lib/utf"
+
+#if defined(__cplusplus)
+extern "C" { 
+#endif
+
+typedef unsigned short Rune;	/* 16 bits */
+
+enum
+{
+	UTFmax		= 3,		/* maximum bytes per rune */
+	Runesync	= 0x80,		/* cannot represent part of a UTF sequence (<) */
+	Runeself	= 0x80,		/* rune and UTF sequences are the same (<) */
+	Runeerror	= 0x80,		/* decoding error in UTF */
+};
+
+/*
+ * rune routines
+ */
+extern	int	runetochar(char*, Rune*);
+extern	int	chartorune(Rune*, char*);
+extern	int	runelen(long);
+extern	int	runenlen(Rune*, int);
+extern	int	fullrune(char*, int);
+extern	int	utflen(char*);
+extern	int	utfnlen(char*, long);
+extern	char*	utfrune(char*, long);
+extern	char*	utfrrune(char*, long);
+extern	char*	utfutf(char*, char*);
+extern	char*	utfecpy(char*, char*, char*);
+
+extern	Rune*	runestrcat(Rune*, Rune*);
+extern	Rune*	runestrchr(Rune*, Rune);
+extern	int	runestrcmp(Rune*, Rune*);
+extern	Rune*	runestrcpy(Rune*, Rune*);
+extern	Rune*	runestrncpy(Rune*, Rune*, long);
+extern	Rune*	runestrecpy(Rune*, Rune*, Rune*);
+extern	Rune*	runestrdup(Rune*);
+extern	Rune*	runestrncat(Rune*, Rune*, long);
+extern	int	runestrncmp(Rune*, Rune*, long);
+extern	Rune*	runestrrchr(Rune*, Rune);
+extern	long	runestrlen(Rune*);
+extern	Rune*	runestrstr(Rune*, Rune*);
+
+extern	Rune	tolowerrune(Rune);
+extern	Rune	totitlerune(Rune);
+extern	Rune	toupperrune(Rune);
+extern	int	isalpharune(Rune);
+extern	int	islowerrune(Rune);
+extern	int	isspacerune(Rune);
+extern	int	istitlerune(Rune);
+extern	int	isupperrune(Rune);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif

+ 2 - 2
sys/lib/plumb/basic

@@ -9,7 +9,7 @@ plumb to showmail
 
 # cheap http/gif,jpeg,ps,pdf renderer
 type is text
-data matches '(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais|prospero)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*\.(jpe?g|JPE?G|gif|GIF|ps|PS|pdf|PDF)'
+data matches '(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais|prospero)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*\.(jpe?g|JPE?G|gif|GIF|ps|PS|pdf|PDF|png|PNG)'
 plumb start rc -c 'hget '$0' | page -w'
 
 # rtf files go to wdoc2txt
@@ -35,7 +35,7 @@ plumb start window rc -c '''echo % mail '''$0'; mail '$0
 # image files go to page
 type is text
 data matches '[a-zA-Z¡-￿0-9_\-./]+'
-data matches '([a-zA-Z¡-￿0-9_\-./]+)\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|bit)'
+data matches '([a-zA-Z¡-￿0-9_\-./]+)\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|PPM|bit|BIT|png|PNG)'
 arg isfile	$0
 plumb to image
 plumb client page -wi

+ 3 - 0
sys/man/1/tar

@@ -77,6 +77,9 @@ a non-Plan 9 system.
 Use the next (numeric) argument as the group id for files in
 the output archive.
 .TP
+.BR p
+Create files in POSIX ustar format.
+.TP
 .B R
 When extracting, ignore leading slash on file names,
 i.e., extract all files relative to the current directory.

+ 7 - 1
sys/man/1/yesterday

@@ -4,7 +4,7 @@ yesterday \- print file names from the dump
 .SH SYNOPSIS
 .B yesterday
 [
-.B -abcCdD
+.B -abcCdDs
 ] [
 .B -n
 .I daysago
@@ -90,6 +90,12 @@ option selects the dump
 .I daysago
 prior to the current day.
 .PP
+The
+.B -s
+option selects the most recent snapshot instead of the most
+recent archived dump.  Snapshots may occur more frequently
+than dumps.
+.PP
 .I Yesterday
 does not guarantee that the string it prints represents an existing file.
 .SH EXAMPLES

+ 16 - 8
sys/src/9/ip/tcp.c

@@ -447,10 +447,11 @@ tcpstate(Conv *c, char *state, int n)
 	s = (Tcpctl*)(c->ptcl);
 
 	return snprint(state, n,
-		"%s srtt %d mdev %d cwin %lud swin %lud>>%d rwin %lud>>%d timer.start %d timer.count %d rerecv %d\n",
+		"%s srtt %d mdev %d cwin %lud swin %lud>>%d rwin %lud>>%d timer.start %d timer.count %d rerecv %d katimer.start %d katimer.count %d\n",
 		tcpstates[s->state], s->srtt, s->mdev,
 		s->cwind, s->snd.wnd, s->rcv.scale, s->rcv.wnd, s->snd.scale,
-		s->timer.start, s->timer.count, s->rerecv);
+		s->timer.start, s->timer.count, s->rerecv,
+		s->katimer.start, s->katimer.count);
 }
 
 static int
@@ -2065,8 +2066,8 @@ reset:
 	/* fix up window */
 	seg.wnd <<= tcb->rcv.scale;
 
-	if(tcb->kacounter > 0)
-		tcpsetkacounter(tcb);
+	/* every input packet in puts off the keep alive time out */
+	tcpsetkacounter(tcb);
 
 	switch(tcb->state) {
 	case Closed:
@@ -2576,8 +2577,9 @@ tcpoutput(Conv *s)
 		}
 
 		tpriv->stats[OutSegs]++;
-		if(tcb->kacounter > 0)
-			tcpgo(tpriv, &tcb->katimer);
+
+		/* put off the next keep alive */
+		tcpgo(tpriv, &tcb->katimer);
 
 		switch(version){
 		case V4:
@@ -2659,8 +2661,7 @@ tcpsendka(Conv *s)
 }
 
 /*
- *  if we've timed out, close the connection
- *  otherwise, send a keepalive and restart the timer
+ *  set connection to time out after 12 minutes
  */
 void
 tcpsetkacounter(Tcpctl *tcb)
@@ -2669,6 +2670,11 @@ tcpsetkacounter(Tcpctl *tcb)
 	if(tcb->kacounter < 3)
 		tcb->kacounter = 3;
 }
+
+/*
+ *  if we've timed out, close the connection
+ *  otherwise, send a keepalive and restart the timer
+ */
 void
 tcpkeepalive(void *v)
 {
@@ -2704,6 +2710,8 @@ tcpstartka(Conv *s, char **f, int n)
 	int x;
 
 	tcb = (Tcpctl*)s->ptcl;
+	if(tcb->state != Established)
+		return "connection must be in Establised state";
 	if(n > 1){
 		x = atoi(f[1]);
 		if(x >= MSPTICK)

+ 7 - 2
sys/src/9/port/qio.c

@@ -1300,6 +1300,9 @@ qwrite(Queue *q, void *vp, int len)
 /*
  *  used by print() to write to a queue.  Since we may be splhi or not in
  *  a process, don't qlock.
+ *
+ *  this routine merges adjacent blocks if block n+1 will fit into
+ *  the free space of block n.
  */
 int
 qiwrite(Queue *q, void *vp, int len)
@@ -1324,8 +1327,10 @@ qiwrite(Queue *q, void *vp, int len)
 
 		ilock(q);
 
-		/* don't queue over the limit, just lose the bytes */
-		if(q->len >= q->limit){
+		/* we use an artificially high limit for kernel prints since anything
+		 * over the limit gets dropped
+		 */
+		if(q->dlen >= 16*1024){
 			iunlock(q);
 			freeb(b);
 			break;

+ 4 - 0
sys/src/ape/lib/ap/plan9/9errstr.c

@@ -0,0 +1,4 @@
+#include "sys9.h"
+
+int
+_ERRSTR(

+ 14 - 0
sys/src/ape/lib/ap/plan9/9mallocz.c

@@ -0,0 +1,14 @@
+#include <stdlib.h>
+#include <string.h>
+
+void*
+_MALLOCZ(int n, int clr)
+{
+	void *v;
+
+	v = malloc(n);
+	if(v && clr)
+		memset(v, 0, n);
+	return v;
+}
+

+ 21 - 0
sys/src/ape/lib/ap/plan9/9readn.c

@@ -0,0 +1,21 @@
+#include "sys9.h"
+
+long
+_READN(int f, void *av, long n)
+{
+	char *a;
+	long m, t;
+
+	a = av;
+	t = 0;
+	while(t < n){
+		m = _READ(f, a+t, n-t);
+		if(m <= 0){
+			if(t == 0)
+				return m;
+			break;
+		}
+		t += m;
+	}
+	return t;
+}

+ 3 - 0
sys/src/ape/lib/ap/plan9/mkfile

@@ -10,7 +10,9 @@ OFILES=\
 	_fdinfo.$O\
 	_getpw.$O\
 	_nap.$O\
+	9mallocz.$O\
 	9read.$O\
+	9readn.$O\
 	9wait.$O\
 	9write.$O\
 	access.$O\
@@ -67,6 +69,7 @@ OFILES=\
 	pause.$O\
 	pipe.$O\
 	profile.$O\
+	qlock.$O\
 	raise.$O\
 	read.$O\
 	rename.$O\

+ 365 - 0
sys/src/ape/lib/ap/plan9/qlock.c

@@ -0,0 +1,365 @@
+#define _LOCK_EXTENSION
+#define _QLOCK_EXTENSION
+#define _RESEARCH_SOURCE
+#include <u.h>
+#include <lock.h>
+#include <qlock.h>
+#include <stdlib.h>
+#include "sys9.h"
+
+#define rendezvous _RENDEZVOUS
+#define _rendezvousp rendezvous
+#define _tas tas
+#define nelem(x) (sizeof(x)/sizeof((x)[0]))
+
+static struct {
+	QLp	*p;
+	QLp	x[1024];
+} ql = {
+	ql.x
+};
+
+enum
+{
+	Queuing,
+	QueuingR,
+	QueuingW,
+	Sleeping,
+};
+
+/* find a free shared memory location to queue ourselves in */
+static QLp*
+getqlp(void)
+{
+	QLp *p, *op;
+
+	op = ql.p;
+	for(p = op+1; ; p++){
+		if(p == &ql.x[nelem(ql.x)])
+			p = ql.x;
+		if(p == op)
+			abort();
+		if(_tas(&(p->inuse)) == 0){
+			ql.p = p;
+			p->next = nil;
+			break;
+		}
+	}
+	return p;
+}
+
+void
+qlock(QLock *q)
+{
+	QLp *p, *mp;
+
+	lock(&q->lock);
+	if(!q->locked){
+		q->locked = 1;
+		unlock(&q->lock);
+		return;
+	}
+
+
+	/* chain into waiting list */
+	mp = getqlp();
+	p = q->tail;
+	if(p == nil)
+		q->head = mp;
+	else
+		p->next = mp;
+	q->tail = mp;
+	mp->state = Queuing;
+	unlock(&q->lock);
+
+	/* wait */
+	while((*_rendezvousp)((ulong)mp, 1) == ~0)
+		;
+	mp->inuse = 0;
+}
+
+void
+qunlock(QLock *q)
+{
+	QLp *p;
+
+	lock(&q->lock);
+	p = q->head;
+	if(p != nil){
+		/* wakeup head waiting process */
+		q->head = p->next;
+		if(q->head == nil)
+			q->tail = nil;
+		unlock(&q->lock);
+		while((*_rendezvousp)((ulong)p, 0x12345) == ~0)
+			;
+		return;
+	}
+	q->locked = 0;
+	unlock(&q->lock);
+}
+
+int
+canqlock(QLock *q)
+{
+	if(!canlock(&q->lock))
+		return 0;
+	if(!q->locked){
+		q->locked = 1;
+		unlock(&q->lock);
+		return 1;
+	}
+	unlock(&q->lock);
+	return 0;
+}
+
+#if 0
+
+void
+rlock(RWLock *q)
+{
+	QLp *p, *mp;
+
+	lock(&q->lock);
+	if(q->writer == 0 && q->head == nil){
+		/* no writer, go for it */
+		q->readers++;
+		unlock(&q->lock);
+		return;
+	}
+
+	mp = getqlp();
+	p = q->tail;
+	if(p == 0)
+		q->head = mp;
+	else
+		p->next = mp;
+	q->tail = mp;
+	mp->next = nil;
+	mp->state = QueuingR;
+	unlock(&q->lock);
+
+	/* wait in kernel */
+	while((*_rendezvousp)((ulong)mp, 1) == ~0)
+		;
+	mp->inuse = 0;
+}
+
+int
+canrlock(RWLock *q)
+{
+	lock(&q->lock);
+	if (q->writer == 0 && q->head == nil) {
+		/* no writer; go for it */
+		q->readers++;
+		unlock(&q->lock);
+		return 1;
+	}
+	unlock(&q->lock);
+	return 0;
+}
+
+void
+runlock(RWLock *q)
+{
+	QLp *p;
+
+	lock(&q->lock);
+	if(q->readers <= 0)
+		abort();
+	p = q->head;
+	if(--(q->readers) > 0 || p == nil){
+		unlock(&q->lock);
+		return;
+	}
+
+	/* start waiting writer */
+	if(p->state != QueuingW)
+		abort();
+	q->head = p->next;
+	if(q->head == 0)
+		q->tail = 0;
+	q->writer = 1;
+	unlock(&q->lock);
+
+	/* wakeup waiter */
+	while((*_rendezvousp)((ulong)p, 0) == ~0)
+		;
+}
+
+void
+wlock(RWLock *q)
+{
+	QLp *p, *mp;
+
+	lock(&q->lock);
+	if(q->readers == 0 && q->writer == 0){
+		/* noone waiting, go for it */
+		q->writer = 1;
+		unlock(&q->lock);
+		return;
+	}
+
+	/* wait */
+	p = q->tail;
+	mp = getqlp();
+	if(p == nil)
+		q->head = mp;
+	else
+		p->next = mp;
+	q->tail = mp;
+	mp->next = nil;
+	mp->state = QueuingW;
+	unlock(&q->lock);
+
+	/* wait in kernel */
+	while((*_rendezvousp)((ulong)mp, 1) == ~0)
+		;
+	mp->inuse = 0;
+}
+
+int
+canwlock(RWLock *q)
+{
+	lock(&q->lock);
+	if (q->readers == 0 && q->writer == 0) {
+		/* no one waiting; go for it */
+		q->writer = 1;
+		unlock(&q->lock);
+		return 1;
+	}
+	unlock(&q->lock);
+	return 0;
+}
+
+void
+wunlock(RWLock *q)
+{
+	QLp *p;
+
+	lock(&q->lock);
+	if(q->writer == 0)
+		abort();
+	p = q->head;
+	if(p == nil){
+		q->writer = 0;
+		unlock(&q->lock);
+		return;
+	}
+	if(p->state == QueuingW){
+		/* start waiting writer */
+		q->head = p->next;
+		if(q->head == nil)
+			q->tail = nil;
+		unlock(&q->lock);
+		while((*_rendezvousp)((ulong)p, 0) == ~0)
+			;
+		return;
+	}
+
+	if(p->state != QueuingR)
+		abort();
+
+	/* wake waiting readers */
+	while(q->head != nil && q->head->state == QueuingR){
+		p = q->head;
+		q->head = p->next;
+		q->readers++;
+		while((*_rendezvousp)((ulong)p, 0) == ~0)
+			;
+	}
+	if(q->head == nil)
+		q->tail = nil;
+	q->writer = 0;
+	unlock(&q->lock);
+}
+
+void
+rsleep(Rendez *r)
+{
+	QLp *t, *me;
+
+	if(!r->l)
+		abort();
+	lock(&r->l->lock);
+	/* we should hold the qlock */
+	if(!r->l->locked)
+		abort();
+
+	/* add ourselves to the wait list */
+	me = getqlp();
+	me->state = Sleeping;
+	if(r->head == nil)
+		r->head = me;
+	else
+		r->tail->next = me;
+	me->next = nil;
+	r->tail = me;
+
+	/* pass the qlock to the next guy */
+	t = r->l->head;
+	if(t){
+		r->l->head = t->next;
+		if(r->l->head == nil)
+			r->l->tail = nil;
+		unlock(&r->l->lock);
+		while((*_rendezvousp)((ulong)t, 0x12345) == ~0)
+			;
+	}else{
+		r->l->locked = 0;
+		unlock(&r->l->lock);
+	}
+
+	/* wait for a wakeup */
+	while((*_rendezvousp)((ulong)me, 1) == ~0)
+		;
+	me->inuse = 0;
+}
+
+int
+rwakeup(Rendez *r)
+{
+	QLp *t;
+
+	/*
+	 * take off wait and put on front of queue
+	 * put on front so guys that have been waiting will not get starved
+	 */
+	
+	if(!r->l)
+		abort();
+	lock(&r->l->lock);
+	if(!r->l->locked)
+		abort();
+
+	t = r->head;
+	if(t == nil){
+		unlock(&r->l->lock);
+		return 0;
+	}
+
+	r->head = t->next;
+	if(r->head == nil)
+		r->tail = nil;
+
+	t->next = r->l->head;
+	r->l->head = t;
+	if(r->l->tail == nil)
+		r->l->tail = t;
+
+	t->state = Queuing;
+	unlock(&r->l->lock);
+	return 1;
+}
+
+int
+rwakeupall(Rendez *r)
+{
+	int i;
+
+	for(i=0; rwakeup(r); i++)
+		;
+	return i;
+}
+
+#endif

+ 203 - 0
sys/src/ape/lib/draw/colors.c

@@ -0,0 +1,203 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+
+char *argv0;
+
+static void
+_sysfatalimpl(char *fmt, va_list arg)
+{
+	char buf[1024];
+
+	vseprint(buf, buf+sizeof(buf), fmt, arg);
+	if(argv0)
+		fprint(2, "%s: %s\n", argv0, buf);
+	else
+		fprint(2, "%s\n", buf);
+	exits(buf);
+}
+
+void (*_sysfatal)(char *fmt, va_list arg) = _sysfatalimpl;
+
+void
+sysfatal(char *fmt, ...)
+{
+	va_list arg;
+
+	va_start(arg, fmt);
+	(*_sysfatal)(fmt, arg);
+	va_end(arg);
+}
+
+int nbit, npix;
+Image *pixel;
+Rectangle crect[256];
+
+Image *color[256];
+
+void
+eresized(int new)
+{
+	int x, y, i, n, nx, ny;
+	Rectangle r, b;
+
+	if(new && getwindow(display, Refnone) < 0){
+		fprint(2, "colors: can't reattach to window: %r\n");
+		exits("resized");
+	}
+	if(screen->depth > 8){
+		n = 256;
+		nx = 16;
+	}else{
+		n = 1<<screen->depth;
+		nx = 1<<(screen->depth/2);
+	}
+
+	ny = n/nx;
+	draw(screen, screen->r, display->white, nil, ZP);
+	r = insetrect(screen->r, 5);
+	r.min.y+=20;
+	b.max.y=r.min.y;
+	for(i=n-1, y=0; y!=ny; y++){
+		b.min.y=b.max.y;
+		b.max.y=r.min.y+(r.max.y-r.min.y)*(y+1)/ny;
+		b.max.x=r.min.x;
+		for(x=0; x!=nx; x++, --i){
+			b.min.x=b.max.x;
+			b.max.x=r.min.x+(r.max.x-r.min.x)*(x+1)/nx;
+			crect[i]=insetrect(b, 1);
+			draw(screen, crect[i], color[i], nil, ZP);
+		}
+	}
+	flushimage(display, 1);
+}
+
+char *buttons[] =
+{
+	"exit",
+	0
+};
+
+ulong
+grey(int i)
+{
+	if(i < 0)
+		return grey(0);
+	if(i > 255)
+		return grey(255);
+	return (i<<16)+(i<<8)+i;
+}
+
+Menu menu =
+{
+	buttons
+};
+
+int
+dither[16] =  {
+	0, 8, 2, 10,
+	12, 4, 14, 6,
+	3, 11, 1, 9,
+	15, 7, 13, 5
+};
+
+void
+main(int argc, char *argv[])
+{
+	Point p;
+	Mouse m;
+	int i, j, k, l, n, ramp, prev;
+	char buf[100];
+	char *fmt;
+	Image *dark;
+	ulong rgb;
+
+	ramp = 0;
+
+	fmt = "index %3d r %3lud g %3lud b %3lud 0x%.8luX        ";
+/*
+	ARGBEGIN{
+	default:
+		goto Usage;
+	case 'x':
+		fmt = "index %2luX r %3luX g %3luX b %3luX 0x%.8luX       ";
+		break;
+	case 'r':
+		ramp = 1;
+		break;
+	}ARGEND
+*/
+	argv0 = argv[0];
+	if(argc != 1){
+	Usage:
+		fprint(2, "Usage: %s [-rx]\n", argv0);
+		exits("usage");
+	}
+
+	if(initdraw(nil, nil, "colors") < 0)
+		sysfatal("initdraw failed: %r");
+	einit(Emouse);
+
+	for(i=0; i<256; i++){
+		if(ramp){
+			if(screen->chan == CMAP8){
+				/* dither the fine grey */
+				j = i-(i%17);
+				dark = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(j)<<8)+0xFF);
+				color[i] = allocimage(display, Rect(0,0,4,4), screen->chan, 1, (grey(j+17)<<8)+0xFF);
+				for(j=0; j<16; j++){
+					k = j%4;
+					l = j/4;
+					if(dither[j] > (i%17))
+						draw(color[i], Rect(k, l, k+1, l+1), dark, nil, ZP);
+				}
+				freeimage(dark);
+			}else
+				color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(i)<<8)+0xFF);
+		}else
+			color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (cmap2rgb(i)<<8)+0xFF);
+		if(color[i] == nil)
+			sysfatal("can't allocate image: %r");
+	}
+	eresized(0);
+	prev = -1;
+	for(;;){
+		m = emouse();
+		switch(m.buttons){
+		case 1:
+			while(m.buttons){
+				if(screen->depth > 8)
+					n = 256;
+				else
+					n = 1<<screen->depth;
+				for(i=0; i!=n; i++)
+					if(i!=prev && ptinrect(m.xy, crect[i])){
+						if(ramp)
+							rgb = grey(i);
+						else
+							rgb = cmap2rgb(i);
+						sprint(buf, fmt,
+							i,
+							(rgb>>16)&0xFF,
+							(rgb>>8)&0xFF,
+							rgb&0xFF,
+							(rgb<<8) | 0xFF);
+						p = addpt(screen->r.min, Pt(2,2));
+						draw(screen, Rpt(p, addpt(p, stringsize(font, buf))), display->white, nil, p);
+						string(screen, p, display->black, ZP, font, buf);
+						prev=i;
+						break;
+					}
+				m = emouse();
+			}
+			break;
+
+		case 4:
+			switch(emenuhit(3, &m, &menu)){
+			case 0:
+				exits(0);
+			}
+		}
+	}
+}

+ 135 - 0
sys/src/ape/lib/draw/libc.h

@@ -0,0 +1,135 @@
+#define _LOCK_EXTENSION
+#define _QLOCK_EXTENSION
+#define _BSD_EXTENSION
+#include <sys/types.h>
+#include <lock.h>
+#include <qlock.h>
+#include <lib9.h>
+#include <stdlib.h>
+#include <string.h>
+#include <bsd.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <utf.h>
+#include <fmt.h>
+#include <signal.h>
+
+typedef
+struct Qid
+{
+	uvlong	path;
+	ulong	vers;
+	uchar	type;
+} Qid;
+
+typedef
+struct Dir {
+	/* system-modified data */
+	ushort	type;	/* server type */
+	uint	dev;	/* server subtype */
+	/* file data */
+	Qid	qid;	/* unique id from server */
+	ulong	mode;	/* permissions */
+	ulong	atime;	/* last read time */
+	ulong	mtime;	/* last write time */
+	vlong	length;	/* file length: see <u.h> */
+	char	*name;	/* last element of path */
+	char	*uid;	/* owner name */
+	char	*gid;	/* group name */
+	char	*muid;	/* last modifier name */
+} Dir;
+
+uint	_convM2D(uchar*, uint, Dir*, char*);
+uint	_convD2M(Dir*, uchar*, uint);
+Dir	*_dirstat(char*);
+int	_dirwstat(char*, Dir*);
+Dir	*_dirfstat(int);
+int	_dirfwstat(int, Dir*);
+long	_dirread(int, Dir**);
+long _dirreadall(int, Dir**);
+void _nulldir(Dir*);
+uint _sizeD2M(Dir*);
+
+typedef
+struct Waitmsg
+{
+	int pid;	/* of loved one */
+	unsigned long time[3];	/* of loved one & descendants */
+	char	*msg;
+} Waitmsg;
+
+
+extern	int	_AWAIT(char*, int);
+extern	int	_ALARM(unsigned long);
+extern	int	_BIND(const char*, const char*, int);
+extern	int	_CHDIR(const char*);
+extern	int	_CLOSE(int);
+extern	int	_CREATE(char*, int, unsigned long);
+extern	int	_DUP(int, int);
+extern	int	_ERRSTR(char*, unsigned int);
+extern	int	_EXEC(char*, char*[]);
+extern	void	_EXITS(char *);
+extern	int	_FD2PATH(int, char*, int);
+extern	int	_FAUTH(int, char*);
+extern	int	_FSESSION(int, char*, int);
+extern	int	_FSTAT(int, unsigned char*, int);
+extern	int	_FWSTAT(int, unsigned char*, int);
+extern	int	_MOUNT(int, int, const char*, int, const char*);
+extern	int	_NOTED(int);
+extern	int	_NOTIFY(int(*)(void*, char*));
+extern	int	_OPEN(const char*, int);
+extern	int	_PIPE(int*);
+extern	long	_PREAD(int, void*, long, long long);
+extern	long	_PWRITE(int, void*, long, long long);
+extern	long	_READ(int, void*, long);
+extern	int	_REMOVE(const char*);
+extern	int	_RENDEZVOUS(unsigned long, unsigned long);
+extern	int	_RFORK(int);
+extern	int	_SEGATTACH(int, char*, void*, unsigned long);
+extern	int	_SEGBRK(void*, void*);
+extern	int	_SEGDETACH(void*);
+extern	int	_SEGFLUSH(void*, unsigned long);
+extern	int	_SEGFREE(void*, unsigned long);
+extern	long long	_SEEK(int, long long, int);
+extern	int	_SLEEP(long);
+extern	int	_STAT(const char*, unsigned char*, int);
+extern	Waitmsg*	_WAIT(void);
+extern	long	_WRITE(int, const void*, long);
+extern	int	_WSTAT(const char*, unsigned char*, int);
+extern 	void *_MALLOCZ(int, int);
+extern	int	_WERRSTR(char*, ...);
+extern	long	_READN(int, void*, long);
+
+#define dirstat _dirstat
+#define dirfstat _dirfstat
+
+#define OREAD 0
+#define OWRITE 1
+#define ORDWR 2
+#define OCEXEC 32
+
+#define AREAD 4
+#define AWRITE 2
+#define AEXEC 1
+#define AEXIST 0
+
+#define open _OPEN
+#define close _CLOSE
+#define read _READ
+#define write _WRITE
+#define _exits(s) _exit(s && *(char*)s ? 1 : 0)
+#define exits(s) exit(s && *(char*)s ? 1 : 0)
+#define create _CREATE
+#define pread _PREAD
+#define readn _READN
+#define mallocz _MALLOCZ
+
+/* assume being called as in event.c */
+#define postnote(x, pid, msg) kill(pid, SIGTERM)
+#define atnotify(x, y) signal(SIGTERM, ekill)
+
+/* assume being called as in init.c */
+#define iounit(x) (32*1024)
+
+#define ERRMAX 128

+ 78 - 0
sys/src/ape/lib/draw/mkfile

@@ -0,0 +1,78 @@
+APE=/sys/src/ape
+<$APE/config
+
+LIB=/$objtype/lib/ape/libdraw.a
+
+OFILES=\
+	alloc.$O\
+	allocimagemix.$O\
+	arith.$O\
+	bezier.$O\
+	border.$O\
+	buildfont.$O\
+	bytesperline.$O\
+	chan.$O\
+	cloadimage.$O\
+	computil.$O\
+	creadimage.$O\
+	debug.$O\
+	defont.$O\
+	draw.$O\
+	drawrepl.$O\
+	egetrect.$O\
+	ellipse.$O\
+	emenuhit.$O\
+	event.$O\
+	fmt.$O\
+	font.$O\
+	freesubfont.$O\
+	getdefont.$O\
+	getsubfont.$O\
+	icossin.$O\
+	icossin2.$O\
+	init.$O\
+	line.$O\
+	mkfont.$O\
+	newwindow.$O\
+	openfont.$O\
+	poly.$O\
+	loadimage.$O\
+	readimage.$O\
+	readsubfont.$O\
+	rectclip.$O\
+	replclipr.$O\
+	rgb.$O\
+	string.$O\
+	stringbg.$O\
+	stringsubfont.$O\
+	stringwidth.$O\
+	subfont.$O\
+	subfontcache.$O\
+	subfontname.$O\
+	unloadimage.$O\
+	window.$O\
+	writecolmap.$O\
+	writeimage.$O\
+	writesubfont.$O\
+
+HFILES=\
+	/sys/include/ape/draw.h\
+	/sys/include/ape/event.h\
+	/sys/include/ape/mouse.h\
+	/sys/include/ape/keyboard.h\
+
+UPDATE=\
+	mkfile\
+	$HFILES\
+	${OFILES:%.$O=%.c}\
+	${LIB:/$objtype/%=/386/%}\
+
+</sys/src/cmd/mksyslib
+
+CFLAGS=-c $CFLAGS -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_RESEARCH_SOURCE -I.
+
+%.$O: /sys/src/libdraw/%.c
+	$CC $CFLAGS /sys/src/libdraw/$stem.c
+
+$O.colors: colors.$O
+	$LD -o $target colors.$O

+ 85 - 0
sys/src/ape/lib/fmt/charstod.c

@@ -0,0 +1,85 @@
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ *              Copyright (c) 2002 by Lucent Technologies.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+#include <stdarg.h>
+#include <string.h>
+#include "utf.h"
+#include "fmt.h"
+#include "fmtdef.h"
+
+/*
+ * Reads a floating-point number by interpreting successive characters
+ * returned by (*f)(vp).  The last call it makes to f terminates the
+ * scan, so is not a character in the number.  It may therefore be
+ * necessary to back up the input stream up one byte after calling charstod.
+ */
+
+double
+fmtcharstod(int(*f)(void*), void *vp)
+{
+	double num, dem;
+	int neg, eneg, dig, exp, c;
+
+	num = 0;
+	neg = 0;
+	dig = 0;
+	exp = 0;
+	eneg = 0;
+
+	c = (*f)(vp);
+	while(c == ' ' || c == '\t')
+		c = (*f)(vp);
+	if(c == '-' || c == '+'){
+		if(c == '-')
+			neg = 1;
+		c = (*f)(vp);
+	}
+	while(c >= '0' && c <= '9'){
+		num = num*10 + c-'0';
+		c = (*f)(vp);
+	}
+	if(c == '.')
+		c = (*f)(vp);
+	while(c >= '0' && c <= '9'){
+		num = num*10 + c-'0';
+		dig++;
+		c = (*f)(vp);
+	}
+	if(c == 'e' || c == 'E'){
+		c = (*f)(vp);
+		if(c == '-' || c == '+'){
+			if(c == '-'){
+				dig = -dig;
+				eneg = 1;
+			}
+			c = (*f)(vp);
+		}
+		while(c >= '0' && c <= '9'){
+			exp = exp*10 + c-'0';
+			c = (*f)(vp);
+		}
+	}
+	exp -= dig;
+	if(exp < 0){
+		exp = -exp;
+		eneg = !eneg;
+	}
+	dem = __fmtpow10(exp);
+	if(eneg)
+		num /= dem;
+	else
+		num *= dem;
+	if(neg)
+		return -num;
+	return num;
+}

+ 558 - 0
sys/src/ape/lib/fmt/dofmt.c

@@ -0,0 +1,558 @@
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ *              Copyright (c) 2002 by Lucent Technologies.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+#include <stdarg.h>
+#include <string.h>
+#include "utf.h"
+#include "fmt.h"
+#include "fmtdef.h"
+
+/* format the output into f->to and return the number of characters fmted  */
+int
+dofmt(Fmt *f, char *fmt)
+{
+	Rune rune, *rt, *rs;
+	int r;
+	char *t, *s;
+	int n, nfmt;
+
+	nfmt = f->nfmt;
+	for(;;){
+		if(f->runes){
+			rt = (Rune*)f->to;
+			rs = (Rune*)f->stop;
+			while((r = *(uchar*)fmt) && r != '%'){
+				if(r < Runeself)
+					fmt++;
+				else{
+					fmt += chartorune(&rune, fmt);
+					r = rune;
+				}
+				FMTRCHAR(f, rt, rs, r);
+			}
+			fmt++;
+			f->nfmt += rt - (Rune *)f->to;
+			f->to = rt;
+			if(!r)
+				return f->nfmt - nfmt;
+			f->stop = rs;
+		}else{
+			t = (char*)f->to;
+			s = (char*)f->stop;
+			while((r = *(uchar*)fmt) && r != '%'){
+				if(r < Runeself){
+					FMTCHAR(f, t, s, r);
+					fmt++;
+				}else{
+					n = chartorune(&rune, fmt);
+					if(t + n > s){
+						t = (char*)__fmtflush(f, t, n);
+						if(t != nil)
+							s = (char*)f->stop;
+						else
+							return -1;
+					}
+					while(n--)
+						*t++ = *fmt++;
+				}
+			}
+			fmt++;
+			f->nfmt += t - (char *)f->to;
+			f->to = t;
+			if(!r)
+				return f->nfmt - nfmt;
+			f->stop = s;
+		}
+
+		fmt = (char*)__fmtdispatch(f, fmt, 0);
+		if(fmt == nil)
+			return -1;
+	}
+	return 0;	/* not reached */
+}
+
+void *
+__fmtflush(Fmt *f, void *t, int len)
+{
+	if(f->runes)
+		f->nfmt += (Rune*)t - (Rune*)f->to;
+	else
+		f->nfmt += (char*)t - (char *)f->to;
+	f->to = t;
+	if(f->flush == 0 || (*f->flush)(f) == 0 || (char*)f->to + len > (char*)f->stop){
+		f->stop = f->to;
+		return nil;
+	}
+	return f->to;
+}
+
+/*
+ * put a formatted block of memory sz bytes long of n runes into the output buffer,
+ * left/right justified in a field of at least f->width charactes
+ */
+int
+__fmtpad(Fmt *f, int n)
+{
+	char *t, *s;
+	int i;
+
+	t = (char*)f->to;
+	s = (char*)f->stop;
+	for(i = 0; i < n; i++)
+		FMTCHAR(f, t, s, ' ');
+	f->nfmt += t - (char *)f->to;
+	f->to = t;
+	return 0;
+}
+
+int
+__rfmtpad(Fmt *f, int n)
+{
+	Rune *t, *s;
+	int i;
+
+	t = (Rune*)f->to;
+	s = (Rune*)f->stop;
+	for(i = 0; i < n; i++)
+		FMTRCHAR(f, t, s, ' ');
+	f->nfmt += t - (Rune *)f->to;
+	f->to = t;
+	return 0;
+}
+
+int
+__fmtcpy(Fmt *f, const void *vm, int n, int sz)
+{
+	Rune *rt, *rs, r;
+	char *t, *s, *m, *me;
+	ulong fl;
+	int nc, w;
+
+	m = (char*)vm;
+	me = m + sz;
+	w = f->width;
+	fl = f->flags;
+	if((fl & FmtPrec) && n > f->prec)
+		n = f->prec;
+	if(f->runes){
+		if(!(fl & FmtLeft) && __rfmtpad(f, w - n) < 0)
+			return -1;
+		rt = (Rune*)f->to;
+		rs = (Rune*)f->stop;
+		for(nc = n; nc > 0; nc--){
+			r = *(uchar*)m;
+			if(r < Runeself)
+				m++;
+			else if((me - m) >= UTFmax || fullrune(m, me-m))
+				m += chartorune(&r, m);
+			else
+				break;
+			FMTRCHAR(f, rt, rs, r);
+		}
+		f->nfmt += rt - (Rune *)f->to;
+		f->to = rt;
+		if(m < me)
+			return -1;
+		if(fl & FmtLeft && __rfmtpad(f, w - n) < 0)
+			return -1;
+	}else{
+		if(!(fl & FmtLeft) && __fmtpad(f, w - n) < 0)
+			return -1;
+		t = (char*)f->to;
+		s = (char*)f->stop;
+		for(nc = n; nc > 0; nc--){
+			r = *(uchar*)m;
+			if(r < Runeself)
+				m++;
+			else if((me - m) >= UTFmax || fullrune(m, me-m))
+				m += chartorune(&r, m);
+			else
+				break;
+			FMTRUNE(f, t, s, r);
+		}
+		f->nfmt += t - (char *)f->to;
+		f->to = t;
+		if(fl & FmtLeft && __fmtpad(f, w - n) < 0)
+			return -1;
+	}
+	return 0;
+}
+
+int
+__fmtrcpy(Fmt *f, const void *vm, int n)
+{
+	Rune r, *m, *me, *rt, *rs;
+	char *t, *s;
+	ulong fl;
+	int w;
+
+	m = (Rune*)vm;
+	w = f->width;
+	fl = f->flags;
+	if((fl & FmtPrec) && n > f->prec)
+		n = f->prec;
+	if(f->runes){
+		if(!(fl & FmtLeft) && __rfmtpad(f, w - n) < 0)
+			return -1;
+		rt = (Rune*)f->to;
+		rs = (Rune*)f->stop;
+		for(me = m + n; m < me; m++)
+			FMTRCHAR(f, rt, rs, *m);
+		f->nfmt += rt - (Rune *)f->to;
+		f->to = rt;
+		if(fl & FmtLeft && __rfmtpad(f, w - n) < 0)
+			return -1;
+	}else{
+		if(!(fl & FmtLeft) && __fmtpad(f, w - n) < 0)
+			return -1;
+		t = (char*)f->to;
+		s = (char*)f->stop;
+		for(me = m + n; m < me; m++){
+			r = *m;
+			FMTRUNE(f, t, s, r);
+		}
+		f->nfmt += t - (char *)f->to;
+		f->to = t;
+		if(fl & FmtLeft && __fmtpad(f, w - n) < 0)
+			return -1;
+	}
+	return 0;
+}
+
+/* fmt out one character */
+int
+__charfmt(Fmt *f)
+{
+	char x[1];
+
+	x[0] = va_arg(f->args, int);
+	f->prec = 1;
+	return __fmtcpy(f, (const char*)x, 1, 1);
+}
+
+/* fmt out one rune */
+int
+__runefmt(Fmt *f)
+{
+	Rune x[1];
+
+	x[0] = va_arg(f->args, int);
+	return __fmtrcpy(f, (const void*)x, 1);
+}
+
+/* public helper routine: fmt out a null terminated string already in hand */
+int
+fmtstrcpy(Fmt *f, char *s)
+{
+	int p, i;
+	if(!s)
+		return __fmtcpy(f, "<nil>", 5, 5);
+	/* if precision is specified, make sure we don't wander off the end */
+	if(f->flags & FmtPrec){
+		p = f->prec;
+		for(i = 0; i < p; i++)
+			if(s[i] == 0)
+				break;
+		return __fmtcpy(f, s, utfnlen(s, i), i);	/* BUG?: won't print a partial rune at end */
+	}
+
+	return __fmtcpy(f, s, utflen(s), strlen(s));
+}
+
+/* fmt out a null terminated utf string */
+int
+__strfmt(Fmt *f)
+{
+	char *s;
+
+	s = va_arg(f->args, char *);
+	return fmtstrcpy(f, s);
+}
+
+/* public helper routine: fmt out a null terminated rune string already in hand */
+int
+fmtrunestrcpy(Fmt *f, Rune *s)
+{
+	Rune *e;
+	int n, p;
+
+	if(!s)
+		return __fmtcpy(f, "<nil>", 5, 5);
+	/* if precision is specified, make sure we don't wander off the end */
+	if(f->flags & FmtPrec){
+		p = f->prec;
+		for(n = 0; n < p; n++)
+			if(s[n] == 0)
+				break;
+	}else{
+		for(e = s; *e; e++)
+			;
+		n = e - s;
+	}
+	return __fmtrcpy(f, s, n);
+}
+
+/* fmt out a null terminated rune string */
+int
+__runesfmt(Fmt *f)
+{
+	Rune *s;
+
+	s = va_arg(f->args, Rune *);
+	return fmtrunestrcpy(f, s);
+}
+
+/* fmt a % */
+int
+__percentfmt(Fmt *f)
+{
+	Rune x[1];
+
+	x[0] = f->r;
+	f->prec = 1;
+	return __fmtrcpy(f, (const void*)x, 1);
+}
+
+/* fmt an integer */
+int
+__ifmt(Fmt *f)
+{
+	char buf[70], *p, *conv;
+	uvlong vu;
+	ulong u;
+	int neg, base, i, n, fl, w, isv;
+
+	neg = 0;
+	fl = f->flags;
+	isv = 0;
+	vu = 0;
+	u = 0;
+	/*
+	 * Unsigned verbs
+	 */
+	switch(f->r){
+	case 'o':
+	case 'u':
+	case 'x':
+	case 'X':
+		fl |= FmtUnsigned;
+		break;
+	}
+	if(f->r == 'p'){
+		u = (ulong)va_arg(f->args, void*);
+		f->r = 'x';
+		fl |= FmtUnsigned;
+	}else if(fl & FmtVLong){
+		isv = 1;
+		if(fl & FmtUnsigned)
+			vu = va_arg(f->args, uvlong);
+		else
+			vu = va_arg(f->args, vlong);
+	}else if(fl & FmtLong){
+		if(fl & FmtUnsigned)
+			u = va_arg(f->args, ulong);
+		else
+			u = va_arg(f->args, long);
+	}else if(fl & FmtByte){
+		if(fl & FmtUnsigned)
+			u = (uchar)va_arg(f->args, int);
+		else
+			u = (char)va_arg(f->args, int);
+	}else if(fl & FmtShort){
+		if(fl & FmtUnsigned)
+			u = (ushort)va_arg(f->args, int);
+		else
+			u = (short)va_arg(f->args, int);
+	}else{
+		if(fl & FmtUnsigned)
+			u = va_arg(f->args, uint);
+		else
+			u = va_arg(f->args, int);
+	}
+	conv = "0123456789abcdef";
+	switch(f->r){
+	case 'd':
+	case 'i':
+		base = 10;
+		break;
+	case 'u':
+		base = 10;
+		break;
+	case 'x':
+		base = 16;
+		break;
+	case 'X':
+		base = 16;
+		conv = "0123456789ABCDEF";
+		break;
+	case 'b':
+		base = 2;
+		break;
+	case 'o':
+		base = 8;
+		break;
+	default:
+		return -1;
+	}
+	if(!(fl & FmtUnsigned)){
+		if(isv && (vlong)vu < 0){
+			vu = -(vlong)vu;
+			neg = 1;
+		}else if(!isv && (long)u < 0){
+			u = -(long)u;
+			neg = 1;
+		}
+	}else{
+		fl &= ~(FmtSign|FmtSpace);	/* no + for unsigned conversions */
+	}
+	p = buf + sizeof buf - 1;
+	n = 0;
+	if(isv){
+		while(vu){
+			i = vu % base;