mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 22:06:38 +02:00
Migration of Ruby plugin to new API, new functions to dump script plugin data to WeeChat log file
This commit is contained in:
@@ -38,22 +38,22 @@
|
||||
#define PERL_RETURN_OK XSRETURN_YES
|
||||
#define PERL_RETURN_ERROR XSRETURN_NO
|
||||
#define PERL_RETURN_EMPTY XSRETURN_EMPTY
|
||||
#define PERL_RETURN_STRING(string) \
|
||||
if (string) \
|
||||
{ \
|
||||
XST_mPV (0, string); \
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
#define PERL_RETURN_STRING(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
XST_mPV (0, __string); \
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
XSRETURN (1);
|
||||
#define PERL_RETURN_STRING_FREE(string) \
|
||||
if (string) \
|
||||
{ \
|
||||
XST_mPV (0, string); \
|
||||
free (string); \
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
#define PERL_RETURN_STRING_FREE(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
XST_mPV (0, __string); \
|
||||
free (__string); \
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
XSRETURN (1);
|
||||
|
||||
extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
@@ -65,17 +65,17 @@ extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *author, *version, *license, *shutdown_func, *description;
|
||||
char *name, *author, *version, *license, *description, *shutdown_func;
|
||||
char *charset;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) items;
|
||||
(void) cv;
|
||||
|
||||
|
||||
perl_current_script = NULL;
|
||||
|
||||
if (items < 5)
|
||||
if (items < 7)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("register");
|
||||
PERL_RETURN_ERROR;
|
||||
@@ -86,16 +86,10 @@ static XS (XS_weechat_register)
|
||||
version = SvPV (ST (2), PL_na);
|
||||
license = SvPV (ST (3), PL_na);
|
||||
description = SvPV (ST (4), PL_na);
|
||||
shutdown_func = NULL;
|
||||
charset = NULL;
|
||||
if (items > 5)
|
||||
{
|
||||
shutdown_func = SvPV (ST (5), PL_na);
|
||||
if (items > 6)
|
||||
charset = SvPV (ST (6), PL_na);
|
||||
}
|
||||
shutdown_func = SvPV (ST (5), PL_na);
|
||||
charset = SvPV (ST (6), PL_na);
|
||||
|
||||
if (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,
|
||||
@@ -112,7 +106,7 @@ static XS (XS_weechat_register)
|
||||
(perl_current_script_filename) ?
|
||||
perl_current_script_filename : "",
|
||||
name, author, version, license,
|
||||
shutdown_func, description, charset);
|
||||
description, shutdown_func, charset);
|
||||
if (perl_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
@@ -356,7 +350,8 @@ static XS (XS_weechat_print)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_printf (weechat_perl_plugin, perl_current_script,
|
||||
script_api_printf (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
|
||||
"%s", SvPV (ST (1), PL_na)); /* message */
|
||||
|
||||
@@ -386,7 +381,8 @@ static XS (XS_weechat_infobar_print)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_infobar_printf (weechat_perl_plugin, perl_current_script,
|
||||
script_api_infobar_printf (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
SvIV (ST (0)), /* delay */
|
||||
SvPV (ST (1), PL_na), /* color */
|
||||
"%s",
|
||||
@@ -440,7 +436,8 @@ static XS (XS_weechat_log_print)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_log_printf (weechat_perl_plugin, perl_current_script,
|
||||
script_api_log_printf (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
"%s", SvPV (ST (0), PL_na)); /* message */
|
||||
|
||||
PERL_RETURN_OK;
|
||||
@@ -456,7 +453,7 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[3], empty_arg[1] = { '\0' };
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) argv;
|
||||
@@ -467,16 +464,17 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
perl_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
|
||||
perl_argv[2] = NULL;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (perl_argv[0])
|
||||
free (perl_argv[0]);
|
||||
@@ -532,20 +530,21 @@ weechat_perl_api_hook_timer_cb (void *data)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[1] = { NULL };
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -597,21 +596,21 @@ weechat_perl_api_hook_fd_cb (void *data)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[1] = { NULL };
|
||||
int *r;
|
||||
int ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -666,7 +665,7 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[5];
|
||||
static char timebuffer[64];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -678,16 +677,17 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
|
||||
perl_argv[3] = message;
|
||||
perl_argv[4] = NULL;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (perl_argv[0])
|
||||
free (perl_argv[0]);
|
||||
@@ -743,7 +743,7 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[3];
|
||||
static char value_str[64];
|
||||
int *r, ret, free_needed;
|
||||
int *rc, ret, free_needed;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -768,16 +768,17 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
|
||||
perl_argv[1] = NULL;
|
||||
perl_argv[2] = NULL;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (free_needed && perl_argv[1])
|
||||
free (perl_argv[1]);
|
||||
@@ -882,7 +883,7 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[4];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -891,16 +892,17 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
|
||||
perl_argv[2] = value;
|
||||
perl_argv[3] = NULL;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -953,7 +955,7 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[4];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -962,16 +964,17 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
|
||||
perl_argv[2] = script_pointer_to_string (list);
|
||||
perl_argv[3] = NULL;
|
||||
|
||||
r = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (perl_argv[1])
|
||||
free (perl_argv[1]);
|
||||
@@ -1039,7 +1042,8 @@ static XS (XS_weechat_unhook)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (script_api_unhook (weechat_perl_plugin, perl_current_script,
|
||||
if (script_api_unhook (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
script_string_to_pointer (SvPV (ST (0), PL_na))))
|
||||
PERL_RETURN_OK;
|
||||
|
||||
@@ -1064,7 +1068,8 @@ static XS (XS_weechat_unhook_all)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_unhook_all (weechat_perl_plugin, perl_current_script);
|
||||
script_api_unhook_all (weechat_perl_plugin,
|
||||
perl_current_script);
|
||||
|
||||
PERL_RETURN_OK;
|
||||
}
|
||||
@@ -1337,7 +1342,7 @@ static XS (XS_weechat_nicklist_search_group)
|
||||
static XS (XS_weechat_nicklist_add_nick)
|
||||
{
|
||||
struct t_gui_nick *new_nick;
|
||||
char *str_prefix, prefix, *result;
|
||||
char *prefix, char_prefix, *result;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -1355,17 +1360,17 @@ static XS (XS_weechat_nicklist_add_nick)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
str_prefix = SvPV(ST (4), PL_na);
|
||||
if (str_prefix && str_prefix[0])
|
||||
prefix = str_prefix[0];
|
||||
prefix = SvPV(ST (4), PL_na);
|
||||
if (prefix && prefix[0])
|
||||
char_prefix = prefix[0];
|
||||
else
|
||||
prefix = ' ';
|
||||
char_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,
|
||||
char_prefix,
|
||||
SvPV (ST (5), PL_na), /* prefix_color */
|
||||
SvIV (ST (6))); /* visible */
|
||||
|
||||
@@ -1515,7 +1520,8 @@ static XS (XS_weechat_command)
|
||||
PERL_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_command (weechat_perl_plugin, perl_current_script,
|
||||
script_api_command (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
|
||||
SvPV (ST (1), PL_na)); /* command */
|
||||
|
||||
@@ -2290,7 +2296,7 @@ static XS (XS_weechat_get_buffer_data)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_perl_xs_init (pTHX)
|
||||
weechat_perl_api_init (pTHX)
|
||||
{
|
||||
HV *stash;
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
#ifndef __WEECHAT_PERL_API_H
|
||||
#define __WEECHAT_PERL_API_H 1
|
||||
|
||||
extern void weechat_perl_xs_init (pTHX);
|
||||
extern void weechat_perl_api_init (pTHX);
|
||||
|
||||
#endif /* weechat-perl.h */
|
||||
|
||||
@@ -229,10 +229,6 @@ weechat_perl_load (char *filename)
|
||||
char *perl_args[] = { "", "-e", "0" };
|
||||
#endif
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "perl", filename);
|
||||
|
||||
if (stat (filename, &buf) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
@@ -240,11 +236,15 @@ weechat_perl_load (char *filename)
|
||||
weechat_prefix ("error"), "perl", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "perl", filename);
|
||||
|
||||
perl_current_script = NULL;
|
||||
|
||||
#ifndef MULTIPLICITY
|
||||
snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num);
|
||||
snprintf (pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num);
|
||||
perl_num++;
|
||||
tempscript.interpreter = "WeechatPerlScriptLoader";
|
||||
perl_argv[0] = filename;
|
||||
@@ -270,7 +270,7 @@ weechat_perl_load (char *filename)
|
||||
PERL_SET_CONTEXT (perl_current_interpreter);
|
||||
perl_construct (perl_current_interpreter);
|
||||
tempscript.interpreter = (PerlInterpreter *) perl_current_interpreter;
|
||||
perl_parse (perl_current_interpreter, weechat_perl_xs_init, 3, perl_args,
|
||||
perl_parse (perl_current_interpreter, weechat_perl_api_init, 3, perl_args,
|
||||
NULL);
|
||||
|
||||
eval_pv (perl_weechat_code, TRUE);
|
||||
@@ -330,8 +330,8 @@ weechat_perl_load (char *filename)
|
||||
#endif
|
||||
if (perl_current_script && (perl_current_script != &tempscript))
|
||||
{
|
||||
script_remove (weechat_perl_plugin,
|
||||
&perl_scripts, perl_current_script);
|
||||
script_remove (weechat_perl_plugin, &perl_scripts,
|
||||
perl_current_script);
|
||||
}
|
||||
|
||||
free (eval);
|
||||
@@ -425,7 +425,7 @@ weechat_perl_unload_name (char *name)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = 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);
|
||||
@@ -498,7 +498,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// List Perl message handlers
|
||||
// list Perl message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl message handlers:");
|
||||
handler_found = 0;
|
||||
@@ -517,7 +517,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Perl command handlers
|
||||
// list Perl command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl command handlers:");
|
||||
handler_found = 0;
|
||||
@@ -536,7 +536,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Perl timer handlers
|
||||
// list Perl timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl timer handlers:");
|
||||
handler_found = 0;
|
||||
@@ -555,7 +555,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Perl keyboard handlers
|
||||
// list Perl keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl keyboard handlers:");
|
||||
handler_found = 0;
|
||||
@@ -573,7 +573,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Perl event handlers
|
||||
// list Perl event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl event handlers:");
|
||||
handler_found = 0;
|
||||
@@ -592,7 +592,7 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Perl modifiers
|
||||
// list Perl modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl modifiers:");
|
||||
modifier_found = 0;
|
||||
@@ -624,8 +624,8 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -666,6 +666,25 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_dump_data_cb: dump Perl plugin data in WeeChat log file
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_dump_data_cb (void *data, char *signal, char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
script_print_log (weechat_perl_plugin, perl_scripts);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Perl plugin
|
||||
*/
|
||||
@@ -674,7 +693,7 @@ int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
weechat_perl_plugin = plugin;
|
||||
|
||||
|
||||
#ifndef MULTIPLICITY
|
||||
char *perl_args[] = { "", "-e", "0" };
|
||||
|
||||
@@ -708,9 +727,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_mkdir_home ("perl", 0644);
|
||||
weechat_mkdir_home ("perl/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_perl_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_perl_plugin);
|
||||
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;
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#ifndef __WEECHAT_PERL_H
|
||||
#define __WEECHAT_PERL_H 1
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
|
||||
#define weechat_plugin weechat_perl_plugin
|
||||
|
||||
extern struct t_weechat_plugin *weechat_perl_plugin;
|
||||
|
||||
@@ -38,17 +38,17 @@
|
||||
#define PYTHON_RETURN_EMPTY \
|
||||
Py_INCREF(Py_None); \
|
||||
return Py_None;
|
||||
#define PYTHON_RETURN_STRING(string) \
|
||||
if (string) \
|
||||
return Py_BuildValue ("s", string); \
|
||||
#define PYTHON_RETURN_STRING(__string) \
|
||||
if (__string) \
|
||||
return Py_BuildValue ("s", __string); \
|
||||
return Py_BuildValue ("s", "");
|
||||
#define PYTHON_RETURN_STRING_FREE(string) \
|
||||
if (string) \
|
||||
{ \
|
||||
object = Py_BuildValue ("s", string); \
|
||||
free (string); \
|
||||
return object; \
|
||||
} \
|
||||
#define PYTHON_RETURN_STRING_FREE(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
object = Py_BuildValue ("s", __string); \
|
||||
free (__string); \
|
||||
return object; \
|
||||
} \
|
||||
return Py_BuildValue ("s", "");
|
||||
|
||||
|
||||
@@ -71,18 +71,18 @@ weechat_python_api_register (PyObject *self, PyObject *args)
|
||||
author = NULL;
|
||||
version = NULL;
|
||||
license = NULL;
|
||||
shutdown_func = NULL;
|
||||
description = NULL;
|
||||
shutdown_func = NULL;
|
||||
charset = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssssss|s", &name, &author, &version,
|
||||
&license, &shutdown_func, &description, &charset))
|
||||
if (!PyArg_ParseTuple (args, "sssssss", &name, &author, &version,
|
||||
&license, &description, &shutdown_func, &charset))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("register");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (script_search (weechat_python_plugin, &python_scripts, name))
|
||||
if (script_search (weechat_python_plugin, python_scripts, name))
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
weechat_printf (NULL,
|
||||
@@ -99,7 +99,7 @@ weechat_python_api_register (PyObject *self, PyObject *args)
|
||||
(python_current_script_filename) ?
|
||||
python_current_script_filename : "",
|
||||
name, author, version, license,
|
||||
shutdown_func, description, charset);
|
||||
description, shutdown_func, charset);
|
||||
if (python_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
@@ -109,7 +109,9 @@ weechat_python_api_register (PyObject *self, PyObject *args)
|
||||
name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
@@ -366,7 +368,8 @@ weechat_python_api_prnt (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_printf (weechat_python_plugin, python_current_script,
|
||||
script_api_printf (weechat_python_plugin,
|
||||
python_current_script,
|
||||
script_string_to_pointer (buffer),
|
||||
"%s", message);
|
||||
|
||||
@@ -401,7 +404,8 @@ weechat_python_api_infobar_print (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_infobar_printf (weechat_python_plugin, python_current_script,
|
||||
script_api_infobar_printf (weechat_python_plugin,
|
||||
python_current_script,
|
||||
delay, color, "%s", message);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
@@ -464,7 +468,8 @@ weechat_python_api_log_print (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_log_printf (weechat_python_plugin, python_current_script,
|
||||
script_api_log_printf (weechat_python_plugin,
|
||||
python_current_script,
|
||||
"%s", message);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
@@ -480,7 +485,7 @@ weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[3], empty_arg[1] = { '\0' };
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) argv;
|
||||
@@ -491,16 +496,17 @@ weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
python_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
|
||||
python_argv[2] = NULL;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (python_argv[0])
|
||||
free (python_argv[0]);
|
||||
@@ -543,7 +549,8 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_command (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_command (weechat_python_plugin,
|
||||
python_current_script,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
@@ -565,20 +572,21 @@ weechat_python_api_hook_timer_cb (void *data)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[1] = { NULL };
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -617,7 +625,8 @@ weechat_python_api_hook_timer (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_timer (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_timer (weechat_python_plugin,
|
||||
python_current_script,
|
||||
interval,
|
||||
align_second,
|
||||
max_calls,
|
||||
@@ -637,20 +646,21 @@ weechat_python_api_hook_fd_cb (void *data)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[1] = { NULL };
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -690,7 +700,8 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_fd (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_fd (weechat_python_plugin,
|
||||
python_current_script,
|
||||
fd,
|
||||
read,
|
||||
write,
|
||||
@@ -713,7 +724,7 @@ weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[5];
|
||||
static char timebuffer[64];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -725,16 +736,17 @@ weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
|
||||
python_argv[3] = message;
|
||||
python_argv[4] = NULL;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (python_argv[0])
|
||||
free (python_argv[0]);
|
||||
@@ -775,7 +787,8 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_print (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_print (weechat_python_plugin,
|
||||
python_current_script,
|
||||
script_string_to_pointer (buffer),
|
||||
message,
|
||||
strip_colors,
|
||||
@@ -797,7 +810,7 @@ weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data,
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[3];
|
||||
static char value_str[64];
|
||||
int *r, ret, free_needed;
|
||||
int *rc, ret, free_needed;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -822,16 +835,17 @@ weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data,
|
||||
python_argv[1] = NULL;
|
||||
python_argv[2] = NULL;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (free_needed && python_argv[1])
|
||||
free (python_argv[1]);
|
||||
@@ -868,7 +882,8 @@ weechat_python_api_hook_signal (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_signal (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_signal (weechat_python_plugin,
|
||||
python_current_script,
|
||||
signal,
|
||||
&weechat_python_api_hook_signal_cb,
|
||||
function);
|
||||
@@ -937,7 +952,7 @@ weechat_python_api_hook_config_cb (void *data, char *type, char *option,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[4];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -946,16 +961,17 @@ weechat_python_api_hook_config_cb (void *data, char *type, char *option,
|
||||
python_argv[2] = value;
|
||||
python_argv[3] = NULL;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -991,7 +1007,8 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
new_hook = script_api_hook_config (weechat_python_plugin, python_current_script,
|
||||
new_hook = script_api_hook_config (weechat_python_plugin,
|
||||
python_current_script,
|
||||
type,
|
||||
option,
|
||||
&weechat_python_api_hook_config_cb,
|
||||
@@ -1012,7 +1029,7 @@ weechat_python_api_hook_completion_cb (void *data, char *completion,
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[4];
|
||||
int *r, ret;
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
@@ -1021,16 +1038,17 @@ weechat_python_api_hook_completion_cb (void *data, char *completion,
|
||||
python_argv[2] = script_pointer_to_string (list);
|
||||
python_argv[3] = NULL;
|
||||
|
||||
r = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
if (!r)
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (!rc)
|
||||
ret = WEECHAT_RC_ERROR;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
ret = *rc;
|
||||
free (rc);
|
||||
}
|
||||
if (python_argv[1])
|
||||
free (python_argv[1]);
|
||||
@@ -1105,7 +1123,8 @@ weechat_python_api_unhook (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (script_api_unhook (weechat_python_plugin, python_current_script,
|
||||
if (script_api_unhook (weechat_python_plugin,
|
||||
python_current_script,
|
||||
script_string_to_pointer (hook)))
|
||||
PYTHON_RETURN_OK;
|
||||
|
||||
@@ -1129,7 +1148,8 @@ weechat_python_api_unhook_all (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_unhook_all (weechat_python_plugin, python_current_script);
|
||||
script_api_unhook_all (weechat_python_plugin,
|
||||
python_current_script);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
@@ -1201,7 +1221,8 @@ weechat_python_api_buffer_new (PyObject *self, PyObject *args)
|
||||
|
||||
new_buffer = script_api_buffer_new (weechat_python_plugin,
|
||||
python_current_script,
|
||||
category, name,
|
||||
category,
|
||||
name,
|
||||
&weechat_python_api_input_data_cb,
|
||||
function);
|
||||
|
||||
@@ -1273,7 +1294,8 @@ weechat_python_api_buffer_close (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_buffer_close (weechat_python_plugin, python_current_script,
|
||||
script_api_buffer_close (weechat_python_plugin,
|
||||
python_current_script,
|
||||
script_string_to_pointer (buffer),
|
||||
switch_to_another);
|
||||
|
||||
@@ -1339,7 +1361,9 @@ weechat_python_api_buffer_set (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
weechat_buffer_set (script_string_to_pointer (buffer), property, value);
|
||||
weechat_buffer_set (script_string_to_pointer (buffer),
|
||||
property,
|
||||
value);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
@@ -1380,7 +1404,9 @@ weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args)
|
||||
|
||||
new_group = weechat_nicklist_add_group (script_string_to_pointer (buffer),
|
||||
script_string_to_pointer (parent_group),
|
||||
name, color, visible);
|
||||
name,
|
||||
color,
|
||||
visible);
|
||||
|
||||
result = script_pointer_to_string (new_group);
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
@@ -1432,8 +1458,8 @@ static PyObject *
|
||||
weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
|
||||
{
|
||||
struct t_gui_nick *new_nick;
|
||||
char *buffer, *group, *name, *color, *str_prefix, *prefix_color, *result;
|
||||
char prefix;
|
||||
char *buffer, *group, *name, *color, *prefix, *prefix_color, *result;
|
||||
char char_prefix;
|
||||
int visible;
|
||||
PyObject *object;
|
||||
|
||||
@@ -1450,25 +1476,28 @@ weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
|
||||
group = NULL;
|
||||
name = NULL;
|
||||
color = NULL;
|
||||
str_prefix = NULL;
|
||||
prefix = NULL;
|
||||
prefix_color = NULL;
|
||||
visible = 0;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssssssi", &buffer, &group, &name, &color,
|
||||
&str_prefix, &prefix_color, &visible))
|
||||
&prefix, &prefix_color, &visible))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("nicklist_add_nick");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (str_prefix && str_prefix[0])
|
||||
prefix = str_prefix[0];
|
||||
if (prefix && prefix[0])
|
||||
char_prefix = prefix[0];
|
||||
else
|
||||
prefix = ' ';
|
||||
char_prefix = ' ';
|
||||
|
||||
new_nick = weechat_nicklist_add_nick (script_string_to_pointer (buffer),
|
||||
script_string_to_pointer (group),
|
||||
name, color, prefix, prefix_color,
|
||||
name,
|
||||
color,
|
||||
char_prefix,
|
||||
prefix_color,
|
||||
visible);
|
||||
|
||||
result = script_pointer_to_string (new_nick);
|
||||
@@ -1637,8 +1666,10 @@ weechat_python_api_command (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
script_api_command (weechat_python_plugin, python_current_script,
|
||||
script_string_to_pointer (buffer), command);
|
||||
script_api_command (weechat_python_plugin,
|
||||
python_current_script,
|
||||
script_string_to_pointer (buffer),
|
||||
command);
|
||||
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
@@ -2658,42 +2689,42 @@ weechat_python_api_get_buffer_data (PyObject *self, PyObject *args)
|
||||
|
||||
PyMethodDef weechat_python_funcs[] =
|
||||
{
|
||||
{ "register", weechat_python_api_register, METH_VARARGS, "" },
|
||||
{ "charset_set", weechat_python_api_charset_set, METH_VARARGS, "" },
|
||||
{ "iconv_to_internal", weechat_python_api_iconv_to_internal, METH_VARARGS, "" },
|
||||
{ "iconv_from_internal", weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
|
||||
{ "mkdir_home", weechat_python_api_mkdir_home, METH_VARARGS, "" },
|
||||
{ "mkdir", weechat_python_api_mkdir, METH_VARARGS, "" },
|
||||
{ "prefix", weechat_python_api_prefix, METH_VARARGS, "" },
|
||||
{ "color", weechat_python_api_color, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_api_prnt, METH_VARARGS, "" },
|
||||
{ "infobar_print", weechat_python_api_infobar_print, METH_VARARGS, "" },
|
||||
{ "infobar_remove", weechat_python_api_infobar_remove, METH_VARARGS, "" },
|
||||
{ "log_print", weechat_python_api_log_print, METH_VARARGS, "" },
|
||||
{ "hook_command", weechat_python_api_hook_command, METH_VARARGS, "" },
|
||||
{ "hook_timer", weechat_python_api_hook_timer, METH_VARARGS, "" },
|
||||
{ "hook_fd", weechat_python_api_hook_fd, METH_VARARGS, "" },
|
||||
{ "hook_print", weechat_python_api_hook_print, METH_VARARGS, "" },
|
||||
{ "hook_signal", weechat_python_api_hook_signal, METH_VARARGS, "" },
|
||||
{ "hook_signal_send", weechat_python_api_hook_signal_send, METH_VARARGS, "" },
|
||||
{ "hook_config", weechat_python_api_hook_config, METH_VARARGS, "" },
|
||||
{ "hook_completion", weechat_python_api_hook_completion, METH_VARARGS, "" },
|
||||
{ "unhook", weechat_python_api_unhook, METH_VARARGS, "" },
|
||||
{ "unhook_all", weechat_python_api_unhook_all, METH_VARARGS, "" },
|
||||
{ "buffer_new", weechat_python_api_buffer_new, METH_VARARGS, "" },
|
||||
{ "buffer_search", weechat_python_api_buffer_search, METH_VARARGS, "" },
|
||||
{ "buffer_close", weechat_python_api_buffer_close, METH_VARARGS, "" },
|
||||
{ "buffer_get", weechat_python_api_buffer_get, METH_VARARGS, "" },
|
||||
{ "buffer_set", weechat_python_api_buffer_set, METH_VARARGS, "" },
|
||||
{ "nicklist_add_group", weechat_python_api_nicklist_add_group, METH_VARARGS, "" },
|
||||
{ "nicklist_search_group", weechat_python_api_nicklist_search_group, METH_VARARGS, "" },
|
||||
{ "nicklist_add_nick", weechat_python_api_nicklist_add_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_search_nick", weechat_python_api_nicklist_search_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_group", weechat_python_api_nicklist_remove_group, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_nick", weechat_python_api_nicklist_remove_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_all", weechat_python_api_nicklist_remove_all, METH_VARARGS, "" },
|
||||
{ "command", weechat_python_api_command, METH_VARARGS, "" },
|
||||
{ "info_get", weechat_python_api_info_get, METH_VARARGS, "" },
|
||||
{ "register", &weechat_python_api_register, METH_VARARGS, "" },
|
||||
{ "charset_set", &weechat_python_api_charset_set, METH_VARARGS, "" },
|
||||
{ "iconv_to_internal", &weechat_python_api_iconv_to_internal, METH_VARARGS, "" },
|
||||
{ "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
|
||||
{ "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
|
||||
{ "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
|
||||
{ "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
|
||||
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
|
||||
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
|
||||
{ "infobar_print", &weechat_python_api_infobar_print, METH_VARARGS, "" },
|
||||
{ "infobar_remove", &weechat_python_api_infobar_remove, METH_VARARGS, "" },
|
||||
{ "log_print", &weechat_python_api_log_print, METH_VARARGS, "" },
|
||||
{ "hook_command", &weechat_python_api_hook_command, METH_VARARGS, "" },
|
||||
{ "hook_timer", &weechat_python_api_hook_timer, METH_VARARGS, "" },
|
||||
{ "hook_fd", &weechat_python_api_hook_fd, METH_VARARGS, "" },
|
||||
{ "hook_print", &weechat_python_api_hook_print, METH_VARARGS, "" },
|
||||
{ "hook_signal", &weechat_python_api_hook_signal, METH_VARARGS, "" },
|
||||
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
|
||||
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
|
||||
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
|
||||
{ "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
|
||||
{ "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" },
|
||||
{ "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
|
||||
{ "buffer_search", &weechat_python_api_buffer_search, METH_VARARGS, "" },
|
||||
{ "buffer_close", &weechat_python_api_buffer_close, METH_VARARGS, "" },
|
||||
{ "buffer_get", &weechat_python_api_buffer_get, METH_VARARGS, "" },
|
||||
{ "buffer_set", &weechat_python_api_buffer_set, METH_VARARGS, "" },
|
||||
{ "nicklist_add_group", &weechat_python_api_nicklist_add_group, METH_VARARGS, "" },
|
||||
{ "nicklist_search_group", &weechat_python_api_nicklist_search_group, METH_VARARGS, "" },
|
||||
{ "nicklist_add_nick", &weechat_python_api_nicklist_add_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_search_nick", &weechat_python_api_nicklist_search_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_group", &weechat_python_api_nicklist_remove_group, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_nick", &weechat_python_api_nicklist_remove_nick, METH_VARARGS, "" },
|
||||
{ "nicklist_remove_all", &weechat_python_api_nicklist_remove_all, METH_VARARGS, "" },
|
||||
{ "command", &weechat_python_api_command, METH_VARARGS, "" },
|
||||
{ "info_get", &weechat_python_api_info_get, METH_VARARGS, "" },
|
||||
/*
|
||||
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
|
||||
{ "get_config", weechat_python_get_config, METH_VARARGS, "" },
|
||||
|
||||
@@ -25,14 +25,6 @@
|
||||
#endif
|
||||
|
||||
#include <Python.h>
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
//#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../script.h"
|
||||
@@ -46,7 +38,7 @@ WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION("0.1");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
|
||||
struct t_weechat_plugin *weechat_python_plugin;
|
||||
struct t_weechat_plugin *weechat_python_plugin = NULL;
|
||||
|
||||
struct t_plugin_script *python_scripts = NULL;
|
||||
struct t_plugin_script *python_current_script = NULL;
|
||||
@@ -256,9 +248,6 @@ weechat_python_load (char *filename)
|
||||
char *w_home, *p_home;
|
||||
int len;
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "python", filename);
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
@@ -267,6 +256,10 @@ weechat_python_load (char *filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "python", filename);
|
||||
|
||||
python_current_script = NULL;
|
||||
|
||||
/* PyEval_AcquireLock (); */
|
||||
@@ -460,7 +453,7 @@ weechat_python_unload_name (char *name)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = script_search (weechat_python_plugin, &python_scripts, name);
|
||||
ptr_script = script_search (weechat_python_plugin, python_scripts, name);
|
||||
if (ptr_script)
|
||||
{
|
||||
weechat_python_unload (ptr_script);
|
||||
@@ -490,7 +483,7 @@ weechat_python_unload_all ()
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_cmd: /python command handler
|
||||
* weechat_python_cmd: callback for "/python" command
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -533,7 +526,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// List Python message handlers
|
||||
// list Python message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python message handlers:");
|
||||
handler_found = 0;
|
||||
@@ -552,7 +545,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Python command handlers
|
||||
// list Python command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python command handlers:");
|
||||
handler_found = 0;
|
||||
@@ -571,7 +564,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Python timer handlers
|
||||
// list Python timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python timer handlers:");
|
||||
handler_found = 0;
|
||||
@@ -590,7 +583,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Python keyboard handlers
|
||||
// list Python keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python keyboard handlers:");
|
||||
handler_found = 0;
|
||||
@@ -608,7 +601,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Python event handlers
|
||||
// list Python event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python event handlers:");
|
||||
handler_found = 0;
|
||||
@@ -627,7 +620,7 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// List Python modifiers
|
||||
// list Python modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python modifiers:");
|
||||
modifier_found = 0;
|
||||
@@ -659,14 +652,14 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_python_plugin, "python",
|
||||
&weechat_python_load_cb);
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_python_unload_all ();
|
||||
script_auto_load (weechat_python_plugin, "python",
|
||||
&weechat_python_load_cb);
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
@@ -701,6 +694,25 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_dump_data_cb: dump Python plugin data in WeeChat log file
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_dump_data_cb (void *data, char *signal, char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
script_print_log (weechat_python_plugin, python_scripts);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Python plugin
|
||||
*/
|
||||
@@ -752,9 +764,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_mkdir_home ("python", 0644);
|
||||
weechat_mkdir_home ("python/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_python_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_python_plugin);
|
||||
script_auto_load (weechat_python_plugin, "python",
|
||||
&weechat_python_load_cb);
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#ifndef __WEECHAT_PYTHON_H
|
||||
#define __WEECHAT_PYTHON_H 1
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
|
||||
#define weechat_plugin weechat_python_plugin
|
||||
|
||||
extern struct t_weechat_plugin *weechat_python_plugin;
|
||||
|
||||
@@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = ruby.la
|
||||
|
||||
ruby_la_SOURCES = ruby.c
|
||||
ruby_la_SOURCES = weechat-ruby.c \
|
||||
weechat-ruby.h \
|
||||
weechat-ruby-api.c \
|
||||
weechat-ruby-api.h
|
||||
ruby_la_LDFLAGS = -module
|
||||
ruby_la_LIBADD = ../lib_weechat_plugins_scripts.la $(RUBY_LFLAGS)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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_RUBY_API_H
|
||||
#define __WEECHAT_RUBY_API_H 1
|
||||
|
||||
extern void weechat_ruby_api_init (VALUE ruby_mWeechat);
|
||||
|
||||
#endif /* weechat-ruby.h */
|
||||
@@ -0,0 +1,845 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* weechat-ruby.c: Ruby plugin for WeeChat */
|
||||
|
||||
#undef _
|
||||
|
||||
#include <ruby.h>
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../script.h"
|
||||
#include "weechat-ruby.h"
|
||||
#include "weechat-ruby-api.h"
|
||||
|
||||
|
||||
WEECHAT_PLUGIN_NAME("ruby");
|
||||
WEECHAT_PLUGIN_DESCRIPTION("Ruby plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION("0.1");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
|
||||
struct t_weechat_plugin *weechat_ruby_plugin = NULL;
|
||||
|
||||
struct t_plugin_script *ruby_scripts = NULL;
|
||||
struct t_plugin_script *ruby_current_script = NULL;
|
||||
char *ruby_current_script_filename = NULL;
|
||||
|
||||
VALUE ruby_mWeechat, ruby_mWeechatOutputs;
|
||||
|
||||
#define MOD_NAME_PREFIX "WeechatRubyModule"
|
||||
int ruby_num = 0;
|
||||
|
||||
char ruby_buffer_output[128];
|
||||
|
||||
typedef struct protect_call_arg {
|
||||
VALUE recv;
|
||||
ID mid;
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
} protect_call_arg_t;
|
||||
|
||||
|
||||
/*
|
||||
* protect_funcall0 : used to protect a function call
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
protect_funcall0(VALUE arg)
|
||||
{
|
||||
return rb_funcall2(((protect_call_arg_t *) arg)->recv,
|
||||
((protect_call_arg_t *) arg)->mid,
|
||||
((protect_call_arg_t *) arg)->argc,
|
||||
((protect_call_arg_t *) arg)->argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* rb_protect_funcall : function call in protect mode
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_protect_funcall (VALUE recv, ID mid, int *state, int argc, ...)
|
||||
{
|
||||
va_list ap;
|
||||
VALUE *argv;
|
||||
struct protect_call_arg arg;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
int i;
|
||||
argv = ALLOCA_N(VALUE, argc);
|
||||
va_start(ap, argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
argv[i] = va_arg(ap, VALUE);
|
||||
va_end(ap);
|
||||
}
|
||||
else
|
||||
argv = 0;
|
||||
arg.recv = recv;
|
||||
arg.mid = mid;
|
||||
arg.argc = argc;
|
||||
arg.argv = argv;
|
||||
return rb_protect(protect_funcall0, (VALUE) &arg, state);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_exec: execute a Ruby script
|
||||
*/
|
||||
|
||||
void *
|
||||
weechat_ruby_exec (struct t_plugin_script *script,
|
||||
int ret_type, char *function, char **argv)
|
||||
{
|
||||
VALUE rc, err;
|
||||
int ruby_error, *ret_i;
|
||||
void *ret_value;
|
||||
|
||||
ruby_current_script = script;
|
||||
|
||||
if (argv && argv[0])
|
||||
{
|
||||
if (argv[1])
|
||||
{
|
||||
if (argv[2])
|
||||
{
|
||||
if (argv[3])
|
||||
{
|
||||
if (argv[4])
|
||||
{
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 5,
|
||||
rb_str_new2(argv[0]),
|
||||
rb_str_new2(argv[1]),
|
||||
rb_str_new2(argv[2]),
|
||||
rb_str_new2(argv[3]),
|
||||
rb_str_new2(argv[4]));
|
||||
}
|
||||
else
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 4,
|
||||
rb_str_new2(argv[0]),
|
||||
rb_str_new2(argv[1]),
|
||||
rb_str_new2(argv[2]),
|
||||
rb_str_new2(argv[3]));
|
||||
}
|
||||
else
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 3,
|
||||
rb_str_new2(argv[0]),
|
||||
rb_str_new2(argv[1]),
|
||||
rb_str_new2(argv[2]));
|
||||
}
|
||||
else
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 2,
|
||||
rb_str_new2(argv[0]),
|
||||
rb_str_new2(argv[1]));
|
||||
}
|
||||
else
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 1,
|
||||
rb_str_new2(argv[0]));
|
||||
}
|
||||
else
|
||||
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 0);
|
||||
|
||||
if (ruby_error)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to run function \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", function);
|
||||
|
||||
err = rb_inspect(rb_gv_get("$!"));
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", STR2CSTR(err));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((TYPE(rc) == T_STRING) && (ret_type == WEECHAT_SCRIPT_EXEC_STRING))
|
||||
{
|
||||
if (STR2CSTR (rc))
|
||||
ret_value = strdup (STR2CSTR (rc));
|
||||
else
|
||||
ret_value = NULL;
|
||||
}
|
||||
else if ((TYPE(rc) == T_FIXNUM) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
|
||||
{
|
||||
ret_i = (int *)malloc (sizeof(int));
|
||||
if (ret_i)
|
||||
*ret_i = NUM2INT(rc);
|
||||
ret_value = ret_i;
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: function \"%s\" must return a "
|
||||
"valid value"),
|
||||
weechat_prefix ("error"), "ruby", function);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (ret_value == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: not enough memory in function "
|
||||
"\"%s\""),
|
||||
weechat_prefix ("error"), "ruby", function);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_output: redirection for stdout and stderr
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_output (VALUE self, VALUE str)
|
||||
{
|
||||
char *msg, *p, *m;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
msg = strdup(STR2CSTR(str));
|
||||
|
||||
m = msg;
|
||||
while ((p = strchr (m, '\n')) != NULL)
|
||||
{
|
||||
*p = '\0';
|
||||
if (strlen (m) + strlen (ruby_buffer_output) > 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: stdout/stderr : %s%s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
ruby_buffer_output, m);
|
||||
}
|
||||
*p = '\n';
|
||||
ruby_buffer_output[0] = '\0';
|
||||
m = ++p;
|
||||
}
|
||||
|
||||
if (strlen(m) + strlen(ruby_buffer_output) > sizeof(ruby_buffer_output))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: stdout/stderr : %s%s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
ruby_buffer_output, m);
|
||||
ruby_buffer_output[0] = '\0';
|
||||
}
|
||||
else
|
||||
strcat (ruby_buffer_output, m);
|
||||
|
||||
if (msg)
|
||||
free (msg);
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_output_flush: just for compatibility
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_output_flush (VALUE self)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* weechat_ruby_load: load a Ruby script
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_load (char *filename)
|
||||
{
|
||||
char modname[64];
|
||||
VALUE curModule, ruby_retcode, err;
|
||||
int ruby_error;
|
||||
struct stat buf;
|
||||
|
||||
if (stat (filename, &buf) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" not found"),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "ruby", filename);
|
||||
|
||||
ruby_current_script = NULL;
|
||||
|
||||
snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num);
|
||||
ruby_num++;
|
||||
|
||||
curModule = rb_define_module(modname);
|
||||
|
||||
ruby_current_script_filename = filename;
|
||||
|
||||
ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"),
|
||||
&ruby_error, 1, rb_str_new2(filename));
|
||||
|
||||
if (ruby_retcode == Qnil)
|
||||
{
|
||||
err = rb_inspect(rb_gv_get("$!"));
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", STR2CSTR(err));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NUM2INT(ruby_retcode) != 0)
|
||||
{
|
||||
VALUE ruby_eval_error;
|
||||
|
||||
switch (NUM2INT(ruby_retcode))
|
||||
{
|
||||
case 1:
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to read file "
|
||||
"\"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
break;
|
||||
case 2:
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error while loading "
|
||||
"file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
break;
|
||||
case 3:
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to find "
|
||||
"\"weechat_init\" function "
|
||||
"in file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
break;
|
||||
}
|
||||
|
||||
if (NUM2INT(ruby_retcode) == 1 || NUM2INT(ruby_retcode) == 2)
|
||||
{
|
||||
ruby_eval_error = rb_iv_get(curModule, "@load_eval_file_error");
|
||||
if (ruby_eval_error)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: %s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
STR2CSTR(ruby_eval_error));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ruby_retcode = rb_protect_funcall (curModule, rb_intern("weechat_init"), &ruby_error, 0);
|
||||
|
||||
if (ruby_error)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to eval "
|
||||
"\"weechat_init\" in file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
|
||||
err = rb_inspect(rb_gv_get("$!"));
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", STR2CSTR(err));
|
||||
|
||||
if (ruby_current_script != NULL)
|
||||
{
|
||||
script_remove (weechat_ruby_plugin,
|
||||
&ruby_scripts, ruby_current_script);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ruby_current_script == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: function \"register\" not "
|
||||
"found (or failed) in file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ruby_current_script->interpreter = (VALUE *) curModule;
|
||||
rb_gc_register_address (ruby_current_script->interpreter);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_load_cb: callback for weechat_script_auto_load() function
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_load_cb (void *data, char *filename)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
return weechat_ruby_load (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_unload: unload a Ruby script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_ruby_unload (struct t_plugin_script *script)
|
||||
{
|
||||
int *r;
|
||||
char *ruby_argv[1] = { NULL };
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "ruby", script->name);
|
||||
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
{
|
||||
r = (int *) weechat_ruby_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script->shutdown_func,
|
||||
ruby_argv);
|
||||
if (r)
|
||||
free (r);
|
||||
}
|
||||
|
||||
if (script->interpreter)
|
||||
rb_gc_unregister_address (script->interpreter);
|
||||
|
||||
script_remove (weechat_ruby_plugin, &ruby_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_unload_name: unload a Ruby script by name
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_ruby_unload_name (char *name)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name);
|
||||
if (ptr_script)
|
||||
{
|
||||
weechat_ruby_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "ruby", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" not loaded"),
|
||||
weechat_prefix ("error"), "ruby", name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_unload_all: unload all Ruby scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_ruby_unload_all ()
|
||||
{
|
||||
while (ruby_scripts)
|
||||
{
|
||||
weechat_ruby_unload (ruby_scripts);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_command_cb: callback for "/ruby" command
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//t_plugin_handler *ptr_handler;
|
||||
//t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Ruby scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"ruby");
|
||||
if (ruby_scripts)
|
||||
{
|
||||
for (ptr_script = ruby_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Ruby message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Ruby(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Ruby(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Ruby(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Ruby(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Ruby(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
*/
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_ruby_unload_all ();
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
weechat_ruby_unload_all ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Ruby script */
|
||||
path_script = script_search_full_name (weechat_ruby_plugin,
|
||||
"ruby", argv_eol[2]);
|
||||
weechat_ruby_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
/* unload Ruby script */
|
||||
weechat_ruby_unload_name (argv_eol[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unknown option for "
|
||||
"command \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", "ruby");
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_dump_data_cb: dump Ruby plugin data in WeeChat log file
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_dump_data_cb (void *data, char *signal, char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
script_print_log (weechat_ruby_plugin, ruby_scripts);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Ruby plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
int ruby_error;
|
||||
char *weechat_ruby_code =
|
||||
{
|
||||
"$stdout = WeechatOutputs\n"
|
||||
"$stderr = WeechatOutputs\n"
|
||||
"\n"
|
||||
"class Module\n"
|
||||
" @load_eval_file_error = ''\n"
|
||||
"\n"
|
||||
" def load_eval_file (file)\n"
|
||||
" lines = ''\n"
|
||||
" begin\n"
|
||||
" f = File.open(file, 'r')\n"
|
||||
" lines = f.readlines.join\n"
|
||||
" rescue => e\n"
|
||||
" @load_eval_file_error = e\n"
|
||||
" return 1\n"
|
||||
" end\n"
|
||||
"\n"
|
||||
" begin\n"
|
||||
" module_eval(lines)\n"
|
||||
" rescue => e\n"
|
||||
" @load_eval_file_error = e\n"
|
||||
" return 2\n"
|
||||
" end\n"
|
||||
"\n"
|
||||
" has_init = false\n"
|
||||
"\n"
|
||||
" instance_methods.each do |meth|\n"
|
||||
" if meth == 'weechat_init'\n"
|
||||
" has_init = true\n"
|
||||
" end\n"
|
||||
" module_eval('module_function :' + meth)\n"
|
||||
" end\n"
|
||||
"\n"
|
||||
" unless has_init\n"
|
||||
" return 3\n"
|
||||
" end\n"
|
||||
"\n"
|
||||
" return 0\n"
|
||||
" end\n"
|
||||
"end\n"
|
||||
};
|
||||
|
||||
weechat_ruby_plugin = plugin;
|
||||
|
||||
ruby_error = 0;
|
||||
|
||||
/* init stdout/stderr buffer */
|
||||
ruby_buffer_output[0] = '\0';
|
||||
|
||||
ruby_init ();
|
||||
ruby_init_loadpath ();
|
||||
ruby_script ("__weechat_plugin__");
|
||||
|
||||
ruby_mWeechat = rb_define_module("Weechat");
|
||||
weechat_ruby_api_init (ruby_mWeechat);
|
||||
|
||||
/* redirect stdin and stdout */
|
||||
ruby_mWeechatOutputs = rb_define_module("WeechatOutputs");
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1);
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "puts", weechat_ruby_output, 1);
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "p", weechat_ruby_output, 1);
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "flush", weechat_ruby_output_flush, 0);
|
||||
|
||||
rb_eval_string_protect(weechat_ruby_code, &ruby_error);
|
||||
if (ruby_error)
|
||||
{
|
||||
VALUE ruby_error_info = rb_inspect(ruby_errinfo);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to eval weechat ruby "
|
||||
"internal code"),
|
||||
weechat_prefix ("error"), "ruby");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: %s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
STR2CSTR(ruby_error_info));
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
weechat_hook_command ("ruby",
|
||||
weechat_gettext ("list/load/unload Ruby scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Ruby script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /ruby command "
|
||||
"lists all loaded Ruby scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_ruby_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("ruby", 0644);
|
||||
weechat_mkdir_home ("ruby/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_ruby_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_ruby_plugin);
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Ruby interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
/* unload all scripts */
|
||||
weechat_ruby_unload_all ();
|
||||
|
||||
ruby_finalize();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_RUBY_H
|
||||
#define __WEECHAT_RUBY_H 1
|
||||
|
||||
#define weechat_plugin weechat_ruby_plugin
|
||||
|
||||
extern struct t_weechat_plugin *weechat_ruby_plugin;
|
||||
|
||||
extern struct t_plugin_script *ruby_scripts;
|
||||
extern struct t_plugin_script *ruby_current_script;
|
||||
extern char *ruby_current_script_filename;
|
||||
|
||||
extern void * weechat_ruby_exec (struct t_plugin_script *script,
|
||||
int ret_type, char *function, char **argv);
|
||||
|
||||
#endif /* weechat-perl.h */
|
||||
@@ -453,6 +453,9 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_script_callback *new_script_callback;
|
||||
struct t_gui_buffer *new_buffer;
|
||||
|
||||
if (!function || !function[0])
|
||||
return weechat_buffer_new (category, name, NULL, NULL);
|
||||
|
||||
new_script_callback = script_callback_alloc ();
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
@@ -105,3 +105,21 @@ script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
|
||||
script_callback_remove (weechat_plugin, script, script->callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* script_callback_print_log: print callback infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
void
|
||||
script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_script_callback *script_callback)
|
||||
{
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf ("[callback (addr:0x%x)]", script_callback);
|
||||
weechat_log_printf (" script. . . . . . . : 0x%x", script_callback->script);
|
||||
weechat_log_printf (" function. . . . . . : '%s'", script_callback->function);
|
||||
weechat_log_printf (" hook. . . . . . . . : 0x%x", script_callback->hook);
|
||||
weechat_log_printf (" buffer. . . . . . . : 0x%x", script_callback->buffer);
|
||||
weechat_log_printf (" prev_callback . . . : 0x%x", script_callback->prev_callback);
|
||||
weechat_log_printf (" next_callback . . . : 0x%x", script_callback->next_callback);
|
||||
}
|
||||
|
||||
@@ -37,5 +37,7 @@ extern void script_callback_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_script_callback *script_callback);
|
||||
extern void script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script);
|
||||
extern void script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_script_callback *script_callback);
|
||||
|
||||
#endif /* script-callback.h */
|
||||
|
||||
@@ -38,7 +38,7 @@ int script_option_check_license = 0;
|
||||
|
||||
|
||||
/*
|
||||
* script_config_read: read config options
|
||||
* script_config_read: read script configuration
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -65,6 +65,7 @@ script_config_read (struct t_weechat_plugin *weechat_plugin)
|
||||
int
|
||||
script_config_cb (void *data, char *type, char *option, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) type;
|
||||
(void) option;
|
||||
(void) value;
|
||||
@@ -84,8 +85,10 @@ script_init (struct t_weechat_plugin *weechat_plugin)
|
||||
char *option;
|
||||
int length;
|
||||
|
||||
/* read script configuration */
|
||||
script_config_read (weechat_plugin);
|
||||
|
||||
/* add hook for config option */
|
||||
length = strlen (weechat_plugin->name) + 32;
|
||||
option= (char *)malloc (length);
|
||||
if (option)
|
||||
@@ -93,7 +96,7 @@ script_init (struct t_weechat_plugin *weechat_plugin)
|
||||
snprintf (option, length - 1, "%s.%s",
|
||||
weechat_plugin->name, SCRIPT_OPTION_CHECK_LICENSE);
|
||||
weechat_hook_config ("plugin", option,
|
||||
&script_config_cb, (void *)weechat_plugin);
|
||||
&script_config_cb, weechat_plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +144,7 @@ script_string_to_pointer (char *pointer_str)
|
||||
|
||||
void
|
||||
script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
char *language,
|
||||
int (*callback)(void *data, char *filename))
|
||||
char *language, int (*callback)(void *data, char *filename))
|
||||
{
|
||||
char *dir_home, *dir_name;
|
||||
int dir_length;
|
||||
@@ -168,11 +170,11 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
|
||||
struct t_plugin_script *
|
||||
script_search (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **list, char *name)
|
||||
struct t_plugin_script *scripts, char *name)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
for (ptr_script = *list; ptr_script;
|
||||
for (ptr_script = scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (weechat_strcasecmp (ptr_script->name, name) == 0)
|
||||
@@ -275,10 +277,10 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
|
||||
struct t_plugin_script *
|
||||
script_add (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **script_list,
|
||||
char *filename,
|
||||
char *name, char *author, char *version, char *license,
|
||||
char *shutdown_func, char *description, char *charset)
|
||||
struct t_plugin_script **scripts,
|
||||
char *filename, char *name, char *author, char *version,
|
||||
char *license, char *description, char *shutdown_func,
|
||||
char *charset)
|
||||
{
|
||||
struct t_plugin_script *new_script;
|
||||
|
||||
@@ -319,11 +321,11 @@ script_add (struct t_weechat_plugin *weechat_plugin,
|
||||
new_script->callbacks = NULL;
|
||||
|
||||
/* add new script to list */
|
||||
if ((*script_list))
|
||||
(*script_list)->prev_script = new_script;
|
||||
if (*scripts)
|
||||
(*scripts)->prev_script = new_script;
|
||||
new_script->prev_script = NULL;
|
||||
new_script->next_script = (*script_list);
|
||||
(*script_list) = new_script;
|
||||
new_script->next_script = *scripts;
|
||||
*scripts = new_script;
|
||||
|
||||
return new_script;
|
||||
}
|
||||
@@ -341,7 +343,7 @@ script_add (struct t_weechat_plugin *weechat_plugin,
|
||||
|
||||
void
|
||||
script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **script_list,
|
||||
struct t_plugin_script **scripts,
|
||||
struct t_plugin_script *script)
|
||||
{
|
||||
/* remove all callbacks created by this script */
|
||||
@@ -365,10 +367,55 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
if (script->prev_script)
|
||||
(script->prev_script)->next_script = script->next_script;
|
||||
else
|
||||
(*script_list) = script->next_script;
|
||||
*scripts = script->next_script;
|
||||
if (script->next_script)
|
||||
(script->next_script)->prev_script = script->prev_script;
|
||||
|
||||
/* free script */
|
||||
free (script);
|
||||
}
|
||||
|
||||
/*
|
||||
* script_print_log: print script infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
void
|
||||
script_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
struct t_script_callback *ptr_script_callback;
|
||||
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf ("***** \"%s\" plugin dump *****",
|
||||
weechat_plugin->name);
|
||||
|
||||
for (ptr_script = scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf ("[script %s (addr:0x%x)]", ptr_script->name, ptr_script);
|
||||
weechat_log_printf (" filename. . . . . . : '%s'", ptr_script->filename);
|
||||
weechat_log_printf (" interpreter . . . . : 0x%x", ptr_script->interpreter);
|
||||
weechat_log_printf (" name. . . . . . . . : '%s'", ptr_script->name);
|
||||
weechat_log_printf (" author. . . . . . . : '%s'", ptr_script->author);
|
||||
weechat_log_printf (" version . . . . . . : '%s'", ptr_script->version);
|
||||
weechat_log_printf (" license . . . . . . : '%s'", ptr_script->license);
|
||||
weechat_log_printf (" description . . . . : '%s'", ptr_script->description);
|
||||
weechat_log_printf (" shutdown_func . . . : '%s'", ptr_script->shutdown_func);
|
||||
weechat_log_printf (" charset . . . . . . : '%s'", ptr_script->charset);
|
||||
weechat_log_printf (" callbacks . . . . . : 0x%x", ptr_script->callbacks);
|
||||
weechat_log_printf (" prev_script . . . . : 0x%x", ptr_script->prev_script);
|
||||
weechat_log_printf (" next_script . . . . : 0x%x", ptr_script->next_script);
|
||||
|
||||
for (ptr_script_callback = ptr_script->callbacks; ptr_script_callback;
|
||||
ptr_script_callback = ptr_script_callback->next_callback)
|
||||
{
|
||||
script_callback_print_log (weechat_plugin, ptr_script_callback);
|
||||
}
|
||||
}
|
||||
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf ("***** End of \"%s\" plugin dump *****",
|
||||
weechat_plugin->name);
|
||||
}
|
||||
|
||||
@@ -63,19 +63,20 @@ 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,
|
||||
struct t_plugin_script *scripts,
|
||||
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,
|
||||
struct t_plugin_script **scripts,
|
||||
char *filename, char *name,
|
||||
char *author, char *version,
|
||||
char *license, char *shutdown_func,
|
||||
char *description,
|
||||
char *charset);
|
||||
char *license, char *description,
|
||||
char *shutdown_func, char *charset);
|
||||
extern void script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **script_list,
|
||||
struct t_plugin_script **scripts,
|
||||
struct t_plugin_script *script);
|
||||
extern void script_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts);
|
||||
|
||||
#endif /* script.h */
|
||||
|
||||
Reference in New Issue
Block a user