]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-eq.c
6 #include "../lib/irc_string.h"
13 struct searchNode
**nodes
;
16 void eq_free(struct searchNode
*thenode
);
17 void *eq_exe(struct searchNode
*thenode
, int type
, void *theinput
);
19 struct searchNode
*eq_parse(int type
, int argc
, char **argv
) {
20 struct eq_localdata
*localdata
;
21 struct searchNode
*thenode
;
24 if (!(localdata
= (struct eq_localdata
*)malloc(sizeof(struct eq_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
= eq_exe
;
47 thenode
->free
= eq_free
;
49 for (i
=0;i
<argc
;i
++) {
50 if (!(localdata
->nodes
[i
] = search_parse(type
, argv
[i
]))) {
60 void eq_free(struct searchNode
*thenode
) {
61 struct eq_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 *eq_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
80 struct eq_localdata
*localdata
;
82 localdata
=thenode
->localdata
;
84 if (localdata
->count
==0)
87 switch (localdata
->nodes
[0]->returntype
& RETURNTYPE_TYPE
) {
89 intval
= (int)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_INT
, theinput
);
90 for (i
=1;i
<localdata
->count
;i
++) {
91 if ((int)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_INT
, theinput
) != intval
)
92 return falseval(type
);
98 intval
= (int)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_BOOL
, theinput
);
99 for (i
=1;i
<localdata
->count
;i
++) {
100 rval
=(int)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_BOOL
, theinput
);
101 if ((rval
&& !intval
) || (!rval
&& intval
)) { /* LOGICAL XOR GOES HERE FS */
102 return falseval(type
);
106 return trueval(type
);
108 case RETURNTYPE_STRING
:
109 strval
= (char *)(localdata
->nodes
[0]->exe
)(localdata
->nodes
[0], RETURNTYPE_STRING
, theinput
);
110 for (i
=1;i
<localdata
->count
;i
++) {
111 if (ircd_strcmp(strval
, (char *)(localdata
->nodes
[i
]->exe
)(localdata
->nodes
[i
], RETURNTYPE_STRING
, theinput
)))
112 return falseval(type
);
115 return trueval(type
);
118 return falseval(type
);