]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-match.c
6 #include "../lib/irc_string.h"
11 struct match_localdata
{
12 struct searchNode
*targnode
;
13 struct searchNode
*patnode
;
16 void *match_exe(struct searchNode
*thenode
, int type
, void *theinput
);
17 void match_free(struct searchNode
*thenode
);
19 struct searchNode
*match_parse(int type
, int argc
, char **argv
) {
20 struct match_localdata
*localdata
;
21 struct searchNode
*thenode
;
22 struct searchNode
*targnode
, *patnode
;
25 parseError
="match: usage: match source pattern";
29 if (!(targnode
= search_parse(type
, argv
[0])))
32 if (!(patnode
= search_parse(type
, argv
[1]))) {
33 (targnode
->free
)(targnode
);
37 localdata
=(struct match_localdata
*)malloc(sizeof (struct match_localdata
));
39 localdata
->targnode
=targnode
;
40 localdata
->patnode
=patnode
;
42 thenode
= (struct searchNode
*)malloc(sizeof (struct searchNode
));
44 thenode
->returntype
= RETURNTYPE_BOOL
;
45 thenode
->localdata
= localdata
;
46 thenode
->exe
= match_exe
;
47 thenode
->free
= match_free
;
52 void *match_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
53 struct match_localdata
*localdata
;
54 char *pattern
, *target
;
57 localdata
= thenode
->localdata
;
59 pattern
= (char *)(localdata
->patnode
->exe
) (localdata
->patnode
, RETURNTYPE_STRING
, theinput
);
60 target
= (char *)(localdata
->targnode
->exe
)(localdata
->targnode
,RETURNTYPE_STRING
, theinput
);
62 ret
= match2strings(pattern
, target
);
70 case RETURNTYPE_STRING
:
71 return (ret
? "1" : "");
75 void match_free(struct searchNode
*thenode
) {
76 struct match_localdata
*localdata
;
78 localdata
=thenode
->localdata
;
80 (localdata
->patnode
->free
)(localdata
->patnode
);
81 (localdata
->targnode
->free
)(localdata
->targnode
);