]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
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 | thenode=(searchNode *)malloc(sizeof(searchNode)); | |
23 | ||
24 | thenode->returntype = RETURNTYPE_BOOL; | |
25 | thenode->exe = not_exe; | |
26 | thenode->free = not_free; | |
27 | ||
28 | subnode=search_parse(type, argv[0]); /* Propogate the search type */ | |
29 | ||
30 | if (!subnode) { | |
31 | free(thenode); | |
32 | return NULL; | |
33 | } | |
34 | ||
35 | thenode->localdata=(void *)subnode; | |
36 | ||
37 | return thenode; | |
38 | } | |
39 | ||
40 | void not_free(struct searchNode *thenode) { | |
41 | struct searchNode *subnode; | |
42 | subnode=thenode->localdata; | |
43 | ||
44 | (subnode->free)(subnode); | |
45 | free(thenode); | |
46 | } | |
47 | ||
48 | void *not_exe(struct searchNode *thenode, int type, void *theinput) { | |
49 | void *ret; | |
50 | struct searchNode *subnode; | |
51 | ||
52 | subnode=thenode->localdata; | |
53 | ||
54 | ret = (subnode->exe)(subnode, RETURNTYPE_BOOL, theinput); | |
55 | ||
56 | switch (type) { | |
57 | ||
58 | case RETURNTYPE_INT: | |
59 | case RETURNTYPE_BOOL: | |
60 | if (ret==NULL) { | |
61 | return (void *)1; | |
62 | } else { | |
63 | return NULL; | |
64 | } | |
65 | ||
66 | case RETURNTYPE_STRING: | |
67 | if (ret==NULL) { | |
68 | return "1"; | |
69 | } else { | |
70 | return ""; | |
71 | } | |
72 | } | |
73 | ||
74 | return NULL; | |
75 | } |