]>
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 localdata
= (struct gt_localdata
*)malloc(sizeof(struct gt_localdata
));
25 localdata
->nodes
= (struct searchNode
**)malloc(sizeof(struct searchNode
*) * argc
);
28 thenode
= (struct searchNode
*)malloc(sizeof(struct searchNode
));
30 thenode
->localdata
= localdata
;
31 thenode
->returntype
= RETURNTYPE_BOOL
;
32 thenode
->exe
= gt_exe
;
33 thenode
->free
= gt_free
;
35 for (i
=0;i
<argc
;i
++) {
36 if (!(localdata
->nodes
[i
] = search_parse(type
, argv
[i
]))) {
46 void gt_free(struct searchNode
*thenode
) {
47 struct gt_localdata
*localdata
;
50 localdata
=thenode
->localdata
;
52 for (i
=0;i
<localdata
->count
;i
++) {
53 (localdata
->nodes
[i
]->free
)(localdata
->nodes
[i
]);
56 free(localdata
->nodes
);
61 void *gt_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
65 struct gt_localdata
*localdata
;
67 localdata
=thenode
->localdata
;
69 if (localdata
->count
==0)
72 switch (localdata
->nodes
[0]->returntype
& RETURNTYPE_TYPE
) {
74 intval
= (int)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_INT
, theinput
);
75 for (i
=1;i
<localdata
->count
;i
++) {
76 if ((int)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_INT
, theinput
) > intval
)
77 return falseval(type
);
82 case RETURNTYPE_STRING
:
83 strval
= (char *)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_STRING
, theinput
);
84 for (i
=1;i
<localdata
->count
;i
++) {
85 if (ircd_strcmp(strval
, (char *)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_STRING
, theinput
)) > 0)
86 return falseval(type
);
92 return falseval(type
);