summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugins-interface.c89
-rw-r--r--src/plugins/plugins.c121
-rw-r--r--src/plugins/plugins.h4
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c404
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c248
-rw-r--r--src/plugins/scripts/python/weechat-python.c182
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c208
-rw-r--r--src/plugins/scripts/weechat-script.c31
-rw-r--r--src/plugins/scripts/weechat-script.h3
-rw-r--r--src/plugins/weechat-plugin.h14
10 files changed, 1099 insertions, 205 deletions
diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c
index b0d83cdfe..0355036bf 100644
--- a/src/plugins/plugins-interface.c
+++ b/src/plugins/plugins-interface.c
@@ -317,6 +317,22 @@ weechat_plugin_timer_handler_add (t_weechat_plugin *plugin, int interval,
}
/*
+ * weechat_plugin_keyboard_handler_add: add a keyboard handler
+ */
+
+t_plugin_handler *
+weechat_plugin_keyboard_handler_add (t_weechat_plugin *plugin,
+ t_plugin_handler_func *handler_func,
+ char *handler_args, void *handler_pointer)
+{
+ if (plugin && handler_func)
+ return plugin_keyboard_handler_add (plugin, handler_func,
+ handler_args, handler_pointer);
+
+ return NULL;
+}
+
+/*
* weechat_plugin_handler_remove: remove a WeeChat handler
*/
@@ -385,7 +401,7 @@ weechat_plugin_get_info (t_weechat_plugin *plugin, char *info, char *server)
t_irc_server *ptr_server;
t_irc_channel *ptr_channel;
time_t inactivity;
- char *inactivity_str;
+ char *return_str;
if (!plugin || !info)
return NULL;
@@ -420,11 +436,39 @@ weechat_plugin_get_info (t_weechat_plugin *plugin, char *info, char *server)
inactivity = 0;
else
inactivity = time (NULL) - gui_last_activity_time;
- inactivity_str = (char *) malloc (128);
- if (!inactivity_str)
+ return_str = (char *) malloc (32);
+ if (!return_str)
return NULL;
- snprintf (inactivity_str, 128, "%ld", inactivity);
- return inactivity_str;
+ snprintf (return_str, 32, "%ld", inactivity);
+ return return_str;
+ }
+ else if (ascii_strcasecmp (info, "input") == 0)
+ {
+ if (gui_current_window->buffer->has_input)
+ return strdup (gui_current_window->buffer->input_buffer);
+ else
+ return strdup ("");
+ }
+ else if (ascii_strcasecmp (info, "input_mask") == 0)
+ {
+ if (gui_current_window->buffer->has_input)
+ return strdup (gui_current_window->buffer->input_buffer_color_mask);
+ else
+ return strdup ("");
+ }
+ else if (ascii_strcasecmp (info, "input_pos") == 0)
+ {
+ if (gui_current_window->buffer->has_input)
+ {
+ return_str = (char *) malloc (32);
+ if (!return_str)
+ return NULL;
+ snprintf (return_str, 32, "%d",
+ gui_current_window->buffer->input_buffer_pos);
+ return return_str;
+ }
+ else
+ return strdup ("");
}
/* below are infos that need server to return value */
@@ -1009,3 +1053,38 @@ weechat_plugin_free_nick_info (t_weechat_plugin *plugin, t_plugin_nick_info *nic
nick_info = new_nick_info;
}
}
+
+/*
+ * weechat_plugin_input_color: add color in input buffer
+ * if color < 0, input buffer is refresh
+ * if start < 0 or length <= 0, color mask is reinit
+ * otherwise, color is applied from start to start + length
+ */
+
+void
+weechat_plugin_input_color (t_weechat_plugin *plugin, int color, int start, int length)
+{
+ int i;
+
+ if (!plugin
+ || (!gui_current_window->buffer->has_input)
+ || (gui_current_window->buffer->input_buffer_size == 0))
+ return;
+
+ if (color < 0)
+ gui_draw_buffer_input (gui_current_window->buffer, 0);
+ else
+ {
+ if ((start < 0) || (length <= 0))
+ gui_input_init_color_mask (gui_current_window->buffer);
+ else
+ {
+ color %= GUI_NUM_IRC_COLORS;
+ for (i = start; i < start + length; i++)
+ {
+ gui_current_window->buffer->input_buffer_color_mask[i] =
+ '0' + color;
+ }
+ }
+ }
+}
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index cbd5b276a..b96ef0365 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -371,6 +371,62 @@ plugin_timer_handler_add (t_weechat_plugin *plugin, int interval,
}
/*
+ * plugin_keyboard_handler_add: add a timer handler
+ * arguments:
+ * 1. the plugin pointer
+ * 2. the interval between two calls
+ * 3. the handler function
+ * 4. handler args: a string given to
+ * handler when called (used by scripts)
+ * 5. handler pointer: a pointer given to
+ * handler when called (used by scripts)
+ */
+
+t_plugin_handler *
+plugin_keyboard_handler_add (t_weechat_plugin *plugin,
+ t_plugin_handler_func *handler_func,
+ char *handler_args, void *handler_pointer)
+{
+ t_plugin_handler *new_handler;
+
+ new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
+ if (new_handler)
+ {
+ new_handler->type = HANDLER_KEYBOARD;
+ new_handler->irc_command = NULL;
+ new_handler->command = NULL;
+ new_handler->description = NULL;
+ new_handler->arguments = NULL;
+ new_handler->arguments_description = NULL;
+ new_handler->completion_template = NULL;
+ new_handler->interval = 0;
+ new_handler->remaining = 0;
+ new_handler->handler = handler_func;
+ new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
+ new_handler->handler_pointer = handler_pointer;
+ new_handler->running = 0;
+
+ /* add new handler to list */
+ new_handler->prev_handler = plugin->last_handler;
+ new_handler->next_handler = NULL;
+ if (plugin->handlers)
+ (plugin->last_handler)->next_handler = new_handler;
+ else
+ plugin->handlers = new_handler;
+ plugin->last_handler = new_handler;
+ }
+ else
+ {
+ irc_display_prefix (NULL, NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s plugin %s: unable to add keyboard handler (not enough memory)\n"),
+ WEECHAT_ERROR, plugin->name);
+ return NULL;
+ }
+ return new_handler;
+}
+
+/*
* plugin_msg_handler_exec: execute a message handler
* return: code for informing WeeChat whether message
* should be ignored or not
@@ -382,6 +438,11 @@ plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
t_weechat_plugin *ptr_plugin;
t_plugin_handler *ptr_handler;
int return_code, final_return_code;
+ char *argv[3] = { NULL, NULL, NULL };
+
+ argv[0] = server;
+ argv[1] = irc_command;
+ argv[2] = irc_message;
final_return_code = PLUGIN_RC_OK;
@@ -398,9 +459,7 @@ plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
{
ptr_handler->running = 1;
return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- server,
- irc_command,
- irc_message,
+ 3, argv,
ptr_handler->handler_args,
ptr_handler->handler_pointer));
ptr_handler->running = 0;
@@ -432,6 +491,11 @@ plugin_cmd_handler_exec (char *server, char *command, char *arguments)
t_weechat_plugin *ptr_plugin;
t_plugin_handler *ptr_handler;
int return_code;
+ char *argv[3] = { NULL, NULL, NULL };
+
+ argv[0] = server;
+ argv[1] = command;
+ argv[2] = arguments;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
@@ -446,9 +510,7 @@ plugin_cmd_handler_exec (char *server, char *command, char *arguments)
{
ptr_handler->running = 1;
return_code = (int) (ptr_handler->handler) (ptr_plugin,
- server,
- command,
- arguments,
+ 3, argv,
ptr_handler->handler_args,
ptr_handler->handler_pointer);
ptr_handler->running = 0;
@@ -488,9 +550,7 @@ plugin_timer_handler_exec ()
if (ptr_handler->remaining <= 0)
{
return_code = ((int) (ptr_handler->handler) (ptr_plugin,
- "",
- "",
- "",
+ 0, NULL,
ptr_handler->handler_args,
ptr_handler->handler_pointer));
ptr_handler->remaining = ptr_handler->interval;
@@ -505,6 +565,47 @@ plugin_timer_handler_exec ()
}
/*
+ * plugin_keyboard_handler_exec: execute all keyboard handlers
+ * return: PLUGIN_RC_OK if all ok
+ * PLUGIN_RC_KO if at least one handler failed
+ */
+
+int
+plugin_keyboard_handler_exec (char *key, char *input_before, char *input_after)
+{
+ t_weechat_plugin *ptr_plugin;
+ t_plugin_handler *ptr_handler;
+ int return_code, final_return_code;
+ char *argv[3] = { NULL, NULL, NULL };
+
+ argv[0] = key;
+ argv[1] = input_before;
+ argv[2] = input_after;
+
+ final_return_code = PLUGIN_RC_OK;
+
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ for (ptr_handler = ptr_plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
+ {
+ if (ptr_handler->type == HANDLER_KEYBOARD)
+ {
+ return_code = ((int) (ptr_handler->handler) (ptr_plugin,
+ 3, argv,
+ ptr_handler->handler_args,
+ ptr_handler->handler_pointer));
+ if (return_code == PLUGIN_RC_KO)
+ final_return_code = PLUGIN_RC_KO;
+ }
+ }
+ }
+
+ return final_return_code;
+}
+
+/*
* plugin_handler_remove: remove a handler for a plugin
*/
@@ -736,6 +837,7 @@ plugin_load (char *filename)
new_plugin->msg_handler_add = &weechat_plugin_msg_handler_add;
new_plugin->cmd_handler_add = &weechat_plugin_cmd_handler_add;
new_plugin->timer_handler_add = &weechat_plugin_timer_handler_add;
+ new_plugin->keyboard_handler_add = &weechat_plugin_keyboard_handler_add;
new_plugin->handler_remove = &weechat_plugin_handler_remove;
new_plugin->handler_remove_all = &weechat_plugin_handler_remove_all;
new_plugin->print = &weechat_plugin_print;
@@ -757,6 +859,7 @@ plugin_load (char *filename)
new_plugin->free_channel_info = &weechat_plugin_free_channel_info;
new_plugin->get_nick_info = &weechat_plugin_get_nick_info;
new_plugin->free_nick_info = &weechat_plugin_free_nick_info;
+ new_plugin->input_color = &weechat_plugin_input_color;
/* handlers */
new_plugin->handlers = NULL;
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 2ca01aa5b..48eb16944 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -48,9 +48,13 @@ extern t_plugin_handler *plugin_cmd_handler_add (t_weechat_plugin *, char *,
extern t_plugin_handler *plugin_timer_handler_add (t_weechat_plugin *, int,
t_plugin_handler_func *,
char *, void *);
+extern t_plugin_handler *plugin_keyboard_handler_add (t_weechat_plugin *,
+ t_plugin_handler_func *,
+ char *, void *);
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 void plugin_handler_remove (t_weechat_plugin *,
t_plugin_handler *);
extern void plugin_handler_remove_all (t_weechat_plugin *);
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index e2efb8d6b..889f2c300 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -54,7 +54,7 @@ lua_State *lua_current_interpreter = NULL;
int
weechat_lua_exec (t_weechat_plugin *plugin,
t_plugin_script *script,
- char *function, char *server, char *arguments)
+ char *function, char *arg1, char *arg2, char *arg3)
{
lua_current_interpreter = script->interpreter;
@@ -62,10 +62,19 @@ weechat_lua_exec (t_weechat_plugin *plugin,
lua_getglobal (lua_current_interpreter, function);
lua_current_script = script;
- lua_pushstring (lua_current_interpreter, server == NULL ? "" : server);
- lua_pushstring (lua_current_interpreter, arguments == NULL ? "" : arguments);
+ if (arg1)
+ {
+ lua_pushstring (lua_current_interpreter, (arg1) ? arg1 : "");
+ if (arg2)
+ {
+ lua_pushstring (lua_current_interpreter, (arg2) ? arg2 : "");
+ if (arg3)
+ lua_pushstring (lua_current_interpreter, (arg3) ? arg3 : "");
+ }
+ }
- if ( lua_pcall(lua_current_interpreter, 2, 1, 0) != 0)
+ if (lua_pcall (lua_current_interpreter,
+ (arg1) ? ((arg2) ? ((arg3) ? 3 : 2) : 1) : 0, 1, 0) != 0)
{
plugin->print_server (plugin,
"Lua error: unable to run function \"%s\"",
@@ -80,19 +89,52 @@ weechat_lua_exec (t_weechat_plugin *plugin,
}
/*
- * weechat_lua_handler: general message and command handler for Lua
+ * weechat_lua_cmd_msg_handler: general command/message handler for Lua
+ */
+
+int
+weechat_lua_cmd_msg_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[2], NULL);
+ else
+ return PLUGIN_RC_KO;
+}
+
+/*
+ * weechat_lua_timer_handler: general timer handler for Lua
*/
int
-weechat_lua_handler (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
- char *handler_args, void *handler_pointer)
+weechat_lua_timer_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
{
/* make gcc happy */
- (void) command;
+ (void) argc;
+ (void) argv;
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
- handler_args, server, arguments);
+ handler_args, NULL, NULL, NULL);
+}
+
+/*
+ * weechat_lua_keyboard_handler: general keyboard handler for Lua
+ */
+
+int
+weechat_lua_keyboard_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 2)
+ return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[1], argv[2]);
+ else
+ return PLUGIN_RC_KO;
}
/*
@@ -104,6 +146,7 @@ weechat_lua_register (lua_State *L)
{
const char *name, *version, *shutdown_func, *description;
int n;
+
/* make gcc happy */
(void) L;
@@ -179,6 +222,7 @@ weechat_lua_print (lua_State *L)
{
const char *message, *channel_name, *server_name;
int n;
+
/* make gcc happy */
(void) L;
@@ -199,24 +243,24 @@ weechat_lua_print (lua_State *L)
switch (n)
{
- case 1:
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- case 2:
- channel_name = lua_tostring (lua_current_interpreter, -2);
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- case 3:
- server_name = lua_tostring (lua_current_interpreter, -3);
- channel_name = lua_tostring (lua_current_interpreter, -2);
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- default:
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"print\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ case 1:
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 2:
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 3:
+ server_name = lua_tostring (lua_current_interpreter, -3);
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ default:
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"print\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
}
lua_plugin->print (lua_plugin,
@@ -237,6 +281,7 @@ weechat_lua_print_infobar (lua_State *L)
{
const char *message;
int delay, n;
+
/* make gcc happy */
(void) L;
@@ -280,6 +325,7 @@ static int
weechat_lua_remove_infobar (lua_State *L)
{
int n, how_many;
+
/* make gcc happy */
(void) L;
@@ -314,6 +360,7 @@ weechat_lua_log (lua_State *L)
{
const char *message, *channel_name, *server_name;
int n;
+
/* make gcc happy */
(void) L;
@@ -334,24 +381,24 @@ weechat_lua_log (lua_State *L)
switch (n)
{
- case 1:
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- case 2:
- channel_name = lua_tostring (lua_current_interpreter, -2);
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- case 3:
- server_name = lua_tostring (lua_current_interpreter, -3);
- channel_name = lua_tostring (lua_current_interpreter, -2);
- message = lua_tostring (lua_current_interpreter, -1);
- break;
- default:
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"log\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ case 1:
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 2:
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 3:
+ server_name = lua_tostring (lua_current_interpreter, -3);
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+ break;
+ default:
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"log\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
}
lua_plugin->log (lua_plugin,
@@ -372,6 +419,7 @@ weechat_lua_command (lua_State *L)
{
const char *command, *channel_name, *server_name;
int n;
+
/* make gcc happy */
(void) L;
@@ -392,24 +440,24 @@ weechat_lua_command (lua_State *L)
switch (n)
{
- case 1:
- command = lua_tostring (lua_current_interpreter, -1);
- break;
- case 2:
- channel_name = lua_tostring (lua_current_interpreter, -2);
- command = lua_tostring (lua_current_interpreter, -1);
- break;
- case 3:
- server_name = lua_tostring (lua_current_interpreter, -3);
- channel_name = lua_tostring (lua_current_interpreter, -2);
- command = lua_tostring (lua_current_interpreter, -1);
- break;
- default:
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"command\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ case 1:
+ command = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 2:
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ command = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 3:
+ server_name = lua_tostring (lua_current_interpreter, -3);
+ channel_name = lua_tostring (lua_current_interpreter, -2);
+ command = lua_tostring (lua_current_interpreter, -1);
+ break;
+ default:
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"command\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
}
lua_plugin->exec_command (lua_plugin,
@@ -430,6 +478,7 @@ weechat_lua_add_message_handler (lua_State *L)
{
const char *irc_command, *function;
int n;
+
/* make gcc happy */
(void) L;
@@ -460,7 +509,8 @@ weechat_lua_add_message_handler (lua_State *L)
function = lua_tostring (lua_current_interpreter, -1);
if (!lua_plugin->msg_handler_add (lua_plugin, (char *) irc_command,
- weechat_lua_handler, (char *) function,
+ weechat_lua_cmd_msg_handler,
+ (char *) function,
(void *)lua_current_script))
{
lua_pushnumber (lua_current_interpreter, 0);
@@ -481,6 +531,7 @@ weechat_lua_add_command_handler (lua_State *L)
const char *command, *function, *description, *arguments, *arguments_description;
const char *completion_template;
int n;
+
/* make gcc happy */
(void) L;
@@ -504,24 +555,24 @@ weechat_lua_add_command_handler (lua_State *L)
switch (n)
{
- case 2:
- command = lua_tostring (lua_current_interpreter, -2);
- function = lua_tostring (lua_current_interpreter, -1);
- break;
- case 6:
- command = lua_tostring (lua_current_interpreter, -6);
- function = lua_tostring (lua_current_interpreter, -5);
- description = lua_tostring (lua_current_interpreter, -4);
- arguments = lua_tostring (lua_current_interpreter, -3);
- arguments_description = lua_tostring (lua_current_interpreter, -2);
- completion_template = lua_tostring (lua_current_interpreter, -1);
- break;
- default:
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"add_command_handler\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ case 2:
+ command = lua_tostring (lua_current_interpreter, -2);
+ function = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 6:
+ command = lua_tostring (lua_current_interpreter, -6);
+ function = lua_tostring (lua_current_interpreter, -5);
+ description = lua_tostring (lua_current_interpreter, -4);
+ arguments = lua_tostring (lua_current_interpreter, -3);
+ arguments_description = lua_tostring (lua_current_interpreter, -2);
+ completion_template = lua_tostring (lua_current_interpreter, -1);
+ break;
+ default:
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"add_command_handler\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
}
if (!lua_plugin->cmd_handler_add (lua_plugin,
@@ -530,7 +581,7 @@ weechat_lua_add_command_handler (lua_State *L)
(char *) arguments,
(char *) arguments_description,
(char *) completion_template,
- weechat_lua_handler,
+ weechat_lua_cmd_msg_handler,
(char *) function,
(void *)lua_current_script))
{
@@ -552,6 +603,7 @@ weechat_lua_add_timer_handler (lua_State *L)
int interval;
const char *function;
int n;
+
/* make gcc happy */
(void) L;
@@ -582,7 +634,8 @@ weechat_lua_add_timer_handler (lua_State *L)
function = lua_tostring (lua_current_interpreter, -1);
if (!lua_plugin->timer_handler_add (lua_plugin, interval,
- weechat_lua_handler, (char *) function,
+ weechat_lua_timer_handler,
+ (char *) function,
(void *)lua_current_script))
{
lua_pushnumber (lua_current_interpreter, 0);
@@ -594,7 +647,57 @@ weechat_lua_add_timer_handler (lua_State *L)
}
/*
- * weechat_lua_remove_handler: remove a handler
+ * weechat_lua_add_keyboard_handler: add a keyboard handler
+ */
+
+static int
+weechat_lua_add_keyboard_handler (lua_State *L)
+{
+ const char *function;
+ int n;
+
+ /* make gcc happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: unable to add keyboard handler, "
+ "script not initialized");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n != 1)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"add_keyboard_handler\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ if (!lua_plugin->keyboard_handler_add (lua_plugin,
+ weechat_lua_keyboard_handler,
+ (char *) function,
+ (void *)lua_current_script))
+ {
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ lua_pushnumber (lua_current_interpreter, 1);
+ return 1;
+}
+
+/*
+ * weechat_lua_remove_handler: remove a command/message handler
*/
static int
@@ -602,6 +705,7 @@ weechat_lua_remove_handler (lua_State *L)
{
const char *command, *function;
int n;
+
/* make gcc happy */
(void) L;
@@ -647,6 +751,7 @@ weechat_lua_remove_timer_handler (lua_State *L)
{
const char *function;
int n;
+
/* make gcc happy */
(void) L;
@@ -682,6 +787,50 @@ weechat_lua_remove_timer_handler (lua_State *L)
}
/*
+ * weechat_lua_remove_keyboard_handler: remove a keyboard handler
+ */
+
+static int
+weechat_lua_remove_keyboard_handler (lua_State *L)
+{
+ const char *function;
+ int n;
+
+ /* make gcc happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: unable to remove keyboard handler, "
+ "script not initialized");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n != 1)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"remove_keyboard_handler\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_script_remove_keyboard_handler (lua_plugin, lua_current_script,
+ (char *) function);
+
+ lua_pushnumber (lua_current_interpreter, 1);
+ return 1;
+}
+
+/*
* weechat_lua_get_info: get various infos
*/
@@ -691,6 +840,7 @@ weechat_lua_get_info (lua_State *L)
const char *arg, *server_name;
char *info;
int n;
+
/* make gcc happy */
(void) L;
@@ -710,19 +860,19 @@ weechat_lua_get_info (lua_State *L)
switch (n)
{
- case 1:
- arg = lua_tostring (lua_current_interpreter, -1);
- break;
- case 2:
- arg = lua_tostring (lua_current_interpreter, -2);
- server_name = lua_tostring (lua_current_interpreter, -1);
- break;
- default:
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_info\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ case 1:
+ arg = lua_tostring (lua_current_interpreter, -1);
+ break;
+ case 2:
+ arg = lua_tostring (lua_current_interpreter, -2);
+ server_name = lua_tostring (lua_current_interpreter, -1);
+ break;
+ default:
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"get_info\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
}
info = lua_plugin->get_info (lua_plugin, (char *) arg, (char *) server_name);
@@ -746,6 +896,7 @@ weechat_lua_get_dcc_info (lua_State *L)
char timebuffer2[64];
struct in_addr in;
int i;
+
/* make gcc happy */
(void) L;
@@ -767,7 +918,7 @@ weechat_lua_get_dcc_info (lua_State *L)
lua_newtable (lua_current_interpreter);
- for(i=0, ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc, i++)
+ for (i = 0, ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc, i++)
{
strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
localtime(&ptr_dcc->start_time));
@@ -860,6 +1011,7 @@ weechat_lua_get_config (lua_State *L)
const char *option;
char *return_value;
int n;
+
/* make gcc happy */
(void) L;
@@ -905,6 +1057,7 @@ weechat_lua_set_config (lua_State *L)
{
const char *option, *value;
int n;
+
/* make gcc happy */
(void) L;
@@ -952,6 +1105,7 @@ weechat_lua_get_plugin_config (lua_State *L)
const char *option;
char *return_value;
int n;
+
/* make gcc happy */
(void) L;
@@ -999,6 +1153,7 @@ weechat_lua_set_plugin_config (lua_State *L)
{
const char *option, *value;
int n;
+
/* make gcc happy */
(void) L;
@@ -1047,6 +1202,7 @@ weechat_lua_get_server_info (lua_State *L)
{
t_plugin_server_info *server_info, *ptr_server;
char timebuffer[64];
+
/* make gcc happy */
(void) L;
@@ -1067,7 +1223,7 @@ weechat_lua_get_server_info (lua_State *L)
lua_newtable (lua_current_interpreter);
- for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
+ for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
{
strftime(timebuffer, sizeof(timebuffer), "%F %T",
localtime(&ptr_server->away_time));
@@ -1201,6 +1357,7 @@ weechat_lua_get_channel_info (lua_State *L)
t_plugin_channel_info *channel_info, *ptr_channel;
const char *server;
int n;
+
/* make gcc happy */
(void) L;
@@ -1237,7 +1394,7 @@ weechat_lua_get_channel_info (lua_State *L)
lua_newtable (lua_current_interpreter);
- for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
+ for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
{
lua_pushstring (lua_current_interpreter, ptr_channel->name);
lua_newtable (lua_current_interpreter);
@@ -1284,6 +1441,7 @@ weechat_lua_get_nick_info (lua_State *L)
t_plugin_nick_info *nick_info, *ptr_nick;
const char *server, *channel;
int n;
+
/* make gcc happy */
(void) L;
@@ -1349,6 +1507,7 @@ weechat_lua_constant_plugin_rc_ok (lua_State *L)
{
/* make gcc happy */
(void) L;
+
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK);
return 1;
}
@@ -1358,6 +1517,7 @@ weechat_lua_constant_plugin_rc_ko (lua_State *L)
{
/* make gcc happy */
(void) L;
+
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_KO);
return 1;
}
@@ -1367,6 +1527,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_weechat (lua_State *L)
{
/* make gcc happy */
(void) L;
+
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_WEECHAT);
return 1;
}
@@ -1376,6 +1537,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_plugins (lua_State *L)
{
/* make gcc happy */
(void) L;
+
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_PLUGINS);
return 1;
}
@@ -1385,6 +1547,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_all (lua_State *L)
{
/* make gcc happy */
(void) L;
+
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_ALL);
return 1;
}
@@ -1404,8 +1567,10 @@ const struct luaL_reg weechat_lua_funcs[] = {
{ "add_message_handler", weechat_lua_add_message_handler},
{ "add_command_handler", weechat_lua_add_command_handler},
{ "add_timer_handler", weechat_lua_add_timer_handler},
+ { "add_keyboard_handler", weechat_lua_add_keyboard_handler},
{ "remove_handler", weechat_lua_remove_handler},
{ "remove_timer_handler", weechat_lua_remove_timer_handler},
+ { "remove_keyboard_handler", weechat_lua_remove_keyboard_handler},
{ "get_info", weechat_lua_get_info},
{ "get_dcc_info", weechat_lua_get_dcc_info},
{ "get_config", weechat_lua_get_config},
@@ -1536,7 +1701,7 @@ weechat_lua_unload (t_weechat_plugin *plugin, t_plugin_script *script)
script->name);
if (script->shutdown_func[0])
- weechat_lua_exec (plugin, script, script->shutdown_func, "", "");
+ weechat_lua_exec (plugin, script, script->shutdown_func, "", "", "");
lua_close (script->interpreter);
@@ -1590,8 +1755,8 @@ weechat_lua_unload_all (t_weechat_plugin *plugin)
int
weechat_lua_cmd (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
- char *handler_args, void *handler_pointer)
+ int cmd_argc, char **cmd_argv,
+ char *handler_args, void *handler_pointer)
{
int argc, handler_found;
char **argv, *path_script;
@@ -1599,13 +1764,14 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
t_plugin_handler *ptr_handler;
/* make gcc happy */
- (void) server;
- (void) command;
(void) handler_args;
(void) handler_pointer;
- if (arguments)
- argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
+ if (cmd_argc < 3)
+ return PLUGIN_RC_KO;
+
+ if (cmd_argv[2])
+ argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
else
{
argv = NULL;
@@ -1689,6 +1855,24 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
}
if (!handler_found)
plugin->print_server (plugin, " (none)");
+
+ /* list Lua keyboard handlers */
+ plugin->print_server (plugin, "");
+ plugin->print_server (plugin, "Lua keyboard handlers:");
+ handler_found = 0;
+ for (ptr_handler = plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
+ {
+ if ((ptr_handler->type == HANDLER_KEYBOARD)
+ && (ptr_handler->handler_args))
+ {
+ handler_found = 1;
+ plugin->print_server (plugin, " Lua(%s)",
+ ptr_handler->handler_args);
+ }
+ }
+ if (!handler_found)
+ plugin->print_server (plugin, " (none)");
break;
case 1:
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
@@ -1730,7 +1914,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
if (argv)
plugin->free_exploded_string (plugin, argv);
- return 1;
+ return PLUGIN_RC_OK;
}
/*
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index c1605e22a..d2e3aa297 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -103,11 +103,11 @@ char *weechat_perl_code =
int
weechat_perl_exec (t_weechat_plugin *plugin,
t_plugin_script *script,
- char *function, char *server, char *arguments)
+ char *function, char *arg1, char *arg2, char *arg3)
{
- char empty_server[1] = { '\0' };
+ char empty_arg[1] = { '\0' };
char *func;
- char *argv[3];
+ char *argv[4];
unsigned int count;
int return_code;
SV *sv;
@@ -116,11 +116,11 @@ weechat_perl_exec (t_weechat_plugin *plugin,
dSP;
#ifndef MULTIPLICITY
- int size = strlen(script->interpreter) + strlen(function) + 3;
+ int size = strlen (script->interpreter) + strlen(function) + 3;
func = (char *) malloc ( size * sizeof(char));
- if (func == NULL)
+ if (!func)
return PLUGIN_RC_KO;
- snprintf(func, size, "%s::%s", (char *) script->interpreter, function);
+ snprintf (func, size, "%s::%s", (char *) script->interpreter, function);
#else
func = function;
PERL_SET_CONTEXT (script->interpreter);
@@ -129,12 +129,25 @@ weechat_perl_exec (t_weechat_plugin *plugin,
ENTER;
SAVETMPS;
PUSHMARK(sp);
- if (!server)
- argv[0] = empty_server;
+ if (arg1)
+ {
+ argv[0] = (arg1) ? arg1 : empty_arg;
+ if (arg2)
+ {
+ argv[1] = (arg2) ? arg2 : empty_arg;
+ if (arg3)
+ {
+ argv[2] = (arg3) ? arg3 : empty_arg;
+ argv[3] = NULL;
+ }
+ else
+ argv[2] = NULL;
+ }
+ else
+ argv[1] = NULL;
+ }
else
- argv[0] = server;
- argv[1] = arguments;
- argv[2] = NULL;
+ argv[0] = NULL;
perl_current_script = script;
@@ -166,26 +179,59 @@ weechat_perl_exec (t_weechat_plugin *plugin,
LEAVE;
#ifndef MULTIPLICITY
- free(func);
+ free (func);
#endif
return return_code;
}
/*
- * weechat_perl_handler: general message and command handler for Perl
+ * weechat_perl_cmd_msg_handler: general command/message handler for Perl
+ */
+
+int
+weechat_perl_cmd_msg_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[2], NULL);
+ else
+ return PLUGIN_RC_KO;
+}
+
+/*
+ * weechat_perl_timer_handler: general timer handler for Perl
*/
int
-weechat_perl_handler (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
- char *handler_args, void *handler_pointer)
+weechat_perl_timer_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
{
/* make gcc happy */
- (void) command;
+ (void) argc;
+ (void) argv;
return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
- handler_args, server, arguments);
+ handler_args, NULL, NULL, NULL);
+}
+
+/*
+ * weechat_perl_keyboard_handler: general keyboard handler for Perl
+ */
+
+int
+weechat_perl_keyboard_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[1], argv[2]);
+ else
+ return PLUGIN_RC_KO;
}
/*
@@ -456,7 +502,7 @@ static XS (XS_weechat_command)
}
/*
- * weechat::add_message_handler: add handler for messages (privmsg, ...)
+ * weechat::add_message_handler: add a handler for messages (privmsg, ...)
*/
static XS (XS_weechat_add_message_handler)
@@ -488,7 +534,7 @@ static XS (XS_weechat_add_message_handler)
function = SvPV (ST (1), integer);
if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
- weechat_perl_handler, function,
+ weechat_perl_cmd_msg_handler, function,
(void *)perl_current_script))
XSRETURN_YES;
@@ -496,7 +542,7 @@ static XS (XS_weechat_add_message_handler)
}
/*
- * weechat::add_command_handler: add command handler (define/redefine commands)
+ * weechat::add_command_handler: add a command handler (define/redefine commands)
*/
static XS (XS_weechat_add_command_handler)
@@ -538,7 +584,7 @@ static XS (XS_weechat_add_command_handler)
arguments,
arguments_description,
completion_template,
- weechat_perl_handler,
+ weechat_perl_cmd_msg_handler,
function,
(void *)perl_current_script))
XSRETURN_YES;
@@ -547,7 +593,7 @@ static XS (XS_weechat_add_command_handler)
}
/*
- * weechat::add_timer_handler: add timer handler
+ * weechat::add_timer_handler: add a timer handler
*/
static XS (XS_weechat_add_timer_handler)
@@ -579,10 +625,8 @@ static XS (XS_weechat_add_timer_handler)
interval = SvIV (ST (0));
function = SvPV (ST (1), integer);
- perl_plugin->print_server (perl_plugin,
- "Perl add timer: interval = %d", interval);
if (perl_plugin->timer_handler_add (perl_plugin, interval,
- weechat_perl_handler, function,
+ weechat_perl_timer_handler, function,
(void *)perl_current_script))
XSRETURN_YES;
@@ -590,6 +634,46 @@ static XS (XS_weechat_add_timer_handler)
}
/*
+ * weechat::add_keyboard_handler: add a keyboard handler
+ */
+
+static XS (XS_weechat_add_keyboard_handler)
+{
+ char *function;
+ unsigned int integer;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: unable to add keyboard handler, "
+ "script not initialized");
+ XSRETURN_NO;
+ }
+
+ if (items < 1)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: wrong parameters for "
+ "\"add_keyboard_handler\" function");
+ XSRETURN_NO;
+ }
+
+ function = SvPV (ST (0), integer);
+
+ if (perl_plugin->keyboard_handler_add (perl_plugin,
+ weechat_perl_keyboard_handler,
+ function,
+ (void *)perl_current_script))
+ XSRETURN_YES;
+
+ XSRETURN_NO;
+}
+
+/*
* weechat::remove_handler: remove a message/command handler
*/
@@ -665,6 +749,43 @@ static XS (XS_weechat_remove_timer_handler)
}
/*
+ * weechat::remove_keyboard_handler: remove a keyboard handler
+ */
+
+static XS (XS_weechat_remove_keyboard_handler)
+{
+ char *function;
+ unsigned int integer;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: unable to remove keyboard handler, "
+ "script not initialized");
+ XSRETURN_NO;
+ }
+
+ if (items < 1)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: wrong parameters for "
+ "\"remove_keyboard_handler\" function");
+ XSRETURN_NO;
+ }
+
+ function = SvPV (ST (0), integer);
+
+ weechat_script_remove_keyboard_handler (perl_plugin, perl_current_script,
+ function);
+
+ XSRETURN_YES;
+}
+
+/*
* weechat::get_info: get various infos
*/
@@ -1171,6 +1292,43 @@ static XS (XS_weechat_get_nick_info)
}
/*
+ * weechat::color_input: add color in input buffer
+ */
+
+static XS (XS_weechat_input_color)
+{
+ int color, start, length;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: unable to colorize input, "
+ "script not initialized");
+ XSRETURN_NO;
+ }
+
+ if (items < 3)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: wrong parameters for "
+ "\"color_input\" function");
+ XSRETURN_NO;
+ }
+
+ color = SvIV (ST (0));
+ start = SvIV (ST (1));
+ length = SvIV (ST (2));
+
+ perl_plugin->input_color (perl_plugin, color, start, length);
+
+ XSRETURN_YES;
+}
+
+/*
* weechat_perl_xs_init: initialize subroutines
*/
@@ -1191,8 +1349,10 @@ weechat_perl_xs_init (pTHX)
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
newXS ("weechat::add_timer_handler", XS_weechat_add_timer_handler, "weechat");
+ newXS ("weechat::add_keyboard_handler", XS_weechat_add_keyboard_handler, "weechat");
newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat");
newXS ("weechat::remove_timer_handler", XS_weechat_remove_timer_handler, "weechat");
+ newXS ("weechat::remove_keyboard_handler", XS_weechat_remove_keyboard_handler, "weechat");
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
newXS ("weechat::get_config", XS_weechat_get_config, "weechat");
@@ -1202,6 +1362,7 @@ weechat_perl_xs_init (pTHX)
newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat");
newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat");
newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
+ newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
/* interface constants */
stash = gv_stashpv ("weechat", TRUE);
@@ -1237,7 +1398,7 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename)
snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, packnum);
packnum++;
tempscript.interpreter = "WeechatPerlScriptLoader";
- eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, pkgname);
+ eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, pkgname, "");
#else
perl_current_interpreter = perl_alloc();
@@ -1256,7 +1417,7 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename)
perl_parse (perl_current_interpreter, weechat_perl_xs_init, 3, perl_args, NULL);
eval_pv (weechat_perl_code, TRUE);
- eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, "");
+ eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, "", "");
free (perl_current_script_filename);
@@ -1338,7 +1499,7 @@ weechat_perl_unload (t_weechat_plugin *plugin, t_plugin_script *script)
#endif
if (script->shutdown_func[0])
- weechat_perl_exec (plugin, script, script->shutdown_func, "", "");
+ weechat_perl_exec (plugin, script, script->shutdown_func, "", "", "");
#ifndef MULTIPLICITY
if (script->interpreter)
@@ -1398,7 +1559,7 @@ weechat_perl_unload_all (t_weechat_plugin *plugin)
int
weechat_perl_cmd (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
+ int cmd_argc, char **cmd_argv,
char *handler_args, void *handler_pointer)
{
int argc, handler_found;
@@ -1406,14 +1567,15 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
t_plugin_script *ptr_script;
t_plugin_handler *ptr_handler;
+ if (cmd_argc < 3)
+ return PLUGIN_RC_KO;
+
/* make gcc happy */
- (void) server;
- (void) command;
(void) handler_args;
(void) handler_pointer;
- if (arguments)
- argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
+ if (cmd_argv[2])
+ argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
else
{
argv = NULL;
@@ -1497,6 +1659,22 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
}
if (!handler_found)
plugin->print_server (plugin, " (none)");
+
+ /* list Perl keyboard handlers */
+ plugin->print_server (plugin, "");
+ plugin->print_server (plugin, "Perl keyboard handlers:");
+ handler_found = 0;
+ for (ptr_handler = plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
+ {
+ if ((ptr_handler->type == HANDLER_KEYBOARD)
+ && (ptr_handler->handler_args))
+ {
+ handler_found = 1;
+ plugin->print_server (plugin, " Perl(%s)",
+ ptr_handler->handler_args);
+ }
+ }
break;
case 1:
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
@@ -1538,7 +1716,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
if (argv)
plugin->free_exploded_string (plugin, argv);
- return 1;
+ return PLUGIN_RC_OK;
}
/*
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index cca2db855..572130906 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -50,7 +50,7 @@ PyThreadState *python_mainThreadState = NULL;
int
weechat_python_exec (t_weechat_plugin *plugin,
t_plugin_script *script,
- char *function, char *server, char *arguments)
+ char *function, char *arg1, char *arg2, char *arg3)
{
PyObject *evMain;
PyObject *evDict;
@@ -75,8 +75,21 @@ weechat_python_exec (t_weechat_plugin *plugin,
ret = -1;
python_current_script = script;
-
- rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
+
+ if (arg1)
+ {
+ if (arg2)
+ {
+ if (arg3)
+ rc = PyObject_CallFunction (evFunc, "sss", arg1, arg2, arg3);
+ else
+ rc = PyObject_CallFunction (evFunc, "ss", arg1, arg2);
+ }
+ else
+ rc = PyObject_CallFunction (evFunc, "s", arg1);
+ }
+ else
+ rc = PyObject_CallFunction (evFunc, "");
if (rc)
{
@@ -94,19 +107,52 @@ weechat_python_exec (t_weechat_plugin *plugin,
}
/*
- * weechat_python_handler: general message and command handler for Python
+ * weechat_python_cmd_msg_handler: general command/message handler for Python
*/
int
-weechat_python_handler (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
- char *handler_args, void *handler_pointer)
+weechat_python_cmd_msg_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[2], NULL);
+ else
+ return PLUGIN_RC_KO;
+}
+
+/*
+ * weechat_python_timer_handler: general timer handler for Python
+ */
+
+int
+weechat_python_timer_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
{
/* make gcc happy */
- (void) command;
+ (void) argc;
+ (void) argv;
return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
- handler_args, server, arguments);
+ handler_args, NULL, NULL, NULL);
+}
+
+/*
+ * weechat_python_keyboard_handler: general keyboard handler for Python
+ */
+
+int
+weechat_python_keyboard_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[1], argv[2]);
+ else
+ return PLUGIN_RC_KO;
}
/*
@@ -392,7 +438,8 @@ weechat_python_add_message_handler (PyObject *self, PyObject *args)
}
if (python_plugin->msg_handler_add (python_plugin, irc_command,
- weechat_python_handler, function,
+ weechat_python_cmd_msg_handler,
+ function,
(void *)python_current_script))
return Py_BuildValue ("i", 1);
@@ -443,7 +490,7 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
arguments,
arguments_description,
completion_template,
- weechat_python_handler,
+ weechat_python_cmd_msg_handler,
function,
(void *)python_current_script))
return Py_BuildValue ("i", 1);
@@ -484,7 +531,8 @@ weechat_python_add_timer_handler (PyObject *self, PyObject *args)
}
if (python_plugin->timer_handler_add (python_plugin, interval,
- weechat_python_handler, function,
+ weechat_python_timer_handler,
+ function,
(void *)python_current_script))
return Py_BuildValue ("i", 1);
@@ -492,6 +540,45 @@ weechat_python_add_timer_handler (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_add_keyboard_handler: add a keyboard handler
+ */
+
+static PyObject *
+weechat_python_add_keyboard_handler (PyObject *self, PyObject *args)
+{
+ char *function;
+
+ /* make gcc happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: unable to add keyboard handler, "
+ "script not initialized");
+ return Py_BuildValue ("i", 0);
+ }
+
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &function))
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: wrong parameters for "
+ "\"add_keyboard_handler\" function");
+ return Py_BuildValue ("i", 0);
+ }
+
+ if (python_plugin->keyboard_handler_add (python_plugin,
+ weechat_python_keyboard_handler,
+ function,
+ (void *)python_current_script))
+ return Py_BuildValue ("i", 1);
+
+ return Py_BuildValue ("i", 0);
+}
+
+/*
* weechat_python_remove_handler: remove a handler
*/
@@ -565,6 +652,42 @@ weechat_python_remove_timer_handler (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_remove_keyboard_handler: remove a keyboard handler
+ */
+
+static PyObject *
+weechat_python_remove_keyboard_handler (PyObject *self, PyObject *args)
+{
+ char *function;
+
+ /* make gcc happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: unable to remove keyboard handler, "
+ "script not initialized");
+ return Py_BuildValue ("i", 0);
+ }
+
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &function))
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: wrong parameters for "
+ "\"remove_keyboard_handler\" function");
+ return Py_BuildValue ("i", 0);
+ }
+
+ weechat_script_remove_keyboard_handler (python_plugin, python_current_script,
+ function);
+
+ return Py_BuildValue ("i", 1);
+}
+
+/*
* weechat_python_get_info: get various infos
*/
@@ -1132,8 +1255,10 @@ PyMethodDef weechat_python_funcs[] = {
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
{ "add_timer_handler", weechat_python_add_timer_handler, METH_VARARGS, "" },
+ { "add_keyboard_handler", weechat_python_add_keyboard_handler, METH_VARARGS, "" },
{ "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" },
{ "remove_timer_handler", weechat_python_remove_timer_handler, METH_VARARGS, "" },
+ { "remove_keyboard_handler", weechat_python_remove_keyboard_handler, METH_VARARGS, "" },
{ "get_info", weechat_python_get_info, METH_VARARGS, "" },
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
{ "get_config", weechat_python_get_config, METH_VARARGS, "" },
@@ -1307,7 +1432,7 @@ weechat_python_unload (t_weechat_plugin *plugin, t_plugin_script *script)
script->name);
if (script->shutdown_func[0])
- weechat_python_exec (plugin, script, script->shutdown_func, "", "");
+ weechat_python_exec (plugin, script, script->shutdown_func, "", "", "");
PyThreadState_Swap (script->interpreter);
Py_EndInterpreter (script->interpreter);
@@ -1362,7 +1487,7 @@ weechat_python_unload_all (t_weechat_plugin *plugin)
int
weechat_python_cmd (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
+ int cmd_argc, char **cmd_argv,
char *handler_args, void *handler_pointer)
{
int argc, handler_found;
@@ -1371,13 +1496,14 @@ weechat_python_cmd (t_weechat_plugin *plugin,
t_plugin_handler *ptr_handler;
/* make gcc happy */
- (void) server;
- (void) command;
(void) handler_args;
(void) handler_pointer;
- if (arguments)
- argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
+ if (cmd_argc < 3)
+ return PLUGIN_RC_KO;
+
+ if (cmd_argv[2])
+ argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
else
{
argv = NULL;
@@ -1461,6 +1587,24 @@ weechat_python_cmd (t_weechat_plugin *plugin,
}
if (!handler_found)
plugin->print_server (plugin, " (none)");
+
+ /* list Python keyboard handlers */
+ plugin->print_server (plugin, "");
+ plugin->print_server (plugin, "Python keyboard handlers:");
+ handler_found = 0;
+ for (ptr_handler = plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
+ {
+ if ((ptr_handler->type == HANDLER_KEYBOARD)
+ && (ptr_handler->handler_args))
+ {
+ handler_found = 1;
+ plugin->print_server (plugin, " Python(%s)",
+ ptr_handler->handler_args);
+ }
+ }
+ if (!handler_found)
+ plugin->print_server (plugin, " (none)");
break;
case 1:
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
@@ -1502,7 +1646,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
if (argv)
plugin->free_exploded_string (plugin, argv);
- return 1;
+ return PLUGIN_RC_OK;
}
/*
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 13f1e927f..1f6b8d933 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -104,7 +104,7 @@ rb_protect_funcall(VALUE recv, ID mid, int *state, int argc, ...)
int
weechat_ruby_exec (t_weechat_plugin *plugin,
t_plugin_script *script,
- char *function, char *server, char *arguments)
+ char *function, char *arg1, char *arg2, char *arg3)
{
VALUE ruby_retcode, err;
int ruby_error;
@@ -112,11 +112,32 @@ weechat_ruby_exec (t_weechat_plugin *plugin,
(void) plugin;
ruby_current_script = script;
-
- ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
- &ruby_error, 2,
- rb_str_new2((server == NULL) ? "" : server),
- rb_str_new2((arguments == NULL) ? "" : arguments));
+
+ if (arg1)
+ {
+ if (arg2)
+ {
+ if (arg3)
+ ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
+ &ruby_error, 3,
+ rb_str_new2(arg1),
+ rb_str_new2(arg2),
+ rb_str_new2(arg3));
+ else
+ ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
+ &ruby_error, 2,
+ rb_str_new2(arg1),
+ rb_str_new2(arg2));
+ }
+ else
+ ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
+ &ruby_error, 1,
+ rb_str_new2(arg1));
+ }
+ else
+ ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
+ &ruby_error, 0);
+
if (ruby_error)
{
ruby_plugin->print_server (ruby_plugin,
@@ -137,19 +158,52 @@ weechat_ruby_exec (t_weechat_plugin *plugin,
}
/*
- * weechat_ruby_handler: general message and command handler for Ruby
+ * weechat_ruby_cmd_msg_handler: general command/message handler for Ruby
*/
int
-weechat_ruby_handler (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
- char *handler_args, void *handler_pointer)
+weechat_ruby_cmd_msg_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 3)
+ return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[2], NULL);
+ else
+ return PLUGIN_RC_KO;
+}
+
+/*
+ * weechat_ruby_timer_handler: general timer handler for Ruby
+ */
+
+int
+weechat_ruby_timer_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
{
/* make gcc happy */
- (void) command;
+ (void) argc;
+ (void) argv;
return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
- handler_args, server, arguments);
+ handler_args, NULL, NULL, NULL);
+}
+
+/*
+ * weechat_ruby_keyboard_handler: general keyboard handler for Ruby
+ */
+
+int
+weechat_ruby_keyboard_handler (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *handler_args, void *handler_pointer)
+{
+ if (argc >= 2)
+ return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
+ handler_args, argv[0], argv[1], argv[2]);
+ else
+ return PLUGIN_RC_KO;
}
/*
@@ -482,7 +536,7 @@ weechat_ruby_command (int argc, VALUE *argv, VALUE class)
}
/*
- * weechat_ruby_add_message_handler: add handler for messages
+ * weechat_ruby_add_message_handler: add a handler for messages (privmsg, ...)
*/
static VALUE
@@ -519,7 +573,8 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
c_function = STR2CSTR (function);
if (ruby_plugin->msg_handler_add (ruby_plugin, c_message,
- weechat_ruby_handler, c_function,
+ weechat_ruby_cmd_msg_handler,
+ c_function,
(void *)ruby_current_script))
return INT2FIX (1);
@@ -527,7 +582,7 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
}
/*
- * weechat_ruby_add_command_handler: define/redefines commands
+ * weechat_ruby_add_command_handler: add a command handler (define/redefine commands)
*/
static VALUE
@@ -608,7 +663,7 @@ weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class)
c_arguments,
c_arguments_description,
c_completion_template,
- weechat_ruby_handler,
+ weechat_ruby_cmd_msg_handler,
c_function,
(void *)ruby_current_script))
return INT2FIX (1);
@@ -655,7 +710,8 @@ weechat_ruby_add_timer_handler (VALUE class, VALUE interval, VALUE function)
c_function = STR2CSTR (function);
if (ruby_plugin->timer_handler_add (ruby_plugin, c_interval,
- weechat_ruby_handler, c_function,
+ weechat_ruby_timer_handler,
+ c_function,
(void *)ruby_current_script))
return INT2FIX (1);
@@ -663,6 +719,49 @@ weechat_ruby_add_timer_handler (VALUE class, VALUE interval, VALUE function)
}
/*
+ * weechat_ruby_add_keyboard_handler: add a keyboard handler
+ */
+
+static VALUE
+weechat_ruby_add_keyboard_handler (VALUE class, VALUE function)
+{
+ char *c_function;
+
+ /* make gcc happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: unable to add keyboard handler, "
+ "script not initialized");
+ return INT2FIX (0);
+ }
+
+ c_function = NULL;
+
+ if (NIL_P (function))
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: wrong parameters for "
+ "\"add_keyboard_handler\" function");
+ return INT2FIX (0);
+ }
+
+ Check_Type (function, T_STRING);
+
+ c_function = STR2CSTR (function);
+
+ if (ruby_plugin->keyboard_handler_add (ruby_plugin,
+ weechat_ruby_keyboard_handler,
+ c_function,
+ (void *)ruby_current_script))
+ return INT2FIX (1);
+
+ return INT2FIX (0);
+}
+
+/*
* weechat_ruby_remove_handler: remove a handler
*/
@@ -746,6 +845,46 @@ weechat_ruby_remove_timer_handler (VALUE class, VALUE function)
}
/*
+ * weechat_ruby_remove_keyboard_handler: remove a keyboard handler
+ */
+
+static VALUE
+weechat_ruby_remove_keyboard_handler (VALUE class, VALUE function)
+{
+ char *c_function;
+
+ /* make gcc happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: unable to remove keyboard handler, "
+ "script not initialized");
+ return INT2FIX (0);
+ }
+
+ c_function = NULL;
+
+ if (NIL_P (function))
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: wrong parameters for "
+ "\"remove_keyboard_handler\" function");
+ return INT2FIX (0);
+ }
+
+ Check_Type (function, T_STRING);
+
+ c_function = STR2CSTR (function);
+
+ weechat_script_remove_keyboard_handler (ruby_plugin, ruby_current_script,
+ c_function);
+
+ return INT2FIX (1);
+}
+
+/*
* weechat_ruby_get_info: get various infos
*/
@@ -1485,7 +1624,7 @@ weechat_ruby_unload (t_weechat_plugin *plugin, t_plugin_script *script)
script->name);
if (script->shutdown_func[0])
- weechat_ruby_exec (plugin, script, script->shutdown_func, "", "");
+ weechat_ruby_exec (plugin, script, script->shutdown_func, "", "", "");
if (script->interpreter)
rb_gc_unregister_address (script->interpreter);
@@ -1541,7 +1680,7 @@ weechat_ruby_unload_all (t_weechat_plugin *plugin)
int
weechat_ruby_cmd (t_weechat_plugin *plugin,
- char *server, char *command, char *arguments,
+ int cmd_argc, char **cmd_argv,
char *handler_args, void *handler_pointer)
{
int argc, handler_found;
@@ -1550,13 +1689,14 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
t_plugin_handler *ptr_handler;
/* make gcc happy */
- (void) server;
- (void) command;
(void) handler_args;
(void) handler_pointer;
- if (arguments)
- argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
+ if (cmd_argc < 3)
+ return PLUGIN_RC_KO;
+
+ if (cmd_argv[2])
+ argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
else
{
argv = NULL;
@@ -1640,6 +1780,24 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
}
if (!handler_found)
plugin->print_server (plugin, " (none)");
+
+ /* list Ruby keyboard handlers */
+ plugin->print_server (plugin, "");
+ plugin->print_server (plugin, "Ruby keyboard handlers:");
+ handler_found = 0;
+ for (ptr_handler = plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
+ {
+ if ((ptr_handler->type == HANDLER_KEYBOARD)
+ && (ptr_handler->handler_args))
+ {
+ handler_found = 1;
+ plugin->print_server (plugin, " Ruby(%s)",
+ ptr_handler->handler_args);
+ }
+ }
+ if (!handler_found)
+ plugin->print_server (plugin, " (none)");
break;
case 1:
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
@@ -1681,7 +1839,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
if (argv)
plugin->free_exploded_string (plugin, argv);
- return 1;
+ return PLUGIN_RC_OK;
}
/*
@@ -1758,8 +1916,10 @@ weechat_plugin_init (t_weechat_plugin *plugin)
rb_define_module_function (mWeechat, "add_message_handler", weechat_ruby_add_message_handler, 2);
rb_define_module_function (mWeechat, "add_command_handler", weechat_ruby_add_command_handler, -1);
rb_define_module_function (mWeechat, "add_timer_handler", weechat_ruby_add_timer_handler, 2);
+ rb_define_module_function (mWeechat, "add_keyboard_handler", weechat_ruby_add_keyboard_handler, 1);
rb_define_module_function (mWeechat, "remove_handler", weechat_ruby_remove_handler, 2);
rb_define_module_function (mWeechat, "remove_timer_handler", weechat_ruby_remove_timer_handler, 1);
+ rb_define_module_function (mWeechat, "remove_keyboard_handler", weechat_ruby_remove_keyboard_handler, 1);
rb_define_module_function (mWeechat, "get_info", weechat_ruby_get_info, -1);
rb_define_module_function (mWeechat, "get_dcc_info", weechat_ruby_get_dcc_info, 0);
rb_define_module_function (mWeechat, "get_config", weechat_ruby_get_config, 1);
diff --git a/src/plugins/scripts/weechat-script.c b/src/plugins/scripts/weechat-script.c
index f95809426..419b10adb 100644
--- a/src/plugins/scripts/weechat-script.c
+++ b/src/plugins/scripts/weechat-script.c
@@ -317,7 +317,36 @@ weechat_script_remove_timer_handler (t_weechat_plugin *plugin,
ptr_handler = plugin->handlers;
while (ptr_handler)
{
- if (((t_plugin_script *)ptr_handler->handler_pointer == script)
+ if ((ptr_handler->type == HANDLER_TIMER)
+ && ((t_plugin_script *)ptr_handler->handler_pointer == script)
+ && (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
+ {
+ next_handler = ptr_handler->next_handler;
+ plugin->handler_remove (plugin, ptr_handler);
+ ptr_handler = next_handler;
+ }
+ else
+ ptr_handler = ptr_handler->next_handler;
+ }
+}
+
+/*
+ * weechat_script_remove_keyboard_handler: remove a keyboard handler for a script
+ */
+
+void
+weechat_script_remove_keyboard_handler (t_weechat_plugin *plugin,
+ t_plugin_script *script,
+ char *function)
+{
+ t_plugin_handler *ptr_handler, *next_handler;
+
+ /* search and remove keyboard handlers */
+ ptr_handler = plugin->handlers;
+ while (ptr_handler)
+ {
+ if ((ptr_handler->type == HANDLER_KEYBOARD)
+ && ((t_plugin_script *)ptr_handler->handler_pointer == script)
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
{
next_handler = ptr_handler->next_handler;
diff --git a/src/plugins/scripts/weechat-script.h b/src/plugins/scripts/weechat-script.h
index 007bc8713..922eaab7f 100644
--- a/src/plugins/scripts/weechat-script.h
+++ b/src/plugins/scripts/weechat-script.h
@@ -56,6 +56,9 @@ extern void weechat_script_remove_handler (t_weechat_plugin *,
extern void weechat_script_remove_timer_handler (t_weechat_plugin *,
t_plugin_script *,
char *);
+extern void weechat_script_remove_keyboard_handler (t_weechat_plugin *,
+ t_plugin_script *,
+ char *);
extern char *weechat_script_get_plugin_config (t_weechat_plugin *,
t_plugin_script *,
char *);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 57c01644c..107baf206 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -125,7 +125,7 @@ struct t_plugin_nick_info
typedef struct t_weechat_plugin t_weechat_plugin;
-typedef int (t_plugin_handler_func) (t_weechat_plugin *, char *, char *, char *, char *, void *);
+typedef int (t_plugin_handler_func) (t_weechat_plugin *, int, char **, char *, void *);
/* handlers */
@@ -135,7 +135,8 @@ enum t_handler_type
{
HANDLER_MESSAGE = 0, /* IRC message handler */
HANDLER_COMMAND, /* command handler */
- HANDLER_TIMER /* timer handler */
+ HANDLER_TIMER, /* timer handler */
+ HANDLER_KEYBOARD /* keyboard handler */
};
typedef struct t_plugin_handler t_plugin_handler;
@@ -219,6 +220,9 @@ struct t_weechat_plugin
t_plugin_handler *(*timer_handler_add) (t_weechat_plugin *, int,
t_plugin_handler_func *,
char *, void *);
+ t_plugin_handler *(*keyboard_handler_add) (t_weechat_plugin *,
+ t_plugin_handler_func *,
+ char *, void *);
void (*handler_remove) (t_weechat_plugin *, t_plugin_handler *);
void (*handler_remove_all) (t_weechat_plugin *);
@@ -239,6 +243,8 @@ struct t_weechat_plugin
void (*log) (t_weechat_plugin *, char *, char *, char *, ...);
+ void (*input_color) (t_weechat_plugin *, int, int, int);
+
/* WeeChat developers: ALWAYS add new functions at the end */
};
@@ -272,6 +278,9 @@ extern t_plugin_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, cha
extern t_plugin_handler *weechat_plugin_timer_handler_add (t_weechat_plugin *, int,
t_plugin_handler_func *,
char *, void *);
+extern t_plugin_handler *weechat_plugin_keyboard_handler_add (t_weechat_plugin *,
+ t_plugin_handler_func *,
+ char *, void *);
extern void weechat_plugin_handler_remove (t_weechat_plugin *, t_plugin_handler *);
extern void weechat_plugin_handler_remove_all (t_weechat_plugin *);
@@ -290,5 +299,6 @@ extern t_plugin_channel_info *weechat_plugin_get_channel_info (t_weechat_plugin
extern void weechat_plugin_free_channel_info (t_weechat_plugin *, t_plugin_channel_info *);
extern t_plugin_nick_info *weechat_plugin_get_nick_info (t_weechat_plugin *, char *, char *);
extern void weechat_plugin_free_nick_info (t_weechat_plugin *, t_plugin_nick_info *);
+extern void weechat_plugin_input_color (t_weechat_plugin *, int, int, int);
#endif /* weechat-plugin.h */