diff options
-rw-r--r-- | apps/tagtree.c | 134 | ||||
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/common/bsearch.c | 49 | ||||
-rw-r--r-- | firmware/include/bsearch.h | 28 |
4 files changed, 65 insertions, 147 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 | ||
diff --git a/firmware/SOURCES b/firmware/SOURCES index dd3e028e30..4aef86f002 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -105,7 +105,6 @@ libc/mktime.c | |||
105 | 105 | ||
106 | /* Common */ | 106 | /* Common */ |
107 | common/version.c | 107 | common/version.c |
108 | common/bsearch.c | ||
109 | common/config.c | 108 | common/config.c |
110 | common/crc32.c | 109 | common/crc32.c |
111 | #ifdef MI4_FORMAT | 110 | #ifdef MI4_FORMAT |
diff --git a/firmware/common/bsearch.c b/firmware/common/bsearch.c deleted file mode 100644 index cbfec3578a..0000000000 --- a/firmware/common/bsearch.c +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc. | ||
2 | This file is part of the GNU C Library. | ||
3 | |||
4 | The GNU C Library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) any later version. | ||
8 | |||
9 | The GNU C Library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with the GNU C Library; if not, write to the Free | ||
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
17 | 02111-1307 USA. */ | ||
18 | |||
19 | #include <stdlib.h> | ||
20 | |||
21 | |||
22 | /* Perform a binary search for KEY in BASE which has NMEMB elements | ||
23 | of SIZE bytes each. The comparisons are done by (*COMPAR)(). */ | ||
24 | void * | ||
25 | bsearch (const void *key, const void *base, size_t nmemb, size_t size, | ||
26 | int (*compar) (const void *, const void *)) | ||
27 | { | ||
28 | size_t l, u, idx; | ||
29 | const void *p; | ||
30 | int comparison; | ||
31 | |||
32 | l = 0; | ||
33 | u = nmemb; | ||
34 | while (l < u) | ||
35 | { | ||
36 | idx = (l + u) / 2; | ||
37 | p = (void *) (((const char *) base) + (idx * size)); | ||
38 | comparison = (*compar) (key, p); | ||
39 | if (comparison < 0) | ||
40 | u = idx; | ||
41 | else if (comparison > 0) | ||
42 | l = idx + 1; | ||
43 | else | ||
44 | return (void *) p; | ||
45 | } | ||
46 | |||
47 | return NULL; | ||
48 | } | ||
49 | /* libc_hidden_def (bsearch) */ | ||
diff --git a/firmware/include/bsearch.h b/firmware/include/bsearch.h deleted file mode 100644 index e113676a06..0000000000 --- a/firmware/include/bsearch.h +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc. | ||
2 | This file is part of the GNU C Library. | ||
3 | |||
4 | The GNU C Library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) any later version. | ||
8 | |||
9 | The GNU C Library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with the GNU C Library; if not, write to the Free | ||
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
17 | 02111-1307 USA. */ | ||
18 | |||
19 | #ifndef __BSEARCH_H__ | ||
20 | #define __BSEARCH_H__ | ||
21 | |||
22 | /* Perform a binary search for KEY in BASE which has NMEMB elements | ||
23 | of SIZE bytes each. The comparisons are done by (*COMPAR)(). */ | ||
24 | void * | ||
25 | bsearch (const void *key, const void *base, size_t nmemb, size_t size, | ||
26 | int (*compar) (const void *, const void *)); | ||
27 | |||
28 | #endif | ||