commit 4fa98fecf66bdf2dd7480d5061b55d0105fac6c1
parent cf710f60850495f40ecf59f80ff3006b9544ab29
Author: rpa <rpa@grass>
Date: Wed, 22 Nov 2023 19:20:39 +0000
wdb/search: add search by tag, type
Diffstat:
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/wdb/search.c b/src/wdb/search.c
@@ -12,7 +12,7 @@ Biobuf *bout;
enum { MaxTags = 256, Growth = 16, BSize = 8192, };
-char *tags[MaxTags];
+char *tags[MaxTags], *types[MaxTags];
Slice *wdb;
@@ -78,15 +78,25 @@ testname(TLnode *n, Reprog *re)
int
testtags(TLnode *n)
{
- // TODO
- return 1;
+ TLnode *ntag = TLgetnode(n->children, "tags", nil);
+ if (ntag == nil) sysfatal("testtags: can't get tags node");
+ char *str = TLval2str(ntag);
+ if (str == nil) sysfatal("testtags: can't get tags value");
+ int r = _testtagsstr(tags, str);
+ free(str);
+ return r;
}
int
testtype(TLnode *n)
{
- // TODO
- return 1;
+ TLnode *ntype = TLgetnode(n->children, "type", nil);
+ if (ntype == nil) sysfatal("testtags: can't get tags node");
+ char *str = TLval2str(ntype);
+ if (str == nil) sysfatal("testtags: can't get tags value");
+ int r = _testtagsstr(types, str);
+ free(str);
+ return r;
}
void
@@ -106,6 +116,10 @@ main(int argc, char *argv[])
t = EARGF(usage());
tokenize(t, tags, MaxTags);
break;
+ case 'T':
+ t = EARGF(usage());
+ tokenize(t, types, MaxTags);
+ break;
default:
usage();
} ARGEND