Rename core_option functions

This commit is contained in:
twinaphex 2016-05-10 01:21:55 +02:00
parent 3dc55d4e72
commit 2c6d6a223c
6 changed files with 125 additions and 122 deletions

View File

@ -46,66 +46,7 @@ struct core_option_manager
bool updated; bool updated;
}; };
/** static bool core_option_manager_parse_variable(core_option_manager_t *opt, size_t idx,
* core_option_free:
* @opt : options manager handle
*
* Frees core option manager handle.
**/
void core_option_free(core_option_manager_t *opt)
{
size_t i;
if (!opt)
return;
for (i = 0; i < opt->size; i++)
{
if (opt->opts[i].desc)
free(opt->opts[i].desc);
if (opt->opts[i].key)
free(opt->opts[i].key);
if (opt->opts[i].vals)
string_list_free(opt->opts[i].vals);
opt->opts[i].desc = NULL;
opt->opts[i].key = NULL;
opt->opts[i].vals = NULL;
}
if (opt->conf)
config_file_free(opt->conf);
free(opt->opts);
free(opt);
}
void core_option_get(core_option_manager_t *opt, void *data)
{
size_t i;
struct retro_variable *var = (struct retro_variable*)data;
if (!opt)
return;
opt->updated = false;
for (i = 0; i < opt->size; i++)
{
if (string_is_empty(opt->opts[i].key))
continue;
if (string_is_equal(opt->opts[i].key, var->key))
{
var->value = core_option_get_val(opt, i);
return;
}
}
var->value = NULL;
}
static bool parse_variable(core_option_manager_t *opt, size_t idx,
const struct retro_variable *var) const struct retro_variable *var)
{ {
const char *val_start = NULL; const char *val_start = NULL;
@ -161,7 +102,67 @@ static bool parse_variable(core_option_manager_t *opt, size_t idx,
} }
/** /**
* core_option_new: * core_option_manager_free:
* @opt : options manager handle
*
* Frees core option manager handle.
**/
void core_option_manager_free(core_option_manager_t *opt)
{
size_t i;
if (!opt)
return;
for (i = 0; i < opt->size; i++)
{
if (opt->opts[i].desc)
free(opt->opts[i].desc);
if (opt->opts[i].key)
free(opt->opts[i].key);
if (opt->opts[i].vals)
string_list_free(opt->opts[i].vals);
opt->opts[i].desc = NULL;
opt->opts[i].key = NULL;
opt->opts[i].vals = NULL;
}
if (opt->conf)
config_file_free(opt->conf);
free(opt->opts);
free(opt);
}
void core_option_manager_get(core_option_manager_t *opt, void *data)
{
size_t i;
struct retro_variable *var = (struct retro_variable*)data;
if (!opt)
return;
opt->updated = false;
for (i = 0; i < opt->size; i++)
{
if (string_is_empty(opt->opts[i].key))
continue;
if (string_is_equal(opt->opts[i].key, var->key))
{
var->value = core_option_manager_get_val(opt, i);
return;
}
}
var->value = NULL;
}
/**
* core_option_manager_new:
* @conf_path : Filesystem path to write core option config file to. * @conf_path : Filesystem path to write core option config file to.
* @vars : Pointer to variable array handle. * @vars : Pointer to variable array handle.
* *
@ -169,7 +170,7 @@ static bool parse_variable(core_option_manager_t *opt, size_t idx,
* *
* Returns: handle to new core manager handle, otherwise NULL. * Returns: handle to new core manager handle, otherwise NULL.
**/ **/
core_option_manager_t *core_option_new(const char *conf_path, core_option_manager_t *core_option_manager_new(const char *conf_path,
const void *data) const void *data)
{ {
const struct retro_variable *var; const struct retro_variable *var;
@ -203,19 +204,19 @@ core_option_manager_t *core_option_new(const char *conf_path,
for (var = vars; var->key && var->value; size++, var++) for (var = vars; var->key && var->value; size++, var++)
{ {
if (!parse_variable(opt, size, var)) if (!core_option_manager_parse_variable(opt, size, var))
goto error; goto error;
} }
return opt; return opt;
error: error:
core_option_free(opt); core_option_manager_free(opt);
return NULL; return NULL;
} }
/** /**
* core_option_updated: * core_option_manager_updated:
* @opt : options manager handle * @opt : options manager handle
* *
* Has a core option been updated? * Has a core option been updated?
@ -223,7 +224,7 @@ error:
* Returns: true (1) if a core option has been updated, * Returns: true (1) if a core option has been updated,
* otherwise false (0). * otherwise false (0).
**/ **/
bool core_option_updated(core_option_manager_t *opt) bool core_option_manager_updated(core_option_manager_t *opt)
{ {
if (!opt) if (!opt)
return false; return false;
@ -231,7 +232,7 @@ bool core_option_updated(core_option_manager_t *opt)
} }
/** /**
* core_option_flush: * core_option_manager_flush:
* @opt : options manager handle * @opt : options manager handle
* *
* Writes core option key-pair values to file. * Writes core option key-pair values to file.
@ -239,7 +240,7 @@ bool core_option_updated(core_option_manager_t *opt)
* Returns: true (1) if core option values could be * Returns: true (1) if core option values could be
* successfully saved to disk, otherwise false (0). * successfully saved to disk, otherwise false (0).
**/ **/
bool core_option_flush(core_option_manager_t *opt) bool core_option_manager_flush(core_option_manager_t *opt)
{ {
size_t i; size_t i;
@ -248,14 +249,15 @@ bool core_option_flush(core_option_manager_t *opt)
struct core_option *option = (struct core_option*)&opt->opts[i]; struct core_option *option = (struct core_option*)&opt->opts[i];
if (option) if (option)
config_set_string(opt->conf, option->key, core_option_get_val(opt, i)); config_set_string(opt->conf, option->key,
core_option_manager_get_val(opt, i));
} }
return config_file_write(opt->conf, opt->conf_path); return config_file_write(opt->conf, opt->conf_path);
} }
/** /**
* core_option_flush_game_specific: * core_option_manager_flush_game_specific:
* @opt : options manager handle * @opt : options manager handle
* @path : path for the core options file * @path : path for the core options file
* *
@ -264,7 +266,7 @@ bool core_option_flush(core_option_manager_t *opt)
* Returns: true (1) if core option values could be * Returns: true (1) if core option values could be
* successfully saved to disk, otherwise false (0). * successfully saved to disk, otherwise false (0).
**/ **/
bool core_option_flush_game_specific(core_option_manager_t *opt, char* path) bool core_option_manager_flush_game_specific(core_option_manager_t *opt, char* path)
{ {
size_t i; size_t i;
for (i = 0; i < opt->size; i++) for (i = 0; i < opt->size; i++)
@ -272,21 +274,22 @@ bool core_option_flush_game_specific(core_option_manager_t *opt, char* path)
struct core_option *option = (struct core_option*)&opt->opts[i]; struct core_option *option = (struct core_option*)&opt->opts[i];
if (option) if (option)
config_set_string(opt->conf, option->key, core_option_get_val(opt, i)); config_set_string(opt->conf, option->key,
core_option_manager_get_val(opt, i));
} }
return config_file_write(opt->conf, path); return config_file_write(opt->conf, path);
} }
/** /**
* core_option_size: * core_option_manager_size:
* @opt : options manager handle * @opt : options manager handle
* *
* Gets total number of options. * Gets total number of options.
* *
* Returns: Total number of options. * Returns: Total number of options.
**/ **/
size_t core_option_size(core_option_manager_t *opt) size_t core_option_manager_size(core_option_manager_t *opt)
{ {
if (!opt) if (!opt)
return 0; return 0;
@ -294,7 +297,7 @@ size_t core_option_size(core_option_manager_t *opt)
} }
/** /**
* core_option_get_desc: * core_option_manager_get_desc:
* @opt : options manager handle * @opt : options manager handle
* @index : index identifier of the option * @index : index identifier of the option
* *
@ -302,7 +305,7 @@ size_t core_option_size(core_option_manager_t *opt)
* *
* Returns: Description for an option. * Returns: Description for an option.
**/ **/
const char *core_option_get_desc(core_option_manager_t *opt, size_t idx) const char *core_option_manager_get_desc(core_option_manager_t *opt, size_t idx)
{ {
if (!opt) if (!opt)
return NULL; return NULL;
@ -310,7 +313,7 @@ const char *core_option_get_desc(core_option_manager_t *opt, size_t idx)
} }
/** /**
* core_option_get_val: * core_option_manager_get_val:
* @opt : options manager handle * @opt : options manager handle
* @index : index identifier of the option * @index : index identifier of the option
* *
@ -318,7 +321,7 @@ const char *core_option_get_desc(core_option_manager_t *opt, size_t idx)
* *
* Returns: Value for an option. * Returns: Value for an option.
**/ **/
const char *core_option_get_val(core_option_manager_t *opt, size_t idx) const char *core_option_manager_get_val(core_option_manager_t *opt, size_t idx)
{ {
struct core_option *option = NULL; struct core_option *option = NULL;
if (!opt) if (!opt)
@ -329,7 +332,7 @@ const char *core_option_get_val(core_option_manager_t *opt, size_t idx)
return option->vals->elems[option->index].data; return option->vals->elems[option->index].data;
} }
void core_option_set_val(core_option_manager_t *opt, void core_option_manager_set_val(core_option_manager_t *opt,
size_t idx, size_t val_idx) size_t idx, size_t val_idx)
{ {
struct core_option *option= NULL; struct core_option *option= NULL;
@ -347,14 +350,14 @@ void core_option_set_val(core_option_manager_t *opt,
} }
/** /**
* core_option_next: * core_option_manager_next:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : index of core option to be reset to defaults. * @idx : index of core option to be reset to defaults.
* *
* Get next value for core option specified by @idx. * Get next value for core option specified by @idx.
* Options wrap around. * Options wrap around.
**/ **/
void core_option_next(core_option_manager_t *opt, size_t idx) void core_option_manager_next(core_option_manager_t *opt, size_t idx)
{ {
struct core_option *option = NULL; struct core_option *option = NULL;
@ -371,7 +374,7 @@ void core_option_next(core_option_manager_t *opt, size_t idx)
} }
/** /**
* core_option_prev: * core_option_manager_prev:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : index of core option to be reset to defaults. * @idx : index of core option to be reset to defaults.
* Options wrap around. * Options wrap around.
@ -379,7 +382,7 @@ void core_option_next(core_option_manager_t *opt, size_t idx)
* Get previous value for core option specified by @idx. * Get previous value for core option specified by @idx.
* Options wrap around. * Options wrap around.
**/ **/
void core_option_prev(core_option_manager_t *opt, size_t idx) void core_option_manager_prev(core_option_manager_t *opt, size_t idx)
{ {
struct core_option *option = NULL; struct core_option *option = NULL;
@ -397,13 +400,13 @@ void core_option_prev(core_option_manager_t *opt, size_t idx)
} }
/** /**
* core_option_set_default: * core_option_manager_set_default:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : index of core option to be reset to defaults. * @idx : index of core option to be reset to defaults.
* *
* Reset core option specified by @idx and sets default value for option. * Reset core option specified by @idx and sets default value for option.
**/ **/
void core_option_set_default(core_option_manager_t *opt, size_t idx) void core_option_manager_set_default(core_option_manager_t *opt, size_t idx)
{ {
if (!opt) if (!opt)
return; return;

View File

@ -28,7 +28,7 @@ extern "C" {
typedef struct core_option_manager core_option_manager_t; typedef struct core_option_manager core_option_manager_t;
/** /**
* core_option_new: * core_option_manager_new:
* @conf_path : Filesystem path to write core option config file to. * @conf_path : Filesystem path to write core option config file to.
* @vars : Pointer to variable array handle. * @vars : Pointer to variable array handle.
* *
@ -36,11 +36,11 @@ typedef struct core_option_manager core_option_manager_t;
* *
* Returns: handle to new core manager handle, otherwise NULL. * Returns: handle to new core manager handle, otherwise NULL.
**/ **/
core_option_manager_t *core_option_new(const char *conf_path, core_option_manager_t *core_option_manager_new(const char *conf_path,
const void *data); const void *data);
/** /**
* core_option_updated: * core_option_manager_updated:
* @opt : options manager handle * @opt : options manager handle
* *
* Has a core option been updated? * Has a core option been updated?
@ -48,10 +48,10 @@ core_option_manager_t *core_option_new(const char *conf_path,
* Returns: true (1) if a core option has been updated, * Returns: true (1) if a core option has been updated,
* otherwise false (0). * otherwise false (0).
**/ **/
bool core_option_updated(core_option_manager_t *opt); bool core_option_manager_updated(core_option_manager_t *opt);
/** /**
* core_option_flush: * core_option_manager_flush:
* @opt : options manager handle * @opt : options manager handle
* *
* Writes core option key-pair values to file. * Writes core option key-pair values to file.
@ -59,10 +59,10 @@ bool core_option_updated(core_option_manager_t *opt);
* Returns: true (1) if core option values could be * Returns: true (1) if core option values could be
* successfully saved to disk, otherwise false (0). * successfully saved to disk, otherwise false (0).
**/ **/
bool core_option_flush(core_option_manager_t *opt); bool core_option_manager_flush(core_option_manager_t *opt);
/** /**
* core_option_flush_game_specific: * core_option_manager_flush_game_specific:
* @opt : options manager handle * @opt : options manager handle
* @path : path for the core options file * @path : path for the core options file
* *
@ -71,31 +71,31 @@ bool core_option_flush(core_option_manager_t *opt);
* Returns: true (1) if core option values could be * Returns: true (1) if core option values could be
* successfully saved to disk, otherwise false (0). * successfully saved to disk, otherwise false (0).
**/ **/
bool core_option_flush_game_specific( bool core_option_manager_flush_game_specific(
core_option_manager_t *opt, char* path); core_option_manager_t *opt, char* path);
/** /**
* core_option_free: * core_option_manager_free:
* @opt : options manager handle * @opt : options manager handle
* *
* Frees core option manager handle. * Frees core option manager handle.
**/ **/
void core_option_free(core_option_manager_t *opt); void core_option_manager_free(core_option_manager_t *opt);
void core_option_get(core_option_manager_t *opt, void *data); void core_option_manager_get(core_option_manager_t *opt, void *data);
/** /**
* core_option_size: * core_option_manager_size:
* @opt : options manager handle * @opt : options manager handle
* *
* Gets total number of options. * Gets total number of options.
* *
* Returns: Total number of options. * Returns: Total number of options.
**/ **/
size_t core_option_size(core_option_manager_t *opt); size_t core_option_manager_size(core_option_manager_t *opt);
/** /**
* core_option_get_desc: * core_option_manager_get_desc:
* @opt : options manager handle * @opt : options manager handle
* @idx : idx identifier of the option * @idx : idx identifier of the option
* *
@ -103,11 +103,11 @@ size_t core_option_size(core_option_manager_t *opt);
* *
* Returns: Description for an option. * Returns: Description for an option.
**/ **/
const char *core_option_get_desc(core_option_manager_t *opt, const char *core_option_manager_get_desc(core_option_manager_t *opt,
size_t idx); size_t idx);
/** /**
* core_option_get_val: * core_option_manager_get_val:
* @opt : options manager handle * @opt : options manager handle
* @idx : idx identifier of the option * @idx : idx identifier of the option
* *
@ -115,24 +115,24 @@ const char *core_option_get_desc(core_option_manager_t *opt,
* *
* Returns: Value for an option. * Returns: Value for an option.
**/ **/
const char *core_option_get_val(core_option_manager_t *opt, const char *core_option_manager_get_val(core_option_manager_t *opt,
size_t idx); size_t idx);
void core_option_set_val(core_option_manager_t *opt, void core_option_manager_set_val(core_option_manager_t *opt,
size_t idx, size_t val_idx); size_t idx, size_t val_idx);
/** /**
* core_option_next: * core_option_manager_next:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : idx of core option to be reset to defaults. * @idx : idx of core option to be reset to defaults.
* *
* Get next value for core option specified by @idx. * Get next value for core option specified by @idx.
* Options wrap around. * Options wrap around.
**/ **/
void core_option_next(core_option_manager_t *opt, size_t idx); void core_option_manager_next(core_option_manager_t *opt, size_t idx);
/** /**
* core_option_prev: * core_option_manager_prev:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : idx of core option to be reset to defaults. * @idx : idx of core option to be reset to defaults.
* Options wrap around. * Options wrap around.
@ -140,16 +140,16 @@ void core_option_next(core_option_manager_t *opt, size_t idx);
* Get previous value for core option specified by @idx. * Get previous value for core option specified by @idx.
* Options wrap around. * Options wrap around.
**/ **/
void core_option_prev(core_option_manager_t *opt, size_t idx); void core_option_manager_prev(core_option_manager_t *opt, size_t idx);
/** /**
* core_option_set_default: * core_option_manager_set_default:
* @opt : pointer to core option manager object. * @opt : pointer to core option manager object.
* @idx : idx of core option to be reset to defaults. * @idx : idx of core option to be reset to defaults.
* *
* Reset core option specified by @idx and sets default value for option. * Reset core option specified by @idx and sets default value for option.
**/ **/
void core_option_set_default(core_option_manager_t *opt, size_t idx); void core_option_manager_set_default(core_option_manager_t *opt, size_t idx);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1258,7 +1258,7 @@ static void menu_action_setting_disp_set_label(file_list_t* list,
if (runloop_ctl(RUNLOOP_CTL_COREOPTS_GET, &coreopts)) if (runloop_ctl(RUNLOOP_CTL_COREOPTS_GET, &coreopts))
{ {
core_opt = core_option_get_val(coreopts, core_opt = core_option_manager_get_val(coreopts,
type - MENU_SETTINGS_CORE_OPTION_START); type - MENU_SETTINGS_CORE_OPTION_START);
strlcpy(s, "", len); strlcpy(s, "", len);

View File

@ -259,7 +259,7 @@ static int action_start_core_setting(unsigned type,
core_option_manager_t *coreopts = NULL; core_option_manager_t *coreopts = NULL;
if (runloop_ctl(RUNLOOP_CTL_COREOPTS_GET, &coreopts)) if (runloop_ctl(RUNLOOP_CTL_COREOPTS_GET, &coreopts))
core_option_set_default(coreopts, idx); core_option_manager_set_default(coreopts, idx);
return 0; return 0;
} }

View File

@ -3934,7 +3934,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
for (i = 0; i < opts; i++) for (i = 0; i < opts; i++)
menu_entries_add(info->list, menu_entries_add(info->list,
core_option_get_desc(coreopts, i), "", core_option_manager_get_desc(coreopts, i), "",
MENU_SETTINGS_CORE_OPTION_START + i, 0, 0); MENU_SETTINGS_CORE_OPTION_START + i, 0, 0);
} }
} }

View File

@ -672,7 +672,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
unsigned *idx = (unsigned*)data; unsigned *idx = (unsigned*)data;
if (!idx) if (!idx)
return false; return false;
*idx = core_option_size(runloop_core_options); *idx = core_option_manager_size(runloop_core_options);
} }
break; break;
case RUNLOOP_CTL_HAS_CORE_OPTIONS: case RUNLOOP_CTL_HAS_CORE_OPTIONS:
@ -1076,13 +1076,13 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED: case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED:
if (!runloop_core_options) if (!runloop_core_options)
return false; return false;
return core_option_updated(runloop_core_options); return core_option_manager_updated(runloop_core_options);
case RUNLOOP_CTL_CORE_OPTION_PREV: case RUNLOOP_CTL_CORE_OPTION_PREV:
{ {
unsigned *idx = (unsigned*)data; unsigned *idx = (unsigned*)data;
if (!idx) if (!idx)
return false; return false;
core_option_prev(runloop_core_options, *idx); core_option_manager_prev(runloop_core_options, *idx);
if (ui_companion_is_on_foreground()) if (ui_companion_is_on_foreground())
ui_companion_driver_notify_refresh(); ui_companion_driver_notify_refresh();
} }
@ -1092,7 +1092,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
unsigned *idx = (unsigned*)data; unsigned *idx = (unsigned*)data;
if (!idx) if (!idx)
return false; return false;
core_option_next(runloop_core_options, *idx); core_option_manager_next(runloop_core_options, *idx);
if (ui_companion_is_on_foreground()) if (ui_companion_is_on_foreground())
ui_companion_driver_notify_refresh(); ui_companion_driver_notify_refresh();
} }
@ -1105,7 +1105,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
return false; return false;
RARCH_LOG("Environ GET_VARIABLE %s:\n", var->key); RARCH_LOG("Environ GET_VARIABLE %s:\n", var->key);
core_option_get(runloop_core_options, var); core_option_manager_get(runloop_core_options, var);
RARCH_LOG("\t%s\n", var->value ? var->value : "N/A"); RARCH_LOG("\t%s\n", var->value ? var->value : "N/A");
} }
break; break;
@ -1134,21 +1134,21 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
{ {
runloop_ctl(RUNLOOP_CTL_SET_GAME_OPTIONS_ACTIVE, NULL); runloop_ctl(RUNLOOP_CTL_SET_GAME_OPTIONS_ACTIVE, NULL);
runloop_core_options = runloop_core_options =
core_option_new(game_options_path, vars); core_option_manager_new(game_options_path, vars);
free(game_options_path); free(game_options_path);
} }
else else
{ {
runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL); runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL);
runloop_core_options = runloop_core_options =
core_option_new(options_path, vars); core_option_manager_new(options_path, vars);
} }
} }
break; break;
case RUNLOOP_CTL_CORE_OPTIONS_FREE: case RUNLOOP_CTL_CORE_OPTIONS_FREE:
if (runloop_core_options) if (runloop_core_options)
core_option_free(runloop_core_options); core_option_manager_free(runloop_core_options);
runloop_core_options = NULL; runloop_core_options = NULL;
break; break;
case RUNLOOP_CTL_CORE_OPTIONS_DEINIT: case RUNLOOP_CTL_CORE_OPTIONS_DEINIT:
@ -1161,12 +1161,12 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
to that file instead */ to that file instead */
if(global && !string_is_empty(global->path.core_options_path)) if(global && !string_is_empty(global->path.core_options_path))
{ {
core_option_flush_game_specific(runloop_core_options, core_option_manager_flush_game_specific(runloop_core_options,
global->path.core_options_path); global->path.core_options_path);
global->path.core_options_path[0] = '\0'; global->path.core_options_path[0] = '\0';
} }
else else
core_option_flush(runloop_core_options); core_option_manager_flush(runloop_core_options);
if (runloop_ctl(RUNLOOP_CTL_IS_GAME_OPTIONS_ACTIVE, NULL)) if (runloop_ctl(RUNLOOP_CTL_IS_GAME_OPTIONS_ACTIVE, NULL))
runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL); runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL);