]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/newsearch_ast.c
docs: Change section title.
[irc/quakenet/newserv.git] / newsearch / newsearch_ast.c
index fd8e1038ff4afb47a2afd39dd0c518694b6659b2..d77f0a215bb443b04db79888568d6ffb95f6da70 100644 (file)
@@ -11,12 +11,6 @@ typedef union exprunion {
   char *literal;
 } exprunion;
 
-typedef struct searchASTCache {
-  searchASTExpr *tree;
-  searchASTExpr *cache[AST_RECENT];
-  int nextpos;
-} searchASTCache;
-
 /* comares either a string and a string or an expression and an expression */
 static searchASTExpr *compareloc(searchASTExpr *expr, exprunion *loc) {
   if(expr->type == AST_NODE_LITERAL) {
@@ -162,6 +156,35 @@ int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc
   return CMD_OK;
 }
 
+int ast_whowassearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, WhowasDisplayFunc display, HeaderFunc header, void *headerarg, int limit) {
+  searchCtx ctx;
+  searchASTCache cache;
+  searchNode *search;
+  char buf[1024];
+
+  memset(&cache, 0, sizeof(cache));
+  cache.tree = tree;
+
+  newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_whowassearch, sender, display, limit);
+
+  buf[0] = '\0';
+  reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_whowassearch));
+  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);
+  whowassearch_exe(search, &ctx);
+
+  (search->free)(&ctx, search);
+
+  return CMD_OK;
+}
+
 int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit) {
   searchCtx ctx;
   searchASTCache cache;
@@ -242,32 +265,17 @@ static char *ast_printtree_real(StringBuf *buf, searchASTExpr *expr, searchCmd *
     sbaddchar(buf, ')');
 
   } else if(expr->type == AST_NODE_LITERAL) {
-    int quotesrequired, escrequired;
     char *p;
-    for(quotesrequired=escrequired=0,p=expr->u.literal;*p;p++) {
-      if(*p == '(' || *p == ')' || *p == ' ')
-        quotesrequired = 1;
-      if(*p == '\\' || *p == '"') {
-        escrequired = 1;
-        if(quotesrequired)
-          break;
-      }
-    }
-    if(quotesrequired)
-      sbaddchar(buf, '"');
-    
-    if(escrequired) {
-      for(p=expr->u.literal;*p;p++) {
-        if(*p == '\\' || *p == '"')
-          sbaddchar(buf, '\\');
-        sbaddchar(buf, *p);
-      }
-    } else {
-      sbaddstr(buf, expr->u.literal);
+
+    sbaddchar(buf, '"');
+
+    for(p=expr->u.literal;*p;p++) {
+      if(*p == '\\' || *p == '"')
+        sbaddchar(buf, '\\');
+      sbaddchar(buf, *p);
     }
 
-    if(quotesrequired)
-      sbaddchar(buf, '"');
+    sbaddchar(buf, '"');
   } else {
     sbaddstr(buf, "???");
   }