forked from len0rd/rockbox
Code policy...
Removed tokentool for now since this is not the proper place, but what is? git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6383 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
388d9ff6a3
commit
ec407a86a7
7 changed files with 329 additions and 417 deletions
|
@ -44,7 +44,7 @@ int database_init() {
|
||||||
p=(char *)entryarray;
|
p=(char *)entryarray;
|
||||||
// zero all entries.
|
// zero all entries.
|
||||||
for(i=0;i<sizeof(struct entry)*rb->tagdbheader->filecount;i++)
|
for(i=0;i<sizeof(struct entry)*rb->tagdbheader->filecount;i++)
|
||||||
*(p++)=0;
|
*(p++)=0;
|
||||||
if(*rb->tagdb_initialized!=1) {
|
if(*rb->tagdb_initialized!=1) {
|
||||||
if(!rb->tagdb_init()) {
|
if(!rb->tagdb_init()) {
|
||||||
// failed loading db
|
// failed loading db
|
||||||
|
@ -55,21 +55,21 @@ int database_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
long readlong(int fd) {
|
long readlong(int fd) {
|
||||||
long num;
|
long num;
|
||||||
rb->read(fd,&num,4);
|
rb->read(fd,&num,4);
|
||||||
#ifdef ROCKBOX_LITTLE_ENDIAN
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
||||||
num=BE32(num);
|
num=BE32(num);
|
||||||
#endif
|
#endif
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
short readshort(int fd) {
|
short readshort(int fd) {
|
||||||
short num;
|
short num;
|
||||||
rb->read(fd,&num,2);
|
rb->read(fd,&num,2);
|
||||||
#ifdef ROCKBOX_LITTLE_ENDIAN
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
||||||
num=BE16(num);
|
num=BE16(num);
|
||||||
#endif
|
#endif
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,11 +77,11 @@ void loadentry(int filerecord) {
|
||||||
if(entryarray[filerecord].loadedfiledata==0) {
|
if(entryarray[filerecord].loadedfiledata==0) {
|
||||||
rb->lseek(*rb->tagdb_fd,FILERECORD2OFFSET(filerecord),SEEK_SET);
|
rb->lseek(*rb->tagdb_fd,FILERECORD2OFFSET(filerecord),SEEK_SET);
|
||||||
entryarray[filerecord].filename=(char *)my_malloc(rb->tagdbheader->filelen);
|
entryarray[filerecord].filename=(char *)my_malloc(rb->tagdbheader->filelen);
|
||||||
rb->read(*rb->tagdb_fd,entryarray[filerecord].filename,rb->tagdbheader->filelen);
|
rb->read(*rb->tagdb_fd,entryarray[filerecord].filename,rb->tagdbheader->filelen);
|
||||||
entryarray[filerecord].hash=readlong(*rb->tagdb_fd);
|
entryarray[filerecord].hash=readlong(*rb->tagdb_fd);
|
||||||
entryarray[filerecord].songentry=readlong(*rb->tagdb_fd);
|
entryarray[filerecord].songentry=readlong(*rb->tagdb_fd);
|
||||||
entryarray[filerecord].rundbentry=readlong(*rb->tagdb_fd);
|
entryarray[filerecord].rundbentry=readlong(*rb->tagdb_fd);
|
||||||
entryarray[filerecord].loadedfiledata=1;
|
entryarray[filerecord].loadedfiledata=1;
|
||||||
}
|
}
|
||||||
currententry=&entryarray[filerecord];
|
currententry=&entryarray[filerecord];
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ void loadsongdata() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadrundbdata() {
|
void loadrundbdata() {
|
||||||
// we don't do this yet.
|
// we don't do this yet.
|
||||||
currententry->loadedrundbdata=1;
|
currententry->loadedrundbdata=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void loadartistname() {
|
||||||
* write that pointer to the entrys using it.
|
* write that pointer to the entrys using it.
|
||||||
*/
|
*/
|
||||||
if(currententry->loadedartistname)
|
if(currententry->loadedartistname)
|
||||||
return;
|
return;
|
||||||
loadsongdata();
|
loadsongdata();
|
||||||
currententry->artistname=(char *)my_malloc(rb->tagdbheader->artistlen);
|
currententry->artistname=(char *)my_malloc(rb->tagdbheader->artistlen);
|
||||||
rb->lseek(*rb->tagdb_fd,currententry->artistoffset,SEEK_SET);
|
rb->lseek(*rb->tagdb_fd,currententry->artistoffset,SEEK_SET);
|
||||||
|
@ -123,7 +123,7 @@ void loadartistname() {
|
||||||
void loadalbumname() {
|
void loadalbumname() {
|
||||||
/* see the note at loadartistname */
|
/* see the note at loadartistname */
|
||||||
if(currententry->loadedalbumname)
|
if(currententry->loadedalbumname)
|
||||||
return;
|
return;
|
||||||
loadsongdata();
|
loadsongdata();
|
||||||
currententry->albumname=(char *)my_malloc(rb->tagdbheader->albumlen);
|
currententry->albumname=(char *)my_malloc(rb->tagdbheader->albumlen);
|
||||||
rb->lseek(*rb->tagdb_fd,currententry->albumoffset,SEEK_SET);
|
rb->lseek(*rb->tagdb_fd,currententry->albumoffset,SEEK_SET);
|
||||||
|
@ -133,7 +133,7 @@ void loadalbumname() {
|
||||||
|
|
||||||
char *getfilename(int entry) {
|
char *getfilename(int entry) {
|
||||||
if(entryarray[entry].loadedfiledata==0)
|
if(entryarray[entry].loadedfiledata==0)
|
||||||
return "error O.o;;;";
|
return "error O.o;;;";
|
||||||
else
|
else
|
||||||
return entryarray[entry].filename;
|
return entryarray[entry].filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,264 +29,260 @@ int parse_fd;
|
||||||
char errormsg[250];
|
char errormsg[250];
|
||||||
|
|
||||||
unsigned char *parse(int fd) {
|
unsigned char *parse(int fd) {
|
||||||
unsigned char *ret=0;
|
unsigned char *ret=0;
|
||||||
int i;
|
int i;
|
||||||
syntaxerror=0;
|
syntaxerror=0;
|
||||||
parse_fd=fd;
|
parse_fd=fd;
|
||||||
currentlevel=0;
|
currentlevel=0;
|
||||||
if(nofilter==0) {
|
if(nofilter==0) {
|
||||||
nofilter=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
|
nofilter=my_malloc(sizeof(unsigned char)*rb->tagdbheader->filecount);
|
||||||
rb->memset(nofilter,1,rb->tagdbheader->filecount);
|
rb->memset(nofilter,1,rb->tagdbheader->filecount);
|
||||||
}
|
}
|
||||||
for(i=0;i<20;i++)
|
for(i=0;i<20;i++)
|
||||||
filter[i]=nofilter;
|
filter[i]=nofilter;
|
||||||
database_init();
|
database_init();
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
currentToken=&curtoken;
|
currentToken=&curtoken;
|
||||||
PUTS("parse");
|
PUTS("parse");
|
||||||
ret=parseMExpr();
|
ret=parseMExpr();
|
||||||
if(syntaxerror) {
|
if(syntaxerror) {
|
||||||
PUTS("Syntaxerror");
|
PUTS("Syntaxerror");
|
||||||
rb->splash(HZ*3,true,errormsg);
|
rb->splash(HZ*3,true,errormsg);
|
||||||
}
|
}
|
||||||
parser_accept(TOKEN_EOF);
|
parser_accept(TOKEN_EOF);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser_acceptIt(void) {
|
void parser_acceptIt(void) {
|
||||||
if(syntaxerror) return;
|
if(syntaxerror) return;
|
||||||
rb->read(parse_fd,&curtoken,sizeof(struct token));
|
rb->read(parse_fd,&curtoken,sizeof(struct token));
|
||||||
}
|
}
|
||||||
|
|
||||||
int parser_accept(unsigned char kind) {
|
int parser_accept(unsigned char kind) {
|
||||||
if(currentToken->kind!=kind) {
|
if(currentToken->kind!=kind) {
|
||||||
syntaxerror=1;
|
syntaxerror=1;
|
||||||
rb->snprintf(errormsg,250,"'%d' found where '%d' expected\n",currentToken->kind,kind);
|
rb->snprintf(errormsg,250,"'%d' found where '%d' expected\n",currentToken->kind,kind);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseCompareNum");
|
PUTS("parseCompareNum");
|
||||||
if(currentToken->kind==TOKEN_NUM ||
|
if(currentToken->kind==TOKEN_NUM ||
|
||||||
currentToken->kind==TOKEN_NUMIDENTIFIER) {
|
currentToken->kind==TOKEN_NUMIDENTIFIER) {
|
||||||
rb->memcpy(&number1,currentToken,sizeof(struct token));
|
rb->memcpy(&number1,currentToken,sizeof(struct token));
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
syntaxerror=1;
|
syntaxerror=1;
|
||||||
rb->snprintf(errormsg,250,"'%d' found where NUM/NUMID expected\n",currentToken->kind);
|
rb->snprintf(errormsg,250,"'%d' found where NUM/NUMID expected\n",currentToken->kind);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(currentToken->kind>=TOKEN_GT && currentToken->kind <= TOKEN_NE) {
|
if(currentToken->kind>=TOKEN_GT && currentToken->kind <= TOKEN_NE) {
|
||||||
op=currentToken->kind;
|
op=currentToken->kind;
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
syntaxerror=1;
|
syntaxerror=1;
|
||||||
rb->snprintf(errormsg,250,"'%d' found where NUMOP expected\n",currentToken->kind);
|
rb->snprintf(errormsg,250,"'%d' found where NUMOP expected\n",currentToken->kind);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(currentToken->kind==TOKEN_NUM ||
|
if(currentToken->kind==TOKEN_NUM ||
|
||||||
currentToken->kind==TOKEN_NUMIDENTIFIER) {
|
currentToken->kind==TOKEN_NUMIDENTIFIER) {
|
||||||
rb->memcpy(&number2,currentToken,sizeof(struct token));
|
rb->memcpy(&number2,currentToken,sizeof(struct token));
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
syntaxerror=1;
|
||||||
|
rb->snprintf(errormsg,250,"'%d' found where NUM/NUMID expected\n",currentToken->kind);
|
||||||
|
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);
|
||||||
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
|
if(filter[currentlevel][i]) {
|
||||||
|
loadentry(i);
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
case TOKEN_GTE:
|
||||||
|
ret[i]=n1 >= n2;
|
||||||
|
break;
|
||||||
|
case TOKEN_LT:
|
||||||
|
ret[i]=n1 < n2;
|
||||||
|
break;
|
||||||
|
case TOKEN_LTE:
|
||||||
|
ret[i]=n1 <= n2;
|
||||||
|
break;
|
||||||
|
case TOKEN_EQ:
|
||||||
|
ret[i]=n1 == n2;
|
||||||
|
break;
|
||||||
|
case TOKEN_NE:
|
||||||
|
ret[i]=n1 != n2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
return ret;
|
||||||
syntaxerror=1;
|
|
||||||
rb->snprintf(errormsg,250,"'%d' found where NUM/NUMID expected\n",currentToken->kind);
|
|
||||||
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);
|
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
|
||||||
if(filter[currentlevel][i]) {
|
|
||||||
loadentry(i);
|
|
||||||
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;
|
|
||||||
break;
|
|
||||||
case TOKEN_GTE:
|
|
||||||
ret[i]=n1 >= n2;
|
|
||||||
break;
|
|
||||||
case TOKEN_LT:
|
|
||||||
ret[i]=n1 < n2;
|
|
||||||
break;
|
|
||||||
case TOKEN_LTE:
|
|
||||||
ret[i]=n1 <= n2;
|
|
||||||
break;
|
|
||||||
case TOKEN_EQ:
|
|
||||||
ret[i]=n1 == n2;
|
|
||||||
break;
|
|
||||||
case TOKEN_NE:
|
|
||||||
ret[i]=n1 != n2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseCompareString");
|
PUTS("parseCompareString");
|
||||||
if(currentToken->kind==TOKEN_STRING ||
|
if(currentToken->kind==TOKEN_STRING ||
|
||||||
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
|
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
|
||||||
rb->memcpy(&string1,currentToken,sizeof(struct token));
|
rb->memcpy(&string1,currentToken,sizeof(struct token));
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
syntaxerror=1;
|
||||||
|
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(currentToken->kind==TOKEN_CONTAINS ||
|
||||||
|
currentToken->kind==TOKEN_EQUALS) {
|
||||||
|
if(currentToken->kind==TOKEN_CONTAINS) {
|
||||||
|
contains=1;
|
||||||
|
PUTS("Contains");
|
||||||
|
} else {
|
||||||
|
contains=0;
|
||||||
|
PUTS("Equals");
|
||||||
}
|
}
|
||||||
else {
|
parser_acceptIt();
|
||||||
syntaxerror=1;
|
} else {
|
||||||
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
syntaxerror=1;
|
||||||
return 0;
|
rb->snprintf(errormsg,250,"'%d' found where CONTAINS/EQUALS expected\n",currentToken->kind);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(currentToken->kind==TOKEN_STRING ||
|
||||||
|
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
|
||||||
|
rb->memcpy(&string2,currentToken,sizeof(struct token));
|
||||||
|
parser_acceptIt();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
syntaxerror=1;
|
||||||
|
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
||||||
|
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);
|
||||||
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
|
if(filter[currentlevel][i]) {
|
||||||
|
loadentry(i);
|
||||||
|
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
|
||||||
|
ret[i]=rb->strcasecmp(s1,s2)==0;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
if(currentToken->kind==TOKEN_CONTAINS ||
|
|
||||||
currentToken->kind==TOKEN_EQUALS) {
|
|
||||||
if(currentToken->kind==TOKEN_CONTAINS) {
|
|
||||||
contains=1;
|
|
||||||
PUTS("Contains");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
contains=0;
|
|
||||||
PUTS("Equals");
|
|
||||||
}
|
|
||||||
parser_acceptIt();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
syntaxerror=1;
|
|
||||||
rb->snprintf(errormsg,250,"'%d' found where CONTAINS/EQUALS expected\n",currentToken->kind);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentToken->kind==TOKEN_STRING ||
|
|
||||||
currentToken->kind==TOKEN_STRINGIDENTIFIER) {
|
|
||||||
rb->memcpy(&string2,currentToken,sizeof(struct token));
|
|
||||||
parser_acceptIt();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
syntaxerror=1;
|
|
||||||
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
|
||||||
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);
|
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
|
||||||
if(filter[currentlevel][i]) {
|
|
||||||
loadentry(i);
|
|
||||||
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
|
|
||||||
ret[i]=rb->strcasecmp(s1,s2)==0;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *parseExpr() {
|
unsigned char *parseExpr() {
|
||||||
unsigned char *ret;
|
unsigned char *ret;
|
||||||
int i;
|
int i;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseExpr");
|
PUTS("parseExpr");
|
||||||
switch(currentToken->kind) {
|
switch(currentToken->kind) {
|
||||||
case TOKEN_NOT:
|
case TOKEN_NOT:
|
||||||
parser_accept(TOKEN_NOT);
|
parser_accept(TOKEN_NOT);
|
||||||
PUTS("parseNot");
|
PUTS("parseNot");
|
||||||
ret = parseExpr();
|
ret = parseExpr();
|
||||||
if(ret==NULL) return 0;
|
if(ret==NULL) return 0;
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
if(filter[currentlevel][i])
|
if(filter[currentlevel][i])
|
||||||
ret[i]=!ret[i];
|
ret[i]=!ret[i];
|
||||||
break;
|
break;
|
||||||
case TOKEN_LPAREN:
|
case TOKEN_LPAREN:
|
||||||
parser_accept(TOKEN_LPAREN);
|
parser_accept(TOKEN_LPAREN);
|
||||||
currentlevel++;
|
currentlevel++;
|
||||||
ret = parseMExpr();
|
ret = parseMExpr();
|
||||||
currentlevel--;
|
currentlevel--;
|
||||||
if(ret==NULL) return 0;
|
if(ret==NULL) return 0;
|
||||||
parser_accept(TOKEN_RPAREN);
|
parser_accept(TOKEN_RPAREN);
|
||||||
break;
|
break;
|
||||||
case TOKEN_NUM:
|
case TOKEN_NUM:
|
||||||
case TOKEN_NUMIDENTIFIER:
|
case TOKEN_NUMIDENTIFIER:
|
||||||
ret = parseCompareNum();
|
ret = parseCompareNum();
|
||||||
if(ret==NULL) return 0;
|
if(ret==NULL) return 0;
|
||||||
break;
|
break;
|
||||||
case TOKEN_STRING:
|
case TOKEN_STRING:
|
||||||
case TOKEN_STRINGIDENTIFIER:
|
case TOKEN_STRINGIDENTIFIER:
|
||||||
ret = parseCompareString();
|
ret = parseCompareString();
|
||||||
if(ret==NULL) return 0;
|
if(ret==NULL) return 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error, unexpected symbol
|
// error, unexpected symbol
|
||||||
syntaxerror=1;
|
syntaxerror=1;
|
||||||
rb->snprintf(errormsg,250,"unexpected '%d' found at parseExpr\n",currentToken->kind);
|
rb->snprintf(errormsg,250,"unexpected '%d' found at parseExpr\n",currentToken->kind);
|
||||||
ret=0;
|
ret=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *parseMExpr() {
|
unsigned char *parseMExpr() {
|
||||||
unsigned char *ret,*ret2;
|
unsigned char *ret,*ret2;
|
||||||
int i;
|
int i;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseMExpr");
|
PUTS("parseMExpr");
|
||||||
ret=parseLExpr();
|
ret=parseLExpr();
|
||||||
while(currentToken->kind==TOKEN_OR) {
|
while(currentToken->kind==TOKEN_OR) {
|
||||||
parser_accept(TOKEN_OR);
|
parser_accept(TOKEN_OR);
|
||||||
PUTS("parseOr");
|
PUTS("parseOr");
|
||||||
ret2 = parseLExpr();
|
ret2 = parseLExpr();
|
||||||
if(ret2==NULL) return 0;
|
if(ret2==NULL) return 0;
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
if(filter[currentlevel][i]) // this should always be true
|
if(filter[currentlevel][i]) // this should always be true
|
||||||
ret[i]=ret[i] || ret2[i];
|
ret[i]=ret[i] || ret2[i];
|
||||||
else
|
else
|
||||||
rb->splash(HZ*2,true,"An or is having a filter, bad.");
|
rb->splash(HZ*2,true,"An or is having a filter, bad.");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *parseLExpr() {
|
unsigned char *parseLExpr() {
|
||||||
unsigned char *ret,*ret2;
|
unsigned char *ret,*ret2;
|
||||||
int i;
|
int i;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseLExpr");
|
PUTS("parseLExpr");
|
||||||
filter[currentlevel]=nofilter;
|
filter[currentlevel]=nofilter;
|
||||||
ret=parseExpr();
|
ret=parseExpr();
|
||||||
filter[currentlevel]=ret;
|
filter[currentlevel]=ret;
|
||||||
while(currentToken->kind==TOKEN_AND) {
|
while(currentToken->kind==TOKEN_AND) {
|
||||||
parser_accept(TOKEN_AND);
|
parser_accept(TOKEN_AND);
|
||||||
PUTS("parseAnd");
|
PUTS("parseAnd");
|
||||||
ret2 = parseExpr();
|
ret2 = parseExpr();
|
||||||
if(ret2==NULL) return 0;
|
if(ret2==NULL) return 0;
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
ret[i]=ret[i] && ret2[i];
|
ret[i]=ret[i] && ret2[i];
|
||||||
}
|
}
|
||||||
filter[currentlevel]=nofilter;
|
filter[currentlevel]=nofilter;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
parsefd=rb->open(parameter,O_RDONLY);
|
parsefd=rb->open(parameter,O_RDONLY);
|
||||||
if(parsefd<0) {
|
if(parsefd<0) {
|
||||||
rb->splash(2*HZ,true,"Unable to open search tokenstream");
|
rb->splash(2*HZ,true,"Unable to open search tokenstream");
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
}
|
}
|
||||||
result=parse(parsefd);
|
result=parse(parsefd);
|
||||||
rb->snprintf(buf,250,"Retval: 0x%x",result);
|
rb->snprintf(buf,250,"Retval: 0x%x",result);
|
||||||
|
@ -80,15 +80,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
rb->close(parsefd);
|
rb->close(parsefd);
|
||||||
hits=0;
|
hits=0;
|
||||||
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;
|
||||||
for(i=0;i<rb->tagdbheader->filecount;i++)
|
for(i=0;i<rb->tagdbheader->filecount;i++)
|
||||||
if(result[i]) {
|
if(result[i]) {
|
||||||
hits++;
|
hits++;
|
||||||
rb->fdprintf(fd,"%s\n",getfilename(i));
|
rb->fdprintf(fd,"%s\n",getfilename(i));
|
||||||
}
|
}
|
||||||
/* rb->write(fd,result,rb->tagdbheader->filecount);*/
|
rb->close(fd);
|
||||||
rb->close(fd);
|
|
||||||
}
|
}
|
||||||
rb->snprintf(buf,250,"Hits: %d",hits);
|
rb->snprintf(buf,250,"Hits: %d",hits);
|
||||||
rb->splash(HZ*3,true,buf);
|
rb->splash(HZ*3,true,buf);
|
||||||
|
|
|
@ -25,15 +25,15 @@
|
||||||
extern int w, h, y;
|
extern int w, h, y;
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
#define PUTS(str) do { \
|
#define PUTS(str) do { \
|
||||||
rb->lcd_putsxy(1, y, str); \
|
rb->lcd_putsxy(1, y, str); \
|
||||||
rb->lcd_getstringsize(str, &w, &h); \
|
rb->lcd_getstringsize(str, &w, &h); \
|
||||||
y += h + 1; \
|
y += h + 1; \
|
||||||
} while (0); \
|
} while (0); \
|
||||||
rb->lcd_update()
|
rb->lcd_update()
|
||||||
#else
|
#else
|
||||||
#define PUTS(str) do { \
|
#define PUTS(str) do { \
|
||||||
rb->lcd_puts(0, y, str); \
|
rb->lcd_puts(0, y, str); \
|
||||||
y = (y + 1) % 2; \
|
y = (y + 1) % 2; \
|
||||||
} while (0);
|
} while (0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -21,59 +21,59 @@
|
||||||
#include "dbinterface.h"
|
#include "dbinterface.h"
|
||||||
|
|
||||||
char *getstring(struct token *token) {
|
char *getstring(struct token *token) {
|
||||||
switch(token->kind) {
|
switch(token->kind) {
|
||||||
case TOKEN_STRING:
|
case TOKEN_STRING:
|
||||||
return token->spelling;
|
return token->spelling;
|
||||||
case TOKEN_STRINGIDENTIFIER:
|
case TOKEN_STRINGIDENTIFIER:
|
||||||
switch(token->intvalue) {
|
switch(token->intvalue) {
|
||||||
case INTVALUE_TITLE:
|
case INTVALUE_TITLE:
|
||||||
loadsongdata();
|
loadsongdata();
|
||||||
return currententry->title;
|
return currententry->title;
|
||||||
case INTVALUE_ARTIST:
|
case INTVALUE_ARTIST:
|
||||||
loadartistname();
|
loadartistname();
|
||||||
return currententry->artistname;
|
return currententry->artistname;
|
||||||
case INTVALUE_ALBUM:
|
case INTVALUE_ALBUM:
|
||||||
loadalbumname();
|
loadalbumname();
|
||||||
return currententry->albumname;
|
return currententry->albumname;
|
||||||
case INTVALUE_GENRE:
|
case INTVALUE_GENRE:
|
||||||
loadsongdata();
|
loadsongdata();
|
||||||
return currententry->genre;
|
return currententry->genre;
|
||||||
case INTVALUE_FILENAME:
|
case INTVALUE_FILENAME:
|
||||||
return currententry->filename;
|
return currententry->filename;
|
||||||
default:
|
default:
|
||||||
rb->splash(HZ*2,true,"unknown stringid intvalue");
|
rb->splash(HZ*2,true,"unknown stringid intvalue");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// report error
|
// report error
|
||||||
rb->splash(HZ*2,true,"unknown token...");
|
rb->splash(HZ*2,true,"unknown token...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getvalue(struct token *token) {
|
int getvalue(struct token *token) {
|
||||||
switch(token->kind) {
|
switch(token->kind) {
|
||||||
case TOKEN_NUM:
|
case TOKEN_NUM:
|
||||||
return token->intvalue;
|
return token->intvalue;
|
||||||
case TOKEN_NUMIDENTIFIER:
|
case TOKEN_NUMIDENTIFIER:
|
||||||
switch(token->intvalue) {
|
switch(token->intvalue) {
|
||||||
case INTVALUE_YEAR:
|
case INTVALUE_YEAR:
|
||||||
loadsongdata();
|
loadsongdata();
|
||||||
return currententry->year;
|
return currententry->year;
|
||||||
case INTVALUE_RATING:
|
case INTVALUE_RATING:
|
||||||
loadrundbdata();
|
loadrundbdata();
|
||||||
return currententry->rating;
|
return currententry->rating;
|
||||||
case INTVALUE_PLAYCOUNT:
|
case INTVALUE_PLAYCOUNT:
|
||||||
loadrundbdata();
|
loadrundbdata();
|
||||||
return currententry->playcount;
|
return currententry->playcount;
|
||||||
default:
|
default:
|
||||||
rb->splash(HZ*2,true,"unknown numid intvalue");
|
rb->splash(HZ*2,true,"unknown numid intvalue");
|
||||||
// report error.
|
// report error.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
rb->splash(HZ*2,true,"unknown token...");
|
rb->splash(HZ*2,true,"unknown token...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#define TOKEN_INVALID -1
|
#define TOKEN_INVALID -1
|
||||||
#define TOKEN_EOF 0 // EOF
|
#define TOKEN_EOF 0 // EOF
|
||||||
#define TOKEN_NOT 1 // "not"
|
#define TOKEN_NOT 1 // "not"
|
||||||
#define TOKEN_AND 2 // "and"
|
#define TOKEN_AND 2 // "and"
|
||||||
#define TOKEN_OR 3 // "or"
|
#define TOKEN_OR 3 // "or"
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
#define TOKEN_EQ 8 // '=='
|
#define TOKEN_EQ 8 // '=='
|
||||||
#define TOKEN_NE 9 // '!='
|
#define TOKEN_NE 9 // '!='
|
||||||
#define TOKEN_CONTAINS 10 // "contains"
|
#define TOKEN_CONTAINS 10 // "contains"
|
||||||
#define TOKEN_EQUALS 11 // "equals"
|
#define TOKEN_EQUALS 11 // "equals"
|
||||||
#define TOKEN_LPAREN 12 // '('
|
#define TOKEN_LPAREN 12 // '('
|
||||||
#define TOKEN_RPAREN 13 // ')'
|
#define TOKEN_RPAREN 13 // ')'
|
||||||
#define TOKEN_NUM 14 // (0..9)+
|
#define TOKEN_NUM 14 // (0..9)+
|
||||||
|
@ -36,17 +36,17 @@
|
||||||
#define TOKEN_STRING 16 // (?)+
|
#define TOKEN_STRING 16 // (?)+
|
||||||
#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
|
#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
|
||||||
|
|
||||||
#define INTVALUE_YEAR 1
|
#define INTVALUE_YEAR 1
|
||||||
#define INTVALUE_RATING 2
|
#define INTVALUE_RATING 2
|
||||||
#define INTVALUE_PLAYCOUNT 3
|
#define INTVALUE_PLAYCOUNT 3
|
||||||
#define INTVALUE_TITLE 4
|
#define INTVALUE_TITLE 4
|
||||||
#define INTVALUE_ARTIST 5
|
#define INTVALUE_ARTIST 5
|
||||||
#define INTVALUE_ALBUM 6
|
#define INTVALUE_ALBUM 6
|
||||||
#define INTVALUE_GENRE 7
|
#define INTVALUE_GENRE 7
|
||||||
#define INTVALUE_FILENAME 8
|
#define INTVALUE_FILENAME 8
|
||||||
|
|
||||||
/* static char *spelling[] = { "not", "and", "or",">",">=","<", "<=","==","!=",
|
/* static char *spelling[] = { "not", "and", "or",">",">=","<", "<=","==","!=",
|
||||||
"contains","(",")" }; */
|
"contains","(",")" }; */
|
||||||
|
|
||||||
struct token {
|
struct token {
|
||||||
unsigned char kind;
|
unsigned char kind;
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* __________ __ ___.
|
|
||||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
||||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
||||||
* \/ \/ \/ \/ \/
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 by Michiel van der Kolk
|
|
||||||
*
|
|
||||||
* All files in this archive are subject to the GNU General Public License.
|
|
||||||
* See the file COPYING in the source tree root for full license agreement.
|
|
||||||
*
|
|
||||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
||||||
* KIND, either express or implied.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "token.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LITTLE_ENDIAN
|
|
||||||
#define BE32(_x_) (((_x_ & 0xff000000) >> 24) | \
|
|
||||||
((_x_ & 0x00ff0000) >> 8) | \
|
|
||||||
((_x_ & 0x0000ff00) << 8) | \
|
|
||||||
((_x_ & 0x000000ff) << 24))
|
|
||||||
#else
|
|
||||||
#define BE32(_x_) _x_
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct token token;
|
|
||||||
char buf[500];
|
|
||||||
long num;
|
|
||||||
FILE *fp;
|
|
||||||
main() {
|
|
||||||
int done=0;
|
|
||||||
printf("Output filename? ");
|
|
||||||
fflush(stdout);
|
|
||||||
fgets(buf,254,stdin);
|
|
||||||
buf[strlen(buf)-1]=0;
|
|
||||||
fp=fopen(buf,"w");
|
|
||||||
if(fp<0) {
|
|
||||||
printf("Error opening outputfile.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
printf("EOF=0 NOT=1 AND=2 OR=3 GT=4 GTE=5 LT=6 LTE=7 EQ=8 NE=9\n");
|
|
||||||
printf("(strings:) CONTAINS=10 EQUALS=11\n");
|
|
||||||
printf("'('=12 ')'=13\n");
|
|
||||||
printf("(arguments:) NUMBER=14 NUMBERFIELD=15 STRING=16 STRINGFIELD=17\n");
|
|
||||||
printf("Token kind? ");
|
|
||||||
fflush(stdout);
|
|
||||||
fgets(buf,254,stdin);
|
|
||||||
token.kind=strtol(buf,0,10);
|
|
||||||
memset(&token.spelling,0,256);
|
|
||||||
if(token.kind==TOKEN_STRING) {
|
|
||||||
printf("Token spelling? ");
|
|
||||||
fflush(stdout);
|
|
||||||
fgets(token.spelling,254,stdin);
|
|
||||||
token.spelling[strlen(token.spelling)-1]=0;
|
|
||||||
}
|
|
||||||
if(token.kind==TOKEN_STRINGIDENTIFIER)
|
|
||||||
printf("TITLE=4 ARTIST=5 ALBUM=6 GENRE=7 FILENAME=8\n");
|
|
||||||
else if(token.kind==TOKEN_NUMIDENTIFIER)
|
|
||||||
printf("YEAR=1 RATING=2 PLAYCOUNT=3\n");
|
|
||||||
token.intvalue=0;
|
|
||||||
if(token.kind==TOKEN_STRINGIDENTIFIER ||
|
|
||||||
token.kind==TOKEN_NUMIDENTIFIER ||
|
|
||||||
token.kind==TOKEN_NUM) {
|
|
||||||
printf("Token intvalue? ");
|
|
||||||
fflush(stdout);
|
|
||||||
fgets(buf,254,stdin);
|
|
||||||
token.intvalue=BE32(strtol(buf,0,10));
|
|
||||||
}
|
|
||||||
fwrite(&token,sizeof(struct token),1,fp);
|
|
||||||
done=token.kind==0;
|
|
||||||
} while(!done);
|
|
||||||
fclose(fp);
|
|
||||||
printf("Successfully wrote tokenfile\n");
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue