commit f54e32cff2391f36feebe3fcad8ff1714391c642
parent db38512955eea2fc8b6b3174ba0cb269cc69063a
Author: glenda <glenda@9front.local>
Date: Sat, 24 Jul 2021 16:04:31 +0000
some refactoring, reading from new creates new object
Diffstat:
3 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/fs.c b/fs.c
@@ -17,7 +17,14 @@ fs_read(Req *r)
f = r->fid->file;
aux = f->aux;
if (f == new) {
- respond(r, "not implemented");
+ if (r->ifcall.offset == 0) {
+ Object *obj;
+ Fsctl *fsctl;
+ fsctl = new->aux;
+ obj = mkobjectftree(newobject(&rich), fsctl->tree->root, strdup(""));
+ readstr(r, obj->id);
+ }
+ respond(r, nil);
} else if (aux != nil) {
readbuf(r, aux->data->p, aux->data->n);
respond(r, nil);
diff --git a/richterm.c b/richterm.c
@@ -134,8 +134,6 @@ threadmain(int argc, char **argv)
{nil, nil, CHANEND},
};
for (;;) {
- Object *obj;
- Faux *auxtext, *auxfont, *auxlink, *auximage;
switch(alt(alts)) {
case MOUSE:
break;
@@ -183,23 +181,7 @@ threadmain(int argc, char **argv)
nbsend(dctl->rc, &kv);
break;
case DEVFSWRITE:
- rich.count++;
- rich.obj = realloc(rich.obj, rich.count * sizeof(Object));
- obj = &(rich.obj[rich.count - 1]);
- obj->id = smprint("%ld", rich.count);
-
- obj->dir = createfile(fsctl->tree->root, obj->id, "richterm", DMDIR|0555, nil);
-
- auxtext = fauxalloc(ov);
- auxfont = fauxalloc(strdup(font->name));
- auxlink = fauxalloc(strdup(""));
- auximage = fauxalloc(strdup(""));
-
- obj->ftext = createfile(obj->dir, "text", "richterm", 0666, auxtext);
- obj->ffont = createfile(obj->dir, "font", "richterm", 0666, auxfont);
- obj->flink = createfile(obj->dir, "link", "richterm", 0666, auxlink);
- obj->fimage = createfile(obj->dir, "image", "richterm", 0666, auximage);
-
+ mkobjectftree(newobject(&rich), fsctl->tree->root, ov);
generatepage(&rich);
draw(screen, screen->r, display->white, nil, ZP);
for (i = 0; i < rich.page.count; i++){
@@ -393,3 +375,33 @@ fauxalloc(char *str)
aux->data->n = strlen(str);
return aux;
}
+
+Object *
+newobject(Rich *rich)
+{
+ Object *obj;
+ rich->count++;
+ rich->obj = realloc(rich->obj, rich->count * sizeof(Object));
+ obj = &(rich->obj[rich->count - 1]);
+ obj->id = smprint("%ld", rich->count);
+ return obj;
+}
+
+Object *
+mkobjectftree(Object *obj, File *root, char *text)
+{
+ Faux *auxtext, *auxfont, *auxlink, *auximage;
+
+ obj->dir = createfile(root, obj->id, "richterm", DMDIR|0555, nil);
+
+ auxtext = fauxalloc(text);
+ auxfont = fauxalloc(strdup(font->name));
+ auxlink = fauxalloc(strdup(""));
+ auximage = fauxalloc(strdup(""));
+
+ obj->ftext = createfile(obj->dir, "text", "richterm", 0666, auxtext);
+ obj->ffont = createfile(obj->dir, "font", "richterm", 0666, auxfont);
+ obj->flink = createfile(obj->dir, "link", "richterm", 0666, auxlink);
+ obj->fimage = createfile(obj->dir, "image", "richterm", 0666, auximage);
+ return obj;
+}
+\ No newline at end of file
diff --git a/richterm.h b/richterm.h
@@ -18,6 +18,8 @@ struct Object {
char *id;
};
+Object * mkobjectftree(Object *, File *, char *);
+
typedef struct Fonts Fonts;
struct Fonts {
@@ -65,6 +67,7 @@ struct Rich {
extern Rich rich;
void generatepage(Rich *);
+Object * newobject(Rich *);
typedef struct Devfsctl Devfsctl;