From b64b0fe6ca4c3d890cafc397b9e1f3021043fe72 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 5 Nov 2007 18:51:53 +0100 Subject: Added string_remove_quotes() function, use of argv and argv_eol for WeeChat commands arguments --- src/core/wee-command.c | 892 +++++++++++++++++-------------------------- src/core/wee-command.h | 38 +- src/core/wee-config-option.c | 11 +- src/core/wee-hook.c | 9 +- src/core/wee-input.c | 14 +- src/core/wee-string.c | 45 ++- src/core/wee-string.h | 1 + src/gui/gui-buffer.c | 23 +- src/gui/gui-buffer.h | 1 + src/gui/gui-chat.c | 2 +- src/plugins/demo/demo.c | 2 + 11 files changed, 460 insertions(+), 578 deletions(-) (limited to 'src') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 1212b598c..e36920677 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -93,8 +93,8 @@ struct command weechat_commands[] = "move|close|list|notify|scroll|%S|%C %S|%C", 0, MAX_ARGS, 0, command_buffer }, { "builtin", - N_("launch WeeChat/IRC builtin command (do not look at plugins handlers " - "or aliases)"), + N_("launch WeeChat builtin command (do not look at commands hooked or " + "aliases)"), N_("command"), N_("command: command to execute (a '/' is automatically added if not " "found at beginning of command)\n"), @@ -359,51 +359,32 @@ command_print_stdout (struct command *commands) int command_alias (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { - char *pos; + char *alias_name; struct alias *ptr_alias; - + /* make C compiler happy */ (void) buffer; - (void) argc; - (void) argv; - if (arguments && arguments[0]) + if (argc > 0) { - while (arguments[0] == '/') - { - arguments++; - } - - /* Define new alias */ - pos = strchr (arguments, ' '); - if (pos) + alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0]; + if (argc > 1) { - pos[0] = '\0'; - pos++; - while (pos[0] == ' ') - pos++; - if (!pos[0]) - { - gui_chat_printf (NULL, - _("%sError: missing arguments for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "alias"); - return -1; - } - if (!alias_new (arguments, pos)) + /* Define new alias */ + if (!alias_new (alias_name, argv_eol[1])) return -1; + if (weelist_add (&weechat_index_commands, &weechat_last_index_command, - arguments, + alias_name, WEELIST_POS_SORT)) { gui_chat_printf (NULL, _("%sAlias \"%s\" => \"%s\" created"), gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - arguments, pos); + alias_name, argv_eol[1]); } else { @@ -411,13 +392,14 @@ command_alias (struct t_gui_buffer *buffer, _("%sError: not enough memory for creating " "alias \"%s\" => \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - arguments, pos); + alias_name, argv_eol[1]); return -1; } } else { - ptr_alias = alias_search (arguments); + /* Display one alias */ + ptr_alias = alias_search (alias_name); if (ptr_alias) { gui_chat_printf (NULL, ""); @@ -526,7 +508,7 @@ command_buffer_display_info (struct t_gui_buffer *buffer) int command_buffer (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { struct t_gui_buffer *ptr_buffer; long number; @@ -534,9 +516,10 @@ command_buffer (struct t_gui_buffer *buffer, int target_buffer; /* make C compiler happy */ - (void) arguments; + (void) argv_eol; - if ((argc == 0) || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) + || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) { /* list open buffers */ @@ -547,11 +530,17 @@ command_buffer (struct t_gui_buffer *buffer, ptr_buffer = ptr_buffer->next_buffer) { gui_chat_printf (NULL, - "%s[%s%d%s] ", + "%s[%s%d%s]%s (%s) %s / %s", GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), ptr_buffer->number, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + (ptr_buffer->plugin) ? + ((struct t_weechat_plugin *)ptr_buffer->plugin)->name : + "weechat", + ptr_buffer->category, + ptr_buffer->name); command_buffer_display_info (ptr_buffer); } } @@ -755,26 +744,22 @@ command_buffer (struct t_gui_buffer *buffer, int command_builtin (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { char *command; int length; - /* make C compiler happy */ - (void) argc; - (void) argv; - - if (arguments && arguments[0]) + if (argc > 0) { - if (arguments[0] == '/') - input_data (buffer, arguments, 1); + if (argv[0][0] == '/') + input_data (buffer, argv_eol[0], 1); else { - length = strlen (arguments) + 2; + length = strlen (argv_eol[0]) + 2; command = (char *)malloc (length); if (command) { - snprintf (command, length, "/%s", arguments); + snprintf (command, length, "/%s", argv_eol[0]); input_data (buffer, command, 1); free (command); } @@ -789,7 +774,7 @@ command_builtin (struct t_gui_buffer *buffer, int command_clear (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char**argv, char **argv_eol) { struct t_gui_buffer *ptr_buffer; char *error; @@ -797,7 +782,7 @@ command_clear (struct t_gui_buffer *buffer, int i; /* make C compiler happy */ - (void) arguments; + (void) argv_eol; if (argc > 0) { @@ -812,25 +797,8 @@ command_clear (struct t_gui_buffer *buffer, if (error && (error[0] == '\0')) { ptr_buffer = gui_buffer_search_by_number (number); - if (!ptr_buffer) - { - gui_chat_printf (NULL, - _("%sError: buffer number \"%s\" not " - "found for \"%s\" command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[i], "clear"); - return -1; - } - gui_buffer_clear (ptr_buffer); - } - else - { - gui_chat_printf (NULL, - _("%sError: unknown option for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "clear"); - return -1; + if (ptr_buffer) + gui_buffer_clear (ptr_buffer); } } } @@ -886,43 +854,35 @@ command_debug_display_windows (struct t_gui_window_tree *tree, int indent) int command_debug (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { /* make C compiler happy */ - (void) buffer; - (void) arguments; - - if (argc != 1) - { - gui_chat_printf (NULL, - _("%sError: wrong argument count for \"%s\" " - "command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "debug"); - return -1; - } - - if (string_strcasecmp (argv[0], "dump") == 0) - { - weechat_dump (0); - } - else if (string_strcasecmp (argv[0], "buffer") == 0) - { - gui_buffer_dump_hexa (buffer); - } - else if (string_strcasecmp (argv[0], "windows") == 0) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, "DEBUG: windows tree:"); - command_debug_display_windows (gui_windows_tree, 1); - } - else + (void) argv_eol; + + if (argc >= 1) { - gui_chat_printf (NULL, - _("%sError: unknown option for \"%s\" command"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - "debug"); - return -1; + if (string_strcasecmp (argv[0], "dump") == 0) + { + weechat_dump (0); + } + else if (string_strcasecmp (argv[0], "buffer") == 0) + { + gui_buffer_dump_hexa (buffer); + } + else if (string_strcasecmp (argv[0], "windows") == 0) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "DEBUG: windows tree:"); + command_debug_display_windows (gui_windows_tree, 1); + } + else + { + gui_chat_printf (NULL, + _("%sError: unknown option for \"%s\" command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "debug"); + return -1; + } } return 0; @@ -934,14 +894,14 @@ command_debug (struct t_gui_buffer *buffer, int command_help (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { int i; struct t_hook *ptr_hook; /* make C compiler happy */ (void) buffer; - (void) arguments; + (void) argv_eol; switch (argc) { @@ -1070,15 +1030,13 @@ command_help (struct t_gui_buffer *buffer, int command_history (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { struct t_gui_history *ptr_history; - int n; - int n_total; - int n_user; + int n, n_total, n_user, displayed; /* make C compiler happy */ - (void) arguments; + (void) argv_eol; n_user = cfg_history_display_default; @@ -1102,14 +1060,18 @@ command_history (struct t_gui_buffer *buffer, { n_total++; } + displayed = 0; for (n = 0; ptr_history; ptr_history = ptr_history->prev_history, n++) { if ((n_user > 0) && ((n_total - n_user) > n)) continue; - gui_chat_printf (buffer, - "%s%s", - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - ptr_history->text); + if (!displayed) + { + gui_chat_printf (buffer, ""); + gui_chat_printf (buffer, _("Buffer command history:")); + } + gui_chat_printf (buffer, "%s", ptr_history->text); + displayed = 1; } } @@ -1127,23 +1089,27 @@ command_key_display (t_gui_key *key, int new_key) expanded_name = gui_keyboard_get_expanded_name (key->key); if (new_key) - { gui_chat_printf (NULL, - _("New key binding: %s"), + _("%sNew key binding: %s%s => %s%s%s%s%s"), gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - (expanded_name) ? expanded_name : key->key); - } + (expanded_name) ? expanded_name : key->key, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + (key->function) ? + gui_keyboard_function_search_by_ptr (key->function) : key->command, + (key->args) ? " \"" : "", + (key->args) ? key->args : "", + (key->args) ? "\"" : ""); else - gui_chat_printf (NULL, " %20s", - (expanded_name) ? expanded_name : key->key); - gui_chat_printf (NULL, "%s => %s%s%s%s%s", - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT), - (key->function) ? - gui_keyboard_function_search_by_ptr (key->function) : key->command, - (key->args) ? " \"" : "", - (key->args) ? key->args : "", - (key->args) ? "\"" : ""); + gui_chat_printf (NULL, " %20s%s => %s%s%s%s%s", + (expanded_name) ? expanded_name : key->key, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + (key->function) ? + gui_keyboard_function_search_by_ptr (key->function) : key->command, + (key->args) ? " \"" : "", + (key->args) ? key->args : "", + (key->args) ? "\"" : ""); if (expanded_name) free (expanded_name); } @@ -1154,25 +1120,17 @@ command_key_display (t_gui_key *key, int new_key) int command_key (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { - char *pos, *pos_args, *args_tmp, *internal_code; - int i, length; + char *args, *internal_code; + int i; t_gui_key *ptr_key; t_gui_key_func *ptr_function; /* make C compiler happy */ (void) buffer; - (void) argc; - (void) argv; - - if (arguments) - { - while (arguments[0] == ' ') - arguments++; - } - if (!arguments || (arguments[0] == '\0')) + if (argc == 0) { gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Key bindings:")); @@ -1180,29 +1138,10 @@ command_key (struct t_gui_buffer *buffer, { command_key_display (ptr_key, 0); } + return 0; } - else if (string_strncasecmp (arguments, "unbind ", 7) == 0) - { - arguments += 7; - while (arguments[0] == ' ') - arguments++; - if (gui_keyboard_unbind (arguments)) - { - gui_chat_printf (NULL, - _("%sKey \"%s\" unbound"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - arguments); - } - else - { - gui_chat_printf (NULL, - _("%sError: unable to unbind key \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - arguments); - return -1; - } - } - else if (string_strcasecmp (arguments, "functions") == 0) + + if (string_strcasecmp (argv[0], "functions") == 0) { gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Internal key functions:")); @@ -1215,57 +1154,12 @@ command_key (struct t_gui_buffer *buffer, _(gui_key_functions[i].description)); i++; } + return 0; } - else if (string_strncasecmp (arguments, "call ", 5) == 0) - { - arguments += 5; - while (arguments[0] == ' ') - arguments++; - pos = strchr (arguments, ' '); - if (pos) - pos[0] = '\0'; - ptr_function = gui_keyboard_function_search_by_name (arguments); - if (pos) - pos[0] = ' '; - if (ptr_function) - { - pos_args = pos; - args_tmp = NULL; - if (pos_args) - { - pos_args++; - while (pos_args[0] == ' ') - pos_args++; - if (pos_args[0] == '"') - { - length = strlen (pos_args); - if ((length > 1) && (pos_args[length - 1] == '"')) - args_tmp = strndup (pos_args + 1, length - 2); - else - args_tmp = strdup (pos_args); - } - else - args_tmp = strdup (pos_args); - } - (void)(*ptr_function)(args_tmp); - if (args_tmp) - free (args_tmp); - } - else - { - gui_chat_printf (NULL, - _("%sError: unknown key function \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - arguments); - return -1; - } - } - else if (string_strncasecmp (arguments, "reset", 5) == 0) + + if (string_strcasecmp (argv[0], "reset") == 0) { - arguments += 5; - while (arguments[0] == ' ') - arguments++; - if (string_strcasecmp (arguments, "-yes") == 0) + if ((argc == 1) && (string_strcasecmp (argv[1], "-yes") == 0)) { gui_keyboard_free_all (); gui_keyboard_init (); @@ -1281,51 +1175,91 @@ command_key (struct t_gui_buffer *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return -1; } + return 0; } - else + + if (string_strcasecmp (argv[0], "unbind") == 0) { - while (arguments[0] == ' ') - arguments++; - pos = strchr (arguments, ' '); - if (!pos) + if (argc >= 2) { - ptr_key = NULL; - internal_code = gui_keyboard_get_internal_code (arguments); - if (internal_code) - ptr_key = gui_keyboard_search (internal_code); - if (ptr_key) + if (gui_keyboard_unbind (argv[1])) { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("Key:")); - command_key_display (ptr_key, 0); + gui_chat_printf (NULL, + _("%sKey \"%s\" unbound"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + argv[1]); } else { gui_chat_printf (NULL, - _("%sNo key found."), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); + _("%sError: unable to unbind key \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[1]); + return -1; + } + } + return 0; + } + + if (string_strcasecmp (argv[0], "call") == 0) + { + if (argc >= 2) + { + ptr_function = gui_keyboard_function_search_by_name (argv[1]); + if (ptr_function) + { + args = string_remove_quotes (argv_eol[2], "'\""); + (void)(*ptr_function)((args) ? args : argv_eol[2]); + if (args) + free (args); + } + else + { + gui_chat_printf (NULL, + _("%sError: unknown key function \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[1]); + return -1; } - if (internal_code) - free (internal_code); - return 0; } - pos[0] = '\0'; - pos++; - while (pos[0] == ' ') - pos++; - ptr_key = gui_keyboard_bind (arguments, pos); + return 0; + } + + /* display a key */ + if (argc == 1) + { + ptr_key = NULL; + internal_code = gui_keyboard_get_internal_code (argv[0]); + if (internal_code) + ptr_key = gui_keyboard_search (internal_code); if (ptr_key) - command_key_display (ptr_key, 1); + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Key:")); + command_key_display (ptr_key, 0); + } else { gui_chat_printf (NULL, - _("%sError: unable to bind key \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - arguments); - return -1; + _("No key found.")); } + if (internal_code) + free (internal_code); + return 0; + } + + /* bind new key */ + ptr_key = gui_keyboard_bind (argv[0], argv_eol[1]); + if (ptr_key) + command_key_display (ptr_key, 1); + else + { + gui_chat_printf (NULL, + _("%sError: unable to bind key \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[0]); + return -1; } - return 0; } @@ -1519,11 +1453,11 @@ command_plugin_list (char *name, int full) int command_plugin (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { /* make C compiler happy */ (void) buffer; - (void) arguments; + (void) argv_eol; switch (argc) { @@ -1582,12 +1516,12 @@ command_plugin (struct t_gui_buffer *buffer, int command_quit (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { (void) buffer; - (void) arguments; (void) argc; (void) argv; + (void) argv_eol; quit_weechat = 1; @@ -1600,13 +1534,13 @@ command_quit (struct t_gui_buffer *buffer, int command_save (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { /* make C compiler happy */ (void) buffer; - (void) arguments; (void) argc; (void) argv; + (void) argv_eol; /* save WeeChat configuration */ if (weechat_config_write () == 0) @@ -1635,14 +1569,16 @@ command_save (struct t_gui_buffer *buffer, */ void -command_set_display_option (struct t_config_option *option, char *message) +command_set_display_option (struct t_config_option *option, char *prefix, + char *message) { char *color_name; switch (option->type) { case OPTION_TYPE_BOOLEAN: - gui_chat_printf (NULL, "%s%s%s = %s%s", + gui_chat_printf (NULL, "%s%s%s%s = %s%s", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), @@ -1650,7 +1586,8 @@ command_set_display_option (struct t_config_option *option, char *message) (*((int *)(option->ptr_int))) ? "ON" : "OFF"); break; case OPTION_TYPE_INT: - gui_chat_printf (NULL, "%s%s%s = %s%d", + gui_chat_printf (NULL, "%s%s%s%s = %s%d", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), @@ -1658,7 +1595,8 @@ command_set_display_option (struct t_config_option *option, char *message) *((int *)(option->ptr_int))); break; case OPTION_TYPE_INT_WITH_STRING: - gui_chat_printf (NULL, "%s%s%s = %s%s", + gui_chat_printf (NULL, "%s%s%s%s = %s%s", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), @@ -1667,7 +1605,8 @@ command_set_display_option (struct t_config_option *option, char *message) break; case OPTION_TYPE_COLOR: color_name = gui_color_get_name (*((int *)(option->ptr_int))); - gui_chat_printf (NULL, "%s%s%s = %s%s", + gui_chat_printf (NULL, "%s%s%s%s = %s%s", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), @@ -1676,17 +1615,17 @@ command_set_display_option (struct t_config_option *option, char *message) break; case OPTION_TYPE_STRING: if (*((char **)(option->ptr_string))) - { - gui_chat_printf (NULL, "%s%s%s = \"%s%s%s\"", + gui_chat_printf (NULL, "%s%s%s%s = \"%s%s%s\"", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT_HOST), *(option->ptr_string), GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - } else - gui_chat_printf (NULL, "%s%s%s = \"\"", + gui_chat_printf (NULL, "%s%s%s%s = \"\"", + prefix, (message) ? message : " ", option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); @@ -1732,7 +1671,8 @@ command_set_display_option_list (char **config_sections, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); section_displayed = 1; } - command_set_display_option (&config_options[i][j], message); + command_set_display_option (&config_options[i][j], + "", message); number_found++; } } @@ -1748,169 +1688,32 @@ command_set_display_option_list (char **config_sections, int command_set (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { - char *option, *value, *pos; + char *value; struct t_config_option *ptr_option; - int number_found; + int number_found, rc; /* make C compiler happy */ (void) buffer; - (void) argc; - (void) argv; - - option = NULL; - value = NULL; - if (arguments && arguments[0]) - { - option = arguments; - value = strchr (option, '='); - if (value) - { - value[0] = '\0'; - - /* remove spaces before '=' */ - pos = value - 1; - while ((pos > option) && (pos[0] == ' ')) - { - pos[0] = '\0'; - pos--; - } - - /* skip spaces after '=' */ - value++; - while (value[0] && (value[0] == ' ')) - { - value++; - } - - /* remove simple or double quotes - and spaces at the end */ - if (strlen(value) > 1) - { - pos = value + strlen (value) - 1; - while ((pos > value) && (pos[0] == ' ')) - { - pos[0] = '\0'; - pos--; - } - pos = value + strlen (value) - 1; - if (((value[0] == '\'') && - (pos[0] == '\'')) || - ((value[0] == '"') && - (pos[0] == '"'))) - { - pos[0] = '\0'; - value++; - } - } - } - } - if (value) - { - pos = strrchr (option, '.'); - /*if (pos) - { - pos[0] = '\0'; - ptr_protocol = protocol_search (option); - if (!ptr_protocol) - { - gui_chat_printf (NULL, - _("%sError: protocol \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - option); - } - else - { - ptr_option = config_option_section_option_search (ptr_protocol->config_sections, - ptr_protocol->config_options, - pos + 1); - if (ptr_option) - { - switch (config_option_set (ptr_option, value)) - { - case 0: - gui_chat_printf (NULL, ""); - command_set_display_option (ptr_option, ptr_protocol->name); - break; - default: - gui_chat_printf (NULL, - _("%sError: incorrect value for " - "option \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - pos + 1); - break; - } - } - else - gui_chat_printf (NULL, - _("%sError: config option \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - pos + 1); - } - pos[0] = '.'; - } - else*/ - { - ptr_option = config_option_section_option_search (weechat_config_sections, - weechat_config_options, - option); - if (ptr_option) - { - if (ptr_option->handler_change == NULL) - { - gui_chat_printf (NULL, - _("%sError: option \"%s\" can not be " - "changed while WeeChat is " - "running"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - option); - } - else - { - if (config_option_set (ptr_option, value) == 0) - { - command_set_display_option (ptr_option, - _("Option changed: ")); - (void) (ptr_option->handler_change()); - } - else - { - gui_chat_printf (NULL, - _("%sError: incorrect value for " - "option \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - option); - } - } - } - else - { - gui_chat_printf (NULL, - _("%sError: configuration option \"%s\" not " - "found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - option); - } - } - } - else + /* display list of options */ + if (argc < 2) { number_found = 0; number_found += command_set_display_option_list (weechat_config_sections, - weechat_config_options, - NULL, - option); + weechat_config_options, + NULL, + (argc == 1) ? argv[0] : NULL); if (number_found == 0) { - if (option) + if (argc == 1) gui_chat_printf (NULL, _("No configuration option found with " "\"%s\""), - option); + argv[0]); else gui_chat_printf (NULL, _("No configuration option found")); @@ -1918,14 +1721,14 @@ command_set (struct t_gui_buffer *buffer, else { gui_chat_printf (NULL, ""); - if (option) + if (argc == 1) gui_chat_printf (NULL, _("%s%d%s configuration option(s) found with " "\"%s\""), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), number_found, GUI_COLOR(GUI_COLOR_CHAT), - option); + argv[0]); else gui_chat_printf (NULL, _("%s%d%s configuration option(s) found"), @@ -1933,7 +1736,57 @@ command_set (struct t_gui_buffer *buffer, number_found, GUI_COLOR(GUI_COLOR_CHAT)); } + return 0; } + + /* set option value */ + if ((argc >= 3) && (string_strcasecmp (argv[1], "=") == 0)) + { + ptr_option = config_option_section_option_search (weechat_config_sections, + weechat_config_options, + argv[0]); + if (!ptr_option) + { + gui_chat_printf (NULL, + _("%sError: configuration option \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[0]); + return -1; + } + if (!ptr_option->handler_change) + { + gui_chat_printf (NULL, + _("%sError: option \"%s\" can not be " + "changed while WeeChat is " + "running"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[0]); + return -1; + } + value = string_remove_quotes (argv_eol[2], "'\""); + rc = config_option_set (ptr_option, + (value) ? value : argv_eol[2]); + if (value) + free (value); + if (rc == 0) + { + command_set_display_option (ptr_option, + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + _("Option changed: ")); + (void) (ptr_option->handler_change()); + } + else + { + gui_chat_printf (NULL, + _("%sError: incorrect value for " + "option \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[0]); + return -1; + } + } + return 0; } @@ -1943,9 +1796,9 @@ command_set (struct t_gui_buffer *buffer, int command_setp (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { - char *option, *value, *pos, *ptr_name; + char *pos, *ptr_name, *value; struct t_plugin_option *ptr_option; int number_found; @@ -1953,82 +1806,83 @@ command_setp (struct t_gui_buffer *buffer, (void) buffer; (void) argc; (void) argv; - - option = NULL; - value = NULL; - if (arguments && arguments[0]) + + if (argc < 2) { - option = arguments; - value = strchr (option, '='); - if (value) + number_found = 0; + for (ptr_option = plugin_options; ptr_option; + ptr_option = ptr_option->next_option) { - value[0] = '\0'; - - /* remove spaces before '=' */ - pos = value - 1; - while ((pos > option) && (pos[0] == ' ')) + if ((argc == 0) || + (strstr (ptr_option->name, argv[0]))) { - pos[0] = '\0'; - pos--; - } - - /* skip spaces after '=' */ - value++; - while (value[0] && (value[0] == ' ')) - { - value++; - } - - /* remove simple or double quotes - and spaces at the end */ - if (strlen(value) > 1) - { - pos = value + strlen (value) - 1; - while ((pos > value) && (pos[0] == ' ')) - { - pos[0] = '\0'; - pos--; - } - pos = value + strlen (value) - 1; - if (((value[0] == '\'') && - (pos[0] == '\'')) || - ((value[0] == '"') && - (pos[0] == '"'))) - { - pos[0] = '\0'; - value++; - } + if (number_found == 0) + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, " %s%s = \"%s%s%s\"", + ptr_option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + ptr_option->value, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + number_found++; } } + if (number_found == 0) + { + if (argc == 1) + gui_chat_printf (NULL, + _("No plugin option found with \"%s\""), + argv[0]); + else + gui_chat_printf (NULL, _("No plugin option found")); + } + else + { + gui_chat_printf (NULL, ""); + if (argc == 1) + gui_chat_printf (NULL, "%s%d%s plugin option(s) found with \"%s\"", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT), + argv[0]); + else + gui_chat_printf (NULL, "%s%d%s plugin option(s) found", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT)); + } } - - if (value) + + if ((argc >= 3) && (string_strcasecmp (argv[1], "=") == 0)) { ptr_name = NULL; - ptr_option = plugin_config_search_internal (option); + ptr_option = plugin_config_search_internal (argv[0]); if (ptr_option) ptr_name = ptr_option->name; else { - pos = strchr (option, '.'); + pos = strchr (argv[0], '.'); if (pos) pos[0] = '\0'; - if (!pos || !pos[1] || (!plugin_search (option))) + if (!pos || !pos[1] || (!plugin_search (argv[0]))) { gui_chat_printf (NULL, _("%sError: plugin \"%s\" not found"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - option); + argv[0]); + if (pos) + pos[0] = '.'; + return -1; } else - ptr_name = option; + ptr_name = argv[0]; if (pos) pos[0] = '.'; } if (ptr_name) { - if (plugin_config_set_internal (ptr_name, value)) - { + value = string_remove_quotes (argv_eol[2], "'\""); + if (plugin_config_set_internal (ptr_name, (value) ? value : argv[2])) gui_chat_printf (NULL, _("Plugin option changed: %s%s = \"%s%s%s\""), ptr_name, @@ -2036,7 +1890,6 @@ command_setp (struct t_gui_buffer *buffer, GUI_COLOR(GUI_COLOR_CHAT_HOST), value, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - } else { gui_chat_printf (NULL, @@ -2044,53 +1897,12 @@ command_setp (struct t_gui_buffer *buffer, "option \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], ptr_name); + if (value) + free (value); + return -1; } - } - } - else - { - number_found = 0; - for (ptr_option = plugin_options; ptr_option; - ptr_option = ptr_option->next_option) - { - if ((!option) || - ((option) && (option[0]) - && (strstr (ptr_option->name, option) != NULL))) - { - if (number_found == 0) - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, " %s%s = \"%s%s%s\"", - ptr_option->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - ptr_option->value, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - number_found++; - } - } - if (number_found == 0) - { - if (option) - gui_chat_printf (NULL, - _("No plugin option found with \"%s\""), - option); - else - gui_chat_printf (NULL, _("No plugin option found")); - } - else - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, "%s%d %s", - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - number_found, - GUI_COLOR(GUI_COLOR_CHAT)); - if (option) - gui_chat_printf (NULL, - _("plugin option(s) found with \"%s\""), - option); - else - gui_chat_printf (NULL, - _("plugin option(s) found")); + if (value) + free (value); } } @@ -2103,39 +1915,39 @@ command_setp (struct t_gui_buffer *buffer, int command_unalias (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { + char *alias_name; struct t_weelist *ptr_weelist; struct alias *ptr_alias; /* make C compiler happy */ (void) buffer; - (void) argc; - (void) argv; - - if (arguments[0] == '/') - arguments++; - - ptr_weelist = weelist_search (weechat_index_commands, arguments); - if (!ptr_weelist) + (void) argv_eol; + + if (argc > 0) { + alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0]; + ptr_alias = alias_search (alias_name); + if (!ptr_alias) + { + gui_chat_printf (NULL, + _("%sAlias \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + alias_name); + return -1; + } + alias_free (ptr_alias); + ptr_weelist = weelist_search (weechat_index_commands, alias_name); + if (ptr_weelist) + weelist_remove (&weechat_index_commands, + &weechat_last_index_command, + ptr_weelist); gui_chat_printf (NULL, - _("%sError: alias or command \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - arguments); - return -1; + _("%sAlias \"%s\" removed"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + alias_name); } - - weelist_remove (&weechat_index_commands, - &weechat_last_index_command, - ptr_weelist); - ptr_alias = alias_search (arguments); - if (ptr_alias) - alias_free (ptr_alias); - gui_chat_printf (NULL, - _("%sAlias \"%s\" removed"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - arguments); return 0; } @@ -2145,7 +1957,7 @@ command_unalias (struct t_gui_buffer *buffer, int command_upgrade (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { /*int filename_length; char *filename, *ptr_binary; @@ -2153,9 +1965,9 @@ command_upgrade (struct t_gui_buffer *buffer, /* make C compiler happy */ (void) buffer; - (void) arguments; (void) argc; (void) argv; + (void) argv_eol; /*ptr_binary = (argc > 0) ? argv[0] : weechat_argv0; @@ -2242,14 +2054,14 @@ command_upgrade (struct t_gui_buffer *buffer, int command_uptime (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { time_t running_time; int day, hour, min, sec; char string[256]; /* make C compiler happy */ - (void) arguments; + (void) argv_eol; running_time = time (NULL) - weechat_start_time; day = running_time / (60 * 60 * 24); @@ -2257,7 +2069,7 @@ command_uptime (struct t_gui_buffer *buffer, min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; - if ((argc == 1) && (strcmp (argv[0], "-o") == 0)) + if ((argc == 1) && (string_strcasecmp (argv[0], "-o") == 0)) { snprintf (string, sizeof (string), _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), @@ -2273,10 +2085,9 @@ command_uptime (struct t_gui_buffer *buffer, else { gui_chat_printf (NULL, - _("%sWeeChat uptime: %s%d %s%s " + _("WeeChat uptime: %s%d %s%s " "%s%02d%s:%s%02d%s:%s%02d%s, " "started on %s%s"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], GUI_COLOR(GUI_COLOR_CHAT_BUFFER), day, GUI_COLOR(GUI_COLOR_CHAT), @@ -2303,7 +2114,7 @@ command_uptime (struct t_gui_buffer *buffer, int command_window (struct t_gui_buffer *buffer, - char *arguments, int argc, char **argv) + int argc, char **argv, char **argv_eol) { struct t_gui_window *ptr_win; int i; @@ -2312,9 +2123,10 @@ command_window (struct t_gui_buffer *buffer, /* make C compiler happy */ (void) buffer; - (void) arguments; + (void) argv_eol; - if ((argc == 0) || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) + || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) { /* list open windows */ diff --git a/src/core/wee-command.h b/src/core/wee-command.h index ea93e7f20..d36787d19 100644 --- a/src/core/wee-command.h +++ b/src/core/wee-command.h @@ -35,7 +35,7 @@ struct command int min_arg, max_arg; /* min & max number of arguments */ int conversion; /* = 1 if cmd args are converted (charset*/ /* and color) before execution */ - int (*cmd_function)(struct t_gui_buffer *, char *, int, char **); + int (*cmd_function)(struct t_gui_buffer *, int, char **, char **); /* function called when user enters cmd */ }; @@ -51,24 +51,22 @@ extern void command_index_remove (char *); extern int command_is_command (char *); extern void command_print_stdout (struct command *); -extern int command_alias (struct t_gui_buffer *, char *, int, char **); -extern int command_buffer (struct t_gui_buffer *, char *, int, char **); -extern int command_builtin (struct t_gui_buffer *, char *, int, char **); -extern int command_clear (struct t_gui_buffer *, char *, int, char **); -extern int command_debug (struct t_gui_buffer *, char *, int, char **); -extern int command_help (struct t_gui_buffer *, char *, int, char **); -extern int command_history (struct t_gui_buffer *, char *, int, char **); -extern int command_key (struct t_gui_buffer *, char *, int, char **); -extern int command_panel (struct t_gui_buffer *, char *, int, char **); -extern int command_plugin (struct t_gui_buffer *, char *, int, char **); -extern int command_quit (struct t_gui_buffer *, char *, int, char **); -extern int command_save (struct t_gui_buffer *, char *, int, char **); -extern int command_set (struct t_gui_buffer *, char *, int, char **); -extern int command_setp (struct t_gui_buffer *, char *, int, char **); -extern int command_unalias (struct t_gui_buffer *, char *, int, char **); -extern int command_unignore (struct t_gui_buffer *, char *, int, char **); -extern int command_upgrade (struct t_gui_buffer *, char *, int, char **); -extern int command_uptime (struct t_gui_buffer *, char *, int, char **); -extern int command_window (struct t_gui_buffer *, char *, int, char **); +extern int command_alias (struct t_gui_buffer *, int, char **, char **); +extern int command_buffer (struct t_gui_buffer *, int, char **, char **); +extern int command_builtin (struct t_gui_buffer *, int, char **, char **); +extern int command_clear (struct t_gui_buffer *, int, char **, char **); +extern int command_debug (struct t_gui_buffer *, int, char **, char **); +extern int command_help (struct t_gui_buffer *, int, char **, char **); +extern int command_history (struct t_gui_buffer *, int, char **, char **); +extern int command_key (struct t_gui_buffer *, int, char **, char **); +extern int command_plugin (struct t_gui_buffer *, int, char **, char **); +extern int command_quit (struct t_gui_buffer *, int, char **, char **); +extern int command_save (struct t_gui_buffer *, int, char **, char **); +extern int command_set (struct t_gui_buffer *, int, char **, char **); +extern int command_setp (struct t_gui_buffer *, int, char **, char **); +extern int command_unalias (struct t_gui_buffer *, int, char **, char **); +extern int command_upgrade (struct t_gui_buffer *, int, char **, char **); +extern int command_uptime (struct t_gui_buffer *, int, char **, char **); +extern int command_window (struct t_gui_buffer *, int, char **, char **); #endif /* wee-command.h */ diff --git a/src/core/wee-config-option.c b/src/core/wee-config-option.c index 4c1c63e02..6b15b39d6 100644 --- a/src/core/wee-config-option.c +++ b/src/core/wee-config-option.c @@ -298,10 +298,13 @@ config_option_section_option_search (char **config_sections, for (i = 0; config_sections[i]; i++) { - ptr_option = config_option_search (config_options[i], - option_name); - if (ptr_option) - return ptr_option; + if (config_options[i]) + { + ptr_option = config_option_search (config_options[i], + option_name); + if (ptr_option) + return ptr_option; + } } /* option not found */ diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index cea271b7d..e33d26e4f 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -162,8 +162,7 @@ hook_command_exec (void *plugin, char *string) argv = string_explode (string, " ", 0, 0, &argc); if (argc == 0) { - if (argv) - string_free_exploded (argv); + string_free_exploded (argv); return -1; } argv_eol = string_explode (string, " ", 1, 0, NULL); @@ -184,10 +183,8 @@ hook_command_exec (void *plugin, char *string) } } - if (argv) - string_free_exploded (argv); - if (argv_eol) - string_free_exploded (argv_eol); + string_free_exploded (argv); + string_free_exploded (argv_eol); /* no hook found */ return -1; diff --git a/src/core/wee-input.c b/src/core/wee-input.c index faad27150..b3fc0da40 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -51,7 +51,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, { int i, rc, argc, return_code, length1, length2; char *command, *pos, *ptr_args; - char **argv, *alias_command; + char **argv, **argv_eol, *alias_command; char **commands, **ptr_cmd, **ptr_next_cmd; char *args_replaced, *vars_replaced, *new_ptr_cmd; int some_args_replaced; @@ -98,16 +98,17 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, switch (rc) { - case 0: /* plugin handler KO */ + case 0: /* command hooked, KO */ gui_chat_printf (NULL, _("%sError: command \"%s\" failed"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command + 1); break; - case 1: /* plugin handler OK, executed */ + case 1: /* command hooked, OK (executed) */ break; - default: /* plugin handler not found */ + default: /* no command hooked */ argv = string_explode (ptr_args, " ", 0, 0, &argc); + argv_eol = string_explode (ptr_args, " ", 1, 0, NULL); /* look for alias */ if (!only_builtin) @@ -222,6 +223,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, } } string_free_exploded (argv); + string_free_exploded (argv_eol); free (command); return 1; } @@ -277,7 +279,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, (weechat_commands[i].conversion && cfg_irc_colors_send)) : NULL;*/ return_code = (int) (weechat_commands[i].cmd_function) - (buffer, ptr_args, argc, argv); + (buffer, argc, argv, argv_eol); if (return_code < 0) { gui_chat_printf (NULL, @@ -287,6 +289,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, } } string_free_exploded (argv); + string_free_exploded (argv_eol); free (command); return 1; } @@ -328,6 +331,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, command + 1); string_free_exploded (argv); + string_free_exploded (argv_eol); } free (command); return 0; diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 54f9c641e..8d172767b 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -199,7 +199,7 @@ string_strcasestr (char *string, char *search) /* * string_replace: replace a string by new one in a string - * note: returned value has to be free() after use + * note: returned value has to be free() after use */ char * @@ -253,6 +253,49 @@ string_replace (char *string, char *search, char *replace) return new_string; } +/* + * string_remove_quotes: remove quotes at beginning/end of string + * (ignore spaces if there are before first quote or + * after last quote) + * note: returned value has to be free() after use + */ + +char * +string_remove_quotes (char *string, char *quotes) +{ + int length; + char *pos_start, *pos_end; + + if (!string || !quotes) + return NULL; + + if (!string[0]) + return strdup (string); + + pos_start = string; + while (pos_start[0] == ' ') + { + pos_start++; + } + length = strlen (string); + pos_end = string + length - 1; + while ((pos_end[0] == ' ') && (pos_end > pos_start)) + { + pos_end--; + } + if (!pos_start[0] || !pos_end[0] || (pos_end <= pos_start)) + return strdup (string); + + if (strchr (quotes, pos_start[0]) && (pos_end[0] == pos_start[0])) + { + if (pos_end == (pos_start + 1)) + return strdup (""); + return strndup (pos_start + 1, pos_end - pos_start - 1); + } + + return strdup (string); +} + /* * string_convert_hex_chars: convert hex chars (\x??) to value */ diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 94ed642d0..d308d2e5a 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -29,6 +29,7 @@ extern int string_strcasecmp (char *, char *); extern int string_strncasecmp (char *, char *, int); extern char *string_strcasestr (char *, char *); extern char *string_replace (char *, char *, char *); +extern char *string_remove_quotes (char *, char *); extern char *string_convert_hex_chars (char *); extern char **string_explode (char *, char *, int, int, int *); extern void string_free_exploded (char **); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index cb0051574..60f0b57f8 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -70,7 +70,7 @@ gui_buffer_new (void *plugin, char *category, char *name) weechat_log_printf ("Creating new buffer\n"); #endif - if (!name) + if (!category || !name) return NULL; /* create new buffer */ @@ -276,6 +276,27 @@ gui_buffer_set_nick (struct t_gui_buffer *buffer, char *new_nick) buffer->input_nick = (new_nick) ? strdup (new_nick) : NULL; } +/* + * gui_buffer_search_main: get main buffer (weechat one, created at startup) + * return first buffer if not found + */ + +struct t_gui_buffer * +gui_buffer_search_main () +{ + struct t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (!ptr_buffer->plugin) + return ptr_buffer; + } + + /* buffer not found, return first buffer by default */ + return gui_buffers; +} + /* * gui_buffer_search_by_category_name: search a buffer by category and/or name */ diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 3b5840272..5380a54f3 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -151,6 +151,7 @@ extern void gui_buffer_set_log (struct t_gui_buffer *, char *); extern void gui_buffer_set_title (struct t_gui_buffer *, char *); extern void gui_buffer_set_nick_case_sensitive (struct t_gui_buffer *, int); extern void gui_buffer_set_nick (struct t_gui_buffer *, char *); +extern struct t_gui_buffer *gui_buffer_search_main (); extern struct t_gui_buffer *gui_buffer_search_by_category_name (char *, char *); extern struct t_gui_buffer *gui_buffer_search_by_number (int); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 4ae1c57a9..c709b2e1a 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -463,7 +463,7 @@ gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date, if (gui_init_ok) { if (buffer == NULL) - buffer = gui_buffers; + buffer = gui_buffer_search_main (); if (buffer->type == GUI_BUFFER_TYPE_FREE) buffer = gui_buffers; diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index b5fdb9bb1..ebb1a8745 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -178,6 +178,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) "action: one of following actions:\n" " buffer display infos about buffers", "buffer|buffer_lines", demo_command, NULL); + + weechat_buffer_new ("categ", "nam"); return PLUGIN_RC_SUCCESS; } -- cgit v1.2.3