summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-05-10 23:44:22 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-05-10 23:44:22 +0000
commitf5eae08361c4b1c9d7c846c7b4b54fabf7467e31 (patch)
treeca9d05970a00e34d93f6651c2e8d27a9fe3caacd /apps
parent09d82dbed8ebbefb2dfb248cd2d6191e917e9797 (diff)
downloadrockbox-f5eae08361c4b1c9d7c846c7b4b54fabf7467e31.tar.gz
rockbox-f5eae08361c4b1c9d7c846c7b4b54fabf7467e31.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/databox/databox.c2
-rw-r--r--apps/plugins/databox/editparser.c2
-rw-r--r--apps/plugins/databox/edittoken.c9
-rw-r--r--apps/plugins/databox/edittoken.h98
-rw-r--r--apps/plugins/searchengine/parser.c35
-rw-r--r--apps/plugins/searchengine/token.c3
-rw-r--r--apps/plugins/searchengine/token.h57
7 files changed, 120 insertions, 86 deletions
diff --git a/apps/plugins/databox/databox.c b/apps/plugins/databox/databox.c
index af2bdda927..58f949ee19 100644
--- a/apps/plugins/databox/databox.c
+++ b/apps/plugins/databox/databox.c
@@ -145,6 +145,8 @@ void buildchoices(int mask) {
if(mask&ACCEPT_STROP) {
editing.selection_candidates[i++]=TOKEN_CONTAINS;
editing.selection_candidates[i++]=TOKEN_EQUALS;
+ editing.selection_candidates[i++]=TOKEN_STARTSWITH;
+ editing.selection_candidates[i++]=TOKEN_ENDSWITH;
}
if(mask&ACCEPT_LPAREN) {
editing.selection_candidates[i++]=TOKEN_LPAREN;
diff --git a/apps/plugins/databox/editparser.c b/apps/plugins/databox/editparser.c
index d2fcbc4e6d..5ee9ffbd56 100644
--- a/apps/plugins/databox/editparser.c
+++ b/apps/plugins/databox/editparser.c
@@ -100,6 +100,8 @@ void parse_checktoken() {
break;
case TOKEN_EQUALS:
case TOKEN_CONTAINS:
+ case TOKEN_STARTSWITH:
+ case TOKEN_ENDSWITH:
ok=acceptedmask&ACCEPT_STROP;
break;
case TOKEN_STRING:
diff --git a/apps/plugins/databox/edittoken.c b/apps/plugins/databox/edittoken.c
index f5b869757b..71548d6ce1 100644
--- a/apps/plugins/databox/edittoken.c
+++ b/apps/plugins/databox/edittoken.c
@@ -35,6 +35,8 @@ char *tokentypetostring(int tokentype) {
case TOKEN_RPAREN: return ")";
case TOKEN_CONTAINS: return "contains";
case TOKEN_EQUALS: return "equals";
+ case TOKEN_STARTSWITH: return "starts with";
+ case TOKEN_ENDSWITH: return "ends with";
case TOKEN_NUM: return "<number>";
case TOKEN_NUMIDENTIFIER: return "<numberproperty>";
case TOKEN_STRING: return "<string>";
@@ -58,6 +60,7 @@ char *numidtostring(int numid) {
case INTVALUE_YEAR: return "<year>";
case INTVALUE_RATING: return "<rating>";
case INTVALUE_PLAYCOUNT: return "<playcount>";
+ case INTVALUE_AUTORATING: return "<autorating>";
}
return "numiderror";
}
@@ -100,6 +103,10 @@ void buildtoken(int tokentype,struct token *token) {
token->kind=TOKEN_NUMIDENTIFIER;
token->intvalue=INTVALUE_PLAYCOUNT;
break;
+ case TOKEN_AUTORATING:
+ token->kind=TOKEN_NUMIDENTIFIER;
+ token->intvalue=INTVALUE_AUTORATING;
+ break;
case TOKEN_TITLE:
token->kind=TOKEN_STRINGIDENTIFIER;
token->intvalue=INTVALUE_TITLE;
@@ -172,6 +179,8 @@ char *tokentostring(struct token *token) {
case TOKEN_RPAREN:
case TOKEN_CONTAINS:
case TOKEN_EQUALS:
+ case TOKEN_STARTSWITH:
+ case TOKEN_ENDSWITH:
return tokentypetostring(token->kind);
case TOKEN_NUM: rb->snprintf(bufbla,40,"%d",token->intvalue);
return bufbla;
diff --git a/apps/plugins/databox/edittoken.h b/apps/plugins/databox/edittoken.h
index a5c8d472e1..4c9f535448 100644
--- a/apps/plugins/databox/edittoken.h
+++ b/apps/plugins/databox/edittoken.h
@@ -19,54 +19,62 @@
#ifndef EDITTOKEN_H
#define EDITTOKEN_H
-#define TOKEN_INVALID -1
-#define TOKEN_EOF 0 // EOF
-#define TOKEN_NOT 1 // "not"
-#define TOKEN_AND 2 // "and"
-#define TOKEN_OR 3 // "or"
-#define TOKEN_GT 4 // '>'
-#define TOKEN_GTE 5 // '>='
-#define TOKEN_LT 6 // '<'
-#define TOKEN_LTE 7 // '<='
-#define TOKEN_EQ 8 // '=='
-#define TOKEN_NE 9 // '!='
-#define TOKEN_CONTAINS 10 // "contains"
-#define TOKEN_EQUALS 11 // "equals"
-#define TOKEN_LPAREN 12 // '('
-#define TOKEN_RPAREN 13 // ')'
-#define TOKEN_NUM 14 // (0..9)+
-#define TOKEN_NUMIDENTIFIER 15 // year, trackid, bpm, etc.
-#define TOKEN_STRING 16 // (?)+
-#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
-#define TOKEN_YEAR 18
-#define TOKEN_RATING 19
-#define TOKEN_PLAYCOUNT 20
-#define TOKEN_TITLE 21
-#define TOKEN_ARTIST 22
-#define TOKEN_ALBUM 23
-#define TOKEN_GENRE 24
-#define TOKEN_FILENAME 25
-#define TOKEN_EDIT 26
+#define TOKEN_INVALID -1
+#define TOKEN_EOF 0 // EOF
+#define TOKEN_NOT 1 // "not"
+#define TOKEN_AND 2 // "and"
+#define TOKEN_OR 3 // "or"
+#define TOKEN_GT 4 // '>'
+#define TOKEN_GTE 5 // '>='
+#define TOKEN_LT 6 // '<'
+#define TOKEN_LTE 7 // '<='
+#define TOKEN_EQ 8 // '=='
+#define TOKEN_NE 9 // '!='
+#define TOKEN_CONTAINS 10 // "contains"
+#define TOKEN_EQUALS 11 // "equals"
+#define TOKEN_STARTSWITH 12
+#define TOKEN_ENDSWITH 13
+#define TOKEN_LPAREN 14 // '('
+#define TOKEN_RPAREN 15 // ')'
+#define TOKEN_NUM 16 // (0..9)+
+#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 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
+// pseudotokens..
+#define TOKEN_YEAR 118
+#define TOKEN_RATING 119
+#define TOKEN_PLAYCOUNT 120
+#define TOKEN_TITLE 121
+#define TOKEN_ARTIST 122
+#define TOKEN_ALBUM 123
+#define TOKEN_GENRE 124
+#define TOKEN_FILENAME 125
+#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_PLAYCOUNT 3
-#define INTVALUE_TITLE 4
-#define INTVALUE_ARTIST 5
-#define INTVALUE_ALBUM 6
-#define INTVALUE_GENRE 7
-#define INTVALUE_FILENAME 8
+#define INTVALUE_PLAYCOUNT 3
+#define INTVALUE_AUTORATING 4
+#define INTVALUE_TITLE 14
+#define INTVALUE_ARTIST 15
+#define INTVALUE_ALBUM 16
+#define INTVALUE_GENRE 17
+#define INTVALUE_FILENAME 18
struct token {
char kind;
diff --git a/apps/plugins/searchengine/parser.c b/apps/plugins/searchengine/parser.c
index 62423e256f..76beab49cc 100644
--- a/apps/plugins/searchengine/parser.c
+++ b/apps/plugins/searchengine/parser.c
@@ -146,7 +146,8 @@ unsigned char *parseCompareString() {
struct token string1,string2;
unsigned char *ret;
char *s1=NULL,*s2=NULL;
- int i,contains;
+ int i,i2;
+ int op;
if(syntaxerror) return 0;
PUTS("parseCompareString");
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);
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");
- }
+ op=currentToken->kind;
+ if(op>=TOKEN_CONTAINS&&op<=TOKEN_ENDSWITH) {
parser_acceptIt();
} else {
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;
}
if(currentToken->kind==TOKEN_STRING ||
@@ -196,10 +190,21 @@ unsigned char *parseCompareString() {
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;
+ switch(op) {
+ case TOKEN_CONTAINS:
+ ret[i]=rb->strcasestr(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;
}
diff --git a/apps/plugins/searchengine/token.c b/apps/plugins/searchengine/token.c
index fa1f84eb7d..d8cd64072f 100644
--- a/apps/plugins/searchengine/token.c
+++ b/apps/plugins/searchengine/token.c
@@ -71,6 +71,9 @@ int getvalue(struct token *token) {
case INTVALUE_PLAYCOUNT:
loadrundbdata();
return currententry->playcount;
+ case INTVALUE_AUTORATING:
+ // todo.
+ return 0;
default:
rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
rb->splash(HZ*2,true,buf);
diff --git a/apps/plugins/searchengine/token.h b/apps/plugins/searchengine/token.h
index 183f365c59..12065511ac 100644
--- a/apps/plugins/searchengine/token.h
+++ b/apps/plugins/searchengine/token.h
@@ -16,34 +16,39 @@
* KIND, either express or implied.
*
****************************************************************************/
-#define TOKEN_INVALID -1
-#define TOKEN_EOF 0 // EOF
-#define TOKEN_NOT 1 // "not"
-#define TOKEN_AND 2 // "and"
-#define TOKEN_OR 3 // "or"
-#define TOKEN_GT 4 // '>'
-#define TOKEN_GTE 5 // '>='
-#define TOKEN_LT 6 // '<'
-#define TOKEN_LTE 7 // '<='
-#define TOKEN_EQ 8 // '=='
-#define TOKEN_NE 9 // '!='
-#define TOKEN_CONTAINS 10 // "contains"
-#define TOKEN_EQUALS 11 // "equals"
-#define TOKEN_LPAREN 12 // '('
-#define TOKEN_RPAREN 13 // ')'
-#define TOKEN_NUM 14 // (0..9)+
-#define TOKEN_NUMIDENTIFIER 15 // year, trackid, bpm, etc.
-#define TOKEN_STRING 16 // (?)+
-#define TOKEN_STRINGIDENTIFIER 17 // album, artist, title, genre ...
+#define TOKEN_INVALID -1
+#define TOKEN_EOF 0 // EOF
+#define TOKEN_NOT 1 // "not"
+#define TOKEN_AND 2 // "and"
+#define TOKEN_OR 3 // "or"
+#define TOKEN_GT 4 // '>'
+#define TOKEN_GTE 5 // '>='
+#define TOKEN_LT 6 // '<'
+#define TOKEN_LTE 7 // '<='
+#define TOKEN_EQ 8 // '=='
+#define TOKEN_NE 9 // '!='
+#define TOKEN_CONTAINS 10 // "contains"
+#define TOKEN_EQUALS 11 // "equals"
+#define TOKEN_STARTSWITH 12
+#define TOKEN_ENDSWITH 13
+#define TOKEN_LPAREN 14 // '('
+#define TOKEN_RPAREN 15 // ')'
+#define TOKEN_NUM 16 // (0..9)+
+#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_PLAYCOUNT 3
-#define INTVALUE_TITLE 4
-#define INTVALUE_ARTIST 5
-#define INTVALUE_ALBUM 6
-#define INTVALUE_GENRE 7
-#define INTVALUE_FILENAME 8
+#define INTVALUE_PLAYCOUNT 3
+#define INTVALUE_AUTORATING 4
+#define INTVALUE_TITLE 14
+#define INTVALUE_ARTIST 15
+#define INTVALUE_ALBUM 16
+#define INTVALUE_GENRE 17
+#define INTVALUE_FILENAME 18
/* static char *spelling[] = { "not", "and", "or",">",">=","<", "<=","==","!=",
"contains","(",")" }; */