]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-all.c
10 void all_free(searchCtx
*ctx
, struct searchNode
*thenode
);
11 void *all_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
13 #define MAX_ITERATIONS 1000
15 struct all_localdata
{
21 struct searchNode
*all_parse(searchCtx
*ctx
, int argc
, char **argv
) {
23 struct all_localdata
*localdata
;
26 parseError
= "all: usage: all (generatorfn x) (fn ... (var x) ...)";
30 if(!(localdata
=(struct all_localdata
*)malloc(sizeof(struct all_localdata
)))) {
31 parseError
= "malloc: could not allocate memory for this search.";
35 localdata
->hitlimit
= 0;
37 if(!(localdata
->genfn
=ctx
->parser(ctx
, argv
[0]))) {
42 localdata
->lambdafn
= ctx
->parser(ctx
, argv
[1]);
43 if(!(localdata
->lambdafn
= coerceNode(ctx
, localdata
->lambdafn
, RETURNTYPE_BOOL
))) {
44 (localdata
->genfn
->free
)(ctx
, localdata
->genfn
);
49 if(!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
50 parseError
= "malloc: could not allocate memory for this search.";
51 (localdata
->genfn
->free
)(ctx
, localdata
->genfn
);
52 (localdata
->lambdafn
->free
)(ctx
, localdata
->lambdafn
);
57 thenode
->returntype
= RETURNTYPE_BOOL
;
58 thenode
->localdata
= localdata
;
59 thenode
->exe
= all_exe
;
60 thenode
->free
= all_free
;
65 void all_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
66 struct all_localdata
*localdata
= thenode
->localdata
;
68 if(localdata
->hitlimit
)
69 ctx
->reply(senderNSExtern
, "Warning: your expression was terminated for %d nicks as it hit the maximum iteration count.", localdata
->hitlimit
);
71 (localdata
->genfn
->free
)(ctx
, localdata
->genfn
);
72 (localdata
->lambdafn
->free
)(ctx
, localdata
->lambdafn
);
78 void *all_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
79 struct all_localdata
*localdata
= thenode
->localdata
;
82 /* if(localdata->hitlimit)
86 for(i
=0;i
<MAX_ITERATIONS
;i
++) {
87 if(!(localdata
->genfn
->exe
)(ctx
, localdata
->genfn
, theinput
))
90 if(!(localdata
->lambdafn
->exe
)(ctx
, localdata
->lambdafn
, theinput
))
94 localdata
->hitlimit
++;