1
0
Fork 0
forked from len0rd/rockbox

Read searchquery from a search "file" (search tokenstream)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6372 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michiel Van Der Kolk 2005-04-28 14:48:12 +00:00
parent 9ceac0a293
commit 29909a341a
4 changed files with 45 additions and 58 deletions

View file

@ -19,18 +19,15 @@
#ifndef DATABASE_H #ifndef DATABASE_H
#define DATABASE_H #define DATABASE_H
/* workaround for cygwin not defining endian macros */ #ifdef ROCKBOX_LITTLE_ENDIAN
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) && defined(_X86_)
#define LITTLE_ENDIAN
#endif
#ifdef LITTLE_ENDIAN
#define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \ #define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \
((_x_ & 0x00ff0000) >> 8) | \ ((_x_ & 0x00ff0000) >> 8) | \
((_x_ & 0x0000ff00) << 8) | \ ((_x_ & 0x0000ff00) << 8) | \
((_x_ & 0x000000ff) << 24)) ((_x_ & 0x000000ff) << 24))
#define BE16(_x_) ( ((_x_&0xFF00) >> 8)|((_x_&0xFF)<<8))
#else #else
#define BE32(_x_) _x_ #define BE32(_x_) _x_
#define BE16(_x_) _x_
#endif #endif
#define SONGENTRY_SIZE (tagdbheader.songlen+12+tagdbheader.genrelen+4) #define SONGENTRY_SIZE (tagdbheader.songlen+12+tagdbheader.genrelen+4)

View file

@ -21,18 +21,18 @@
#include "dbinterface.h" #include "dbinterface.h"
#include "parser.h" #include "parser.h"
struct token *tokenbuffer,*currentToken; struct token *currentToken, curtoken;
int currentindex;
int syntaxerror; int syntaxerror;
int parse_fd;
char errormsg[250]; char errormsg[250];
unsigned char *parse(struct token *tokenbuf) { unsigned char *parse(int fd) {
unsigned char *ret=0; unsigned char *ret=0;
currentindex=0;
syntaxerror=0; syntaxerror=0;
tokenbuffer=tokenbuf; parse_fd=fd;
database_init(); database_init();
currentToken=&tokenbuffer[currentindex]; parser_acceptIt();
currentToken=&curtoken;
PUTS("parse"); PUTS("parse");
ret=parseMExpr(); ret=parseMExpr();
if(syntaxerror) { if(syntaxerror) {
@ -45,7 +45,7 @@ unsigned char *parse(struct token *tokenbuf) {
void parser_acceptIt(void) { void parser_acceptIt(void) {
if(syntaxerror) return; if(syntaxerror) return;
currentToken=&tokenbuffer[++currentindex]; rb->read(parse_fd,&curtoken,sizeof(struct token));
} }
int parser_accept(unsigned char kind) { int parser_accept(unsigned char kind) {
@ -61,7 +61,7 @@ int parser_accept(unsigned char kind) {
} }
unsigned char *parseCompareNum() { unsigned char *parseCompareNum() {
struct token *number1,*number2; struct token number1,number2;
unsigned char *ret; unsigned char *ret;
int i,n1=-1,n2=-1; int i,n1=-1,n2=-1;
int op; int op;
@ -69,7 +69,7 @@ unsigned char *parseCompareNum() {
PUTS("parseCompareNum"); PUTS("parseCompareNum");
if(currentToken->kind==TOKEN_NUM || if(currentToken->kind==TOKEN_NUM ||
currentToken->kind==TOKEN_NUMIDENTIFIER) { currentToken->kind==TOKEN_NUMIDENTIFIER) {
number1=currentToken; rb->memcpy(&number1,currentToken,sizeof(struct token));
parser_acceptIt(); parser_acceptIt();
} }
else { else {
@ -88,7 +88,7 @@ unsigned char *parseCompareNum() {
} }
if(currentToken->kind==TOKEN_NUM || if(currentToken->kind==TOKEN_NUM ||
currentToken->kind==TOKEN_NUMIDENTIFIER) { currentToken->kind==TOKEN_NUMIDENTIFIER) {
number2=currentToken; rb->memcpy(&number2,currentToken,sizeof(struct token));
parser_acceptIt(); parser_acceptIt();
} }
else { else {
@ -97,16 +97,16 @@ unsigned char *parseCompareNum() {
return 0; return 0;
} }
ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount); ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
if(number1->kind==TOKEN_NUM) if(number1.kind==TOKEN_NUM)
n1=getvalue(number1); n1=getvalue(&number1);
if(number2->kind==TOKEN_NUM) if(number2.kind==TOKEN_NUM)
n2=getvalue(number2); n2=getvalue(&number2);
for(i=0;i<rb->tagdbheader->filecount;i++) { for(i=0;i<rb->tagdbheader->filecount;i++) {
loadentry(i); loadentry(i);
if(number1->kind==TOKEN_NUMIDENTIFIER) if(number1.kind==TOKEN_NUMIDENTIFIER)
n1=getvalue(number1); n1=getvalue(&number1);
if(number2->kind==TOKEN_NUMIDENTIFIER) if(number2.kind==TOKEN_NUMIDENTIFIER)
n2=getvalue(number2); n2=getvalue(&number2);
switch(op) { switch(op) {
case TOKEN_GT: case TOKEN_GT:
ret[i]=n1 > n2; ret[i]=n1 > n2;
@ -132,7 +132,7 @@ unsigned char *parseCompareNum() {
} }
unsigned char *parseCompareString() { unsigned char *parseCompareString() {
struct token *string1,*string2; struct token string1,string2;
unsigned char *ret; unsigned char *ret;
char *s1=NULL,*s2=NULL; char *s1=NULL,*s2=NULL;
int i,contains; int i,contains;
@ -140,7 +140,7 @@ unsigned char *parseCompareString() {
PUTS("parseCompareString"); PUTS("parseCompareString");
if(currentToken->kind==TOKEN_STRING || if(currentToken->kind==TOKEN_STRING ||
currentToken->kind==TOKEN_STRINGIDENTIFIER) { currentToken->kind==TOKEN_STRINGIDENTIFIER) {
string1=currentToken; rb->memcpy(&string1,currentToken,sizeof(struct token));
parser_acceptIt(); parser_acceptIt();
} }
else { else {
@ -161,7 +161,7 @@ unsigned char *parseCompareString() {
if(currentToken->kind==TOKEN_STRING || if(currentToken->kind==TOKEN_STRING ||
currentToken->kind==TOKEN_STRINGIDENTIFIER) { currentToken->kind==TOKEN_STRINGIDENTIFIER) {
string2=currentToken; rb->memcpy(&string2,currentToken,sizeof(struct token));
parser_acceptIt(); parser_acceptIt();
} }
else { else {
@ -170,16 +170,16 @@ unsigned char *parseCompareString() {
return 0; return 0;
} }
ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount); ret=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
if(string1->kind==TOKEN_STRING) if(string1.kind==TOKEN_STRING)
s1=getstring(string1); s1=getstring(&string1);
if(string2->kind==TOKEN_STRING) if(string2.kind==TOKEN_STRING)
s2=getstring(string2); s2=getstring(&string2);
for(i=0;i<rb->tagdbheader->filecount;i++) { for(i=0;i<rb->tagdbheader->filecount;i++) {
loadentry(i); loadentry(i);
if(string1->kind==TOKEN_STRINGIDENTIFIER) if(string1.kind==TOKEN_STRINGIDENTIFIER)
s1=getstring(string1); s1=getstring(&string1);
if(string2->kind==TOKEN_STRINGIDENTIFIER) if(string2.kind==TOKEN_STRINGIDENTIFIER)
s2=getstring(string2); s2=getstring(&string2);
if(contains) if(contains)
ret[i]=rb->strcasestr(s1,s2)!=0; ret[i]=rb->strcasestr(s1,s2)!=0;
else else

View file

@ -16,12 +16,11 @@
* KIND, either express or implied. * KIND, either express or implied.
* *
****************************************************************************/ ****************************************************************************/
extern struct token *tokenbuffer,*currentToken; extern struct token *currentToken;
extern int syntaxerror; extern int syntaxerror;
extern char errormsg[250]; extern char errormsg[250];
unsigned char *parse(struct token *tokenbuf); unsigned char *parse(int fd);
void parser_acceptIt(void); void parser_acceptIt(void);
int parser_accept(unsigned char kind); int parser_accept(unsigned char kind);
unsigned char *parseCompareNum(void); unsigned char *parseCompareNum(void);

View file

@ -50,19 +50,16 @@ void setmallocpos(void *pointer)
audio_buffer_free = audio_bufferpointer - audio_bufferbase; audio_buffer_free = audio_bufferpointer - audio_bufferbase;
} }
struct token tokenstream[10];
/* this is the plugin entry point */ /* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{ {
unsigned char *result,buf[500]; unsigned char *result,buf[500];
int parsefd;
/* this macro should be called as the first thing you do in the plugin. /* 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 it test that the api version and model the plugin was compiled for
matches the machine it is running on */ matches the machine it is running on */
TEST_PLUGIN_API(api); TEST_PLUGIN_API(api);
(void)parameter;
/* if you are using a global api pointer, don't forget to copy it! /* if you are using a global api pointer, don't forget to copy it!
otherwise you will get lovely "I04: IllInstr" errors... :-) */ otherwise you will get lovely "I04: IllInstr" errors... :-) */
rb = api; rb = api;
@ -72,21 +69,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* now go ahead and have fun! */ /* now go ahead and have fun! */
PUTS("SearchEngine v0.1"); PUTS("SearchEngine v0.1");
tokenstream[0].kind=TOKEN_NUMIDENTIFIER; parsefd=rb->open(parameter,O_RDONLY);
tokenstream[0].intvalue=INTVALUE_YEAR; if(parsefd<0) {
tokenstream[1].kind=TOKEN_GTE; rb->splash(2*HZ,true,"Unable to open search tokenstream");
tokenstream[2].kind=TOKEN_NUM; return PLUGIN_ERROR;
tokenstream[2].intvalue=1980; }
tokenstream[3].kind=TOKEN_AND; result=parse(parsefd);
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);
rb->snprintf(buf,250,"Retval: 0x%x",result); rb->snprintf(buf,250,"Retval: 0x%x",result);
PUTS(buf); PUTS(buf);
rb->close(parsefd);
if(result!=0) { if(result!=0) {
int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC); int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
int i; int i;