1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 08:13:14 +02:00

Added "buffer_move" event handler to plugins API (task #6708)

This commit is contained in:
Sebastien Helleu
2007-07-18 12:02:40 +00:00
parent b1a99c5e6f
commit 2c3fad454c
38 changed files with 838 additions and 484 deletions
+15 -2
View File
@@ -679,6 +679,9 @@ weechat_dump (int crash)
t_irc_nick *ptr_nick;
t_gui_window *ptr_window;
t_gui_buffer *ptr_buffer;
#ifdef PLUGINS
t_weechat_plugin *ptr_plugin;
#endif
/* prevent reentrance */
if (sigsegv)
@@ -747,7 +750,8 @@ weechat_dump (int crash)
gui_window_print_log (ptr_window);
}
for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
weechat_log_printf ("\n");
gui_buffer_print_log (ptr_buffer);
@@ -755,10 +759,19 @@ weechat_dump (int crash)
weechat_log_printf ("\n");
irc_ignore_print_log ();
weechat_log_printf ("\n");
hotlist_print_log ();
#ifdef PLUGINS
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
weechat_log_printf ("\n");
plugin_print_log (ptr_plugin);
}
#endif
weechat_log_printf ("\n");
weechat_log_printf ("****** End of dump ******\n");
weechat_log_printf ("\n");
+20 -4
View File
@@ -87,7 +87,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
{
t_gui_buffer *new_buffer, *ptr_buffer;
#ifdef PLUGINS
char buffer_str[16];
char buffer_str[16], *argv[1] = { NULL };
#endif
#ifdef DEBUG
@@ -243,7 +243,8 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
#ifdef PLUGINS
snprintf (buffer_str, sizeof (buffer_str) - 1, "%d", new_buffer->number);
(void) plugin_event_handler_exec ("buffer_open", buffer_str);
argv[0] = buffer_str;
(void) plugin_event_handler_exec ("buffer_open", 1, argv);
#endif
}
else
@@ -572,12 +573,13 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another)
t_irc_server *ptr_server;
int create_new;
#ifdef PLUGINS
char buffer_str[16];
char buffer_str[16], *argv[1] = { NULL };
#endif
#ifdef PLUGINS
snprintf (buffer_str, sizeof (buffer_str) - 1, "%d", buffer->number);
(void) plugin_event_handler_exec ("buffer_close", buffer_str);
argv[0] = buffer_str;
(void) plugin_event_handler_exec ("buffer_close", 1, argv);
#endif
create_new = (buffer->server || buffer->channel);
@@ -985,6 +987,9 @@ gui_buffer_move_to_number (t_gui_buffer *buffer, int number)
{
t_gui_buffer *ptr_buffer;
int i;
#ifdef PLUGINS
char buf1_str[16], buf2_str[16], *argv[2] = { NULL, NULL };
#endif
/* if only one buffer then return */
if (gui_buffers == last_gui_buffer)
@@ -996,6 +1001,10 @@ gui_buffer_move_to_number (t_gui_buffer *buffer, int number)
if (number < 1)
number = 1;
#ifdef PLUGINS
snprintf (buf2_str, sizeof (buf2_str) - 1, "%d", buffer->number);
#endif
/* remove buffer from list */
if (buffer == gui_buffers)
@@ -1063,6 +1072,13 @@ gui_buffer_move_to_number (t_gui_buffer *buffer, int number)
}
gui_window_redraw_buffer (buffer);
#ifdef PLUGINS
snprintf (buf1_str, sizeof (buf1_str) - 1, "%d", buffer->number);
argv[0] = buf1_str;
argv[1] = buf2_str;
(void) plugin_event_handler_exec ("buffer_move", 2, argv);
#endif
}
/*
+71 -6
View File
@@ -37,6 +37,7 @@
#include "plugins.h"
#include "plugins-config.h"
#include "../common/command.h"
#include "../common/log.h"
#include "../common/util.h"
#include "../common/weeconfig.h"
#include "../irc/irc.h"
@@ -696,14 +697,11 @@ plugin_keyboard_handler_exec (char *key, char *input_before, char *input_after)
*/
int
plugin_event_handler_exec (char *event, char *data)
plugin_event_handler_exec (char *event, int argc, char **argv)
{
t_weechat_plugin *ptr_plugin;
t_plugin_handler *ptr_handler;
int return_code, final_return_code;
char *argv[1] = { NULL };
argv[0] = data;
final_return_code = PLUGIN_RC_OK;
@@ -717,7 +715,7 @@ plugin_event_handler_exec (char *event, char *data)
&& (ascii_strcasecmp (ptr_handler->event, event) == 0))
{
return_code = ((int) (ptr_handler->handler) (ptr_plugin,
1, argv,
argc, argv,
ptr_handler->handler_args,
ptr_handler->handler_pointer));
if (return_code == PLUGIN_RC_KO)
@@ -823,7 +821,8 @@ plugin_modifier_add (t_weechat_plugin *plugin, char *type, char *command,
if (new_modifier)
{
new_modifier->type = type_int;
new_modifier->command = (command) ? strdup (command) : strdup ("*");
new_modifier->command = (command && command[0]) ?
strdup (command) : strdup ("*");
new_modifier->modifier = modifier_func;
new_modifier->modifier_args = (modifier_args) ? strdup (modifier_args) : NULL;
new_modifier->modifier_pointer = modifier_pointer;
@@ -1499,3 +1498,69 @@ plugin_end ()
/* unload all plugins */
plugin_unload_all ();
}
/*
* plugin_print_log: print plugin infos in log (usually for crash dump)
*/
void
plugin_print_log (t_weechat_plugin *plugin)
{
t_plugin_handler *ptr_handler;
t_plugin_modifier *ptr_modifier;
weechat_log_printf ("[plugin (addr:0x%X)]\n", plugin);
weechat_log_printf (" filename . . . . . . . : '%s'\n", plugin->filename);
weechat_log_printf (" handle . . . . . . . . : 0x%X\n", plugin->handle);
weechat_log_printf (" name . . . . . . . . . : '%s'\n", plugin->name);
weechat_log_printf (" description. . . . . . : '%s'\n", plugin->description);
weechat_log_printf (" version. . . . . . . . : '%s'\n", plugin->version);
weechat_log_printf (" charset. . . . . . . . : '%s'\n", plugin->charset);
weechat_log_printf (" handlers . . . . . . . : 0x%X\n", plugin->handlers);
weechat_log_printf (" last_handler . . . . . : 0x%X\n", plugin->last_handler);
weechat_log_printf (" modifiers. . . . . . . : 0x%X\n", plugin->modifiers);
weechat_log_printf (" last_modifier. . . . . : 0x%X\n", plugin->last_modifier);
weechat_log_printf (" prev_plugin. . . . . . : 0x%X\n", plugin->prev_plugin);
weechat_log_printf (" next_plugin. . . . . . : 0x%X\n", plugin->next_plugin);
weechat_log_printf ("\n");
weechat_log_printf (" => handlers:\n");
for (ptr_handler = plugin->handlers; ptr_handler;
ptr_handler = ptr_handler->next_handler)
{
weechat_log_printf ("\n");
weechat_log_printf (" [handler (addr:0x%X)]\n", ptr_handler);
weechat_log_printf (" type . . . . . . . . : %d\n", ptr_handler->type);
weechat_log_printf (" irc_command. . . . . : '%s'\n", ptr_handler->irc_command);
weechat_log_printf (" command. . . . . . . : '%s'\n", ptr_handler->command);
weechat_log_printf (" description. . . . . : '%s'\n", ptr_handler->description);
weechat_log_printf (" arguments. . . . . . : '%s'\n", ptr_handler->arguments);
weechat_log_printf (" arguments_description: '%s'\n", ptr_handler->arguments_description);
weechat_log_printf (" completion_template. : '%s'\n", ptr_handler->completion_template);
weechat_log_printf (" interval . . . . . . : %d\n", ptr_handler->interval);
weechat_log_printf (" remaining. . . . . . : %d\n", ptr_handler->remaining);
weechat_log_printf (" event. . . . . . . . : '%s'\n", ptr_handler->event);
weechat_log_printf (" handler_args . . . . : '%s'\n", ptr_handler->handler_args);
weechat_log_printf (" handler_pointer. . . : 0x%X\n", ptr_handler->handler_pointer);
weechat_log_printf (" running. . . . . . . : %d\n", ptr_handler->running);
weechat_log_printf (" prev_handler . . . . : 0x%X\n", ptr_handler->prev_handler);
weechat_log_printf (" next_handler . . . . : 0x%X\n", ptr_handler->next_handler);
}
weechat_log_printf ("\n");
weechat_log_printf (" => modifiers:\n");
for (ptr_modifier = plugin->modifiers; ptr_modifier;
ptr_modifier = ptr_modifier->next_modifier)
{
weechat_log_printf ("\n");
weechat_log_printf (" [modifier (addr:0x%X)]\n", ptr_modifier);
weechat_log_printf (" type . . . . . . . . : %d\n", ptr_modifier->type);
weechat_log_printf (" command. . . . . . . : '%s'\n", ptr_modifier->command);
weechat_log_printf (" modifier . . . . . . : 0x%X\n", ptr_modifier->modifier);
weechat_log_printf (" modifier_args. . . . : '%s'\n", ptr_modifier->modifier_args);
weechat_log_printf (" modifier_pointer . . : 0x%X\n", ptr_modifier->modifier_pointer);
weechat_log_printf (" running. . . . . . . : %d\n", ptr_modifier->running);
weechat_log_printf (" prev_modifier. . . . : 0x%X\n", ptr_modifier->prev_modifier);
weechat_log_printf (" next_modifier. . . . : 0x%X\n", ptr_modifier->next_modifier);
}
}
+2 -1
View File
@@ -67,7 +67,7 @@ extern int plugin_msg_handler_exec (char *, char *, char *);
extern int plugin_cmd_handler_exec (char *, char *, char *);
extern int plugin_timer_handler_exec ();
extern int plugin_keyboard_handler_exec (char *, char *, char *);
extern int plugin_event_handler_exec (char *, char *);
extern int plugin_event_handler_exec (char *, int, char **);
extern void plugin_handler_remove (t_weechat_plugin *,
t_plugin_handler *);
extern void plugin_handler_remove_all (t_weechat_plugin *);
@@ -88,5 +88,6 @@ extern void plugin_unload_all ();
extern void plugin_reload_name (char *);
extern void plugin_init (int);
extern void plugin_end ();
extern void plugin_print_log (t_weechat_plugin *);
#endif /* plugins.h */
+22 -1
View File
@@ -215,7 +215,10 @@ weechat_lua_event_handler (t_weechat_plugin *plugin,
{
r = (int *) weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
SCRIPT_EXEC_INT,
handler_args, argv[0], NULL, NULL);
handler_args,
argv[0],
(argc >= 2) ? argv[1] : NULL,
(argc >= 3) ? argv[2] : NULL);
if (r == NULL)
ret = PLUGIN_RC_KO;
else
@@ -768,6 +771,24 @@ weechat_lua_add_command_handler (lua_State *L)
command = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
break;
case 3:
command = lua_tostring (lua_current_interpreter, -3);
function = lua_tostring (lua_current_interpreter, -2);
description = lua_tostring (lua_current_interpreter, -1);
break;
case 4:
command = lua_tostring (lua_current_interpreter, -4);
function = lua_tostring (lua_current_interpreter, -3);
description = lua_tostring (lua_current_interpreter, -2);
arguments = lua_tostring (lua_current_interpreter, -1);
break;
case 5:
command = lua_tostring (lua_current_interpreter, -5);
function = lua_tostring (lua_current_interpreter, -4);
description = lua_tostring (lua_current_interpreter, -3);
arguments = lua_tostring (lua_current_interpreter, -2);
arguments_description = lua_tostring (lua_current_interpreter, -1);
break;
case 6:
command = lua_tostring (lua_current_interpreter, -6);
function = lua_tostring (lua_current_interpreter, -5);
+4 -1
View File
@@ -336,7 +336,10 @@ weechat_perl_event_handler (t_weechat_plugin *plugin,
{
r = (int *) weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
SCRIPT_EXEC_INT,
handler_args, argv[0], NULL, NULL);
handler_args,
argv[0],
(argc >= 2) ? argv[1] : NULL,
(argc >= 3) ? argv[2] : NULL);
if (r == NULL)
ret = PLUGIN_RC_KO;
else
+4 -1
View File
@@ -257,7 +257,10 @@ weechat_python_event_handler (t_weechat_plugin *plugin,
{
r = (int *) weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
SCRIPT_EXEC_INT,
handler_args, argv[0], NULL, NULL);
handler_args,
argv[0],
(argc >= 2) ? argv[1] : NULL,
(argc >= 3) ? argv[2] : NULL);
if (r == NULL)
ret = PLUGIN_RC_KO;
else
+4 -1
View File
@@ -296,7 +296,10 @@ weechat_ruby_event_handler (t_weechat_plugin *plugin,
{
r = (int *) weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
SCRIPT_EXEC_INT,
handler_args, argv[0], NULL, NULL);
handler_args,
argv[0],
(argc >= 2) ? argv[1] : NULL,
(argc >= 3) ? argv[2] : NULL);
if (r == NULL)
ret = PLUGIN_RC_KO;
else