diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tagtree.c | 134 |
1 files changed, 65 insertions, 69 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 1bdc0550a6..3df8d9db2b 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include "string-extra.h" | 31 | #include "string-extra.h" |
32 | #include "bsearch.h" | ||
33 | #include "config.h" | 32 | #include "config.h" |
34 | #include "system.h" | 33 | #include "system.h" |
35 | #include "kernel.h" | 34 | #include "kernel.h" |
@@ -161,13 +160,6 @@ struct match | |||
161 | int symbol; | 160 | int symbol; |
162 | }; | 161 | }; |
163 | 162 | ||
164 | static int compare_match(const void* _key, const void* _elem) | ||
165 | { | ||
166 | const char* key = _key; | ||
167 | const struct match *elem = _elem; | ||
168 | return strcasecmp(key, elem->str); | ||
169 | } | ||
170 | |||
171 | /* Statusbar text of the current view. */ | 163 | /* Statusbar text of the current view. */ |
172 | static char current_title[MAX_TAGS][128]; | 164 | static char current_title[MAX_TAGS][128]; |
173 | 165 | ||
@@ -229,42 +221,42 @@ static int get_token_str(char *buf, int size) | |||
229 | static int get_tag(int *tag) | 221 | static int get_tag(int *tag) |
230 | { | 222 | { |
231 | static const struct match get_tag_match[] = | 223 | static const struct match get_tag_match[] = |
232 | { /* sorted by ascii (case insensitive) for bsearch */ | 224 | { |
233 | { "%format", var_format }, | 225 | {"album", tag_album}, |
234 | { "%include", var_include }, | 226 | {"artist", tag_artist}, |
235 | { "%limit", var_limit }, | 227 | {"bitrate", tag_bitrate}, |
236 | {"%menu_start",var_menu_start}, | 228 | {"composer", tag_composer}, |
237 | {"%root_menu",var_rootmenu}, | 229 | {"comment", tag_comment}, |
238 | { "%sort", var_sorttype }, | 230 | {"albumartist", tag_albumartist}, |
239 | { "%strip", var_strip }, | 231 | {"ensemble", tag_albumartist}, |
240 | {"->",menu_next}, | 232 | {"grouping", tag_grouping}, |
241 | { "==>", menu_load }, | 233 | {"genre", tag_genre}, |
242 | { "album", tag_album }, | 234 | {"length", tag_length}, |
243 | { "albumartist", tag_albumartist }, | 235 | {"Lm", tag_virt_length_min}, |
244 | { "artist", tag_artist }, | 236 | {"Ls", tag_virt_length_sec}, |
245 | { "autoscore", tag_virt_autoscore }, | 237 | {"Pm", tag_virt_playtime_min}, |
246 | { "bitrate", tag_bitrate }, | 238 | {"Ps", tag_virt_playtime_sec}, |
247 | { "comment", tag_comment }, | 239 | {"title", tag_title}, |
248 | { "commitid", tag_commitid }, | 240 | {"filename", tag_filename}, |
249 | { "composer", tag_composer }, | 241 | {"tracknum", tag_tracknumber}, |
250 | { "discnum", tag_discnumber }, | 242 | {"discnum", tag_discnumber}, |
251 | { "ensemble", tag_albumartist }, | 243 | {"year", tag_year}, |
252 | { "entryage", tag_virt_entryage }, | 244 | {"playcount", tag_playcount}, |
253 | { "filename", tag_filename }, | 245 | {"rating", tag_rating}, |
254 | { "genre", tag_genre }, | 246 | {"lastplayed", tag_lastplayed}, |
255 | { "grouping", tag_grouping }, | 247 | {"lastoffset", tag_lastoffset}, |
256 | { "lastoffset", tag_lastoffset }, | 248 | {"commitid", tag_commitid}, |
257 | { "lastplayed", tag_lastplayed }, | 249 | {"entryage", tag_virt_entryage}, |
258 | { "length", tag_length }, | 250 | {"autoscore", tag_virt_autoscore}, |
259 | { "Lm", tag_virt_length_min }, | 251 | {"%sort", var_sorttype}, |
260 | { "Ls", tag_virt_length_sec }, | 252 | {"%limit", var_limit}, |
261 | { "playcount", tag_playcount }, | 253 | {"%strip", var_strip}, |
262 | { "Pm", tag_virt_playtime_min }, | 254 | {"%menu_start", var_menu_start}, |
263 | { "Ps", tag_virt_playtime_sec }, | 255 | {"%include", var_include}, |
264 | { "rating", tag_rating }, | 256 | {"%root_menu", var_rootmenu}, |
265 | { "title", tag_title }, | 257 | {"%format", var_format}, |
266 | { "tracknum", tag_tracknumber }, | 258 | {"->", menu_next}, |
267 | { "year", tag_year }, | 259 | {"==>", menu_load} |
268 | }; | 260 | }; |
269 | char buf[128]; | 261 | char buf[128]; |
270 | unsigned int i; | 262 | unsigned int i; |
@@ -285,13 +277,15 @@ static int get_tag(int *tag) | |||
285 | } | 277 | } |
286 | buf[i] = '\0'; | 278 | buf[i] = '\0'; |
287 | 279 | ||
288 | struct match *elem = bsearch(buf, get_tag_match, ARRAYLEN(get_tag_match), | 280 | for (i = 0; i < ARRAYLEN(get_tag_match); i++) |
289 | sizeof(struct match), compare_match); | ||
290 | if (elem) | ||
291 | { | 281 | { |
292 | *tag = elem->symbol; | 282 | if (!strcasecmp(buf, get_tag_match[i].str)) |
293 | return 1; | 283 | { |
284 | *tag = get_tag_match[i].symbol; | ||
285 | return 1; | ||
286 | } | ||
294 | } | 287 | } |
288 | |||
295 | logf("NO MATCH: %s\n", buf); | 289 | logf("NO MATCH: %s\n", buf); |
296 | if (buf[0] == '?') | 290 | if (buf[0] == '?') |
297 | return 0; | 291 | return 0; |
@@ -302,21 +296,21 @@ static int get_tag(int *tag) | |||
302 | static int get_clause(int *condition) | 296 | static int get_clause(int *condition) |
303 | { | 297 | { |
304 | static const struct match get_clause_match[] = | 298 | static const struct match get_clause_match[] = |
305 | { /* sorted by ascii (case insensitive) for bsearch */ | 299 | { |
306 | { "!$", clause_not_ends_with }, | 300 | {"=", clause_is}, |
307 | { "!=", clause_is_not }, | 301 | {"==", clause_is}, |
308 | { "!^", clause_not_begins_with }, | 302 | {"!=", clause_is_not}, |
309 | { "!~", clause_not_contains }, | 303 | {">", clause_gt}, |
310 | { "$", clause_ends_with }, | 304 | {">=", clause_gteq}, |
311 | { "<", clause_lt }, | 305 | {"<", clause_lt}, |
312 | { "<=", clause_lteq }, | 306 | {"<=", clause_lteq}, |
313 | { "=", clause_is }, | 307 | {"~", clause_contains}, |
314 | { "==", clause_is }, | 308 | {"!~", clause_not_contains}, |
315 | { ">", clause_gt }, | 309 | {"^", clause_begins_with}, |
316 | { ">=", clause_gteq }, | 310 | {"!^", clause_not_begins_with}, |
317 | { "@", clause_oneof }, | 311 | {"$", clause_ends_with}, |
318 | { "^", clause_begins_with }, | 312 | {"!$", clause_not_ends_with}, |
319 | { "~", clause_contains }, | 313 | {"@", clause_oneof} |
320 | }; | 314 | }; |
321 | 315 | ||
322 | char buf[4]; | 316 | char buf[4]; |
@@ -338,13 +332,15 @@ static int get_clause(int *condition) | |||
338 | } | 332 | } |
339 | buf[i] = '\0'; | 333 | buf[i] = '\0'; |
340 | 334 | ||
341 | struct match *elem = bsearch(buf, get_clause_match, ARRAYLEN(get_clause_match), | 335 | for (i = 0; i < ARRAYLEN(get_clause_match); i++) |
342 | sizeof(struct match), compare_match); | ||
343 | if (elem) | ||
344 | { | 336 | { |
345 | *condition = elem->symbol; | 337 | if (!strcasecmp(buf, get_clause_match[i].str)) |
346 | return 1; | 338 | { |
339 | *condition = get_clause_match[i].symbol; | ||
340 | return 1; | ||
341 | } | ||
347 | } | 342 | } |
343 | |||
348 | return 0; | 344 | return 0; |
349 | } | 345 | } |
350 | 346 | ||