richterm

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

commit 1367143adc74745208d3696de347aaea3d98a1b7
parent 6a4290043e1bd71dc3ad5408da591f54d968634b
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Mon, 28 Feb 2022 21:25:00 +0000

set appropriate file length in stat

Diffstat:
Mfs.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mrichterm.c | 16+---------------
Mrichterm.h | 7++++---
3 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/fs.c b/fs.c @@ -27,6 +27,7 @@ void fs_flush(Req *); void fs_open(Req *); void fs_read(Req *); void fs_write(Req *); +void fs_stat(Req *); int initfs(char *srvname) @@ -36,6 +37,7 @@ initfs(char *srvname) .read = fs_read, .write = fs_write, .flush = fs_flush, + .stat = fs_stat, .destroyfid = fs_destroyfid, }; consbuf = nil; @@ -47,29 +49,34 @@ initfs(char *srvname) fsroot = srv.tree->root; cons = createfile(fsroot, "cons", "richterm", DMAPPEND|0666, - fauxalloc(nil, nil, consread, conswrite, nil)); + fauxalloc(nil, nil, consread, conswrite, nil, nil)); consctl = createfile(fsroot, "consctl", "richterm", DMAPPEND|0666, - fauxalloc(nil, nil, nil, nil, nil)); + fauxalloc(nil, nil, nil, nil, nil, nil)); text = createfile(fsroot, "text", "richterm", 0666, - fauxalloc(richdata, nil, arrayread, arraywrite, nil)); + fauxalloc(richdata, arrayopen, arrayread, arraywrite, nil, nil)); + text->length = richdata->count; menu = createfile(fsroot, "menu", "richterm", 0666, - fauxalloc(menubuf, nil, arrayread, arraywrite, nil)); + fauxalloc(menubuf, nil, arrayread, arraywrite, nil, nil)); threadpostmountsrv(&srv, srvname, "/mnt/richterm", MREPL); return 0; } Faux * -fauxalloc(Array *data, - void (*open)(Req *), void (*read)(Req *), - void (*write)(Req *), void (*destroyfid)(Fid *)) +fauxalloc( + Array *data, + void (*open)(Req *), + void (*read)(Req *), + void (*write)(Req *), + void (*stat)(Req *), + void (*destroyfid)(Fid *)) { Faux *aux; aux = mallocz(sizeof(Faux), 1); - *aux = (Faux) {data, open, read, write, destroyfid}; + *aux = (Faux) {data, open, read, write, stat, destroyfid}; return aux; } @@ -81,8 +88,7 @@ fs_destroyfid(Fid *fid) void fs_open(Req *r) { - Faux *aux; - aux = r->fid->file->aux; + Faux *aux = r->fid->file->aux; if ((aux != nil) && (aux->open != nil)) aux->open(r); else respond(r, nil); } @@ -108,6 +114,20 @@ fs_write(Req *r) } void +fs_stat(Req *r) +{ + Faux *aux = r->fid->file->aux; + if (aux != nil) { + if (aux->stat != nil) aux->stat(r); + else if (aux->data != nil) { + r->fid->file->length = aux->data->count; + r->d.length = aux->data->count; + respond(r, nil); + } + } else respond(r, "fs_stat: f->aux is nil"); +} + +void fs_flush(Req *r) { respond(r, nil); @@ -127,44 +147,52 @@ delayedread(Req *r) void arrayopen(Req *r) { - + Array *data = ((Faux *)r->fid->file->aux)->data; + + if ((r->ifcall.mode & OTRUNC) != 0) { + qlock(data->l); + data->count = 0; + qunlock(data->l); + r->fid->file->length = 0; + } respond(r, nil); } void arrayread(Req *r) { - Array *data; - data = ((Faux *)r->fid->file->aux)->data; + Array *data = ((Faux *)r->fid->file->aux)->data; + qlock(rich.l); qlock(data->l); readbuf(r, data->p, data->count); qunlock(data->l); qunlock(rich.l); - respond(r, nil); } void arraywrite(Req *r) { - long count; - Array *data; - qlock(rich.l); - data = ((Faux *)r->fid->file->aux)->data; - count = r->ifcall.count + r->ifcall.offset; + Array *data = ((Faux *)r->fid->file->aux)->data; + + long count = r->ifcall.count + r->ifcall.offset; + + if (count > data->count) arraygrow(data, count - data->count, nil); + else data->count = count; -// data->count = 0; -// arraygrow(data, r->ifcall.count, r->ifcall.data); qlock(data->l); + memcpy(data->p + r->ifcall.offset, r->ifcall.data, r->ifcall.count); qunlock(data->l); + r->ofcall.count = r->ifcall.count; + r->fid->file->length = data->count; - qunlock(rich.l); + respond(r, nil); } diff --git a/richterm.c b/richterm.c @@ -676,21 +676,7 @@ Array *richdata; Elem *euser; char *sampledata = - ".A\n" - "t\n" - ".beta\n" - "s\n" - "Lhttp://nsmpr.xyz\n" - ".gamma\n" - "L\n" - "s\n" - "Lhttp://9front.org\n" - "F/lib/font/bit/terminus/unicode.12.font\n" - ".delta\n" - "L\n" - "F\n" - "n\n" - ".Каким-то макаром попали к татарам амбары да бары пропали задаром\n" + ".We richterm now\n" "n\n"; char * diff --git a/richterm.h b/richterm.h @@ -26,10 +26,11 @@ struct Faux { void (*open)(Req *); void (*read)(Req *); void (*write)(Req *); + void (*stat)(Req *); void (*destroyfid)(Fid *); }; -Faux * fauxalloc(Array *, void (*)(Req *), void (*)(Req *), void (*)(Req *), void (*)(Fid *)); +Faux * fauxalloc(Array *, void (*)(Req *), void (*)(Req *), void (*)(Req *), void (*)(Req *), void (*)(Fid *)); Font* getfont(Array *, char *); int initfs(char *); void drawpage(Image *, Rich *); @@ -50,8 +51,8 @@ extern Rich rich; enum { E_NOOP = '\0', E_TEXT = '.', - E_FONT = 'F', - E_LINK = 'L', + E_FONT = 'f', + E_LINK = 'l', E_IMAGE = 'I', E_NL = 'n', E_TAB = 't',