]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-not.c
Refactor the execution functions in nicksearch.
[irc/quakenet/newserv.git] / newsearch / ns-not.c
CommitLineData
c86edd1d
Q
1/*
2 * NOT functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
10void not_free(struct searchNode *thenode);
c7f7a584 11void *not_exe(struct searchNode *thenode, void *theinput);
c86edd1d
Q
12
13struct 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 */
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
31 subnode=search_parse(type, argv[0]); /* Propogate the search type */
32
33 if (!subnode) {
34 free(thenode);
35 return NULL;
36 }
37
c7f7a584 38 /* Our subnode needs to return a BOOL */
6fe7577e 39 subnode=coerceNode(subnode, RETURNTYPE_BOOL);
c7f7a584 40
c86edd1d
Q
41 thenode->localdata=(void *)subnode;
42
43 return thenode;
44}
45
46void not_free(struct searchNode *thenode) {
47 struct searchNode *subnode;
48 subnode=thenode->localdata;
49
50 (subnode->free)(subnode);
51 free(thenode);
52}
53
c7f7a584 54void *not_exe(struct searchNode *thenode, void *theinput) {
c86edd1d
Q
55 struct searchNode *subnode;
56
57 subnode=thenode->localdata;
58
c7f7a584 59 if ((subnode->exe)(subnode, theinput)) {
60 return (void *)0;
61 } else {
62 return (void *)1;
c86edd1d 63 }
c86edd1d 64}