commit 0ce52aa165ba5efb61e7ad5cce2832e75ccd0365
parent 3f2aee21828f5489dd680cd8c244139e619bf699
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 26 Feb 2022 21:59:20 +0000
purge old code
Diffstat:
M | fs.c | | | 343 | +++---------------------------------------------------------------------------- |
M | richterm.c | | | 404 | ++++++++++--------------------------------------------------------------------- |
M | richterm.h | | | 79 | ++++++++++++++++--------------------------------------------------------------- |
3 files changed, 75 insertions(+), 751 deletions(-)
diff --git a/fs.c b/fs.c
@@ -11,8 +11,7 @@
Array *consbuf, *ctlbuf, *menubuf;
Channel *consc, *ctlc;
File *fsroot;
-File *cons, *consctl, *ctl, *menu, *new, *text;
-Object *newobj;
+File *cons, *consctl, *ctl, *menu, *new, *richtext;
Reqqueue *rq;
void arrayopen(Req *);
@@ -46,150 +45,44 @@ initfs(char *srvname)
.flush = fs_flush,
.destroyfid = fs_destroyfid,
};
- // newobj = nil;
consbuf = nil;
rq = reqqueuecreate();
- // menubuf = arraycreate(sizeof(char), 1024, nil);
+ menubuf = arraycreate(sizeof(char), 1024, nil);
consc = chancreate(sizeof(Array *), 1024);
- // ctlc = chancreate(sizeof(Array *), 1024);
srv.tree = alloctree("richterm", "richterm", DMDIR|0555, nil);
fsroot = srv.tree->root;
cons = createfile(fsroot, "cons", "richterm", DMAPPEND|0666,
- fauxalloc(nil, nil, nil, consread, conswrite, nil));
+ fauxalloc(nil, nil, consread, conswrite, nil));
consctl = createfile(fsroot, "consctl", "richterm", DMAPPEND|0666,
- fauxalloc(nil, nil, nil, nil, nil, nil));
-
-/*
-
- new = createfile(fsroot, "new", "richterm", 0444,
- fauxalloc(nil, nil, newopen, newread, nil, nil));
- ctl = createfile(fsroot, "ctl", "richterm", DMAPPEND|0666,
- fauxalloc(nil, nil, nil, ctlread, ctlwrite, nil));
-
-
- text = createfile(fsroot, "text", "richterm", 0444,
- fauxalloc(nil, rich.text, nil, arrayread, nil, nil));
-
+ fauxalloc(nil, nil, nil, nil, nil));
+ richtext = createfile(fsroot, "richtext", "richterm", 0666,
+ fauxalloc(richdata, nil, arrayread, arraywrite, nil));
menu = createfile(fsroot, "menu", "richterm", 0666,
- fauxalloc(nil, menubuf, nil, arrayread, arraywrite, nil));
-
-*/
+ fauxalloc(menubuf, nil, arrayread, arraywrite, nil));
threadpostmountsrv(&srv, srvname, "/mnt/richterm", MREPL);
return 0;
}
-void
-rmobjectftree(Object *obj)
-{
- free(obj->ftext->aux);
- free(obj->ffont->aux);
- free(obj->flink->aux);
- free(obj->fimage->aux);
-
- removefile(obj->ftext);
- removefile(obj->ffont);
- removefile(obj->flink);
- removefile(obj->fimage);
-
- removefile(obj->dir);
-
- free(obj->id);
-}
-
-Object *
-mkobjectftree(Object *obj, File *root)
-{
- obj->id = smprint("%ulld", ++rich.idcount);
-
- obj->dir = createfile(root, obj->id, "richterm", DMDIR|0555, nil);
-
- obj->ftext = createfile(obj->dir, "text", "richterm", 0666,
- fauxalloc(obj, nil, nil, textread, textwrite, nil));
-
- obj->ffont = createfile(obj->dir, "font", "richterm", DMAPPEND|0666,
- fauxalloc(obj, nil, nil, fontread, fontwrite, nil));
-
- obj->flink = createfile(obj->dir, "link", "richterm", 0666,
- fauxalloc(obj, obj->dlink, nil, arrayread, arraywrite, nil));
-
- obj->fimage = createfile(obj->dir, "image", "richterm", 0666,
- fauxalloc(obj, obj->dimage, nil, arrayread, arraywrite, nil));
-
- return obj;
-}
-
Faux *
-fauxalloc(Object *obj, Array *data,
+fauxalloc(Array *data,
void (*open)(Req *), void (*read)(Req *),
void (*write)(Req *), void (*destroyfid)(Fid *))
{
Faux *aux;
aux = mallocz(sizeof(Faux), 1);
- *aux = (Faux) {obj, data, open, read, write, destroyfid};
+ *aux = (Faux) {data, open, read, write, destroyfid};
return aux;
}
-char *
-ctlcmd(char *buf)
-{
- Object *obj;
- int n, i, j;
- char *args[256];
- obj = nil;
- n = tokenize(buf, args, 256);
- if (n <= 0) return "expected a command";
- qlock(rich.l);
- if (strcmp(args[0], "remove") == 0) {
- for (i = 1; i < n; i++) {
- for (j = 0; j < rich.objects->count; j++) {
- arrayget(rich.objects, j, &obj);
- if (obj == olast) continue;
- if (strcmp(obj->id, args[i]) == 0) {
- objsettext(obj, nil, 0);
- rmobjectftree(obj);
- objectfree(obj);
- free(obj);
- arraydel(rich.objects, j, 1);
- break;
- }
- }
- }
- } else if (strcmp(args[0], "clear") == 0) {
- for (i = 0; i < rich.objects->count; i++) {
- arrayget(rich.objects, i, &obj);
- if (obj != olast) rmobjectftree(obj);
- objectfree(obj);
- free(obj);
- }
- rich.objects->count = 0;
- rich.text->count = 0;
- olast = objectcreate();
- arraygrow(rich.objects, 1, &olast);
- } else {
- qunlock(rich.l);
- return "unknown command";
- }
- qunlock(rich.l);
- return nil;
-}
-
-
void
fs_destroyfid(Fid *fid)
{
- if (fid->file == nil) return;
- if (fid->file->aux == nil) return;
- if (((Faux *)fid->file->aux)->obj == nil) return;
- if (((Faux *)fid->file->aux)->obj->fimage == nil) return;
- if (fid->file == ((Faux *)fid->file->aux)->obj->fimage) {
- imageclose(fid);
- }
}
void
@@ -215,7 +108,7 @@ fs_write(Req *r)
if (aux != nil) {
if (aux->write != nil) {
aux->write(r);
- nbsend(redrawc, &aux->obj);
+ nbsend(redrawc, nil);
}
else respond(r, "no write");
} else respond(r, "fs_write: f->aux is nil");
@@ -248,9 +141,6 @@ arrayopen(Req *r)
void
arrayread(Req *r)
{
-
-/*
-
Array *data;
data = ((Faux *)r->fid->file->aux)->data;
qlock(rich.l);
@@ -259,7 +149,6 @@ arrayread(Req *r)
qunlock(data->l);
qunlock(rich.l);
-*/
respond(r, nil);
}
@@ -287,98 +176,6 @@ arraywrite(Req *r)
}
void
-textread(Req *r)
-{
- Faux *aux;
- Object *obj, *oe;
- char *s;
- usize n;
-
- qlock(rich.l);
- aux = r->fid->file->aux;
- obj = aux->obj;
- oe = obj->next;
-
- if (oe == nil) n = rich.text->count;
- else n = oe->offset;
-
- s = arrayget(rich.text, obj->offset, nil);
-
- qlock(rich.text->l);
-
- readbuf(r, s, n - obj->offset);
-
- r->fid->file->length = objtextlen(obj);
-
- qunlock(rich.text->l);
- qunlock(rich.l);
- respond(r, nil);
-}
-
-void
-textwrite(Req *r)
-{
- /* TODO: this is not exactly finished */
- /* in particular TRUNK/APPEND handling is needed */
-
- char *buf;
- Faux *aux;
- Object *obj;
- long n, m, k;
-
- aux = r->fid->file->aux;
- obj = aux->obj;
-
- n = r->ifcall.offset + r->ifcall.count;
- m = objtextlen(obj);
- k = (n > m) ? n : m;
- buf = malloc(sizeof(char) * k);
-
- qlock(rich.l);
- memcpy(buf, arrayget(rich.text, obj->offset, nil), m);
- memcpy(buf + r->ifcall.offset, r->ifcall.data, r->ifcall.count);
- objsettext(obj, buf, k);
- qunlock(rich.l);
-
- free(buf);
- r->ofcall.count = r->ifcall.count;
- respond(r, nil);
-}
-
-void
-fontread(Req *r)
-{
- Faux *aux;
- qlock(rich.l);
- aux = r->fid->file->aux;
- readstr(r, aux->obj->font->name);
- qunlock(rich.l);
- respond(r, nil);
-}
-
-void
-fontwrite(Req *r)
-{
- char buf[4096], *bp;
- Faux *aux;
- qlock(rich.l);
- aux = r->fid->file->aux;
- memcpy(buf, r->ifcall.data, r->ifcall.count);
- buf[r->ifcall.count] = '\0';
-
- for(bp = buf+ r->ifcall.count - 1; bp >= buf; bp--)
- if ((*bp==' ')||(*bp=='\t')||(*bp=='\n')) *bp = '\0';
-
- for(bp = buf; bp < buf + r->ifcall.count - 1; bp++)
- if ((*bp!=' ')&&(*bp!='\t')&&(*bp!='\n')) break;
-
- aux->obj->font = getfont(fonts, bp);
- qunlock(rich.l);
- r->ofcall.count = r->ifcall.count;
- respond(r, nil);
-}
-
-void
consread(Req *r)
{
if (consbuf == nil) recv(consc, &consbuf);
@@ -406,123 +203,3 @@ conswrite(Req *r)
respond(r, nil);
}
-void
-ctlread(Req *r)
-{
- if (ctlbuf == nil) recv(ctlc, &ctlbuf);
- r->ifcall.offset = 0;
- readbuf(r, ctlbuf->p, ctlbuf->count);
- if (arraydel(ctlbuf, 0, r->ofcall.count) != 0)
- sysfatal("ctlread: %r");
- if (ctlbuf->count == 0) {
- arrayfree(ctlbuf);
- ctlbuf = nil;
- }
- respond(r, nil);
-}
-
-void
-ctlwrite(Req *r)
-{
- char *ret, *buf;
- buf = mallocz(r->ifcall.count + 1, 1);
- memcpy(buf, r->ifcall.data, r->ifcall.count);
- ret = ctlcmd(buf);
- free(buf);
- r->ofcall.count = r->ifcall.count;
- respond(r, ret);
-}
-
-void
-newopen(Req *r)
-{
- newobj = objectcreate();
- mkobjectftree(newobj, fsroot);
- objinsertbeforelast(newobj);
- respond(r, nil);
-}
-
-void
-newread(Req *r)
-{
- readstr(r, newobj->id);
- respond(r, nil);
-}
-
-void
-imageclose(Fid *fid)
-{
- Array *data;
- Rectangle r;
- char *p;
- int compressed, m;
- long n;
- ulong chan;
- Faux *aux;
-
-
- compressed = 0;
- aux = fid->file->aux;
- data = aux->data;
-
- if (aux->obj->image != nil) return;
-
- qlock(data->l);
- p = data->p;
- n = data->count;
- if (n < 10) {
- data->count = 0;
- aux->obj->ftext->length = 0;
- qunlock(data->l);
- fprint(2, "imageclose: image file too short\n");
- return;
- }
- if (strncmp("compressed\n", p, 11) == 0) {
- p += 11;
- n -= 11;
- compressed = 1;
- }
- if (n < 60) {
- data->count = 0;
- aux->obj->ftext->length = 0;
- qunlock(data->l);
- fprint(2, "imageclose: image file too short\n");
- return;
- }
- if ((chan = strtochan(p)) == 0) {
- data->count = 0;
- aux->obj->ftext->length = 0;
- qunlock(data->l);
- fprint(2, "imageclose: image channel unknown: %12s\n", p);
- return;
- }
- p += 12; n -= 12;
- r.min.x = atoi(p); p += 12; n -= 12;
- r.min.y = atoi(p); p += 12; n -= 12;
- r.max.x = atoi(p); p += 12; n -= 12;
- r.max.y = atoi(p); p += 12; n -= 12;
-
- lockdisplay(display);
- aux->obj->image = allocimage(display, r, chan, 0, DBlue);
- if (aux->obj->image == nil) {
- data->count = 0;
- aux->obj->ftext->length = 0;
- qunlock(data->l);
- unlockdisplay(display);
- fprint(2, "imageclose: allocimage failed: %r\n");
- return;
- }
- if (compressed != 0) m = cloadimage(aux->obj->image, r, (uchar *)p, n);
- else m = loadimage(aux->obj->image, r, (uchar *)p, n);
- if (m != n) {
- fprint(2, "imageclose: failed to load image\n");
- freeimage(aux->obj->image);
- data->count = 0;
- aux->obj->ftext->length = 0;
- }
-
- unlockdisplay(display);
- qunlock(data->l);
-
- return;
-}
diff --git a/richterm.c b/richterm.c
@@ -18,12 +18,6 @@ void send_interrupt(void);
void runcmd(void *);
void scroll(Point, Rich *);
void mouse(Mousectl *, Mouse, int *);
-void drawobject(Object *, Point *);
-Object * getobj(Point);
-Object * minobj(Object *, Object *);
-long getsel(Point);
-int objectisvisible(Object *);
-
void insertfromcons(Array *);
Rich rich;
@@ -49,12 +43,12 @@ Menu mmenu = {
.lasthit = 0,
};
-void rfollow(Object *);
-void rsnarf(Object *);
-void rplumb(Object *);
+void rfollow(void *);
+void rsnarf(void *);
+void rplumb(void *);
char *ritems[] = {"Follow", "Snarf", "Plumb", nil};
-void (*rfunc[])(Object *) = {rfollow, rsnarf, rplumb, nil};
+void (*rfunc[])(void *) = {rfollow, rsnarf, rplumb, nil};
int rsize = sizeof(ritems) / sizeof(*ritems);
char * rgen(int);
@@ -73,8 +67,6 @@ Menu rusermenu = {
.lasthit = 0,
};
-Object *olast;
-
enum {
MM_NONE,
MM_SCROLLBAR,
@@ -95,7 +87,6 @@ threadmain(int argc, char **argv)
int rv[2], mmode;
Mouse mv;
Rune kv;
- Object *ov, *ov2, *obj;
Array *av;
ARGBEGIN{
@@ -109,9 +100,6 @@ threadmain(int argc, char **argv)
usage();
} ARGEND
- ov = nil;
- ov2 = nil;
- obj = nil;
av = nil;
mmode = MM_NONE;
@@ -143,12 +131,6 @@ threadmain(int argc, char **argv)
qlock(rich.l);
- rich.text = arraycreate(sizeof(char), 4096, nil);
- rich.objects = arraycreate(sizeof(Object *), 8, nil);
-
- olast = objectcreate();
- arraygrow(rich.objects, 1, &olast);
-
rich.page.scroll = ZP;
rich.selmin = 0;
@@ -156,7 +138,7 @@ threadmain(int argc, char **argv)
qunlock(rich.l);
- redrawc = chancreate(sizeof(Object *), 8);
+ redrawc = chancreate(sizeof(void *), 8);
insertc = chancreate(sizeof(Array *), 8);
generatesampleelems();
@@ -178,6 +160,7 @@ threadmain(int argc, char **argv)
threadsetname("main");
+ void *ov, *ov2;
enum {MOUSE, RESIZE, REDRAW, INSERT, KBD, AEND};
Alt alts[AEND + 1] = {
@@ -201,7 +184,9 @@ threadmain(int argc, char **argv)
nbsend(redrawc, nil);
break;
case REDRAW:
- while (nbrecv(redrawc, &ov2) != 0) ov = minobj(ov, ov2);
+
+ while (nbrecv(redrawc, &ov2) != 0) ov = ov2;
+
lockdisplay(display);
draw(screen, screen->r, Inormbg, nil, ZP);
drawelems();
@@ -226,7 +211,7 @@ threadmain(int argc, char **argv)
elemslinklist(elems);
elemsupdatecache(elems);
- nbsend(redrawc, &obj);
+ nbsend(redrawc, nil);
break;
case KBD:
if (kv == 0x7f) shutdown(); /* delete */
@@ -305,7 +290,7 @@ threadmain(int argc, char **argv)
euser->str = str;
euser->count = strlen(str);
}
- nbsend(redrawc, &obj);
+ nbsend(redrawc, nil);
}
break;
case AEND:
@@ -365,6 +350,7 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
case MM_TEXT:
break;
+/*
if (mv.buttons == 1) {
selstart = getsel(mv.xy);
selend = selstart;
@@ -394,15 +380,16 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
*mmode = MM_NONE;
}
break;
+*/
+
case MM_SELECT:
break;
+/*
if (mv.buttons == (1|2)) {
- /* cut */
break;
}
if (mv.buttons == (1|4)) {
- /* paste */
break;
}
selend = getsel(mv.xy);
@@ -414,6 +401,8 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
rich.selmax = selstart;
}
nbsend(redrawc, nil);
+*/
+
}
}
@@ -470,26 +459,6 @@ drawscrollbar(void)
draw(screen, rs, Inormbg, nil, ZP);
}
-Object *
-objectcreate(void)
-{
- Object *obj;
- obj = mallocz(sizeof(Object), 1);
-
- obj->font = font;
- obj->dlink = arraycreate(sizeof(char), 4096, nil);
- obj->dimage = arraycreate(sizeof(char), 4096, nil);
- return obj;
-}
-
-void
-objectfree(Object *obj)
-{
- arrayfree(obj->dlink);
- arrayfree(obj->dimage);
-}
-
-
void
runcmd(void *args)
{
@@ -567,7 +536,7 @@ mpaste(Rich *)
}
if (n < 0) fprint(2, "mpaste: %r\n");
close(fd);
- nbsend(redrawc, &olast);
+ nbsend(redrawc, nil);
}
}
@@ -606,289 +575,6 @@ mplumb(Rich *)
}
}
-int
-objectisvisible(Object *obj)
-{
- return (obj->nextlinept.y >= rich.page.scroll.y) &&
- (obj->startpt.y <= rich.page.scroll.y + Dy(rich.page.r));
-}
-
-void
-_drawchar(Rune r, Point pt, Font *font, Image *fg, Image *bg)
-{
- runestringnbg(screen,
- subpt(addpt(pt, rich.page.r.min), rich.page.scroll),
- fg, ZP, font, &r, 1, bg, ZP);
-}
-
-void
-drawchar(Object *obj, long *n, Point *cur)
-{
- int tabw, cw;
- Image *bg, *fg;
- Rune r;
- char *p;
-
- bg = ((*n >= rich.selmin) && (*n < rich.selmax)) ?
- Iselbg : Inormbg;
-
- fg = (obj->dlink->count > 0) ? Ilink : Itext;
-
- p = arrayget(rich.text, *n, nil);
-
- if (p == nil) return;
-
- *n += chartorune(&r, p);
- cw = runestringnwidth(obj->font, &r, 1);
-
- if (cur->x + cw >= Dx(rich.page.r)) {
- *cur = obj->nextlinept;
- obj->nextlinept.y += obj->font->height;
- }
-
- switch (*p) {
- case '\n':
- if (objectisvisible(obj))
- draw(screen,
- rectaddpt(
- Rpt(*cur, Pt(Dx(rich.page.r), obj->nextlinept.y)),
- subpt(rich.page.r.min, rich.page.scroll)),
- bg, nil, ZP);
-
- cur->x = Dx(rich.page.r);
- break;
- case '\t':
- tabw = stringwidth(font, "0") * 4;
- if (objectisvisible(obj))
- draw(screen,
- rectaddpt(
- Rpt(*cur, Pt(cur->x + tabw, obj->nextlinept.y)),
- subpt(rich.page.r.min, rich.page.scroll)),
- bg, nil, ZP);
-
- cur->x = (cur->x / tabw + 1) * tabw;
- break;
- default:
- if (objectisvisible(obj))
- _drawchar(r, *cur, obj->font, fg, bg);
- cur->x += cw;
- }
-}
-
-void
-drawobject(Object *obj, Point *cur)
-{
- long i, n;
- if ((obj->offset > rich.text->count) || (obj->offset < 0)) {
- fprint(2, "drawobject: object out of bonds: %ld %ld\n",
- obj->offset, rich.text->count);
- return;
- }
-
- if ((cur->x >= Dx(rich.page.r)) && (obj->prev != nil)) {
- *cur = obj->prev->nextlinept;
- }
-
- obj->nextlinept = Pt(0, cur->y + obj->font->height);
-
- if ((obj->prev != nil) && (cur->x != 0)) {
- if (obj->nextlinept.y < obj->prev->nextlinept.y)
- obj->nextlinept.y = obj->prev->nextlinept.y;
- }
-
- if (obj->image != nil) {
- Rectangle r;
- r = rectaddpt(obj->image->r,
- subpt(addpt(*cur, rich.page.r.min), rich.page.scroll));
- draw(screen, r, obj->image, nil, ZP);
- cur->x += Dx(r);
- if (cur->y + Dy(r) > obj->nextlinept.y)
- obj->nextlinept.y = cur->y + Dy(r);
- }
-
- obj->startpt = *cur;
-
- if (obj->next == nil) n = rich.text->count;
- else n = obj->next->offset;
-
- for (i = obj->offset; i < n;) {
- drawchar(obj, &i, cur);
- }
- obj->endpt = *cur;
-}
-
-void
-redraw(Object *op)
-{
-
- Point cur;
- Object *obj;
- int skip;
- long i;
-
- obj = nil;
- cur = ZP;
- skip = 0;
-
- qlock(rich.l);
-
- if (op == nil) draw(screen, rich.page.r, Inormbg, nil, ZP);
- else {
- skip = 1;
-
- /* TODO: following will clean previous objects if selected
- * object is not at x=0, even though I did not encounter
- * this so far in testing.
- * Still, it should probably be fixed in the future.
- */
-
- draw(
- screen,
- Rpt(
- subpt(
- addpt(Pt(0, op->endpt.y), rich.page.r.min),
- rich.page.scroll),
- rich.page.r.max),
- Inormbg, nil, ZP);
- }
-
- for (i = 0; i < rich.objects->count; i++) {
- if (arrayget(rich.objects, i, &obj) == nil)
- sysfatal("redraw: %r");
- if (obj == op) skip = 0;
- if (skip == 0) drawobject(obj, &cur);
- else {
- cur = obj->endpt;
- }
- }
- rich.page.max = obj->nextlinept;
- if (rich.page.scroll.y > rich.page.max.y)
- rich.page.scroll.y = rich.page.max.y;
- qunlock(rich.l);
-
-}
-
-Object *
-getobj(Point xy)
-{
- long i;
- Object *obj;
- Point prevlinept;
- xy = subpt(xy, subpt(rich.page.r.min, rich.page.scroll));
- for (i = 0; i < rich.objects->count; i++) {
- arrayget(rich.objects, i, &obj);
- prevlinept = ( obj->prev == nil) ? ZP : obj->prev->nextlinept;
-
- if (((obj->startpt.y == obj->endpt.y) &&
- (xy.y >= obj->startpt.y) &&
- (xy.y < obj->nextlinept.y) &&
- (xy.x >= obj->startpt.x) &&
- (xy.x < obj->endpt.x)) ||
-
- ((xy.x >= obj->startpt.x) &&
- (xy.y >= obj->startpt.y) &&
- (xy.y < obj->endpt.y)) ||
-
- ((obj->startpt.y < obj->endpt.y) &&
- (xy.x < obj->endpt.x) &&
- (xy.y >= obj->endpt.y) &&
- (xy.y < obj->nextlinept.y)) ||
-
- ((xy.y >= prevlinept.y) &&
- (xy.y < obj->endpt.y))
- )
- return obj;
- }
- return nil;
-}
-
-long
-getsel(Point xy)
-{
- Object *obj;
- long n, i, li;
- Point cur, oldcur;
-
- obj = getobj(xy);
-
- xy = subpt(xy, subpt(rich.page.r.min, rich.page.scroll));
-
- if (obj == nil)
- return (xy.y > rich.page.max.y) ? rich.text->count : 0;
-
- n = (obj->next == nil) ? rich.text->count : obj->next->offset;
- li = obj->offset;
-
- cur = obj->startpt;
- obj->nextlinept = Pt(0, cur.y + obj->font->height);
- if ((obj->prev != nil) && (cur.x != 0)) {
- if (obj->nextlinept.y < obj->prev->nextlinept.y)
- obj->nextlinept.y = obj->prev->nextlinept.y;
- }
-
- for (i = obj->offset; i < n;) {
- oldcur = cur;
- li = i;
- drawchar(obj, &i, &cur);
-
- if (ptinrect(xy, Rpt(oldcur, Pt(cur.x, obj->nextlinept.y))) ||
- (cur.y > xy.y))
- break;
- }
- return li;
-}
-
-void
-objinsertbeforelast(Object *obj)
-{
- qlock(rich.l);
- obj->offset = olast->offset;
- arrayinsert(rich.objects, rich.objects->count - 1, 1, &obj);
- obj->next = olast;
- obj->prev = olast->prev;
- if (olast->prev != nil) olast->prev->next = obj;
- olast->prev = obj;
- obj->endpt = olast->startpt;
- qunlock(rich.l);
-}
-
-long
-objtextlen(Object *obj)
-{
- long n;
- n = (obj->next == nil) ? rich.text->count : obj->next->offset;
- return n - obj->offset;
-}
-
-void
-objsettext(Object *obj, char *data, long count)
-{
- long n, m, dn;
- char *p, *pe;
-
- n = objtextlen(obj);
- m = count;
- dn = m - n;
-
- if (dn > 0) arraygrow(rich.text, dn, nil);
- else rich.text->count += dn;
-
- p = arrayget(rich.text, obj->offset, nil);
- pe = arrayget(rich.text, rich.text->count - dn, nil);
-
- qlock(rich.text->l);
- if (p != nil) memcpy(p + m, p + n, pe - p);
- else p = pe;
- memcpy(p, data, count);
- qunlock(rich.text->l);
-
- qlock(rich.objects->l);
- if (obj->ftext != nil) obj->ftext->length = count;
- for (obj = obj->next; obj != nil; obj = obj->next) {
- obj->offset += dn;
- }
- qunlock(rich.objects->l);
-}
char *
rgen(int n)
@@ -898,20 +584,25 @@ rgen(int n)
}
void
-rfollow(Object *obj)
+rfollow(void *)
{
+
+/*
Array *a;
a = arraycreate(sizeof(char), 1024, nil);
arraygrow(a, 5, "link ");
arraygrow(a, obj->dlink->count, arrayget(obj->dlink, 0, nil));
arraygrow(a, 1, "\n");
-
nbsend(ctlc, &a);
+*/
+
}
void
-rsnarf(Object *obj)
+rsnarf(void *)
{
+
+/*
int fd;
long n;
if ((fd = open("/dev/snarf", OWRITE)) > 0) {
@@ -920,11 +611,15 @@ rsnarf(Object *obj)
if (n < obj->dlink->count) fprint(2, "rsnarf: %r\n");
close(fd);
}
+*/
+
}
void
-rplumb(Object *obj)
+rplumb(void *)
{
+/*
+
char buf[1024];
int pd;
Plumbmsg m;
@@ -941,6 +636,8 @@ rplumb(Object *obj)
plumbsend(pd, &m);
close(pd);
}
+*/
+
}
void
@@ -956,7 +653,7 @@ ruseract(int f)
arraygrow(a, 5, "menu ");
arraygrow(a, strlen(s), s);
arraygrow(a, 1, "\n");
- nbsend(ctlc, &a);
+ // nbsend(ctlc, &a);
}
@@ -986,22 +683,6 @@ rusergen(int f)
return genbuf;
}
-Object *
-minobj(Object *o1, Object *o2)
-{
- Object *op;
- Array *objs;
- long n;
- objs = rich.objects;
- if ((o1 == nil) || (o2 == nil)) return nil;
- for (n = 0; n < objs->count; n++) {
- arrayget(objs, n, &op);
- if (op == o1) return o1;
- if (op == o2) return o2;
- }
- return nil;
-}
-
/* **** New Code Beyond This Point **** */
Array *elems;
@@ -1332,4 +1013,18 @@ insertfromcons(Array *a)
}
}
qunlock(a->l);
-}
-\ No newline at end of file
+}
+
+void
+freeelem(Elem *e)
+{
+ e->str = realloc(e->str, 0);
+ e->count = 0;
+ e->next = nil;
+ e->prev = nil;
+ e->link = realloc(e->link, 0);
+ if (e->image != nil) freeimage(e->image);
+ e->font = nil;
+ e->pos = ZP;
+ e->nlpos = ZP;
+}
diff --git a/richterm.h b/richterm.h
@@ -1,54 +1,6 @@
-extern Channel *redrawc;
-extern Channel *insertc;
-extern Channel *consc;
-extern Channel *ctlc;
-extern File *fsroot;
-extern Array *menubuf;
-
-void drawscrollbar(void);
-
-typedef struct Object Object;
-
-struct Object {
- File *dir;
- File *ftext;
- File *ffont;
- File *flink;
- File *fimage;
- char *id;
-
- Array *dlink;
- Array *dimage;
- Font *font;
- Image *image;
-
- long offset;
-
- Object *next;
- Object *prev;
-
- Point startpt;
- Point endpt;
- Point nextlinept;
-};
-
-extern Object *olast;
-
-void redraw(Object *);
-
-Object * objectcreate(void);
-Object * mkobjectftree(Object *, File *);
-void objinsertbeforelast(Object *);
-void rmobjectftree(Object *);
-void objectfree(Object *);
-long objtextlen(Object *obj);
-void objsettext(Object *, char *, long);
-
-extern Array *fonts;
-
-Font* getfont(Array *, char *);
-
typedef struct Page Page;
+typedef struct Rich Rich;
+typedef struct Faux Faux;
struct Page {
Point scroll;
@@ -57,8 +9,6 @@ struct Page {
Rectangle rs;
};
-typedef struct Rich Rich;
-
struct Rich {
QLock *l;
Array *objects;
@@ -71,17 +21,7 @@ struct Rich {
int max;
};
-extern Rich rich;
-
-void drawpage(Image *, Rich *);
-void generatepage(Rich *, long);
-
-int initfs(char *);
-
-typedef struct Faux Faux;
-
struct Faux {
- Object *obj;
Array *data;
void (*open)(Req *);
void (*read)(Req *);
@@ -89,8 +29,20 @@ struct Faux {
void (*destroyfid)(Fid *);
};
-Faux * fauxalloc(Object *, Array *, void (*)(Req *), void (*)(Req *), void (*)(Req *), void (*)(Fid *));
+Faux * fauxalloc(Array *, void (*)(Req *), void (*)(Req *), void (*)(Req *), void (*)(Fid *));
+Font* getfont(Array *, char *);
+int initfs(char *);
+void drawpage(Image *, Rich *);
+void drawscrollbar(void);
+void generatepage(Rich *, long);
+extern Channel *redrawc;
+extern Channel *insertc;
+extern Channel *consc;
+extern File *fsroot;
+extern Array *menubuf;
+extern Array *fonts;
+extern Rich rich;
/* **** New Code Beyond This Point **** */
@@ -138,6 +90,7 @@ Point drawnoop(Elem *);
char * elemparse(Elem *, char *, long);
void elemslinklist(Array *);
void elemsupdatecache(Array *);
+void freeelem(Elem *);
void generatesampleelems(void);
void parsedata(Array *, Array *);