General cleanups -

* struct was erroneously named 'catagory' - changed to 'category'
* Removed some strlcpys that were just setting the string to a fixed constant value
* Random nits
This commit is contained in:
LibretroAdmin 2022-08-01 21:31:45 +02:00
parent e4bff7c12c
commit 9d66e2d5e1
4 changed files with 104 additions and 135 deletions

View File

@ -1986,8 +1986,7 @@ static core_info_list_t *core_info_list_new(const char *path,
if (!path_list) if (!path_list)
goto error; goto error;
core_info_list = (core_info_list_t*)malloc(sizeof(*core_info_list)); if (!(core_info_list = (core_info_list_t*)malloc(sizeof(*core_info_list))))
if (!core_info_list)
goto error; goto error;
core_info_list->list = NULL; core_info_list->list = NULL;
@ -1995,10 +1994,8 @@ static core_info_list_t *core_info_list_new(const char *path,
core_info_list->info_count = 0; core_info_list->info_count = 0;
core_info_list->all_ext = NULL; core_info_list->all_ext = NULL;
core_info = (core_info_t*)calloc(path_list->core_list->size, if (!(core_info = (core_info_t*)calloc(path_list->core_list->size,
sizeof(*core_info)); sizeof(*core_info))))
if (!core_info)
{ {
core_info_list_free(core_info_list); core_info_list_free(core_info_list);
goto error; goto error;
@ -2074,7 +2071,7 @@ static core_info_list_t *core_info_list_new(const char *path,
} }
/* Cache core path */ /* Cache core path */
info->path = strdup(base_path); info->path = strdup(base_path);
/* Get core lock status */ /* Get core lock status */
info->is_locked = core_info_path_is_locked( info->is_locked = core_info_path_is_locked(
@ -2085,9 +2082,7 @@ static core_info_list_t *core_info_list_new(const char *path,
info->core_file_id.hash = core_info_hash_string(core_file_id); info->core_file_id.hash = core_info_hash_string(core_file_id);
/* Parse core info file */ /* Parse core info file */
conf = core_info_get_config_file(core_file_id, info_dir); if ((conf = core_info_get_config_file(core_file_id, info_dir)))
if (conf)
{ {
core_info_parse_config_file(core_info_list, info, conf); core_info_parse_config_file(core_info_list, info, conf);
config_file_free(conf); config_file_free(conf);
@ -2232,10 +2227,8 @@ static bool core_info_list_update_missing_firmware_internal(
if (!core_info_list) if (!core_info_list)
return false; return false;
info = core_info_find_internal( if (!(info = core_info_find_internal(
core_info_list, core_path); core_info_list, core_path)))
if (!info)
return false; return false;
for (i = 0; i < info->firmware_count; i++) for (i = 0; i < info->firmware_count; i++)
@ -2359,21 +2352,21 @@ bool core_info_get_list(core_info_list_t **core)
size_t core_info_count(void) size_t core_info_count(void)
{ {
core_info_state_t *p_coreinfo = &core_info_st; core_info_state_t *p_coreinfo = &core_info_st;
if (!p_coreinfo || !p_coreinfo->curr_list) if (p_coreinfo && p_coreinfo->curr_list)
return 0; return p_coreinfo->curr_list->count;
return p_coreinfo->curr_list->count; return 0;
} }
bool core_info_list_update_missing_firmware( bool core_info_list_update_missing_firmware(
core_info_ctx_firmware_t *info, bool *set_missing_bios) core_info_ctx_firmware_t *info, bool *set_missing_bios)
{ {
core_info_state_t *p_coreinfo = &core_info_st; core_info_state_t *p_coreinfo = &core_info_st;
if (!info) if (info)
return false; return core_info_list_update_missing_firmware_internal(
return core_info_list_update_missing_firmware_internal( p_coreinfo->curr_list,
p_coreinfo->curr_list, info->path, info->directory.system,
info->path, info->directory.system, set_missing_bios);
set_missing_bios); return false;
} }
bool core_info_load(const char *core_path) bool core_info_load(const char *core_path)
@ -2405,9 +2398,7 @@ bool core_info_find(const char *core_path,
if (!core_info || !p_coreinfo->curr_list) if (!core_info || !p_coreinfo->curr_list)
return false; return false;
info = core_info_find_internal(p_coreinfo->curr_list, core_path); if (!(info = core_info_find_internal(p_coreinfo->curr_list, core_path)))
if (!info)
return false; return false;
*core_info = info; *core_info = info;
@ -2624,15 +2615,11 @@ core_updater_info_t *core_info_get_core_updater_info(
return NULL; return NULL;
/* Read config file */ /* Read config file */
conf = config_file_new_from_path_to_string(info_path); if (!(conf = config_file_new_from_path_to_string(info_path)))
if (!conf)
return NULL; return NULL;
/* Create info struct */ /* Create info struct */
info = (core_updater_info_t*)malloc(sizeof(*info)); if (!(info = (core_updater_info_t*)malloc(sizeof(*info))))
if (!info)
return NULL; return NULL;
info->is_experimental = false; info->is_experimental = false;
@ -2700,49 +2687,42 @@ void core_info_free_core_updater_info(core_updater_info_t *info)
static int core_info_qsort_func_path(const core_info_t *a, static int core_info_qsort_func_path(const core_info_t *a,
const core_info_t *b) const core_info_t *b)
{ {
if (!a || !b) if (!a || !b || string_is_empty(a->path) || string_is_empty(b->path))
return 0; return 0;
if (string_is_empty(a->path) || string_is_empty(b->path))
return 0;
return strcasecmp(a->path, b->path); return strcasecmp(a->path, b->path);
} }
static int core_info_qsort_func_display_name(const core_info_t *a, static int core_info_qsort_func_display_name(const core_info_t *a,
const core_info_t *b) const core_info_t *b)
{ {
if (!a || !b) if ( !a
return 0; || !b
|| string_is_empty(a->display_name)
if ( string_is_empty(a->display_name)
|| string_is_empty(b->display_name)) || string_is_empty(b->display_name))
return 0; return 0;
return strcasecmp(a->display_name, b->display_name); return strcasecmp(a->display_name, b->display_name);
} }
static int core_info_qsort_func_core_name(const core_info_t *a, static int core_info_qsort_func_core_name(const core_info_t *a,
const core_info_t *b) const core_info_t *b)
{ {
if (!a || !b) if ( !a
|| !b
|| string_is_empty(a->core_name)
|| string_is_empty(b->core_name))
return 0; return 0;
if (string_is_empty(a->core_name) || string_is_empty(b->core_name))
return 0;
return strcasecmp(a->core_name, b->core_name); return strcasecmp(a->core_name, b->core_name);
} }
static int core_info_qsort_func_system_name(const core_info_t *a, static int core_info_qsort_func_system_name(const core_info_t *a,
const core_info_t *b) const core_info_t *b)
{ {
if (!a || !b) if (
!a
|| !b
|| string_is_empty(a->systemname)
|| string_is_empty(b->systemname))
return 0; return 0;
if (string_is_empty(a->systemname) || string_is_empty(b->systemname))
return 0;
return strcasecmp(a->systemname, b->systemname); return strcasecmp(a->systemname, b->systemname);
} }
@ -2900,9 +2880,10 @@ bool core_info_set_core_lock(const char *core_path, bool lock)
#endif #endif
/* Search for specified core */ /* Search for specified core */
if (string_is_empty(core_path) || if (
!core_info_find(core_path, &core_info) || string_is_empty(core_path)
string_is_empty(core_info->path)) || !core_info_find(core_path, &core_info)
|| string_is_empty(core_info->path))
return false; return false;
/* Get lock file path */ /* Get lock file path */
@ -2994,10 +2975,10 @@ bool core_info_set_core_standalone_exempt(const char *core_path, bool exempt)
char exempt_file_path[PATH_MAX_LENGTH]; char exempt_file_path[PATH_MAX_LENGTH];
/* Search for specified core */ /* Search for specified core */
if (string_is_empty(core_path) || if ( string_is_empty(core_path)
!core_info_find(core_path, &core_info) || || !core_info_find(core_path, &core_info)
string_is_empty(core_info->path) || || string_is_empty(core_info->path)
!core_info->supports_no_game) || !core_info->supports_no_game)
return false; return false;
/* Get 'standalone exempt' file path */ /* Get 'standalone exempt' file path */
@ -3035,10 +3016,10 @@ bool core_info_get_core_standalone_exempt(const char *core_path)
char exempt_file_path[PATH_MAX_LENGTH]; char exempt_file_path[PATH_MAX_LENGTH];
/* Search for specified core */ /* Search for specified core */
if (string_is_empty(core_path) || if ( string_is_empty(core_path)
!core_info_find(core_path, &core_info) || || !core_info_find(core_path, &core_info)
string_is_empty(core_info->path) || || string_is_empty(core_info->path)
!core_info->supports_no_game) || !core_info->supports_no_game)
return false; return false;
/* Get 'standalone exempt' file path */ /* Get 'standalone exempt' file path */

View File

@ -70,9 +70,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v1(
return NULL; return NULL;
/* Allocate output retro_core_options_v2 struct */ /* Allocate output retro_core_options_v2 struct */
options_v2 = (struct retro_core_options_v2 *) if (!(options_v2 = (struct retro_core_options_v2 *)
malloc(sizeof(*options_v2)); malloc(sizeof(*options_v2))))
if (!options_v2)
return NULL; return NULL;
/* Note: v1 options have no concept of /* Note: v1 options have no concept of
@ -85,10 +84,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v1(
* > One extra entry required for terminating NULL entry * > One extra entry required for terminating NULL entry
* > Note that calloc() sets terminating NULL entry and * > Note that calloc() sets terminating NULL entry and
* correctly 'nullifies' each values array */ * correctly 'nullifies' each values array */
option_v2_defs = (struct retro_core_option_v2_definition *) if (!(option_v2_defs = (struct retro_core_option_v2_definition *)
calloc(num_options + 1, sizeof(*option_v2_defs)); calloc(num_options + 1, sizeof(*option_v2_defs))))
if (!option_v2_defs)
{ {
free(options_v2); free(options_v2);
return NULL; return NULL;
@ -103,7 +100,7 @@ struct retro_core_options_v2 *core_option_manager_convert_v1(
size_t num_values = 0; size_t num_values = 0;
/* Set key */ /* Set key */
option_v2_defs[i].key = options_v1[i].key; option_v2_defs[i].key = options_v1[i].key;
/* Set default value */ /* Set default value */
option_v2_defs[i].default_value = options_v1[i].default_value; option_v2_defs[i].default_value = options_v1[i].default_value;
@ -186,9 +183,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v1_intl(
return NULL; return NULL;
/* Allocate output retro_core_options_v2 struct */ /* Allocate output retro_core_options_v2 struct */
options_v2 = (struct retro_core_options_v2 *) if (!(options_v2 = (struct retro_core_options_v2 *)
malloc(sizeof(*options_v2)); malloc(sizeof(*options_v2))))
if (!options_v2)
return NULL; return NULL;
/* Note: v1 options have no concept of /* Note: v1 options have no concept of
@ -201,10 +197,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v1_intl(
* > One extra entry required for terminating NULL entry * > One extra entry required for terminating NULL entry
* > Note that calloc() sets terminating NULL entry and * > Note that calloc() sets terminating NULL entry and
* correctly 'nullifies' each values array */ * correctly 'nullifies' each values array */
option_v2_defs = (struct retro_core_option_v2_definition *) if (!(option_v2_defs = (struct retro_core_option_v2_definition *)
calloc(num_options + 1, sizeof(*option_v2_defs)); calloc(num_options + 1, sizeof(*option_v2_defs))))
if (!option_v2_defs)
{ {
core_option_manager_free_converted(options_v2); core_option_manager_free_converted(options_v2);
return NULL; return NULL;
@ -374,9 +368,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
return NULL; return NULL;
/* Allocate output retro_core_options_v2 struct */ /* Allocate output retro_core_options_v2 struct */
options_v2 = (struct retro_core_options_v2 *) if (!(options_v2 = (struct retro_core_options_v2 *)
malloc(sizeof(*options_v2)); malloc(sizeof(*options_v2))))
if (!options_v2)
return NULL; return NULL;
options_v2->categories = NULL; options_v2->categories = NULL;
@ -387,10 +380,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
* > Note that calloc() sets terminating NULL entry */ * > Note that calloc() sets terminating NULL entry */
if (num_categories > 0) if (num_categories > 0)
{ {
option_v2_cats = (struct retro_core_option_v2_category *) if (!(option_v2_cats = (struct retro_core_option_v2_category *)
calloc(num_categories + 1, sizeof(*option_v2_cats)); calloc(num_categories + 1, sizeof(*option_v2_cats))))
if (!option_v2_cats)
{ {
core_option_manager_free_converted(options_v2); core_option_manager_free_converted(options_v2);
return NULL; return NULL;
@ -403,10 +394,8 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
* > One extra entry required for terminating NULL entry * > One extra entry required for terminating NULL entry
* > Note that calloc() sets terminating NULL entry and * > Note that calloc() sets terminating NULL entry and
* correctly 'nullifies' each values array */ * correctly 'nullifies' each values array */
option_v2_defs = (struct retro_core_option_v2_definition *) if (!(option_v2_defs = (struct retro_core_option_v2_definition *)
calloc(num_options + 1, sizeof(*option_v2_defs)); calloc(num_options + 1, sizeof(*option_v2_defs))))
if (!option_v2_defs)
{ {
core_option_manager_free_converted(options_v2); core_option_manager_free_converted(options_v2);
return NULL; return NULL;
@ -741,8 +730,8 @@ static bool core_option_manager_parse_variable(
option->vals->elems[i].userdata = (void*)value_hash; option->vals->elems[i].userdata = (void*)value_hash;
/* Redundant safely check... */ /* Redundant safely check... */
value_label = string_is_empty(value_label) ? if (string_is_empty(value_label))
value : value_label; value_label = value;
/* Append value label string */ /* Append value label string */
string_list_append(option->val_labels, value_label, attr); string_list_append(option->val_labels, value_label, attr);
@ -819,9 +808,7 @@ core_option_manager_t *core_option_manager_new_vars(
if (!vars) if (!vars)
return NULL; return NULL;
opt = (core_option_manager_t*)malloc(sizeof(*opt)); if (!(opt = (core_option_manager_t*)malloc(sizeof(*opt))))
if (!opt)
return NULL; return NULL;
opt->conf = NULL; opt->conf = NULL;
@ -859,8 +846,7 @@ core_option_manager_t *core_option_manager_new_vars(
goto error; goto error;
/* Create options array */ /* Create options array */
opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts)); if (!(opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts))))
if (!opt->opts)
goto error; goto error;
opt->size = size; opt->size = size;
@ -1028,8 +1014,8 @@ static bool core_option_manager_parse_option(
value, value_label); value, value_label);
/* > Redundant safely check... */ /* > Redundant safely check... */
value_label = string_is_empty(value_label) ? if (string_is_empty(value_label))
value : value_label; value_label = value;
/* Append value label string */ /* Append value label string */
string_list_append(option->val_labels, value_label, attr); string_list_append(option->val_labels, value_label, attr);
@ -1113,9 +1099,7 @@ core_option_manager_t *core_option_manager_new(
option_cats = options_v2->categories; option_cats = options_v2->categories;
option_defs = options_v2->definitions; option_defs = options_v2->definitions;
opt = (core_option_manager_t*)malloc(sizeof(*opt)); if (!(opt = (core_option_manager_t*)malloc(sizeof(*opt))))
if (!opt)
return NULL; return NULL;
opt->conf = NULL; opt->conf = NULL;
@ -1166,8 +1150,8 @@ core_option_manager_t *core_option_manager_new(
/* Create categories array */ /* Create categories array */
if (cats_size > 0) if (cats_size > 0)
{ {
opt->cats = (struct core_catagory*)calloc(size, sizeof(*opt->cats)); if (!(opt->cats = (struct core_category*)calloc(size,
if (!opt->cats) sizeof(*opt->cats))))
goto error; goto error;
opt->cats_size = cats_size; opt->cats_size = cats_size;
@ -1190,8 +1174,7 @@ core_option_manager_t *core_option_manager_new(
} }
/* Create options array */ /* Create options array */
opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts)); if (!(opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts))))
if (!opt->opts)
goto error; goto error;
opt->size = size; opt->size = size;
@ -1338,21 +1321,21 @@ const char *core_option_manager_get_category_desc(core_option_manager_t *opt,
uint32_t key_hash; uint32_t key_hash;
size_t i; size_t i;
if (!opt || if ( !opt
string_is_empty(key)) || string_is_empty(key))
return NULL; return NULL;
key_hash = core_option_manager_hash_string(key); key_hash = core_option_manager_hash_string(key);
for (i = 0; i < opt->cats_size; i++) for (i = 0; i < opt->cats_size; i++)
{ {
struct core_catagory *catagory = &opt->cats[i]; struct core_category *category = &opt->cats[i];
if ((key_hash == catagory->key_hash) && if ((key_hash == category->key_hash) &&
!string_is_empty(catagory->key) && !string_is_empty(category->key) &&
string_is_equal(key, catagory->key)) string_is_equal(key, category->key))
{ {
return catagory->desc; return category->desc;
} }
} }
@ -1387,13 +1370,13 @@ const char *core_option_manager_get_category_info(core_option_manager_t *opt,
for (i = 0; i < opt->cats_size; i++) for (i = 0; i < opt->cats_size; i++)
{ {
struct core_catagory *catagory = &opt->cats[i]; struct core_category *category = &opt->cats[i];
if ((key_hash == catagory->key_hash) && if ((key_hash == category->key_hash) &&
!string_is_empty(catagory->key) && !string_is_empty(category->key) &&
string_is_equal(key, catagory->key)) string_is_equal(key, category->key))
{ {
return catagory->info; return category->info;
} }
} }
@ -1412,7 +1395,7 @@ const char *core_option_manager_get_category_info(core_option_manager_t *opt,
* be visible if at least one of the options * be visible if at least one of the options
* in the category is visible) * in the category is visible)
* *
* Returns: true if option category should be * @return true if option category should be
* displayed by the frontend, otherwise false. * displayed by the frontend, otherwise false.
**/ **/
bool core_option_manager_get_category_visible(core_option_manager_t *opt, bool core_option_manager_get_category_visible(core_option_manager_t *opt,
@ -1429,16 +1412,12 @@ bool core_option_manager_get_category_visible(core_option_manager_t *opt,
return false; return false;
/* Fetch category item from map */ /* Fetch category item from map */
category_item = nested_list_get_item(opt->option_map, if (!(category_item = nested_list_get_item(opt->option_map,
key, NULL); key, NULL)))
if (!category_item)
return false; return false;
/* Get child options of specified category */ /* Get child options of specified category */
option_list = nested_list_item_get_children(category_item); if (!(option_list = nested_list_item_get_children(category_item)))
if (!option_list)
return false; return false;
/* Loop over child options */ /* Loop over child options */
@ -1472,7 +1451,7 @@ bool core_option_manager_get_category_visible(core_option_manager_t *opt,
* Fetches the index of the core option identified * Fetches the index of the core option identified
* by the specified @key. * by the specified @key.
* *
* Returns: true if option matching the specified * @return true if option matching the specified
* key was found, otherwise false. * key was found, otherwise false.
**/ **/
bool core_option_manager_get_idx(core_option_manager_t *opt, bool core_option_manager_get_idx(core_option_manager_t *opt,
@ -1703,8 +1682,8 @@ const char *core_option_manager_get_val_label(core_option_manager_t *opt,
bool core_option_manager_get_visible(core_option_manager_t *opt, bool core_option_manager_get_visible(core_option_manager_t *opt,
size_t idx) size_t idx)
{ {
if (!opt || if ( !opt
(idx >= opt->size)) || (idx >= opt->size))
return false; return false;
return opt->opts[idx].visible; return opt->opts[idx].visible;

View File

@ -51,7 +51,7 @@ struct core_option
bool visible; bool visible;
}; };
struct core_catagory struct core_category
{ {
char *key; char *key;
char *desc; char *desc;
@ -68,7 +68,7 @@ struct core_option_manager
config_file_t *conf; config_file_t *conf;
char conf_path[PATH_MAX_LENGTH]; char conf_path[PATH_MAX_LENGTH];
struct core_catagory *cats; struct core_category *cats;
struct core_option *opts; struct core_option *opts;
nested_list_t *option_map; nested_list_t *option_map;
@ -252,7 +252,7 @@ const char *core_option_manager_get_category_info(core_option_manager_t *opt,
* be visible if at least one of the options * be visible if at least one of the options
* in the category is visible) * in the category is visible)
* *
* Returns: true if option category should be * @return true if option category should be
* displayed by the frontend, otherwise false. * displayed by the frontend, otherwise false.
**/ **/
bool core_option_manager_get_category_visible(core_option_manager_t *opt, bool core_option_manager_get_category_visible(core_option_manager_t *opt,
@ -274,7 +274,7 @@ bool core_option_manager_get_category_visible(core_option_manager_t *opt,
* Fetches the index of the core option identified * Fetches the index of the core option identified
* by the specified @key. * by the specified @key.
* *
* Returns: true if option matching the specified * @return true if option matching the specified
* key was found, otherwise false. * key was found, otherwise false.
**/ **/
bool core_option_manager_get_idx(core_option_manager_t *opt, bool core_option_manager_get_idx(core_option_manager_t *opt,

View File

@ -254,7 +254,12 @@ bool gfx_thumbnail_set_system(gfx_thumbnail_path_data_t *path_data,
/* Hack: There is only one MAME thumbnail repo, /* Hack: There is only one MAME thumbnail repo,
* so filter any input starting with 'MAME...' */ * so filter any input starting with 'MAME...' */
if (strncmp(system, "MAME", 4) == 0) if (strncmp(system, "MAME", 4) == 0)
strlcpy(path_data->system, "MAME", sizeof(path_data->system)); {
path_data->system[0] = path_data->system[2] = 'M';
path_data->system[1] = 'A';
path_data->system[3] = 'E';
path_data->system[4] = '\0';
}
else else
strlcpy(path_data->system, system, sizeof(path_data->system)); strlcpy(path_data->system, system, sizeof(path_data->system));
@ -508,8 +513,12 @@ bool gfx_thumbnail_set_content_playlist(
/* Hack: There is only one MAME thumbnail repo, /* Hack: There is only one MAME thumbnail repo,
* so filter any input starting with 'MAME...' */ * so filter any input starting with 'MAME...' */
if (strncmp(db_name, "MAME", 4) == 0) if (strncmp(db_name, "MAME", 4) == 0)
strlcpy(path_data->content_db_name, "MAME", {
sizeof(path_data->content_db_name)); path_data->content_db_name[0] = path_data->content_db_name[2] = 'M';
path_data->content_db_name[1] = 'A';
path_data->content_db_name[3] = 'E';
path_data->content_db_name[4] = '\0';
}
else else
{ {
char *db_name_no_ext = NULL; char *db_name_no_ext = NULL;