From f5eae08361c4b1c9d7c846c7b4b54fabf7467e31 Mon Sep 17 00:00:00 2001 From: Michiel Van Der Kolk Date: Tue, 10 May 2005 23:44:22 +0000 Subject: 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 --- apps/plugins/searchengine/parser.c | 35 +++++++++++++---------- apps/plugins/searchengine/token.c | 3 ++ apps/plugins/searchengine/token.h | 57 +++++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 41 deletions(-) (limited to 'apps/plugins/searchengine') diff --git a/apps/plugins/searchengine/parser.c b/apps/plugins/searchengine/parser.c index 62423e2..76beab4 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 fa1f84e..d8cd640 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 183f365..1206551 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","(",")" }; */ -- cgit v1.1