diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-04-28 21:28:42 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-04-28 21:28:42 +0000 |
commit | 388d9ff6a3229149c4b37f52321d10b460acc382 (patch) | |
tree | 3e3a08d7b823c192baba66869b98f53fd0af8c26 | |
parent | 74875ef37ebe70c1ed54c6eb75cf3cf218dfc212 (diff) | |
download | rockbox-388d9ff6a3229149c4b37f52321d10b460acc382.tar.gz rockbox-388d9ff6a3229149c4b37f52321d10b460acc382.zip |
This should give some optimization when and-ing things....
*hopes he got this right and it won't screw up the search engine*
but thats what cvs is for :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6382 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/searchengine/parser.c | 72 | ||||
-rw-r--r-- | apps/plugins/searchengine/parser.h | 1 |
2 files changed, 50 insertions, 23 deletions
diff --git a/apps/plugins/searchengine/parser.c b/apps/plugins/searchengine/parser.c index 32849b19e3..834c0d4aa1 100644 --- a/apps/plugins/searchengine/parser.c +++ b/apps/plugins/searchengine/parser.c | |||
@@ -22,14 +22,24 @@ | |||
22 | #include "parser.h" | 22 | #include "parser.h" |
23 | 23 | ||
24 | struct token *currentToken, curtoken; | 24 | struct token *currentToken, curtoken; |
25 | unsigned char *filter[20],*nofilter=0; | ||
26 | int currentlevel=0; | ||
25 | int syntaxerror; | 27 | int syntaxerror; |
26 | int parse_fd; | 28 | int parse_fd; |
27 | char errormsg[250]; | 29 | char errormsg[250]; |
28 | 30 | ||
29 | unsigned char *parse(int fd) { | 31 | unsigned char *parse(int fd) { |
30 | unsigned char *ret=0; | 32 | unsigned char *ret=0; |
33 | int i; | ||
31 | syntaxerror=0; | 34 | syntaxerror=0; |
32 | parse_fd=fd; | 35 | parse_fd=fd; |
36 | currentlevel=0; | ||
37 | if(nofilter==0) { | ||
38 | nofilter=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount); | ||
39 | rb->memset(nofilter,1,rb->tagdbheader->filecount); | ||
40 | } | ||
41 | for(i=0;i<20;i++) | ||
42 | filter[i]=nofilter; | ||
33 | database_init(); | 43 | database_init(); |
34 | parser_acceptIt(); | 44 | parser_acceptIt(); |
35 | currentToken=&curtoken; | 45 | currentToken=&curtoken; |
@@ -101,7 +111,8 @@ unsigned char *parseCompareNum() { | |||
101 | n1=getvalue(&number1); | 111 | n1=getvalue(&number1); |
102 | if(number2.kind==TOKEN_NUM) | 112 | if(number2.kind==TOKEN_NUM) |
103 | n2=getvalue(&number2); | 113 | n2=getvalue(&number2); |
104 | for(i=0;i<rb->tagdbheader->filecount;i++) { | 114 | for(i=0;i<rb->tagdbheader->filecount;i++) |
115 | if(filter[currentlevel][i]) { | ||
105 | loadentry(i); | 116 | loadentry(i); |
106 | if(number1.kind==TOKEN_NUMIDENTIFIER) | 117 | if(number1.kind==TOKEN_NUMIDENTIFIER) |
107 | n1=getvalue(&number1); | 118 | n1=getvalue(&number1); |
@@ -182,7 +193,8 @@ unsigned char *parseCompareString() { | |||
182 | s1=getstring(&string1); | 193 | s1=getstring(&string1); |
183 | if(string2.kind==TOKEN_STRING) | 194 | if(string2.kind==TOKEN_STRING) |
184 | s2=getstring(&string2); | 195 | s2=getstring(&string2); |
185 | for(i=0;i<rb->tagdbheader->filecount;i++) { | 196 | for(i=0;i<rb->tagdbheader->filecount;i++) |
197 | if(filter[currentlevel][i]) { | ||
186 | loadentry(i); | 198 | loadentry(i); |
187 | if(string1.kind==TOKEN_STRINGIDENTIFIER) | 199 | if(string1.kind==TOKEN_STRINGIDENTIFIER) |
188 | s1=getstring(&string1); | 200 | s1=getstring(&string1); |
@@ -208,11 +220,14 @@ unsigned char *parseExpr() { | |||
208 | ret = parseExpr(); | 220 | ret = parseExpr(); |
209 | if(ret==NULL) return 0; | 221 | if(ret==NULL) return 0; |
210 | for(i=0;i<rb->tagdbheader->filecount;i++) | 222 | for(i=0;i<rb->tagdbheader->filecount;i++) |
211 | ret[i]=!ret[i]; | 223 | if(filter[currentlevel][i]) |
224 | ret[i]=!ret[i]; | ||
212 | break; | 225 | break; |
213 | case TOKEN_LPAREN: | 226 | case TOKEN_LPAREN: |
214 | parser_accept(TOKEN_LPAREN); | 227 | parser_accept(TOKEN_LPAREN); |
228 | currentlevel++; | ||
215 | ret = parseMExpr(); | 229 | ret = parseMExpr(); |
230 | currentlevel--; | ||
216 | if(ret==NULL) return 0; | 231 | if(ret==NULL) return 0; |
217 | parser_accept(TOKEN_RPAREN); | 232 | parser_accept(TOKEN_RPAREN); |
218 | break; | 233 | break; |
@@ -241,26 +256,37 @@ unsigned char *parseMExpr() { | |||
241 | int i; | 256 | int i; |
242 | if(syntaxerror) return 0; | 257 | if(syntaxerror) return 0; |
243 | PUTS("parseMExpr"); | 258 | PUTS("parseMExpr"); |
244 | ret=parseExpr(); | 259 | ret=parseLExpr(); |
245 | while(currentToken->kind==TOKEN_AND||currentToken->kind==TOKEN_OR) { | 260 | while(currentToken->kind==TOKEN_OR) { |
246 | switch(currentToken->kind) { | 261 | parser_accept(TOKEN_OR); |
247 | case TOKEN_AND: | 262 | PUTS("parseOr"); |
248 | parser_accept(TOKEN_AND); | 263 | ret2 = parseLExpr(); |
249 | PUTS("parseAnd"); | 264 | if(ret2==NULL) return 0; |
250 | ret2 = parseExpr(); | 265 | for(i=0;i<rb->tagdbheader->filecount;i++) |
251 | if(ret2==NULL) return 0; | 266 | if(filter[currentlevel][i]) // this should always be true |
252 | for(i=0;i<rb->tagdbheader->filecount;i++) | 267 | ret[i]=ret[i] || ret2[i]; |
253 | ret[i]=ret[i] && ret2[i]; | 268 | else |
254 | break; | 269 | rb->splash(HZ*2,true,"An or is having a filter, bad."); |
255 | case TOKEN_OR: | ||
256 | parser_accept(TOKEN_OR); | ||
257 | PUTS("parseOr"); | ||
258 | ret2 = parseExpr(); | ||
259 | if(ret2==NULL) return 0; | ||
260 | for(i=0;i<rb->tagdbheader->filecount;i++) | ||
261 | ret[i]=ret[i] || ret2[i]; | ||
262 | break; | ||
263 | } | ||
264 | } | 270 | } |
265 | return ret; | 271 | return ret; |
266 | } | 272 | } |
273 | |||
274 | unsigned char *parseLExpr() { | ||
275 | unsigned char *ret,*ret2; | ||
276 | int i; | ||
277 | if(syntaxerror) return 0; | ||
278 | PUTS("parseLExpr"); | ||
279 | filter[currentlevel]=nofilter; | ||
280 | ret=parseExpr(); | ||
281 | filter[currentlevel]=ret; | ||
282 | while(currentToken->kind==TOKEN_AND) { | ||
283 | parser_accept(TOKEN_AND); | ||
284 | PUTS("parseAnd"); | ||
285 | ret2 = parseExpr(); | ||
286 | if(ret2==NULL) return 0; | ||
287 | for(i=0;i<rb->tagdbheader->filecount;i++) | ||
288 | ret[i]=ret[i] && ret2[i]; | ||
289 | } | ||
290 | filter[currentlevel]=nofilter; | ||
291 | return ret; | ||
292 | } | ||
diff --git a/apps/plugins/searchengine/parser.h b/apps/plugins/searchengine/parser.h index b40a6aee1c..c20dde82e0 100644 --- a/apps/plugins/searchengine/parser.h +++ b/apps/plugins/searchengine/parser.h | |||
@@ -27,3 +27,4 @@ unsigned char *parseCompareNum(void); | |||
27 | unsigned char *parseCompareString(void); | 27 | unsigned char *parseCompareString(void); |
28 | unsigned char *parseExpr(void); | 28 | unsigned char *parseExpr(void); |
29 | unsigned char *parseMExpr(void); | 29 | unsigned char *parseMExpr(void); |
30 | unsigned char *parseLExpr(void); | ||