commit 6a4290043e1bd71dc3ad5408da591f54d968634b
parent 0ce52aa165ba5efb61e7ad5cce2832e75ccd0365
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 26 Feb 2022 22:36:36 +0000
clean up
Diffstat:
4 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/extra/clear b/extra/clear
@@ -1,2 +0,0 @@
-#!/bin/rc
-echo clear > /mnt/richterm/ctl
diff --git a/fs.c b/fs.c
@@ -11,7 +11,7 @@
Array *consbuf, *ctlbuf, *menubuf;
Channel *consc, *ctlc;
File *fsroot;
-File *cons, *consctl, *ctl, *menu, *new, *richtext;
+File *cons, *consctl, *ctl, *menu, *new, *text;
Reqqueue *rq;
void arrayopen(Req *);
@@ -22,18 +22,11 @@ void conswrite(Req *);
void ctlread(Req *);
void ctlwrite(Req *);
void delayedread(Req *);
-void fontread(Req *);
-void fontwrite(Req *);
void fs_destroyfid(Fid *);
void fs_flush(Req *);
void fs_open(Req *);
void fs_read(Req *);
void fs_write(Req *);
-void imageclose(Fid *);
-void newopen(Req *);
-void newread(Req *);
-void textread(Req *);
-void textwrite(Req *);
int
initfs(char *srvname)
@@ -59,7 +52,7 @@ initfs(char *srvname)
consctl = createfile(fsroot, "consctl", "richterm", DMAPPEND|0666,
fauxalloc(nil, nil, nil, nil, nil));
- richtext = createfile(fsroot, "richtext", "richterm", 0666,
+ text = createfile(fsroot, "text", "richterm", 0666,
fauxalloc(richdata, nil, arrayread, arraywrite, nil));
menu = createfile(fsroot, "menu", "richterm", 0666,
@@ -202,4 +195,3 @@ conswrite(Req *r)
respond(r, nil);
}
-
diff --git a/richterm.c b/richterm.c
@@ -195,23 +195,7 @@ threadmain(int argc, char **argv)
unlockdisplay(display);
break;
case INSERT:
- /*obj = objectcreate();
- mkobjectftree(obj, fsroot);
- objinsertbeforelast(obj);
- objsettext(obj, arrayget(av, 0, nil), av->count);*/
-
insertfromcons(av);
- arrayfree(av);
- // TODO: this is not how things should be done!
- // elems should be cleaned properly,
- // or even better only append fresh data instead of reparsing everything
- elems->count = 0;
- parsedata(richdata, elems);
- arraygrow(elems, 1, &euser);
- elemslinklist(elems);
- elemsupdatecache(elems);
-
- nbsend(redrawc, nil);
break;
case KBD:
if (kv == 0x7f) shutdown(); /* delete */
@@ -257,12 +241,14 @@ threadmain(int argc, char **argv)
} else if (kv == '\n') {
// TODO: send str as array to consc channel
- Array *msg = arraycreate(sizeof(char), strlen(euser->str) + 1, nil);
- arraygrow(msg, strlen(euser->str), euser->str);
+ Array *msg = arraycreate(sizeof(char), 0, nil);
+ if (euser->str != nil) {
+ arraygrow(msg, strlen(euser->str), euser->str);
+ str = smprint("%c%s\n" "n\n", euser->type, euser->str);
+ } else str = smprint("n\n");
arraygrow(msg, 1, "\n");
nbsend(consc, &msg);
- str = smprint("%c%s\n" "n\n", euser->type, euser->str);
arraygrow(richdata, strlen(str), str);
e = mallocz(sizeof(Elem), 1);
@@ -1013,6 +999,19 @@ insertfromcons(Array *a)
}
}
qunlock(a->l);
+
+ arrayfree(a);
+
+ // TODO: this is not how things should be done!
+ // elems should be cleaned properly,
+ // or even better only append fresh data instead of reparsing everything
+ elems->count = 0;
+ parsedata(richdata, elems);
+ arraygrow(elems, 1, &euser);
+ elemslinklist(elems);
+ elemsupdatecache(elems);
+
+ nbsend(redrawc, nil);
}
void
diff --git a/richterm.h b/richterm.h
@@ -39,6 +39,7 @@ void generatepage(Rich *, long);
extern Channel *redrawc;
extern Channel *insertc;
extern Channel *consc;
+extern Channel *ctlc;
extern File *fsroot;
extern Array *menubuf;
extern Array *fonts;