diff options
Diffstat (limited to 'apps/plugins/databox/editparser.c')
-rw-r--r-- | apps/plugins/databox/editparser.c | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/apps/plugins/databox/editparser.c b/apps/plugins/databox/editparser.c deleted file mode 100644 index 5ee9ffbd56..0000000000 --- a/apps/plugins/databox/editparser.c +++ /dev/null | |||
@@ -1,205 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Michiel van der Kolk | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "databox.h" | ||
20 | #include "edittoken.h" | ||
21 | #include "editparser.h" | ||
22 | |||
23 | struct token *currenttoken,*lasttoken,*tokenstream; | ||
24 | int currentindex; | ||
25 | int lparencount,acceptedmask; | ||
26 | int tokensleft; | ||
27 | int invalid; | ||
28 | int invalid_mode; | ||
29 | |||
30 | void check_accepted(struct token *tstream, int count) { | ||
31 | parse_stream(tstream,count+1,INVALID_EXPERT); | ||
32 | } | ||
33 | |||
34 | void parse_stream(struct token *tstream, int count, int inv_mode) { | ||
35 | invalid_mode=inv_mode; | ||
36 | acceptedmask=0; | ||
37 | lparencount=0; | ||
38 | tokensleft=count; | ||
39 | currentindex=0; | ||
40 | invalid=0; | ||
41 | tokenstream=tstream; | ||
42 | currenttoken=&tokenstream[currentindex]; | ||
43 | parseMExpr(); | ||
44 | } | ||
45 | |||
46 | int check_tokenstream(struct token *tstream, int inv_mode) { | ||
47 | int inval=0; | ||
48 | int i; | ||
49 | parse_stream(tstream,-1,inv_mode); | ||
50 | inval=invalid; | ||
51 | while( (inv_mode==INVALID_STRIP||inv_mode==INVALID_MARK) && invalid) | ||
52 | parse_stream(tstream,-1,inv_mode); | ||
53 | i=0; | ||
54 | while(tstream[i].kind!=TOKEN_EOF) | ||
55 | if(tstream[i++].kind==TOKEN_INVALID) { | ||
56 | inval=1; | ||
57 | break; | ||
58 | } | ||
59 | return inval==0; | ||
60 | } | ||
61 | |||
62 | |||
63 | void parse_accept_rparen(void) { | ||
64 | if(!tokensleft) return; | ||
65 | if(lparencount) { | ||
66 | acceptedmask|=ACCEPT_RPAREN; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | void parse_accept(int bitmask) { | ||
71 | if(!tokensleft) return; | ||
72 | acceptedmask|=bitmask; | ||
73 | if(lparencount) { | ||
74 | acceptedmask&=~ACCEPT_EOF; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | void parse_checktoken() { | ||
79 | int ok=0; | ||
80 | if(!tokensleft) return; | ||
81 | lasttoken=currenttoken; | ||
82 | switch(lasttoken->kind) { | ||
83 | case TOKEN_EOF: | ||
84 | ok=acceptedmask&ACCEPT_EOF; | ||
85 | break; | ||
86 | case TOKEN_NOT: | ||
87 | ok=acceptedmask&ACCEPT_NOT; | ||
88 | break; | ||
89 | case TOKEN_AND: | ||
90 | case TOKEN_OR: | ||
91 | ok=acceptedmask&ACCEPT_BOOLOP; | ||
92 | break; | ||
93 | case TOKEN_GT: | ||
94 | case TOKEN_GTE: | ||
95 | case TOKEN_LT: | ||
96 | case TOKEN_LTE: | ||
97 | case TOKEN_NE: | ||
98 | case TOKEN_EQ: | ||
99 | ok=acceptedmask&ACCEPT_NUMOP; | ||
100 | break; | ||
101 | case TOKEN_EQUALS: | ||
102 | case TOKEN_CONTAINS: | ||
103 | case TOKEN_STARTSWITH: | ||
104 | case TOKEN_ENDSWITH: | ||
105 | ok=acceptedmask&ACCEPT_STROP; | ||
106 | break; | ||
107 | case TOKEN_STRING: | ||
108 | case TOKEN_STRINGIDENTIFIER: | ||
109 | ok=acceptedmask&ACCEPT_STRARG; | ||
110 | break; | ||
111 | case TOKEN_NUM: | ||
112 | case TOKEN_NUMIDENTIFIER: | ||
113 | ok=acceptedmask&ACCEPT_NUMARG; | ||
114 | break; | ||
115 | case TOKEN_LPAREN: | ||
116 | ok=acceptedmask&ACCEPT_LPAREN; | ||
117 | if(ok) lparencount++; | ||
118 | break; | ||
119 | case TOKEN_RPAREN: | ||
120 | ok=acceptedmask&ACCEPT_RPAREN; | ||
121 | if(ok) lparencount--; | ||
122 | break; | ||
123 | case TOKEN_INVALID: | ||
124 | if(invalid_mode!=INVALID_STRIP) | ||
125 | ok=1; | ||
126 | break; | ||
127 | } | ||
128 | tokensleft--; | ||
129 | if(lasttoken->kind==TOKEN_EOF) | ||
130 | tokensleft=0; | ||
131 | if(!ok&&tokensleft) { | ||
132 | // delete token | ||
133 | int i=currentindex; | ||
134 | //printf("Syntax error. accepted: 0x%x index:%d token: %d %s\n",acceptedmask,currentindex,currenttoken->kind,tokentostring(currenttoken)); | ||
135 | switch (invalid_mode) { | ||
136 | case INVALID_STRIP: | ||
137 | do { | ||
138 | rb->memcpy(currenttoken,&tokenstream[++i],sizeof(struct token));; | ||
139 | currenttoken=&tokenstream[i]; | ||
140 | } while (currenttoken->kind!=TOKEN_EOF); | ||
141 | currenttoken=&tokenstream[currentindex]; | ||
142 | break; | ||
143 | case INVALID_MARK: | ||
144 | currenttoken->kind=TOKEN_INVALID; | ||
145 | break; | ||
146 | } | ||
147 | tokensleft=0; | ||
148 | invalid=1; | ||
149 | } | ||
150 | if(tokensleft) { | ||
151 | currenttoken=&tokenstream[++currentindex]; | ||
152 | acceptedmask=0; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void parseCompareNum() { | ||
157 | parse_accept(ACCEPT_NUMOP); | ||
158 | parse_checktoken(); | ||
159 | parse_accept(ACCEPT_NUMARG); | ||
160 | parse_checktoken(); | ||
161 | } | ||
162 | |||
163 | void parseCompareString() { | ||
164 | parse_accept(ACCEPT_STROP); | ||
165 | parse_checktoken(); | ||
166 | parse_accept(ACCEPT_STRARG); | ||
167 | parse_checktoken(); | ||
168 | } | ||
169 | |||
170 | void parseExpr() { | ||
171 | if(!tokensleft) return; | ||
172 | parse_accept(ACCEPT_NOT|ACCEPT_LPAREN|ACCEPT_NUMARG|ACCEPT_STRARG); | ||
173 | parse_checktoken(); | ||
174 | switch(lasttoken->kind) { | ||
175 | case TOKEN_NOT: | ||
176 | parseExpr(); | ||
177 | break; | ||
178 | case TOKEN_LPAREN: | ||
179 | parseMExpr(); | ||
180 | break; | ||
181 | case TOKEN_NUM: | ||
182 | case TOKEN_NUMIDENTIFIER: | ||
183 | parseCompareNum(); | ||
184 | break; | ||
185 | case TOKEN_STRING: | ||
186 | case TOKEN_STRINGIDENTIFIER: | ||
187 | parseCompareString(); | ||
188 | break; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | void parseMExpr() { | ||
193 | parseExpr(); | ||
194 | parse_accept_rparen(); | ||
195 | parse_accept(ACCEPT_BOOLOP|ACCEPT_EOF); | ||
196 | parse_checktoken(); | ||
197 | while(lasttoken->kind==TOKEN_OR || lasttoken->kind == TOKEN_AND) { | ||
198 | parseExpr(); | ||
199 | parse_accept_rparen(); | ||
200 | parse_accept(ACCEPT_BOOLOP|ACCEPT_EOF); | ||
201 | parse_checktoken(); | ||
202 | if(!tokensleft) | ||
203 | return; | ||
204 | } | ||
205 | } | ||