commit d398300d47a0564641f8c0c628f8682d27ebcf84
parent f2fe56ca1912bfc782aae0707249e7d321237496
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 11 Apr 2021 20:44:19 +0000
some boilerplate
Diffstat:
5 files changed, 72 insertions(+), 12 deletions(-)
diff --git a/devfs.c b/devfs.c
@@ -0,0 +1,25 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <thread.h>
+#include <9p.h>
+
+void
+devfs_read(Req *r)
+{
+ respond(r, nil);
+}
+
+int
+initdevfs(void)
+{
+ /* TODO: should set errstr */
+ static Srv srv;
+ srv.read = devfs_read;
+ 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;
+ threadpostmountsrv(&srv, "octreedev", "/dev", RFPROC);
+ return 0;
+}
diff --git a/fs.c b/fs.c
diff --git a/mkfile b/mkfile
@@ -1,6 +1,7 @@
</$objtype/mkfile
TARG=richterm
-OFILES=richterm.$O
+OFILES=richterm.$O devfs.$O fs.$O
+HFILES=richterm.h
</sys/src/cmd/mkone
diff --git a/richterm.c b/richterm.c
@@ -8,7 +8,7 @@
#include <cursor.h>
#include <9p.h>
-void usage(void);
+#include "richterm.h"
void
threadmain(int argc, char **argv)
@@ -16,22 +16,29 @@ threadmain(int argc, char **argv)
Mousectl *mctl;
int rv[2];
Mouse mv;
+ View view;
ARGBEGIN{
+ case 'D':
+ chatty9p++;
+ break;
default:
usage();
}ARGEND
- // init graphics and I/O
- if (initdraw(0, 0, "richterm") < 0) sysfatal("initdraw failed: %r");
+ if (initdraw(0, 0, "richterm") < 0)
+ sysfatal("initdraw failed: %r");
+ if (initview(&view) < 0) sysfatal("initview failed: %r);
draw(screen, screen->r, display->white, nil, ZP);
flushimage(display, 1);
- mctl = initmouse(nil, screen);
- if (mctl == nil) sysfatal("initmouse failed: %r");
-
- // init /dev fs for console
-
+ if ((mctl = initmouse(nil, screen)) == nil)
+ sysfatal("initmouse failed: %r");
+
+ if (initdevfs() < 0) sysfatal("initdevfs failed: %r");
// init /mnt fs for exposing internals
- // even processing loop
+
+ // launch a subprocess from cmd passed on args
+ // if args are empty, cmd = "rc"
+
enum {MOUSE, RESIZE, NONE};
Alt alts[3]={
{mctl->c, &mv, CHANRCV},
@@ -43,7 +50,8 @@ threadmain(int argc, char **argv)
case MOUSE:
break;
case RESIZE:
- if (getwindow(display, Refnone) < 0) sysfatal("resize failed: %r");
+ if (getwindow(display, Refnone) < 0)
+ sysfatal("resize failed: %r");
draw(screen, screen->r, display->white, nil, ZP);
flushimage(display, 1);
break;
@@ -56,6 +64,15 @@ threadmain(int argc, char **argv)
void
usage(void)
{
- fprint(2, "usage: %s [cmd]\n", argv0);
+ fprint(2, "usage: %s [-D] [cmd]\n", argv0);
threadexitsall("usage");
}
+
+int
+initview(View *view)
+{
+ char *m = "Welcome to RichTerm!";
+ view->count = 1;
+ view->obj = malloc(sizeof(Obj));
+ view->obj[0] = (Obj){ "text", nil, m, strlen(m) };
+}
diff --git a/richterm.h b/richterm.h
@@ -0,0 +1,17 @@
+typedef struct Obj Obj;
+struct Obj {
+ char *type;
+ char *opts;
+ char *data;
+ long count;
+};
+
+typedef struct View View;
+struct View {
+ Obj *obj;
+ long count;
+};
+
+void usage(void);
+int initview(View *);
+int initdevfs(void);