forked from len0rd/rockbox
Starts with and ends with support (for strings), as requested.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6454 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
09d82dbed8
commit
f5eae08361
7 changed files with 120 additions and 86 deletions
|
@ -145,6 +145,8 @@ void buildchoices(int mask) {
|
||||||
if(mask&ACCEPT_STROP) {
|
if(mask&ACCEPT_STROP) {
|
||||||
editing.selection_candidates[i++]=TOKEN_CONTAINS;
|
editing.selection_candidates[i++]=TOKEN_CONTAINS;
|
||||||
editing.selection_candidates[i++]=TOKEN_EQUALS;
|
editing.selection_candidates[i++]=TOKEN_EQUALS;
|
||||||
|
editing.selection_candidates[i++]=TOKEN_STARTSWITH;
|
||||||
|
editing.selection_candidates[i++]=TOKEN_ENDSWITH;
|
||||||
}
|
}
|
||||||
if(mask&ACCEPT_LPAREN) {
|
if(mask&ACCEPT_LPAREN) {
|
||||||
editing.selection_candidates[i++]=TOKEN_LPAREN;
|
editing.selection_candidates[i++]=TOKEN_LPAREN;
|
||||||
|
|
|
@ -100,6 +100,8 @@ void parse_checktoken() {
|
||||||
break;
|
break;
|
||||||
case TOKEN_EQUALS:
|
case TOKEN_EQUALS:
|
||||||
case TOKEN_CONTAINS:
|
case TOKEN_CONTAINS:
|
||||||
|
case TOKEN_STARTSWITH:
|
||||||
|
case TOKEN_ENDSWITH:
|
||||||
ok=acceptedmask&ACCEPT_STROP;
|
ok=acceptedmask&ACCEPT_STROP;
|
||||||
break;
|
break;
|
||||||
case TOKEN_STRING:
|
case TOKEN_STRING:
|
||||||
|
|
|
@ -35,6 +35,8 @@ char *tokentypetostring(int tokentype) {
|
||||||
case TOKEN_RPAREN: return ")";
|
case TOKEN_RPAREN: return ")";
|
||||||
case TOKEN_CONTAINS: return "contains";
|
case TOKEN_CONTAINS: return "contains";
|
||||||
case TOKEN_EQUALS: return "equals";
|
case TOKEN_EQUALS: return "equals";
|
||||||
|
case TOKEN_STARTSWITH: return "starts with";
|
||||||
|
case TOKEN_ENDSWITH: return "ends with";
|
||||||
case TOKEN_NUM: return "<number>";
|
case TOKEN_NUM: return "<number>";
|
||||||
case TOKEN_NUMIDENTIFIER: return "<numberproperty>";
|
case TOKEN_NUMIDENTIFIER: return "<numberproperty>";
|
||||||
case TOKEN_STRING: return "<string>";
|
case TOKEN_STRING: return "<string>";
|
||||||
|
@ -58,6 +60,7 @@ char *numidtostring(int numid) {
|
||||||
case INTVALUE_YEAR: return "<year>";
|
case INTVALUE_YEAR: return "<year>";
|
||||||
case INTVALUE_RATING: return "<rating>";
|
case INTVALUE_RATING: return "<rating>";
|
||||||
case INTVALUE_PLAYCOUNT: return "<playcount>";
|
case INTVALUE_PLAYCOUNT: return "<playcount>";
|
||||||
|
case INTVALUE_AUTORATING: return "<autorating>";
|
||||||
}
|
}
|
||||||
return "numiderror";
|
return "numiderror";
|
||||||
}
|
}
|
||||||
|
@ -100,6 +103,10 @@ void buildtoken(int tokentype,struct token *token) {
|
||||||
token->kind=TOKEN_NUMIDENTIFIER;
|
token->kind=TOKEN_NUMIDENTIFIER;
|
||||||
token->intvalue=INTVALUE_PLAYCOUNT;
|
token->intvalue=INTVALUE_PLAYCOUNT;
|
||||||
break;
|
break;
|
||||||
|
case TOKEN_AUTORATING:
|
||||||
|
token->kind=TOKEN_NUMIDENTIFIER;
|
||||||
|
token->intvalue=INTVALUE_AUTORATING;
|
||||||
|
break;
|
||||||
case TOKEN_TITLE:
|
case TOKEN_TITLE:
|
||||||
token->kind=TOKEN_STRINGIDENTIFIER;
|
token->kind=TOKEN_STRINGIDENTIFIER;
|
||||||
token->intvalue=INTVALUE_TITLE;
|
token->intvalue=INTVALUE_TITLE;
|
||||||
|
@ -172,6 +179,8 @@ char *tokentostring(struct token *token) {
|
||||||
case TOKEN_RPAREN:
|
case TOKEN_RPAREN:
|
||||||
case TOKEN_CONTAINS:
|
case TOKEN_CONTAINS:
|
||||||
case TOKEN_EQUALS:
|
case TOKEN_EQUALS:
|
||||||
|
case TOKEN_STARTSWITH:
|
||||||
|
case TOKEN_ENDSWITH:
|
||||||
return tokentypetostring(token->kind);
|
return tokentypetostring(token->kind);
|
||||||
case TOKEN_NUM: rb->snprintf(bufbla,40,"%d",token->intvalue);
|
case TOKEN_NUM: rb->snprintf(bufbla,40,"%d",token->intvalue);
|
||||||
return bufbla;
|
return bufbla;
|
||||||
|
|
|
@ -19,54 +19,62 @@
|
||||||
#ifndef EDITTOKEN_H
|
#ifndef EDITTOKEN_H
|
||||||
#define EDITTOKEN_H
|
#define EDITTOKEN_H
|
||||||
|
|
||||||
#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"
|
||||||
#define TOKEN_GT 4 // '>'
|
#define TOKEN_GT 4 // '>'
|
||||||
#define TOKEN_GTE 5 // '>='
|
#define TOKEN_GTE 5 // '>='
|
||||||
#define TOKEN_LT 6 // '<'
|
#define TOKEN_LT 6 // '<'
|
||||||
#define TOKEN_LTE 7 // '<='
|
#define TOKEN_LTE 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_STARTSWITH 12
|
||||||
#define TOKEN_RPAREN 13 // ')'
|
#define TOKEN_ENDSWITH 13
|
||||||
#define TOKEN_NUM 14 // (0..9)+
|
#define TOKEN_LPAREN 14 // '('
|
||||||
#define TOKEN_NUMIDENTIFIER 15 // year, trackid, bpm, etc.
|
#define TOKEN_RPAREN 15 // ')'
|
||||||
#define TOKEN_STRING 16 // (?)+
|
#define TOKEN_NUM 16 // (0..9)+
|
||||||
#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
|
#define TOKEN_NUMIDENTIFIER 17 // year, trackid, bpm, etc.
|
||||||
#define TOKEN_YEAR 18
|
#define TOKEN_STRING 18 // (?)+
|
||||||
#define TOKEN_RATING 19
|
#define TOKEN_STRINGIDENTIFIER 19 // album, artist, title, genre ...
|
||||||
#define TOKEN_PLAYCOUNT 20
|
#define TOKEN_SHUFFLE 20
|
||||||
#define TOKEN_TITLE 21
|
#define TOKEN_PLAYTIMELIMIT 21
|
||||||
#define TOKEN_ARTIST 22
|
|
||||||
#define TOKEN_ALBUM 23
|
|
||||||
#define TOKEN_GENRE 24
|
|
||||||
#define TOKEN_FILENAME 25
|
|
||||||
#define TOKEN_EDIT 26
|
|
||||||
|
|
||||||
#define ACCEPT_EOF 0x1
|
// pseudotokens..
|
||||||
#define ACCEPT_BOOLOP 0x2
|
#define TOKEN_YEAR 118
|
||||||
#define ACCEPT_NUMOP 0x4
|
#define TOKEN_RATING 119
|
||||||
#define ACCEPT_STROP 0x8
|
#define TOKEN_PLAYCOUNT 120
|
||||||
#define ACCEPT_LPAREN 0x10
|
#define TOKEN_TITLE 121
|
||||||
#define ACCEPT_RPAREN 0x20
|
#define TOKEN_ARTIST 122
|
||||||
#define ACCEPT_NUMARG 0x40
|
#define TOKEN_ALBUM 123
|
||||||
#define ACCEPT_STRARG 0x80
|
#define TOKEN_GENRE 124
|
||||||
#define ACCEPT_NOT 0x100
|
#define TOKEN_FILENAME 125
|
||||||
#define ACCEPT_DELETE 0x200
|
#define TOKEN_EDIT 126
|
||||||
|
#define TOKEN_AUTORATING 127
|
||||||
|
|
||||||
#define INTVALUE_YEAR 1
|
#define ACCEPT_EOF 0x1
|
||||||
|
#define ACCEPT_BOOLOP 0x2
|
||||||
|
#define ACCEPT_NUMOP 0x4
|
||||||
|
#define ACCEPT_STROP 0x8
|
||||||
|
#define ACCEPT_LPAREN 0x10
|
||||||
|
#define ACCEPT_RPAREN 0x20
|
||||||
|
#define ACCEPT_NUMARG 0x40
|
||||||
|
#define ACCEPT_STRARG 0x80
|
||||||
|
#define ACCEPT_NOT 0x100
|
||||||
|
#define ACCEPT_DELETE 0x200
|
||||||
|
|
||||||
|
#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_AUTORATING 4
|
||||||
#define INTVALUE_ARTIST 5
|
#define INTVALUE_TITLE 14
|
||||||
#define INTVALUE_ALBUM 6
|
#define INTVALUE_ARTIST 15
|
||||||
#define INTVALUE_GENRE 7
|
#define INTVALUE_ALBUM 16
|
||||||
#define INTVALUE_FILENAME 8
|
#define INTVALUE_GENRE 17
|
||||||
|
#define INTVALUE_FILENAME 18
|
||||||
|
|
||||||
struct token {
|
struct token {
|
||||||
char kind;
|
char kind;
|
||||||
|
|
|
@ -146,7 +146,8 @@ 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,i2;
|
||||||
|
int op;
|
||||||
if(syntaxerror) return 0;
|
if(syntaxerror) return 0;
|
||||||
PUTS("parseCompareString");
|
PUTS("parseCompareString");
|
||||||
if(currentToken->kind==TOKEN_STRING ||
|
if(currentToken->kind==TOKEN_STRING ||
|
||||||
|
@ -159,19 +160,12 @@ unsigned char *parseCompareString() {
|
||||||
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
rb->snprintf(errormsg,250,"'%d' found where STRING/STRINGID expected\n",currentToken->kind);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(currentToken->kind==TOKEN_CONTAINS ||
|
op=currentToken->kind;
|
||||||
currentToken->kind==TOKEN_EQUALS) {
|
if(op>=TOKEN_CONTAINS&&op<=TOKEN_ENDSWITH) {
|
||||||
if(currentToken->kind==TOKEN_CONTAINS) {
|
|
||||||
contains=1;
|
|
||||||
PUTS("Contains");
|
|
||||||
} else {
|
|
||||||
contains=0;
|
|
||||||
PUTS("Equals");
|
|
||||||
}
|
|
||||||
parser_acceptIt();
|
parser_acceptIt();
|
||||||
} else {
|
} else {
|
||||||
syntaxerror=1;
|
syntaxerror=1;
|
||||||
rb->snprintf(errormsg,250,"'%d' found where CONTAINS/EQUALS expected\n",currentToken->kind);
|
rb->snprintf(errormsg,250,"'%d' found where STROP expected\n",op);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(currentToken->kind==TOKEN_STRING ||
|
if(currentToken->kind==TOKEN_STRING ||
|
||||||
|
@ -196,10 +190,21 @@ unsigned char *parseCompareString() {
|
||||||
s1=getstring(&string1);
|
s1=getstring(&string1);
|
||||||
if(string2.kind==TOKEN_STRINGIDENTIFIER)
|
if(string2.kind==TOKEN_STRINGIDENTIFIER)
|
||||||
s2=getstring(&string2);
|
s2=getstring(&string2);
|
||||||
if(contains)
|
switch(op) {
|
||||||
ret[i]=rb->strcasestr(s1,s2)!=0;
|
case TOKEN_CONTAINS:
|
||||||
else
|
ret[i]=rb->strcasestr(s1,s2)!=0;
|
||||||
ret[i]=rb->strcasecmp(s1,s2)==0;
|
break;
|
||||||
|
case TOKEN_EQUALS:
|
||||||
|
ret[i]=rb->strcasecmp(s1,s2)==0;
|
||||||
|
break;
|
||||||
|
case TOKEN_STARTSWITH:
|
||||||
|
ret[i]=rb->strncasecmp(s1,s2,rb->strlen(s2))==0;
|
||||||
|
break;
|
||||||
|
case TOKEN_ENDSWITH:
|
||||||
|
i2=rb->strlen(s2);
|
||||||
|
ret[i]=rb->strncasecmp(s1+rb->strlen(s1)-i2,s2,i2)==0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,9 @@ int getvalue(struct token *token) {
|
||||||
case INTVALUE_PLAYCOUNT:
|
case INTVALUE_PLAYCOUNT:
|
||||||
loadrundbdata();
|
loadrundbdata();
|
||||||
return currententry->playcount;
|
return currententry->playcount;
|
||||||
|
case INTVALUE_AUTORATING:
|
||||||
|
// todo.
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
|
rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
|
||||||
rb->splash(HZ*2,true,buf);
|
rb->splash(HZ*2,true,buf);
|
||||||
|
|
|
@ -16,34 +16,39 @@
|
||||||
* 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"
|
||||||
#define TOKEN_GT 4 // '>'
|
#define TOKEN_GT 4 // '>'
|
||||||
#define TOKEN_GTE 5 // '>='
|
#define TOKEN_GTE 5 // '>='
|
||||||
#define TOKEN_LT 6 // '<'
|
#define TOKEN_LT 6 // '<'
|
||||||
#define TOKEN_LTE 7 // '<='
|
#define TOKEN_LTE 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_STARTSWITH 12
|
||||||
#define TOKEN_RPAREN 13 // ')'
|
#define TOKEN_ENDSWITH 13
|
||||||
#define TOKEN_NUM 14 // (0..9)+
|
#define TOKEN_LPAREN 14 // '('
|
||||||
#define TOKEN_NUMIDENTIFIER 15 // year, trackid, bpm, etc.
|
#define TOKEN_RPAREN 15 // ')'
|
||||||
#define TOKEN_STRING 16 // (?)+
|
#define TOKEN_NUM 16 // (0..9)+
|
||||||
#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
|
#define TOKEN_NUMIDENTIFIER 17 // year, trackid, bpm, etc.
|
||||||
|
#define TOKEN_STRING 18 // (?)+
|
||||||
|
#define TOKEN_STRINGIDENTIFIER 19 // album, artist, title, genre ...
|
||||||
|
#define TOKEN_SHUFFLE 20
|
||||||
|
#define TOKEN_PLAYTIMELIMIT 21
|
||||||
|
|
||||||
#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_AUTORATING 4
|
||||||
#define INTVALUE_ARTIST 5
|
#define INTVALUE_TITLE 14
|
||||||
#define INTVALUE_ALBUM 6
|
#define INTVALUE_ARTIST 15
|
||||||
#define INTVALUE_GENRE 7
|
#define INTVALUE_ALBUM 16
|
||||||
#define INTVALUE_FILENAME 8
|
#define INTVALUE_GENRE 17
|
||||||
|
#define INTVALUE_FILENAME 18
|
||||||
|
|
||||||
/* static char *spelling[] = { "not", "and", "or",">",">=","<", "<=","==","!=",
|
/* static char *spelling[] = { "not", "and", "or",">",">=","<", "<=","==","!=",
|
||||||
"contains","(",")" }; */
|
"contains","(",")" }; */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue