#include "../authext/authext.h"
#include "../patricia/patricia.h"
+#ifndef __NEWSEARCH_H
+#define __NEWSEARCH_H
+
#define NSMAX_KILL_LIMIT 500
#define NSMAX_GLINE_LIMIT 500
#define NSMAX_GLINE_CLONES 5
int lastvar;
struct searchCmd *searchcmd;
nick *sender;
+ int limit;
+ void *displayfn;
} searchCtx;
/* Core functions */
/* Nick functions (various types) */
struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *away_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *authname_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *authts_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *ident_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *channels_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *cidr_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *ipv6_parse(searchCtx *ctx, int argc, char **argv);
/* Channel functions (various types) */
struct searchNode *exists_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *name_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *topic_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *cumodecount_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *cumodepct_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv);
struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv);
/* Iteraterable functions */
struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *nickiter_parse(searchCtx *ctx, int argc, char **argv);
/* Functions that operate on strings */
struct searchNode *cumodes_parse(searchCtx *ctx, int argc, char **argv);
/* Special nick* printf */
void nssnprintf(char *, size_t, const char *, nick *);
+#ifdef NEWSEARCH_NEWPARSER
+void displaystrerror(replyFunc reply, nick *np, const char *input);
+#endif
+
extern const char *parseError;
extern nick *senderNSExtern;
void printuser(searchCtx *, nick *, authname *);
void printchannel(searchCtx *, nick *, chanindex *);
-void nicksearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, NickDisplayFunc display, int limit);
-void chansearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, ChanDisplayFunc display, int limit);
-void usersearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, UserDisplayFunc display, int limit);
+void nicksearch_exe(struct searchNode *search, searchCtx *sctx);
+void chansearch_exe(struct searchNode *search, searchCtx *sctx);
+void usersearch_exe(struct searchNode *search, searchCtx *ctx);
int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv);
int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv);
searchNode *var_get(searchCtx *ctx, char *arg);
void var_setstr(struct searchVariable *v, char *data);
-void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *sender);
+void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *sender, void *displayfn, int limit);
/* AST functions */
/* items to store in the ast lookup cache */
#define AST_RECENT 10
+struct searchASTExpr;
+
+typedef struct searchASTNode {
+ parseFunc fn;
+ int argc;
+ struct searchASTExpr *argv;
+} searchASTNode;
+
typedef struct searchASTExpr {
int type;
union {
char *literal;
- struct searchASTNode *child;
+ /* this was originally a pointer, but having it as one means you can't memcpy directly */
+ struct searchASTNode child;
} u;
} searchASTExpr;
-typedef struct searchASTNode {
- parseFunc fn;
- int argc;
- struct searchASTExpr **argv;
-} searchASTNode;
+typedef struct searchASTCache {
+ searchASTExpr *tree;
+ searchASTExpr *cache[AST_RECENT];
+ int nextpos;
+} searchASTCache;
+
+#define __NSASTSizeOfArray(x) (sizeof(x) / sizeof(x[0]))
+
+#define __NSASTExpr(x, y, ...) (searchASTExpr){.type = x, .u.y = __VA_ARGS__}
+#define __NSASTRawNode(x, c, y) (searchASTNode){.fn = x, .argc = c, .argv = y}
+
+#define __NSASTSizeNode(x, y) __NSASTRawNode(x, __NSASTSizeOfArray(y), y)
+#define __NSASTNode(x, ...) __NSASTSizeNode(x, ((searchASTExpr []){__VA_ARGS__}))
-/*
- *
- * FEAR THE COMPOUND LITERALS
- * MUHAHAHHAHAHAHAHAHAAH
- *
- */
-#define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__}
-#define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__}
-#define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)}
#define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__)
-#define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data)
+#define NSASTLiteral(value) __NSASTExpr(AST_NODE_LITERAL, literal, value)
#define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__))
+#define NSASTManualNode(fn, count, children) __NSASTChild(__NSASTRawNode(fn, count, children))
searchNode *search_astparse(searchCtx *, char *);
int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void *display, CommandTree *sl, replyFunc reply, void *sender);
+typedef int (*ASTFunc)(searchASTExpr *, replyFunc, void *, wallFunc, void *, HeaderFunc, void *, int limit);
+
/* erk */
extern searchList *globalterms;
extern NickDisplayFunc defaultnickfn;
extern ChanDisplayFunc defaultchanfn;
+struct searchNode *argtoconststr(char *command, searchCtx *ctx, char *arg, char **p);
+
+#endif