]>
Commit | Line | Data |
---|---|---|
f1903ace CP |
1 | /* |
2 | * GT functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
4ad1cf7a | 7 | #include "../lib/irc_string.h" |
f1903ace CP |
8 | #include <stdio.h> |
9 | #include <stdlib.h> | |
10 | ||
11 | struct gt_localdata { | |
12 | int count; | |
13 | struct searchNode **nodes; | |
14 | }; | |
15 | ||
16 | void gt_free(struct searchNode *thenode); | |
17 | void *gt_exe(struct searchNode *thenode, int type, void *theinput); | |
18 | ||
19 | struct searchNode *gt_parse(int type, int argc, char **argv) { | |
20 | struct gt_localdata *localdata; | |
21 | struct searchNode *thenode; | |
22 | int i; | |
23 | ||
24 | localdata = (struct gt_localdata *)malloc(sizeof(struct gt_localdata)); | |
25 | localdata->nodes = (struct searchNode **)malloc(sizeof(struct searchNode *) * argc); | |
26 | localdata->count = 0; | |
27 | ||
28 | thenode = (struct searchNode *)malloc(sizeof(struct searchNode)); | |
29 | ||
30 | thenode->localdata = localdata; | |
31 | thenode->returntype = RETURNTYPE_BOOL; | |
32 | thenode->exe = gt_exe; | |
33 | thenode->free = gt_free; | |
34 | ||
35 | for (i=0;i<argc;i++) { | |
36 | if (!(localdata->nodes[i] = search_parse(type, argv[i]))) { | |
37 | gt_free(thenode); | |
38 | return NULL; | |
39 | } | |
40 | localdata->count++; | |
41 | } | |
42 | ||
43 | return thenode; | |
44 | } | |
45 | ||
46 | void gt_free(struct searchNode *thenode) { | |
47 | struct gt_localdata *localdata; | |
48 | int i; | |
49 | ||
50 | localdata=thenode->localdata; | |
51 | ||
52 | for (i=0;i<localdata->count;i++) { | |
53 | (localdata->nodes[i]->free)(localdata->nodes[i]); | |
54 | } | |
55 | ||
56 | free(localdata->nodes); | |
57 | free(localdata); | |
58 | free(thenode); | |
59 | } | |
60 | ||
61 | void *gt_exe(struct searchNode *thenode, int type, void *theinput) { | |
62 | int i; | |
63 | char *strval; | |
64 | int intval; | |
f1903ace CP |
65 | struct gt_localdata *localdata; |
66 | ||
67 | localdata=thenode->localdata; | |
68 | ||
69 | if (localdata->count==0) | |
70 | return trueval(type); | |
71 | ||
72 | switch (localdata->nodes[0]->returntype & RETURNTYPE_TYPE) { | |
73 | case RETURNTYPE_INT: | |
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); | |
78 | } | |
79 | ||
80 | return trueval(type); | |
81 | ||
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); | |
87 | } | |
88 | ||
89 | return trueval(type); | |
90 | ||
91 | default: | |
92 | return falseval(type); | |
93 | } | |
94 | } | |
95 |