richterm

"terminal emulator" with support for text fonts and images for plan9
git clone git://nsmpr.xyz/richterm.git
Log | Files | Refs | README

commit 03aa7bbfe7d4fd1527052f7145a8827db6832a68
parent 14a73c85cf56a1863ab0cde5517e38f62f8e7e4a
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Sat,  8 May 2021 21:08:14 +0000

move devfs control into it's own struct

Diffstat:
Mdevfs.c | 27++++++++++++++++-----------
Mrichterm.c | 10+++++-----
Mrichterm.h | 13+++++++------
3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/devfs.c b/devfs.c @@ -6,8 +6,6 @@ #include "richterm.h" -Channel *objchan; - void devfs_read(Req *r) { @@ -17,30 +15,37 @@ devfs_read(Req *r) void devfs_write(Req *r) { + Devfsctl *dctl; Object obj; + dctl = r->fid->file->aux; + if (dctl == nil) sysfatal("dctl is nil"); + if (dctl->wc == nil) sysfatal("dctl->wc is nil"); obj.type = strdup("text"); obj.opts = strdup(""); obj.count = r->ifcall.count + 1; obj.data = mallocz(obj.count, 1); memcpy(obj.data, r->ifcall.data, r->ifcall.count); - send(objchan, &obj); + send(dctl->wc, &obj); r->ofcall.count = r->ifcall.count; respond(r, nil); } -int -initdevfs(Channel *chan) +Devfsctl * +initdevfs(void) { - /* TODO: should set errstr */ + Devfsctl *dctl; static Srv srv = { .read = devfs_read, .write = devfs_write, }; - objchan = chan; + dctl = mallocz(sizeof(Devfsctl), 1); + + dctl->wc = chancreate(sizeof(Object), 0); srv.tree = alloctree(nil, nil, 0600, nil); - if (srv.tree == nil) return -1; - if (createfile(srv.tree->root, "cons", nil, 0600, nil) == nil) - return -1; + if (srv.tree == nil) + return nil; + if (createfile(srv.tree->root, "cons", nil, 0600, dctl) == nil) + return nil; threadpostmountsrv(&srv, "rtdev", nil, 0); - return 0; + return dctl; } diff --git a/richterm.c b/richterm.c @@ -47,6 +47,7 @@ threadmain(int argc, char **argv) int i; Mousectl *mctl; Keyboardctl *kctl; + Devfsctl *dctl; int rv[2]; Mouse mv; Rune kv; @@ -87,7 +88,6 @@ threadmain(int argc, char **argv) "different fonts\n", strlen("different fonts\n") }; - oc = chancreate(sizeof(Object), 0); rich.page = generatepage(screen->r, &rich); draw(screen, screen->r, display->white, nil, ZP); @@ -102,18 +102,18 @@ threadmain(int argc, char **argv) if ((kctl = initkeyboard(nil)) == nil) sysfatal("%s: %r", argv0); - if (initdevfs(oc) < 0) sysfatal("initdevfs failed: %r"); + if ((dctl = initdevfs()) == nil) sysfatal("initdevfs failed: %r"); // init /mnt fs for exposing internals // launch a subprocess from cmd passed on args // if args are empty, cmd = "rc" - enum {MOUSE, RESIZE, KBD, OBJ, NONE}; + enum {MOUSE, RESIZE, KBD, DEVFSWRITE, NONE}; Alt alts[5]={ {mctl->c, &mv, CHANRCV}, {mctl->resizec, rv, CHANRCV}, {kctl->c, &kv, CHANRCV}, - {oc, &ov, CHANRCV}, + {dctl->wc, &ov, CHANRCV}, {nil, nil, CHANEND}, }; for (;;) { @@ -133,7 +133,7 @@ threadmain(int argc, char **argv) case KBD: if (kv == 0x7f) threadexitsall(nil); break; - case OBJ: + case DEVFSWRITE: rich.count++; rich.obj = realloc(rich.obj, rich.count * sizeof(Object)); rich.obj[rich.count - 1] = ov; diff --git a/richterm.h b/richterm.h @@ -1,8 +1,9 @@ -/* - * Object is an atom of internal data structure. - * There should be a list of Objects, manipulatable - * either through GUI or file system. - */ +typedef struct Devfsctl Devfsctl; +struct Devfsctl { + Channel *rc; + Channel *wc; +}; + typedef struct Object Object; struct Object { char *type; @@ -11,4 +12,4 @@ struct Object { long count; }; -int initdevfs(Channel *); +Devfsctl * initdevfs(void);