diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-05-09 13:12:12 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-05-09 13:12:12 +0000 |
commit | 7290f0f1abbbb50e83ea0ab0e050839aebccb8eb (patch) | |
tree | 00ac3c529560448be65118936602f42ef83b3f26 | |
parent | 0093bf08497b22a23778822111c4ef86c744fa81 (diff) | |
download | weechat-7290f0f1abbbb50e83ea0ab0e050839aebccb8eb.zip |
Fixed bug with $nick/$channel/$server variables in commands
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/common/alias.c | 28 | ||||
-rw-r--r-- | src/common/alias.h | 4 | ||||
-rw-r--r-- | src/common/command.c | 4 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 2 | ||||
-rw-r--r-- | weechat/ChangeLog | 1 | ||||
-rw-r--r-- | weechat/src/common/alias.c | 28 | ||||
-rw-r--r-- | weechat/src/common/alias.h | 4 | ||||
-rw-r--r-- | weechat/src/common/command.c | 4 | ||||
-rw-r--r-- | weechat/src/irc/irc-recv.c | 2 |
10 files changed, 38 insertions, 40 deletions
@@ -5,6 +5,7 @@ ChangeLog - 2007-05-09 Version 0.2.5 (under dev!): + * fixed bug with $nick/$channel/$server variables in commands * forget current nick when user manually disconnects from server * fixed nick display in input window * fixed bug with erroneous nickname when connecting to server (bug #19812) diff --git a/src/common/alias.c b/src/common/alias.c index 703dd6928..eb45a3243 100644 --- a/src/common/alias.c +++ b/src/common/alias.c @@ -299,40 +299,36 @@ alias_replace_args (char *alias_args, char *user_args) */ char * -alias_replace_vars (char *string) +alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string) { - char *nick, *channel, *server; + char *var_nick, *var_channel, *var_server; char empty_string[1] = { '\0' }; char *res, *temp; - nick = (SERVER(gui_current_window->buffer) - && SERVER(gui_current_window->buffer)->nick) ? - SERVER(gui_current_window->buffer)->nick : empty_string; - channel = (CHANNEL(gui_current_window->buffer)) ? - CHANNEL(gui_current_window->buffer)->name : empty_string; - server = (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : empty_string; - + var_nick = (server && server->nick) ? server->nick : empty_string; + var_channel = (channel) ? channel->name : empty_string; + var_server = (server) ? server->name : empty_string; + /* replace nick */ - temp = weechat_strreplace (string, "$nick", nick); + temp = weechat_strreplace (string, "$nick", var_nick); if (!temp) return NULL; res = temp; - + /* replace channel */ - temp = weechat_strreplace (res, "$channel", channel); + temp = weechat_strreplace (res, "$channel", var_channel); free (res); if (!temp) return NULL; res = temp; - + /* replace server */ - temp = weechat_strreplace (res, "$server", server); + temp = weechat_strreplace (res, "$server", var_server); free (res); if (!temp) return NULL; res = temp; - + /* return result */ return res; } diff --git a/src/common/alias.h b/src/common/alias.h index 4a6cd051f..bac5f872d 100644 --- a/src/common/alias.h +++ b/src/common/alias.h @@ -21,6 +21,8 @@ #ifndef __WEECHAT_ALIAS_H #define __WEECHAT_ALIAS_H 1 +#include "../irc/irc.h" + typedef struct t_weechat_alias t_weechat_alias; struct t_weechat_alias @@ -39,7 +41,7 @@ extern t_weechat_alias *alias_search (char *); extern t_weechat_alias *alias_new (char *, char *); extern char *alias_get_final_command (t_weechat_alias *); extern char *alias_replace_args (char *, char *); -extern char *alias_replace_vars (char *); +extern char *alias_replace_vars (t_irc_server *, t_irc_channel *, char *); extern void alias_free (t_weechat_alias *); extern void alias_free_all (); diff --git a/src/common/command.c b/src/common/command.c index 954567699..311ac3868 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -379,7 +379,7 @@ exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string rc = -1; else { - vars_replaced = alias_replace_vars (ptr_args); + vars_replaced = alias_replace_vars (server, channel, ptr_args); rc = plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, (vars_replaced) ? vars_replaced : ptr_args); if (vars_replaced) @@ -429,7 +429,7 @@ exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string ptr_next_cmd = ptr_cmd; ptr_next_cmd++; - vars_replaced = alias_replace_vars (*ptr_cmd); + vars_replaced = alias_replace_vars (server, channel, *ptr_cmd); new_ptr_cmd = (vars_replaced) ? vars_replaced : *ptr_cmd; args_replaced = alias_replace_args (new_ptr_cmd, ptr_args); if (args_replaced) diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index b1d1b9e94..688444840 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -2419,7 +2419,7 @@ irc_cmd_recv_001 (t_irc_server *server, char *host, char *nick, char *arguments) { for (ptr = commands; *ptr; ptr++) { - vars_replaced = alias_replace_vars (*ptr); + vars_replaced = alias_replace_vars (server, NULL, *ptr); user_command (server, NULL, (vars_replaced) ? vars_replaced : *ptr, 0); if (vars_replaced) diff --git a/weechat/ChangeLog b/weechat/ChangeLog index 93f703e13..482302c0a 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -5,6 +5,7 @@ ChangeLog - 2007-05-09 Version 0.2.5 (under dev!): + * fixed bug with $nick/$channel/$server variables in commands * forget current nick when user manually disconnects from server * fixed nick display in input window * fixed bug with erroneous nickname when connecting to server (bug #19812) diff --git a/weechat/src/common/alias.c b/weechat/src/common/alias.c index 703dd6928..eb45a3243 100644 --- a/weechat/src/common/alias.c +++ b/weechat/src/common/alias.c @@ -299,40 +299,36 @@ alias_replace_args (char *alias_args, char *user_args) */ char * -alias_replace_vars (char *string) +alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string) { - char *nick, *channel, *server; + char *var_nick, *var_channel, *var_server; char empty_string[1] = { '\0' }; char *res, *temp; - nick = (SERVER(gui_current_window->buffer) - && SERVER(gui_current_window->buffer)->nick) ? - SERVER(gui_current_window->buffer)->nick : empty_string; - channel = (CHANNEL(gui_current_window->buffer)) ? - CHANNEL(gui_current_window->buffer)->name : empty_string; - server = (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : empty_string; - + var_nick = (server && server->nick) ? server->nick : empty_string; + var_channel = (channel) ? channel->name : empty_string; + var_server = (server) ? server->name : empty_string; + /* replace nick */ - temp = weechat_strreplace (string, "$nick", nick); + temp = weechat_strreplace (string, "$nick", var_nick); if (!temp) return NULL; res = temp; - + /* replace channel */ - temp = weechat_strreplace (res, "$channel", channel); + temp = weechat_strreplace (res, "$channel", var_channel); free (res); if (!temp) return NULL; res = temp; - + /* replace server */ - temp = weechat_strreplace (res, "$server", server); + temp = weechat_strreplace (res, "$server", var_server); free (res); if (!temp) return NULL; res = temp; - + /* return result */ return res; } diff --git a/weechat/src/common/alias.h b/weechat/src/common/alias.h index 4a6cd051f..bac5f872d 100644 --- a/weechat/src/common/alias.h +++ b/weechat/src/common/alias.h @@ -21,6 +21,8 @@ #ifndef __WEECHAT_ALIAS_H #define __WEECHAT_ALIAS_H 1 +#include "../irc/irc.h" + typedef struct t_weechat_alias t_weechat_alias; struct t_weechat_alias @@ -39,7 +41,7 @@ extern t_weechat_alias *alias_search (char *); extern t_weechat_alias *alias_new (char *, char *); extern char *alias_get_final_command (t_weechat_alias *); extern char *alias_replace_args (char *, char *); -extern char *alias_replace_vars (char *); +extern char *alias_replace_vars (t_irc_server *, t_irc_channel *, char *); extern void alias_free (t_weechat_alias *); extern void alias_free_all (); diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c index 954567699..311ac3868 100644 --- a/weechat/src/common/command.c +++ b/weechat/src/common/command.c @@ -379,7 +379,7 @@ exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string rc = -1; else { - vars_replaced = alias_replace_vars (ptr_args); + vars_replaced = alias_replace_vars (server, channel, ptr_args); rc = plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, (vars_replaced) ? vars_replaced : ptr_args); if (vars_replaced) @@ -429,7 +429,7 @@ exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string ptr_next_cmd = ptr_cmd; ptr_next_cmd++; - vars_replaced = alias_replace_vars (*ptr_cmd); + vars_replaced = alias_replace_vars (server, channel, *ptr_cmd); new_ptr_cmd = (vars_replaced) ? vars_replaced : *ptr_cmd; args_replaced = alias_replace_args (new_ptr_cmd, ptr_args); if (args_replaced) diff --git a/weechat/src/irc/irc-recv.c b/weechat/src/irc/irc-recv.c index b1d1b9e94..688444840 100644 --- a/weechat/src/irc/irc-recv.c +++ b/weechat/src/irc/irc-recv.c @@ -2419,7 +2419,7 @@ irc_cmd_recv_001 (t_irc_server *server, char *host, char *nick, char *arguments) { for (ptr = commands; *ptr; ptr++) { - vars_replaced = alias_replace_vars (*ptr); + vars_replaced = alias_replace_vars (server, NULL, *ptr); user_command (server, NULL, (vars_replaced) ? vars_replaced : *ptr, 0); if (vars_replaced) |