option_string clean-up and consolidate with metadata_common

Change-Id: I2649f6af37bd871fb8f181ae2f716ff0bcf1f65c
This commit is contained in:
William Wilgus 2022-03-13 10:55:47 -04:00
parent eb86ee296a
commit 77e4dd81f5
5 changed files with 58 additions and 35 deletions

View file

@ -252,22 +252,42 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
return success;
}
static int get_tag_option(const char *option, const char *const oplist[])
#ifndef ROCKBOX /*codecs can be built without rockbox */
/* returns match index from option list
* returns -1 if option was not found
* option list is array of char pointers with the final item set to null
* ex - const char *option[] = { "op_a", "op_b", "op_c", NULL}
*/
int string_option(const char *option, const char *const oplist[], bool ignore_case)
{
int i;
int ifound = -1;
const char *op;
for (i=0; (op=oplist[i]) != NULL; i++)
if (ignore_case)
{
if (strcasecmp(op, option) == 0)
for (i=0; (op=oplist[i]) != NULL; i++)
{
ifound = i;
break;
if (strcasecmp(op, option) == 0)
{
ifound = i;
break;
}
}
}
else
{
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcmp(op, option) == 0)
{
ifound = i;
break;
}
}
}
return ifound;
}
#endif
/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.
* String values to keep are written to buf. Returns number of bytes written
* to buf (including end nil).
@ -287,7 +307,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
eMUSICBRAINZ1, eMUSICBRAINZ2
};
const char *tagops[] =
static const char *tagops[] =
{ "track", "tracknumber", "discnumber", "disc",
"year","date","title", "artist", "album", "genre"
"composer","comment","albumartist","album artist",
@ -295,7 +315,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
"musicbrainz_trackid", "http://musicbrainz.org", NULL
};
int item = get_tag_option(name, tagops);
int item = string_option(name, tagops, true);
if (((item == eTRACK && (type == TAGTYPE_APE)))
|| (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS)))