summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/wee-command.c956
-rw-r--r--src/core/wee-command.h51
-rw-r--r--src/core/wee-config-file.c21
-rw-r--r--src/core/wee-config-file.h1
-rw-r--r--src/core/wee-config.c1
-rw-r--r--src/core/wee-hook.c129
-rw-r--r--src/core/wee-hook.h4
-rw-r--r--src/core/wee-input.c108
-rw-r--r--src/core/wee-list.c2
-rw-r--r--src/core/weechat.c21
-rw-r--r--src/gui/curses/Makefile.am14
-rw-r--r--src/gui/gtk/Makefile.am14
-rw-r--r--src/gui/gui-action.c1
-rw-r--r--src/gui/gui-buffer.c11
-rw-r--r--src/gui/gui-completion.c90
-rw-r--r--src/gui/gui-keyboard.c1
-rw-r--r--src/gui/gui-window.c1
-rw-r--r--src/plugins/alias/alias.c3
-rw-r--r--src/plugins/plugin-api.c1
-rw-r--r--src/plugins/plugin.c5
20 files changed, 712 insertions, 723 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 86542b60c..69ae10b29 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -49,297 +49,12 @@
#include "../plugins/plugin-config.h"
-/* WeeChat internal commands */
-
-struct command weechat_commands[] =
-{ { "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\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"
- " (when executed on server buffer, this sets default notify "
- "level for whole server)\n"
- " scroll: scroll in history (may be relative, and may end by a letter: "
- "s=sec, m=min, h=hour, d=day, M=month, y=year); if there is "
- "only letter, then scroll to beginning of this item\n\n"
- " number: jump to buffer by number\n"
- "server,\n"
- "channel: jump to buffer by server and/or channel name\n\n"
- "Examples:\n"
- " 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 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|set|%S|%C %S|%C",
- 0, MAX_ARGS, 0, command_buffer },
- { "builtin",
- N_("launch WeeChat builtin command (do not look at commands hooked or "
- "aliases)"),
- N_("command"),
- N_("command: command to execute (a '/' is automatically added if not "
- "found at beginning of command)\n"),
- "%w", 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, 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"
- " buffer: dump buffer content with hexadecimal values in log file\n"
- "windows: display windows tree"),
- "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|%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, 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, 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"
- " 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, command_plugin },
- { "quit",
- N_("quit WeeChat"), "", "",
- NULL, 0, 0, 0, command_quit },
- { "reload",
- N_("reload WeeChat and plugins configuration files from disk"),
- "", "",
- NULL, 0, 0, 0, command_reload },
- { "save",
- N_("save WeeChat and plugins configuration files to disk"),
- "", "",
- NULL, 0, 0, 0, command_save },
- { "set", N_("set config options"),
- N_("[option [ = value]]"),
- N_("option: name of an option (if name is full "
- "and no value is given, then help is displayed on option)\n"
- " 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, 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, command_setp },
- { "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, command_upgrade },
- { "uptime",
- N_("show WeeChat uptime"),
- N_("[-o]"),
- N_("-o: send uptime on current channel as an IRC message"),
- "-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"
- " -1: jump to previous window\n"
- " +1: jump to next window\n"
- " b#: jump to next window displaying buffer number #\n"
- " up: switch to window above current one\n"
- " down: switch to window below current one\n"
- " left: switch to window on the left\n"
- " 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"
- " 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, command_window },
- { NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL }
-};
-
-struct t_weelist *weechat_index_commands;
-struct t_weelist *weechat_last_index_command;
-
-
-/*
- * command_is_used: return 1 if command is used by weechat
- * (WeeChat command)
- */
-
-int
-command_is_used (char *command)
-{
- int i;
-
- /* look for WeeChat command */
- for (i = 0; weechat_commands[i].name; i++)
- {
- if (string_strcasecmp (weechat_commands[i].name, command) == 0)
- return 1;
- }
-
- /* no command found */
- return 0;
-}
-
-/*
- * command_index_build: build an index of commands (internal, irc and alias)
- * This list will be sorted, and used for completion
- */
-
-void
-command_index_build ()
-{
- int i;
-
- weechat_index_commands = NULL;
- weechat_last_index_command = NULL;
- i = 0;
- while (weechat_commands[i].name)
- {
- (void) weelist_add (&weechat_index_commands,
- &weechat_last_index_command,
- weechat_commands[i].name,
- WEELIST_POS_SORT);
- i++;
- }
-}
-
-/*
- * command_index_free: remove all commands in index
- */
-
-void
-command_index_free ()
-{
- while (weechat_index_commands)
- {
- weelist_remove (&weechat_index_commands,
- &weechat_last_index_command,
- weechat_index_commands);
- }
-}
-
-/*
- * command_index_add: add command to commands index
- */
-
-void
-command_index_add (char *command)
-{
- if (!weelist_search (weechat_index_commands, command))
- weelist_add (&weechat_index_commands, &weechat_last_index_command,
- command, WEELIST_POS_SORT);
-}
-
-/*
- * 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));
-}
-
-/*
- * command_is_command: return 1 if line is a command, 0 otherwise
- */
-
-int
-command_is_command (char *line)
-{
- char *pos_slash, *pos_space;
-
- if (strncmp (line, "/*", 2) == 0)
- return 0;
-
- pos_slash = strchr (line + 1, '/');
- pos_space = strchr (line + 1, ' ');
-
- return (line[0] == '/')
- && (!pos_slash || (pos_space && pos_slash > pos_space));
-}
-
-/*
- * command_print_stdout: print list of commands on standard output
- */
-
-void
-command_print_stdout (struct command *commands)
-{
- int i;
-
- for (i = 0; commands[i].name; i++)
- {
- 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));
- }
-}
-
/*
* command_buffer: manage buffers
*/
int
-command_buffer (struct t_gui_buffer *buffer,
+command_buffer (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
struct t_gui_buffer *ptr_buffer;
@@ -347,13 +62,16 @@ command_buffer (struct t_gui_buffer *buffer,
char *error ,*value;
int target_buffer;
- if ((argc == 0)
- || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0)))
+ /* make C compiler happy */
+ (void) data;
+
+ if ((argc == 1)
+ || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0)))
{
- /* list open buffers */
+ /* list buffers */
gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, _("Open buffers:"));
+ gui_chat_printf (NULL, _("Buffers list:"));
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
@@ -374,11 +92,11 @@ command_buffer (struct t_gui_buffer *buffer,
}
else
{
- if (string_strcasecmp (argv[0], "move") == 0)
+ if (string_strcasecmp (argv[1], "move") == 0)
{
/* move buffer to another number in the list */
- if (argc < 2)
+ if (argc < 3)
{
gui_chat_printf (NULL,
_("%sError: missing arguments for \"%s\" "
@@ -389,17 +107,17 @@ command_buffer (struct t_gui_buffer *buffer,
}
error = NULL;
- number = strtol (((argv[1][0] == '+') || (argv[1][0] == '-')) ?
- argv[1] + 1 : argv[1],
+ number = strtol (((argv[2][0] == '+') || (argv[2][0] == '-')) ?
+ argv[2] + 1 : argv[2],
&error, 10);
if (error && (error[0] == '\0'))
{
- if (argv[1][0] == '+')
+ if (argv[2][0] == '+')
gui_buffer_move_to_number (buffer,
- buffer->number + ((int) number));
- else if (argv[1][0] == '-')
+ ((struct t_gui_buffer *)buffer)->number + ((int) number));
+ else if (argv[2][0] == '-')
gui_buffer_move_to_number (buffer,
- buffer->number - ((int) number));
+ ((struct t_gui_buffer *)buffer)->number - ((int) number));
else
gui_buffer_move_to_number (buffer, (int) number);
}
@@ -412,9 +130,9 @@ command_buffer (struct t_gui_buffer *buffer,
return -1;
}
}
- else if (string_strcasecmp (argv[0], "close") == 0)
+ else if (string_strcasecmp (argv[1], "close") == 0)
{
- if (!buffer->plugin)
+ if (!((struct t_gui_buffer *)buffer)->plugin)
{
gui_chat_printf (NULL,
_("%sError: WeeChat main buffer can't be "
@@ -426,9 +144,9 @@ command_buffer (struct t_gui_buffer *buffer,
gui_status_draw (gui_current_window->buffer, 1);
gui_input_draw (gui_current_window->buffer, 1);
}
- else if (string_strcasecmp (argv[0], "notify") == 0)
+ else if (string_strcasecmp (argv[1], "notify") == 0)
{
- if (argc < 2)
+ if (argc < 3)
{
/* display notify level for all buffers */
gui_chat_printf (NULL, "");
@@ -448,7 +166,7 @@ command_buffer (struct t_gui_buffer *buffer,
{
/* set notify level for buffer */
error = NULL;
- number = strtol (argv[1], &error, 10);
+ number = strtol (argv[2], &error, 10);
if (error && (error[0] == '\0'))
{
if ((number < GUI_BUFFER_NOTIFY_LEVEL_MIN)
@@ -468,7 +186,7 @@ command_buffer (struct t_gui_buffer *buffer,
"%d %s"),
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
- buffer->name,
+ ((struct t_gui_buffer *)buffer)->name,
GUI_COLOR(GUI_COLOR_CHAT),
number,
GUI_COLOR(GUI_COLOR_CHAT));
@@ -511,11 +229,11 @@ command_buffer (struct t_gui_buffer *buffer,
}
}
}
- else if (string_strcasecmp (argv[0], "set") == 0)
+ else if (string_strcasecmp (argv[1], "set") == 0)
{
/* set a property on buffer */
- if (argc < 3)
+ if (argc < 4)
{
gui_chat_printf (NULL,
_("%sError: missing arguments for \"%s\" "
@@ -524,8 +242,8 @@ command_buffer (struct t_gui_buffer *buffer,
"buffer");
return -1;
}
- value = string_remove_quotes (argv_eol[2], "'\"");
- gui_buffer_set (buffer, argv[1], (value) ? value : argv_eol[2]);
+ value = string_remove_quotes (argv_eol[3], "'\"");
+ gui_buffer_set (buffer, argv[2], (value) ? value : argv_eol[3]);
if (value)
free (value);
}
@@ -533,14 +251,14 @@ command_buffer (struct t_gui_buffer *buffer,
{
/* jump to buffer by number or server/channel name */
- if (argv[0][0] == '-')
+ if (argv[1][0] == '-')
{
/* relative jump '-' */
error = NULL;
- number = strtol (argv[0] + 1, &error, 10);
+ number = strtol (argv[1] + 1, &error, 10);
if (error && (error[0] == '\0'))
{
- target_buffer = buffer->number - (int) number;
+ target_buffer = ((struct t_gui_buffer *)buffer)->number - (int) number;
if (target_buffer < 1)
target_buffer = (last_gui_buffer) ?
last_gui_buffer->number + target_buffer : 1;
@@ -548,14 +266,14 @@ command_buffer (struct t_gui_buffer *buffer,
target_buffer);
}
}
- else if (argv[0][0] == '+')
+ else if (argv[1][0] == '+')
{
/* relative jump '+' */
error = NULL;
- number = strtol (argv[0] + 1, &error, 10);
+ number = strtol (argv[1] + 1, &error, 10);
if (error && (error[0] == '\0'))
{
- target_buffer = buffer->number + (int) number;
+ target_buffer = ((struct t_gui_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 (gui_current_window,
@@ -566,23 +284,23 @@ command_buffer (struct t_gui_buffer *buffer,
{
/* absolute jump by number, or by category/name */
error = NULL;
- number = strtol (argv[0], &error, 10);
+ number = strtol (argv[1], &error, 10);
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_by_category_name (argv[0],
- argv[1]);
+ if (argc > 2)
+ ptr_buffer = gui_buffer_search_by_category_name (argv[1],
+ argv[2]);
else
{
- ptr_buffer = gui_buffer_search_by_category_name (argv[0],
+ ptr_buffer = gui_buffer_search_by_category_name (argv[1],
NULL);
if (!ptr_buffer)
ptr_buffer = gui_buffer_search_by_category_name (NULL,
- argv[0]);
+ argv[1]);
}
if (ptr_buffer)
{
@@ -603,23 +321,26 @@ command_buffer (struct t_gui_buffer *buffer,
*/
int
-command_builtin (struct t_gui_buffer *buffer,
+command_builtin (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
char *command;
int length;
- if (argc > 0)
+ /* make C compiler happy */
+ (void) data;
+
+ if (argc > 1)
{
- if (argv[0][0] == '/')
- input_data (buffer, argv_eol[0], 1);
+ if (argv[1][0] == '/')
+ input_data (buffer, argv_eol[1], 1);
else
{
- length = strlen (argv_eol[0]) + 2;
+ length = strlen (argv_eol[1]) + 2;
command = (char *)malloc (length);
if (command)
{
- snprintf (command, length, "/%s", argv_eol[0]);
+ snprintf (command, length, "/%s", argv_eol[1]);
input_data (buffer, command, 1);
free (command);
}
@@ -633,7 +354,7 @@ command_builtin (struct t_gui_buffer *buffer,
*/
int
-command_clear (struct t_gui_buffer *buffer,
+command_clear (void *data, void *buffer,
int argc, char**argv, char **argv_eol)
{
struct t_gui_buffer *ptr_buffer;
@@ -642,15 +363,16 @@ command_clear (struct t_gui_buffer *buffer,
int i;
/* make C compiler happy */
+ (void) data;
(void) argv_eol;
- if (argc > 0)
+ if (argc > 1)
{
- if (string_strcasecmp (argv[0], "-all") == 0)
+ if (string_strcasecmp (argv[1], "-all") == 0)
gui_buffer_clear_all ();
else
{
- for (i = 0; i < argc; i++)
+ for (i = 1; i < argc; i++)
{
error = NULL;
number = strtol (argv[i], &error, 10);
@@ -713,26 +435,27 @@ command_debug_display_windows (struct t_gui_window_tree *tree, int indent)
*/
int
-command_debug (struct t_gui_buffer *buffer,
+command_debug (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
/* make C compiler happy */
+ (void) data;
(void) argv_eol;
- if (argc >= 1)
+ if (argc >= 2)
{
- if (string_strcasecmp (argv[0], "dump") == 0)
+ if (string_strcasecmp (argv[1], "dump") == 0)
{
weechat_dump (0);
}
- else if (string_strcasecmp (argv[0], "buffer") == 0)
+ else if (string_strcasecmp (argv[1], "buffer") == 0)
{
gui_buffer_dump_hexa (buffer);
gui_chat_printf (NULL,
"DEBUG: buffer content written in WeeChat "
"log file");
}
- else if (string_strcasecmp (argv[0], "windows") == 0)
+ else if (string_strcasecmp (argv[1], "windows") == 0)
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, "DEBUG: windows tree:");
@@ -756,34 +479,46 @@ command_debug (struct t_gui_buffer *buffer,
*/
int
-command_help (struct t_gui_buffer *buffer,
+command_help (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
- int i;
struct t_hook *ptr_hook;
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argv_eol;
switch (argc)
{
- case 0:
+ case 1:
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("%s internal commands:"), PACKAGE_NAME);
- for (i = 0; weechat_commands[i].name; i++)
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
{
- if (weechat_commands[i].description
- && weechat_commands[i].description[0])
- gui_chat_printf (NULL, " %s%s %s- %s",
+ if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && !ptr_hook->plugin
+ && HOOK_COMMAND(ptr_hook, command)
+ && HOOK_COMMAND(ptr_hook, command)[0])
+ {
+ gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s",
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
- weechat_commands[i].name,
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ "(" : "",
+ HOOK_COMMAND(ptr_hook, command),
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ ")" : "",
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);
+ (HOOK_COMMAND(ptr_hook, description)
+ && HOOK_COMMAND(ptr_hook, description)[0]) ?
+ " - " : "",
+ (HOOK_COMMAND(ptr_hook, description)
+ && HOOK_COMMAND(ptr_hook, description)[0]) ?
+ _(HOOK_COMMAND(ptr_hook, description)) : "",
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ _(" (used by a plugin)") : "");
+ }
}
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Other commands:"));
@@ -791,32 +526,39 @@ command_help (struct t_gui_buffer *buffer,
ptr_hook = ptr_hook->next_hook)
{
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && ptr_hook->plugin
&& HOOK_COMMAND(ptr_hook, command)
&& HOOK_COMMAND(ptr_hook, command)[0])
{
- 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));
+ gui_chat_printf (NULL, " %s%s%s%s%s%s%s%s",
+ GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ "(" : "",
+ HOOK_COMMAND(ptr_hook, command),
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ ")" : "",
+ GUI_COLOR(GUI_COLOR_CHAT),
+ (HOOK_COMMAND(ptr_hook, description)
+ && HOOK_COMMAND(ptr_hook, description)[0]) ?
+ " - " : "",
+ (HOOK_COMMAND(ptr_hook, description)
+ && HOOK_COMMAND(ptr_hook, description)[0]) ?
+ HOOK_COMMAND(ptr_hook, description) : "",
+ (HOOK_COMMAND(ptr_hook, level) > 0) ?
+ _(" (masked by a plugin)") : "");
}
}
break;
- case 1:
+ case 2:
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]
+ && (HOOK_COMMAND(ptr_hook, level) == 0)
&& (string_strcasecmp (HOOK_COMMAND(ptr_hook, command),
- argv[0]) == 0))
+ argv[1]) == 0))
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL,
@@ -848,40 +590,11 @@ command_help (struct t_gui_buffer *buffer,
return 0;
}
}
- for (i = 0; weechat_commands[i].name; i++)
- {
- if (string_strcasecmp (weechat_commands[i].name, argv[0]) == 0)
- {
- 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_chat_printf (NULL, "");
- gui_chat_printf (NULL, "%s",
- _(weechat_commands[i].arguments_description));
- }
- return 0;
- }
- }
gui_chat_printf (NULL,
_("%sNo help available, \"%s\" is an "
"unknown command"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[0]);
+ argv[1]);
break;
}
return 0;
@@ -892,32 +605,33 @@ command_help (struct t_gui_buffer *buffer,
*/
int
-command_history (struct t_gui_buffer *buffer,
+command_history (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
struct t_gui_history *ptr_history;
int n, n_total, n_user, displayed;
/* make C compiler happy */
+ (void) data;
(void) argv_eol;
n_user = CONFIG_INTEGER(config_history_display_default);
- if (argc == 1)
+ if (argc == 2)
{
- if (string_strcasecmp (argv[0], "clear") == 0)
+ if (string_strcasecmp (argv[1], "clear") == 0)
{
gui_history_buffer_free (buffer);
return 0;
}
else
- n_user = atoi (argv[0]);
+ n_user = atoi (argv[1]);
}
- if (buffer->history)
+ if (((struct t_gui_buffer *)buffer)->history)
{
n_total = 1;
- for (ptr_history = buffer->history;
+ for (ptr_history = ((struct t_gui_buffer *)buffer)->history;
ptr_history->next_history;
ptr_history = ptr_history->next_history)
{
@@ -982,7 +696,7 @@ command_key_display (t_gui_key *key, int new_key)
*/
int
-command_key (struct t_gui_buffer *buffer,
+command_key (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
char *args, *internal_code;
@@ -991,9 +705,10 @@ command_key (struct t_gui_buffer *buffer,
t_gui_key_func *ptr_function;
/* make C compiler happy */
+ (void) data;
(void) buffer;
- if (argc == 0)
+ if (argc == 1)
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Key bindings:"));
@@ -1004,7 +719,7 @@ command_key (struct t_gui_buffer *buffer,
return 0;
}
- if (string_strcasecmp (argv[0], "functions") == 0)
+ if (string_strcasecmp (argv[1], "functions") == 0)
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Internal key functions:"));
@@ -1020,9 +735,9 @@ command_key (struct t_gui_buffer *buffer,
return 0;
}
- if (string_strcasecmp (argv[0], "reset") == 0)
+ if (string_strcasecmp (argv[1], "reset") == 0)
{
- if ((argc == 1) && (string_strcasecmp (argv[1], "-yes") == 0))
+ if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0))
{
gui_keyboard_free_all ();
gui_keyboard_init ();
@@ -1041,47 +756,52 @@ command_key (struct t_gui_buffer *buffer,
return 0;
}
- if (string_strcasecmp (argv[0], "unbind") == 0)
+ if (string_strcasecmp (argv[1], "unbind") == 0)
{
- if (argc >= 2)
+ if (argc >= 3)
{
- if (gui_keyboard_unbind (argv[1]))
+ if (gui_keyboard_unbind (argv[2]))
{
gui_chat_printf (NULL,
_("%sKey \"%s\" unbound"),
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
- argv[1]);
+ argv[2]);
}
else
{
gui_chat_printf (NULL,
_("%sError: unable to unbind key \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[1]);
+ argv[2]);
return -1;
}
}
return 0;
}
- if (string_strcasecmp (argv[0], "call") == 0)
+ if (string_strcasecmp (argv[1], "call") == 0)
{
- if (argc >= 2)
+ if (argc >= 3)
{
- ptr_function = gui_keyboard_function_search_by_name (argv[1]);
+ ptr_function = gui_keyboard_function_search_by_name (argv[2]);
if (ptr_function)
{
- args = string_remove_quotes (argv_eol[2], "'\"");
- (void)(*ptr_function)((args) ? args : argv_eol[2]);
- if (args)
- free (args);
+ if (argc >= 4)
+ {
+ args = string_remove_quotes (argv_eol[3], "'\"");
+ (void)(*ptr_function)((args) ? args : argv_eol[3]);
+ if (args)
+ free (args);
+ }
+ else
+ (void)(*ptr_function)(NULL);
}
else
{
gui_chat_printf (NULL,
_("%sError: unknown key function \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[1]);
+ argv[2]);
return -1;
}
}
@@ -1089,10 +809,10 @@ command_key (struct t_gui_buffer *buffer,
}
/* display a key */
- if (argc == 1)
+ if (argc == 2)
{
ptr_key = NULL;
- internal_code = gui_keyboard_get_internal_code (argv[0]);
+ internal_code = gui_keyboard_get_internal_code (argv[1]);
if (internal_code)
ptr_key = gui_keyboard_search (internal_code);
if (ptr_key)
@@ -1112,7 +832,7 @@ command_key (struct t_gui_buffer *buffer,
}
/* bind new key */
- ptr_key = gui_keyboard_bind (argv[0], argv_eol[1]);
+ ptr_key = gui_keyboard_bind (argv[1], argv_eol[2]);
if (ptr_key)
command_key_display (ptr_key, 1);
else
@@ -1120,7 +840,7 @@ command_key (struct t_gui_buffer *buffer,
gui_chat_printf (NULL,
_("%sError: unable to bind key \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[0]);
+ argv[1]);
return -1;
}
return 0;
@@ -1328,44 +1048,45 @@ command_plugin_list (char *name, int full)
*/
int
-command_plugin (struct t_gui_buffer *buffer,
+command_plugin (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argv_eol;
switch (argc)
{
- case 0:
+ case 1:
command_plugin_list (NULL, 0);
break;
- case 1:
- if (string_strcasecmp (argv[0], "list") == 0)
+ case 2:
+ if (string_strcasecmp (argv[1], "list") == 0)
command_plugin_list (NULL, 0);
- else if (string_strcasecmp (argv[0], "listfull") == 0)
+ else if (string_strcasecmp (argv[1], "listfull") == 0)
command_plugin_list (NULL, 1);
- else if (string_strcasecmp (argv[0], "autoload") == 0)
+ else if (string_strcasecmp (argv[1], "autoload") == 0)
plugin_auto_load ();
- else if (string_strcasecmp (argv[0], "reload") == 0)
+ else if (string_strcasecmp (argv[1], "reload") == 0)
{
plugin_unload_all ();
plugin_auto_load ();
}
- else if (string_strcasecmp (argv[0], "unload") == 0)
+ else if (string_strcasecmp (argv[1], "unload") == 0)
plugin_unload_all ();
break;
- case 2:
- 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 (string_strcasecmp (argv[0], "reload") == 0)
- plugin_reload_name (argv[1]);
- else if (string_strcasecmp (argv[0], "unload") == 0)
- plugin_unload_name (argv[1]);
+ case 3:
+ if (string_strcasecmp (argv[1], "list") == 0)
+ command_plugin_list (argv[2], 0);
+ else if (string_strcasecmp (argv[1], "listfull") == 0)
+ command_plugin_list (argv[2], 1);
+ else if (string_strcasecmp (argv[1], "load") == 0)
+ plugin_load (argv[2]);
+ else if (string_strcasecmp (argv[1], "reload") == 0)
+ plugin_reload_name (argv[2]);
+ else if (string_strcasecmp (argv[1], "unload") == 0)
+ plugin_unload_name (argv[2]);
else
{
gui_chat_printf (NULL,
@@ -1391,9 +1112,11 @@ command_plugin (struct t_gui_buffer *buffer,
*/
int
-command_quit (struct t_gui_buffer *buffer,
+command_quit (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
+ /* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argc;
(void) argv;
@@ -1409,10 +1132,11 @@ command_quit (struct t_gui_buffer *buffer,
*/
int
-command_reload (struct t_gui_buffer *buffer,
+command_reload (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argc;
(void) argv;
@@ -1446,10 +1170,11 @@ command_reload (struct t_gui_buffer *buffer,
*/
int
-command_save (struct t_gui_buffer *buffer,
+command_save (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argc;
(void) argv;
@@ -1597,7 +1322,7 @@ command_set_display_option_list (struct t_config_file *config_file,
*/
int
-command_set (struct t_gui_buffer *buffer,
+command_set (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
char *value;
@@ -1605,25 +1330,26 @@ command_set (struct t_gui_buffer *buffer,
int number_found, rc;
/* make C compiler happy */
+ (void) data;
(void) buffer;
/* display list of options */
- if (argc < 2)
+ if (argc < 3)
{
number_found = 0;
number_found += command_set_display_option_list (weechat_config,
NULL,
- (argc == 1) ?
- argv[0] : NULL);
+ (argc == 2) ?
+ argv[1] : NULL);
if (number_found == 0)
{
- if (argc == 1)
+ if (argc == 2)
gui_chat_printf (NULL,
_("No configuration option found with "
"\"%s\""),
- argv[0]);
+ argv[1]);
else
gui_chat_printf (NULL,
_("No configuration option found"));
@@ -1631,14 +1357,14 @@ command_set (struct t_gui_buffer *buffer,
else
{
gui_chat_printf (NULL, "");
- if (argc == 1)
+ if (argc == 2)
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),
- argv[0]);
+ argv[1]);
else
gui_chat_printf (NULL,
_("%s%d%s configuration option(s) found"),
@@ -1650,21 +1376,21 @@ command_set (struct t_gui_buffer *buffer,
}
/* set option value */
- if ((argc >= 3) && (string_strcasecmp (argv[1], "=") == 0))
+ if ((argc >= 4) && (string_strcasecmp (argv[2], "=") == 0))
{
- ptr_option = config_file_search_option (weechat_config, NULL, argv[0]);
+ ptr_option = config_file_search_option (weechat_config, NULL, argv[1]);
if (!ptr_option)
{
gui_chat_printf (NULL,
_("%sError: configuration option \"%s\" not "
"found"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[0]);
+ argv[1]);
return -1;
}
- value = string_remove_quotes (argv_eol[2], "'\"");
+ value = string_remove_quotes (argv_eol[3], "'\"");
rc = config_file_option_set (ptr_option,
- (value) ? value : argv_eol[2]);
+ (value) ? value : argv_eol[3]);
if (value)
free (value);
if (rc > 0)
@@ -1681,7 +1407,7 @@ command_set (struct t_gui_buffer *buffer,
_("%sError: incorrect value for "
"option \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[0]);
+ argv[1]);
return -1;
}
}
@@ -1694,7 +1420,7 @@ command_set (struct t_gui_buffer *buffer,
*/
int
-command_setp (struct t_gui_buffer *buffer,
+command_setp (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
char *pos, *ptr_name, *value;
@@ -1702,18 +1428,19 @@ command_setp (struct t_gui_buffer *buffer,
int number_found;
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argc;
(void) argv;
- if (argc < 2)
+ if (argc < 3)
{
number_found = 0;
for (ptr_option = plugin_options; ptr_option;
ptr_option = ptr_option->next_option)
{
- if ((argc == 0) ||
- (strstr (ptr_option->name, argv[0])))
+ if ((argc == 1) ||
+ (strstr (ptr_option->name, argv[1])))
{
if (number_found == 0)
gui_chat_printf (NULL, "");
@@ -1728,22 +1455,22 @@ command_setp (struct t_gui_buffer *buffer,
}
if (number_found == 0)
{
- if (argc == 1)
+ if (argc == 2)
gui_chat_printf (NULL,
_("No plugin option found with \"%s\""),
- argv[0]);
+ argv[1]);
else
gui_chat_printf (NULL, _("No plugin option found"));
}
else
{
gui_chat_printf (NULL, "");
- if (argc == 1)
+ if (argc == 2)
gui_chat_printf (NULL, "%s%d%s plugin option(s) found with \"%s\"",
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
number_found,
GUI_COLOR(GUI_COLOR_CHAT),
- argv[0]);
+ argv[1]);
else
gui_chat_printf (NULL, "%s%d%s plugin option(s) found",
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
@@ -1752,36 +1479,36 @@ command_setp (struct t_gui_buffer *buffer,
}
}
- if ((argc >= 3) && (string_strcasecmp (argv[1], "=") == 0))
+ if ((argc >= 4) && (string_strcasecmp (argv[2], "=") == 0))
{
ptr_name = NULL;
- ptr_option = plugin_config_search_internal (argv[0]);
+ ptr_option = plugin_config_search_internal (argv[1]);
if (ptr_option)
ptr_name = ptr_option->name;
else
{
- pos = strchr (argv[0], '.');
+ pos = strchr (argv[1], '.');
if (pos)
pos[0] = '\0';
- if (!pos || !pos[1] || (!plugin_search (argv[0])))
+ if (!pos || !pos[1] || (!plugin_search (argv[1])))
{
gui_chat_printf (NULL,
_("%sError: plugin \"%s\" not found"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[0]);
+ argv[1]);
if (pos)
pos[0] = '.';
return -1;
}
else
- ptr_name = argv[0];
+ ptr_name = argv[1];
if (pos)
pos[0] = '.';
}
if (ptr_name)
{
- value = string_remove_quotes (argv_eol[2], "'\"");
- if (plugin_config_set_internal (ptr_name, (value) ? value : argv[2]))
+ value = string_remove_quotes (argv_eol[3], "'\"");
+ if (plugin_config_set_internal (ptr_name, (value) ? value : argv_eol[3]))
gui_chat_printf (NULL,
_("Plugin option changed: %s%s = \"%s%s%s\""),
ptr_name,
@@ -1813,7 +1540,7 @@ command_setp (struct t_gui_buffer *buffer,
*/
int
-command_upgrade (struct t_gui_buffer *buffer,
+command_upgrade (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
/*int filename_length;
@@ -1821,12 +1548,13 @@ command_upgrade (struct t_gui_buffer *buffer,
char *exec_args[7] = { NULL, "-a", "--dir", NULL, "--session", NULL, NULL };*/
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argc;
(void) argv;
(void) argv_eol;
- /*ptr_binary = (argc > 0) ? argv[0] : weechat_argv0;
+ /*ptr_binary = (argc > 1) ? argv_eol[1] : weechat_argv0;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
@@ -1910,7 +1638,7 @@ command_upgrade (struct t_gui_buffer *buffer,
*/
int
-command_uptime (struct t_gui_buffer *buffer,
+command_uptime (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
time_t running_time;
@@ -1918,6 +1646,7 @@ command_uptime (struct t_gui_buffer *buffer,
char string[256];
/* make C compiler happy */
+ (void) data;
(void) argv_eol;
running_time = time (NULL) - weechat_start_time;
@@ -1926,7 +1655,7 @@ command_uptime (struct t_gui_buffer *buffer,
min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60;
sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60;
- if ((argc == 1) && (string_strcasecmp (argv[0], "-o") == 0))
+ if ((argc == 2) && (string_strcasecmp (argv[1], "-o") == 0))
{
snprintf (string, sizeof (string),
_("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"),
@@ -1970,7 +1699,7 @@ command_uptime (struct t_gui_buffer *buffer,
*/
int
-command_window (struct t_gui_buffer *buffer,
+command_window (void *data, void *buffer,
int argc, char **argv, char **argv_eol)
{
struct t_gui_window *ptr_win;
@@ -1979,16 +1708,17 @@ command_window (struct t_gui_buffer *buffer,
long number;
/* make C compiler happy */
+ (void) data;
(void) buffer;
(void) argv_eol;
- if ((argc == 0)
- || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0)))
+ if ((argc == 1)
+ || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0)))
{
/* list open windows */
gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, _("Open windows:"));
+ gui_chat_printf (NULL, _("Windows list:"));
i = 1;
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
@@ -2011,13 +1741,13 @@ command_window (struct t_gui_buffer *buffer,
}
else
{
- if (string_strcasecmp (argv[0], "splith") == 0)
+ if (string_strcasecmp (argv[1], "splith") == 0)
{
/* split window horizontally */
- if (argc > 1)
+ if (argc > 2)
{
error = NULL;
- number = strtol (argv[1], &error, 10);
+ number = strtol (argv[2], &error, 10);
if (error && (error[0] == '\0')
&& (number > 0) && (number < 100))
gui_window_split_horiz (gui_current_window, number);
@@ -2025,13 +1755,13 @@ command_window (struct t_gui_buffer *buffer,
else
gui_window_split_horiz (gui_current_window, 50);
}
- else if (string_strcasecmp (argv[0], "splitv") == 0)
+ else if (string_strcasecmp (argv[1], "splitv") == 0)
{
/* split window vertically */
- if (argc > 1)
+ if (argc > 2)
{
error = NULL;
- number = strtol (argv[1], &error, 10);
+ number = strtol (argv[2], &error, 10);
if (error && (error[0] == '\0')
&& (number > 0) && (number < 100))
gui_window_split_vertic (gui_current_window, number);
@@ -2039,23 +1769,23 @@ command_window (struct t_gui_buffer *buffer,
else
gui_window_split_vertic (gui_current_window, 50);
}
- else if (string_strcasecmp (argv[0], "resize") == 0)
+ else if (string_strcasecmp (argv[1], "resize") == 0)
{
/* resize window */
- if (argc > 1)
+ if (argc > 2)
{
error = NULL;
- number = strtol (argv[1], &error, 10);
+ number = strtol (argv[2], &error, 10);
if (error && (error[0] == '\0')
&& (number > 0) && (number < 100))
gui_window_resize (gui_current_window, number);
}
}
- else if (string_strcasecmp (argv[0], "merge") == 0)
+ else if (string_strcasecmp (argv[1], "merge") == 0)
{
- if (argc >= 2)
+ if (argc > 2)
{
- if (string_strcasecmp (argv[1], "all") == 0)
+ if (string_strcasecmp (argv[2], "all") == 0)
gui_window_merge_all (gui_current_window);
else
{
@@ -2080,30 +1810,30 @@ command_window (struct t_gui_buffer *buffer,
}
}
}
- else if (string_strncasecmp (argv[0], "b", 1) == 0)
+ else if (string_strncasecmp (argv[1], "b", 1) == 0)
{
/* jump to window by buffer number */
error = NULL;
- number = strtol (argv[0] + 1, &error, 10);
+ number = strtol (argv[1] + 1, &error, 10);
if (error && (error[0] == '\0'))
gui_window_switch_by_buffer (gui_current_window, number);
}
- else if (string_strcasecmp (argv[0], "-1") == 0)
+ else if (string_strcasecmp (argv[1], "-1") == 0)
gui_window_switch_previous (gui_current_window);
- else if (string_strcasecmp (argv[0], "+1") == 0)
+ else if (string_strcasecmp (argv[1], "+1") == 0)
gui_window_switch_next (gui_current_window);
- else if (string_strcasecmp (argv[0], "up") == 0)
+ else if (string_strcasecmp (argv[1], "up") == 0)
gui_window_switch_up (gui_current_window);
- else if (string_strcasecmp (argv[0], "down") == 0)
+ else if (string_strcasecmp (argv[1], "down") == 0)
gui_window_switch_down (gui_current_window);
- else if (string_strcasecmp (argv[0], "left") == 0)
+ else if (string_strcasecmp (argv[1], "left") == 0)
gui_window_switch_left (gui_current_window);
- else if (string_strcasecmp (argv[0], "right") == 0)
+ else if (string_strcasecmp (argv[1], "right") == 0)
gui_window_switch_right (gui_current_window);
- else if (string_strcasecmp (argv[0], "scroll") == 0)
+ else if (string_strcasecmp (argv[1], "scroll") == 0)
{
- if (argc >= 2)
- gui_window_scroll (gui_current_window, argv[1]);
+ if (argc > 2)
+ gui_window_scroll (gui_current_window, argv[2]);
}
else
{
@@ -2116,3 +1846,225 @@ command_window (struct t_gui_buffer *buffer,
}
return 0;
}
+
+/*
+ * command_init: init WeeChat commands (create hooks)
+ */
+
+void
+command_init ()
+{
+ hook_command (NULL, "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\n"
+ " list: list 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"
+ " (when executed on server buffer, this sets "
+ "default notify level for whole server)\n"
+ " scroll: scroll in history (may be relative, and may "
+ "end by a letter: s=sec, m=min, h=hour, d=day, M=month, "
+ "y=year); if there is only letter, then scroll to "
+ "beginning of this item\n\n"
+ " number: jump to buffer by number\n"
+ "server,\n"
+ "channel: jump to buffer by server and/or channel name\n\n"
+ "Examples:\n"
+ " 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 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|set|%S|%C %S|%C",
+ command_buffer, NULL);
+ hook_command (NULL, "builtin",
+ N_("launch WeeChat builtin command (do not look at commands "
+ "hooked)"),
+ N_("command"),
+ N_("command: command to execute (a '/' is automatically "
+ "added if not found at beginning of command)"),
+ "%w",
+ command_builtin, NULL);
+ hook_command (NULL, "clear",
+ N_("clear buffer(s)"),
+ N_("[-all | number [number ...]]"),
+ N_(" -all: clear all buffers\n"
+ "number: clear buffer by number"),
+ "-all",
+ command_clear, NULL);
+ hook_command (NULL, "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"
+ " buffer: dump buffer content with hexadecimal values "
+ "in log file\n"
+ "windows: display windows tree"),
+ "dump|buffer|windows",
+ command_debug, NULL);
+ hook_command (NULL, "help",
+ N_("display help about commands"),
+ N_("[command]"),
+ N_("command: name of a WeeChat or IRC command"),
+ "%w|%h",
+ command_help, NULL);
+ hook_command (NULL, "history",
+ N_("show buffer command history"),
+ N_("[clear | value]"),
+ N_("clear: clear history\n"
+ "value: number of history entries to show"),
+ "-clear",
+ command_history, NULL);
+ hook_command (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"
+ " 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",
+ command_key, NULL);
+ hook_command (NULL, "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"
+ " unload: unload one or all plugins\n\n"
+ "Without argument, /plugin command lists loaded plugins."),
+ "list|listfull|load|autoload|reload|unload %P",
+ command_plugin, NULL);
+ hook_command (NULL, "quit",
+ N_("quit WeeChat"),
+ "", "",
+ NULL,
+ command_quit, NULL);
+ hook_command (NULL, "reload",
+ N_("reload WeeChat and plugins configuration files from "
+ "disk"),
+ "", "",
+ NULL,
+ command_reload, NULL);
+ hook_command (NULL, "save",
+ N_("save WeeChat and plugins configuration files to disk"),
+ "", "",
+ NULL,
+ command_save, NULL);
+ hook_command (NULL, "set",
+ N_("set config options"),
+ N_("[option [ = value]]"),
+ N_("option: name of an option (if name is full "
+ "and no value is given, then help is displayed on "
+ "option)\n"
+ " 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",
+ command_set, NULL);
+ hook_command (NULL, "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",
+ command_setp, NULL);
+ hook_command (NULL, "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",
+ command_upgrade, NULL);
+ hook_command (NULL, "uptime",
+ N_("show WeeChat uptime"),
+ N_("[-o]"),
+ N_("-o: send uptime on current channel as an IRC message"),
+ "-o",
+ command_uptime, NULL);
+ hook_command (NULL, "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"
+ " -1: jump to previous window\n"
+ " +1: jump to next window\n"
+ " b#: jump to next window displaying buffer number #\n"
+ " up: switch to window above current one\n"
+ " down: switch to window below current one\n"
+ " left: switch to window on the left\n"
+ " 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"
+ " 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",
+ command_window, NULL);
+}
+
+/*
+ * command_print_stdout: print list of commands on standard output
+ */
+
+void
+command_print_stdout ()
+{
+ struct t_hook *ptr_hook;
+
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
+ {
+ if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && HOOK_COMMAND(ptr_hook, command)
+ && HOOK_COMMAND(ptr_hook, command)[0]
+ && !ptr_hook->plugin)
+ {
+ string_iconv_fprintf (stdout, "* %s",
+ HOOK_COMMAND(ptr_hook, command));
+ if (HOOK_COMMAND(ptr_hook, args)
+ && HOOK_COMMAND(ptr_hook, args)[0])
+ string_iconv_fprintf (stdout, " %s\n\n",
+ _(HOOK_COMMAND(ptr_hook, args)));
+ else
+ string_iconv_fprintf (stdout, "\n\n");
+ string_iconv_fprintf (stdout, "%s\n\n",
+ _(HOOK_COMMAND(ptr_hook, description)));
+ if (HOOK_COMMAND(ptr_hook, args_description)
+ && HOOK_COMMAND(ptr_hook, args_description)[0])
+ string_iconv_fprintf (stdout, "%s\n\n",
+ _(HOOK_COMMAND(ptr_hook, args_description)));
+ }
+ }
+}
diff --git a/src/core/wee-command.h b/src/core/wee-command.h
index 2a31ae73c..66a53dfd9 100644
--- a/src/core/wee-command.h
+++ b/src/core/wee-command.h
@@ -20,54 +20,7 @@
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
-#include "../gui/gui-buffer.h"
-
-#define MAX_ARGS 8192
-
-struct command
-{
- 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 *, int, char **, char **);
- /* function called when user enters cmd */
-};
-
-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 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 *, int, char **, char **);
-extern int command_buffer (struct t_gui_buffer *, int, char **, char **);
-extern int command_builtin (struct t_gui_buffer *, int, char **, char **);
-extern int command_clear (struct t_gui_buffer *, int, char **, char **);
-extern int command_debug (struct t_gui_buffer *, int, char **, char **);
-extern int command_help (struct t_gui_buffer *, int, char **, char **);
-extern int command_history (struct t_gui_buffer *, int, char **, char **);
-extern int command_key (struct t_gui_buffer *, int, char **, char **);
-extern int command_plugin (struct t_gui_buffer *, int, char **, char **);
-extern int command_quit (struct t_gui_buffer *, int, char **, char **);
-extern int command_reload (struct t_gui_buffer *, int, char **, char **);
-extern int command_save (struct t_gui_buffer *, int, char **, char **);
-extern int command_set (struct t_gui_buffer *, int, char **, char **);
-extern int command_setp (struct t_gui_buffer *, int, char **, char **);
-extern int command_unalias (struct t_gui_buffer *, int, char **, char **);
-extern int command_upgrade (struct t_gui_buffer *, int, char **, char **);
-extern int command_uptime (struct t_gui_buffer *, int, char **, char **);
-extern int command_window (struct t_gui_buffer *, int, char **, char **);
+extern void command_init ();
+extern void command_print_stdout ();
#endif /* wee-command.h */
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 5cba2ef3e..dc17c332a 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -1183,6 +1183,27 @@ config_file_free_all ()
}
/*
+ * config_file_free_all: free all configuration files for a plugin
+ */
+
+void
+config_file_free_all_plugin (void *plugin)
+{
+ struct t_config_file *ptr_config, *next_config;
+
+ ptr_config = config_files;
+ while (ptr_config)
+ {
+ next_config = ptr_config->next_config;
+
+ if (ptr_config->plugin == plugin)
+ config_file_free (ptr_config);
+
+ ptr_config = next_config;
+ }
+}
+
+/*
* config_file_print_stdout: print options on standard output
*/
diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h
index 2fac140b3..5cfc9a289 100644
--- a/src/core/wee-config-file.h
+++ b/src/core/wee-config-file.h
@@ -133,6 +133,7 @@ extern void config_file_section_free (struct t_config_file *,
struct t_config_section *);
extern void config_file_free (struct t_config_file *);
extern void config_file_free_all ();
+extern void config_file_free_all_plugin (void *);
extern void config_file_print_stdout (struct t_config_file *);
extern void config_file_print_log ();
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index 0723de65c..2f87e9ca1 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -36,7 +36,6 @@
#include "weechat.h"
#include "wee-config.h"
#include "wee-config-file.h"
-#include "wee-command.h"
#include "wee-log.h"
#include "wee-util.h"
#include "wee-list.h"
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 66982ada0..4ca24395c 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -30,10 +30,10 @@
#include "weechat.h"
#include "wee-hook.h"
-#include "wee-command.h"
#include "wee-log.h"
#include "wee-string.h"
#include "wee-util.h"
+#include "../gui/gui-buffer.h"
#include "../gui/gui-color.h"
#include "../plugins/plugin.h"
@@ -43,19 +43,71 @@ struct t_hook *last_weechat_hook = NULL;
/*
+ * hook_find_pos: find position for new hook (keeping command list sorted)
+ */
+
+struct t_hook *
+hook_find_pos (struct t_hook *hook)
+{
+ struct t_hook *ptr_hook;
+
+ /* if it's not command hook, then add to the end of list */
+ if (hook->type != HOOK_TYPE_COMMAND)
+ return NULL;
+
+ /* for command hook, keep list sorted */
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
+ {
+ if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && (string_strcasecmp (HOOK_COMMAND(hook, command),
+ HOOK_COMMAND(ptr_hook, command)) <= 0))
+ return ptr_hook;
+ }
+
+ /* position not found, best position is at the end */
+ return NULL;
+}
+
+/*
* hook_add_to_list: add a hook to list
*/
void
hook_add_to_list (struct t_hook *new_hook)
{
- new_hook->prev_hook = last_weechat_hook;
+ struct t_hook *pos_hook;
+
if (weechat_hooks)
- last_weechat_hook->next_hook = new_hook;
+ {
+ pos_hook = hook_find_pos (new_hook);
+ if (pos_hook)
+ {
+ /* add hook somewhere in the list */
+ new_hook->prev_hook = pos_hook->prev_hook;
+ new_hook->next_hook = pos_hook;
+ if (pos_hook->prev_hook)
+ (pos_hook->prev_hook)->next_hook = new_hook;
+ else
+ weechat_hooks = new_hook;
+ pos_hook->prev_hook = new_hook;
+ }
+ else
+ {
+ /* add hook to end of list */
+ new_hook->prev_hook = last_weechat_hook;
+ new_hook->next_hook = NULL;
+ last_weechat_hook->next_hook = new_hook;
+ last_weechat_hook = new_hook;
+ }
+ }
else
+ {
+ new_hook->prev_hook = NULL;
+ new_hook->next_hook = NULL;
weechat_hooks = new_hook;
- last_weechat_hook = new_hook;
- new_hook->next_hook = NULL;
+ last_weechat_hook = new_hook;
+ }
}
/*
@@ -150,12 +202,25 @@ hook_command (void *plugin, char *command, char *description,
t_hook_callback_command *callback,
void *callback_data)
{
- struct t_hook *new_hook;
+ struct t_hook *ptr_hook,*new_hook;
struct t_hook_command *new_hook_command;
if ((string_strcasecmp (command, "builtin") == 0)
&& hook_search_command (command))
return NULL;
+
+ /* increase level for command hooks with same command name
+ so that these commands will not be used any more, until this
+ one is removed */
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
+ {
+ if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), command) == 0))
+ {
+ HOOK_COMMAND(ptr_hook, level)++;
+ }
+ }
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
if (!new_hook)
@@ -168,11 +233,12 @@ hook_command (void *plugin, char *command, char *description,
}
hook_init (new_hook, plugin, HOOK_TYPE_COMMAND, callback_data);
-
+
new_hook->hook_data = new_hook_command;
new_hook_command->callback = callback;
new_hook_command->command = (command) ?
strdup (command) : strdup ("");
+ new_hook_command->level = 0;
new_hook_command->description = (description) ?
strdup (description) : strdup ("");
new_hook_command->args = (args) ?
@@ -184,9 +250,6 @@ hook_command (void *plugin, char *command, char *description,
hook_add_to_list (new_hook);
- if (command && command[0])
- command_index_add (command);
-
return new_hook;
}
@@ -198,7 +261,7 @@ hook_command (void *plugin, char *command, char *description,
*/
int
-hook_command_exec (void *buffer, char *string)
+hook_command_exec (void *buffer, char *string, int only_builtin)
{
struct t_hook *ptr_hook, *next_hook;
char **argv, **argv_eol;
@@ -221,8 +284,11 @@ hook_command_exec (void *buffer, char *string)
next_hook = ptr_hook->next_hook;
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && (HOOK_COMMAND(ptr_hook, level) == 0)
&& (!ptr_hook->running)
- && (!((struct t_gui_buffer *)buffer)->plugin
+ && (!only_builtin || !ptr_hook->plugin)
+ && (!ptr_hook->plugin
+ || !((struct t_gui_buffer *)buffer)->plugin
|| (((struct t_gui_buffer *)buffer)->plugin == ptr_hook->plugin))
&& (string_strcasecmp (argv[0] + 1,
HOOK_COMMAND(ptr_hook, command)) == 0))
@@ -665,7 +731,7 @@ hook_config_exec (char *type, char *option, char *value)
void
unhook (struct t_hook *hook)
{
- struct t_hook *new_hooks;
+ struct t_hook *new_hooks, *ptr_hook;
/* free data */
if (hook->hook_data)
@@ -673,9 +739,20 @@ unhook (struct t_hook *hook)
switch (hook->type)
{
case HOOK_TYPE_COMMAND:
- if (HOOK_COMMAND(hook, command)
- && HOOK_COMMAND(hook, command)[0])
- command_index_remove (HOOK_COMMAND(hook, command));
+ /* decrease level for command hooks with same command name
+ and level higher than this one */
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
+ {
+ if ((ptr_hook != hook)
+ && (ptr_hook->type == HOOK_TYPE_COMMAND)
+ && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command),
+ HOOK_COMMAND(hook, command)) == 0)
+ && (HOOK_COMMAND(ptr_hook, level) > HOOK_COMMAND(hook, level)))
+ {
+ HOOK_COMMAND(ptr_hook, level)--;
+ }
+ }
if (HOOK_COMMAND(hook, command))
free (HOOK_COMMAND(hook, command));
if (HOOK_COMMAND(hook, description))
@@ -780,41 +857,57 @@ hook_print_log ()
{
log_printf ("\n");
log_printf ("[hook (addr:0x%X)]\n", ptr_hook);
- log_printf (" type . . . . . . . . . : %d\n", ptr_hook->type);
- log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
switch (ptr_hook->type)
{
case HOOK_TYPE_COMMAND:
+ log_printf (" type . . . . . . . . . : %d (command)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" command data:\n");
log_printf (" callback . . . . . . : 0x%X\n", HOOK_COMMAND(ptr_hook, callback));
log_printf (" command. . . . . . . : '%s'\n", HOOK_COMMAND(ptr_hook, command));
+ log_printf (" level. . . . . . . . : %d\n", HOOK_COMMAND(ptr_hook, level));
log_printf (" command_desc . . . . : '%s'\n", HOOK_COMMAND(ptr_hook, description));
log_printf (" command_args . . . . : '%s'\n", HOOK_COMMAND(ptr_hook, args));
log_printf (" command_args_desc. . : '%s'\n", HOOK_COMMAND(ptr_hook, args_description));
log_printf (" command_completion . : '%s'\n", HOOK_COMMAND(ptr_hook, completion));
break;
case HOOK_TYPE_TIMER:
+ log_printf (" type . . . . . . . . . : %d (timer)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" timer data:\n");
+ log_printf (" callback . . . . . . : 0x%X\n", HOOK_TIMER(ptr_hook, callback));
log_printf (" interval . . . . . . : %ld\n", HOOK_TIMER(ptr_hook, interval));
log_printf (" last_exec.tv_sec . . : %ld\n", HOOK_TIMER(ptr_hook, last_exec.tv_sec));
log_printf (" last_exec.tv_usec. . : %ld\n", HOOK_TIMER(ptr_hook, last_exec.tv_usec));
break;
case HOOK_TYPE_FD:
+ log_printf (" type . . . . . . . . . : %d (fd)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" fd data:\n");
+ log_printf (" callback . . . . . . : 0x%X\n", HOOK_FD(ptr_hook, callback));
log_printf (" fd . . . . . . . . . : %ld\n", HOOK_FD(ptr_hook, fd));
log_printf (" flags. . . . . . . . : %ld\n", HOOK_FD(ptr_hook, flags));
break;
case HOOK_TYPE_PRINT:
+ log_printf (" type . . . . . . . . . : %d (print)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" print data:\n");
+ log_printf (" callback . . . . . . : 0x%X\n", HOOK_PRINT(ptr_hook, callback));
log_printf (" buffer . . . . . . . : 0x%X\n", HOOK_PRINT(ptr_hook, buffer));
log_printf (" message. . . . . . . : '%s'\n", HOOK_PRINT(ptr_hook, message));
break;
case HOOK_TYPE_EVENT:
+ log_printf (" type . . . . . . . . . : %d (event)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" event data:\n");
+ log_printf (" callback . . . . . . : 0x%X\n", HOOK_EVENT(ptr_hook, callback));
log_printf (" event. . . . . . . . : '%s'\n", HOOK_EVENT(ptr_hook, event));
break;
case HOOK_TYPE_CONFIG:
+ log_printf (" type . . . . . . . . . : %d (config)\n", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%X\n", ptr_hook->callback_data);
log_printf (" config data:\n");
+ log_printf (" callback . . . . . . : 0x%X\n", HOOK_CONFIG(ptr_hook, callback));
log_printf (" type . . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, type));
log_printf (" option . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, option));
break;
diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h
index 10ebdc14a..8df84de47 100644
--- a/src/core/wee-hook.h
+++ b/src/core/wee-hook.h
@@ -65,6 +65,8 @@ struct t_hook_command
{
t_hook_callback_command *callback; /* command callback */
char *command; /* name of command (without '/') */
+ int level; /* when many commands with same name */
+ /* exist: lower level= high priority */
char *description; /* (for /help) short cmd description */
char *args; /* (for /help) command arguments */
char *args_description; /* (for /help) args long description */
@@ -130,7 +132,7 @@ extern int hook_valid_for_plugin (void *, struct t_hook *);
extern struct t_hook *hook_command (void *, char *, char *, char *, char *,
char *, t_hook_callback_command *, void *);
-extern int hook_command_exec (void *, char *);
+extern int hook_command_exec (void *, char *, int);
extern struct t_hook *hook_timer (void *, long, int, t_hook_callback_timer *,
void *);
extern void hook_timer_exec (struct timeval *);
diff --git a/src/core/wee-input.c b/src/core/wee-input.c
index 4fe0f8a00..ddd3b00c0 100644
--- a/src/core/wee-input.c
+++ b/src/core/wee-input.c
@@ -28,7 +28,6 @@
#include "weechat.h"
#include "wee-input.h"
-#include "wee-command.h"
#include "wee-config.h"
#include "wee-hook.h"
#include "wee-string.h"
@@ -36,6 +35,26 @@
#include "../plugins/plugin.h"
+
+/*
+ * input_is_command: return 1 if line is a command, 0 otherwise
+ */
+
+int
+input_is_command (char *line)
+{
+ char *pos_slash, *pos_space;
+
+ if (strncmp (line, "/*", 2) == 0)
+ return 0;
+
+ pos_slash = strchr (line + 1, '/');
+ pos_space = strchr (line + 1, ' ');
+
+ return (line[0] == '/')
+ && (!pos_slash || (pos_space && pos_slash > pos_space));
+}
+
/*
* input_exec_command: executes a command (WeeChat internal or a
* plugin command)
@@ -49,7 +68,7 @@ int
input_exec_command (struct t_gui_buffer *buffer, char *string,
int only_builtin)
{
- int i, rc, argc, return_code;
+ int rc, argc;
char *command, *pos, *ptr_args;
char **argv, **argv_eol;
@@ -69,16 +88,12 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
pos[1] = '\0';
}
- rc = -1;
- if (!only_builtin)
- {
- rc = hook_command_exec (buffer, command);
- /*vars_replaced = alias_replace_vars (window, ptr_args);
- rc = plugin_cmd_handler_exec (window->buffer->protocol, command + 1,
- (vars_replaced) ? vars_replaced : ptr_args);
- if (vars_replaced)
- free (vars_replaced);*/
- }
+ rc = hook_command_exec (buffer, command, only_builtin);
+ /*vars_replaced = alias_replace_vars (window, ptr_args);
+ rc = plugin_cmd_handler_exec (window->buffer->protocol, command + 1,
+ (vars_replaced) ? vars_replaced : ptr_args);
+ if (vars_replaced)
+ free (vars_replaced);*/
pos = strchr (command, ' ');
if (pos)
@@ -106,71 +121,6 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
argv = string_explode (ptr_args, " ", 0, 0, &argc);
argv_eol = string_explode (ptr_args, " ", 1, 0, NULL);
- /* look for WeeChat command */
- for (i = 0; weechat_commands[i].name; i++)
- {
- if (string_strcasecmp (weechat_commands[i].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)
- {
- gui_chat_printf (NULL,
- NG_("%sError: wrong argument count "
- "for %s command \"%s\" "
- "(expected: %d arg)",
- "%s%s wrong argument count "
- "for %s command \"%s\" "
- "(expected: %d args)",
- weechat_commands[i].max_arg),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- PACKAGE_NAME,
- command + 1,
- weechat_commands[i].max_arg);
- }
- else
- {
- gui_chat_printf (NULL,
- NG_("%sError: wrong argument count "
- "for %s command \"%s\" "
- "(expected: between %d and "
- "%d arg)",
- "%s%s wrong argument count "
- "for %s command \"%s\" "
- "(expected: between %d and "
- "%d args)",
- weechat_commands[i].max_arg),
- gui_chat_prefix[GUI_CHAT_PREFIX_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;*/
- return_code = (int) (weechat_commands[i].cmd_function)
- (buffer, argc, argv, argv_eol);
- if (return_code < 0)
- {
- gui_chat_printf (NULL,
- _("%sError: command \"%s\" failed"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- command + 1);
- }
- }
- string_free_exploded (argv);
- string_free_exploded (argv_eol);
- free (command);
- return 1;
- }
- }
-
/* should we send unknown command to IRC server? */
/*if (cfg_irc_send_unknown_commands)
{
@@ -249,7 +199,7 @@ input_data (struct t_gui_buffer *buffer, char *data, int only_builtin)
if (pos)
pos[0] = '\0';
- if (command_is_command (ptr_data))
+ if (input_is_command (ptr_data))
{
/* WeeChat or plugin command */
(void) input_exec_command (buffer, ptr_data,
@@ -260,7 +210,7 @@ input_data (struct t_gui_buffer *buffer, char *data, int only_builtin)
if ((ptr_data[0] == '/') && (ptr_data[1] == '/'))
ptr_data++;
- hook_command_exec (buffer, ptr_data);
+ hook_command_exec (buffer, ptr_data, 0);
if (buffer->input_data_cb)
{
diff --git a/src/core/wee-list.c b/src/core/wee-list.c
index 8511d69d0..48269b905 100644
--- a/src/core/wee-list.c
+++ b/src/core/wee-list.c
@@ -132,7 +132,7 @@ weelist_insert (struct t_weelist **weelist, struct t_weelist **last_weelist,
element->prev_weelist = pos_weelist->prev_weelist;
element->next_weelist = pos_weelist;
if (pos_weelist->prev_weelist)
- pos_weelist->prev_weelist->next_weelist = element;
+ (pos_weelist->prev_weelist)->next_weelist = element;
else
*weelist = element;
pos_weelist->prev_weelist = element;
diff --git a/src/core/weechat.c b/src/core/weechat.c
index 3cb266c11..30aa88852 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -144,7 +144,7 @@ weechat_display_commands ()
_("%s internal commands:\n"),
PACKAGE_NAME);
string_iconv_fprintf (stdout, "\n");
- command_print_stdout (weechat_commands);
+ command_print_stdout ();
}
/*
@@ -276,19 +276,8 @@ weechat_parse_args (int argc, char *argv[])
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,
- _("Error: missing argument for \"%s\" "
- "option\n"),
- "--commands");
- weechat_shutdown (EXIT_FAILURE, 0);
- }
+ weechat_display_commands ();
+ weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-p") == 0)
|| (strcmp (argv[i], "--no-plugin") == 0))
@@ -594,6 +583,7 @@ main (int argc, char *argv[])
signal (SIGSEGV, weechat_sigsegv); /* crash dump when SIGSEGV received */
gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */
weechat_init_vars (); /* initialize some variables */
+ command_init (); /* initialize WeeChat commands */
gui_keyboard_init (); /* init keyb. (default key bindings)*/
config_weechat_init (); /* init options with default values */
weechat_parse_args (argc, argv); /* parse command line args */
@@ -601,7 +591,6 @@ main (int argc, char *argv[])
log_init (); /* init log file */
if (config_weechat_read () < 0) /* read WeeChat configuration */
exit (EXIT_FAILURE);
- command_index_build (); /* build cmd index for completion */
gui_main_init (); /* init WeeChat interface */
//if (weechat_session)
//session_load (weechat_session); /* load previous session if asked */
@@ -611,8 +600,8 @@ main (int argc, char *argv[])
plugin_end (); /* end plugin interface(s) */
if (CONFIG_BOOLEAN(config_look_save_on_exit))
(void) config_weechat_write (NULL); /* save WeeChat config file */
- command_index_free (); /* free commands index */
gui_main_end (); /* shut down WeeChat GUI */
+ unhook_all (); /* remove all hooks */
weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */
return EXIT_SUCCESS; /* make C compiler happy */
diff --git a/src/gui/curses/Makefile.am b/src/gui/curses/Makefile.am
index 89e5e2011..909a35020 100644
--- a/src/gui/curses/Makefile.am
+++ b/src/gui/curses/Makefile.am
@@ -18,7 +18,19 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(NCURSES_CFLAGS)
bin_PROGRAMS = weechat-curses
-weechat_curses_LDADD = ../../core/lib_weechat_core.a \
+weechat_curses_LDADD = ../../core/weechat.o \
+ ../../core/wee-backtrace.o \
+ ../../core/wee-command.o \
+ ../../core/wee-config.o \
+ ../../core/wee-config-file.o \
+ ../../core/wee-hook.o \
+ ../../core/wee-input.o \
+ ../../core/wee-list.o \
+ ../../core/wee-log.o \
+ ../../core/wee-upgrade.o \
+ ../../core/wee-string.o \
+ ../../core/wee-utf8.o \
+ ../../core/wee-util.o \
../../plugins/lib_weechat_plugins.a \
../lib_weechat_gui_common.a \
$(PLUGINS_LFLAGS) \
diff --git a/src/gui/gtk/Makefile.am b/src/gui/gtk/Makefile.am
index aec706d7a..e00d2a63e 100644
--- a/src/gui/gtk/Makefile.am
+++ b/src/gui/gtk/Makefile.am
@@ -18,7 +18,19 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS)
bin_PROGRAMS = weechat-gtk
-weechat_gtk_LDADD = ../../core/lib_weechat_core.a \
+weechat_gtk_LDADD = ../../core/weechat.o \
+ ../../core/wee-backtrace.o \
+ ../../core/wee-command.o \
+ ../../core/wee-config.o \
+ ../../core/wee-config-file.o \
+ ../../core/wee-hook.o \
+ ../../core/wee-input.o \
+ ../../core/wee-list.o \
+ ../../core/wee-log.o \
+ ../../core/wee-upgrade.o \
+ ../../core/wee-string.o \
+ ../../core/wee-utf8.o \
+ ../../core/wee-util.o \
../../plugins/lib_weechat_plugins.a \
../lib_weechat_gui_common.a \
$(PLUGINS_LFLAGS) \
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index 55324c507..daef042a6 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -32,7 +32,6 @@
#include <time.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-config.h"
#include "../core/wee-input.h"
#include "../core/wee-log.h"
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 0f2abb410..d9776b440 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -33,6 +33,11 @@
#include <ctype.h>
#include "../core/weechat.h"
+#include "../core/wee-config.h"
+#include "../core/wee-hook.h"
+#include "../core/wee-log.h"
+#include "../core/wee-string.h"
+#include "../core/wee-utf8.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-color.h"
@@ -44,12 +49,6 @@
#include "gui-nicklist.h"
#include "gui-status.h"
#include "gui-window.h"
-#include "../core/wee-command.h"
-#include "../core/wee-config.h"
-#include "../core/wee-hook.h"
-#include "../core/wee-log.h"
-#include "../core/wee-string.h"
-#include "../core/wee-utf8.h"
#include "../plugins/plugin.h"
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 06e99fc5f..420ef43fb 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -31,7 +31,6 @@
#include <unistd.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-config.h"
#include "../core/wee-hook.h"
#include "../core/wee-log.h"
@@ -41,6 +40,7 @@
#include "../plugins/plugin.h"
#include "../plugins/plugin-config.h"
#include "gui-completion.h"
+#include "gui-buffer.h"
#include "gui-color.h"
#include "gui-keyboard.h"
@@ -133,36 +133,23 @@ gui_completion_stop (struct t_gui_completion *completion)
void
gui_completion_get_command_infos (struct t_gui_completion *completion,
- char **template, int *max_arg)
+ char **template)
{
struct t_hook *ptr_hook;
- int i;
*template = NULL;
- *max_arg = MAX_ARGS;
- /* look for command hooked */
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]
+ && (HOOK_COMMAND(ptr_hook, level) == 0)
&& (string_strcasecmp (HOOK_COMMAND(ptr_hook, command),
completion->base_command) == 0))
{
*template = HOOK_COMMAND(ptr_hook, completion);
- *max_arg = MAX_ARGS;
- return;
- }
- }
-
- /* look for WeeChat internal command */
- for (i = 0; weechat_commands[i].name; i++)
- {
- if (string_strcasecmp (weechat_commands[i].name,
- completion->base_command) == 0)
- {
- *template = weechat_commands[i].completion_template;
- *max_arg = weechat_commands[i].max_arg;
return;
}
}
@@ -406,7 +393,8 @@ gui_completion_list_add_command_hooks (struct t_gui_completion *completion)
{
struct t_hook *ptr_hook;
- for (ptr_hook = weechat_hooks; ptr_hook; ptr_hook = ptr_hook->next_hook)
+ 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))
@@ -858,12 +846,20 @@ gui_completion_list_add_plugin_option_value (struct t_gui_completion *completion
void
gui_completion_list_add_weechat_cmd (struct t_gui_completion *completion)
{
- int i;
+ struct t_hook *ptr_hook;
- for (i = 0; weechat_commands[i].name; i++)
+ for (ptr_hook = weechat_hooks; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
{
- gui_completion_list_add (completion, weechat_commands[i].name,
- 0, WEELIST_POS_SORT);
+ if ((ptr_hook->type == HOOK_TYPE_COMMAND)
+ && !ptr_hook->plugin
+ && HOOK_COMMAND(ptr_hook, command)
+ && HOOK_COMMAND(ptr_hook, command)[0])
+ {
+ gui_completion_list_add (completion,
+ HOOK_COMMAND(ptr_hook, command),
+ 0, WEELIST_POS_SORT);
+ }
}
}
@@ -994,13 +990,12 @@ void
gui_completion_build_list (struct t_gui_completion *completion)
{
char *template, *pos_template, *pos_space;
- int repeat_last, max_arg, i, length;
+ int repeat_last, i, length;
repeat_last = 0;
- gui_completion_get_command_infos (completion, &template, &max_arg);
- if (!template || (strcmp (template, "-") == 0) ||
- (completion->base_command_arg > max_arg))
+ gui_completion_get_command_infos (completion, &template);
+ if (!template || (strcmp (template, "-") == 0))
{
gui_completion_stop (completion);
return;
@@ -1114,16 +1109,15 @@ gui_completion_find_context (struct t_gui_completion *completion, char *data,
while ((i < size) && (data[i] != ' '))
i++;
pos_end = i - 1;
+
+ if (completion->context == GUI_COMPLETION_COMMAND)
+ pos_start++;
completion->base_word_pos = pos_start;
if (pos_start <= pos_end)
{
- if (completion->context == GUI_COMPLETION_COMMAND)
- completion->position_replace = pos_start + 1;
- else
- completion->position_replace = pos_start;
-
+ completion->position_replace = pos_start;
completion->base_word = (char *) malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = data[i];
@@ -1175,18 +1169,35 @@ void
gui_completion_command (struct t_gui_completion *completion)
{
int length, word_found_seen, other_completion;
+ struct t_hook *ptr_hook;
struct t_weelist *ptr_weelist, *ptr_weelist2;
- length = strlen (completion->base_word) - 1;
+ length = strlen (completion->base_word);
word_found_seen = 0;
other_completion = 0;
+ if (!completion->completion_list)
+ {
+ 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]
+ && (HOOK_COMMAND(ptr_hook, level) == 0))
+ {
+ gui_completion_list_add (completion,
+ HOOK_COMMAND(ptr_hook, command),
+ 0, WEELIST_POS_SORT);
+ }
+ }
+ }
if (completion->direction < 0)
- ptr_weelist = weechat_last_index_command;
+ ptr_weelist = completion->last_completion;
else
- ptr_weelist = weechat_index_commands;
+ ptr_weelist = completion->completion_list;
while (ptr_weelist)
{
- if (string_strncasecmp (ptr_weelist->data, completion->base_word + 1, length) == 0)
+ if (string_strncasecmp (ptr_weelist->data, completion->base_word, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
@@ -1202,7 +1213,7 @@ gui_completion_command (struct t_gui_completion *completion)
while (ptr_weelist2)
{
if (string_strncasecmp (ptr_weelist2->data,
- completion->base_word + 1, length) == 0)
+ completion->base_word, length) == 0)
other_completion++;
if (completion->direction < 0)
@@ -1563,11 +1574,6 @@ gui_completion_search (struct t_gui_completion *completion, int direction,
strlen (completion->base_word);
completion->diff_length = utf8_strlen (completion->word_found) -
utf8_strlen (completion->base_word);
- if (completion->context == GUI_COMPLETION_COMMAND)
- {
- completion->diff_size++;
- completion->diff_length++;
- }
}
}
if (old_word_found)
diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c
index 7dc082f5b..c31252d2b 100644
--- a/src/gui/gui-keyboard.c
+++ b/src/gui/gui-keyboard.c
@@ -28,7 +28,6 @@
#include <ctype.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-input.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index c8cba5124..df62cf72e 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -33,7 +33,6 @@
#include <ctype.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-config.h"
#include "../core/wee-log.h"
#include "../core/wee-utf8.h"
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index f3b7fc8db..372006688 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -306,7 +306,7 @@ alias_new (char *name, char *command)
if ((new_alias = ((struct t_alias *) malloc (sizeof (struct t_alias)))))
{
- new_hook = weechat_hook_command (name, NULL, NULL, NULL, NULL,
+ new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, NULL,
alias_cb, new_alias);
if (!new_hook)
{
@@ -724,6 +724,7 @@ weechat_plugin_end ()
{
alias_config_write ();
alias_free_all ();
+ weechat_config_free (alias_config_file);
weechat_unhook (alias_command);
weechat_unhook (unalias_command);
return PLUGIN_RC_SUCCESS;
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index ef98d2af8..513f7307d 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -32,7 +32,6 @@
#include <sys/stat.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-config.h"
#include "../core/wee-hook.h"
#include "../core/wee-input.h"
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 53b42bdbe..c25ff870a 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -34,7 +34,6 @@
#include <dlfcn.h>
#include "../core/weechat.h"
-#include "../core/wee-command.h"
#include "../core/wee-config.h"
#include "../core/wee-hook.h"
#include "../core/wee-log.h"
@@ -251,6 +250,7 @@ plugin_load (char *filename)
new_plugin->config_reload = &plugin_api_config_reload;
new_plugin->config_write = &plugin_api_config_write;
new_plugin->config_write_line = &plugin_api_config_write_line;
+ new_plugin->config_free = &plugin_api_config_free;
new_plugin->config_get = &plugin_api_config_get;
new_plugin->config_set = &plugin_api_config_set;
new_plugin->plugin_config_get = &plugin_api_plugin_config_get;
@@ -460,6 +460,9 @@ plugin_remove (struct t_weechat_plugin *plugin)
if (plugin->next_plugin)
(plugin->next_plugin)->prev_plugin = plugin->prev_plugin;
+ /* remove all config files */
+ config_file_free_all_plugin (plugin);
+
/* remove all hooks */
unhook_all_plugin (plugin);