mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 08:30:16 +00:00
(core_options.c) Cleanups
This commit is contained in:
parent
ff3367d807
commit
13c9c13f00
@ -43,6 +43,7 @@ struct core_option_manager
|
||||
void core_option_free(core_option_manager_t *opt)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
@ -62,10 +63,12 @@ void core_option_free(core_option_manager_t *opt)
|
||||
void core_option_get(core_option_manager_t *opt, struct retro_variable *var)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
opt->updated = false;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
if (strcmp(opt->opts[i].key, var->key) == 0)
|
||||
if (!strcmp(opt->opts[i].key, var->key))
|
||||
{
|
||||
var->value = core_option_get_val(opt, i);
|
||||
return;
|
||||
@ -78,18 +81,17 @@ void core_option_get(core_option_manager_t *opt, struct retro_variable *var)
|
||||
static bool parse_variable(core_option_manager_t *opt, size_t idx,
|
||||
const struct retro_variable *var)
|
||||
{
|
||||
char *value, *desc_end, *config_val = NULL;
|
||||
const char *val_start;
|
||||
size_t i;
|
||||
const char *val_start;
|
||||
char *value, *desc_end, *config_val = NULL;
|
||||
struct core_option *option = (struct core_option*)&opt->opts[idx];
|
||||
|
||||
if (!option)
|
||||
return false;
|
||||
|
||||
option->key = strdup(var->key);
|
||||
|
||||
value = strdup(var->value);
|
||||
desc_end = strstr(value, "; ");
|
||||
value = strdup(var->value);
|
||||
desc_end = strstr(value, "; ");
|
||||
|
||||
if (!desc_end)
|
||||
{
|
||||
@ -97,10 +99,10 @@ static bool parse_variable(core_option_manager_t *opt, size_t idx,
|
||||
return false;
|
||||
}
|
||||
|
||||
*desc_end = '\0';
|
||||
*desc_end = '\0';
|
||||
option->desc = strdup(value);
|
||||
|
||||
val_start = desc_end + 2;
|
||||
val_start = desc_end + 2;
|
||||
option->vals = string_split(val_start, "|");
|
||||
|
||||
if (!option->vals)
|
||||
@ -238,6 +240,16 @@ const char *core_option_get_val(core_option_manager_t *opt, size_t idx)
|
||||
return option->vals->elems[option->index].data;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_get_vals:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : idx of core option.
|
||||
*
|
||||
* Gets list of core option values from core option at index @idx.
|
||||
*
|
||||
* Returns: string list of core option values if successful, otherwise
|
||||
* NULL.
|
||||
**/
|
||||
struct string_list *core_option_get_vals(
|
||||
core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
@ -255,7 +267,7 @@ void core_option_set_val(core_option_manager_t *opt,
|
||||
return;
|
||||
|
||||
option->index = val_idx % option->vals->size;
|
||||
opt->updated = true;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,7 +286,7 @@ void core_option_next(core_option_manager_t *opt, size_t idx)
|
||||
return;
|
||||
|
||||
option->index = (option->index + 1) % option->vals->size;
|
||||
opt->updated = true;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,7 +307,7 @@ void core_option_prev(core_option_manager_t *opt, size_t idx)
|
||||
|
||||
option->index = (option->index + option->vals->size - 1) %
|
||||
option->vals->size;
|
||||
opt->updated = true;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,5 +323,5 @@ void core_option_set_default(core_option_manager_t *opt, size_t idx)
|
||||
return;
|
||||
|
||||
opt->opts[idx].index = 0;
|
||||
opt->updated = true;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <boolean.h>
|
||||
#include "libretro.h"
|
||||
#include <stddef.h>
|
||||
#include <string/string_list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -51,61 +52,70 @@ size_t core_option_size(core_option_manager_t *opt);
|
||||
/**
|
||||
* core_option_get_desc:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
* @idx : idx identifier of the option
|
||||
*
|
||||
* Gets description for an option.
|
||||
*
|
||||
* Returns: Description for an option.
|
||||
**/
|
||||
const char *core_option_get_desc(core_option_manager_t *opt, size_t index);
|
||||
const char *core_option_get_desc(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_get_val:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
* @idx : idx identifier of the option
|
||||
*
|
||||
* Gets value for an option.
|
||||
*
|
||||
* Returns: Value for an option.
|
||||
**/
|
||||
const char *core_option_get_val(core_option_manager_t *opt, size_t index);
|
||||
const char *core_option_get_val(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/* Helpers to present a list of options */
|
||||
/**
|
||||
* core_option_get_vals:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : idx of core option.
|
||||
*
|
||||
* Gets list of core option values from core option at index @idx.
|
||||
*
|
||||
* Returns: string list of core option values if successful, otherwise
|
||||
* NULL.
|
||||
**/
|
||||
struct string_list *core_option_get_vals(
|
||||
core_option_manager_t *opt, size_t index);
|
||||
core_option_manager_t *opt, size_t idx);
|
||||
|
||||
void core_option_set_val(core_option_manager_t *opt,
|
||||
size_t index, size_t val_index);
|
||||
size_t idx, size_t val_idx);
|
||||
|
||||
/**
|
||||
* core_option_next:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index 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.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_next(core_option_manager_t *opt, size_t index);
|
||||
void core_option_next(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_prev:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
* @idx : idx of core option to be reset to defaults.
|
||||
* Options wrap around.
|
||||
*
|
||||
* Get previous value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_prev(core_option_manager_t *opt, size_t index);
|
||||
void core_option_prev(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_set_default:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index 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.
|
||||
**/
|
||||
void core_option_set_default(core_option_manager_t *opt, size_t index);
|
||||
void core_option_set_default(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user