From b9aac28ccccf1f50e99f093b5627ce0e562dc859 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 9 Apr 2014 22:05:31 +0100 Subject: [PATCH] Refactored invalid command usage --- src/command/command.c | 14 +------------- src/ui/core.c | 19 +++++++++++++++++++ src/ui/ui.h | 2 ++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 8b4a936d..4174f8a8 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1252,19 +1252,7 @@ cmd_execute(const char * const command, const char * const inp) if (cmd != NULL) { gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); if (result == FALSE) { - if (cmd->setting_func != NULL) { - cons_show(""); - (*cmd->setting_func)(); - cons_show("Usage: %s", cmd->help.usage); - } else { - cons_show(""); - cons_show("Usage: %s", cmd->help.usage); - if (ui_current_win_type() == WIN_CHAT) { - char usage[strlen(cmd->help.usage) + 8]; - sprintf(usage, "Usage: %s", cmd->help.usage); - ui_current_print_line(usage); - } - } + ui_invalid_command_usage(cmd->help.usage, cmd->setting_func); return TRUE; } else { gboolean result = cmd->func(args, cmd->help); diff --git a/src/ui/core.c b/src/ui/core.c index eaa0af48..569425f9 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -520,6 +520,24 @@ _ui_handle_error(const char * const err_msg) g_string_free(msg, TRUE); } +static void +_ui_invalid_command_usage(const char * const usage, void (**setting_func)(void)) +{ + if (setting_func != NULL) { + cons_show(""); + (*setting_func)(); + cons_show("Usage: %s", usage); + } else { + cons_show(""); + cons_show("Usage: %s", usage); + if (ui_current_win_type() == WIN_CHAT) { + char usage_cpy[strlen(usage) + 8]; + sprintf(usage_cpy, "Usage: %s", usage); + ui_current_print_line(usage_cpy); + } + } +} + static void _ui_disconnected(void) { @@ -1896,4 +1914,5 @@ ui_init_module(void) ui_input_clear = _ui_input_clear; ui_input_nonblocking = _ui_input_nonblocking; ui_replace_input = _ui_replace_input; + ui_invalid_command_usage = _ui_invalid_command_usage; } diff --git a/src/ui/ui.h b/src/ui/ui.h index cd95e9fa..a528b390 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -159,6 +159,8 @@ void (*ui_input_clear)(void); void (*ui_input_nonblocking)(void); void (*ui_replace_input)(char *input, const char * const new_input, int *size); +void (*ui_invalid_command_usage)(const char * const usage, void (**setting_func)(void)); + // console window actions void (*cons_show)(const char * const msg, ...); void (*cons_about)(void);