]>
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 | ||
c8be5183 CP |
10 | void not_free(searchCtx *ctx, struct searchNode *thenode); |
11 | void *not_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
c86edd1d | 12 | |
f33f3f52 | 13 | struct searchNode *not_parse(searchCtx *ctx, int argc, char **argv) { |
c86edd1d Q |
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 */ | |
9ce4f0be IB |
22 | if (!(thenode=(searchNode *)malloc(sizeof(searchNode)))) { |
23 | parseError = "malloc: could not allocate memory for this search."; | |
24 | return NULL; | |
25 | } | |
c86edd1d Q |
26 | |
27 | thenode->returntype = RETURNTYPE_BOOL; | |
28 | thenode->exe = not_exe; | |
29 | thenode->free = not_free; | |
30 | ||
f33f3f52 | 31 | subnode=ctx->parser(ctx, argv[0]); /* Propogate the search type */ |
c86edd1d Q |
32 | |
33 | if (!subnode) { | |
34 | free(thenode); | |
35 | return NULL; | |
36 | } | |
37 | ||
c7f7a584 | 38 | /* Our subnode needs to return a BOOL */ |
c8be5183 | 39 | subnode=coerceNode(ctx, subnode, RETURNTYPE_BOOL); |
179f6932 CP |
40 | if(!subnode) { |
41 | free(thenode); | |
42 | return NULL; | |
43 | } | |
44 | ||
c86edd1d Q |
45 | thenode->localdata=(void *)subnode; |
46 | ||
47 | return thenode; | |
48 | } | |
49 | ||
c8be5183 | 50 | void not_free(searchCtx *ctx, struct searchNode *thenode) { |
c86edd1d Q |
51 | struct searchNode *subnode; |
52 | subnode=thenode->localdata; | |
53 | ||
c8be5183 | 54 | (subnode->free)(ctx, subnode); |
c86edd1d Q |
55 | free(thenode); |
56 | } | |
57 | ||
c8be5183 | 58 | void *not_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
c86edd1d Q |
59 | struct searchNode *subnode; |
60 | ||
61 | subnode=thenode->localdata; | |
62 | ||
c8be5183 | 63 | if ((subnode->exe)(ctx, subnode, theinput)) { |
c7f7a584 | 64 | return (void *)0; |
65 | } else { | |
66 | return (void *)1; | |
c86edd1d | 67 | } |
c86edd1d | 68 | } |