commit e2762aed174dde8f4022a6f6b756c9f037cf31d0
parent e6fbd25ecf457f068d3586a17ca837b27daca2e9
Author: rpa <rpa@grass>
Date: Sun, 10 Sep 2023 00:03:26 +0000
src/tablist/extract: probably some code
Diffstat:
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/tablist/extract.c b/src/tablist/extract.c
@@ -5,13 +5,19 @@
#include "../util/util.h"
#include "../tablist/tablist.h"
+enum {
+ MDefault = 0,
+ MPrune,
+ MTail,
+ MHead,
+};
Reprog **query;
-int qcount;
+int mode = MDefault, qcount;
void
usage(void)
{
- fprint(2, "usage: %s query\n", argv0);
+ fprint(2, "usage: [-pth] %s query\n", argv0);
exits("usage");
}
@@ -71,7 +77,7 @@ filter(Slice *in, int (*ffunc)(TLnode *, void *))
for (i = 0; i < in->len; i++) {
v = slicegetp(in, i);
n = *v;
- if (frecur(n, nil)) {
+ if (ffunc(n, nil)) {
sliceappendp(out, 1, v);
}
}
@@ -88,10 +94,19 @@ main(int argc, char **argv)
Slice *out;
ARGBEGIN {
+ case 'p':
+ mode = MPrune;
+ break;
+ case 't':
+ mode = MTail;
+ break;
+ case 'h':
+ mode = MHead;
+ break;
default:
usage();
} ARGEND
-
+
qcount = argc;
query = malloc(sizeof(Reprog *) * qcount);
for (i = 0; i < qcount; i++) {
@@ -103,7 +118,25 @@ main(int argc, char **argv)
TLdecode(dec, buf, n);
}
- out = filter(dec->nodes, fregex);
+ switch (mode) {
+ case MDefault:
+ out = filter(dec->nodes, frecur);
+ break;
+ case MPrune:
+ break;
+ case MTail:
+ break;
+ case MHead:
+ out = filter(dec->nodes, frecur);
+ for (i = 0; i < out->len; i++) {
+ TLnode **v = slicegetp(out, i);
+ TLnode *n = *v;
+ n->children->len = 0;
+ }
+ break;
+ default:
+ sysfatal("unknown mode %d", mode);
+ }
enc = initTLencoder(out);
while ((n = TLencode(enc, buf, sizeof(buf))) > 0) {