mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 08:13:14 +02:00
Improved Perl interface and some changes in Python:
- function "print_with_channel" was removed - function "command" now runs weechat command or send text to channel - Perl functions are now called with weechat::name (instead of IRC::name) - IRC::xxx functions are still active for compatibility with old scripts
This commit is contained in:
+408
-23
@@ -45,10 +45,14 @@ t_plugin_script *last_perl_script = NULL;
|
||||
extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
|
||||
/******************************* Old interface ********************************/
|
||||
|
||||
/*
|
||||
* IRC::register: startup function for all WeeChat Perl scripts
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
@@ -78,12 +82,12 @@ static XS (XS_IRC_register)
|
||||
|
||||
if (perl_script_found)
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
/* error: another script already exists with this name! */
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: unable to register Perl script \"%s\" (another script "
|
||||
_("%s error: unable to register \"%s\" script (another script "
|
||||
"already exists with this name)\n"),
|
||||
name);
|
||||
"Perl", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -105,15 +109,15 @@ static XS (XS_IRC_register)
|
||||
perl_scripts = new_perl_script;
|
||||
last_perl_script = new_perl_script;
|
||||
|
||||
wee_log_printf (_("registered Perl script: \"%s\", version %s (%s)\n"),
|
||||
name, version, description);
|
||||
wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
|
||||
"Perl", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unable to load Perl script \"%s\" (not enough memory)\n"),
|
||||
WEECHAT_ERROR, name);
|
||||
_("%s error: unable to load script \"%s\" (not enough memory)\n"),
|
||||
"Perl", name);
|
||||
}
|
||||
}
|
||||
XST_mPV (0, VERSION);
|
||||
@@ -124,6 +128,8 @@ static XS (XS_IRC_register)
|
||||
* IRC::print: print message to current buffer
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_print)
|
||||
{
|
||||
int i, integer;
|
||||
@@ -148,6 +154,8 @@ static XS (XS_IRC_print)
|
||||
* (server is optional)
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_print_with_channel)
|
||||
{
|
||||
int integer;
|
||||
@@ -207,6 +215,8 @@ static XS (XS_IRC_print_with_channel)
|
||||
* IRC::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_print_infobar)
|
||||
{
|
||||
int integer;
|
||||
@@ -221,7 +231,8 @@ static XS (XS_IRC_print_infobar)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: wrong parameters for IRC::print_infobar Perl function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "print_infobar");
|
||||
}
|
||||
|
||||
XSRETURN_EMPTY;
|
||||
@@ -231,6 +242,8 @@ static XS (XS_IRC_print_infobar)
|
||||
* IRC::command: send command to server
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_command)
|
||||
{
|
||||
int integer;
|
||||
@@ -254,7 +267,8 @@ static XS (XS_IRC_command)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: server not found for IRC::command Perl function\n"));
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Perl", "command");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -280,6 +294,8 @@ static XS (XS_IRC_command)
|
||||
* IRC::add_message_handler: add handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_add_message_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
@@ -301,6 +317,8 @@ static XS (XS_IRC_add_message_handler)
|
||||
* IRC::add_command_handler: add command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_add_command_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
@@ -332,6 +350,8 @@ static XS (XS_IRC_add_command_handler)
|
||||
* IRC::get_info: get various infos
|
||||
*/
|
||||
|
||||
/*** DEPRECATED function, kept for compatibility only, please don't update! ***/
|
||||
|
||||
static XS (XS_IRC_get_info)
|
||||
{
|
||||
char *arg, *info = NULL, *server;
|
||||
@@ -355,7 +375,8 @@ static XS (XS_IRC_get_info)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: server not found for IRC::get_info Perl function\n"));
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Perl", "get_info");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -406,6 +427,355 @@ static XS (XS_IRC_get_info)
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/******************************* New interface ********************************/
|
||||
|
||||
/*
|
||||
* weechat::register: startup function for all WeeChat Perl scripts
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
int integer;
|
||||
t_plugin_script *ptr_perl_script, *perl_script_found, *new_perl_script;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) items;
|
||||
(void) cv;
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
version = SvPV (ST (1), integer);
|
||||
shutdown_func = SvPV (ST (2), integer);
|
||||
description = SvPV (ST (3), integer);
|
||||
|
||||
perl_script_found = NULL;
|
||||
for (ptr_perl_script = perl_scripts; ptr_perl_script;
|
||||
ptr_perl_script = ptr_perl_script->next_script)
|
||||
{
|
||||
if (strcasecmp (ptr_perl_script->name, name) == 0)
|
||||
{
|
||||
perl_script_found = ptr_perl_script;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (perl_script_found)
|
||||
{
|
||||
/* error: another script already exists with this name! */
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to register \"%s\" script (another script "
|
||||
"already exists with this name)\n"),
|
||||
"Perl", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* registering script */
|
||||
new_perl_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
|
||||
if (new_perl_script)
|
||||
{
|
||||
new_perl_script->name = strdup (name);
|
||||
new_perl_script->version = strdup (version);
|
||||
new_perl_script->shutdown_func = strdup (shutdown_func);
|
||||
new_perl_script->description = strdup (description);
|
||||
|
||||
/* add new script to list */
|
||||
new_perl_script->prev_script = last_perl_script;
|
||||
new_perl_script->next_script = NULL;
|
||||
if (perl_scripts)
|
||||
last_perl_script->next_script = new_perl_script;
|
||||
else
|
||||
perl_scripts = new_perl_script;
|
||||
last_perl_script = new_perl_script;
|
||||
|
||||
wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
|
||||
"Perl", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: unable to load script \"%s\" (not enough memory)\n"),
|
||||
"Perl", name);
|
||||
}
|
||||
}
|
||||
XST_mPV (0, VERSION);
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
{
|
||||
int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "print");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
ptr_buffer = plugin_find_buffer (server_name, channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
message = SvPV (ST (0), integer);
|
||||
irc_display_prefix (ptr_buffer, PREFIX_PLUGIN);
|
||||
gui_printf (ptr_buffer, "%s%s",
|
||||
message,
|
||||
((strlen (message) == 0) || (message[strlen (message) - 1] != '\n')) ? "\n" : "");
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_infobar)
|
||||
{
|
||||
int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "print_infobar");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
gui_infobar_printf (SvIV (ST (0)), COLOR_WIN_INFOBAR, SvPV (ST (1), integer));
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::command: send command to server
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_command)
|
||||
{
|
||||
int integer;
|
||||
char *command, *channel_name, *server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "command");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
}
|
||||
|
||||
ptr_buffer = plugin_find_buffer (server_name, channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
command = SvPV (ST (0), integer);
|
||||
user_command (SERVER(ptr_buffer), ptr_buffer, command);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/* buffer not found */
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_message_handler: add handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "add_message_handler");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler,
|
||||
PLUGIN_TYPE_PERL, name, function);
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_command_handler: add command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_command_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
int integer;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "add_command_handler");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
if (!weelist_search (index_commands, name))
|
||||
weelist_add (&index_commands, &last_index_command, name);
|
||||
ptr_plugin_handler = plugin_handler_search (plugin_cmd_handlers, name);
|
||||
if (ptr_plugin_handler)
|
||||
{
|
||||
free (ptr_plugin_handler->function_name);
|
||||
ptr_plugin_handler->function_name = strdup (function);
|
||||
}
|
||||
else
|
||||
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_PERL, name, function);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_info: get various infos
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_info)
|
||||
{
|
||||
char *arg, *info = NULL, *server_name;
|
||||
t_irc_server *ptr_server;
|
||||
int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if ((items < 1) || (items > 2))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Perl", "get_info");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items == 2)
|
||||
{
|
||||
server_name = SvPV (ST (1), integer);
|
||||
ptr_server = server_search (server_name);
|
||||
}
|
||||
else
|
||||
ptr_server = SERVER(gui_current_window->buffer);
|
||||
|
||||
if (!ptr_server)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Perl", "get_info");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
arg = SvPV (ST (0), integer);
|
||||
if (arg)
|
||||
{
|
||||
if ( (strcasecmp (arg, "0") == 0) || (strcasecmp (arg, "version") == 0) )
|
||||
{
|
||||
info = PACKAGE_STRING;
|
||||
}
|
||||
else if ( (strcasecmp (arg, "1") == 0) || (strcasecmp (arg, "nick") == 0) )
|
||||
{
|
||||
if (ptr_server->nick)
|
||||
info = ptr_server->nick;
|
||||
}
|
||||
else if ( (strcasecmp (arg, "2") == 0) || (strcasecmp (arg, "channel") == 0) )
|
||||
{
|
||||
if (BUFFER_IS_CHANNEL (gui_current_window->buffer))
|
||||
info = CHANNEL (gui_current_window->buffer)->name;
|
||||
}
|
||||
else if ( (strcasecmp (arg, "3") == 0) || (strcasecmp (arg, "server") == 0) )
|
||||
{
|
||||
if (ptr_server->name)
|
||||
info = ptr_server->name;
|
||||
}
|
||||
else if ( (strcasecmp (arg, "4") == 0) || (strcasecmp (arg, "weechatdir") == 0) )
|
||||
{
|
||||
info = weechat_home;
|
||||
}
|
||||
else if ( (strcasecmp (arg, "5") == 0) || (strcasecmp (arg, "away") == 0) )
|
||||
{
|
||||
XST_mIV (0, SERVER(gui_current_window->buffer)->is_away);
|
||||
XSRETURN (1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info)
|
||||
XST_mPV (0, info);
|
||||
else
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* xs_init: initialize subroutines
|
||||
*/
|
||||
@@ -414,6 +784,8 @@ void
|
||||
xs_init (pTHX)
|
||||
{
|
||||
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
|
||||
|
||||
/* DEPRECATED & old interface (WeeChat <= 0.1.1), kept for compatibility */
|
||||
newXS ("IRC::register", XS_IRC_register, "IRC");
|
||||
newXS ("IRC::print", XS_IRC_print, "IRC");
|
||||
newXS ("IRC::print_with_channel", XS_IRC_print_with_channel, "IRC");
|
||||
@@ -422,6 +794,15 @@ xs_init (pTHX)
|
||||
newXS ("IRC::add_message_handler", XS_IRC_add_message_handler, "IRC");
|
||||
newXS ("IRC::add_command_handler", XS_IRC_add_command_handler, "IRC");
|
||||
newXS ("IRC::get_info", XS_IRC_get_info, "IRC");
|
||||
|
||||
/* new interface (WeeChat >= 0.1.2) */
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
newXS ("weechat::command", XS_weechat_command, "weechat");
|
||||
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
|
||||
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
|
||||
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -433,7 +814,7 @@ wee_perl_init ()
|
||||
{
|
||||
char *perl_args[] = { "", "-e", "0" };
|
||||
/* Following Perl code is extracted/modified from X-Chat IRC client */
|
||||
/* X-Chat is (c) 1998-2002 Peter Zelezny */
|
||||
/* X-Chat is (c) 1998-2005 Peter Zelezny */
|
||||
char *weechat_perl_func =
|
||||
{
|
||||
"sub wee_perl_load_file"
|
||||
@@ -451,21 +832,22 @@ wee_perl_init ()
|
||||
" my $content = wee_perl_load_file ($filename);"
|
||||
" if ($content eq \"__WEECHAT_ERROR__\")"
|
||||
" {"
|
||||
" IRC::print \"WeeChat Error: Perl script '$filename' not found.\\n\";"
|
||||
" weechat::print \"WeeChat Error: Perl script '$filename' not found.\\n\";"
|
||||
" return 1;"
|
||||
" }"
|
||||
" eval $content;"
|
||||
" if ($@)"
|
||||
" {"
|
||||
" IRC::print \"WeeChat error: unable to load Perl script '$filename':\\n\";"
|
||||
" IRC::print \"$@\\n\";"
|
||||
" weechat::print \"WeeChat error: unable to load Perl script '$filename':\\n\";"
|
||||
" weechat::print \"$@\\n\";"
|
||||
" return 2;"
|
||||
" }"
|
||||
" return 0;"
|
||||
"}"
|
||||
"$SIG{__WARN__} = sub { IRC::print \"$_[0]\n\"; };"
|
||||
"$SIG{__WARN__} = sub { weechat::print \"$_[0]\n\"; };"
|
||||
};
|
||||
|
||||
wee_log_printf (_("Loading %s module \"weechat\"\n"), "Perl");
|
||||
my_perl = perl_alloc ();
|
||||
perl_construct (my_perl);
|
||||
perl_parse (my_perl, xs_init, 3, perl_args, NULL);
|
||||
@@ -524,7 +906,7 @@ wee_perl_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: %s\n"),
|
||||
_("Perl error: %s"),
|
||||
SvPV (sv, count));
|
||||
POPs;
|
||||
}
|
||||
@@ -534,8 +916,8 @@ wee_perl_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Perl error: too much values from \"%s\" (%d). Expected: 1.\n"),
|
||||
function, count);
|
||||
_("%s error: too much values from \"%s\" (%d). Expected: 1.\n"),
|
||||
"Perl", function, count);
|
||||
}
|
||||
else
|
||||
return_code = POPi;
|
||||
@@ -556,9 +938,9 @@ int
|
||||
wee_perl_load (char *filename)
|
||||
{
|
||||
/* execute Perl script */
|
||||
wee_log_printf (_("loading Perl script \"%s\"\n"), filename);
|
||||
wee_log_printf (_("Loading %s script \"%s\"\n"), "Perl", filename);
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Loading Perl script \"%s\"\n"), filename);
|
||||
gui_printf (NULL, _("Loading %s script \"%s\"\n"), "Perl", filename);
|
||||
return wee_perl_exec ("wee_perl_load_eval_file", filename, "");
|
||||
}
|
||||
|
||||
@@ -607,8 +989,8 @@ wee_perl_unload (t_plugin_script *ptr_perl_script)
|
||||
{
|
||||
if (ptr_perl_script)
|
||||
{
|
||||
wee_log_printf (_("unloading Perl script \"%s\"\n"),
|
||||
ptr_perl_script->name);
|
||||
wee_log_printf (_("Unloading %s script \"%s\"\n"),
|
||||
"Perl", ptr_perl_script->name);
|
||||
|
||||
/* call shutdown callback function */
|
||||
if (ptr_perl_script->shutdown_func[0])
|
||||
@@ -624,9 +1006,12 @@ wee_perl_unload (t_plugin_script *ptr_perl_script)
|
||||
void
|
||||
wee_perl_unload_all ()
|
||||
{
|
||||
wee_log_printf (_("unloading all Perl scripts...\n"));
|
||||
wee_log_printf (_("Unloading all %s scripts...\n"), "Perl");
|
||||
while (perl_scripts)
|
||||
wee_perl_unload (perl_scripts);
|
||||
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s scripts unloaded\n"), "Perl");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+77
-5
@@ -90,7 +90,7 @@ plugin_auto_load (int plugin_type, char *directory)
|
||||
lstat (entry->d_name, &statbuf);
|
||||
if (! S_ISDIR(statbuf.st_mode))
|
||||
{
|
||||
wee_log_printf (_("auto-loading %s script: %s%s%s\n"),
|
||||
wee_log_printf (_("Auto-loading %s script: %s%s%s\n"),
|
||||
plugin_name[plugin_type],
|
||||
dir_name, DIR_SEPARATOR, entry->d_name);
|
||||
plugin_load (plugin_type, entry->d_name);
|
||||
@@ -194,6 +194,7 @@ plugin_handler_add (t_plugin_handler **plugin_handlers,
|
||||
new_plugin_handler->plugin_type = plugin_type;
|
||||
new_plugin_handler->name = strdup (name);
|
||||
new_plugin_handler->function_name = strdup (function);
|
||||
new_plugin_handler->running = 0;
|
||||
|
||||
/* add new handler to list */
|
||||
new_plugin_handler->prev_handler = *last_plugin_handler;
|
||||
@@ -301,11 +302,25 @@ plugin_event_msg (char *irc_command, char *arguments, char *server)
|
||||
{
|
||||
#ifdef PLUGIN_PERL
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
{
|
||||
if (ptr_plugin_handler->running == 0)
|
||||
{
|
||||
ptr_plugin_handler->running = 1;
|
||||
wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
ptr_plugin_handler->running = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef PLUGIN_PYTHON
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
wee_python_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
{
|
||||
if (ptr_plugin_handler->running == 0)
|
||||
{
|
||||
ptr_plugin_handler->running = 1;
|
||||
wee_python_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
ptr_plugin_handler->running = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -334,11 +349,25 @@ plugin_exec_command (char *user_command, char *arguments, char *server)
|
||||
{
|
||||
#ifdef PLUGIN_PERL
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
|
||||
wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
{
|
||||
if (ptr_plugin_handler->running == 0)
|
||||
{
|
||||
ptr_plugin_handler->running = 1;
|
||||
wee_perl_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
ptr_plugin_handler->running = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef PLUGIN_PYTHON
|
||||
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
|
||||
wee_python_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
{
|
||||
if (ptr_plugin_handler->running == 0)
|
||||
{
|
||||
ptr_plugin_handler->running = 1;
|
||||
wee_python_exec (ptr_plugin_handler->function_name, arguments, server);
|
||||
ptr_plugin_handler->running = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* command executed */
|
||||
@@ -356,6 +385,49 @@ plugin_exec_command (char *user_command, char *arguments, char *server)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_find_buffer: find a buffer for text display or command execution
|
||||
*/
|
||||
|
||||
t_gui_buffer *
|
||||
plugin_find_buffer (char *server, char *channel)
|
||||
{
|
||||
t_irc_server *ptr_server;
|
||||
t_irc_channel *ptr_channel;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
ptr_server = NULL;
|
||||
ptr_channel = NULL;
|
||||
ptr_buffer = NULL;
|
||||
|
||||
if (server)
|
||||
{
|
||||
ptr_server = server_search (server);
|
||||
if (!ptr_server)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_server = SERVER(gui_current_window->buffer);
|
||||
if (!ptr_server)
|
||||
ptr_server = SERVER(gui_buffers);
|
||||
}
|
||||
|
||||
if (channel && ptr_server)
|
||||
{
|
||||
ptr_channel = channel_search (ptr_server, channel);
|
||||
if (ptr_channel)
|
||||
ptr_buffer = ptr_channel->buffer;
|
||||
}
|
||||
else
|
||||
ptr_buffer = gui_current_window->buffer;
|
||||
|
||||
if (!ptr_buffer)
|
||||
return NULL;
|
||||
|
||||
return (ptr_buffer->dcc) ? NULL : ptr_buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_unload: unload all scripts for a plugin type
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef __WEECHAT_PLUGINS_H
|
||||
#define __WEECHAT_PLUGINS_H 1
|
||||
|
||||
#include "../gui/gui.h"
|
||||
|
||||
#define PLUGIN_TYPE_PERL 0
|
||||
#define PLUGIN_TYPE_PYTHON 1
|
||||
#define PLUGIN_TYPE_RUBY 2
|
||||
@@ -45,6 +47,8 @@ struct t_plugin_handler
|
||||
char *name; /* name of IRC command (PRIVMSG, ..)
|
||||
or command (without first '/') */
|
||||
char *function_name; /* name of function (handler) */
|
||||
int running; /* 1 if currently running */
|
||||
/* (used to prevent circular call) */
|
||||
t_plugin_handler *prev_handler; /* link to previous handler */
|
||||
t_plugin_handler *next_handler; /* link to next handler */
|
||||
};
|
||||
@@ -66,14 +70,15 @@ extern t_plugin_script *python_scripts;
|
||||
extern void plugin_auto_load (int, char *);
|
||||
extern void plugin_init ();
|
||||
extern void plugin_load (int, char *);
|
||||
extern void plugin_unload (int, /*@null@*/ char *);
|
||||
extern void plugin_unload (int, char *);
|
||||
extern t_plugin_handler *plugin_handler_search (t_plugin_handler *, char *);
|
||||
extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
|
||||
int, char *, char *);
|
||||
extern void plugin_handler_free_all_type (t_plugin_handler **,
|
||||
t_plugin_handler **, int);
|
||||
extern void plugin_event_msg (char *, char *, char *);
|
||||
extern int plugin_exec_command (char *, /*@null@*/ char *, char *);
|
||||
extern int plugin_exec_command (char *, char *, char *);
|
||||
extern t_gui_buffer *plugin_find_buffer (char *, char *);
|
||||
extern void plugin_end ();
|
||||
|
||||
#endif /* plugins.h */
|
||||
|
||||
+95
-145
@@ -41,8 +41,7 @@ t_plugin_script *last_python_script = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* weechat.register(nom, version, fonction, description):
|
||||
* startup function for all WeeChat Python scripts
|
||||
* weechat.register: startup function for all WeeChat Python scripts
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -58,7 +57,8 @@ wee_python_register (PyObject *self, PyObject *args)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'print_with_channel' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "print_with_channel");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ wee_python_register (PyObject *self, PyObject *args)
|
||||
/* error: another scripts already exists with this name! */
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: unable to register Python script \"%s\" (another script "
|
||||
"already exists with this name)\n"),
|
||||
name);
|
||||
_("%s error: unable to register \"%s\" script (another script "
|
||||
"already exists with this name)\n"),
|
||||
"Python", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -102,15 +102,15 @@ wee_python_register (PyObject *self, PyObject *args)
|
||||
python_scripts = new_python_script;
|
||||
last_python_script = new_python_script;
|
||||
|
||||
wee_log_printf (_("registered Python script: \"%s\", version %s (%s)\n"),
|
||||
name, version, description);
|
||||
wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
|
||||
"Python", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s unable to load Python script \"%s\" (not enough memory)\n"),
|
||||
WEECHAT_ERROR, name);
|
||||
_("%s error: unable to load script \"%s\" (not enough memory)\n"),
|
||||
"Python", name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,91 +119,45 @@ wee_python_register (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print(message): print message to current buffer
|
||||
* weechat.print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
wee_python_print (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'print' Python function\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
irc_display_prefix (gui_current_window->buffer, PREFIX_PLUGIN);
|
||||
gui_printf (gui_current_window->buffer, "%s\n", message);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print_with_channel(message, channel, server=None):
|
||||
* print message to a specific channel/server
|
||||
* (server is optional)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
wee_python_print_with_channel (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *channel, *server = NULL;
|
||||
int ret = 0;
|
||||
char *message, *channel_name, *server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
t_irc_server *ptr_server;
|
||||
t_irc_channel *ptr_channel;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss|s", &message, &channel, &server))
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'print_with_channel' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "print");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr_buffer = NULL;
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
if (!server || (strcasecmp (ptr_server->name, server)) == 0)
|
||||
{
|
||||
for (ptr_channel = ptr_server->channels; ptr_channel;
|
||||
ptr_channel = ptr_channel->next_channel)
|
||||
{
|
||||
if (strcasecmp (ptr_channel->name, channel) == 0)
|
||||
{
|
||||
ptr_buffer = ptr_channel->buffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ptr_buffer)
|
||||
break;
|
||||
}
|
||||
|
||||
/* buffer found => display message & return 1 ~= True */
|
||||
ptr_buffer = plugin_find_buffer (server_name, channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
irc_display_prefix (ptr_buffer, PREFIX_PLUGIN);
|
||||
gui_printf (ptr_buffer, "%s", message);
|
||||
ret = 1;
|
||||
gui_printf (ptr_buffer, "%s\n", message);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", ret);
|
||||
/* buffer not found */
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.print_infobar(delay, message): print message to infobar
|
||||
* weechat.print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -215,11 +169,15 @@ wee_python_print_infobar (PyObject *self, PyObject *args)
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
delay = 1;
|
||||
message = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "is", &delay, &message))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'print_infobar' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "print_infobar");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -230,62 +188,44 @@ wee_python_print_infobar (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.command(command, server=None): send command to server
|
||||
* weechat.command: send command to server
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
wee_python_command (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *server = NULL, *command, *command2;
|
||||
t_irc_server *ptr_server;
|
||||
char *command, *channel_name, *server_name;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|s", &command, &server))
|
||||
command = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &command, &channel_name, &server_name))
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'command' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (server == NULL)
|
||||
ptr_buffer = plugin_find_buffer (server_name, channel_name);
|
||||
if (ptr_buffer)
|
||||
{
|
||||
ptr_server = SERVER(gui_current_window->buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
|
||||
{
|
||||
if (strcasecmp (ptr_server->name, server) == 0)
|
||||
break;
|
||||
}
|
||||
if (!ptr_server)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: server not found for 'command' Python function\n"));
|
||||
}
|
||||
user_command (SERVER(ptr_buffer), ptr_buffer, command);
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
if (ptr_server)
|
||||
{
|
||||
command2 = (char *) malloc (strlen (command) + 8);
|
||||
strcpy (command2, command);
|
||||
if (!strstr (command2, "\r\n"))
|
||||
strcat (command2, "\r\n");
|
||||
server_sendf (ptr_server, command2);
|
||||
free (command2);
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
/* buffer not found */
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_message_handler(message, function):
|
||||
* add handler for messages
|
||||
* weechat.add_message_handler: add handler for messages
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -300,7 +240,8 @@ wee_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'add_message_handler' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "add_message_handler");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -312,8 +253,7 @@ wee_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.add_command_handler(name, function):
|
||||
* define/redefines commands
|
||||
* weechat.add_command_handler: define/redefines commands
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -329,7 +269,8 @@ wee_python_add_command_handler(PyObject *self, PyObject *args)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'add_command_handler' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "add_command_handler");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -351,8 +292,7 @@ wee_python_add_command_handler(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_info(info, server=None):
|
||||
* get various infos
|
||||
* weechat.get_info: get various infos
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -368,7 +308,8 @@ wee_python_get_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: wrong parameters for 'get_info' Python function\n"));
|
||||
_("%s error: wrong parameters for \"%s\" function\n"),
|
||||
"Python", "get_info");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -387,7 +328,8 @@ wee_python_get_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: server not found for 'get_info' Python function\n"));
|
||||
_("%s error: server not found for \"%s\" function\n"),
|
||||
"Python", "get_info");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,20 +373,19 @@ wee_python_get_info (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize subroutines
|
||||
* Python subroutines
|
||||
*/
|
||||
|
||||
static
|
||||
PyMethodDef weechat_funcs[] = {
|
||||
{"register", wee_python_register, METH_VARARGS, ""},
|
||||
{"prnt", wee_python_print, METH_VARARGS, ""},
|
||||
{"print_with_channel", wee_python_print_with_channel, METH_VARARGS, ""},
|
||||
{"print_infobar", wee_python_print_infobar, METH_VARARGS, ""},
|
||||
{"command", wee_python_command, METH_VARARGS, ""},
|
||||
{"add_message_handler", wee_python_add_message_handler, METH_VARARGS, ""},
|
||||
{"add_command_handler", wee_python_add_command_handler, METH_VARARGS, ""},
|
||||
{"get_info", wee_python_get_info, METH_VARARGS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
{ "register", wee_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", wee_python_print, METH_VARARGS, "" },
|
||||
{ "print_infobar", wee_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "command", wee_python_command, METH_VARARGS, "" },
|
||||
{ "add_message_handler", wee_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", wee_python_add_command_handler, METH_VARARGS, "" },
|
||||
{ "get_info", wee_python_get_info, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -459,13 +400,13 @@ wee_python_init ()
|
||||
if (Py_IsInitialized () == 0)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Python error: error while launching Python interpreter\n"));
|
||||
gui_printf (NULL, _("%s error: error while launching interpreter\n"),
|
||||
"Python");
|
||||
}
|
||||
else
|
||||
{
|
||||
wee_log_printf (_("Loading %s module \"weechat\"\n"), "Python");
|
||||
Py_InitModule ("weechat", weechat_funcs);
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Loading Python module \"weechat\"\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,8 +457,8 @@ wee_python_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: unable to run function \"%s\"in Python script (not enough memory)\n"),
|
||||
function);
|
||||
_("%s error: unable to run function \"%s\" in script (not enough memory)\n"),
|
||||
"Python", function);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -544,8 +485,8 @@ wee_python_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: unable to run function \"%s\"in Python script (not enough memory)\n"),
|
||||
function);
|
||||
_("%s error: unable to run function \"%s\" in script (not enough memory)\n"),
|
||||
"Python", function);
|
||||
free (args);
|
||||
return 0;
|
||||
}
|
||||
@@ -566,7 +507,8 @@ wee_python_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: error while running function \"%s\"\n"), function);
|
||||
_("%s error: error while running function \"%s\"\n"),
|
||||
"Python", function);
|
||||
return_code = 0;
|
||||
}
|
||||
free (runstring);
|
||||
@@ -575,8 +517,8 @@ wee_python_exec (char *function, char *server, char *arguments)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: unable to run function \"%s\"in Python script (not enough memory)\n"),
|
||||
function);
|
||||
_("%s error: unable to run function \"%s\" in script (not enough memory)\n"),
|
||||
"Python", function);
|
||||
return_code = 0;
|
||||
}
|
||||
|
||||
@@ -596,15 +538,16 @@ wee_python_load (char *filename)
|
||||
FILE *fp;
|
||||
|
||||
/* execute Python script */
|
||||
wee_log_printf (_("loading Python script \"%s\"\n"), filename);
|
||||
wee_log_printf (_("Loading %s script \"%s\"\n"), "Python", filename);
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Loading Python script \"%s\"\n"), filename);
|
||||
gui_printf (NULL, _("Loading %s script \"%s\"\n"), "Python", filename);
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: error while opening file \"%s\"\n"), filename);
|
||||
_("%s error: error while opening file \"%s\"\n"),
|
||||
"Python", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -612,7 +555,8 @@ wee_python_load (char *filename)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("Python error: error while parsing file \"%s\"\n"), filename);
|
||||
_("%s error: error while parsing file \"%s\"\n"),
|
||||
"Python", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -665,8 +609,8 @@ wee_python_unload (t_plugin_script *ptr_python_script)
|
||||
{
|
||||
if (ptr_python_script)
|
||||
{
|
||||
wee_log_printf (_("unloading Python script \"%s\"\n"),
|
||||
ptr_python_script->name);
|
||||
wee_log_printf (_("Unloading %s script \"%s\"\n"),
|
||||
"Python", ptr_python_script->name);
|
||||
|
||||
/* call shutdown callback function */
|
||||
if (ptr_python_script->shutdown_func[0])
|
||||
@@ -682,9 +626,12 @@ wee_python_unload (t_plugin_script *ptr_python_script)
|
||||
void
|
||||
wee_python_unload_all ()
|
||||
{
|
||||
wee_log_printf (_("unloading all Python scripts...\n"));
|
||||
wee_log_printf (_("Unloading all %s scripts...\n"), "Python");
|
||||
while (python_scripts)
|
||||
wee_python_unload (python_scripts);
|
||||
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s scripts unloaded\n"), "Python");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -705,9 +652,12 @@ wee_python_end ()
|
||||
&last_plugin_cmd_handler,
|
||||
PLUGIN_TYPE_PYTHON);
|
||||
|
||||
/* free Python interpreter */
|
||||
Py_Finalize ();
|
||||
if (Py_IsInitialized () != 0) {
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("Python error: error while freeing Python interpreter\n"));
|
||||
if (Py_IsInitialized () != 0)
|
||||
{
|
||||
irc_display_prefix (NULL, PREFIX_PLUGIN);
|
||||
gui_printf (NULL, _("%s error: error while freeing interpreter\n"),
|
||||
"Python");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user