Read searchquery from a search "file" (search tokenstream)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6372 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/database.h b/apps/database.h
index 3828257..facfb53 100644
--- a/apps/database.h
+++ b/apps/database.h
@@ -19,18 +19,15 @@
#ifndef DATABASE_H
#define DATABASE_H
-/* workaround for cygwin not defining endian macros */
-#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && defined(_X86_)
-#define LITTLE_ENDIAN
-#endif
-
-#ifdef LITTLE_ENDIAN
+#ifdef ROCKBOX_LITTLE_ENDIAN
#define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \
- ((_x_ & 0x00ff0000) >> 8) | \
- ((_x_ & 0x0000ff00) << 8) | \
- ((_x_ & 0x000000ff) << 24))
+ ((_x_ & 0x00ff0000) >> 8) | \
+ ((_x_ & 0x0000ff00) << 8) | \
+ ((_x_ & 0x000000ff) << 24))
+#define BE16(_x_) ( ((_x_&0xFF00) >> 8)|((_x_&0xFF)<<8))
#else
#define BE32(_x_) _x_
+#define BE16(_x_) _x_
#endif
#define SONGENTRY_SIZE (tagdbheader.songlen+12+tagdbheader.genrelen+4)
diff --git a/apps/plugins/searchengine/parser.c b/apps/plugins/searchengine/parser.c
index 501450c..cbedeb3 100644
--- a/apps/plugins/searchengine/parser.c
+++ b/apps/plugins/searchengine/parser.c
@@ -21,18 +21,18 @@
#include "dbinterface.h"
#include "parser.h"
-struct token *tokenbuffer,*currentToken;
-int currentindex;
+struct token *currentToken, curtoken;
int syntaxerror;
+int parse_fd;
char errormsg[250];
-unsigned char *parse(struct token *tokenbuf) {
+unsigned char *parse(int fd) {
unsigned char *ret=0;
- currentindex=0;
syntaxerror=0;
- tokenbuffer=tokenbuf;
+ parse_fd=fd;
database_init();
- currentToken=&tokenbuffer[currentindex];
+ parser_acceptIt();
+ currentToken=&curtoken;
PUTS("parse");
ret=parseMExpr();
if(syntaxerror) {
@@ -45,7 +45,7 @@
void parser_acceptIt(void) {
if(syntaxerror) return;
- currentToken=&tokenbuffer[++currentindex];
+ rb->read(parse_fd,&curtoken,sizeof(struct token));
}
int parser_accept(unsigned char kind) {
@@ -61,7 +61,7 @@
}
unsigned char *parseCompareNum() {
- struct token *number1,*number2;
+ struct token number1,number2;
unsigned char *ret;
int i,n1=-1,n2=-1;
int op;
@@ -69,7 +69,7 @@
PUTS("parseCompareNum");
if(currentToken->kind==TOKEN_NUM ||
currentToken->kind==TOKEN_NUMIDENTIFIER) {
- number1=currentToken;
+ rb->memcpy(&number1,currentToken,sizeof(struct token));
parser_acceptIt();
}
else {
@@ -88,7 +88,7 @@
}
if(currentToken->kind==TOKEN_NUM ||
currentToken->kind==TOKEN_NUMIDENTIFIER) {
- number2=currentToken;
+ rb->memcpy(&number2,currentToken,sizeof(struct token));
parser_acceptIt();
}
else {
@@ -97,16 +97,16 @@
return 0;
}
ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
- if(number1->kind==TOKEN_NUM)
- n1=getvalue(number1);
- if(number2->kind==TOKEN_NUM)
- n2=getvalue(number2);
+ if(number1.kind==TOKEN_NUM)
+ n1=getvalue(&number1);
+ if(number2.kind==TOKEN_NUM)
+ n2=getvalue(&number2);
for(i=0;i<rb->tagdbheader->filecount;i++) {
loadentry(i);
- if(number1->kind==TOKEN_NUMIDENTIFIER)
- n1=getvalue(number1);
- if(number2->kind==TOKEN_NUMIDENTIFIER)
- n2=getvalue(number2);
+ if(number1.kind==TOKEN_NUMIDENTIFIER)
+ n1=getvalue(&number1);
+ if(number2.kind==TOKEN_NUMIDENTIFIER)
+ n2=getvalue(&number2);
switch(op) {
case TOKEN_GT:
ret[i]=n1 > n2;
@@ -132,7 +132,7 @@
}
unsigned char *parseCompareString() {
- struct token *string1,*string2;
+ struct token string1,string2;
unsigned char *ret;
char *s1=NULL,*s2=NULL;
int i,contains;
@@ -140,7 +140,7 @@
PUTS("parseCompareString");
if(currentToken->kind==TOKEN_STRING ||
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
- string1=currentToken;
+ rb->memcpy(&string1,currentToken,sizeof(struct token));
parser_acceptIt();
}
else {
@@ -161,7 +161,7 @@
if(currentToken->kind==TOKEN_STRING ||
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
- string2=currentToken;
+ rb->memcpy(&string2,currentToken,sizeof(struct token));
parser_acceptIt();
}
else {
@@ -170,16 +170,16 @@
return 0;
}
ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
- if(string1->kind==TOKEN_STRING)
- s1=getstring(string1);
- if(string2->kind==TOKEN_STRING)
- s2=getstring(string2);
+ if(string1.kind==TOKEN_STRING)
+ s1=getstring(&string1);
+ if(string2.kind==TOKEN_STRING)
+ s2=getstring(&string2);
for(i=0;i<rb->tagdbheader->filecount;i++) {
loadentry(i);
- if(string1->kind==TOKEN_STRINGIDENTIFIER)
- s1=getstring(string1);
- if(string2->kind==TOKEN_STRINGIDENTIFIER)
- s2=getstring(string2);
+ if(string1.kind==TOKEN_STRINGIDENTIFIER)
+ s1=getstring(&string1);
+ if(string2.kind==TOKEN_STRINGIDENTIFIER)
+ s2=getstring(&string2);
if(contains)
ret[i]=rb->strcasestr(s1,s2)!=0;
else
diff --git a/apps/plugins/searchengine/parser.h b/apps/plugins/searchengine/parser.h
index e9c36d3..b40a6ae 100644
--- a/apps/plugins/searchengine/parser.h
+++ b/apps/plugins/searchengine/parser.h
@@ -16,12 +16,11 @@
* KIND, either express or implied.
*
****************************************************************************/
-extern struct token *tokenbuffer,*currentToken;
-
+extern struct token *currentToken;
extern int syntaxerror;
extern char errormsg[250];
-unsigned char *parse(struct token *tokenbuf);
+unsigned char *parse(int fd);
void parser_acceptIt(void);
int parser_accept(unsigned char kind);
unsigned char *parseCompareNum(void);
diff --git a/apps/plugins/searchengine/searchengine.c b/apps/plugins/searchengine/searchengine.c
index 5065da7..0cb090e 100644
--- a/apps/plugins/searchengine/searchengine.c
+++ b/apps/plugins/searchengine/searchengine.c
@@ -50,19 +50,16 @@
audio_buffer_free = audio_bufferpointer - audio_bufferbase;
}
-struct token tokenstream[10];
-
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
unsigned char *result,buf[500];
+ int parsefd;
/* this macro should be called as the first thing you do in the plugin.
it test that the api version and model the plugin was compiled for
matches the machine it is running on */
TEST_PLUGIN_API(api);
- (void)parameter;
-
/* if you are using a global api pointer, don't forget to copy it!
otherwise you will get lovely "I04: IllInstr" errors... :-) */
rb = api;
@@ -72,21 +69,15 @@
/* now go ahead and have fun! */
PUTS("SearchEngine v0.1");
- tokenstream[0].kind=TOKEN_NUMIDENTIFIER;
- tokenstream[0].intvalue=INTVALUE_YEAR;
- tokenstream[1].kind=TOKEN_GTE;
- tokenstream[2].kind=TOKEN_NUM;
- tokenstream[2].intvalue=1980;
- tokenstream[3].kind=TOKEN_AND;
- tokenstream[4].kind=TOKEN_NUMIDENTIFIER;
- tokenstream[4].intvalue=INTVALUE_YEAR;
- tokenstream[5].kind=TOKEN_LT;
- tokenstream[6].kind=TOKEN_NUM;
- tokenstream[6].intvalue=1990;
- tokenstream[7].kind=TOKEN_EOF;
- result=parse(tokenstream);
+ parsefd=rb->open(parameter,O_RDONLY);
+ if(parsefd<0) {
+ rb->splash(2*HZ,true,"Unable to open search tokenstream");
+ return PLUGIN_ERROR;
+ }
+ result=parse(parsefd);
rb->snprintf(buf,250,"Retval: 0x%x",result);
PUTS(buf);
+ rb->close(parsefd);
if(result!=0) {
int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
int i;