Simplify config_get_entry

This commit is contained in:
twinaphex 2020-08-26 02:17:37 +02:00
parent 54dfaaa3bc
commit ad61d8ff92
4 changed files with 66 additions and 58 deletions

View File

@ -123,12 +123,12 @@ static void core_info_list_resolve_all_firmware(
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
entry = config_get_entry(config, path_key, NULL);
entry = config_get_entry(config, path_key);
if (entry && !string_is_empty(entry->value))
info->firmware[c].path = strdup(entry->value);
entry = config_get_entry(config, desc_key, NULL);
entry = config_get_entry(config, desc_key);
if (entry && !string_is_empty(entry->value))
info->firmware[c].desc = strdup(entry->value);
@ -321,32 +321,32 @@ static core_info_list_t *core_info_list_new(const char *path,
bool tmp_bool = false;
unsigned tmp_uint = 0;
struct config_entry_list
*entry = config_get_entry(conf, "display_name", NULL);
*entry = config_get_entry(conf, "display_name");
if (entry && !string_is_empty(entry->value))
core_info[i].display_name = strdup(entry->value);
entry = config_get_entry(conf, "display_version", NULL);
entry = config_get_entry(conf, "display_version");
if (entry && !string_is_empty(entry->value))
core_info[i].display_version = strdup(entry->value);
entry = config_get_entry(conf, "corename", NULL);
entry = config_get_entry(conf, "corename");
if (entry && !string_is_empty(entry->value))
core_info[i].core_name = strdup(entry->value);
entry = config_get_entry(conf, "systemname", NULL);
entry = config_get_entry(conf, "systemname");
if (entry && !string_is_empty(entry->value))
core_info[i].systemname = strdup(entry->value);
entry = config_get_entry(conf, "systemid", NULL);
entry = config_get_entry(conf, "systemid");
if (entry && !string_is_empty(entry->value))
core_info[i].system_id = strdup(entry->value);
entry = config_get_entry(conf, "manufacturer", NULL);
entry = config_get_entry(conf, "manufacturer");
if (entry && !string_is_empty(entry->value))
core_info[i].system_manufacturer = strdup(entry->value);
@ -354,7 +354,7 @@ static core_info_list_t *core_info_list_new(const char *path,
config_get_uint(conf, "firmware_count", &tmp_uint);
core_info[i].firmware_count = tmp_uint;
entry = config_get_entry(conf, "supported_extensions", NULL);
entry = config_get_entry(conf, "supported_extensions");
if (entry && !string_is_empty(entry->value))
{
@ -363,7 +363,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].supported_extensions, "|");
}
entry = config_get_entry(conf, "authors", NULL);
entry = config_get_entry(conf, "authors");
if (entry && !string_is_empty(entry->value))
{
@ -372,7 +372,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].authors, "|");
}
entry = config_get_entry(conf, "permissions", NULL);
entry = config_get_entry(conf, "permissions");
if (entry && !string_is_empty(entry->value))
{
@ -381,7 +381,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].permissions, "|");
}
entry = config_get_entry(conf, "license", NULL);
entry = config_get_entry(conf, "license");
if (entry && !string_is_empty(entry->value))
{
@ -390,7 +390,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].licenses, "|");
}
entry = config_get_entry(conf, "categories", NULL);
entry = config_get_entry(conf, "categories");
if (entry && !string_is_empty(entry->value))
{
@ -399,7 +399,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].categories, "|");
}
entry = config_get_entry(conf, "database", NULL);
entry = config_get_entry(conf, "database");
if (entry && !string_is_empty(entry->value))
{
@ -408,7 +408,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].databases, "|");
}
entry = config_get_entry(conf, "notes", NULL);
entry = config_get_entry(conf, "notes");
if (entry && !string_is_empty(entry->value))
{
@ -417,7 +417,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].notes, "|");
}
entry = config_get_entry(conf, "required_hw_api", NULL);
entry = config_get_entry(conf, "required_hw_api");
if (entry && !string_is_empty(entry->value))
{
@ -426,7 +426,7 @@ static core_info_list_t *core_info_list_new(const char *path,
string_split(core_info[i].required_hw_api, "|");
}
entry = config_get_entry(conf, "description", NULL);
entry = config_get_entry(conf, "description");
if (entry && !string_is_empty(entry->value))
core_info[i].description = strdup(entry->value);
@ -937,9 +937,9 @@ void core_info_get_name(const char *path, char *s, size_t len,
continue;
if (get_display_name)
entry = config_get_entry(conf, "display_name", NULL);
entry = config_get_entry(conf, "display_name");
else
entry = config_get_entry(conf, "corename", NULL);
entry = config_get_entry(conf, "corename");
if (entry && !string_is_empty(entry->value))
strlcpy(s, entry->value, len);
@ -1094,7 +1094,7 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
if (!conf)
return false;
entry = config_get_entry(conf, "display_name", NULL);
entry = config_get_entry(conf, "display_name");
if (entry && !string_is_empty(entry->value))
strlcpy(s, entry->value, len);
@ -1143,19 +1143,19 @@ core_updater_info_t *core_info_get_core_updater_info(const char *path)
info->is_experimental = tmp_bool;
/* > display_name */
entry = config_get_entry(conf, "display_name", NULL);
entry = config_get_entry(conf, "display_name");
if (entry && !string_is_empty(entry->value))
info->display_name = strdup(entry->value);
/* > description */
entry = config_get_entry(conf, "description", NULL);
entry = config_get_entry(conf, "description");
if (entry && !string_is_empty(entry->value))
info->description = strdup(entry->value);
/* > licenses */
entry = config_get_entry(conf, "license", NULL);
entry = config_get_entry(conf, "license");
if (entry && !string_is_empty(entry->value))
info->licenses = strdup(entry->value);

View File

@ -484,19 +484,13 @@ static bool config_file_parse_line(config_file_t *conf,
if (!path)
return false;
if (string_is_empty(path))
if ( string_is_empty(path)
|| conf->include_depth >= MAX_INCLUDE_DEPTH)
{
free(path);
return false;
}
if (conf->include_depth >= MAX_INCLUDE_DEPTH)
{
fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n");
free(path);
return false;
}
real_path[0] = '\0';
config_file_add_sub_conf(conf, path,
real_path, sizeof(real_path), cb);
@ -795,7 +789,7 @@ config_file_t *config_file_new_alloc(void)
return conf;
}
struct config_entry_list *config_get_entry(
static struct config_entry_list *config_get_entry_internal(
const config_file_t *conf,
const char *key, struct config_entry_list **prev)
{
@ -816,9 +810,22 @@ struct config_entry_list *config_get_entry(
return NULL;
}
struct config_entry_list *config_get_entry(
const config_file_t *conf, const char *key)
{
struct config_entry_list *entry = NULL;
for (entry = conf->entries; entry; entry = entry->next)
{
if (string_is_equal(key, entry->key))
return entry;
}
return NULL;
}
bool config_get_double(config_file_t *conf, const char *key, double *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (!entry)
return false;
@ -829,7 +836,7 @@ bool config_get_double(config_file_t *conf, const char *key, double *in)
bool config_get_float(config_file_t *conf, const char *key, float *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (!entry)
return false;
@ -841,7 +848,7 @@ bool config_get_float(config_file_t *conf, const char *key, float *in)
bool config_get_int(config_file_t *conf, const char *key, int *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
errno = 0;
if (entry)
@ -860,7 +867,7 @@ bool config_get_int(config_file_t *conf, const char *key, int *in)
bool config_get_size_t(config_file_t *conf, const char *key, size_t *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
errno = 0;
if (entry)
@ -879,7 +886,7 @@ bool config_get_size_t(config_file_t *conf, const char *key, size_t *in)
#if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
errno = 0;
if (entry)
@ -898,7 +905,7 @@ bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
errno = 0;
if (entry)
@ -917,7 +924,7 @@ bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
errno = 0;
if (entry)
@ -936,7 +943,7 @@ bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
bool config_get_char(config_file_t *conf, const char *key, char *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (entry)
{
@ -952,7 +959,7 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
bool config_get_string(config_file_t *conf, const char *key, char **str)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (!entry || !entry->value)
return false;
@ -971,8 +978,7 @@ bool config_get_config_path(config_file_t *conf, char *s, size_t len)
bool config_get_array(config_file_t *conf, const char *key,
char *buf, size_t size)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (entry)
return strlcpy(buf, entry->value, size) < size;
return false;
@ -985,7 +991,7 @@ bool config_get_path(config_file_t *conf, const char *key,
if (config_get_array(conf, key, buf, size))
return true;
#else
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (entry)
{
@ -998,7 +1004,7 @@ bool config_get_path(config_file_t *conf, const char *key,
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
{
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
const struct config_entry_list *entry = config_get_entry(conf, key);
if (!entry)
return false;
@ -1042,7 +1048,8 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
}
else
{
entry = config_get_entry(conf, key, &last);
entry = config_get_entry_internal(
conf, key, &last);
if (entry)
{
/* An entry corresponding to 'key' already exists
@ -1098,7 +1105,7 @@ void config_unset(config_file_t *conf, const char *key)
return;
last = conf->entries;
entry = config_get_entry(conf, key, &last);
entry = config_get_entry_internal(conf, key, &last);
if (!entry)
return;

View File

@ -138,8 +138,7 @@ struct config_file_entry
};
struct config_entry_list *config_get_entry(
const config_file_t *conf,
const char *key, struct config_entry_list **prev);
const config_file_t *conf, const char *key);
bool config_get_entry_list_head(config_file_t *conf, struct config_file_entry *entry);
bool config_get_entry_list_next(struct config_file_entry *entry);

View File

@ -17838,9 +17838,9 @@ static bool core_option_manager_parse_variable(
option->index = 0;
if (config_src)
entry = config_get_entry(config_src, option->key, NULL);
entry = config_get_entry(config_src, option->key);
else
entry = config_get_entry(opt->conf, option->key, NULL);
entry = config_get_entry(opt->conf, option->key);
/* Set current config value */
if (entry && !string_is_empty(entry->value))
@ -17871,13 +17871,15 @@ static bool core_option_manager_parse_option(
{
size_t i;
union string_list_elem_attr attr;
size_t num_vals = 0;
struct config_entry_list *entry = NULL;
struct core_option *option = (struct core_option*)&opt->opts[idx];
const struct retro_core_option_value *values = option_def->values;
struct config_entry_list
*entry = NULL;
size_t num_vals = 0;
struct core_option *option = (struct core_option*)&opt->opts[idx];
const struct retro_core_option_value
*values = option_def->values;
/* All options are visible by default */
option->visible = true;
option->visible = true;
if (!string_is_empty(option_def->key))
option->key = strdup(option_def->key);
@ -17944,9 +17946,9 @@ static bool core_option_manager_parse_option(
}
if (config_src)
entry = config_get_entry(config_src, option->key, NULL);
entry = config_get_entry(config_src, option->key);
else
entry = config_get_entry(opt->conf, option->key, NULL);
entry = config_get_entry(opt->conf, option->key);
/* Set current config value */
if (entry && !string_is_empty(entry->value))