diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-10-31 17:09:43 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-10-31 17:09:43 +0100 |
commit | a3cb19dbea05886dafc65a35e7c959414bad12e5 (patch) | |
tree | 671fc4c491f24d18ced3b35aaf9a56f214485974 /src | |
parent | eb2835fa24d510a46f8616855624f7ac1ddd19b8 (diff) | |
download | weechat-a3cb19dbea05886dafc65a35e7c959414bad12e5.zip |
Renamed many functions, removed all IRC specific stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/core/Makefile.am | 58 | ||||
-rw-r--r-- | src/core/wee-alias.c | 113 | ||||
-rw-r--r-- | src/core/wee-alias.h | 30 | ||||
-rw-r--r-- | src/core/wee-backtrace.c | 10 | ||||
-rw-r--r-- | src/core/wee-backtrace.h | 2 | ||||
-rw-r--r-- | src/core/wee-command.c | 4366 | ||||
-rw-r--r-- | src/core/wee-command.h | 96 | ||||
-rw-r--r-- | src/core/wee-config.c | 2957 | ||||
-rw-r--r-- | src/core/wee-config.h | 256 | ||||
-rw-r--r-- | src/core/wee-list.c | 66 | ||||
-rw-r--r-- | src/core/wee-list.h | 20 | ||||
-rw-r--r-- | src/core/wee-log.c | 30 | ||||
-rw-r--r-- | src/core/wee-log.h | 2 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 206 | ||||
-rw-r--r-- | src/core/wee-upgrade.h | 2 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 45 | ||||
-rw-r--r-- | src/core/wee-utf8.h | 7 | ||||
-rw-r--r-- | src/core/wee-util.c | 751 | ||||
-rw-r--r-- | src/core/wee-util.h | 24 | ||||
-rw-r--r-- | src/core/weechat.c | 648 | ||||
-rw-r--r-- | src/core/weechat.h | 6 |
22 files changed, 2740 insertions, 6967 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8f48d90b2..0e20941dc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -14,10 +14,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -SET(LIB_MAIN_SRC weechat.c weechat.h alias.c alias.h backtrace.c backtrace.h -command.c command.h completion.c completion.h weelist.c weelist.h weeconfig.c -weeconfig.h history.c history.h hotlist.c hotlist.h log.c log.h fifo.c fifo.h -session.c session.h utf8.c utf8.h util.c util.h) +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-config-option.c wee-config-option.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) @@ -25,4 +27,4 @@ CHECK_INCLUDE_FILES("sys/file.h" HAVE_SYS_FILE_H) CHECK_SYMBOL_EXISTS(flock "sys/file.h" HAVE_FLOCK) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) -ADD_LIBRARY(weechat_main STATIC ${LIB_MAIN_SRC}) +ADD_LIBRARY(weechat_core STATIC ${LIB_CORE_SRC}) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index ca0701c73..043dba416 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -16,33 +16,35 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GNUTLS_CFLAGS) -noinst_LIBRARIES = lib_weechat_main.a +noinst_LIBRARIES = lib_weechat_core.a -lib_weechat_main_a_SOURCES = weechat.c \ +lib_weechat_core_a_SOURCES = weechat.c \ weechat.h \ - alias.c \ - alias.h \ - backtrace.c \ - backtrace.h \ - command.c \ - command.h \ - completion.c \ - completion.h \ - weelist.c \ - weelist.h \ - weeconfig.c \ - weeconfig.h \ - history.c \ - history.h \ - hotlist.c \ - hotlist.h \ - log.c \ - log.h \ - fifo.c \ - fifo.h \ - session.c \ - session.h \ - utf8.c \ - utf8.h \ - util.c \ - util.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-config-option.c \ + wee-config-option.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-upgrade.c \ + wee-upgrade.h \ + wee-string.c \ + wee-string.h \ + wee-utf8.c \ + wee-utf8.h \ + wee-util.c \ + wee-util.h diff --git a/src/core/wee-alias.c b/src/core/wee-alias.c index 4a8919f35..dd2836081 100644 --- a/src/core/wee-alias.c +++ b/src/core/wee-alias.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* alias.c: WeeChat alias */ +/* wee-alias.c: WeeChat alias */ #ifdef HAVE_CONFIG_H @@ -27,27 +27,27 @@ #include <string.h> #include "weechat.h" -#include "alias.h" -#include "util.h" -#include "../protocols/irc/irc.h" +#include "wee-alias.h" +#include "wee-config.h" +#include "wee-string.h" -t_weechat_alias *weechat_alias = NULL; -t_weechat_alias *weechat_last_alias = NULL; +struct alias *weechat_alias = NULL; +struct alias *weechat_last_alias = NULL; /* * alias_search: search an alias */ -t_weechat_alias * +struct alias * alias_search (char *alias_name) { - t_weechat_alias *ptr_alias; + struct alias *ptr_alias; for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) == 0) + if (string_strcasecmp (alias_name, ptr_alias->name) == 0) return ptr_alias; } return NULL; @@ -57,14 +57,14 @@ alias_search (char *alias_name) * alias_find_pos: find position for an alias (for sorting aliases) */ -t_weechat_alias * +struct alias * alias_find_pos (char *alias_name) { - t_weechat_alias *ptr_alias; + struct alias *ptr_alias; for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) < 0) + if (string_strcasecmp (alias_name, ptr_alias->name) < 0) return ptr_alias; } return NULL; @@ -75,11 +75,11 @@ alias_find_pos (char *alias_name) */ void -alias_insert_sorted (t_weechat_alias *alias) +alias_insert_sorted (struct alias *alias) { - t_weechat_alias *pos_alias; + struct alias *pos_alias; - pos_alias = alias_find_pos (alias->alias_name); + pos_alias = alias_find_pos (alias->name); if (weechat_alias) { @@ -116,35 +116,35 @@ alias_insert_sorted (t_weechat_alias *alias) * alias_new: create new alias and add it to alias list */ -t_weechat_alias * -alias_new (char *alias_name, char *alias_command) +struct alias * +alias_new (char *name, char *command) { - t_weechat_alias *new_alias, *ptr_alias; + struct alias *new_alias, *ptr_alias; - while (alias_name[0] == '/') + while (name[0] == '/') { - alias_name++; + name++; } - if (ascii_strcasecmp (alias_name, "builtin") == 0) + if (string_strcasecmp (name, "builtin") == 0) return NULL; - ptr_alias = alias_search (alias_name); + ptr_alias = alias_search (name); if (ptr_alias) { - if (ptr_alias->alias_command) - free (ptr_alias->alias_command); - ptr_alias->alias_command = strdup (alias_command); + if (ptr_alias->command) + free (ptr_alias->command); + ptr_alias->command = strdup (command); return ptr_alias; } - if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias))))) + if ((new_alias = ((struct alias *) malloc (sizeof (struct alias))))) { - new_alias->alias_name = strdup (alias_name); - new_alias->alias_command = (char *) malloc (strlen (alias_command) + 1); + new_alias->name = strdup (name); + new_alias->command = (char *) malloc (strlen (command) + 1); new_alias->running = 0; - if (new_alias->alias_command) - strcpy (new_alias->alias_command, alias_command); + if (new_alias->command) + strcpy (new_alias->command, command); alias_insert_sorted (new_alias); return new_alias; } @@ -157,22 +157,23 @@ alias_new (char *alias_name, char *alias_command) */ char * -alias_get_final_command (t_weechat_alias *alias) +alias_get_final_command (struct alias *alias) { - t_weechat_alias *ptr_alias; + struct alias *ptr_alias; char *result; if (alias->running) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s circular reference when calling alias \"/%s\"\n"), - WEECHAT_ERROR, alias->alias_name); + gui_chat_printf (NULL, + _("%s%s circular reference when calling alias " + "\"/%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, alias->name); return NULL; } - ptr_alias = alias_search ((alias->alias_command[0] == '/') ? - alias->alias_command + 1 : alias->alias_command); + ptr_alias = alias_search ((alias->command[0] == '/') ? + alias->command + 1 : alias->command); if (ptr_alias) { alias->running = 1; @@ -180,8 +181,8 @@ alias_get_final_command (t_weechat_alias *alias) alias->running = 0; return result; } - return (alias->alias_command[0] == '/') ? - alias->alias_command + 1 : alias->alias_command; + return (alias->command[0] == '/') ? + alias->command + 1 : alias->command; } /* @@ -224,7 +225,7 @@ alias_replace_args (char *alias_args, char *user_args) char **argv, *start, *pos, *res; int argc, length_res, args_count; - argv = explode_string (user_args, " ", 0, &argc); + argv = string_explode (user_args, " ", 0, &argc); res = NULL; length_res = 0; @@ -288,19 +289,23 @@ alias_replace_args (char *alias_args, char *user_args) } if (argv) - free_exploded_string (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 (t_irc_server *server, t_irc_channel *channel, char *string) +alias_replace_vars (struct t_gui_buffer *buffer, char *string) { - char *var_nick, *var_channel, *var_server; + /* 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; @@ -308,28 +313,26 @@ alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string) var_channel = (channel) ? channel->name : empty_string; var_server = (server) ? server->name : empty_string; - /* replace nick */ temp = weechat_strreplace (string, "$nick", var_nick); if (!temp) return NULL; res = temp; - /* replace channel */ temp = weechat_strreplace (res, "$channel", var_channel); free (res); if (!temp) return NULL; res = temp; - /* replace server */ temp = weechat_strreplace (res, "$server", var_server); free (res); if (!temp) return NULL; res = temp; - /* return result */ - return res; + return res;*/ + + return strdup (string); } /* @@ -337,9 +340,9 @@ alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string) */ void -alias_free (t_weechat_alias *alias) +alias_free (struct alias *alias) { - t_weechat_alias *new_weechat_alias; + struct alias *new_weechat_alias; /* remove alias from list */ if (weechat_last_alias == alias) @@ -356,10 +359,10 @@ alias_free (t_weechat_alias *alias) (alias->next_alias)->prev_alias = alias->prev_alias; /* free data */ - if (alias->alias_name) - free (alias->alias_name); - if (alias->alias_command) - free (alias->alias_command); + if (alias->name) + free (alias->name); + if (alias->command) + free (alias->command); free (alias); weechat_alias = new_weechat_alias; } diff --git a/src/core/wee-alias.h b/src/core/wee-alias.h index 759330ddd..fc713f973 100644 --- a/src/core/wee-alias.h +++ b/src/core/wee-alias.h @@ -20,28 +20,26 @@ #ifndef __WEECHAT_ALIAS_H #define __WEECHAT_ALIAS_H 1 -#include "../protocols/irc/irc.h" +#include "../gui/gui-buffer.h" -typedef struct t_weechat_alias t_weechat_alias; - -struct t_weechat_alias +struct alias { - char *alias_name; - char *alias_command; + char *name; + char *command; int running; - t_weechat_alias *prev_alias; - t_weechat_alias *next_alias; + struct alias *prev_alias; + struct alias *next_alias; }; -extern t_weechat_alias *weechat_alias; -extern t_weechat_alias *weechat_last_alias; +extern struct alias *weechat_alias; +extern struct alias *weechat_last_alias; -extern t_weechat_alias *alias_search (char *); -extern t_weechat_alias *alias_new (char *, char *); -extern char *alias_get_final_command (t_weechat_alias *); +extern 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 (t_irc_server *, t_irc_channel *, char *); -extern void alias_free (t_weechat_alias *); +extern char *alias_replace_vars (struct t_gui_buffer *, char *); +extern void alias_free (struct alias *); extern void alias_free_all (); -#endif /* alias.h */ +#endif /* wee-alias.h */ diff --git a/src/core/wee-backtrace.c b/src/core/wee-backtrace.c index d6d0b8b08..49ec1ec02 100644 --- a/src/core/wee-backtrace.c +++ b/src/core/wee-backtrace.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* backtrace.c: display backtrace after a segfault */ +/* wee-backtrace.c: display backtrace after a segfault */ #ifdef HAVE_CONFIG_H @@ -39,9 +39,9 @@ #endif #include "weechat.h" -#include "backtrace.h" -#include "log.h" -#include "util.h" +#include "wee-backtrace.h" +#include "wee-log.h" +#include "wee-string.h" /* @@ -58,7 +58,7 @@ weechat_backtrace_printf (char *message, ...) vsnprintf (buffer, sizeof (buffer) - 1, message, argptr); va_end (argptr); - weechat_iconv_fprintf (stderr, "%s", buffer); + string_iconv_fprintf (stderr, "%s", buffer); weechat_log_printf ("%s", buffer); } diff --git a/src/core/wee-backtrace.h b/src/core/wee-backtrace.h index 80a2c8f41..6df51b5a3 100644 --- a/src/core/wee-backtrace.h +++ b/src/core/wee-backtrace.h @@ -24,4 +24,4 @@ extern void weechat_backtrace (); -#endif /* backtrace.h */ +#endif /* wee-backtrace.h */ diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 337a961a2..7f790e5ba 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* command.c: WeeChat internal commands */ +/* wee-command.c: WeeChat commands */ #ifdef HAVE_CONFIG_H @@ -29,27 +29,29 @@ #include <ctype.h> #include "weechat.h" -#include "command.h" -#include "alias.h" -#include "fifo.h" -#include "log.h" -#include "session.h" -#include "utf8.h" -#include "util.h" -#include "weelist.h" -#include "weeconfig.h" -#include "../protocols/irc/irc.h" -#include "../gui/gui.h" - -#ifdef PLUGINS -#include "../plugins/plugins.h" -#endif +#include "wee-command.h" +#include "wee-alias.h" +#include "wee-config.h" +#include "wee-hook.h" +#include "wee-input.h" +#include "wee-log.h" +#include "wee-session.h" +#include "wee-string.h" +#include "wee-utf8.h" +#include "wee-list.h" +#include "../gui/gui-chat.h" +#include "../gui/gui-history.h" +#include "../gui/gui-keyboard.h" +#include "../gui/gui-window.h" +#include "../plugins/plugin.h" +#include "../plugins/plugin-config.h" /* WeeChat internal commands */ -t_weechat_command weechat_commands[] = -{ { "alias", N_("create an alias for a command"), +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 " @@ -59,12 +61,12 @@ t_weechat_command weechat_commands[] = "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, NULL, weechat_cmd_alias }, - { "buffer", N_("manage buffers"), + "%- %A", 0, MAX_ARGS, 1, command_alias }, + { "buffer", + N_("manage buffers"), N_("[action [args] | number | [[server] [channel]]]"), N_(" action: action to do:\n" " move: move buffer in the list (may be relative, for example -1)\n" - " close: close buffer (optional arg is part message, for a channel)\n" " list: list open buffers (no parameter implies this list)\n" " notify: set notify level for buffer (0=never, 1=highlight, 2=1+msg, " "3=2+join/part)\n" @@ -80,140 +82,79 @@ t_weechat_command weechat_commands[] = " move buffer: /buffer move 5\n" " close buffer: /buffer close this is part msg\n" " set notify: /buffer notify 2\n" - " scroll 1 day up: /buffer scroll 1d == /buffer scroll -1d == /buffer scroll -24h\n" + " scroll 1 day up: /buffer scroll 1d == /buffer scroll -1d == " + "/buffer scroll -24h\n" "scroll to beginning\n" " of this day: /buffer scroll d\n" " scroll 15 min down: /buffer scroll +15m\n" " scroll 20 msgs up: /buffer scroll -20\n" " jump to #weechat: /buffer #weechat"), - "move|close|list|notify|scroll|%S|%C %S|%C", 0, MAX_ARGS, 0, NULL, weechat_cmd_buffer }, - { "builtin", N_("launch WeeChat/IRC builtin command (do not look at plugins handlers or aliases)"), + "move|close|list|notify|scroll|%S|%C %S|%C", + 0, MAX_ARGS, 0, command_buffer }, + { "builtin", + N_("launch WeeChat/IRC builtin command (do not look at plugins handlers " + "or aliases)"), N_("command"), - N_("command: command to execute (a '/' is automatically added if not found at beginning of command)\n"), - "%w|%i", 0, MAX_ARGS, 1, NULL, weechat_cmd_builtin }, - { "clear", N_("clear window(s)"), + N_("command: command to execute (a '/' is automatically added if not " + "found at beginning of command)\n"), + "%w|%i", 0, MAX_ARGS, 1, command_builtin }, + { "clear", + N_("clear window(s)"), N_("[-all | number [number ...]]"), N_(" -all: clear all buffers\n" "number: clear buffer by number"), - "-all", 0, MAX_ARGS, 0, weechat_cmd_clear, NULL }, - { "connect", N_("connect to server(s)"), - N_("[-all [-nojoin] | servername [servername ...] [-nojoin] | hostname " - "[-port port] [-ipv6] [-ssl]]"), - N_(" -all: connect to all servers\n" - "servername: internal server name to connect\n" - " -nojoin: do not join any channel (even if autojoin is enabled on server)\n" - " hostname: hostname to connect, creating temporary server\n" - " port: port for server (integer, default is 6667)\n" - " ipv6: use IPv6 protocol\n" - " ssl: use SSL protocol"), - "%S|-all|-nojoin|%*", 0, MAX_ARGS, 0, weechat_cmd_connect, NULL }, - { "disconnect", N_("disconnect from server(s)"), - N_("[-all | servername [servername ...]]"), - N_(" -all: disconnect from all servers\n" - "servername: server name to disconnect"), - "%S|-all", 0, MAX_ARGS, 0, weechat_cmd_disconnect, NULL }, - { "dcc", N_("starts DCC (file or chat) or close chat"), - N_("action [nickname [file]]"), - N_(" action: 'send' (file) or 'chat' or 'close' (chat)\n" - "nickname: nickname to send file or chat\n" - " file: filename (on local host)"), - "chat|send|close %n %f", 1, MAX_ARGS, 0, NULL, weechat_cmd_dcc }, - { "debug", N_("print debug messages"), + "-all", 0, MAX_ARGS, 0, command_clear }, + { "debug", + N_("print debug messages"), N_("dump | buffer | windows"), - N_(" dump: save memory dump in WeeChat log file (same dump is written when WeeChat crashes)\n" + N_(" dump: save memory dump in WeeChat log file (same dump is written " + "when WeeChat crashes)\n" " buffer: dump buffer content with hexadecimal values in log file\n" "windows: display windows tree"), - "dump|buffer|windows", 1, 1, 0, weechat_cmd_debug, NULL }, - { "help", N_("display help about commands"), + "dump|buffer|windows", 1, 1, 0, command_debug }, + { "help", + N_("display help about commands"), N_("[command]"), N_("command: name of a WeeChat or IRC command"), - "%w|%i|%h", 0, 1, 0, weechat_cmd_help, NULL }, - { "history", N_("show buffer command history"), + "%w|%i|%h", 0, 1, 0, command_help }, + { "history", + N_("show buffer command history"), N_("[clear | value]"), N_("clear: clear history\n" "value: number of history entries to show"), - "clear", 0, 1, 0, weechat_cmd_history, NULL }, - { "ignore", N_("ignore IRC messages and/or hosts"), - N_("[mask [[type | command] [channel [server]]]]"), - N_(" mask: nick or host mask to ignore\n" - " type: type of message to ignore (action, ctcp, dcc, pv)\n" - "command: IRC command\n" - "channel: name of channel for ignore\n" - " server: name of server for ignore\n\n" - "For each argument, '*' means all.\n" - "Without argument, /ignore command lists all defined ignore."), - "*|%n *|action|ctcp|dcc|pv|%I *|%c *|%s", - 0, 4, 0, weechat_cmd_ignore, NULL }, - { "key", N_("bind/unbind keys"), - N_("[key [function/command]] [unbind key] [functions] [call function [\"args\"]] [reset -yes]"), - N_(" key: display or bind this key to an internal function or a command " - "(beginning by \"/\")\n" + "clear", 0, 1, 0, command_history }, + { "key", + N_("bind/unbind keys"), + N_("[key [function/command]] [unbind key] [functions] [call function " + "[\"args\"]] [reset -yes]"), + N_(" key: display or bind this key to an internal function or a " + "command (beginning by \"/\")\n" " unbind: unbind a key\n" "functions: list internal functions for key bindings\n" " call: call a function by name (with optional arguments)\n" " reset: restore bindings to the default values and delete ALL " "personal bindings (use carefully!)"), - "unbind|functions|call|reset %k", 0, MAX_ARGS, 0, NULL, weechat_cmd_key }, -/* { "panel", N_("manage panels"), - N_("[list | add type position size | resize # size | close # | move #1 #2]"), - N_(" list: list open panels (no parameter implies this list)\n" - " add: add a panel, type is global|local, position is top|bottom|left|right\n" - " resize: resize a panel with a new size (may be relative, for example -1)\n" - " close: close a panel by number\n" - " move: move a panel to another number (may be relative, for example -1)"), - "list|add|close|move global|local top|bottom|left|right", - 0, MAX_ARGS, 0, weechat_cmd_panel, NULL },*/ - { "plugin", N_("list/load/unload plugins"), - N_("[list [name]] | [listfull [name]] | [load filename] | [autoload] | [reload [name]] | [unload [name]]"), + "unbind|functions|call|reset %k", 0, MAX_ARGS, 0, command_key }, + { "plugin", + N_("list/load/unload plugins"), + N_("[list [name]] | [listfull [name]] | [load filename] | [autoload] | " + "[reload [name]] | [unload [name]]"), N_(" list: list loaded plugins\n" "listfull: list loaded plugins with detailed info for each plugin\n" " load: load a plugin\n" "autoload: autoload plugins in system or user directory\n" - " reload: reload one plugin (if no name given, unload all plugins, then autoload plugins)\n" + " reload: reload one plugin (if no name given, unload all plugins, " + "then autoload plugins)\n" " unload: unload one or all plugins\n\n" "Without argument, /plugin command lists loaded plugins."), - "list|listfull|load|autoload|reload|unload %P", 0, 2, 0, weechat_cmd_plugin, NULL }, - { "reconnect", N_("reconnect to server(s)"), - N_("[-all [-nojoin] | servername [servername ...] [-nojoin]]"), - N_(" -all: reconnect to all servers\n" - "servername: server name to reconnect\n" - " -nojoin: do not join any channel (even if autojoin is enabled on server)"), - "%S|-all|-nojoin|%*", 0, MAX_ARGS, 0, weechat_cmd_reconnect, NULL }, - { "save", N_("save config to disk"), - N_("[file]"), N_("file: filename for writing config"), - NULL, 0, 1, 0, weechat_cmd_save, NULL }, - { "server", N_("list, add or remove servers"), - N_("[list [servername]] | [listfull [servername]] | [add servername " - "hostname [-port port] [-temp] [-auto | -noauto] [-ipv6] [-ssl] " - "[-pwd password] [-nicks nick1 nick2 nick3] [-username username] " - "[-realname realname] [-command command] [-autojoin channel[,channel]] ] " - "| [copy servername newservername] | [rename servername newservername] " - "| [keep servername] | [del servername]"), - N_(" list: list servers (no parameter implies this list)\n" - " listfull: list servers with detailed info for each server\n" - " add: create a new server\n" - "servername: server name, for internal and display use\n" - " hostname: name or IP address of server\n" - " port: port for server (integer, default is 6667)\n" - " temp: create temporary server (not saved in config file)\n" - " auto: automatically connect to server when WeeChat starts\n" - " noauto: do not connect to server when WeeChat starts (default)\n" - " ipv6: use IPv6 protocol\n" - " ssl: use SSL protocol\n" - " password: password for server\n" - " nick1: first nick for server\n" - " nick2: alternate nick for server\n" - " nick3: second alternate nick for server\n" - " username: user name\n" - " realname: real name of user\n" - " copy: duplicate a server\n" - " rename: rename a server\n" - " keep: keep server in config file (for temporary servers only)\n" - " del: delete a server\n" - " deloutq: delete messages out queue for all servers (all messages " - "WeeChat is currently sending)"), - "add|copy|rename|keep|del|deloutq|list|listfull %S %S", - 0, MAX_ARGS, 0, weechat_cmd_server, NULL }, + "list|listfull|load|autoload|reload|unload %P", 0, 2, 0, command_plugin }, + { "quit", + "", "", "", + NULL, 0, 0, 0, command_quit }, + { "save", + N_("save configuration files to disk"), + "", "", + NULL, 0, 1, 0, command_save }, { "set", N_("set config options"), N_("[option [ = value]]"), N_("option: name of an option (if name is full " @@ -221,39 +162,33 @@ t_weechat_command weechat_commands[] = " value: value for option\n\n" "Option may be: servername.server_xxx where \"servername\" is an " "internal server name and \"xxx\" an option for this server."), - "%o = %v", 0, MAX_ARGS, 0, NULL, weechat_cmd_set }, - { "setp", N_("set plugin config options"), + "%o = %v", 0, MAX_ARGS, 0, command_set }, + { "setp", + N_("set plugin config options"), N_("[option [ = value]]"), N_("option: name of a plugin option\n" " value: value for option\n\n" "Option is format: plugin.option, example: perl.myscript.item1"), - "%O = %V", 0, MAX_ARGS, 0, NULL, weechat_cmd_setp }, - { "unalias", N_("remove an alias"), + "%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, NULL, weechat_cmd_unalias }, - { "unignore", N_("unignore IRC messages and/or hosts"), - N_("[number | [mask [[type | command] [channel [server]]]]]"), - N_(" number: # of ignore to unignore (number is displayed by list of ignore)\n" - " mask: nick or host mask to unignore\n" - " type: type of message to unignore (action, ctcp, dcc, pv)\n" - "command: IRC command\n" - "channel: name of channel for unignore\n" - " server: name of server for unignore\n\n" - "For each argument, '*' means all.\n" - "Without argument, /unignore command lists all defined ignore."), - "*|%n *|action|ctcp|dcc|pv|%I *|%c *|%s", - 0, 4, 0, weechat_cmd_unignore, NULL }, - { "upgrade", N_("upgrade WeeChat without disconnecting from servers"), + "%a", 1, 1, 0, command_unalias }, + { "upgrade", + N_("upgrade WeeChat without disconnecting from servers"), N_("[path_to_binary]"), N_("path_to_binary: path to WeeChat binary (default is current binary)\n\n" - "This command run again a WeeChat binary, so it should have been compiled " - "or installed with a package manager before running this command."), - "%f", 0, 1, 0, weechat_cmd_upgrade, NULL }, - { "uptime", N_("show WeeChat uptime"), + "This command run again a WeeChat binary, so it should have been " + "compiled or installed with a package manager before running this " + "command."), + "%f", 0, 1, 0, command_upgrade }, + { "uptime", + N_("show WeeChat uptime"), N_("[-o]"), N_("-o: send uptime on current channel as an IRC message"), - "-o", 0, 1, 0, weechat_cmd_uptime, NULL }, - { "window", N_("manage windows"), + "-o", 0, 1, 0, command_uptime }, + { "window", + N_("manage windows"), N_("[list | -1 | +1 | b# | up | down | left | right | splith [pct] " "| splitv [pct] | resize pct | merge [all]]"), N_(" list: list open windows (no parameter implies this list)\n" @@ -266,593 +201,119 @@ t_weechat_command weechat_commands[] = " right: switch to window on the right\n" "splith: split current window horizontally\n" "splitv: split current window vertically\n" - "resize: resize window size, new size is <pct> pourcentage of parent window\n" + "resize: resize window size, new size is <pct> pourcentage of parent " + "window\n" " merge: merge window with another (all = keep only one window)\n\n" "For splith and splitv, pct is a pourcentage which represents " "size of new window, computed with current window as size reference. " "For example 25 means create a new window with size = current_size / 4"), "list|-1|+1|up|down|left|right|splith|splitv|resize|merge all", - 0, 2, 0, weechat_cmd_window, NULL }, - { NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL } + 0, 2, 0, command_window }, + { NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL } }; -t_weelist *index_commands; -t_weelist *last_index_command; - - -/* - * command_index_build: build an index of commands (internal, irc and alias) - * This list will be sorted, and used for completion - */ +struct t_weelist *weechat_index_commands; +struct t_weelist *weechat_last_index_command; -void -command_index_build () -{ - int i; - - index_commands = NULL; - last_index_command = NULL; - i = 0; - while (weechat_commands[i].command_name) - { - (void) weelist_add (&index_commands, &last_index_command, - weechat_commands[i].command_name, - WEELIST_POS_SORT); - i++; - } - i = 0; - while (irc_commands[i].command_name) - { - if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg) - (void) weelist_add (&index_commands, &last_index_command, - irc_commands[i].command_name, - WEELIST_POS_SORT); - i++; - } -} - -/* - * command_index_free: remove all commands in index - */ - -void -command_index_free () -{ - while (index_commands) - { - weelist_remove (&index_commands, &last_index_command, index_commands); - } -} /* - * command_used_by_weechat: return 1 if command is used by weechat - * (weechat command, IRC command or alias) + * command_is_used: return 1 if command is used by weechat + * (WeeChat/alias command) */ int -command_used_by_weechat (char *command) +command_is_used (char *command) { - t_weechat_alias *ptr_alias; + struct alias *ptr_alias; int i; - + /* look for alias */ for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (ascii_strcasecmp (ptr_alias->alias_name, command) == 0) + if (string_strcasecmp (ptr_alias->name, command) == 0) return 1; } - + /* look for WeeChat command */ - for (i = 0; weechat_commands[i].command_name; i++) + for (i = 0; weechat_commands[i].name; i++) { - if (ascii_strcasecmp (weechat_commands[i].command_name, command) == 0) + if (string_strcasecmp (weechat_commands[i].name, command) == 0) return 1; } - - /* look for IRC command */ - for (i = 0; irc_commands[i].command_name; i++) - { - if ((ascii_strcasecmp (irc_commands[i].command_name, command) == 0) && - ((irc_commands[i].cmd_function_args) || - (irc_commands[i].cmd_function_1arg))) - return 1; - } - + /* no command/alias found */ return 0; } /* - * exec_weechat_command: executes a command (WeeChat internal or IRC) - * if only_builtin == 1, then try only WeeChat/IRC commands - * (not plugins neither aliases) - * returns: 1 if command was executed succesfully - * 0 if error (command not executed) + * command_index_build: build an index of commands (internal, irc and alias) + * This list will be sorted, and used for completion */ -int -exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string, - int only_builtin) +void +command_index_build () { - int i, rc, argc, argc2, return_code, length1, length2; - char *command, *pos, *ptr_args, *ptr_args2; - char **argv, **argv2, *alias_command; - char **commands, **ptr_cmd, **ptr_next_cmd; - char *args_replaced, *vars_replaced, *new_ptr_cmd; - char *unknown_command; - int some_args_replaced; - t_weechat_alias *ptr_alias; - - if ((!string) || (!string[0]) || (string[0] != '/')) - return 0; - - command = strdup (string); - - /* look for end of command */ - ptr_args = NULL; - - pos = &command[strlen (command) - 1]; - if (pos[0] == ' ') - { - while ((pos > command) && (pos[0] == ' ')) - pos--; - pos[1] = '\0'; - } - - pos = strchr (command, ' '); - if (pos) - { - pos[0] = '\0'; - pos++; - while (pos[0] == ' ') - pos++; - ptr_args = pos; - if (!ptr_args[0]) - ptr_args = NULL; - } + int i; -#ifdef PLUGINS - if (only_builtin) - rc = -1; - else - { - vars_replaced = alias_replace_vars (server, channel, ptr_args); - rc = plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, - (vars_replaced) ? vars_replaced : ptr_args); - if (vars_replaced) - free (vars_replaced); - } -#else - rc = -1; -#endif - switch (rc) + weechat_index_commands = NULL; + weechat_last_index_command = NULL; + i = 0; + while (weechat_commands[i].name) { - case 0: /* plugin handler KO */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s command \"%s\" failed\n"), - WEECHAT_ERROR, command + 1); - break; - case 1: /* plugin handler OK, executed */ - break; - default: /* plugin handler not found */ - argv = explode_string (ptr_args, " ", 0, &argc); - - /* look for alias */ - if (!only_builtin) - { - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - if (ascii_strcasecmp (ptr_alias->alias_name, command + 1) == 0) - { - if (ptr_alias->running == 1) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s circular reference when calling alias \"/%s\"\n"), - WEECHAT_ERROR, ptr_alias->alias_name); - } - else - { - /* an alias can contain many commands separated by ';' */ - commands = split_multi_command (ptr_alias->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 (server, channel, *ptr_cmd); - new_ptr_cmd = (vars_replaced) ? vars_replaced : *ptr_cmd; - args_replaced = alias_replace_args (new_ptr_cmd, ptr_args); - if (args_replaced) - { - some_args_replaced = 1; - if (*ptr_cmd[0] == '/') - (void) exec_weechat_command (server, channel, 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) exec_weechat_command (server, channel, 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) exec_weechat_command (server, channel, alias_command, only_builtin); - free (alias_command); - } - } - else - { - if (*ptr_cmd[0] == '/') - (void) exec_weechat_command (server, channel, 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) exec_weechat_command (server, channel, alias_command, only_builtin); - free (alias_command); - } - } - } - } - if (vars_replaced) - free (vars_replaced); - } - ptr_alias->running = 0; - free_multi_command (commands); - } - } - free_exploded_string (argv); - free (command); - return 1; - } - } - } - - /* look for WeeChat command */ - for (i = 0; weechat_commands[i].command_name; i++) - { - if (ascii_strcasecmp (weechat_commands[i].command_name, command + 1) == 0) - { - if ((argc < weechat_commands[i].min_arg) - || (argc > weechat_commands[i].max_arg)) - { - if (weechat_commands[i].min_arg == - weechat_commands[i].max_arg) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - NG_("%s wrong argument count for %s command \"%s\" " - "(expected: %d arg)\n", - "%s wrong argument count for %s command \"%s\" " - "(expected: %d args)\n", - weechat_commands[i].max_arg), - WEECHAT_ERROR, PACKAGE_NAME, - command + 1, - weechat_commands[i].max_arg); - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - NG_("%s wrong argument count for %s command \"%s\" " - "(expected: between %d and %d arg)\n", - "%s wrong argument count for %s command \"%s\" " - "(expected: between %d and %d args)\n", - weechat_commands[i].max_arg), - WEECHAT_ERROR, PACKAGE_NAME, - command + 1, - weechat_commands[i].min_arg, - weechat_commands[i].max_arg); - } - } - else - { - ptr_args2 = (ptr_args) ? (char *)gui_color_encode ((unsigned char *)ptr_args, - (weechat_commands[i].conversion - && cfg_irc_colors_send)) : NULL; - if (weechat_commands[i].cmd_function_args) - { - argv2 = explode_string ((ptr_args2) ? ptr_args2 : ptr_args, - " ", 0, &argc2); - return_code = (int) (weechat_commands[i].cmd_function_args) - (server, channel, argc2, argv2); - free_exploded_string (argv2); - } - else - return_code = (int) (weechat_commands[i].cmd_function_1arg) - (server, channel, (ptr_args2) ? ptr_args2 : ptr_args); - if (return_code < 0) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s command \"%s\" failed\n"), - WEECHAT_ERROR, command + 1); - } - if (ptr_args2) - free (ptr_args2); - } - free_exploded_string (argv); - free (command); - return 1; - } - } - - /* look for IRC command */ - for (i = 0; irc_commands[i].command_name; i++) - { - if ((ascii_strcasecmp (irc_commands[i].command_name, command + 1) == 0) && - ((irc_commands[i].cmd_function_args) || - (irc_commands[i].cmd_function_1arg))) - { - if ((argc < irc_commands[i].min_arg) - || (argc > irc_commands[i].max_arg)) - { - if (irc_commands[i].min_arg == irc_commands[i].max_arg) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf - (NULL, - NG_("%s wrong argument count for IRC command \"%s\" " - "(expected: %d arg)\n", - "%s wrong argument count for IRC command \"%s\" " - "(expected: %d args)\n", - irc_commands[i].max_arg), - WEECHAT_ERROR, - command + 1, - irc_commands[i].max_arg); - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf - (NULL, - NG_("%s wrong argument count for IRC command \"%s\" " - "(expected: between %d and %d arg)\n", - "%s wrong argument count for IRC command \"%s\" " - "(expected: between %d and %d args)\n", - irc_commands[i].max_arg), - WEECHAT_ERROR, - command + 1, - irc_commands[i].min_arg, irc_commands[i].max_arg); - } - } - else - { - if ((irc_commands[i].needs_connection) && - ((!server) || (!server->is_connected))) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s command \"%s\" needs a server connection!\n"), - WEECHAT_ERROR, irc_commands[i].command_name); - free (command); - return 0; - } - if (channel && channel->dcc_chat) - { - irc_display_prefix (server, channel->buffer, GUI_PREFIX_ERROR); - gui_printf (channel->buffer, - _("%s command \"%s\" can not be " - "executed on DCC CHAT buffer\n"), - WEECHAT_ERROR, - irc_commands[i].command_name); - free (command); - return 0; - } - ptr_args2 = (ptr_args) ? (char *)gui_color_encode ((unsigned char *)ptr_args, - (irc_commands[i].conversion - && cfg_irc_colors_send)) : NULL; - if (irc_commands[i].cmd_function_args) - { - argv2 = explode_string ((ptr_args2) ? ptr_args2 : ptr_args, - " ", 0, &argc2); - return_code = (int) (irc_commands[i].cmd_function_args) - (server, channel, argc2, argv2); - free_exploded_string (argv2); - } - else - return_code = (int) (irc_commands[i].cmd_function_1arg) - (server, channel, (ptr_args2) ? ptr_args2 : ptr_args); - if (return_code < 0) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s command \"%s\" failed\n"), - WEECHAT_ERROR, command + 1); - } - if (ptr_args2) - free (ptr_args2); - } - free_exploded_string (argv); - free (command); - return 1; - } - } - - /* should we send unknown command to IRC server? */ - if (cfg_irc_send_unknown_commands) - { - if (ptr_args) - unknown_command = (char *)malloc (strlen (command + 1) + 1 + strlen (ptr_args) + 1); - else - unknown_command = (char *)malloc (strlen (command + 1) + 1); - - if (unknown_command) - { - strcpy (unknown_command, command + 1); - if (ptr_args) - { - strcat (unknown_command, " "); - strcat (unknown_command, ptr_args); - } - irc_send_cmd_quote (server, channel, unknown_command); - free (unknown_command); - } - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown command \"%s\" (type /help for help). " - "To send unknown commands to IRC server, enable option " - "irc_send_unknown_commands.\n"), - WEECHAT_ERROR, - command + 1); - } - - free_exploded_string (argv); + (void) weelist_add (&weechat_index_commands, + &weechat_last_index_command, + weechat_commands[i].name, + WEELIST_POS_SORT); + i++; } - free (command); - return 0; } /* - * user_message_display: display user message + * command_index_free: remove all commands in index */ void -user_message_display (t_irc_server *server, t_gui_buffer *buffer, char *text) +command_index_free () { - t_irc_nick *ptr_nick; - - if ((GUI_CHANNEL(buffer)->type == IRC_CHANNEL_TYPE_PRIVATE) - || (GUI_CHANNEL(buffer)->type == IRC_CHANNEL_TYPE_DCC_CHAT)) + while (weechat_index_commands) { - irc_display_nick (buffer, NULL, server->nick, - GUI_MSG_TYPE_NICK, 1, GUI_COLOR_WIN_NICK_SELF, 0); - gui_printf_type (buffer, - GUI_MSG_TYPE_MSG, - "%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - text); - } - else - { - ptr_nick = irc_nick_search (GUI_CHANNEL(buffer), server->nick); - if (ptr_nick) - { - irc_display_nick (buffer, ptr_nick, NULL, - GUI_MSG_TYPE_NICK, 1, -1, 0); - gui_printf_type (buffer, - GUI_MSG_TYPE_MSG, - "%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - text); - } - else - { - irc_display_prefix (server, server->buffer, GUI_PREFIX_ERROR); - gui_printf (server->buffer, - _("%s cannot find nick for sending message\n"), - WEECHAT_ERROR); - } + weelist_remove (&weechat_index_commands, + &weechat_last_index_command, + weechat_index_commands); } } /* - * user_message: send a PRIVMSG message, and split it if > 512 bytes + * command_index_add: add command to commands index */ void -user_message (t_irc_server *server, t_gui_buffer *buffer, char *text) +command_index_add (char *command) { - int max_length; - char *pos, *pos_next, *pos_max, *next, saved_char, *last_space; + if (!weelist_search (weechat_index_commands, command)) + weelist_add (&weechat_index_commands, &weechat_last_index_command, + command, WEELIST_POS_SORT); +} - if (!text || !text[0]) - return; - - if (!server->is_connected) - { - irc_display_prefix (server, buffer, GUI_PREFIX_ERROR); - gui_printf (buffer, _("%s you are not connected to server\n"), - WEECHAT_ERROR); - return; - } - - next = NULL; - last_space = NULL; - saved_char = '\0'; - - max_length = 512 - 16 - 65 - 10 - strlen (server->nick) - - strlen (GUI_CHANNEL(buffer)->name); - - if (max_length > 0) - { - if ((int)strlen (text) > max_length) - { - pos = text; - pos_max = text + max_length; - while (pos && pos[0]) - { - if (pos[0] == ' ') - last_space = pos; - pos_next = utf8_next_char (pos); - if (pos_next > pos_max) - break; - pos = pos_next; - } - if (last_space && (last_space < pos)) - pos = last_space + 1; - saved_char = pos[0]; - pos[0] = '\0'; - next = pos; - } - } - - irc_server_sendf_queued (server, "PRIVMSG %s :%s", - GUI_CHANNEL(buffer)->name, text); - user_message_display (server, buffer, text); - - if (next) - { - next[0] = saved_char; - user_message (server, buffer, next); - } +/* + * command_index_remove: remove command from commands index + */ + +void +command_index_remove (char *command) +{ + if (!command_is_used (command)) + weelist_remove (&weechat_index_commands, &weechat_last_index_command, + weelist_search (weechat_index_commands, command)); } /* - * is_command: return 1 if line is a command, 0 otherwise + * command_is_command: return 1 if line is a command, 0 otherwise */ int -is_command (char *line) +command_is_command (char *line) { char *pos_slash, *pos_space; @@ -867,122 +328,45 @@ is_command (char *line) } /* - * user_command: interprets user command (if beginning with '/') - * any other text is sent to the server, if connected + * command_print_stdout: print list of commands on standard output */ void -user_command (t_irc_server *server, t_irc_channel *channel, char *command, int only_builtin) +command_print_stdout (struct command *commands) { - t_gui_buffer *buffer; - char *new_cmd, *ptr_cmd, *pos; - char *command_with_colors; - - if ((!command) || (!command[0]) || (command[0] == '\r') || (command[0] == '\n')) - return; - -#ifdef PLUGINS - new_cmd = plugin_modifier_exec (PLUGIN_MODIFIER_IRC_USER, - (server) ? server->name : "", - command); -#else - new_cmd = NULL; -#endif - - /* no changes in new command */ - if (new_cmd && (strcmp (command, new_cmd) == 0)) - { - free (new_cmd); - new_cmd = NULL; - } + int i; - /* message not dropped? */ - if (!new_cmd || new_cmd[0]) + for (i = 0; commands[i].name; i++) { - /* use new command (returned by plugin) */ - ptr_cmd = (new_cmd) ? new_cmd : command; - - while (ptr_cmd && ptr_cmd[0]) - { - pos = strchr (ptr_cmd, '\n'); - if (pos) - pos[0] = '\0'; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - if (is_command (ptr_cmd)) - { - /* WeeChat internal command (or IRC command) */ - (void) exec_weechat_command (server, channel, ptr_cmd, only_builtin); - } - else - { - if ((ptr_cmd[0] == '/') && (ptr_cmd[1] == '/')) - ptr_cmd++; - - if (server && (!GUI_BUFFER_IS_SERVER(buffer))) - { - command_with_colors = (char *)gui_color_encode ((unsigned char *)ptr_cmd, - cfg_irc_colors_send); - - if (GUI_CHANNEL(buffer)->dcc_chat) - { - if (((t_irc_dcc *)(GUI_CHANNEL(buffer)->dcc_chat))->sock < 0) - { - irc_display_prefix (server, buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (buffer, "%s DCC CHAT is closed\n", - WEECHAT_ERROR); - } - else - { - irc_dcc_chat_sendf ((t_irc_dcc *)(GUI_CHANNEL(buffer)->dcc_chat), - "%s\r\n", - (command_with_colors) ? command_with_colors : ptr_cmd); - user_message_display (server, buffer, - (command_with_colors) ? - command_with_colors : ptr_cmd); - } - } - else - user_message (server, buffer, - (command_with_colors) ? command_with_colors : ptr_cmd); - - if (command_with_colors) - free (command_with_colors); - } - else - { - irc_display_prefix (NULL, (server) ? server->buffer : NULL, GUI_PREFIX_ERROR); - gui_printf_nolog ((server) ? server->buffer : NULL, - _("This window is not a channel!\n")); - } - } - - if (pos) - { - pos[0] = '\n'; - ptr_cmd = pos + 1; - } - else - ptr_cmd = NULL; - } + string_iconv_fprintf (stdout, "* %s", commands[i].name); + if (commands[i].arguments && + commands[i].arguments[0]) + string_iconv_fprintf (stdout, " %s\n\n", _(commands[i].arguments)); + else + string_iconv_fprintf (stdout, "\n\n"); + string_iconv_fprintf (stdout, "%s\n\n", _(commands[i].description)); + if (commands[i].arguments_description && + commands[i].arguments_description[0]) + string_iconv_fprintf (stdout, "%s\n\n", + _(commands[i].arguments_description)); } } /* - * weechat_cmd_alias: display or create alias + * command_alias: display or create alias */ int -weechat_cmd_alias (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_alias (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { char *pos; - t_weechat_alias *ptr_alias; - + struct alias *ptr_alias; + /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) argc; + (void) argv; if (arguments && arguments[0]) { @@ -1001,26 +385,32 @@ weechat_cmd_alias (t_irc_server *server, t_irc_channel *channel, pos++; if (!pos[0]) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s missing arguments for \"%s\" command\n"), - WEECHAT_ERROR, "alias"); + gui_chat_printf (NULL, + _("%s%s missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "alias"); return -1; } if (!alias_new (arguments, pos)) return -1; - if (weelist_add (&index_commands, &last_index_command, arguments, + if (weelist_add (&weechat_index_commands, + &weechat_last_index_command, + arguments, WEELIST_POS_SORT)) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Alias \"%s\" => \"%s\" created\n"), - arguments, pos); + gui_chat_printf (NULL, + _("%sAlias \"%s\" => \"%s\" created"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + arguments, pos); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("Failed to create alias \"%s\" => \"%s\" " - "(not enough memory)\n"), - arguments, pos); + gui_chat_printf (NULL, + _("%sFailed to create alias \"%s\" => " + "\"%s\" (not enough memory)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + arguments, pos); return -1; } } @@ -1029,19 +419,18 @@ weechat_cmd_alias (t_irc_server *server, t_irc_channel *channel, ptr_alias = alias_search (arguments); if (ptr_alias) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Alias:\n")); - gui_printf (NULL, " %s %s=>%s %s\n", - ptr_alias->alias_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_alias->alias_command); + 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 - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No alias found.\n")); - } + gui_chat_printf (NULL, + _("%sNo alias found."), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); } } else @@ -1049,141 +438,143 @@ weechat_cmd_alias (t_irc_server *server, t_irc_channel *channel, /* List all aliases */ if (weechat_alias) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("List of aliases:\n")); + 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_printf (NULL, " %s %s=>%s %s\n", - ptr_alias->alias_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_alias->alias_command); + 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 - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No alias defined.\n")); - } + gui_chat_printf (NULL, + _("%sNo alias defined."), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); } return 0; } /* - * weechat_cmd_buffer_display_info: display info about a buffer + * command_buffer_display_info: display info about a buffer */ void -weechat_cmd_buffer_display_info (t_gui_buffer *buffer) +command_buffer_display_info (struct t_gui_buffer *buffer) { - switch (buffer->type) + /* TODO: write again this function */ + (void) buffer; +/* switch (buffer->type) { case GUI_BUFFER_TYPE_STANDARD: if (GUI_BUFFER_IS_SERVER(buffer)) { if (GUI_SERVER(buffer)) - gui_printf (NULL, _("%sServer: %s%s\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name); + gui_chat_printf (NULL, _("%sServer: %s%s"), + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), + GUI_SERVER(buffer)->name); else - gui_printf (NULL, _("%snot connected\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, _("%snot connected"), + GUI_COLOR(GUI_COLOR_CHAT)); } else if (GUI_BUFFER_IS_CHANNEL (buffer)) - gui_printf (NULL, _("%sChannel: %s%s %s(server: %s%s%s)\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - GUI_CHANNEL(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, _("%sChannel: %s%s %s(server: %s%s%s)"), + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + GUI_CHANNEL(buffer)->name, + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), + GUI_SERVER(buffer)->name, + GUI_COLOR(GUI_COLOR_CHAT)); else if (GUI_BUFFER_IS_PRIVATE (buffer)) - gui_printf (NULL, _("%sPrivate with: %s%s %s(server: %s%s%s)\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), - GUI_CHANNEL(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, _("%sPrivate with: %s%s %s(server: %s%s%s)"), + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_NICK), + GUI_CHANNEL(buffer)->name, + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), + GUI_SERVER(buffer)->name, + GUI_COLOR(GUI_COLOR_CHAT)); else - gui_printf (NULL, _("%sunknown\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, _("%sunknown"), + GUI_COLOR(GUI_COLOR_CHAT)); break; case GUI_BUFFER_TYPE_DCC: - gui_printf (NULL, "%sDCC\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL)); + gui_chat_printf (NULL, "%sDCC", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER)); break; case GUI_BUFFER_TYPE_RAW_DATA: - gui_printf (NULL, _("%sraw IRC data\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL)); + gui_chat_printf (NULL, _("%sraw IRC data"), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER)); break; default: - gui_printf (NULL, _("%sunknown\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, _("%sunknown"), + GUI_COLOR(GUI_COLOR_CHAT)); break; - } + }*/ } /* - * weechat_cmd_buffer: manage buffers + * command_buffer: manage buffers */ int -weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_buffer (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_window *window; - t_gui_buffer *buffer, *ptr_buffer; - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; + struct t_gui_buffer *ptr_buffer; long number; - char *error, *pos, **argv; - int argc, target_buffer, count; - - gui_buffer_find_context (server, channel, &window, &buffer); - - argv = explode_string (arguments, " ", 0, &argc); + char *error; + int target_buffer; + + /* make C compiler happy */ + (void) arguments; - if ((argc == 0) || ((argc == 1) && (ascii_strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) { /* list open buffers */ - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Open buffers:\n")); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Open buffers:")); - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) { - gui_printf (NULL, "%s[%s%d%s] ", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_buffer->number, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - weechat_cmd_buffer_display_info (ptr_buffer); + gui_chat_printf (NULL, + "%s[%s%d%s] ", + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + ptr_buffer->number, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + command_buffer_display_info (ptr_buffer); } } else { - if (ascii_strcasecmp (argv[0], "move") == 0) + if (string_strcasecmp (argv[0], "move") == 0) { /* move buffer to another number in the list */ if (argc < 2) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s missing arguments for \"%s\" command\n"), - WEECHAT_ERROR, "buffer"); - free_exploded_string (argv); + gui_chat_printf (NULL, + _("%s%s missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "buffer"); return -1; } error = NULL; - number = strtol (((argv[1][0] == '+') || (argv[1][0] == '-')) ? argv[1] + 1 : argv[1], + number = strtol (((argv[1][0] == '+') || (argv[1][0] == '-')) ? + argv[1] + 1 : argv[1], &error, 10); - if ((error) && (error[0] == '\0')) + if (error && (error[0] == '\0')) { if (argv[1][0] == '+') gui_buffer_move_to_number (buffer, @@ -1197,239 +588,100 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, else { /* invalid number */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect buffer number\n"), - WEECHAT_ERROR); - free_exploded_string (argv); - return -1; - } - } - else if (ascii_strcasecmp (argv[0], "close") == 0) - { - /* close buffer (server or channel/private) */ - - if ((!buffer->next_buffer) - && (buffer == gui_buffers) - && ((!buffer->all_servers) - || (!GUI_SERVER(buffer)))) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s can not close the single buffer\n"), - WEECHAT_ERROR); - free_exploded_string (argv); + gui_chat_printf (NULL, + _("%s%s incorrect buffer number"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR); return -1; } - if (GUI_BUFFER_IS_SERVER(buffer)) - { - if (GUI_SERVER(buffer)) - { - if (GUI_SERVER(buffer)->channels) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s can not close server buffer while channels " - "are open\n"), - WEECHAT_ERROR); - free_exploded_string (argv); - return -1; - } - irc_server_disconnect (GUI_SERVER(buffer), 0); - ptr_server = GUI_SERVER(buffer); - if (!buffer->all_servers) - { - gui_buffer_free (buffer, 1); - ptr_server->buffer = NULL; - } - else - { - ptr_server->buffer = NULL; - buffer->server = NULL; - gui_window_switch_server (window); - } - gui_status_draw (gui_current_window->buffer, 1); - gui_input_draw (gui_current_window->buffer, 1); - } - } - else - { - if (GUI_CHANNEL(buffer) - && (GUI_CHANNEL(buffer)->type == IRC_CHANNEL_TYPE_DCC_CHAT)) - { - ptr_server = GUI_SERVER(buffer); - ptr_channel = GUI_CHANNEL(buffer); - gui_buffer_free (ptr_channel->buffer, 1); - irc_channel_free (ptr_server, ptr_channel); - gui_status_draw (gui_current_window->buffer, 1); - gui_input_draw (gui_current_window->buffer, 1); - } - else - { - if (GUI_SERVER(buffer)) - { - if (GUI_SERVER(buffer)->is_connected - && GUI_CHANNEL(buffer) - && GUI_CHANNEL(buffer)->nicks) - { - pos = strstr (arguments, "close "); - if (pos) - pos += 6; - GUI_CHANNEL(buffer)->close = 1; - irc_send_cmd_part (GUI_SERVER(buffer), - GUI_CHANNEL(buffer), - pos); - } - else - { - ptr_channel = GUI_CHANNEL(buffer); - ptr_server = GUI_SERVER(buffer); - gui_buffer_free (buffer, 1); - if (ptr_channel) - irc_channel_free (ptr_server, ptr_channel); - } - } - else - gui_buffer_free (buffer, 1); - gui_status_draw (gui_current_window->buffer, 1); - } - } } - else if (ascii_strcasecmp (argv[0], "notify") == 0) + else if (string_strcasecmp (argv[0], "notify") == 0) { if (argc < 2) { - gui_printf (NULL, "\n"); - - /* display default notify level for all connected servers */ - gui_printf (NULL, _("Default notify levels for servers:")); - count = 0; - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->buffer) - { - gui_printf (NULL, " %s:%d", - ptr_server->name, - irc_server_get_default_notify_level (ptr_server)); - count++; - } - } - if (count == 0) - gui_printf (NULL, " -"); - gui_printf (NULL, "\n"); - /* display notify level for all buffers */ - gui_printf (NULL, _("Notify levels:")); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Notify levels:")); for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { - gui_printf (NULL, " %d.%s:", - ptr_buffer->number, - (ptr_buffer->type == GUI_BUFFER_TYPE_DCC) ? "DCC" : - ((ptr_buffer->type == GUI_BUFFER_TYPE_RAW_DATA) ? _("Raw IRC data") : - ((GUI_BUFFER_IS_SERVER(ptr_buffer) && GUI_SERVER(ptr_buffer)) ? GUI_SERVER(ptr_buffer)->name : - ((GUI_CHANNEL(ptr_buffer)) ? (GUI_CHANNEL(ptr_buffer)->name) : "-")))); - if ((!GUI_BUFFER_IS_CHANNEL(ptr_buffer)) - && (!GUI_BUFFER_IS_PRIVATE(ptr_buffer))) - gui_printf (NULL, "-"); - else - gui_printf (NULL, "%d", ptr_buffer->notify_level); + gui_chat_printf (NULL, + " %d.%s: %d", + ptr_buffer->number, + ptr_buffer->name, + ptr_buffer->notify_level); } - gui_printf (NULL, "\n"); + gui_chat_printf (NULL, ""); } else { /* set notify level for buffer */ error = NULL; number = strtol (argv[1], &error, 10); - if ((error) && (error[0] == '\0')) + if (error && (error[0] == '\0')) { - if ((number < GUI_NOTIFY_LEVEL_MIN) || (number > GUI_NOTIFY_LEVEL_MAX)) + if ((number < GUI_BUFFER_NOTIFY_LEVEL_MIN) + || (number > GUI_BUFFER_NOTIFY_LEVEL_MAX)) { /* invalid highlight level */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect notify level (must be between %d and %d)\n"), - WEECHAT_ERROR, GUI_NOTIFY_LEVEL_MIN, GUI_NOTIFY_LEVEL_MAX); - free_exploded_string (argv); + gui_chat_printf (NULL, + _("%s%s incorrect notify level " + "(must be between %d and %d)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, + GUI_BUFFER_NOTIFY_LEVEL_MIN, + GUI_BUFFER_NOTIFY_LEVEL_MAX); return -1; } - if (!GUI_SERVER(buffer) - || ((!GUI_BUFFER_IS_SERVER(buffer)) - && (!GUI_BUFFER_IS_CHANNEL(buffer)) - && (!GUI_BUFFER_IS_PRIVATE(buffer)))) - { - /* invalid buffer type (only ok on server, channel or private) */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s incorrect buffer for notify " - "(must be server, channel or private)\n"), - WEECHAT_ERROR); - free_exploded_string (argv); - return -1; - } - if (GUI_BUFFER_IS_SERVER(buffer)) - { - irc_server_set_default_notify_level (GUI_SERVER(buffer), - number); - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("New default notify level for server %s%s%s: %s%d %s"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - number, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - } - else - { - irc_channel_set_notify_level (GUI_SERVER(buffer), - GUI_CHANNEL(buffer), - number); - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("New notify level for %s%s%s: %s%d %s"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - GUI_CHANNEL(buffer)->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - number, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - } + gui_chat_printf (NULL, + _("%sNew notify level for %s%s%s: " + "%d %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + buffer->name, + GUI_COLOR(GUI_COLOR_CHAT), + number, + GUI_COLOR(GUI_COLOR_CHAT)); switch (number) { case 0: - gui_printf (NULL, _("(hotlist: never)\n")); + gui_chat_printf (NULL, + _("(hotlist: never)")); break; case 1: - gui_printf (NULL, _("(hotlist: highlights)\n")); + gui_chat_printf (NULL, + _("(hotlist: highlights)")); break; case 2: - gui_printf (NULL, _("(hotlist: highlights + messages)\n")); + gui_chat_printf (NULL, + _("(hotlist: highlights + " + "messages)")); break; case 3: - gui_printf (NULL, _("(hotlist: highlights + messages + join/part (all))\n")); + gui_chat_printf (NULL, + _("(hotlist: highlights + " + "messages + join/part " + "(all))")); break; default: - gui_printf (NULL, "\n"); + gui_chat_printf (NULL, ""); break; } - config_change_notify_levels (); } else { /* invalid number */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect notify level (must be between %d and %d)\n"), - WEECHAT_ERROR, GUI_NOTIFY_LEVEL_MIN, GUI_NOTIFY_LEVEL_MAX); - free_exploded_string (argv); + gui_chat_printf (NULL, + _("%s%s incorrect notify level (must " + "be between %d and %d)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, + GUI_BUFFER_NOTIFY_LEVEL_MIN, + GUI_BUFFER_NOTIFY_LEVEL_MAX); return -1; } } } - else if (ascii_strcasecmp (argv[0], "scroll") == 0) - { - if (argc >= 2) - gui_buffer_scroll (window, argv[1]); - } else { /* jump to buffer by number or server/channel name */ @@ -1439,13 +691,13 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, /* relative jump '-' */ error = NULL; number = strtol (argv[0] + 1, &error, 10); - if ((error) && (error[0] == '\0')) + if (error && (error[0] == '\0')) { target_buffer = buffer->number - (int) number; if (target_buffer < 1) target_buffer = (last_gui_buffer) ? last_gui_buffer->number + target_buffer : 1; - gui_buffer_switch_by_number (window, + gui_buffer_switch_by_number (gui_current_window, target_buffer); } } @@ -1454,38 +706,41 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, /* relative jump '+' */ error = NULL; number = strtol (argv[0] + 1, &error, 10); - if ((error) && (error[0] == '\0')) + if (error && (error[0] == '\0')) { target_buffer = buffer->number + (int) number; if (last_gui_buffer && target_buffer > last_gui_buffer->number) target_buffer -= last_gui_buffer->number; - gui_buffer_switch_by_number (window, + gui_buffer_switch_by_number (gui_current_window, target_buffer); } } else { - /* absolute jump by number, or by server/channel name */ + /* absolute jump by number, or by category/name */ error = NULL; number = strtol (argv[0], &error, 10); - if ((error) && (error[0] == '\0')) - gui_buffer_switch_by_number (window, (int) number); + if (error && (error[0] == '\0')) + gui_buffer_switch_by_number (gui_current_window, + (int) number); else { ptr_buffer = NULL; if (argc > 1) - ptr_buffer = gui_buffer_search (argv[0], argv[1]); + ptr_buffer = gui_buffer_search_by_category_name (argv[0], + argv[1]); else { - ptr_server = irc_server_search (argv[0]); - if (ptr_server) - ptr_buffer = gui_buffer_search (argv[0], NULL); - else - ptr_buffer = gui_buffer_search (NULL, argv[0]); + ptr_buffer = gui_buffer_search_by_category_name (argv[0], + NULL); + if (!ptr_buffer) + ptr_buffer = gui_buffer_search_by_category_name (NULL, + argv[0]); } if (ptr_buffer) { - gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_switch_to_buffer (gui_current_window, + ptr_buffer); gui_window_redraw_buffer (ptr_buffer); } } @@ -1493,25 +748,28 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, } } - free_exploded_string (argv); return 0; } /* - * weechat_cmd_builtin: launch WeeChat/IRC builtin command + * command_builtin: launch WeeChat/IRC builtin command */ int -weechat_cmd_builtin (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_builtin (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { char *command; int length; + /* make C compiler happy */ + (void) argc; + (void) argv; + if (arguments && arguments[0]) { if (arguments[0] == '/') - user_command (server, channel, arguments, 1); + input_data (buffer, arguments, 1); else { length = strlen (arguments) + 2; @@ -1519,7 +777,7 @@ weechat_cmd_builtin (t_irc_server *server, t_irc_channel *channel, if (command) { snprintf (command, length, "/%s", arguments); - user_command (server, channel, command, 1); + input_data (buffer, command, 1); free (command); } } @@ -1528,21 +786,24 @@ weechat_cmd_builtin (t_irc_server *server, t_irc_channel *channel, } /* - * weechat_cmd_clear: display or create alias + * command_clear: display or create alias */ int -weechat_cmd_clear (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_clear (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; + struct t_gui_buffer *ptr_buffer; char *error; long number; int i; + /* make C compiler happy */ + (void) arguments; + if (argc > 0) { - if (ascii_strcasecmp (argv[0], "-all") == 0) + if (string_strcasecmp (argv[0], "-all") == 0) gui_buffer_clear_all (); else { @@ -1550,395 +811,120 @@ weechat_cmd_clear (t_irc_server *server, t_irc_channel *channel, { error = NULL; number = strtol (argv[i], &error, 10); - if ((error) && (error[0] == '\0')) + if (error && (error[0] == '\0')) { - buffer = gui_buffer_search_by_number (number); - if (!buffer) + ptr_buffer = gui_buffer_search_by_number (number); + if (!ptr_buffer) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s buffer number \"%s\" not found for \"%s\" command\n"), - WEECHAT_ERROR, argv[i], "clear"); + gui_chat_printf (NULL, + _("%s%s buffer number \"%s\" not " + "found for \"%s\" command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, argv[i], + "clear"); return -1; } - gui_buffer_clear (buffer); + gui_buffer_clear (ptr_buffer); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "clear"); + gui_chat_printf (NULL, + _("%s%s unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "clear"); return -1; } } } } else - { - gui_buffer_find_context (server, channel, NULL, &buffer); gui_buffer_clear (buffer); - } - - return 0; -} - -/* - * weechat_cmd_connect_one_server: connect to one server - * return 0 if error, 1 if ok - */ - -int -weechat_cmd_connect_one_server (t_gui_window *window, t_irc_server *server, - int no_join) -{ - if (server->is_connected) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s already connected to server \"%s\"!\n"), - WEECHAT_ERROR, server->name); - return 0; - } - if (server->child_pid > 0) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s currently connecting to server \"%s\"!\n"), - WEECHAT_ERROR, server->name); - return 0; - } - if (!server->buffer) - { - if (!gui_buffer_new (window, server, NULL, - GUI_BUFFER_TYPE_STANDARD, 1)) - return 0; - } - if (irc_server_connect (server, no_join)) - { - server->reconnect_start = 0; - server->reconnect_join = (server->channels) ? 1 : 0; - gui_status_draw (server->buffer, 1); - } - - /* connect ok */ - return 1; -} - -/* - * weechat_cmd_connect: connect to server(s) - */ - -int -weechat_cmd_connect (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) -{ - t_gui_window *window; - t_gui_buffer *buffer; - t_irc_server *ptr_server, server_tmp; - int i, nb_connect, connect_ok, all_servers, no_join, port, ipv6, ssl; - char *error; - long number; - - gui_buffer_find_context (server, channel, &window, &buffer); - - nb_connect = 0; - connect_ok = 1; - port = IRC_DEFAULT_PORT; - ipv6 = 0; - ssl = 0; - - all_servers = 0; - no_join = 0; - for (i = 0; i < argc; i++) - { - if (ascii_strcasecmp (argv[i], "-all") == 0) - all_servers = 1; - if (ascii_strcasecmp (argv[i], "-nojoin") == 0) - no_join = 1; - if (ascii_strcasecmp (argv[i], "-ipv6") == 0) - ipv6 = 1; - if (ascii_strcasecmp (argv[i], "-ssl") == 0) - ssl = 1; - if (ascii_strcasecmp (argv[i], "-port") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-port"); - return -1; - } - error = NULL; - number = strtol (argv[++i], &error, 10); - if ((error) && (error[0] == '\0')) - port = number; - } - } - - if (all_servers) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - nb_connect++; - if (!ptr_server->is_connected && (ptr_server->child_pid == 0)) - { - if (!weechat_cmd_connect_one_server (window, ptr_server, - no_join)) - connect_ok = 0; - } - } - } - else - { - for (i = 0; i < argc; i++) - { - if (argv[i][0] != '-') - { - nb_connect++; - ptr_server = irc_server_search (argv[i]); - if (ptr_server) - { - if (!weechat_cmd_connect_one_server (window, ptr_server, - no_join)) - connect_ok = 0; - } - else - { - irc_server_init (&server_tmp); - server_tmp.name = strdup (argv[i]); - server_tmp.address = strdup (argv[i]); - server_tmp.port = port; - server_tmp.ipv6 = ipv6; - server_tmp.ssl = ssl; - ptr_server = irc_server_new (server_tmp.name, - server_tmp.autoconnect, - server_tmp.autoreconnect, - server_tmp.autoreconnect_delay, - 1, /* temp server */ - server_tmp.address, - server_tmp.port, - server_tmp.ipv6, - server_tmp.ssl, - server_tmp.password, - server_tmp.nick1, - server_tmp.nick2, - server_tmp.nick3, - server_tmp.username, - server_tmp.realname, - server_tmp.hostname, - server_tmp.command, - 1, /* command_delay */ - server_tmp.autojoin, - 1, /* autorejoin */ - NULL); - if (ptr_server) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s created (temporary server, NOT SAVED!)\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - server_tmp.name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - if (!weechat_cmd_connect_one_server (window, ptr_server, 0)) - connect_ok = 0; - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unable to create server \"%s\"\n"), - WEECHAT_ERROR, argv[i]); - } - } - } - else - { - if (ascii_strcasecmp (argv[i], "-port") == 0) - i++; - } - } - } - - if (nb_connect == 0) - connect_ok = weechat_cmd_connect_one_server (window, server, no_join); - - if (!connect_ok) - return -1; - - return 0; -} - -/* - * weechat_cmd_dcc: DCC control (file or chat) - */ - -int -weechat_cmd_dcc (t_irc_server *server, t_irc_channel *channel, - char *arguments) -{ - t_gui_buffer *buffer; - char *pos_nick, *pos_file; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - /* DCC SEND file */ - if (strncasecmp (arguments, "send", 4) == 0) - { - pos_nick = strchr (arguments, ' '); - if (!pos_nick) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (server->buffer, - _("%s wrong argument count for \"%s\" command\n"), - WEECHAT_ERROR, "dcc send"); - return -1; - } - while (pos_nick[0] == ' ') - pos_nick++; - - pos_file = strchr (pos_nick, ' '); - if (!pos_file) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (server->buffer, - _("%s wrong argument count for \"%s\" command\n"), - WEECHAT_ERROR, "dcc send"); - return -1; - } - pos_file[0] = '\0'; - pos_file++; - while (pos_file[0] == ' ') - pos_file++; - - irc_dcc_send_request (server, IRC_DCC_FILE_SEND, pos_nick, pos_file); - } - /* DCC CHAT */ - else if (strncasecmp (arguments, "chat", 4) == 0) - { - pos_nick = strchr (arguments, ' '); - if (!pos_nick) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (server->buffer, - _("%s wrong argument count for \"%s\" command\n"), - WEECHAT_ERROR, "dcc chat"); - return -1; - } - while (pos_nick[0] == ' ') - pos_nick++; - - irc_dcc_send_request (server, IRC_DCC_CHAT_SEND, pos_nick, NULL); - } - /* close DCC CHAT */ - else if (ascii_strcasecmp (arguments, "close") == 0) - { - if (GUI_BUFFER_IS_PRIVATE(buffer) && - GUI_CHANNEL(buffer)->dcc_chat) - { - irc_dcc_close ((t_irc_dcc *)(GUI_CHANNEL(buffer)->dcc_chat), - IRC_DCC_ABORTED); - irc_dcc_redraw (1); - } - } - /* unknown DCC action */ - else - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (server->buffer, - _("%s wrong arguments for \"%s\" command\n"), - WEECHAT_ERROR, "dcc"); - return -1; - } return 0; } /* - * weechat_cmd_debug_display_windows: display tree of windows + * command_debug_display_windows: display tree of windows */ void -weechat_cmd_debug_display_windows (t_gui_window_tree *tree, int indent) +command_debug_display_windows (struct t_gui_window_tree *tree, int indent) { - int i; - if (tree) { - for (i = 0; i < indent; i++) - gui_printf_nolog (NULL, " "); - if (tree->window) { /* leaf */ - gui_printf_nolog (NULL, "leaf: %X (parent:%X), win=%X, child1=%X, child2=%X, %d,%d %dx%d, %d%%x%d%%\n", - tree, tree->parent_node, tree->window, - tree->child1, tree->child2, - tree->window->win_x, tree->window->win_y, - tree->window->win_width, tree->window->win_height, - tree->window->win_width_pct, tree->window->win_height_pct); + gui_chat_printf (NULL, + "leaf: %X (parent:%X), win=%X, child1=%X, " + "child2=%X, %d,%d %dx%d, %d%%x%d%%", + tree, tree->parent_node, tree->window, + tree->child1, tree->child2, + tree->window->win_x, tree->window->win_y, + tree->window->win_width, tree->window->win_height, + tree->window->win_width_pct, + tree->window->win_height_pct); } else { /* node */ - gui_printf_nolog (NULL, "node: %X (parent:%X), win=%X, child1=%X, child2=%X)\n", - tree, tree->parent_node, tree->window, - tree->child1, tree->child2); + gui_chat_printf (NULL, + "node: %X (parent:%X), win=%X, child1=%X, " + "child2=%X)", + tree, tree->parent_node, tree->window, + tree->child1, tree->child2); } if (tree->child1) - weechat_cmd_debug_display_windows (tree->child1, indent + 1); + command_debug_display_windows (tree->child1, indent + 1); if (tree->child2) - weechat_cmd_debug_display_windows (tree->child2, indent + 1); + command_debug_display_windows (tree->child2, indent + 1); } } /* - * weechat_cmd_debug: print debug messages + * command_debug: print debug messages */ int -weechat_cmd_debug (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_debug (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; - /* make C compiler happy */ - (void) server; - (void) channel; - - gui_buffer_find_context (server, channel, NULL, &buffer); + (void) buffer; + (void) arguments; if (argc != 1) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s wrong argument count for \"%s\" command\n"), - WEECHAT_ERROR, "debug"); + gui_chat_printf (NULL, + _("%s%s wrong argument count for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "debug"); return -1; } - if (ascii_strcasecmp (argv[0], "dump") == 0) + if (string_strcasecmp (argv[0], "dump") == 0) { weechat_dump (0); } - else if (ascii_strcasecmp (argv[0], "buffer") == 0) + else if (string_strcasecmp (argv[0], "buffer") == 0) { gui_buffer_dump_hexa (buffer); } - else if (ascii_strcasecmp (argv[0], "windows") == 0) + else if (string_strcasecmp (argv[0], "windows") == 0) { - gui_printf_nolog (NULL, "\n"); - gui_printf_nolog (NULL, "DEBUG: windows tree:\n"); - weechat_cmd_debug_display_windows (gui_windows_tree, 1); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "DEBUG: windows tree:"); + command_debug_display_windows (gui_windows_tree, 1); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "debug"); + gui_chat_printf (NULL, + _("%s%s unknown option for \"%s\" command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "debug"); return -1; } @@ -1946,288 +932,164 @@ weechat_cmd_debug (t_irc_server *server, t_irc_channel *channel, } /* - * weechat_cmd_disconnect_one_server: disconnect from a server - * return 0 if error, 1 if ok + * command_help: display help about commands */ int -weechat_cmd_disconnect_one_server (t_irc_server *server) -{ - if ((!server->is_connected) && (server->child_pid == 0) - && (server->reconnect_start == 0)) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf (server->buffer, - _("%s not connected to server \"%s\"!\n"), - WEECHAT_ERROR, server->name); - return 0; - } - if (server->reconnect_start > 0) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_INFO); - gui_printf (server->buffer, - _("Auto-reconnection is cancelled\n")); - } - irc_send_quit_server (server, NULL); - irc_server_disconnect (server, 0); - gui_status_draw (server->buffer, 1); - - /* disconnect ok */ - return 1; -} - -/* - * weechat_cmd_disconnect: disconnect from server(s) - */ - -int -weechat_cmd_disconnect (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) -{ - t_gui_buffer *buffer; - t_irc_server *ptr_server; - int i, disconnect_ok; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - if (argc == 0) - disconnect_ok = weechat_cmd_disconnect_one_server (server); - else - { - disconnect_ok = 1; - - if (ascii_strcasecmp (argv[0], "-all") == 0) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if ((ptr_server->is_connected) || (ptr_server->child_pid != 0) - || (ptr_server->reconnect_start != 0)) - { - if (!weechat_cmd_disconnect_one_server (ptr_server)) - disconnect_ok = 0; - } - } - } - else - { - for (i = 0; i < argc; i++) - { - ptr_server = irc_server_search (argv[i]); - if (ptr_server) - { - if (!weechat_cmd_disconnect_one_server (ptr_server)) - disconnect_ok = 0; - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s server \"%s\" not found\n"), - WEECHAT_ERROR, argv[i]); - disconnect_ok = 0; - } - } - } - } - - if (!disconnect_ok) - return -1; - - return 0; -} - -/* - * weechat_cmd_help: display help - */ - -int -weechat_cmd_help (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_help (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { int i; -#ifdef PLUGINS - t_weechat_plugin *ptr_plugin; - t_plugin_handler *ptr_handler; -#endif + struct t_hook *ptr_hook; /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) arguments; switch (argc) { case 0: - gui_printf (NULL, "\n"); - gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME); - for (i = 0; weechat_commands[i].command_name; i++) - { - gui_printf (NULL, " %s%s %s- %s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - weechat_commands[i].command_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - _(weechat_commands[i].command_description)); - } - gui_printf (NULL, "\n"); - gui_printf (NULL, _("IRC commands:\n")); - for (i = 0; irc_commands[i].command_name; i++) - { - if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg) - { - gui_printf (NULL, " %s%s %s- %s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - irc_commands[i].command_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - _(irc_commands[i].command_description)); - } - } -#ifdef PLUGINS - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Plugin commands:\n")); - for (ptr_plugin = weechat_plugins; ptr_plugin; - ptr_plugin = ptr_plugin->next_plugin) - { - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("%s internal commands:"), PACKAGE_NAME); + for (i = 0; weechat_commands[i].name; i++) + { + if (weechat_commands[i].description + && weechat_commands[i].description[0]) + gui_chat_printf (NULL, " %s%s %s- %s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + weechat_commands[i].name, + GUI_COLOR(GUI_COLOR_CHAT), + _(weechat_commands[i].description)); + else + gui_chat_printf (NULL, " %s%s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + weechat_commands[i].name); + } + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Other commands:")); + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if ((ptr_hook->type == HOOK_TYPE_COMMAND) + && HOOK_COMMAND(ptr_hook, command) + && HOOK_COMMAND(ptr_hook, command)[0]) { - if (ptr_handler->type == PLUGIN_HANDLER_COMMAND) - { - gui_printf (NULL, " %s%s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_handler->command); - if (ptr_handler->description - && ptr_handler->description[0]) - gui_printf (NULL, " %s- %s", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_handler->description); - gui_printf (NULL, "\n"); - } + if (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) + gui_chat_printf (NULL, " %s%s %s- %s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + HOOK_COMMAND(ptr_hook, command), + GUI_COLOR(GUI_COLOR_CHAT), + HOOK_COMMAND(ptr_hook, description)); + else + gui_chat_printf (NULL, " %s%s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + HOOK_COMMAND(ptr_hook, command)); } } -#endif break; case 1: -#ifdef PLUGINS - for (ptr_plugin = weechat_plugins; ptr_plugin; - ptr_plugin = ptr_plugin->next_plugin) - { - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) + { + if ((ptr_hook->type == HOOK_TYPE_COMMAND) + && HOOK_COMMAND(ptr_hook, command) + && HOOK_COMMAND(ptr_hook, command)[0] + && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), + argv[0]) == 0)) { - if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND) - && (ascii_strcasecmp (ptr_handler->command, argv[0]) == 0)) + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, + _("[%s%s] %s/%s %s%s"), + (ptr_hook->plugin) ? + _("plugin:") : "weechat", + (ptr_hook->plugin) ? + ptr_hook->plugin->name : "", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + HOOK_COMMAND(ptr_hook, command), + GUI_COLOR(GUI_COLOR_CHAT), + (HOOK_COMMAND(ptr_hook, args) + && HOOK_COMMAND(ptr_hook, args)[0]) ? + HOOK_COMMAND(ptr_hook, args) : ""); + if (HOOK_COMMAND(ptr_hook, description) + && HOOK_COMMAND(ptr_hook, description)[0]) { - gui_printf (NULL, "\n"); - gui_printf (NULL, "[p]"); - gui_printf (NULL, " %s/%s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_handler->command); - if (ptr_handler->arguments && - ptr_handler->arguments[0]) - gui_printf (NULL, " %s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_handler->arguments); - else - gui_printf (NULL, "\n"); - if (ptr_handler->description && - ptr_handler->description[0]) - gui_printf (NULL, "\n%s\n", - ptr_handler->description); - if (ptr_handler->arguments_description && - ptr_handler->arguments_description[0]) - gui_printf (NULL, "\n%s\n", - ptr_handler->arguments_description); - return 0; + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + HOOK_COMMAND(ptr_hook, description)); } + if (HOOK_COMMAND(ptr_hook, args_description) + && HOOK_COMMAND(ptr_hook, args_description)[0]) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + HOOK_COMMAND(ptr_hook, args_description)); + } + return 0; } } -#endif - for (i = 0; weechat_commands[i].command_name; i++) + for (i = 0; weechat_commands[i].name; i++) { - if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0) + if (string_strcasecmp (weechat_commands[i].name, argv[0]) == 0) { - gui_printf (NULL, "\n"); - gui_printf (NULL, "[w]"); - gui_printf (NULL, " %s/%s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - weechat_commands[i].command_name); - if (weechat_commands[i].arguments && - weechat_commands[i].arguments[0]) - gui_printf (NULL, " %s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - _(weechat_commands[i].arguments)); - else - gui_printf (NULL, "\n"); - if (weechat_commands[i].command_description && - weechat_commands[i].command_description[0]) - gui_printf (NULL, "\n%s\n", - _(weechat_commands[i].command_description)); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "[weechat] %s/%s %s%s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + weechat_commands[i].name, + GUI_COLOR(GUI_COLOR_CHAT), + (weechat_commands[i].arguments + && weechat_commands[i].arguments[0]) ? + _(weechat_commands[i].arguments) : ""); + if (weechat_commands[i].description && + weechat_commands[i].description[0]) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + _(weechat_commands[i].description)); + } if (weechat_commands[i].arguments_description && weechat_commands[i].arguments_description[0]) - gui_printf (NULL, "\n%s\n", - _(weechat_commands[i].arguments_description)); - return 0; - } - } - for (i = 0; irc_commands[i].command_name; i++) - { - if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0) - && (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, "[i]"); - gui_printf (NULL, " %s/%s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - irc_commands[i].command_name); - if (irc_commands[i].arguments && - irc_commands[i].arguments[0]) - gui_printf (NULL, " %s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - _(irc_commands[i].arguments)); - else - gui_printf (NULL, "\n"); - if (irc_commands[i].command_description && - irc_commands[i].command_description[0]) - gui_printf (NULL, "\n%s\n", - _(irc_commands[i].command_description)); - if (irc_commands[i].arguments_description && - irc_commands[i].arguments_description[0]) - gui_printf (NULL, "\n%s\n", - _(irc_commands[i].arguments_description)); + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s", + _(weechat_commands[i].arguments_description)); + } return 0; } } - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("No help available, \"%s\" is an unknown command\n"), - argv[0]); + gui_chat_printf (NULL, + _("%sNo help available, \"%s\" is an " + "unknown command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[0]); break; } return 0; } /* - * weechat_cmd_history: display current buffer history + * command_history: display current buffer history */ int -weechat_cmd_history (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_history (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; - t_history *ptr_history; + struct t_gui_history *ptr_history; int n; int n_total; int n_user; - gui_buffer_find_context (server, channel, NULL, &buffer); + /* make C compiler happy */ + (void) arguments; n_user = cfg_history_display_default; if (argc == 1) { - if (ascii_strcasecmp (argv[0], "clear") == 0) + if (string_strcasecmp (argv[0], "clear") == 0) { - history_buffer_free (buffer); + gui_history_buffer_free (buffer); return 0; } else @@ -2247,8 +1109,10 @@ weechat_cmd_history (t_irc_server *server, t_irc_channel *channel, { if ((n_user > 0) && ((n_total - n_user) > n)) continue; - irc_display_prefix (NULL, buffer, GUI_PREFIX_INFO); - gui_printf_nolog (buffer, "%s\n", ptr_history->text); + gui_chat_printf (buffer, + "%s%s", + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + ptr_history->text); } } @@ -2256,151 +1120,54 @@ weechat_cmd_history (t_irc_server *server, t_irc_channel *channel, } /* - * weechat_cmd_ignore_display: display an ignore entry + * command_key_display: display a key binding */ void -weechat_cmd_ignore_display (char *text, t_irc_ignore *ptr_ignore) -{ - if (text) - gui_printf (NULL, "%s%s ", - GUI_COLOR(GUI_COLOR_WIN_CHAT), - text); - - gui_printf (NULL, _("%son %s%s%s/%s%s%s:%s ignoring %s%s%s from %s%s\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_ignore->server_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_ignore->channel_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_ignore->type, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - ptr_ignore->mask); -} - -/* - * weechat_cmd_ignore: ignore IRC commands and/or hosts - */ - -int -weechat_cmd_ignore (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) -{ - t_gui_buffer *buffer; - t_irc_ignore *ptr_ignore; - int i; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - ptr_ignore = NULL; - switch (argc) - { - case 0: - /* List all ignore */ - if (irc_ignore) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("List of ignore:\n")); - i = 0; - for (ptr_ignore = irc_ignore; ptr_ignore; - ptr_ignore = ptr_ignore->next_ignore) - { - i++; - gui_printf (NULL, "%s[%s%d%s] ", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - i, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - weechat_cmd_ignore_display (NULL, ptr_ignore); - } - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No ignore defined.\n")); - } - return 0; - break; - case 1: - ptr_ignore = irc_ignore_add (argv[0], "*", "*", - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 2: - ptr_ignore = irc_ignore_add (argv[0], argv[1], "*", - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 3: - ptr_ignore = irc_ignore_add (argv[0], argv[1], argv[2], - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 4: - ptr_ignore = irc_ignore_add (argv[0], argv[1], argv[2], argv[3]); - break; - } - if (ptr_ignore) - { - gui_printf (NULL, "\n"); - weechat_cmd_ignore_display (_("New ignore:"), ptr_ignore); - return 0; - } - else - return -1; -} - -/* - * weechat_cmd_key_display: display a key binding - */ - -void -weechat_cmd_key_display (t_gui_key *key, int new_key) +command_key_display (t_gui_key *key, int new_key) { char *expanded_name; expanded_name = gui_keyboard_get_expanded_name (key->key); if (new_key) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("New key binding: %s"), - (expanded_name) ? expanded_name : key->key); + gui_chat_printf (NULL, + _("New key binding: %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + (expanded_name) ? expanded_name : key->key); } else - gui_printf (NULL, " %20s", (expanded_name) ? expanded_name : key->key); - gui_printf (NULL, "%s => %s%s%s%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - (key->function) ? - gui_keyboard_function_search_by_ptr (key->function) : key->command, - (key->args) ? " \"" : "", - (key->args) ? key->args : "", - (key->args) ? "\"" : ""); + gui_chat_printf (NULL, " %20s", + (expanded_name) ? expanded_name : key->key); + gui_chat_printf (NULL, "%s => %s%s%s%s%s", + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + (key->function) ? + gui_keyboard_function_search_by_ptr (key->function) : key->command, + (key->args) ? " \"" : "", + (key->args) ? key->args : "", + (key->args) ? "\"" : ""); if (expanded_name) free (expanded_name); } /* - * weechat_cmd_key: bind/unbind keys + * command_key: bind/unbind keys */ int -weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_key (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_window *window; - t_gui_buffer *buffer; char *pos, *pos_args, *args_tmp, *internal_code; int i, length; t_gui_key *ptr_key; - void (*ptr_function)(t_gui_window *, char *); + t_gui_key_func *ptr_function; - gui_buffer_find_context (server, channel, &window, &buffer); + /* make C compiler happy */ + (void) buffer; + (void) argc; + (void) argv; if (arguments) { @@ -2410,46 +1177,49 @@ weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, if (!arguments || (arguments[0] == '\0')) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Key bindings:\n")); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Key bindings:")); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) { - weechat_cmd_key_display (ptr_key, 0); + command_key_display (ptr_key, 0); } } - else if (ascii_strncasecmp (arguments, "unbind ", 7) == 0) + else if (string_strncasecmp (arguments, "unbind ", 7) == 0) { arguments += 7; while (arguments[0] == ' ') arguments++; if (gui_keyboard_unbind (arguments)) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Key \"%s\" unbound\n"), arguments); + gui_chat_printf (NULL, + _("%sKey \"%s\" unbound"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + arguments); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unable to unbind key \"%s\"\n"), - WEECHAT_ERROR, arguments); + gui_chat_printf (NULL, + _("%s%s unable to unbind key \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, arguments); return -1; } } - else if (ascii_strcasecmp (arguments, "functions") == 0) + else if (string_strcasecmp (arguments, "functions") == 0) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Internal key functions:\n")); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Internal key functions:")); i = 0; while (gui_key_functions[i].function_name) { - gui_printf (NULL, "%25s %s\n", - gui_key_functions[i].function_name, - _(gui_key_functions[i].description)); + gui_chat_printf (NULL, + "%25s %s", + gui_key_functions[i].function_name, + _(gui_key_functions[i].description)); i++; } } - else if (ascii_strncasecmp (arguments, "call ", 5) == 0) + else if (string_strncasecmp (arguments, "call ", 5) == 0) { arguments += 5; while (arguments[0] == ' ') @@ -2480,37 +1250,39 @@ weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, else args_tmp = strdup (pos_args); } - (void)(*ptr_function)(window, args_tmp); + (void)(*ptr_function)(args_tmp); if (args_tmp) free (args_tmp); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown key function \"%s\"\n"), - WEECHAT_ERROR, arguments); + gui_chat_printf (NULL, + _("%s%s unknown key function \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, arguments); return -1; } } - else if (ascii_strncasecmp (arguments, "reset", 5) == 0) + else if (string_strncasecmp (arguments, "reset", 5) == 0) { arguments += 5; while (arguments[0] == ' ') arguments++; - if (ascii_strcasecmp (arguments, "-yes") == 0) + if (string_strcasecmp (arguments, "-yes") == 0) { gui_keyboard_free_all (); gui_keyboard_init (); - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Default key bindings restored\n")); + gui_chat_printf (NULL, + _("%sDefault key bindings restored"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s \"-yes\" argument is required for keys reset (security reason)\n"), - WEECHAT_ERROR); + gui_chat_printf (NULL, + _("%s%s \"-yes\" argument is required for " + "keys reset (security reason)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR); return -1; } } @@ -2527,14 +1299,15 @@ weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, ptr_key = gui_keyboard_search (internal_code); if (ptr_key) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Key:\n")); - weechat_cmd_key_display (ptr_key, 0); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Key:")); + command_key_display (ptr_key, 0); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No key found.\n")); + gui_chat_printf (NULL, + _("%sNo key found."), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); } if (internal_code) free (internal_code); @@ -2546,13 +1319,13 @@ weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, pos++; ptr_key = gui_keyboard_bind (arguments, pos); if (ptr_key) - weechat_cmd_key_display (ptr_key, 1); + command_key_display (ptr_key, 1); else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unable to bind key \"%s\"\n"), - WEECHAT_ERROR, arguments); + gui_chat_printf (NULL, + _("%s%s unable to bind key \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, arguments); return -1; } } @@ -2561,99 +1334,20 @@ weechat_cmd_key (t_irc_server *server, t_irc_channel *channel, } /* - * weechat_cmd_panel_display_info: display infos about a panel + * command_plugin_list: list loaded plugins */ void -weechat_cmd_panel_display_info (t_gui_panel *panel) -{ - gui_printf (NULL, " %s%2d%s. ", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - panel->number, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - gui_printf (NULL, "%s%s%s ", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - panel->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - gui_printf (NULL, "(%s%s/%s", - (panel->panel_window) ? _("global") : _("local"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - switch (panel->position) - { - case GUI_PANEL_TOP: - gui_printf (NULL, "%s", _("top")); - break; - case GUI_PANEL_BOTTOM: - gui_printf (NULL, "%s", _("bottom")); - break; - case GUI_PANEL_LEFT: - gui_printf (NULL, "%s", _("left")); - break; - case GUI_PANEL_RIGHT: - gui_printf (NULL, "%s", _("right")); - break; - } - gui_printf (NULL, "%s/%s%d)\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - panel->size); -} - -/* - * weechat_cmd_panel: manage panels - */ - -int -weechat_cmd_panel (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_plugin_list (char *name, int full) { - t_gui_panel *ptr_panel; + struct t_weechat_plugin *ptr_plugin; + struct t_hook *ptr_hook; + int plugins_found, hook_found, interval; - /* make C compiler happy */ - (void) server; - (void) channel; - - gui_printf (NULL, "\n/panel command is under development!\n"); - - if ((argc == 0) || ((argc == 1) && (ascii_strcasecmp (argv[0], "list") == 0))) - { - /* list open panels */ - - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Open panels:\n")); - - for (ptr_panel = gui_panels; ptr_panel; ptr_panel = ptr_panel->next_panel) - { - weechat_cmd_panel_display_info (ptr_panel); - } - } - else - { - } - return 0; -} - -/* - * weechat_cmd_plugin_list: list loaded plugins - */ - -void -weechat_cmd_plugin_list (char *name, int full) -{ -#ifdef PLUGINS - t_weechat_plugin *ptr_plugin; - int plugins_found; - t_plugin_handler *ptr_handler; - int handler_found; - t_plugin_modifier *ptr_modifier; - int modifier_found; - - gui_printf (NULL, "\n"); + gui_chat_printf (NULL, ""); if (!name) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _("Plugins loaded:\n")); + gui_chat_printf (NULL, _("Plugins loaded:")); } plugins_found = 0; @@ -2661,960 +1355,415 @@ weechat_cmd_plugin_list (char *name, int full) for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) { - if (!name || (ascii_strcasestr (ptr_plugin->name, name))) + if (!name || (string_strcasestr (ptr_plugin->name, name))) { plugins_found++; /* plugin info */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, " %s%s%s v%s - %s (%s)\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ptr_plugin->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_plugin->version, - ptr_plugin->description, - ptr_plugin->filename); + gui_chat_printf (NULL, + " %s%s%s v%s - %s (%s)", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + ptr_plugin->name, + GUI_COLOR(GUI_COLOR_CHAT), + ptr_plugin->version, + ptr_plugin->description, + ptr_plugin->filename); if (full) { - /* message handlers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" message handlers:\n")); - handler_found = 0; - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + /* commands hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - if (ptr_handler->type == PLUGIN_HANDLER_MESSAGE) + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_COMMAND)) { - handler_found = 1; - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" IRC(%s)\n"), - ptr_handler->irc_command); + if (!hook_found) + gui_chat_printf (NULL, _(" commands hooked:")); + hook_found = 1; + gui_chat_printf (NULL, + " /%s %s%s%s", + ((struct t_hook_command *)ptr_hook->hook_data)->command, + (((struct t_hook_command *)ptr_hook->hook_data)->description) ? "(" : "", + (((struct t_hook_command *)ptr_hook->hook_data)->description) ? + ((struct t_hook_command *)ptr_hook->hook_data)->description : "", + (((struct t_hook_command *)ptr_hook->hook_data)->description) ? ")" : ""); } } - if (!handler_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" (no message handler)\n")); - } - /* command handlers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" command handlers:\n")); - handler_found = 0; - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + /* messages hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - if (ptr_handler->type == PLUGIN_HANDLER_COMMAND) + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_MESSAGE)) { - handler_found = 1; - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, " /%s", - ptr_handler->command); - if (ptr_handler->description - && ptr_handler->description[0]) - gui_printf (NULL, " (%s)", - ptr_handler->description); - gui_printf (NULL, "\n"); + if (!hook_found) + gui_chat_printf (NULL, _(" messages hooked:")); + hook_found = 1; + gui_chat_printf (NULL, + " %s", + ((struct t_hook_message *)ptr_hook->hook_data)->message); } } - if (!handler_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" (no command handler)\n")); - } - /* timer handlers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" timer handlers:\n")); - handler_found = 0; - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + /* config options hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - if (ptr_handler->type == PLUGIN_HANDLER_TIMER) + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_MESSAGE)) { - handler_found = 1; - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" %d seconds\n"), - ptr_handler->interval); + if (!hook_found) + gui_chat_printf (NULL, + _(" configuration otions " + "hooked:")); + hook_found = 1; + gui_chat_printf (NULL, + " (%s) %s", + ((struct t_hook_config *)ptr_hook->hook_data)->type ? + ((struct t_hook_config *)ptr_hook->hook_data)->type : "*", + ((struct t_hook_config *)ptr_hook->hook_data)->option ? + ((struct t_hook_config *)ptr_hook->hook_data)->option : "*"); + } } - if (!handler_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" (no timer handler)\n")); - } - /* keyboard handlers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" keyboard handlers:\n")); - handler_found = 0; - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + /* timers hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - if (ptr_handler->type == PLUGIN_HANDLER_KEYBOARD) - handler_found++; + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_TIMER)) + { + if (!hook_found) + gui_chat_printf (NULL, _(" timers hooked:")); + hook_found = 1; + interval = (((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ? + ((struct t_hook_timer *)ptr_hook->hook_data)->interval / 1000 : + ((struct t_hook_timer *)ptr_hook->hook_data)->interval; + if (((struct t_hook_timer *)ptr_hook->hook_data)->remaining_calls > 0) + gui_chat_printf (NULL, + _(" %d %s " + "(%d calls remaining)"), + interval, + (((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ? + ((interval > 1) ? + _("seconds") : + _("second")) : + ((interval > 1) ? + _("milliseconds") : + _("millisecond")), + ((struct t_hook_timer *)ptr_hook->hook_data)->remaining_calls); + else + gui_chat_printf (NULL, + _(" %d %s " + "(no call limit)"), + interval, + (((struct t_hook_timer *)ptr_hook->hook_data)->interval % 1000 == 0) ? + ((interval > 1) ? + _("seconds") : + _("second")) : + ((interval > 1) ? + _("milliseconds") : + _("millisecond"))); + } } - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - if (!handler_found) - gui_printf (NULL, _(" (no keyboard handler)\n")); - else - gui_printf (NULL, _(" %d defined\n"), - handler_found); - /* event handlers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" event handlers:\n")); - handler_found = 0; - for (ptr_handler = ptr_plugin->handlers; - ptr_handler; ptr_handler = ptr_handler->next_handler) + /* fd hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - if (ptr_handler->type == PLUGIN_HANDLER_EVENT) - handler_found++; + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_MESSAGE)) + { + if (!hook_found) + gui_chat_printf (NULL, + _(" fd hooked:")); + hook_found = 1; + gui_chat_printf (NULL, + _(" %d (flags: %d)"), + ((struct t_hook_fd *)ptr_hook->hook_data)->fd, + ((struct t_hook_fd *)ptr_hook->hook_data)->flags); + } } - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - if (!handler_found) - gui_printf (NULL, _(" (no event handler)\n")); - else - gui_printf (NULL, _(" %d defined\n"), - handler_found); - /* modifiers */ - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - gui_printf (NULL, _(" modifiers:\n")); - modifier_found = 0; - for (ptr_modifier = ptr_plugin->modifiers; - ptr_modifier; ptr_modifier = ptr_modifier->next_modifier) + /* keyboards hooked */ + hook_found = 0; + for (ptr_hook = weechat_hooks; ptr_hook; + ptr_hook = ptr_hook->next_hook) { - modifier_found++; + if ((ptr_hook->plugin == ptr_plugin) + && (ptr_hook->type == HOOK_TYPE_KEYBOARD)) + hook_found++; } - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); - if (!modifier_found) - gui_printf (NULL, _(" (no modifier)\n")); - else - gui_printf (NULL, _(" %d defined\n"), - modifier_found); + if (hook_found) + gui_chat_printf (NULL, _(" %d keyboards hooked"), + hook_found); } } } if (plugins_found == 0) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_PLUGIN); if (name) - gui_printf (NULL, _("No plugin found.\n")); + gui_chat_printf (NULL, _("No plugin found.")); else - gui_printf (NULL, _(" (no plugin)\n")); + gui_chat_printf (NULL, _(" (no plugin)")); } -#else - /* make C compiler happy */ - (void) name; - (void) full; -#endif } /* - * weechat_cmd_plugin: list/load/unload WeeChat plugins + * command_plugin: list/load/unload WeeChat plugins */ int -weechat_cmd_plugin (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_plugin (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { -#ifdef PLUGINS /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) arguments; switch (argc) { case 0: - weechat_cmd_plugin_list (NULL, 0); + command_plugin_list (NULL, 0); break; case 1: - if (ascii_strcasecmp (argv[0], "list") == 0) - weechat_cmd_plugin_list (NULL, 0); - else if (ascii_strcasecmp (argv[0], "listfull") == 0) - weechat_cmd_plugin_list (NULL, 1); - else if (ascii_strcasecmp (argv[0], "autoload") == 0) + if (string_strcasecmp (argv[0], "list") == 0) + command_plugin_list (NULL, 0); + else if (string_strcasecmp (argv[0], "listfull") == 0) + command_plugin_list (NULL, 1); + else if (string_strcasecmp (argv[0], "autoload") == 0) plugin_auto_load (); - else if (ascii_strcasecmp (argv[0], "reload") == 0) + else if (string_strcasecmp (argv[0], "reload") == 0) { plugin_unload_all (); plugin_auto_load (); } - else if (ascii_strcasecmp (argv[0], "unload") == 0) + else if (string_strcasecmp (argv[0], "unload") == 0) plugin_unload_all (); break; case 2: - if (ascii_strcasecmp (argv[0], "list") == 0) - weechat_cmd_plugin_list (argv[1], 0); - else if (ascii_strcasecmp (argv[0], "listfull") == 0) - weechat_cmd_plugin_list (argv[1], 1); - else if (ascii_strcasecmp (argv[0], "load") == 0) + if (string_strcasecmp (argv[0], "list") == 0) + command_plugin_list (argv[1], 0); + else if (string_strcasecmp (argv[0], "listfull") == 0) + command_plugin_list (argv[1], 1); + else if (string_strcasecmp (argv[0], "load") == 0) plugin_load (argv[1]); - else if (ascii_strcasecmp (argv[0], "reload") == 0) + else if (string_strcasecmp (argv[0], "reload") == 0) plugin_reload_name (argv[1]); - else if (ascii_strcasecmp (argv[0], "unload") == 0) + else if (string_strcasecmp (argv[0], "unload") == 0) plugin_unload_name (argv[1]); else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "plugin"); + gui_chat_printf (NULL, + _("%s%s unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "plugin"); } break; default: - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s wrong argument count for \"%s\" command\n"), - WEECHAT_ERROR, "plugin"); + gui_chat_printf (NULL, + _("%s%s wrong argument count for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "plugin"); } -#else - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("Command \"%s\" is not available, WeeChat was built " - "without plugins support.\n"), - "plugin"); - /* make C compiler happy */ - (void) server; - (void) channel; - (void) argc; - (void) argv; -#endif /* PLUGINS */ return 0; } /* - * weechat_cmd_reconnect_one_server: reconnect to a server - * return 0 if error, 1 if ok - */ - -int -weechat_cmd_reconnect_one_server (t_irc_server *server, int no_join) -{ - if ((!server->is_connected) && (server->child_pid == 0)) - { - irc_display_prefix (NULL, server->buffer, GUI_PREFIX_ERROR); - gui_printf (server->buffer, - _("%s not connected to server \"%s\"!\n"), - WEECHAT_ERROR, server->name); - return 0; - } - irc_send_quit_server (server, NULL); - irc_server_disconnect (server, 0); - if (irc_server_connect (server, no_join)) - { - server->reconnect_start = 0; - server->reconnect_join = (server->channels) ? 1 : 0; - } - gui_status_draw (server->buffer, 1); - - /* reconnect ok */ - return 1; -} - -/* - * weechat_cmd_reconnect: reconnect to server(s) + * command_quit: quit WeeChat */ int -weechat_cmd_reconnect (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_quit (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; - t_irc_server *ptr_server; - int i, nb_reconnect, reconnect_ok, all_servers, no_join; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - nb_reconnect = 0; - reconnect_ok = 1; - - all_servers = 0; - no_join = 0; - for (i = 0; i < argc; i++) - { - if (ascii_strcasecmp (argv[i], "-all") == 0) - all_servers = 1; - if (ascii_strcasecmp (argv[i], "-nojoin") == 0) - no_join = 1; - } - - if (all_servers) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - nb_reconnect++; - if ((ptr_server->is_connected) || (ptr_server->child_pid != 0)) - { - if (!weechat_cmd_reconnect_one_server (ptr_server, no_join)) - reconnect_ok = 0; - } - } - } - else - { - for (i = 0; i < argc; i++) - { - if (argv[i][0] != '-') - { - nb_reconnect++; - ptr_server = irc_server_search (argv[i]); - if (ptr_server) - { - if (!weechat_cmd_reconnect_one_server (ptr_server, no_join)) - reconnect_ok = 0; - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s server \"%s\" not found\n"), - WEECHAT_ERROR, argv[i]); - reconnect_ok = 0; - } - } - } - } + (void) buffer; + (void) arguments; + (void) argc; + (void) argv; - if (nb_reconnect == 0) - reconnect_ok = weechat_cmd_reconnect_one_server (server, no_join); - - if (!reconnect_ok) - return -1; + quit_weechat = 1; return 0; } /* - * weechat_cmd_save: save WeeChat and plugins options to disk + * command_save: save WeeChat and plugins options to disk */ int -weechat_cmd_save (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_save (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { /* make C compiler happy */ - (void) server; - (void) channel; - - if (config_write ((argc == 1) ? argv[0] : NULL) == 0) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf_nolog (NULL, _("Configuration file saved\n")); - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, _("%s failed to save configuration file\n"), - WEECHAT_ERROR); - } + (void) buffer; + (void) arguments; + (void) argc; + (void) argv; -#ifdef PLUGINS + /* save WeeChat configuration */ + if (weechat_config_write () == 0) + gui_chat_printf (NULL, + _("%sWeeChat configuration file saved"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); + else + gui_chat_printf (NULL, + _("%s%s failed to save configuration file"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR); + + /* save plugins configuration */ if (plugin_config_write () == 0) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf_nolog (NULL, _("Plugins options saved\n")); - } + gui_chat_printf (NULL, _("%sPlugins options saved"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, _("%s failed to save plugins options\n"), - WEECHAT_ERROR); - } -#endif + gui_chat_printf (NULL, + _("%s%s failed to save plugins options"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR); return 0; } /* - * weechat_cmd_server: list, add or remove server(s) + * command_set_display_option: display config option */ -int -weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +void +command_set_display_option (struct t_config_option *option, char *message) { - t_gui_window *window; - t_gui_buffer *buffer; - int i, detailed_list, one_server_found; - t_irc_server server_tmp, *ptr_server, *server_found, *new_server; - t_gui_buffer *ptr_buffer; - char *server_name, *error; - long number; + char *color_name; - gui_buffer_find_context (server, channel, &window, &buffer); - - if ((argc == 0) - || (ascii_strcasecmp (argv[0], "list") == 0) - || (ascii_strcasecmp (argv[0], "listfull") == 0)) + switch (option->type) { - /* list servers */ - server_name = NULL; - detailed_list = 0; - for (i = 0; i < argc; i++) - { - if (ascii_strcasecmp (argv[i], "list") == 0) - continue; - if (ascii_strcasecmp (argv[i], "listfull") == 0) - { - detailed_list = 1; - continue; - } - if (!server_name) - server_name = argv[i]; - } - if (!server_name) - { - if (irc_servers) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("All servers:\n")); - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - irc_display_server (ptr_server, detailed_list); - } - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No server.\n")); - } - } - else - { - one_server_found = 0; - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ascii_strcasestr (ptr_server->name, server_name)) - { - if (!one_server_found) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Servers with '%s':\n"), - server_name); - } - one_server_found = 1; - irc_display_server (ptr_server, detailed_list); - } - } - if (!one_server_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("No server with '%s' found.\n"), - server_name); - } - } - } - else - { - if (ascii_strcasecmp (argv[0], "add") == 0) - { - if (argc < 3) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing parameters for \"%s\" command\n"), - WEECHAT_ERROR, "server"); - return -1; - } - - if (irc_server_name_already_exists (argv[1])) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" already exists, can't create it!\n"), - WEECHAT_ERROR, argv[1]); - return -1; - } - - /* init server struct */ - irc_server_init (&server_tmp); - - server_tmp.name = strdup (argv[1]); - server_tmp.address = strdup (argv[2]); - server_tmp.port = IRC_DEFAULT_PORT; - - /* parse arguments */ - for (i = 3; i < argc; i++) - { - if (argv[i][0] == '-') - { - if (ascii_strcasecmp (argv[i], "-temp") == 0) - server_tmp.temp_server = 1; - if (ascii_strcasecmp (argv[i], "-auto") == 0) - server_tmp.autoconnect = 1; - if (ascii_strcasecmp (argv[i], "-noauto") == 0) - server_tmp.autoconnect = 0; - if (ascii_strcasecmp (argv[i], "-ipv6") == 0) - server_tmp.ipv6 = 1; - if (ascii_strcasecmp (argv[i], "-ssl") == 0) - server_tmp.ssl = 1; - if (ascii_strcasecmp (argv[i], "-port") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-port"); - irc_server_destroy (&server_tmp); - return -1; - } - error = NULL; - number = strtol (argv[++i], &error, 10); - if ((error) && (error[0] == '\0')) - server_tmp.port = number; - } - if (ascii_strcasecmp (argv[i], "-pwd") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-pwd"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.password = strdup (argv[++i]); - } - if (ascii_strcasecmp (argv[i], "-nicks") == 0) - { - if (i >= (argc - 3)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-nicks"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.nick1 = strdup (argv[++i]); - server_tmp.nick2 = strdup (argv[++i]); - server_tmp.nick3 = strdup (argv[++i]); - } - if (ascii_strcasecmp (argv[i], "-username") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-username"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.username = strdup (argv[++i]); - } - if (ascii_strcasecmp (argv[i], "-realname") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-realname"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.realname = strdup (argv[++i]); - } - if (ascii_strcasecmp (argv[i], "-command") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-command"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.command = strdup (argv[++i]); - } - if (ascii_strcasecmp (argv[i], "-autojoin") == 0) - { - if (i == (argc - 1)) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing argument for \"%s\" option\n"), - WEECHAT_ERROR, "-autojoin"); - irc_server_destroy (&server_tmp); - return -1; - } - server_tmp.autojoin = strdup (argv[++i]); - } - } - } - - /* create new server */ - new_server = irc_server_new (server_tmp.name, - server_tmp.autoconnect, - server_tmp.autoreconnect, - server_tmp.autoreconnect_delay, - server_tmp.temp_server, - server_tmp.address, - server_tmp.port, - server_tmp.ipv6, - server_tmp.ssl, - server_tmp.password, - server_tmp.nick1, - server_tmp.nick2, - server_tmp.nick3, - server_tmp.username, - server_tmp.realname, - server_tmp.hostname, - server_tmp.command, - 1, /* command_delay */ - server_tmp.autojoin, - 1, /* autorejoin */ - NULL); - if (new_server) + case OPTION_TYPE_BOOLEAN: + gui_chat_printf (NULL, "%s%s%s = %s%s", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + (*((int *)(option->ptr_int))) ? "ON" : "OFF"); + break; + case OPTION_TYPE_INT: + gui_chat_printf (NULL, "%s%s%s = %s%d", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + *((int *)(option->ptr_int))); + break; + case OPTION_TYPE_INT_WITH_STRING: + gui_chat_printf (NULL, "%s%s%s = %s%s", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + option->array_values[*((int *)(option->ptr_int))]); + break; + case OPTION_TYPE_COLOR: + color_name = gui_color_get_name (*((int *)(option->ptr_int))); + gui_chat_printf (NULL, "%s%s%s = %s%s", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + (color_name) ? color_name : _("(unknown)")); + break; + case OPTION_TYPE_STRING: + if (*((char **)(option->ptr_string))) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s created\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - server_tmp.name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, "%s%s%s = \"%s%s%s\"", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + *(option->ptr_string), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); } else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unable to create server\n"), - WEECHAT_ERROR); - irc_server_destroy (&server_tmp); - return -1; - } - - if (new_server->autoconnect) - { - (void) gui_buffer_new (window, new_server, NULL, - GUI_BUFFER_TYPE_STANDARD, 1); - irc_server_connect (new_server, 0); - } - - irc_server_destroy (&server_tmp); - } - else if (ascii_strcasecmp (argv[0], "copy") == 0) - { - if (argc < 3) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing server name for \"%s\" command\n"), - WEECHAT_ERROR, "server copy"); - return -1; - } - - /* look for server by name */ - server_found = irc_server_search (argv[1]); - if (!server_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" not found for \"%s\" command\n"), - WEECHAT_ERROR, argv[1], "server copy"); - return -1; - } - - /* check if target name already exists */ - if (irc_server_search (argv[2])) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" already exists for \"%s\" command\n"), - WEECHAT_ERROR, argv[2], "server copy"); - return -1; - } - - /* duplicate server */ - new_server = irc_server_duplicate (server_found, argv[2]); - if (new_server) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s has been copied to %s%s\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - argv[1], - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - argv[2]); - gui_window_redraw_all_buffers (); - return 0; - } - - return -1; - } - else if (ascii_strcasecmp (argv[0], "rename") == 0) - { - if (argc < 3) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing server name for \"%s\" command\n"), - WEECHAT_ERROR, "server rename"); - return -1; - } - - /* look for server by name */ - server_found = irc_server_search (argv[1]); - if (!server_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" not found for \"%s\" command\n"), - WEECHAT_ERROR, argv[1], "server rename"); - return -1; - } - - /* check if target name already exists */ - if (irc_server_search (argv[2])) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" already exists for \"%s\" command\n"), - WEECHAT_ERROR, argv[2], "server rename"); - return -1; - } - - /* rename server */ - if (irc_server_rename (server_found, argv[2])) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s has been renamed to %s%s\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - argv[1], - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - argv[2]); - gui_window_redraw_all_buffers (); - return 0; - } - - return -1; - } - else if (ascii_strcasecmp (argv[0], "keep") == 0) - { - if (argc < 2) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing server name for \"%s\" command\n"), - WEECHAT_ERROR, "server keep"); - return -1; - } - - /* look for server by name */ - server_found = irc_server_search (argv[1]); - if (!server_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" not found for \"%s\" command\n"), - WEECHAT_ERROR, argv[1], "server keep"); - return -1; - } - - /* check that it is temporary server */ - if (!server_found->temp_server) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" is not a temporary server\n"), - WEECHAT_ERROR, argv[1]); - return -1; - } - - /* remove temporary flag on server */ - server_found->temp_server = 0; - - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s is not temporary any more\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - argv[1], - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - - return 0; - } - else if (ascii_strcasecmp (argv[0], "del") == 0) - { - if (argc < 2) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s missing server name for \"%s\" command\n"), - WEECHAT_ERROR, "server del"); - return -1; - } - - /* look for server by name */ - server_found = irc_server_search (argv[1]); - if (!server_found) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" not found for \"%s\" command\n"), - WEECHAT_ERROR, argv[1], "server del"); - return -1; - } - if (server_found->is_connected) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s you can not delete server \"%s\" because you are connected to. " - "Try /disconnect %s before.\n"), - WEECHAT_ERROR, argv[1], argv[1]); - return -1; - } - - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (GUI_SERVER(ptr_buffer) == server_found) - { - ptr_buffer->server = NULL; - ptr_buffer->channel = NULL; - } - } - - server_name = strdup (server_found->name); - - irc_server_free (server_found); - - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Server %s%s%s has been deleted\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - server_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - if (server_name) - free (server_name); - - gui_window_redraw_buffer (buffer); - - return 0; - } - else if (ascii_strcasecmp (argv[0], "deloutq") == 0) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - irc_server_outqueue_free_all (ptr_server); - } - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf_nolog (NULL, _("Messages outqueue DELETED for all servers. " - "Some messages from you or WeeChat may " - "have been lost!\n")); - return 0; - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "server"); - return -1; - } + gui_chat_printf (NULL, "%s%s%s = \"\"", + (message) ? message : " ", + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + break; } - return 0; } /* - * weechat_cmd_set_display_option: display config option + * command_set_display_option_list: display list of options + * Return: number of options displayed */ -void -weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *value) +int +command_set_display_option_list (char **config_sections, + struct t_config_option **config_options, + char *message, char *search) { - char *color_name, *value2; + int i, j, number_found, section_displayed; - gui_printf (NULL, " %s%s%s%s = ", - (prefix) ? prefix : "", - (prefix) ? "." : "", - option->option_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - if (!value) - { - if (option->option_type == OPTION_TYPE_STRING) - value = option->ptr_string; - else - value = option->ptr_int; - } - switch (option->option_type) + if (!config_sections || !config_options) + return 0; + + number_found = 0; + + for (i = 0; config_sections[i]; i++) { - case OPTION_TYPE_BOOLEAN: - gui_printf (NULL, "%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - (*((int *)value)) ? "ON" : "OFF"); - break; - case OPTION_TYPE_INT: - gui_printf (NULL, "%s%d\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - *((int *)value)); - break; - case OPTION_TYPE_INT_WITH_STRING: - gui_printf (NULL, "%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - option->array_values[*((int *)value)]); - break; - case OPTION_TYPE_COLOR: - color_name = gui_color_get_name (*((int *)value)); - gui_printf (NULL, "%s%s\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - (color_name) ? color_name : _("(unknown)")); - break; - case OPTION_TYPE_STRING: - if (*((char **)value)) + if (config_options[i]) + { + section_displayed = 0; + for (j = 0; config_options[i][j].name; j++) { - value2 = strdup (*((char **)value)); - if (value2) + if ((!search) || + ((search) && (search[0]) + && (string_strcasestr (config_options[i][j].name, search)))) { - if (cfg_log_hide_nickserv_pwd) + if (!section_displayed) { - irc_display_hide_password (value2, 1); - if (strcmp (*((char **)value), value2) != 0) - gui_printf (NULL, _("%s(password hidden) "), - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s[%s%s%s]", + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + config_sections[i], + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + section_displayed = 1; } - gui_printf (NULL, "%s\"%s%s%s\"", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - value2, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - free (value2); + command_set_display_option (&config_options[i][j], message); + number_found++; } } - else - gui_printf (NULL, "%s\"\"", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - gui_printf (NULL, "\n"); - break; + } } + + return number_found; } /* - * weechat_cmd_set: set config options + * command_set: set config options */ int -weechat_cmd_set (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_set (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { char *option, *value, *pos; - int i, j, section_displayed; - t_config_option *ptr_option; - t_irc_server *ptr_server; - char option_name[256]; - void *ptr_option_value; - int last_section, last_option, number_found; + struct t_config_option *ptr_option; + int number_found; /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) argc; + (void) argv; option = NULL; value = NULL; @@ -3667,284 +1816,150 @@ weechat_cmd_set (t_irc_server *server, t_irc_channel *channel, if (value) { pos = strrchr (option, '.'); - if (pos) + /*if (pos) { - /* server config option modification */ pos[0] = '\0'; - ptr_server = irc_server_search (option); - if (!ptr_server) + ptr_protocol = protocol_search (option); + if (!ptr_protocol) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s server \"%s\" not found\n"), - WEECHAT_ERROR, option); + gui_chat_printf (NULL, + _("%s%s protocol \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, + option); } else { - switch (config_set_server_value (ptr_server, pos + 1, value)) + ptr_option = config_option_section_option_search (ptr_protocol->config_sections, + ptr_protocol->config_options, + pos + 1); + if (ptr_option) { - case 0: - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s[%s%s %s%s%s]\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - config_sections[CONFIG_SECTION_SERVER].section_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - ptr_server->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) - { - if (strcmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, pos + 1) == 0) - break; - } - if (weechat_options[CONFIG_SECTION_SERVER][i].option_name) - { - ptr_option_value = config_get_server_option_ptr (ptr_server, - weechat_options[CONFIG_SECTION_SERVER][i].option_name); - weechat_cmd_set_display_option (&weechat_options[CONFIG_SECTION_SERVER][i], - ptr_server->name, - ptr_option_value); - } - config_change_buffer_content (); - break; - case -1: - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s config option \"%s\" not found\n"), - WEECHAT_ERROR, pos + 1); - break; - case -2: - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect value for option \"%s\"\n"), - WEECHAT_ERROR, pos + 1); - break; + switch (config_option_set (ptr_option, value)) + { + case 0: + gui_chat_printf (NULL, ""); + command_set_display_option (ptr_option, ptr_protocol->name); + break; + default: + gui_chat_printf (NULL, + _("%s%s incorrect value for " + "option \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, pos + 1); + break; + } } + else + gui_chat_printf (NULL, + _("%s%s config option \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, pos + 1); } pos[0] = '.'; } - else + else*/ { - ptr_option = config_option_search (option); + ptr_option = config_option_section_option_search (weechat_config_sections, + weechat_config_options, + option); if (ptr_option) { if (ptr_option->handler_change == NULL) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s option \"%s\" can not be changed while WeeChat is running\n"), - WEECHAT_ERROR, option); + gui_chat_printf (NULL, + _("%s%s option \"%s\" can not be " + "changed while WeeChat is " + "running"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, option); } else { - if (config_option_set_value (ptr_option, value) == 0) + if (config_option_set (ptr_option, value) == 0) { - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s[%s%s%s]\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - config_get_section (ptr_option), - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - weechat_cmd_set_display_option (ptr_option, NULL, NULL); + command_set_display_option (ptr_option, + _("Option changed: ")); (void) (ptr_option->handler_change()); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect value for option \"%s\"\n"), - WEECHAT_ERROR, option); + gui_chat_printf (NULL, + _("%s%s incorrect value for " + "option \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, option); } } } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s config option \"%s\" not found\n"), - WEECHAT_ERROR, option); + gui_chat_printf (NULL, + _("%s%s configuration option \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, option); } } } else { - last_section = -1; - last_option = -1; number_found = 0; - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - section_displayed = 0; - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) - { - for (j = 0; weechat_options[i][j].option_name; j++) - { - if ((!option) || - ((option) && (option[0]) - && (strstr (weechat_options[i][j].option_name, option) - != NULL))) - { - if (!section_displayed) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s[%s%s%s]\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - config_sections[i].section_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - section_displayed = 1; - } - weechat_cmd_set_display_option (&weechat_options[i][j], NULL, NULL); - last_section = i; - last_option = j; - number_found++; - } - } - } - } - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - section_displayed = 0; - for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) - { - snprintf (option_name, sizeof (option_name), "%s.%s", - ptr_server->name, - weechat_options[CONFIG_SECTION_SERVER][i].option_name); - if ((!option) || - ((option) && (option[0]) - && (strstr (option_name, option) != NULL))) - { - if (!section_displayed) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s[%s%s %s%s%s]\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - config_sections[CONFIG_SECTION_SERVER].section_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - ptr_server->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); - section_displayed = 1; - } - ptr_option_value = config_get_server_option_ptr (ptr_server, - weechat_options[CONFIG_SECTION_SERVER][i].option_name); - if (ptr_option_value) - { - weechat_cmd_set_display_option (&weechat_options[CONFIG_SECTION_SERVER][i], - ptr_server->name, - ptr_option_value); - last_section = CONFIG_SECTION_SERVER; - last_option = i; - number_found++; - } - } - } - } + + number_found += command_set_display_option_list (weechat_config_sections, + weechat_config_options, + NULL, + option); + if (number_found == 0) { if (option) - gui_printf (NULL, _("No config option found with \"%s\"\n"), - option); + gui_chat_printf (NULL, + _("No configuration option found with " + "\"%s\""), + option); else - gui_printf (NULL, _("No config option found\n")); + gui_chat_printf (NULL, + _("No configuration option found")); } else { - if ((number_found == 1) && (last_section >= 0) && (last_option >= 0)) - { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("%sDetail:\n"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL)); - switch (weechat_options[last_section][last_option].option_type) - { - case OPTION_TYPE_BOOLEAN: - gui_printf (NULL, _(" . type boolean (values: 'on' or 'off')\n")); - gui_printf (NULL, _(" . default value: '%s'\n"), - (weechat_options[last_section][last_option].default_int == BOOL_TRUE) ? - "on" : "off"); - break; - case OPTION_TYPE_INT: - gui_printf (NULL, _(" . type integer (values: between %d and %d)\n"), - weechat_options[last_section][last_option].min, - weechat_options[last_section][last_option].max); - gui_printf (NULL, _(" . default value: %d\n"), - weechat_options[last_section][last_option].default_int); - break; - case OPTION_TYPE_INT_WITH_STRING: - gui_printf (NULL, _(" . type string (values: ")); - i = 0; - while (weechat_options[last_section][last_option].array_values[i]) - { - gui_printf (NULL, "'%s'", - weechat_options[last_section][last_option].array_values[i]); - if (weechat_options[last_section][last_option].array_values[i + 1]) - gui_printf (NULL, ", "); - i++; - } - gui_printf (NULL, ")\n"); - gui_printf (NULL, _(" . default value: '%s'\n"), - (weechat_options[last_section][last_option].default_string) ? - weechat_options[last_section][last_option].default_string : _("empty")); - break; - case OPTION_TYPE_COLOR: - gui_printf (NULL, _(" . type color (Curses or Gtk color, look at WeeChat doc)\n")); - gui_printf (NULL, _(" . default value: '%s'\n"), - (weechat_options[last_section][last_option].default_string) ? - weechat_options[last_section][last_option].default_string : _("empty")); - break; - case OPTION_TYPE_STRING: - switch (weechat_options[last_section][last_option].max) - { - case 0: - gui_printf (NULL, _(" . type string (any string)\n")); - break; - case 1: - gui_printf (NULL, _(" . type: char (any char)\n")); - break; - default: - gui_printf (NULL, _(" . type string (any string, limit: %d chars)\n"), - weechat_options[last_section][last_option].max); - break; - } - gui_printf (NULL, _(" . default value: '%s'\n"), - (weechat_options[last_section][last_option].default_string) ? - weechat_options[last_section][last_option].default_string : _("empty")); - break; - } - gui_printf (NULL, _(" . description: %s\n"), - _(weechat_options[last_section][last_option].long_description)); - } + gui_chat_printf (NULL, ""); + if (option) + gui_chat_printf (NULL, + _("%s%d%s configuration option(s) found with " + "\"%s\""), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT), + option); else - { - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s%d %s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - number_found, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - if (option) - gui_printf (NULL, _("config option(s) found with \"%s\"\n"), - option); - else - gui_printf (NULL, _("config option(s) found\n")); - } + gui_chat_printf (NULL, + _("%s%d%s configuration option(s) found"), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT)); } } return 0; } /* - * weechat_cmd_setp: set plugin options + * command_setp: set plugin options */ int -weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_setp (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { -#ifdef PLUGINS char *option, *value, *pos, *ptr_name; - t_plugin_option *ptr_option; + struct t_plugin_option *ptr_option; int number_found; /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) argc; + (void) argv; option = NULL; value = NULL; @@ -4007,9 +2022,10 @@ weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, pos[0] = '\0'; if (!pos || !pos[1] || (!plugin_search (option))) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s plugin \"%s\" not found\n"), - WEECHAT_ERROR, option); + gui_chat_printf (NULL, + _("%s%s plugin \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, option); } else ptr_name = option; @@ -4020,18 +2036,21 @@ weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, { if (plugin_config_set_internal (ptr_name, value)) { - gui_printf (NULL, "\n %s%s = \"%s%s%s\"\n", - ptr_name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - value, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); + gui_chat_printf (NULL, + _("Plugin option changed: %s%s = \"%s%s%s\""), + ptr_name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + value, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); } else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect value for plugin option \"%s\"\n"), - WEECHAT_ERROR, ptr_name); + gui_chat_printf (NULL, + _("%s%s incorrect value for plugin " + "option \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, ptr_name); } } } @@ -4046,50 +2065,41 @@ weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, && (strstr (ptr_option->name, option) != NULL))) { if (number_found == 0) - gui_printf (NULL, "\n"); - gui_printf (NULL, " %s%s = \"%s%s%s\"\n", - ptr_option->name, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_HOST), - ptr_option->value, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, " %s%s = \"%s%s%s\"", + ptr_option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + ptr_option->value, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); number_found++; } } if (number_found == 0) { if (option) - gui_printf (NULL, _("No plugin option found with \"%s\"\n"), - option); + gui_chat_printf (NULL, + _("No plugin option found with \"%s\""), + option); else - gui_printf (NULL, _("No plugin option found\n")); + gui_chat_printf (NULL, _("No plugin option found")); } else { - gui_printf (NULL, "\n"); - gui_printf (NULL, "%s%d %s", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - number_found, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, "%s%d %s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + number_found, + GUI_COLOR(GUI_COLOR_CHAT)); if (option) - gui_printf (NULL, _("plugin option(s) found with \"%s\"\n"), - option); + gui_chat_printf (NULL, + _("plugin option(s) found with \"%s\""), + option); else - gui_printf (NULL, _("plugin option(s) found\n")); + gui_chat_printf (NULL, + _("plugin option(s) found")); } } -#else - /* make C compiler happy */ - (void) server; - (void) channel; - (void) arguments; - - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("Command \"%s\" is not available, WeeChat was built " - "without plugins support.\n"), - "setp"); -#endif return 0; } @@ -4099,156 +2109,90 @@ weechat_cmd_setp (t_irc_server *server, t_irc_channel *channel, */ int -weechat_cmd_unalias (t_irc_server *server, t_irc_channel *channel, - char *arguments) +command_unalias (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_weelist *ptr_weelist; - t_weechat_alias *ptr_alias; + struct t_weelist *ptr_weelist; + struct alias *ptr_alias; /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) argc; + (void) argv; if (arguments[0] == '/') arguments++; - ptr_weelist = weelist_search (index_commands, arguments); + ptr_weelist = weelist_search (weechat_index_commands, arguments); if (!ptr_weelist) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s alias or command \"%s\" not found\n"), - WEECHAT_ERROR, arguments); + gui_chat_printf (NULL, + _("%s%s alias or command \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, arguments); return -1; } - weelist_remove (&index_commands, &last_index_command, ptr_weelist); + weelist_remove (&weechat_index_commands, + &weechat_last_index_command, + ptr_weelist); ptr_alias = alias_search (arguments); if (ptr_alias) alias_free (ptr_alias); - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, _("Alias \"%s\" removed\n"), - arguments); + gui_chat_printf (NULL, + _("%sAlias \"%s\" removed"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + arguments); return 0; } /* - * weechat_cmd_unignore: unignore IRC commands and/or hosts + * command_upgrade: upgrade WeeChat */ int -weechat_cmd_unignore (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_upgrade (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; - char *error; - int number, ret; - - gui_buffer_find_context (server, channel, NULL, &buffer); - - ret = 0; - switch (argc) - { - case 0: - /* List all ignore */ - weechat_cmd_ignore (server, channel, argc, argv); - return 0; - break; - case 1: - error = NULL; - number = strtol (argv[0], &error, 10); - if ((error) && (error[0] == '\0')) - ret = irc_ignore_search_free_by_number (number); - else - ret = irc_ignore_search_free (argv[0], "*", "*", - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 2: - ret = irc_ignore_search_free (argv[0], argv[1], "*", - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 3: - ret = irc_ignore_search_free (argv[0], argv[1], argv[2], - (GUI_SERVER(buffer)) ? - GUI_SERVER(buffer)->name : "*"); - break; - case 4: - ret = irc_ignore_search_free (argv[0], argv[1], argv[2], argv[3]); - break; - } - - if (ret) - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf (NULL, - NG_("%s%d%s ignore was removed.\n", - "%s%d%s ignore were removed.\n", - ret), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ret, - GUI_COLOR(GUI_COLOR_WIN_CHAT)); - } - else - { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, _("%s no ignore found\n"), - WEECHAT_ERROR); - return -1; - } - - return 0; -} - -/* - * weechat_cmd_upgrade: upgrade WeeChat - */ - -int -weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) -{ - t_irc_server *ptr_server; - int filename_length; + /*int filename_length; char *filename, *ptr_binary; - char *exec_args[7] = { NULL, "-a", "--dir", NULL, "--session", NULL, NULL }; + char *exec_args[7] = { NULL, "-a", "--dir", NULL, "--session", NULL, NULL };*/ /* make C compiler happy */ - (void) server; - (void) channel; + (void) buffer; + (void) arguments; + (void) argc; + (void) argv; - ptr_binary = (argc > 0) ? argv[0] : weechat_argv0; + /*ptr_binary = (argc > 0) ? argv[0] : weechat_argv0; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->child_pid != 0) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, + gui_chat_printf_error (NULL, _("%s can't upgrade: connection to at least " - "one server is pending\n"), + "one server is pending"), WEECHAT_ERROR); return -1; - } + }*/ /* TODO: remove this test, and fix gnutls save/load in session */ - if (ptr_server->is_connected && ptr_server->ssl_connected) + /*if (ptr_server->is_connected && ptr_server->ssl_connected) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, - _("%s can't upgrade: connection to at least " - "one SSL server is active " - "(should be fixed in a future version)\n"), - WEECHAT_ERROR); + gui_chat_printf_error_nolog (NULL, + _("%s can't upgrade: connection to at least " + "one SSL server is active " + "(should be fixed in a future version)"), + WEECHAT_ERROR); return -1; } if (ptr_server->outqueue) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, - _("%s can't upgrade: anti-flood is active on " - "at least one server (sending many lines)\n"), - WEECHAT_ERROR); + gui_chat_printf_error_nolog (NULL, + _("%s can't upgrade: anti-flood is active on " + "at least one server (sending many lines)"), + WEECHAT_ERROR); return -1; } } @@ -4260,69 +2204,64 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel, snprintf (filename, filename_length, "%s%s" WEECHAT_SESSION_NAME, weechat_home, DIR_SEPARATOR); - irc_display_prefix (NULL, NULL, GUI_PREFIX_INFO); - gui_printf_nolog (NULL, _("Upgrading WeeChat...\n")); + gui_chat_printf_info_nolog (NULL, + _("Upgrading WeeChat...")); if (!session_save (filename)) { free (filename); - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf_nolog (NULL, - _("%s unable to save session in file\n"), - WEECHAT_ERROR); + gui_chat_printf_error_nolog (NULL, + _("%s unable to save session in file"), + WEECHAT_ERROR); return -1; } exec_args[0] = strdup (ptr_binary); exec_args[3] = strdup (weechat_home); - exec_args[5] = strdup (filename); + exec_args[5] = strdup (filename);*/ /* unload plugins, save config, then upgrade */ -#ifdef PLUGINS plugin_end (); -#endif - if (cfg_look_save_on_exit) + /*if (cfg_look_save_on_exit) (void) config_write (NULL); gui_main_end (); fifo_remove (); weechat_log_close (); - execvp (exec_args[0], exec_args); + execvp (exec_args[0], exec_args);*/ /* this code should not be reached if execvp is ok */ -#ifdef PLUGINS plugin_init (1); -#endif - weechat_iconv_fprintf (stderr, - _("%s exec failed (program: \"%s\"), exiting WeeChat\n"), - WEECHAT_ERROR, - exec_args[0]); + /*string_iconv_fprintf (stderr, + _("%s exec failed (program: \"%s\"), exiting WeeChat"), + WEECHAT_ERROR, + exec_args[0]); free (exec_args[0]); free (exec_args[3]); free (filename); - exit (EXIT_FAILURE); + exit (EXIT_FAILURE);*/ /* never executed */ return -1; } /* - * weechat_cmd_uptime: display WeeChat uptime + * command_uptime: display WeeChat uptime */ int -weechat_cmd_uptime (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_uptime (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_buffer *buffer; time_t running_time; int day, hour, min, sec; char string[256]; - gui_buffer_find_context (server, channel, NULL, &buffer); + /* make C compiler happy */ + (void) arguments; running_time = time (NULL) - weechat_start_time; day = running_time / (60 * 60 * 24); @@ -4330,9 +2269,7 @@ weechat_cmd_uptime (t_irc_server *server, t_irc_channel *channel, min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; - if ((argc == 1) && (strcmp (argv[0], "-o") == 0) - && ((GUI_BUFFER_IS_CHANNEL(buffer)) - || (GUI_BUFFER_IS_PRIVATE(buffer)))) + if ((argc == 1) && (strcmp (argv[0], "-o") == 0)) { snprintf (string, sizeof (string), _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), @@ -4343,177 +2280,184 @@ weechat_cmd_uptime (t_irc_server *server, t_irc_channel *channel, sec, ctime (&weechat_start_time)); string[strlen (string) - 1] = '\0'; - user_command (server, channel, string, 0); + input_data (buffer, string, 0); } else { - irc_display_prefix (NULL, buffer, GUI_PREFIX_INFO); - gui_printf_nolog (buffer, - _("WeeChat uptime: %s%d %s%s " - "%s%02d%s:%s%02d%s:%s%02d%s, " - "started on %s%s"), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - day, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - NG_("day", "days", day), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - hour, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - min, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - sec, - GUI_COLOR(GUI_COLOR_WIN_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - ctime (&weechat_start_time)); + gui_chat_printf (NULL, + _("%sWeeChat uptime: %s%d %s%s " + "%s%02d%s:%s%02d%s:%s%02d%s, " + "started on %s%s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + day, + GUI_COLOR(GUI_COLOR_CHAT), + NG_("day", "days", day), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + hour, + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + min, + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + sec, + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + ctime (&weechat_start_time)); } return 0; } /* - * weechat_cmd_window: manage windows + * command_window: manage windows */ int -weechat_cmd_window (t_irc_server *server, t_irc_channel *channel, - int argc, char **argv) +command_window (struct t_gui_buffer *buffer, + char *arguments, int argc, char **argv) { - t_gui_window *window, *ptr_win; - t_gui_buffer *buffer; + struct t_gui_window *ptr_win; int i; char *error; long number; + + /* make C compiler happy */ + (void) buffer; + (void) arguments; - gui_buffer_find_context (server, channel, &window, &buffer); - - if ((argc == 0) || ((argc == 1) && (ascii_strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) { /* list open windows */ - gui_printf (NULL, "\n"); - gui_printf (NULL, _("Open windows:\n")); + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("Open windows:")); i = 1; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { - gui_printf (NULL, "%s[%s%d%s] (%s%d:%d%s;%s%dx%d%s) ", - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - i, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_win->win_x, - ptr_win->win_y, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK), - GUI_COLOR(GUI_COLOR_WIN_CHAT), - ptr_win->win_width, - ptr_win->win_height, - GUI_COLOR(GUI_COLOR_WIN_CHAT_DARK)); + gui_chat_printf (NULL, "%s[%s%d%s] (%s%d:%d%s;%s%dx%d%s) ", + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + i, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + ptr_win->win_x, + ptr_win->win_y, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + ptr_win->win_width, + ptr_win->win_height, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - weechat_cmd_buffer_display_info (ptr_win->buffer); + command_buffer_display_info (ptr_win->buffer); i++; } } else { - if (ascii_strcasecmp (argv[0], "splith") == 0) + if (string_strcasecmp (argv[0], "splith") == 0) { /* split window horizontally */ if (argc > 1) { error = NULL; number = strtol (argv[1], &error, 10); - if ((error) && (error[0] == '\0') + if (error && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_split_horiz (window, number); + gui_window_split_horiz (gui_current_window, number); } else - gui_window_split_horiz (window, 50); + gui_window_split_horiz (gui_current_window, 50); } - else if (ascii_strcasecmp (argv[0], "splitv") == 0) + else if (string_strcasecmp (argv[0], "splitv") == 0) { /* split window vertically */ if (argc > 1) { error = NULL; number = strtol (argv[1], &error, 10); - if ((error) && (error[0] == '\0') + if (error && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_split_vertic (window, number); + gui_window_split_vertic (gui_current_window, number); } else - gui_window_split_vertic (window, 50); + gui_window_split_vertic (gui_current_window, 50); } - else if (ascii_strcasecmp (argv[0], "resize") == 0) + else if (string_strcasecmp (argv[0], "resize") == 0) { /* resize window */ if (argc > 1) { error = NULL; number = strtol (argv[1], &error, 10); - if ((error) && (error[0] == '\0') + if (error && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_resize (window, number); + gui_window_resize (gui_current_window, number); } } - else if (ascii_strcasecmp (argv[0], "merge") == 0) + else if (string_strcasecmp (argv[0], "merge") == 0) { if (argc >= 2) { - if (ascii_strcasecmp (argv[1], "all") == 0) - gui_window_merge_all (window); + if (string_strcasecmp (argv[1], "all") == 0) + gui_window_merge_all (gui_current_window); else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "window merge"); + gui_chat_printf (NULL, + _("%s%s unknown option for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "window merge"); return -1; } } else { - if (!gui_window_merge (window)) + if (!gui_window_merge (gui_current_window)) { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s can not merge windows, " - "there's no other window with same size " - "near current one.\n"), - WEECHAT_ERROR); + gui_chat_printf (NULL, + _("%s%s can not merge windows, " + "there's no other window with same " + "size near current one."), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR); return -1; } } } - else if (ascii_strncasecmp (argv[0], "b", 1) == 0) + else if (string_strncasecmp (argv[0], "b", 1) == 0) { /* jump to window by buffer number */ error = NULL; number = strtol (argv[0] + 1, &error, 10); - if ((error) && (error[0] == '\0')) - gui_window_switch_by_buffer (window, number); + if (error && (error[0] == '\0')) + gui_window_switch_by_buffer (gui_current_window, number); + } + else if (string_strcasecmp (argv[0], "-1") == 0) + gui_window_switch_previous (gui_current_window); + else if (string_strcasecmp (argv[0], "+1") == 0) + gui_window_switch_next (gui_current_window); + else if (string_strcasecmp (argv[0], "up") == 0) + gui_window_switch_up (gui_current_window); + else if (string_strcasecmp (argv[0], "down") == 0) + gui_window_switch_down (gui_current_window); + else if (string_strcasecmp (argv[0], "left") == 0) + gui_window_switch_left (gui_current_window); + else if (string_strcasecmp (argv[0], "right") == 0) + gui_window_switch_right (gui_current_window); + else if (string_strcasecmp (argv[0], "scroll") == 0) + { + if (argc >= 2) + gui_window_scroll (gui_current_window, argv[1]); } - else if (ascii_strcasecmp (argv[0], "-1") == 0) - gui_window_switch_previous (window); - else if (ascii_strcasecmp (argv[0], "+1") == 0) - gui_window_switch_next (window); - else if (ascii_strcasecmp (argv[0], "up") == 0) - gui_window_switch_up (window); - else if (ascii_strcasecmp (argv[0], "down") == 0) - gui_window_switch_down (window); - else if (ascii_strcasecmp (argv[0], "left") == 0) - gui_window_switch_left (window); - else if (ascii_strcasecmp (argv[0], "right") == 0) - gui_window_switch_right (window); else { - irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR); - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "window"); + gui_chat_printf (NULL, + _("%s%s unknown option for \"%s\" command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + WEECHAT_ERROR, "window"); return -1; } } diff --git a/src/core/wee-command.h b/src/core/wee-command.h index 644491dd0..ea93e7f20 100644 --- a/src/core/wee-command.h +++ b/src/core/wee-command.h @@ -20,67 +20,55 @@ #ifndef __WEECHAT_COMMAND_H #define __WEECHAT_COMMAND_H 1 -#include "weelist.h" -#include "../protocols/irc/irc.h" -#include "../gui/gui.h" +#include "../gui/gui-buffer.h" #define MAX_ARGS 8192 -typedef struct t_weechat_command t_weechat_command; - -struct t_weechat_command +struct command { - char *command_name; /* WeeChat (internal) command name */ - char *command_description; /* command description (for /help) */ - char *arguments; /* command arguments (for /help) */ - char *arguments_description; /* arguments description (for /help) */ - char *completion_template; /* template for completion */ - /* NULL=no completion, ""=default (nick) */ - int min_arg, max_arg; /* min & max number of arguments */ - int conversion; /* = 1 if cmd args are converted (charset */ - /* and color) before execution */ - int (*cmd_function_args)(t_irc_server *, t_irc_channel *, int, char **); - /* function called when user enters cmd */ - int (*cmd_function_1arg)(t_irc_server *, t_irc_channel *, char *); - /* function called when user enters cmd */ + char *name; /* WeeChat (internal) command name */ + char *description; /* command description (for /help) */ + char *arguments; /* command arguments (for /help) */ + char *arguments_description; /* arguments description (for /help) */ + char *completion_template; /* template for completion */ + /* NULL=no completion, ""=default (nick) */ + int min_arg, max_arg; /* min & max number of arguments */ + int conversion; /* = 1 if cmd args are converted (charset*/ + /* and color) before execution */ + int (*cmd_function)(struct t_gui_buffer *, char *, int, char **); + /* function called when user enters cmd */ }; -extern t_weechat_command weechat_commands[]; - -extern t_weelist *index_commands; -extern t_weelist *last_index_command; +extern struct command weechat_commands[]; +struct t_weelist *weechat_index_commands; +struct t_weelist *weechat_last_index_command; +extern int command_command_is_used (char *); extern void command_index_build (); extern void command_index_free (); -extern int command_used_by_weechat (char *); -extern char **split_multi_command (char *, char); -extern void free_multi_command (char **); -extern int exec_weechat_command (t_irc_server *, t_irc_channel *, char *, int); -extern void user_command (t_irc_server *, t_irc_channel *, char *, int); -extern int weechat_cmd_alias (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_buffer (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_builtin (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_clear (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_connect (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_dcc (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_debug (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_disconnect (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_help (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_history (t_irc_server *, t_irc_channel *, int, char **); -extern void weechat_cmd_ignore_display (char *, t_irc_ignore *); -extern int weechat_cmd_ignore (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_key (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_panel (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_plugin (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_reconnect (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_save (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_server (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_set (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_setp (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_unalias (t_irc_server *, t_irc_channel *, char *); -extern int weechat_cmd_unignore (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_upgrade (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_uptime (t_irc_server *, t_irc_channel *, int, char **); -extern int weechat_cmd_window (t_irc_server *, t_irc_channel *, int, char **); +extern void command_index_add (char *); +extern void command_index_remove (char *); +extern int command_is_command (char *); +extern void command_print_stdout (struct command *); + +extern int command_alias (struct t_gui_buffer *, char *, int, char **); +extern int command_buffer (struct t_gui_buffer *, char *, int, char **); +extern int command_builtin (struct t_gui_buffer *, char *, int, char **); +extern int command_clear (struct t_gui_buffer *, char *, int, char **); +extern int command_debug (struct t_gui_buffer *, char *, int, char **); +extern int command_help (struct t_gui_buffer *, char *, int, char **); +extern int command_history (struct t_gui_buffer *, char *, int, char **); +extern int command_key (struct t_gui_buffer *, char *, int, char **); +extern int command_panel (struct t_gui_buffer *, char *, int, char **); +extern int command_plugin (struct t_gui_buffer *, char *, int, char **); +extern int command_quit (struct t_gui_buffer *, char *, int, char **); +extern int command_save (struct t_gui_buffer *, char *, int, char **); +extern int command_set (struct t_gui_buffer *, char *, int, char **); +extern int command_setp (struct t_gui_buffer *, char *, int, char **); +extern int command_unalias (struct t_gui_buffer *, char *, int, char **); +extern int command_unignore (struct t_gui_buffer *, char *, int, char **); +extern int command_upgrade (struct t_gui_buffer *, char *, int, char **); +extern int command_uptime (struct t_gui_buffer *, char *, int, char **); +extern int command_window (struct t_gui_buffer *, char *, int, char **); -#endif /* command.h */ +#endif /* wee-command.h */ diff --git a/src/core/wee-config.c b/src/core/wee-config.c index b4f1c8f46..6f87ef15c 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* weeconfig.c: WeeChat configuration */ +/* wee-config.c: WeeChat configuration options */ #ifdef HAVE_CONFIG_H @@ -30,51 +30,35 @@ #include <string.h> #include <limits.h> #include <time.h> -#include <pwd.h> #include <sys/types.h> #include <sys/stat.h> #include "weechat.h" -#include "weeconfig.h" -#include "alias.h" -#include "command.h" -#include "fifo.h" -#include "hotlist.h" -#include "log.h" -#include "utf8.h" -#include "util.h" -#include "../protocols/irc/irc.h" -#include "../gui/gui.h" - - -/* config sections */ - -t_config_section config_sections[CONFIG_NUMBER_SECTIONS] = -{ { CONFIG_SECTION_LOOK, "look" }, - { CONFIG_SECTION_COLORS, "colors" }, - { CONFIG_SECTION_HISTORY, "history" }, - { CONFIG_SECTION_LOG, "log" }, - { CONFIG_SECTION_IRC, "irc" }, - { CONFIG_SECTION_DCC, "dcc" }, - { CONFIG_SECTION_PROXY, "proxy" }, - { CONFIG_SECTION_PLUGINS, "plugins" }, - { CONFIG_SECTION_KEYS, "keys" }, - { CONFIG_SECTION_ALIAS, "alias" }, - { CONFIG_SECTION_IGNORE, "ignore" }, - { CONFIG_SECTION_SERVER, "server" } -}; +#include "wee-config.h" +#include "wee-alias.h" +#include "wee-command.h" +#include "wee-config-file.h" +#include "wee-list.h" +#include "wee-log.h" +#include "wee-string.h" +#include "wee-util.h" +#include "../gui/gui-chat.h" +#include "../gui/gui-hotlist.h" +#include "../gui/gui-keyboard.h" +#include "../gui/gui-status.h" +#include "../gui/gui-window.h" + /* config, look & feel section */ +int cfg_look_color_real_white; int cfg_look_save_on_exit; int cfg_look_set_title; int cfg_look_startup_logo; int cfg_look_startup_version; char *cfg_look_weechat_slogan; -int cfg_look_one_server_buffer; int cfg_look_scroll_amount; -int cfg_look_open_near_server; -char *cfg_look_buffer_timestamp; +char *cfg_look_buffer_time_format; int cfg_look_color_nicks_number; int cfg_look_color_actions; int cfg_look_nicklist; @@ -87,21 +71,19 @@ int cfg_look_nicklist_separator; int cfg_look_nickmode; int cfg_look_nickmode_empty; char *cfg_look_no_nickname; -char *cfg_look_nick_prefix; -char *cfg_look_nick_suffix; -int cfg_look_align_nick; -char *cfg_look_align_nick_values[] = +char *cfg_look_prefix[GUI_CHAT_PREFIX_NUMBER]; +int cfg_look_prefix_align; +char *cfg_look_prefix_align_values[] = { "none", "left", "right", NULL }; -int cfg_look_align_other; -int cfg_look_align_size; -int cfg_look_align_size_max; +int cfg_look_prefix_align_max; +char *cfg_look_prefix_suffix; int cfg_look_align_text_offset; char *cfg_look_nick_completor; char *cfg_look_nick_completion_ignore; int cfg_look_nick_completion_smart; int cfg_look_nick_complete_first; int cfg_look_infobar; -char *cfg_look_infobar_timestamp; +char *cfg_look_infobar_time_format; int cfg_look_infobar_seconds; int cfg_look_infobar_delay_highlight; int cfg_look_hotlist_names_count; @@ -113,221 +95,233 @@ char *cfg_look_hotlist_sort_values[] = "group_number_asc", "group_number_desc", "number_asc", "number_desc" }; int cfg_look_day_change; -char *cfg_look_day_change_timestamp; +char *cfg_look_day_change_time_format; char *cfg_look_read_marker; char *cfg_look_input_format; int cfg_look_paste_max_lines; -t_config_option weechat_options_look[] = -{ { "look_save_on_exit", N_("save config file on exit"), - N_("save config file on exit"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_save_on_exit, NULL, config_change_save_on_exit }, - { "look_set_title", N_("set title for window (terminal for Curses GUI) with name and version"), +struct t_config_option weechat_options_look[] = +{ { "look_color_real_white", + N_("if set, uses real white color, disabled by default for terms with " + "white background (if you never use white background, you should turn " + "on this option to see real white instead of default term foreground " + "color)"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_look_color_real_white, NULL, weechat_config_change_color }, + { "look_save_on_exit", + N_("save configuration file on exit"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_save_on_exit, NULL, weechat_config_change_save_on_exit }, + { "look_set_title", N_("set title for window (terminal for Curses GUI) with name and version"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_set_title, NULL, config_change_title }, - { "look_startup_logo", N_("display WeeChat logo at startup"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_set_title, NULL, weechat_config_change_title }, + { "look_startup_logo", N_("display WeeChat logo at startup"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_startup_logo, NULL, config_change_noop }, - { "look_startup_version", N_("display WeeChat version at startup"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_startup_logo, NULL, weechat_config_change_noop }, + { "look_startup_version", N_("display WeeChat version at startup"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_startup_version, NULL, config_change_noop }, - { "look_weechat_slogan", N_("WeeChat slogan"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_startup_version, NULL, weechat_config_change_noop }, + { "look_weechat_slogan", N_("WeeChat slogan (if empty, slogan is not used)"), - OPTION_TYPE_STRING, 0, 0, 0, - "the geekest IRC client!", NULL, NULL, &cfg_look_weechat_slogan, config_change_noop }, - { "look_one_server_buffer", N_("use same buffer for all servers"), - N_("use same buffer for all servers"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_look_one_server_buffer, NULL, config_change_one_server_buffer }, - { "look_open_near_server", N_("open new channels/privates near server"), - N_("open new channels/privates near server"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_look_open_near_server, NULL, config_change_noop }, - { "look_scroll_amount", N_("how many lines to scroll by with scroll_up and scroll_down"), + OPTION_TYPE_STRING, 0, 0, 0, "the geekest IRC client!", NULL, + NULL, &cfg_look_weechat_slogan, weechat_config_change_noop }, + { "look_scroll_amount", N_("how many lines to scroll by with scroll_up and scroll_down"), - OPTION_TYPE_INT, 1, INT_MAX, 3, - NULL, NULL, &cfg_look_scroll_amount, NULL, config_change_buffer_content }, - { "look_buffer_timestamp", N_("timestamp for buffers"), - N_("timestamp for buffers"), - OPTION_TYPE_STRING, 0, 0, 0, - "[%H:%M:%S]", NULL, NULL, &cfg_look_buffer_timestamp, config_change_buffer_content }, - { "look_color_nicks_number", N_("number of colors to use for nicks colors"), + OPTION_TYPE_INT, 1, INT_MAX, 3, NULL, NULL, + &cfg_look_scroll_amount, NULL, weechat_config_change_buffer_content }, + { "look_buffer_time_format", + N_("time format for buffers"), + OPTION_TYPE_STRING, 0, 0, 0, "[%H:%M:%S]", NULL, + NULL, &cfg_look_buffer_time_format, weechat_config_change_buffer_time_format }, + { "look_color_nicks_number", N_("number of colors to use for nicks colors"), - OPTION_TYPE_INT, 1, 10, 10, - NULL, NULL, &cfg_look_color_nicks_number, NULL, config_change_nicks_colors }, - { "look_color_actions", N_("display actions with different colors"), + OPTION_TYPE_INT, 1, 10, 10, NULL, NULL, + &cfg_look_color_nicks_number, NULL, weechat_config_change_nicks_colors }, + { "look_color_actions", N_("display actions with different colors"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_color_actions, NULL, config_change_noop }, - { "look_nicklist", N_("display nicklist window"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_color_actions, NULL, weechat_config_change_noop }, + { "look_nicklist", N_("display nicklist window (for channel windows)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_nicklist, NULL, config_change_buffers }, - { "look_nicklist_position", N_("nicklist position"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_nicklist, NULL, weechat_config_change_buffers }, + { "look_nicklist_position", N_("nicklist position (top, left, right (default), bottom)"), - OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, - "right", cfg_look_nicklist_position_values, &cfg_look_nicklist_position, NULL, config_change_buffers }, - { "look_nicklist_min_size", N_("min size for nicklist"), + OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, "right", cfg_look_nicklist_position_values, + &cfg_look_nicklist_position, NULL, weechat_config_change_buffers }, + { "look_nicklist_min_size", N_("min size for nicklist (width or height, depending on look_nicklist_position " "(0 = no min size))"), - OPTION_TYPE_INT, 0, 100, 0, - NULL, NULL, &cfg_look_nicklist_min_size, NULL, config_change_buffers }, - { "look_nicklist_max_size", N_("max size for nicklist"), + OPTION_TYPE_INT, 0, 100, 0, NULL, NULL, + &cfg_look_nicklist_min_size, NULL, weechat_config_change_buffers }, + { "look_nicklist_max_size", N_("max size for nicklist (width or height, depending on look_nicklist_position " "(0 = no max size; if min = max and > 0, then size is fixed))"), - OPTION_TYPE_INT, 0, 100, 0, - NULL, NULL, &cfg_look_nicklist_max_size, NULL, config_change_buffers }, - { "look_nicklist_separator", N_("separator between chat and nicklist"), + OPTION_TYPE_INT, 0, 100, 0, NULL, NULL, + &cfg_look_nicklist_max_size, NULL, weechat_config_change_buffers }, + { "look_nicklist_separator", N_("separator between chat and nicklist"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_nicklist_separator, NULL, config_change_buffers }, - { "look_no_nickname", N_("text to display instead of nick when not connected"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_nicklist_separator, NULL, weechat_config_change_buffers }, + { "look_no_nickname", N_("text to display instead of nick when not connected"), - OPTION_TYPE_STRING, 0, 0, 0, - "-cmd-", NULL, NULL, &cfg_look_no_nickname, config_change_buffer_content }, - { "look_nickmode", N_("display nick mode ((half)op/voice) before each nick"), + OPTION_TYPE_STRING, 0, 0, 0, "-cmd-", NULL, + NULL, &cfg_look_no_nickname, weechat_config_change_buffer_content }, + { "look_nickmode", N_("display nick mode ((half)op/voice) before each nick"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_nickmode, NULL, config_change_buffers }, - { "look_nickmode_empty", N_("display space if nick mode is not (half)op/voice"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_nickmode, NULL, weechat_config_change_buffers }, + { "look_nickmode_empty", N_("display space if nick mode is not (half)op/voice"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_look_nickmode_empty, NULL, config_change_buffers }, - { "look_nick_prefix", N_("text to display before nick in chat window"), - N_("text to display before nick in chat window"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_look_nick_prefix, config_change_noop }, - { "look_nick_suffix", N_("text to display after nick in chat window"), - N_("text to display after nick in chat window"), - OPTION_TYPE_STRING, 0, 0, 0, - " |", NULL, NULL, &cfg_look_nick_suffix, config_change_noop }, - { "look_align_nick", N_("nick alignment (fixed size for nicks in chat window)"), - N_("nick alignment (fixed size for nicks in chat window (none, left, right))"), - OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, - "right", cfg_look_align_nick_values, &cfg_look_align_nick, NULL, config_change_noop }, - { "look_align_other", N_("alignment for other messages (not beginning with a nick)"), - N_("alignment for other messages (not beginning with a nick)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_align_other, NULL, config_change_noop }, - { "look_align_size", N_("size for aligning nick and other messages"), - N_("size for aligning nick and other messages"), - OPTION_TYPE_INT, 8, 64, 14, - NULL, NULL, &cfg_look_align_size, NULL, config_change_noop }, - { "look_align_size_max", N_("max size for aligning nick and other messages"), - N_("max size for aligning nick and other messages (should be >= to " - "look_align_size)"), - OPTION_TYPE_INT, 8, 64, 20, - NULL, NULL, &cfg_look_align_size_max, NULL, config_change_noop }, - { "look_align_text_offset", N_("offset for aligning lines of messages " - "(except first lines)"), - N_("offset for aligning lines of messages (except first lines), default is " - "-1 (align after nick), a null or positive value is offset after " + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_look_nickmode_empty, NULL, weechat_config_change_buffers }, + { "look_prefix_info", + N_("prefix for info messages"), + OPTION_TYPE_STRING, 0, 0, 0, "-=-", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_INFO], weechat_config_change_prefix }, + { "look_prefix_error", + N_("prefix for error messages"), + OPTION_TYPE_STRING, 0, 0, 0, "=!=", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_ERROR], weechat_config_change_prefix }, + { "look_prefix_network", + N_("prefix for network messages"), + OPTION_TYPE_STRING, 0, 0, 0, "-@-", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_NETWORK], weechat_config_change_prefix }, + { "look_prefix_action", + N_("prefix for action messages"), + OPTION_TYPE_STRING, 0, 0, 0, "-*-", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_ACTION], weechat_config_change_prefix }, + { "look_prefix_join", + N_("prefix for join messages"), + OPTION_TYPE_STRING, 0, 0, 0, "-->", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_JOIN], weechat_config_change_prefix }, + { "look_prefix_quit", + N_("prefix for quit messages"), + OPTION_TYPE_STRING, 0, 0, 0, "<--", NULL, + NULL, &cfg_look_prefix[GUI_CHAT_PREFIX_QUIT], weechat_config_change_prefix }, + { "look_prefix_align", + N_("prefix alignment (none, left, right))"), + OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, "right", cfg_look_prefix_align_values, + &cfg_look_prefix_align, NULL, weechat_config_change_buffers }, + { "look_prefix_align_max", + N_("max size for prefix (0 = no max size)"), + OPTION_TYPE_INT, 0, 64, 0, NULL, NULL, + &cfg_look_prefix_align_max, NULL, weechat_config_change_buffers }, + { "look_prefix_suffix", + N_("string displayed after prefix"), + OPTION_TYPE_STRING, 0, 0, 0, "|", NULL, + NULL, &cfg_look_prefix_suffix, weechat_config_change_buffers }, + { "look_align_text_offset", + N_("offset for aligning lines of messages (except first lines), default " + "is -1 (align after prefix), a null or positive value is offset after " "beginning of line"), - OPTION_TYPE_INT, -1, 64, -1, - NULL, NULL, &cfg_look_align_text_offset, NULL, config_change_buffers }, - { "look_nick_completor", N_("the string inserted after nick completion"), + OPTION_TYPE_INT, -1, 64, -1, NULL, NULL, + &cfg_look_align_text_offset, NULL, weechat_config_change_buffers }, + { "look_nick_completor", N_("the string inserted after nick completion"), - OPTION_TYPE_STRING, 0, 0, 0, - ":", NULL, NULL, &cfg_look_nick_completor, config_change_noop }, - { "look_nick_completion_ignore", N_("chars ignored for nick completion"), + OPTION_TYPE_STRING, 0, 0, 0, ":", NULL, + NULL, &cfg_look_nick_completor, weechat_config_change_noop }, + { "look_nick_completion_ignore", N_("chars ignored for nick completion"), - OPTION_TYPE_STRING, 0, 0, 0, - "[]-^", NULL, NULL, &cfg_look_nick_completion_ignore, config_change_noop }, - { "look_nick_completion_smart", N_("smart completion for nicks"), + OPTION_TYPE_STRING, 0, 0, 0, "[]-^", NULL, + NULL, &cfg_look_nick_completion_ignore, weechat_config_change_noop }, + { "look_nick_completion_smart", N_("smart completion for nicks (completes with last speakers first)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_nick_completion_smart, NULL, config_change_noop }, - { "look_nick_complete_first", N_("complete only with first nick found"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_nick_completion_smart, NULL, weechat_config_change_noop }, + { "look_nick_complete_first", N_("complete only with first nick found"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_look_nick_complete_first, NULL, config_change_noop }, - { "look_infobar", N_("enable info bar"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_look_nick_complete_first, NULL, weechat_config_change_noop }, + { "look_infobar", N_("enable info bar"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_infobar, NULL, config_change_buffers }, - { "look_infobar_timestamp", N_("timestamp for time in infobar"), - N_("timestamp for time in infobar"), - OPTION_TYPE_STRING, 0, 0, 0, - "%B, %A %d %Y", NULL, NULL, &cfg_look_infobar_timestamp, config_change_buffer_content }, - { "look_infobar_seconds", N_("display seconds in infobar time"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_infobar, NULL, weechat_config_change_buffers }, + { "look_infobar_time_format", + N_("time format for time in infobar"), + OPTION_TYPE_STRING, 0, 0, 0, "%B, %A %d %Y", NULL, + NULL, &cfg_look_infobar_time_format, weechat_config_change_buffer_content }, + { "look_infobar_seconds", N_("display seconds in infobar time"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_infobar_seconds, NULL, config_change_buffer_content }, - { "look_infobar_delay_highlight", N_("delay (in seconds) for highlight messages in infobar"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_infobar_seconds, NULL, weechat_config_change_buffer_content }, + { "look_infobar_delay_highlight", N_("delay (in seconds) for highlight messages in infobar " "(0 = disable highlight notifications in infobar)"), - OPTION_TYPE_INT, 0, INT_MAX, 7, - NULL, NULL, &cfg_look_infobar_delay_highlight, NULL, config_change_noop }, - { "look_hotlist_names_count", N_("max number of names in hotlist"), + OPTION_TYPE_INT, 0, INT_MAX, 7, NULL, NULL, + &cfg_look_infobar_delay_highlight, NULL, weechat_config_change_noop }, + { "look_hotlist_names_count", N_("max number of names in hotlist (0 = no name displayed, only buffer numbers)"), - OPTION_TYPE_INT, 0, 32, 3, - NULL, NULL, &cfg_look_hotlist_names_count, NULL, config_change_buffer_content }, - { "look_hotlist_names_level", N_("level for displaying names in hotlist"), - N_("level for displaying names in hotlist (combination of: 1=join/part, 2=message, " - "4=private, 8=highlight, for example: 12=private+highlight)"), - OPTION_TYPE_INT, 1, 15, 12, - NULL, NULL, &cfg_look_hotlist_names_level, NULL, config_change_buffer_content }, - { "look_hotlist_names_length", N_("max length of names in hotlist"), + OPTION_TYPE_INT, 0, 32, 3, NULL, NULL, + &cfg_look_hotlist_names_count, NULL, weechat_config_change_buffer_content }, + { "look_hotlist_names_level", + N_("level for displaying names in hotlist (combination of: 1=join/part, " + "2=message, 4=private, 8=highlight, for example: 12=private+highlight)"), + OPTION_TYPE_INT, 1, 15, 12, NULL, NULL, + &cfg_look_hotlist_names_level, NULL, weechat_config_change_buffer_content }, + { "look_hotlist_names_length", N_("max length of names in hotlist (0 = no limit)"), - OPTION_TYPE_INT, 0, 32, 0, - NULL, NULL, &cfg_look_hotlist_names_length, NULL, config_change_buffer_content }, - { "look_hotlist_sort", N_("hotlist sort type"), + OPTION_TYPE_INT, 0, 32, 0, NULL, NULL, + &cfg_look_hotlist_names_length, NULL, weechat_config_change_buffer_content }, + { "look_hotlist_sort", N_("hotlist sort type (group_time_asc (default), group_time_desc, " "group_number_asc, group_number_desc, number_asc, number_desc)"), - OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, - "group_time_asc", cfg_look_hotlist_sort_values, &cfg_look_hotlist_sort, NULL, config_change_hotlist }, - { "look_day_change", N_("display special message when day changes"), + OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, "group_time_asc", cfg_look_hotlist_sort_values, + &cfg_look_hotlist_sort, NULL, weechat_config_change_hotlist }, + { "look_day_change", N_("display special message when day changes"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_look_day_change, NULL, config_change_noop }, - { "look_day_change_timestamp", N_("timestamp for date displayed when day changed"), - N_("timestamp for date displayed when day changed"), - OPTION_TYPE_STRING, 0, 0, 0, - "%a, %d %b %Y", NULL, NULL, &cfg_look_day_change_timestamp, config_change_noop }, - { "look_read_marker", N_("use a marker on servers/channels to show first unread line"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, + &cfg_look_day_change, NULL, weechat_config_change_noop }, + { "look_day_change_time_format", + N_("time format for date displayed when day changed"), + OPTION_TYPE_STRING, 0, 0, 0, "%a, %d %b %Y", NULL, + NULL, &cfg_look_day_change_time_format, weechat_config_change_noop }, + { "look_read_marker", N_("use a marker on servers/channels to show first unread line"), - OPTION_TYPE_STRING, 0, 1, 0, - " ", NULL, NULL, &cfg_look_read_marker, config_change_read_marker }, - { "look_input_format", N_("format for input prompt"), + OPTION_TYPE_STRING, 0, 1, 0, " ", NULL, + NULL, &cfg_look_read_marker, weechat_config_change_read_marker }, + { "look_input_format", N_("format for input prompt ('%c' is replaced by channel or server, " "'%n' by nick and '%m' by nick modes)"), - OPTION_TYPE_STRING, 0, 0, 0, - "[%n(%m)] ", NULL, NULL, &cfg_look_input_format, config_change_buffer_content }, - { "look_paste_max_lines", N_("max number of lines for paste without asking user"), + OPTION_TYPE_STRING, 0, 0, 0, "[%n(%m)] ", NULL, + NULL, &cfg_look_input_format, weechat_config_change_buffer_content }, + { "look_paste_max_lines", N_("max number of lines for paste without asking user (0 = disable this feature)"), - OPTION_TYPE_INT, 0, INT_MAX, 3, - NULL, NULL, &cfg_look_paste_max_lines, NULL, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + OPTION_TYPE_INT, 0, INT_MAX, 3, NULL, NULL, + &cfg_look_paste_max_lines, NULL, weechat_config_change_noop }, + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; /* config, colors section */ -int cfg_col_real_white; int cfg_col_separator; int cfg_col_title; -int cfg_col_title_more; int cfg_col_title_bg; +int cfg_col_title_more; int cfg_col_chat; +int cfg_col_chat_bg; int cfg_col_chat_time; -int cfg_col_chat_time_sep; -int cfg_col_chat_prefix1; -int cfg_col_chat_prefix2; +int cfg_col_chat_time_delimiters; +int cfg_col_chat_prefix[GUI_CHAT_PREFIX_NUMBER]; +int cfg_col_chat_prefix_more; +int cfg_col_chat_prefix_suffix; +int cfg_col_chat_buffer; int cfg_col_chat_server; -int cfg_col_chat_join; -int cfg_col_chat_part; +int cfg_col_chat_channel; int cfg_col_chat_nick; +int cfg_col_chat_nick_self; +int cfg_col_chat_nick_other; +int cfg_col_chat_nick_colors[GUI_COLOR_NICK_NUMBER]; int cfg_col_chat_host; -int cfg_col_chat_channel; -int cfg_col_chat_dark; +int cfg_col_chat_delimiters; int cfg_col_chat_highlight; -int cfg_col_chat_bg; int cfg_col_chat_read_marker; int cfg_col_chat_read_marker_bg; int cfg_col_status; +int cfg_col_status_bg; int cfg_col_status_delimiters; int cfg_col_status_channel; int cfg_col_status_data_msg; @@ -335,349 +329,360 @@ int cfg_col_status_data_private; int cfg_col_status_data_highlight; int cfg_col_status_data_other; int cfg_col_status_more; -int cfg_col_status_bg; int cfg_col_infobar; +int cfg_col_infobar_bg; int cfg_col_infobar_delimiters; int cfg_col_infobar_highlight; int cfg_col_infobar_bg; int cfg_col_input; +int cfg_col_input_bg; int cfg_col_input_server; int cfg_col_input_channel; int cfg_col_input_nick; int cfg_col_input_delimiters; int cfg_col_input_text_not_found; int cfg_col_input_actions; -int cfg_col_input_bg; -int cfg_col_nick; -int cfg_col_nick_away; -int cfg_col_nick_chanowner; -int cfg_col_nick_chanadmin; -int cfg_col_nick_op; -int cfg_col_nick_halfop; -int cfg_col_nick_voice; -int cfg_col_nick_user; -int cfg_col_nick_more; -int cfg_col_nick_sep; -int cfg_col_nick_self; -int cfg_col_nick_colors[GUI_COLOR_WIN_NICK_NUMBER]; -int cfg_col_nick_private; -int cfg_col_nick_bg; +int cfg_col_nicklist; int cfg_col_nicklist_bg; -int cfg_col_dcc_selected; -int cfg_col_dcc_waiting; -int cfg_col_dcc_connecting; -int cfg_col_dcc_active; -int cfg_col_dcc_done; -int cfg_col_dcc_failed; -int cfg_col_dcc_aborted; - -t_config_option weechat_options_colors[] = +int cfg_col_nicklist_away; +int cfg_col_nicklist_prefix1; +int cfg_col_nicklist_prefix2; +int cfg_col_nicklist_prefix3; +int cfg_col_nicklist_prefix4; +int cfg_col_nicklist_prefix5; +int cfg_col_nicklist_more; +int cfg_col_nicklist_separator; +int cfg_col_info; +int cfg_col_info_bg; +int cfg_col_info_waiting; +int cfg_col_info_connecting; +int cfg_col_info_active; +int cfg_col_info_done; +int cfg_col_info_failed; +int cfg_col_info_aborted; + +struct t_config_option weechat_options_colors[] = { /* general color settings */ - { "col_real_white", N_("if set, uses real white color"), - N_("if set, uses real white color, disabled by default for terms with white " - "background (if you never use white background, you should turn on " - "this option to see real white instead of default term foreground color)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_col_real_white, NULL, config_change_color }, - { "col_separator", N_("color for window separators (when splited)"), + { "col_separator", N_("color for window separators (when splited)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_separator, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_SEPARATOR, "blue", NULL, + &cfg_col_separator, NULL, weechat_config_change_color }, + /* title window */ - { "col_title", N_("color for title bar"), + { "col_title", N_("color for title bar"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_title, NULL, &config_change_color }, - { "col_title_more", N_("color for '+' when scrolling topic"), - N_("color for '+' when scrolling topic"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightmagenta", NULL, &cfg_col_title_more, NULL, &config_change_color }, - { "col_title_bg", N_("background for title bar"), - N_("background for title bar"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_title_bg, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_TITLE, "default", NULL, + &cfg_col_title, NULL, weechat_config_change_color }, + { "col_title_bg", + N_("background color for title bar"), + OPTION_TYPE_COLOR, 0, 0, -1, "blue", NULL, + &cfg_col_title_bg, NULL, weechat_config_change_color }, + { "col_title_more", + N_("color for '+' when scrolling title"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_TITLE_MORE, "lightmagenta", NULL, + &cfg_col_title_more, NULL, weechat_config_change_color }, /* chat window */ - { "col_chat", N_("color for chat text"), + { "col_chat", N_("color for chat text"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_chat, NULL, &config_change_color }, - { "col_chat_time", N_("color for time"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT, "default", NULL, + &cfg_col_chat, NULL, weechat_config_change_color }, + { "col_chat_bg", + N_("background for chat text"), + OPTION_TYPE_COLOR, 0, 0, -1, "default", NULL, + &cfg_col_chat_bg, NULL, weechat_config_change_color }, + { "col_chat_time", N_("color for time in chat window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_chat_time, NULL, &config_change_color }, - { "col_chat_time_sep", N_("color for time separator"), - N_("color for time separator (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "brown", NULL, &cfg_col_chat_time_sep, NULL, &config_change_color }, - { "col_chat_prefix1", N_("color for 1st and 3rd char of prefix"), - N_("color for 1st and 3rd char of prefix"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightcyan", NULL, &cfg_col_chat_prefix1, NULL, &config_change_color }, - { "col_chat_prefix2", N_("color for middle char of prefix"), - N_("color for middle char of prefix"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_chat_prefix2, NULL, &config_change_color }, - { "col_chat_server", N_("color for server name"), - N_("color for server name"), - OPTION_TYPE_COLOR, 0, 0, 0, - "brown", NULL, &cfg_col_chat_server, NULL, &config_change_color }, - { "col_chat_join", N_("color for join arrow (prefix)"), - N_("color for join arrow (prefix)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_chat_join, NULL, &config_change_color }, - { "col_chat_part", N_("color for part/quit arrow (prefix)"), - N_("color for part/quit arrow (prefix)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightred", NULL, &cfg_col_chat_part, NULL, &config_change_color }, - { "col_chat_nick", N_("color for nicks in actions"), - N_("color for nicks in actions (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightcyan", NULL, &cfg_col_chat_nick, NULL, &config_change_color }, - { "col_chat_host", N_("color for hostnames"), - N_("color for hostnames (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_chat_host, NULL, &config_change_color }, - { "col_chat_channel", N_("color for channel names in actions"), - N_("color for channel names in actions (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_chat_channel, NULL, &config_change_color }, - { "col_chat_dark", N_("color for dark separators"), - N_("color for dark separators (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "green", NULL, &cfg_col_chat_dark, NULL, &config_change_color }, - { "col_chat_highlight", N_("color for highlighted nick"), - N_("color for highlighted nick (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "yellow", NULL, &cfg_col_chat_highlight, NULL, &config_change_color }, - { "col_chat_bg", N_("background for chat"), - N_("background for chat window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_chat_bg, NULL, &config_change_color }, - { "col_chat_read_marker", N_("color for unread data marker"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_TIME, "default", NULL, + &cfg_col_chat_time, NULL, weechat_config_change_color }, + { "col_chat_time_delimiters", + N_("color for time delimiters)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_TIME_DELIMITERS, "brown", NULL, + &cfg_col_chat_time_delimiters, NULL, weechat_config_change_color }, + { "col_chat_prefix_info", + N_("color for info prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_INFO, "lightcyan", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_INFO], NULL, weechat_config_change_color }, + { "col_chat_prefix_error", + N_("color for error prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_ERROR, "yellow", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_ERROR], NULL, weechat_config_change_color }, + { "col_chat_prefix_network", + N_("color for network prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_NETWORK, "lightmagenta", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_NETWORK], NULL, weechat_config_change_color }, + { "col_chat_prefix_action", + N_("color for action prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_ACTION, "white", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_ACTION], NULL, weechat_config_change_color }, + { "col_chat_prefix_join", + N_("color for join prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_JOIN, "lightgreen", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_JOIN], NULL, weechat_config_change_color }, + { "col_chat_prefix_quit", + N_("color for quit prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_QUIT, "lightred", NULL, + &cfg_col_chat_prefix[GUI_CHAT_PREFIX_QUIT], NULL, weechat_config_change_color }, + { "col_chat_prefix_more", + N_("color for '+' when prefix is too long"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_MORE, "lightmagenta", NULL, + &cfg_col_chat_prefix_more, NULL, weechat_config_change_color }, + { "col_chat_prefix_suffix", + N_("color for text after prefix"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_PREFIX_SUFFIX, "blue", NULL, + &cfg_col_chat_prefix_suffix, NULL, weechat_config_change_color }, + { "col_chat_buffer", + N_("color for buffer names"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_BUFFER, "white", NULL, + &cfg_col_chat_buffer, NULL, weechat_config_change_color }, + { "col_chat_server", + N_("color for server names"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_SERVER, "brown", NULL, + &cfg_col_chat_server, NULL, weechat_config_change_color }, + { "col_chat_channel", + N_("color for channel names"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_CHANNEL, "white", NULL, + &cfg_col_chat_channel, NULL, weechat_config_change_color }, + { "col_chat_nick", + N_("color for nicks"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK, "lightcyan", NULL, + &cfg_col_chat_nick, NULL, weechat_config_change_color }, + { "col_chat_nick_self", + N_("color for local nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK_SELF, "white", NULL, + &cfg_col_chat_nick_self, NULL, weechat_config_change_color }, + { "col_chat_nick_other", + N_("color for other nick in private buffer"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK_OTHER, "default", NULL, + &cfg_col_chat_nick_other, NULL, weechat_config_change_color }, + { "col_chat_nick_color1", + N_("color #1 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK1, "cyan", NULL, + &cfg_col_chat_nick_colors[0], NULL, weechat_config_change_color }, + { "col_chat_nick_color2", + N_("color #2 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK2, "magenta", NULL, + &cfg_col_chat_nick_colors[1], NULL, weechat_config_change_color }, + { "col_chat_nick_color3", + N_("color #3 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK3, "green", NULL, + &cfg_col_chat_nick_colors[2], NULL, weechat_config_change_color }, + { "col_chat_nick_color4", + N_("color #4 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK4, "brown", NULL, + &cfg_col_chat_nick_colors[3], NULL, weechat_config_change_color }, + { "col_chat_nick_color5", + N_("color #5 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK5, "lightblue", NULL, + &cfg_col_chat_nick_colors[4], NULL, weechat_config_change_color }, + { "col_chat_nick_color6", + N_("color #6 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK6, "default", NULL, + &cfg_col_chat_nick_colors[5], NULL, weechat_config_change_color }, + { "col_chat_nick_color7", + N_("color #7 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK7, "lightcyan", NULL, + &cfg_col_chat_nick_colors[6], NULL, weechat_config_change_color }, + { "col_chat_nick_color8", + N_("color #8 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK8, "lightmagenta", NULL, + &cfg_col_chat_nick_colors[7], NULL, weechat_config_change_color }, + { "col_chat_nick_color9", + N_("color #9 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK9, "lightgreen", NULL, + &cfg_col_chat_nick_colors[8], NULL, weechat_config_change_color }, + { "col_chat_nick_color10", + N_("color #10 for nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_NICK10, "blue", NULL, + &cfg_col_chat_nick_colors[9], NULL, weechat_config_change_color }, + { "col_chat_host", + N_("color for hostnames"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_HOST, "cyan", NULL, + &cfg_col_chat_host, NULL, weechat_config_change_color }, + { "col_chat_delimiters", + N_("color for delimiters"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_DELIMITERS, "green", NULL, + &cfg_col_chat_delimiters, NULL, weechat_config_change_color }, + { "col_chat_highlight", + N_("color for highlighted nick"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_HIGHLIGHT, "yellow", NULL, + &cfg_col_chat_highlight, NULL, weechat_config_change_color }, + { "col_chat_read_marker", N_("color for unread data marker"), - OPTION_TYPE_COLOR, 0, 0, 0, - "yellow", NULL, &cfg_col_chat_read_marker, NULL, &config_change_color }, - { "col_chat_read_marker_bg", N_("background for unread data marker"), - N_("background for unread data marker"), - OPTION_TYPE_COLOR, 0, 0, 0, - "magenta", NULL, &cfg_col_chat_read_marker_bg, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_CHAT_READ_MARKER, "yellow", NULL, + &cfg_col_chat_read_marker, NULL, weechat_config_change_color }, + { "col_chat_read_marker_bg", + N_("background color for unread data marker"), + OPTION_TYPE_COLOR, 0, 0, -1, "magenta", NULL, + &cfg_col_chat_read_marker_bg, NULL, weechat_config_change_color }, /* status window */ - { "col_status", N_("color for status bar"), + { "col_status", N_("color for status bar"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_status, NULL, &config_change_color }, - { "col_status_delimiters", N_("color for status bar delimiters"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS, "default", NULL, + &cfg_col_status, NULL, weechat_config_change_color }, + { "col_status_bg", + N_("background color for status bar"), + OPTION_TYPE_COLOR, 0, 0, -1, "blue", NULL, + &cfg_col_status_bg, NULL, weechat_config_change_color }, + { "col_status_delimiters", N_("color for status bar delimiters"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_status_delimiters, NULL, &config_change_color }, - { "col_status_channel", N_("color for current channel in status bar"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_DELIMITERS, "cyan", NULL, + &cfg_col_status_delimiters, NULL, weechat_config_change_color }, + { "col_status_channel", N_("color for current channel in status bar"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_status_channel, NULL, &config_change_color }, - { "col_status_data_msg", N_("color for window with new messages"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_CHANNEL, "white", NULL, + &cfg_col_status_channel, NULL, weechat_config_change_color }, + { "col_status_data_msg", N_("color for window with new messages (status bar)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "yellow", NULL, &cfg_col_status_data_msg, NULL, &config_change_color }, - { "col_status_private", N_("color for window with private message"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_DATA_MSG, "yellow", NULL, + &cfg_col_status_data_msg, NULL, weechat_config_change_color }, + { "col_status_data_private", N_("color for window with private message (status bar)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightmagenta", NULL, &cfg_col_status_data_private, NULL, &config_change_color }, - { "col_status_highlight", N_("color for window with highlight"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_DATA_PRIVATE, "lightmagenta", NULL, + &cfg_col_status_data_private, NULL, weechat_config_change_color }, + { "col_status_data_highlight", N_("color for window with highlight (status bar)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightred", NULL, &cfg_col_status_data_highlight, NULL, &config_change_color }, - { "col_status_data_other", N_("color for window with new data (not messages)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_DATA_HIGHLIGHT, "lightred", NULL, + &cfg_col_status_data_highlight, NULL, weechat_config_change_color }, + { "col_status_data_other", N_("color for window with new data (not messages) (status bar)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_status_data_other, NULL, &config_change_color }, - { "col_status_more", N_("color for \"-MORE-\" text"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_DATA_OTHER, "default", NULL, + &cfg_col_status_data_other, NULL, weechat_config_change_color }, + { "col_status_more", N_("color for window with new data (status bar)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_status_more, NULL, &config_change_color }, - { "col_status_bg", N_("background for status window"), - N_("background for status window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_status_bg, NULL, &config_change_color }, - + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_STATUS_MORE, "white", NULL, + &cfg_col_status_more, NULL, weechat_config_change_color }, + /* infobar window */ - { "col_infobar", N_("color for info bar text"), + { "col_infobar", N_("color for info bar text"), - OPTION_TYPE_COLOR, 0, 0, 0, - "black", NULL, &cfg_col_infobar, NULL, &config_change_color }, - { "col_infobar_delimiters", N_("color for infobar delimiters"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFOBAR, "black", NULL, + &cfg_col_infobar, NULL, weechat_config_change_color }, + { "col_infobar_bg", + N_("background color for info bar text"), + OPTION_TYPE_COLOR, 0, 0, -1, "cyan", NULL, + &cfg_col_infobar_bg, NULL, weechat_config_change_color }, + { "col_infobar_delimiters", N_("color for infobar delimiters"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_infobar_delimiters, NULL, &config_change_color }, - { "col_infobar_highlight", N_("color for info bar highlight notification"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFOBAR_DELIMITERS, "blue", NULL, + &cfg_col_infobar_delimiters, NULL, weechat_config_change_color }, + { "col_infobar_highlight", N_("color for info bar highlight notification"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_infobar_highlight, NULL, &config_change_color }, - { "col_infobar_bg", N_("background for info bar window"), - N_("background for info bar window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_infobar_bg, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFOBAR_HIGHLIGHT, "white", NULL, + &cfg_col_infobar_highlight, NULL, weechat_config_change_color }, /* input window */ - { "col_input", N_("color for input text"), + { "col_input", N_("color for input text"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_input, NULL, &config_change_color }, - { "col_input_server", N_("color for input text (server name)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT, "default", NULL, + &cfg_col_input, NULL, weechat_config_change_color }, + { "col_input_bg", + N_("background color for input text"), + OPTION_TYPE_COLOR, 0, 0, -1, "default", NULL, + &cfg_col_input_bg, NULL, weechat_config_change_color }, + { "col_input_server", N_("color for input text (server name)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "brown", NULL, &cfg_col_input_server, NULL, &config_change_color }, - { "col_input_channel", N_("color for input text (channel name)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_SERVER, "brown", NULL, + &cfg_col_input_server, NULL, weechat_config_change_color }, + { "col_input_channel", N_("color for input text (channel name)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_input_channel, NULL, &config_change_color }, - { "col_input_nick", N_("color for input text (nick name)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_CHANNEL, "white", NULL, + &cfg_col_input_channel, NULL, weechat_config_change_color }, + { "col_input_nick", N_("color for input text (nick name)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightcyan", NULL, &cfg_col_input_nick, NULL, &config_change_color }, - { "col_input_delimiters", N_("color for input text (delimiters)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_NICK, "lightcyan", NULL, + &cfg_col_input_nick, NULL, weechat_config_change_color }, + { "col_input_delimiters", N_("color for input text (delimiters)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_input_delimiters, NULL, &config_change_color }, - { "col_input_text_not_found", N_("color for text not found"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_DELIMITERS, "cyan", NULL, + &cfg_col_input_delimiters, NULL, weechat_config_change_color }, + { "col_input_text_not_found", N_("color for text not found"), - OPTION_TYPE_COLOR, 0, 0, 0, - "red", NULL, &cfg_col_input_text_not_found, NULL, &config_change_color }, - { "col_input_actions", N_("color for actions in input window"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_TEXT_NOT_FOUND, "red", NULL, + &cfg_col_input_text_not_found, NULL, weechat_config_change_color }, + { "col_input_actions", N_("color for actions in input window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_input_actions, NULL, &config_change_color }, - { "col_input_bg", N_("background for input window"), - N_("background for input window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_input_bg, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INPUT_ACTIONS, "lightgreen", NULL, + &cfg_col_input_actions, NULL, weechat_config_change_color }, - /* nick window */ - { "col_nick", N_("color for nicknames"), - N_("color for nicknames"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_nick, NULL, &config_change_color }, - { "col_nick_away", N_("color for away nicknames"), + /* nicklist window */ + { "col_nicklist", + N_("color for nicklist"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST, "default", NULL, + &cfg_col_nicklist, NULL, weechat_config_change_color }, + { "col_nicklist_bg", + N_("background color for nicklist"), + OPTION_TYPE_COLOR, 0, 0, -1, "default", NULL, + &cfg_col_nicklist_bg, NULL, weechat_config_change_color }, + { "col_nicklist_away", N_("color for away nicknames"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_nick_away, NULL, &config_change_color }, - { "col_nick_chanowner", N_("color for chan owner symbol"), - N_("color for chan owner symbol (specific to unrealircd)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_nick_chanowner, NULL, &config_change_color }, - { "col_nick_chanadmin", N_("color for chan admin symbol"), - N_("color for chan admin symbol (specific to unrealircd)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_nick_chanadmin, NULL, &config_change_color }, - { "col_nick_op", N_("color for operator symbol"), - N_("color for operator symbol"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_nick_op, NULL, &config_change_color }, - { "col_nick_halfop", N_("color for half-operator symbol"), - N_("color for half-operator symbol"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightmagenta", NULL, &cfg_col_nick_halfop, NULL, &config_change_color }, - { "col_nick_voice", N_("color for voice symbol"), - N_("color for voice symbol"), - OPTION_TYPE_COLOR, 0, 0, 0, - "yellow", NULL, &cfg_col_nick_voice, NULL, &config_change_color }, - { "col_nick_user", N_("color for user symbol"), - N_("color for user symbol"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_nick_user, NULL, &config_change_color }, - { "col_nick_more", N_("color for '+' when scrolling nicks"), - N_("color for '+' when scrolling nicks"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightmagenta", NULL, &cfg_col_nick_more, NULL, &config_change_color }, - { "col_nick_sep", N_("color for nick separator"), - N_("color for nick separator"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_nick_sep, NULL, &config_change_color }, - { "col_nick_self", N_("color for local nick"), - N_("color for local nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_nick_self, NULL, &config_change_color }, - { "col_nick_color1", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "cyan", NULL, &cfg_col_nick_colors[0], NULL, &config_change_color }, - { "col_nick_color2", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "magenta", NULL, &cfg_col_nick_colors[1], NULL, &config_change_color }, - { "col_nick_color3", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "green", NULL, &cfg_col_nick_colors[2], NULL, &config_change_color }, - { "col_nick_color4", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "brown", NULL, &cfg_col_nick_colors[3], NULL, &config_change_color }, - { "col_nick_color5", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightblue", NULL, &cfg_col_nick_colors[4], NULL, &config_change_color }, - { "col_nick_color6", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_nick_colors[5], NULL, &config_change_color }, - { "col_nick_color7", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightcyan", NULL, &cfg_col_nick_colors[6], NULL, &config_change_color }, - { "col_nick_color8", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightmagenta", NULL, &cfg_col_nick_colors[7], NULL, &config_change_color }, - { "col_nick_color9", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_nick_colors[8], NULL, &config_change_color }, - { "col_nick_color10", N_("color for nick"), - N_("color for nick"), - OPTION_TYPE_COLOR, 0, 0, 0, - "blue", NULL, &cfg_col_nick_colors[9], NULL, &config_change_color }, - { "col_nick_private", N_("color for other nick in private window"), - N_("color for other nick in private window"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_nick_private, NULL, &config_change_color }, - { "col_nick_bg", N_("background for nicknames"), - N_("background for nicknames"), - OPTION_TYPE_COLOR, 0, 0, 0, - "default", NULL, &cfg_col_nick_bg, NULL, &config_change_color }, + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_AWAY, "cyan", NULL, + &cfg_col_nicklist_away, NULL, weechat_config_change_color }, + { "col_nicklist_prefix1", + N_("color for prefix 1"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_PREFIX1, "lightgreen", NULL, + &cfg_col_nicklist_prefix1, NULL, weechat_config_change_color }, + { "col_nicklist_prefix2", + N_("color for prefix 2"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_PREFIX2, "lightmagenta", NULL, + &cfg_col_nicklist_prefix2, NULL, weechat_config_change_color }, + { "col_nicklist_prefix3", + N_("color for prefix 3"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_PREFIX3, "yellow", NULL, + &cfg_col_nicklist_prefix3, NULL, weechat_config_change_color }, + { "col_nicklist_prefix4", + N_("color for prefix 4"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_PREFIX4, "blue", NULL, + &cfg_col_nicklist_prefix4, NULL, weechat_config_change_color }, + { "col_nicklist_prefix5", + N_("color for prefix 5"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_PREFIX5, "brown", NULL, + &cfg_col_nicklist_prefix5, NULL, weechat_config_change_color }, + { "col_nicklist_more", + N_("color for '+' when scrolling nicks (nicklist)"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_MORE, "lightmagenta", NULL, + &cfg_col_nicklist_more, NULL, weechat_config_change_color }, + { "col_nicklist_separator", + N_("color for nicklist separator"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_NICKLIST_SEPARATOR, "blue", NULL, + &cfg_col_nicklist_separator, NULL, weechat_config_change_color }, + + /* status info (for example: file transfers) */ + { "col_info", + N_("color for status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO, "default", NULL, + &cfg_col_info, NULL, weechat_config_change_color }, + { "col_info_bg", + N_("background color for status info"), + OPTION_TYPE_COLOR, 0, 0, -1, "default", NULL, + &cfg_col_info_bg, NULL, weechat_config_change_color }, + { "col_info_waiting", + N_("color for \"waiting\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_WAITING, "lightcyan", NULL, + &cfg_col_info_waiting, NULL, weechat_config_change_color }, + { "col_info_connecting", + N_("color for \"connecting\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_CONNECTING, "yellow", NULL, + &cfg_col_info_connecting, NULL, weechat_config_change_color }, + { "col_info_active", + N_("color for \"active\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_ACTIVE, "lightblue", NULL, + &cfg_col_info_active, NULL, weechat_config_change_color }, + { "col_info_done", + N_("color for \"done\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_DONE, "lightgreen", NULL, + &cfg_col_info_done, NULL, weechat_config_change_color }, + { "col_info_failed", + N_("color for \"failed\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_FAILED, "lightred", NULL, + &cfg_col_info_failed, NULL, weechat_config_change_color }, + { "col_info_aborted", + N_("color for \"aborted\" status info"), + OPTION_TYPE_COLOR, 0, 0, GUI_COLOR_INFO_ABORTED, "lightred", NULL, + &cfg_col_info_aborted, NULL, weechat_config_change_color }, - /* DCC */ - { "col_chat_dcc_selected", N_("color for selected DCC"), - N_("color for selected DCC (chat window)"), - OPTION_TYPE_COLOR, 0, 0, 0, - "white", NULL, &cfg_col_dcc_selected, NULL, &config_change_color }, - { "col_dcc_waiting", N_("color for \"waiting\" dcc status"), - N_("color for \"waiting\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightcyan", NULL, &cfg_col_dcc_waiting, NULL, &config_change_color }, - { "col_dcc_connecting", N_("color for \"connecting\" dcc status"), - N_("color for \"connecting\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "yellow", NULL, &cfg_col_dcc_connecting, NULL, &config_change_color }, - { "col_dcc_active", N_("color for \"active\" dcc status"), - N_("color for \"active\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightblue", NULL, &cfg_col_dcc_active, NULL, &config_change_color }, - { "col_dcc_done", N_("color for \"done\" dcc status"), - N_("color for \"done\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightgreen", NULL, &cfg_col_dcc_done, NULL, &config_change_color }, - { "col_dcc_failed", N_("color for \"failed\" dcc status"), - N_("color for \"failed\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightred", NULL, &cfg_col_dcc_failed, NULL, &config_change_color }, - { "col_dcc_aborted", N_("color for \"aborted\" dcc status"), - N_("color for \"aborted\" dcc status"), - OPTION_TYPE_COLOR, 0, 0, 0, - "lightred", NULL, &cfg_col_dcc_aborted, NULL, &config_change_color }, - - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; /* config, history section */ @@ -686,227 +691,45 @@ int cfg_history_max_lines; int cfg_history_max_commands; int cfg_history_display_default; -t_config_option weechat_options_history[] = -{ { "history_max_lines", N_("max lines in history (per window)"), +struct t_config_option weechat_options_history[] = +{ { "history_max_lines", N_("maximum number of lines in history " "for one server/channel/private window (0 = unlimited)"), - OPTION_TYPE_INT, 0, INT_MAX, 4096, - NULL, NULL, &cfg_history_max_lines, NULL, &config_change_noop }, - { "history_max_commands", N_("max user commands in history"), + OPTION_TYPE_INT, 0, INT_MAX, 4096, NULL, NULL, + &cfg_history_max_lines, NULL, weechat_config_change_noop }, + { "history_max_commands", N_("maximum number of user commands in history (0 = unlimited)"), - OPTION_TYPE_INT, 0, INT_MAX, 100, - NULL, NULL, &cfg_history_max_commands, NULL, &config_change_noop }, - { "history_display_default", N_("max commands to display"), - N_("maximum number of commands to display by default in history listing (0 = unlimited)"), - OPTION_TYPE_INT, 0, INT_MAX, 5, - NULL, NULL, &cfg_history_display_default, NULL, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + OPTION_TYPE_INT, 0, INT_MAX, 100, NULL, NULL, + &cfg_history_max_commands, NULL, weechat_config_change_noop }, + { "history_display_default", + N_("maximum number of commands to display by default in history listing " + "(0 = unlimited)"), + OPTION_TYPE_INT, 0, INT_MAX, 5, NULL, NULL, + &cfg_history_display_default, NULL, weechat_config_change_noop }, + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; /* config, log section */ -int cfg_log_auto_server; -int cfg_log_auto_channel; -int cfg_log_auto_private; int cfg_log_plugin_msg; char *cfg_log_path; -char *cfg_log_timestamp; -int cfg_log_hide_nickserv_pwd; - -t_config_option weechat_options_log[] = -{ { "log_auto_server", N_("automatically log server messages"), - N_("automatically log server messages"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_log_auto_server, NULL, &config_change_log }, - { "log_auto_channel", N_("automatically log channel chats"), - N_("automatically log channel chats"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_log_auto_channel, NULL, &config_change_log }, - { "log_auto_private", N_("automatically log private chats"), - N_("automatically log private chats"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_log_auto_private, NULL, &config_change_log }, - { "log_plugin_msg", N_("log messages from plugins (scripts)"), - N_("log messages from plugins (scripts)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_log_plugin_msg, NULL, &config_change_noop }, - { "log_path", N_("path for log files"), +char *cfg_log_time_format; + +struct t_config_option weechat_options_log[] = +{ { "log_plugin_msg", + N_("log messages from plugins"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_log_plugin_msg, NULL, weechat_config_change_noop }, + { "log_path", N_("path for WeeChat log files ('%h' will be replaced by WeeChat home, " "~/.weechat by default)"), - OPTION_TYPE_STRING, 0, 0, 0, - "%h/logs/", NULL, NULL, &cfg_log_path, &config_change_noop }, - { "log_timestamp", N_("timestamp for log"), - N_("timestamp for log (see man strftime for date/time specifiers)"), - OPTION_TYPE_STRING, 0, 0, 0, - "%Y %b %d %H:%M:%S", NULL, NULL, &cfg_log_timestamp, &config_change_noop }, - { "log_hide_nickserv_pwd", N_("hide password displayed by nickserv"), - N_("hide password displayed by nickserv"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_log_hide_nickserv_pwd, NULL, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } -}; - -/* config, irc section */ - -int cfg_irc_display_away; -int cfg_irc_show_away_once; -char *cfg_irc_display_away_values[] = -{ "off", "local", "channel", NULL }; -char *cfg_irc_default_msg_part; -char *cfg_irc_default_msg_quit; -int cfg_irc_notice_as_pv; -int cfg_irc_away_check; -int cfg_irc_away_check_max_nicks; -int cfg_irc_lag_check; -int cfg_irc_lag_min_show; -int cfg_irc_lag_disconnect; -int cfg_irc_anti_flood; -int cfg_irc_fifo_pipe; -char *cfg_irc_highlight; -int cfg_irc_colors_receive; -int cfg_irc_colors_send; -int cfg_irc_send_unknown_commands; - -t_config_option weechat_options_irc[] = -{ { "irc_display_away", N_("display message for away"), - N_("display message when (un)marking as away"), - OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, - "off", cfg_irc_display_away_values, &cfg_irc_display_away, NULL, &config_change_noop }, - { "irc_show_away_once", N_("show remote away message only once in private"), - N_("show remote away message only once in private"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_irc_show_away_once, NULL, &config_change_noop }, - { "irc_default_msg_part", N_("default part message (leaving channel)"), - N_("default part message (leaving channel) ('%v' will be replaced by " - "WeeChat version in string)"), - OPTION_TYPE_STRING, 0, 0, 0, - "WeeChat %v", NULL, NULL, &cfg_irc_default_msg_part, &config_change_noop }, - { "irc_default_msg_quit", N_("default quit message"), - N_("default quit message ('%v' will be replaced by WeeChat version in string)"), - OPTION_TYPE_STRING, 0, 0, 0, - "WeeChat %v", NULL, NULL, &cfg_irc_default_msg_quit, &config_change_noop }, - { "irc_notice_as_pv", N_("display notices as private messages"), - N_("display notices as private messages"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_irc_notice_as_pv, NULL, &config_change_noop }, - { "irc_away_check", N_("interval between two checks for away"), - N_("interval between two checks for away (in minutes, 0 = never check)"), - OPTION_TYPE_INT, 0, INT_MAX, 0, - NULL, NULL, &cfg_irc_away_check, NULL, &config_change_away_check }, - { "irc_away_check_max_nicks", N_("max number of nicks for away check"), - N_("do not check away nicks on channels with high number of nicks (0 = unlimited)"), - OPTION_TYPE_INT, 0, INT_MAX, 0, - NULL, NULL, &cfg_irc_away_check_max_nicks, NULL, &config_change_away_check }, - { "irc_lag_check", N_("interval between two checks for lag"), - N_("interval between two checks for lag (in seconds)"), - OPTION_TYPE_INT, 30, INT_MAX, 60, - NULL, NULL, &cfg_irc_lag_check, NULL, &config_change_noop }, - { "irc_lag_min_show", N_("minimum lag to show"), - N_("minimum lag to show (in seconds)"), - OPTION_TYPE_INT, 0, INT_MAX, 1, - NULL, NULL, &cfg_irc_lag_min_show, NULL, &config_change_noop }, - { "irc_lag_disconnect", N_("disconnect after important lag"), - N_("disconnect after important lag (in minutes, 0 = never disconnect)"), - OPTION_TYPE_INT, 0, INT_MAX, 5, - NULL, NULL, &cfg_irc_lag_disconnect, NULL, &config_change_noop }, - { "irc_anti_flood", N_("anti-flood"), - N_("anti-flood: # seconds between two user messages (0 = no anti-flood)"), - OPTION_TYPE_INT, 0, 5, 2, - NULL, NULL, &cfg_irc_anti_flood, NULL, &config_change_noop }, - { "irc_fifo_pipe", N_("create a FIFO pipe for remote control"), - N_("create a FIFO pipe for remote control"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_irc_fifo_pipe, NULL, &config_change_fifo_pipe }, - { "irc_highlight", N_("list of words to highlight"), - N_("comma separated list of words to highlight (case insensitive comparison, " - "words may begin or end with \"*\" for partial match)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_irc_highlight, &config_change_noop }, - { "irc_colors_receive", N_("when off, colors codes are ignored in " - "incoming messages"), - N_("when off, colors codes are ignored in incoming messages"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_irc_colors_receive, NULL, config_change_noop }, - { "irc_colors_send", N_("allow user to send colors"), - N_("allow user to send colors with special codes (^Cb=bold, ^Ccxx=color, " - "^Ccxx,yy=color+background, ^Cu=underline, ^Cr=reverse)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_irc_colors_send, NULL, config_change_noop }, - { "irc_send_unknown_commands", N_("send unknown commands to IRC server"), - N_("send unknown commands to IRC server"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_irc_send_unknown_commands, NULL, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } -}; - -/* config, dcc section */ - -int cfg_dcc_auto_accept_files; -int cfg_dcc_auto_accept_chats; -int cfg_dcc_timeout; -int cfg_dcc_blocksize; -int cfg_dcc_fast_send; -char *cfg_dcc_port_range; -char *cfg_dcc_own_ip; -char *cfg_dcc_download_path; -char *cfg_dcc_upload_path; -int cfg_dcc_convert_spaces; -int cfg_dcc_auto_rename; -int cfg_dcc_auto_resume; - -t_config_option weechat_options_dcc[] = -{ { "dcc_auto_accept_files", N_("automatically accept dcc files"), - N_("automatically accept incoming dcc files"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_dcc_auto_accept_files, NULL, &config_change_noop }, - { "dcc_auto_accept_chats", N_("automatically accept dcc chats"), - N_("automatically accept dcc chats (use carefully!)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_dcc_auto_accept_chats, NULL, &config_change_noop }, - { "dcc_timeout", N_("timeout for dcc request"), - N_("timeout for dcc request (in seconds)"), - OPTION_TYPE_INT, 5, INT_MAX, 300, - NULL, NULL, &cfg_dcc_timeout, NULL, &config_change_noop }, - { "dcc_blocksize", N_("block size for dcc packets"), - N_("block size for dcc packets in bytes (default: 65536)"), - OPTION_TYPE_INT, IRC_DCC_MIN_BLOCKSIZE, IRC_DCC_MAX_BLOCKSIZE, 65536, - NULL, NULL, &cfg_dcc_blocksize, NULL, &config_change_noop }, - { "dcc_fast_send", N_("does not wait for ACK when sending file"), - N_("does not wait for ACK when sending file"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_dcc_fast_send, NULL, &config_change_noop }, - { "dcc_port_range", N_("allowed ports for outgoing dcc"), - N_("restricts outgoing dcc to use only ports in the given range " - "(useful for NAT) (syntax: a single port, ie. 5000 or a port " - "range, ie. 5000-5015, empty value means any port)"), - OPTION_TYPE_STRING, 0, 0, 0, "", - NULL, NULL, &cfg_dcc_port_range, &config_change_noop }, - { "dcc_own_ip", N_("IP address for outgoing dcc"), - N_("IP or DNS address used for outgoing dcc " - "(if empty, local interface IP is used)"), - OPTION_TYPE_STRING, 0, 0, 0, "", - NULL, NULL, &cfg_dcc_own_ip, &config_change_noop }, - { "dcc_download_path", N_("path for incoming files with dcc"), - N_("path for writing incoming files with dcc (default: user home)"), - OPTION_TYPE_STRING, 0, 0, 0, - "%h/dcc", NULL, NULL, &cfg_dcc_download_path, &config_change_noop }, - { "dcc_upload_path", N_("default path for sending files with dcc"), - N_("path for reading files when sending thru dcc (when no path is specified)"), - OPTION_TYPE_STRING, 0, 0, 0, "~", - NULL, NULL, &cfg_dcc_upload_path, &config_change_noop }, - { "dcc_convert_spaces", N_("convert spaces to underscores when sending files"), - N_("convert spaces to underscores when sending files"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_dcc_convert_spaces, NULL, &config_change_noop }, - { "dcc_auto_rename", N_("automatically rename dcc files if already exists"), - N_("rename incoming files if already exists (add '.1', '.2', ...)"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_dcc_auto_rename, NULL, &config_change_noop }, - { "dcc_auto_resume", N_("automatically resume aborted transfers"), - N_("automatically resume dcc transfer if connection with remote host is loosed"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_dcc_auto_resume, NULL, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + OPTION_TYPE_STRING, 0, 0, 0, "%h/logs/", NULL, + NULL, &cfg_log_path, weechat_config_change_noop }, + { "log_time_format", + N_("time format for log (see man strftime for date/time specifiers)"), + OPTION_TYPE_STRING, 0, 0, 0, "%Y %b %d %H:%M:%S", NULL, + NULL, &cfg_log_time_format, weechat_config_change_noop }, + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; /* config, proxy section */ @@ -921,36 +744,36 @@ int cfg_proxy_port; char *cfg_proxy_username; char *cfg_proxy_password; -t_config_option weechat_options_proxy[] = -{ { "proxy_use", N_("use proxy"), +struct t_config_option weechat_options_proxy[] = +{ { "proxy_use", N_("use a proxy server to connect to irc server"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_proxy_use, NULL, &config_change_noop }, - { "proxy_type", N_("proxy type"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_proxy_use, NULL, weechat_config_change_noop }, + { "proxy_type", N_("proxy type (http (default), socks4, socks5)"), - OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, - "http", cfg_proxy_type_values, &cfg_proxy_type, NULL, &config_change_noop }, - { "proxy_ipv6", N_("use ipv6 proxy"), + OPTION_TYPE_INT_WITH_STRING, 0, 0, 0, "http", cfg_proxy_type_values, + &cfg_proxy_type, NULL, weechat_config_change_noop }, + { "proxy_ipv6", N_("connect to proxy in ipv6"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_proxy_ipv6, NULL, &config_change_noop }, - { "proxy_address", N_("proxy address"), + OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, NULL, NULL, + &cfg_proxy_ipv6, NULL, weechat_config_change_noop }, + { "proxy_address", N_("proxy server address (IP or hostname)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_proxy_address, &config_change_noop }, - { "proxy_port", N_("port for proxy"), + OPTION_TYPE_STRING, 0, 0, 0, "", NULL, + NULL, &cfg_proxy_address, weechat_config_change_noop }, + { "proxy_port", N_("port for connecting to proxy server"), - OPTION_TYPE_INT, 0, 65535, 3128, - NULL, NULL, &cfg_proxy_port, NULL, &config_change_noop }, - { "proxy_username", N_("proxy username"), + OPTION_TYPE_INT, 0, 65535, 3128, NULL, NULL, + &cfg_proxy_port, NULL, weechat_config_change_noop }, + { "proxy_username", N_("username for proxy server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_proxy_username, &config_change_noop }, - { "proxy_password", N_("proxy password"), + OPTION_TYPE_STRING, 0, 0, 0, "", NULL, + NULL, &cfg_proxy_username, weechat_config_change_noop }, + { "proxy_password", N_("password for proxy server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_proxy_password, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + OPTION_TYPE_STRING, 0, 0, 0, "", NULL, + NULL, &cfg_proxy_password, weechat_config_change_noop }, + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; /* config, plugins section */ @@ -959,19 +782,19 @@ char *cfg_plugins_path; char *cfg_plugins_autoload; char *cfg_plugins_extension; -t_config_option weechat_options_plugins[] = -{ { "plugins_path", N_("path for searching plugins"), +struct t_config_option weechat_options_plugins[] = +{ { "plugins_path", N_("path for searching plugins ('%h' will be replaced by WeeChat home, " "~/.weechat by default)"), - OPTION_TYPE_STRING, 0, 0, 0, - "%h/plugins", NULL, NULL, &cfg_plugins_path, &config_change_noop }, - { "plugins_autoload", N_("list of plugins to load automatically"), + OPTION_TYPE_STRING, 0, 0, 0, "%h/plugins", NULL, + NULL, &cfg_plugins_path, weechat_config_change_noop }, + { "plugins_autoload", N_("comma separated list of plugins to load automatically at startup, " "\"*\" means all plugins found " - "(names may be partial, for example \"perl\" is ok for \"libperl.so\")"), - OPTION_TYPE_STRING, 0, 0, 0, - "*", NULL, NULL, &cfg_plugins_autoload, &config_change_noop }, - { "plugins_extension", N_("standard plugins extension in filename"), + "(names may be partial, for example \"perl\" is ok for \"perl.so\")"), + OPTION_TYPE_STRING, 0, 0, 0, "*", NULL, + NULL, &cfg_plugins_autoload, weechat_config_change_noop }, + { "plugins_extension", N_("standard plugins extension in filename, used for autoload " "(if empty, then all files are loaded when autoload is \"*\")"), OPTION_TYPE_STRING, 0, 0, 0, @@ -980,1298 +803,332 @@ t_config_option weechat_options_plugins[] = #else ".so", #endif - NULL, NULL, &cfg_plugins_extension, &config_change_noop }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } + NULL, + NULL, &cfg_plugins_extension, weechat_config_change_noop }, + { NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; -/* config, server section */ - -static t_irc_server cfg_server; - -t_config_option weechat_options_server[] = -{ { "server_name", N_("server name"), - N_("name associated to IRC server (for display only)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.name), NULL }, - { "server_autoconnect", N_("automatically connect to server"), - N_("automatically connect to server when WeeChat is starting"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &(cfg_server.autoconnect), NULL, NULL }, - { "server_autoreconnect", N_("automatically reconnect to server"), - N_("automatically reconnect to server when disconnected"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &(cfg_server.autoreconnect), NULL, NULL }, - { "server_autoreconnect_delay", N_("delay before trying again to reconnect"), - N_("delay (in seconds) before trying again to reconnect to server"), - OPTION_TYPE_INT, 0, 65535, 30, - NULL, NULL, &(cfg_server.autoreconnect_delay), NULL, NULL }, - { "server_address", N_("server address or hostname"), - N_("IP address or hostname of IRC server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.address), NULL }, - { "server_port", N_("port for IRC server"), - N_("port for connecting to server"), - OPTION_TYPE_INT, 0, 65535, 6667, - NULL, NULL, &(cfg_server.port), NULL, NULL }, - { "server_ipv6", N_("use IPv6 protocol for server communication"), - N_("use IPv6 protocol for server communication"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &(cfg_server.ipv6), NULL, NULL }, - { "server_ssl", N_("use SSL for server communication"), - N_("use SSL for server communication"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &(cfg_server.ssl), NULL, NULL }, - { "server_password", N_("server password"), - N_("password for IRC server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.password), NULL }, - { "server_nick1", N_("nickname for server"), - N_("nickname to use on IRC server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.nick1), NULL }, - { "server_nick2", N_("alternate nickname for server"), - N_("alternate nickname to use on IRC server (if nickname is already used)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.nick2), NULL }, - { "server_nick3", N_("2nd alternate nickname for server"), - N_("2nd alternate nickname to use on IRC server (if alternate nickname is already used)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.nick3), NULL }, - { "server_username", N_("user name for server"), - N_("user name to use on IRC server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.username), NULL }, - { "server_realname", N_("real name for server"), - N_("real name to use on IRC server"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.realname), NULL }, - { "server_hostname", N_("custom hostname/IP for server"), - N_("custom hostname/IP for server (optional, if empty local hostname is used)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.hostname), NULL }, - { "server_command", N_("command(s) to run when connected to server"), - N_("command(s) to run when connected to server (many commands should be " - "separated by ';', use '\\;' for a semicolon, special variables $nick, " - "$channel and $server are replaced by their value)"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.command), NULL }, - { "server_command_delay", N_("delay (in seconds) after command was executed"), - N_("delay (in seconds) after command was executed (example: give some time for authentication)"), - OPTION_TYPE_INT, 0, 3600, 0, - NULL, NULL, &(cfg_server.command_delay), NULL, NULL }, - { "server_autojoin", N_("list of channels to join when connected to server"), - N_("comma separated list of channels to join when connected to server (example: \"#chan1,#chan2,#chan3 key1,key2\")"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.autojoin), NULL }, - { "server_autorejoin", N_("automatically rejoin channels when kicked"), - N_("automatically rejoin channels when kicked"), - OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &(cfg_server.autorejoin), NULL, NULL }, - { "server_notify_levels", N_("notify levels for channels of this server"), - N_("comma separated list of notify levels for channels of this server " - "(format: #channel:1,..), a channel name '*' is reserved for server " - "default notify level"), - OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels }, - { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } +char *weechat_config_sections[] = +{ "look", "colors", + "history", "log", + "proxy", "plugins", + "alias", "keys", + NULL }; -/* all weechat options */ - -t_config_option *weechat_options[CONFIG_NUMBER_SECTIONS] = -{ weechat_options_look, weechat_options_colors, weechat_options_history, - weechat_options_log, weechat_options_irc, weechat_options_dcc, - weechat_options_proxy, weechat_options_plugins, NULL, NULL, NULL, - weechat_options_server +struct t_config_option *weechat_config_options[] = +{ weechat_options_look, weechat_options_colors, + weechat_options_history, weechat_options_log, + weechat_options_proxy, weechat_options_plugins, + NULL, NULL, + NULL }; +t_config_func_read_option *weechat_config_read_functions[] = +{ config_file_read_option, config_file_read_option, + config_file_read_option, config_file_read_option, + config_file_read_option, config_file_read_option, + weechat_config_read_alias, weechat_config_read_key, + NULL +}; -/* - * config_get_pos_array_values: return position of a string in an array of values - * return -1 if not found, otherwise position - */ - -int -config_get_pos_array_values (char **array, char *string) -{ - int i; - - i = 0; - while (array[i]) - { - if (ascii_strcasecmp (array[i], string) == 0) - return i; - i++; - } - /* string not found in array */ - return -1; -} +t_config_func_write_options *weechat_config_write_functions[] = +{ config_file_write_options, config_file_write_options, + config_file_write_options, config_file_write_options, + config_file_write_options, config_file_write_options, + weechat_config_write_alias, weechat_config_write_keys, + NULL +}; -/* - * config_get_section: get section name from option pointer - */ +t_config_func_write_options *weechat_config_write_default_functions[] = +{ config_file_write_options_default_values, config_file_write_options_default_values, + config_file_write_options_default_values, config_file_write_options_default_values, + config_file_write_options_default_values, config_file_write_options_default_values, + weechat_config_write_alias_default_values, weechat_config_write_keys_default_values, + NULL +}; -char * -config_get_section (t_config_option *ptr_option) -{ - int i, j; - - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) - { - for (j = 0; weechat_options[i][j].option_name; j++) - { - /* if option found, return pointer to section name */ - if (ptr_option == &weechat_options[i][j]) - return config_sections[i].section_name; - } - } - } - /* option not found */ - return NULL; -} /* - * config_change_noop: called when an option is changed by /set command - * and that no special action is needed after that + * weechat_config_change_noop: called when an option is changed by /set command + * and that no special action is needed after that */ void -config_change_noop () +weechat_config_change_noop () { /* do nothing */ } /* - * config_change_save_on_exit: called when "save_on_exit" flag is changed + * weechat_config_change_save_on_exit: called when "save_on_exit" flag is changed */ void -config_change_save_on_exit () +weechat_config_change_save_on_exit () { if (!cfg_look_save_on_exit) { - gui_printf (NULL, "\n"); - gui_printf (NULL, _("%s you should now issue /save to write " - "\"save_on_exit\" option in config file.\n"), - WEECHAT_WARNING); + gui_chat_printf (NULL, "\n"); + gui_chat_printf (NULL, + _("%s you should now issue /save to write " + "\"save_on_exit\" option in configuration file.\n"), + WEECHAT_WARNING); } } /* - * config_change_title: called when title is changed + * weechat_config_change_title: called when title is changed */ void -config_change_title () +weechat_config_change_title () { if (cfg_look_set_title) - gui_window_set_title (); + gui_window_title_set (); else - gui_window_reset_title (); + gui_window_title_reset (); } /* - * config_change_buffers: called when buffers change (for example nicklist) + * weechat_config_change_buffers: called when buffers change (for example nicklist) */ void -config_change_buffers () +weechat_config_change_buffers () { gui_window_refresh_windows (); } /* - * config_change_buffer_content: called when content of a buffer changes + * weechat_config_change_buffer_content: called when content of a buffer changes */ void -config_change_buffer_content () +weechat_config_change_buffer_content () { gui_window_redraw_buffer (gui_current_window->buffer); } /* - * config_change_hotlist: called when hotlist changes - */ - -void -config_change_hotlist () -{ - hotlist_resort (); - gui_status_draw (gui_current_window->buffer, 1); -} - -/* - * config_change_read_marker: called when read marker is changed + * weechat_config_change_buffer_time_format: called when buffer time format changes */ void -config_change_read_marker () +weechat_config_change_buffer_time_format () { - gui_window_redraw_all_buffers (); + gui_chat_time_length = util_get_time_length (cfg_look_buffer_time_format); + gui_chat_change_time_format (); + gui_window_redraw_buffer (gui_current_window->buffer); } /* - * config_change_one_server_buffer: called when the "one server buffer" - * setting is changed + * weechat_config_change_hotlist: called when hotlist changes */ void -config_change_one_server_buffer () +weechat_config_change_hotlist () { - if (cfg_look_one_server_buffer) - gui_buffer_merge_servers (gui_current_window); - else - gui_buffer_split_server (gui_current_window); + gui_hotlist_resort (); + gui_status_draw (gui_current_window->buffer, 1); } /* - * config_change_color: called when a color is changed by /set command + * weechat_config_change_read_marker: called when read marker is changed */ void -config_change_color () +weechat_config_change_read_marker () { - gui_color_init_pairs (); - gui_color_rebuild_weechat (); - gui_window_refresh_windows (); + gui_window_redraw_all_buffers (); } /* - * config_change_nicks_colors: called when number of nicks color changed + * weechat_config_change_prefix: called when a prefix is changed */ void -config_change_nicks_colors () +weechat_config_change_prefix () { - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; - t_irc_nick *ptr_nick; + int i; - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) + for (i = 0; i < GUI_CHAT_PREFIX_NUMBER; i++) { - if (ptr_server->is_connected) - { - for (ptr_channel = ptr_server->channels; ptr_channel; - ptr_channel = ptr_channel->next_channel) - { - for (ptr_nick = ptr_channel->nicks; ptr_nick; - ptr_nick = ptr_nick->next_nick) - { - if (ptr_nick->color != GUI_COLOR_WIN_NICK_SELF) - ptr_nick->color = irc_nick_find_color (ptr_nick); - } - } - } + if (gui_chat_prefix[i]) + free (gui_chat_prefix[i]); } + gui_chat_prefix_build (); } /* - * config_change_away_check: called when away check is changed + * weechat_config_change_color: called when a color is changed by /set command */ void -config_change_away_check () +weechat_config_change_color () { - if (cfg_irc_away_check == 0) - { - /* reset away flag for all nicks/chans/servers */ - irc_server_remove_away (); - } - irc_check_away = cfg_irc_away_check * 60; -} - -/* - * config_change_fifo_pipe: called when FIFO pipe is changed - */ - -void -config_change_fifo_pipe () -{ - if (cfg_irc_fifo_pipe) - { - if (weechat_fifo == -1) - fifo_create (); - } - else - { - if (weechat_fifo != -1) - fifo_remove (); - } + gui_color_init_pairs (); + gui_color_rebuild_weechat (); + gui_window_refresh_windows (); } /* - * config_change_notify_levels: called when notify levels is changed for a server + * weechat_config_change_nicks_colors: called when number of nicks color changed */ void -config_change_notify_levels () +weechat_config_change_nicks_colors () { - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (GUI_BUFFER_IS_CHANNEL(ptr_buffer) || GUI_BUFFER_IS_PRIVATE(ptr_buffer)) - ptr_buffer->notify_level = - irc_channel_get_notify_level (GUI_SERVER(ptr_buffer), GUI_CHANNEL(ptr_buffer)); - } -} - -/* - * config_change_log: called when log settings are changed (for server/channel/private logging) - */ + struct t_gui_buffer *ptr_buffer; + struct t_gui_nick *ptr_nick; -void -config_change_log () -{ - t_gui_buffer *ptr_buffer; - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { - if (GUI_BUFFER_IS_SERVER(ptr_buffer)) + if (ptr_buffer->nicks) { - if (cfg_log_auto_server && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!cfg_log_auto_server && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - if (GUI_BUFFER_IS_CHANNEL(ptr_buffer)) - { - if (cfg_log_auto_channel && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!cfg_log_auto_channel && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - if (GUI_BUFFER_IS_PRIVATE(ptr_buffer)) - { - if (cfg_log_auto_private && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!cfg_log_auto_private && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - } -} - -/* - * config_option_get_boolean_value: get boolean value with user text - * return: BOOL_FALSE or BOOL_TRUE - */ - -int -config_option_get_boolean_value (char *text) -{ - if ((ascii_strcasecmp (text, "on") == 0) - || (ascii_strcasecmp (text, "yes") == 0) - || (ascii_strcasecmp (text, "y") == 0) - || (ascii_strcasecmp (text, "true") == 0) - || (ascii_strcasecmp (text, "t") == 0) - || (ascii_strcasecmp (text, "1") == 0)) - return BOOL_TRUE; - - if ((ascii_strcasecmp (text, "off") == 0) - || (ascii_strcasecmp (text, "no") == 0) - || (ascii_strcasecmp (text, "n") == 0) - || (ascii_strcasecmp (text, "false") == 0) - || (ascii_strcasecmp (text, "f") == 0) - || (ascii_strcasecmp (text, "0") == 0)) - return BOOL_FALSE; - - /* invalid text */ - return -1; -} - -/* - * config_option_set_value: set new value for an option - * return: 0 if success - * -1 if error (bad value) - */ - -int -config_option_set_value (t_config_option *option, char *value) -{ - int int_value; - - switch (option->option_type) - { - case OPTION_TYPE_BOOLEAN: - int_value = config_option_get_boolean_value (value); - switch (int_value) + for (ptr_nick = ptr_buffer->nicks; ptr_nick; + ptr_nick = ptr_nick->next_nick) { - case BOOL_TRUE: - *(option->ptr_int) = BOOL_TRUE; - break; - case BOOL_FALSE: - *(option->ptr_int) = BOOL_FALSE; - break; - default: - return -1; - } - break; - case OPTION_TYPE_INT: - int_value = atoi (value); - if ((int_value < option->min) || (int_value > option->max)) - return -1; - *(option->ptr_int) = int_value; - break; - case OPTION_TYPE_INT_WITH_STRING: - int_value = config_get_pos_array_values (option->array_values, - value); - if (int_value < 0) - return -1; - *(option->ptr_int) = int_value; - break; - case OPTION_TYPE_COLOR: - if (!gui_color_assign (option->ptr_int, value)) - return -1; - break; - case OPTION_TYPE_STRING: - if ((option->max > 0) && (utf8_strlen (value) > option->max)) - return -1; - if (*(option->ptr_string)) - free (*(option->ptr_string)); - *(option->ptr_string) = strdup (value); - break; - } - return 0; -} - -/* - * config_option_list_remove: remove an item from a list for an option - * (for options with value like: "abc:1,def:blabla") - */ - -void -config_option_list_remove (char **string, char *item) -{ - char *name, *pos, *pos2; - - if (!string || !(*string)) - return; - - name = (char *) malloc (strlen (item) + 2); - strcpy (name, item); - strcat (name, ":"); - pos = ascii_strcasestr (*string, name); - free (name); - if (pos) - { - pos2 = pos + strlen (item); - if (pos2[0] == ':') - { - pos2++; - if (pos2[0]) - { - while (pos2[0] && (pos2[0] != ',')) - pos2++; - if (pos2[0] == ',') - pos2++; - if (!pos2[0] && (pos != (*string))) - pos--; - strcpy (pos, pos2); - if (!(*string)[0]) - { - free (*string); - *string = NULL; - } - else - (*string) = (char *) realloc (*string, strlen (*string) + 1); - } + //gui_nick_find_color (ptr_nick); + } } } } /* - * config_option_list_set: set an item from a list for an option - * (for options with value like: "abc:1,def:blabla") + * weechat_config_read_alias: read an alias in configuration file + * Return: 0 = successful + * -1 = option not found + * -2 = bad format/value */ -void -config_option_list_set (char **string, char *item, char *value) +int +weechat_config_read_alias (struct t_config_option *options, + char *option_name, char *value) { - config_option_list_remove (string, item); + /* make C compiler happy */ + (void) options; - if (!(*string)) + if (option_name) { - (*string) = (char *) malloc (strlen (item) + 1 + strlen (value) + 1); - (*string)[0] = '\0'; + /* create new alias */ + if (alias_new (option_name, value)) + weelist_add (&weechat_index_commands, + &weechat_last_index_command, + option_name, + WEELIST_POS_SORT); + else + return -2; } else - (*string) = (char *) realloc (*string, - strlen (*string) + 1 + - strlen (item) + 1 + strlen (value) + 1); - - if ((*string)[0]) - strcat (*string, ","); - strcat (*string, item); - strcat (*string, ":"); - strcat (*string, value); -} - -/* - * config_option_list_get_value: return position of item value in the list - * (for options with value like: "abc:1,def:blabla") - */ - -void -config_option_list_get_value (char **string, char *item, - char **pos_found, int *length) -{ - char *name, *pos, *pos2, *pos_comma; - - *pos_found = NULL; - *length = 0; - - if (!string || !(*string)) - return; - - name = (char *) malloc (strlen (item) + 2); - strcpy (name, item); - strcat (name, ":"); - pos = ascii_strcasestr (*string, name); - free (name); - if (pos) { - pos2 = pos + strlen (item); - if (pos2[0] == ':') - { - pos2++; - *pos_found = pos2; - pos_comma = strchr (pos2, ','); - if (pos_comma) - *length = pos_comma - pos2; - else - *length = strlen (pos2); - } + /* does nothing for new [alias] section */ } -} - -/* - * config_get_server_option_ptr: get a pointer to a server config option - */ - -void * -config_get_server_option_ptr (t_irc_server *server, char *option_name) -{ - if (ascii_strcasecmp (option_name, "server_name") == 0) - return (void *)(&server->name); - if (ascii_strcasecmp (option_name, "server_autoconnect") == 0) - return (void *)(&server->autoconnect); - if (ascii_strcasecmp (option_name, "server_autoreconnect") == 0) - return (void *)(&server->autoreconnect); - if (ascii_strcasecmp (option_name, "server_autoreconnect_delay") == 0) - return (void *)(&server->autoreconnect_delay); - if (ascii_strcasecmp (option_name, "server_address") == 0) - return (void *)(&server->address); - if (ascii_strcasecmp (option_name, "server_port") == 0) - return (void *)(&server->port); - if (ascii_strcasecmp (option_name, "server_ipv6") == 0) - return (void *)(&server->ipv6); - if (ascii_strcasecmp (option_name, "server_ssl") == 0) - return (void *)(&server->ssl); - if (ascii_strcasecmp (option_name, "server_password") == 0) - return (void *)(&server->password); - if (ascii_strcasecmp (option_name, "server_nick1") == 0) - return (void *)(&server->nick1); - if (ascii_strcasecmp (option_name, "server_nick2") == 0) - return (void *)(&server->nick2); - if (ascii_strcasecmp (option_name, "server_nick3") == 0) - return (void *)(&server->nick3); - if (ascii_strcasecmp (option_name, "server_username") == 0) - return (void *)(&server->username); - if (ascii_strcasecmp (option_name, "server_realname") == 0) - return (void *)(&server->realname); - if (ascii_strcasecmp (option_name, "server_hostname") == 0) - return (void *)(&server->hostname); - if (ascii_strcasecmp (option_name, "server_command") == 0) - return (void *)(&server->command); - if (ascii_strcasecmp (option_name, "server_command_delay") == 0) - return (void *)(&server->command_delay); - if (ascii_strcasecmp (option_name, "server_autojoin") == 0) - return (void *)(&server->autojoin); - if (ascii_strcasecmp (option_name, "server_autorejoin") == 0) - return (void *)(&server->autorejoin); - if (ascii_strcasecmp (option_name, "server_notify_levels") == 0) - return (void *)(&server->notify_levels); - /* option not found */ - return NULL; -} - -/* - * config_set_server_value: set new value for an option - * return: 0 if success - * -1 if option not found - * -2 if bad value - */ - -int -config_set_server_value (t_irc_server *server, char *option_name, - char *value) -{ - t_config_option *ptr_option; - int i; - void *ptr_data; - int int_value; - ptr_data = config_get_server_option_ptr (server, option_name); - if (!ptr_data) - return -1; - - ptr_option = NULL; - for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) - { - /* if option found, return pointer */ - if (ascii_strcasecmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, option_name) == 0) - { - ptr_option = &weechat_options[CONFIG_SECTION_SERVER][i]; - break; - } - } - if (!ptr_option) - return -1; - - switch (ptr_option->option_type) - { - case OPTION_TYPE_BOOLEAN: - int_value = config_option_get_boolean_value (value); - switch (int_value) - { - case BOOL_TRUE: - *((int *)(ptr_data)) = BOOL_TRUE; - break; - case BOOL_FALSE: - *((int *)(ptr_data)) = BOOL_FALSE; - break; - default: - return -2; - } - break; - case OPTION_TYPE_INT: - int_value = atoi (value); - if ((int_value < ptr_option->min) || (int_value > ptr_option->max)) - return -2; - *((int *)(ptr_data)) = int_value; - break; - case OPTION_TYPE_INT_WITH_STRING: - int_value = config_get_pos_array_values (ptr_option->array_values, - value); - if (int_value < 0) - return -2; - *((int *)(ptr_data)) = int_value; - break; - case OPTION_TYPE_COLOR: - if (!gui_color_assign ((int *)ptr_data, value)) - return -2; - break; - case OPTION_TYPE_STRING: - if (*((char **)ptr_data)) - free (*((char **)ptr_data)); - *((char **)ptr_data) = strdup (value); - break; - } - if (ptr_option->handler_change != NULL) - (void) (ptr_option->handler_change()); + /* all ok */ return 0; } /* - * config_option_search: look for an option and return pointer to this option - * if option is not found, NULL is returned + * weechat_config_read_key: read a key in configuration file + * Return: 0 = successful + * -1 = option not found + * -2 = bad format/value */ -t_config_option * -config_option_search (char *option_name) +int +weechat_config_read_key (struct t_config_option *options, + char *option_name, char *value) { - int i, j; + /* make C compiler happy */ + (void) options; - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) + if (option_name) { - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) + if (value[0]) { - for (j = 0; weechat_options[i][j].option_name; j++) - { - /* if option found, return pointer */ - if (ascii_strcasecmp (weechat_options[i][j].option_name, option_name) == 0) - return &weechat_options[i][j]; - } + /* bind key (overwrite any binding with same key) */ + gui_keyboard_bind (option_name, value); } - } - /* option not found */ - return NULL; -} - -/* - * config_option_search_option_value: look for type and value of an option - * (including server options) - * if option is not found, NULL is returned - */ - -void -config_option_search_option_value (char *option_name, t_config_option **option, - void **option_value) -{ - t_config_option *ptr_option; - t_irc_server *ptr_server; - int i; - void *ptr_value; - char *pos; - - ptr_option = NULL; - ptr_value = NULL; - - ptr_option = config_option_search (option_name); - if (!ptr_option) - { - pos = strchr (option_name, '.'); - if (pos) + else { - pos[0] = '\0'; - ptr_server = irc_server_search (option_name); - if (ptr_server) - { - for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) - { - if (strcmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, - pos + 1) == 0) - { - ptr_option = &weechat_options[CONFIG_SECTION_SERVER][i]; - ptr_value = config_get_server_option_ptr (ptr_server, pos + 1); - break; - } - } - } - pos[0] = '.'; + /* unbin key if no value given */ + gui_keyboard_unbind (option_name); } } else { - switch (ptr_option->option_type) - { - case OPTION_TYPE_BOOLEAN: - case OPTION_TYPE_INT: - case OPTION_TYPE_INT_WITH_STRING: - case OPTION_TYPE_COLOR: - ptr_value = (void *)(ptr_option->ptr_int); - break; - case OPTION_TYPE_STRING: - ptr_value = (void *)(ptr_option->ptr_string); - break; - } + /* does nothing for new [key] section */ } - if (ptr_option) - { - *option = ptr_option; - *option_value = ptr_value; - } + /* all ok */ + return 0; } /* - * config_set_value: set new value for an option (found by name) - * return: 0 if success - * -1 if bad value for option - * -2 if option is not found + * weechat_config_read: read WeeChat configuration file + * return: 0 = successful + * -1 = configuration file file not found + * -2 = error in configuration file */ int -config_set_value (char *option_name, char *value) +weechat_config_read () { - t_config_option *ptr_option; - - ptr_option = config_option_search (option_name); - if (ptr_option) - return config_option_set_value (ptr_option, value); - else - return -2; + return config_file_read (weechat_config_sections, weechat_config_options, + weechat_config_read_functions, + config_file_read_option, + weechat_config_write_default_functions, + WEECHAT_CONFIG_NAME); } /* - * config_allocate_server: allocate a new server + * weechat_config_write_alias: write alias section in configuration file + * Return: 0 = successful + * -1 = write error */ int -config_allocate_server (char *filename, int line_number) +weechat_config_write_alias (FILE *file, char *section_name, + struct t_config_option *options) { - if (!cfg_server.name - || !cfg_server.address - || cfg_server.port < 0 - || !cfg_server.nick1 - || !cfg_server.nick2 - || !cfg_server.nick3 - || !cfg_server.username - || !cfg_server.realname) - { - irc_server_free_all (); - gui_printf (NULL, - _("%s %s, line %d: new server, but previous was incomplete\n"), - WEECHAT_WARNING, filename, line_number); - return 0; - - } - if (irc_server_name_already_exists (cfg_server.name)) - { - irc_server_free_all (); - gui_printf (NULL, - _("%s %s, line %d: server '%s' already exists\n"), - WEECHAT_WARNING, filename, line_number, cfg_server.name); - return 0; - } - if (!irc_server_new (cfg_server.name, - cfg_server.autoconnect, cfg_server.autoreconnect, - cfg_server.autoreconnect_delay, 0, cfg_server.address, - cfg_server.port, cfg_server.ipv6, cfg_server.ssl, - cfg_server.password, cfg_server.nick1, cfg_server.nick2, - cfg_server.nick3, cfg_server.username, cfg_server.realname, - cfg_server.hostname, cfg_server.command, - cfg_server.command_delay, cfg_server.autojoin, - cfg_server.autorejoin, cfg_server.notify_levels)) - { - irc_server_free_all (); - gui_printf (NULL, - _("%s %s, line %d: unable to create server\n"), - WEECHAT_WARNING, filename, line_number); - return 0; - } + struct alias *ptr_alias; - irc_server_destroy (&cfg_server); - irc_server_init (&cfg_server); - - return 1; -} - -/* - * config_default_values: initialize config variables with default values - */ - -void -config_default_values () -{ - int i, j, int_value; - - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) - { - for (j = 0; weechat_options[i][j].option_name; j++) - { - switch (weechat_options[i][j].option_type) - { - case OPTION_TYPE_BOOLEAN: - case OPTION_TYPE_INT: - *weechat_options[i][j].ptr_int = - weechat_options[i][j].default_int; - break; - case OPTION_TYPE_INT_WITH_STRING: - int_value = config_get_pos_array_values ( - weechat_options[i][j].array_values, - weechat_options[i][j].default_string); - if (int_value < 0) - gui_printf (NULL, - _("%s unable to assign default int with string (\"%s\")\n"), - WEECHAT_WARNING, weechat_options[i][j].default_string); - else - *weechat_options[i][j].ptr_int = - int_value; - break; - case OPTION_TYPE_COLOR: - if (!gui_color_assign ( - weechat_options[i][j].ptr_int, - weechat_options[i][j].default_string)) - gui_printf (NULL, - _("%s unable to assign default color (\"%s\")\n"), - WEECHAT_WARNING, weechat_options[i][j].default_string); - break; - case OPTION_TYPE_STRING: - *weechat_options[i][j].ptr_string = - strdup (weechat_options[i][j].default_string); - break; - } - } - } - } -} - -/* - * config_read: read WeeChat configuration - * returns: 0 = successful - * -1 = config file file not found - * < -1 = other error (fatal) - */ - -int -config_read () -{ - int filename_length; - char *filename; - FILE *file; - int section, line_number, i, option_number; - int server_found; - char line[1024], *ptr_line, *ptr_line2, *pos, *pos2; - - filename_length = strlen (weechat_home) + strlen (WEECHAT_CONFIG_NAME) + 2; - filename = (char *) malloc (filename_length * sizeof (char)); - if (!filename) - return -2; - snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, - weechat_home, DIR_SEPARATOR); - if ((file = fopen (filename, "r")) == NULL) - { - gui_printf (NULL, _("%s config file \"%s\" not found.\n"), - WEECHAT_WARNING, filename); - free (filename); - return -1; - } + /* make C compiler happy */ + (void) options; - config_default_values (); - irc_server_init (&cfg_server); + string_iconv_fprintf (file, "\n[%s]\n", section_name); - /* read config file */ - section = CONFIG_SECTION_NONE; - server_found = 0; - line_number = 0; - while (!feof (file)) + for (ptr_alias = weechat_alias; ptr_alias; + ptr_alias = ptr_alias->next_alias) { - ptr_line = fgets (line, sizeof (line) - 1, file); - line_number++; - if (ptr_line) - { - /* encode line to internal charset */ - ptr_line2 = weechat_iconv_to_internal (NULL, ptr_line); - if (ptr_line2) - { - snprintf (line, sizeof (line) - 1, "%s", ptr_line2); - free (ptr_line2); - } - - /* skip spaces */ - while (ptr_line[0] == ' ') - ptr_line++; - /* not a comment and not an empty line */ - if ((ptr_line[0] != '#') && (ptr_line[0] != '\r') - && (ptr_line[0] != '\n')) - { - /* beginning of section */ - if (ptr_line[0] == '[') - { - pos = strchr (line, ']'); - if (pos == NULL) - gui_printf (NULL, - _("%s %s, line %d: invalid syntax, missing \"]\"\n"), - WEECHAT_WARNING, filename, line_number); - else - { - pos[0] = '\0'; - pos = ptr_line + 1; - section = CONFIG_SECTION_NONE; - for (i = 0; config_sections[i].section_name; i++) - { - if (strcmp (config_sections[i].section_name, pos) == 0) - { - section = i; - break; - } - } - if (section == CONFIG_SECTION_NONE) - gui_printf (NULL, - _("%s %s, line %d: unknown section identifier (\"%s\")\n"), - WEECHAT_WARNING, filename, line_number, pos); - else - { - if (server_found) - { - /* if server already started => create it */ - config_allocate_server (filename, line_number); - } - server_found = (section == CONFIG_SECTION_SERVER) ? 1 : 0; - } - } - } - else - { - if (section == CONFIG_SECTION_NONE) - { - gui_printf (NULL, - _("%s %s, line %d: invalid section for option, line is ignored\n"), - WEECHAT_WARNING, filename, line_number); - } - else - { - pos = strchr (line, '='); - if (pos == NULL) - gui_printf (NULL, - _("%s %s, line %d: invalid syntax, missing \"=\"\n"), - WEECHAT_WARNING, filename, line_number); - else - { - pos[0] = '\0'; - pos++; - - /* remove spaces before '=' */ - pos2 = pos - 2; - while ((pos2 > line) && (pos2[0] == ' ')) - { - pos2[0] = '\0'; - pos2--; - } - - /* skip spaces after '=' */ - while (pos[0] && (pos[0] == ' ')) - { - pos++; - } - - /* remove CR/LF */ - pos2 = strchr (pos, '\r'); - if (pos2 != NULL) - pos2[0] = '\0'; - pos2 = strchr (pos, '\n'); - if (pos2 != NULL) - pos2[0] = '\0'; - - /* remove simple or double quotes - and spaces at the end */ - if (strlen(pos) > 1) - { - pos2 = pos + strlen (pos) - 1; - while ((pos2 > pos) && (pos2[0] == ' ')) - { - pos2[0] = '\0'; - pos2--; - } - pos2 = pos + strlen (pos) - 1; - if (((pos[0] == '\'') && - (pos2[0] == '\'')) || - ((pos[0] == '"') && - (pos2[0] == '"'))) - { - pos2[0] = '\0'; - pos++; - } - } - - if (section == CONFIG_SECTION_KEYS) - { - if (pos[0]) - { - /* bind key (overwrite any binding with same key) */ - gui_keyboard_bind (line, pos); - } - else - { - /* unbin key if no value given */ - gui_keyboard_unbind (line); - } - } - else if (section == CONFIG_SECTION_ALIAS) - { - /* create new alias */ - if (alias_new (line, pos)) - weelist_add (&index_commands, &last_index_command, - line, WEELIST_POS_SORT); - } - else if (section == CONFIG_SECTION_IGNORE) - { - /* create new ignore */ - if (ascii_strcasecmp (line, "ignore") != 0) - gui_printf (NULL, - _("%s %s, line %d: invalid option \"%s\"\n"), - WEECHAT_WARNING, filename, line_number, line); - else - { - if (!irc_ignore_add_from_config (pos)) - gui_printf (NULL, - _("%s %s, line %d: invalid ignore options \"%s\"\n"), - WEECHAT_WARNING, filename, line_number, pos); - } - } - else - { - option_number = -1; - for (i = 0; - weechat_options[section][i].option_name; i++) - { - if (strcmp - (weechat_options[section][i].option_name, - ptr_line) == 0) - { - option_number = i; - break; - } - } - if (option_number < 0) - gui_printf (NULL, - _("%s %s, line %d: invalid option \"%s\"\n"), - WEECHAT_WARNING, filename, line_number, ptr_line); - else - { - if (config_option_set_value (&weechat_options[section][option_number], pos) < 0) - { - switch (weechat_options[section] - [option_number].option_type) - { - case OPTION_TYPE_BOOLEAN: - gui_printf (NULL, - _("%s %s, line %d: invalid value for " - "option '%s'\n" - "Expected: boolean value: " - "'off' or 'on'\n"), - WEECHAT_WARNING, filename, - line_number, ptr_line); - break; - case OPTION_TYPE_INT: - gui_printf (NULL, - _("%s %s, line %d: invalid value for " - "option '%s'\n" - "Expected: integer between %d " - "and %d\n"), - WEECHAT_WARNING, filename, - line_number, ptr_line, - weechat_options[section][option_number].min, - weechat_options[section][option_number].max); - break; - case OPTION_TYPE_INT_WITH_STRING: - gui_printf (NULL, - _("%s %s, line %d: invalid value for " - "option '%s'\n" - "Expected: one of these strings: "), - WEECHAT_WARNING, filename, - line_number, ptr_line); - i = 0; - while (weechat_options[section][option_number].array_values[i]) - { - gui_printf (NULL, "\"%s\" ", - weechat_options[section][option_number].array_values[i]); - i++; - } - gui_printf (NULL, "\n"); - break; - case OPTION_TYPE_COLOR: - gui_printf (NULL, - _("%s %s, line %d: invalid color " - "name for option '%s'\n"), - WEECHAT_WARNING, filename, - line_number, - ptr_line); - break; - } - } - } - } - } - } - } - } - } - } - - if (server_found) - { - if (!config_allocate_server (filename, line_number)) - { - fclose (file); - free (filename); - return -2; - } + string_iconv_fprintf (file, "%s = \"%s\"\n", + ptr_alias->name, ptr_alias->command); } - fclose (file); - free (filename); - + /* all ok */ return 0; } - /* - * config_create_default: create default WeeChat config - * return: 0 if ok - * < 0 if error + * weechat_config_write_keys: write alias section in configuration file + * Return: 0 = successful + * -1 = write error */ int -config_create_default () +weechat_config_write_keys (FILE *file, char *section_name, + struct t_config_option *options) { - int filename_length; - char *filename; - FILE *file; - int i, j; - time_t current_time; - struct passwd *my_passwd; - char *realname, *pos; t_gui_key *ptr_key; char *expanded_name, *function_name; - - filename_length = strlen (weechat_home) + - strlen (WEECHAT_CONFIG_NAME) + 2; - filename = - (char *) malloc (filename_length * sizeof (char)); - if (!filename) - return -2; - snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, - weechat_home, DIR_SEPARATOR); - if ((file = fopen (filename, "w")) == NULL) - { - gui_printf (NULL, _("%s cannot create file \"%s\"\n"), - WEECHAT_ERROR, filename); - free (filename); - return -1; - } - - weechat_iconv_fprintf (stdout, _("%s: creating default config file...\n"), PACKAGE_NAME); - weechat_log_printf (_("Creating default config file\n")); - current_time = time (NULL); - weechat_iconv_fprintf (file, _("#\n# %s configuration file, created by " - "%s v%s on %s"), - PACKAGE_NAME, PACKAGE_NAME, PACKAGE_VERSION, - ctime (¤t_time)); - weechat_iconv_fprintf (file, _("# WARNING! Be careful when editing this file, " - "WeeChat writes this file when exiting.\n#\n")); + /* make C compiler happy */ + (void) options; - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) - { - weechat_iconv_fprintf (file, "\n[%s]\n", config_sections[i].section_name); - for (j = 0; weechat_options[i][j].option_name; j++) - { - switch (weechat_options[i][j].option_type) - { - case OPTION_TYPE_BOOLEAN: - weechat_iconv_fprintf (file, "%s = %s\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].default_int) ? - "on" : "off"); - break; - case OPTION_TYPE_INT: - weechat_iconv_fprintf (file, "%s = %d\n", - weechat_options[i][j].option_name, - weechat_options[i][j].default_int); - break; - case OPTION_TYPE_INT_WITH_STRING: - case OPTION_TYPE_COLOR: - weechat_iconv_fprintf (file, "%s = %s\n", - weechat_options[i][j].option_name, - weechat_options[i][j].default_string); - break; - case OPTION_TYPE_STRING: - weechat_iconv_fprintf (file, "%s = \"%s\"\n", - weechat_options[i][j].option_name, - weechat_options[i][j].default_string); - break; - } - } - } - } + string_iconv_fprintf (file, "\n[%s]\n", section_name); - /* default key bindings */ - weechat_iconv_fprintf (file, "\n[keys]\n"); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) { expanded_name = gui_keyboard_get_expanded_name (ptr_key->key); @@ -2279,229 +1136,88 @@ config_create_default () { function_name = gui_keyboard_function_search_by_ptr (ptr_key->function); if (function_name) - weechat_iconv_fprintf (file, "%s = \"%s%s%s\"\n", - (expanded_name) ? expanded_name : ptr_key->key, - function_name, - (ptr_key->args) ? " " : "", - (ptr_key->args) ? ptr_key->args : ""); + string_iconv_fprintf (file, "%s = \"%s%s%s\"\n", + (expanded_name) ? expanded_name : ptr_key->key, + function_name, + (ptr_key->args) ? " " : "", + (ptr_key->args) ? ptr_key->args : ""); } else - weechat_iconv_fprintf (file, "%s = \"%s\"\n", - (expanded_name) ? expanded_name : ptr_key->key, - ptr_key->command); + string_iconv_fprintf (file, "%s = \"%s\"\n", + (expanded_name) ? expanded_name : ptr_key->key, + ptr_key->command); if (expanded_name) free (expanded_name); } - /* default aliases */ - weechat_iconv_fprintf (file, "\n[alias]\n"); - weechat_iconv_fprintf (file, "SAY = \"msg *\"\n"); - weechat_iconv_fprintf (file, "BYE = \"quit\"\n"); - weechat_iconv_fprintf (file, "EXIT = \"quit\"\n"); - weechat_iconv_fprintf (file, "SIGNOFF = \"quit\"\n"); - weechat_iconv_fprintf (file, "C = \"clear\"\n"); - weechat_iconv_fprintf (file, "CL = \"clear\"\n"); - weechat_iconv_fprintf (file, "CLOSE = \"buffer close\"\n"); - weechat_iconv_fprintf (file, "CHAT = \"dcc chat\"\n"); - weechat_iconv_fprintf (file, "IG = \"ignore\"\n"); - weechat_iconv_fprintf (file, "J = \"join\"\n"); - weechat_iconv_fprintf (file, "K = \"kick\"\n"); - weechat_iconv_fprintf (file, "KB = \"kickban\"\n"); - weechat_iconv_fprintf (file, "LEAVE = \"part\"\n"); - weechat_iconv_fprintf (file, "M = \"msg\"\n"); - weechat_iconv_fprintf (file, "MUB = \"unban *\"\n"); - weechat_iconv_fprintf (file, "N = \"names\"\n"); - weechat_iconv_fprintf (file, "Q = \"query\"\n"); - weechat_iconv_fprintf (file, "T = \"topic\"\n"); - weechat_iconv_fprintf (file, "UB = \"unban\"\n"); - weechat_iconv_fprintf (file, "UNIG = \"unignore\"\n"); - weechat_iconv_fprintf (file, "W = \"who\"\n"); - weechat_iconv_fprintf (file, "WC = \"window merge\"\n"); - weechat_iconv_fprintf (file, "WI = \"whois\"\n"); - weechat_iconv_fprintf (file, "WW = \"whowas\"\n"); + /* all ok */ + return 0; +} + +/* + * weechat_config_write_alias_default_values: write alias section with default values + * in configuration file + * Return: 0 = successful + * -1 = write error + */ + +int +weechat_config_write_alias_default_values (FILE *file, char *section_name, + struct t_config_option *options) +{ + /* make C compiler happy */ + (void) options; - /* no ignore by default */ + string_iconv_fprintf (file, "\n[%s]\n", section_name); - /* default server is freenode */ - weechat_iconv_fprintf (file, "\n[server]\n"); - weechat_iconv_fprintf (file, "server_name = \"freenode\"\n"); - weechat_iconv_fprintf (file, "server_autoconnect = on\n"); - weechat_iconv_fprintf (file, "server_autoreconnect = on\n"); - weechat_iconv_fprintf (file, "server_autoreconnect_delay = 30\n"); - weechat_iconv_fprintf (file, "server_address = \"irc.freenode.net\"\n"); - weechat_iconv_fprintf (file, "server_port = 6667\n"); - weechat_iconv_fprintf (file, "server_ipv6 = off\n"); - weechat_iconv_fprintf (file, "server_ssl = off\n"); - weechat_iconv_fprintf (file, "server_password = \"\"\n"); + string_iconv_fprintf (file, "SAY = \"msg *\"\n"); + string_iconv_fprintf (file, "BYE = \"quit\"\n"); + string_iconv_fprintf (file, "EXIT = \"quit\"\n"); + string_iconv_fprintf (file, "SIGNOFF = \"quit\"\n"); + string_iconv_fprintf (file, "C = \"clear\"\n"); + string_iconv_fprintf (file, "CL = \"clear\"\n"); + string_iconv_fprintf (file, "CLOSE = \"buffer close\"\n"); + string_iconv_fprintf (file, "CHAT = \"dcc chat\"\n"); + string_iconv_fprintf (file, "IG = \"ignore\"\n"); + string_iconv_fprintf (file, "J = \"join\"\n"); + string_iconv_fprintf (file, "K = \"kick\"\n"); + string_iconv_fprintf (file, "KB = \"kickban\"\n"); + string_iconv_fprintf (file, "LEAVE = \"part\"\n"); + string_iconv_fprintf (file, "M = \"msg\"\n"); + string_iconv_fprintf (file, "MUB = \"unban *\"\n"); + string_iconv_fprintf (file, "N = \"names\"\n"); + string_iconv_fprintf (file, "Q = \"query\"\n"); + string_iconv_fprintf (file, "T = \"topic\"\n"); + string_iconv_fprintf (file, "UB = \"unban\"\n"); + string_iconv_fprintf (file, "UNIG = \"unignore\"\n"); + string_iconv_fprintf (file, "W = \"who\"\n"); + string_iconv_fprintf (file, "WC = \"window merge\"\n"); + string_iconv_fprintf (file, "WI = \"whois\"\n"); + string_iconv_fprintf (file, "WW = \"whowas\"\n"); - /* Get the user's name from /etc/passwd */ - if ((my_passwd = getpwuid (geteuid ())) != NULL) - { - weechat_iconv_fprintf (file, "server_nick1 = \"%s\"\n", my_passwd->pw_name); - weechat_iconv_fprintf (file, "server_nick2 = \"%s1\"\n", my_passwd->pw_name); - weechat_iconv_fprintf (file, "server_nick3 = \"%s2\"\n", my_passwd->pw_name); - weechat_iconv_fprintf (file, "server_username = \"%s\"\n", my_passwd->pw_name); - if ((!my_passwd->pw_gecos) - || (my_passwd->pw_gecos[0] == '\0') - || (my_passwd->pw_gecos[0] == ',') - || (my_passwd->pw_gecos[0] == ' ')) - weechat_iconv_fprintf (file, "server_realname = \"%s\"\n", my_passwd->pw_name); - else - { - realname = strdup (my_passwd->pw_gecos); - pos = strchr (realname, ','); - if (pos) - pos[0] = '\0'; - weechat_iconv_fprintf (file, "server_realname = \"%s\"\n", - realname); - if (pos) - pos[0] = ','; - free (realname); - } - } - else - { - /* default values if /etc/passwd can't be read */ - weechat_iconv_fprintf (stderr, "%s: %s (%s).", - WEECHAT_WARNING, - _("Unable to get user's name"), - strerror (errno)); - weechat_iconv_fprintf (file, "server_nick1 = \"weechat1\"\n"); - weechat_iconv_fprintf (file, "server_nick2 = \"weechat2\"\n"); - weechat_iconv_fprintf (file, "server_nick3 = \"weechat3\"\n"); - weechat_iconv_fprintf (file, "server_username = \"weechat\"\n"); - weechat_iconv_fprintf (file, "server_realname = \"WeeChat default realname\"\n"); - } - - weechat_iconv_fprintf (file, "server_hostname = \"\"\n"); - weechat_iconv_fprintf (file, "server_command = \"\"\n"); - weechat_iconv_fprintf (file, "server_command_delay = 0\n"); - weechat_iconv_fprintf (file, "server_autojoin = \"\"\n"); - weechat_iconv_fprintf (file, "server_autorejoin = on\n"); - weechat_iconv_fprintf (file, "server_notify_levels = \"\"\n"); - - fclose (file); - chmod (filename, 0600); - free (filename); + /* all ok */ return 0; } /* - * config_write: write WeeChat configurtion - * return: 0 if ok - * < 0 if error + * weechat_config_write_keys_default_values: write keys section with default values + * in configuration file + * Return: 0 = successful + * -1 = write error */ int -config_write (char *config_name) +weechat_config_write_keys_default_values (FILE *file, char *section_name, + struct t_config_option *options) { - int filename_length; - char *filename, *filename2; - FILE *file; - int i, j, rc; - time_t current_time; - t_irc_server *ptr_server; - t_weechat_alias *ptr_alias; - t_irc_ignore *ptr_ignore; t_gui_key *ptr_key; char *expanded_name, *function_name; - if (config_name) - { - filename_length = strlen (config_name); - filename = strdup (config_name); - } - else - { - filename_length = strlen (weechat_home) + - strlen (WEECHAT_CONFIG_NAME) + 2; - filename = - (char *) malloc (filename_length * sizeof (char)); - if (!filename) - return -2; - snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, - weechat_home, DIR_SEPARATOR); - } - - filename2 = (char *) malloc ((filename_length + 32) * sizeof (char)); - if (!filename2) - { - free (filename); - return -2; - } - snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); + /* make C compiler happy */ + (void) options; - if ((file = fopen (filename2, "w")) == NULL) - { - gui_printf (NULL, _("%s cannot create file \"%s\"\n"), - WEECHAT_ERROR, filename2); - free (filename); - free (filename2); - return -1; - } - - weechat_log_printf (_("Saving config to disk\n")); + string_iconv_fprintf (file, "\n[%s]\n", section_name); - current_time = time (NULL); - weechat_iconv_fprintf (file, _("#\n# %s configuration file, created by " - "%s v%s on %s"), - PACKAGE_NAME, PACKAGE_NAME, PACKAGE_VERSION, - ctime (¤t_time)); - weechat_iconv_fprintf (file, _("# WARNING! Be careful when editing this file, " - "WeeChat writes this file when exiting.\n#\n")); - - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS) - && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER)) - { - weechat_iconv_fprintf (file, "\n[%s]\n", config_sections[i].section_name); - for (j = 0; weechat_options[i][j].option_name; j++) - { - switch (weechat_options[i][j].option_type) - { - case OPTION_TYPE_BOOLEAN: - weechat_iconv_fprintf (file, "%s = %s\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].ptr_int && - *weechat_options[i][j].ptr_int) ? - "on" : "off"); - break; - case OPTION_TYPE_INT: - weechat_iconv_fprintf (file, "%s = %d\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].ptr_int) ? - *weechat_options[i][j].ptr_int : - weechat_options[i][j].default_int); - break; - case OPTION_TYPE_INT_WITH_STRING: - weechat_iconv_fprintf (file, "%s = %s\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].ptr_int) ? - weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int] : - weechat_options[i][j].array_values[weechat_options[i][j].default_int]); - break; - case OPTION_TYPE_COLOR: - weechat_iconv_fprintf (file, "%s = %s\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].ptr_int) ? - gui_color_get_name (*weechat_options[i][j].ptr_int) : - weechat_options[i][j].default_string); - break; - case OPTION_TYPE_STRING: - weechat_iconv_fprintf (file, "%s = \"%s\"\n", - weechat_options[i][j].option_name, - (weechat_options[i][j].ptr_string) ? - *weechat_options[i][j].ptr_string : - weechat_options[i][j].default_string); - break; - } - } - } - } - - /* keys section */ - weechat_iconv_fprintf (file, "\n[keys]\n"); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) { expanded_name = gui_keyboard_get_expanded_name (ptr_key->key); @@ -2509,89 +1225,46 @@ config_write (char *config_name) { function_name = gui_keyboard_function_search_by_ptr (ptr_key->function); if (function_name) - weechat_iconv_fprintf (file, "%s = \"%s%s%s\"\n", - (expanded_name) ? expanded_name : ptr_key->key, - function_name, - (ptr_key->args) ? " " : "", - (ptr_key->args) ? ptr_key->args : ""); + string_iconv_fprintf (file, "%s = \"%s%s%s\"\n", + (expanded_name) ? expanded_name : ptr_key->key, + function_name, + (ptr_key->args) ? " " : "", + (ptr_key->args) ? ptr_key->args : ""); } else - weechat_iconv_fprintf (file, "%s = \"%s\"\n", - (expanded_name) ? expanded_name : ptr_key->key, - ptr_key->command); + string_iconv_fprintf (file, "%s = \"%s\"\n", + (expanded_name) ? expanded_name : ptr_key->key, + ptr_key->command); if (expanded_name) free (expanded_name); } - /* alias section */ - weechat_iconv_fprintf (file, "\n[alias]\n"); - for (ptr_alias = weechat_alias; ptr_alias; - ptr_alias = ptr_alias->next_alias) - { - weechat_iconv_fprintf (file, "%s = \"%s\"\n", - ptr_alias->alias_name, ptr_alias->alias_command); - } - - /* ignore section */ - weechat_iconv_fprintf (file, "\n[ignore]\n"); - for (ptr_ignore = irc_ignore; ptr_ignore; - ptr_ignore = ptr_ignore->next_ignore) - { - weechat_iconv_fprintf (file, "ignore = \"%s,%s,%s,%s\"\n", - ptr_ignore->mask, - ptr_ignore->type, - ptr_ignore->channel_name, - ptr_ignore->server_name); - } - - /* server section */ - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (!ptr_server->temp_server) - { - weechat_iconv_fprintf (file, "\n[server]\n"); - weechat_iconv_fprintf (file, "server_name = \"%s\"\n", ptr_server->name); - weechat_iconv_fprintf (file, "server_autoconnect = %s\n", - (ptr_server->autoconnect) ? "on" : "off"); - weechat_iconv_fprintf (file, "server_autoreconnect = %s\n", - (ptr_server->autoreconnect) ? "on" : "off"); - weechat_iconv_fprintf (file, "server_autoreconnect_delay = %d\n", - ptr_server->autoreconnect_delay); - weechat_iconv_fprintf (file, "server_address = \"%s\"\n", ptr_server->address); - weechat_iconv_fprintf (file, "server_port = %d\n", ptr_server->port); - weechat_iconv_fprintf (file, "server_ipv6 = %s\n", - (ptr_server->ipv6) ? "on" : "off"); - weechat_iconv_fprintf (file, "server_ssl = %s\n", - (ptr_server->ssl) ? "on" : "off"); - weechat_iconv_fprintf (file, "server_password = \"%s\"\n", - (ptr_server->password) ? ptr_server->password : ""); - weechat_iconv_fprintf (file, "server_nick1 = \"%s\"\n", ptr_server->nick1); - weechat_iconv_fprintf (file, "server_nick2 = \"%s\"\n", ptr_server->nick2); - weechat_iconv_fprintf (file, "server_nick3 = \"%s\"\n", ptr_server->nick3); - weechat_iconv_fprintf (file, "server_username = \"%s\"\n", ptr_server->username); - weechat_iconv_fprintf (file, "server_realname = \"%s\"\n", ptr_server->realname); - weechat_iconv_fprintf (file, "server_hostname = \"%s\"\n", - (ptr_server->hostname) ? ptr_server->hostname : ""); - weechat_iconv_fprintf (file, "server_command = \"%s\"\n", - (ptr_server->command) ? ptr_server->command : ""); - weechat_iconv_fprintf (file, "server_command_delay = %d\n", ptr_server->command_delay); - weechat_iconv_fprintf (file, "server_autojoin = \"%s\"\n", - (ptr_server->autojoin) ? ptr_server->autojoin : ""); - weechat_iconv_fprintf (file, "server_autorejoin = %s\n", - (ptr_server->autorejoin) ? "on" : "off"); - weechat_iconv_fprintf (file, "server_notify_levels = \"%s\"\n", - (ptr_server->notify_levels) ? ptr_server->notify_levels : ""); - } - } - - fclose (file); - chmod (filename2, 0600); - unlink (filename); - rc = rename (filename2, filename); - free (filename); - free (filename2); - if (rc != 0) - return -1; + /* all ok */ return 0; } + +/* + * weechat_config_write: write WeeChat configuration file + * return: 0 if ok + * < 0 if error + */ + +int +weechat_config_write () +{ + weechat_log_printf (_("Saving WeeChat configuration to disk\n")); + return config_file_write (weechat_config_sections, weechat_config_options, + weechat_config_write_functions, + WEECHAT_CONFIG_NAME); +} + +/* + * weechat_config_print_stdout: print WeeChat options on standard output + */ + +void +weechat_config_print_stdout () +{ + config_option_print_stdout (weechat_config_sections, + weechat_config_options); +} diff --git a/src/core/wee-config.h b/src/core/wee-config.h index cac086840..2918cb32c 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -20,42 +20,21 @@ #ifndef __WEECHAT_CONFIG_H #define __WEECHAT_CONFIG_H 1 -#include "../protocols/irc/irc.h" +#include "wee-config-option.h" +#include "wee-config-file.h" +#include "../gui/gui-chat.h" +#include "../gui/gui-color.h" #define WEECHAT_CONFIG_NAME "weechat.rc" -#define CONFIG_SECTION_NONE -1 -#define CONFIG_SECTION_LOOK 0 -#define CONFIG_SECTION_COLORS 1 -#define CONFIG_SECTION_HISTORY 2 -#define CONFIG_SECTION_LOG 3 -#define CONFIG_SECTION_IRC 4 -#define CONFIG_SECTION_DCC 5 -#define CONFIG_SECTION_PROXY 6 -#define CONFIG_SECTION_PLUGINS 7 -#define CONFIG_SECTION_KEYS 8 -#define CONFIG_SECTION_ALIAS 9 -#define CONFIG_SECTION_IGNORE 10 -#define CONFIG_SECTION_SERVER 11 -#define CONFIG_NUMBER_SECTIONS 12 - -#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */ -#define OPTION_TYPE_INT 2 /* values: from min to max */ -#define OPTION_TYPE_INT_WITH_STRING 3 /* values: one from **array_values */ -#define OPTION_TYPE_COLOR 4 /* values: a color name */ -#define OPTION_TYPE_STRING 5 /* values: any string, may be empty */ - -#define BOOL_FALSE 0 -#define BOOL_TRUE 1 - #define CFG_LOOK_NICKLIST_LEFT 0 #define CFG_LOOK_NICKLIST_RIGHT 1 #define CFG_LOOK_NICKLIST_TOP 2 #define CFG_LOOK_NICKLIST_BOTTOM 3 -#define CFG_LOOK_ALIGN_NICK_NONE 0 -#define CFG_LOOK_ALIGN_NICK_LEFT 1 -#define CFG_LOOK_ALIGN_NICK_RIGHT 2 +#define CFG_LOOK_PREFIX_ALIGN_NONE 0 +#define CFG_LOOK_PREFIX_ALIGN_LEFT 1 +#define CFG_LOOK_PREFIX_ALIGN_RIGHT 2 #define CFG_LOOK_HOTLIST_SORT_GROUP_TIME_ASC 0 #define CFG_LOOK_HOTLIST_SORT_GROUP_TIME_DESC 1 @@ -64,35 +43,8 @@ #define CFG_LOOK_HOTLIST_SORT_NUMBER_ASC 4 #define CFG_LOOK_HOTLIST_SORT_NUMBER_DESC 5 -#define CFG_IRC_DISPLAY_AWAY_OFF 0 -#define CFG_IRC_DISPLAY_AWAY_LOCAL 1 -#define CFG_IRC_DISPLAY_AWAY_CHANNEL 2 - -typedef struct t_config_section t_config_section; - -struct t_config_section -{ - int section_number; - char *section_name; -}; - -typedef struct t_config_option t_config_option; - -struct t_config_option -{ - char *option_name; - char *short_description; - char *long_description; - int option_type; - int min, max; - int default_int; - char *default_string; - char **array_values; - int *ptr_int; - char **ptr_string; - void (*handler_change)(); -}; - +extern struct t_config_option weechat_options_look[]; +extern int cfg_look_color_real_white; extern int cfg_look_save_on_exit; extern int cfg_look_set_title; extern int cfg_look_startup_logo; @@ -101,7 +53,7 @@ extern char *cfg_look_weechat_slogan; extern int cfg_look_one_server_buffer; extern int cfg_look_open_near_server; extern int cfg_look_scroll_amount; -extern char *cfg_look_buffer_timestamp; +extern char *cfg_look_buffer_time_format; extern int cfg_look_color_nicks_number; extern int cfg_look_color_actions; extern int cfg_look_nicklist; @@ -112,19 +64,17 @@ extern int cfg_look_nicklist_separator; extern int cfg_look_nickmode; extern int cfg_look_nickmode_empty; extern char *cfg_look_no_nickname; -extern char *cfg_look_nick_prefix; -extern char *cfg_look_nick_suffix; -extern int cfg_look_align_nick; -extern int cfg_look_align_other; -extern int cfg_look_align_size; -extern int cfg_look_align_size_max; +extern char *cfg_look_prefix[GUI_CHAT_PREFIX_NUMBER]; +extern int cfg_look_prefix_align; +extern int cfg_look_prefix_align_max; +extern char *cfg_look_prefix_suffix; extern int cfg_look_align_text_offset; extern char *cfg_look_nick_completor; extern char *cfg_look_nick_completion_ignore; extern int cfg_look_nick_completion_smart; extern int cfg_look_nick_complete_first; extern int cfg_look_infobar; -extern char *cfg_look_infobar_timestamp; +extern char *cfg_look_infobar_time_format; extern int cfg_look_infobar_seconds; extern int cfg_look_infobar_delay_highlight; extern int cfg_look_hotlist_names_count; @@ -132,33 +82,37 @@ extern int cfg_look_hotlist_names_level; extern int cfg_look_hotlist_names_length; extern int cfg_look_hotlist_sort; extern int cfg_look_day_change; -extern char *cfg_look_day_change_timestamp; +extern char *cfg_look_day_change_time_format; extern char *cfg_look_read_marker; extern char *cfg_look_input_format; extern int cfg_look_paste_max_lines; -extern int cfg_col_real_white; +extern struct t_config_option weechat_options_colors[]; extern int cfg_col_separator; extern int cfg_col_title; -extern int cfg_col_title_more; extern int cfg_col_title_bg; +extern int cfg_col_title_more; extern int cfg_col_chat; +extern int cfg_col_chat_bg; extern int cfg_col_chat_time; -extern int cfg_col_chat_time_sep; -extern int cfg_col_chat_prefix1; -extern int cfg_col_chat_prefix2; +extern int cfg_col_chat_time_delimiters; +extern int cfg_col_chat_prefix[GUI_CHAT_PREFIX_NUMBER]; +extern int cfg_col_chat_prefix_more; +extern int cfg_col_chat_prefix_suffix; +extern int cfg_col_chat_buffer; extern int cfg_col_chat_server; -extern int cfg_col_chat_join; -extern int cfg_col_chat_part; +extern int cfg_col_chat_channel; extern int cfg_col_chat_nick; +extern int cfg_col_chat_nick_self; +extern int cfg_col_chat_nick_other; +extern int cfg_col_chat_nick_colors[GUI_COLOR_NICK_NUMBER]; extern int cfg_col_chat_host; -extern int cfg_col_chat_channel; -extern int cfg_col_chat_dark; +extern int cfg_col_chat_delimiters; extern int cfg_col_chat_highlight; -extern int cfg_col_chat_bg; extern int cfg_col_chat_read_marker; extern int cfg_col_chat_read_marker_bg; extern int cfg_col_status; +extern int cfg_col_status_bg; extern int cfg_col_status_delimiters; extern int cfg_col_status_channel; extern int cfg_col_status_data_msg; @@ -166,83 +120,49 @@ extern int cfg_col_status_data_private; extern int cfg_col_status_data_highlight; extern int cfg_col_status_data_other; extern int cfg_col_status_more; -extern int cfg_col_status_bg; extern int cfg_col_infobar; +extern int cfg_col_infobar_bg; extern int cfg_col_infobar_delimiters; extern int cfg_col_infobar_highlight; extern int cfg_col_infobar_bg; extern int cfg_col_input; +extern int cfg_col_input_bg; extern int cfg_col_input_server; extern int cfg_col_input_channel; extern int cfg_col_input_nick; extern int cfg_col_input_delimiters; extern int cfg_col_input_text_not_found; extern int cfg_col_input_actions; -extern int cfg_col_input_bg; -extern int cfg_col_nick; -extern int cfg_col_nick_away; -extern int cfg_col_nick_chanowner; -extern int cfg_col_nick_chanadmin; -extern int cfg_col_nick_op; -extern int cfg_col_nick_halfop; -extern int cfg_col_nick_voice; -extern int cfg_col_nick_user; -extern int cfg_col_nick_more; -extern int cfg_col_nick_sep; -extern int cfg_col_nick_self; -extern int cfg_col_nick_colors[GUI_COLOR_WIN_NICK_NUMBER]; -extern int cfg_col_nick_private; -extern int cfg_col_nick_bg; -extern int cfg_col_dcc_selected; -extern int cfg_col_dcc_waiting; -extern int cfg_col_dcc_connecting; -extern int cfg_col_dcc_active; -extern int cfg_col_dcc_done; -extern int cfg_col_dcc_failed; -extern int cfg_col_dcc_aborted; - +extern int cfg_col_nicklist; +extern int cfg_col_nicklist_bg; +extern int cfg_col_nicklist_away; +extern int cfg_col_nicklist_prefix1; +extern int cfg_col_nicklist_prefix2; +extern int cfg_col_nicklist_prefix3; +extern int cfg_col_nicklist_prefix4; +extern int cfg_col_nicklist_prefix5; +extern int cfg_col_nicklist_more; +extern int cfg_col_nicklist_separator; +extern int cfg_col_info; +extern int cfg_col_info_bg; +extern int cfg_col_info_waiting; +extern int cfg_col_info_connecting; +extern int cfg_col_info_active; +extern int cfg_col_info_done; +extern int cfg_col_info_failed; +extern int cfg_col_info_aborted; + +extern struct t_config_option weechat_options_history[]; extern int cfg_history_max_lines; extern int cfg_history_max_commands; extern int cfg_history_display_default; -extern int cfg_log_auto_server; -extern int cfg_log_auto_channel; -extern int cfg_log_auto_private; +extern struct t_config_option weechat_options_log[]; extern int cfg_log_plugin_msg; extern char *cfg_log_path; -extern char *cfg_log_timestamp; -extern int cfg_log_hide_nickserv_pwd; - -extern int cfg_irc_display_away; -extern int cfg_irc_show_away_once; -extern char *cfg_irc_default_msg_part; -extern char *cfg_irc_default_msg_quit; -extern int cfg_irc_notice_as_pv; -extern int cfg_irc_away_check; -extern int cfg_irc_away_check_max_nicks; -extern int cfg_irc_lag_check; -extern int cfg_irc_lag_min_show; -extern int cfg_irc_lag_disconnect; -extern int cfg_irc_anti_flood; -extern int cfg_irc_fifo_pipe; -extern char *cfg_irc_highlight; -extern int cfg_irc_colors_receive; -extern int cfg_irc_colors_send; -extern int cfg_irc_send_unknown_commands; - -extern int cfg_dcc_auto_accept_files; -extern int cfg_dcc_auto_accept_chats; -extern int cfg_dcc_timeout; -extern int cfg_dcc_blocksize; -extern int cfg_dcc_fast_send; -extern char *cfg_dcc_port_range; -extern char *cfg_dcc_own_ip; -extern char *cfg_dcc_download_path; -extern char *cfg_dcc_upload_path; -extern int cfg_dcc_convert_spaces; -extern int cfg_dcc_auto_rename; -extern int cfg_dcc_auto_resume; +extern char *cfg_log_time_format; +extern struct t_config_option weechat_options_proxy[]; extern int cfg_proxy_use; extern int cfg_proxy_type; extern char *cfg_proxy_type_values[]; @@ -252,40 +172,40 @@ extern int cfg_proxy_port; extern char *cfg_proxy_username; extern char *cfg_proxy_password; +extern struct t_config_option weechat_options_plugins[]; extern char *cfg_plugins_path; extern char *cfg_plugins_autoload; extern char *cfg_plugins_extension; -extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS]; -extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS]; - -extern char *config_get_section (); -extern void config_change_noop (); -extern void config_change_save_on_exit (); -extern void config_change_title (); -extern void config_change_buffers (); -extern void config_change_buffer_content (); -extern void config_change_hotlist (); -extern void config_change_read_marker (); -extern void config_change_charset (); -extern void config_change_one_server_buffer (); -extern void config_change_color (); -extern void config_change_nicks_colors (); -extern void config_change_away_check (); -extern void config_change_fifo_pipe (); -extern void config_change_notify_levels (); -extern void config_change_log (); -extern int config_option_set_value (t_config_option *, char *); -extern void config_option_list_remove (char **, char *); -extern void config_option_list_set (char **, char *, char *); -extern void config_option_list_get_value (char **, char *, char **, int *); -extern t_config_option *config_option_search (char *); -extern void config_option_search_option_value (char *, t_config_option **, void **); -extern int config_set_value (char *, char *); -extern void *config_get_server_option_ptr (t_irc_server *, char *); -extern int config_set_server_value (t_irc_server *, char *, char *); -extern int config_read (); -extern int config_create_default (); -extern int config_write (); - -#endif /* weeconfig.h */ +extern char *weechat_config_sections[]; +extern struct t_config_option *weechat_config_options[]; + +extern void weechat_config_change_noop (); +extern void weechat_config_change_save_on_exit (); +extern void weechat_config_change_title (); +extern void weechat_config_change_buffers (); +extern void weechat_config_change_buffer_content (); +extern void weechat_config_change_buffer_time_format (); +extern void weechat_config_change_hotlist (); +extern void weechat_config_change_read_marker (); +extern void weechat_config_change_prefix (); +extern void weechat_config_change_charset (); +extern void weechat_config_change_color (); +extern void weechat_config_change_nicks_colors (); +extern void weechat_config_change_away_check (); +extern void weechat_config_change_fifo_pipe (); +extern void weechat_config_change_log (); + +extern int weechat_config_read_alias (struct t_config_option *, char *, char *); +extern int weechat_config_read_key (struct t_config_option *, char *, char *); +extern int weechat_config_write_alias (FILE *, char *, struct t_config_option *); +extern int weechat_config_write_keys (FILE *, char *, struct t_config_option *); +extern int weechat_config_write_alias_default_values (FILE *, char *, + struct t_config_option *); +extern int weechat_config_write_keys_default_values (FILE *, char *, + struct t_config_option *); +extern int weechat_config_read (); +extern int weechat_config_write (); +extern void weechat_config_print_stdout (); + +#endif /* wee-config.h */ diff --git a/src/core/wee-list.c b/src/core/wee-list.c index 3e0872eb6..4de434329 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* weelist.c: sorted lists management */ +/* wee-list.c: sorted lists management */ #ifdef HAVE_CONFIG_H @@ -27,9 +27,9 @@ #include <string.h> #include "weechat.h" -#include "weelist.h" -#include "log.h" -#include "util.h" +#include "wee-list.h" +#include "wee-log.h" +#include "wee-string.h" /* @@ -37,14 +37,15 @@ */ int -weelist_get_size (t_weelist *weelist) +weelist_get_size (struct t_weelist *weelist) { - t_weelist *ptr_weelist; + struct t_weelist *ptr_weelist; int count; count = 0; - for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) + for (ptr_weelist = weelist; ptr_weelist; + ptr_weelist = ptr_weelist->next_weelist) { count++; } @@ -53,17 +54,18 @@ weelist_get_size (t_weelist *weelist) } /* - * weelist_search: search date in a list + * weelist_search: search data in a list */ -t_weelist * -weelist_search (t_weelist *weelist, char *data) +struct t_weelist * +weelist_search (struct t_weelist *weelist, char *data) { - t_weelist *ptr_weelist; + struct t_weelist *ptr_weelist; - for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) + for (ptr_weelist = weelist; ptr_weelist; + ptr_weelist = ptr_weelist->next_weelist) { - if (ascii_strcasecmp (data, ptr_weelist->data) == 0) + if (string_strcasecmp (data, ptr_weelist->data) == 0) return ptr_weelist; } /* word not found in list */ @@ -74,14 +76,15 @@ weelist_search (t_weelist *weelist, char *data) * weelist_find_pos: find position for data (keeping list sorted) */ -t_weelist * -weelist_find_pos (t_weelist *weelist, char *data) +struct t_weelist * +weelist_find_pos (struct t_weelist *weelist, char *data) { - t_weelist *ptr_weelist; + struct t_weelist *ptr_weelist; - for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) + for (ptr_weelist = weelist; ptr_weelist; + ptr_weelist = ptr_weelist->next_weelist) { - if (ascii_strcasecmp (data, ptr_weelist->data) < 0) + if (string_strcasecmp (data, ptr_weelist->data) < 0) return ptr_weelist; } /* position not found, best position is at the end */ @@ -93,10 +96,10 @@ weelist_find_pos (t_weelist *weelist, char *data) */ void -weelist_insert (t_weelist **weelist, t_weelist **last_weelist, t_weelist *element, - int position) +weelist_insert (struct t_weelist **weelist, struct t_weelist **last_weelist, + struct t_weelist *element, int position) { - t_weelist *pos_weelist; + struct t_weelist *pos_weelist; if (*weelist) { @@ -156,16 +159,16 @@ weelist_insert (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen * weelist_add: create new data and add it to list */ -t_weelist * -weelist_add (t_weelist **weelist, t_weelist **last_weelist, char *data, - int position) +struct t_weelist * +weelist_add (struct t_weelist **weelist, struct t_weelist **last_weelist, + char *data, int position) { - t_weelist *new_weelist; + struct t_weelist *new_weelist; if (!data || (!data[0])) return NULL; - if ((new_weelist = ((t_weelist *) malloc (sizeof (t_weelist))))) + if ((new_weelist = ((struct t_weelist *) malloc (sizeof (struct t_weelist))))) { new_weelist->data = strdup (data); weelist_insert (weelist, last_weelist, new_weelist, position); @@ -180,9 +183,10 @@ weelist_add (t_weelist **weelist, t_weelist **last_weelist, char *data, */ void -weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *element) +weelist_remove (struct t_weelist **weelist, struct t_weelist **last_weelist, + struct t_weelist *element) { - t_weelist *new_weelist; + struct t_weelist *new_weelist; if (!element || !(*weelist)) return; @@ -213,7 +217,7 @@ weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen */ void -weelist_remove_all (t_weelist **weelist, t_weelist **last_weelist) +weelist_remove_all (struct t_weelist **weelist, struct t_weelist **last_weelist) { while (*weelist) { @@ -226,9 +230,9 @@ weelist_remove_all (t_weelist **weelist, t_weelist **last_weelist) */ void -weelist_print_log (t_weelist *weelist, char *name) +weelist_print_log (struct t_weelist *weelist, char *name) { - t_weelist *ptr_weelist; + struct t_weelist *ptr_weelist; for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) diff --git a/src/core/wee-list.h b/src/core/wee-list.h index 4cc9ffb83..7e748f1f5 100644 --- a/src/core/wee-list.h +++ b/src/core/wee-list.h @@ -24,20 +24,18 @@ #define WEELIST_POS_BEGINNING 1 #define WEELIST_POS_END 2 -typedef struct t_weelist t_weelist; - struct t_weelist { char *data; - t_weelist *prev_weelist; - t_weelist *next_weelist; + struct t_weelist *prev_weelist; + struct t_weelist *next_weelist; }; -extern int weelist_get_size (t_weelist *); -extern t_weelist *weelist_search (t_weelist *, char *); -extern t_weelist *weelist_add (t_weelist **, t_weelist **, char *, int); -extern void weelist_remove (t_weelist **, t_weelist **, t_weelist *); -extern void weelist_remove_all (t_weelist **, t_weelist **); -extern void weelist_print_log (t_weelist *, char *); +extern int weelist_get_size (struct t_weelist *); +extern struct t_weelist *weelist_search (struct t_weelist *, char *); +extern struct t_weelist *weelist_add (struct t_weelist **, struct t_weelist **, char *, int); +extern void weelist_remove (struct t_weelist **, struct t_weelist **, struct t_weelist *); +extern void weelist_remove_all (struct t_weelist **, struct t_weelist **); +extern void weelist_print_log (struct t_weelist *, char *); -#endif /* weelist.h */ +#endif /* wee-list.h */ diff --git a/src/core/wee-log.c b/src/core/wee-log.c index 2132e67a8..b7c4936d6 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* log.c: WeeChat log file */ +/* wee-log.c: WeeChat log file */ #ifdef HAVE_CONFIG_H @@ -37,8 +37,8 @@ #include <time.h> #include "weechat.h" -#include "log.h" -#include "util.h" +#include "wee-log.h" +#include "wee-string.h" char *weechat_log_filename = NULL; /* log name (~/.weechat/weechat.log) */ @@ -103,11 +103,11 @@ weechat_log_init () { if (!weechat_log_open (NULL, "w")) { - weechat_iconv_fprintf (stderr, - _("%s unable to create/append to log file (weechat.log)\n" - "If another WeeChat process is using this file, try to run WeeChat\n" - "with another home using \"--dir\" command line option.\n"), - WEECHAT_ERROR); + string_iconv_fprintf (stderr, + _("%s unable to create/append to log file (weechat.log)\n" + "If another WeeChat process is using this file, try to run WeeChat\n" + "with another home using \"--dir\" command line option.\n"), + WEECHAT_ERROR); exit (1); } } @@ -146,12 +146,12 @@ weechat_log_printf (char *message, ...) seconds = time (NULL); date_tmp = localtime (&seconds); if (date_tmp) - weechat_iconv_fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s", - date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday, - date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec, - buffer); + string_iconv_fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s", + date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday, + date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec, + buffer); else - weechat_iconv_fprintf (weechat_log_file, "%s", buffer); + string_iconv_fprintf (weechat_log_file, "%s", buffer); fflush (weechat_log_file); } @@ -217,8 +217,8 @@ weechat_log_crash_rename () getpid()); if (rename (old_name, new_name) == 0) { - weechat_iconv_fprintf (stderr, "*** Full crash dump was saved to %s file.\n", - new_name); + string_iconv_fprintf (stderr, "*** Full crash dump was saved to %s file.\n", + new_name); weechat_log_open (new_name, "a"); free (old_name); free (new_name); diff --git a/src/core/wee-log.h b/src/core/wee-log.h index 4f2a9e5ce..1375b795b 100644 --- a/src/core/wee-log.h +++ b/src/core/wee-log.h @@ -28,4 +28,4 @@ extern void weechat_log_close (); extern void weechat_log_printf (char *, ...); extern int weechat_log_crash_rename (); -#endif /* log.h */ +#endif /* wee-log.h */ diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index f74b015e5..ef3adf50a 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* session.c: save/restore session data */ +/* wee-session.c: save/restore session data */ #ifdef HAVE_CONFIG_H @@ -29,24 +29,23 @@ #include <stdarg.h> #include <string.h> -#ifdef HAVE_GNUTLS +/*#ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> -#endif +#endif*/ #include "weechat.h" -#include "session.h" -#include "hotlist.h" -#include "log.h" -#include "utf8.h" -#include "util.h" -#include "../protocols/irc/irc.h" -#include "../gui/gui.h" +#include "wee-session.h" +#include "wee-log.h" +#include "wee-string.h" +#include "wee-utf8.h" +#include "../gui/gui-chat.h" +#include "../gui/gui-main.h" /* current server/channel (used when loading session) */ -t_irc_server *session_current_server = NULL; +/*t_irc_server *session_current_server = NULL; t_irc_channel *session_current_channel = NULL; -t_gui_buffer *session_current_buffer = NULL; +t_gui_buffer *session_current_buffer = NULL;*/ long session_last_read_pos = 0; int session_last_read_length = 0; @@ -140,7 +139,7 @@ session_write_buf (FILE *file, int id, void *buffer, int size) * session_save_nick: save a nick into session file */ -int +/*int session_save_nick (FILE *file, t_irc_nick *nick) { int rc; @@ -153,13 +152,13 @@ session_save_nick (FILE *file, t_irc_nick *nick) rc = rc && (session_write_str (file, SESSION_NICK_HOST, nick->host)); rc = rc && (session_write_id (file, SESSION_NICK_END)); return rc; -} +}*/ /* * session_save_channel: save a channel into session file */ -int +/*int session_save_channel (FILE *file, t_irc_channel *channel) { int rc; @@ -192,13 +191,13 @@ session_save_channel (FILE *file, t_irc_channel *channel) } return 1; -} +}*/ /* * session_save_servers: save all servers into session file */ -int +/*int session_save_servers (FILE *file) { int rc; @@ -281,13 +280,13 @@ session_save_servers (FILE *file) } } return 1; -} +}*/ /* * session_save_dcc: save all DCC into session file */ -int +/*int session_save_dcc (FILE *file) { int rc; @@ -332,14 +331,14 @@ session_save_dcc (FILE *file) return 0; } return 1; -} +}*/ /* * session_save_history: save history into session file * (from last to first, to restore it in good order) */ -int +/*int session_save_history (FILE *file, t_history *last_history) { int rc; @@ -355,13 +354,13 @@ session_save_history (FILE *file, t_history *last_history) } rc = rc && (session_write_id (file, SESSION_HIST_END)); return rc; -} +}*/ /* * session_save_line: save a buffer line into session file */ -int +/*int session_save_line (FILE *file, t_gui_line *line) { int rc; @@ -380,13 +379,13 @@ session_save_line (FILE *file, t_gui_line *line) rc = rc && (session_write_buf (file, SESSION_LINE_DATE, &(line->date), sizeof (time_t))); rc = rc && (session_write_id (file, SESSION_LINE_END)); return rc; -} +}*/ /* * session_save_buffers: save all buffers into session file */ -int +/*int session_save_buffers (FILE *file) { int rc; @@ -419,13 +418,13 @@ session_save_buffers (FILE *file) return 0; } return 1; -} +}*/ /* * session_save_uptime: save uptime into session file */ -int +/*int session_save_uptime (FILE *file) { int rc; @@ -436,13 +435,13 @@ session_save_uptime (FILE *file) rc = rc && (session_write_buf (file, SESSION_UPT_START_TIME, &weechat_start_time, sizeof (time_t))); rc = rc && (session_write_id (file, SESSION_UPT_END)); return rc; -} +}*/ /* * session_save_hotlist: save hotlist into session file */ -int +/*int session_save_hotlist (FILE *file) { int rc; @@ -464,13 +463,13 @@ session_save_hotlist (FILE *file) return 0; } return rc; -} +}*/ /* * session_save: save current session */ -int +/*int session_save (char *filename) { FILE *file; @@ -491,7 +490,7 @@ session_save (char *filename) fclose (file); return rc; -} +}*/ /* ========================================================================== */ @@ -511,21 +510,21 @@ session_crash (FILE *file, char *message, ...) fclose (file); gui_main_end (); - weechat_iconv_fprintf (stderr, "%s %s\n", - WEECHAT_ERROR, buffer); - weechat_iconv_fprintf (stderr, - _("Last operation with session file was at position %ld, " - "read of %d bytes\n"), - session_last_read_pos, - session_last_read_length); - weechat_iconv_fprintf (stderr, - _("Please send %s/%s, %s/%s and " - "above messages to WeeChat developers for support.\n" - "Be careful, private info may be in these files.\n"), - weechat_home, - WEECHAT_LOG_NAME, - weechat_home, - WEECHAT_SESSION_NAME); + string_iconv_fprintf (stderr, "%s %s\n", + WEECHAT_ERROR, buffer); + string_iconv_fprintf (stderr, + _("Last operation with session file was at position %ld, " + "read of %d bytes\n"), + session_last_read_pos, + session_last_read_length); + string_iconv_fprintf (stderr, + _("Please send %s/%s, %s/%s and " + "above messages to WeeChat developers for support.\n" + "Be careful, private info may be in these files.\n"), + weechat_home, + WEECHAT_LOG_NAME, + weechat_home, + WEECHAT_SESSION_NAME); exit (EXIT_FAILURE); } @@ -818,7 +817,7 @@ session_read_ignore_object (FILE *file) * session_load_server: load server from file */ -int +/*int session_load_server (FILE *file) { int object_id, rc; @@ -829,7 +828,7 @@ session_load_server (FILE *file) int session_size_int; #endif - /* read server name */ + // read server name server_name = NULL; if (!session_read_object (file, SESSION_SERV_NAME, SESSION_TYPE_STR, &server_name, 0)) { @@ -837,7 +836,7 @@ session_load_server (FILE *file) return 0; } - /* use or allocate server */ + // use or allocate server weechat_log_printf (_("session: loading server \"%s\"\n"), server_name); session_current_server = irc_server_search (server_name); @@ -858,7 +857,7 @@ session_load_server (FILE *file) } free (server_name); - /* read server values */ + // read server values rc = 1; while (rc) { @@ -1036,33 +1035,33 @@ session_load_server (FILE *file) } } return 0; -} +}*/ /* * session_load_channel: load channel from file */ -int +/*int session_load_channel (FILE *file) { int object_id, rc, channel_type; char *channel_name; - /* check if server is allocated for this channel */ + // check if server is allocated for this channel if (!session_current_server) { session_crash (file, _("channel found without server")); return 0; } - /* read channel type */ + // read channel type if (!session_read_object (file, SESSION_CHAN_TYPE, SESSION_TYPE_INT, &channel_type, 0)) { session_crash (file, _("channel type not found")); return 0; } - /* read channel name */ + // read channel name channel_name = NULL; if (!session_read_object (file, SESSION_CHAN_NAME, SESSION_TYPE_STR, &channel_name, 0)) { @@ -1070,7 +1069,7 @@ session_load_channel (FILE *file) return 0; } - /* allocate channel */ + // allocate channel weechat_log_printf (_("session: loading channel \"%s\"\n"), channel_name); session_current_channel = irc_channel_new (session_current_server, @@ -1083,7 +1082,7 @@ session_load_channel (FILE *file) return 0; } - /* read channel values */ + // read channel values rc = 1; while (rc) { @@ -1112,7 +1111,7 @@ session_load_channel (FILE *file) break; case SESSION_CHAN_NICKS_COUNT: rc = rc && (session_read_int (file, &(session_current_channel->nicks_count))); - /* will be incremented when adding nicks */ + // will be incremented when adding nicks session_current_channel->nicks_count = 0; break; case SESSION_CHAN_CHECKING_AWAY: @@ -1139,27 +1138,27 @@ session_load_channel (FILE *file) } } return 0; -} +}*/ /* * session_load_nick: load nick from file */ -int +/*int session_load_nick (FILE *file) { int rc, object_id; char *nick_name; t_irc_nick *nick; - /* check if channel is allocated for this nick */ + // check if channel is allocated for this nick if (!session_current_channel) { session_crash (file, _("nick found without channel")); return 0; } - /* read nick name */ + // read nick name nick_name = NULL; if (!session_read_object (file, SESSION_NICK_NICK, SESSION_TYPE_STR, &nick_name, 0)) { @@ -1167,7 +1166,7 @@ session_load_nick (FILE *file) return 0; } - /* allocate nick */ + // allocate nick nick = irc_nick_new (session_current_server, session_current_channel, nick_name, 0, 0, 0, 0, 0, 0, 0); free (nick_name); @@ -1177,7 +1176,7 @@ session_load_nick (FILE *file) return 0; } - /* read nick values */ + // read nick values rc = 1; while (rc) { @@ -1210,13 +1209,13 @@ session_load_nick (FILE *file) } } return 0; -} +}*/ /* * session_load_dcc: load DCC from file */ -int +/*int session_load_dcc (FILE *file) { int object_id, rc; @@ -1225,7 +1224,7 @@ session_load_dcc (FILE *file) t_irc_server *ptr_server; t_irc_channel *ptr_channel; - /* allocate DCC */ + // allocate DCC dcc = irc_dcc_alloc (); if (!dcc) { @@ -1235,7 +1234,7 @@ session_load_dcc (FILE *file) weechat_log_printf (_("session: loading DCC\n")); - /* read DCC values */ + // read DCC values ptr_server = NULL; ptr_channel = NULL; rc = 1; @@ -1374,13 +1373,13 @@ session_load_dcc (FILE *file) } } return 0; -} +}*/ /* * session_load_history: load history from file (global or for a buffer) */ -int +/*int session_load_history (FILE *file) { int object_id, rc; @@ -1391,7 +1390,7 @@ session_load_history (FILE *file) else weechat_log_printf (_("session: loading global history\n")); - /* read history values */ + // read history values rc = 1; while (rc) { @@ -1411,9 +1410,9 @@ session_load_history (FILE *file) if (!session_read_str_utf8 (file, &text)) return 0; if (session_current_buffer) - history_buffer_add (session_current_buffer, text); + gui_history_buffer_add (session_current_buffer, text); else - history_global_add (text); + gui_history_global_add (text); free (text); break; default: @@ -1425,13 +1424,13 @@ session_load_history (FILE *file) } } return 0; -} +}*/ /* * session_load_buffer: load buffer from file */ -int +/*int session_load_buffer (FILE *file) { int object_id, rc; @@ -1440,7 +1439,7 @@ session_load_buffer (FILE *file) t_irc_server *ptr_server; t_irc_channel *ptr_channel; - /* read server name */ + // read server name server_name = NULL; if (!session_read_object (file, SESSION_BUFF_SERVER, SESSION_TYPE_STR, &server_name, 0)) { @@ -1448,7 +1447,7 @@ session_load_buffer (FILE *file) return 0; } - /* read channel name */ + // read channel name channel_name = NULL; if (!session_read_object (file, SESSION_BUFF_CHANNEL, SESSION_TYPE_STR, &channel_name, 0)) { @@ -1456,14 +1455,14 @@ session_load_buffer (FILE *file) return 0; } - /* read buffer type */ + // read buffer type if (!session_read_object (file, SESSION_BUFF_TYPE, SESSION_TYPE_INT, &buffer_type, 0)) { session_crash (file, _("buffer type not found")); return 0; } - /* allocate buffer */ + // allocate buffer weechat_log_printf (_("session: loading buffer (server: %s, channel: %s, type: %d)\n"), (server_name) ? server_name : "-", (channel_name) ? channel_name : "-", @@ -1490,7 +1489,8 @@ session_load_buffer (FILE *file) } } - session_current_buffer = gui_buffer_new (gui_windows, ptr_server, + session_current_buffer = gui_buffer_new (gui_windows, weechat_protocols, + ptr_server, ptr_channel, buffer_type, 1); if (!session_current_buffer) { @@ -1501,7 +1501,7 @@ session_load_buffer (FILE *file) free (server_name); free (channel_name); - /* read buffer values */ + // read buffer values rc = 1; while (rc) { @@ -1528,26 +1528,26 @@ session_load_buffer (FILE *file) } } return 0; -} +}*/ /* * session_load_line: load buffer line from file */ -int +/*int session_load_line (FILE *file) { int object_id, rc; t_gui_line *line; - /* check if buffer is allocated for this line */ + // check if buffer is allocated for this line if (!session_current_buffer) { session_crash (file, _("line found without buffer")); return 0; } - /* allocate line */ + // allocate line line = gui_buffer_line_new (session_current_buffer, time (NULL)); if (!line) { @@ -1555,7 +1555,7 @@ session_load_line (FILE *file) return 0; } - /* read line values */ + // read line values rc = 1; while (rc) { @@ -1609,18 +1609,18 @@ session_load_line (FILE *file) } } return 0; -} +}*/ /* * session_load_uptime: load uptime from file */ -int +/*int session_load_uptime (FILE *file) { int object_id, rc; - /* read uptime values */ + // read uptime values rc = 1; while (rc) { @@ -1647,13 +1647,13 @@ session_load_uptime (FILE *file) } } return 0; -} +}*/ /* * session_load_hotlist: load hotlist from file */ -int +/*int session_load_hotlist (FILE *file) { int object_id, rc; @@ -1670,7 +1670,7 @@ session_load_hotlist (FILE *file) ptr_server = NULL; ptr_buffer = NULL; - /* read hotlist values */ + // read hotlist values rc = 1; while (rc) { @@ -1712,13 +1712,13 @@ session_load_hotlist (FILE *file) } } return 0; -} +}*/ /* * session_load: load session from file */ -int +/*int session_load (char *filename) { FILE *file; @@ -1838,7 +1838,7 @@ session_load (char *filename) } } - /* assign a buffer to all connected servers */ + // assign a buffer to all connected servers for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { @@ -1853,15 +1853,13 @@ session_load (char *filename) if (unlink (filename) < 0) { - irc_display_prefix (NULL, gui_current_window->buffer, GUI_PREFIX_ERROR); - gui_printf_nolog (gui_current_window->buffer, - _("%s can't delete session file (%s)\n"), - WEECHAT_ERROR, filename); + gui_printf_error_nolog (gui_current_window->buffer, + _("%s can't delete session file (%s)\n"), + WEECHAT_WARNING, filename); } - irc_display_prefix (NULL, gui_current_window->buffer, GUI_PREFIX_INFO); - gui_printf_nolog (gui_current_window->buffer, - _("Upgrade completed successfully\n")); + gui_printf_info_nolog (gui_current_window->buffer, + _("Upgrade completed successfully\n")); return 1; -} +}*/ diff --git a/src/core/wee-upgrade.h b/src/core/wee-upgrade.h index 7728220f3..3ee11d26b 100644 --- a/src/core/wee-upgrade.h +++ b/src/core/wee-upgrade.h @@ -202,4 +202,4 @@ enum t_session_hotlist int session_save (char *filename); int session_load (char *filename); -#endif /* session.h */ +#endif /* wee-session.h */ diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 176fee797..c7b8596d3 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* utf8.c: UTF-8 string functions for WeeChat */ +/* wee-utf8.c: UTF-8 string functions for WeeChat */ #ifdef HAVE_CONFIG_H @@ -27,9 +27,9 @@ #include <string.h> #include "weechat.h" -#include "utf8.h" -#include "util.h" -#include "weeconfig.h" +#include "wee-utf8.h" +#include "wee-config.h" +#include "wee-string.h" int local_utf8 = 0; @@ -41,7 +41,7 @@ int local_utf8 = 0; void utf8_init () { - local_utf8 = (ascii_strcasecmp (local_charset, "UTF-8") == 0); + local_utf8 = (string_strcasecmp (local_charset, "UTF-8") == 0); } /* @@ -260,7 +260,7 @@ utf8_strlen (char *string) } /* - * utf8_strnlen: return length of an UTF-8 string, for N bytes + * utf8_strnlen: return length of an UTF-8 string, for N bytes max in string */ int @@ -283,11 +283,12 @@ utf8_strnlen (char *string, int bytes) } /* - * utf8_width_screen: return number of chars needed on screen to display UTF-8 string + * utf8_strlen_screen: return number of chars needed on screen to display + * UTF-8 string */ int -utf8_width_screen (char *string) +utf8_strlen_screen (char *string) { int length, num_char; wchar_t *wstring; @@ -315,6 +316,30 @@ utf8_width_screen (char *string) } /* + * utf8_char_size_screen: return number of chars needed on screen to display + * UTF-8 char + */ + +int +utf8_char_size_screen (char *string) +{ + int char_size; + char utf_char[16]; + + if (!string) + return 0; + + char_size = utf8_char_size (string); + if (char_size == 0) + return 0; + + memcpy (utf_char, string, char_size); + utf_char[char_size] = '\0'; + + return utf8_strlen_screen (utf_char); +} + +/* * utf8_add_offset: moves forward N chars in an UTF-8 string */ @@ -386,11 +411,11 @@ utf8_pos (char *string, int real_pos) } /* - * utf8_get_wc: get wide char from string (first char) + * utf8_get_wide_char: get wide char from string (first char) */ wint_t -utf8_get_wc (char *string) +utf8_get_wide_char (char *string) { int char_size; wint_t result; diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h index caf7b7b10..af11e2c67 100644 --- a/src/core/wee-utf8.h +++ b/src/core/wee-utf8.h @@ -41,10 +41,11 @@ extern char *utf8_next_char (char *); extern int utf8_char_size (char *); extern int utf8_strlen (char *); extern int utf8_strnlen (char *, int); -extern int utf8_width_screen (char *); +extern int utf8_strlen_screen (char *); +extern int utf8_char_size_screen (char *); extern char *utf8_add_offset (char *, int); extern int utf8_real_pos (char *, int); extern int utf8_pos (char *, int); -extern wint_t utf8_get_wc (char *); +extern wint_t utf8_get_wide_char (char *); -#endif /* utf8.h */ +#endif /* wee-utf8.h */ diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 4fe9395c5..b150fa0b7 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* util.c: some useful functions for WeeChat */ +/* wee-util.c: some useful functions for WeeChat */ #ifdef HAVE_CONFIG_H @@ -25,706 +25,183 @@ #include <stdlib.h> #include <errno.h> -#include <stdarg.h> #include <string.h> -#include <ctype.h> - -#ifdef HAVE_ICONV -#include <iconv.h> -#endif - -#ifndef ICONV_CONST - #ifdef ICONV_2ARG_IS_CONST - #define ICONV_CONST const - #else - #define ICONV_CONST - #endif -#endif +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> #include "weechat.h" -#include "utf8.h" -#include "weeconfig.h" - - -/* - * strndup: define strndup function if not existing (FreeBSD and maybe other) - */ - -#ifndef HAVE_STRNDUP -char * -strndup (char *string, int length) -{ - char *result; - - if ((int)strlen (string) < length) - return strdup (string); - - result = (char *)malloc (length + 1); - if (!result) - return NULL; - - memcpy (result, string, length); - result[length] = '\0'; - - return result; -} -#endif - -/* - * ascii_tolower: locale independant string conversion to lower case - */ - -void -ascii_tolower (char *string) -{ - while (string && string[0]) - { - if ((string[0] >= 'A') && (string[0] <= 'Z')) - string[0] += ('a' - 'A'); - string++; - } -} - -/* - * ascii_toupper: locale independant string conversion to upper case - */ +#include "wee-util.h" +#include "wee-config.h" +#include "wee-string.h" -void -ascii_toupper (char *string) -{ - while (string && string[0]) - { - if ((string[0] >= 'a') && (string[0] <= 'z')) - string[0] -= ('a' - 'A'); - string++; - } -} /* - * ascii_strcasecmp: locale and case independent string comparison + * util_get_timeval_diff: calculates difference between two times (return in + * milliseconds) */ -int -ascii_strcasecmp (char *string1, char *string2) +long +util_get_timeval_diff (struct timeval *tv1, struct timeval *tv2) { - int c1, c2; + long diff_sec, diff_usec; - if (!string1 || !string2) - return (string1) ? 1 : ((string2) ? -1 : 0); + diff_sec = tv2->tv_sec - tv1->tv_sec; + diff_usec = tv2->tv_usec - tv1->tv_usec; - while (string1[0] && string2[0]) + if (diff_usec < 0) { - c1 = (int)((unsigned char) string1[0]); - c2 = (int)((unsigned char) string2[0]); - - if ((c1 >= 'A') && (c1 <= 'Z')) - c1 += ('a' - 'A'); - - if ((c2 >= 'A') && (c2 <= 'Z')) - c2 += ('a' - 'A'); - - if ((c1 - c2) != 0) - return c1 - c2; - - string1++; - string2++; + diff_usec += 1000000; + diff_sec--; } - - return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); + return ((diff_usec / 1000) + (diff_sec * 1000)); } /* - * ascii_strncasecmp: locale and case independent string comparison - * with max length + * util_get_time_length: calculates time length with a time format */ int -ascii_strncasecmp (char *string1, char *string2, int max) +util_get_time_length (char *time_format) { - int c1, c2, count; - - if (!string1 || !string2) - return (string1) ? 1 : ((string2) ? -1 : 0); - - count = 0; - while ((count < max) && string1[0] && string2[0]) - { - c1 = (int)((unsigned char) string1[0]); - c2 = (int)((unsigned char) string2[0]); - - if ((c1 >= 'A') && (c1 <= 'Z')) - c1 += ('a' - 'A'); - - if ((c2 >= 'A') && (c2 <= 'Z')) - c2 += ('a' - 'A'); - - if ((c1 - c2) != 0) - return c1 - c2; - - string1++; - string2++; - count++; - } + time_t date; + struct tm *local_time; + char text_time[1024]; - if (count >= max) + if (!time_format || !time_format[0]) return 0; - else - return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); -} - -/* - * ascii_strcasestr: locale and case independent string search - */ - -char * -ascii_strcasestr (char *string, char *search) -{ - int length_search; - - length_search = strlen (search); - - if (!string || !search || (length_search == 0)) - return NULL; - - while (string[0]) - { - if (ascii_strncasecmp (string, search, length_search) == 0) - return string; - - string++; - } - return NULL; + date = time (NULL); + local_time = localtime (&date); + strftime (text_time, sizeof (text_time), + time_format, local_time); + return strlen (text_time); } + /* - * weechat_iconv: convert string to another charset + * util_create_dir: create a directory + * return: 1 if ok (or directory already exists) + * 0 if error */ -char * -weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) +int +util_create_dir (char *directory, int permissions) { - char *outbuf; - -#ifdef HAVE_ICONV - iconv_t cd; - char *inbuf, *ptr_inbuf, *ptr_outbuf, *next_char; - char *ptr_inbuf_shift; - int done; - size_t err, inbytesleft, outbytesleft; - - if (from_code && from_code[0] && to_code && to_code[0] - && (ascii_strcasecmp(from_code, to_code) != 0)) + if (mkdir (directory, 0755) < 0) { - cd = iconv_open (to_code, from_code); - if (cd == (iconv_t)(-1)) - outbuf = strdup (string); - else + /* exit if error (except if directory already exists) */ + if (errno != EEXIST) { - inbuf = strdup (string); - ptr_inbuf = inbuf; - inbytesleft = strlen (inbuf); - outbytesleft = inbytesleft * 4; - outbuf = (char *) malloc (outbytesleft + 2); - ptr_outbuf = outbuf; - ptr_inbuf_shift = NULL; - done = 0; - while (!done) - { - err = iconv (cd, (ICONV_CONST char **)(&ptr_inbuf), &inbytesleft, - &ptr_outbuf, &outbytesleft); - if (err == (size_t)(-1)) - { - switch (errno) - { - case EINVAL: - done = 1; - break; - case E2BIG: - done = 1; - break; - case EILSEQ: - if (from_utf8) - { - next_char = utf8_next_char (ptr_inbuf); - if (next_char) - { - inbytesleft -= next_char - ptr_inbuf; - ptr_inbuf = next_char; - } - else - { - inbytesleft--; - ptr_inbuf++; - } - } - else - { - ptr_inbuf++; - inbytesleft--; - } - ptr_outbuf[0] = '?'; - ptr_outbuf++; - outbytesleft--; - break; - } - } - else - { - if (!ptr_inbuf_shift) - { - ptr_inbuf_shift = ptr_inbuf; - ptr_inbuf = NULL; - inbytesleft = 0; - } - else - done = 1; - } - } - if (ptr_inbuf_shift) - ptr_inbuf = ptr_inbuf_shift; - ptr_outbuf[0] = '\0'; - free (inbuf); - iconv_close (cd); + string_iconv_fprintf (stderr, + _("%s cannot create directory \"%s\"\n"), + WEECHAT_ERROR, directory); + return 0; } + return 1; } - else - outbuf = strdup (string); -#else - /* make C compiler happy */ - (void) from_utf8; - (void) from_code; - (void) to_code; - outbuf = strdup (string); -#endif /* HAVE_ICONV */ - - return outbuf; -} - -/* - * weechat_iconv_to_internal: convert user string (input, script, ..) to - * WeeChat internal storage charset - */ - -char * -weechat_iconv_to_internal (char *charset, char *string) -{ - char *input, *output; - - input = strdup (string); - - /* optimize for UTF-8: if charset is NULL => we use term charset => - if ths charset is already UTF-8, then no iconv needed */ - if (local_utf8 && (!charset || !charset[0])) - return input; - - if (input) - { - if (utf8_has_8bits (input) && utf8_is_valid (input, NULL)) - return input; - - output = weechat_iconv (0, - (charset && charset[0]) ? - charset : local_charset, - WEECHAT_INTERNAL_CHARSET, - input); - utf8_normalize (output, '?'); - free (input); - return output; - } - return NULL; -} - -/* - * weechat_iconv_from_internal: convert internal string to terminal charset, - * for display - */ - -char * -weechat_iconv_from_internal (char *charset, char *string) -{ - char *input, *output; - - input = strdup (string); - - /* optimize for UTF-8: if charset is NULL => we use term charset => - if ths charset is already UTF-8, then no iconv needed */ - if (local_utf8 && (!charset || !charset[0])) - return input; - - if (input) - { - utf8_normalize (input, '?'); - output = weechat_iconv (1, - WEECHAT_INTERNAL_CHARSET, - (charset && charset[0]) ? - charset : local_charset, - input); - free (input); - return output; - } - return NULL; + if ((permissions != 0) && (strcmp (directory, getenv ("HOME")) != 0)) + chmod (directory, permissions); + return 1; } /* - * weechat_iconv_fprintf: encode to terminal charset, then call fprintf on a file + * util_exec_on_files: find files in a directory and execute a + * function on each file */ void -weechat_iconv_fprintf (FILE *file, char *data, ...) -{ - va_list argptr; - static char buf[4096]; - char *buf2; - - va_start (argptr, data); - vsnprintf (buf, sizeof (buf) - 1, data, argptr); - va_end (argptr); - - buf2 = weechat_iconv_from_internal (NULL, buf); - fprintf (file, "%s", (buf2) ? buf2 : buf); - if (buf2) - free (buf2); -} - -/* - * weechat_strreplace: replace a string by new one in a string - * note: returned value has to be free() after use - */ - -char * -weechat_strreplace (char *string, char *search, char *replace) +util_exec_on_files (char *directory, int (*callback)(char *)) { - char *pos, *new_string; - int length1, length2, length_new, count; - - if (!string || !search || !replace) - return NULL; - - length1 = strlen (search); - length2 = strlen (replace); - - /* count number of strings to replace */ - count = 0; - pos = string; - while (pos && pos[0] && (pos = strstr (pos, search))) - { - count++; - pos += length1; - } - - /* easy: no string to replace! */ - if (count == 0) - return strdup (string); - - /* compute needed memory for new string */ - length_new = strlen (string) - (count * length1) + (count * length2) + 1; + char complete_filename[1024]; + DIR *dir; + struct dirent *entry; + struct stat statbuf; - /* allocate new string */ - new_string = (char *)malloc (length_new * sizeof (char)); - if (!new_string) - return strdup (string); - - /* replace all occurences */ - new_string[0] = '\0'; - while (string && string[0]) - { - pos = strstr (string, search); - if (pos) - { - strncat (new_string, string, pos - string); - strcat (new_string, replace); - pos += length1; - } - else - strcat (new_string, string); - string = pos; - } - return new_string; -} - -/* - * weechat_convert_hex_chars: convert hex chars (\x??) to value - */ - -char * -weechat_convert_hex_chars (char *string) -{ - char *output, hex_str[8], *error; - int pos_output; - long number; - - output = (char *)malloc (strlen (string) + 1); - if (output) + dir = opendir (directory); + if (dir) { - pos_output = 0; - while (string && string[0]) + while ((entry = readdir (dir))) { - if (string[0] == '\\') - { - string++; - switch (string[0]) - { - case '\\': - output[pos_output++] = '\\'; - string++; - break; - case 'x': - case 'X': - if (isxdigit (string[1]) - && isxdigit (string[2])) - { - snprintf (hex_str, sizeof (hex_str), - "0x%c%c", string[1], string[2]); - number = strtol (hex_str, &error, 16); - if ((error) && (error[0] == '\0')) - { - output[pos_output++] = number; - string += 3; - } - else - { - output[pos_output++] = '\\'; - output[pos_output++] = string[0]; - string++; - } - } - else - { - output[pos_output++] = string[0]; - string++; - } - break; - default: - output[pos_output++] = '\\'; - output[pos_output++] = string[0]; - string++; - break; - } - } - else + snprintf (complete_filename, sizeof (complete_filename) - 1, + "%s/%s", directory, entry->d_name); + lstat (complete_filename, &statbuf); + if (!S_ISDIR(statbuf.st_mode)) { - output[pos_output++] = string[0]; - string++; + (int) (*callback) (complete_filename); } } - output[pos_output] = '\0'; - } - - return output; -} - -/* - * get_timeval_diff: calculates difference between two times (return in milliseconds) - */ - -long -get_timeval_diff (struct timeval *tv1, struct timeval *tv2) -{ - long diff_sec, diff_usec; - - diff_sec = tv2->tv_sec - tv1->tv_sec; - diff_usec = tv2->tv_usec - tv1->tv_usec; - - if (diff_usec < 0) - { - diff_usec += 1000000; - diff_sec--; + closedir (dir); } - return ((diff_usec / 1000) + (diff_sec * 1000)); } /* - * explode_string: explode a string according to separators + * util_search_full_lib_name: search the full name of a WeeChat library + * file with a part of name + * - look in WeeChat user's dir, then WeeChat + * global lib dir + * - sys_directory is the system directory under + * WeeChat lib prefix, for example "plugins" + * - result has to be free() after use */ -char ** -explode_string (char *string, char *separators, int num_items_max, - int *num_items) +char * +util_search_full_lib_name (char *filename, char *sys_directory) { - int i, n_items; - char **array; - char *ptr, *ptr1, *ptr2; - - if (num_items != NULL) - *num_items = 0; + char *name_with_ext, *final_name; + int length; + struct stat st; - if (!string || !string[0]) - return NULL; + /* filename is already a full path */ + if (strchr (filename, '/') || strchr (filename, '\\')) + return strdup (filename); - /* calculate number of items */ - ptr = string; - i = 1; - while ((ptr = strpbrk (ptr, separators))) - { - while (strchr (separators, ptr[0]) != NULL) - ptr++; - i++; - } - n_items = i; - - if ((num_items_max != 0) && (n_items > num_items_max)) - n_items = num_items_max; + length = strlen (filename) + 16; + if (cfg_plugins_extension && cfg_plugins_extension[0]) + length += strlen (cfg_plugins_extension); + name_with_ext = (char *)malloc (length); + if (!name_with_ext) + return strdup (filename); + strcpy (name_with_ext, filename); + if (!strchr (filename, '.') + && cfg_plugins_extension && cfg_plugins_extension[0]) + strcat (name_with_ext, cfg_plugins_extension); - array = - (char **) malloc ((n_items + 1) * sizeof (char *)); - - ptr1 = string; - ptr2 = string; - - for (i = 0; i < n_items; i++) + /* try WeeChat user's dir */ + length = strlen (weechat_home) + strlen (name_with_ext) + + strlen (sys_directory) + 16; + final_name = (char *)malloc (length); + if (!final_name) { - while (strchr (separators, ptr1[0]) != NULL) - ptr1++; - if (i == (n_items - 1) || (ptr2 = strpbrk (ptr1, separators)) == NULL) - if ((ptr2 = strchr (ptr1, '\r')) == NULL) - if ((ptr2 = strchr (ptr1, '\n')) == NULL) - ptr2 = strchr (ptr1, '\0'); - - if ((ptr1 == NULL) || (ptr2 == NULL)) - { - array[i] = NULL; - } - else - { - if (ptr2 - ptr1 > 0) - { - array[i] = - (char *) malloc ((ptr2 - ptr1 + 1) * sizeof (char)); - array[i] = strncpy (array[i], ptr1, ptr2 - ptr1); - array[i][ptr2 - ptr1] = '\0'; - ptr1 = ++ptr2; - } - else - { - array[i] = NULL; - } - } + free (name_with_ext); + return strdup (filename); } - - array[i] = NULL; - if (num_items != NULL) - *num_items = i; - - return array; -} - -/* - * free_exploded_string: free an exploded string - */ - -void -free_exploded_string (char **exploded_string) -{ - int i; - - if (exploded_string) + snprintf (final_name, length, + "%s/%s/%s", weechat_home, sys_directory, name_with_ext); + if ((stat (final_name, &st) == 0) && (st.st_size > 0)) { - for (i = 0; exploded_string[i]; i++) - free (exploded_string[i]); - free (exploded_string); + free (name_with_ext); + return final_name; } -} - -/* - * 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 - */ - -char ** -split_multi_command (char *command, char sep) -{ - int nb_substr, arr_idx, str_idx, type; - char **array; - char *buffer, *ptr, *p; - - if (command == NULL) - return NULL; + free (final_name); - nb_substr = 1; - ptr = command; - while ( (p = strchr(ptr, sep)) != NULL) + /* try WeeChat global lib dir */ + length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) + + strlen (sys_directory) + 16; + final_name = (char *)malloc (length); + if (!final_name) { - nb_substr++; - ptr = ++p; + free (name_with_ext); + return strdup (filename); } - - array = (char **) malloc ((nb_substr + 1) * sizeof(char *)); - if (!array) - return NULL; - - buffer = (char *) malloc ( (strlen(command) + 1) * sizeof (char)); - if (!buffer) + snprintf (final_name, length, + "%s/%s/%s", WEECHAT_LIBDIR, sys_directory, name_with_ext); + if ((stat (final_name, &st) == 0) && (st.st_size > 0)) { - free (array); - return NULL; - } - - ptr = command; - str_idx = 0; - arr_idx = 0; - while(*ptr != '\0') - { - type = 0; - if (*ptr == ';') - { - if (ptr == command) - type = 1; - else if ( *(ptr-1) != '\\') - type = 1; - else if ( *(ptr-1) == '\\') - type = 2; - } - if (type == 1) - { - buffer[str_idx] = '\0'; - str_idx = -1; - p = buffer; - /* strip white spaces a the begining of the line */ - while (*p == ' ') p++; - if (p && p[0]) - array[arr_idx++] = strdup (p); - } - else if (type == 2) - buffer[--str_idx] = *ptr; - else - buffer[str_idx] = *ptr; - str_idx++; - ptr++; + free (name_with_ext); + return final_name; } - - buffer[str_idx] = '\0'; - p = buffer; - while (*p == ' ') p++; - if (p && p[0]) - array[arr_idx++] = strdup (p); - - array[arr_idx] = NULL; + free (final_name); - free (buffer); - - array = (char **) realloc (array, (arr_idx + 1) * sizeof(char *)); - - return array; -} - -/* - * free_multi_command : free a list of commands splitted - * with split_multi_command - */ - -void -free_multi_command (char **commands) -{ - int i; - - if (commands) - { - for (i = 0; commands[i]; i++) - free (commands[i]); - free (commands); - } + return name_with_ext; } diff --git a/src/core/wee-util.h b/src/core/wee-util.h index e3ec09e38..0652ff0c7 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -20,22 +20,10 @@ #ifndef __WEECHAT_UTIL_H #define __WEECHAT_UTIL_H 1 -#ifndef HAVE_STRNDUP -extern char *strndup (char *, int); -#endif -extern void ascii_tolower (char *); -extern void ascii_toupper (char *); -extern int ascii_strcasecmp (char *, char *); -extern int ascii_strncasecmp (char *, char *, int); -extern char *ascii_strcasestr (char *, char *); -extern char *weechat_iconv (char *, char *, char *); -extern char *weechat_iconv_to_internal (char *, char *); -extern char *weechat_iconv_from_internal (char *, char *); -extern void weechat_iconv_fprintf (FILE *, char *, ...); -extern char *weechat_strreplace (char *, char *, char *); -extern char *weechat_convert_hex_chars (char *); -extern long get_timeval_diff (struct timeval *, struct timeval *); -extern char **explode_string (char *, char *, int, int *); -extern void free_exploded_string (char **); +extern long util_get_timeval_diff (struct timeval *, struct timeval *); +extern int util_get_time_length (char *); +extern int util_create_dir (char *, int); +extern void util_exec_on_files (char *, int (*)(char *)); +extern char *util_search_full_lib_name (char *, char *); -#endif /* util.h */ +#endif /* wee-util.h */ diff --git a/src/core/weechat.c b/src/core/weechat.c index 60fc100e1..5a6c68289 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -46,31 +46,28 @@ #include <time.h> #include <signal.h> -#ifdef HAVE_GNUTLS -#include <gnutls/gnutls.h> -#endif - #ifdef HAVE_LANGINFO_CODESET #include <langinfo.h> #endif #include "weechat.h" -#include "alias.h" -#include "backtrace.h" -#include "command.h" -#include "fifo.h" -#include "hotlist.h" -#include "log.h" -#include "session.h" -#include "utf8.h" -#include "util.h" -#include "weeconfig.h" -#include "../protocols/irc/irc.h" -#include "../gui/gui.h" - -#ifdef PLUGINS -#include "../plugins/plugins.h" -#endif +#include "wee-alias.h" +#include "wee-backtrace.h" +#include "wee-command.h" +#include "wee-config.h" +#include "wee-hook.h" +#include "wee-log.h" +#include "wee-session.h" +#include "wee-string.h" +#include "wee-utf8.h" +#include "wee-util.h" +#include "../gui/gui-buffer.h" +#include "../gui/gui-chat.h" +#include "../gui/gui-hotlist.h" +#include "../gui/gui-main.h" +#include "../gui/gui-keyboard.h" +#include "../gui/gui-window.h" +#include "../plugins/plugin.h" char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */ @@ -86,10 +83,6 @@ int server_cmd_line; /* at least 1 server on WeeChat command line */ int auto_connect; /* enabled by default (cmd option to disable) */ int auto_load_plugins; /* enabled by default (cmd option to disable) */ -#ifdef HAVE_GNUTLS -gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ -#endif - /* * weechat_display_usage: display WeeChat usage @@ -98,30 +91,31 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ void weechat_display_usage (char *exec_name) { - weechat_iconv_fprintf (stdout, "\n"); - weechat_iconv_fprintf (stdout, - _("%s (c) Copyright 2003-2007, compiled on %s %s\n" - "Developed by FlashCode <flashcode@flashtux.org> - %s"), - PACKAGE_STRING, __DATE__, __TIME__, WEECHAT_WEBSITE); - weechat_iconv_fprintf (stdout, "\n\n"); - weechat_iconv_fprintf (stdout, - _("Usage: %s [options ...]\n" \ - " or: %s [irc[6][s]://[nickname[:password]@]irc.example.org[:port][/channel][,channel[...]]"), - exec_name, exec_name); - weechat_iconv_fprintf (stdout, "\n\n"); - weechat_iconv_fprintf (stdout, - _(" -a, --no-connect disable auto-connect to servers at startup\n" - " -c, --config display config file options\n" - " -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n" - " -f, --key-functions display WeeChat internal functions for keys\n" - " -h, --help this help\n" - " -i, --irc-commands display IRC commands\n" - " -k, --keys display WeeChat default keys\n" - " -l, --license display WeeChat license\n" - " -p, --no-plugin don't load any plugin at startup\n" - " -v, --version display WeeChat version\n" - " -w, --weechat-commands display WeeChat commands\n")); - weechat_iconv_fprintf(stdout, "\n"); + string_iconv_fprintf (stdout, "\n"); + string_iconv_fprintf (stdout, + _("%s (c) Copyright 2003-2007, compiled on %s %s\n" + "Developed by FlashCode <flashcode@flashtux.org> " + "- %s"), + PACKAGE_STRING, __DATE__, __TIME__, WEECHAT_WEBSITE); + string_iconv_fprintf (stdout, "\n\n"); + string_iconv_fprintf (stdout, + _("Usage: %s [options ...]\n" \ + " or: %s [irc[6][s]://[nickname[:password]@]" + "irc.example.org[:port][/channel][,channel[...]]"), + exec_name, exec_name); + string_iconv_fprintf (stdout, "\n\n"); + string_iconv_fprintf (stdout, + _(" -a, --no-connect disable auto-connect to servers at startup\n" + " -c, --config display config file options\n" + " -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n" + " -f, --key-functions display WeeChat internal functions for keys\n" + " -h, --help this help\n" + " -m, --commands display WeeChat commands\n" + " -k, --keys display WeeChat default keys\n" + " -l, --license display WeeChat license\n" + " -p, --no-plugin don't load any plugin at startup\n" + " -v, --version display WeeChat version\n\n")); + string_iconv_fprintf(stdout, "\n"); } /* @@ -131,145 +125,23 @@ weechat_display_usage (char *exec_name) void weechat_display_config_options () { - int i, j, k; - - weechat_iconv_fprintf (stdout, - _("WeeChat configuration options (<weechat_home>/weechat.rc):\n\n")); - for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++) - { - if (weechat_options[i]) - { - j = 0; - while (weechat_options[i][j].option_name) - { - weechat_iconv_fprintf (stdout, - "* %s:\n", - weechat_options[i][j].option_name); - switch (weechat_options[i][j].option_type) - { - case OPTION_TYPE_BOOLEAN: - weechat_iconv_fprintf (stdout, _(" . type: boolean\n")); - weechat_iconv_fprintf (stdout, _(" . values: 'on' or 'off'\n")); - weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"), - (weechat_options[i][j].default_int == BOOL_TRUE) ? - "on" : "off"); - break; - case OPTION_TYPE_INT: - weechat_iconv_fprintf (stdout, _(" . type: integer\n")); - weechat_iconv_fprintf (stdout, _(" . values: between %d and %d\n"), - weechat_options[i][j].min, - weechat_options[i][j].max); - weechat_iconv_fprintf (stdout, _(" . default value: %d\n"), - weechat_options[i][j].default_int); - break; - case OPTION_TYPE_INT_WITH_STRING: - weechat_iconv_fprintf (stdout, _(" . type: string\n")); - weechat_iconv_fprintf (stdout, _(" . values: ")); - k = 0; - while (weechat_options[i][j].array_values[k]) - { - weechat_iconv_fprintf (stdout, "'%s'", - weechat_options[i][j].array_values[k]); - if (weechat_options[i][j].array_values[k + 1]) - weechat_iconv_fprintf (stdout, ", "); - k++; - } - weechat_iconv_fprintf (stdout, "\n"); - weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"), - (weechat_options[i][j].default_string) ? - weechat_options[i][j].default_string : _("empty")); - break; - case OPTION_TYPE_COLOR: - weechat_iconv_fprintf (stdout, _(" . type: color\n")); - weechat_iconv_fprintf (stdout, _(" . values: Curses or Gtk color\n")); - weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"), - (weechat_options[i][j].default_string) ? - weechat_options[i][j].default_string : _("empty")); - break; - case OPTION_TYPE_STRING: - switch (weechat_options[i][j].max) - { - case 0: - weechat_iconv_fprintf (stdout, _(" . type: string\n")); - weechat_iconv_fprintf (stdout, _(" . values: any string\n")); - break; - case 1: - weechat_iconv_fprintf (stdout, _(" . type: char\n")); - weechat_iconv_fprintf (stdout, _(" . values: any char\n")); - break; - default: - weechat_iconv_fprintf (stdout, _(" . type: string\n")); - weechat_iconv_fprintf (stdout, _(" . values: any string (limit: %d chars)\n"), - weechat_options[i][j].max); - break; - } - weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"), - (weechat_options[i][j].default_string) ? - weechat_options[i][j].default_string : _("empty")); - break; - } - weechat_iconv_fprintf (stdout, _(" . description: %s\n"), - _(weechat_options[i][j].long_description)); - weechat_iconv_fprintf (stdout, "\n"); - j++; - } - } - } + string_iconv_fprintf (stdout, + _("%s configuration options:\n"), + PACKAGE_NAME); + weechat_config_print_stdout (); } /* - * weechat_display_commands: display WeeChat and/or IRC commands + * weechat_display_commands: display commands for one or more protocols */ void -weechat_display_commands (int weechat_cmd, int irc_cmd) +weechat_display_commands () { - int i; - - if (weechat_cmd) - { - weechat_iconv_fprintf (stdout, - _("%s internal commands:\n"), PACKAGE_NAME); - weechat_iconv_fprintf (stdout, "\n"); - for (i = 0; weechat_commands[i].command_name; i++) - { - weechat_iconv_fprintf (stdout, "* %s", weechat_commands[i].command_name); - if (weechat_commands[i].arguments && - weechat_commands[i].arguments[0]) - weechat_iconv_fprintf (stdout, " %s\n\n", _(weechat_commands[i].arguments)); - else - weechat_iconv_fprintf (stdout, "\n\n"); - weechat_iconv_fprintf (stdout, "%s\n\n", _(weechat_commands[i].command_description)); - if (weechat_commands[i].arguments_description && - weechat_commands[i].arguments_description[0]) - weechat_iconv_fprintf (stdout, "%s\n\n", - _(weechat_commands[i].arguments_description)); - } - } - - if (irc_cmd) - { - weechat_iconv_fprintf (stdout, _("IRC commands:\n")); - weechat_iconv_fprintf (stdout, "\n"); - for (i = 0; irc_commands[i].command_name; i++) - { - if (irc_commands[i].cmd_function_args || - irc_commands[i].cmd_function_1arg) - { - weechat_iconv_fprintf (stdout, "* %s", irc_commands[i].command_name); - if (irc_commands[i].arguments && - irc_commands[i].arguments[0]) - weechat_iconv_fprintf (stdout, " %s\n\n", _(irc_commands[i].arguments)); - else - weechat_iconv_fprintf (stdout, "\n\n"); - weechat_iconv_fprintf (stdout, "%s\n\n", _(irc_commands[i].command_description)); - if (irc_commands[i].arguments_description && - irc_commands[i].arguments_description[0]) - weechat_iconv_fprintf (stdout, "%s\n\n", - _(irc_commands[i].arguments_description)); - } - } - } + string_iconv_fprintf (stdout, + _("%s internal commands:\n"), PACKAGE_NAME); + string_iconv_fprintf (stdout, "\n"); + command_print_stdout (weechat_commands); } /* @@ -281,15 +153,15 @@ weechat_display_key_functions () { int i; - weechat_iconv_fprintf (stdout, _("Internal key functions:\n")); - weechat_iconv_fprintf (stdout, "\n"); + string_iconv_fprintf (stdout, _("Internal key functions:\n")); + string_iconv_fprintf (stdout, "\n"); i = 0; while (gui_key_functions[i].function_name) { - weechat_iconv_fprintf (stdout, - "* %s: %s\n", - gui_key_functions[i].function_name, - _(gui_key_functions[i].description)); + string_iconv_fprintf (stdout, + "* %s: %s\n", + gui_key_functions[i].function_name, + _(gui_key_functions[i].description)); i++; } } @@ -304,16 +176,17 @@ weechat_display_keys () t_gui_key *ptr_key; char *expanded_name; - weechat_iconv_fprintf (stdout, - _("%s default keys:\n"), PACKAGE_NAME); - weechat_iconv_fprintf (stdout, "\n"); + string_iconv_fprintf (stdout, + _("%s default keys:\n"), PACKAGE_NAME); + string_iconv_fprintf (stdout, "\n"); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) { expanded_name = gui_keyboard_get_expanded_name (ptr_key->key); - weechat_iconv_fprintf (stdout, - "* %s => %s\n", - (expanded_name) ? expanded_name : ptr_key->key, - (ptr_key->function) ? gui_keyboard_function_search_by_ptr (ptr_key->function) : ptr_key->command); + string_iconv_fprintf (stdout, + "* %s => %s\n", + (expanded_name) ? expanded_name : ptr_key->key, + (ptr_key->function) ? + gui_keyboard_function_search_by_ptr (ptr_key->function) : ptr_key->command); if (expanded_name) free (expanded_name); } @@ -327,8 +200,7 @@ void weechat_parse_args (int argc, char *argv[]) { int i; - t_irc_server server_tmp; - + weechat_argv0 = strdup (argv[0]); weechat_session = NULL; weechat_home = NULL; @@ -344,8 +216,20 @@ weechat_parse_args (int argc, char *argv[]) else if ((strcmp (argv[i], "-c") == 0) || (strcmp (argv[i], "--config") == 0)) { - weechat_display_config_options (); - weechat_shutdown (EXIT_SUCCESS, 0); + if (i + 1 < argc) + { + weechat_display_config_options (argv[i + 1]); + weechat_shutdown (EXIT_SUCCESS, 0); + } + else + { + string_iconv_fprintf (stderr, + _("%s missing argument for \"%s\" " + "option\n"), + WEECHAT_ERROR, + "--config"); + weechat_shutdown (EXIT_FAILURE, 0); + } } else if ((strcmp (argv[i], "-d") == 0) || (strcmp (argv[i], "--dir") == 0)) @@ -354,9 +238,11 @@ weechat_parse_args (int argc, char *argv[]) weechat_home = strdup (argv[++i]); else { - weechat_iconv_fprintf (stderr, - _("%s missing argument for --dir option\n"), - WEECHAT_ERROR); + string_iconv_fprintf (stderr, + _("%s missing argument for \"%s\" " + "option\n"), + WEECHAT_ERROR, + "--dir"); weechat_shutdown (EXIT_FAILURE, 0); } } @@ -372,12 +258,6 @@ weechat_parse_args (int argc, char *argv[]) weechat_display_usage (argv[0]); weechat_shutdown (EXIT_SUCCESS, 0); } - else if ((strcmp (argv[i], "-i") == 0) - || (strcmp (argv[i], "--irc-commands") == 0)) - { - weechat_display_commands (0, 1); - weechat_shutdown (EXIT_SUCCESS, 0); - } else if ((strcmp (argv[i], "-k") == 0) || (strcmp (argv[i], "--keys") == 0)) { @@ -387,43 +267,60 @@ weechat_parse_args (int argc, char *argv[]) else if ((strcmp (argv[i], "-l") == 0) || (strcmp (argv[i], "--license") == 0)) { - weechat_iconv_fprintf (stdout, "\n%s%s", WEE_LICENSE); + string_iconv_fprintf (stdout, "\n%s%s", WEECHAT_LICENSE); weechat_shutdown (EXIT_SUCCESS, 0); } + else if ((strcmp (argv[i], "-m") == 0) + || (strcmp (argv[i], "--commands") == 0)) + { + if (i + 1 < argc) + { + weechat_display_commands (argv[i+1]); + weechat_shutdown (EXIT_SUCCESS, 0); + } + else + { + string_iconv_fprintf (stderr, + _("%s missing argument for \"%s\" " + "option\n"), + WEECHAT_ERROR, + "--commands"); + weechat_shutdown (EXIT_FAILURE, 0); + } + } else if ((strcmp (argv[i], "-p") == 0) || (strcmp (argv[i], "--no-plugin") == 0)) + { auto_load_plugins = 0; + } else if (strcmp (argv[i], "--session") == 0) { if (i + 1 < argc) weechat_session = strdup (argv[++i]); else { - weechat_iconv_fprintf (stderr, - _("%s missing argument for --session option\n"), - WEECHAT_ERROR); + string_iconv_fprintf (stderr, + _("%s missing argument for \"%s\" " + "option\n"), + WEECHAT_ERROR, + "--session"); weechat_shutdown (EXIT_FAILURE, 0); } } else if ((strcmp (argv[i], "-v") == 0) || (strcmp (argv[i], "--version") == 0)) { - weechat_iconv_fprintf (stdout, PACKAGE_VERSION "\n"); - weechat_shutdown (EXIT_SUCCESS, 0); - } - else if ((strcmp (argv[i], "-w") == 0) - || (strcmp (argv[i], "--weechat-commands") == 0)) - { - weechat_display_commands (1, 0); + string_iconv_fprintf (stdout, PACKAGE_VERSION "\n"); weechat_shutdown (EXIT_SUCCESS, 0); } - else if ((ascii_strncasecmp (argv[i], "irc", 3) == 0)) + /*else if ((weechat_strncasecmp (argv[i], "irc", 3) == 0)) { if (irc_server_init_with_url (argv[i], &server_tmp) < 0) { - weechat_iconv_fprintf (stderr, - _("%s invalid syntax for IRC server ('%s'), ignored\n"), - WEECHAT_WARNING, argv[i]); + string_iconv_fprintf (stderr, + _("%s invalid syntax for IRC server " + "('%s'), ignored\n"), + WEECHAT_WARNING, argv[i]); } else { @@ -436,48 +333,24 @@ weechat_parse_args (int argc, char *argv[]) server_tmp.nick2, server_tmp.nick3, NULL, NULL, NULL, NULL, 0, server_tmp.autojoin, 1, NULL)) - weechat_iconv_fprintf (stderr, - _("%s unable to create server ('%s'), ignored\n"), - WEECHAT_WARNING, argv[i]); + string_iconv_fprintf (stderr, + _("%s unable to create server " + "('%s'), ignored\n"), + WEECHAT_WARNING, argv[i]); irc_server_destroy (&server_tmp); server_cmd_line = 1; } - } + }*/ else { - weechat_iconv_fprintf (stderr, - _("%s unknown parameter '%s', ignored\n"), - WEECHAT_WARNING, argv[i]); + string_iconv_fprintf (stderr, + _("%s unknown parameter '%s', ignored\n"), + WEECHAT_WARNING, argv[i]); } } } /* - * weechat_create_dir: create a directory - * return: 1 if ok (or directory already exists) - * 0 if error - */ - -int -weechat_create_dir (char *directory, int permissions) -{ - if (mkdir (directory, 0755) < 0) - { - /* exit if error (except if directory already exists) */ - if (errno != EEXIST) - { - weechat_iconv_fprintf (stderr, _("%s cannot create directory \"%s\"\n"), - WEECHAT_ERROR, directory); - return 0; - } - return 1; - } - if ((permissions != 0) && (strcmp (directory, getenv ("HOME")) != 0)) - chmod (directory, permissions); - return 1; -} - -/* * weechat_create_home_dirs: create WeeChat directories */ @@ -493,8 +366,9 @@ weechat_create_home_dirs () ptr_home = getenv ("HOME"); if (!ptr_home) { - weechat_iconv_fprintf (stderr, _("%s unable to get HOME directory\n"), - WEECHAT_ERROR); + string_iconv_fprintf (stderr, + _("%s unable to get HOME directory\n"), + WEECHAT_ERROR); weechat_shutdown (EXIT_FAILURE, 0); } dir_length = strlen (ptr_home) + 10; @@ -502,8 +376,10 @@ weechat_create_home_dirs () (char *) malloc (dir_length * sizeof (char)); if (!weechat_home) { - weechat_iconv_fprintf (stderr, _("%s not enough memory for home directory\n"), - WEECHAT_ERROR); + string_iconv_fprintf (stderr, + _("%s not enough memory for home " + "directory\n"), + WEECHAT_ERROR); weechat_shutdown (EXIT_FAILURE, 0); } snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home, @@ -515,17 +391,19 @@ weechat_create_home_dirs () { if (!S_ISDIR (statinfo.st_mode)) { - weechat_iconv_fprintf (stderr, _("%s home (%s) is not a directory\n"), - WEECHAT_ERROR, weechat_home); + string_iconv_fprintf (stderr, + _("%s home (%s) is not a directory\n"), + WEECHAT_ERROR, weechat_home); weechat_shutdown (EXIT_FAILURE, 0); } } /* create home directory; error is fatal */ - if (!weechat_create_dir (weechat_home, 0)) + if (!util_create_dir (weechat_home, 0)) { - weechat_iconv_fprintf (stderr, _("%s unable to create \"%s\" directory\n"), - WEECHAT_ERROR, weechat_home); + string_iconv_fprintf (stderr, + _("%s unable to create \"%s\" directory\n"), + WEECHAT_ERROR, weechat_home); weechat_shutdown (EXIT_FAILURE, 0); } } @@ -540,22 +418,17 @@ weechat_create_config_dirs () char *dir1, *dir2; /* create logs directory" */ - dir1 = weechat_strreplace (cfg_log_path, "~", getenv ("HOME")); - dir2 = weechat_strreplace (dir1, "%h", weechat_home); - (void) weechat_create_dir (dir2, 0700); - if (dir1) - free (dir1); - if (dir2) - free (dir2); - - /* create DCC download directory */ - dir1 = weechat_strreplace (cfg_dcc_download_path, "~", getenv ("HOME")); - dir2 = weechat_strreplace (dir1, "%h", weechat_home); - (void) weechat_create_dir (dir2, 0700); + dir1 = string_replace (cfg_log_path, "~", getenv ("HOME")); if (dir1) + { + dir2 = string_replace (dir1, "%h", weechat_home); + if (dir2) + { + (void) util_create_dir (dir2, 0700); + free (dir2); + } free (dir1); - if (dir2) - free (dir2); + } } /* @@ -567,36 +440,6 @@ weechat_init_vars () { /* start time, used by /uptime command */ weechat_start_time = time (NULL); - - /* init gnutls */ -#ifdef HAVE_GNUTLS - gnutls_global_init (); - gnutls_certificate_allocate_credentials (&gnutls_xcred); - gnutls_certificate_set_x509_trust_file (gnutls_xcred, "ca.pem", GNUTLS_X509_FMT_PEM); -#endif -} - -/* - * weechat_config_read: read WeeChat config file - */ - -void -weechat_config_read () -{ - switch (config_read ()) - { - case 0: /* read ok */ - break; - case -1: /* config file not found */ - if (config_create_default () < 0) - exit (EXIT_FAILURE); - if (config_read () != 0) - exit (EXIT_FAILURE); - break; - default: /* other error (fatal) */ - irc_server_free_all (); - exit (EXIT_FAILURE); - } } /* @@ -608,42 +451,42 @@ weechat_welcome_message () { if (cfg_look_startup_logo) { - gui_printf (NULL, - "%s ___ __ ______________ _____ \n" - "%s __ | / /___________ ____/__ /_______ __ /_\n" - "%s __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n" - "%s __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n" - "%s ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ \n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK), - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK)); + gui_chat_printf (NULL, + "%s ___ __ ______________ _____ \n" + "%s __ | / /___________ ____/__ /_______ __ /_\n" + "%s __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n" + "%s __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n" + "%s ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ ", + GUI_COLOR(GUI_COLOR_CHAT_NICK), + GUI_COLOR(GUI_COLOR_CHAT_NICK), + GUI_COLOR(GUI_COLOR_CHAT_NICK), + GUI_COLOR(GUI_COLOR_CHAT_NICK), + GUI_COLOR(GUI_COLOR_CHAT_NICK)); } if (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) { - gui_printf (NULL, _("%sWelcome to %s%s%s, %s\n"), - (cfg_look_startup_logo) ? " " : "", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - PACKAGE_NAME, - GUI_NO_COLOR, - cfg_look_weechat_slogan); + gui_chat_printf (NULL, _("%sWelcome to %s%s%s, %s"), + (cfg_look_startup_logo) ? " " : "", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + PACKAGE_NAME, + GUI_NO_COLOR, + cfg_look_weechat_slogan); } if (cfg_look_startup_version) { - gui_printf (NULL, "%s%s%s%s, %s %s %s\n", - (cfg_look_startup_logo) ? " " : "", - GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL), - PACKAGE_STRING, - GUI_NO_COLOR, - _("compiled on"), __DATE__, __TIME__); + gui_chat_printf (NULL, "%s%s%s%s, %s %s %s", + (cfg_look_startup_logo) ? " " : "", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + PACKAGE_STRING, + GUI_NO_COLOR, + _("compiled on"), __DATE__, __TIME__); } if (cfg_look_startup_logo || (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) || cfg_look_startup_version) - gui_printf (NULL, - "%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n", - GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK)); + gui_chat_printf (NULL, + "%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", + GUI_COLOR(GUI_COLOR_CHAT_NICK)); weechat_log_printf ("%s (%s %s %s)\n", PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__); @@ -658,7 +501,6 @@ weechat_shutdown (int return_code, int crash) { if (weechat_argv0) free (weechat_argv0); - fifo_remove (); if (weechat_home) free (weechat_home); weechat_log_close (); @@ -666,11 +508,6 @@ weechat_shutdown (int return_code, int crash) free (local_charset); alias_free_all (); -#ifdef HAVE_GNUTLS - gnutls_certificate_free_credentials (gnutls_xcred); - gnutls_global_deinit(); -#endif - if (crash) abort(); else @@ -684,15 +521,6 @@ weechat_shutdown (int return_code, int crash) void weechat_dump (int crash) { - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; - t_irc_nick *ptr_nick; - t_gui_window *ptr_window; - t_gui_buffer *ptr_buffer; -#ifdef PLUGINS - t_weechat_plugin *ptr_plugin; -#endif - /* prevent reentrance */ if (sigsegv) exit (EXIT_FAILURE); @@ -714,73 +542,14 @@ weechat_dump (int crash) { weechat_log_printf ("****** WeeChat dump request ******\n"); } + + gui_window_print_log (); + gui_buffer_print_log (); + gui_hotlist_print_log (); - for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) - { - weechat_log_printf ("\n"); - irc_server_print_log (ptr_server); - - for (ptr_channel = ptr_server->channels; ptr_channel; - ptr_channel = ptr_channel->next_channel) - { - weechat_log_printf ("\n"); - irc_channel_print_log (ptr_channel); - - for (ptr_nick = ptr_channel->nicks; ptr_nick; - ptr_nick = ptr_nick->next_nick) - { - weechat_log_printf ("\n"); - irc_nick_print_log (ptr_nick); - } - - } - } - - irc_dcc_print_log (); - - gui_panel_print_log (); - - weechat_log_printf ("\n"); - weechat_log_printf ("[windows/buffers]\n"); - weechat_log_printf (" => windows:\n"); - for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window) - { - weechat_log_printf (" 0x%X\n", ptr_window); - } - weechat_log_printf (" => buffers:\n"); - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - weechat_log_printf (" 0x%X\n", ptr_buffer); - } - weechat_log_printf (" => current window = 0x%X\n", gui_current_window); - - for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window) - { - weechat_log_printf ("\n"); - gui_window_print_log (ptr_window); - } - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - weechat_log_printf ("\n"); - gui_buffer_print_log (ptr_buffer); - } - - weechat_log_printf ("\n"); - irc_ignore_print_log (); - - weechat_log_printf ("\n"); - hotlist_print_log (); + hook_print_log (); -#ifdef PLUGINS - for (ptr_plugin = weechat_plugins; ptr_plugin; - ptr_plugin = ptr_plugin->next_plugin) - { - weechat_log_printf ("\n"); - plugin_print_log (ptr_plugin); - } -#endif + plugin_print_log (); weechat_log_printf ("\n"); weechat_log_printf ("****** End of dump ******\n"); @@ -788,31 +557,30 @@ weechat_dump (int crash) } /* - * weechat_sigsegv: SIGSEGV handler: save crash log to <weechat_home>/weechat.log and exit + * weechat_sigsegv: SIGSEGV handler: save crash log to + * <weechat_home>/weechat.log and exit */ void weechat_sigsegv () { weechat_dump (1); - irc_dcc_end (); - irc_server_free_all (); gui_main_end (); - weechat_iconv_fprintf (stderr, "\n"); - weechat_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n"); + string_iconv_fprintf (stderr, "\n"); + string_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n"); if (!weechat_log_crash_rename ()) - weechat_iconv_fprintf (stderr, - "*** Full crash dump was saved to %s/weechat.log file.\n", - weechat_home); - weechat_iconv_fprintf (stderr, "***\n"); - weechat_iconv_fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n"); - weechat_iconv_fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n"); - weechat_iconv_fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n"); - weechat_iconv_fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n"); - weechat_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n"); - weechat_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n"); - weechat_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n"); + string_iconv_fprintf (stderr, + "*** Full crash dump was saved to %s/weechat.log file.\n", + weechat_home); + string_iconv_fprintf (stderr, "***\n"); + string_iconv_fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n"); + string_iconv_fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n"); + string_iconv_fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n"); + string_iconv_fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n"); + string_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n"); + string_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n"); + string_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n"); weechat_backtrace (); @@ -851,32 +619,20 @@ main (int argc, char *argv[]) weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dirs (); /* create WeeChat directories */ weechat_log_init (); /* init log file */ - command_index_build (); /* build cmd index for completion */ - weechat_config_read (); /* read configuration */ + if (weechat_config_read () < 0) /* read WeeChat configuration */ + exit (EXIT_FAILURE); weechat_create_config_dirs (); /* create config directories */ + command_index_build (); /* build cmd index for completion */ gui_main_init (); /* init WeeChat interface */ - fifo_create (); /* FIFO pipe for remote control */ - if (weechat_session) - session_load (weechat_session); /* load previous session if asked */ + //if (weechat_session) + //session_load (weechat_session); /* load previous session if asked */ weechat_welcome_message (); /* display WeeChat welcome message */ -#ifdef PLUGINS plugin_init (auto_load_plugins); /* init plugin interface(s) */ -#endif - - irc_server_auto_connect (auto_connect, /* auto-connect to servers */ - server_cmd_line); - gui_main_loop (); /* WeeChat main loop */ - -#ifdef PLUGINS plugin_end (); /* end plugin interface(s) */ -#endif - irc_server_disconnect_all (); /* disconnect from all servers */ if (cfg_look_save_on_exit) - (void) config_write (NULL); /* save config file */ + (void) weechat_config_write (NULL); /* save WeeChat config file */ command_index_free (); /* free commands index */ - irc_dcc_end (); /* remove all DCC */ - irc_server_free_all (); /* free all servers */ gui_main_end (); /* shut down WeeChat GUI */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ diff --git a/src/core/weechat.h b/src/core/weechat.h index 34e95a50e..ef7da227c 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -66,7 +66,7 @@ /* license */ -#define WEE_LICENSE \ +#define WEECHAT_LICENSE \ PACKAGE_STRING " (c) Copyright 2003-2007, compiled on " __DATE__ " " __TIME__ \ "\nDeveloped by FlashCode <flashcode@flashtux.org> - " WEECHAT_WEBSITE "\n\n" \ "This program is free software; you can redistribute it and/or modify\n" \ @@ -111,10 +111,6 @@ extern int quit_weechat; extern char *weechat_home; extern char *local_charset; -#ifdef HAVE_GNUTLS -extern gnutls_certificate_credentials gnutls_xcred; -#endif - extern void weechat_dump (int); extern void weechat_shutdown (int, int); |