]>
Commit | Line | Data |
---|---|---|
b697c21c CP |
1 | /* |
2 | * AND functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | ||
10 | #define MAX_CHANS 500 | |
11 | ||
12 | void channeliter_free(searchCtx *ctx, struct searchNode *thenode); | |
13 | void *channeliter_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
14 | ||
15 | struct channeliter_localdata { | |
16 | int currentchannel; | |
17 | struct searchVariable *variable; | |
18 | nick *lastnick; | |
19 | }; | |
20 | ||
f33f3f52 | 21 | struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv) { |
b697c21c CP |
22 | searchNode *thenode; |
23 | struct channeliter_localdata *localdata; | |
24 | ||
25 | if(argc < 1) { | |
26 | parseError = "channeliter: usage: channeliter variable"; | |
27 | return NULL; | |
28 | } | |
29 | ||
b697c21c CP |
30 | if(!(localdata=(struct channeliter_localdata *)malloc(sizeof(struct channeliter_localdata)))) { |
31 | parseError = "malloc: could not allocate memory for this search."; | |
32 | return NULL; | |
33 | } | |
34 | ||
f33f3f52 | 35 | if(!(localdata->variable=var_register(ctx, argv[0], RETURNTYPE_STRING))) { |
b697c21c CP |
36 | free(localdata); |
37 | return NULL; | |
38 | } | |
39 | ||
40 | if(!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) { | |
41 | parseError = "malloc: could not allocate memory for this search."; | |
42 | free(localdata); | |
43 | return NULL; | |
44 | } | |
45 | ||
46 | localdata->currentchannel = 0; | |
47 | localdata->lastnick = NULL; | |
48 | ||
49 | thenode->returntype = RETURNTYPE_BOOL; | |
50 | thenode->localdata = localdata; | |
51 | thenode->exe = channeliter_exe; | |
52 | thenode->free = channeliter_free; | |
53 | ||
54 | return thenode; | |
55 | } | |
56 | ||
57 | void channeliter_free(searchCtx *ctx, struct searchNode *thenode) { | |
58 | free(thenode->localdata); | |
59 | free(thenode); | |
60 | } | |
61 | ||
62 | void *channeliter_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { | |
63 | struct channeliter_localdata *localdata = thenode->localdata; | |
64 | nick *np = (nick *)theinput; | |
65 | ||
66 | if(np != localdata->lastnick) { | |
67 | localdata->lastnick = np; | |
68 | localdata->currentchannel = 0; | |
69 | } | |
70 | ||
71 | if(np->channels->cursi > MAX_CHANS) | |
72 | return (void *)0; | |
73 | ||
74 | if(localdata->currentchannel >= np->channels->cursi) | |
75 | return (void *)0; | |
76 | ||
77 | var_setstr(localdata->variable, ((channel **)np->channels->content)[localdata->currentchannel++]->index->name->content); | |
78 | ||
79 | return (void *)1; | |
80 | } |