summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-04-28 14:48:12 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-04-28 14:48:12 +0000
commit29909a341aa5b829b80472fe4a726120f2a6f514 (patch)
treecd4fd91ae658b5c6bdd8b8c156eb27244b92bc74
parent9ceac0a293b22e71dc534a89751f7c4be8b1a0cb (diff)
downloadrockbox-29909a341aa5b829b80472fe4a726120f2a6f514.tar.gz
rockbox-29909a341aa5b829b80472fe4a726120f2a6f514.zip
Read searchquery from a search "file" (search tokenstream)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6372 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/database.h15
-rw-r--r--apps/plugins/searchengine/parser.c58
-rw-r--r--apps/plugins/searchengine/parser.h5
-rw-r--r--apps/plugins/searchengine/searchengine.c25
4 files changed, 45 insertions, 58 deletions
diff --git a/apps/database.h b/apps/database.h
index 3828257811..facfb5338e 100644
--- a/apps/database.h
+++ b/apps/database.h
@@ -19,18 +19,15 @@
19#ifndef DATABASE_H 19#ifndef DATABASE_H
20#define DATABASE_H 20#define DATABASE_H
21 21
22/* workaround for cygwin not defining endian macros */ 22#ifdef ROCKBOX_LITTLE_ENDIAN
23#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && defined(_X86_)
24#define LITTLE_ENDIAN
25#endif
26
27#ifdef LITTLE_ENDIAN
28#define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \ 23#define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \
29 ((_x_ & 0x00ff0000) >> 8) | \ 24 ((_x_ & 0x00ff0000) >> 8) | \
30 ((_x_ & 0x0000ff00) << 8) | \ 25 ((_x_ & 0x0000ff00) << 8) | \
31 ((_x_ & 0x000000ff) << 24)) 26 ((_x_ & 0x000000ff) << 24))
27#define BE16(_x_) ( ((_x_&0xFF00) >> 8)|((_x_&0xFF)<<8))
32#else 28#else
33#define BE32(_x_) _x_ 29#define BE32(_x_) _x_
30#define BE16(_x_) _x_
34#endif 31#endif
35 32
36#define SONGENTRY_SIZE (tagdbheader.songlen+12+tagdbheader.genrelen+4) 33#define SONGENTRY_SIZE (tagdbheader.songlen+12+tagdbheader.genrelen+4)
diff --git a/apps/plugins/searchengine/parser.c b/apps/plugins/searchengine/parser.c
index 501450c562..cbedeb3041 100644
--- a/apps/plugins/searchengine/parser.c
+++ b/apps/plugins/searchengine/parser.c
@@ -21,18 +21,18 @@
21#include "dbinterface.h" 21#include "dbinterface.h"
22#include "parser.h" 22#include "parser.h"
23 23
24struct token *tokenbuffer,*currentToken; 24struct token *currentToken, curtoken;
25int currentindex;
26int syntaxerror; 25int syntaxerror;
26int parse_fd;
27char errormsg[250]; 27char errormsg[250];
28 28
29unsigned char *parse(struct token *tokenbuf) { 29unsigned char *parse(int fd) {
30 unsigned char *ret=0; 30 unsigned char *ret=0;
31 currentindex=0;
32 syntaxerror=0; 31 syntaxerror=0;
33 tokenbuffer=tokenbuf; 32 parse_fd=fd;
34 database_init(); 33 database_init();
35 currentToken=&tokenbuffer[currentindex]; 34 parser_acceptIt();
35 currentToken=&curtoken;
36 PUTS("parse"); 36 PUTS("parse");
37 ret=parseMExpr(); 37 ret=parseMExpr();
38 if(syntaxerror) { 38 if(syntaxerror) {
@@ -45,7 +45,7 @@ unsigned char *parse(struct token *tokenbuf) {
45 45
46void parser_acceptIt(void) { 46void parser_acceptIt(void) {
47 if(syntaxerror) return; 47 if(syntaxerror) return;
48 currentToken=&tokenbuffer[++currentindex]; 48 rb->read(parse_fd,&curtoken,sizeof(struct token));
49} 49}
50 50
51int parser_accept(unsigned char kind) { 51int parser_accept(unsigned char kind) {
@@ -61,7 +61,7 @@ int parser_accept(unsigned char kind) {
61} 61}
62 62
63unsigned char *parseCompareNum() { 63unsigned char *parseCompareNum() {
64 struct token *number1,*number2; 64 struct token number1,number2;
65 unsigned char *ret; 65 unsigned char *ret;
66 int i,n1=-1,n2=-1; 66 int i,n1=-1,n2=-1;
67 int op; 67 int op;
@@ -69,7 +69,7 @@ unsigned char *parseCompareNum() {
69 PUTS("parseCompareNum"); 69 PUTS("parseCompareNum");
70 if(currentToken->kind==TOKEN_NUM || 70 if(currentToken->kind==TOKEN_NUM ||
71 currentToken->kind==TOKEN_NUMIDENTIFIER) { 71 currentToken->kind==TOKEN_NUMIDENTIFIER) {
72 number1=currentToken; 72 rb->memcpy(&number1,currentToken,sizeof(struct token));
73 parser_acceptIt(); 73 parser_acceptIt();
74 } 74 }
75 else { 75 else {
@@ -88,7 +88,7 @@ unsigned char *parseCompareNum() {
88 } 88 }
89 if(currentToken->kind==TOKEN_NUM || 89 if(currentToken->kind==TOKEN_NUM ||
90 currentToken->kind==TOKEN_NUMIDENTIFIER) { 90 currentToken->kind==TOKEN_NUMIDENTIFIER) {
91 number2=currentToken; 91 rb->memcpy(&number2,currentToken,sizeof(struct token));
92 parser_acceptIt(); 92 parser_acceptIt();
93 } 93 }
94 else { 94 else {
@@ -97,16 +97,16 @@ unsigned char *parseCompareNum() {
97 return 0; 97 return 0;
98 } 98 }
99 ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount); 99 ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
100 if(number1->kind==TOKEN_NUM) 100 if(number1.kind==TOKEN_NUM)
101 n1=getvalue(number1); 101 n1=getvalue(&number1);
102 if(number2->kind==TOKEN_NUM) 102 if(number2.kind==TOKEN_NUM)
103 n2=getvalue(number2); 103 n2=getvalue(&number2);
104 for(i=0;i<rb->tagdbheader->filecount;i++) { 104 for(i=0;i<rb->tagdbheader->filecount;i++) {
105 loadentry(i); 105 loadentry(i);
106 if(number1->kind==TOKEN_NUMIDENTIFIER) 106 if(number1.kind==TOKEN_NUMIDENTIFIER)
107 n1=getvalue(number1); 107 n1=getvalue(&number1);
108 if(number2->kind==TOKEN_NUMIDENTIFIER) 108 if(number2.kind==TOKEN_NUMIDENTIFIER)
109 n2=getvalue(number2); 109 n2=getvalue(&number2);
110 switch(op) { 110 switch(op) {
111 case TOKEN_GT: 111 case TOKEN_GT:
112 ret[i]=n1 > n2; 112 ret[i]=n1 > n2;
@@ -132,7 +132,7 @@ unsigned char *parseCompareNum() {
132} 132}
133 133
134unsigned char *parseCompareString() { 134unsigned char *parseCompareString() {
135 struct token *string1,*string2; 135 struct token string1,string2;
136 unsigned char *ret; 136 unsigned char *ret;
137 char *s1=NULL,*s2=NULL; 137 char *s1=NULL,*s2=NULL;
138 int i,contains; 138 int i,contains;
@@ -140,7 +140,7 @@ unsigned char *parseCompareString() {
140 PUTS("parseCompareString"); 140 PUTS("parseCompareString");
141 if(currentToken->kind==TOKEN_STRING || 141 if(currentToken->kind==TOKEN_STRING ||
142 currentToken->kind==TOKEN_STRINGIDENTIFIER) { 142 currentToken->kind==TOKEN_STRINGIDENTIFIER) {
143 string1=currentToken; 143 rb->memcpy(&string1,currentToken,sizeof(struct token));
144 parser_acceptIt(); 144 parser_acceptIt();
145 } 145 }
146 else { 146 else {
@@ -161,7 +161,7 @@ unsigned char *parseCompareString() {
161 161
162 if(currentToken->kind==TOKEN_STRING || 162 if(currentToken->kind==TOKEN_STRING ||
163 currentToken->kind==TOKEN_STRINGIDENTIFIER) { 163 currentToken->kind==TOKEN_STRINGIDENTIFIER) {
164 string2=currentToken; 164 rb->memcpy(&string2,currentToken,sizeof(struct token));
165 parser_acceptIt(); 165 parser_acceptIt();
166 } 166 }
167 else { 167 else {
@@ -170,16 +170,16 @@ unsigned char *parseCompareString() {
170 return 0; 170 return 0;
171 } 171 }
172 ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount); 172 ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
173 if(string1->kind==TOKEN_STRING) 173 if(string1.kind==TOKEN_STRING)
174 s1=getstring(string1); 174 s1=getstring(&string1);
175 if(string2->kind==TOKEN_STRING) 175 if(string2.kind==TOKEN_STRING)
176 s2=getstring(string2); 176 s2=getstring(&string2);
177 for(i=0;i<rb->tagdbheader->filecount;i++) { 177 for(i=0;i<rb->tagdbheader->filecount;i++) {
178 loadentry(i); 178 loadentry(i);
179 if(string1->kind==TOKEN_STRINGIDENTIFIER) 179 if(string1.kind==TOKEN_STRINGIDENTIFIER)
180 s1=getstring(string1); 180 s1=getstring(&string1);
181 if(string2->kind==TOKEN_STRINGIDENTIFIER) 181 if(string2.kind==TOKEN_STRINGIDENTIFIER)
182 s2=getstring(string2); 182 s2=getstring(&string2);
183 if(contains) 183 if(contains)
184 ret[i]=rb->strcasestr(s1,s2)!=0; 184 ret[i]=rb->strcasestr(s1,s2)!=0;
185 else 185 else
diff --git a/apps/plugins/searchengine/parser.h b/apps/plugins/searchengine/parser.h
index e9c36d3b54..b40a6aee1c 100644
--- a/apps/plugins/searchengine/parser.h
+++ b/apps/plugins/searchengine/parser.h
@@ -16,12 +16,11 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19extern struct token *tokenbuffer,*currentToken; 19extern struct token *currentToken;
20
21extern int syntaxerror; 20extern int syntaxerror;
22extern char errormsg[250]; 21extern char errormsg[250];
23 22
24unsigned char *parse(struct token *tokenbuf); 23unsigned char *parse(int fd);
25void parser_acceptIt(void); 24void parser_acceptIt(void);
26int parser_accept(unsigned char kind); 25int parser_accept(unsigned char kind);
27unsigned char *parseCompareNum(void); 26unsigned char *parseCompareNum(void);
diff --git a/apps/plugins/searchengine/searchengine.c b/apps/plugins/searchengine/searchengine.c
index 5065da7e78..0cb090e141 100644
--- a/apps/plugins/searchengine/searchengine.c
+++ b/apps/plugins/searchengine/searchengine.c
@@ -50,19 +50,16 @@ void setmallocpos(void *pointer)
50 audio_buffer_free = audio_bufferpointer - audio_bufferbase; 50 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
51} 51}
52 52
53struct token tokenstream[10];
54
55/* this is the plugin entry point */ 53/* this is the plugin entry point */
56enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 54enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
57{ 55{
58 unsigned char *result,buf[500]; 56 unsigned char *result,buf[500];
57 int parsefd;
59 /* this macro should be called as the first thing you do in the plugin. 58 /* this macro should be called as the first thing you do in the plugin.
60 it test that the api version and model the plugin was compiled for 59 it test that the api version and model the plugin was compiled for
61 matches the machine it is running on */ 60 matches the machine it is running on */
62 TEST_PLUGIN_API(api); 61 TEST_PLUGIN_API(api);
63 62
64 (void)parameter;
65
66 /* if you are using a global api pointer, don't forget to copy it! 63 /* if you are using a global api pointer, don't forget to copy it!
67 otherwise you will get lovely "I04: IllInstr" errors... :-) */ 64 otherwise you will get lovely "I04: IllInstr" errors... :-) */
68 rb = api; 65 rb = api;
@@ -72,21 +69,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
72 69
73 /* now go ahead and have fun! */ 70 /* now go ahead and have fun! */
74 PUTS("SearchEngine v0.1"); 71 PUTS("SearchEngine v0.1");
75 tokenstream[0].kind=TOKEN_NUMIDENTIFIER; 72 parsefd=rb->open(parameter,O_RDONLY);
76 tokenstream[0].intvalue=INTVALUE_YEAR; 73 if(parsefd<0) {
77 tokenstream[1].kind=TOKEN_GTE; 74 rb->splash(2*HZ,true,"Unable to open search tokenstream");
78 tokenstream[2].kind=TOKEN_NUM; 75 return PLUGIN_ERROR;
79 tokenstream[2].intvalue=1980; 76 }
80 tokenstream[3].kind=TOKEN_AND; 77 result=parse(parsefd);
81 tokenstream[4].kind=TOKEN_NUMIDENTIFIER;
82 tokenstream[4].intvalue=INTVALUE_YEAR;
83 tokenstream[5].kind=TOKEN_LT;
84 tokenstream[6].kind=TOKEN_NUM;
85 tokenstream[6].intvalue=1990;
86 tokenstream[7].kind=TOKEN_EOF;
87 result=parse(tokenstream);
88 rb->snprintf(buf,250,"Retval: 0x%x",result); 78 rb->snprintf(buf,250,"Retval: 0x%x",result);
89 PUTS(buf); 79 PUTS(buf);
80 rb->close(parsefd);
90 if(result!=0) { 81 if(result!=0) {
91 int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC); 82 int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
92 int i; 83 int i;