+}
+
+int do_whowassearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
+ nick *sender = source;
+ int limit=500;
+ int arg=0;
+ WhowasDisplayFunc display=defaultwhowasfn;
+ int ret;
+ parsertree *tree;
+
+ if (cargc<1) {
+ reply( sender, "Usage: [flags] <criteria>");
+ reply( sender, "For help, see help whowassearch");
+ return CMD_OK;
+ }
+
+ ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void *)&display, reg_whowassearch->outputtree, reply, sender);
+ if(ret != CMD_OK)
+ return ret;
+
+ if (arg>=cargc) {
+ reply(sender,"No search terms - aborting.");
+ return CMD_ERROR;
+ }
+
+ if (arg<(cargc-1)) {
+ rejoinline(cargv[arg],cargc-arg);
+ }
+
+ tree = parse_string(reg_whowassearch, cargv[arg]);
+ if(!tree) {
+ displaystrerror(reply, sender, cargv[arg]);
+ return CMD_ERROR;
+ }
+
+ ast_whowassearch(tree->root, reply, sender, wall, display, NULL, NULL, limit, NULL);
+
+ parse_free(tree);
+
+ return CMD_OK;
+}
+
+int do_whowassearch(void *source, int cargc, char **cargv) {
+ return do_whowassearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
+}
+
+void whowassearch_exe(struct searchNode *search, searchCtx *ctx) {
+ int i, matches = 0;
+ whowas *ww;
+ nick *sender = ctx->sender;
+ senderNSExtern = sender;
+ WhowasDisplayFunc display = ctx->displayfn;
+ int limit = ctx->limit;
+
+ /* The top-level node needs to return a BOOL */
+ search=coerceNode(ctx, search, RETURNTYPE_BOOL);
+
+ for (i = whowasoffset; i < whowasoffset + WW_MAXENTRIES; i++) {
+ if (ctx->target) {
+ ww = ctx->target;
+ } else {
+ ww = &whowasrecs[i % WW_MAXENTRIES];
+
+ if (ww->type == WHOWAS_UNUSED)
+ continue;
+ }
+
+ /* Note: We're passing the nick to the filter function. The original
+ * whowas record is in the nick's ->next field. */
+ if ((search->exe)(ctx, search, &ww->nick)) {
+ if (matches<limit)
+ display(ctx, sender, ww);
+
+ if (matches==limit)
+ ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
+ matches++;
+ }
+
+ if (ctx->target)
+ break;
+ }
+
+ ctx->reply(sender,"--- End of list: %d matches", matches);