ref: f41811c5b13705495acee0eda08a8bb5955c1e00
parent: e81025205d1ac4e517e2a4e21dfa9326c937a57b
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Dec 16 05:52:56 EST 2025
lots of fixes, needs prepass
--- a/code.c
+++ b/code.c
@@ -14,7 +14,7 @@
Vqid *vqids = nil;
static void
-printvars(VFile *file)
+printvars(VFile *file, char *prefix)
{char **a;
char *s;
@@ -32,7 +32,7 @@
continue;
strcpy(buf, s);
buf[n] = 0;
- print(", char *%s", buf+1);+ print("%s%s", prefix, buf+1);}
}
@@ -63,11 +63,26 @@
char buf[32];
genfuncname(file, buf, sizeof(buf), nm);
print("static void\n%s(Req *r", buf);- printvars(file);
+ printvars(file, ", char *");
print(")\n");+ fprint(2, "function: %s for file %s\n", buf, file->path);
}
void
+printgenfuncend(VFile *file, char *nm)
+{+ char buf[32];
+ genfuncname(file, buf, sizeof(buf), nm);
+ print("}\n\n");+ print("static void\nCall_%s(Req *r)\n{\n", buf);+ print(" FileAux *a = r->fid->aux;\n");+ print(" %s(r", buf);+ printvars(file, ", a->");
+ print(");\n");+ print("}\n\n");+}
+
+void
printls(VFile *file)
{char buf[64];
@@ -177,6 +192,7 @@
Vqid *v;
for (v = parent->children; v; v = v->next) {+ fprint(2, "compare %s == %s\n", v->name, child);
if (strcmp(v->name, child) == 0)
return v;
}
@@ -187,7 +203,8 @@
genqids(VFile *f, void*)
{Vqid *v, *nv;
- char **s;
+ char **a;
+ char *s;
char buf[64];
if (!vqids) {@@ -196,21 +213,26 @@
vqids->name = "root";
vqids->vfile = f;
vqids->vfile->isdir = 1;
+ fprint(2, "root qid\n");
}
v = vqids;
- for (s = f->parts; *s; s++) {- if (**s == 0) {+ for (a = f->parts; *a; a++) {+ s = *a;
+ fprint(2, "walk: %s\n", s);
+ if (*s == 0) {/* if root element */
continue;
}
- nv = findchild(v, *s);
+ nv = findchild(v, s);
if (nv) {+ fprint(2, "child %s of %s exists\n", s, v->vfile->path);
v = nv;
continue;
}
+ fprint(2, "create child %s of %s\n", s, v->vfile->path);
nv = mallocz(sizeof(Vqid), 1);
- pathtostring(buf, sizeof(buf), f->path);
+ pathtostring(buf, sizeof(buf), f->path+1);
nv->name = strdup(buf);
nv->vfile = f;
nv->next = v->children;
--- a/files.c
+++ b/files.c
@@ -53,6 +53,8 @@
numparts++;
s = buf;
+ *s = '/';
+ s++;
for (i = 1; i < numparts - 1; i++) {strcpy(s, parts[i]);
vf = addfile(buf);
@@ -60,7 +62,7 @@
return 0;
vf->isdir = 1;
s += strlen(parts[i]);
- *s = '_';
+ *s = '/';
s++;
}
return 1;
@@ -69,7 +71,7 @@
VFile*
addfile(char *path)
{- VFile *old;
+ VFile *old, *new;
old = getfile(path);
if (old)
@@ -83,15 +85,17 @@
files = mallocz(sizeof(VFile), 1);
files->next = old;
}
- files->path = strdup(path);
- files->parts = parsepath(path);
- if (!files->parts)
+ /* verifyfiles may add new files, thus changing the global files pointer */
+ new = files;
+ new->path = strdup(path);
+ new->parts = parsepath(path);
+ if (!new->parts)
return nil;
- if (!verifyfiles(files->parts))
+ if (!verifyfiles(new->parts))
return nil;
- return files;
+ return new;
}
VFile*
--- a/fns.h
+++ b/fns.h
@@ -8,5 +8,8 @@
void printqids(void);
void printgenfunc(VFile*, char*);
+void printgenfuncend(VFile*, char*);
void printfs(void);
void printpre(void);
+
+void printauxvars(void);
--- a/main.c
+++ b/main.c
@@ -40,6 +40,7 @@
currentfile = addfile(s);
if (!currentfile)
goto Err;
+ fprint(2, "new file: %s\n", currentfile->path);
state = HASFILE;
break;
}
@@ -51,22 +52,22 @@
goto Err;
case COPY:
if (strcmp("r}", s) == 0) {- print("}\n\n");+ printgenfuncend(currentfile, "read");
state = HASFILE;
break;
}
if (strcmp("w}", s) == 0) {- print("}\n\n");+ printgenfuncend(currentfile, "write");
state = HASFILE;
break;
}
if (strcmp("ls}", s) == 0) {- print("}\n\n");+ printgenfuncend(currentfile, "ls");
state = HASFILE;
break;
}
if (strcmp("s}", s) == 0) {- print("}\n\n");+ printgenfuncend(currentfile, "stat");
state = HASFILE;
break;
}
@@ -165,6 +166,8 @@
process(bin);
Bterm(bin);
+
+ printauxvars();
foreachfile(genqids, nil);
printqids();
--- a/mkfile
+++ b/mkfile
@@ -5,6 +5,7 @@
main.$O\
files.$O\
code.$O\
+ vars.$O\
HFILES=dat.h fns.h
CLEANFILES=fsfunc.cinc fshandler.cinc preamble.cinc
--- a/preamble.inc
+++ b/preamble.inc
@@ -15,6 +15,9 @@
Dir dir;
};
+typedef struct FileAux FileAux;
+#pragma incomplete FileAux
+
int SHIFT = 3;
int qidtype = -1;
--- /dev/null
+++ b/vars.c
@@ -1,0 +1,84 @@
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "fns.h"
+
+typedef struct Var Var;
+struct Var {+ char *name;
+ Var *next;
+};
+
+Var *vars = nil;
+
+static int
+hasvar(char *name)
+{+ Var *v;
+
+ for (v = vars; v; v = v->next)
+ if (v->name == name)
+ return 1;
+ return 0;
+}
+
+static void
+caddvar(char *name)
+{+ Var *v;
+ if (!vars) {+ vars = mallocz(sizeof(Var), 1);
+ vars->name = name;
+ return;
+ }
+ if (hasvar(name))
+ return;
+ v = vars;
+ vars = mallocz(sizeof(Var), 1);
+ vars->name = name;
+ vars->next = v;
+}
+
+static void
+collectvars(VFile *f, void*)
+{+ char **a;
+ char *s;
+ int n;
+
+ for (a = f->parts; *a; a++) {+ s = *a;
+ if (s[0] == 0)
+ continue;
+ n = strlen(s) - 1;
+ if (!(s[0] == '{' && s[n] == '}'))+ continue;
+ caddvar(s);
+ }
+}
+
+void
+printauxvars()
+{+ Var *v;
+ char buf[32];
+ char *s;
+
+ foreachfile(collectvars, nil);
+
+ print(
+ "struct FileAux {\n"+ );
+
+ if (!vars)
+ print(" int dummy;\n");+
+ for (v = vars; v; v = v->next) {+ strcpy(buf, v->name+1);
+ s = strchr(buf, '}');
+ *s = 0;
+ print(" char *%s;\n", buf);+ }
+
+ print("};\n\n");+}
--
⑨