commit 0b704fc2079df5c6d568c0bf272d384c0cfd7bd2
parent 17e958dcd48e0ee10e7d84bfd16d90ea3e208c25
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 17 Aug 2024 00:15:39 +0000
src: add wdb2fltp
Diffstat:
2 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/src/mkfile b/src/mkfile
@@ -3,13 +3,33 @@ TARG=\
shuf \
poke \
baseconv \
+ wdb2fltp \
HFILES=
OFILES=
+
</sys/src/cmd/mkmany
$O.list: list.$O binlist/liblist.a$O
+$O.wdb2fltp: wdb2fltp.$O
+ bind -b tablist /$objtype/lib
+ bind -b util /$objtype/lib
+ lc /$objtype/lib/*a$O
+ $LD $LDFLAGS -o $target $prereq
+
binlist/liblist.a$O:
cd binlist
mk
+
+tablist/libtablist.a$O:
+ cd tablist
+ mk
+
+fltp/libfltp.a$O:
+ cd fltp
+ mk
+
+util/libutil.a$O:
+ cd util
+ mk
diff --git a/src/wdb2fltp.c b/src/wdb2fltp.c
@@ -0,0 +1,55 @@
+/*
+ * convert wdb databse from tablist to fltp format
+ * hardcodes galore
+ */
+
+
+#include <u.h>
+#include <libc.h>
+
+// #include "fltp/fltp.h"
+#include <util/util.h>
+#include <tablist/tablist.h>
+
+TLdecoder *tld;
+
+void printslice(Slice *);
+
+void
+printself(TLnode *node){
+ if(node->name != nil) print("%.*s ", node->name->len, node->name->p);
+ else print(".n %.*s\n", node->value->len, node->value->p);
+}
+
+void
+printnode(TLnode *node){
+ if (node->children->len > 0){
+ print("{ ");
+ printself(node);
+ printslice(node->children);
+ print("}\n");
+ } else printself(node);
+}
+
+void
+printslice(Slice *s){
+ int i;
+ void **v;
+ TLnode *node;
+ for(i = 0; i < s->len; i++){
+ v = slicegetp(s, i);
+ node = *v;
+ printnode(node);
+ }
+}
+
+void
+main(void){
+ char *buf;
+ long n;
+ tld = initTLdecoder(nil);
+ buf = malloc(8912);
+ while((n = read(0, buf, 8912)) > 0) TLdecode(tld, buf, n);
+ if(n < 0) sysfatal("%r");
+ printslice(tld->nodes);
+}