]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include "newsearch.h" | |
3 | #include "parser.h" | |
4 | ||
5 | struct yy_buffer_state; | |
6 | ||
7 | struct yy_buffer_state *yy_scan_string(const char *); | |
8 | void yy_delete_buffer(struct yy_buffer_state *); | |
9 | void yy_flush_buffer(struct yy_buffer_state *); | |
10 | ||
11 | int yyparse(void); | |
12 | char *parseStrError; | |
13 | int parseStrErrorPos; | |
14 | ||
15 | parseFunc fnfinder(char *name, void *arg) { | |
16 | searchCmd *cmdtree = arg; | |
17 | struct Command *cmd; | |
18 | parseFunc ret; | |
19 | ||
20 | if (!(cmd=findcommandintree(cmdtree->searchtree, name, 1))) { | |
21 | parseError = "Unknown command (for valid command list, see help <searchcmd>)"; | |
22 | return NULL; | |
23 | } | |
24 | ret = (parseFunc)cmd->handler; | |
25 | /* TODO */ | |
26 | ||
27 | /* | |
28 | if (!controlpermitted(ret->level, ret->sender)) { | |
29 | parseError = "Access denied (for valid command list, see help <searchcmd>)"; | |
30 | return NULL; | |
31 | } | |
32 | return ((parseFunc)cmd->handler)(ctx, j, argvector+1); | |
33 | }*/ | |
34 | ||
35 | return ret; | |
36 | } | |
37 | ||
38 | parsertree *parse_string(searchCmd *cmd, const char *str) { | |
39 | int ret; | |
40 | struct yy_buffer_state *b; | |
41 | parsertree *pt; | |
42 | ||
43 | b = yy_scan_string(str); | |
44 | if(!b) { | |
45 | parseStrError = "string buffer creation error"; | |
46 | return NULL; | |
47 | } | |
48 | ||
49 | resetparser(fnfinder, cmd, &pt); | |
50 | ret = yyparse(); | |
51 | ||
52 | yy_flush_buffer(b); | |
53 | yy_delete_buffer(b); | |
54 | ||
55 | if(ret) /* error occured, parseStrError has it */ | |
56 | return NULL; | |
57 | ||
58 | parseStrError = "BUG: you shouldn't ever see this"; | |
59 | return pt; | |
60 | } | |
61 | ||
62 | void parse_free(parsertree *pt) { | |
63 | stringlist *sl, *nsl; | |
64 | expressionlist *xl, *nxl; | |
65 | ||
66 | for(sl=pt->strlist;sl;sl=nsl) { | |
67 | nsl = sl->next; | |
68 | freesstring(sl->data); | |
69 | free(sl); | |
70 | } | |
71 | ||
72 | for(xl=pt->exprlist;xl;xl=nxl) { | |
73 | nxl = xl->next; | |
74 | free(xl); | |
75 | } | |
76 | ||
77 | if(pt->finished) | |
78 | free(pt); | |
79 | } |