summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/alias.c28
-rw-r--r--src/common/alias.h4
-rw-r--r--src/common/command.c4
3 files changed, 17 insertions, 19 deletions
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)