*/
#include "newsearch.h"
-
#include "../lib/irc_string.h"
+
#include <stdio.h>
#include <stdlib.h>
struct gt_localdata {
+ int type;
int count;
struct searchNode **nodes;
};
-void gt_free(struct searchNode *thenode);
-void *gt_exe(struct searchNode *thenode, int type, void *theinput);
+void gt_free(searchCtx *ctx, struct searchNode *thenode);
+void *gt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *gt_parse(int type, int argc, char **argv) {
+struct searchNode *gt_parse(searchCtx *ctx, int argc, char **argv) {
struct gt_localdata *localdata;
struct searchNode *thenode;
int i;
thenode->free = gt_free;
for (i=0;i<argc;i++) {
- if (!(localdata->nodes[i] = search_parse(type, argv[i]))) {
- gt_free(thenode);
+ /* Parse the node.. */
+ localdata->nodes[i] = ctx->parser(ctx, argv[i]);
+
+ /* Subsequent nodes get coerced to match the type of the first node */
+ if (i)
+ localdata->nodes[i]=coerceNode(ctx,localdata->nodes[i],localdata->type);
+
+ /* If a node didn't parse, give up */
+ if (!localdata->nodes[i]) {
+ gt_free(ctx, thenode);
return NULL;
}
+
+ if (!i) {
+ /* First arg determines the type */
+ localdata->type = localdata->nodes[0]->returntype & RETURNTYPE_TYPE;
+ }
+
localdata->count++;
}
return thenode;
}
-void gt_free(struct searchNode *thenode) {
+void gt_free(searchCtx *ctx, struct searchNode *thenode) {
struct gt_localdata *localdata;
int i;
localdata=thenode->localdata;
for (i=0;i<localdata->count;i++) {
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ if (localdata->nodes[i])
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *gt_exe(struct searchNode *thenode, int type, void *theinput) {
+void *gt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
char *strval;
int intval;
localdata=thenode->localdata;
if (localdata->count==0)
- return trueval(type);
+ return (void *)1;
- switch (localdata->nodes[0]->returntype & RETURNTYPE_TYPE) {
+ switch (localdata->type) {
case RETURNTYPE_INT:
- intval = (int)((long)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_INT, theinput));
+ case RETURNTYPE_BOOL:
+ intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput));
for (i=1;i<localdata->count;i++) {
- if ((int)((long)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_INT, theinput) > intval))
- return falseval(type);
+ if ((int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput) >= intval))
+ return (void *)0;
}
-
- return trueval(type);
+ return (void *)1;
case RETURNTYPE_STRING:
- strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_STRING, theinput);
+ strval = (char *)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput);
for (i=1;i<localdata->count;i++) {
- if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_STRING, theinput)) > 0)
- return falseval(type);
+ if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput)) <= 0)
+ return (void *)0;
}
-
- return trueval(type);
+ return (void *)1;
default:
- return falseval(type);
+ return (void *)0;
}
}