diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-12-03 18:03:10 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-12-03 18:03:10 +0100 |
commit | 2888d41425afc7e38238533a95930cf0f46cc10c (patch) | |
tree | 8364be89c534411d08ecb9f291f1d4d64d28e6f4 /src | |
parent | e0826e1ce7bcff9c0404da0f2fac05b7224aad2c (diff) | |
download | weechat-2888d41425afc7e38238533a95930cf0f46cc10c.zip |
Added alias plugin, added missing config file functions in plugins API
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/core/Makefile.am | 2 | ||||
-rw-r--r-- | src/core/wee-alias.c | 380 | ||||
-rw-r--r-- | src/core/wee-command.c | 163 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 168 | ||||
-rw-r--r-- | src/core/wee-config-file.h | 7 | ||||
-rw-r--r-- | src/core/wee-config.c | 94 | ||||
-rw-r--r-- | src/core/wee-hook.c | 25 | ||||
-rw-r--r-- | src/core/wee-input.c | 129 | ||||
-rw-r--r-- | src/core/wee-string.c | 18 | ||||
-rw-r--r-- | src/core/wee-string.h | 4 | ||||
-rw-r--r-- | src/core/weechat.c | 2 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 71 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 4 | ||||
-rw-r--r-- | src/plugins/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 7 | ||||
-rw-r--r-- | src/plugins/alias/CMakeLists.txt | 22 | ||||
-rw-r--r-- | src/plugins/alias/Makefile.am | 25 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 730 | ||||
-rw-r--r-- | src/plugins/alias/alias.h (renamed from src/core/wee-alias.h) | 32 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 4 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 92 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 41 | ||||
-rw-r--r-- | src/plugins/plugin.c | 29 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 27 |
25 files changed, 1195 insertions, 895 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f850d1948..8886cd7f2 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -14,11 +14,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -SET(LIB_CORE_SRC weechat.c weechat.h wee-alias.c wee-alias.h wee-backtrace.c -wee-backtrace.h wee-command.c wee-command.h wee-config.c wee-config.h -wee-config-file.c wee-config-file.h wee-hook.c wee-hook.h wee-input.c -wee-input.h wee-list.c wee-list.h wee-log.c wee-log.h wee-string.c wee-string.h -wee-upgrade.c wee-upgrade.h wee-utf8.c wee-utf8.h wee-util.c wee-util.h) +SET(LIB_CORE_SRC weechat.c weechat.h wee-backtrace.c wee-backtrace.h +wee-command.c wee-command.h wee-config.c wee-config.h wee-config-file.c +wee-config-file.h wee-hook.c wee-hook.h wee-input.c wee-input.h wee-list.c +wee-list.h wee-log.c wee-log.h wee-string.c wee-string.h wee-upgrade.c +wee-upgrade.h wee-utf8.c wee-utf8.h wee-util.c wee-util.h) # Check for flock support INCLUDE(CheckSymbolExists) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 487c5693f..67ca3fa18 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -20,8 +20,6 @@ noinst_LIBRARIES = lib_weechat_core.a lib_weechat_core_a_SOURCES = weechat.c \ weechat.h \ - wee-alias.c \ - wee-alias.h \ wee-backtrace.c \ wee-backtrace.h \ wee-command.c \ diff --git a/src/core/wee-alias.c b/src/core/wee-alias.c deleted file mode 100644 index 992e30d5c..000000000 --- a/src/core/wee-alias.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org> - * See README for License detail, AUTHORS for developers list. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* wee-alias.c: WeeChat alias */ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <string.h> - -#include "weechat.h" -#include "wee-alias.h" -#include "wee-config.h" -#include "wee-string.h" -#include "../gui/gui-chat.h" - - -struct alias *weechat_alias = NULL; -struct alias *weechat_last_alias = NULL; - - -/* - * alias_search: search an alias - */ - -struct alias * -alias_search (char *alias_name) -{ - struct alias *ptr_alias; - - for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) - { - if (string_strcasecmp (alias_name, ptr_alias->name) == 0) - return ptr_alias; - } - return NULL; -} - -/* - * alias_find_pos: find position for an alias (for sorting aliases) - */ - -struct alias * -alias_find_pos (char *alias_name) -{ - struct alias *ptr_alias; - - for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) - { - if (string_strcasecmp (alias_name, ptr_alias->name) < 0) - return ptr_alias; - } - return NULL; -} - -/* - * alias_insert_sorted: insert alias into sorted list - */ - -void -alias_insert_sorted (struct alias *alias) -{ - struct alias *pos_alias; - - pos_alias = alias_find_pos (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_new: create new alias and add it to alias list - */ - -struct alias * -alias_new (char *name, char *command) -{ - struct alias *new_alias, *ptr_alias; - - while (name[0] == '/') - { - name++; - } - - if (string_strcasecmp (name, "builtin") == 0) - return NULL; - - ptr_alias = alias_search (name); - if (ptr_alias) - { - if (ptr_alias->command) - free (ptr_alias->command); - ptr_alias->command = strdup (command); - return ptr_alias; - } - - if ((new_alias = ((struct alias *) malloc (sizeof (struct alias))))) - { - new_alias->name = strdup (name); - new_alias->command = (char *) malloc (strlen (command) + 1); - new_alias->running = 0; - if (new_alias->command) - strcpy (new_alias->command, command); - alias_insert_sorted (new_alias); - return new_alias; - } - else - return NULL; -} - -/* - * alias_get_final_command: get final command pointed by an alias - */ - -char * -alias_get_final_command (struct alias *alias) -{ - struct alias *ptr_alias; - char *result; - - if (alias->running) - { - gui_chat_printf (NULL, - _("%sError: circular reference when calling alias " - "\"/%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - alias->name); - return NULL; - } - - ptr_alias = alias_search ((alias->command[0] == '/') ? - alias->command + 1 : alias->command); - if (ptr_alias) - { - alias->running = 1; - result = alias_get_final_command (ptr_alias); - alias->running = 0; - return result; - } - return (alias->command[0] == '/') ? - alias->command + 1 : alias->command; -} - -/* - * alias_add_word: add word to string and increment length - * This function should NOT be called directly. - */ - -void -alias_add_word (char **alias, int *length, char *word) -{ - int length_word; - - if (!word) - return; - - length_word = strlen (word); - if (length_word == 0) - return; - - if (*alias == NULL) - { - *alias = (char *) malloc (length_word + 1); - strcpy (*alias, word); - } - else - { - *alias = realloc (*alias, strlen (*alias) + length_word + 1); - strcat (*alias, word); - } - *length += length_word; -} - -/* - * alias_replace_args: replace arguments ($1, $2, .. or $*) in alias arguments - */ - -char * -alias_replace_args (char *alias_args, char *user_args) -{ - char **argv, *start, *pos, *res; - int argc, length_res, args_count; - - argv = string_explode (user_args, " ", 0, 0, &argc); - - res = NULL; - length_res = 0; - args_count = 0; - start = alias_args; - pos = start; - while (pos && pos[0]) - { - if ((pos[0] == '\\') && (pos[1] == '$')) - { - pos[0] = '\0'; - alias_add_word (&res, &length_res, start); - alias_add_word (&res, &length_res, "$"); - pos[0] = '\\'; - start = pos + 2; - pos = start; - } - else - { - if (pos[0] == '$') - { - if (pos[1] == '*') - { - args_count++; - pos[0] = '\0'; - alias_add_word (&res, &length_res, start); - alias_add_word (&res, &length_res, user_args); - pos[0] = '$'; - start = pos + 2; - pos = start; - } - else - { - if ((pos[1] >= '1') && (pos[1] <= '9')) - { - args_count++; - pos[0] = '\0'; - alias_add_word (&res, &length_res, start); - if (pos[1] - '0' <= argc) - alias_add_word (&res, &length_res, argv[pos[1] - '1']); - pos[0] = '$'; - start = pos + 2; - pos = start; - } - else - pos++; - } - } - else - pos++; - } - } - - if (start < pos) - alias_add_word (&res, &length_res, start); - - if ((args_count == 0) && user_args && user_args[0]) - { - alias_add_word (&res, &length_res, " "); - alias_add_word (&res, &length_res, user_args); - } - - if (argv) - string_free_exploded (argv); - - return res; -} - -/* - * alias_replace_vars: replace special vars ($nick, $channel, $server) in a string - * Note: result has to be free() after use - */ - -char * -alias_replace_vars (struct t_gui_buffer *buffer, char *string) -{ - /* TODO: call protocol specific function to do this */ - (void) buffer; - -/* char *var_nick, *var_channel, *var_server; - char empty_string[1] = { '\0' }; - char *res, *temp; - - var_nick = (server && server->nick) ? server->nick : empty_string; - var_channel = (channel) ? channel->name : empty_string; - var_server = (server) ? server->name : empty_string; - - temp = weechat_strreplace (string, "$nick", var_nick); - if (!temp) - return NULL; - res = temp; - - temp = weechat_strreplace (res, "$channel", var_channel); - free (res); - if (!temp) - return NULL; - res = temp; - - temp = weechat_strreplace (res, "$server", var_server); - free (res); - if (!temp) - return NULL; - res = temp; - - return res;*/ - - return strdup (string); -} - -/* - * alias_free: free an alias and reomve it from list - */ - -void -alias_free (struct alias *alias) -{ - struct 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->name) - free (alias->name); - if (alias->command) - free (alias->command); - free (alias); - weechat_alias = new_weechat_alias; -} - -/* - * alias_free_all: free all alias - */ - -void -alias_free_all () -{ - while (weechat_alias) - alias_free (weechat_alias); -} diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 05967700f..86542b60c 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -30,7 +30,6 @@ #include "weechat.h" #include "wee-command.h" -#include "wee-alias.h" #include "wee-config.h" #include "wee-hook.h" #include "wee-input.h" @@ -53,19 +52,7 @@ /* WeeChat internal commands */ struct command weechat_commands[] = -{ { "alias", - N_("create an alias for a command"), - N_("[alias_name [command [arguments]]]"), - N_("alias_name: name of alias\n" - " command: command name (WeeChat or IRC command, many commands " - "can be separated by semicolons)\n" - " arguments: arguments for command\n\n" - "Note: in command, special variables $1, $2,..,$9 are replaced by " - "arguments given by user, and $* is replaced by all arguments.\n" - "Variables $nick, $channel and $server are replaced by current " - "nick/channel/server."), - "%- %A", 0, MAX_ARGS, 1, command_alias }, - { "buffer", +{ { "buffer", N_("manage buffers"), N_("[action [args] | number | [[server] [channel]]]"), N_(" action: action to do:\n" @@ -178,10 +165,6 @@ struct command weechat_commands[] = " value: value for option\n\n" "Option is format: plugin.option, example: perl.myscript.item1"), "%O = %V", 0, MAX_ARGS, 0, command_setp }, - { "unalias", - N_("remove an alias"), - N_("alias_name"), N_("alias_name: name of alias to remove"), - "%a", 1, 1, 0, command_unalias }, { "upgrade", N_("upgrade WeeChat without disconnecting from servers"), N_("[path_to_binary]"), @@ -226,23 +209,14 @@ struct t_weelist *weechat_last_index_command; /* * command_is_used: return 1 if command is used by weechat - * (WeeChat/alias command) + * (WeeChat command) */ int command_is_used (char *command) { - struct alias *ptr_alias; int i; - /* look for alias */ - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - if (string_strcasecmp (ptr_alias->name, command) == 0) - return 1; - } - /* look for WeeChat command */ for (i = 0; weechat_commands[i].name; i++) { @@ -250,7 +224,7 @@ command_is_used (char *command) return 1; } - /* no command/alias found */ + /* no command found */ return 0; } @@ -361,95 +335,6 @@ command_print_stdout (struct command *commands) } /* - * command_alias: display or create alias - */ - -int -command_alias (struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *alias_name; - struct alias *ptr_alias; - - /* make C compiler happy */ - (void) buffer; - - if (argc > 0) - { - alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0]; - if (argc > 1) - { - /* Define new alias */ - if (!alias_new (alias_name, argv_eol[1])) - return -1; - - if (weelist_add (&weechat_index_commands, - &weechat_last_index_command, - alias_name, - WEELIST_POS_SORT)) - { - gui_chat_printf (NULL, - _("%sAlias \"%s\" => \"%s\" created"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - alias_name, argv_eol[1]); - } - else - { - gui_chat_printf (NULL, - _("%sError: not enough memory for creating " - "alias \"%s\" => \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - alias_name, argv_eol[1]); - return -1; - } - } - else - { - /* Display one alias */ - ptr_alias = alias_search (alias_name); - if (ptr_alias) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("Alias:")); - gui_chat_printf (NULL, " %s %s=>%s %s", - ptr_alias->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT), - ptr_alias->command); - } - else - gui_chat_printf (NULL, - _("%sNo alias found."), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); - } - } - else - { - /* List all aliases */ - if (weechat_alias) - { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("List of aliases:")); - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - gui_chat_printf (NULL, - " %s %s=>%s %s", - ptr_alias->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT), - ptr_alias->command); - } - } - else - gui_chat_printf (NULL, - _("%sNo alias defined."), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); - } - return 0; -} - -/* * command_buffer: manage buffers */ @@ -1924,48 +1809,6 @@ command_setp (struct t_gui_buffer *buffer, } /* - * command_unalias: remove an alias - */ - -int -command_unalias (struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *alias_name; - struct t_weelist *ptr_weelist; - struct alias *ptr_alias; - - /* make C compiler happy */ - (void) buffer; - (void) argv_eol; - - if (argc > 0) - { - alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0]; - ptr_alias = alias_search (alias_name); - if (!ptr_alias) - { - gui_chat_printf (NULL, - _("%sAlias \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - alias_name); - return -1; - } - alias_free (ptr_alias); - ptr_weelist = weelist_search (weechat_index_commands, alias_name); - if (ptr_weelist) - weelist_remove (&weechat_index_commands, - &weechat_last_index_command, - ptr_weelist); - gui_chat_printf (NULL, - _("%sAlias \"%s\" removed"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - alias_name); - } - return 0; -} - -/* * command_upgrade: upgrade WeeChat */ diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 4e4360b73..5cba2ef3e 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -41,6 +41,26 @@ struct t_config_file *last_config_file = NULL; /* + * config_file_search: search a configuration file + */ + +struct t_config_file * +config_file_search (char *filename) +{ + struct t_config_file *ptr_config; + + for (ptr_config = config_files; ptr_config; + ptr_config = ptr_config->next_config) + { + if (strcmp (ptr_config->filename, filename) == 0) + return ptr_config; + } + + /* configuration file not found */ + return NULL; +} + +/* * config_file_new: create new config options structure */ @@ -52,6 +72,10 @@ config_file_new (void *plugin, char *filename) if (!filename) return NULL; + /* it's NOT authorized to create two config files with same filename */ + if (config_file_search (filename)) + return NULL; + new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file)); if (new_config_file) { @@ -74,6 +98,29 @@ config_file_new (void *plugin, char *filename) } /* + * config_file_valid_for_plugin: check if a configuration file pointer exists for a plugin + * return 1 if configuration file exists for plugin + * 0 if configuration file is not found for plugin + */ + +int +config_file_valid_for_plugin (void *plugin, struct t_config_file *config_file) +{ + struct t_config_file *ptr_config; + + for (ptr_config = config_files; ptr_config; + ptr_config = ptr_config->next_config) + { + if ((ptr_config == config_file) + && (ptr_config->plugin == (struct t_weechat_plugin *)plugin)) + return 1; + } + + /* configuration file not found */ + return 0; +} + +/* * config_file_new_section: create a new section in a config */ @@ -1015,6 +1062,127 @@ config_file_write (struct t_config_file *config_file, int default_options) } /* + * config_file_option_free: free an option + */ + +void +config_file_option_free (struct t_config_section *section, + struct t_config_option *option) +{ + struct t_config_option *new_options; + + /* remove option */ + if (section->last_option == option) + section->last_option = option->prev_option; + if (option->prev_option) + { + (option->prev_option)->next_option = option->next_option; + new_options = section->options; + } + else + new_options = option->next_option; + + if (option->next_option) + (option->next_option)->prev_option = option->prev_option; + + /* free data */ + if (option->name) + free (option->name); + if (option->description) + free (option->description); + if (option->string_values) + string_free_exploded (option->string_values); + if (option->default_value) + free (option->default_value); + if (option->value) + free (option->value); + + section->options = new_options; +} + +/* + * config_file_section_free: free a section + */ + +void +config_file_section_free (struct t_config_file *config_file, + struct t_config_section *section) +{ + struct t_config_section *new_sections; + + /* remove section */ + if (config_file->last_section == section) + config_file->last_section = section->prev_section; + if (section->prev_section) + { + (section->prev_section)->next_section = section->next_section; + new_sections = config_file->sections; + } + else + new_sections = section->next_section; + + if (section->next_section) + (section->next_section)->prev_section = section->prev_section; + + /* free data */ + while (section->options) + { + config_file_option_free (section, section->options); + } + if (section->name) + free (section->name); + + config_file->sections = new_sections; +} + +/* + * config_file_free: free a configuration file + */ + +void +config_file_free (struct t_config_file *config_file) +{ + struct t_config_file *new_config_files; + + /* remove config file */ + if (last_config_file == config_file) + last_config_file = config_file->prev_config; + if (config_file->prev_config) + { + (config_file->prev_config)->next_config = config_file->next_config; + new_config_files = config_files; + } + else + new_config_files = config_file->next_config; + + if (config_file->next_config) + (config_file->next_config)->prev_config = config_file->prev_config; + + /* free data */ + while (config_file->sections) + { + config_file_section_free (config_file, config_file->sections); + } + if (config_file->filename) + free (config_file->filename); + + config_files = new_config_files; +} + +/* + * config_file_free_all: free all configuration files + */ + +void +config_file_free_all () +{ + while (config_files) + { + config_file_free (config_files); + } +} + +/* * config_file_print_stdout: print options on standard output */ diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index b0e852452..2fac140b3 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -85,6 +85,7 @@ struct t_config_option }; extern struct t_config_file *config_file_new (void *, char *); +extern int config_file_valid_for_plugin (void *, struct t_config_file *); extern struct t_config_section *config_file_new_section (struct t_config_file *, char *, void (*)(void *, char *, char *), @@ -126,6 +127,12 @@ extern int config_file_read (struct t_config_file *); extern int config_file_reload (struct t_config_file *); extern void config_file_write_line (struct t_config_file *, char *, char *); extern int config_file_write (struct t_config_file *, int); +extern void config_file_option_free (struct t_config_section *, + struct t_config_option *); +extern void config_file_section_free (struct t_config_file *, + struct t_config_section *); +extern void config_file_free (struct t_config_file *); +extern void config_file_free_all (); extern void config_file_print_stdout (struct t_config_file *); extern void config_file_print_log (); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index ba599f13b..0723de65c 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -36,7 +36,6 @@ #include "weechat.h" #include "wee-config.h" #include "wee-config-file.h" -#include "wee-alias.h" #include "wee-command.h" #include "wee-log.h" #include "wee-util.h" @@ -320,25 +319,6 @@ config_change_nicks_colors () } /* - * config_weechat_read_alias: read an alias in configuration file - */ - -void -config_weechat_read_alias (void *config_file, - char *option_name, char *value) -{ - /* make C compiler happy */ - (void) config_file; - - /* create new alias */ - if (alias_new (option_name, value)) - weelist_add (&weechat_index_commands, - &weechat_last_index_command, - option_name, - WEELIST_POS_SORT); -} - -/* * config_weechat_read_key: read a key in configuration file */ @@ -362,69 +342,6 @@ config_weechat_read_key (void *config_file, } /* - * config_weechat_write_alias: write alias section in configuration file - * Return: 0 = successful - * -1 = write error - */ - -void -config_weechat_write_alias (void *config_file) -{ - struct alias *ptr_alias; - char *string; - - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - string = (char *)malloc (strlen (ptr_alias->command) + 4); - if (string) - { - strcpy (string, "\""); - strcat (string, ptr_alias->command); - strcat (string, "\""); - config_file_write_line (config_file, - ptr_alias->name, - string); - free (string); - } - } -} - -/* - * config_weechat_write_alias_default_values: write alias section with default values - * in configuration file - */ - -void -config_weechat_write_alias_default_values (void *config_file) -{ - config_file_write_line (config_file, "SAY", "\"msg *\""); - config_file_write_line (config_file, "BYE", "\"quit\""); - config_file_write_line (config_file, "EXIT", "\"quit\""); - config_file_write_line (config_file, "SIGNOFF", "\"quit\""); - config_file_write_line (config_file, "C", "\"clear\""); - config_file_write_line (config_file, "CL", "\"clear\""); - config_file_write_line (config_file, "CLOSE", "\"buffer close\""); - config_file_write_line (config_file, "CHAT", "\"dcc chat\""); - config_file_write_line (config_file, "IG", "\"ignore\""); - config_file_write_line (config_file, "J", "\"join\""); - config_file_write_line (config_file, "K", "\"kick\""); - config_file_write_line (config_file, "KB", "\"kickban\""); - config_file_write_line (config_file, "LEAVE", "\"part\""); - config_file_write_line (config_file, "M", "\"msg\""); - config_file_write_line (config_file, "MUB", "\"unban *\""); - config_file_write_line (config_file, "N", "\"names\""); - config_file_write_line (config_file, "Q", "\"query\""); - config_file_write_line (config_file, "T", "\"topic\""); - config_file_write_line (config_file, "UB", "\"unban\""); - config_file_write_line (config_file, "UNIG", "\"unignore\""); - config_file_write_line (config_file, "W", "\"who\""); - config_file_write_line (config_file, "WC", "\"window merge\""); - config_file_write_line (config_file, "WI", "\"whois\""); - config_file_write_line (config_file, "WW", "\"whowas\""); -} - -/* * config_weechat_write_keys: write alias section in configuration file * Return: 0 = successful * -1 = write error @@ -1099,13 +1016,7 @@ config_weechat_init () #endif NULL); } - - /* alias */ - section = config_file_new_section (weechat_config, "alias", - &config_weechat_read_alias, - &config_weechat_write_alias, - &config_weechat_write_alias_default_values); - + /* keys */ section = config_file_new_section (weechat_config, "keys", &config_weechat_read_key, @@ -1137,9 +1048,6 @@ config_weechat_read () int config_weechat_reload () { - /* remove all alias */ - alias_free_all (); - /* remove all keys */ gui_keyboard_free_all (); diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 9d44f4f06..66982ada0 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -120,6 +120,27 @@ hook_valid_for_plugin (void *plugin, struct t_hook *hook) } /* + * hook_search_command: search command hook in list + */ + +struct t_hook * +hook_search_command (char *command) +{ + struct t_hook *ptr_hook; + + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if ((ptr_hook->type == HOOK_TYPE_COMMAND) + && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), command) == 0)) + return ptr_hook; + } + + /* command hook not found */ + return NULL; +} + +/* * hook_command: hook a command */ @@ -131,6 +152,10 @@ hook_command (void *plugin, char *command, char *description, { struct t_hook *new_hook; struct t_hook_command *new_hook_command; + + if ((string_strcasecmp (command, "builtin") == 0) + && hook_search_command (command)) + return NULL; new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); if (!new_hook) diff --git a/src/core/wee-input.c b/src/core/wee-input.c index 74beb81a1..4fe0f8a00 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -28,7 +28,6 @@ #include "weechat.h" #include "wee-input.h" -#include "wee-alias.h" #include "wee-command.h" #include "wee-config.h" #include "wee-hook.h" @@ -50,13 +49,9 @@ int input_exec_command (struct t_gui_buffer *buffer, char *string, int only_builtin) { - int i, rc, argc, return_code, length1, length2; + int i, rc, argc, return_code; char *command, *pos, *ptr_args; - char **argv, **argv_eol, *alias_command; - char **commands, **ptr_cmd, **ptr_next_cmd; - char *args_replaced, *vars_replaced, *new_ptr_cmd; - int some_args_replaced; - struct alias *ptr_alias; + char **argv, **argv_eol; if ((!string) || (!string[0]) || (string[0] != '/')) return 0; @@ -111,126 +106,6 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, argv = string_explode (ptr_args, " ", 0, 0, &argc); argv_eol = string_explode (ptr_args, " ", 1, 0, NULL); - /* look for alias */ - if (!only_builtin) - { - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - if (string_strcasecmp (ptr_alias->name, command + 1) == 0) - { - if (ptr_alias->running == 1) - { - gui_chat_printf (NULL, - _("%sError: circular reference when " - "calling alias \"/%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - ptr_alias->name); - } - else - { - /* an alias can contain many commands separated by ';' */ - commands = string_split_multi_command (ptr_alias->command, - ';'); - if (commands) - { - some_args_replaced = 0; - ptr_alias->running = 1; - for (ptr_cmd=commands; *ptr_cmd; ptr_cmd++) - { - ptr_next_cmd = ptr_cmd; - ptr_next_cmd++; - - vars_replaced = alias_replace_vars (buffer, - *ptr_cmd); - new_ptr_cmd = (vars_replaced) ? vars_replaced : *ptr_cmd; - args_replaced = alias_replace_args (new_ptr_cmd, - ptr_args); - if (args_replaced) - { - some_args_replaced = 1; - if (*ptr_cmd[0] == '/') - (void) input_exec_command (buffer, - args_replaced, - only_builtin); - else - { - alias_command = (char *) malloc (1 + strlen(args_replaced) + 1); - if (alias_command) - { - strcpy (alias_command, "/"); - strcat (alias_command, args_replaced); - (void) input_exec_command (buffer, - alias_command, - only_builtin); - free (alias_command); - } - } - free (args_replaced); - } - else - { - /* if alias has arguments, they are now - arguments of the last command in the list (if no $1,$2,..$*) was found */ - if ((*ptr_next_cmd == NULL) && ptr_args && (!some_args_replaced)) - { - length1 = strlen (new_ptr_cmd); - length2 = strlen (ptr_args); - - alias_command = (char *) malloc ( 1 + length1 + 1 + length2 + 1); - if (alias_command) - { - if (*ptr_cmd[0] != '/') - strcpy (alias_command, "/"); - else - strcpy (alias_command, ""); - - strcat (alias_command, new_ptr_cmd); - strcat (alias_command, " "); - strcat (alias_command, ptr_args); - - (void) input_exec_command (buffer, - alias_command, - only_builtin); - free (alias_command); - } - } - else - { - if (*ptr_cmd[0] == '/') - (void) input_exec_command (buffer, - new_ptr_cmd, - only_builtin); - else - { - alias_command = (char *) malloc (1 + strlen (new_ptr_cmd) + 1); - if (alias_command) - { - strcpy (alias_command, "/"); - strcat (alias_command, new_ptr_cmd); - (void) input_exec_command (buffer, - alias_command, - only_builtin); - free (alias_command); - } - } - } - } - if (vars_replaced) - free (vars_replaced); - } - ptr_alias->running = 0; - string_free_multi_command (commands); - } - } - string_free_exploded (argv); - string_free_exploded (argv_eol); - free (command); - return 1; - } - } - } - /* look for WeeChat command */ for (i = 0; weechat_commands[i].name; i++) { diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 80844ceff..2b3aa7380 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -460,15 +460,15 @@ string_free_exploded (char **exploded_string) } /* - * string_split_multi_command: split a list of commands separated by 'sep' - * and ecscaped with '\' - * - empty commands are removed - * - spaces on the left of each commands are stripped - * Result must be freed with free_multi_command + * string_split_command: split a list of commands separated by 'sep' + * and ecscaped with '\' + * - empty commands are removed + * - spaces on the left of each commands are stripped + * Result must be freed with free_multi_command */ char ** -string_split_multi_command (char *command, char sep) +string_split_command (char *command, char sep) { int nb_substr, arr_idx, str_idx, type; char **array; @@ -545,12 +545,12 @@ string_split_multi_command (char *command, char sep) } /* - * string_free_multi_command : free a list of commands splitted - * with split_multi_command + * string_free_splitted_command : free a list of commands splitted + * with string_split_command */ void -string_free_multi_command (char **commands) +string_free_splitted_command (char **commands) { int i; diff --git a/src/core/wee-string.h b/src/core/wee-string.h index d308d2e5a..67922b5d0 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -33,8 +33,8 @@ extern char *string_remove_quotes (char *, char *); extern char *string_convert_hex_chars (char *); extern char **string_explode (char *, char *, int, int, int *); extern void string_free_exploded (char **); -extern char **string_split_multi_command (char *, char); -extern void string_free_multi_command (char **); +extern char **string_split_command (char *, char); +extern void string_free_splitted_command (char **); extern char *string_iconv (int, char *, char *, char *); extern char *string_iconv_to_internal (char *, char *); extern char *string_iconv_from_internal (char *, char *); diff --git a/src/core/weechat.c b/src/core/weechat.c index 323b740ce..3cb266c11 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -51,7 +51,6 @@ #endif #include "weechat.h" -#include "wee-alias.h" #include "wee-backtrace.h" #include "wee-command.h" #include "wee-config.h" @@ -487,7 +486,6 @@ weechat_shutdown (int return_code, int crash) log_close (); if (local_charset) free (local_charset); - alias_free_all (); if (crash) abort(); diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index f7869e34e..06e99fc5f 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -31,7 +31,6 @@ #include <unistd.h> #include "../core/weechat.h" -#include "../core/wee-alias.h" #include "../core/wee-command.h" #include "../core/wee-config.h" #include "../core/wee-hook.h" @@ -136,43 +135,22 @@ void gui_completion_get_command_infos (struct t_gui_completion *completion, char **template, int *max_arg) { - struct alias *ptr_alias; struct t_hook *ptr_hook; - char *ptr_command, *ptr_command2, *pos; int i; *template = NULL; *max_arg = MAX_ARGS; - ptr_alias = alias_search (completion->base_command); - if (ptr_alias) - { - ptr_command = alias_get_final_command (ptr_alias); - if (!ptr_command) - return; - } - else - ptr_command = completion->base_command; - - ptr_command2 = strdup (ptr_command); - if (!ptr_command2) - return; - - pos = strchr (ptr_command2, ' '); - if (pos) - pos[0] = '\0'; - /* look for command hooked */ for (ptr_hook = weechat_hooks; ptr_hook; ptr_hook = ptr_hook->next_hook) { if ((ptr_hook->type == HOOK_TYPE_COMMAND) && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), - ptr_command2) == 0)) + completion->base_command) == 0)) { *template = HOOK_COMMAND(ptr_hook, completion); *max_arg = MAX_ARGS; - free (ptr_command2); return; } } @@ -181,17 +159,13 @@ gui_completion_get_command_infos (struct t_gui_completion *completion, for (i = 0; weechat_commands[i].name; i++) { if (string_strcasecmp (weechat_commands[i].name, - ptr_command2) == 0) + completion->base_command) == 0) { *template = weechat_commands[i].completion_template; *max_arg = weechat_commands[i].max_arg; - free (ptr_command2); return; } } - - free (ptr_command2); - return; } /* @@ -290,39 +264,6 @@ gui_completion_list_add (struct t_gui_completion *completion, char *word, } /* - * gui_completion_list_add_alias: add alias to completion list - */ - -void -gui_completion_list_add_alias (struct t_gui_completion *completion) -{ - struct alias *ptr_alias; - - for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) - { - gui_completion_list_add (completion, ptr_alias->name, - 0, WEELIST_POS_SORT); - } -} - -/* - * gui_completion_list_add_alias_cmd: add alias and comands to completion list - */ - -void -gui_completion_list_add_alias_cmd (struct t_gui_completion *completion) -{ - struct t_weelist *ptr_list; - - for (ptr_list = weechat_index_commands; ptr_list; - ptr_list = ptr_list->next_weelist) - { - gui_completion_list_add (completion, ptr_list->data, 0, - WEELIST_POS_SORT); - } -} - -/* * gui_completion_list_add_channel: add current channel to completion list */ @@ -969,12 +910,6 @@ gui_completion_build_list_template (struct t_gui_completion *completion, char *t break; case '*': /* repeat last completion (do nothing there) */ break; - case 'a': /* alias */ - gui_completion_list_add_alias (completion); - break; - case 'A': /* alias or any command */ - gui_completion_list_add_alias_cmd (completion); - break; case 'c': /* current channel */ gui_completion_list_add_channel (completion); break; @@ -984,7 +919,7 @@ gui_completion_build_list_template (struct t_gui_completion *completion, char *t case 'f': /* filename */ gui_completion_list_add_filename (completion); break; - case 'h': /* commands hooks */ + case 'h': /* command hooks */ gui_completion_list_add_command_hooks (completion); break; case 'k': /* key cmd/funtcions*/ diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index ea927f841..7dc082f5b 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -628,7 +628,7 @@ gui_keyboard_pressed (char *key_str) gui_key_combo_buffer[0] = '\0'; if (ptr_key->command) { - commands = string_split_multi_command (ptr_key->command, ';'); + commands = string_split_command (ptr_key->command, ';'); if (commands) { for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++) @@ -636,7 +636,7 @@ gui_keyboard_pressed (char *key_str) input_data (gui_current_window->buffer, *ptr_cmd, 0); } - string_free_multi_command (commands); + string_free_splitted_command (commands); } } else diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 7fb61b9e2..71364ec9f 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -28,6 +28,10 @@ IF(NOT DISABLE_IRC) ADD_SUBDIRECTORY( irc ) ENDIF(NOT DISABLE_IRC) +IF(NOT DISABLE_ALIAS) + ADD_SUBDIRECTORY( alias ) +ENDIF(NOT DISABLE_ALIAS) + IF(NOT DISABLE_ASPELL) # Check for aspell libraries FIND_PACKAGE(Aspell) diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 0a6162543..b5854a35b 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -32,6 +32,10 @@ if PLUGIN_IRC irc_dir = irc endif +if PLUGIN_ALIAS +alias_dir = alias +endif + if PLUGIN_ASPELL aspell_dir = aspell endif @@ -72,4 +76,5 @@ if PLUGIN_DEMO demo_dir = demo endif -SUBDIRS = . $(irc_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) $(logger_dir) $(trigger_dir) $(demo_dir) $(script_dir) +SUBDIRS = . $(irc_dir) $(alias_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) \ + $(logger_dir) $(trigger_dir) $(demo_dir) $(script_dir) diff --git a/src/plugins/alias/CMakeLists.txt b/src/plugins/alias/CMakeLists.txt new file mode 100644 index 000000000..6a101474e --- /dev/null +++ b/src/plugins/alias/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +ADD_LIBRARY(alias MODULE alias.c alias.h) +SET_TARGET_PROPERTIES(alias PROPERTIES PREFIX "") + +TARGET_LINK_LIBRARIES(alias) + +INSTALL(TARGETS alias LIBRARY DESTINATION lib/${PROJECT_NAME}/plugins) diff --git a/src/plugins/alias/Makefile.am b/src/plugins/alias/Makefile.am new file mode 100644 index 000000000..28a73b9a2 --- /dev/null +++ b/src/plugins/alias/Makefile.am @@ -0,0 +1,25 @@ +# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(ALIAS_CFLAGS) + +libdir = ${weechat_libdir}/plugins + +lib_LTLIBRARIES = alias.la + +alias_la_SOURCES = alias.c alias.h +alias_la_LDFLAGS = -module +alias_la_LIBADD = $(ALIAS_LFLAGS) diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c new file mode 100644 index 000000000..f3b7fc8db --- /dev/null +++ b/src/plugins/alias/alias.c @@ -0,0 +1,730 @@ +/* + * Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* alias.c: Alias plugin for WeeChat */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdlib.h> +#include <string.h> + +#include "../weechat-plugin.h" +#include "alias.h" + + +static struct t_weechat_plugin *weechat_plugin = NULL; + +static struct t_config_file *alias_config_file = NULL; +static struct t_alias *alias_list = NULL; +static struct t_alias *last_alias = NULL; +static struct t_hook *alias_command = NULL; +static struct t_hook *unalias_command = NULL; + + +/* + * alias_search: search an alias + */ + +static struct t_alias * +alias_search (char *alias_name) +{ + struct t_alias *ptr_alias; + + for (ptr_alias = alias_list; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + if (weechat_strcasecmp (alias_name, ptr_alias->name) == 0) + return ptr_alias; + } + return NULL; +} + +/* + * alias_add_word: add word to string and increment length + * This function should NOT be called directly. + */ + +static void +alias_add_word (char **alias, int *length, char *word) +{ + int length_word; + + if (!word) + return; + + length_word = strlen (word); + if (length_word == 0) + return; + + if (*alias == NULL) + { + *alias = (char *) malloc (length_word + 1); + strcpy (*alias, word); + } + else + { + *alias = realloc (*alias, strlen (*alias) + length_word + 1); + strcat (*alias, word); + } + *length += length_word; +} + +/* + * alias_replace_args: replace arguments ($1, $2, .. or $*) in alias arguments + */ + +static char * +alias_replace_args (char *alias_args, char *user_args) +{ + char **argv, *start, *pos, *res; + int argc, length_res, args_count; + + argv = weechat_string_explode (user_args, " ", 0, 0, &argc); + + res = NULL; + length_res = 0; + args_count = 0; + start = alias_args; + pos = start; + while (pos && pos[0]) + { + if ((pos[0] == '\\') && (pos[1] == '$')) + { + pos[0] = '\0'; + alias_add_word (&res, &length_res, start); + alias_add_word (&res, &length_res, "$"); + pos[0] = '\\'; + start = pos + 2; + pos = start; + } + else + { + if (pos[0] == '$') + { + if (pos[1] == '*') + { + args_count++; + pos[0] = '\0'; + alias_add_word (&res, &length_res, start); + alias_add_word (&res, &length_res, user_args); + pos[0] = '$'; + start = pos + 2; + pos = start; + } + else + { + if ((pos[1] >= '1') && (pos[1] <= '9')) + { + args_count++; + pos[0] = '\0'; + alias_add_word (&res, &length_res, start); + if (pos[1] - '0' <= argc) + alias_add_word (&res, &length_res, argv[pos[1] - '1']); + pos[0] = '$'; + start = pos + 2; + pos = start; + } + else + pos++; + } + } + else + pos++; + } + } + + if (start < pos) + alias_add_word (&res, &length_res, start); + + if ((args_count == 0) && user_args && user_args[0]) + { + alias_add_word (&res, &length_res, " "); + alias_add_word (&res, &length_res, user_args); + } + + if (argv) + weechat_string_free_exploded (argv); + + return res; +} + +/* + * alias_cb: callback for alias (called when user uses an alias) + */ + +static int +alias_cb (void *data, void *buffer, int argc, char **argv, + char **argv_eol) +{ + struct t_alias *ptr_alias; + char **commands, **ptr_cmd, **ptr_next_cmd; + char *args_replaced, *alias_command; + int some_args_replaced, length1, length2; + + /* make C compiler happy */ + (void) argc; + (void) argv; + + ptr_alias = (struct t_alias *)data; + + if (ptr_alias->running) + { + weechat_printf (NULL, + _("%sError: circular reference when " + "calling alias \"/%s\""), + weechat_prefix ("error"), + ptr_alias->name); + return PLUGIN_RC_FAILED; + } + else + { + /* an alias can contain many commands separated by ';' */ + commands = weechat_string_split_command (ptr_alias->command, ';'); + if (commands) + { + some_args_replaced = 0; + ptr_alias->running = 1; + for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++) + { + ptr_next_cmd = ptr_cmd; + ptr_next_cmd++; + + args_replaced = (argc > 1) ? + alias_replace_args (*ptr_cmd, argv_eol[1]) : NULL; + if (args_replaced) + { + some_args_replaced = 1; + if (*ptr_cmd[0] == '/') + weechat_command (buffer, args_replaced); + else + { + alias_command = (char *) malloc (1 + strlen(args_replaced) + 1); + if (alias_command) + { + strcpy (alias_command, "/"); + strcat (alias_command, args_replaced); + weechat_command (buffer, alias_command); + free (alias_command); + } + } + free (args_replaced); + } + else + { + /* if alias has arguments, they are now + arguments of the last command in the list (if no $1,$2,..$*) was found */ + if ((*ptr_next_cmd == NULL) && argv_eol[1] && (!some_args_replaced)) + { + length1 = strlen (*ptr_cmd); + length2 = strlen (argv_eol[1]); + + alias_command = (char *) malloc ( 1 + length1 + 1 + length2 + 1); + if (alias_command) + { + if (*ptr_cmd[0] != '/') + strcpy (alias_command, "/"); + else + strcpy (alias_command, ""); + + strcat (alias_command, *ptr_cmd); + strcat (alias_command, " "); + strcat (alias_command, argv_eol[1]); + + weechat_command (buffer, alias_command); + free (alias_command); + } + } + else + { + if (*ptr_cmd[0] == '/') + (void) weechat_command(buffer, *ptr_cmd); + else + { + alias_command = (char *) malloc (1 + strlen (*ptr_cmd) + 1); + if (alias_command) + { + strcpy (alias_command, "/"); + strcat (alias_command, *ptr_cmd); + weechat_command (buffer, alias_command); + free (alias_command); + } + } + } + } + } + ptr_alias->running = 0; + weechat_string_free_splitted_command (commands); + } + } + return PLUGIN_RC_SUCCESS; +} + +/* + * alias_new: create new alias and add it to alias list + */ + +static struct t_alias * +alias_new (char *name, char *command) +{ + struct t_alias *new_alias, *ptr_alias; + struct t_hook *new_hook; + + if (!name || !name[0] || !command || !command[0]) + return NULL; + + while (name[0] == '/') + { + name++; + } + + ptr_alias = alias_search (name); + if (ptr_alias) + { + if (ptr_alias->command) + free (ptr_alias->command); + ptr_alias->command = strdup (command); + return ptr_alias; + } + + if ((new_alias = ((struct t_alias *) malloc (sizeof (struct t_alias))))) + { + new_hook = weechat_hook_command (name, NULL, NULL, NULL, NULL, + alias_cb, new_alias); + if (!new_hook) + { + free (new_alias); + return NULL; + } + + new_alias->hook = new_hook; + new_alias->name = strdup (name); + new_alias->command = strdup (command); + new_alias->running = 0; + + new_alias->prev_alias = last_alias; + new_alias->next_alias = NULL; + if (alias_list) + last_alias->next_alias = new_alias; + else + alias_list = new_alias; + last_alias = new_alias; + + return new_alias; + } + + return NULL; +} + +/* + * alias_get_final_command: get final command pointed by an alias + */ + +static char * +alias_get_final_command (struct t_alias *alias) +{ + struct t_alias *ptr_alias; + char *result; + + if (alias->running) + { + weechat_printf (NULL, + _("%sError: circular reference when calling alias " + "\"/%s\""), + weechat_prefix ("error"), + alias->name); + return NULL; + } + + ptr_alias = alias_search ((alias->command[0] == '/') ? + alias->command + 1 : alias->command); + if (ptr_alias) + { + alias->running = 1; + result = alias_get_final_command (ptr_alias); + alias->running = 0; + return result; + } + return (alias->command[0] == '/') ? + alias->command + 1 : alias->command; +} + +/* + * alias_free: free an alias and reomve it from list + */ + +static 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 + */ + +static void +alias_free_all () +{ + while (alias_list) + alias_free (alias_list); +} + +/* + * alias_config_read_line: read an alias in configuration file + */ + +void +alias_config_read_line (void *config_file, char *option_name, char *value) +{ + /* make C compiler happy */ + (void) config_file; + + /* create new alias */ + if (!alias_new (option_name, value)) + { + weechat_printf (NULL, + "%sAlias: error creating alias \"%s\" => \"%s\"", + weechat_prefix ("error"), + option_name, value); + } +} + +/* + * alias_config_write_section: write alias section in configuration file + * Return: 0 = successful + * -1 = write error + */ + +void +alias_config_write_section (void *config_file) +{ + struct t_alias *ptr_alias; + char *string; + + for (ptr_alias = alias_list; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + string = (char *)malloc (strlen (ptr_alias->command) + 4); + if (string) + { + strcpy (string, "\""); + strcat (string, ptr_alias->command); + strcat (string, "\""); + weechat_config_write_line (config_file, + ptr_alias->name, + string); + free (string); + } + } +} + +/* + * alias_config_write_default_aliases: write default aliases in configuration file + */ + +void +alias_config_write_default_aliases (void *config_file) +{ + weechat_config_write_line (config_file, "SAY", "\"msg *\""); + weechat_config_write_line (config_file, "BYE", "\"quit\""); + weechat_config_write_line (config_file, "EXIT", "\"quit\""); + weechat_config_write_line (config_file, "SIGNOFF", "\"quit\""); + weechat_config_write_line (config_file, "C", "\"clear\""); + weechat_config_write_line (config_file, "CL", "\"clear\""); + weechat_config_write_line (config_file, "CLOSE", "\"buffer close\""); + weechat_config_write_line (config_file, "CHAT", "\"dcc chat\""); + weechat_config_write_line (config_file, "IG", "\"ignore\""); + weechat_config_write_line (config_file, "J", "\"join\""); + weechat_config_write_line (config_file, "K", "\"kick\""); + weechat_config_write_line (config_file, "KB", "\"kickban\""); + weechat_config_write_line (config_file, "LEAVE", "\"part\""); + weechat_config_write_line (config_file, "M", "\"msg\""); + weechat_config_write_line (config_file, "MUB", "\"unban *\""); + weechat_config_write_line (config_file, "N", "\"names\""); + weechat_config_write_line (config_file, "Q", "\"query\""); + weechat_config_write_line (config_file, "T", "\"topic\""); + weechat_config_write_line (config_file, "UB", "\"unban\""); + weechat_config_write_line (config_file, "UNIG", "\"unignore\""); + weechat_config_write_line (config_file, "W", "\"who\""); + weechat_config_write_line (config_file, "WC", "\"window merge\""); + weechat_config_write_line (config_file, "WI", "\"whois\""); + weechat_config_write_line (config_file, "WW", "\"whowas\""); +} + +/* + * alias_config_init: init alias configuration file + */ + +static int +alias_config_init () +{ + struct t_config_section *ptr_section; + + alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME); + if (alias_config_file) + { + ptr_section = weechat_config_new_section (alias_config_file, "alias", + alias_config_read_line, + alias_config_write_section, + alias_config_write_default_aliases); + if (ptr_section) + return 1; + weechat_config_free (alias_config_file); + } + return 0; +} + +/* + * alias_config_read: read alias configuration file + */ + +static int +alias_config_read () +{ + return weechat_config_read (alias_config_file); +} + +/* + * alias_config_reaload: reload alias configuration file + */ + +static int +alias_config_reload () +{ + alias_free_all (); + return weechat_config_reload (alias_config_file); +} + +/* + * alias_config_write: write alias configuration file + */ + +static int +alias_config_write () +{ + return weechat_config_write (alias_config_file); +} + +/* + * alias_command_cb: display or create alias + */ + +static int +alias_command_cb (void *data, void *buffer, int argc, char **argv, + char **argv_eol) +{ + char *alias_name; + struct t_alias *ptr_alias; + + /* make C compiler happy */ + (void) data; + (void) buffer; + + if (argc > 1) + { + alias_name = (argv[1][0] == '/') ? argv[1] + 1 : argv[1]; + if (argc > 2) + { + /* Define new alias */ + if (!alias_new (alias_name, argv_eol[2])) + { + weechat_printf (NULL, + _("%sAlias: error creating alias \"%s\" " + "=> \"%\""), + weechat_prefix ("error"), + alias_name, argv_eol[2]); + return PLUGIN_RC_FAILED; + } + weechat_printf (NULL, + _("%sAlias \"%s\" => \"%s\" created"), + weechat_prefix ("info"), + alias_name, argv_eol[2]); + } + else + { + /* Display one alias */ + ptr_alias = alias_search (alias_name); + if (ptr_alias) + { + weechat_printf (NULL, ""); + weechat_printf (NULL, _("Alias:")); + weechat_printf (NULL, " %s %s=>%s %s", + ptr_alias->name, + weechat_color ("color_chat_delimiters"), + weechat_color ("color_chat"), + ptr_alias->command); + } + else + weechat_printf (NULL, + _("%sNo alias found."), + weechat_prefix ("info")); + } + } + else + { + /* List all aliases */ + if (alias_list) + { + weechat_printf (NULL, ""); + weechat_printf (NULL, _("List of aliases:")); + for (ptr_alias = alias_list; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + weechat_printf (NULL, + " %s %s=>%s %s", + ptr_alias->name, + weechat_color ("color_chat_delimiters"), + weechat_color ("color_chat"), + ptr_alias->command); + } + } + else + weechat_printf (NULL, + _("%sNo alias defined."), + weechat_prefix ("info")); + } + return 0; +} + +/* + * unalias_command_cb: remove an alias + */ + +int +unalias_command_cb (void *data, void *buffer, int argc, char **argv, + char **argv_eol) +{ + char *alias_name; + struct t_alias *ptr_alias; + + /* make C compiler happy */ + (void) data; + (void) buffer; + (void) argv_eol; + + if (argc > 1) + { + alias_name = (argv[1][0] == '/') ? argv[1] + 1 : argv[1]; + ptr_alias = alias_search (alias_name); + if (!ptr_alias) + { + weechat_printf (NULL, + _("%sAlias \"%s\" not found"), + weechat_prefix ("error"), + alias_name); + return -1; + } + alias_free (ptr_alias); + weechat_printf (NULL, + _("%sAlias \"%s\" removed"), + weechat_prefix ("info"), + alias_name); + } + return 0; +} + +/* + * weechat_plugin_init: initialize alias plugin + */ + +int +weechat_plugin_init (struct t_weechat_plugin *plugin) +{ + weechat_plugin = plugin; + + if (!alias_config_init ()) + { + weechat_printf (NULL, + "%sAlias: error creating configuration file \"%s\"", + weechat_prefix("error"), + ALIAS_CONFIG_FILENAME); + return PLUGIN_RC_FAILED; + } + alias_config_read (); + + alias_command = weechat_hook_command ("alias", + N_("create an alias for a command"), + N_("[alias_name [command [arguments]]]"), + N_("alias_name: name of alias\n" + " command: command name (many " + "commands can be separated by " + "semicolons)\n" + " arguments: arguments for " + "command\n\n" + "Note: in command, special " + "variables $1, $2,..,$9 " + "are replaced by arguments given " + "by user, and $* " + "is replaced by all arguments.\n" + "Variables $nick, $channel and " + "$server are " + "replaced by current nick/channel" + "/server."), + "%- %h", + alias_command_cb, NULL); + + unalias_command = weechat_hook_command ("unalias", N_("remove an alias"), + N_("alias_name"), + N_("alias_name: name of alias to " + "remove"), + "%h", + unalias_command_cb, NULL); + + return PLUGIN_RC_SUCCESS; +} + +/* + * weechat_plugin_end: end alias plugin + */ + +int +weechat_plugin_end () +{ + alias_config_write (); + alias_free_all (); + weechat_unhook (alias_command); + weechat_unhook (unalias_command); + return PLUGIN_RC_SUCCESS; +} diff --git a/src/core/wee-alias.h b/src/plugins/alias/alias.h index fc713f973..1ad13bd3b 100644 --- a/src/core/wee-alias.h +++ b/src/plugins/alias/alias.h @@ -20,26 +20,20 @@ #ifndef __WEECHAT_ALIAS_H #define __WEECHAT_ALIAS_H 1 -#include "../gui/gui-buffer.h" +char plugin_name[] = "alias"; +char plugin_version[] = "0.1"; +char plugin_description[] = "Alias plugin for WeeChat"; -struct alias +#define ALIAS_CONFIG_FILENAME "alias.rc" + +struct t_alias { - char *name; - char *command; - int running; - struct alias *prev_alias; - struct alias *next_alias; + struct t_hook *hook; /* command hook */ + char *name; /* alias name */ + char *command; /* alias command */ + int running; /* 1 if alias is running */ + struct t_alias *prev_alias; /* link to previous alias */ + struct t_alias *next_alias; /* link to next alias */ }; -extern struct alias *weechat_alias; -extern struct alias *weechat_last_alias; - -extern struct alias *alias_search (char *); -extern struct alias *alias_new (char *, char *); -extern char *alias_get_final_command (struct alias *); -extern char *alias_replace_args (char *, char *); -extern char *alias_replace_vars (struct t_gui_buffer *, char *); -extern void alias_free (struct alias *); -extern void alias_free_all (); - -#endif /* wee-alias.h */ +#endif /* alias.h */ diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index da50e4bb3..6e985125a 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2597,7 +2597,7 @@ irc_protocol_cmd_001 (t_irc_server *server, char *irc_message, char *host, if (server->command && server->command[0]) { /* splitting command on ';' which can be escaped with '\;' */ - commands = weechat_split_multi_command (server->command, ';'); + commands = weechat_split_command (server->command, ';'); if (commands) { for (ptr = commands; *ptr; ptr++) @@ -2608,7 +2608,7 @@ irc_protocol_cmd_001 (t_irc_server *server, char *irc_message, char *host, if (vars_replaced) free (vars_replaced); } - weechat_free_multi_command (commands); + weechat_free_splitted_command (commands); } if (server->command_delay > 0) diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index a95435bdb..ef98d2af8 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -200,6 +200,34 @@ plugin_api_string_free_exploded (struct t_weechat_plugin *plugin, } /* + * plugin_api_string_split_command: split a ocmmanc + */ + +char ** +plugin_api_string_split_command (struct t_weechat_plugin *plugin, char *string, + char separator) +{ + if (!plugin || !string) + return NULL; + + return string_split_command (string, separator); +} + +/* + * plugin_api_string_free_splitted_command: free splitted command + */ + +void +plugin_api_string_free_splitted_command (struct t_weechat_plugin *plugin, + char **splitted_command) +{ + /* make C compiler happy */ + (void) plugin; + + string_free_splitted_command (splitted_command); +} + +/* * plugin_api_mkdir_home: create a directory in WeeChat home */ @@ -398,6 +426,70 @@ plugin_api_config_color (struct t_weechat_plugin *plugin, void *option) } /* + * plugin_api_config_read: read a configuration file + */ + +int +plugin_api_config_read (struct t_weechat_plugin *plugin, void *config_file) +{ + if (plugin && config_file_valid_for_plugin (plugin, config_file)) + return config_file_read ((struct t_config_file *)config_file); + else + return -1; +} + +/* + * plugin_api_config_reload: reload a configuration file + */ + +int +plugin_api_config_reload (struct t_weechat_plugin *plugin, void *config_file) +{ + if (plugin && config_file_valid_for_plugin (plugin, config_file)) + return config_file_reload ((struct t_config_file *)config_file); + else + return -1; +} + +/* + * plugin_api_config_write: write a configuration file + */ + +int +plugin_api_config_write (struct t_weechat_plugin *plugin, void *config_file) +{ + if (plugin && config_file_valid_for_plugin (plugin, config_file)) + return config_file_write ((struct t_config_file *)config_file, 0); + else + return -1; +} + +/* + * plugin_api_config_write_line: write a line in configuration file + */ + +void +plugin_api_config_write_line (struct t_weechat_plugin *plugin, + void *config_file, char *option_name, + char *value) +{ + if (plugin && config_file_valid_for_plugin (plugin, config_file)) + config_file_write_line ((struct t_config_file *)config_file, + option_name, value); +} + +/* + * plugin_api_config_free: free a configuration file + */ + +void +plugin_api_config_free (struct t_weechat_plugin *plugin, void *config_file) +{ + if (plugin && config_file_valid_for_plugin (plugin, config_file)) + config_file_free ((struct t_config_file *)config_file); +} + +/* * plugin_api_get_config_str_value: return string value for any option * This function should never be called directly * (only used by weechat_get_config) diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index 2b98ecac3..308ec330e 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -38,6 +38,10 @@ extern char **plugin_api_string_explode (struct t_weechat_plugin *, char *, char *, int, int, int *); extern void plugin_api_string_free_exploded (struct t_weechat_plugin *, char **); +extern char **plugin_api_string_split_command (struct t_weechat_plugin *, + char *, char); +extern void plugin_api_string_free_splitted_command (struct t_weechat_plugin *, + char **); /* directories */ extern int plugin_api_mkdir_home (struct t_weechat_plugin *, char *); @@ -45,20 +49,29 @@ extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *, int (*)(char *)); /* config */ -extern struct t_config_file *config_new (struct t_weechat_plugin *, char *); -extern struct t_config_section *config_new_section (struct t_weechat_plugin *, - void *, char *, - void (*)(void *, char *, char *), - void (*)(void *), - void (*)(void *)); -extern struct t_config_option *config_new_option (struct t_weechat_plugin *, - void *, char *, char *, - char *, char *, int, int, - char *, void (*)()); -extern char config_boolean (struct t_weechat_plugin *, void *); -extern int config_integer (struct t_weechat_plugin *, void *); -extern char *config_string (struct t_weechat_plugin *, void *); -extern int config_color (struct t_weechat_plugin *, void *); +extern struct t_config_file *plugin_api_config_new (struct t_weechat_plugin *, + char *); +extern struct t_config_section *plugin_api_config_new_section (struct t_weechat_plugin *, + void *, char *, + void (*)(void *, char *, char *), + void (*)(void *), + void (*)(void *)); +extern struct t_config_option *plugin_api_config_new_option (struct t_weechat_plugin *, + void *, char *, + char *, char *, + char *, int, int, + char *, + void (*)()); +extern char plugin_api_config_boolean (struct t_weechat_plugin *, void *); +extern int plugin_api_config_integer (struct t_weechat_plugin *, void *); +extern char *plugin_api_config_string (struct t_weechat_plugin *, void *); +extern int plugin_api_config_color (struct t_weechat_plugin *, void *); +extern int plugin_api_config_read (struct t_weechat_plugin *, void *); +extern int plugin_api_config_reload (struct t_weechat_plugin *, void *); +extern int plugin_api_config_write (struct t_weechat_plugin *, void *); +extern void plugin_api_config_write_line (struct t_weechat_plugin *, void *, + char *, char *); +extern void plugin_api_config_free (struct t_weechat_plugin *, void *); extern char *plugin_api_config_get (struct t_weechat_plugin *, char *); extern int plugin_api_config_set (struct t_weechat_plugin *, char *, char *); extern char *plugin_api_plugin_config_get (struct t_weechat_plugin *, char *); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index cd5d2cb0a..53b42bdbe 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -234,14 +234,32 @@ plugin_load (char *filename) new_plugin->string_replace = &plugin_api_string_replace; new_plugin->string_explode = &plugin_api_string_explode; new_plugin->string_free_exploded = &plugin_api_string_free_exploded; + new_plugin->string_split_command = &plugin_api_string_split_command; + new_plugin->string_free_splitted_command = &plugin_api_string_free_splitted_command; new_plugin->mkdir_home = &plugin_api_mkdir_home; new_plugin->exec_on_files = &plugin_api_exec_on_files; - - new_plugin->printf = &plugin_api_printf; - new_plugin->printf_date = &plugin_api_printf_date; + + new_plugin->config_new = &plugin_api_config_new; + new_plugin->config_new_section = &plugin_api_config_new_section; + new_plugin->config_new_option = &plugin_api_config_new_option; + new_plugin->config_boolean = &plugin_api_config_boolean; + new_plugin->config_integer = &plugin_api_config_integer; + new_plugin->config_string = &plugin_api_config_string; + new_plugin->config_color = &plugin_api_config_color; + new_plugin->config_read = &plugin_api_config_read; + new_plugin->config_reload = &plugin_api_config_reload; + new_plugin->config_write = &plugin_api_config_write; + new_plugin->config_write_line = &plugin_api_config_write_line; + new_plugin->config_get = &plugin_api_config_get; + new_plugin->config_set = &plugin_api_config_set; + new_plugin->plugin_config_get = &plugin_api_plugin_config_get; + new_plugin->plugin_config_set = &plugin_api_plugin_config_set; + new_plugin->prefix = &plugin_api_prefix; new_plugin->color = &plugin_api_color; + new_plugin->printf = &plugin_api_printf; + new_plugin->printf_date = &plugin_api_printf_date; new_plugin->print_infobar = &plugin_api_print_infobar; new_plugin->infobar_remove = &plugin_api_infobar_remove; @@ -275,11 +293,6 @@ plugin_load (char *filename) new_plugin->list_time = &plugin_api_list_time; new_plugin->list_free = &plugin_api_list_free; - new_plugin->config_get = &plugin_api_config_get; - new_plugin->config_set = &plugin_api_config_set; - new_plugin->plugin_config_get = &plugin_api_plugin_config_get; - new_plugin->plugin_config_set = &plugin_api_plugin_config_set; - new_plugin->log = &plugin_api_log; /* add new plugin to list */ diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 22537e4f5..07357f250 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -67,6 +67,8 @@ struct t_weechat_plugin char **(*string_explode) (struct t_weechat_plugin *, char *, char *, int, int, int *); void (*string_free_exploded) (struct t_weechat_plugin *, char **); + char **(*string_split_command) (struct t_weechat_plugin *, char *, char); + void (*string_free_splitted_command) (struct t_weechat_plugin *, char **); /* directories */ int (*mkdir_home) (struct t_weechat_plugin *, char *); @@ -88,11 +90,16 @@ struct t_weechat_plugin int (*config_integer) (struct t_weechat_plugin *, void *); char *(*config_string) (struct t_weechat_plugin *, void *); int (*config_color) (struct t_weechat_plugin *, void *); + int (*config_read) (struct t_weechat_plugin *, void *); + int (*config_reload) (struct t_weechat_plugin *, void *); + int (*config_write) (struct t_weechat_plugin *, void *); + void (*config_write_line) (struct t_weechat_plugin *, void *, + char *, char *); + void (*config_free) (struct t_weechat_plugin *, void *); char *(*config_get) (struct t_weechat_plugin *, char *); int (*config_set) (struct t_weechat_plugin *, char *, char *); char *(*plugin_config_get) (struct t_weechat_plugin *, char *); int (*plugin_config_set) (struct t_weechat_plugin *, char *, char *); - /* display */ char *(*prefix) (struct t_weechat_plugin *, char *); @@ -193,6 +200,12 @@ struct t_weechat_plugin __num_items) #define weechat_string_free_exploded(__array_str) \ weechat_plugin->string_free_exploded(weechat_plugin, __array_str) +#define weechat_string_split_command(__string1, __separator) \ + weechat_plugin->string_split_command(weechat_plugin, __string1, \ + __separator) +#define weechat_string_free_splitted_command(__array_str) \ + weechat_plugin->string_free_splitted_command(weechat_plugin, \ + __array_str) /* directories */ #define weechat_mkdir_home(__directory) \ @@ -224,6 +237,18 @@ struct t_weechat_plugin weechat_plugin->config_string(weechat_plugin, __option) #define weechat_config_color(__option) \ weechat_plugin->config_color(weechat_plugin, __option) +#define weechat_config_read(__config) \ + weechat_plugin->config_read(weechat_plugin, __config) +#define weechat_config_reload(__config) \ + weechat_plugin->config_reload(weechat_plugin, __config) +#define weechat_config_write(__config) \ + weechat_plugin->config_write(weechat_plugin, __config) +#define weechat_config_write_line(__config, __option, __value) \ + weechat_plugin->config_write_line(weechat_plugin, \ + __config, __option, \ + __value) +#define weechat_config_free(__config) \ + weechat_plugin->config_free(weechat_plugin, __config) #define weechat_config_get(__option) \ weechat_plugin->config_get(weechat_plugin, __option) #define weechat_config_set(__option, __value) \ |