]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-gt.c
7 #include "../lib/irc_string.h"
13 struct searchNode
**nodes
;
16 void gt_free(struct searchNode
*thenode
);
17 void *gt_exe(struct searchNode
*thenode
, int type
, void *theinput
);
19 struct searchNode
*gt_parse(int type
, int argc
, char **argv
) {
20 struct gt_localdata
*localdata
;
21 struct searchNode
*thenode
;
24 if (!(localdata
= (struct gt_localdata
*)malloc(sizeof(struct gt_localdata
)))) {
25 parseError
= "malloc: could not allocate memory for this search.";
28 if (!(localdata
->nodes
= (struct searchNode
**)malloc(sizeof(struct searchNode
*) * argc
))) {
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 if (!(thenode
= (struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
37 /* couldn't malloc() memory for thenode, so free localdata and localdata->nodes to avoid leakage */
38 parseError
= "malloc: could not allocate memory for this search.";
39 free(localdata
->nodes
);
44 thenode
->localdata
= localdata
;
45 thenode
->returntype
= RETURNTYPE_BOOL
;
46 thenode
->exe
= gt_exe
;
47 thenode
->free
= gt_free
;
49 for (i
=0;i
<argc
;i
++) {
50 if (!(localdata
->nodes
[i
] = search_parse(type
, argv
[i
]))) {
60 void gt_free(struct searchNode
*thenode
) {
61 struct gt_localdata
*localdata
;
64 localdata
=thenode
->localdata
;
66 for (i
=0;i
<localdata
->count
;i
++) {
67 (localdata
->nodes
[i
]->free
)(localdata
->nodes
[i
]);
70 free(localdata
->nodes
);
75 void *gt_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
79 struct gt_localdata
*localdata
;
81 localdata
=thenode
->localdata
;
83 if (localdata
->count
==0)
86 switch (localdata
->nodes
[0]->returntype
& RETURNTYPE_TYPE
) {
88 intval
= (int)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_INT
, theinput
);
89 for (i
=1;i
<localdata
->count
;i
++) {
90 if ((int)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_INT
, theinput
) > intval
)
91 return falseval(type
);
96 case RETURNTYPE_STRING
:
97 strval
= (char *)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_STRING
, theinput
);
98 for (i
=1;i
<localdata
->count
;i
++) {
99 if (ircd_strcmp(strval
, (char *)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_STRING
, theinput
)) > 0)
100 return falseval(type
);
103 return trueval(type
);
106 return falseval(type
);