option_string clean-up and consolidate with metadata_common
Change-Id: I2649f6af37bd871fb8f181ae2f716ff0bcf1f65c
This commit is contained in:
parent
eb86ee296a
commit
77e4dd81f5
5 changed files with 58 additions and 35 deletions
|
@ -601,7 +601,7 @@ static int parse_viewporttextstyle(struct skin_element *element,
|
|||
*line = (struct line_desc)LINE_DESC_DEFINIT;
|
||||
unsigned colour;
|
||||
|
||||
const char *vp_options[] = { "invert", "color", "colour",
|
||||
static const char *vp_options[] = { "invert", "color", "colour",
|
||||
"clear", "gradient", NULL};
|
||||
|
||||
int vp_op = string_option(mode, vp_options, false);
|
||||
|
@ -1054,15 +1054,11 @@ static int parse_progressbar_tag(struct skin_element* element,
|
|||
eBACKDROP, eVERTICAL, eHORIZONTAL, eNOTOUCH, eSETTING
|
||||
};
|
||||
|
||||
const char *pb_options[] = {"invert", "nofill", "noborder, nobar", "slider",
|
||||
static const char *pb_options[] = {"invert", "nofill", "noborder, nobar", "slider",
|
||||
"image", "backdrop", "vertical", "horizontal",
|
||||
"notouch", "setting", NULL};
|
||||
|
||||
int pb_op;
|
||||
|
||||
|
||||
|
||||
|
||||
while (curr_param < element->params_count)
|
||||
{
|
||||
char* text;
|
||||
|
@ -1402,7 +1398,7 @@ static int parse_skinvar( struct skin_element *element,
|
|||
return 0;
|
||||
case SKIN_TOKEN_VAR_SET:
|
||||
{
|
||||
const char *sv_options[] = {"touch", "set", "inc", "dec", NULL};
|
||||
static const char *sv_options[] = {"touch", "set", "inc", "dec", NULL};
|
||||
|
||||
struct skin_var_changer *data = skin_buffer_alloc(sizeof(*data));
|
||||
if (!data)
|
||||
|
@ -1706,7 +1702,7 @@ static int parse_touchregion(struct skin_element *element,
|
|||
if (region->action == ACTION_NONE)
|
||||
return WPS_ERROR_INVALID_PARAM;
|
||||
}
|
||||
const char *pm_options[] = {"allow_while_locked", "reverse_bar",
|
||||
static const char *pm_options[] = {"allow_while_locked", "reverse_bar",
|
||||
"repeat_press", "long_press", NULL};
|
||||
int pm_op;
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -38,6 +38,7 @@ bool read_ape_tags(int fd, struct mp3entry* id3);
|
|||
long read_vorbis_tags(int fd, struct mp3entry *id3,
|
||||
long tag_remaining);
|
||||
|
||||
int string_option(const char *option, const char *const oplist[], bool ignore_case);
|
||||
bool skip_id3v2(int fd, struct mp3entry *id3);
|
||||
long read_string(int fd, char* buf, long buf_size, int eos, long size);
|
||||
|
||||
|
|
|
@ -533,13 +533,18 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3,
|
|||
rd_ret = 0;
|
||||
tag_name[rd_ret] = 0;
|
||||
|
||||
static const char *tn_options[] = {"composer", "iTunSMPB",
|
||||
"musicbrainz track id", "album artist", NULL};
|
||||
|
||||
if ((strcasecmp(tag_name, "composer") == 0) && !cwrt)
|
||||
int tn_op = string_option(tag_name, tn_options, true);
|
||||
|
||||
|
||||
if (tn_op == 0 && !cwrt) /*composer*/
|
||||
{
|
||||
read_mp4_tag_string(fd, size, &buffer, &buffer_left,
|
||||
&id3->composer);
|
||||
}
|
||||
else if (strcasecmp(tag_name, "iTunSMPB") == 0)
|
||||
else if (tn_op == 1) /*iTunSMPB*/
|
||||
{
|
||||
char value[TAG_VALUE_LENGTH];
|
||||
char* value_p = value;
|
||||
|
@ -552,12 +557,12 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3,
|
|||
DEBUGF("AAC: lead_trim %d, tail_trim %d\n",
|
||||
id3->lead_trim, id3->tail_trim);
|
||||
}
|
||||
else if (strcasecmp(tag_name, "musicbrainz track id") == 0)
|
||||
else if (tn_op == 2) /*musicbrainz track id*/
|
||||
{
|
||||
read_mp4_tag_string(fd, size, &buffer, &buffer_left,
|
||||
&id3->mb_track_id);
|
||||
}
|
||||
else if ((strcasecmp(tag_name, "album artist") == 0))
|
||||
else if (tn_op == 3) /*album artist*/
|
||||
{
|
||||
read_mp4_tag_string(fd, size, &buffer, &buffer_left,
|
||||
&id3->albumartist);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "debug.h"
|
||||
#include "replaygain.h"
|
||||
#include "fixedpoint.h"
|
||||
#include "metadata_common.h"
|
||||
|
||||
#define FP_BITS (12)
|
||||
#define FP_ONE (1 << FP_BITS)
|
||||
|
@ -167,29 +168,29 @@ long get_replaygain_int(long int_gain)
|
|||
void parse_replaygain(const char* key, const char* value,
|
||||
struct mp3entry* entry)
|
||||
{
|
||||
if (((strcasecmp(key, "replaygain_track_gain") == 0) ||
|
||||
(strcasecmp(key, "rg_radio") == 0)) &&
|
||||
!entry->track_gain)
|
||||
{
|
||||
static const char *rg_options[] = {"replaygain_track_gain", "rg_radio",
|
||||
"replaygain_album_gain", "rg_audiophile",
|
||||
"replaygain_track_peak", "rg_peak",
|
||||
"replaygain_album_peak", NULL};
|
||||
|
||||
int rg_op = string_option(key, rg_options, true);
|
||||
|
||||
if ((rg_op == 0 || rg_op == 1) && !entry->track_gain)
|
||||
{ /*replaygain_track_gain||rg_radio*/
|
||||
entry->track_level = get_replaygain(value);
|
||||
entry->track_gain = convert_gain(entry->track_level);
|
||||
}
|
||||
else if (((strcasecmp(key, "replaygain_album_gain") == 0) ||
|
||||
(strcasecmp(key, "rg_audiophile") == 0)) &&
|
||||
!entry->album_gain)
|
||||
{
|
||||
else if ((rg_op == 2 || rg_op == 3) && !entry->album_gain)
|
||||
{ /*replaygain_album_gain||rg_audiophile*/
|
||||
entry->album_level = get_replaygain(value);
|
||||
entry->album_gain = convert_gain(entry->album_level);
|
||||
}
|
||||
else if (((strcasecmp(key, "replaygain_track_peak") == 0) ||
|
||||
(strcasecmp(key, "rg_peak") == 0)) &&
|
||||
!entry->track_peak)
|
||||
{
|
||||
else if ((rg_op == 4 || rg_op == 5) && !entry->track_peak)
|
||||
{ /*replaygain_track_peak||rg_peak*/
|
||||
entry->track_peak = get_replaypeak(value);
|
||||
}
|
||||
else if ((strcasecmp(key, "replaygain_album_peak") == 0) &&
|
||||
!entry->album_peak)
|
||||
{
|
||||
else if ((rg_op == 6) && !entry->album_peak)
|
||||
{ /*replaygain_album_peak*/
|
||||
entry->album_peak = get_replaypeak(value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue