mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 16:23:14 +02:00
Removed WeeChat "command" structure, now all internal commands are hooked when WeeChat starts
This commit is contained in:
+454
-502
File diff suppressed because it is too large
Load Diff
+2
-49
@@ -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 */
|
||||
|
||||
@@ -1182,6 +1182,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
|
||||
*/
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
+111
-18
@@ -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"
|
||||
|
||||
@@ -42,6 +42,33 @@ struct t_hook *weechat_hooks = NULL;
|
||||
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
|
||||
*/
|
||||
@@ -49,13 +76,38 @@ struct t_hook *last_weechat_hook = NULL;
|
||||
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;
|
||||
|
||||
+3
-1
@@ -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 *);
|
||||
|
||||
+29
-79
@@ -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)
|
||||
{
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+5
-16
@@ -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 */
|
||||
|
||||
@@ -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) \
|
||||
|
||||
+13
-1
@@ -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) \
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
+48
-42
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user