summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-01-10 18:37:31 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-01-10 18:37:31 +0100
commit8a6729991214cbf02fe200940d7e0a5e39c90efc (patch)
tree39b6de492fc370d5236140de9e9fe44acfe55874 /src/plugins
parent938574feecf59ddd7df90e7266593dba5ac0e1c0 (diff)
downloadweechat-8a6729991214cbf02fe200940d7e0a5e39c90efc.zip
Added some missing functions in Perl plugin API
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/demo/demo.c16
-rw-r--r--src/plugins/irc/irc-channel.c2
-rw-r--r--src/plugins/irc/irc-input.c17
-rw-r--r--src/plugins/irc/irc-input.h3
-rw-r--r--src/plugins/irc/irc-server.c3
-rw-r--r--src/plugins/scripts/Makefile.am6
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c864
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c62
-rw-r--r--src/plugins/scripts/script-api.c574
-rw-r--r--src/plugins/scripts/script-api.h116
-rw-r--r--src/plugins/scripts/script-callback.c107
-rw-r--r--src/plugins/scripts/script-callback.h41
-rw-r--r--src/plugins/scripts/script.c607
-rw-r--r--src/plugins/scripts/script.h135
-rw-r--r--src/plugins/weechat-plugin.h11
15 files changed, 1678 insertions, 886 deletions
diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c
index fb99f86b1..9df0bc912 100644
--- a/src/plugins/demo/demo.c
+++ b/src/plugins/demo/demo.c
@@ -107,10 +107,17 @@ demo_infobar_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
* demo_buffer_input_data_cb: callback for input data on buffer
*/
-void
-demo_buffer_input_data_cb (struct t_gui_buffer *buffer, char *data)
+int
+demo_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer,
+ char *input_data)
{
- weechat_printf (buffer, "buffer input_data_cb: data = '%s'", data);
+ /* make C compiler happy */
+ (void) data;
+
+ weechat_printf (buffer,
+ "buffer input_data_cb: input_data = '%s'", input_data);
+
+ return WEECHAT_RC_OK;
}
/*
@@ -131,7 +138,8 @@ demo_buffer_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
if (argc > 2)
{
new_buffer = weechat_buffer_new (argv[1], argv[2],
- demo_buffer_input_data_cb);
+ &demo_buffer_input_data_cb,
+ NULL);
if (new_buffer)
weechat_buffer_set (new_buffer, "display", "1");
weechat_hook_signal_send ("logger_backlog",
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index b75e9102a..bfb825854 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -60,7 +60,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
/* create buffer for channel */
new_buffer = weechat_buffer_new (server->name, channel_name,
- &irc_input_data);
+ &irc_input_data, NULL);
if (!new_buffer)
{
free (new_channel);
diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c
index 72e37a6f6..fc0b6a450 100644
--- a/src/plugins/irc/irc-input.c
+++ b/src/plugins/irc/irc-input.c
@@ -151,16 +151,19 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, char *text)
* PROTOCOL_RC_KO if error
*/
-void
-irc_input_data (struct t_gui_buffer *buffer, char *data)
+int
+irc_input_data (void *data, struct t_gui_buffer *buffer, char *input_data)
{
char *data_with_colors;
+ /* make C compiler happy */
+ (void) data;
+
IRC_GET_SERVER_CHANNEL(buffer);
if (ptr_channel)
{
- data_with_colors = (char *)irc_color_encode ((unsigned char *)data,
+ data_with_colors = (char *)irc_color_encode ((unsigned char *)input_data,
weechat_config_boolean (irc_config_irc_colors_send));
if (ptr_channel->dcc_chat)
@@ -175,15 +178,15 @@ irc_input_data (struct t_gui_buffer *buffer, char *data)
{
//irc_dcc_chat_sendf (ptr_channel->dcc_chat,
// "%s\r\n",
- // (data_with_colors) ? data_with_colors : data);
+ // (data_with_colors) ? data_with_colors : input_data);
//irc_input_user_message_display (buffer,
// (data_with_colors) ?
- // data_with_colors : data);
+ // data_with_colors : input_data);
}
}
else
irc_input_send_user_message (buffer,
- (data_with_colors) ? data_with_colors : data);
+ (data_with_colors) ? data_with_colors : input_data);
if (data_with_colors)
free (data_with_colors);
@@ -194,4 +197,6 @@ irc_input_data (struct t_gui_buffer *buffer, char *data)
_("%s: this buffer is not a channel!"),
"irc");
}
+
+ return WEECHAT_RC_OK;
}
diff --git a/src/plugins/irc/irc-input.h b/src/plugins/irc/irc-input.h
index 8fefc8da7..f7efa95a8 100644
--- a/src/plugins/irc/irc-input.h
+++ b/src/plugins/irc/irc-input.h
@@ -20,6 +20,7 @@
#ifndef __WEECHAT_IRC_INPUT_H
#define __WEECHAT_IRC_INPUT_H 1
-extern void irc_input_data (struct t_gui_buffer *buffer, char *data);
+extern int irc_input_data (void *data, struct t_gui_buffer *buffer,
+ char *input_data);
#endif /* irc-input.h */
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 953e650f7..3c8c9297c 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -2184,7 +2184,8 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
if (!server->buffer)
{
- server->buffer = weechat_buffer_new (server->name, server->name, NULL);
+ server->buffer = weechat_buffer_new (server->name, server->name,
+ NULL, NULL);
if (!server->buffer)
return 0;
weechat_buffer_set (server->buffer, "display", "1");
diff --git a/src/plugins/scripts/Makefile.am b/src/plugins/scripts/Makefile.am
index 0a2e4367f..f04b97d59 100644
--- a/src/plugins/scripts/Makefile.am
+++ b/src/plugins/scripts/Makefile.am
@@ -19,7 +19,11 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
noinst_LTLIBRARIES = lib_weechat_plugins_scripts.la
lib_weechat_plugins_scripts_la_SOURCES = script.c \
- script.h
+ script.h \
+ script-callback.c \
+ script-callback.h \
+ script-api.c \
+ script-api.h
if PLUGIN_PERL
perl_dir = perl
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 4ccbe7dbf..14a0188f3 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -30,6 +30,8 @@
#include "../../weechat-plugin.h"
#include "../script.h"
+#include "../script-api.h"
+#include "../script-callback.h"
#include "weechat-perl.h"
@@ -53,7 +55,7 @@ static XS (XS_weechat_register)
if ((items < 4) || (items > 5))
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "register");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "register");
XSRETURN_NO;
}
@@ -63,30 +65,30 @@ static XS (XS_weechat_register)
description = SvPV (ST (3), PL_na);
charset = (items == 5) ? SvPV (ST (4), PL_na) : NULL;
- if (weechat_script_search (weechat_perl_plugin, &perl_scripts, name))
+ if (script_search (weechat_perl_plugin, &perl_scripts, name))
{
/* error: another script already exists with this name! */
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to register script "
"\"%s\" (another script already "
"exists with this name)"),
- weechat_prefix ("error"), "perl", name);
+ weechat_prefix ("error"), "Perl", name);
XSRETURN_NO;
}
/* register script */
- perl_current_script = weechat_script_add (weechat_perl_plugin,
- &perl_scripts,
- (perl_current_script_filename) ?
- perl_current_script_filename : "",
- name, version, shutdown_func,
- description, charset);
+ perl_current_script = script_add (weechat_perl_plugin,
+ &perl_scripts,
+ (perl_current_script_filename) ?
+ perl_current_script_filename : "",
+ name, version, shutdown_func,
+ description, charset);
if (perl_current_script)
{
weechat_printf (NULL,
weechat_gettext ("%s%s: registered script \"%s\", "
"version %s (%s)"),
- weechat_prefix ("info"), "perl",
+ weechat_prefix ("info"), "Perl",
name, version, description);
}
else
@@ -110,18 +112,18 @@ static XS (XS_weechat_charset_set)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "charset_set");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "charset_set");
XSRETURN_NO;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "charset_set");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "charset_set");
XSRETURN_NO;
}
- weechat_script_charset_set (perl_current_script,
- SvPV (ST (0), PL_na));
+ script_api_charset_set (perl_current_script,
+ SvPV (ST (0), PL_na));
XSRETURN_YES;
}
@@ -140,13 +142,13 @@ static XS (XS_weechat_iconv_to_internal)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "iconv_to_internal");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "iconv_to_internal");
XSRETURN_EMPTY;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "iconv_to_internal");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "iconv_to_internal");
XSRETURN_EMPTY;
}
@@ -188,13 +190,13 @@ static XS (XS_weechat_iconv_from_internal)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "iconv_from_internal");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "iconv_from_internal");
XSRETURN_EMPTY;
}
if (items < 2)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "iconv_from_internal");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "iconv_from_internal");
XSRETURN_EMPTY;
}
@@ -226,13 +228,13 @@ static XS (XS_weechat_mkdir_home)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "mkdir_home");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "mkdir_home");
XSRETURN_NO;
}
if (items < 2)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "mkdir_home");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "mkdir_home");
XSRETURN_NO;
}
@@ -254,18 +256,19 @@ static XS (XS_weechat_mkdir)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "mkdir");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "mkdir");
XSRETURN_NO;
}
if (items < 2)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "mkdir");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "mkdir");
XSRETURN_NO;
}
weechat_mkdir (SvPV (ST (0), PL_na), /* directory */
SvIV (ST (1))); /* mode */
+
XSRETURN_YES;
}
@@ -283,13 +286,13 @@ static XS (XS_weechat_prefix)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "prefix");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "prefix");
XSRETURN_EMPTY;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "prefix");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "prefix");
XSRETURN_EMPTY;
}
@@ -318,13 +321,13 @@ static XS (XS_weechat_color)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "color");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "color");
XSRETURN_EMPTY;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "color");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "color");
XSRETURN_EMPTY;
}
@@ -353,13 +356,13 @@ static XS (XS_weechat_print)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "print");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "print");
XSRETURN_NO;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "print");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "print");
XSRETURN_NO;
}
@@ -374,9 +377,9 @@ static XS (XS_weechat_print)
message = SvPV (ST (0), PL_na);
}
- weechat_script_printf (weechat_perl_plugin, perl_current_script,
- weechat_script_string_to_pointer (buffer),
- "%s", message);
+ script_api_printf (weechat_perl_plugin, perl_current_script,
+ script_string_to_pointer (buffer),
+ "%s", message);
XSRETURN_YES;
}
@@ -394,20 +397,21 @@ static XS (XS_weechat_infobar_print)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "infobar_print");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "infobar_print");
XSRETURN_NO;
}
if (items < 3)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "infobar_print");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "infobar_print");
XSRETURN_NO;
}
- weechat_script_infobar_printf (weechat_perl_plugin, perl_current_script,
- SvIV (ST (0)),
- SvPV (ST (1), PL_na),
- "%s", SvPV (ST (1), PL_na));
+ script_api_infobar_printf (weechat_perl_plugin, perl_current_script,
+ SvIV (ST (0)), /* delay */
+ SvPV (ST (1), PL_na), /* color */
+ "%s",
+ SvPV (ST (1), PL_na)); /* message */
XSRETURN_YES;
}
@@ -425,7 +429,7 @@ static XS (XS_weechat_infobar_remove)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "infobar_remove");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "infobar_remove");
XSRETURN_NO;
}
@@ -447,18 +451,18 @@ static XS (XS_weechat_log_print)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "log_print");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "log_print");
XSRETURN_NO;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "log_print");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "log_print");
XSRETURN_NO;
}
- weechat_script_log_printf (weechat_perl_plugin, perl_current_script,
- "%s", SvPV (ST (0), PL_na));
+ script_api_log_printf (weechat_perl_plugin, perl_current_script,
+ "%s", SvPV (ST (0), PL_na));
XSRETURN_YES;
}
@@ -471,16 +475,16 @@ int
weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[3];
int *r, ret;
/* make C compiler happy */
(void) argv;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
- perl_argv[0] = weechat_script_pointer_to_string (buffer);
+ perl_argv[0] = script_pointer_to_string (buffer);
if (argc > 1)
{
perl_argv[1] = argv_eol[1];
@@ -490,9 +494,9 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
{
perl_argv[1] = NULL;
}
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -503,6 +507,7 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
}
if (perl_argv[0])
free (perl_argv[0]);
+
return ret;
}
@@ -519,25 +524,25 @@ static XS (XS_weechat_hook_command)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_command");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_command");
XSRETURN_NO;
}
if (items < 6)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_command");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_command");
XSRETURN_NO;
}
- if (weechat_script_hook_command (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* command */
- SvPV (ST (1), PL_na), /* description */
- SvPV (ST (2), PL_na), /* args */
- SvPV (ST (3), PL_na), /* args_description */
- SvPV (ST (4), PL_na), /* completion */
- weechat_perl_api_hook_command_cb,
- SvPV (ST (5), PL_na)))
+ if (script_api_hook_command (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* command */
+ SvPV (ST (1), PL_na), /* description */
+ SvPV (ST (2), PL_na), /* args */
+ SvPV (ST (3), PL_na), /* args_description */
+ SvPV (ST (4), PL_na), /* completion */
+ &weechat_perl_api_hook_command_cb,
+ SvPV (ST (5), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -550,15 +555,15 @@ static XS (XS_weechat_hook_command)
int
weechat_perl_api_hook_timer_cb (void *data)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[1] = { NULL };
int *r, ret;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -567,6 +572,7 @@ weechat_perl_api_hook_timer_cb (void *data)
ret = *r;
free (r);
}
+
return ret;
}
@@ -583,23 +589,23 @@ static XS (XS_weechat_hook_timer)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_timer");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_timer");
XSRETURN_NO;
}
if (items < 4)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_timer");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_timer");
XSRETURN_NO;
}
- if (weechat_script_hook_timer (weechat_perl_plugin,
- perl_current_script,
- SvIV (ST (0)), /* interval */
- SvIV (ST (1)), /* align_second */
- SvIV (ST (2)), /* max_calls */
- weechat_perl_api_hook_timer_cb,
- SvPV (ST (3), PL_na)))
+ if (script_api_hook_timer (weechat_perl_plugin,
+ perl_current_script,
+ SvIV (ST (0)), /* interval */
+ SvIV (ST (1)), /* align_second */
+ SvIV (ST (2)), /* max_calls */
+ &weechat_perl_api_hook_timer_cb,
+ SvPV (ST (3), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -612,16 +618,16 @@ static XS (XS_weechat_hook_timer)
int
weechat_perl_api_hook_fd_cb (void *data)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[1] = { NULL };
int *r;
int ret;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -630,6 +636,7 @@ weechat_perl_api_hook_fd_cb (void *data)
ret = *r;
free (r);
}
+
return ret;
}
@@ -646,24 +653,24 @@ static XS (XS_weechat_hook_fd)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_fd");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_fd");
XSRETURN_NO;
}
if (items < 5)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_fd");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_fd");
XSRETURN_NO;
}
- if (weechat_script_hook_fd (weechat_perl_plugin,
- perl_current_script,
- SvIV (ST (0)), /* fd */
- SvIV (ST (1)), /* read */
- SvIV (ST (2)), /* write */
- SvIV (ST (3)), /* exception */
- weechat_perl_api_hook_fd_cb,
- SvPV (ST (4), PL_na)))
+ if (script_api_hook_fd (weechat_perl_plugin,
+ perl_current_script,
+ SvIV (ST (0)), /* fd */
+ SvIV (ST (1)), /* read */
+ SvIV (ST (2)), /* write */
+ SvIV (ST (3)), /* exception */
+ &weechat_perl_api_hook_fd_cb,
+ SvPV (ST (4), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -677,24 +684,24 @@ int
weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
time_t date, char *prefix, char *message)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[5];
static char timebuffer[64];
int *r, ret;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
- perl_argv[0] = weechat_script_pointer_to_string (buffer);
+ perl_argv[0] = script_pointer_to_string (buffer);
perl_argv[1] = timebuffer;
perl_argv[2] = prefix;
perl_argv[3] = message;
perl_argv[4] = NULL;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -705,6 +712,7 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
}
if (perl_argv[0])
free (perl_argv[0]);
+
return ret;
}
@@ -721,23 +729,23 @@ static XS (XS_weechat_hook_print)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_print");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_print");
XSRETURN_NO;
}
if (items < 4)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_print");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_print");
XSRETURN_NO;
}
- if (weechat_script_hook_print (weechat_perl_plugin,
- perl_current_script,
- weechat_script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- SvPV (ST (1), PL_na), /* message */
- SvIV (ST (2)), /* strip_colors */
- weechat_perl_api_hook_print_cb,
- SvPV (ST (3), PL_na)))
+ if (script_api_hook_print (weechat_perl_plugin,
+ perl_current_script,
+ script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ SvPV (ST (1), PL_na), /* message */
+ SvIV (ST (2)), /* strip_colors */
+ &weechat_perl_api_hook_print_cb,
+ SvPV (ST (3), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -751,12 +759,12 @@ int
weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
void *signal_data)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[3];
static char value_str[64];
int *r, ret, free_needed;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
perl_argv[0] = signal;
free_needed = 0;
@@ -772,16 +780,16 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
- perl_argv[1] = weechat_script_pointer_to_string (signal_data);
+ perl_argv[1] = script_pointer_to_string (signal_data);
free_needed = 1;
}
else
perl_argv[1] = NULL;
perl_argv[2] = NULL;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -792,6 +800,7 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
if (free_needed && perl_argv[1])
free (perl_argv[1]);
+
return ret;
}
@@ -808,27 +817,57 @@ static XS (XS_weechat_hook_signal)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_signal");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_signal");
XSRETURN_NO;
}
if (items < 2)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_signal");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_signal");
XSRETURN_NO;
}
- if (weechat_script_hook_signal (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* signal */
- weechat_perl_api_hook_signal_cb,
- SvPV (ST (1), PL_na)))
+ if (script_api_hook_signal (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* signal */
+ &weechat_perl_api_hook_signal_cb,
+ SvPV (ST (1), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
}
/*
+ * weechat::hook_signal_send: send a signal
+ */
+
+static XS (XS_weechat_hook_signal_send)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_signal_send");
+ XSRETURN_NO;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_signal_send");
+ XSRETURN_NO;
+ }
+
+ weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */
+ SvPV (ST (1), PL_na), /* type_data */
+ SvPV (ST (2), PL_na)); /* signal_data */
+
+ XSRETURN_YES;
+}
+
+/*
* weechat_perl_api_hook_config_cb: callback for config option hooked
*/
@@ -836,20 +875,20 @@ int
weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
char *value)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[4];
int *r, ret;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
perl_argv[0] = type;
perl_argv[1] = option;
perl_argv[2] = value;
perl_argv[3] = NULL;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -858,6 +897,7 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
ret = *r;
free (r);
}
+
return ret;
}
@@ -874,22 +914,22 @@ static XS (XS_weechat_hook_config)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_config");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_config");
XSRETURN_NO;
}
if (items < 3)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_config");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_config");
XSRETURN_NO;
}
- if (weechat_script_hook_config (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* type */
- SvPV (ST (1), PL_na), /* option */
- weechat_perl_api_hook_config_cb,
- SvPV (ST (2), PL_na)))
+ if (script_api_hook_config (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* type */
+ SvPV (ST (1), PL_na), /* option */
+ &weechat_perl_api_hook_config_cb,
+ SvPV (ST (2), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -904,20 +944,20 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
struct t_gui_buffer *buffer,
struct t_weelist *list)
{
- struct t_script_hook *script_hook;
+ struct t_script_callback *script_callback;
char *perl_argv[4];
int *r, ret;
- script_hook = (struct t_script_hook *)data;
+ script_callback = (struct t_script_callback *)data;
perl_argv[0] = completion;
- perl_argv[1] = weechat_script_pointer_to_string (buffer);
- perl_argv[2] = weechat_script_pointer_to_string (list);
+ perl_argv[1] = script_pointer_to_string (buffer);
+ perl_argv[2] = script_pointer_to_string (list);
perl_argv[3] = NULL;
- r = (int *) weechat_perl_exec (script_hook->script,
+ r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
- script_hook->function,
+ script_callback->function,
perl_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
@@ -930,6 +970,7 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
free (perl_argv[1]);
if (perl_argv[2])
free (perl_argv[2]);
+
return ret;
}
@@ -946,21 +987,21 @@ static XS (XS_weechat_hook_completion)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "hook_completion");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "hook_completion");
XSRETURN_NO;
}
if (items < 2)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "hook_completion");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "hook_completion");
XSRETURN_NO;
}
- if (weechat_script_hook_completion (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* completion */
- weechat_perl_api_hook_completion_cb,
- SvPV (ST (1), PL_na)))
+ if (script_api_hook_completion (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* completion */
+ &weechat_perl_api_hook_completion_cb,
+ SvPV (ST (1), PL_na))) /* perl function */
XSRETURN_YES;
XSRETURN_NO;
@@ -979,18 +1020,519 @@ static XS (XS_weechat_unhook)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "unhook");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "unhook");
XSRETURN_NO;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "unhook");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "unhook");
+ XSRETURN_NO;
+ }
+
+ script_api_unhook (weechat_perl_plugin, perl_current_script,
+ script_string_to_pointer (SvPV (ST (0), PL_na)));
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat::unhook_all: unhook all for script
+ */
+
+static XS (XS_weechat_unhook_all)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+ (void) items;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "unhook_all");
+ XSRETURN_NO;
+ }
+
+ script_api_unhook_all (weechat_perl_plugin, perl_current_script);
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat_perl_api_input_data_cb: callback for input data in a buffer
+ */
+
+int
+weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
+ char *input_data)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[3];
+ int *r, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ perl_argv[0] = script_pointer_to_string (buffer);
+ perl_argv[1] = input_data;
+ perl_argv[2] = NULL;
+
+ r = (int *) weechat_perl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ perl_argv);
+ if (!r)
+ ret = WEECHAT_RC_ERROR;
+ else
+ {
+ ret = *r;
+ free (r);
+ }
+ if (perl_argv[0])
+ free (perl_argv[0]);
+
+ return ret;
+}
+
+/*
+ * weechat::buffer_new: create a new buffer
+ */
+
+static XS (XS_weechat_buffer_new)
+{
+ struct t_gui_buffer *new_buffer;
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "buffer_new");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "buffer_new");
+ XSRETURN_EMPTY;
+ }
+
+ new_buffer = script_api_buffer_new (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* category */
+ SvPV (ST (1), PL_na), /* name */
+ &weechat_perl_api_input_data_cb,
+ SvPV (ST (2), PL_na)); /* perl function */
+
+ result = script_pointer_to_string (new_buffer);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::buffer_search: search a buffer
+ */
+
+static XS (XS_weechat_buffer_search)
+{
+ struct t_gui_buffer *ptr_buffer;
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "buffer_search");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "buffer_search");
+ XSRETURN_EMPTY;
+ }
+
+ ptr_buffer = weechat_buffer_search (SvPV (ST (0), PL_na), /* category */
+ SvPV (ST (1), PL_na)); /* name */
+
+ result = script_pointer_to_string (ptr_buffer);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::buffer_close: close a buffer
+ */
+
+static XS (XS_weechat_buffer_close)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "buffer_close");
+ XSRETURN_NO;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "buffer_close");
+ XSRETURN_NO;
+ }
+
+ script_api_buffer_close (weechat_perl_plugin,
+ perl_current_script,
+ script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ SvIV (ST (1))); /* switch_to_another */
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat::buffer_get: get a buffer property
+ */
+
+static XS (XS_weechat_buffer_get)
+{
+ char *value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "buffer_get");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "buffer_get");
+ XSRETURN_EMPTY;
+ }
+
+ value = weechat_buffer_get (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ SvPV (ST (1), PL_na)); /* property */
+ if (value)
+ {
+ XST_mPV (0, value);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::buffer_set: set a buffer property
+ */
+
+static XS (XS_weechat_buffer_set)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "buffer_set");
+ XSRETURN_NO;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "buffer_set");
+ XSRETURN_NO;
+ }
+
+ weechat_buffer_set (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ SvPV (ST (1), PL_na), /* property */
+ SvPV (ST (2), PL_na)); /* value */
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat::nicklist_add_group: add a group in nicklist
+ */
+
+static XS (XS_weechat_nicklist_add_group)
+{
+ struct t_gui_nick_group *new_group;
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_add_group");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 5)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_add_group");
+ XSRETURN_EMPTY;
+ }
+
+ new_group = weechat_nicklist_add_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na)), /* parent_group */
+ SvPV (ST (2), PL_na), /* name */
+ SvPV (ST (3), PL_na), /* color */
+ SvIV (ST (4))); /* visible */
+
+ result = script_pointer_to_string (new_group);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::nicklist_search_group: search a group in nicklist
+ */
+
+static XS (XS_weechat_nicklist_search_group)
+{
+ struct t_gui_nick_group *ptr_group;
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_search_group");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_search_group");
+ XSRETURN_EMPTY;
+ }
+
+ ptr_group = weechat_nicklist_search_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na)), /* from_group */
+ SvPV (ST (2), PL_na)); /* name */
+
+ result = script_pointer_to_string (ptr_group);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::nicklist_add_nick: add a nick in nicklist
+ */
+
+static XS (XS_weechat_nicklist_add_nick)
+{
+ struct t_gui_nick *new_nick;
+ char *str_prefix, prefix, *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_add_nick");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 7)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_add_nick");
+ XSRETURN_EMPTY;
+ }
+
+ str_prefix = SvPV(ST (4), PL_na);
+ if (str_prefix && str_prefix[0])
+ prefix = str_prefix[0];
+ else
+ prefix = ' ';
+ new_nick = weechat_nicklist_add_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na)), /* group */
+ SvPV (ST (2), PL_na), /* name */
+ SvPV (ST (3), PL_na), /* color */
+ prefix,
+ SvPV (ST (5), PL_na), /* prefix_color */
+ SvIV (ST (6))); /* visible */
+
+ result = script_pointer_to_string (new_nick);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::nicklist_search_nick: search a nick in nicklist
+ */
+
+static XS (XS_weechat_nicklist_search_nick)
+{
+ struct t_gui_nick *ptr_nick;
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_search_nick");
+ XSRETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_search_nick");
+ XSRETURN_EMPTY;
+ }
+
+ ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na)), /* from_group */
+ SvPV (ST (2), PL_na)); /* name */
+
+ result = script_pointer_to_string (ptr_nick);
+ if (result)
+ {
+ XST_mPV (0, result);
+ free (result);
+ XSRETURN (1);
+ }
+
+ XST_mPV (0, "");
+ XSRETURN (1);
+}
+
+/*
+ * weechat::nicklist_remove_group: remove a group from nicklist
+ */
+
+static XS (XS_weechat_nicklist_remove_group)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_remove_group");
+ XSRETURN_NO;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_remove_group");
+ XSRETURN_NO;
+ }
+
+ weechat_nicklist_remove_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na))); /* group */
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat::nicklist_remove_nick: remove a nick from nicklist
+ */
+
+static XS (XS_weechat_nicklist_remove_nick)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_remove_nick");
+ XSRETURN_NO;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_remove_nick");
+ XSRETURN_NO;
+ }
+
+ weechat_nicklist_remove_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_string_to_pointer (SvPV (ST (1), PL_na))); /* nick */
+
+ XSRETURN_YES;
+}
+
+/*
+ * weechat::nicklist_remove_all: remove all groups/nicks from nicklist
+ */
+
+static XS (XS_weechat_nicklist_remove_all)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "nicklist_remove_all");
+ XSRETURN_NO;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "nicklist_remove_all");
XSRETURN_NO;
}
- weechat_script_unhook (weechat_perl_plugin, perl_current_script,
- weechat_script_string_to_pointer (SvPV (ST (0), PL_na)));
+ weechat_nicklist_remove_all (script_string_to_pointer (SvPV (ST (0), PL_na))); /* buffer */
+
XSRETURN_YES;
}
@@ -1008,13 +1550,13 @@ static XS (XS_weechat_command)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "command");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "command");
XSRETURN_NO;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "command");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "command");
XSRETURN_NO;
}
@@ -1029,9 +1571,9 @@ static XS (XS_weechat_command)
command = SvPV (ST (0), PL_na);
}
- weechat_script_command (weechat_perl_plugin, perl_current_script,
- weechat_script_string_to_pointer (buffer),
- command);
+ script_api_command (weechat_perl_plugin, perl_current_script,
+ script_string_to_pointer (buffer),
+ command);
XSRETURN_YES;
}
@@ -1050,13 +1592,13 @@ static XS (XS_weechat_info_get)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "info_get");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "info_get");
XSRETURN_EMPTY;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "info_get");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "info_get");
XSRETURN_EMPTY;
}
@@ -1155,13 +1697,13 @@ static XS (XS_weechat_config_get_weechat)
if (!perl_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("perl", "config_get_weechat");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("Perl", "config_get_weechat");
XSRETURN_EMPTY;
}
if (items < 1)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("perl", "config_get_weechat");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("Perl", "config_get_weechat");
XSRETURN_EMPTY;
}
@@ -1835,9 +2377,23 @@ weechat_perl_xs_init (pTHX)
newXS ("weechat::hook_fd", XS_weechat_hook_fd, "weechat");
newXS ("weechat::hook_print", XS_weechat_hook_print, "weechat");
newXS ("weechat::hook_signal", XS_weechat_hook_signal, "weechat");
+ newXS ("weechat::hook_signal_send", XS_weechat_hook_signal_send, "weechat");
newXS ("weechat::hook_config", XS_weechat_hook_config, "weechat");
newXS ("weechat::hook_completion", XS_weechat_hook_completion, "weechat");
newXS ("weechat::unhook", XS_weechat_unhook, "weechat");
+ newXS ("weechat::unhook_all", XS_weechat_unhook_all, "weechat");
+ newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat");
+ newXS ("weechat::buffer_search", XS_weechat_buffer_search, "weechat");
+ newXS ("weechat::buffer_close", XS_weechat_buffer_close, "weechat");
+ newXS ("weechat::buffer_get", XS_weechat_buffer_get, "weechat");
+ newXS ("weechat::buffer_set", XS_weechat_buffer_set, "weechat");
+ newXS ("weechat::nicklist_add_group", XS_weechat_nicklist_add_group, "weechat");
+ newXS ("weechat::nicklist_search_group", XS_weechat_nicklist_search_group, "weechat");
+ newXS ("weechat::nicklist_add_nick", XS_weechat_nicklist_add_nick, "weechat");
+ newXS ("weechat::nicklist_search_nick", XS_weechat_nicklist_search_nick, "weechat");
+ newXS ("weechat::nicklist_remove_group", XS_weechat_nicklist_remove_group, "weechat");
+ newXS ("weechat::nicklist_remove_nick", XS_weechat_nicklist_remove_nick, "weechat");
+ newXS ("weechat::nicklist_remove_all", XS_weechat_nicklist_remove_all, "weechat");
newXS ("weechat::command", XS_weechat_command, "weechat");
newXS ("weechat::info_get", XS_weechat_info_get, "weechat");
//newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
@@ -1862,4 +2418,14 @@ weechat_perl_xs_init (pTHX)
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_PLUGINS", newSViv (WEECHAT_RC_OK_IGNORE_PLUGINS));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_ALL", newSViv (WEECHAT_RC_OK_IGNORE_ALL));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_WITH_HIGHLIGHT", newSViv (WEECHAT_RC_OK_WITH_HIGHLIGHT));
+ newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_SORT", newSVpv (WEECHAT_LIST_POS_SORT, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_BEGINNING", newSVpv (WEECHAT_LIST_POS_BEGINNING, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_END", newSVpv (WEECHAT_LIST_POS_END, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_LOW", newSVpv (WEECHAT_HOTLIST_LOW, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_MESSAGE", newSVpv (WEECHAT_HOTLIST_MESSAGE, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_PRIVATE", newSVpv (WEECHAT_HOTLIST_PRIVATE, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_HIGHLIGHT", newSVpv (WEECHAT_HOTLIST_HIGHLIGHT, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_STRING", newSVpv (WEECHAT_HOOK_SIGNAL_STRING, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_INT", newSVpv (WEECHAT_HOOK_SIGNAL_INT, PL_na));
+ newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_POINTER", newSVpv (WEECHAT_HOOK_SIGNAL_POINTER, PL_na));
}
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index f52137d75..97d9870db 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -149,7 +149,7 @@ weechat_perl_exec (struct t_plugin_script *script,
{
weechat_printf (NULL,
weechat_gettext ("%s%s: error: %s"),
- weechat_prefix ("error"), "perl", SvPV_nolen (ERRSV));
+ weechat_prefix ("error"), "Perl", SvPV_nolen (ERRSV));
(void) POPs; /* poping the 'undef' */
mem_err = 0;
}
@@ -160,7 +160,7 @@ weechat_perl_exec (struct t_plugin_script *script,
weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" must "
"return one valid value (%d)"),
- weechat_prefix ("error"), "perl", function, count);
+ weechat_prefix ("error"), "Perl", function, count);
mem_err = 0;
}
else
@@ -183,7 +183,7 @@ weechat_perl_exec (struct t_plugin_script *script,
weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" is "
"internally misused"),
- weechat_prefix ("error"), "perl", function);
+ weechat_prefix ("error"), "Perl", function);
mem_err = 0;
}
}
@@ -202,7 +202,7 @@ weechat_perl_exec (struct t_plugin_script *script,
weechat_printf (NULL,
weechat_gettext ("%s%s: not enough memory in function "
"\"%s\""),
- weechat_prefix ("error"), "perl", function);
+ weechat_prefix ("error"), "Perl", function);
return NULL;
}
@@ -231,13 +231,13 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: loading Perl script \"%s\""),
- weechat_prefix ("info"), "perl", filename);
+ weechat_prefix ("info"), "Perl", filename);
if (stat (filename, &buf) != 0)
{
weechat_printf (NULL,
weechat_gettext ("%s%s: script \"%s\" not found"),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
return 0;
}
@@ -261,7 +261,7 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to create new "
"sub-interpreter"),
- weechat_prefix ("error"), "perl");
+ weechat_prefix ("error"), "Perl");
return 0;
}
@@ -286,7 +286,7 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: not enough memory to parse "
"file \"%s\""),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
return 0;
}
@@ -297,10 +297,10 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to parse file "
"\"%s\""),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
weechat_printf (NULL,
weechat_gettext ("%s%s: error: %s"),
- weechat_prefix ("error"), "perl",
+ weechat_prefix ("error"), "Perl",
#ifndef MULTIPLICITY
SvPV(perl_get_sv("WeechatPerlScriptLoader::"
"weechat_perl_load_eval_file_error",
@@ -315,22 +315,24 @@ weechat_perl_load (char *filename)
{
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to run file \"%s\""),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
}
else
{
weechat_printf (NULL,
weechat_gettext ("%s%s: unknown error while "
"loading file \"%s\""),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
}
#ifdef MULTIPLICITY
perl_destruct (perl_current_interpreter);
perl_free (perl_current_interpreter);
#endif
if (perl_current_script && (perl_current_script != &tempscript))
- weechat_script_remove (weechat_perl_plugin,
- &perl_scripts, perl_current_script);
+ {
+ script_remove (weechat_perl_plugin,
+ &perl_scripts, perl_current_script);
+ }
free (eval);
return 0;
@@ -343,7 +345,7 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: function \"register\" not "
"found (or failed) in file \"%s\""),
- weechat_prefix ("error"), "perl", filename);
+ weechat_prefix ("error"), "Perl", filename);
#ifdef MULTIPLICITY
perl_destruct (perl_current_interpreter);
perl_free (perl_current_interpreter);
@@ -385,7 +387,7 @@ weechat_perl_unload (struct t_plugin_script *script)
weechat_printf (NULL,
weechat_gettext ("%s%s: unloading script \"%s\""),
- weechat_prefix ("info"), "perl", script->name);
+ weechat_prefix ("info"), "Perl", script->name);
#ifndef MULTIPLICITY
eval_pv (script->interpreter, TRUE);
@@ -411,7 +413,7 @@ weechat_perl_unload (struct t_plugin_script *script)
perl_free (script->interpreter);
#endif
- weechat_script_remove (weechat_perl_plugin, &perl_scripts, script);
+ script_remove (weechat_perl_plugin, &perl_scripts, script);
}
/*
@@ -423,20 +425,19 @@ weechat_perl_unload_name (char *name)
{
struct t_plugin_script *ptr_script;
- ptr_script = weechat_script_search (weechat_perl_plugin,
- &perl_scripts, name);
+ ptr_script = script_search (weechat_perl_plugin, &perl_scripts, name);
if (ptr_script)
{
weechat_perl_unload (ptr_script);
weechat_printf (NULL,
weechat_gettext ("%s%s: script \"%s\" unloaded"),
- weechat_prefix ("info"), "perl", name);
+ weechat_prefix ("info"), "Perl", name);
}
else
{
weechat_printf (NULL,
weechat_gettext ("%s%s: script \"%s\" not loaded"),
- weechat_prefix ("error"), "perl", name);
+ weechat_prefix ("error"), "Perl", name);
}
}
@@ -618,14 +619,14 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
{
if (weechat_strcasecmp (argv[1], "autoload") == 0)
{
- weechat_script_auto_load (weechat_perl_plugin,
- "perl", &weechat_perl_load_cb);
+ script_auto_load (weechat_perl_plugin, "perl",
+ &weechat_perl_load_cb);
}
else if (weechat_strcasecmp (argv[1], "reload") == 0)
{
weechat_perl_unload_all ();
- weechat_script_auto_load (weechat_perl_plugin,
- "perl", &weechat_perl_load_cb);
+ script_auto_load (weechat_perl_plugin,
+ "perl", &weechat_perl_load_cb);
}
else if (weechat_strcasecmp (argv[1], "unload") == 0)
{
@@ -637,8 +638,8 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
if (weechat_strcasecmp (argv[1], "load") == 0)
{
/* load Perl script */
- path_script = weechat_script_search_full_name (weechat_perl_plugin,
- "perl", argv_eol[2]);
+ path_script = script_search_full_name (weechat_perl_plugin,
+ "perl", argv_eol[2]);
weechat_perl_load ((path_script) ? path_script : argv_eol[2]);
if (path_script)
free (path_script);
@@ -653,7 +654,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
weechat_printf (NULL,
weechat_gettext ("%s%s: unknown option for "
"command \"%s\""),
- weechat_prefix ("error"), "perl", "perl");
+ weechat_prefix ("error"), "Perl", "perl");
}
}
@@ -678,7 +679,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
{
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to initialize Perl"),
- weechat_prefix ("error"), "perl");
+ weechat_prefix ("error"), "Perl");
return WEECHAT_RC_ERROR;
}
@@ -702,8 +703,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
weechat_mkdir_home ("perl", 0644);
weechat_mkdir_home ("perl/autoload", 0644);
- weechat_script_auto_load (weechat_perl_plugin,
- "perl", &weechat_perl_load_cb);
+ script_auto_load (weechat_perl_plugin, "perl", &weechat_perl_load_cb);
/* init ok */
return WEECHAT_RC_OK;
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
new file mode 100644
index 000000000..e85793f2b
--- /dev/null
+++ b/src/plugins/scripts/script-api.c
@@ -0,0 +1,574 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* script-api.c: script API */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "../weechat-plugin.h"
+#include "script.h"
+#include "script-callback.h"
+
+
+/*
+ * script_api_charset_set: set charset for script
+ */
+
+void
+script_api_charset_set (struct t_plugin_script *script,
+ char *charset)
+{
+ if (script->charset)
+ free (script->charset);
+
+ script->charset = (charset) ? strdup (charset) : NULL;
+}
+
+/*
+ * script_api_printf: print a message
+ */
+
+void
+script_api_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer, char *format, ...)
+{
+ va_list argptr;
+ static char buf[8192];
+ char *buf2;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ buf2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_printf (buffer, "%s", (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+}
+
+/*
+ * script_api_infobar_printf: print a message in infobar
+ */
+
+void
+script_api_infobar_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int delay, char *color_name,
+ char *format, ...)
+{
+ va_list argptr;
+ static char buf[1024];
+ char *buf2;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ buf2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_infobar_printf (delay, color_name, "%s", (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+}
+
+/*
+ * script_api_log_printf: add a message in WeeChat log file
+ */
+
+void
+script_api_log_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *format, ...)
+{
+ va_list argptr;
+ static char buf[1024];
+ char *buf2;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ buf2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_log_printf ("%s", (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+}
+
+/*
+ * script_api_hook_command: hook a command
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *command, char *description,
+ char *args, char *args_description,
+ char *completion,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ int argc, char **argv,
+ char **argv_eol),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_script_callback->script = NULL;
+ new_script_callback->function = NULL;
+ new_script_callback->hook = NULL;
+
+ new_hook = weechat_hook_command (command, description, args,
+ args_description, completion,
+ callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_timer: hook a timer
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int interval, int align_second, int max_calls,
+ int (*callback)(void *data),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_timer (interval, align_second, max_calls,
+ callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_fd: hook a fd
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int fd, int flag_read, int flag_write,
+ int flag_exception,
+ int (*callback)(void *data),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_fd (fd, flag_read, flag_write, flag_exception,
+ callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_print: hook a print
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ char *message, int strip_colors,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ time_t date, char *prefix,
+ char *message),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_print (buffer, message, strip_colors,
+ callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_signal: hook a signal
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *signal,
+ int (*callback)(void *data, char *signal,
+ char *type_data,
+ void *signal_data),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_signal (signal, callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_config: hook a config option
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *type, char *option,
+ int (*callback)(void *data, char *type,
+ char *option, char *value),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_config (type, option, callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_hook_completion: hook a completion
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *completion,
+ int (*callback)(void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_hook *new_hook;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return 0;
+
+ new_hook = weechat_hook_completion (completion, callback, new_script_callback);
+ if (!new_hook)
+ {
+ free (new_script_callback);
+ return 0;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->hook = new_hook;
+
+ script_callback_add (script, new_script_callback);
+
+ return 1;
+}
+
+/*
+ * script_api_unhook: unhook something
+ */
+
+void
+script_api_unhook (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_hook *hook)
+{
+ struct t_script_callback *ptr_script_callback;
+
+ if (!weechat_plugin || !script || !hook)
+ return;
+
+ for (ptr_script_callback = script->callbacks; ptr_script_callback;
+ ptr_script_callback = ptr_script_callback->next_callback)
+ {
+ if (ptr_script_callback->hook == hook)
+ break;
+ }
+
+ if (ptr_script_callback)
+ {
+ script_callback_remove (weechat_plugin, script, ptr_script_callback);
+ }
+}
+
+/*
+ * script_api_unhook_all: remove all hooks from a script
+ */
+
+void
+script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script)
+{
+ struct t_script_callback *ptr_callback, *next_callback;
+
+ ptr_callback = script->callbacks;
+ while (ptr_callback)
+ {
+ next_callback = ptr_callback->next_callback;
+
+ script_callback_remove (weechat_plugin, script, ptr_callback);
+
+ ptr_callback = next_callback;
+ }
+}
+
+/*
+ * script_api_buffer_new: create a new buffer
+ */
+
+struct t_gui_buffer *
+script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *category, char *name,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ char *input_data),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_gui_buffer *new_buffer;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return NULL;
+
+ new_buffer = weechat_buffer_new (category, name,
+ callback, new_script_callback);
+ if (!new_buffer)
+ {
+ free (new_script_callback);
+ return NULL;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->buffer = new_buffer;
+
+ script_callback_add (script, new_script_callback);
+
+ return new_buffer;
+}
+
+/*
+ * script_api_buffer_close: close a buffer
+ */
+
+void
+script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ int switch_to_another)
+{
+ struct t_script_callback *ptr_script_callback;
+
+ if (!weechat_plugin || !script || !buffer)
+ return;
+
+ weechat_buffer_close (buffer, switch_to_another);
+
+ for (ptr_script_callback = script->callbacks; ptr_script_callback;
+ ptr_script_callback = ptr_script_callback->next_callback)
+ {
+ if (ptr_script_callback->buffer == buffer)
+ break;
+ }
+
+ if (ptr_script_callback)
+ {
+ script_callback_remove (weechat_plugin, script, ptr_script_callback);
+ }
+}
+
+/*
+ * script_api_command: execute a command (simulate user entry)
+ */
+
+void
+script_api_command (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer, char *command)
+{
+ char *command2;
+
+ command2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, command) : NULL;
+ weechat_command (buffer, (command2) ? command2 : command);
+ if (command2)
+ free (command2);
+}
+
+/*
+ * script_api_config_get_plugin: get a value of a script option
+ * format in file is: plugin.script.option=value
+ */
+
+char *
+script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *option)
+{
+ char *option_fullname, *return_value;
+
+ option_fullname = (char *)malloc (strlen (script->name) +
+ strlen (option) + 2);
+ if (!option_fullname)
+ return NULL;
+
+ strcpy (option_fullname, script->name);
+ strcat (option_fullname, ".");
+ strcat (option_fullname, option);
+
+ return_value = weechat_config_get_plugin (option_fullname);
+ free (option_fullname);
+
+ return return_value;
+}
+
+/*
+ * script_api_config_set_plugin: set value of a script config option
+ * format in file is: plugin.script.option=value
+ */
+
+int
+script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *option, char *value)
+{
+ char *option_fullname;
+ int return_code;
+
+ option_fullname = (char *)malloc (strlen (script->name) +
+ strlen (option) + 2);
+ if (!option_fullname)
+ return 0;
+
+ strcpy (option_fullname, script->name);
+ strcat (option_fullname, ".");
+ strcat (option_fullname, option);
+
+ return_code = weechat_config_set_plugin (option_fullname, value);
+ free (option_fullname);
+
+ return return_code;
+}
diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h
new file mode 100644
index 000000000..68c898c9b
--- /dev/null
+++ b/src/plugins/scripts/script-api.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __WEECHAT_SCRIPT_API_H
+#define __WEECHAT_SCRIPT_API_H 1
+
+extern void script_api_charset_set (struct t_plugin_script *script,
+ char *charset);
+extern void script_api_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ char *format, ...);
+extern void script_api_infobar_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int delay, char *color_name,
+ char *format, ...);
+extern void script_api_log_printf (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *format, ...);
+extern int script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *command, char *description,
+ char *args, char *args_description,
+ char *completion,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ int argc, char **argv,
+ char **argv_eol),
+ char *function);
+extern int script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int interval, int align_second,
+ int max_calls,
+ int (*callback)(void *data),
+ char *function);
+extern int script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ int fd, int flag_read, int flag_write,
+ int flag_exception,
+ int (*callback)(void *data),
+ char *function);
+extern int script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ char *message, int strip_colors,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ time_t date, char *prefix,
+ char *message),
+ char *function);
+extern int script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *signal,
+ int (*callback)(void *data,
+ char *signal,
+ char *type_data,
+ void *signal_data),
+ char *function);
+extern int script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *type, char *option,
+ int (*callback)(void *data, char *type,
+ char *option,
+ char *value),
+ char *function);
+extern int script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *completion,
+ int (*callback)(void *data,
+ char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list),
+ char *function);
+extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_hook *hook);
+extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script);
+struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *category, char *name,
+ int (*callback)(void *data,
+ struct t_gui_buffer *buffer,
+ char *input_data),
+ char *function);
+extern void script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ int switch_to_another);
+extern void script_api_command (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ char *command);
+extern char *script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *option);
+extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *option, char *value);
+
+#endif /* script-api.h */
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
new file mode 100644
index 000000000..169c52a0f
--- /dev/null
+++ b/src/plugins/scripts/script-callback.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* script-callback.c: script callbacks */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../weechat-plugin.h"
+#include "script.h"
+#include "script-callback.h"
+
+
+/*
+ * script_callback_alloc: allocate a new callback and initializes it
+ */
+
+struct t_script_callback *
+script_callback_alloc ()
+{
+ struct t_script_callback *new_script_callback;
+
+ new_script_callback = (struct t_script_callback *)malloc (sizeof (struct t_script_callback));
+ if (new_script_callback)
+ {
+ new_script_callback->script = NULL;
+ new_script_callback->function = NULL;
+ new_script_callback->hook = NULL;
+ new_script_callback->buffer = NULL;
+ return new_script_callback;
+ }
+
+ return NULL;
+}
+
+/*
+ * script_callback_add: add a callback to list
+ */
+
+void
+script_callback_add (struct t_plugin_script *script,
+ struct t_script_callback *callback)
+{
+ if (script->callbacks)
+ script->callbacks->prev_callback = callback;
+ callback->prev_callback = NULL;
+ callback->next_callback = script->callbacks;
+ script->callbacks = callback;
+}
+
+/*
+ * script_callback_remove: remove a callback from a script
+ */
+
+void
+script_callback_remove (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_script_callback *script_callback)
+{
+ /* remove callback from list */
+ if (script_callback->prev_callback)
+ script_callback->prev_callback->next_callback =
+ script_callback->next_callback;
+ if (script_callback->next_callback)
+ script_callback->next_callback->prev_callback =
+ script_callback->prev_callback;
+ if (script->callbacks == script_callback)
+ script->callbacks = script_callback->next_callback;
+
+ /* unhook and free data */
+ if (script_callback->function)
+ free (script_callback->function);
+ if (script_callback->hook)
+ weechat_unhook (script_callback->hook);
+
+ free (script_callback);
+}
+
+/*
+ * script_callback_remove_all: remove all callbacks from a script
+ */
+
+void
+script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script)
+{
+ while (script->callbacks)
+ {
+ script_callback_remove (weechat_plugin, script, script->callbacks);
+ }
+}
diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h
new file mode 100644
index 000000000..1b1d68f2e
--- /dev/null
+++ b/src/plugins/scripts/script-callback.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __WEECHAT_SCRIPT_CALLBACK_H
+#define __WEECHAT_SCRIPT_CALLBACK_H 1
+
+struct t_script_callback
+{
+ void *script; /* pointer to script */
+ char *function; /* script function called */
+ struct t_hook *hook; /* not NULL if hook */
+ struct t_gui_buffer *buffer; /* not NULL if buffer callback */
+ struct t_script_callback *prev_callback; /* link to next callback */
+ struct t_script_callback *next_callback; /* link to previous callback */
+};
+
+extern struct t_script_callback *script_callback_alloc ();
+extern void script_callback_add (struct t_plugin_script *script,
+ struct t_script_callback *callback);
+extern void script_callback_remove (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_script_callback *script_callback);
+extern void script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script);
+
+#endif /* script-callback.h */
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index 42f3365eb..20ef057ba 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -20,8 +20,6 @@
#include <stdlib.h>
-#include <unistd.h>
-#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
@@ -30,16 +28,17 @@
#include "../weechat-plugin.h"
#include "script.h"
+#include "script-callback.h"
/*
- * weechat_script_pointer_to_string: convert pointer to string for usage
- * in a script (any language)
- * WARNING: result has to be free() after use
+ * script_pointer_to_string: convert pointer to string for usage
+ * in a script (any language)
+ * WARNING: result has to be free() after use
*/
char *
-weechat_script_pointer_to_string (void *pointer)
+script_pointer_to_string (void *pointer)
{
char pointer_str[128];
@@ -53,16 +52,16 @@ weechat_script_pointer_to_string (void *pointer)
}
/*
- * weechat_script_string_to_pointer: convert stirng to pointer for usage
- * outside script
+ * script_string_to_pointer: convert stirng to pointer for usage
+ * outside script
*/
void *
-weechat_script_string_to_pointer (char *pointer_str)
+script_string_to_pointer (char *pointer_str)
{
unsigned int value;
- if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[0] != 'x'))
+ if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[1] != 'x'))
return NULL;
sscanf (pointer_str + 2, "%x", &value);
@@ -71,13 +70,13 @@ weechat_script_string_to_pointer (char *pointer_str)
}
/*
- * weechat_script_auto_load: auto-load all scripts in a directory
+ * script_auto_load: auto-load all scripts in a directory
*/
void
-weechat_script_auto_load (struct t_weechat_plugin *weechat_plugin,
- char *language,
- int (*callback)(void *data, char *filename))
+script_auto_load (struct t_weechat_plugin *weechat_plugin,
+ char *language,
+ int (*callback)(void *data, char *filename))
{
char *dir_home, *dir_name;
int dir_length;
@@ -98,12 +97,12 @@ weechat_script_auto_load (struct t_weechat_plugin *weechat_plugin,
}
/*
- * weechat_script_search: search a script in list
+ * script_search: search a script in list
*/
struct t_plugin_script *
-weechat_script_search (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **list, char *name)
+script_search (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **list, char *name)
{
struct t_plugin_script *ptr_script;
@@ -119,12 +118,12 @@ weechat_script_search (struct t_weechat_plugin *weechat_plugin,
}
/*
- * weechat_script_search_full_name: search the full path name of a script
+ * script_search_full_name: search the full path name of a script
*/
char *
-weechat_script_search_full_name (struct t_weechat_plugin *weechat_plugin,
- char *language, char *filename)
+script_search_full_name (struct t_weechat_plugin *weechat_plugin,
+ char *language, char *filename)
{
char *final_name, *dir_home, *dir_system;
int length;
@@ -205,16 +204,16 @@ weechat_script_search_full_name (struct t_weechat_plugin *weechat_plugin,
}
/*
- * weechat_script_add: add a script to list of scripts
+ * script_add: add a script to list of scripts
*/
struct t_plugin_script *
-weechat_script_add (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **script_list,
- char *filename,
- char *name, char *version,
- char *shutdown_func, char *description,
- char *charset)
+script_add (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **script_list,
+ char *filename,
+ char *name, char *version,
+ char *shutdown_func, char *description,
+ char *charset)
{
struct t_plugin_script *new_script;
@@ -238,7 +237,7 @@ weechat_script_add (struct t_weechat_plugin *weechat_plugin,
new_script->description = strdup (description);
new_script->charset = (charset) ? strdup (charset) : NULL;
- new_script->hooks = NULL;
+ new_script->callbacks = NULL;
/* add new script to list */
if ((*script_list))
@@ -258,45 +257,16 @@ weechat_script_add (struct t_weechat_plugin *weechat_plugin,
}
/*
- * weechat_script_remove_script_hook: remove a script_hook from script
+ * script_remove: remove a script from list of scripts
*/
void
-weechat_script_remove_script_hook (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_script_hook *script_hook)
+script_remove (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **script_list,
+ struct t_plugin_script *script)
{
- /* remove script_hook from list */
- if (script_hook->prev_hook)
- script_hook->prev_hook->next_hook = script_hook->next_hook;
- if (script_hook->next_hook)
- script_hook->next_hook->prev_hook = script_hook->prev_hook;
- if (script->hooks == script_hook)
- script->hooks = script_hook->next_hook;
-
- /* unhook and free data */
- if (script_hook->hook)
- weechat_unhook (script_hook->hook);
- if (script_hook->function)
- free (script_hook->function);
-}
-
-/*
- * weechat_script_remove: remove a script from list of scripts
- */
-
-void
-weechat_script_remove (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **script_list,
- struct t_plugin_script *script)
-{
- /* remove all hooks created by this script */
- while (script->hooks)
- {
- weechat_script_remove_script_hook (weechat_plugin,
- script,
- script->hooks);
- }
+ /* remove all callbacks created by this script */
+ script_callback_remove_all (weechat_plugin, script);
/* free data */
if (script->filename)
@@ -323,514 +293,3 @@ weechat_script_remove (struct t_weechat_plugin *weechat_plugin,
/* free script */
free (script);
}
-
-/*
- * weechat_script_charset_set: set charset for script
- */
-
-void
-weechat_script_charset_set (struct t_plugin_script *script,
- char *charset)
-{
- if (script->charset)
- free (script->charset);
-
- script->charset = (charset) ? strdup (charset) : NULL;
-}
-
-/*
- * weechat_script_printf: print a message
- */
-
-void
-weechat_script_printf (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer, char *format, ...)
-{
- va_list argptr;
- static char buf[8192];
- char *buf2;
-
- va_start (argptr, format);
- vsnprintf (buf, sizeof (buf) - 1, format, argptr);
- va_end (argptr);
-
- buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_printf (buffer, "%s", (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_script_infobar_printf: print a message in infobar
- */
-
-void
-weechat_script_infobar_printf (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int delay, char *color_name, char *format, ...)
-{
- va_list argptr;
- static char buf[1024];
- char *buf2;
-
- va_start (argptr, format);
- vsnprintf (buf, sizeof (buf) - 1, format, argptr);
- va_end (argptr);
-
- buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_infobar_printf (delay, color_name, "%s", (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_script_log_printf: add a message in WeeChat log file
- */
-
-void
-weechat_script_log_printf (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *format, ...)
-{
- va_list argptr;
- static char buf[1024];
- char *buf2;
-
- va_start (argptr, format);
- vsnprintf (buf, sizeof (buf) - 1, format, argptr);
- va_end (argptr);
-
- buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_log_printf ("%s", (buf2) ? buf2 : buf);
- if (buf2)
- free (buf2);
-}
-
-/*
- * weechat_script_hook_command: hook a command
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_command (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *command, char *description,
- char *args, char *args_description,
- char *completion,
- int (*callback)(void *data,
- struct t_gui_buffer *buffer,
- int argc, char **argv,
- char **argv_eol),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_command (command, description, args,
- args_description, completion,
- callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_timer: hook a timer
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_timer (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int interval, int align_second, int max_calls,
- int (*callback)(void *data),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_timer (interval, align_second, max_calls,
- callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_fd: hook a fd
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_fd (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int fd, int flag_read, int flag_write,
- int flag_exception,
- int (*callback)(void *data),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_fd (fd, flag_read, flag_write, flag_exception,
- callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_print: hook a print
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_print (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer,
- char *message, int strip_colors,
- int (*callback)(void *data,
- struct t_gui_buffer *buffer,
- time_t date, char *prefix,
- char *message),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_print (buffer, message, strip_colors,
- callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_signal: hook a signal
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_signal (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *signal,
- int (*callback)(void *data, char *signal,
- char *type_data,
- void *signal_data),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_signal (signal, callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_config: hook a config option
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_config (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *type, char *option,
- int (*callback)(void *data, char *type,
- char *option, char *value),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_config (type, option, callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_hook_completion: hook a completion
- * return 1 if ok, 0 if error
- */
-
-int
-weechat_script_hook_completion (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *completion,
- int (*callback)(void *data, char *completion,
- struct t_gui_buffer *buffer,
- struct t_weelist *list),
- char *function)
-{
- struct t_script_hook *new_script_hook;
- struct t_hook *new_hook;
-
- new_script_hook = (struct t_script_hook *)malloc (sizeof (struct t_script_hook));
- if (!new_script_hook)
- return 0;
-
- new_script_hook->hook = NULL;
- new_script_hook->function = NULL;
- new_script_hook->script = NULL;
-
- new_hook = weechat_hook_completion (completion, callback, new_script_hook);
- if (!new_hook)
- {
- free (new_script_hook);
- return 0;
- }
-
- new_script_hook->hook = new_hook;
- new_script_hook->function = strdup (function);
- new_script_hook->script = script;
-
- /* add script_hook to list of hooks for current script */
- if (script->hooks)
- script->hooks->prev_hook = new_script_hook;
- new_script_hook->prev_hook = NULL;
- new_script_hook->next_hook = script->hooks;
- script->hooks = new_script_hook;
-
- return 1;
-}
-
-/*
- * weechat_script_unhook: unhook something
- */
-
-void
-weechat_script_unhook (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_hook *hook)
-{
- struct t_script_hook *ptr_script_hook;
-
- for (ptr_script_hook = script->hooks; ptr_script_hook;
- ptr_script_hook = ptr_script_hook->next_hook)
- {
- if (ptr_script_hook->hook == hook)
- break;
- }
-
- if (ptr_script_hook)
- weechat_script_remove_script_hook (weechat_plugin,
- script,
- ptr_script_hook);
-}
-
-/*
- * weechat_script_command: execute a command (simulate user entry)
- */
-
-void
-weechat_script_command (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer, char *command)
-{
- char *command2;
-
- command2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, command) : NULL;
- weechat_command (buffer, (command2) ? command2 : command);
- if (command2)
- free (command2);
-}
-
-/*
- * weechat_script_config_get_plugin: get a value of a script option
- * format in file is: plugin.script.option=value
- */
-
-char *
-weechat_script_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *option)
-{
- char *option_fullname, *return_value;
-
- option_fullname = (char *)malloc (strlen (script->name) +
- strlen (option) + 2);
- if (!option_fullname)
- return NULL;
-
- strcpy (option_fullname, script->name);
- strcat (option_fullname, ".");
- strcat (option_fullname, option);
-
- return_value = weechat_config_get_plugin (option_fullname);
- free (option_fullname);
-
- return return_value;
-}
-
-/*
- * weechat_script_config_set_plugin: set value of a script config option
- * format in file is: plugin.script.option=value
- */
-
-int
-weechat_script_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *option, char *value)
-{
- char *option_fullname;
- int return_code;
-
- option_fullname = (char *)malloc (strlen (script->name) +
- strlen (option) + 2);
- if (!option_fullname)
- return 0;
-
- strcpy (option_fullname, script->name);
- strcat (option_fullname, ".");
- strcat (option_fullname, option);
-
- return_code = weechat_config_set_plugin (option_fullname, value);
- free (option_fullname);
-
- return return_code;
-}
diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h
index 3fad8624e..61771976f 100644
--- a/src/plugins/scripts/script.h
+++ b/src/plugins/scripts/script.h
@@ -16,9 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* This header is designed to be distributed with WeeChat plugins, if scripts
- management is needed */
-
#ifndef __WEECHAT_SCRIPT_H
#define __WEECHAT_SCRIPT_H 1
@@ -38,15 +35,6 @@
"function \"%s\""), \
weechat_prefix ("error"), __language, __function)
-struct t_script_hook
-{
- struct t_hook *hook; /* pointer to hook */
- char *function; /* script function called */
- void *script; /* pointer to script */
- struct t_script_hook *prev_hook; /* link to next script hook */
- struct t_script_hook *next_hook; /* link to previous hook */
-};
-
struct t_plugin_script
{
/* script variables */
@@ -58,112 +46,31 @@ struct t_plugin_script
char *shutdown_func; /* function when script is unloaded*/
char *charset; /* script charset */
- struct t_script_hook *hooks; /* hooks for script */
+ struct t_script_callback *callbacks; /* callbacks for script */
struct t_plugin_script *prev_script; /* link to previous script */
struct t_plugin_script *next_script; /* link to next script */
};
-extern char *weechat_script_pointer_to_string (void *pointer);
-extern void *weechat_script_string_to_pointer (char *pointer_str);
-extern void weechat_script_auto_load (struct t_weechat_plugin *weechat_plugin,
- char *language,
- int (*callback)(void *data, char *filename));
-extern struct t_plugin_script *weechat_script_search (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **list,
- char *name);
-extern char *weechat_script_search_full_name (struct t_weechat_plugin *weechat_plugin,
- char *language, char *filename);
-extern struct t_plugin_script *weechat_script_add (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **script_list,
- char *filename, char *name,
- char *version,
- char *shutdown_func,
- char *description,
- char *charset);
-extern void weechat_script_remove (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **script_list,
- struct t_plugin_script *script);
-extern void weechat_script_charset_set (struct t_plugin_script *script,
- char *charset);
-extern void weechat_script_printf (struct t_weechat_plugin *plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer,
- char *format, ...);
-extern void weechat_script_infobar_printf (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int delay, char *color_name,
- char *format, ...);
-extern void weechat_script_log_printf (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *format, ...);
-extern int weechat_script_hook_command (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *command, char *description,
- char *args, char *args_description,
- char *completion,
- int (*callback)(void *data,
- struct t_gui_buffer *buffer,
- int argc, char **argv,
- char **argv_eol),
- char *function);
-extern int weechat_script_hook_timer (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int interval, int align_second,
- int max_calls,
- int (*callback)(void *data),
- char *function);
-extern int weechat_script_hook_fd (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- int fd, int flag_read, int flag_write,
- int flag_exception,
- int (*callback)(void *data),
- char *function);
-extern int weechat_script_hook_print (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer,
- char *message, int strip_colors,
- int (*callback)(void *data,
- struct t_gui_buffer *buffer,
- time_t date,
- char *prefix,
- char *message),
- char *function);
-extern int weechat_script_hook_signal (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *signal,
- int (*callback)(void *data,
- char *signal,
- char *type_data,
- void *signal_data),
- char *function);
-extern int weechat_script_hook_config (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *type, char *option,
- int (*callback)(void *data, char *type,
- char *option,
- char *value),
- char *function);
-extern int weechat_script_hook_completion (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *completion,
- int (*callback)(void *data,
- char *completion,
- struct t_gui_buffer *buffer,
- struct t_weelist *list),
- char *function);
-extern void weechat_script_unhook (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_hook *hook);
-extern void weechat_script_command (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_gui_buffer *buffer,
- char *command);
-extern char *weechat_script_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *option);
-extern int weechat_script_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- char *option, char *value);
+extern char *script_pointer_to_string (void *pointer);
+extern void *script_string_to_pointer (char *pointer_str);
+extern void script_auto_load (struct t_weechat_plugin *weechat_plugin,
+ char *language,
+ int (*callback)(void *data, char *filename));
+extern struct t_plugin_script *script_search (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **list,
+ char *name);
+extern char *script_search_full_name (struct t_weechat_plugin *weechat_plugin,
+ char *language, char *filename);
+extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **script_list,
+ char *filename, char *name,
+ char *version,
+ char *shutdown_func,
+ char *description,
+ char *charset);
+extern void script_remove (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script **script_list,
+ struct t_plugin_script *script);
#endif /* script.h */
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index d9c778ebb..247d12cc6 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -261,8 +261,10 @@ struct t_weechat_plugin
/* buffers */
struct t_gui_buffer *(*buffer_new) (struct t_weechat_plugin *plugin,
char *category, char *name,
- void (*callback_input_data)(struct t_gui_buffer *buffer,
- char *data));
+ int (*input_callback)(void *data,
+ struct t_gui_buffer *buffer,
+ char *input_data),
+ void *input_callback_data);
struct t_gui_buffer *(*buffer_search) (char *category, char *name);
void (*buffer_close) (struct t_gui_buffer *buffer, int switch_to_another);
void *(*buffer_get) (struct t_gui_buffer *buffer, char *property);
@@ -532,9 +534,10 @@ struct t_weechat_plugin
weechat_plugin->unhook_all_plugin(weechat_plugin)
/* buffers */
-#define weechat_buffer_new(__category, __name, __callback_input_data) \
+#define weechat_buffer_new(__category, __name, __input_callback, \
+ __input_callback_data) \
weechat_plugin->buffer_new(weechat_plugin, __category, __name, \
- __callback_input_data)
+ __input_callback, __input_callback_data)
#define weechat_buffer_search(__category, __name) \
weechat_plugin->buffer_search(__category, __name)
#define weechat_current_buffer \