]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-or.c
10 void or_free(searchCtx
*ctx
, struct searchNode
*thenode
);
11 void *or_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
18 struct searchNode
*or_parse(searchCtx
*ctx
, int argc
, char **argv
) {
19 searchNode
*thenode
, *subnode
;
20 struct or_localdata
*localdata
;
23 /* Set up our local data - a list of nodes to OR together */
24 if (!(localdata
=(struct or_localdata
*)malloc(sizeof(struct or_localdata
)))) {
25 parseError
= "malloc: could not allocate memory for this search.";
28 if (!(localdata
->nodes
=(searchNode
**)malloc(argc
* sizeof(searchNode
*)))) {
29 /* couldn't malloc() memory for localdata->nodes, so free localdata to avoid leakage */
30 parseError
= "malloc: could not allocate memory for this search.";
36 /* Allocate our actual node */
37 if (!(thenode
=(searchNode
*)malloc(sizeof(searchNode
)))) {
38 /* couldn't malloc() memory for thenode, so free localdata->nodes and localdata to avoid leakage */
39 parseError
= "malloc: could not allocate memory for this search.";
40 free(localdata
->nodes
);
45 thenode
->returntype
= RETURNTYPE_BOOL
;
46 thenode
->localdata
= localdata
;
47 thenode
->exe
= or_exe
;
48 thenode
->free
= or_free
;
50 for (i
=0;i
<argc
;i
++) {
51 subnode
=ctx
->parser(ctx
, argv
[i
]); /* Propogate the search type */
52 subnode
=coerceNode(ctx
, subnode
, RETURNTYPE_BOOL
); /* BOOL please */
54 localdata
->nodes
[localdata
->count
++] = subnode
;
56 or_free(ctx
, thenode
);
64 void or_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
65 struct or_localdata
*localdata
;
68 localdata
=thenode
->localdata
;
69 for (i
=0;i
<localdata
->count
;i
++) {
70 (localdata
->nodes
[i
]->free
)(ctx
, localdata
->nodes
[i
]);
73 free(localdata
->nodes
);
78 void *or_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
80 struct or_localdata
*localdata
;
82 localdata
=thenode
->localdata
;
84 for (i
=0;i
<localdata
->count
;i
++) {
85 if ((localdata
->nodes
[i
]->exe
)(ctx
, localdata
->nodes
[i
], theinput
))