replace more strcmp if then trees with string_option()

1

Change-Id: Ic89bbb2ab41068d09c7bd9caa5ba7f38749b9084
This commit is contained in:
William Wilgus 2022-03-13 14:31:02 -04:00
parent a62d36d9e7
commit 2352cef6d0
6 changed files with 82 additions and 80 deletions

View file

@ -260,32 +260,16 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
*/
int string_option(const char *option, const char *const oplist[], bool ignore_case)
{
int i;
int ifound = -1;
const char *op;
if (ignore_case)
int (*cmp_fn)(const char*, const char*) = &strcasecmp;
if (!ignore_case)
cmp_fn = strcmp;
for (int i=0; (op=oplist[i]) != NULL; i++)
{
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcasecmp(op, option) == 0)
{
ifound = i;
break;
}
}
if (cmp_fn(op, option) == 0)
return i;
}
else
{
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcmp(op, option) == 0)
{
ifound = i;
break;
}
}
}
return ifound;
return -1;
}
#endif
/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.