From 99fcc63b3896cc917584c2b52fb6f29bb1a21023 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 26 Nov 2017 06:12:51 +0100 Subject: [PATCH] Cut down on code duplication --- menu/cbs/menu_cbs_ok.c | 149 +++++++++++------------------------------ 1 file changed, 40 insertions(+), 109 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index bea7d7aa28..92671dcb5e 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1996,117 +1996,48 @@ static void menu_input_st_string_cb_cheat_file_save_as( menu_input_dialog_end(); } -static int action_ok_shader_preset_save_as(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_PRESET_FILENAME); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)idx; - line.cb = menu_input_st_string_cb_save_preset; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; +#define default_action_dialog_start(funcname, _label_setting, _idx, _cb) \ +static int (funcname)(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) \ +{ \ + menu_input_ctx_line_t line; \ + line.label = label; \ + line.label_setting = _label_setting; \ + line.type = type; \ + line.idx = (_idx); \ + line.cb = _cb; \ + if (!menu_input_dialog_start(&line)) \ + return -1; \ + return 0; \ } -static int action_ok_enable_settings(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_ENABLE_SETTINGS_PASSWORD); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)entry_idx; - line.cb = menu_input_st_string_cb_enable_settings; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} - -static int action_ok_wifi(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = "Passphrase"; - line.label_setting = label; - line.type = type; - line.idx = (unsigned)idx; - line.cb = menu_input_wifi_cb; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} - -static int action_ok_cheat_file_save_as(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_CHEAT_FILENAME); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)idx; - line.cb = menu_input_st_string_cb_cheat_file_save_as; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} - -static int action_ok_cheat(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_CHEAT); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)idx; - line.cb = menu_input_st_cheat_cb; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} - -static int action_ok_disable_kiosk_mode(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_KIOSK_MODE_PASSWORD); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)entry_idx; - line.cb = menu_input_st_string_cb_disable_kiosk_mode; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} - -static int action_ok_rename_entry(const char *path, - const char *label, unsigned type, size_t idx, size_t entry_idx) -{ - menu_input_ctx_line_t line; - - line.label = msg_hash_to_str(MSG_INPUT_RENAME_ENTRY); - line.label_setting = label; - line.type = type; - line.idx = (unsigned)entry_idx; - line.cb = menu_input_st_string_cb_rename_entry; - - if (!menu_input_dialog_start(&line)) - return -1; - return 0; -} +default_action_dialog_start(action_ok_shader_preset_save_as, + msg_hash_to_str(MSG_INPUT_PRESET_FILENAME), + (unsigned)idx, + menu_input_st_string_cb_save_preset) +default_action_dialog_start(action_ok_enable_settings, + msg_hash_to_str(MSG_INPUT_ENABLE_SETTINGS_PASSWORD), + (unsigned)entry_idx, + menu_input_st_string_cb_enable_settings) +default_action_dialog_start(action_ok_wifi, + "Passphrase", + (unsigned)idx, + menu_input_wifi_cb) +default_action_dialog_start(action_ok_cheat_file_save_as, + msg_hash_to_str(MSG_INPUT_CHEAT_FILENAME), + (unsigned)idx, + menu_input_st_string_cb_cheat_file_save_as) +default_action_dialog_start(action_ok_cheat, + msg_hash_to_str(MSG_INPUT_CHEAT), + (unsigned)idx, + menu_input_st_cheat_cb) +default_action_dialog_start(action_ok_disable_kiosk_mode, + msg_hash_to_str(MSG_INPUT_KIOSK_MODE_PASSWORD), + (unsigned)entry_idx, + menu_input_st_string_cb_disable_kiosk_mode) +default_action_dialog_start(action_ok_rename_entry, + msg_hash_to_str(MSG_INPUT_RENAME_ENTRY), + (unsigned)entry_idx, + menu_input_st_string_cb_rename_entry) enum {