From 3782ef828a0ef0505b965367cf02b39038666066 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 3 Oct 2003 19:50:37 +0000 Subject: [PATCH] Added control of alias when config file is loaded --- TODO | 1 + src/command.c | 50 ++++++++++++++++++++++--------------------- src/config.c | 4 ++-- weechat/TODO | 1 + weechat/src/command.c | 50 ++++++++++++++++++++++--------------------- weechat/src/config.c | 4 ++-- 6 files changed, 58 insertions(+), 52 deletions(-) diff --git a/TODO b/TODO index eb98f8231..f1c211b19 100644 --- a/TODO +++ b/TODO @@ -93,6 +93,7 @@ Future versions: * Configuration: - add key bindings to config file - add missing options for config file + - wrong alias is not created and not saved when quitting WeeChat * Plugins: - add Perl plugin diff --git a/src/command.c b/src/command.c index 8e9759b8e..53d5564c4 100644 --- a/src/command.c +++ b/src/command.c @@ -324,8 +324,33 @@ alias_insert_sorted (t_weechat_alias *alias) t_weechat_alias * alias_new (char *alias_name, char *alias_command) { + char *pos; t_weechat_alias *new_alias; + if (index_command_search (alias_name)) + { + gui_printf (NULL, _("%s alias or command \"%s\" already exists!\n"), + WEECHAT_ERROR, alias_name); + return NULL; + } + pos = strchr (alias_command, ' '); + if (pos) + pos[0] = '\0'; + if (alias_search (alias_command)) + { + gui_printf (NULL, _("%s alias cannot run another alias!\n"), + WEECHAT_ERROR); + return NULL; + } + if (!index_command_search (alias_command)) + { + gui_printf (NULL, _("%s target command \"%s\" does not exist!\n"), + WEECHAT_ERROR, pos); + return NULL; + } + if (pos) + pos[0] = ' '; + if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias))))) { new_alias->alias_name = strdup (alias_name); @@ -710,7 +735,7 @@ user_command (t_irc_server *server, char *command) int weechat_cmd_alias (char *arguments) { - char *pos, *pos2; + char *pos; t_weechat_alias *ptr_alias; if (arguments && arguments[0]) @@ -729,29 +754,6 @@ weechat_cmd_alias (char *arguments) WEECHAT_ERROR); return -1; } - if (index_command_search (arguments)) - { - gui_printf (NULL, _("%s alias or command \"%s\" already exists!\n"), - WEECHAT_ERROR, arguments); - return -1; - } - pos2 = strchr (pos, ' '); - if (pos2) - pos2[0] = '\0'; - if (alias_search (pos)) - { - gui_printf (NULL, _("%s alias cannot run another alias!\n"), - WEECHAT_ERROR); - return -1; - } - if (!index_command_search (pos)) - { - gui_printf (NULL, _("%s target command \"%s\" does not exist!\n"), - WEECHAT_ERROR, pos); - return -1; - } - if (pos2) - pos2[0] = ' '; index_command_new (arguments); if (!alias_new (arguments, pos)) return -1; diff --git a/src/config.c b/src/config.c index 1282b3620..5935af5b0 100644 --- a/src/config.c +++ b/src/config.c @@ -730,8 +730,8 @@ config_read () if (section == CONFIG_SECTION_ALIAS) { - index_command_new (pos); - alias_new (line, pos); + if (alias_new (line, pos)) + index_command_new (pos); } else { diff --git a/weechat/TODO b/weechat/TODO index eb98f8231..f1c211b19 100644 --- a/weechat/TODO +++ b/weechat/TODO @@ -93,6 +93,7 @@ Future versions: * Configuration: - add key bindings to config file - add missing options for config file + - wrong alias is not created and not saved when quitting WeeChat * Plugins: - add Perl plugin diff --git a/weechat/src/command.c b/weechat/src/command.c index 8e9759b8e..53d5564c4 100644 --- a/weechat/src/command.c +++ b/weechat/src/command.c @@ -324,8 +324,33 @@ alias_insert_sorted (t_weechat_alias *alias) t_weechat_alias * alias_new (char *alias_name, char *alias_command) { + char *pos; t_weechat_alias *new_alias; + if (index_command_search (alias_name)) + { + gui_printf (NULL, _("%s alias or command \"%s\" already exists!\n"), + WEECHAT_ERROR, alias_name); + return NULL; + } + pos = strchr (alias_command, ' '); + if (pos) + pos[0] = '\0'; + if (alias_search (alias_command)) + { + gui_printf (NULL, _("%s alias cannot run another alias!\n"), + WEECHAT_ERROR); + return NULL; + } + if (!index_command_search (alias_command)) + { + gui_printf (NULL, _("%s target command \"%s\" does not exist!\n"), + WEECHAT_ERROR, pos); + return NULL; + } + if (pos) + pos[0] = ' '; + if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias))))) { new_alias->alias_name = strdup (alias_name); @@ -710,7 +735,7 @@ user_command (t_irc_server *server, char *command) int weechat_cmd_alias (char *arguments) { - char *pos, *pos2; + char *pos; t_weechat_alias *ptr_alias; if (arguments && arguments[0]) @@ -729,29 +754,6 @@ weechat_cmd_alias (char *arguments) WEECHAT_ERROR); return -1; } - if (index_command_search (arguments)) - { - gui_printf (NULL, _("%s alias or command \"%s\" already exists!\n"), - WEECHAT_ERROR, arguments); - return -1; - } - pos2 = strchr (pos, ' '); - if (pos2) - pos2[0] = '\0'; - if (alias_search (pos)) - { - gui_printf (NULL, _("%s alias cannot run another alias!\n"), - WEECHAT_ERROR); - return -1; - } - if (!index_command_search (pos)) - { - gui_printf (NULL, _("%s target command \"%s\" does not exist!\n"), - WEECHAT_ERROR, pos); - return -1; - } - if (pos2) - pos2[0] = ' '; index_command_new (arguments); if (!alias_new (arguments, pos)) return -1; diff --git a/weechat/src/config.c b/weechat/src/config.c index 1282b3620..5935af5b0 100644 --- a/weechat/src/config.c +++ b/weechat/src/config.c @@ -730,8 +730,8 @@ config_read () if (section == CONFIG_SECTION_ALIAS) { - index_command_new (pos); - alias_new (line, pos); + if (alias_new (line, pos)) + index_command_new (pos); } else {