From bb2e5299c10277e05f5ca24a3714bc84e501628a Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 23 Jun 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-06-23 --- gnot/dat.h | 1 + gnot/devincon.c | 2 + gnot/errno.h | 1 + gnot/lock.c | 1 + gnot/main.c | 1 + port/devbit.c | 112 +++++++++++++++++++++++++++++++++++++++++++----- port/devmnt.c | 3 -- 7 files changed, 108 insertions(+), 13 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index 4876d16ad1cc98371a6a032b5eb13cd5d5e0978e..ee0116431d44f417826927cb83080b8c5259962a 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -137,6 +137,7 @@ struct Conf int nsrv; /* public servers (devsrv.c) */ int nbitmap; /* bitmap structs (devbit.c) */ int nbitbyte; /* bytes of bitmap data (devbit.c) */ + int nfont; /* font structs (devbit.c) */ }; struct Dev diff --git a/gnot/devincon.c b/gnot/devincon.c index 902a9ed395db055e5a6145b071df1cd966105fcd..e911a9259b2f2a09991bf3dea49f7057d19cef81 100644 --- a/gnot/devincon.c +++ b/gnot/devincon.c @@ -229,6 +229,8 @@ inconrestart(Incon *ip) if(!canqlock(&ip->reslock)) return; + print("inconrestart\n"); + /* * poll for incon station numbers */ diff --git a/gnot/errno.h b/gnot/errno.h index 8bfaa8f7648e97fe4551f3826f707c1f305ffff5..3b5738e2c513928e82e01adf22b6979ffe040709 100644 --- a/gnot/errno.h +++ b/gnot/errno.h @@ -52,5 +52,6 @@ enum{ Ebadbitmap, /* unallocated bitmap */ Eshortmsg, /* short message */ Ebadmsg, /* format error or mismatch in message */ + Enofont, /* out of font descriptors */ Egreg, /* it's all greg's fault */ }; diff --git a/gnot/lock.c b/gnot/lock.c index f8d5067fd9239dd6817f31b55a4c99eed73bf5c6..29eb703c8deb9dfda7c72a7c9a92057fa520c988 100644 --- a/gnot/lock.c +++ b/gnot/lock.c @@ -94,6 +94,7 @@ qunlock(QLock *q) Proc *p; lock(&q->queue); + u->p->qlock = 0; if(q->head){ p = q->head; q->head = p->qnext; diff --git a/gnot/main.c b/gnot/main.c index f791f11d29b324acfe3696228ca3fed5c4d1821c..beea439541ef795b49abf8d0c1d3357a5e1f3586 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -310,4 +310,5 @@ confinit(void) conf.nsrv = 32*mul; conf.nbitmap = 100*mul; conf.nbitbyte = 300*1024*mul*mul; + conf.nfont = 10*mul; } diff --git a/port/devbit.c b/port/devbit.c index 8919580eb4fff9f1f6dae4871830bc19028fd2c8..e18ed9a42c5870b4db6196075ea9bb8111ad975e 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -32,7 +32,9 @@ struct ulong *words; /* storage */ ulong nwords; /* total in arena */ ulong *wfree; /* pointer to next free word */ + Font *font; /* arena; looked up linearly BUG */ int lastid; /* last allocated bitmap id */ + int lastfid; /* last allocated font id */ int init; /* freshly opened; init message pending */ int rid; /* read bitmap id */ int rminy; /* read miny */ @@ -126,6 +128,7 @@ Dirtab bitdir[]={ }; #define NBIT (sizeof bitdir/sizeof(Dirtab)) +#define NINFO 150 void bitreset(void) @@ -143,9 +146,14 @@ bitreset(void) bit.map[0] = screen; /* bitmap 0 is screen */ bit.free = bit.map+1; bit.lastid = -1; + bit.lastfid = -1; bit.words = ialloc(conf.nbitbyte, 0); bit.nwords = conf.nbitbyte/sizeof(ulong); bit.wfree = bit.words; + bit.font = ialloc(conf.nfont * sizeof(Font), 0); + bit.font[0] = *defont; + for(i=1; iqid!=CHDIR && (c->flag&COPEN)){ lock(&bit); @@ -242,6 +252,8 @@ bitclose(Chan *c) for(i=1,bp=&bit.map[1]; ildepth >= 0) bitfree(bp); + for(i=1,fp=&bit.font[1]; ibits = 0; } unlock(&bit); } @@ -337,6 +349,20 @@ bitread(Chan *c, void *va, long n) n = 3; break; } + if(bit.lastfid > 0){ + /* + * allocate font: + * 'K' 1 + * font id 2 + */ + if(n < 3) + error(0, Ebadblt); + p[0] = 'K'; + PSHORT(p+1, bit.lastfid); + bit.lastfid = -1; + n = 3; + break; + } if(bit.rid >= 0){ /* * read @@ -395,11 +421,13 @@ bitwrite(Chan *c, void *va, long n) uchar *p, *q; long m, v, miny, maxy, t, x, y; ulong l, nw, ws; - int off; + int off, i; Point pt, pt1, pt2; Rectangle rect; Cursor curs; + Fontchar *fcp; Bitmap *bp, *src, *dst; + Font *f; if(c->qid == CHDIR) error(0, Eisdir); @@ -551,13 +579,30 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; - if(v>=conf.nbitmap || dst->ldepth<0) + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(0, Ebadbitmap); bitfree(dst); m -= 3; p += 3; break; + case 'g': + /* + * free font (free bitmap separately) + * 'g' 1 + * id 2 + */ + if(m < 3) + error(0, Ebadblt); + v = GSHORT(p+1); + f = &bit.font[v]; + if(v<0 || v>=conf.nfont || f->bits==0) + error(0, Ebadbitmap); + f->bits = 0; + m -= 3; + p += 3; + break; + case 'i': /* * init @@ -569,6 +614,52 @@ bitwrite(Chan *c, void *va, long n) p += 1; break; + case 'k': + /* + * allocate font + * 'k' 1 + * n 2 + * height 1 + * ascent 1 + * bitmap id 2 + * fontchars 6*n + * next read returns allocated font id + */ + if(m < 7) + error(0, Ebadblt); + v = GSHORT(p+1); + if(v<0 || v>NINFO || m<7+6*(v+1)) /* BUG */ + error(0, Ebadblt); + for(i=1; in = v; + f->height = p[3]; + f->ascent = p[4]; + v = GSHORT(p+5); + dst = &bit.map[v]; + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) + error(0, Ebadbitmap); + m -= 7; + p += 7; + fcp = f->info; + for(i=0; i<=f->n; i++,fcp++){ + fcp->x = GSHORT(p); + fcp->top = p[2]; + fcp->bottom = p[3]; + fcp->left = p[4]; + fcp->width = p[5]; + fcp->top = p[2]; + p += 6; + m -= 6; + } + bit.lastfid = f - bit.font; + f->bits = dst; + break; + case 'l': /* * line segment @@ -584,7 +675,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; - if(v>=conf.nbitmap || dst->ldepth<0) + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(0, Ebadbitmap); off = 0; if(v == 0) @@ -616,7 +707,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); src = &bit.map[v]; - if(v>=conf.nbitmap || src->ldepth<0) + if(v<0 || v>=conf.nbitmap || src->ldepth<0) error(0, Ebadbitmap); miny = GLONG(p+3); maxy = GLONG(p+7); @@ -643,7 +734,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; - if(v>=conf.nbitmap || dst->ldepth<0) + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(0, Ebadbitmap); off = 0; if(v == 0) @@ -651,7 +742,8 @@ bitwrite(Chan *c, void *va, long n) pt.x = GLONG(p+3); pt.y = GLONG(p+7); v = GSHORT(p+11); - if(v != 0) /* BUG */ + f = &bit.font[v]; + if(v<0 || v>=conf.nfont || f->bits==0 || f->bits->ldepth<0) error(0, Ebadblt); v = GSHORT(p+13); p += 15; @@ -661,7 +753,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); if(off) cursoroff(1); - string(dst, pt, defont/*BUG*/, (char*)p, v); + string(dst, pt, f, (char*)p, v); if(off) cursoron(1); q++; @@ -682,7 +774,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; - if(v>=conf.nbitmap || dst->ldepth<0) + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(0, Ebadbitmap); off = 0; if(v == 0) @@ -693,7 +785,7 @@ bitwrite(Chan *c, void *va, long n) rect.max.y = GLONG(p+15); v = GSHORT(p+19); src = &bit.map[v]; - if(v>=conf.nbitmap || src->ldepth<0) + if(v<0 || v>=conf.nbitmap || src->ldepth<0) error(0, Ebadbitmap); if(src->r.min.x!=0 || src->r.min.y!=0 || src->r.max.x!=16 || src->r.max.y!=16) error(0, Ebadblt); @@ -727,7 +819,7 @@ bitwrite(Chan *c, void *va, long n) error(0, Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; - if(v>=conf.nbitmap || dst->ldepth<0) + if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(0, Ebadbitmap); off = 0; if(v == 0) diff --git a/port/devmnt.c b/port/devmnt.c index 18018b9c196ad1df3fcbb95c62f2bba97cf60557..4d9b2c6db0f23f838ce65c1cf9ff478b06d82ee6 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -771,7 +771,6 @@ mntxmit(Mnt *m, Mnthdr *mh) qlocked = 0; n = (*devtab[q->msg->type].read)(q->msg, mh->mbr->buf, BUFSIZE); if(convM2S(mh->mbr->buf, &mh->rhdr, n) == 0){ - print("format error in mntxmit\n"); mnterrdequeue(q, mh); error(0, Ebadmsg); } @@ -795,7 +794,6 @@ mntxmit(Mnt *m, Mnthdr *mh) /* * Hand response to correct recipient */ - if(q->writer==0) print("response with empty queue\n"); for(ow=0,w=q->writer; w; ow=w,w=w->next) if(mh->rhdr.fid == w->thdr.fid && mh->rhdr.type == w->thdr.type+1){ @@ -821,7 +819,6 @@ mntxmit(Mnt *m, Mnthdr *mh) qunlock(q); qlocked = 0; if(waserror()){ /* interrupted sleep */ - print("interrupted i/o\n"); mnterrdequeue(q, mh); nexterror(); }