]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-not.c
Merged.
[irc/quakenet/newserv.git] / newsearch / ns-not.c
1 /*
2 * NOT functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 void not_free(struct searchNode *thenode);
11 void *not_exe(struct searchNode *thenode, int type, void *theinput);
12
13 struct searchNode *not_parse(int type, int argc, char **argv) {
14 searchNode *thenode, *subnode;
15
16 if (argc!=1) {
17 parseError="not: usage: not (term)";
18 return NULL;
19 }
20
21 /* Allocate our actual node */
22 if (!(thenode=(searchNode *)malloc(sizeof(searchNode)))) {
23 parseError = "malloc: could not allocate memory for this search.";
24 return NULL;
25 }
26
27 thenode->returntype = RETURNTYPE_BOOL;
28 thenode->exe = not_exe;
29 thenode->free = not_free;
30
31 subnode=search_parse(type, argv[0]); /* Propogate the search type */
32
33 if (!subnode) {
34 free(thenode);
35 return NULL;
36 }
37
38 thenode->localdata=(void *)subnode;
39
40 return thenode;
41 }
42
43 void not_free(struct searchNode *thenode) {
44 struct searchNode *subnode;
45 subnode=thenode->localdata;
46
47 (subnode->free)(subnode);
48 free(thenode);
49 }
50
51 void *not_exe(struct searchNode *thenode, int type, void *theinput) {
52 void *ret;
53 struct searchNode *subnode;
54
55 subnode=thenode->localdata;
56
57 ret = (subnode->exe)(subnode, RETURNTYPE_BOOL, theinput);
58
59 switch (type) {
60
61 case RETURNTYPE_INT:
62 case RETURNTYPE_BOOL:
63 if (ret==NULL) {
64 return (void *)1;
65 } else {
66 return NULL;
67 }
68
69 case RETURNTYPE_STRING:
70 if (ret==NULL) {
71 return "1";
72 } else {
73 return "";
74 }
75 }
76
77 return NULL;
78 }