diff options
author | Nils Wallménius <nils@rockbox.org> | 2011-05-31 19:44:21 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2011-05-31 19:44:21 +0000 |
commit | f42a305b5764764db816000c572327930eeee9e6 (patch) | |
tree | 9a38e5ed396d2bb769031f0c6a687937b8eb9f97 /apps/tagtree.c | |
parent | 8f4202db285b2139cfee6269b838733d6d2a2306 (diff) | |
download | rockbox-f42a305b5764764db816000c572327930eeee9e6.tar.gz rockbox-f42a305b5764764db816000c572327930eeee9e6.zip |
Accept FS#12136: Save some binsize in tagtree.c. Thanks to sideral for testing.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29937 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r-- | apps/tagtree.c | 159 |
1 files changed, 91 insertions, 68 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index e7f703154c..d28928dbd5 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -156,6 +156,12 @@ struct menu_root { | |||
156 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; | 156 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | struct match | ||
160 | { | ||
161 | const char* str; | ||
162 | int symbol; | ||
163 | }; | ||
164 | |||
159 | /* Statusbar text of the current view. */ | 165 | /* Statusbar text of the current view. */ |
160 | static char current_title[MAX_TAGS][128]; | 166 | static char current_title[MAX_TAGS][128]; |
161 | 167 | ||
@@ -193,16 +199,48 @@ static int get_token_str(char *buf, int size) | |||
193 | return 0; | 199 | return 0; |
194 | } | 200 | } |
195 | 201 | ||
196 | #define MATCH(tag,str1,str2,settag) \ | ||
197 | if (!strcasecmp(str1, str2)) { \ | ||
198 | *tag = settag; \ | ||
199 | return 1; \ | ||
200 | } | ||
201 | |||
202 | static int get_tag(int *tag) | 202 | static int get_tag(int *tag) |
203 | { | 203 | { |
204 | static const struct match get_tag_match[] = | ||
205 | { | ||
206 | {"album", tag_album}, | ||
207 | {"artist", tag_artist}, | ||
208 | {"bitrate", tag_bitrate}, | ||
209 | {"composer", tag_composer}, | ||
210 | {"comment", tag_comment}, | ||
211 | {"albumartist", tag_albumartist}, | ||
212 | {"ensemble", tag_albumartist}, | ||
213 | {"grouping", tag_grouping}, | ||
214 | {"genre", tag_genre}, | ||
215 | {"length", tag_length}, | ||
216 | {"Lm", tag_virt_length_min}, | ||
217 | {"Ls", tag_virt_length_sec}, | ||
218 | {"Pm", tag_virt_playtime_min}, | ||
219 | {"Ps", tag_virt_playtime_sec}, | ||
220 | {"title", tag_title}, | ||
221 | {"filename", tag_filename}, | ||
222 | {"tracknum", tag_tracknumber}, | ||
223 | {"discnum", tag_discnumber}, | ||
224 | {"year", tag_year}, | ||
225 | {"playcount", tag_playcount}, | ||
226 | {"rating", tag_rating}, | ||
227 | {"lastplayed", tag_lastplayed}, | ||
228 | {"lastoffset", tag_lastoffset}, | ||
229 | {"commitid", tag_commitid}, | ||
230 | {"entryage", tag_virt_entryage}, | ||
231 | {"autoscore", tag_virt_autoscore}, | ||
232 | {"%sort", var_sorttype}, | ||
233 | {"%limit", var_limit}, | ||
234 | {"%strip", var_strip}, | ||
235 | {"%menu_start", var_menu_start}, | ||
236 | {"%include", var_include}, | ||
237 | {"%root_menu", var_rootmenu}, | ||
238 | {"%format", var_format}, | ||
239 | {"->", menu_next}, | ||
240 | {"==>", menu_load} | ||
241 | }; | ||
204 | char buf[128]; | 242 | char buf[128]; |
205 | int i; | 243 | unsigned int i; |
206 | 244 | ||
207 | /* Find the start. */ | 245 | /* Find the start. */ |
208 | while ((*strp == ' ' || *strp == '>') && *strp != '\0') | 246 | while ((*strp == ' ' || *strp == '>') && *strp != '\0') |
@@ -210,8 +248,8 @@ static int get_tag(int *tag) | |||
210 | 248 | ||
211 | if (*strp == '\0' || *strp == '?') | 249 | if (*strp == '\0' || *strp == '?') |
212 | return 0; | 250 | return 0; |
213 | 251 | ||
214 | for (i = 0; i < (int)sizeof(buf)-1; i++) | 252 | for (i = 0; i < sizeof(buf)-1; i++) |
215 | { | 253 | { |
216 | if (*strp == '\0' || *strp == ' ') | 254 | if (*strp == '\0' || *strp == ' ') |
217 | break ; | 255 | break ; |
@@ -219,63 +257,54 @@ static int get_tag(int *tag) | |||
219 | strp++; | 257 | strp++; |
220 | } | 258 | } |
221 | buf[i] = '\0'; | 259 | buf[i] = '\0'; |
222 | 260 | ||
223 | MATCH(tag, buf, "album", tag_album); | 261 | for (i = 0; i < ARRAYLEN(get_tag_match); i++) |
224 | MATCH(tag, buf, "artist", tag_artist); | 262 | { |
225 | MATCH(tag, buf, "bitrate", tag_bitrate); | 263 | if (!strcasecmp(buf, get_tag_match[i].str)) |
226 | MATCH(tag, buf, "composer", tag_composer); | 264 | { |
227 | MATCH(tag, buf, "comment", tag_comment); | 265 | *tag = get_tag_match[i].symbol; |
228 | MATCH(tag, buf, "albumartist", tag_albumartist); | 266 | return 1; |
229 | MATCH(tag, buf, "ensemble", tag_albumartist); | 267 | } |
230 | MATCH(tag, buf, "grouping", tag_grouping); | 268 | } |
231 | MATCH(tag, buf, "genre", tag_genre); | 269 | |
232 | MATCH(tag, buf, "length", tag_length); | ||
233 | MATCH(tag, buf, "Lm", tag_virt_length_min); | ||
234 | MATCH(tag, buf, "Ls", tag_virt_length_sec); | ||
235 | MATCH(tag, buf, "Pm", tag_virt_playtime_min); | ||
236 | MATCH(tag, buf, "Ps", tag_virt_playtime_sec); | ||
237 | MATCH(tag, buf, "title", tag_title); | ||
238 | MATCH(tag, buf, "filename", tag_filename); | ||
239 | MATCH(tag, buf, "tracknum", tag_tracknumber); | ||
240 | MATCH(tag, buf, "discnum", tag_discnumber); | ||
241 | MATCH(tag, buf, "year", tag_year); | ||
242 | MATCH(tag, buf, "playcount", tag_playcount); | ||
243 | MATCH(tag, buf, "rating", tag_rating); | ||
244 | MATCH(tag, buf, "lastplayed", tag_lastplayed); | ||
245 | MATCH(tag, buf, "lastoffset", tag_lastoffset); | ||
246 | MATCH(tag, buf, "commitid", tag_commitid); | ||
247 | MATCH(tag, buf, "entryage", tag_virt_entryage); | ||
248 | MATCH(tag, buf, "autoscore", tag_virt_autoscore); | ||
249 | MATCH(tag, buf, "%sort", var_sorttype); | ||
250 | MATCH(tag, buf, "%limit", var_limit); | ||
251 | MATCH(tag, buf, "%strip", var_strip); | ||
252 | MATCH(tag, buf, "%menu_start", var_menu_start); | ||
253 | MATCH(tag, buf, "%include", var_include); | ||
254 | MATCH(tag, buf, "%root_menu", var_rootmenu); | ||
255 | MATCH(tag, buf, "%format", var_format); | ||
256 | MATCH(tag, buf, "->", menu_next); | ||
257 | MATCH(tag, buf, "==>", menu_load); | ||
258 | |||
259 | logf("NO MATCH: %s\n", buf); | 270 | logf("NO MATCH: %s\n", buf); |
260 | if (buf[0] == '?') | 271 | if (buf[0] == '?') |
261 | return 0; | 272 | return 0; |
262 | 273 | ||
263 | return -1; | 274 | return -1; |
264 | } | 275 | } |
265 | 276 | ||
266 | static int get_clause(int *condition) | 277 | static int get_clause(int *condition) |
267 | { | 278 | { |
279 | static const struct match get_clause_match[] = | ||
280 | { | ||
281 | {"=", clause_is}, | ||
282 | {"==", clause_is}, | ||
283 | {"!=", clause_is_not}, | ||
284 | {">", clause_gt}, | ||
285 | {">=", clause_gteq}, | ||
286 | {"<", clause_lt}, | ||
287 | {"<=", clause_lteq}, | ||
288 | {"~", clause_contains}, | ||
289 | {"!~", clause_not_contains}, | ||
290 | {"^", clause_begins_with}, | ||
291 | {"!^", clause_not_begins_with}, | ||
292 | {"$", clause_ends_with}, | ||
293 | {"!$", clause_not_ends_with}, | ||
294 | {"@", clause_oneof} | ||
295 | }; | ||
296 | |||
268 | char buf[4]; | 297 | char buf[4]; |
269 | int i; | 298 | unsigned int i; |
270 | 299 | ||
271 | /* Find the start. */ | 300 | /* Find the start. */ |
272 | while (*strp == ' ' && *strp != '\0') | 301 | while (*strp == ' ' && *strp != '\0') |
273 | strp++; | 302 | strp++; |
274 | 303 | ||
275 | if (*strp == '\0') | 304 | if (*strp == '\0') |
276 | return 0; | 305 | return 0; |
277 | 306 | ||
278 | for (i = 0; i < (int)sizeof(buf)-1; i++) | 307 | for (i = 0; i < sizeof(buf)-1; i++) |
279 | { | 308 | { |
280 | if (*strp == '\0' || *strp == ' ') | 309 | if (*strp == '\0' || *strp == ' ') |
281 | break ; | 310 | break ; |
@@ -283,22 +312,16 @@ static int get_clause(int *condition) | |||
283 | strp++; | 312 | strp++; |
284 | } | 313 | } |
285 | buf[i] = '\0'; | 314 | buf[i] = '\0'; |
286 | 315 | ||
287 | MATCH(condition, buf, "=", clause_is); | 316 | for (i = 0; i < ARRAYLEN(get_clause_match); i++) |
288 | MATCH(condition, buf, "==", clause_is); | 317 | { |
289 | MATCH(condition, buf, "!=", clause_is_not); | 318 | if (!strcasecmp(buf, get_clause_match[i].str)) |
290 | MATCH(condition, buf, ">", clause_gt); | 319 | { |
291 | MATCH(condition, buf, ">=", clause_gteq); | 320 | *condition = get_clause_match[i].symbol; |
292 | MATCH(condition, buf, "<", clause_lt); | 321 | return 1; |
293 | MATCH(condition, buf, "<=", clause_lteq); | 322 | } |
294 | MATCH(condition, buf, "~", clause_contains); | 323 | } |
295 | MATCH(condition, buf, "!~", clause_not_contains); | 324 | |
296 | MATCH(condition, buf, "^", clause_begins_with); | ||
297 | MATCH(condition, buf, "!^", clause_not_begins_with); | ||
298 | MATCH(condition, buf, "$", clause_ends_with); | ||
299 | MATCH(condition, buf, "!$", clause_not_ends_with); | ||
300 | MATCH(condition, buf, "@", clause_oneof); | ||
301 | |||
302 | return 0; | 325 | return 0; |
303 | } | 326 | } |
304 | 327 | ||