]> jfr.im git - irc/quakenet/newserv.git/commitdiff
trust search ast
authorPaul <redacted>
Thu, 25 Dec 2008 22:23:44 +0000 (22:23 +0000)
committerPaul <redacted>
Thu, 25 Dec 2008 22:23:44 +0000 (22:23 +0000)
--HG--
branch : paul

trusts_search/Makefile.in
trusts_search/newsearch_ast.c [new file with mode: 0644]
trusts_search/trusts_search.c
trusts_search/trusts_search.h

index f8589e1156f70cf9443e02ab3c42a184b0709aad..34e8a43df053ac3407e58203a8a2bc19c1836c74 100644 (file)
@@ -6,5 +6,5 @@ LDFLAGS+=$(LIBPGSQL) $(LIBPCRE)
 .PHONY: all
 all: trusts_search.so
 
-trusts_search.so: formats.o trusts_search.o
+trusts_search.so: formats.o trusts_search.o newsearch_ast.o
 
diff --git a/trusts_search/newsearch_ast.c b/trusts_search/newsearch_ast.c
new file mode 100644 (file)
index 0000000..93afaf4
--- /dev/null
@@ -0,0 +1,36 @@
+#include "../lib/sstring.h"
+#include "../lib/strlfunc.h"
+#include "../lib/stringbuf.h"
+#include <stdarg.h>
+#include <string.h>
+#include "trusts_search.h"
+
+int ast_tgsearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit) {
+  searchCtx ctx;
+  searchASTCache cache;
+  searchNode *search;
+  char buf[1024];
+
+  newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_tgsearch, sender, display, limit);
+
+  memset(&cache, 0, sizeof(cache));
+  cache.tree = tree;
+
+  buf[0] = '\0';
+  reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_tgsearch));
+  search = ctx.parser(&ctx, (char *)tree);
+  if(!search) {
+    reply(sender, "Parse error: %s", parseError);
+    return CMD_ERROR;
+  }
+
+  reply(sender, "Executing...");
+  if(header)
+    header(sender, headerarg);
+  tgsearch_exe(search, &ctx);
+
+  (search->free)(&ctx, search);
+
+  return CMD_OK;
+}
+
index e2d4f167daa661bade0351e8e28ffa78ac40068b..d20e0ccd1d5bca1b8ae959d9f7bcfeb0ddb0e94c 100644 (file)
@@ -18,7 +18,7 @@ typedef void (*THDisplayFunc)(struct searchCtx *, nick *, trusthost_t *);
 
 int do_tgsearch(void *source, int cargc, char **cargv);
 int do_tgsearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv);
-void tgsearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, TGDisplayFunc display, int limit, patricia_node_t *subset);
+void tgsearch_exe(struct searchNode *search, searchCtx *ctx);
 int do_thsearch(void *source, int cargc, char **cargv);
 int do_thsearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv);
 void thsearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, THDisplayFunc display, int limit, patricia_node_t *subset);
@@ -59,16 +59,18 @@ static void controlwallwrapper(int level, char *format, ...) {
 
 int do_tgsearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
   nick *sender = senderNSExtern = source;
-  struct searchNode *search;
   int limit=500;
   int arg=0;
   TGDisplayFunc display=defaulttgfn;
-  searchCtx ctx;
   int ret;
   patricia_node_t *subset = iptree->head;
+  parsertree *tree;
 
-  if (cargc<1)
-    return CMD_USAGE;
+  if (cargc<1) {
+    reply( sender, "Usage: [flags] <criteria>");
+    reply( sender, "For help, see help nicksearch");
+    return CMD_OK;
+  }
 
   ret = parseopts(cargc, cargv, &arg, &limit, (void *)&subset, (void **)&display, reg_tgsearch->outputtree, reply, sender);
   if(ret != CMD_OK)
@@ -83,16 +85,15 @@ int do_tgsearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, ch
     rejoinline(cargv[arg],cargc-arg);
   }
 
-  newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_tgsearch, sender, display, limit);
-
-  if (!(search = ctx.parser(&ctx, cargv[arg]))) {
-    reply(sender,"Parse error: %s",parseError);
+  tree = parse_string(reg_tgsearch, cargv[arg]);
+  if(!tree) {
+    displaystrerror(reply, sender, cargv[arg]);
     return CMD_ERROR;
   }
 
-  tgsearch_exe(search, &ctx, sender, display, limit, subset);
+  ast_tgsearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
 
-  (search->free)(&ctx, search);
+  parse_free(tree);
 
   return CMD_OK;
 }
@@ -101,10 +102,14 @@ int do_tgsearch(void *source, int cargc, char **cargv) {
   return do_tgsearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
 }
 
-void tgsearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, TGDisplayFunc display, int limit, patricia_node_t *subset) {
+void tgsearch_exe(struct searchNode *search, searchCtx *ctx) {
   int matches = 0;
   trustgroup_t *tg;
   int i;
+  nick *np, *sender = ctx->sender;
+  senderNSExtern = sender;
+  TGDisplayFunc display = ctx->displayfn;
+  int limit = ctx->limit;
 
   /* Get a marker value to mark "seen" channels for unique count */
   //nmarker=nextnodemarker();
index b50fee382d48968907c6ca9af8fb26691de09a54..7de96b2ba72f6edf1157fe0cd37cb5bcd02176fa 100644 (file)
@@ -12,6 +12,7 @@
 #include "../lib/stringbuf.h"
 #include "../lib/strlfunc.h"
 #include "../trusts2/trusts.h"
+#include "../newsearch/parser.h"
 
 extern searchCmd *reg_tgsearch;
 extern searchCmd *reg_thsearch;