Adapt the remaining plugins to put the greyscale isr on cop. Now they can be used...
[Rockbox.git] / apps / plugins / searchengine / token.c
blob3c01d4633ea78e02aed9bf46a72f4616f533ada2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Michiel van der Kolk
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "searchengine.h"
20 #include "token.h"
21 #include "dbinterface.h"
23 char *getstring(struct token *token) {
24 char buf[200];
25 switch(token->kind) {
26 case TOKEN_STRING:
27 return token->spelling;
28 case TOKEN_STRINGIDENTIFIER:
29 switch(token->intvalue) {
30 case INTVALUE_TITLE:
31 loadsongdata();
32 return currententry->title;
33 case INTVALUE_ARTIST:
34 loadartistname();
35 return currententry->artistname;
36 case INTVALUE_ALBUM:
37 loadalbumname();
38 return currententry->albumname;
39 case INTVALUE_GENRE:
40 loadsongdata();
41 return currententry->genre;
42 case INTVALUE_FILENAME:
43 return currententry->filename;
44 default:
45 rb->snprintf(buf,199,"unknown stringid intvalue %d",token->intvalue);
46 rb->splash(HZ*2,buf);
47 return "";
49 break;
50 default:
51 // report error
52 rb->snprintf(buf,199,"unknown token %d in getstring..",token->kind);
53 rb->splash(HZ*2,buf);
54 return "";
58 int getvalue(struct token *token) {
59 char buf[200];
60 int index,i;
61 switch(token->kind) {
62 case TOKEN_NUM:
63 return token->intvalue;
64 case TOKEN_NUMIDENTIFIER:
65 switch(token->intvalue) {
66 case INTVALUE_YEAR:
67 loadsongdata();
68 return currententry->year;
69 case INTVALUE_RATING:
70 loadrundbdata();
71 return currententry->rating;
72 case INTVALUE_PLAYCOUNT:
73 loadrundbdata();
74 return currententry->playcount;
75 case INTVALUE_PLAYTIME:
76 loadsongdata();
77 return currententry->playtime;
78 case INTVALUE_TRACKNUM:
79 loadsongdata();
80 return currententry->track;
81 case INTVALUE_BITRATE:
82 loadsongdata();
83 return currententry->bitrate;
84 case INTVALUE_SAMPLERATE:
85 loadsongdata();
86 return currententry->samplerate;
87 case INTVALUE_AUTORATING:
88 if(!dbglobal.gotplaycountlimits) {
89 index=dbglobal.currententryindex;
90 dbglobal.playcountmax=0;
91 dbglobal.playcountmin=0xFFFFFFFF;
92 for(i=0;i<rb->tagdbheader->filecount;i++) {
93 loadentry(i);
94 loadrundbdata();
95 if(currententry->playcount>dbglobal.playcountmax)
96 dbglobal.playcountmax=currententry->playcount;
97 if(currententry->playcount<dbglobal.playcountmin)
98 dbglobal.playcountmin=currententry->playcount;
100 dbglobal.gotplaycountlimits=1;
101 loadentry(index);
103 loadrundbdata();
104 return (currententry->playcount-dbglobal.playcountmin)*10/(dbglobal.playcountmax-dbglobal.playcountmin);
105 default:
106 rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
107 rb->splash(HZ*2,buf);
108 // report error.
109 return 0;
111 default:
112 rb->snprintf(buf,199,"unknown token %d in getvalue..",token->kind);
113 rb->splash(HZ*2,buf);
114 return 0;