stew

a monorepo of some sort
Log | Files | Refs

commit 7238e384a8efc72cf0f9fbc7296c055583481536
parent 2d1d2d535b6ad6401d73c1bbfb42735a81dbc8cc
Author: rpa <rpa@grass>
Date:   Wed, 22 Nov 2023 20:40:47 +0000

wdb: typos, clean up mkfile, searh.c

Diffstat:
Msrc/wdb/mkfile | 2--
Msrc/wdb/search.c | 55++++++++++++++++---------------------------------------
Msrc/wdb/ui.inc | 2+-
3 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/src/wdb/mkfile b/src/wdb/mkfile @@ -6,10 +6,8 @@ RC=\ genindex\ print\ tags\ - typesearch\ ui.inc\ new\ - tagsearch\ ui TARG=search update diff --git a/src/wdb/search.c b/src/wdb/search.c @@ -32,22 +32,6 @@ _testtags(char **tags, char **test) return 1; } -int -_testtagsstr(char **tags, char *str) -{ - char *test[MaxTags]; - char *s; - int n, r; - if (tags[0] == nil) return 1; - if (str == nil) return 0; - s = strdup(str); - n = tokenize(s, test, MaxTags); - test[n] = nil; - r = _testtags(test, tags); - free(s); - return r; -} - void loadindex(void) { @@ -65,6 +49,7 @@ loadindex(void) int testname(TLnode *n, Reprog *re) { + if (re == nil) return 1; TLnode *name = TLgetnode(n->children, "name", nil); char *str = TLval2str(name); if (str == nil) sysfatal("testname: can't get name"); @@ -74,25 +59,17 @@ testname(TLnode *n, Reprog *re) } int -testtags(TLnode *n) -{ - 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) +testtags(TLnode *n, char *field, char **tags) { - 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); + if (tags[0] == nil) return 1; + TLnode *nfield = TLgetnode(n->children, field, nil); + if (nfield == nil) sysfatal("testtags: can't get tags node %s", field); + char *str = TLval2str(nfield); + if (str == nil) sysfatal("testtags: can't get tags value %s", field); + char *test[MaxTags]; + int N = tokenize(str, test, MaxTags); + test[N] = nil; + int r = _testtags(test, tags); free(str); return r; } @@ -107,6 +84,7 @@ usage(void) void main(int argc, char *argv[]) { + long i; Reprog *re; char *t; ARGBEGIN { @@ -123,18 +101,17 @@ main(int argc, char *argv[]) } ARGEND if (argc > 1) usage(); if (argc == 1) re = regcomp(argv[0]); - else re = regcomp(".*"); - + else re = nil; + bout = Bfdopen(1, OWRITE); loadindex(); - long i; for (i = 0; i < wdb->len; i++) { TLnode **p = slicegetp(wdb, i); TLnode *n = *p; if (testname(n, re) == 0) continue; - if (testtags(n) == 0) continue; - if (testtype(n) == 0) continue; + if (testtags(n, "tags", tags) == 0) continue; + if (testtags(n, "type", types) == 0) continue; Bprint(bout, "%.*s\n", n->name->len, n->name->p); } } diff --git a/src/wdb/ui.inc b/src/wdb/ui.inc @@ -34,7 +34,7 @@ fn entry { } fn enumer { - echo Fount $#1 entries. + echo Found $#1 entries. } fn main {