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/core | |
parent | e0826e1ce7bcff9c0404da0f2fac05b7224aad2c (diff) | |
download | weechat-2888d41425afc7e38238533a95930cf0f46cc10c.zip |
Added alias plugin, added missing config file functions in plugins API
Diffstat (limited to 'src/core')
-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-alias.h | 45 | ||||
-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 |
13 files changed, 222 insertions, 825 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-alias.h b/src/core/wee-alias.h deleted file mode 100644 index fc713f973..000000000 --- a/src/core/wee-alias.h +++ /dev/null @@ -1,45 +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/>. - */ - - -#ifndef __WEECHAT_ALIAS_H -#define __WEECHAT_ALIAS_H 1 - -#include "../gui/gui-buffer.h" - -struct alias -{ - char *name; - char *command; - int running; - struct alias *prev_alias; - struct alias *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 */ 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(); |