]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-length.c
2 * length functionality - returns the length of a string
7 #include "../lib/irc_string.h"
12 void length_free(searchCtx
*ctx
, struct searchNode
*thenode
);
13 void *length_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
15 struct searchNode
*length_parse(searchCtx
*ctx
, int argc
, char **argv
) {
16 struct searchNode
*thenode
, *childnode
;
18 if (!(thenode
= (struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
19 parseError
= "malloc: could not allocate memory for this search.";
23 thenode
->localdata
= NULL
;
24 thenode
->returntype
= RETURNTYPE_INT
;
25 thenode
->exe
= length_exe
;
26 thenode
->free
= length_free
;
29 parseError
= "length: usage: length <string>";
34 childnode
= ctx
->parser(ctx
, argv
[0]);
35 if (!(thenode
->localdata
= coerceNode(ctx
, childnode
, RETURNTYPE_STRING
))) {
36 length_free(ctx
, thenode
);
43 void length_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
44 struct searchNode
*anode
;
46 if ((anode
=thenode
->localdata
))
47 (anode
->free
)(ctx
, anode
);
52 void *length_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
54 struct searchNode
*anode
=thenode
->localdata
;
56 strval
=(char *)(anode
->exe
)(ctx
, anode
, theinput
);
58 return (void *)strlen(strval
);