summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2003-10-02 22:42:51 +0000
committerSebastien Helleu <flashcode@flashtux.org>2003-10-02 22:42:51 +0000
commit106bdb1d4ac51198ffed5f28c35818e842432e33 (patch)
tree507f5a986ddb7b69490c41c91399f085e92d74f0
parentef4e6b93e0ce0370ed1f29a546e69f044cfe1ad1 (diff)
downloadweechat-106bdb1d4ac51198ffed5f28c35818e842432e33.zip
Added /alias and /unalias commands
-rw-r--r--BUGS3
-rw-r--r--ChangeLog3
-rw-r--r--TODO4
-rw-r--r--src/command.c286
-rw-r--r--src/command.h14
-rw-r--r--weechat/BUGS3
-rw-r--r--weechat/ChangeLog3
-rw-r--r--weechat/TODO4
-rw-r--r--weechat/src/command.c286
-rw-r--r--weechat/src/command.h14
10 files changed, 574 insertions, 46 deletions
diff --git a/BUGS b/BUGS
index 44f22ed1f..2f1952d8b 100644
--- a/BUGS
+++ b/BUGS
@@ -1,12 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-WeeChat known bugs, 2003-09-29
+WeeChat known bugs, 2003-10-03
- too much nicks in the channel (> height of window) => display bug
- some IRC commands are marked as 'unknown' when received
(IRC protocol is under dev!)
-- alias/unalias commands doesn't work
- config is not saved (to ~/.weechat/weechatrc)
- intercept Ctrl-C (do not quit immediately if Ctrl-C pressed!)
- program is stopped when bad option in config file (it should not, only display
diff --git a/ChangeLog b/ChangeLog
index 40d3be739..bbd472750 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-ChangeLog - 2003-10-01
+ChangeLog - 2003-10-03
Version 0.0.2 (under dev!):
+ * alias for commands (new commands /alias and /unalias)
* config is now saved automatically when quitting WeeChat
* added new WeeChat commands: server, connect, disconnect, save
* added autoconnect flag for each server in config file
diff --git a/TODO b/TODO
index 7e6ad7e12..cc590b41e 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-TODO - 2003-10-01
+TODO - 2003-10-03
Legend:
# done
@@ -27,6 +27,7 @@ v0.0.2:
+ "/set" command: allow the user to set the WeeChat variables
under WeeChat without editing the config file (colours, time
format, etc)
+ - "/alias" and "/unalias" commands
- "/highlight" command: highlight a given word when it appears on
channels/privates
@@ -38,6 +39,7 @@ v0.0.2:
* Configuration:
# write config file
+ + add alias definition
- add an option for each server in order to run commands on join
(example: /msg nickserv identify password)
- channel list for auto-join (for each server)
diff --git a/src/command.c b/src/command.c
index 79b23356f..91463ea6d 100644
--- a/src/command.c
+++ b/src/command.c
@@ -39,8 +39,8 @@ t_weechat_command weechat_commands[] =
{ { "alias", N_("create an alias for a command"),
N_("[alias_name [command [arguments]]"),
N_("alias_name: name of alias\ncommand: command name (" WEECHAT_NAME
- " or IRC command)\n" "arguments: arguments for command"),
- 0, MAX_ARGS, weechat_cmd_alias, NULL },
+ " or IRC command, without first '/')\n" "arguments: arguments for command"),
+ 0, MAX_ARGS, NULL, weechat_cmd_alias },
{ "clear", N_("clear window(s)"),
N_("[-all]"),
N_("-all: clear all windows"),
@@ -79,16 +79,36 @@ t_weechat_command weechat_commands[] =
0, 2, weechat_cmd_set, NULL },
{ "unalias", N_("remove an alias"),
N_("alias_name"), N_("alias_name: name of alias to remove"),
- 1, 1, weechat_cmd_unalias, NULL },
+ 1, 1, NULL, weechat_cmd_unalias },
{ NULL, NULL, NULL, NULL, 0, 0, NULL, NULL }
};
+t_weechat_alias *weechat_alias = NULL;
+t_weechat_alias *weechat_last_alias = NULL;
+
t_index_command *index_commands;
t_index_command *last_index_command;
/*
- * index_find_pos: find position for a command index (for sorting index)
+ * index_command_search: search a command
+ */
+
+t_index_command *
+index_command_search (char *command)
+{
+ t_index_command *ptr_index;
+
+ for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
+ {
+ if (strcasecmp (command, ptr_index->command_name) == 0)
+ return ptr_index;
+ }
+ return NULL;
+}
+
+/*
+ * index_command_find_pos: find position for a command index (for sorting index)
*/
t_index_command *
@@ -144,7 +164,36 @@ index_command_insert_sorted (t_index_command *index)
index_commands = index;
last_index_command = index;
}
- return;
+}
+
+/*
+ * index_command_free: free an index command and reomve it from list
+ */
+
+void
+index_command_free (t_index_command *index)
+{
+ t_index_command *new_index_commands;
+
+ /* remove index command from list */
+ if (last_index_command == index)
+ last_index_command = index->prev_index;
+ if (index->prev_index)
+ {
+ (index->prev_index)->next_index = index->next_index;
+ new_index_commands = index_commands;
+ }
+ else
+ new_index_commands = index->next_index;
+
+ if (index->next_index)
+ (index->next_index)->prev_index = index->prev_index;
+
+ /* free data */
+ if (index->command_name)
+ free (index->command_name);
+ free (index);
+ index_commands = new_index_commands;
}
/*
@@ -186,6 +235,114 @@ index_command_build ()
}
/*
+ * alias_search: search an alias
+ */
+
+t_weechat_alias *
+alias_search (char *alias_name)
+{
+ t_weechat_alias *ptr_alias;
+
+ for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (alias_name, ptr_alias->alias_name) == 0)
+ return ptr_alias;
+ }
+ return NULL;
+}
+
+/*
+ * alias_find_pos: find position for an alias (for sorting aliases)
+ */
+
+t_weechat_alias *
+alias_find_pos (char *alias_name)
+{
+ t_weechat_alias *ptr_alias;
+
+ for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (alias_name, ptr_alias->alias_name) < 0)
+ return ptr_alias;
+ }
+ return NULL;
+}
+
+/*
+ * alias_insert_sorted: insert alias into sorted list
+ */
+
+void
+alias_insert_sorted (t_weechat_alias *alias)
+{
+ t_weechat_alias *pos_alias;
+
+ pos_alias = alias_find_pos (alias->alias_name);
+
+ if (weechat_alias)
+ {
+ if (pos_alias)
+ {
+ /* insert alias into the list (before alias found) */
+ alias->prev_alias = pos_alias->prev_alias;
+ alias->next_alias = pos_alias;
+ if (pos_alias->prev_alias)
+ pos_alias->prev_alias->next_alias = alias;
+ else
+ weechat_alias = alias;
+ pos_alias->prev_alias = alias;
+ }
+ else
+ {
+ /* add alias to the end */
+ alias->prev_alias = weechat_last_alias;
+ alias->next_alias = NULL;
+ weechat_last_alias->next_alias = alias;
+ weechat_last_alias = alias;
+ }
+ }
+ else
+ {
+ alias->prev_alias = NULL;
+ alias->next_alias = NULL;
+ weechat_alias = alias;
+ weechat_last_alias = alias;
+ }
+}
+
+/*
+ * alias_free: free an alias and reomve it from list
+ */
+
+void
+alias_free (t_weechat_alias *alias)
+{
+ t_weechat_alias *new_weechat_alias;
+
+ /* remove alias from list */
+ if (weechat_last_alias == alias)
+ weechat_last_alias = alias->prev_alias;
+ if (alias->prev_alias)
+ {
+ (alias->prev_alias)->next_alias = alias->next_alias;
+ new_weechat_alias = weechat_alias;
+ }
+ else
+ new_weechat_alias = alias->next_alias;
+
+ if (alias->next_alias)
+ (alias->next_alias)->prev_alias = alias->prev_alias;
+
+ /* free data */
+ if (alias->alias_name)
+ free (alias->alias_name);
+ if (alias->alias_command)
+ free (alias->alias_command);
+ free (alias);
+ weechat_alias = new_weechat_alias;
+}
+
+/*
* explode_string: explode a string according to separators
*/
@@ -281,6 +438,7 @@ exec_weechat_command (t_irc_server *server, char *string)
{
int i, j, argc, return_code;
char *pos, *ptr_args, **argv;
+ t_weechat_alias *ptr_alias;
if ((!string[0]) || (string[0] != '/'))
return 0;
@@ -411,7 +569,16 @@ exec_weechat_command (t_irc_server *server, char *string)
return 1;
}
}
- gui_printf (server->window,
+ for (ptr_alias = weechat_alias; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (ptr_alias->alias_name, string + 1) == 0)
+ {
+ exec_weechat_command (server, ptr_alias->alias_command);
+ return 1;
+ }
+ }
+ gui_printf (NULL,
_("%s unknown command '%s' (type /help for help)\n"),
WEECHAT_ERROR,
string + 1);
@@ -493,14 +660,91 @@ user_command (t_irc_server *server, char *command)
*/
int
-weechat_cmd_alias (int argc, char **argv)
+weechat_cmd_alias (char *arguments)
{
- if (argc == 0)
+ char *pos, *pos2;
+ t_weechat_alias *ptr_alias, *new_alias;
+ t_index_command *new_index;
+
+ if (arguments && arguments[0])
+ {
+ /* Define new alias */
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (!pos[0])
+ {
+ gui_printf (NULL, _("%s missing arguments for \"alias\" command\n"),
+ 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] = ' ';
+ if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
+ {
+ new_index->command_name = strdup (arguments);
+ index_command_insert_sorted (new_index);
+ }
+ if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias)))))
+ {
+ new_alias->alias_name = strdup (arguments);
+ new_alias->alias_command = (char *)malloc (strlen (pos) + 2);
+ new_alias->alias_command[0] = '/';
+ strcpy (new_alias->alias_command + 1, pos);
+ alias_insert_sorted (new_alias);
+ }
+ gui_printf (NULL, _("Alias \"%s\" => \"%s\" created\n"),
+ arguments, pos);
+ }
+ else
+ {
+ gui_printf (NULL, _("%s missing arguments for \"alias\" command\n"),
+ WEECHAT_ERROR);
+ return -1;
+ }
+ }
+ else
{
/* List all aliases */
+ if (weechat_alias)
+ {
+ gui_printf (NULL, _("List of aliases:\n"));
+ for (ptr_alias = weechat_alias; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ gui_printf (NULL, " %s => %s\n",
+ ptr_alias->alias_name,
+ ptr_alias->alias_command + 1);
+ }
+ }
+ else
+ gui_printf (NULL, _("No alias defined.\n"));
}
- argv = NULL;
- gui_printf (NULL, _("(TODO) \"/alias\" command not developed!\n"));
return 0;
}
@@ -1034,16 +1278,24 @@ weechat_cmd_set (int argc, char **argv)
*/
int
-weechat_cmd_unalias (int argc, char **argv)
+weechat_cmd_unalias (char *arguments)
{
- if (argc != 1)
+ t_index_command *ptr_index;
+ t_weechat_alias *ptr_alias;
+
+ ptr_index = index_command_search (arguments);
+ if (!ptr_index)
{
- gui_printf
- (NULL,
- _("Wrong argument count for unalias function (expexted: 1 arg)\n"));
+ gui_printf (NULL, _("%s alias or command \"%s\" not found\n"),
+ WEECHAT_ERROR, arguments);
return -1;
}
- argv = NULL;
- gui_printf (NULL, _("(TODO) \"/unalias\" not developed!\n"));
+
+ index_command_free (ptr_index);
+ ptr_alias = alias_search (arguments);
+ if (ptr_alias)
+ alias_free (ptr_alias);
+ gui_printf (NULL, _("Alias \"%s\" removed\n"),
+ arguments);
return 0;
}
diff --git a/src/command.h b/src/command.h
index b8857c0ef..ac248c526 100644
--- a/src/command.h
+++ b/src/command.h
@@ -40,6 +40,16 @@ struct t_weechat_command
int (*cmd_function_1arg)(char *);
};
+typedef struct t_weechat_alias t_weechat_alias;
+
+struct t_weechat_alias
+{
+ char *alias_name;
+ char *alias_command;
+ t_weechat_alias *prev_alias;
+ t_weechat_alias *next_alias;
+};
+
typedef struct t_index_command t_index_command;
struct t_index_command
@@ -54,7 +64,7 @@ extern t_index_command *index_commands;
extern void index_command_build ();
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
-extern int weechat_cmd_alias (int, char **);
+extern int weechat_cmd_alias (char *);
extern int weechat_cmd_clear (int, char **);
extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_disconnect (int, char **);
@@ -62,6 +72,6 @@ extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_save (int, char **);
extern int weechat_cmd_set (int, char **);
-extern int weechat_cmd_unalias (int, char **);
+extern int weechat_cmd_unalias (char *);
#endif /* command.h */
diff --git a/weechat/BUGS b/weechat/BUGS
index 44f22ed1f..2f1952d8b 100644
--- a/weechat/BUGS
+++ b/weechat/BUGS
@@ -1,12 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-WeeChat known bugs, 2003-09-29
+WeeChat known bugs, 2003-10-03
- too much nicks in the channel (> height of window) => display bug
- some IRC commands are marked as 'unknown' when received
(IRC protocol is under dev!)
-- alias/unalias commands doesn't work
- config is not saved (to ~/.weechat/weechatrc)
- intercept Ctrl-C (do not quit immediately if Ctrl-C pressed!)
- program is stopped when bad option in config file (it should not, only display
diff --git a/weechat/ChangeLog b/weechat/ChangeLog
index 40d3be739..bbd472750 100644
--- a/weechat/ChangeLog
+++ b/weechat/ChangeLog
@@ -1,10 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-ChangeLog - 2003-10-01
+ChangeLog - 2003-10-03
Version 0.0.2 (under dev!):
+ * alias for commands (new commands /alias and /unalias)
* config is now saved automatically when quitting WeeChat
* added new WeeChat commands: server, connect, disconnect, save
* added autoconnect flag for each server in config file
diff --git a/weechat/TODO b/weechat/TODO
index 7e6ad7e12..cc590b41e 100644
--- a/weechat/TODO
+++ b/weechat/TODO
@@ -1,7 +1,7 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-TODO - 2003-10-01
+TODO - 2003-10-03
Legend:
# done
@@ -27,6 +27,7 @@ v0.0.2:
+ "/set" command: allow the user to set the WeeChat variables
under WeeChat without editing the config file (colours, time
format, etc)
+ - "/alias" and "/unalias" commands
- "/highlight" command: highlight a given word when it appears on
channels/privates
@@ -38,6 +39,7 @@ v0.0.2:
* Configuration:
# write config file
+ + add alias definition
- add an option for each server in order to run commands on join
(example: /msg nickserv identify password)
- channel list for auto-join (for each server)
diff --git a/weechat/src/command.c b/weechat/src/command.c
index 79b23356f..91463ea6d 100644
--- a/weechat/src/command.c
+++ b/weechat/src/command.c
@@ -39,8 +39,8 @@ t_weechat_command weechat_commands[] =
{ { "alias", N_("create an alias for a command"),
N_("[alias_name [command [arguments]]"),
N_("alias_name: name of alias\ncommand: command name (" WEECHAT_NAME
- " or IRC command)\n" "arguments: arguments for command"),
- 0, MAX_ARGS, weechat_cmd_alias, NULL },
+ " or IRC command, without first '/')\n" "arguments: arguments for command"),
+ 0, MAX_ARGS, NULL, weechat_cmd_alias },
{ "clear", N_("clear window(s)"),
N_("[-all]"),
N_("-all: clear all windows"),
@@ -79,16 +79,36 @@ t_weechat_command weechat_commands[] =
0, 2, weechat_cmd_set, NULL },
{ "unalias", N_("remove an alias"),
N_("alias_name"), N_("alias_name: name of alias to remove"),
- 1, 1, weechat_cmd_unalias, NULL },
+ 1, 1, NULL, weechat_cmd_unalias },
{ NULL, NULL, NULL, NULL, 0, 0, NULL, NULL }
};
+t_weechat_alias *weechat_alias = NULL;
+t_weechat_alias *weechat_last_alias = NULL;
+
t_index_command *index_commands;
t_index_command *last_index_command;
/*
- * index_find_pos: find position for a command index (for sorting index)
+ * index_command_search: search a command
+ */
+
+t_index_command *
+index_command_search (char *command)
+{
+ t_index_command *ptr_index;
+
+ for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
+ {
+ if (strcasecmp (command, ptr_index->command_name) == 0)
+ return ptr_index;
+ }
+ return NULL;
+}
+
+/*
+ * index_command_find_pos: find position for a command index (for sorting index)
*/
t_index_command *
@@ -144,7 +164,36 @@ index_command_insert_sorted (t_index_command *index)
index_commands = index;
last_index_command = index;
}
- return;
+}
+
+/*
+ * index_command_free: free an index command and reomve it from list
+ */
+
+void
+index_command_free (t_index_command *index)
+{
+ t_index_command *new_index_commands;
+
+ /* remove index command from list */
+ if (last_index_command == index)
+ last_index_command = index->prev_index;
+ if (index->prev_index)
+ {
+ (index->prev_index)->next_index = index->next_index;
+ new_index_commands = index_commands;
+ }
+ else
+ new_index_commands = index->next_index;
+
+ if (index->next_index)
+ (index->next_index)->prev_index = index->prev_index;
+
+ /* free data */
+ if (index->command_name)
+ free (index->command_name);
+ free (index);
+ index_commands = new_index_commands;
}
/*
@@ -186,6 +235,114 @@ index_command_build ()
}
/*
+ * alias_search: search an alias
+ */
+
+t_weechat_alias *
+alias_search (char *alias_name)
+{
+ t_weechat_alias *ptr_alias;
+
+ for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (alias_name, ptr_alias->alias_name) == 0)
+ return ptr_alias;
+ }
+ return NULL;
+}
+
+/*
+ * alias_find_pos: find position for an alias (for sorting aliases)
+ */
+
+t_weechat_alias *
+alias_find_pos (char *alias_name)
+{
+ t_weechat_alias *ptr_alias;
+
+ for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (alias_name, ptr_alias->alias_name) < 0)
+ return ptr_alias;
+ }
+ return NULL;
+}
+
+/*
+ * alias_insert_sorted: insert alias into sorted list
+ */
+
+void
+alias_insert_sorted (t_weechat_alias *alias)
+{
+ t_weechat_alias *pos_alias;
+
+ pos_alias = alias_find_pos (alias->alias_name);
+
+ if (weechat_alias)
+ {
+ if (pos_alias)
+ {
+ /* insert alias into the list (before alias found) */
+ alias->prev_alias = pos_alias->prev_alias;
+ alias->next_alias = pos_alias;
+ if (pos_alias->prev_alias)
+ pos_alias->prev_alias->next_alias = alias;
+ else
+ weechat_alias = alias;
+ pos_alias->prev_alias = alias;
+ }
+ else
+ {
+ /* add alias to the end */
+ alias->prev_alias = weechat_last_alias;
+ alias->next_alias = NULL;
+ weechat_last_alias->next_alias = alias;
+ weechat_last_alias = alias;
+ }
+ }
+ else
+ {
+ alias->prev_alias = NULL;
+ alias->next_alias = NULL;
+ weechat_alias = alias;
+ weechat_last_alias = alias;
+ }
+}
+
+/*
+ * alias_free: free an alias and reomve it from list
+ */
+
+void
+alias_free (t_weechat_alias *alias)
+{
+ t_weechat_alias *new_weechat_alias;
+
+ /* remove alias from list */
+ if (weechat_last_alias == alias)
+ weechat_last_alias = alias->prev_alias;
+ if (alias->prev_alias)
+ {
+ (alias->prev_alias)->next_alias = alias->next_alias;
+ new_weechat_alias = weechat_alias;
+ }
+ else
+ new_weechat_alias = alias->next_alias;
+
+ if (alias->next_alias)
+ (alias->next_alias)->prev_alias = alias->prev_alias;
+
+ /* free data */
+ if (alias->alias_name)
+ free (alias->alias_name);
+ if (alias->alias_command)
+ free (alias->alias_command);
+ free (alias);
+ weechat_alias = new_weechat_alias;
+}
+
+/*
* explode_string: explode a string according to separators
*/
@@ -281,6 +438,7 @@ exec_weechat_command (t_irc_server *server, char *string)
{
int i, j, argc, return_code;
char *pos, *ptr_args, **argv;
+ t_weechat_alias *ptr_alias;
if ((!string[0]) || (string[0] != '/'))
return 0;
@@ -411,7 +569,16 @@ exec_weechat_command (t_irc_server *server, char *string)
return 1;
}
}
- gui_printf (server->window,
+ for (ptr_alias = weechat_alias; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ if (strcasecmp (ptr_alias->alias_name, string + 1) == 0)
+ {
+ exec_weechat_command (server, ptr_alias->alias_command);
+ return 1;
+ }
+ }
+ gui_printf (NULL,
_("%s unknown command '%s' (type /help for help)\n"),
WEECHAT_ERROR,
string + 1);
@@ -493,14 +660,91 @@ user_command (t_irc_server *server, char *command)
*/
int
-weechat_cmd_alias (int argc, char **argv)
+weechat_cmd_alias (char *arguments)
{
- if (argc == 0)
+ char *pos, *pos2;
+ t_weechat_alias *ptr_alias, *new_alias;
+ t_index_command *new_index;
+
+ if (arguments && arguments[0])
+ {
+ /* Define new alias */
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (!pos[0])
+ {
+ gui_printf (NULL, _("%s missing arguments for \"alias\" command\n"),
+ 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] = ' ';
+ if ((new_index = ((t_index_command *) malloc (sizeof (t_index_command)))))
+ {
+ new_index->command_name = strdup (arguments);
+ index_command_insert_sorted (new_index);
+ }
+ if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias)))))
+ {
+ new_alias->alias_name = strdup (arguments);
+ new_alias->alias_command = (char *)malloc (strlen (pos) + 2);
+ new_alias->alias_command[0] = '/';
+ strcpy (new_alias->alias_command + 1, pos);
+ alias_insert_sorted (new_alias);
+ }
+ gui_printf (NULL, _("Alias \"%s\" => \"%s\" created\n"),
+ arguments, pos);
+ }
+ else
+ {
+ gui_printf (NULL, _("%s missing arguments for \"alias\" command\n"),
+ WEECHAT_ERROR);
+ return -1;
+ }
+ }
+ else
{
/* List all aliases */
+ if (weechat_alias)
+ {
+ gui_printf (NULL, _("List of aliases:\n"));
+ for (ptr_alias = weechat_alias; ptr_alias;
+ ptr_alias = ptr_alias->next_alias)
+ {
+ gui_printf (NULL, " %s => %s\n",
+ ptr_alias->alias_name,
+ ptr_alias->alias_command + 1);
+ }
+ }
+ else
+ gui_printf (NULL, _("No alias defined.\n"));
}
- argv = NULL;
- gui_printf (NULL, _("(TODO) \"/alias\" command not developed!\n"));
return 0;
}
@@ -1034,16 +1278,24 @@ weechat_cmd_set (int argc, char **argv)
*/
int
-weechat_cmd_unalias (int argc, char **argv)
+weechat_cmd_unalias (char *arguments)
{
- if (argc != 1)
+ t_index_command *ptr_index;
+ t_weechat_alias *ptr_alias;
+
+ ptr_index = index_command_search (arguments);
+ if (!ptr_index)
{
- gui_printf
- (NULL,
- _("Wrong argument count for unalias function (expexted: 1 arg)\n"));
+ gui_printf (NULL, _("%s alias or command \"%s\" not found\n"),
+ WEECHAT_ERROR, arguments);
return -1;
}
- argv = NULL;
- gui_printf (NULL, _("(TODO) \"/unalias\" not developed!\n"));
+
+ index_command_free (ptr_index);
+ ptr_alias = alias_search (arguments);
+ if (ptr_alias)
+ alias_free (ptr_alias);
+ gui_printf (NULL, _("Alias \"%s\" removed\n"),
+ arguments);
return 0;
}
diff --git a/weechat/src/command.h b/weechat/src/command.h
index b8857c0ef..ac248c526 100644
--- a/weechat/src/command.h
+++ b/weechat/src/command.h
@@ -40,6 +40,16 @@ struct t_weechat_command
int (*cmd_function_1arg)(char *);
};
+typedef struct t_weechat_alias t_weechat_alias;
+
+struct t_weechat_alias
+{
+ char *alias_name;
+ char *alias_command;
+ t_weechat_alias *prev_alias;
+ t_weechat_alias *next_alias;
+};
+
typedef struct t_index_command t_index_command;
struct t_index_command
@@ -54,7 +64,7 @@ extern t_index_command *index_commands;
extern void index_command_build ();
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
-extern int weechat_cmd_alias (int, char **);
+extern int weechat_cmd_alias (char *);
extern int weechat_cmd_clear (int, char **);
extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_disconnect (int, char **);
@@ -62,6 +72,6 @@ extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_save (int, char **);
extern int weechat_cmd_set (int, char **);
-extern int weechat_cmd_unalias (int, char **);
+extern int weechat_cmd_unalias (char *);
#endif /* command.h */