commit d7f78577327e439fe62e595fd500fa49854f6554
parent fe3cb1d893df14b85c0582e3e7898dafbcb8b897
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 19 Aug 2024 17:53:39 +0000
sync
Diffstat:
2 files changed, 174 insertions(+), 1 deletion(-)
diff --git a/src/wdb/mkfile b/src/wdb/mkfile
@@ -9,7 +9,7 @@ RC=\
ui.inc\
new\
ui
-TARG=search update
+TARG=search update search-fltp
</sys/src/cmd/mkmany
@@ -24,3 +24,7 @@ installdir:V:
installrc:V: installdir
cp $RC $BIN
+
+$O.search-fltp:
+ bind -b ../fltp /$objtype/lib
+ $LD $LDFLAGS -o $target $prereq
diff --git a/src/wdb/search-fltp.c b/src/wdb/search-fltp.c
@@ -0,0 +1,169 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <regexp.h>
+
+Biobuf *bout;
+
+#include "../fltp/fltp.h"
+
+enum{
+ MaxTags = 256,
+ BufSize = 4096,
+ ListSize = 256,
+};
+
+char *buf;
+char *tagsbuf[MaxTags], *typebuf[MaxTags];
+FLTNode *listbuf[ListSize], *uuid, *name, *tags, *type;
+
+FLTP *wdb;
+
+void
+runtests(FLTP *fltp){
+
+}
+
+void
+fltpnewendlist(FLTP *fltp){
+ int i;
+ char *s;
+ FLTNode *np, *ls;
+ fltpendlist(fltp);
+ ls = fltp->np->parent;
+ for(i = 0, np = ls->next; np != fltp->np; np = np->next){
+ if(np->parent != ls) continue;
+ if(i >= ListSize - 1)
+ sysfatal("list buffer overflown");
+ listbuf[i] = np;
+ i++;
+ }
+ listbuf[i] = nil;
+ if(i == 0) return;
+ s = (char *)(listbuf[0]) + sizeof(FLTNode);
+ snprint(buf, BufSize, "%.*s", (long)listbuf[0]->nbytes, s);
+ if(listbuf[0]->prev->parent == nil){
+ runtests(fltp);
+ return;
+ }
+ if(strcmp(buf, "name") == 0){
+ name = listbuf[0];
+ return;
+ }
+ if(strcmp(buf, "tags") == 0){
+ tags = listbuf[0];
+ return;
+ }
+ if(strcmp(buf, "type") == 0){
+ type = listbuf[0];
+ return;
+ }
+}
+/*
+int
+_testtag(char **tags, char *test)
+{
+ for (; *tags != nil; tags++) {
+ if (strcmp(test, *tags) == 0) return 1;
+ }
+ return 0;
+}
+
+int
+_testtags(char **tags, char **test)
+{
+ for (; *test != nil; test++) {
+ if (_testtag(tags, *test) == 0) return 0;
+ }
+ return 1;
+}
+*/
+void
+loadindex(void){
+ Biobuf *bfd;
+ char *bp, *path = "/usr/rpa/lib/wdb/index/all";
+ wdb = initfltp();
+ bfd = Bopen(path, OREAD);
+ while((bp = Brdline(bfd, '\n')) != nil){
+ evalfltp(wdb, bp, Blinelen(bfd));
+ }
+ Bterm(bfd);
+}
+
+int
+testname(FLTNode *n, Reprog *re){
+ /* char *sp, *np = "name";
+ FLTNode *vp;
+ if (re == nil) return 1;
+ vp = n->next;
+ while(vp->parent !=
+ sp = (char *)n + sizeof(FLTNode);
+ if (n->nbytes != strlen(np)) return 1;
+ if (strncmp(sp, np, n->nbytes) != 0) return 1;
+ snprint(buf, "%.*s", n->nbytes;
+ int r = regexec(re, str, nil, 0);
+ free(str);
+ return r; */
+ return 1;
+}
+
+int
+testtags(FLTNode *n, char *field, char **tags){
+ /* int i;
+ char uuid[64], *str;
+ if (tags[0] == nil) return 1;
+ i = snprint(uuid, 64, "%.*s\n", n->name->len, n->name->p);
+ uuid[i-1] = 0;
+ TLnode *nfield = TLgetnode(n->children, field, nil);
+ if (nfield == nil) {
+ fprint(2, "can't get node %s→%s\n", uuid, field);
+ return 0;
+ }
+ str = TLval2str(nfield);
+ if (str == nil) {
+ fprint(2, "can't get value %s→%s\n", uuid, field);
+ return 0;
+ }
+ char *test[MaxTags];
+ int N = tokenize(str, test, MaxTags);
+ test[N] = nil;
+ int r = _testtags(test, tags);
+ free(str);
+ return r; */
+ return 1;
+}
+
+void
+usage(void){
+ fprint(2, "usage: %s [-t tags] [-T type] [query]\n", argv0);
+ exits("usage");
+}
+
+void
+main(int argc, char *argv[]){
+ long i;
+ Reprog *re;
+ char *t;
+ FLTNode *np;
+ ARGBEGIN{
+ case 't':
+ t = EARGF(usage());
+ tokenize(t, tagsbuf, MaxTags);
+ break;
+ case 'T':
+ t = EARGF(usage());
+ tokenize(t, typebuf, MaxTags);
+ break;
+ default:
+ usage();
+ } ARGEND
+ if(argc > 1) usage();
+ if(argc == 1) re = regcomp(argv[0]);
+ else re = nil;
+
+ buf = malloc(BufSize);
+
+ bout = Bfdopen(1, OWRITE);
+ loadindex();
+
+}