Cleanup input_remapping_load_file/input_remapping_save_file - none

of these huge char arrays were needed, wrong size being passed
to snprintf, fill_pathname_join, k loop variable unneeded, etc.
This commit is contained in:
twinaphex 2021-04-11 14:36:51 +02:00
parent d9cacc0b8c
commit 0087be2a53

View File

@ -4523,7 +4523,7 @@ bool config_replace(bool config_replace_save_on_exit, char *path)
**/
bool input_remapping_load_file(void *data, const char *path)
{
unsigned i, j, k;
unsigned i, j;
config_file_t *conf = (config_file_t*)data;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
@ -4533,7 +4533,7 @@ bool input_remapping_load_file(void *data, const char *path)
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
if (!conf || string_is_empty(path))
if (!conf || string_is_empty(path))
return false;
if (!string_is_empty(global->name.remapfile))
@ -4543,9 +4543,6 @@ bool input_remapping_load_file(void *data, const char *path)
for (i = 0; i < MAX_USERS; i++)
{
char s1[32], s2[32], s3[32];
char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[8][128] = {{0}};
old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i];
old_libretro_device[i] = settings->uints.input_libretro_device[i];
@ -4566,13 +4563,17 @@ bool input_remapping_load_file(void *data, const char *path)
{
int btn_remap = -1;
int key_remap = -1;
char btn_ident[128];
char key_ident[128];
btn_ident[0] = key_ident[0] = '\0';
fill_pathname_join_delim(btn_ident[j], s1,
key_string, '_', sizeof(btn_ident[j]));
fill_pathname_join_delim(key_ident[j], s2,
key_string, '_', sizeof(btn_ident[j]));
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
if (config_get_int(conf, btn_ident[j], &btn_remap))
if (config_get_int(conf, btn_ident, &btn_remap))
{
if (btn_remap == -1)
btn_remap = RARCH_UNMAPPED;
@ -4581,7 +4582,7 @@ bool input_remapping_load_file(void *data, const char *path)
settings->uints.input_remap_ids[i][j], btn_remap);
}
if (!config_get_int(conf, key_ident[j], &key_remap))
if (!config_get_int(conf, key_ident, &key_remap))
key_remap = RETROK_UNKNOWN;
configuration_set_uint(settings,
@ -4589,19 +4590,21 @@ bool input_remapping_load_file(void *data, const char *path)
}
else
{
char stk_ident[128];
int stk_remap = -1;
k = j - RARCH_FIRST_CUSTOM_BIND;
stk_ident[0] = '\0';
fill_pathname_join_delim(stk_ident[k], s3,
key_string, '$', sizeof(stk_ident[k]));
fill_pathname_join_delim(stk_ident, s3,
key_string, '$', sizeof(stk_ident));
snprintf(stk_ident[k],
sizeof(stk_ident[k]),
snprintf(stk_ident,
sizeof(stk_ident),
"%s_%s",
s3,
key_string);
if (config_get_int(conf, stk_ident[k], &stk_remap))
if (config_get_int(conf, stk_ident, &stk_remap))
{
if (stk_remap == -1)
stk_remap = RARCH_UNMAPPED;
@ -4633,7 +4636,7 @@ bool input_remapping_load_file(void *data, const char *path)
bool input_remapping_save_file(const char *path)
{
bool ret;
unsigned i, j, k;
unsigned i, j;
char buf[PATH_MAX_LENGTH];
char remap_file[PATH_MAX_LENGTH];
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] = {
@ -4661,9 +4664,6 @@ bool input_remapping_save_file(const char *path)
for (i = 0; i < max_users; i++)
{
char s1[32], s2[32], s3[32];
char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[8][128] = {{0}};
s1[0] = '\0';
s2[0] = '\0';
@ -4681,37 +4681,40 @@ bool input_remapping_save_file(const char *path)
if (j < RARCH_FIRST_CUSTOM_BIND)
{
fill_pathname_join_delim(btn_ident[j], s1,
key_string, '_', sizeof(btn_ident[j]));
fill_pathname_join_delim(key_ident[j], s2,
key_string, '_', sizeof(btn_ident[j]));
char btn_ident[128], key_ident[128];
btn_ident[0] = key_ident[0] = '\0';
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
key_string, '_', sizeof(key_ident));
/* only save values that have been modified */
if (remap_id != j && remap_id != RARCH_UNMAPPED)
config_set_int(conf, btn_ident[j],
config_set_int(conf, btn_ident,
settings->uints.input_remap_ids[i][j]);
else if (remap_id != j && remap_id == RARCH_UNMAPPED)
config_set_int(conf, btn_ident[j], -1);
config_set_int(conf, btn_ident, -1);
else
config_unset(conf, btn_ident[j]);
config_unset(conf, btn_ident);
if (keymap_id != RETROK_UNKNOWN)
config_set_int(conf, key_ident[j],
config_set_int(conf, key_ident,
settings->uints.input_keymapper_ids[i][j]);
}
else
{
k = j - RARCH_FIRST_CUSTOM_BIND;
fill_pathname_join_delim(stk_ident[k], s3,
key_string, '_', sizeof(stk_ident[k]));
char stk_ident[128];
stk_ident[0] = '\0';
fill_pathname_join_delim(stk_ident, s3,
key_string, '_', sizeof(stk_ident));
if (remap_id != j && remap_id != RARCH_UNMAPPED)
config_set_int(conf, stk_ident[k],
config_set_int(conf, stk_ident,
settings->uints.input_remap_ids[i][j]);
else if (remap_id != j && remap_id == RARCH_UNMAPPED)
config_set_int(conf, stk_ident[k],
config_set_int(conf, stk_ident,
-1);
else
config_unset(conf, stk_ident[k]);
config_unset(conf, stk_ident);
}
}