diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 10:55:47 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 10:55:47 -0400 |
commit | 77e4dd81f5abedda802b8b6e895849995907b484 (patch) | |
tree | 750656ede0dac091aa1512ccd81660ec40ddbb58 | |
parent | eb86ee296a40249c33d1969087f98108735beaa9 (diff) | |
download | rockbox-77e4dd81f5abedda802b8b6e895849995907b484.tar.gz rockbox-77e4dd81f5abedda802b8b6e895849995907b484.zip |
option_string clean-up and consolidate with metadata_common
Change-Id: I2649f6af37bd871fb8f181ae2f716ff0bcf1f65c
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 12 | ||||
-rw-r--r-- | lib/rbcodec/metadata/metadata_common.c | 36 | ||||
-rw-r--r-- | lib/rbcodec/metadata/metadata_common.h | 1 | ||||
-rw-r--r-- | lib/rbcodec/metadata/mp4.c | 13 | ||||
-rw-r--r-- | lib/rbcodec/metadata/replaygain.c | 31 |
5 files changed, 58 insertions, 35 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index bb6ec7c421..a9b1ef4706 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -601,7 +601,7 @@ static int parse_viewporttextstyle(struct skin_element *element, | |||
601 | *line = (struct line_desc)LINE_DESC_DEFINIT; | 601 | *line = (struct line_desc)LINE_DESC_DEFINIT; |
602 | unsigned colour; | 602 | unsigned colour; |
603 | 603 | ||
604 | const char *vp_options[] = { "invert", "color", "colour", | 604 | static const char *vp_options[] = { "invert", "color", "colour", |
605 | "clear", "gradient", NULL}; | 605 | "clear", "gradient", NULL}; |
606 | 606 | ||
607 | int vp_op = string_option(mode, vp_options, false); | 607 | int vp_op = string_option(mode, vp_options, false); |
@@ -1054,15 +1054,11 @@ static int parse_progressbar_tag(struct skin_element* element, | |||
1054 | eBACKDROP, eVERTICAL, eHORIZONTAL, eNOTOUCH, eSETTING | 1054 | eBACKDROP, eVERTICAL, eHORIZONTAL, eNOTOUCH, eSETTING |
1055 | }; | 1055 | }; |
1056 | 1056 | ||
1057 | const char *pb_options[] = {"invert", "nofill", "noborder, nobar", "slider", | 1057 | static const char *pb_options[] = {"invert", "nofill", "noborder, nobar", "slider", |
1058 | "image", "backdrop", "vertical", "horizontal", | 1058 | "image", "backdrop", "vertical", "horizontal", |
1059 | "notouch", "setting", NULL}; | 1059 | "notouch", "setting", NULL}; |
1060 | |||
1061 | int pb_op; | 1060 | int pb_op; |
1062 | 1061 | ||
1063 | |||
1064 | |||
1065 | |||
1066 | while (curr_param < element->params_count) | 1062 | while (curr_param < element->params_count) |
1067 | { | 1063 | { |
1068 | char* text; | 1064 | char* text; |
@@ -1402,7 +1398,7 @@ static int parse_skinvar( struct skin_element *element, | |||
1402 | return 0; | 1398 | return 0; |
1403 | case SKIN_TOKEN_VAR_SET: | 1399 | case SKIN_TOKEN_VAR_SET: |
1404 | { | 1400 | { |
1405 | const char *sv_options[] = {"touch", "set", "inc", "dec", NULL}; | 1401 | static const char *sv_options[] = {"touch", "set", "inc", "dec", NULL}; |
1406 | 1402 | ||
1407 | struct skin_var_changer *data = skin_buffer_alloc(sizeof(*data)); | 1403 | struct skin_var_changer *data = skin_buffer_alloc(sizeof(*data)); |
1408 | if (!data) | 1404 | if (!data) |
@@ -1706,7 +1702,7 @@ static int parse_touchregion(struct skin_element *element, | |||
1706 | if (region->action == ACTION_NONE) | 1702 | if (region->action == ACTION_NONE) |
1707 | return WPS_ERROR_INVALID_PARAM; | 1703 | return WPS_ERROR_INVALID_PARAM; |
1708 | } | 1704 | } |
1709 | const char *pm_options[] = {"allow_while_locked", "reverse_bar", | 1705 | static const char *pm_options[] = {"allow_while_locked", "reverse_bar", |
1710 | "repeat_press", "long_press", NULL}; | 1706 | "repeat_press", "long_press", NULL}; |
1711 | int pm_op; | 1707 | int pm_op; |
1712 | 1708 | ||
diff --git a/lib/rbcodec/metadata/metadata_common.c b/lib/rbcodec/metadata/metadata_common.c index 3677599c30..2586b2b65e 100644 --- a/lib/rbcodec/metadata/metadata_common.c +++ b/lib/rbcodec/metadata/metadata_common.c | |||
@@ -252,22 +252,42 @@ bool skip_id3v2(int fd, struct mp3entry *id3) | |||
252 | return success; | 252 | return success; |
253 | } | 253 | } |
254 | 254 | ||
255 | static int get_tag_option(const char *option, const char *const oplist[]) | 255 | #ifndef ROCKBOX /*codecs can be built without rockbox */ |
256 | /* returns match index from option list | ||
257 | * returns -1 if option was not found | ||
258 | * option list is array of char pointers with the final item set to null | ||
259 | * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL} | ||
260 | */ | ||
261 | int string_option(const char *option, const char *const oplist[], bool ignore_case) | ||
256 | { | 262 | { |
257 | int i; | 263 | int i; |
258 | int ifound = -1; | 264 | int ifound = -1; |
259 | const char *op; | 265 | const char *op; |
260 | for (i=0; (op=oplist[i]) != NULL; i++) | 266 | if (ignore_case) |
261 | { | 267 | { |
262 | if (strcasecmp(op, option) == 0) | 268 | for (i=0; (op=oplist[i]) != NULL; i++) |
263 | { | 269 | { |
264 | ifound = i; | 270 | if (strcasecmp(op, option) == 0) |
265 | break; | 271 | { |
272 | ifound = i; | ||
273 | break; | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | for (i=0; (op=oplist[i]) != NULL; i++) | ||
280 | { | ||
281 | if (strcmp(op, option) == 0) | ||
282 | { | ||
283 | ifound = i; | ||
284 | break; | ||
285 | } | ||
266 | } | 286 | } |
267 | } | 287 | } |
268 | return ifound; | 288 | return ifound; |
269 | } | 289 | } |
270 | 290 | #endif | |
271 | /* Parse the tag (the name-value pair) and fill id3 and buffer accordingly. | 291 | /* Parse the tag (the name-value pair) and fill id3 and buffer accordingly. |
272 | * String values to keep are written to buf. Returns number of bytes written | 292 | * String values to keep are written to buf. Returns number of bytes written |
273 | * to buf (including end nil). | 293 | * to buf (including end nil). |
@@ -287,7 +307,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3, | |||
287 | eMUSICBRAINZ1, eMUSICBRAINZ2 | 307 | eMUSICBRAINZ1, eMUSICBRAINZ2 |
288 | }; | 308 | }; |
289 | 309 | ||
290 | const char *tagops[] = | 310 | static const char *tagops[] = |
291 | { "track", "tracknumber", "discnumber", "disc", | 311 | { "track", "tracknumber", "discnumber", "disc", |
292 | "year","date","title", "artist", "album", "genre" | 312 | "year","date","title", "artist", "album", "genre" |
293 | "composer","comment","albumartist","album artist", | 313 | "composer","comment","albumartist","album artist", |
@@ -295,7 +315,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3, | |||
295 | "musicbrainz_trackid", "http://musicbrainz.org", NULL | 315 | "musicbrainz_trackid", "http://musicbrainz.org", NULL |
296 | }; | 316 | }; |
297 | 317 | ||
298 | int item = get_tag_option(name, tagops); | 318 | int item = string_option(name, tagops, true); |
299 | 319 | ||
300 | if (((item == eTRACK && (type == TAGTYPE_APE))) | 320 | if (((item == eTRACK && (type == TAGTYPE_APE))) |
301 | || (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS))) | 321 | || (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS))) |
diff --git a/lib/rbcodec/metadata/metadata_common.h b/lib/rbcodec/metadata/metadata_common.h index db91729de4..14115b745a 100644 --- a/lib/rbcodec/metadata/metadata_common.h +++ b/lib/rbcodec/metadata/metadata_common.h | |||
@@ -38,6 +38,7 @@ bool read_ape_tags(int fd, struct mp3entry* id3); | |||
38 | long read_vorbis_tags(int fd, struct mp3entry *id3, | 38 | long read_vorbis_tags(int fd, struct mp3entry *id3, |
39 | long tag_remaining); | 39 | long tag_remaining); |
40 | 40 | ||
41 | int string_option(const char *option, const char *const oplist[], bool ignore_case); | ||
41 | bool skip_id3v2(int fd, struct mp3entry *id3); | 42 | bool skip_id3v2(int fd, struct mp3entry *id3); |
42 | long read_string(int fd, char* buf, long buf_size, int eos, long size); | 43 | long read_string(int fd, char* buf, long buf_size, int eos, long size); |
43 | 44 | ||
diff --git a/lib/rbcodec/metadata/mp4.c b/lib/rbcodec/metadata/mp4.c index 41f38480b1..accc5cd662 100644 --- a/lib/rbcodec/metadata/mp4.c +++ b/lib/rbcodec/metadata/mp4.c | |||
@@ -533,13 +533,18 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3, | |||
533 | rd_ret = 0; | 533 | rd_ret = 0; |
534 | tag_name[rd_ret] = 0; | 534 | tag_name[rd_ret] = 0; |
535 | 535 | ||
536 | static const char *tn_options[] = {"composer", "iTunSMPB", | ||
537 | "musicbrainz track id", "album artist", NULL}; | ||
536 | 538 | ||
537 | if ((strcasecmp(tag_name, "composer") == 0) && !cwrt) | 539 | int tn_op = string_option(tag_name, tn_options, true); |
540 | |||
541 | |||
542 | if (tn_op == 0 && !cwrt) /*composer*/ | ||
538 | { | 543 | { |
539 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, | 544 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, |
540 | &id3->composer); | 545 | &id3->composer); |
541 | } | 546 | } |
542 | else if (strcasecmp(tag_name, "iTunSMPB") == 0) | 547 | else if (tn_op == 1) /*iTunSMPB*/ |
543 | { | 548 | { |
544 | char value[TAG_VALUE_LENGTH]; | 549 | char value[TAG_VALUE_LENGTH]; |
545 | char* value_p = value; | 550 | char* value_p = value; |
@@ -552,12 +557,12 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3, | |||
552 | DEBUGF("AAC: lead_trim %d, tail_trim %d\n", | 557 | DEBUGF("AAC: lead_trim %d, tail_trim %d\n", |
553 | id3->lead_trim, id3->tail_trim); | 558 | id3->lead_trim, id3->tail_trim); |
554 | } | 559 | } |
555 | else if (strcasecmp(tag_name, "musicbrainz track id") == 0) | 560 | else if (tn_op == 2) /*musicbrainz track id*/ |
556 | { | 561 | { |
557 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, | 562 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, |
558 | &id3->mb_track_id); | 563 | &id3->mb_track_id); |
559 | } | 564 | } |
560 | else if ((strcasecmp(tag_name, "album artist") == 0)) | 565 | else if (tn_op == 3) /*album artist*/ |
561 | { | 566 | { |
562 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, | 567 | read_mp4_tag_string(fd, size, &buffer, &buffer_left, |
563 | &id3->albumartist); | 568 | &id3->albumartist); |
diff --git a/lib/rbcodec/metadata/replaygain.c b/lib/rbcodec/metadata/replaygain.c index 7aa77cfedd..eb98bbc342 100644 --- a/lib/rbcodec/metadata/replaygain.c +++ b/lib/rbcodec/metadata/replaygain.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "debug.h" | 32 | #include "debug.h" |
33 | #include "replaygain.h" | 33 | #include "replaygain.h" |
34 | #include "fixedpoint.h" | 34 | #include "fixedpoint.h" |
35 | #include "metadata_common.h" | ||
35 | 36 | ||
36 | #define FP_BITS (12) | 37 | #define FP_BITS (12) |
37 | #define FP_ONE (1 << FP_BITS) | 38 | #define FP_ONE (1 << FP_BITS) |
@@ -167,29 +168,29 @@ long get_replaygain_int(long int_gain) | |||
167 | void parse_replaygain(const char* key, const char* value, | 168 | void parse_replaygain(const char* key, const char* value, |
168 | struct mp3entry* entry) | 169 | struct mp3entry* entry) |
169 | { | 170 | { |
170 | if (((strcasecmp(key, "replaygain_track_gain") == 0) || | 171 | static const char *rg_options[] = {"replaygain_track_gain", "rg_radio", |
171 | (strcasecmp(key, "rg_radio") == 0)) && | 172 | "replaygain_album_gain", "rg_audiophile", |
172 | !entry->track_gain) | 173 | "replaygain_track_peak", "rg_peak", |
173 | { | 174 | "replaygain_album_peak", NULL}; |
175 | |||
176 | int rg_op = string_option(key, rg_options, true); | ||
177 | |||
178 | if ((rg_op == 0 || rg_op == 1) && !entry->track_gain) | ||
179 | { /*replaygain_track_gain||rg_radio*/ | ||
174 | entry->track_level = get_replaygain(value); | 180 | entry->track_level = get_replaygain(value); |
175 | entry->track_gain = convert_gain(entry->track_level); | 181 | entry->track_gain = convert_gain(entry->track_level); |
176 | } | 182 | } |
177 | else if (((strcasecmp(key, "replaygain_album_gain") == 0) || | 183 | else if ((rg_op == 2 || rg_op == 3) && !entry->album_gain) |
178 | (strcasecmp(key, "rg_audiophile") == 0)) && | 184 | { /*replaygain_album_gain||rg_audiophile*/ |
179 | !entry->album_gain) | ||
180 | { | ||
181 | entry->album_level = get_replaygain(value); | 185 | entry->album_level = get_replaygain(value); |
182 | entry->album_gain = convert_gain(entry->album_level); | 186 | entry->album_gain = convert_gain(entry->album_level); |
183 | } | 187 | } |
184 | else if (((strcasecmp(key, "replaygain_track_peak") == 0) || | 188 | else if ((rg_op == 4 || rg_op == 5) && !entry->track_peak) |
185 | (strcasecmp(key, "rg_peak") == 0)) && | 189 | { /*replaygain_track_peak||rg_peak*/ |
186 | !entry->track_peak) | ||
187 | { | ||
188 | entry->track_peak = get_replaypeak(value); | 190 | entry->track_peak = get_replaypeak(value); |
189 | } | 191 | } |
190 | else if ((strcasecmp(key, "replaygain_album_peak") == 0) && | 192 | else if ((rg_op == 6) && !entry->album_peak) |
191 | !entry->album_peak) | 193 | { /*replaygain_album_peak*/ |
192 | { | ||
193 | entry->album_peak = get_replaypeak(value); | 194 | entry->album_peak = get_replaypeak(value); |
194 | } | 195 | } |
195 | } | 196 | } |