]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-lt.c
Get rid of ALL WARNINGS!
[irc/quakenet/newserv.git] / newsearch / ns-lt.c
1 /*
2 * GT functionality
3 */
4
5 #include "newsearch.h"
6 #include "../lib/irc_string.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 struct lt_localdata {
12 int count;
13 struct searchNode **nodes;
14 };
15
16 void lt_free(struct searchNode *thenode);
17 void *lt_exe(struct searchNode *thenode, int type, void *theinput);
18
19 struct searchNode *lt_parse(int type, int argc, char **argv) {
20 struct lt_localdata *localdata;
21 struct searchNode *thenode;
22 int i;
23
24 localdata = (struct lt_localdata *)malloc(sizeof(struct lt_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 = lt_exe;
33 thenode->free = lt_free;
34
35 for (i=0;i<argc;i++) {
36 if (!(localdata->nodes[i] = search_parse(type, argv[i]))) {
37 lt_free(thenode);
38 return NULL;
39 }
40 localdata->count++;
41 }
42
43 return thenode;
44 }
45
46 void lt_free(struct searchNode *thenode) {
47 struct lt_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 *lt_exe(struct searchNode *thenode, int type, void *theinput) {
62 int i;
63 char *strval;
64 int intval;
65 struct lt_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