"remote_control: don't use goto.
[kugel-rb.git] / apps / plugins / searchengine / token.c
blob89f238c2d65b4908397f8f8d71d0dcd9aed0c9ee
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Michiel van der Kolk
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "searchengine.h"
22 #include "token.h"
23 #include "dbinterface.h"
25 char *getstring(struct token *token) {
26 char buf[200];
27 switch(token->kind) {
28 case TOKEN_STRING:
29 return token->spelling;
30 case TOKEN_STRINGIDENTIFIER:
31 switch(token->intvalue) {
32 case INTVALUE_TITLE:
33 loadsongdata();
34 return currententry->title;
35 case INTVALUE_ARTIST:
36 loadartistname();
37 return currententry->artistname;
38 case INTVALUE_ALBUM:
39 loadalbumname();
40 return currententry->albumname;
41 case INTVALUE_GENRE:
42 loadsongdata();
43 return currententry->genre;
44 case INTVALUE_FILENAME:
45 return currententry->filename;
46 default:
47 rb->snprintf(buf,199,"unknown stringid intvalue %d",token->intvalue);
48 rb->splash(HZ*2,buf);
49 return "";
51 break;
52 default:
53 // report error
54 rb->snprintf(buf,199,"unknown token %d in getstring..",token->kind);
55 rb->splash(HZ*2,buf);
56 return "";
60 int getvalue(struct token *token) {
61 char buf[200];
62 int index,i;
63 switch(token->kind) {
64 case TOKEN_NUM:
65 return token->intvalue;
66 case TOKEN_NUMIDENTIFIER:
67 switch(token->intvalue) {
68 case INTVALUE_YEAR:
69 loadsongdata();
70 return currententry->year;
71 case INTVALUE_RATING:
72 loadrundbdata();
73 return currententry->rating;
74 case INTVALUE_PLAYCOUNT:
75 loadrundbdata();
76 return currententry->playcount;
77 case INTVALUE_PLAYTIME:
78 loadsongdata();
79 return currententry->playtime;
80 case INTVALUE_TRACKNUM:
81 loadsongdata();
82 return currententry->track;
83 case INTVALUE_BITRATE:
84 loadsongdata();
85 return currententry->bitrate;
86 case INTVALUE_SAMPLERATE:
87 loadsongdata();
88 return currententry->samplerate;
89 case INTVALUE_AUTORATING:
90 if(!dbglobal.gotplaycountlimits) {
91 index=dbglobal.currententryindex;
92 dbglobal.playcountmax=0;
93 dbglobal.playcountmin=0xFFFFFFFF;
94 for(i=0;i<rb->tagdbheader->filecount;i++) {
95 loadentry(i);
96 loadrundbdata();
97 if(currententry->playcount>dbglobal.playcountmax)
98 dbglobal.playcountmax=currententry->playcount;
99 if(currententry->playcount<dbglobal.playcountmin)
100 dbglobal.playcountmin=currententry->playcount;
102 dbglobal.gotplaycountlimits=1;
103 loadentry(index);
105 loadrundbdata();
106 return (currententry->playcount-dbglobal.playcountmin)*10/(dbglobal.playcountmax-dbglobal.playcountmin);
107 default:
108 rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
109 rb->splash(HZ*2,buf);
110 // report error.
111 return 0;
113 default:
114 rb->snprintf(buf,199,"unknown token %d in getvalue..",token->kind);
115 rb->splash(HZ*2,buf);
116 return 0;