]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-match.c
10 struct match_localdata
{
11 struct searchNode
*targnode
;
12 struct searchNode
*patnode
;
15 void *match_exe(struct searchNode
*thenode
, int type
, void *theinput
);
16 void match_free(struct searchNode
*thenode
);
18 struct searchNode
*match_parse(int type
, int argc
, char **argv
) {
19 struct match_localdata
*localdata
;
20 struct searchNode
*thenode
;
21 struct searchNode
*targnode
, *patnode
;
24 parseError
="match: usage: match source pattern";
28 if (!(targnode
= search_parse(type
, argv
[0])))
31 if (!(patnode
= search_parse(type
, argv
[1]))) {
32 (targnode
->free
)(targnode
);
36 localdata
=(struct match_localdata
*)malloc(sizeof (struct match_localdata
));
38 localdata
->targnode
=targnode
;
39 localdata
->patnode
=patnode
;
41 thenode
= (struct searchNode
*)malloc(sizeof (struct searchNode
));
43 thenode
->returntype
= RETURNTYPE_BOOL
;
44 thenode
->localdata
= localdata
;
45 thenode
->exe
= match_exe
;
46 thenode
->free
= match_free
;
51 void *match_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
52 struct match_localdata
*localdata
;
53 char *pattern
, *target
;
56 localdata
= thenode
->localdata
;
58 pattern
= (char *)(localdata
->patnode
->exe
) (localdata
->patnode
, RETURNTYPE_STRING
, theinput
);
59 target
= (char *)(localdata
->targnode
->exe
)(localdata
->targnode
,RETURNTYPE_STRING
, theinput
);
61 ret
= match2strings(pattern
, target
);
69 case RETURNTYPE_STRING
:
70 return (ret
? "1" : "");
74 void match_free(struct searchNode
*thenode
) {
75 struct match_localdata
*localdata
;
77 localdata
=thenode
->localdata
;
79 (localdata
->patnode
->free
)(localdata
->patnode
);
80 (localdata
->targnode
->free
)(localdata
->targnode
);