>From 6221686256dd9ec4605ce3992c6c3e48d300535c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Sun, 16 Dec 2012 02:55:51 +0100 Subject: [PATCH] diff switch for /set, display only changed values --- src/core/wee-command.c | 166 ++++++++++++++++++++++++++++++++++-------------- src/core/wee-config.c | 27 ++++++++ src/core/wee-config.h | 1 + 3 files changed, 146 insertions(+), 48 deletions(-) diff --git a/src/core/wee-command.c b/src/core/wee-command.c index dada867..efff09d 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -4354,14 +4354,14 @@ command_set_display_option (struct t_config_option *option, { const char *color_name; const char *display_undefined = _("(undefined)"); - const char *display_default; + const char *display_default = NULL; char str_default[128]; int is_file_plugins_conf; - display_default = NULL; is_file_plugins_conf = (option->config_file && option->config_file->name && (strcmp (option->config_file->name, "plugins") == 0)); + if (option->value) { if (!is_file_plugins_conf && !option->default_value) @@ -4532,7 +4532,8 @@ command_set_display_option (struct t_config_option *option, */ int -command_set_display_option_list (const char *message, const char *search) +command_set_display_option_list (const char *message, const char *search, + int display_only_changed) { int number_found, section_displayed, length; struct t_config_file *ptr_config; @@ -4545,6 +4546,8 @@ command_set_display_option_list (const char *message, const char *search) for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { + if (display_only_changed && strcmp(ptr_config->name, "plugins") == 0) + continue; for (ptr_section = ptr_config->sections; ptr_section; ptr_section = ptr_section->next_section) { @@ -4553,6 +4556,10 @@ command_set_display_option_list (const char *message, const char *search) for (ptr_option = ptr_section->options; ptr_option; ptr_option = ptr_option->next_option) { + if (display_only_changed && + !config_option_has_changed(ptr_option)) + continue; + length = strlen (ptr_config->name) + 1 + strlen (ptr_section->name) + 1 + strlen (ptr_option->name) + 1; @@ -4585,72 +4592,133 @@ command_set_display_option_list (const char *message, const char *search) } /* - * Callback for command "/set": sets configuration options. + * Display multiple lists of options + * + * Returns the total number of options displayed. */ - -COMMAND_CALLBACK(set) +int +command_set_display_option_lists (const char *message, char **search, + char **search_end, + int display_only_changed) { - char *value; - int number_found, rc; - struct t_config_option *ptr_option, *ptr_option_before; + int total_number_found = 0, number_found, display_single_changed; - /* make C compiler happy */ - (void) data; - (void) buffer; - - /* display list of options */ - if (argc < 3) + display_single_changed = display_only_changed && search == search_end; + + while (1) { - number_found = 0; + number_found = command_set_display_option_list (message, + search ? *search : NULL, + display_only_changed); - number_found += command_set_display_option_list (NULL, - (argc == 2) ? - argv[1] : NULL); + total_number_found += number_found; + + if (display_single_changed) + break; if (number_found == 0) { - if (argc == 2) + if (search) { gui_chat_printf (NULL, - _("%sOption \"%s\" not found (tip: you can use " - "\"*\" at beginning and/or end of option to " - "see a sublist)"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[1]); + _("%sOption \"%s\" not found (tip: you can use " + "\"*\" at beginning and/or end of option to " + "see a sublist)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + *search); } else { gui_chat_printf (NULL, - _("No configuration option found")); + _("No configuration options found")); } } else { gui_chat_printf (NULL, ""); - if (argc == 2) + if (search) { gui_chat_printf (NULL, - NG_("%s%d%s configuration option found " - "matching with \"%s\"", - "%s%d%s configuration options found " - "matching with \"%s\"", - number_found), - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - number_found, - GUI_COLOR(GUI_COLOR_CHAT), - argv[1]); + NG_("%s%d%s configuration option found " + "matching with \"%s\"", + "%s%d%s configuration options found " + "matching with \"%s\"", + number_found), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT), + *search); } else { gui_chat_printf (NULL, - NG_("%s%d%s configuration option found", - "%s%d%s configuration options found", - number_found), - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - number_found, - GUI_COLOR(GUI_COLOR_CHAT)); + NG_("%s%d%s configuration option found", + "%s%d%s configuration options found", + number_found), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT)); } } + + if (search == search_end) + break; + search++; + } + + return total_number_found; +} + +/* + * Callback for command "/set": sets configuration options. + */ + +COMMAND_CALLBACK(set) +{ + char *value, **argv_option = NULL; + int number_found, rc, display_only_changed = 0, display_matching; + struct t_config_option *ptr_option, *ptr_option_before; + + /* if "diff" is specified as first argument, only display changed values */ + if (argc >= 2 && string_strcasecmp(argv[1], "diff") == 0) + { + if (argc >= 3) + argv_option = &argv[2]; + + display_only_changed = 1; + } + else if (argc >= 2) + { + argv_option = &argv[1]; + } + + /* make C compiler happy */ + (void) data; + (void) buffer; + + /* display list of options */ + if (argc < 3 || display_only_changed) + { + display_matching = argv_option == &argv[argc-1]; + number_found = command_set_display_option_lists(NULL, argv_option, + argv_option ? &argv[argc-1]: NULL, + display_only_changed); + + if (display_only_changed) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, + NG_("%s%d%s changed configuration option found%s%s%s", + "%s%d%s changed configuration options found%s%s%s", + number_found), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT), + display_matching ? " matching with \"" : "", + display_matching ? *argv_option : "", + display_matching ? "\"" : ""); + } + return WEECHAT_RC_OK; } @@ -4694,7 +4762,6 @@ COMMAND_CALLBACK(set) return WEECHAT_RC_OK; } - /* * Callback for command "/unset": unsets/resets configuration options. */ @@ -6346,15 +6413,16 @@ command_init () &command_save, NULL); hook_command (NULL, "set", N_("set config options"), - N_("[