diff options
Diffstat (limited to 'src/plugins/alias')
-rw-r--r-- | src/plugins/alias/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/plugins/alias/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias-command.c | 45 | ||||
-rw-r--r-- | src/plugins/alias/alias-command.h | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias-completion.c | 14 | ||||
-rw-r--r-- | src/plugins/alias/alias-completion.h | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias-config.c | 78 | ||||
-rw-r--r-- | src/plugins/alias/alias-config.h | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias-info.c | 16 | ||||
-rw-r--r-- | src/plugins/alias/alias-info.h | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 48 | ||||
-rw-r--r-- | src/plugins/alias/alias.h | 2 |
12 files changed, 151 insertions, 64 deletions
diff --git a/src/plugins/alias/CMakeLists.txt b/src/plugins/alias/CMakeLists.txt index 7214efbc3..8f1c39958 100644 --- a/src/plugins/alias/CMakeLists.txt +++ b/src/plugins/alias/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> +# Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> # # This file is part of WeeChat, the extensible chat client. # diff --git a/src/plugins/alias/Makefile.am b/src/plugins/alias/Makefile.am index 0214ef60d..fb9cffa96 100644 --- a/src/plugins/alias/Makefile.am +++ b/src/plugins/alias/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> +# Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> # # This file is part of WeeChat, the extensible chat client. # diff --git a/src/plugins/alias/alias-command.c b/src/plugins/alias/alias-command.c index 74c1964ff..f492faaa5 100644 --- a/src/plugins/alias/alias-command.c +++ b/src/plugins/alias/alias-command.c @@ -1,7 +1,7 @@ /* * alias-command.c - alias commands * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -76,7 +76,8 @@ alias_command_add (const char *alias_name, const char *command, */ int -alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, +alias_command_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *ptr_alias_name; @@ -85,6 +86,7 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, int alias_found, i; /* make C compiler happy */ + (void) pointer; (void) data; (void) buffer; @@ -123,11 +125,36 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, weechat_printf (NULL, _("All aliases:")); } } - weechat_printf (NULL, " %s %s=>%s %s", - ptr_alias->name, - weechat_color ("chat_delimiters"), - weechat_color ("chat"), - ptr_alias->command); + ptr_option = weechat_config_search_option ( + alias_config_file, + alias_config_section_completion, + ptr_alias->name); + if (ptr_option) + { + weechat_printf ( + NULL, + " %s %s=>%s %s %s(%s%s %s%s)%s", + ptr_alias->name, + weechat_color ("chat_delimiters"), + weechat_color ("chat"), + ptr_alias->command, + weechat_color ("chat_delimiters"), + weechat_color ("chat"), + _("completion:"), + weechat_config_string (ptr_option), + weechat_color ("chat_delimiters"), + weechat_color ("chat")); + } + else + { + weechat_printf ( + NULL, + " %s %s=>%s %s", + ptr_alias->name, + weechat_color ("chat_delimiters"), + weechat_color ("chat"), + ptr_alias->command); + } alias_found = 1; } } @@ -190,7 +217,7 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, ptr_option = weechat_config_search_option ( alias_config_file, alias_config_section_cmd, - ptr_alias_name); + ptr_alias_name); if (ptr_option) weechat_config_option_free (ptr_option); ptr_option = weechat_config_search_option ( @@ -262,5 +289,5 @@ alias_command_init () " || add %(alias) %(commands)|%(alias_value)" " || addcompletion %- %(alias) %(commands)|%(alias_value)" " || del %(alias)|%*", - &alias_command_cb, NULL); + &alias_command_cb, NULL, NULL); } diff --git a/src/plugins/alias/alias-command.h b/src/plugins/alias/alias-command.h index 14b75dbef..033a9bf28 100644 --- a/src/plugins/alias/alias-command.h +++ b/src/plugins/alias/alias-command.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2013-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/alias/alias-completion.c b/src/plugins/alias/alias-completion.c index 44a590abc..fd90b1c5d 100644 --- a/src/plugins/alias/alias-completion.c +++ b/src/plugins/alias/alias-completion.c @@ -1,7 +1,7 @@ /* * alias-completion.c - completion for alias commands * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -32,13 +32,15 @@ */ int -alias_completion_alias_cb (void *data, const char *completion_item, +alias_completion_alias_cb (const void *pointer, void *data, + const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; (void) completion_item; (void) buffer; @@ -58,7 +60,8 @@ alias_completion_alias_cb (void *data, const char *completion_item, */ int -alias_completion_alias_value_cb (void *data, const char *completion_item, +alias_completion_alias_value_cb (const void *pointer, void *data, + const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { @@ -68,6 +71,7 @@ alias_completion_alias_value_cb (void *data, const char *completion_item, struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; (void) completion_item; (void) buffer; @@ -110,7 +114,7 @@ void alias_completion_init () { weechat_hook_completion ("alias", N_("list of aliases"), - &alias_completion_alias_cb, NULL); + &alias_completion_alias_cb, NULL, NULL); weechat_hook_completion ("alias_value", N_("value of alias"), - &alias_completion_alias_value_cb, NULL); + &alias_completion_alias_value_cb, NULL, NULL); } diff --git a/src/plugins/alias/alias-completion.h b/src/plugins/alias/alias-completion.h index eb5ca1e0d..3808c9319 100644 --- a/src/plugins/alias/alias-completion.h +++ b/src/plugins/alias/alias-completion.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2013-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/alias/alias-config.c b/src/plugins/alias/alias-config.c index 2a892649c..1ad8780c3 100644 --- a/src/plugins/alias/alias-config.c +++ b/src/plugins/alias/alias-config.c @@ -1,7 +1,7 @@ /* * alias-config.c - alias configuration options (file alias.conf) * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -78,11 +78,13 @@ char *alias_default_completion[][2] = */ void -alias_config_cmd_change_cb (void *data, struct t_config_option *option) +alias_config_cmd_change_cb (const void *pointer, void *data, + struct t_config_option *option) { struct t_config_option *ptr_option_completion; /* make C compiler happy */ + (void) pointer; (void) data; ptr_option_completion = weechat_config_search_option (alias_config_file, @@ -100,12 +102,14 @@ alias_config_cmd_change_cb (void *data, struct t_config_option *option) */ void -alias_config_cmd_delete_cb (void *data, struct t_config_option *option) +alias_config_cmd_delete_cb (const void *pointer, void *data, + struct t_config_option *option) { struct t_config_option *ptr_option_completion; struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; ptr_option_completion = weechat_config_search_option (alias_config_file, @@ -125,11 +129,13 @@ alias_config_cmd_delete_cb (void *data, struct t_config_option *option) */ void -alias_config_completion_change_cb (void *data, struct t_config_option *option) +alias_config_completion_change_cb (const void *pointer, void *data, + struct t_config_option *option) { struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; ptr_alias = alias_search (weechat_config_option_get_pointer (option, "name")); @@ -145,11 +151,13 @@ alias_config_completion_change_cb (void *data, struct t_config_option *option) */ void -alias_config_completion_delete_cb (void *data, struct t_config_option *option) +alias_config_completion_delete_cb (const void *pointer, void *data, + struct t_config_option *option) { struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; ptr_alias = alias_search (weechat_config_option_get_pointer (option, "name")); @@ -164,9 +172,11 @@ alias_config_completion_delete_cb (void *data, struct t_config_option *option) */ int -alias_config_reload (void *data, struct t_config_file *config_file) +alias_config_reload (const void *pointer, void *data, + struct t_config_file *config_file) { /* make C compiler happy */ + (void) pointer; (void) data; weechat_config_section_free_options (alias_config_section_cmd); @@ -181,13 +191,14 @@ alias_config_reload (void *data, struct t_config_file *config_file) */ int -alias_config_cmd_write_default_cb (void *data, +alias_config_cmd_write_default_cb (const void *pointer, void *data, struct t_config_file *config_file, const char *section_name) { int i; /* make C compiler happy */ + (void) pointer; (void) data; if (!weechat_config_write_line (config_file, section_name, NULL)) @@ -214,9 +225,9 @@ alias_config_cmd_new_option (const char *name, const char *command) weechat_config_new_option (alias_config_file, alias_config_section_cmd, name, "string", NULL, NULL, 0, 0, NULL, command, 0, - NULL, NULL, - &alias_config_cmd_change_cb, NULL, - &alias_config_cmd_delete_cb, NULL); + NULL, NULL, NULL, + &alias_config_cmd_change_cb, NULL, NULL, + &alias_config_cmd_delete_cb, NULL, NULL); } /* @@ -224,7 +235,7 @@ alias_config_cmd_new_option (const char *name, const char *command) */ int -alias_config_cmd_create_option_cb (void *data, +alias_config_cmd_create_option_cb (const void *pointer, void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) @@ -233,6 +244,7 @@ alias_config_cmd_create_option_cb (void *data, int rc; /* make C compiler happy */ + (void) pointer; (void) data; (void) config_file; (void) section; @@ -266,13 +278,14 @@ alias_config_cmd_create_option_cb (void *data, */ int -alias_config_completion_write_default_cb (void *data, +alias_config_completion_write_default_cb (const void *pointer, void *data, struct t_config_file *config_file, const char *section_name) { int i; /* make C compiler happy */ + (void) pointer; (void) data; if (!weechat_config_write_line (config_file, section_name, NULL)) @@ -300,9 +313,9 @@ alias_config_completion_new_option (const char *name, const char *completion) alias_config_section_completion, name, "string", NULL, NULL, 0, 0, NULL, completion, 0, - NULL, NULL, - &alias_config_completion_change_cb, NULL, - &alias_config_completion_delete_cb, NULL); + NULL, NULL, NULL, + &alias_config_completion_change_cb, NULL, NULL, + &alias_config_completion_delete_cb, NULL, NULL); } /* @@ -310,7 +323,7 @@ alias_config_completion_new_option (const char *name, const char *completion) */ int -alias_config_completion_create_option_cb (void *data, +alias_config_completion_create_option_cb (const void *pointer, void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, @@ -319,6 +332,7 @@ alias_config_completion_create_option_cb (void *data, struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; (void) config_file; (void) section; @@ -357,18 +371,19 @@ alias_config_init () struct t_config_section *ptr_section; alias_config_file = weechat_config_new (ALIAS_CONFIG_NAME, - &alias_config_reload, NULL); + &alias_config_reload, NULL, NULL); if (!alias_config_file) return 0; /* cmd */ - ptr_section = weechat_config_new_section (alias_config_file, "cmd", - 1, 1, - NULL, NULL, - NULL, NULL, - &alias_config_cmd_write_default_cb, NULL, - &alias_config_cmd_create_option_cb, NULL, - NULL, NULL); + ptr_section = weechat_config_new_section ( + alias_config_file, "cmd", + 1, 1, + NULL, NULL, NULL, + NULL, NULL, NULL, + &alias_config_cmd_write_default_cb, NULL, NULL, + &alias_config_cmd_create_option_cb, NULL, NULL, + NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (alias_config_file); @@ -377,13 +392,14 @@ alias_config_init () alias_config_section_cmd = ptr_section; /* completion */ - ptr_section = weechat_config_new_section (alias_config_file, "completion", - 1, 1, - NULL, NULL, - NULL, NULL, - &alias_config_completion_write_default_cb, NULL, - &alias_config_completion_create_option_cb, NULL, - NULL, NULL); + ptr_section = weechat_config_new_section ( + alias_config_file, "completion", + 1, 1, + NULL, NULL, NULL, + NULL, NULL, NULL, + &alias_config_completion_write_default_cb, NULL, NULL, + &alias_config_completion_create_option_cb, NULL, NULL, + NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (alias_config_file); diff --git a/src/plugins/alias/alias-config.h b/src/plugins/alias/alias-config.h index 9d7ce25ec..714abfcde 100644 --- a/src/plugins/alias/alias-config.h +++ b/src/plugins/alias/alias-config.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/alias/alias-info.c b/src/plugins/alias/alias-info.c index f91a12487..484c6082b 100644 --- a/src/plugins/alias/alias-info.c +++ b/src/plugins/alias/alias-info.c @@ -1,7 +1,7 @@ /* * alias-info.c - info and infolist hooks for alias plugin * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -30,28 +30,30 @@ */ struct t_infolist * -alias_info_infolist_alias_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) +alias_info_infolist_alias_cb (const void *pointer, void *data, + const char *infolist_name, + void *obj_pointer, const char *arguments) { struct t_infolist *ptr_infolist; struct t_alias *ptr_alias; /* make C compiler happy */ + (void) pointer; (void) data; (void) infolist_name; (void) arguments; - if (pointer && !alias_valid (pointer)) + if (obj_pointer && !alias_valid (obj_pointer)) return NULL; ptr_infolist = weechat_infolist_new (); if (!ptr_infolist) return NULL; - if (pointer) + if (obj_pointer) { /* build list with only one alias */ - if (!alias_add_to_infolist (ptr_infolist, pointer)) + if (!alias_add_to_infolist (ptr_infolist, obj_pointer)) { weechat_infolist_free (ptr_infolist); return NULL; @@ -90,5 +92,5 @@ alias_info_init () "alias", N_("list of aliases"), N_("alias pointer (optional)"), N_("alias name (wildcard \"*\" is allowed) (optional)"), - &alias_info_infolist_alias_cb, NULL); + &alias_info_infolist_alias_cb, NULL, NULL); } diff --git a/src/plugins/alias/alias-info.h b/src/plugins/alias/alias-info.h index 3d0a65ba1..a06373a74 100644 --- a/src/plugins/alias/alias-info.h +++ b/src/plugins/alias/alias-info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index d4e3126ff..961748757 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -1,7 +1,7 @@ /* * alias.c - alias plugin for WeeChat: command aliases * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -337,7 +337,8 @@ alias_run_command (struct t_gui_buffer **buffer, const char *command) */ int -alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, +alias_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_alias *ptr_alias; @@ -346,9 +347,10 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, int some_args_replaced, length1, length2; /* make C compiler happy */ + (void) data; (void) argv; - ptr_alias = (struct t_alias *)data; + ptr_alias = (struct t_alias *)pointer; if (ptr_alias->running) { @@ -545,7 +547,7 @@ alias_hook_command (struct t_alias *alias) alias->command, NULL, NULL, (str_completion) ? str_completion : alias->completion, - &alias_cb, alias); + &alias_cb, alias, NULL); if (str_priority_name) free (str_priority_name); @@ -572,6 +574,33 @@ alias_update_completion (struct t_alias *alias, const char *completion) } /* + * Checks if an alias name is valid: it must not contain any slashes nor + * any spaces. + * + * Returns: + * 1: name is valid + * 0: name is invalid + */ + +int +alias_name_valid (const char *name) +{ + if (!name || !name[0]) + return 0; + + /* no spaces allowed */ + if (strchr (name, ' ')) + return 0; + + /* no slashes allowed */ + if (strchr (name, '/')) + return 0; + + /* name is valid */ + return 1; +} + +/* * Creates a new alias and adds it to alias list. * * Returns pointer to new alias, NULL if error. @@ -582,7 +611,16 @@ alias_new (const char *name, const char *command, const char *completion) { struct t_alias *new_alias, *ptr_alias, *pos_alias; - if (!name || !name[0] || !command || !command[0]) + if (!alias_name_valid (name)) + { + weechat_printf (NULL, + _("%s%s: invalid alias name: \"%s\""), + weechat_prefix ("error"), ALIAS_PLUGIN_NAME, + name); + return NULL; + } + + if (!command || !command[0]) return NULL; while (weechat_string_is_command_char (name)) diff --git a/src/plugins/alias/alias.h b/src/plugins/alias/alias.h index 1fd47f378..58c78a8d4 100644 --- a/src/plugins/alias/alias.h +++ b/src/plugins/alias/alias.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * |