From ebd17f79eb1a8c7db7e11e12b97a757f74c9881e Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Wed, 30 Sep 2009 17:25:55 +0200 Subject: Display alias command in /help alias_name (patch #6924) --- src/plugins/alias/alias.c | 108 +++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 22b084732..d0aa7ca0a 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -324,6 +324,53 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, return WEECHAT_RC_OK; } +/* + * alias_free: free an alias and remove it from list + */ + +void +alias_free (struct t_alias *alias) +{ + struct t_alias *new_alias_list; + + /* remove alias from list */ + if (last_alias == alias) + last_alias = alias->prev_alias; + if (alias->prev_alias) + { + (alias->prev_alias)->next_alias = alias->next_alias; + new_alias_list = alias_list; + } + else + new_alias_list = alias->next_alias; + if (alias->next_alias) + (alias->next_alias)->prev_alias = alias->prev_alias; + + /* free data */ + if (alias->hook) + weechat_unhook (alias->hook); + if (alias->name) + free (alias->name); + if (alias->command) + free (alias->command); + free (alias); + + alias_list = new_alias_list; +} + +/* + * alias_free_all: free all alias + */ + +void +alias_free_all () +{ + while (alias_list) + { + alias_free (alias_list); + } +} + /* * alias_find_pos: find position for an alias (for sorting aliases) */ @@ -365,12 +412,7 @@ alias_new (const char *name, const char *command) ptr_alias = alias_search (name); if (ptr_alias) - { - if (ptr_alias->command) - free (ptr_alias->command); - ptr_alias->command = strdup (command); - return ptr_alias; - } + alias_free (ptr_alias); new_alias = malloc (sizeof (*new_alias)); if (new_alias) @@ -382,7 +424,7 @@ alias_new (const char *name, const char *command) snprintf (str_completion, length, "%%%%%s", (command[0] == '/') ? command + 1 : command); } - new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, + new_hook = weechat_hook_command (name, command, NULL, NULL, (str_completion) ? str_completion : NULL, alias_cb, new_alias); if (str_completion) @@ -466,53 +508,6 @@ alias_get_final_command (struct t_alias *alias) alias->command + 1 : alias->command; } -/* - * alias_free: free an alias and remove it from list - */ - -void -alias_free (struct t_alias *alias) -{ - struct t_alias *new_alias_list; - - /* remove alias from list */ - if (last_alias == alias) - last_alias = alias->prev_alias; - if (alias->prev_alias) - { - (alias->prev_alias)->next_alias = alias->next_alias; - new_alias_list = alias_list; - } - else - new_alias_list = alias->next_alias; - if (alias->next_alias) - (alias->next_alias)->prev_alias = alias->prev_alias; - - /* free data */ - if (alias->hook) - weechat_unhook (alias->hook); - if (alias->name) - free (alias->name); - if (alias->command) - free (alias->command); - free (alias); - - alias_list = new_alias_list; -} - -/* - * alias_free_all: free all alias - */ - -void -alias_free_all () -{ - while (alias_list) - { - alias_free (alias_list); - } -} - /* * alias_config_change_cb: callback called when alias option is modified */ @@ -520,14 +515,9 @@ alias_free_all () void alias_config_change_cb (void *data, struct t_config_option *option) { - struct t_alias *ptr_alias; - /* make C compiler happy */ (void) data; - ptr_alias = alias_search (weechat_config_option_get_pointer (option, "name")); - if (ptr_alias) - alias_free (ptr_alias); alias_new (weechat_config_option_get_pointer (option, "name"), weechat_config_option_get_pointer (option, "value")); } -- cgit v1.2.3