[inferno-npe] 11 new revisions pushed by extrudedaluminiu on 2010-10-08 14:43 GMT

4 views
Skip to first unread message

infer...@googlecode.com

unread,
Oct 8, 2010, 10:44:11 AM10/8/10
to inferno-n...@googlegroups.com
11 new revisions:

Revision: 033899a799
Author: for...@vitanuova.com
Date: Tue Aug 10 12:45:41 2010
Log: 20100810-2045
http://code.google.com/p/inferno-npe/source/detail?r=033899a799

Revision: 78387aa7d1
Author: for...@vitanuova.com
Date: Tue Aug 10 15:06:28 2010
Log: 20100810-2306
http://code.google.com/p/inferno-npe/source/detail?r=78387aa7d1

Revision: 10da85a9c3
Author: for...@vitanuova.com
Date: Thu Aug 19 08:17:42 2010
Log: 20100819-1617
http://code.google.com/p/inferno-npe/source/detail?r=10da85a9c3

Revision: 6dd14bb2ba
Author: for...@vitanuova.com
Date: Thu Aug 19 10:09:32 2010
Log: 20100819-1809
http://code.google.com/p/inferno-npe/source/detail?r=6dd14bb2ba

Revision: ab3b05624d
Author: for...@vitanuova.com
Date: Sat Aug 21 10:01:11 2010
Log: 20100821-1800
http://code.google.com/p/inferno-npe/source/detail?r=ab3b05624d

Revision: cf9af9a93a
Author: for...@vitanuova.com
Date: Sat Aug 21 11:20:57 2010
Log: 20100821-1920
http://code.google.com/p/inferno-npe/source/detail?r=cf9af9a93a

Revision: a3e633a4e6
Author: for...@vitanuova.com
Date: Sun Aug 22 05:59:46 2010
Log: 20100822-1358
http://code.google.com/p/inferno-npe/source/detail?r=a3e633a4e6

Revision: 5426124d08
Author: for...@vitanuova.com
Date: Thu Sep 2 16:32:34 2010
Log: 20100903-0032
http://code.google.com/p/inferno-npe/source/detail?r=5426124d08

Revision: d8cf126ad6
Author: for...@vitanuova.com
Date: Tue Sep 14 05:20:47 2010
Log: 20100914-1320
http://code.google.com/p/inferno-npe/source/detail?r=d8cf126ad6

Revision: bcd3cb9be2
Author: for...@vitanuova.com
Date: Sat Sep 25 06:04:43 2010
Log: 20100925-1403
http://code.google.com/p/inferno-npe/source/detail?r=bcd3cb9be2

Revision: f4d6a0c9b2
Author: Venkatesh Srinivas <venk...@sensorstar.com>
Date: Fri Oct 8 07:37:31 2010
Log: Merge inferno-os 20100925.
http://code.google.com/p/inferno-npe/source/detail?r=f4d6a0c9b2

==============================================================================
Revision: 033899a799
Author: for...@vitanuova.com
Date: Tue Aug 10 12:45:41 2010
Log: 20100810-2045
http://code.google.com/p/inferno-npe/source/detail?r=033899a799

Modified:
/appl/cmd/stackv.b
/dis/stackv.dis

=======================================
--- /appl/cmd/stackv.b Mon Aug 2 06:49:50 2010
+++ /appl/cmd/stackv.b Tue Aug 10 12:45:41 2010
@@ -489,6 +489,7 @@
t := array[n*3/2] of int;
t[0:] = a;
hasht[slot].t1 = t;
+ a = t;
}
a[hasht[slot].t0++] = v;
return 1;
=======================================
--- /dis/stackv.dis Mon Aug 2 06:49:50 2010
+++ /dis/stackv.dis Tue Aug 10 12:45:41 2010
@@ -1,5 +1,5 @@
À €0€@ƒÀ
- ì () È( ) ¼($)
+ ì () È( ) ¼($)
(('
$( H ( Ôž h @ Ô A Ô8- 8 ' È8 H 8 Ô @ < d^ Œ d 8) <8
8 @ 8 \^ Œ \ 8) 88
@@ -393,18 +393,18 @@
$( H ( \
„„ j‚ Œ„’ 4) T4
4
- - $T ,RI 4^J€@4„˜- $
+ - $T ,RI 4^J€@4„˜- $
„«RI 4^J€[4„«bŠ,$„ŸR‰$ 4]J€]4„Ÿ: $
„š=‘, 4`Š$4„§:‘$ 8R‰8 4^J 4„§:‘$ 4R‰4 8]J€@8„ª 8SÍ X 8
8
- : $=‰,$8`J 8„° 8) @8
+ : $=‰,$8`J 8„° 8) @8
8
- - (bŠ,$„ÃR‰$ 0 0€ÌN‘( 8=‘004:‰84(
+ - (bŠ,$„ÃR‰$ 0 0€ÌN‘( 8=‘004:‰84(
„ÁN‘( 8=‘0€a4:
4:‰84(
„Á 8SÍ X 8
8
-
+
„Á: $
„±-
( j‚ „Í A \() Ì( ) ($'
@@ -418,8 +418,8 @@
,$'
0, H , \ A \,) Ì, ) ,,$'
0, H , \- - H 08U t<E‰8<0‘ < t0+i < $- ,bŠ$,„ñr‰<(,^ª
< „ï- : ,
- „êU (<^Š$<„ü^’$ „õ- $@‘$ <C < I <4pI (4‘ < t0)
-4< ) Œ4‘ 8 t0-)8 <: 8 r‰<(<-
+ „êU (<^Š$<„ý^’$ „õ- $@‘$ <C < I <4pI (4‘ < t0)
+4< ) 4() Œ4‘ 8 t0-)8 <: 8 r‰<(<-
< - A Ô0- 0 '
,0 H 0 Ô ()
,( ) Œ,) À($)

==============================================================================
Revision: 78387aa7d1
Author: for...@vitanuova.com
Date: Tue Aug 10 15:06:28 2010
Log: 20100810-2306
http://code.google.com/p/inferno-npe/source/detail?r=78387aa7d1

Added:
/libinterp/crypt.c
/libinterp/ipint.h
/libinterp/keyringif.m
/man/2/crypt-0intro
/man/2/crypt-crypt
/man/2/crypt-dsagen
/man/2/crypt-gensk
/man/2/crypt-rc4
/man/2/crypt-sha1
/man/2/ipints
/man/2/ipints-genprime
/module/crypt.m
/module/ipints.m
Modified:
/CHANGES
/appl/cmd/randpass.b
/dis/randpass.dis
/emu/DragonFly/emu
/emu/DragonFly/emu-g
/emu/FreeBSD/emu
/emu/Hp/emu
/emu/Irix/emu
/emu/Linux/emu
/emu/Linux/emu-g
/emu/Linux/emu-wrt
/emu/MacOSX/emu
/emu/MacOSX/emu-g
/emu/NetBSD/emu
/emu/Nt/emu
/emu/Nt/ie
/emu/OpenBSD/emu
/emu/Plan9/emu
/emu/Plan9/emusig
/emu/Solaris/emu
/emu/Unixware/emu
/include/interp.h
/include/version.h
/libinterp/heap.c
/libinterp/ipint.c
/libinterp/keyring.c
/libinterp/load.c
/libinterp/mkfile
/libkeyring/dsaalg.c
/libkeyring/egalg.c
/libkeyring/keys.h
/libkeyring/rsaalg.c
/libmp/port/mpextendedgcd.c
/module/runt.m
/os/cerf1110/cerf
/os/cerf250/cerf
/os/cerf405/cerf
/os/fads/fads
/os/gum/gum
/os/ipaq1110/ipaq
/os/ipengine/ipe
/os/js/js
/os/manga/manga
/os/pc/pc4e
/os/pc/pcdisk
/os/pc/pix
/os/rpcg/rpcg

=======================================
--- /dev/null
+++ /libinterp/crypt.c Tue Aug 10 15:06:28 2010
@@ -0,0 +1,1350 @@
+#include "lib9.h"
+#include "kernel.h"
+#include <isa.h>
+#include "interp.h"
+#include "runt.h"
+#include "cryptmod.h"
+#include <mp.h>
+#include <libsec.h>
+#include "pool.h"
+#include "raise.h"
+#include "ipint.h"
+
+#define MPX(x) checkIPint((void*)(x))
+
+static Type* TDigestState;
+static Type* TAESstate;
+static Type* TDESstate;
+static Type* TIDEAstate;
+static Type* TBFstate;
+static Type* TRC4state;
+
+static Type* TSKdsa;
+static Type* TPKdsa;
+static Type* TPKsigdsa;
+static Type* TSKeg;
+static Type* TPKeg;
+static Type* TPKsigeg;
+static Type* TSKrsa;
+static Type* TPKrsa;
+static Type* TPKsigrsa;
+
+static uchar DigestStatemap[] = Crypt_DigestState_map;
+static uchar AESstatemap[] = Crypt_AESstate_map;
+static uchar DESstatemap[] = Crypt_DESstate_map;
+static uchar IDEAstatemap[] = Crypt_IDEAstate_map;
+static uchar BFstatemap[] = Crypt_BFstate_map;
+static uchar RC4statemap[] = Crypt_RC4state_map;
+
+static uchar DSAskmap[] = Crypt_SK_DSA_map;
+static uchar DSApkmap[] = Crypt_PK_DSA_map;
+static uchar DSAsigmap[] = Crypt_PKsig_DSA_map;
+static uchar EGskmap[] = Crypt_SK_Elgamal_map;
+static uchar EGpkmap[] = Crypt_PK_Elgamal_map;
+static uchar EGsigmap[] = Crypt_PKsig_Elgamal_map;
+static uchar RSAskmap[] = Crypt_SK_RSA_map;
+static uchar RSApkmap[] = Crypt_PK_RSA_map;
+static uchar RSAsigmap[] = Crypt_PKsig_RSA_map;
+
+static char exBadSK[] = "bad secret key";
+static char exBadPK[] = "bad public key";
+static char exBadBsize[] = "data not multiple of block size";
+static char exBadKey[] = "bad encryption key";
+static char exBadDigest[] = "bad digest value";
+static char exBadIvec[] = "bad ivec";
+static char exBadState[] = "bad encryption state";
+
+/*
+ * these structures reveal the C state of Limbo adts in crypt.m
+ */
+
+typedef struct XDigestState XDigestState;
+typedef struct XAESstate XAESstate;
+typedef struct XDESstate XDESstate;
+typedef struct XIDEAstate XIDEAstate;
+typedef struct XBFstate XBFstate;
+typedef struct XRC4state XRC4state;
+
+/* digest state */
+struct XDigestState
+{
+ Crypt_DigestState x;
+ DigestState state;
+};
+
+/* AES state */
+struct XAESstate
+{
+ Crypt_AESstate x;
+ AESstate state;
+};
+
+/* DES state */
+struct XDESstate
+{
+ Crypt_DESstate x;
+ DESstate state;
+};
+
+/* IDEA state */
+struct XIDEAstate
+{
+ Crypt_IDEAstate x;
+ IDEAstate state;
+};
+
+/* BF state */
+struct XBFstate
+{
+ Crypt_BFstate x;
+ BFstate state;
+};
+
+/* RC4 state */
+struct XRC4state
+{
+ Crypt_RC4state x;
+ RC4state state;
+};
+
+static Crypt_PK*
+newPK(Type *t, int pick)
+{
+ Heap *h;
+ Crypt_PK *sk;
+
+ h = heap(t);
+ sk = H2D(Crypt_PK*, h);
+ sk->pick = pick;
+ return sk;
+}
+
+static Crypt_SK*
+newSK(Crypt_SK** ret, Type *t, int pick)
+{
+ Heap *h;
+ Crypt_SK *sk;
+
+ h = heap(t);
+ sk = H2D(Crypt_SK*, h);
+ sk->pick = pick;
+ if(ret != nil)
+ *ret = sk;
+ switch(pick){
+ case Crypt_PK_RSA:
+ sk->u.RSA.pk = newPK(TPKrsa, Crypt_PK_RSA);
+ break;
+ case Crypt_PK_Elgamal:
+ sk->u.Elgamal.pk = newPK(TPKeg, Crypt_PK_Elgamal);
+ break;
+ case Crypt_PK_DSA:
+ sk->u.DSA.pk = newPK(TPKdsa, Crypt_PK_DSA);
+ break;
+ default:
+ error(exType);
+ }
+ return sk;
+}
+
+static Crypt_PKsig*
+newPKsig(Type *t, int pick)
+{
+ Heap *h;
+ Crypt_PKsig *s;
+
+ h = heap(t);
+ s = H2D(Crypt_PKsig*, h);
+ s->pick = pick;
+ return s;
+}
+
+static IPints_IPint*
+ipcopymp(mpint* b)
+{
+ if(b == nil)
+ return H;
+ return newIPint(mpcopy(b));
+}
+
+/*
+ * digests
+ */
+void
+DigestState_copy(void *fp)
+{
+ F_DigestState_copy *f;
+ Heap *h;
+ XDigestState *ds, *ods;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ if(f->d != H){
+ ods = checktype(f->d, TDigestState, "DigestState", 0);
+ h = heap(TDigestState);
+ ds = H2D(XDigestState*, h);
+ memmove(&ds->state, &ods->state, sizeof(ds->state));
+ *f->ret = (Crypt_DigestState*)ds;
+ }
+}
+
+static Crypt_DigestState*
+crypt_digest_x(Array *buf, int n, Array *digest, int dlen,
Crypt_DigestState *state, DigestState* (*fn)(uchar*, ulong, uchar*,
DigestState*))
+{
+ Heap *h;
+ XDigestState *ds;
+ uchar *cbuf, *cdigest;
+
+ if(buf != H){
+ if(n > buf->len)
+ n = buf->len;
+ cbuf = buf->data;
+ }else{
+ if(n != 0)
+ error(exInval);
+ cbuf = nil;
+ }
+
+ if(digest != H){
+ if(digest->len < dlen)
+ error(exBadDigest);
+ cdigest = digest->data;
+ } else
+ cdigest = nil;
+
+ if(state == H){
+ h = heap(TDigestState);
+ ds = H2D(XDigestState*, h);
+ memset(&ds->state, 0, sizeof(ds->state));
+ } else
+ ds = checktype(state, TDigestState, "DigestState", 1);
+
+ (*fn)(cbuf, n, cdigest, &ds->state);
+
+ return (Crypt_DigestState*)ds;
+}
+
+void
+Crypt_sha1(void *fp)
+{
+ F_Crypt_sha1 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, SHA1dlen, f->state,
sha1);
+}
+
+void
+Crypt_sha224(void *fp)
+{
+ F_Crypt_sha224 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, SHA224dlen, f->state,
sha224);
+}
+
+void
+Crypt_sha256(void *fp)
+{
+ F_Crypt_sha256 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, SHA256dlen, f->state,
sha256);
+}
+
+void
+Crypt_sha384(void *fp)
+{
+ F_Crypt_sha384 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, SHA384dlen, f->state,
sha384);
+}
+
+void
+Crypt_sha512(void *fp)
+{
+ F_Crypt_sha512 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, SHA512dlen, f->state,
sha512);
+}
+
+void
+Crypt_md5(void *fp)
+{
+ F_Crypt_md5 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, MD5dlen, f->state, md5);
+}
+
+void
+Crypt_md4(void *fp)
+{
+ F_Crypt_md4 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+
+ *f->ret = crypt_digest_x(f->buf, f->n, f->digest, MD4dlen, f->state, md4);
+}
+
+static Crypt_DigestState*
+crypt_hmac_x(Array *data, int n, Array *key, Array *digest, int dlen,
Crypt_DigestState *state, DigestState* (*fn)(uchar*, ulong, uchar*, ulong,
uchar*, DigestState*))
+{
+ Heap *h;
+ XDigestState *ds;
+ uchar *cdata, *cdigest;
+
+ if(data != H){
+ if(n > data->len)
+ n = data->len;
+ cdata = data->data;
+ }else{
+ if(n != 0)
+ error(exInval);
+ cdata = nil;
+ }
+
+ if(key == H || key->len > 64)
+ error(exBadKey);
+
+ if(digest != H){
+ if(digest->len < dlen)
+ error(exBadDigest);
+ cdigest = digest->data;
+ } else
+ cdigest = nil;
+
+ if(state == H){
+ h = heap(TDigestState);
+ ds = H2D(XDigestState*, h);
+ memset(&ds->state, 0, sizeof(ds->state));
+ } else
+ ds = checktype(state, TDigestState, "DigestState", 1);
+
+ (*fn)(cdata, n, key->data, key->len, cdigest, &ds->state);
+
+ return (Crypt_DigestState*)ds;
+}
+
+void
+Crypt_hmac_sha1(void *fp)
+{
+ F_Crypt_hmac_sha1 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+ *f->ret = crypt_hmac_x(f->data, f->n, f->key, f->digest, SHA1dlen,
f->state, hmac_sha1);
+}
+
+void
+Crypt_hmac_md5(void *fp)
+{
+ F_Crypt_hmac_md5 *f;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+ *f->ret = crypt_hmac_x(f->data, f->n, f->key, f->digest, MD5dlen,
f->state, hmac_md5);
+}
+
+void
+Crypt_dhparams(void *fp)
+{
+ F_Crypt_dhparams *f;
+ mpint *p, *alpha;
+ void *v;
+
+ f = fp;
+ v = f->ret->t0;
+ f->ret->t0 = H;
+ destroy(v);
+ v = f->ret->t1;
+ f->ret->t1 = H;
+ destroy(v);
+
+ p = mpnew(0);
+ alpha = mpnew(0);
+ release();
+ if(f->nbits == 1024)
+ DSAprimes(alpha, p, nil);
+ else
+ gensafeprime(p, alpha, f->nbits, 0);
+ acquire();
+ f->ret->t0 = newIPint(alpha);
+ f->ret->t1 = newIPint(p);
+}
+
+void
+cryptmodinit(void)
+{
+ ipintsmodinit(); /* TIPint */
+
+ TDigestState = dtype(freeheap, sizeof(XDigestState), DigestStatemap,
sizeof(DigestStatemap));
+ TAESstate = dtype(freeheap, sizeof(XAESstate), AESstatemap,
sizeof(AESstatemap));
+ TDESstate = dtype(freeheap, sizeof(XDESstate), DESstatemap,
sizeof(DESstatemap));
+ TIDEAstate = dtype(freeheap, sizeof(XIDEAstate), IDEAstatemap,
sizeof(IDEAstatemap));
+ TBFstate = dtype(freeheap, sizeof(XBFstate), BFstatemap,
sizeof(BFstatemap));
+ TRC4state = dtype(freeheap, sizeof(XRC4state), RC4statemap,
sizeof(RC4statemap));
+
+ TSKdsa = dtype(freeheap, Crypt_SK_DSA_size, DSAskmap, sizeof(DSAskmap));
+ TPKdsa = dtype(freeheap, Crypt_PK_DSA_size, DSApkmap, sizeof(DSApkmap));
+ TPKsigdsa = dtype(freeheap, Crypt_PKsig_DSA_size, DSAsigmap,
sizeof(DSAsigmap));
+ TSKeg = dtype(freeheap, Crypt_SK_Elgamal_size, EGskmap, sizeof(EGskmap));
+ TPKeg = dtype(freeheap, Crypt_PK_Elgamal_size, EGpkmap, sizeof(EGpkmap));
+ TPKsigeg = dtype(freeheap, Crypt_PKsig_Elgamal_size, EGsigmap,
sizeof(EGsigmap));
+ TSKrsa = dtype(freeheap, Crypt_SK_RSA_size, RSAskmap, sizeof(RSAskmap));
+ TPKrsa = dtype(freeheap, Crypt_PK_RSA_size, RSApkmap, sizeof(RSApkmap));
+ TPKsigrsa = dtype(freeheap, Crypt_PKsig_RSA_size, RSAsigmap,
sizeof(RSAsigmap));
+
+ builtinmod("$Crypt", Cryptmodtab, Cryptmodlen);
+}
+
+void
+Crypt_dessetup(void *fp)
+{
+ F_Crypt_dessetup *f;
+ Heap *h;
+ XDESstate *ds;
+ uchar *ivec;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ if(f->key == H)
+ error(exNilref);
+ if(f->key->len < 8)
+ error(exBadKey);
+ if(f->ivec != H){
+ if(f->ivec->len < 8)
+ error(exBadIvec);
+ ivec = f->ivec->data;
+ }else
+ ivec = nil;
+
+ h = heap(TDESstate);
+ ds = H2D(XDESstate*, h);
+ setupDESstate(&ds->state, f->key->data, ivec);
+
+ *f->ret = (Crypt_DESstate*)ds;
+}
+
+void
+Crypt_desecb(void *fp)
+{
+ F_Crypt_desecb *f;
+ XDESstate *ds;
+ int i;
+ uchar *p;
+
+ f = fp;
+
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ if(f->n & 7)
+ error(exBadBsize);
+
+ ds = checktype(f->state, TDESstate, exBadState, 0);
+ p = f->buf->data;
+
+ for(i = 8; i <= f->n; i += 8, p += 8)
+ block_cipher(ds->state.expanded, p, f->direction);
+}
+
+void
+Crypt_descbc(void *fp)
+{
+ F_Crypt_descbc *f;
+ XDESstate *ds;
+ uchar *p, *ep, *ip, *p2, *eip;
+ uchar tmp[8];
+
+ f = fp;
+
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ if(f->n & 7)
+ error(exBadBsize);
+
+ ds = checktype(f->state, TDESstate, exBadState, 0);
+ p = f->buf->data;
+
+ if(f->direction == 0){
+ for(ep = p + f->n; p < ep; p += 8){
+ p2 = p;
+ ip = ds->state.ivec;
+ for(eip = ip+8; ip < eip; )
+ *p2++ ^= *ip++;
+ block_cipher(ds->state.expanded, p, 0);
+ memmove(ds->state.ivec, p, 8);
+ }
+ } else {
+ for(ep = p + f->n; p < ep; ){
+ memmove(tmp, p, 8);
+ block_cipher(ds->state.expanded, p, 1);
+ p2 = tmp;
+ ip = ds->state.ivec;
+ for(eip = ip+8; ip < eip; ){
+ *p++ ^= *ip;
+ *ip++ = *p2++;
+ }
+ }
+ }
+}
+
+void
+Crypt_ideasetup(void *fp)
+{
+ F_Crypt_ideasetup *f;
+ Heap *h;
+ XIDEAstate *is;
+ uchar *ivec;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ if(f->key == H)
+ error(exNilref);
+ if(f->key->len < 16)
+ error(exBadKey);
+ if(f->ivec != H){
+ if(f->ivec->len < 8)
+ error(exBadIvec);
+ ivec = f->ivec->data;
+ }else
+ ivec = nil;
+
+ h = heap(TIDEAstate);
+ is = H2D(XIDEAstate*, h);
+
+ setupIDEAstate(&is->state, f->key->data, ivec);
+
+ *f->ret = (Crypt_IDEAstate*)is;
+}
+
+void
+Crypt_ideaecb(void *fp)
+{
+ F_Crypt_ideaecb *f;
+ XIDEAstate *is;
+ int i;
+ uchar *p;
+
+ f = fp;
+
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ if(f->n & 7)
+ error(exBadBsize);
+
+ is = checktype(f->state, TIDEAstate, exBadState, 0);
+ p = f->buf->data;
+
+ for(i = 8; i <= f->n; i += 8, p += 8)
+ idea_cipher(is->state.edkey, p, f->direction);
+}
+
+void
+Crypt_ideacbc(void *fp)
+{
+ F_Crypt_ideacbc *f;
+ XIDEAstate *is;
+ uchar *p, *ep, *ip, *p2, *eip;
+ uchar tmp[8];
+
+ f = fp;
+
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ if(f->n & 7)
+ error(exBadBsize);
+
+ is = checktype(f->state, TIDEAstate, exBadState, 0);
+ p = f->buf->data;
+
+ if(f->direction == 0){
+ for(ep = p + f->n; p < ep; p += 8){
+ p2 = p;
+ ip = is->state.ivec;
+ for(eip = ip+8; ip < eip; )
+ *p2++ ^= *ip++;
+ idea_cipher(is->state.edkey, p, 0);
+ memmove(is->state.ivec, p, 8);
+ }
+ } else {
+ for(ep = p + f->n; p < ep; ){
+ memmove(tmp, p, 8);
+ idea_cipher(is->state.edkey, p, 1);
+ p2 = tmp;
+ ip = is->state.ivec;
+ for(eip = ip+8; ip < eip; ){
+ *p++ ^= *ip;
+ *ip++ = *p2++;
+ }
+ }
+ }
+}
+
+void
+Crypt_aessetup(void *fp)
+{
+ F_Crypt_aessetup *f;
+ Heap *h;
+ XAESstate *is;
+ uchar *ivec;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ if(f->key == H)
+ error(exNilref);
+ if(f->key->len != 16 && f->key->len != 24 && f->key->len != 32)
+ error(exBadKey);
+ if(f->ivec != H){
+ if(f->ivec->len < AESbsize)
+ error(exBadIvec);
+ ivec = f->ivec->data;
+ }else
+ ivec = nil;
+
+ h = heap(TAESstate);
+ is = H2D(XAESstate*, h);
+
+ setupAESstate(&is->state, f->key->data, f->key->len, ivec);
+
+ *f->ret = (Crypt_AESstate*)is;
+}
+
+void
+Crypt_aescbc(void *fp)
+{
+ F_Crypt_aescbc *f;
+ XAESstate *is;
+ uchar *p;
+
+ f = fp;
+
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+
+ is = checktype(f->state, TAESstate, exBadState, 0);
+ p = f->buf->data;
+
+ if(f->direction == 0)
+ aesCBCencrypt(p, f->n, &is->state);
+ else
+ aesCBCdecrypt(p, f->n, &is->state);
+}
+
+void
+Crypt_blowfishsetup(void *fp)
+{
+ F_Crypt_blowfishsetup *f;
+ Heap *h;
+ XBFstate *is;
+ uchar *ivec;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ if(f->key == H)
+ error(exNilref);
+ if(f->key->len <= 0)
+ error(exBadKey);
+ if(f->ivec != H){
+ if(f->ivec->len != BFbsize)
+ error(exBadIvec);
+ ivec = f->ivec->data;
+ }else
+ ivec = nil;
+
+ h = heap(TBFstate);
+ is = H2D(XBFstate*, h);
+
+ setupBFstate(&is->state, f->key->data, f->key->len, ivec);
+
+ *f->ret = (Crypt_BFstate*)is;
+}
+
+void
+Crypt_blowfishcbc(void *fp)
+{
+ F_Crypt_blowfishcbc *f;
+ XBFstate *is;
+ uchar *p;
+
+ f = fp;
+
+ if(f->state == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ if(f->n & 7)
+ error(exBadBsize);
+
+ is = checktype(f->state, TBFstate, exBadState, 0);
+ p = f->buf->data;
+
+ if(f->direction == 0)
+ bfCBCencrypt(p, f->n, &is->state);
+ else
+ bfCBCdecrypt(p, f->n, &is->state);
+}
+
+void
+Crypt_rc4setup(void *fp)
+{
+ F_Crypt_rc4setup *f;
+ Heap *h;
+ XRC4state *is;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ if(f->seed == H)
+ error(exNilref);
+
+ h = heap(TRC4state);
+ is = H2D(XRC4state*, h);
+
+ setupRC4state(&is->state, f->seed->data, f->seed->len);
+
+ *f->ret = (Crypt_RC4state*)is;
+}
+
+void
+Crypt_rc4(void *fp)
+{
+ F_Crypt_rc4 *f;
+ XRC4state *is;
+ uchar *p;
+
+ f = fp;
+ if(f->buf == H)
+ return;
+ if(f->n < 0 || f->n > f->buf->len)
+ error(exBounds);
+ is = checktype(f->state, TRC4state, exBadState, 0);
+ p = f->buf->data;
+ rc4(&is->state, p, f->n);
+}
+
+void
+Crypt_rc4skip(void *fp)
+{
+ F_Crypt_rc4skip *f;
+ XRC4state *is;
+
+ f = fp;
+ is = checktype(f->state, TRC4state, exBadState, 0);
+ rc4skip(&is->state, f->n);
+}
+
+void
+Crypt_rc4back(void *fp)
+{
+ F_Crypt_rc4back *f;
+ XRC4state *is;
+
+ f = fp;
+ is = checktype(f->state, TRC4state, exBadState, 0);
+ rc4back(&is->state, f->n);
+}
+
+/*
+ * public/secret keys, signing and verifying
+ */
+
+/*
+ * DSA
+ */
+
+static void
+dsapk2pub(DSApub* p, Crypt_PK* pk)
+{
+ if(pk == H)
+ error(exNilref);
+ if(pk->pick != Crypt_PK_DSA)
+ error(exType);
+ p->p = MPX(pk->u.DSA.p);
+ p->q = MPX(pk->u.DSA.q);
+ p->alpha = MPX(pk->u.DSA.alpha);
+ p->key = MPX(pk->u.DSA.key);
+}
+
+static void
+dsask2priv(DSApriv* p, Crypt_SK* sk)
+{
+ if(sk == H)
+ error(exNilref);
+ if(sk->pick != Crypt_SK_DSA)
+ error(exType);
+ dsapk2pub(&p->pub, sk->u.DSA.pk);
+ p->secret = MPX(sk->u.DSA.secret);
+}
+
+static void
+dsapriv2sk(Crypt_SK* sk, DSApriv* p)
+{
+ Crypt_PK *pk;
+
+ pk = sk->u.DSA.pk;
+ pk->u.DSA.p = ipcopymp(p->pub.p);
+ pk->u.DSA.q = ipcopymp(p->pub.q);
+ pk->u.DSA.alpha = ipcopymp(p->pub.alpha);
+ pk->u.DSA.key = ipcopymp(p->pub.key);
+ sk->u.DSA.secret = ipcopymp(p->secret);
+}
+
+static void
+dsaxgen(Crypt_SK* sk, DSApub* oldpk)
+{
+ DSApriv *p;
+
+ release();
+ p = dsagen(oldpk);
+ acquire();
+ dsapriv2sk(sk, p);
+ dsaprivfree(p);
+}
+
+void
+Crypt_dsagen(void *fp)
+{
+ F_Crypt_dsagen *f;
+ Crypt_SK *sk;
+ DSApub pub, *oldpk;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ sk = newSK(f->ret, TSKdsa, Crypt_SK_DSA);
+ oldpk = nil;
+ if(f->oldpk != H && f->oldpk->pick == Crypt_PK_DSA){
+ dsapk2pub(&pub, f->oldpk);
+ oldpk = &pub;
+ }
+ dsaxgen(sk, oldpk);
+}
+
+/*
+ * Elgamal
+ */
+
+static void
+egpk2pub(EGpub* p, Crypt_PK* pk)
+{
+ if(pk == H)
+ error(exNilref);
+ if(pk->pick != Crypt_PK_Elgamal)
+ error(exType);
+ p->p = MPX(pk->u.Elgamal.p);
+ p->alpha = MPX(pk->u.Elgamal.alpha);
+ p->key = MPX(pk->u.Elgamal.key);
+}
+
+static void
+egsk2priv(EGpriv* p, Crypt_SK* sk)
+{
+ if(sk == H)
+ error(exNilref);
+ if(sk->pick != Crypt_SK_Elgamal)
+ error(exType);
+ egpk2pub(&p->pub, sk->u.Elgamal.pk);
+ p->secret = MPX(sk->u.Elgamal.secret);
+}
+
+static void
+egpriv2sk(Crypt_SK* sk, EGpriv* p)
+{
+ Crypt_PK* pk;
+
+ pk = sk->u.Elgamal.pk;
+ pk->u.Elgamal.p = ipcopymp(p->pub.p);
+ pk->u.Elgamal.alpha = ipcopymp(p->pub.alpha);
+ pk->u.Elgamal.key = ipcopymp(p->pub.key);
+ sk->u.Elgamal.secret = ipcopymp(p->secret);
+}
+
+static void
+egxgen(Crypt_SK* sk, int nlen, int nrep)
+{
+ EGpriv *p;
+
+ release();
+ for(;;){
+ p = eggen(nlen, nrep);
+ if(mpsignif(p->pub.p) == nlen)
+ break;
+ egprivfree(p);
+ }
+ acquire();
+ egpriv2sk(sk, p);
+ egprivfree(p);
+}
+
+
+void
+Crypt_eggen(void *fp)
+{
+ F_Crypt_eggen *f;
+ Crypt_SK *sk;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ sk = newSK(f->ret, TSKeg, Crypt_SK_Elgamal);
+ egxgen(sk, f->nlen, f->nrep);
+}
+
+/*
+ * RSA
+ */
+
+static void
+rsapk2pub(RSApub* p, Crypt_PK* pk)
+{
+ if(pk == H)
+ error(exNilref);
+ if(pk->pick != Crypt_PK_RSA)
+ error(exType);
+ p->n = MPX(pk->u.RSA.n);
+ p->ek = MPX(pk->u.RSA.ek);
+}
+
+static void
+rsask2priv(RSApriv* p, Crypt_SK* sk)
+{
+ if(sk == H)
+ error(exNilref);
+ if(sk->pick != Crypt_SK_RSA)
+ error(exType);
+ rsapk2pub(&p->pub, sk->u.RSA.pk);
+ p->dk = MPX(sk->u.RSA.dk);
+ p->p = MPX(sk->u.RSA.p);
+ p->q = MPX(sk->u.RSA.q);
***The diff for this file has been truncated for email.***
=======================================
--- /dev/null
+++ /libinterp/ipint.h Tue Aug 10 15:06:28 2010
@@ -0,0 +1,12 @@
+typedef struct IPint IPint;
+
+#pragma incomplete IPint
+
+//Keyring_IPint* newIPint(mpint*);
+void* newIPint(mpint*);
+//mpint* checkIPint(Keyring_IPint*);
+mpint* checkIPint(void*);
+void freeIPint(Heap*, int);
+void ipintsmodinit(void);
+
+extern Type* TIPint;
=======================================
--- /dev/null
+++ /libinterp/keyringif.m Tue Aug 10 15:06:28 2010
@@ -0,0 +1,4 @@
+# temporary hack to prevent clashes with DigestState
+include "sys.m";
+
+include "keyring.m";
=======================================
--- /dev/null
+++ /man/2/crypt-0intro Tue Aug 10 15:06:28 2010
@@ -0,0 +1,98 @@
+.TH CRYPT-INTRO 2
+.SH NAME
+Crypt intro \- introduction to the
+.B Crypt
+cryptography
+module
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+.EE
+.SH DESCRIPTION
+.B Crypt
+contains a mixed set of functions that variously:
+.IP \(bu
+form cryptographically secure digests; see
+.IR crypt-sha1 (2)
+.IP \(bu
+generate public/private key pairs; see
+.IR crypt-gensk (2)
+.IP \(bu
+encrypt data, using AES, DES, or IDEA; see
+.IR crypt-crypt (2)
+.IP \(bu
+create and verify cryptographic signatures using the
+public keys; see
+.IR crypt-sign (2)
+.SS "Public Key Cryptography"
+Public key cryptography has many uses.
+Inferno relies on it only for digital signatures.
+The private key may be used to digitally
+sign data, the public one to verify the signature.
+.PP
+Inferno provides three data types to represent the different components of
the public key signature scheme.
+The
+.B PK
+adt contains the data necessary to construct a public key;
+the
+.B SK
+adt contains the data necessary to construct a secret key.
+A key contains the public or secret parameters for the signature algorithm
specified by the adt's pick tag.
+Ownership of a key is not recorded in the key value itself but in a
separate certificate.
+Finally,
+the
+.B PKsig
+adt contains one or more values representing a given form of digital
signature.
+.PP
+Certificates and indeed signature representations are varied, and
implemented by other modules.
+.SS "Large Precision Arithmetic"
+Many
+.B Crypt
+operations require integers much larger than
+.B int
+or
+.BR big .
+It therefore uses the multiple-precision package
+.IR ipints (2).
+That module's
+.B IPint
+adt
+stands for infinite precision integer, though, for
+space considerations, our
+implementation limits the maximum integer to
+2\u\s-2\&8192\s0\d-1.
+.PP
+An
+.B IPint
+can be converted into two external formats.
+The first is
+an array of bytes in which the first byte is the highest order
+byte of the integer. This format is useful when
+communicating with the
+.IR ssl (3)
+device.
+The second is similar but represents the array of bytes as text, using
either base 16 or a MIME base 64 format,
+allowing
+.BR IPint s
+to be stored in files or transmitted across
+networks in a human readable form.
+.SH SOURCE
+.br
+.B /libinterp/crypt.c
+.br
+.B /libinterp/ipint.c
+.br
+.B /libmp
+.br
+.B /libsec
+.SH SEE ALSO
+.IR security-intro (2)
+.br
+B. Schneier,
+.IR "Applied Cryptography" ,
+1996, J. Wiley & Sons, Inc.
=======================================
--- /dev/null
+++ /man/2/crypt-crypt Tue Aug 10 15:06:28 2010
@@ -0,0 +1,142 @@
+.TH CRYPT-CRYPT 2
+.SH NAME
+crypt: aessetup, aescbc, dessetup, descbc, desecb, ideasetup, ideacbc,
ideaecb \- data encryption
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+
+Encrypt: con 0;
+Decrypt: con 1;
+
+AESbsize: con 16;
+
+aessetup: fn(key: array of byte, ivec: array of byte): ref AESstate;
+aescbc: fn(state: ref AESstate, buf: array of byte,
+ n: int, direction: int);
+
+BFbsize: con 8;
+
+blowfishsetup: fn(key: array of byte, ivec: array of byte): ref BFstate;
+blowfishcbc: fn(state: ref BFstate, buf: array of byte,
+ n: int, direction: int);
+
+DESbsize: con 8;
+
+dessetup: fn(key: array of byte, ivec: array of byte): ref DESstate;
+descbc: fn(state: ref DESstate, buf: array of byte,
+ n: int, direction: int);
+desecb: fn(state: ref DESstate, buf: array of byte,
+ n: int, direction: int);
+
+IDEAbsize: con 8;
+
+ideasetup: fn(key: array of byte, ivec: array of byte): ref IDEAstate;
+ideacbc: fn(state: ref IDEAstate, buf: array of byte,
+ n: int, direction: int);
+ideaecb: fn(state: ref IDEAstate, buf: array of byte,
+ n: int, direction: int);
+.EE
+.SH DESCRIPTION
+These functions encrypt and decrypt blocks of data using different
+encryption algorithms.
+The interfaces are similar.
+.PP
+Each algorithm has an adt that holds the current state for a given
encryption.
+It is produced by the setup function for the algorithm,
+.IB alg setup ,
+which is given a secret
+.I key
+and an initialisation vector
+.IR ivec .
+A sequence of blocks of data can then be encrypted or decrypted by
repeatedly calling
+.IB alg cbc
+(for `cipher block chaining'), or
+.IB alg ebc
+(the less secure `electronic code book', if provided).
+On each call,
+.I buf
+provides
+.I n
+bytes of the data to encrypt or decrypt.
+.I N
+must be a multiple of the encryption block size
+.IB ALG bsize .
+Exceptionally,
+.B aescbc
+allows
+.I n
+to be other than a multiple of
+.B AESbsize
+in length, but then
+for successful decryption, the decryptor must use the same
+sequence of buffer sizes as the encryptor.
+.I Direction
+is the constant
+.B Encrypt
+or
+.B Decrypt
+as required.
+.I State
+maintains the encryption state, initially produced by the setup function,
+and updated as each buffer is encrypted or decrypted.
+.PP
+The algorithms currently available are:
+.TP
+.B aes
+The Advanced Encryption Standard, AES (also known as Rijndael).
+The
+.I key
+should be 16, 24 or 32 bytes long (128, 192 or 256 bits).
+.I Ivec
+should be
+.B AESbsize
+bytes of random data: random enough to be unlikely to be reused but
+not cryptographically strongly unpredictable.
+.TP
+.B blowfish
+Bruce Schneier's symmetric block cipher.
+The
+.I key
+is any length from 4 to 56 bytes.
+.I Ivec
+if non-nil is
+.B BFbsize
+bytes of random data.
+For
+.BR blowfishcbc ,
+.I n
+must be a multiple of
+.BR BFbsize .
+.TP
+.B des
+The older Data Encryption Standard, DES.
+.I Key
+is 8 bytes (64 bits), containing a 56-bit key
+encoded into 64 bits where every eighth bit is parity.
+.I Ivec
+is
+.B DESbsize
+bytes of random data.
+.TP
+.B idea
+The International Data Encryption Standard, IDEA™.
+The
+.I key
+is 16 bytes long (128 bits).
+.I Ivec
+is
+.B IDEAbsize
+bytes of random data.
+.SH SEE ALSO
+.IR crypt-intro (2),
+.IR crypt-rc4 (2),
+.IR security-random (2)
+.PP
+IDEA was patented by Ascom-Tech AG (EP 0 482 154 B1, US005214703),
+currently held by iT_SEC Systec Ltd.
+At time of writing, there was no licence fee required for noncommercial use
+but check
+the current licensing policy of iT_SEC Systec Ltd,
+especially for commercial use.
=======================================
--- /dev/null
+++ /man/2/crypt-dsagen Tue Aug 10 15:06:28 2010
@@ -0,0 +1,94 @@
+.TH CRYPT-DSAGEN 2
+.SH NAME
+crypt: dsagen, eggen, rsagen, rsafill, rsaencrypt, rsadecrypt \- specific
public key systems
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+
+dsagen: fn(oldpk: ref PK.DSA): ref SK.DSA;
+
+eggen: fn(nlen: int, nrep: int): ref SK.Elgamal;
+
+rsagen: fn(nlen: int, elen: int, nrep: int): ref SK.RSA;
+rsafill: fn(n: ref IPint, ek: ref IPint, dk: ref IPint,
+ p: ref IPint, q: ref IPint): ref SK.RSA;
+rsaencrypt: fn(k: ref PK.RSA, m: ref IPint): ref IPint;
+rsadecrypt: fn(k: ref SK.RSA, m: ref IPint): ref IPint;
+.EE
+.SH DESCRIPTION
+.IR Crypt-gensk (2)
+describes a set of functions that generate public/private key pairs given
an algorithm name
+and a key length.
+Some key types allow further parameters for key generation or support
further operations.
+.PP
+.B Dsagen
+generates a DSA public/private key pair, represented by the pick adt
+.BR SK.DSA ,
+and compatible with the containing type
+.BR SK .
+If the parameter
+.B oldpk
+is not nil,
+.B dsagen
+takes the new key's modulus and group order from the existing key;
+otherwise it generates a new pair of primes.
+.PP
+.B Eggen
+generates a new El-Gamal key pair, represented by the pick adt
+.BR SK.Elgamal .
+.I Nlen
+is the length of the modulus;
+.I nrep
+is the number of repetitions of the Miller-Rabin primality test (0 gives
the default, currently 18).
+.PP
+.B Rsagen
+generates an RSA public/private key pair, represented by the pick adt
+.BR SK.RSA ,
+and compatible with the containing type
+.BR SK .
+.I Nlen
+gives the length of the key modulus in bits;
+.I elen
+gives the exponent length in bits; and
+.I nrep
+is as above.
+.PP
+The RSA private key representation used by Inferno includes some extra
values to speed computation.
+.B Rsagen
+provides those values but keys imported from other systems might not.
+Given the essential set of RSA private key parameters for a given key,
represented as IPints,
+.B rsafill
+returns a suitable
+.B SK.RSA
+for that key, including the extra values.
+.PP
+The public key of type
+.B PK.RSA
+can be extracted from a given private key value
+.I sk
+by referencing the field
+.BI sk .pk .
+.PP
+.B Rsaencrypt
+encrypts a message
+.IR m ,
+represented by an IPint,
+using the public key
+.IR pk .
+.PP
+.B Rsadecrypt
+decrypts
+.I m
+using private key
+.IR sk .
+The result is again returned as an IPint.
+.SH SEE ALSO
+.IR crypt-gensk (2),
+.IR crypt-sha1 (2),
+.IR security-auth (2),
+.IR security-oldauth (2)
=======================================
--- /dev/null
+++ /man/2/crypt-gensk Tue Aug 10 15:06:28 2010
@@ -0,0 +1,159 @@
+.TH CRYPT-GENSK 2
+.SH NAME
+crypt: genSK, genSKfromPK, sktopk, dhparams, sign, verify \- generate keys
and digital signatures
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+
+PK: adt
+{
+ pick {
+ RSA =>
+ n: ref IPint; # modulus
+ ek: ref IPint; # exp (encryption key)
+ Elgamal =>
+ p: ref IPint; # modulus
+ alpha: ref IPint; # generator
+ key: ref IPint; # encryption key (alpha**secret mod p)
+ DSA =>
+ p: ref IPint; # modulus
+ q: ref IPint; # group order, q divides p-1
+ alpha: ref IPint; # group generator
+ key: ref IPint; # encryption key (alpha**secret mod p)
+ }
+};
+
+SK: adt
+{
+ pick {
+ RSA =>
+ pk: ref PK.RSA;
+ dk: ref IPint; # exp (decryption key)
+ p: ref IPint; # q in pkcs
+ q: ref IPint; # p in pkcs
+ # precomputed crt values
+ kp: ref IPint; # k mod p-1
+ kq: ref IPint; # k mod q-1
+ c2: ref IPint; # for converting residues to number
+ Elgamal =>
+ pk: ref PK.Elgamal;
+ secret: ref IPint; # decryption key
+ DSA =>
+ pk: ref PK.DSA;
+ secret: ref IPint; # decryption key
+ }
+};
+
+PKsig: adt
+{
+ pick {
+ RSA =>
+ n: ref IPint;
+ Elgamal =>
+ r: ref IPint;
+ s: ref IPint;
+ DSA =>
+ r: ref IPint;
+ s: ref IPint;
+ }
+};
+
+genSK: fn(algname: string, length: int): ref SK;
+genSKfromPK: fn(pk: ref PK): ref SK;
+sktopk: fn(sk: ref SK): ref PK;
+
+sign: fn(sk: ref SK, m: ref IPint): ref PKsig;
+verify: fn(pk: ref PK, sig: ref PKsig, m: ref IPint): int;
+
+dhparams: fn(nbits: int): (ref IPint, ref IPint);
+.EE
+.SH DESCRIPTION
+.B Crypt
+implements a set of public-key signature algorithms.
+The public/private key pairs are represented by values of the adt
+.BR SK ,
+containing both the private (secret) and public parts of the pair,
+and
+.BR PK ,
+containing only the public part.
+The several algorithms are represented by different pick variants.
+.PP
+.B GenSK
+generates a new public/private key pair, represented by
+.BR SK .
+.I Algname
+is the name of the algorithm to use; in the current implementation,
+.BR dsa ,
+.B elgamal
+and
+.B rsa
+are possible.
+.I Length
+gives the length of the key modulus in bits.
+.B GenSK
+returns nil if an unknown algorithm has been specified.
+.PP
+.B GenSKfromPK
+generates a private key that has the system parameters as the public key
+.IR pk .
+It is used to generate new keys that are of the same complexity as old
keys.
+.PP
+.B Sktopk
+returns a reference to the public part of private key
+.IR sk .
+.PP
+.B Sign
+creates a digital signature of a message
+.IR m ,
+represented by an IPint,
+using the private key
+.IR sk .
+Typically
+.I m
+represents a secure hash (eg, using
+.IR crypt-sha1 (2))
+of a much larger message.
+.PP
+.B Verify
+uses public key
+.I pk
+to verify that the value
+.I sig
+is a digital signature of the message
+.I m
+using the private key corresponding to
+.IR pk .
+It returns non-zero (true) if the signature is valid; zero (false)
otherwise.
+.PP
+Most applications use generic operations on public and private keys,
+referring to
+.B PK
+and
+.BR SK ,
+but specific variants can be named, such as
+.BR PK.RSA
+for RSA keys, allowing use of RSA-specific operations.
+.IR Crypt-dsagen (2)
+describes functions for key generation that are specific to various
algorithms,
+using algorithm-specific parameters.
+.PP
+.B Dhparams
+creates Diffie-Hellman parameters. It returns
+a tuple of IPints
+.RI ( alpha , p ).
+.I P
+is an
+.I nbits
+long prime number that serves as the modulus.
+.I Alpha
+is a primitive root in the integer field defined by that modulus.
+.SH SEE ALSO
+.IR crypt-dsagen (2),
+.IR crypt-sha1 (2),
+.IR security-auth (2),
+.IR security-oldauth (2)
=======================================
--- /dev/null
+++ /man/2/crypt-rc4 Tue Aug 10 15:06:28 2010
@@ -0,0 +1,49 @@
+.TH CRYPT-RC4 2
+.SH NAME
+crypt: rc4setup, rc4, rc4skip, rc4back \- RC4 encryption
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+
+rc4setup: fn(seed: array of byte): ref RC4state;
+rc4: fn(state: ref RC4state, buf: array of byte, n: int);
+rc4skip: fn(state: ref RC4state, n: int);
+rc4back: fn(state: ref RC4state, n: int);
+.EE
+.SH DESCRIPTION
+These functions implement the stream encryption algorithm that is claimed
to
+be equivalent to RSA Security's RC4.
+It is a pseudo-random number generator with a 256
+byte state and a long cycle.
+.PP
+.B Rc4setup
+sets the initial
+.IR seed ,
+which can be any non-zero length, and
+returns a representation of the initial state of the algorithm,
+which is used in subsequent calls.
+.PP
+.B Rc4
+runs the generator starting with the given
+.IR state ,
+and XORs the output of the generator with
+the first
+.I n
+bytes of
+.IR buf ,
+updating the
+.IR state .
+.B Rc4
+is symmetric and is used both to encrypt and decrypt.
+.B Rc4skip
+skips over bytes (eg, to account for lost transmissions);
+.B rc4back
+runs the generator backwards (eg, to account for retransmissions).
+.SH SEE ALSO
+.IR crypt-intro (2),
+.IR crypt-crypt (2)
=======================================
--- /dev/null
+++ /man/2/crypt-sha1 Tue Aug 10 15:06:28 2010
@@ -0,0 +1,144 @@
+.TH CRYPT-SHA1 2
+.SH NAME
+crypt: sha1, sha224, sha256, sha384, sha512, md4, md5, hmac_sha1, hmac_md5
\- cryptographic digests
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+include "crypt.m";
+crypt := load Crypt Crypt->PATH;
+
+DigestState: adt
+{
+ # hidden state
+ copy: fn(d: self ref DigestState): ref DigestState;
+};
+
+.ta \w'verify:\ 'u +\w'fn(\ \ \ 'u
+sha1: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+sha224: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+sha256: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+sha384: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+sha512: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+md4: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+md5: fn(buf: array of byte, n: int, digest: array of byte,
+ state: ref DigestState): ref DigestState;
+
+SHA1dlen, SHA224dlen, SHA256dlen, SHA384dlen, SHA512dlen, MD4dlen,
MD5dlen: con ...;
+
+hmac_sha1: fn(buf: array of byte, n: int, key: array of byte,
+ digest: array of byte,
+ state: ref DigestState): ref DigestState;
+hmac_md5: fn(buf: array of byte, n: int, key: array of byte,
+ digest: array of byte,
+ state: ref DigestState): ref DigestState;
+.EE
+.SH DESCRIPTION
+.BR Sha1 ,
+.BR sha224 ,
+.BR sha256 ,
+.BR sha384 ,
+.BR sha512 ,
+.B md4
+and
+.B md5
+are cryptographically secure hash functions that produce output called a
message digest.
+Each function computes a hash of
+.I n
+bytes of the data in
+.IR buf ,
+using the named algorithm,
+and updates the current
+.IR state .
+They can be called iteratively to form a single digest for many data
blocks.
+The state is kept in the
+.B DigestState
+value referenced by
+.I state
+between calls.
+.I State
+should be
+.B nil
+on the first call, and a newly allocated
+.B DigestState
+will be returned for use in subsequent calls.
+On a call in which
+.I digest
+is not
+.BR nil ,
+the hash is completed and copied into the
+.I digest
+array.
+.B Sha1
+produces a 20-byte hash
+.RB ( SHA1dlen ),
+.B sha224
+a 28-byte hash
+.RB ( SHA224dlen ),
+.B sha256
+a 32-byte hash
+.RB ( SHA256dlen ),
+.B sha384
+a 48-byte hash
+.RB ( SHA384dlen ),
+.B sha256
+a 64-byte hash
+.RB ( SHA512dlen ),
+.B md4
+and
+.B md5
+a 16-byte one
+.RB ( MD4len
+and
+.BR MD5len ).
+.PP
+.B Hmac_sha1
+and
+.B hmac_md5
+are keyed versions of the hashing functions, following Internet RFC2104.
+The
+.I key
+must be provided in each call, but otherwise
+the calling conventions are those of
+.BR sha1 .
+The
+.I key
+must currently be no more than 64 bytes.
+.PP
+.B DigestState
+hides the state of partially completed hash functions during processing.
+Its
+.B copy
+operation returns a reference to a new copy of a given state.
+.SH EXAMPLES
+A program to read a file and hash it using SHA might contain the following
inner loop:
+.IP
+.EX
+state: ref DigestState = nil;
+while((n := sys->read(fd, buf, len buf)) > 0)
+ state = kr->sha1(buf, n, nil, state);
+digest := array[kr->SHA1dlen] of byte;
+kr->sha1(buf, 0, digest, state);
+.EE
+.SH SOURCE
+.B /libinterp/crypt.c
+.br
+.B /libsec/port/hmac.c
+.br
+.B /libsec/port/md4.c
+.br
+.B /libsec/port/md5.c
+.br
+.B /libsec/port/sha1.c
+.SH BUGS
+The MD4 algorithm is included only to allow communication with software
+that might still use it; it should not otherwise be used now, because it
+is easily broken.
=======================================
--- /dev/null
+++ /man/2/ipints Tue Aug 10 15:06:28 2010
@@ -0,0 +1,193 @@
+.TH IPINTS 2
+.SH NAME
+ipints: IPint \- `infinite' precision integer utility functions
+.SH SYNOPSIS
+.EX
+include "ipints.m"
+ipints:= load IPints IPints->PATH;
+
+IPint: adt
+{
+ iptob64: fn(i: self ref IPint): string;
+ iptob64z: fn(i: self ref IPint): string;
+ b64toip: fn(str: string) : ref IPint;
+ iptobytes: fn(i: self ref IPint): array of byte;
+ bytestoip: fn(buf: array of byte): ref IPint;
+ iptobebytes: fn(i: self ref IPint): array of byte;
+ bebytestoip: fn(buf: array of byte): ref IPint;
+ inttoip: fn(i: int): ref IPint;
+ iptoint: fn(i: self ref IPint): int;
+ iptostr: fn(i: self ref IPint, base: int): string;
+ strtoip: fn(str: string, base: int): ref IPint;
+ random: fn(nbits: int): ref IPint;
+ copy: fn(i: self ref IPint): ref IPint;
+ bits: fn(i: self ref IPint): int;
+ expmod: fn(base: self ref IPint, exp, mod: ref IPint):ref IPint;
+ add: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ sub: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ neg: fn(i: self ref IPint): ref IPint;
+ mul: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ div: fn(i1: self ref IPint, i2: ref IPint): (ref IPint, ref IPint);
+ mod: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ eq: fn(i1: self ref IPint, i2: ref IPint): int;
+ cmp: fn(i1: self ref IPint, i2: ref IPint): int;
+ shl: fn(i: self ref IPint, n: int): ref IPint;
+ shr: fn(i: self ref IPint, n: int): ref IPint;
+ and: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ ori: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ not: fn(i: self ref IPint): ref IPint;
+ xor: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+};
+.EE
+.SH DESCRIPTION
+.B IPint
+provides the following arbitrary-length integer manipulation functions
required for cryptographic support in Limbo:
+.TP
+.IB i .iptob64()
+Returns a string that represents a large integer textually in base 64 for
convenient transmission over a network connection.
+.TP
+.IB i .iptob64z()
+Returns a similar representation to
+.B iptob64
+but ensures that the top bit of the received value is zero.
+.TP
+.BI b64toip( str )
+Returns the
+.B IPint
+represented by the base-64 encoded
+.IR str .
+.TP
+.IB i .iptobytes()
+Returns an array of bytes representing a large integer. The representation
includes both positive and negative numbers.
+.TP
+.BI bytestoip( buf )
+The inverse operation of
+.BR iptobytes .
+.TP
+.IB i .iptobebytes()
+Returns an array of bytes in big-endian format representing the magnitude
of a large integer; used for instance to pass a value to
+.IR ssl (3).
+Only non-negative numbers are represented.
+.TP
+.BI bebytestoip( buf )
+The inverse operation of
+.BR iptobebytes .
+.TP
+.BI inttoip( i )
+Creates a new large integer from integer
+.IR i .
+.TP
+.IB i .iptoint()
+Converts a large integer
+.I i
+to an
+.BR int ;
+returns 0 on error.
+.TP
+.IB i .iptostr( base )
+Converts a large integer to a string in base
+.IR base ;
+returns nil on error.
+Only the bases 10, 16, 32, and 64 are
+supported. Anything else defaults to 16.
+.TP
+.BI strtoip( str , base )
+Converts a string
+.I str
+representing a number in in base
+.I base
+to a large integer; returns nil on error.
+Only the bases 10, 16, 32, and 64 are
+supported.
+.TP
+.BI random( nbits )
+Returns a large random number of length at most
+.IR minbits .
+The largest number allowed in the current implementation is
+2^8192-1 .
+The seed for the generator is obtained by duelling clocks.
+.TP
+.IB i .copy()
+Returns a reference to the same value as
+.IR i .
+.TP
+.IB i .bits()
+Returns the number of bits of precision of
+.IR i .
+.TP
+.IB base .expmod( "exp , mod" )
+Returns
+.BI ( base ** exp ") mod " mod.
+.TP
+.IB i1 .add( i2 )
+Returns
+.RI ( i1 + i2 ).
+.TP
+.IB i1 .sub( i2 )
+Returns
+.RI ( i1 - i2 ).
+.TP
+.IB i1 .mul ( i2 )
+Returns
+.IR i1*i2 .
+.TP
+.IB i1 .div ( i2 )
+Returns
+.RI ( i1 / i2,
+.IR i1 rem i2 ).
+.TP
+.IB i1 .mod ( i2 )
+Returns
+.RI ( i1 mod i2 ).
+.TP
+.IB i1 .eq( i2 )
+Returns 1 if
+.I i1
+and
+.I i2
+are equal; 0 otherwise.
+.TP
+.IB i1 .cmp( i2 )
+Compares two large integers, returning 1 if
+.I i1
+is larger,
+-1 if
+.I i2
+is larger, and 0 if they are equal.
+.TP
+.IB i .shl( n )
+Returns
+.IR i << n
+.TP
+.IB i .shr( n )
+Returns
+.IR i >> n
+.TP
+.IB i1 .and( i2 )
+Returns
+.IR i & n ,
+bitwise AND
+.TP
+.IB i1 .ori( i2 )
+Returns
+.IR i | n ,
+bitwise inclusive-OR
+(it is
+.B ori
+because plain
+.B or
+is a Limbo keyword)
+.TP
+.IB i .not()
+Returns
+.RI ~ i ,
+bitwise ones-complement
+.TP
+.IB i1 .xor( i2 )
+Returns
+.IR i ^ n ,
+bitwise exclusive-OR
+.SH SOURCE
+.B /libinterp/ipint.c
+.br
+.B /libmp
=======================================
--- /dev/null
+++ /man/2/ipints-genprime Tue Aug 10 15:06:28 2010
@@ -0,0 +1,112 @@
+.TH IPINTS-GENPRIME 2
+.SH NAME
+ipints: genprime, gensafeprime, genstrongprime, DSAprimes, probably_prime
\- prime number generation
+.SH SYNOPSIS
+.EX
+include "ipints.m";
+ipints := load IPints IPints->PATH;
+IPint: import ipints;
+
+probably_prime: fn(n: ref IPint, nrep: int): int;
+
+genprime: fn(nbits: int, nrep: int): ref IPint;
+gensafeprime: fn(nbits: int, nrep: int): (ref IPint, ref IPint); # p, alpha
+genstrongprime: fn(nbits: int, nrep: int): ref IPint;
+DSAprimes: fn(): (ref IPint, ref IPint, array of byte); # q, p, seed
+.EE
+.SH DESCRIPTION
+This set of functions in
+.B IPints
+(see
+.IR ipints (2))
+helps Limbo applications
+generate and test large prime numbers with relative efficiency.
+The numbers are all represented by
+.BR IPint .
+.PP
+.I Probably_prime
+uses the Miller-Rabin test to test
+.IR n .
+It returns true (non-zero) if
+.I P
+is probably prime. The probability of
+.I n
+not being prime is
+1/4**\fInrep\fR.
+If
+.I probably_prime
+returns false (zero),
+.I n
+is certainly not prime.
+.PP
+.I Genprime
+returns a random prime of length
+.IR nbits .
+Since it uses the Miller-Rabin test,
+.I nrep
+is the repetition count passed to
+.IR probably_prime .
+.PP
+.I Gensafeprime
+returns a tuple
+.BI ( p,\ alpha ),
+where
+.I p
+is a prime of length
+.I nbits
+and
+.I alpha
+is a generator of the multiplicative group of integers mod \fIp\fR;
+there is a prime \fIq\fR such that \fIp-1=2*q\fR.
+.PP
+.I Genstrongprime
+returns a prime
+.I p
+with the following properties:
+.IP \-
+(\fIp\fR-1)/2 is prime. Therefore
+.IR p -1
+has a large prime factor,
+.IR p '.
+.IP \-
+.IR p '-1
+has a large prime factor
+.IP \-
+.IR p +1
+has a large prime factor
+.PP
+.I DSAprimes
+uses the NIST recommended algorithm for generating DSA primes and
+returns a tuple
+.BI ( q,\ p,\ seed ) ,
+where
+.I p
+and
+.I q
+are primes, and
+.I q
+divides
+.IR p -1.
+The random
+.I seed
+used is also returned, so that sceptics
+can later confirm the computation.
+.SH SOURCE
+.B /libinterp/ipint.c
+.br
+.B /libsec/port/probably_prime.c
+.br
+.B /libsec/port/dsaprimes.c
+.br
+.B /libsec/port/genprime.c
+.br
+.B /libsec/port/gensafeprime.c
+.br
+.B /libsec/port/genstrongprime.c
+.br
+.SH SEE ALSO
+.IR crypt-intro (2),
+.IR crypt-crypt (2),
+.IR crypt-dsagen (2),
+.IR crypt-gensk (2),
+.IR ipints (2)
=======================================
--- /dev/null
+++ /module/crypt.m Tue Aug 10 15:06:28 2010
@@ -0,0 +1,191 @@
+#
+# basic cryptography routines implemented in C
+#
+Crypt: module
+{
+ PATH: con "$Crypt";
+
+ # state held while creating digests
+ DigestState: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+
+ copy: fn(d: self ref DigestState): ref DigestState;
+ };
+
+ # expanded AES key + state for chaining
+ AESstate: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+ };
+
+ # expanded DES key + state for chaining
+ DESstate: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+ };
+
+ # expanded IDEA key + state for chaining
+ IDEAstate: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+ };
+
+ # expanded RC4 key + encryption state
+ RC4state: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+ };
+
+ # expanded Blowfish key + state for chaining
+ BFstate: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+ # all the state is hidden
+ };
+
+ # digests
+ sha1: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ sha224: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ sha256: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ sha384: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ sha512: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ md4: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+ md5: fn(buf: array of byte, n: int, digest: array of byte, state: ref
DigestState):
+ ref DigestState;
+
+ hmac_sha1: fn(data: array of byte, n: int, key: array of byte, digest:
array of byte, state: ref DigestState):
+ ref DigestState;
+ hmac_md5: fn(data: array of byte, n: int, key: array of byte, digest:
array of byte, state: ref DigestState):
+ ref DigestState;
+
+ SHA1dlen: con 20;
+ SHA224dlen: con 28;
+ SHA256dlen: con 32;
+ SHA384dlen: con 48;
+ SHA512dlen: con 64;
+ MD5dlen: con 16;
+ MD4dlen: con 16;
+
+ # encryption interfaces
+ Encrypt: con 0;
+ Decrypt: con 1;
+
+ AESbsize: con 16;
+
+ aessetup: fn(key: array of byte, ivec: array of byte): ref AESstate;
+ aescbc: fn(state: ref AESstate, buf: array of byte, n: int, direction:
int);
+
+ DESbsize: con 8;
+
+ dessetup: fn(key: array of byte, ivec: array of byte): ref DESstate;
+ desecb: fn(state: ref DESstate, buf: array of byte, n: int, direction:
int);
+ descbc: fn(state: ref DESstate, buf: array of byte, n: int, direction:
int);
+
+ IDEAbsize: con 8;
+
+ ideasetup: fn(key: array of byte, ivec: array of byte): ref IDEAstate;
+ ideaecb: fn(state: ref IDEAstate, buf: array of byte, n: int, direction:
int);
+ ideacbc: fn(state: ref IDEAstate, buf: array of byte, n: int, direction:
int);
+
+ BFbsize: con 8;
+
+ blowfishsetup: fn(key: array of byte, ivec: array of byte): ref BFstate;
+# blowfishecb: fn(state: ref BFstate, buf: array of byte, n: int,
direction: int);
+ blowfishcbc: fn(state: ref BFstate, buf: array of byte, n: int,
direction: int);
+
+ rc4setup: fn(seed: array of byte): ref RC4state;
+ rc4: fn(state: ref RC4state, buf: array of byte, n: int);
+ rc4skip: fn(state: ref RC4state, n: int);
+ rc4back: fn(state: ref RC4state, n: int);
+
+ # create an alpha and p for diffie helman exchanges
+ dhparams: fn(nbits: int): (ref IPints->IPint, ref IPints->IPint);
+
+ # public key
+ PK: adt
+ {
+ pick {
+ RSA =>
+ n: ref IPints->IPint; # modulus
+ ek: ref IPints->IPint; # exp (encryption key)
+ Elgamal =>
+ p: ref IPints->IPint; # modulus
+ alpha: ref IPints->IPint; # generator
+ key: ref IPints->IPint; # encryption key (alpha**secret mod p)
+ DSA =>
+ p: ref IPints->IPint; # modulus
+ q: ref IPints->IPint; # group order, q divides p-1
+ alpha: ref IPints->IPint; # group generator
+ key: ref IPints->IPint; # encryption key (alpha**secret mod p)
+ }
+ };
+
+ # secret key (private/public key pair)
+ SK: adt
+ {
+ pick {
+ RSA =>
+ pk: ref PK.RSA;
+ dk: ref IPints->IPint; # exp (decryption key)
+ p: ref IPints->IPint; # q in pkcs
+ q: ref IPints->IPint; # p in pkcs
+ # precomputed crt values
+ kp: ref IPints->IPint; # k mod p-1
+ kq: ref IPints->IPint; # k mod q-1
+ c2: ref IPints->IPint; # for converting residues to number
+ Elgamal =>
+ pk: ref PK.Elgamal;
+ secret: ref IPints->IPint; # decryption key
+ DSA =>
+ pk: ref PK.DSA;
+ secret: ref IPints->IPint; # decryption key
+ }
+ };
+
+ # public key signature
+ PKsig: adt
+ {
+ # could just have list or array of ref IPints->IPint
+ pick {
+ RSA =>
+ n: ref IPints->IPint;
+ Elgamal =>
+ r: ref IPints->IPint;
+ s: ref IPints->IPint;
+ DSA =>
+ r: ref IPints->IPint;
+ s: ref IPints->IPint;
+ }
+ };
+
+ # RSA keys
+ rsagen: fn(nlen: int, elen: int, nrep: int): ref SK.RSA;
+ rsafill: fn(n: ref IPints->IPint, ek: ref IPints->IPint, dk: ref
IPints->IPint, p: ref IPints->IPint, q: ref IPints->IPint): ref SK.RSA;
+ rsadecrypt: fn(k: ref SK.RSA, m: ref IPints->IPint): ref IPints->IPint;
+ rsaencrypt: fn(k: ref PK.RSA, m: ref IPints->IPint): ref IPints->IPint;
+
+ # Elgamal
+ eggen: fn(nlen: int, nrep: int): ref SK.Elgamal;
+
+ # DSA
+ dsagen: fn(oldpk: ref PK.DSA): ref SK.DSA;
+
+ # generic signature functions
+ genSK: fn(algname: string, length: int): ref SK;
+ genSKfromPK: fn(pk: ref PK): ref SK;
+ sign: fn(sk: ref SK, m: ref IPints->IPint): ref PKsig;
+ verify: fn(pk: ref PK, sig: ref PKsig, m: ref IPints->IPint): int;
+ sktopk: fn(sk: ref SK): ref PK;
+};
=======================================
--- /dev/null
+++ /module/ipints.m Tue Aug 10 15:06:28 2010
@@ -0,0 +1,57 @@
+IPints: module
+{
+ PATH: con "$IPints";
+
+ # infinite precision integers
+ IPint: adt
+ {
+ x: int; # dummy for C compiler for runt.h
+
+ # conversions
+ iptob64: fn(i: self ref IPint): string;
+ iptob64z: fn(i: self ref IPint): string;
+ b64toip: fn(str: string): ref IPint;
+ iptobytes: fn(i: self ref IPint): array of byte;
+ iptobebytes: fn(i: self ref IPint): array of byte;
+ bytestoip: fn(buf: array of byte): ref IPint;
+ bebytestoip: fn(mag: array of byte): ref IPint;
+ inttoip: fn(i: int): ref IPint;
+ iptoint: fn(i: self ref IPint): int;
+ iptostr: fn(i: self ref IPint, base: int): string;
+ strtoip: fn(str: string, base: int): ref IPint;
+
+ # create a random large integer
+ random: fn(nbits: int): ref IPint;
+
+ # operations
+ bits: fn(i: self ref IPint): int;
+ expmod: fn(base: self ref IPint, exp, mod: ref IPint): ref IPint;
+ invert: fn(base: self ref IPint, mod: ref IPint): ref IPint;
+ add: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ sub: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ neg: fn(i: self ref IPint): ref IPint;
+ mul: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ div: fn(i1: self ref IPint, i2: ref IPint): (ref IPint, ref IPint);
+ mod: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ eq: fn(i1: self ref IPint, i2: ref IPint): int;
+ cmp: fn(i1: self ref IPint, i2: ref IPint): int;
+ copy: fn(i: self ref IPint): ref IPint;
+
+ # shifts
+ shl: fn(i: self ref IPint, n: int): ref IPint;
+ shr: fn(i: self ref IPint, n: int): ref IPint;
+
+ # bitwise
+ and: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ ori: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ xor: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
+ not: fn(i1: self ref IPint): ref IPint;
+ };
+
+ # primes
+ probably_prime: fn(n: ref IPint, nrep: int): int;
+ genprime: fn(nbits: int, nrep: int): ref IPint;
+ genstrongprime: fn(nbits: int, nrep: int): ref IPint;
+ gensafeprime: fn(nbits: int, nrep: int): (ref IPint, ref IPint);
+ DSAprimes: fn(): (ref IPint, ref IPint, array of byte);
+};
=======================================
--- /CHANGES Mon Aug 2 12:41:25 2010
+++ /CHANGES Tue Aug 10 15:06:28 2010
@@ -1,3 +1,6 @@
+20100810
+ initial introduction of crypt-*(2) and ipints(2)
+ replace keyring.m in module/runt.m by ipints.m and crypt.m; compensate in
libinterp and libkeyring by using keyringif.m to generate Keyring's
interface
20100802
various changes held back by accident, notably stackv in stack(1), better
diagnostics by cat(1)
20100801
=======================================
--- /appl/cmd/randpass.b Fri Dec 22 09:07:39 2006
+++ /appl/cmd/randpass.b Tue Aug 10 15:06:28 2010
@@ -6,9 +6,9 @@

include "draw.m";

-include "keyring.m";
- kr : Keyring;
- IPint: import kr;
+include "ipints.m";
+ ipints: IPints;
+ IPint: import ipints;

Randpass: module
{
@@ -18,7 +18,7 @@
init(nil: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
- kr = load Keyring Keyring->PATH;
+ ipints = load IPints IPints->PATH;

if(args != nil)
args = tl args;
@@ -29,11 +29,7 @@
raise "fail:usage";
}
}
-
- rbig := IPint.random(pwlen*8, pwlen*16);
- rstr := rbig.iptob64();
-
- sys->print("%s\n", rstr[0:pwlen]);
+ sys->print("%s\n", IPint.random(pwlen*8).iptob64()[0: pwlen]);
}

isnumeric(s: string): int
=======================================
--- /dis/randpass.dis Fri Dec 22 12:52:35 2006
+++ /dis/randpass.dis Tue Aug 10 15:06:28 2010
@@ -1,22 +1,22 @@
-À €0€@‚Ð< @
+À €0€@‚Ð? @
@ ]‚$ & $$- (]‚$
- 8"
-$8 '
-48
-8,]J 4 " $<6 <() <- (8`J 8 b’(
+ 0"
+$0 '
+,0
+0/]J , " $46 4() 4- (0`J 0 b’(
A
-€@- €@ '
-<€@ H €@
- 4)
-<4 ) <) 4$'
-84 H 4
-ž A €@@•( €@ @•( €@$'
-,€@ H €@ A €@)
-,€@ '
-0€@ H €@ 8) 8 )
-08$q•( 8$'
-€@8 H 8
+8- 8 '
+48 H 8
+ ,)
+4, ) 4) ,$'
+0, H ,
+ž A €D@•( €D '
+€@€D H €D A ,)
+€@, ) €@'
+<, H , ) <4q‘( 4) < 0) 0 )
+40$) 4'
+80 H 0
- $T (`Š$(7R‰$ (_J0(3R‰$ (`J9(5- : $
- -b’$ :- - ÿ ( À 0 € €H Ù8 $Keyring4 $Sys3 %s
+ 0b’$ =- - ÿ ( À 0 € €H Å€7 $IPints4 $Sys3 %s
04 Usage: randpass [password-length(<256, default=16)]
: fail:usage Randpass BD³Tinit ú´ëŠIPint.iptob64 p¼ÖñIPint.random xù“fildes ôd†Èfprint ¬„ 3print /appl/cmd/randpass.b
=======================================
--- /emu/DragonFly/emu Fri Feb 5 06:51:46 2010
+++ /emu/DragonFly/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/DragonFly/emu-g Fri Feb 5 06:51:46 2010
+++ /emu/DragonFly/emu-g Tue Aug 10 15:06:28 2010
@@ -33,6 +33,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/FreeBSD/emu Sat Jul 25 05:00:30 2009
+++ /emu/FreeBSD/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Hp/emu Sat Jul 25 05:00:30 2009
+++ /emu/Hp/emu Tue Aug 10 15:06:28 2010
@@ -49,6 +49,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Irix/emu Sat Jul 25 05:00:30 2009
+++ /emu/Irix/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Linux/emu Fri Mar 5 03:39:25 2010
+++ /emu/Linux/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Linux/emu-g Mon Dec 14 11:43:13 2009
+++ /emu/Linux/emu-g Tue Aug 10 15:06:28 2010
@@ -37,6 +37,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/Linux/emu-wrt Sat Jul 25 05:00:30 2009
+++ /emu/Linux/emu-wrt Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
# freetype

=======================================
--- /emu/MacOSX/emu Sat Jul 25 05:00:30 2009
+++ /emu/MacOSX/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/MacOSX/emu-g Sat Jul 25 05:00:30 2009
+++ /emu/MacOSX/emu-g Tue Aug 10 15:06:28 2010
@@ -35,6 +35,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/NetBSD/emu Sat Jul 25 05:00:30 2009
+++ /emu/NetBSD/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Nt/emu Sat Jul 25 05:00:30 2009
+++ /emu/Nt/emu Tue Aug 10 15:06:28 2010
@@ -49,6 +49,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Nt/ie Wed May 5 05:18:06 2010
+++ /emu/Nt/ie Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/OpenBSD/emu Sat Jul 25 05:00:30 2009
+++ /emu/OpenBSD/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Plan9/emu Sun Oct 4 15:58:48 2009
+++ /emu/Plan9/emu Tue Aug 10 15:06:28 2010
@@ -49,6 +49,8 @@
math
# srv not used on Plan 9
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Plan9/emusig Wed Apr 16 07:31:04 2008
+++ /emu/Plan9/emusig Tue Aug 10 15:06:28 2010
@@ -39,6 +39,8 @@
math
# srv not used on Plan 9
keyring
+ crypt
+ ipints
loader
freetype

@@ -47,6 +49,8 @@
cache
chan
dev
+ devtab
+
dial
dis
discall
@@ -74,6 +78,7 @@
root
/dev /
/prog /
+ /prof /
/net /
/net.alt /
/chan /
=======================================
--- /emu/Solaris/emu Sat Jul 25 05:00:30 2009
+++ /emu/Solaris/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Unixware/emu Sat Jul 25 05:00:30 2009
+++ /emu/Unixware/emu Tue Aug 10 15:06:28 2010
@@ -48,6 +48,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /include/interp.h Thu Nov 6 03:19:52 2008
+++ /include/interp.h Tue Aug 10 15:06:28 2010
@@ -389,6 +389,7 @@
extern Array* allocimgarray(Heap*, Heap*);
extern Module* builtinmod(char*, void*, int);
extern void cblock(Prog*);
+extern void* checktype(void*, Type*, char*, int);
extern void cmovw(void*, void*);
extern Channel* cnewc(Type*, void (*)(void), int);
extern int compile(Module*, int, Modlink*);
@@ -410,12 +411,12 @@
extern void destroylinks(Module*);
extern void destroystack(REG*);
extern void drawmodinit(void);
+extern Type* dtype(void (*)(Heap*, int), int, uchar*, int);
+extern Module* dupmod(Module*);
extern int dynldable(int);
extern void iqlock(ILock*);
extern void iqunlock(ILock*);
extern void loadermodinit(void);
-extern Type* dtype(void (*)(Heap*, int), int, uchar*, int);
-extern Module* dupmod(Module*);
extern void error(char*);
extern void errorf(char*, ...);
extern void extend(void);
=======================================
--- /include/version.h Mon Aug 2 06:49:50 2010
+++ /include/version.h Tue Aug 10 15:06:28 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100802)"
+#define VERSION "Fourth Edition (20100810)"
=======================================
--- /libinterp/heap.c Fri Dec 22 09:07:39 2006
+++ /libinterp/heap.c Tue Aug 10 15:06:28 2010
@@ -236,6 +236,40 @@
}
poolfree(heapmem, h);
}
+
+Type*
+dtype(void (*destroy)(Heap*, int), int size, uchar *map, int mapsize)
+{
+ Type *t;
+
+ t = malloc(sizeof(Type)+mapsize);
+ if(t != nil) {
+ t->ref = 1;
+ t->free = destroy;
+ t->mark = markheap;
+ t->size = size;
+ t->np = mapsize;
+ memmove(t->map, map, mapsize);
+ }
+ return t;
+}
+
+void*
+checktype(void *v, Type *t, char *name, int newref)
+{
+ Heap *h;
+
+ if(v == H || v == nil)
+ error(exNilref);
+ h = D2H(v);
+ if(t == nil || h->t != t)
+ errorf("%s: %s", exType, name);
+ if(newref){
+ h->ref++;
+ Setmark(h);
+ }
+ return v;
+}

void
freetype(Type *t)
=======================================
--- /libinterp/ipint.c Wed Jun 11 07:40:23 2008
+++ /libinterp/ipint.c Tue Aug 10 15:06:28 2010
@@ -6,13 +6,39 @@
#include <mp.h>
#include <libsec.h>
#include "pool.h"
-#include "../libkeyring/keys.h"
+#include "ipint.h"
#include "raise.h"

-extern Type *TIPint;
+#include "ipintsmod.h"
+
+enum
+{
+ MaxBigBytes = 1024
+};
+
+/* infinite precision integer */
+struct IPint
+{
+ IPints_IPint x;
+ mpint* b;
+};
+
+Type *TIPint;
+static uchar IPintmap[] = IPints_IPint_map;
+
#define MP(x) checkIPint((x))

-Keyring_IPint*
+void
+ipintsmodinit(void)
+{
+ /* can be called from modinit, Keyring or Crypt */
+ if(TIPint == nil)
+ TIPint = dtype(freeIPint, sizeof(IPint), IPintmap, sizeof(IPintmap));
+ builtinmod("$IPints", IPintsmodtab, IPintsmodlen);
+}
+
+//IPints_IPint*
+void*
newIPint(mpint* b)
{
Heap *h;
@@ -23,20 +49,22 @@
h = heap(TIPint); /* TO DO: caller might lose other values if heap raises
error here */
ip = H2D(IPint*, h);
ip->b = b;
- return (Keyring_IPint*)ip;
+ return (IPints_IPint*)ip;
}

mpint*
-checkIPint(Keyring_IPint *v)
-{
+checkIPint(void *a)
+{
+ IPints_IPint *v;
IPint *ip;

+ v = a;
ip = (IPint*)v;
if(ip == H || ip == nil)
error(exNilref);
if(D2H(ip)->t != TIPint)
error(exType);
- return ip->b;
+ return ip->b; /* non-nil by construction */
}

void
@@ -151,7 +179,7 @@
retstr(buf, f->ret);
}

-static Keyring_IPint*
+static IPints_IPint*
strtoipint(String *s, int base)
{
char *p, *q;
@@ -250,7 +278,7 @@
destroy(v);

release();
- b = mprand(f->maxbits, genrandom, nil);
+ b = mprand(f->nbits, genrandom, nil);
acquire();
*f->ret = newIPint(b);
}
@@ -712,3 +740,109 @@
mpnot(i1, ret);
*f->ret = newIPint(ret);
}
+
+/*
+ * primes
+ */
+
+void
+IPints_probably_prime(void *fp)
+{
+ F_IPints_probably_prime *f;
+
+ f = fp;
+ release();
+ *f->ret = probably_prime(checkIPint(f->n), f->nrep);
+ acquire();
+}
+
+void
+IPints_genprime(void *fp)
+{
+ F_IPints_genprime *f;
+ mpint *p;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+ p = mpnew(0);
+ release();
+ genprime(p, f->nbits, f->nrep);
+ acquire();
+ *f->ret = newIPint(p);
+}
+
+void
+IPints_genstrongprime(void *fp)
+{
+ F_IPints_genstrongprime *f;
+ mpint *p;
+ void *r;
+
+ f = fp;
+ r = *f->ret;
+ *f->ret = H;
+ destroy(r);
+ p = mpnew(0);
+ release();
+ genstrongprime(p, f->nbits, f->nrep);
+ acquire();
+ *f->ret = newIPint(p);
+}
+
+void
+IPints_gensafeprime(void *fp)
+{
+ F_IPints_gensafeprime *f;
+ mpint *p, *alpha;
+ void *v;
+
+ f = fp;
+ v = f->ret->t0;
+ f->ret->t0 = H;
+ destroy(v);
+ v = f->ret->t1;
+ f->ret->t1 = H;
+ destroy(v);
+
+ p = mpnew(0);
+ alpha = mpnew(0);
+ release();
+ gensafeprime(p, alpha, f->nbits, f->nrep);
+ acquire();
+ f->ret->t0 = newIPint(p);
+ f->ret->t1 = newIPint(alpha);
+}
+
+void
+IPints_DSAprimes(void *fp)
+{
+ F_IPints_DSAprimes *f;
+ mpint *p, *q;
+ Heap *h;
+ void *v;
+
+ f = fp;
+ v = f->ret->t0;
+ f->ret->t0 = H;
+ destroy(v);
+ v = f->ret->t1;
+ f->ret->t1 = H;
+ destroy(v);
+ v = f->ret->t2;
+ f->ret->t2 = H;
+ destroy(v);
+
+ h = heaparray(&Tbyte, SHA1dlen);
+ f->ret->t2 = H2D(Array*, h);
+
+ p = mpnew(0);
+ q = mpnew(0);
+ release();
+ DSAprimes(q, p, f->ret->t2->data);
+ acquire();
+ f->ret->t0 = newIPint(q);
+ f->ret->t1 = newIPint(p);
+}
=======================================
--- /libinterp/keyring.c Wed Feb 3 12:48:47 2010
+++ /libinterp/keyring.c Tue Aug 10 15:06:28 2010
@@ -2,69 +2,73 @@
#include "kernel.h"
#include <isa.h>
#include "interp.h"
-#include "runt.h"
-#include "keyring.h"
#include <mp.h>
#include <libsec.h>
#include "pool.h"
#include "raise.h"
+
+/* arguably limbo -t should qualify type name */
+#define DigestState_copy Keyring_DigestState_copy
+#define IPint_random Keyring_IPint_random
+#include "keyringif.h"
+#include "keyring.h"
+
+#include "ipint.h"
#include "../libkeyring/keys.h"

-
-Type *TSigAlg;
-Type *TCertificate;
-Type *TSK;
-Type *TPK;
-Type *TDigestState;
-Type *TAuthinfo;
-Type *TAESstate;
-Type *TDESstate;
-Type *TIDEAstate;
-Type *TBFstate;
-Type *TRC4state;
-Type *TIPint;
-Type *TDSAsk;
-Type *TDSApk;
-Type *TDSAsig;
-Type *TEGsk;
-Type *TEGpk;
-Type *TEGsig;
-Type *TRSAsk;
-Type *TRSApk;
-Type *TRSAsig;
+static Type* TDigestState;
+static Type* TAESstate;
+static Type* TDESstate;
+static Type* TIDEAstate;
+static Type* TBFstate;
+static Type* TRC4state;
+
+static Type* TSigAlg;
+static Type* TCertificate;
+static Type* TSK;
+static Type* TPK;
+static Type* TAuthinfo;
+
+static Type* TDSAsk;
+static Type* TDSApk;
+static Type* TDSAsig;
+static Type* TEGsk;
+static Type* TEGpk;
+static Type* TEGsig;
+static Type* TRSAsk;
+static Type* TRSApk;
+static Type* TRSAsig;

enum {
Maxmsg= 4096
};

-uchar IPintmap[] = Keyring_IPint_map;
-uchar SigAlgmap[] = Keyring_SigAlg_map;
-uchar SKmap[] = Keyring_SK_map;
-uchar PKmap[] = Keyring_PK_map;
-uchar Certificatemap[] = Keyring_Certificate_map;
-uchar DigestStatemap[] = Keyring_DigestState_map;
-uchar Authinfomap[] = Keyring_Authinfo_map;
-uchar AESstatemap[] = Keyring_AESstate_map;
-uchar DESstatemap[] = Keyring_DESstate_map;
-uchar IDEAstatemap[] = Keyring_IDEAstate_map;
-uchar BFstatemap[] = Keyring_BFstate_map;
-uchar RC4statemap[] = Keyring_RC4state_map;
-uchar DSAskmap[] = Keyring_DSAsk_map;
-uchar DSApkmap[] = Keyring_DSApk_map;
-uchar DSAsigmap[] = Keyring_DSAsig_map;
-uchar EGskmap[] = Keyring_EGsk_map;
-uchar EGpkmap[] = Keyring_EGpk_map;
-uchar EGsigmap[] = Keyring_EGsig_map;
-uchar RSAskmap[] = Keyring_RSAsk_map;
-uchar RSApkmap[] = Keyring_RSApk_map;
-uchar RSAsigmap[] = Keyring_RSAsig_map;
-
-PK* checkPK(Keyring_PK *k);
+static uchar DigestStatemap[] = Keyring_DigestState_map;
+static uchar AESstatemap[] = Keyring_AESstate_map;
+static uchar DESstatemap[] = Keyring_DESstate_map;
+static uchar IDEAstatemap[] = Keyring_IDEAstate_map;
+static uchar BFstatemap[] = Keyring_BFstate_map;
+static uchar RC4statemap[] = Keyring_RC4state_map;
+
+static uchar SigAlgmap[] = Keyring_SigAlg_map;
+static uchar SKmap[] = Keyring_SK_map;
+static uchar PKmap[] = Keyring_PK_map;
+static uchar Certificatemap[] = Keyring_Certificate_map;
+static uchar Authinfomap[] = Keyring_Authinfo_map;
+static uchar DSAskmap[] = Keyring_DSAsk_map;
+static uchar DSApkmap[] = Keyring_DSApk_map;
+static uchar DSAsigmap[] = Keyring_DSAsig_map;
+static uchar EGskmap[] = Keyring_EGsk_map;
+static uchar EGpkmap[] = Keyring_EGpk_map;
+static uchar EGsigmap[] = Keyring_EGsig_map;
+static uchar RSAskmap[] = Keyring_RSAsk_map;
+static uchar RSApkmap[] = Keyring_RSApk_map;
+static uchar RSAsigmap[] = Keyring_RSAsig_map;
+
+static PK* checkPK(Keyring_PK *k);

extern void setid(char*, int);
extern vlong osusectime(void);
-extern Keyring_IPint* newIPint(mpint*);
-extern mpint* checkIPint(Keyring_IPint*);
extern void freeIPint(Heap*, int);

static char exBadSA[] = "bad signature algorithm";
@@ -86,10 +90,6 @@
BFstate state;
};

-/*
- * Infinite (actually kind of big) precision integers
- */
-
/* convert a Big to base64 ascii */
int
bigtobase64(mpint* b, char *buf, int len)
@@ -567,7 +567,7 @@
freeheap(h, swept);
}

-PK*
+static PK*
checkPK(Keyring_PK *k)
{
PK *pk;
@@ -1169,29 +1169,12 @@
*f->ret = (*sa->vec->verify)(checkIPint(f->m), c->signa, pk->key);
acquire();
}
-
-static void*
-checktype(void *v, Type *t, char *name, int newref)
-{
- Heap *h;
-
- if(v == H || v == nil)
- error(exNilref);
- h = D2H(v);
- if(h->t != t)
- errorf("%s: %s", exType, name);
- if(newref){
- h->ref++;
- Setmark(h);
- }
- return v;
-}

/*
* digests
*/
void
-DigestState_copy(void *fp)
+Keyring_DigestState_copy(void *fp)
{
F_DigestState_copy *f;
Heap *h;
@@ -1933,18 +1916,17 @@
PK *spk;
SK *mysk;
Certificate *c;
+ mpint *p, *alpha;

f = fp;
*f->ret = -1;

if(f->filename == H)
- return;
+ error(exNilref);
if(f->info == H)
- return;
- if(f->info->alpha == H || f->info->p == H)
- return;
- if(((IPint*)f->info->alpha)->b == 0 || ((IPint*)f->info->p)->b == H)
- return;
+ error(exNilref);
+ alpha = checkIPint(f->info->alpha);
+ p = checkIPint(f->info->p);
spk = checkPK(f->info->spk);
mysk = checkSK(f->info->mysk);
c = checkCertificate(f->info->cert);
@@ -1985,12 +1967,12 @@
goto out;

/* diffie hellman base */
- n = bigtobase64(((IPint*)f->info->alpha)->b, buf, Maxbuf);
+ n = bigtobase64(alpha, buf, Maxbuf);
if(sendmsg(fd, buf, n) <= 0)
goto out;

/* diffie hellman modulus */
- n = bigtobase64(((IPint*)f->info->p)->b, buf, Maxbuf);
+ n = bigtobase64(p, buf, Maxbuf);
if(sendmsg(fd, buf, n) <= 0)
goto out;

@@ -2108,7 +2090,7 @@
extern SigAlgVec* rsainit(void);
extern SigAlgVec* dsainit(void);

- TIPint = dtype(freeIPint, sizeof(IPint), IPintmap, sizeof(IPintmap));
+ ipintsmodinit(); /* in case only Keyring is configured */
TSigAlg = dtype(freeSigAlg, sizeof(SigAlg), SigAlgmap, sizeof(SigAlgmap));
TSK = dtype(freeSK, sizeof(SK), SKmap, sizeof(SKmap));
TPK = dtype(freePK, sizeof(PK), PKmap, sizeof(PKmap));
@@ -3081,3 +3063,21 @@
mpfree(t);
acquire();
}
+
+void
+Keyring_IPint_random(void *fp)
+{
+ F_IPint_random *f;
+ mpint *b;
+ void *v;
+
+ f = fp;
+ v = *f->ret;
+ *f->ret = H;
+ destroy(v);
+
+ release();
+ b = mprand(f->maxbits, genrandom, nil);
+ acquire();
+ *f->ret = newIPint(b);
+}
=======================================
--- /libinterp/load.c Fri Dec 22 09:07:39 2006
+++ /libinterp/load.c Tue Aug 10 15:06:28 2010
@@ -78,23 +78,6 @@
{
return readmod(path, nil, 0);
}
-
-Type*
-dtype(void (*destroy)(Heap*, int), int size, uchar *map, int mapsize)
-{
- Type *t;
-
- t = malloc(sizeof(Type)+mapsize);
- if(t != nil) {
- t->ref = 1;
- t->free = destroy;
- t->mark = markheap;
- t->size = size;
- t->np = mapsize;
- memmove(t->map, map, mapsize);
- }
- return t;
-}

int
brpatch(Inst *ip, Module *m)
=======================================
--- /libinterp/mkfile Fri Dec 22 09:07:39 2006
+++ /libinterp/mkfile Tue Aug 10 15:06:28 2010
@@ -6,6 +6,7 @@
alt.$O\
comp-$OBJTYPE.$O\
conv.$O\
+ crypt.$O\
dec.$O\
dlm-$TARGMODEL.$O\
draw.$O\
@@ -48,6 +49,9 @@
../module/keyring.m\
../module/loader.m\
../module/freetype.m\
+ ../module/ipints.m\
+ ../module/crypt.m\
+ keyringif.m\

<$ROOT/mkfiles/mksyslib-$SHELLTYPE

@@ -58,7 +62,7 @@
rm -f $target && limbo -t Sys -I../module ../module/runt.m > $target

keyring.h:D: $MODULES
- rm -f $target && limbo -t Keyring -I../module ../module/runt.m > $target
+ rm -f $target && limbo -t Keyring -I../module keyringif.m > $target

drawmod.h:D: $MODULES
rm -f $target && limbo -t Draw -I../module ../module/runt.m > $target
@@ -78,9 +82,19 @@
freetypemod.h:D: $MODULES
rm -f $target && limbo -t Freetype -I../module ../module/runt.m > $target

+ipintsmod.h:D: $MODULES
+ rm -f $target && limbo -t IPints -I../module ../module/ipints.m > $target
+
benchmod.h:D: ../module/bench.m
rm -f $target && limbo -t Bench -I../module ../module/bench.m > $target

+cryptmod.h:D: $MODULES
+ rm -f $target && limbo -t Crypt -I../module ../module/runt.m > $target
+
+keyringif.h:D: $MODULES keyringif.m
+ rm -f $target && limbo -a -I../module keyringif.m > $target
+
+
bench.h:D:../module/bench.m
rm -f $target && limbo -a -I../module ../module/bench.m > $target

@@ -95,8 +109,9 @@
draw.$O: drawmod.h
tk.$O: $ROOT/include/draw.h tkmod.h
math.$O: mathmod.h
-keyring.$O: keyring.h $ROOT/libkeyring/keys.h
-ipint.$O: keyring.h
+keyring.$O: keyring.h ipint.h keyringif.h
+crypt.$O: ipint.h runt.h cryptmod.h
+ipint.$O: ipint.h ipintsmod.h
loader.$O: loadermod.h
freetype.$O: freetypemod.h $ROOT/include/freetype.h
math.$O: $ROOT/include/mathi.h
@@ -105,11 +120,6 @@
das-68000.c:N: das-68020.c
comp-spim.c:N: comp-mips.c

-kif.c: kif.h
- rm -f $target && kif -t $SYSTARG kif.h > $target
-kif.$O: kif.c
- $CC $CFLAGS kif.c && rm -f kif.c
-
# optab.h: $ROOT/include/isa.h mkoptab
# $SHELLNAME mkoptab > $target

@@ -117,4 +127,4 @@
# it works only on UNIX and Plan 9.

nuke:EV: nuke-std
- rm -f runt.h sysmod.h drawmod.h prefabmod.h tkmod.h mathmod.h keyring.h
readimagemod.h loadermod.h freetypemod.h kif.c
+ rm -f runt.h sysmod.h drawmod.h prefabmod.h tkmod.h mathmod.h keyring.h
readimagemod.h loadermod.h freetypemod.h cryptmod.h keyringif.h ipintsmod.h
=======================================
--- /libkeyring/dsaalg.c Thu Jul 30 11:33:32 2009
+++ /libkeyring/dsaalg.c Tue Aug 10 15:06:28 2010
@@ -2,7 +2,7 @@
#include <kernel.h>
#include <isa.h>
#include "interp.h"
-#include "../libinterp/runt.h"
+#include "../libinterp/keyringif.h"
#include "mp.h"
#include "libsec.h"
#include "keys.h"
=======================================
--- /libkeyring/egalg.c Thu Jul 30 11:33:32 2009
+++ /libkeyring/egalg.c Tue Aug 10 15:06:28 2010
@@ -2,7 +2,7 @@
#include <kernel.h>
#include <isa.h>
#include "interp.h"
-#include "../libinterp/runt.h"
+#include "../libinterp/keyringif.h"
#include "mp.h"
#include "libsec.h"
#include "keys.h"
=======================================
--- /libkeyring/keys.h Wed Jun 11 05:31:51 2008
+++ /libkeyring/keys.h Tue Aug 10 15:06:28 2010
@@ -1,4 +1,3 @@
-typedef struct IPint IPint;
typedef struct SigAlg SigAlg;
typedef struct SigAlgVec SigAlgVec;
typedef struct SK SK;
@@ -16,13 +15,6 @@
MaxBigBytes = 1024
};

-/* infininite precision integer */
-struct IPint
-{
- Keyring_IPint x;
- mpint* b;
-};
-
/* generic certificate */
struct Certificate
{
@@ -115,4 +107,5 @@
int bigtobase64(mpint* b, char *buf, int blen);
mpint* base64tobig(char *str, char **strp);
SigAlgVec* findsigalg(char*);
-Keyring_IPint* newIPint(mpint*);
+//Keyring_IPint* newIPint(mpint*);
+void* newIPint(mpint*);
=======================================
--- /libkeyring/rsaalg.c Thu Jul 30 11:33:32 2009
+++ /libkeyring/rsaalg.c Tue Aug 10 15:06:28 2010
@@ -2,7 +2,7 @@
#include <kernel.h>
#include <isa.h>
#include "interp.h"
-#include "../libinterp/runt.h"
+#include "../libinterp/keyringif.h"
#include "mp.h"
#include "libsec.h"
#include "keys.h"
=======================================
--- /libmp/port/mpextendedgcd.c Fri Dec 22 09:07:39 2006
+++ /libmp/port/mpextendedgcd.c Tue Aug 10 15:06:28 2010
@@ -101,6 +101,4 @@
mpfree(u);
mpfree(a);
mpfree(b);
-
- return;
-}
+}
=======================================
--- /module/runt.m Fri Dec 22 12:52:35 2006
+++ /module/runt.m Tue Aug 10 15:06:28 2010
@@ -5,7 +5,7 @@
include "prefab.m";
include "tk.m";
include "math.m";
-include "keyring.m";
+include "ipints.m";
+include "crypt.m";
include "loader.m";
-# include "readimage.m";
include "freetype.m";
=======================================
--- /os/cerf1110/cerf Fri Dec 22 13:39:35 2006
+++ /os/cerf1110/cerf Tue Aug 10 15:06:28 2010
@@ -57,7 +57,9 @@
sys
# draw
# tk
- keyring
+ keyring crypt
+ ipints
+

port
alarm
=======================================
--- /os/cerf250/cerf Thu Jul 22 03:56:14 2010
+++ /os/cerf250/cerf Tue Aug 10 15:06:28 2010
@@ -60,7 +60,9 @@
sys
# draw
# tk
- keyring
+ keyring crypt
+ ipints
+

port
alarm
=======================================
--- /os/cerf405/cerf Thu Jul 22 03:56:14 2010
+++ /os/cerf405/cerf Tue Aug 10 15:06:28 2010
@@ -53,7 +53,9 @@
mod
math
sys
- keyring
+ keyring crypt
+ ipints
+

port
alarm
=======================================
***Additional files exist in this changeset.***

==============================================================================
Revision: 10da85a9c3
Author: for...@vitanuova.com
Date: Thu Aug 19 08:17:42 2010
Log: 20100819-1617
http://code.google.com/p/inferno-npe/source/detail?r=10da85a9c3

Modified:
/CHANGES
/Solaris/sparc/include/lib9.h
/include/version.h

=======================================
--- /CHANGES Tue Aug 10 15:06:28 2010
+++ /CHANGES Thu Aug 19 08:17:42 2010
@@ -1,3 +1,5 @@
+20100819
+ failed to push Solaris/sparc/include/lib9.h with u64int change [issue 151]
20100810
initial introduction of crypt-*(2) and ipints(2)
replace keyring.m in module/runt.m by ipints.m and crypt.m; compensate in
libinterp and libkeyring by using keyringif.m to generate Keyring's
interface
=======================================
--- /Solaris/sparc/include/lib9.h Mon Jun 9 02:36:43 2008
+++ /Solaris/sparc/include/lib9.h Thu Aug 19 08:17:42 2010
@@ -33,6 +33,8 @@
typedef long long int vlong;
typedef unsigned long long int uvlong;
typedef unsigned int u32int;
+typedef uvlong u64int;
+
typedef unsigned int mpdigit; /* for /sys/include/mp.h */
typedef unsigned short u16int;
typedef unsigned char u8int;
=======================================
--- /include/version.h Tue Aug 10 15:06:28 2010
+++ /include/version.h Thu Aug 19 08:17:42 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100810)"
+#define VERSION "Fourth Edition (20100819)"

==============================================================================
Revision: 6dd14bb2ba
Author: for...@vitanuova.com
Date: Thu Aug 19 10:09:32 2010
Log: 20100819-1809
http://code.google.com/p/inferno-npe/source/detail?r=6dd14bb2ba

Modified:
/appl/cmd/ar.b
/dis/ar.dis

=======================================
--- /appl/cmd/ar.b Sat Dec 30 13:29:14 2006
+++ /appl/cmd/ar.b Thu Aug 19 10:09:32 2010
@@ -174,14 +174,15 @@
for(i = 0; args != nil; args = tl args)
files[i++] = ref File(hd args, trim(hd args), 0);
comfun(cp, files); # do the command
+ allfound := 1;
for(i = 0; i < len files; i++)
if(!files[i].found){
sys->fprint(stderr, "ar: %s not found\n", files[i].name);
- cp = "error";
+ allfound = 0;
}
bout.flush();
- if(cp != nil)
- raise "fail:"+cp;
+ if(!allfound)
+ raise "fail: file not found";
}

#
=======================================
--- /dis/ar.dis Fri Dec 22 16:30:12 2006
+++ /dis/ar.dis Thu Aug 19 10:09:32 2010
@@ -1,97 +1,97 @@
-À €0€@†@† Ä* @
- ¤ @ €Ü H @ €à T @ €ä   A ¤8- 8 ' œ8 H 8 ¤ A ¤€@- €@ '
-<€@ H €@ ¤ A H8)
-<8 ) „<- 8$' D8 H 8 HV $€@bJ €@ €@
-€@ƒ‘& $$" $4& $$- (T 4€@`Š(€@€ R‰(4€@=‘€@€a8_J 8€vaJ 8€v 8€`- €ì
+À €0€@†@† À* & @
+   @ €Ü H @ €à T @ €ä œ A  <- < ' ˜< H <   A  €D- €D '
+€@€D H €D   A H<)
+€@< ) €€@- <$' D< H < HV $€DbJ €D €D
+€Dƒ‘& $$" $0& $$- (T 0€D`Š(€D€ R‰(0€D=‘€D€a<_J <€vaJ <€v <€`- €ì
€ - @
€ - L
- € €@ <^ „€Ø+ @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
+ € €D €@^ €€Ø+ @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
€ - @

- € €@ <^ „€Ø8 @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
- € - ˆ
- € €@ <^ „€Ø€D @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
- € €@ <^ „€Ø€N @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
- € €@ <^ „€Ø€X @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
- € €@ <^ „€Ø€b @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
- € - °
- € - ¼
- € €@ <^ „€Ø€p @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü
+ € €D €@^ €€Ø8 @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
+ € - „
+ € €D €@^ €€Ø€D @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
+ € €D €@^ €€Ø€N @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
+ € €D €@^ €€Ø€X @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
+ € €D €@^ €€Ø€b @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü
+ € - ¬
+ € - ¸
+ € €D €@^ €€Ø€p @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü

-8) œ8 ) 8$R (48('
-€@8 H 8 ¤ €@
-€@ƒ‘
+<) ˜< ) <$R (0<('
+€D< H <   €D
+€Dƒ‘
€ : (
]Ò€ì €Š]Ò @ €Š 8) œ8 ) $8$'
-€@8 H 8 ¤ €@
-€@ƒ‘^Ò€ì €Œ]Ò @ €• €@"
-$€@ ' ”€@
-€@ƒ÷& $$V $€@bJ €@€• €@
-€@ƒ‘^ „ P€¨^Ò ° €Ÿ 8) œ8 ) 8$) |8('
-€@8 H 8 ¤ €@
-€@ƒ‘ €@ <^ „€Ø€£ @ €Ø) €Ø< - < )
-<€@ ) „<
-€@€Ü" $0& $$V $€@ I €@,- (]‚$ „€¼- (€@: (r‰€@,€@ <"
-$< 8"
-$8 '-< 8
-8ƒ÷- < )
-<€@ ) „<& $$
- €­-! P 8 ¡8 P €@)
-0€@ )
-,€@$ Œ8€@ P - (U ,€@`Š(€@€Ôr‰€@,())€@ <^j < €Ò) „< 8) œ8
) €ð8$r‰€D,())€D <)-< 8() „<'
-€@8 H 8 ¤) X0: (
- €Â A H€@) D€@ '
-€D€@ H €@ Hi‚0 „€ÛSÉ \0<ž < ] „ P€å () œ( ) (($) |(('
-$( H ( ¤ (
+€D< H <   €D
+€Dƒ‘^Ò€ì €Œ]Ò @ €• €D"
+$€D ' €D
+€Dƒ÷& $$V $€DbJ €D€• €D
+€Dƒ‘^ € P€¨^Ò ¬ €Ÿ <) ˜< ) <$) x<('
+€D< H <   €D
+€Dƒ‘ €D €@^ €€Ø€£ @ €Ø) €Ø€@ - €@ )
+€@€D ) €€@
+€D€Ü" $8& $$V $€D I €D,- (]‚$ €€¼- (€D: (r‰€D,€D €@"
+$€@ <"
+$< '-€@ <
+<ƒ÷- €@ )
+€@€D ) €€@& $$
+ €­-! P < ¡< P €D)
+8€D )
+,€D$ Œ<€D P - 4- (U ,€D`Š(€D€Õr‰€D,())€D €@^j €@ €Ó) €€@ <) ˜<
) €ð<$r‰€H,())€H €@)-€@ <() €€@'
+€D< H <  - 4: (
+ €Ã A H€D) D€D '
+€H€D H €D H^’4 €Ûž X ] € P€å () ˜( ) (($) x(('
+$( H (   (
(ƒ‘) P € )
€ - € $- € ('
,€
-€ ƒR P r‚€ € r‚€ ) „€ r‚€ ))€ 8]‚, „ f !€ )
+€ ƒR P Œr‚€ Œ € r‚€ Œ ) €€ r‚€ Œ ))€ 8]‚, € f € )
,€ '
(€
-€ „<) (€”]Ê „€” e) „€” €˜)-( €˜ ) ”€˜$'
+€ „<) (€”]Ê €€” e) €€” €˜)-( €˜ ) €˜$'
€ €˜
€˜ƒ×]J € r‚€˜ €˜ ))€˜ 8 €˜)
$€˜ )-( €˜$'
0€˜
-€˜ƒ¸^‚0 „ €˜)
+€˜ƒ¸^‚0 € €˜)
8€˜ )
,€˜$)
(€˜(
€˜
-‘) „<) „0
- €õ- 0 A ¤€˜)-0 €˜ - €˜$'
-<€˜ H €˜ ¤^‚< „ *U $€˜`J €˜ " € ) œ€ ) € $)-0 € ('
-€˜€ H € ¤ €˜)
+‘) €<) €0
+ €õ- 0 A  €˜)-0 €˜ - €˜$'
+<€˜ H €˜  ^‚< € *U $€˜`J €˜ " € ) ˜€ ) € $)-0 € ('
+€˜€ H €   €˜)
8€˜ )
,€˜$)
(€˜(
€˜
-‘) „<) „0
- €õ]Ò ° P A ¤€˜)
+‘) €<) €0
+ €õ]Ò ¬ P A  €˜)
<€˜ '
-€H€˜ H €˜ ¤a’€H 1_ª€x( H`’€H 8 € ) œ€ ) € $)-0 € ('
-€˜€ H € ¤ €˜)
+€H€˜ H €˜  a’€H 1_ª€x( H`’€H 8 € ) ˜€ ) € $)-0 € ('
+€˜€ H €   €˜)
8€˜ )
,€˜$)
(€˜(
€˜
-‘) „€P) „€T) „€X) „€\) „€P) „€T) „€X) „€\) „<) „0
- €õ) „€P) „€T) „€X) „€\) „€P) „€T) „€X) „€\ €˜)
+‘) €€P) €€T) €€X) €€\) €€P) €€T) €€X) €€\) €<) €0
+ €õ) €€P) €€T) €€X) €€\) €€P) €€T) €€X) €€\ €˜)
(€˜ )
,€˜$
€˜
@@ -103,57 +103,57 @@
8€˜ )
(€˜$
€˜
-›) „<) „<) „0
- €õ) „(- €@U $€˜`Š€@€˜ r‰€˜$€@))€˜ 4]j 4 o) „€D) „4
- Ž- 4 A ¤€˜)-4 €˜ - €˜$'
-€D€˜ H €˜ ¤]‚€D „ † €˜- €a€˜ )-4 €˜$
+›) €<) €<) €0
+ €õ) €(- €@U $€˜`Š€@€˜ r‰€˜$€@))€˜ 4]j 4 o) €€D) €4
+ Ž- 4 A  €˜)-4 €˜ - €˜$'
+€D€˜ H €˜  ]‚€D € † €˜- €a€˜ )-4 €˜$
€˜ƒé € )-4 € )
€D€ $'
€”€
-€ „Ý €˜r‚€ )-€ €˜ )
-€”€˜$) „€”
+€ „Ý €˜r‚€ Œ )-€ €˜ )
+€”€˜$) €€”
€˜

- Œ € ) œ€ ) € $)-4 € ('
-€˜€ H € ¤) „€D) „4: €@
- g^‚, „ ˜^Ò L ˜ %€˜)
- €˜ ) €˜$- €˜(
-€˜ƒ™ %€˜)
- €˜ ) €˜$- €˜(
+ Œ € ) ˜€ ) € $)-4 € ('
+€˜€ H €  ) €€D) €4: €@
+ g^‚, € ˜^Ò L ˜ $€˜)
+ €˜ ) Œ€˜$- €˜(
+€˜ƒ™ $€˜)
+ €˜ ) Œ€˜$- €˜(
€˜ƒ™ U $<^J < ¡ - 0 P r‚< < <)
< - <$- <('
,<
-<ƒR !<)
+<ƒR <)
,< '
(<
-<„<) (4]Ê „4 Ë) „4 <)
+<„<) (4]Ê €4 Ë) €4 <)
$< )-( <$'
4<
-<ƒ¸]Ê „4 Ã) „4 <- €d< )-( <$
+<ƒ¸]Ê €4 Ã) €4 <- €d< )-( <$
<Ď <)
(< )
,<$
<
]- 0
- É <r‚8 )-8 < )
+ É <r‚8 Œ )-8 < )
,<$)
(<(
<
-‘) „(
+‘) €(
«]’0 Ñ %8)
- 8 ) 8$- 8(
+ 8 ) Œ8$- 8(
8Ī <)
< - <$- <('
0<
<ƒR- 8 !<)
0< '
(<
-<„<) (€@]Ê „€@‚7) „€@ <)
+<„<) (€@]Ê €€@‚7) €€@ <)
$< )-( <$'
,<
-<ƒ¸) ,€@]Ê „€@‚1) „€@- , A ¤<)-, < - <$Hm ÿ( <('
-4< H < ¤^‚4 „ û €D) œ€D ) €D$)-, €D('
-<€D H €D ¤ €D)
+<ƒ¸) ,€@]Ê €€@‚1) €€@- , A  <)-, < - <$Hm ÿ( <('
+4< H <  ^‚4 € û €D) ˜€D ) €D$)-, €D('
+<€D H €D   €D)
(€D )
0€D$
€D
@@ -165,50 +165,50 @@
0€D$)
4€D(
€D
-g]Ò ˆ ‚$) „€H) „€L) „€P) „€Tv €P€X- €`- €d- €h- €l- €pv €P€x- €€- €„-)( €l-)( €p A ¤<)
+g]Ò „ ‚$) €€H) €€L) €€P) €€Tv €P€X- €`- €d- €h- €l- €pv €P€x- €€- €„-)( €l-)( €p A  <)
4< +M €H<('
-€D< H < ¤bJ €D‚ <) œ< ) <$)-, <('
-€D< H < ¤) „€H) „€L) „€P) „€T) „4) „(U $€D`J €D‚/U $€D: 8-
8<_Š€D<‚/) „4) „, ) „4
+€D< H <  bJ €D‚ <) ˜< ) <$)-, <('
+€D< H <  ) €€H) €€L) €€P) €€T) €4) €(U $€D`J €D‚/U $€D: 8-
8<_Š€D<‚/) €4) €, ) €4
‚5 €D)
(€D )
0€D$
€D
-]) „,
+]) €,
Ù 8)
8 - 8$- 8('
,8
8ƒR- 4 !8)
,8 '
(8
-8„<) (<]Ê „<‚m) „< 8)
+8„<) (<]Ê €<‚m) €< 8)
$8 )-( 8$'
08
-8ƒ¸) 0<]Ê „<‚f) „<]Ò ¼ ‚T €@) €@ )-0 €@$'
-8€@ H €@ ¤ A ¤8- 8 '
-<8 H 8 ¤
+8ƒ¸) 0<]Ê €<‚f) €<]Ò ¸ ‚T €@) €@ )-0 €@$'
+8€@ H €@   A  8- 8 '
+<8 H 8  
€@)
(€@ )
,€@$)
-<€@() „<
+<€@() €<
€@
gU $€@`J €@‚jU $€@: 4- 48_Š€@8‚j) „0 €@)
(€@ )
,€@$
€@
-]) „() „0
+]) €() €0
‚? U $8^J 8‚q P r‚8 8 r‚8 8 r‚8 ) „8 8)
8 - 8$- 8('
,8
-8ƒRr‚8 ))8 0 !8)
+8ƒRr‚8 Œ ))8 0 8)
,8 '
(8
-8„<) (<]Ê „<‚ª) „< €@)-( €@ ) ”€@$'
+8„<) (<]Ê €<‚ª) €< €@)-( €@ ) €@$'
8€@
€@ƒ×]J 8‚ r‚€@ €@ ))€@ 0 €@)
$€@ )-( €@$'
4€@
-€@ƒ¸) 4<]Ê „<‚£) „< €@- €m€@ )-4 €@$
-€@ƒé €@r‚8 )-8 €@ )
+€@ƒ¸) 4<]Ê €<‚£) €< €@- €m€@ )-4 €@$
+€@ƒé €@r‚8 Œ )-8 €@ )
,€@$)
(€@(
€@
@@ -218,72 +218,72 @@
,€@$)
(€@(
€@
-‘) „4
- ‚€i „ ”‚³r‚€@ ^ê „€@ ‚³ 8) œ8 ) €ô8$) ”8('
-€@8 H 8 ¤ %€@)
- €@ ) €@$- €@(
+‘) €4
+ ‚€i € ‚³r‚€@ Œ ^ê €€@ ‚³ 8) ˜8 ) €ô8$) 8('
+€@8 H 8   $€@)
+ €@ ) Œ€@$- €@(
€@ƒ™ 8)
8 - 8$- 8('
,8
-8ƒR !8)
+8ƒR 8)
,8 '
(8
-8„<) (<]Ê „<‚å) „< 8)
+8„<) (<]Ê €<‚å) €< 8)
$8 )-( 8$'
48
-8ƒ¸) 4<]Ê „<‚Þ) „<) „0]Ò ¼ ‚Ö 8)
+8ƒ¸) 4<]Ê €<‚Þ) €<) €0]Ò ¸ ‚Ö 8)
(8 '
<8
-8„ S < 0) „< A H€@) D€@ S©04 <S
+8„ S < 0) €< A H€@) D€@ S©04 <S
< €@$) „<'
-8€@ H €@ H) „0 €@)
+8€@ H €@ H) €0 €@)
(€@ )
,€@$
€@
-]) „() „4
+]) €() €4
‚¿ ^Ò€ì ‚è]Ò @ ‚î €@) œ€@ ) €ü€@$'
-<€@ H €@ ¤ž t €@)
+<€@ H €@  ž p €@)
€@ - €@$- €@('
,€@
-€@ƒ.^‚, „ƒ ^Ò L ‚ü <) œ< ) <$)
+€@ƒ.^‚, €ƒ ^Ò L ‚ü <) ˜< ) <$)
<('
-€@< H < ¤ €@)
+€@< H <   €@)
€@ '
,€@
€@ƒh A
- ¤€@)
+  €@)
,€@ v 8€@(- €@0'
€H€@ H
-€@ ¤- 0U $€@`Š0€@ƒ-r‰€@$0))€@ (- ( A ¤€@)-( €@ - €@$'
-8€@ H €@ ¤]‚8 „ƒ# €@- €q€@ )-( €@$
+€@  - 0U $€@`Š0€@ƒ-r‰€@$0))€@ (- ( A  €@)-( €@ - €@$'
+8€@ H €@  ]‚8 €ƒ# €@- €q€@ )-( €@$
€@ƒé €@)-( €@ )
8€@$'
4€@
-€@„Ý]‚4 „ƒ!
+€@„Ý]‚4 €ƒ!
€@)
4€@ )
,€@$
€@
-*) „4) „4
- ƒ) <) œ< ) <$)-( <('
-€@< H < ¤) „8) „(: 0
- ƒ A ¤4)
+*) €4) €4
+ ƒ) <) ˜< ) <$)-( <('
+€@< H <  ) €8) €(: 0
+ ƒ A  4)
4 -
$4$'
-,4 H 4 ¤^‚, „ƒ>^’( ƒ< 8) œ8 ) 8$)
+,4 H 4  ^‚, €ƒ>^’( ƒ< 8) ˜8 ) 8$)
8('
-48 H 8 ¤ž d) „ Q 0 A ¤4)
+48 H 8  ž `) € Q 0 A  4)
,4 )
04$- 4('
-84 H 4 ¤^J 8ƒI4 0<iÊ <ƒP) „< 4) œ4 ) €ø4$)
+84 H 4  ^J 8ƒI4 0<iÊ <ƒP) €< 4) ˜4 ) €ø4$)
4('
-84 H 4 ¤ž d)
+84 H 4  ž `)
, 4)
4 -
$4$-
(4('
04
-4ƒ.^‚0 „ƒ[) „ A H4)
+4ƒ.^‚0 €ƒ[) € A H4)
04 -
$4$'
,4 H 4 H A H4)
@@ -291,24 +291,24 @@
84 H 4 H)
, A ¤,)
, - ,$- ¶,('
-$, H , ¤^‚$ „ƒv 0) œ0 ) 0$)
+$, H ,  ^‚$ €ƒv 0) ˜0 ) 0$)
0('
-,0 H 0 ¤ž `3 ( 0)
+,0 H 0  ž \3 ( 0)
$0 )
(0$U
(0(
0
)
$ $) œ$ ) 8$$'
- $ H $ ¤ž x $) œ$ ) 0$$'
- $ H $ ¤ž p
-,) œ, ) ,,$v
+ $ H $  ž t $) ˜$ ) 0$$'
+ $ H $  ž l
+,) ˜, ) ,,$v
,('
-(, H , ¤ž l $) œ$ ) ¸$$) Œ$() |$,'
- $ H $ ¤ž t A ¤<- < ) „<$'
-8< H < ¤]’( ƒ¥ 8) œ8 ) 8$)
+(, H ,  ž h $) ˜$ ) ´$$) ˆ$() x$,'
+ $ H $  ž p A  <- < ) €<$'
+8< H <  ]’( ƒ¥ 8) ˜8 ) 8$)
8('
-<8 H 8 ¤ <)
+<8 H 8   <)
< '
4<
<ƒh- ,U $<`Š,<ƒ·r‰<$,))< 0) 0€@]Ê „€@ƒµ) „€@ "<)
@@ -320,30 +320,30 @@
$0 )
$0 - 0 )
0 ) „0 - (U ,`Š(,ƒÕr‰, ()), 0^j 0 ƒÓ) „0r‰, ()), 0jª$0 ƒÓ) „0r‰,
()), 0- 0 ) „0r‰, ()-, : (
- ƒÂ) „ _B ˜ƒçaB ˜ƒç ˜€È]Ò€ì ƒÞjŠ$ ƒç- ˜
+ ƒÂ) € _B ”ƒçaB ”ƒç ”€È]Ò€ì ƒÞjŠ$ ƒç- ”
ƒç]Ò @ ƒçjŠ$ ƒç- ˜- - ˜-
ƒç- ]Ò ¼ ƒö 4) 44 -
4$)
$4('
-04 H 4 ¤ A H,) D, )
-0,$) „0'
+04 H 4   A H,) D, )
+0,$) €0'
(, H , H T $b’$ ƒþ=‘$ 4R‰4 0^J/0ƒþ= $
ƒø- ,- (bŠ$(„ R‰( 4^J/4„ :‘( ,: (
„ )
q $, -) 0P 0H 0r 0 €0))0 ,-) 0P 0H 0r 0 €0S)0 ,Hi
0r 0 €0S©,0 $) „, 0) 0 -- 0$-- 0('
-,0 H 0 ¤S ,$) „, 0) 0 -- 0$'
-,0 H 0 ¤S ,$) „, A T4-- 4 '
+,0 H 0  S ,$) €, 0) 0 -- 0$'
+,0 H 0  S ,$) €, A T4-- 4 '
,4 H 4 T A T0)
-,0 ) „,'
+,0 ) €,'
(0 H 0 T 4) 4 T (0)
(4$q•0 4$T (0)
(4(q•0 4('
-,4 H 4 ¤S $, ) „, Q <$ A H8)
+,4 H 4  S $, ) €, Q <$ A H8)
8 )
$8$U
$8('
08 H 8 H- 04U $8]Š84„P^’0 „I) „ b’0 „N A ¤4) ´4 '
-84 H 4 ¤ 8
+84 H 4   8
8ƒ„ (- ,b’, „\=‘, 8t‰8$8Wê€Z8 „Z=‘, 8t‰8$8Wê€Y8 „Z
„\= ,
„R) $<o‘, <4
@@ -377,12 +377,12 @@
,4 H 4  i‚0 „„¢ 8) œ8 )
8$4
8('
-48 H 8 ¤ž d-
+48 H 8  ž `-
, Q <(U (0]’0 „«= 0t‰4(0, €Y4
„¦3) ,U ,4`J 4„¯oQ ,pI ,( 4) (4 -- 4$'
84 H 4 ¤pI 8() „8 4) ,4 - 4$'
84 H 4 ¤pI
-8() „8 4) ,4 - 4$'
+8() €8 4) ,4 - 4$'
84 H 4 ¤pI"8() „8 4) 04 -- 4$'
84 H 4 ¤pI(8() „8 4) $4 -- 4$'
84 H 4 ¤pI08() „8tŠ4(:, €[4 tŠ4(;, €X4 4)
@@ -397,18 +397,18 @@
,„å)
( A ¤€x)
(€x '
-0€x H €x ¤`’0 „ñ €|) œ€| ) €|$)
+0€x H €x  `’0 „ñ €|) ˜€| ) €|$)
$€|('
-€x€| H €| ¤ž h €|)
+€x€| H €|  ž d €|)
$€| '- €|
€|ƒ÷-
€` - - H•€X ÿ ‰
€h Š) €€†Š€h€€
- €x) œ€x ) €x$)
+ €x) ˜€x ) €x$)
$€x('
-€|€x H €x ¤ž d)
-( ) „
- ]ê „
+€|€x H €x  ž `)
+( ) €
+ ]ê €

U-
,Hi 0-) 4: 40, '-
@@ -423,38 +423,38 @@

a’(

- A ¤0) ´0 '
-40 H 0 ¤ 4
+ A  0) °0 '
+40 H 0   4
4ƒ„-
( A
- ¤0)
+  0)
0 )
$0$-
(0('
,0 H
-0 ¤]Š(,
+0  ]Š(,
) 0
0ƒ~
4)
4 )
$4$
-4„¤]ê „
+4„¤]ê €

5 4)
$4 )-
4$U-
4(
4
- ^ê „
+ ^ê €
7ž < Q À ,-) 0b’0
S- 0(U ,4bŠ(4
->U ,( A ¤4)- 4 )
+>U ,( A  4)- 4 )
,4$-
(4('
-(4 H 4 ¤_’(
+(4 H 4  _’(
L^’(
-J A ¤8) ´8 '
-48 H 8 ¤ 8
+J A  8) °8 '
+48 H 8   8
8ƒ„ 8)
$8 )
,8$-
@@ -469,7 +469,7 @@
A H()
$( Hi ,-) 0: 0,Š
,((- (0'
-8( H ( H ]ê „
+8( H ( H ]ê €

n 8)
(8 )-
@@ -484,8 +484,8 @@
,8('
,8 H 8 H_’,
ƒ^’,
- A ¤<) ´< '
-8< H < ¤ <
+ A  <) °< '
+8< H <   <
<ƒ„ <)
(< )
0<$-
@@ -505,20 +505,20 @@
0 )
(0$
0
-› ) „$$^ê „
+› ) €$$^ê €
Ÿ)
$

¢)) ()
-$($) „()
-$ ]ê „
+$($) €()
+$ ]ê €
¿ Q À , A
- ¤4)- 4 v 84(- 40'
+  4)- 4 v 84(- 40'
€@4 H
-4 ¤ A ¤8)- 8 )
+4   A  8)- 8 )
,8$U
,8('
-08 H 8 ¤- 04`J 4
+08 H 8  - 04`J 4
º 8)
$8 )
,8$-
@@ -528,7 +528,7 @@

¬`’0
½ 8
-8ƒ„) „ ) „,)) (]‚( „
+8ƒ„) € ) €,)) (]‚( €
Ç
8)
(8 )
@@ -536,36 +536,36 @@
8
*))($(

-À )) $^ê „
-ï^Ò À
-ï A ¤4- 4 ) „4$'
-04 H 4 ¤- ( 4) €è4 -
-04$- ¨4(-
+À )) $^ê €
+ï^Ò ¼
+ï A  4- 4 ) €4$'
+04 H 4  - ( 4) €è4 -
+04$- ¤4(-
(4,'
-,4 H 4 ¤ A ¤4)
+,4 H 4   A  4)
,4 - B4$- €4('- 4 H 4 ¤]ê „
-á) „,
+á) €,

îa’(
-ë- À 8) œ8 ) 48$)
+ë- ¼ 8) ˜8 ) 48$)
,8('
-48 H 8 ¤- ) „,: (
+48 H 8  - ) €,: (

-Ñ: ¨
+Ñ: ¤
8)
$8 )- 8$
8
*)-$$ ^ª$
ö)-$$ U)$
-8= 8 ¬- : ¬(- À `Š († - $U (`Š$(† r ( $]ê „( †
-,r 0 $)-0 , '
+8= 8 ¨- : ¨(- À `Š († - $U Œ(`Š$(† r ( Œ$]ê €( †
+,r 0 Œ$)-0 , '
(,
,
È]J (†

ú: $

-þ: ¬ M Ä ÿü ïÿÿoÿÝÆ € € À à ( ( € ( À ( À
+þ: ¨ M À ÿü ïÿÿoÿ»Œ € € À à ( ( € ( À ( À
0 0 € 0  

0 À 0 à 0 ð 8 8 H 8 € 8 À 8 È 8 à 8 ð €@ ð €@ ˆ €@ ˜ €@ ™ €@ À
€@ Ð
@@ -603,5 +603,5 @@
0 8ar: write error: %r
0 <ar: write nil
fd! @ ! L 5 Xerror5 \fail:; `fail:create: dfail:error< hfail:no
stat0 lfail:phase error? pfail:read error: tfail:usage0 xfail:write
error7 |mrxtdpqQ € a € 3 ---3 --x3 -w-3 -wx3 r--3 r-x3 rw-3
rwxq ! ˆ 8 Œuvnbailo! ˜ # ¨ 0 ´unexpected
end-of-file0% ¸usage: ar [%s][%s] archive files ...
-" ¼ Ar
BD³Tinit ž Of% dcmd ‚n$Of% mcmd ‚8#Of% pcmd ‚æ&Of% qcmd €ç)Of% rcmd ‚¹$Of% tcmd Ò(Of% xcmd BD³Tinit Of% dcmd Of% mcmd Of% pcmd Of% qcmd Of% rcmd Of% tcmd Of% xcmd Ùè6[Iobuf.flush ,8e fopen Ùè6[Iobuf.getc ø· Iobuf.offset 1ëIobuf.puts Ô
+" ¸ Ar &BD³Tinit ž Of% dcmd ‚n#Of% mcmd ‚8"Of% pcmd ‚æ%Of% qcmd €ç)Of% rcmd ‚¹#Of% tcmd Ò(Of% xcmd BD³Tinit Of% dcmd Of% mcmd Of% pcmd Of% qcmd Of% rcmd Of% tcmd Of% xcmd Ùè6[Iobuf.flush ,8e fopen Ùè6[Iobuf.getc ø· Iobuf.offset 1ëIobuf.puts Ô

9»Iobuf.read u¾Ö2Iobuf.seek ëB}`local   ž text J¦à#toint wD-Faprint TÛwÙcreate xù“fildes ôd†Èfprint ÚD™Âfstat P¦Çàfwstat G ™open ß'ûpctl ¬„ 3print |
þõWread ®Ì­Ûseek L $¶sprint Æ“XXwerrstr |þõWwrite /appl/cmd/ar.b

==============================================================================
Revision: ab3b05624d
Author: for...@vitanuova.com
Date: Sat Aug 21 10:01:11 2010
Log: 20100821-1800
http://code.google.com/p/inferno-npe/source/detail?r=ab3b05624d

Modified:
/include/tk.h
/include/version.h
/libtk/canvs.c
/libtk/canvs.h
/libtk/canvu.c
/libtk/cwind.c
/libtk/ebind.c
/libtk/entry.c
/libtk/grids.c
/libtk/packr.c
/libtk/textu.c
/libtk/textw.c
/libtk/textw.h
/libtk/twind.c
/libtk/utils.c
/libtk/windw.c

=======================================
--- /include/tk.h Fri Apr 2 12:48:59 2010
+++ /include/tk.h Sat Aug 21 10:01:11 2010
@@ -455,7 +455,7 @@
Tk* master; /* Pack owner */
Tk* slave; /* Packer slaves */
Tk* next; /* Link for packer slaves */
- Tk* parent; /* Window is sub of canvas or text */
+ Tk* parent; /* Window is sub of this canvas or text */
Tk* depth; /* Window depth when mapped */
void (*geom)(Tk*, int, int, int, int); /* Geometry change notify
function */
void (*destroyed)(Tk*); /* Destroy notify function */
@@ -473,7 +473,7 @@
Rectangle dirty; /* dirty rectangle, relative to widget */
TkGrid* grid; /* children are packed in a grid */

-// char obj[TKSTRUCTALIGN];
+ /* followed by widget-dependent data */
};

struct TkWin
@@ -514,6 +514,7 @@
void (*see)(Tk*, Rectangle*, Point*);
Tk* (*inwindow)(Tk*, Point*);
void (*varchanged)(Tk*, char*, char*);
+ void (*forgetsub)(Tk*, Tk*);
int ncmd;
};

@@ -733,6 +734,7 @@
extern void tkputenv(TkEnv*);
extern TkEnv* tkdupenv(TkEnv**);
extern Tk* tknewobj(TkTop*, int, int);
+extern Tk* tkfindsub(Tk*);
extern void tkfreebind(TkAction*);
extern void tkfreename(TkName*);
extern void tkfreeobj(Tk*);
@@ -750,7 +752,6 @@
extern void tkcancel(TkAction**, int);
extern char* tkaction(TkAction**, int, int, char*, int);
extern char* tkitem(char*, char*);
-extern int tkismapped(Tk*);
extern Point tkposn(Tk*);
extern Point tkscrn2local(Tk*, Point);
extern int tkvisiblerect(Tk *tk, Rectangle *rr);
@@ -818,6 +819,11 @@
extern void tkextnfreectxt(TkCtxt*);
extern char* tkextnparseseq(char*, char*, int*);

+/* Debugging */
+extern void tkdump(Tk*);
+extern void tktopdump(Tk*);
+extern void tkcvsdump(Tk*);
+
/* External to libtk */
extern void tkenterleave(TkTop*);
extern void tksetwinimage(Tk*, Image*);
=======================================
--- /include/version.h Thu Aug 19 08:17:42 2010
+++ /include/version.h Sat Aug 21 10:01:11 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100819)"
+#define VERSION "Fourth Edition (20100821)"
=======================================
--- /libtk/canvs.c Mon Mar 22 07:41:55 2010
+++ /libtk/canvs.c Sat Aug 21 10:01:11 2010
@@ -2214,5 +2214,7 @@
tkcvsrelpos,
tkcvsevent,
tkcvsseesub,
- tkcvsinwindow
+ tkcvsinwindow,
+ nil,
+ tkcvsforgetsub,
};
=======================================
--- /libtk/canvs.h Fri Dec 22 09:07:39 2006
+++ /libtk/canvs.h Sat Aug 21 10:01:11 2010
@@ -236,3 +236,5 @@
extern char* tkcvsimgcget(TkCitem*, char*, char**);
extern char* tkcvsimgconf(Tk*, TkCitem*, char*);

+extern TkCitem* tkcvsfindwin(Tk*);
+extern void tkcvsforgetsub(Tk*, Tk*);
=======================================
--- /libtk/canvu.c Fri Dec 22 09:07:39 2006
+++ /libtk/canvu.c Sat Aug 21 10:01:11 2010
@@ -426,18 +426,22 @@
if(!(event & TkKey) && (event & TkEmouse)) {
ftk = tkcvsmouseinsub(w, *(TkMouse*)data);
if(ftk != w->focus) {
+{TkCitem *si; if(w->focus != nil && (si = tkcvsfindwin(w->focus)) !=
i)print("focus botch 4: i=%p si=%p\n", i, si);}
tkdeliver(w->focus, TkLeave, data);
+{TkCitem *si; if(ftk != nil && (si = tkcvsfindwin(ftk)) != i)print("focus
botch: i=%p si=%p\n", i, si);}
+if(0)print("focus %p %q %p %q\n", w->sub, tkname(w->sub), ftk,
tkname(ftk));
tkdeliver(ftk, TkEnter, data);
w->focus = ftk;
}
+else{TkCitem *si; if(ftk != nil && (si = tkcvsfindwin(ftk)) !=
i)print("focus botch 2: i=%p si=%p\n", i, si);}
if(ftk != nil)
dest = tkdeliver(ftk, event, data);
- }
- else {
- if (event & TkLeave) {
+ } else {
+{TkCitem *si; if(w->focus != nil && (si = tkcvsfindwin(w->focus)) !=
i)print("focus botch 3: i=%p si=%p\n", i, si);}
+ if(event & TkLeave) {
tkdeliver(w->focus, TkLeave, data);
w->focus = nil;
- } else if (event & TkEnter) {
+ } else if(event & TkEnter) {
ftk = tkcvsmouseinsub(w, *(TkMouse*)data);
tkdeliver(ftk, TkEnter, data);
w->focus = ftk;
@@ -504,3 +508,39 @@
tksubdeliver(tk, tk->binds, event, data, 0);
return dest;
}
+
+/*
+ * debugging
+ */
+void
+tkcvsdump(Tk *tk)
+{
+ TkCanvas *c;
+ TkCitem *it;
+ TkCwind *w;
+ char v1[Tkminitem], v2[Tkminitem];
+ int i;
+
+ if(tk == nil)
+ return;
+ c = TKobj(TkCanvas, tk);
+ tkfprint(v1, c->width);
+ tkfprint(v2, c->height);
+ print("%q configure -width %s -height %s", tkname(tk), v1, v2);
+ print(" # focus %#p mouse %#p grab %#p\n", c->focus, c->mouse, c->grab);
+ for(it = c->head; it != nil; it = it->next){
+ print("%q create %q", tkname(tk), tkcimethod[it->type].name);
+ for(i = 0; i < it->p.npoint; i++){
+ tkfprint(v1, it->p.parampt[i].x);
+ tkfprint(v2, it->p.parampt[i].y);
+ print(" %s %s", v1, v2);
+ }
+ if(it->type == TkCVwindow){
+ w = TKobj(TkCwind, it);
+ if(w->sub != nil)
+ print(" -window %q", tkname(w->sub));
+ print(" # item %#p id %d sub %#p focus [%#p %q]\n", it, it->id, w->sub,
w->focus, tkname(w->focus));
+ }else
+ print("# item %#p id %d\n", it, it->id);
+ }
+}
=======================================
--- /libtk/cwind.c Fri Dec 22 09:07:39 2006
+++ /libtk/cwind.c Sat Aug 21 10:01:11 2010
@@ -63,6 +63,47 @@
i->p.bb.max.x = p.x + s->act.width + bw;
i->p.bb.max.y = p.y + s->act.height + bw;
}
+
+TkCitem*
+tkcvsfindwin(Tk *tk)
+{
+ Tk *parent, *sub;
+ TkCitem *i;
+ TkCanvas *c;
+ TkCwind *w;
+
+ sub = tkfindsub(tk);
+ if(sub == nil)
+ return nil;
+ parent = sub->parent;
+ if(parent->type != TKcanvas)
+ return nil; /* inconsistent */
+ c = TKobj(TkCanvas, parent);
+ for(i = c->head; i != nil; i = i->next) {
+ if(i->type == TkCVwindow) {
+ w = TKobj(TkCwind, i);
+ if(w->sub == sub)
+ return i;
+ }
+ }
+ return nil;
+}
+
+void
+tkcvsforgetsub(Tk *sub, Tk *tk)
+{
+ TkCwind *w;
+ TkCitem *i;
+
+ i = tkcvsfindwin(sub);
+ if(i == nil)
+ return;
+ w = TKobj(TkCwind, i);
+ if(w->focus == tk) {
+if(0)print("tkcsvsforget sub %p %q focus %p %q\n", sub, tkname(sub), tk,
tkname(tk));
+ w->focus = nil;
+ }
+}

static int
tkcvschkwfocus(TkCwind *w, Tk *tk)
@@ -97,6 +138,7 @@
}

if(win->focus != nil) {
+if(0)print("check focus %p %q %p %q\n", win, tkname(win->focus), sub,
tkname(sub));
if(tkcvschkwfocus(win, sub) == 0)
win->focus = nil;
}
@@ -127,6 +169,15 @@
tk = sub->parent;
if(tk == nil)
return;
+
+if(0)print("tkcvssubdestry %p %q\n", sub, tkname(sub));
+ i = tkcvsfindwin(sub);
+ if(i != nil){
+ win = TKobj(TkCwind, i);
+ if(win->sub != sub){
+ print("inconsistent tkcvssubdestry %p %q\n", sub, tkname(sub));
+ }
+ }

c = TKobj(TkCanvas, tk);
for(i = c->head; i; i = i->next) {
=======================================
--- /libtk/ebind.c Mon Mar 22 07:41:55 2010
+++ /libtk/ebind.c Sat Aug 21 10:01:11 2010
@@ -810,7 +810,7 @@
if(strcmp(buf, n) == 0) {
tk->flag |= Tkdestroy;
found = 1;
- } else if(isroot || (strncmp(buf, n, len) == 0 &&n[len] == '.'))
+ } else if(isroot || (strncmp(buf, n, len) == 0 && n[len] == '.'))
tk->flag |= Tkdestroy;
}
}
@@ -827,13 +827,14 @@
continue;
if(tk->flag & Tkwindow) {
tkunmap(tk);
- if((tk->name != nil)
- && (strcmp(tk->name->name, ".") == 0))
+ if(tk->name != nil &&
+ strcmp(tk->name->name, ".") == 0)
tk->flag &= ~Tkdestroy;
else
tkdeliver(tk, TkDestroy, nil);
} else
tkdeliver(tk, TkDestroy, nil);
+if(0)print("tkdestroy %q\n", tkname(tk));
if(tk->destroyed != nil)
tk->destroyed(tk);
tkpackqit(tk->master);
=======================================
--- /libtk/entry.c Mon Mar 22 07:41:55 2010
+++ /libtk/entry.c Sat Aug 21 10:01:11 2010
@@ -178,17 +178,6 @@
t1 = 0;
return t1;
}
-
-static int
-x2index0(Tk *tk, int x, int *xc)
-{
- int xx, z;
- z = x2index(tk, x, &xx);
- print("x2index(%d)-> (%d, %d)\n", x, z, xx);
- if (xc)
- *xc = xx;
- return z;
-}

/*
* recalculate derived values
=======================================
--- /libtk/grids.c Fri Dec 22 09:07:39 2006
+++ /libtk/grids.c Sat Aug 21 10:01:11 2010
@@ -143,7 +143,7 @@
for(i = olddim.y; i < dim.y; i++){
cells[i] = malloc(sizeof(TkGridcell)*dim.x);
if(cells[i] == nil){
- for(i--; i >= olddim.y; i--)
+ while(--i >= olddim.y)
free(cells[i]);
return TkNomem;
}
@@ -721,32 +721,6 @@
return -1;
}

-/*
- * optimised way to find a given slave, but somewhat more fragile
- * as it assumes the slave has already been placed on the grid.
- * not tested.
- */
-static int
-findslave(TkGrid *grid, Tk *tk, Point *pt)
-{
- Point loc, dim, p;
- TkGridcell **cells;
- dim = grid->dim;
- cells = grid->cells;
- loc.x = gridfindloc(grid->cols, grid->dim.x, tk->act.x);
- if(loc.x == -1)
- loc.x = 0;
- loc.y = gridfindloc(grid->rows, grid->dim.y, tk->act.y);
- if(loc.y == -1)
- loc.y = 0;
- for(p.y = loc.y; p.y < dim.y; p.y++)
- for(p.x = loc.x; p.x < dim.x; p.x++)
- if(cells[p.y][p.x].tk == tk){
- *pt = p;
- return 1;
- }
- return 0;
-}
static char*
tkgridcellinfo(TkTop *t, char *arg, char **val, char *buf, char *ebuf)
{
=======================================
--- /libtk/packr.c Fri Dec 22 09:07:39 2006
+++ /libtk/packr.c Sat Aug 21 10:01:11 2010
@@ -80,7 +80,14 @@
void
tkdelpack(Tk *t)
{
- Tk *f, **l;
+ Tk *f, **l, *sub, *p;
+
+ sub = tkfindsub(t);
+ if(sub != nil) {
+ p = sub->parent;
+ if(tkmethod[p->type]->forgetsub != nil)
+ tkmethod[p->type]->forgetsub(sub, t);
+ }

if(t->master == nil)
return;
=======================================
--- /libtk/textu.c Fri Dec 22 16:30:12 2006
+++ /libtk/textu.c Sat Aug 21 10:01:11 2010
@@ -571,6 +571,7 @@
/* r in V space */
r.min = subpt(l->orig, tkt->deltatv);
r.min.y += l->ascent;
+ r.max = r.min;

/* tabs dependon tags of first non-mark on display line */
for(i = l->items; i->kind == TkTmark; )
=======================================
--- /libtk/textw.c Mon Mar 22 07:41:55 2010
+++ /libtk/textw.c Sat Aug 21 10:01:11 2010
@@ -117,6 +117,8 @@
{TkKey|Pgdown, "%W yview scroll 0.75 page"},
{TkKey|CNTL('w'), "%W tkTextDelIns -w"},
{TkKey|Pgup, "%W yview scroll -0.75 page"},
+ {TkButton4P, "%W yview scroll -0.2 page"},
+ {TkButton5P, "%W yview scroll 0.2 page"},
{TkFocusout, "%W tkTextCursor delete"},
{TkKey|APP|'\t', ""},
{TkKey|BackTab, ""},
=======================================
--- /libtk/textw.h Fri Dec 22 09:07:39 2006
+++ /libtk/textw.h Sat Aug 21 10:01:11 2010
@@ -112,16 +112,16 @@
struct TkTwind
{
Tk* sub; /* Subwindow of canvas */
+ Tk* focus; /* Current Mouse focus */
+ int width; /* current internal width */
+ int height; /* current internal height */
+ int owned; /* true if window is destroyed on item deletion */
int align; /* how to align within line */
char* create; /* creation script */
int padx; /* extra space on each side */
int pady; /* extra space on top and bot */
- int width; /* current internal width */
- int height; /* current internal height */
int ascent; /* distance from top of widget to baseline */
int stretch; /* true if need to stretch height */
- int owned; /* true if window is destroyed on item deletion */
- Tk* focus; /* Current Mouse focus */
};

struct TkTitem
=======================================
--- /libtk/twind.c Fri Dec 22 09:07:39 2006
+++ /libtk/twind.c Sat Aug 21 10:01:11 2010
@@ -383,9 +383,9 @@
tktstartind(tkt, &ix);
fmt = "%s";
do {
- if(ix.item->kind == TkTwin
- && ix.item->iwin->sub != nil
- && (ix.item->iwin->sub->name != nil)) {
+ if(ix.item->kind == TkTwin &&
+ ix.item->iwin->sub != nil &&
+ ix.item->iwin->sub->name != nil) {
e = tkvalue(val, fmt, ix.item->iwin->sub->name->name);
if(e != nil)
return e;
=======================================
--- /libtk/utils.c Tue Apr 6 11:59:10 2010
+++ /libtk/utils.c Sat Aug 21 10:01:11 2010
@@ -56,7 +56,8 @@

char* tkfont;

-/* auto-repeating support
+/*
+ * auto-repeating support
* should perhaps be one rptproc per TkCtxt
* This is not done for the moment as there isn't
* a mechanism for terminating the rptproc
@@ -1016,17 +1017,25 @@
char*
tkname(Tk *tk)
{
- return tk ? (tk->name ? tk->name->name : "(noname)") : "(nil)";
+ if(tk == nil)
+ return "(nil)";
+ if(tk->name == nil)
+ return "(noname)";
+ return tk->name->name;
}

Tk*
tkdeliver(Tk *tk, int event, void *data)
{
Tk *dest;
+
+ if(tk != nil && ((ulong)tk->type >= TKwidgets || (ulong)tk->name < 4096
&& tk->name != nil)){
+ print("invalid Tk: type %d name %p\n", tk->type, tk->name);
+ abort();
+ }
//print("tkdeliver %v to %s\n", event, tkname(tk));
if(tk == nil || ((tk->flag&Tkdestroy) && event != TkDestroy))
return tk;
-
if(event&(TkFocusin|TkFocusout) && (tk->flag&Tktakefocus))
tk->dirty = tkrect(tk, 1);

@@ -1058,6 +1067,7 @@
TkAction *a;
int delivered, genkey, delivered2, iskey;
//int (*debug)(char *fmt, ...);
+
if (!extn)
return tkextndeliver(tk, binds, event, data);

@@ -1201,20 +1211,18 @@
return a;
}

-int
-tkismapped(Tk *tk)
-{
- while(tk->master)
- tk = tk->master;
-
- /* We need subwindows of text & canvas to appear mapped always
- * so that the geom function update are seen by the parent
- * widget
- */
- if((tk->flag & Tkwindow) == 0)
- return 1;
-
- return tk->flag & Tkmapped;
+/*
+ * if tk is a subwindow or a descendent, return the subwindow;
+ * return nil otherwise
+ */
+Tk*
+tkfindsub(Tk *tk)
+{
+ for(; tk != nil; tk = tk->master){
+ if(tk->parent != nil)
+ return tk; /* tk->parent is canvas or text */
+ }
+ return nil;
}

/*
@@ -1233,21 +1241,19 @@
if(tk->parent != nil) {
g = tkmethod[tk->parent->type]->relpos(tk);
f = tk->parent;
- }
- else {
+ } else {
g.x = tk->act.x;
g.y = tk->act.y;
f = tk->master;
}
- while(f) {
+ while(f != nil) {
g.x += f->borderwidth;
g.y += f->borderwidth;
last = f;
if(f->parent != nil) {
g = addpt(g, tkmethod[f->parent->type]->relpos(f));
f = f->parent;
- }
- else {
+ } else {
g.x += f->act.x;
g.y += f->act.y;
f = f->master;
@@ -2064,3 +2070,55 @@
else
rptwakeup(nil, blinkrpt);
}
+
+/*
+ * debugging
+ */
+void
+tkdump(Tk *tk)
+{
+ Tk *sl;
+
+ if(tk == nil)
+ return;
+ if((uint)tk->type < TKwidgets)
+ print("%s", tkmethod[tk->type]->name);
+ else
+ print("TYPE#%#ux", tk->type);
+ if(tk->name == nil || (ulong)tk->name < 512)
+ print(" NAME %p", tk->name);
+ else
+ print(" %s", tkname(tk));
+ print(" # tk %#p flag %#ux grid %#p", tk, tk->flag, tk->grid);
+ if(tk->parent != nil)
+ print(" parent [%#p %q]", tk->parent, tkname(tk->parent));
+ if(tk->master != nil)
+ print(" master [%#p %q]", tk->master, tkname(tk->master));
+ if(tk->slave != nil){
+ print(" slaves");
+ for(sl = tk->slave; sl != nil; sl = sl->next)
+ print(" [%#p %q]", sl, tkname(sl));
+ }
+ print("\n");
+ if(tk->type != TKcanvas)
+ return;
+ tkcvsdump(tk);
+}
+
+void
+tktopdump(Tk *tk)
+{
+ TkTop *top;
+ Tk *sub;
+
+ if(tk == nil || tk->env == nil){
+ print("# %#p no top\n", tk);
+ return;
+ }
+ top = tk->env->top;
+ print("# env %#p top %#p\n", tk->env, top);
+ if(top != nil){
+ for(sub = top->root; sub != nil; sub = sub->siblings)
+ tkdump(sub);
+ }
+}
=======================================
--- /libtk/windw.c Fri Dec 22 16:30:12 2006
+++ /libtk/windw.c Sat Aug 21 10:01:11 2010
@@ -387,29 +387,6 @@
return nil;
//tkupdate(tk->env->top);
}
-
-void
-tkclrfocus(Tk *master)
-{
- TkCtxt *c;
- Tk *tk;
- TkTop *top;
-
- if(master == nil)
- return;
- top = master->env->top;
- c = top->ctxt;
-
- tk = c->mgrab;
- if(tkischild(master, tk))
- tksetmgrab(top, nil);
-
- tk = c->entered;
- if(tkischild(master, tk)){
- c->entered = nil;
- tkdeliver(tk, TkLeave, nil);
- }
-}

void
tkunmap(Tk *tk)

==============================================================================
Revision: cf9af9a93a
Author: for...@vitanuova.com
Date: Sat Aug 21 11:20:57 2010
Log: 20100821-1920
http://code.google.com/p/inferno-npe/source/detail?r=cf9af9a93a

Modified:
/CHANGES
/libtk/NOTICE
/libtk/canvu.c

=======================================
--- /CHANGES Thu Aug 19 08:17:42 2010
+++ /CHANGES Sat Aug 21 11:20:57 2010
@@ -1,5 +1,8 @@
+20100821
+ correct handling of mouse focus in sub-widgets of widget windowed in
canvas (soon, text widget) [issue 241]
20100819
failed to push Solaris/sparc/include/lib9.h with u64int change [issue 151]
+ appl/cmd/ar.b eliminate false error return
20100810
initial introduction of crypt-*(2) and ipints(2)
replace keyring.m in module/runt.m by ipints.m and crypt.m; compensate in
libinterp and libkeyring by using keyringif.m to generate Keyring's
interface
=======================================
--- /libtk/NOTICE Fri Feb 2 15:50:37 2007
+++ /libtk/NOTICE Sat Aug 21 11:20:57 2010
@@ -8,7 +8,8 @@

Copyright © 1995-1999 Lucent Technologies Inc.
Portions Copyright © 1997-2000 Vita Nuova Limited
-Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
+Portions Copyright © 2000-2008 Vita Nuova Holdings Limited
+Portions Copyright © 2010 Vita Nuova Holdings Limited

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (`LGPL') as
published by
=======================================
--- /libtk/canvu.c Sat Aug 21 10:01:11 2010
+++ /libtk/canvu.c Sat Aug 21 11:20:57 2010
@@ -426,18 +426,14 @@
if(!(event & TkKey) && (event & TkEmouse)) {
ftk = tkcvsmouseinsub(w, *(TkMouse*)data);
if(ftk != w->focus) {
-{TkCitem *si; if(w->focus != nil && (si = tkcvsfindwin(w->focus)) !=
i)print("focus botch 4: i=%p si=%p\n", i, si);}
tkdeliver(w->focus, TkLeave, data);
-{TkCitem *si; if(ftk != nil && (si = tkcvsfindwin(ftk)) != i)print("focus
botch: i=%p si=%p\n", i, si);}
if(0)print("focus %p %q %p %q\n", w->sub, tkname(w->sub), ftk,
tkname(ftk));
tkdeliver(ftk, TkEnter, data);
w->focus = ftk;
}
-else{TkCitem *si; if(ftk != nil && (si = tkcvsfindwin(ftk)) !=
i)print("focus botch 2: i=%p si=%p\n", i, si);}
if(ftk != nil)
dest = tkdeliver(ftk, event, data);
} else {
-{TkCitem *si; if(w->focus != nil && (si = tkcvsfindwin(w->focus)) !=
i)print("focus botch 3: i=%p si=%p\n", i, si);}
if(event & TkLeave) {
tkdeliver(w->focus, TkLeave, data);
w->focus = nil;

==============================================================================
Revision: a3e633a4e6
Author: for...@vitanuova.com
Date: Sun Aug 22 05:59:46 2010
Log: 20100822-1358
http://code.google.com/p/inferno-npe/source/detail?r=a3e633a4e6

Modified:
/CHANGES
/libtk/canvu.c
/libtk/cwind.c
/libtk/textw.c
/libtk/textw.h
/libtk/twind.c
/libtk/windw.c

=======================================
--- /CHANGES Sat Aug 21 11:20:57 2010
+++ /CHANGES Sun Aug 22 05:59:46 2010
@@ -1,5 +1,7 @@
+20100822
+ correct handling of mouse focus in sub-widgets of widget windowed in text
[issue 241]
20100821
- correct handling of mouse focus in sub-widgets of widget windowed in
canvas (soon, text widget) [issue 241]
+ correct handling of mouse focus in sub-widgets of widget windowed in
canvas [issue 241]
20100819
failed to push Solaris/sparc/include/lib9.h with u64int change [issue 151]
appl/cmd/ar.b eliminate false error return
=======================================
--- /libtk/canvu.c Sat Aug 21 11:20:57 2010
+++ /libtk/canvu.c Sun Aug 22 05:59:46 2010
@@ -338,16 +338,14 @@

if(anchor & Tknorth)
o.y = dp.y;
- else
- if(anchor & Tksouth)
+ else if(anchor & Tksouth)
o.y = dp.y - h;
else
o.y = dp.y - h/2;

if(anchor & Tkwest)
o.x = dp.x;
- else
- if(anchor & Tkeast)
+ else if(anchor & Tkeast)
o.x = dp.x - w;
else
o.x = dp.x - w/2;
=======================================
--- /libtk/cwind.c Sat Aug 21 10:01:11 2010
+++ /libtk/cwind.c Sun Aug 22 05:59:46 2010
@@ -104,17 +104,6 @@
w->focus = nil;
}
}
-
-static int
-tkcvschkwfocus(TkCwind *w, Tk *tk)
-{
- if(w->focus == tk)
- return 1;
- for(tk = tk->slave; tk; tk = tk->next)
- if(tkcvschkwfocus(w, tk))
- return 1;
- return 0;
-}

static void
tkcvswindgeom(Tk *sub, int x, int y, int w, int h)
@@ -136,12 +125,6 @@
break;
}
}
-
- if(win->focus != nil) {
-if(0)print("check focus %p %q %p %q\n", win, tkname(win->focus), sub,
tkname(sub));
- if(tkcvschkwfocus(win, sub) == 0)
- win->focus = nil;
- }

tkbbmax(&c->update, &i->p.bb);

@@ -172,29 +155,23 @@

if(0)print("tkcvssubdestry %p %q\n", sub, tkname(sub));
i = tkcvsfindwin(sub);
- if(i != nil){
- win = TKobj(TkCwind, i);
- if(win->sub != sub){
+ if(i == nil)
+ return;
+ win = TKobj(TkCwind, i);
+ if(win->sub != sub){
+ if(win->sub != nil)
print("inconsistent tkcvssubdestry %p %q\n", sub, tkname(sub));
- }
+ return;
}

c = TKobj(TkCanvas, tk);
- for(i = c->head; i; i = i->next) {
- if(i->type == TkCVwindow) {
- win = TKobj(TkCwind, i);
- if(win->sub == sub) {
- tkbbmax(&c->update, &i->p.bb);
- tkcvssetdirty(tk);
-
- win->focus = nil;
- win->sub = nil;
- sub->parent = nil;
- sub->geom = nil;
- return;
- }
- }
- }
+ tkbbmax(&c->update, &i->p.bb);
+ tkcvssetdirty(tk);
+
+ win->focus = nil;
+ win->sub = nil;
+ sub->parent = nil;
+ sub->geom = nil;
}

Point
@@ -386,13 +363,13 @@

w = TKobj(TkCwind, i);
sub = w->sub;
- if(w->focus == sub)
- w->focus = nil;
if(sub != nil) {
sub->parent = nil;
sub->geom = nil;
sub->destroyed = nil;
}
+ w->focus = nil;
+ w->sub = nil;
}

void
=======================================
--- /libtk/textw.c Sat Aug 21 10:01:11 2010
+++ /libtk/textw.c Sun Aug 22 05:59:46 2010
@@ -3693,5 +3693,7 @@
tktrelpos,
tktextevent,
nil, /* XXX need to implement textsee */
- tktinwindow
+ tktinwindow,
+ nil,
+ tktxtforgetsub,
};
=======================================
--- /libtk/textw.h Sat Aug 21 10:01:11 2010
+++ /libtk/textw.h Sun Aug 22 05:59:46 2010
@@ -227,3 +227,4 @@
extern char* tkttagparse(Tk*, char**, TkTtaginfo**);
extern int tkttagset(TkTitem*, int);
extern int tktxyind(Tk*, int, int, TkTindex*);
+extern void tktxtforgetsub(Tk*, Tk*);
=======================================
--- /libtk/twind.c Sat Aug 21 10:01:11 2010
+++ /libtk/twind.c Sun Aug 22 05:59:46 2010
@@ -101,21 +101,19 @@
tktextsize(tk, 1);
}

-/*
- * check that w->focus is a window packed under tk.
- * XXX couldn't this be done more simply by traversing
- * directly upwards from w->focus and seeing whether
- * it hits tk? (same applies to tkcvschkwfocus in cwind.c)
- */
-static int
-tktchkwfocus(TkTwind *w, Tk *tk)
-{
- if(w->focus == tk)
- return 1;
- for(tk = tk->slave; tk; tk = tk->next)
- if(tktchkwfocus(w, tk))
- return 1;
- return 0;
+void
+tktxtforgetsub(Tk *sub, Tk *tk)
+{
+ TkTwind *w;
+ TkTindex ix;
+
+ if(!tktfindsubitem(sub, &ix))
+ return;
+ w = ix.item->iwin;
+ if(w->focus == tk) {
+if(0)print("tktxtforget sub %p %q focus %p %q\n", sub, tkname(sub), tk,
tkname(tk));
+ w->focus = nil;
+ }
}

static void
@@ -136,11 +134,6 @@

win = ix.item->iwin;

- if(win->focus != nil) {
- if(tktchkwfocus(win, sub) == 0)
- win->focus = nil;
- }
-
win->width = w;
win->height = h;

=======================================
--- /libtk/windw.c Sat Aug 21 10:01:11 2010
+++ /libtk/windw.c Sun Aug 22 05:59:46 2010
@@ -150,7 +150,6 @@
return tk;
tk = f;
}
- return nil; /* for compiler */
}

Tk*

==============================================================================
Revision: 5426124d08
Author: for...@vitanuova.com
Date: Thu Sep 2 16:32:34 2010
Log: 20100903-0032
http://code.google.com/p/inferno-npe/source/detail?r=5426124d08

Modified:
/os/cerf1110/cerf
/os/cerf250/cerf
/os/cerf405/cerf
/os/fads/fads
/os/gum/gum
/os/ipaq1110/ipaq
/os/ipengine/ipe
/os/js/js
/os/manga/manga
/os/pc/pc4e
/os/pc/pcdisk
/os/pc/pix
/os/rpcg/rpcg

=======================================
--- /os/cerf1110/cerf Tue Aug 10 15:06:28 2010
+++ /os/cerf1110/cerf Thu Sep 2 16:32:34 2010
@@ -57,7 +57,8 @@
sys
# draw
# tk
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/cerf250/cerf Tue Aug 10 15:06:28 2010
+++ /os/cerf250/cerf Thu Sep 2 16:32:34 2010
@@ -60,7 +60,8 @@
sys
# draw
# tk
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/cerf405/cerf Tue Aug 10 15:06:28 2010
+++ /os/cerf405/cerf Thu Sep 2 16:32:34 2010
@@ -53,7 +53,8 @@
mod
math
sys
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/fads/fads Tue Aug 10 15:06:28 2010
+++ /os/fads/fads Thu Sep 2 16:32:34 2010
@@ -63,7 +63,8 @@
draw
tk
math
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/gum/gum Tue Aug 10 15:06:28 2010
+++ /os/gum/gum Thu Sep 2 16:32:34 2010
@@ -59,7 +59,8 @@
sys
# draw
# tk
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/ipaq1110/ipaq Tue Aug 10 15:06:28 2010
+++ /os/ipaq1110/ipaq Thu Sep 2 16:32:34 2010
@@ -58,7 +58,8 @@
sys
draw
tk
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/ipengine/ipe Tue Aug 10 15:06:28 2010
+++ /os/ipengine/ipe Thu Sep 2 16:32:34 2010
@@ -50,7 +50,8 @@
mod
math
sys
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/js/js Tue Aug 10 15:06:28 2010
+++ /os/js/js Thu Sep 2 16:32:34 2010
@@ -49,7 +49,8 @@
draw
prefab
tk
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/manga/manga Tue Aug 10 15:06:28 2010
+++ /os/manga/manga Thu Sep 2 16:32:34 2010
@@ -40,7 +40,8 @@
mod
math
sys
- keyring crypt
+ keyring
+ crypt
ipints


=======================================
--- /os/pc/pc4e Tue Aug 10 15:06:28 2010
+++ /os/pc/pc4e Thu Sep 2 16:32:34 2010
@@ -64,7 +64,8 @@
sys
draw
tk
- keyring crypt
+ keyring
+ crypt
ipints

math
=======================================
--- /os/pc/pcdisk Tue Aug 10 15:06:28 2010
+++ /os/pc/pcdisk Thu Sep 2 16:32:34 2010
@@ -73,7 +73,8 @@
sys
draw
tk
- keyring crypt
+ keyring
+ crypt
ipints

math
=======================================
--- /os/pc/pix Tue Aug 10 15:06:28 2010
+++ /os/pc/pix Thu Sep 2 16:32:34 2010
@@ -68,7 +68,8 @@
sys
# draw
# tk
- keyring crypt
+ keyring
+ crypt
ipints

math
=======================================
--- /os/rpcg/rpcg Tue Aug 10 15:06:28 2010
+++ /os/rpcg/rpcg Thu Sep 2 16:32:34 2010
@@ -61,7 +61,8 @@
# draw
# tk
math
- keyring crypt
+ keyring
+ crypt
ipints



==============================================================================
Revision: d8cf126ad6
Author: for...@vitanuova.com
Date: Tue Sep 14 05:20:47 2010
Log: 20100914-1320
http://code.google.com/p/inferno-npe/source/detail?r=d8cf126ad6

Modified:
/CHANGES
/emu/Nt/os.c
/include/version.h
/mkfiles/mkfile-Linux-386

=======================================
--- /CHANGES Sun Aug 22 05:59:46 2010
+++ /CHANGES Tue Sep 14 05:20:47 2010
@@ -1,5 +1,8 @@
+20100914
+ emu/Nt/os.c - replace trap handling
20100822
correct handling of mouse focus in sub-widgets of widget windowed in text
[issue 241]
+ add various warnings to mkfile-Linux-386
20100821
correct handling of mouse focus in sub-widgets of widget windowed in
canvas [issue 241]
20100819
=======================================
--- /emu/Nt/os.c Thu Aug 20 17:58:39 2009
+++ /emu/Nt/os.c Tue Sep 14 05:20:47 2010
@@ -107,17 +107,6 @@
DWORD WINAPI
tramp(LPVOID p)
{
- // install our own exception handler
- // replacing all others installed on this thread
- DWORD handler = (DWORD)Exhandler;
- _asm {
- mov eax,handler
- push eax
- mov eax,-1
- push eax
- mov fs:[0],esp
- }
-
up = p;
up->func(up->arg);
pexit("", 0);
@@ -251,58 +240,29 @@
DWORD code;
char* name;
} ecodes[] = {
- EXCEPTION_ACCESS_VIOLATION, "Segmentation violation",
- EXCEPTION_DATATYPE_MISALIGNMENT, "Data Alignment",
- EXCEPTION_BREAKPOINT, "Breakpoint",
- EXCEPTION_SINGLE_STEP, "SingleStep",
- EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array Bounds Check",
- EXCEPTION_FLT_DENORMAL_OPERAND, "Denormalized Float",
- EXCEPTION_FLT_DIVIDE_BY_ZERO, "Floating Point Divide by Zero",
- EXCEPTION_FLT_INEXACT_RESULT, "Inexact Floating Point",
- EXCEPTION_FLT_INVALID_OPERATION, "Invalid Floating Operation",
- EXCEPTION_FLT_OVERFLOW, "Floating Point Result Overflow",
- EXCEPTION_FLT_STACK_CHECK, "Floating Point Stack Check",
- EXCEPTION_FLT_UNDERFLOW, "Floating Point Result Underflow",
- EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by Zero",
- EXCEPTION_INT_OVERFLOW, "Integer Overflow",
- EXCEPTION_PRIV_INSTRUCTION, "Privileged Instruction",
- EXCEPTION_IN_PAGE_ERROR, "Page-in Error",
- EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal Instruction",
- EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-Continuable Exception",
- EXCEPTION_STACK_OVERFLOW, "Stack Overflow",
- EXCEPTION_INVALID_DISPOSITION, "Invalid Disposition",
- EXCEPTION_GUARD_PAGE, "Guard Page Violation",
+ EXCEPTION_ACCESS_VIOLATION, "segmentation violation",
+ EXCEPTION_DATATYPE_MISALIGNMENT, "data alignment",
+ EXCEPTION_BREAKPOINT, "breakpoint",
+ EXCEPTION_SINGLE_STEP, "single step",
+ EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "array bounds check",
+ EXCEPTION_FLT_DENORMAL_OPERAND, "denormalized float",
+ EXCEPTION_FLT_DIVIDE_BY_ZERO, "floating point divide by zero",
+ EXCEPTION_FLT_INEXACT_RESULT, "inexact floating point",
+ EXCEPTION_FLT_INVALID_OPERATION, "invalid floating operation",
+ EXCEPTION_FLT_OVERFLOW, "floating point result overflow",
+ EXCEPTION_FLT_STACK_CHECK, "floating point stack check",
+ EXCEPTION_FLT_UNDERFLOW, "floating point result underflow",
+ EXCEPTION_INT_DIVIDE_BY_ZERO, "divide by zero",
+ EXCEPTION_INT_OVERFLOW, "integer overflow",
+ EXCEPTION_PRIV_INSTRUCTION, "privileged instruction",
+ EXCEPTION_IN_PAGE_ERROR, "page-in error",
+ EXCEPTION_ILLEGAL_INSTRUCTION, "illegal instruction",
+ EXCEPTION_NONCONTINUABLE_EXCEPTION, "non-continuable exception",
+ EXCEPTION_STACK_OVERFLOW, "stack overflow",
+ EXCEPTION_INVALID_DISPOSITION, "invalid disposition",
+ EXCEPTION_GUARD_PAGE, "guard page violation",
0, nil
};
-
-void
-dodisfault(void)
-{
- disfault(nil, up->env->errstr);
-}
-
-typedef struct Ereg Ereg;
-struct Ereg {
- Ereg *prev;
- FARPROC handler;
-};
-
-void
-dumpex()
-{
- Ereg *er;
- int i;
- _asm { mov eax,fs:[0] };
- _asm { mov [er],eax };
-
- i = 0;
- while ((unsigned)er != ~0) {
- print("handler %ux\n", er->handler);
- i++;
- er = er->prev;
- }
- print("EXCEPTION CHAIN LENGTH = %d\n", i);
-}

LONG
TrapHandler(LPEXCEPTION_POINTERS ureg)
@@ -325,7 +285,7 @@
}

if(name == nil) {
- snprint(buf, sizeof(buf), "Unrecognized Machine Trap (%.8lux)\n", code);
+ snprint(buf, sizeof(buf), "unknown trap type (%#.8lux)\n", code);
name = buf;
}
/*
@@ -334,8 +294,6 @@
name = buf;
}
*/
- /* YUCK! */
- strncpy(up->env->errstr, name, ERRMAX);
switch (code) {
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
@@ -344,12 +302,12 @@
case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_FLT_UNDERFLOW:
- /* clear exception flags and register stack */
+ /* clear exception flags and ensure safe empty state */
_asm { fnclex };
- ureg->ContextRecord->FloatSave.StatusWord = 0x0000;
- ureg->ContextRecord->FloatSave.TagWord = 0xffff;
- }
- ureg->ContextRecord->Eip = (DWORD)dodisfault;
+ _asm { fninit };
+ }
+ disfault(nil, name);
+ /* not reached */
return EXCEPTION_CONTINUE_EXECUTION;
}

@@ -423,8 +381,8 @@

gethostname(sys, sizeof(sys));
kstrdup(&ossysname, sys);
-// if(sflag == 0)
-// SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TrapHandler);
+ if(sflag == 0)
+ SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TrapHandler);

path = getenv("PATH");
if(path == nil)
=======================================
--- /include/version.h Sat Aug 21 10:01:11 2010
+++ /include/version.h Tue Sep 14 05:20:47 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100821)"
+#define VERSION "Fourth Edition (20100914)"
=======================================
--- /mkfiles/mkfile-Linux-386 Wed Jul 23 12:37:49 2008
+++ /mkfiles/mkfile-Linux-386 Tue Sep 14 05:20:47 2010
@@ -14,6 +14,7 @@
CC= cc -c -m32
CFLAGS= -g\
-O\
+ -Wuninitialized -Wunused -Wreturn-type -Wimplicit\
-I$ROOT/Linux/386/include\
-I$ROOT/include\
-I/usr/X11R6/include\

==============================================================================
Revision: bcd3cb9be2
Author: for...@vitanuova.com
Date: Sat Sep 25 06:04:43 2010
Log: 20100925-1403
http://code.google.com/p/inferno-npe/source/detail?r=bcd3cb9be2

Modified:
/CHANGES
/appl/lib/complete.b
/appl/lib/w3c/uris.b
/appl/svc/httpd/httpd.b
/appl/svc/httpd/httpd.m
/appl/svc/httpd/parser.b
/appl/svc/httpd/parser.m
/dis/lib/complete.dis
/dis/lib/w3c/uris.dis
/dis/svc/httpd/cgiparse.dis
/dis/svc/httpd/echo.dis
/dis/svc/httpd/httpd.dis
/dis/svc/httpd/imagemap.dis
/dis/svc/httpd/parser.dis
/dis/svc/httpd/stats.dis
/include/version.h
/man/2/w3c-uris
/module/NOTICE

=======================================
--- /CHANGES Tue Sep 14 05:20:47 2010
+++ /CHANGES Sat Sep 25 06:04:43 2010
@@ -1,3 +1,6 @@
+20100925
+ appl/lib/w3c/uris.b - handle existing Unicode characters if they happen
not to have been encoded into string
+ appl/svc/httpd/parser.b - similar [response to issue 233]
20100914
emu/Nt/os.c - replace trap handling
20100822
=======================================
--- /appl/lib/complete.b Mon Jan 15 13:04:26 2007
+++ /appl/lib/complete.b Sat Sep 25 06:04:43 2010
@@ -41,7 +41,6 @@
if(n == 0)
return (nil, nil);

- readdir = nil;

c := ref Completion(0, 0, nil, 0, nil);

=======================================
--- /appl/lib/w3c/uris.b Sat Dec 30 13:29:14 2006
+++ /appl/lib/w3c/uris.b Sat Sep 25 06:04:43 2010
@@ -260,20 +260,26 @@
if(s[i] == '%' || s[i] == 0)
break;
}
- o := s[0:i];
+ t := s[0:i];
+ a := array[Sys->UTFmax*len s] of byte; # upper bound
+ o := 0;
while(i < len s){
- case c := s[i++] {
- '%' =>
- if((v := hex2(s[i:])) > 0){
- c = v;
- i += 2;
- }
- 0 =>
- c = ' '; # shouldn't happen
- }
- o[len o] = c;
- }
- return o;
+ c := s[i++];
+ if(c < 16r80){
+ case c {
+ '%' =>
+ if((v := hex2(s[i:])) > 0){
+ c = v;
+ i += 2;
+ }
+ 0 =>
+ c = ' '; # shouldn't happen
+ }
+ a[o++] = byte c;
+ }else
+ o += sys->char2byte(c, a, o); # string contained Unicode
+ }
+ return t + string a[0:o];
}

enc1(s: string, safe: string): string
=======================================
--- /appl/svc/httpd/httpd.b Fri Dec 22 09:07:39 2006
+++ /appl/svc/httpd/httpd.b Sat Sep 25 06:04:43 2010
@@ -212,7 +212,6 @@
g.dbg_log=dbg_log;
g.logfile = logfile;
g.modtime=0;
- g.entity = parser->initarray();
g.mydomain = my_domain;
g.version = "HTTP/1.0";
g.cache = cache;
@@ -715,7 +714,7 @@

getendpoints(dir: string): string
{
- (lsys, lserv) := getendpoint(dir, "local");
- (rsys, rserv) := getendpoint(dir, "remote");
+# (lsys, lserv) := getendpoint(dir, "local");
+ (rsys, nil) := getendpoint(dir, "remote");
return rsys;
}
=======================================
--- /appl/svc/httpd/httpd.m Fri Dec 22 09:07:39 2006
+++ /appl/svc/httpd/httpd.m Sat Sep 25 06:04:43 2010
@@ -1,8 +1,4 @@
Httpd: module {
- Entity: adt{
- name : string;
- value : int;
- };

Internal, TempFail, Unimp, UnkVers, BadCont, BadReq, Syntax,
BadSearch, NotFound, NoSearch , OnlySearch, Unauth, OK : con iota;
@@ -35,7 +31,6 @@
wordval : string;
tok,parse_eof : int;
mydomain,client : string;
- entity: array of Entity;
oklang : list of ref Contents->Content;
};
Request: adt {
=======================================
--- /appl/svc/httpd/parser.b Fri Dec 22 09:07:39 2006
+++ /appl/svc/httpd/parser.b Sat Sep 25 06:04:43 2010
@@ -14,7 +14,7 @@
Content: import contents;
include "cache.m";
include "httpd.m";
- Entity, Private_info: import Httpd;
+ Private_info: import Httpd;
Internal, TempFail, Unimp, UnkVers, BadCont, BadReq, Syntax,
BadSearch, NotFound, NoSearch , OnlySearch, Unauth, OK : import Httpd;
include "parser.m";
@@ -61,236 +61,6 @@
OK => Error("200 OK", "everything is fine","Groovy man"),
};

-latin1 := array[] of {
- '¡',
- '¢',
- '£',
- '¤',
- '¥',
- '¦',
- '§',
- '¨',
- '©',
- 'ª',
- '«',
- '¬',
- '­',
- '®',
- '¯',
- '°',
- '±',
- '²',
- '³',
- '´',
- 'µ',
- '¶',
- '·',
- '¸',
- '¹',
- 'º',
- '»',
- '¼',
- '½',
- '¾',
- '¿',
- 'À',
- 'Á',
- 'Â',
- 'Ã',
- 'Ä',
- 'Å',
- 'Æ',
- 'Ç',
- 'È',
- 'É',
- 'Ê',
- 'Ë',
- 'Ì',
- 'Í',
- 'Î',
- 'Ï',
- 'Ð',
- 'Ñ',
- 'Ò',
- 'Ó',
- 'Ô',
- 'Õ',
- 'Ö',
- '×',
- 'Ø',
- 'Ù',
- 'Ú',
- 'Û',
- 'Ü',
- 'Ý',
- 'Þ',
- 'ß',
- 'à',
- 'á',
- 'â',
- 'ã',
- 'ä',
- 'å',
- 'æ',
- 'ç',
- 'è',
- 'é',
- 'ê',
- 'ë',
- 'ì',
- 'í',
- 'î',
- 'ï',
- 'ð',
- 'ñ',
- 'ò',
- 'ó',
- 'ô',
- 'õ',
- 'ö',
- '÷',
- 'ø',
- 'ù',
- 'ú',
- 'û',
- 'ü',
- 'ý',
- 'þ',
- 'ÿ',
- 0,
-};
-
-entities :=array[] of {
- Entity( "&#161;", '¡' ),
- Entity( "&#162;", '¢' ),
- Entity( "&#163;", '£' ),
- Entity( "&#164;", '¤' ),
- Entity( "&#165;", '¥' ),
- Entity( "&#166;", '¦' ),
- Entity( "&#167;", '§' ),
- Entity( "&#168;", '¨' ),
- Entity( "&#169;", '©' ),
- Entity( "&#170;", 'ª' ),
- Entity( "&#171;", '«' ),
- Entity( "&#172;", '¬' ),
- Entity( "&#173;", '­' ),
- Entity( "&#174;", '®' ),
- Entity( "&#175;", '¯' ),
- Entity( "&#176;", '°' ),
- Entity( "&#177;", '±' ),
- Entity( "&#178;", '²' ),
- Entity( "&#179;", '³' ),
- Entity( "&#180;", '´' ),
- Entity( "&#181;", 'µ' ),
- Entity( "&#182;", '¶' ),
- Entity( "&#183;", '·' ),
- Entity( "&#184;", '¸' ),
- Entity( "&#185;", '¹' ),
- Entity( "&#186;", 'º' ),
- Entity( "&#187;", '»' ),
- Entity( "&#188;", '¼' ),
- Entity( "&#189;", '½' ),
- Entity( "&#190;", '¾' ),
- Entity( "&#191;", '¿' ),
- Entity( "&Agrave;", 'À' ),
- Entity( "&Aacute;", 'Á' ),
- Entity( "&Acirc;", 'Â' ),
- Entity( "&Atilde;", 'Ã' ),
- Entity( "&Auml;", 'Ä' ),
- Entity( "&Aring;", 'Å' ),
- Entity( "&AElig;", 'Æ' ),
- Entity( "&Ccedil;", 'Ç' ),
- Entity( "&Egrave;", 'È' ),
- Entity( "&Eacute;", 'É' ),
- Entity( "&Ecirc;", 'Ê' ),
- Entity( "&Euml;", 'Ë' ),
- Entity( "&Igrave;", 'Ì' ),
- Entity( "&Iacute;", 'Í' ),
- Entity( "&Icirc;", 'Î' ),
- Entity( "&Iuml;", 'Ï' ),
- Entity( "&ETH;", 'Ð' ),
- Entity( "&Ntilde;", 'Ñ' ),
- Entity( "&Ograve;", 'Ò' ),
- Entity( "&Oacute;", 'Ó' ),
- Entity( "&Ocirc;", 'Ô' ),
- Entity( "&Otilde;", 'Õ' ),
- Entity( "&Ouml;", 'Ö' ),
- Entity( "&215;", '×' ),
- Entity( "&Oslash;", 'Ø' ),
- Entity( "&Ugrave;", 'Ù' ),
- Entity( "&Uacute;", 'Ú' ),
- Entity( "&Ucirc;", 'Û' ),
- Entity( "&Uuml;", 'Ü' ),
- Entity( "&Yacute;", 'Ý' ),
- Entity( "&THORN;", 'Þ' ),
- Entity( "&szlig;", 'ß' ),
- Entity( "&agrave;", 'à' ),
- Entity( "&aacute;", 'á' ),
- Entity( "&acirc;", 'â' ),
- Entity( "&atilde;", 'ã' ),
- Entity( "&auml;", 'ä' ),
- Entity( "&aring;", 'å' ),
- Entity( "&aelig;", 'æ' ),
- Entity( "&ccedil;", 'ç' ),
- Entity( "&egrave;", 'è' ),
- Entity( "&eacute;", 'é' ),
- Entity( "&ecirc;", 'ê' ),
- Entity( "&euml;", 'ë' ),
- Entity( "&igrave;", 'ì' ),
- Entity( "&iacute;", 'í' ),
- Entity( "&icirc;", 'î' ),
- Entity( "&iuml;", 'ï' ),
- Entity( "&eth;", 'ð' ),
- Entity( "&ntilde;", 'ñ' ),
- Entity( "&ograve;", 'ò' ),
- Entity( "&oacute;", 'ó' ),
- Entity( "&ocirc;", 'ô' ),
- Entity( "&otilde;", 'õ' ),
- Entity( "&ouml;", 'ö' ),
- Entity( "&247;", '÷' ),
- Entity( "&oslash;", 'ø' ),
- Entity( "&ugrave;", 'ù' ),
- Entity( "&uacute;", 'ú' ),
- Entity( "&ucirc;", 'û' ),
- Entity( "&uuml;", 'ü' ),
- Entity( "&yacute;", 'ý' ),
- Entity( "&thorn;", 'þ' ),
- Entity( "&yuml;", 'ÿ' ),
-
- Entity( "&#SPACE;", ' ' ),
- Entity( "&#RS;", '\n' ),
- Entity( "&#RE;", '\r' ),
- Entity( "&quot;", '"' ),
- Entity( "&amp;", '&' ),
- Entity( "&lt;", '<' ),
- Entity( "&gt;", '>' ),
-
- Entity( "CAP-DELTA", 'Δ' ),
- Entity( "ALPHA", 'α' ),
- Entity( "BETA", 'β' ),
- Entity( "DELTA", 'δ' ),
- Entity( "EPSILON", 'ε' ),
- Entity( "THETA", 'θ' ),
- Entity( "MU", 'μ' ),
- Entity( "PI", 'π' ),
- Entity( "TAU", 'τ' ),
- Entity( "CHI", 'χ' ),
-
- Entity( "<-", '←' ),
- Entity( "^", '↑' ),
- Entity( "->", '→' ),
- Entity( "v", '↓' ),
- Entity( "!=", '≠' ),
- Entity( "<=", '≤' ),
- Entity( nil, 0 ),
- };
-
-
-initarray() : array of Entity
-{
- return entities;
-}
-
badmodule(p: string)
{
sys->fprint(sys->fildes(2), "parse: cannot load %s: %r", p);
@@ -690,92 +460,50 @@
return c & 16r7f;
}

-ungetc(g: ref Private_info) {
+ungetc(g: ref Private_info)
+{
# this is a dirty hack, I am tacitly assuming that characters read
# from stdin will be ASCII.....
g.bufio->g.bin.ungetc();
}

-# go from url with latin1 and escapes to utf
+# go from url with ascii and %xx escapes to unicode, allowing for existing
unencoded utf-8

urlunesc(s : string): string
{
- c, n : int;
- t : string;
- for(i := 0;i<len s ; i++){
- c = int s[i];
- if(c == '%'){
- n = int s[i+1];
- if(n >= '0' && n <= '9')
- n = n - '0';
- else if(n >= 'A' && n <= 'F')
- n = n - 'A' + 10;
- else if(n >= 'a' && n <= 'f')
- n = n - 'a' + 10;
- else
- break;
- c = n;
- n = int s[i+2];
- if(n >= '0' && n <= '9')
- n = n - '0';
- else if(n >= 'A' && n <= 'F')
- n = n - 'A' + 10;
- else if(n >= 'a' && n <= 'f')
- n = n - 'a' + 10;
- else
- break;
- i += 2;
- c = c * 16 + n;
- }
- else if( c == '+' )
- c = ' ';
- t[len t] = c;
- }
- return t;
+ a := array[Sys->UTFmax*len s] of byte;
+ o := 0;
+ for(i := 0; i < len s; i++){
+ c := int s[i];
+ if(c < Runeself){
+ if(c == '%' && i+2 < len s){
+ d0 := hex(int s[i+1]);
+ if(d0 >= 0){
+ d1 := hex(int s[i+2]);
+ if(d1 >= 0){
+ i += 2;
+ c = d0*16 + d1;
+ }
+ }
+ } else if(c == '+' || c == 0)
+ c = ' ';
+ a[o++] = byte c;
+ }else
+ o += sys->char2byte(c, a, o);
+ }
+ return string a[0: o];
}

-
-# go from http with latin1 escapes to utf,
-# we assume that anything >= Runeself is already in utf
-
-httpunesc(g: ref Private_info,s : array of byte): string
-{
- t,v: string;
- c,i : int;
- # convert bytes to a string.
- v = string s;
- for(i=0; i < len v;i++){
- c = v[i];
- if(c == '&'){
- if(v[1] == '#' && v[2] && v[3] && v[4] && v[5] == ';'){
- c = 100*(v[2])+10*(v[3])+(v[4]);
- if(c < Runeself){
- t[len t] = c;
- i += 6;
- continue;
- }
- if(c < 256 && c >= 161){
- t[len t] = g.entity[c-161].value;
- i += 6;
- continue;
- }
- } else {
- for(j:= 0;g.entity[j].name != nil; j++)
- if(g.entity[j].name == v[i+1:])
- # problem here cvert array of byte to string?
- break;
- if(g.entity[j].name != nil){
- i += len g.entity[j].name;
- t[len t] = g.entity[j].value;
- continue;
- }
- }
- }
- t[len t] = c;
- }
- return t;
-}
-
+hex(c: int): int
+{
+ if(c >= '0' && c <= '9')
+ return c-'0';
+ if(c >= 'a' && c <= 'f')
+ return c-'a' + 10;
+ if(c >= 'A' && c <= 'F')
+ return c-'A' + 10;
+ return -1;
+}

# write a failure message to the net and exit
fail(g: ref Private_info,reason : int, message : string)
@@ -845,14 +573,18 @@

urlconv(p : string): string
{
- c : int;
- t : string;
- for(i:=0;i<len p ;i++){
- c = p[i];
+ a := array[Sys->UTFmax] of byte;
+ t := "";
+ for(i := 0; i < len p; i++){
+ c := p[i];
if(c == 0)
- break;
- if(c <= ' ' || c == '%' || c >= Runeself){
- t += sys->sprint("%%%2.2x", c);
+ continue; # ignore nul bytes
+ if(c >= Runeself){ # convert to UTF-8
+ n := sys->char2byte(c, a, 0);
+ for(j := 0; j < n; j++)
+ t += sys->sprint("%%%.2X", int a[j]);
+ }else if(c <= ' ' || c == '%'){
+ t += sys->sprint("%%%2.2X", c);
} else {
t[len t] = c;
}
=======================================
--- /appl/svc/httpd/parser.m Fri Dec 22 09:07:39 2006
+++ /appl/svc/httpd/parser.m Sat Sep 25 06:04:43 2010
@@ -5,7 +5,6 @@
PATH: con "/dis/svc/httpd/parser.dis";

init: fn();
- initarray: fn(): array of Httpd->Entity;
urlunesc: fn(s: string): string;
fail: fn(g: ref Httpd->Private_info,reason: int, message: string);
logit: fn(g: ref Httpd->Private_info, message: string );
=======================================
--- /dis/lib/complete.dis Mon Jan 15 13:04:26 2007
+++ /dis/lib/complete.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/lib/w3c/uris.dis Fri Dec 22 16:30:12 2006
+++ /dis/lib/w3c/uris.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/svc/httpd/cgiparse.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/cgiparse.dis Sat Sep 25 06:04:43 2010
@@ -106,6 +106,6 @@
40POST0 4cannot load %s: %r?8content-length:7€@http://=€Dhttp://beast20
€Hinternal error, g.bin is nil.0
€Linternal error, g.bout is nil.4€Tnone0 €hversion unknown. CgiParse
-sš ¯cgiparse
+ésmòcgiparse
Nå–Zgetbase (

Nå–Zgethost Nå–Ztime ²Íq urlunesc IåÙ}splitl IåÙ}splitr ²Íq tolower ²Íq toupper xù“fildes ôd†Èfprint ÚD™Âfstat G ™open |
þõWread L $¶sprint W3 tokenize /appl/svc/httpd/cgiparse.b
=======================================
--- /dis/svc/httpd/echo.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/echo.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/svc/httpd/httpd.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/httpd.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/svc/httpd/imagemap.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/imagemap.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/svc/httpd/parser.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/parser.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /dis/svc/httpd/stats.dis Fri Dec 22 12:52:35 2006
+++ /dis/svc/httpd/stats.dis Sat Sep 25 06:04:43 2010
Binary file, no diff available.
=======================================
--- /include/version.h Tue Sep 14 05:20:47 2010
+++ /include/version.h Sat Sep 25 06:04:43 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100914)"
+#define VERSION "Fourth Edition (20100925)"
=======================================
--- /man/2/w3c-uris Fri Dec 22 16:30:12 2006
+++ /man/2/w3c-uris Sat Sep 25 06:04:43 2010
@@ -165,7 +165,7 @@
.I u
and
.I v
-are assumed to be in a canonical form for the scheme and application.
+are assumed to be in a canonical form for the scheme and application.
.TP
.IB u .eqf( v )
Returns true if
@@ -214,7 +214,8 @@
.BI % xx
where
.I xx
-is the hexadecimal value of one byte of the character.
+is the hexadecimal value of one byte of the character's encoding in
+.IR utf (6).
A string
.I s
containing such encodings can be decoded by the function
=======================================
--- /module/NOTICE Fri Feb 2 15:50:37 2007
+++ /module/NOTICE Sat Sep 25 06:04:43 2010
@@ -8,7 +8,7 @@

Copyright © 1995-1999 Lucent Technologies Inc.
Portions Copyright © 1997-2000 Vita Nuova Limited
-Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
+Portions Copyright © 2000-2010 Vita Nuova Holdings Limited

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (`LGPL') as
published by

==============================================================================
Revision: f4d6a0c9b2
Author: Venkatesh Srinivas <venk...@sensorstar.com>
Date: Fri Oct 8 07:37:31 2010
Log: Merge inferno-os 20100925.
http://code.google.com/p/inferno-npe/source/detail?r=f4d6a0c9b2

Modified:
/CHANGES
/emu/DragonFly/emu
/emu/DragonFly/emu-g
/emu/FreeBSD/emu
/emu/Hp/emu
/emu/Irix/emu
/emu/Linux/emu
/emu/Linux/emu-g
/emu/Linux/emu-wrt
/emu/MacOSX/emu
/emu/MacOSX/emu-g
/emu/NetBSD/emu
/emu/Nt/emu
/emu/Nt/os.c
/emu/OpenBSD/emu
/emu/Plan9/emu
/emu/Plan9/emusig
/emu/Solaris/emu
/emu/Unixware/emu
/include/interp.h
/include/version.h
/libtk/utils.c

=======================================
--- /CHANGES Tue Aug 3 07:31:59 2010
+++ /CHANGES Fri Oct 8 07:37:31 2010
@@ -1,3 +1,19 @@
+20100925
+ appl/lib/w3c/uris.b - handle existing Unicode characters if they happen
not to have been encoded into string
+ appl/svc/httpd/parser.b - similar [response to issue 233]
+20100914
+ emu/Nt/os.c - replace trap handling
+20100822
+ correct handling of mouse focus in sub-widgets of widget windowed in text
[issue 241]
+ add various warnings to mkfile-Linux-386
+20100821
+ correct handling of mouse focus in sub-widgets of widget windowed in
canvas [issue 241]
+20100819
+ failed to push Solaris/sparc/include/lib9.h with u64int change [issue 151]
+ appl/cmd/ar.b eliminate false error return
+20100810
+ initial introduction of crypt-*(2) and ipints(2)
+ replace keyring.m in module/runt.m by ipints.m and crypt.m; compensate in
libinterp and libkeyring by using keyringif.m to generate Keyring's
interface
20100802
various changes held back by accident, notably stackv in stack(1), better
diagnostics by cat(1)
20100801
=======================================
--- /emu/DragonFly/emu Fri Feb 12 09:46:25 2010
+++ /emu/DragonFly/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/DragonFly/emu-g Fri Feb 12 09:46:25 2010
+++ /emu/DragonFly/emu-g Fri Oct 8 07:37:31 2010
@@ -35,6 +35,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/FreeBSD/emu Fri Feb 12 09:46:25 2010
+++ /emu/FreeBSD/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Hp/emu Fri Feb 12 09:46:25 2010
+++ /emu/Hp/emu Fri Oct 8 07:37:31 2010
@@ -51,6 +51,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Irix/emu Fri Feb 12 09:46:25 2010
+++ /emu/Irix/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Linux/emu Wed Mar 17 18:01:58 2010
+++ /emu/Linux/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Linux/emu-g Tue Feb 9 23:24:33 2010
+++ /emu/Linux/emu-g Fri Oct 8 07:37:31 2010
@@ -39,6 +39,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/Linux/emu-wrt Fri Jan 29 02:36:15 2010
+++ /emu/Linux/emu-wrt Fri Oct 8 07:37:31 2010
@@ -49,6 +49,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
# freetype

=======================================
--- /emu/MacOSX/emu Fri Feb 12 09:46:25 2010
+++ /emu/MacOSX/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/MacOSX/emu-g Fri Feb 12 09:46:25 2010
+++ /emu/MacOSX/emu-g Fri Oct 8 07:37:31 2010
@@ -37,6 +37,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader

port
=======================================
--- /emu/NetBSD/emu Fri Feb 12 09:46:25 2010
+++ /emu/NetBSD/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Nt/emu Fri Jan 29 02:36:15 2010
+++ /emu/Nt/emu Fri Oct 8 07:37:31 2010
@@ -51,6 +51,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Nt/os.c Mon Jan 18 09:15:16 2010
+++ /emu/Nt/os.c Fri Oct 8 07:37:31 2010
@@ -107,17 +107,6 @@
DWORD WINAPI
tramp(LPVOID p)
{
- // install our own exception handler
- // replacing all others installed on this thread
- DWORD handler = (DWORD)Exhandler;
- _asm {
- mov eax,handler
- push eax
- mov eax,-1
- push eax
- mov fs:[0],esp
- }
-
up = p;
up->func(up->arg);
pexit("", 0);
@@ -251,58 +240,29 @@
DWORD code;
char* name;
} ecodes[] = {
- EXCEPTION_ACCESS_VIOLATION, "Segmentation violation",
- EXCEPTION_DATATYPE_MISALIGNMENT, "Data Alignment",
- EXCEPTION_BREAKPOINT, "Breakpoint",
- EXCEPTION_SINGLE_STEP, "SingleStep",
- EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array Bounds Check",
- EXCEPTION_FLT_DENORMAL_OPERAND, "Denormalized Float",
- EXCEPTION_FLT_DIVIDE_BY_ZERO, "Floating Point Divide by Zero",
- EXCEPTION_FLT_INEXACT_RESULT, "Inexact Floating Point",
- EXCEPTION_FLT_INVALID_OPERATION, "Invalid Floating Operation",
- EXCEPTION_FLT_OVERFLOW, "Floating Point Result Overflow",
- EXCEPTION_FLT_STACK_CHECK, "Floating Point Stack Check",
- EXCEPTION_FLT_UNDERFLOW, "Floating Point Result Underflow",
- EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by Zero",
- EXCEPTION_INT_OVERFLOW, "Integer Overflow",
- EXCEPTION_PRIV_INSTRUCTION, "Privileged Instruction",
- EXCEPTION_IN_PAGE_ERROR, "Page-in Error",
- EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal Instruction",
- EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-Continuable Exception",
- EXCEPTION_STACK_OVERFLOW, "Stack Overflow",
- EXCEPTION_INVALID_DISPOSITION, "Invalid Disposition",
- EXCEPTION_GUARD_PAGE, "Guard Page Violation",
+ EXCEPTION_ACCESS_VIOLATION, "segmentation violation",
+ EXCEPTION_DATATYPE_MISALIGNMENT, "data alignment",
+ EXCEPTION_BREAKPOINT, "breakpoint",
+ EXCEPTION_SINGLE_STEP, "single step",
+ EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "array bounds check",
+ EXCEPTION_FLT_DENORMAL_OPERAND, "denormalized float",
+ EXCEPTION_FLT_DIVIDE_BY_ZERO, "floating point divide by zero",
+ EXCEPTION_FLT_INEXACT_RESULT, "inexact floating point",
+ EXCEPTION_FLT_INVALID_OPERATION, "invalid floating operation",
+ EXCEPTION_FLT_OVERFLOW, "floating point result overflow",
+ EXCEPTION_FLT_STACK_CHECK, "floating point stack check",
+ EXCEPTION_FLT_UNDERFLOW, "floating point result underflow",
+ EXCEPTION_INT_DIVIDE_BY_ZERO, "divide by zero",
+ EXCEPTION_INT_OVERFLOW, "integer overflow",
+ EXCEPTION_PRIV_INSTRUCTION, "privileged instruction",
+ EXCEPTION_IN_PAGE_ERROR, "page-in error",
+ EXCEPTION_ILLEGAL_INSTRUCTION, "illegal instruction",
+ EXCEPTION_NONCONTINUABLE_EXCEPTION, "non-continuable exception",
+ EXCEPTION_STACK_OVERFLOW, "stack overflow",
+ EXCEPTION_INVALID_DISPOSITION, "invalid disposition",
+ EXCEPTION_GUARD_PAGE, "guard page violation",
0, nil
};
-
-void
-dodisfault(void)
-{
- disfault(nil, up->env->errstr);
-}
-
-typedef struct Ereg Ereg;
-struct Ereg {
- Ereg *prev;
- FARPROC handler;
-};
-
-void
-dumpex()
-{
- Ereg *er;
- int i;
- _asm { mov eax,fs:[0] };
- _asm { mov [er],eax };
-
- i = 0;
- while ((unsigned)er != ~0) {
- print("handler %ux\n", er->handler);
- i++;
- er = er->prev;
- }
- print("EXCEPTION CHAIN LENGTH = %d\n", i);
-}

LONG
TrapHandler(LPEXCEPTION_POINTERS ureg)
@@ -325,7 +285,7 @@
}

if(name == nil) {
- snprint(buf, sizeof(buf), "Unrecognized Machine Trap (%.8lux)\n", code);
+ snprint(buf, sizeof(buf), "unknown trap type (%#.8lux)\n", code);
name = buf;
}
/*
@@ -334,8 +294,6 @@
name = buf;
}
*/
- /* YUCK! */
- strncpy(up->env->errstr, name, ERRMAX);
switch (code) {
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
@@ -344,12 +302,12 @@
case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_FLT_UNDERFLOW:
- /* clear exception flags and register stack */
+ /* clear exception flags and ensure safe empty state */
_asm { fnclex };
- ureg->ContextRecord->FloatSave.StatusWord = 0x0000;
- ureg->ContextRecord->FloatSave.TagWord = 0xffff;
- }
- ureg->ContextRecord->Eip = (DWORD)dodisfault;
+ _asm { fninit };
+ }
+ disfault(nil, name);
+ /* not reached */
return EXCEPTION_CONTINUE_EXECUTION;
}

@@ -423,8 +381,8 @@

gethostname(sys, sizeof(sys));
kstrdup(&ossysname, sys);
-// if(sflag == 0)
-// SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TrapHandler);
+ if(sflag == 0)
+ SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TrapHandler);

path = getenv("PATH");
if(path == nil)
=======================================
--- /emu/OpenBSD/emu Fri Feb 12 09:46:25 2010
+++ /emu/OpenBSD/emu Fri Oct 8 07:37:31 2010
@@ -51,6 +51,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Plan9/emu Mon Aug 2 22:32:34 2010
+++ /emu/Plan9/emu Fri Oct 8 07:37:31 2010
@@ -51,6 +51,8 @@
math
# srv not used on Plan 9
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Plan9/emusig Fri Feb 12 09:46:25 2010
+++ /emu/Plan9/emusig Fri Oct 8 07:37:31 2010
@@ -41,6 +41,8 @@
math
# srv not used on Plan 9
keyring
+ crypt
+ ipints
loader
freetype

@@ -49,6 +51,8 @@
cache
chan
dev
+ devtab
+
dial
dis
discall
@@ -77,6 +81,7 @@
root
/dev /
/prog /
+ /prof /
/net /
/net.alt /
/chan /
=======================================
--- /emu/Solaris/emu Fri Feb 12 09:46:25 2010
+++ /emu/Solaris/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /emu/Unixware/emu Fri Feb 12 09:46:25 2010
+++ /emu/Unixware/emu Fri Oct 8 07:37:31 2010
@@ -50,6 +50,8 @@
math
srv srv
keyring
+ crypt
+ ipints
loader
freetype

=======================================
--- /include/interp.h Fri Nov 13 05:07:00 2009
+++ /include/interp.h Fri Oct 8 07:37:31 2010
@@ -389,6 +389,7 @@
extern Array* allocimgarray(Heap*, Heap*);
extern Module* builtinmod(char*, void*, int);
extern void cblock(Prog*);
+extern void* checktype(void*, Type*, char*, int);
extern void cmovw(void*, void*);
extern Channel* cnewc(Type*, void (*)(void), int);
extern int compile(Module*, int, Modlink*);
@@ -410,12 +411,12 @@
extern void destroylinks(Module*);
extern void destroystack(REG*);
extern void drawmodinit(void);
+extern Type* dtype(void (*)(Heap*, int), int, uchar*, int);
+extern Module* dupmod(Module*);
extern int dynldable(int);
extern void iqlock(ILock*);
extern void iqunlock(ILock*);
extern void loadermodinit(void);
-extern Type* dtype(void (*)(Heap*, int), int, uchar*, int);
-extern Module* dupmod(Module*);
extern void error(char*);
extern void errorf(char*, ...);
extern void extend(void);
=======================================
--- /include/version.h Tue Aug 3 07:31:59 2010
+++ /include/version.h Fri Oct 8 07:37:31 2010
@@ -1,1 +1,1 @@
-#define VERSION "Fourth Edition (20100802)"
+#define VERSION "Fourth Edition (20100925)"
=======================================
--- /libtk/utils.c Wed Apr 7 06:04:21 2010
+++ /libtk/utils.c Fri Oct 8 07:37:31 2010
@@ -56,7 +56,8 @@

char* tkfont;

-/* auto-repeating support
+/*
+ * auto-repeating support
* should perhaps be one rptproc per TkCtxt
* This is not done for the moment as there isn't
* a mechanism for terminating the rptproc
@@ -1016,17 +1017,25 @@
char*
tkname(Tk *tk)
{
- return tk ? (tk->name ? tk->name->name : "(noname)") : "(nil)";
+ if(tk == nil)
+ return "(nil)";
+ if(tk->name == nil)
+ return "(noname)";
+ return tk->name->name;
}

Tk*
tkdeliver(Tk *tk, int event, void *data)
{
Tk *dest;
+
+ if(tk != nil && ((ulong)tk->type >= TKwidgets || (ulong)tk->name < 4096
&& tk->name != nil)){
+ print("invalid Tk: type %d name %p\n", tk->type, tk->name);
+ abort();
+ }
//print("tkdeliver %v to %s\n", event, tkname(tk));
if(tk == nil || ((tk->flag&Tkdestroy) && event != TkDestroy))
return tk;
-
if(event&(TkFocusin|TkFocusout) && (tk->flag&Tktakefocus))
tk->dirty = tkrect(tk, 1);

@@ -1058,6 +1067,7 @@
TkAction *a;
int delivered, genkey, delivered2, iskey;
//int (*debug)(char *fmt, ...);
+
if (!extn)
return tkextndeliver(tk, binds, event, data);

@@ -1201,20 +1211,18 @@
return a;
}

-int
-tkismapped(Tk *tk)
-{
- while(tk->master)
- tk = tk->master;
-
- /* We need subwindows of text & canvas to appear mapped always
- * so that the geom function update are seen by the parent
- * widget
- */
- if((tk->flag & Tkwindow) == 0)
- return 1;
-
- return tk->flag & Tkmapped;
+/*
+ * if tk is a subwindow or a descendent, return the subwindow;
+ * return nil otherwise
+ */
+Tk*
+tkfindsub(Tk *tk)
+{
+ for(; tk != nil; tk = tk->master){
+ if(tk->parent != nil)
+ return tk; /* tk->parent is canvas or text */
+ }
+ return nil;
}

/*
@@ -1233,21 +1241,19 @@
if(tk->parent != nil) {
g = tkmethod[tk->parent->type]->relpos(tk);
f = tk->parent;
- }
- else {
+ } else {
g.x = tk->act.x;
g.y = tk->act.y;
f = tk->master;
}
- while(f) {
+ while(f != nil) {
g.x += f->borderwidth;
g.y += f->borderwidth;
last = f;
if(f->parent != nil) {
g = addpt(g, tkmethod[f->parent->type]->relpos(f));
f = f->parent;
- }
- else {
+ } else {
g.x += f->act.x;
g.y += f->act.y;
f = f->master;
@@ -2066,3 +2072,55 @@
else
rptwakeup(nil, blinkrpt);
}
+
+/*
+ * debugging
+ */
+void
+tkdump(Tk *tk)
+{
+ Tk *sl;
+
+ if(tk == nil)
+ return;
+ if((uint)tk->type < TKwidgets)
+ print("%s", tkmethod[tk->type]->name);
+ else
+ print("TYPE#%#ux", tk->type);
+ if(tk->name == nil || (ulong)tk->name < 512)
+ print(" NAME %p", tk->name);
+ else
+ print(" %s", tkname(tk));
+ print(" # tk %#p flag %#ux grid %#p", tk, tk->flag, tk->grid);
+ if(tk->parent != nil)
+ print(" parent [%#p %q]", tk->parent, tkname(tk->parent));
+ if(tk->master != nil)
+ print(" master [%#p %q]", tk->master, tkname(tk->master));
+ if(tk->slave != nil){
+ print(" slaves");
+ for(sl = tk->slave; sl != nil; sl = sl->next)
+ print(" [%#p %q]", sl, tkname(sl));
+ }
+ print("\n");
+ if(tk->type != TKcanvas)
+ return;
+ tkcvsdump(tk);
+}
+
+void
+tktopdump(Tk *tk)
+{
+ TkTop *top;
+ Tk *sub;
+
+ if(tk == nil || tk->env == nil){
+ print("# %#p no top\n", tk);
+ return;
+ }
+ top = tk->env->top;
+ print("# env %#p top %#p\n", tk->env, top);
+ if(top != nil){
+ for(sub = top->root; sub != nil; sub = sub->siblings)
+ tkdump(sub);
+ }
+}
Reply all
Reply to author
Forward
0 new messages