From b51bb2bc66f65fcbdf0b649657fb5271ad1ffe17 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 Mar 2021 13:24:10 +0100 Subject: [PATCH] Simplify parse_hat function --- retroarch.c | 73 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/retroarch.c b/retroarch.c index 2a53cbf4c6..602fb891e5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -25951,48 +25951,40 @@ unsigned input_config_translate_str_to_bind_id(const char *str) return RARCH_BIND_LIST_END; } -static void parse_hat(struct retro_keybind *bind, const char *str) +static uint16_t input_config_parse_hat(const char *dir) { - uint16_t hat_dir = 0; - char *dir = NULL; - uint16_t hat = strtoul(str, &dir, 0); - - if (!dir) - { - RARCH_WARN("[Input]: Found invalid hat in config!\n"); - return; - } - if ( dir[0] == 'u' && dir[1] == 'p' && dir[2] == '\0' ) - hat_dir = HAT_UP_MASK; - else if ( dir[0] == 'd' - && dir[1] == 'o' - && dir[2] == 'w' - && dir[3] == 'n' - && dir[4] == '\0' - ) - hat_dir = HAT_DOWN_MASK; - else if ( dir[0] == 'l' - && dir[1] == 'e' - && dir[2] == 'f' - && dir[3] == 't' - && dir[4] == '\0' - ) - hat_dir = HAT_LEFT_MASK; - else if ( dir[0] == 'r' - && dir[1] == 'i' - && dir[2] == 'g' - && dir[3] == 'h' - && dir[4] == 't' - && dir[5] == '\0' - ) - hat_dir = HAT_RIGHT_MASK; + return HAT_UP_MASK; + else if ( + dir[0] == 'd' + && dir[1] == 'o' + && dir[2] == 'w' + && dir[3] == 'n' + && dir[4] == '\0' + ) + return HAT_DOWN_MASK; + else if ( + dir[0] == 'l' + && dir[1] == 'e' + && dir[2] == 'f' + && dir[3] == 't' + && dir[4] == '\0' + ) + return HAT_LEFT_MASK; + else if ( + dir[0] == 'r' + && dir[1] == 'i' + && dir[2] == 'g' + && dir[3] == 'h' + && dir[4] == 't' + && dir[5] == '\0' + ) + return HAT_RIGHT_MASK; - if (hat_dir) - bind->joykey = HAT_MAP(hat, hat_dir); + return 0; } static void input_config_parse_joy_button( @@ -26028,8 +26020,15 @@ static void input_config_parse_joy_button( if (*btn == 'h') { const char *str = btn + 1; + /* Parse hat? */ if (str && ISDIGIT((int)*str)) - parse_hat(bind, str); + { + char *dir = NULL; + uint16_t hat = strtoul(str, &dir, 0); + uint16_t hat_dir = dir ? input_config_parse_hat(dir) : 0; + if (hat_dir) + bind->joykey = HAT_MAP(hat, hat_dir); + } } else bind->joykey = strtoull(tmp, NULL, 0);