ref: e49f718071886411a94f42ebf007f08eca4cfa9d
parent: 7c4e47bececffe6e1a62adb2fc93ff2422a9c274
author: sirjofri <sirjofri@sirjofri.de>
date: Mon Dec 15 06:36:32 EST 2025
generate QID paths
--- a/code.c
+++ b/code.c
@@ -109,3 +109,78 @@
#include "fsfunc.cinc"
);
}
+
+typedef struct Vqid Vqid;
+struct Vqid {+ char *name;
+ VFile *vfile;
+ Vqid *children;
+ Vqid *next;
+};
+
+Vqid *vqids = nil;
+
+static Vqid*
+findchild(Vqid *parent, char *child)
+{+ Vqid *v;
+
+ for (v = parent->children; v; v = v->next) {+ if (strcmp(v->name, child) == 0)
+ return v;
+ }
+ return nil;
+}
+
+void
+genqids(VFile *f, void*)
+{+ Vqid *v, *nv;
+ char **s;
+
+ if (!vqids) {+ /* root element */
+ vqids = mallocz(sizeof(Vqid), 1);
+ vqids->name = "root";
+ }
+
+ v = vqids;
+ for (s = f->parts; *s; s++) {+ if (**s == 0) {+ /* if root element */
+ continue;
+ }
+ nv = findchild(v, *s);
+ if (nv) {+ v = nv;
+ continue;
+ }
+ nv = mallocz(sizeof(Vqid), 1);
+ nv->name = strdup(*s);
+ nv->next = v->children;
+ v->children = nv;
+ v = nv;
+ }
+}
+
+static void
+rprintqids(Vqid *vq, int nest)
+{+ Vqid *v;
+ char buf[32];
+ if (!vq) return;
+
+ for (v = vq; v; v = v->next) {+ pathtostring(buf, sizeof(buf), v->name);
+ print("%*sQ%s,\n", nest*4, "", buf);+ rprintqids(v->children, nest+1);
+ }
+}
+
+void
+printqids()
+{+ print("enum {\n");+ rprintqids(vqids, 1);
+ print("};\n\n");+}
--- a/fns.h
+++ b/fns.h
@@ -2,6 +2,9 @@
VFile *addfile(char *path);
void foreachfile(void (*f)(VFile*,void*), void*);
+void genqids(VFile*,void*);
+void printqids(void);
+
void printread(VFile*);
void printwrite(VFile*);
void printls(VFile*);
--- a/main.c
+++ b/main.c
@@ -50,17 +50,17 @@
goto Err;
case COPY:
if (strcmp("r}", s) == 0) {- print("}\n");+ print("}\n\n");state = HASFILE;
break;
}
if (strcmp("w}", s) == 0) {- print("}\n");+ print("}\n\n");state = HASFILE;
break;
}
if (strcmp("ls}", s) == 0) {- print("}\n");+ print("}\n\n");state = HASFILE;
break;
}
@@ -153,7 +153,10 @@
printpre();
process(bin);
+ Bterm(bin);
+ foreachfile(genqids, nil);
+ printqids();
foreachfile(p, nil);
printfs();
--
⑨