32 |
#include <XSUB.h> |
#include <XSUB.h> |
33 |
#include "../../common/weechat.h" |
#include "../../common/weechat.h" |
34 |
#include "wee-perl.h" |
#include "wee-perl.h" |
35 |
|
#include "../plugins.h" |
36 |
#include "../../gui/gui.h" |
#include "../../gui/gui.h" |
37 |
|
|
38 |
|
|
39 |
static PerlInterpreter *my_perl = NULL; |
static PerlInterpreter *my_perl = NULL; |
40 |
static t_perl_script *perl_scripts = NULL; |
|
41 |
|
t_perl_script *perl_scripts = NULL; |
42 |
|
t_perl_script *last_perl_script = NULL; |
43 |
|
|
44 |
extern void boot_DynaLoader (pTHX_ CV* cv); |
extern void boot_DynaLoader (pTHX_ CV* cv); |
45 |
|
|
67 |
new_perl_script->version = strdup (version); |
new_perl_script->version = strdup (version); |
68 |
new_perl_script->shutdown_func = strdup (shutdown_func); |
new_perl_script->shutdown_func = strdup (shutdown_func); |
69 |
new_perl_script->description = strdup (description); |
new_perl_script->description = strdup (description); |
70 |
new_perl_script->next_script = perl_scripts; |
|
71 |
perl_scripts = new_perl_script; |
/* add new script to list */ |
72 |
wee_log_printf (_("registered Perl script: \"%s\"\n"), name); |
new_perl_script->prev_script = last_perl_script; |
73 |
|
new_perl_script->next_script = NULL; |
74 |
|
if (perl_scripts) |
75 |
|
last_perl_script->next_script = new_perl_script; |
76 |
|
else |
77 |
|
perl_scripts = new_perl_script; |
78 |
|
last_perl_script = new_perl_script; |
79 |
|
|
80 |
|
wee_log_printf (_("registered Perl script: \"%s\", version %s (%s)\n"), |
81 |
|
name, version, description); |
82 |
} |
} |
83 |
else |
else |
84 |
gui_printf (NULL, |
gui_printf (NULL, |
85 |
_("%s unable to load Perl script \"%s\"\n"), |
_("%s unable to load Perl script \"%s\" (not enough memory)\n"), |
86 |
WEECHAT_ERROR, name); |
WEECHAT_ERROR, name); |
87 |
XST_mPV (0, VERSION); |
XST_mPV (0, VERSION); |
88 |
XSRETURN (1); |
XSRETURN (1); |
108 |
} |
} |
109 |
|
|
110 |
/* |
/* |
111 |
|
* IRC::add_message_handler: add handler for messages (privmsg, ...) |
112 |
|
*/ |
113 |
|
|
114 |
|
static XS (XS_IRC_add_message_handler) |
115 |
|
{ |
116 |
|
char *name, *function; |
117 |
|
int integer; |
118 |
|
dXSARGS; |
119 |
|
|
120 |
|
name = SvPV (ST (0), integer); |
121 |
|
function = SvPV (ST (1), integer); |
122 |
|
plugins_msg_handler_add (PLUGIN_PERL, name, function); |
123 |
|
XSRETURN_EMPTY; |
124 |
|
} |
125 |
|
|
126 |
|
/* |
127 |
* xs_init: initialize subroutines |
* xs_init: initialize subroutines |
128 |
*/ |
*/ |
129 |
|
|
133 |
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); |
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); |
134 |
newXS ("IRC::register", XS_IRC_register, "IRC"); |
newXS ("IRC::register", XS_IRC_register, "IRC"); |
135 |
newXS ("IRC::print", XS_IRC_print, "IRC"); |
newXS ("IRC::print", XS_IRC_print, "IRC"); |
136 |
|
newXS ("IRC::add_message_handler", XS_IRC_add_message_handler, "IRC"); |
137 |
} |
} |
138 |
|
|
139 |
/* |
/* |
267 |
} |
} |
268 |
|
|
269 |
/* |
/* |
270 |
|
* wee_perl_script_free: free a Perl script |
271 |
|
*/ |
272 |
|
|
273 |
|
void |
274 |
|
wee_perl_script_free (t_perl_script *ptr_perl_script) |
275 |
|
{ |
276 |
|
t_perl_script *new_perl_scripts; |
277 |
|
|
278 |
|
/* remove script from list */ |
279 |
|
if (last_perl_script == ptr_perl_script) |
280 |
|
last_perl_script = ptr_perl_script->prev_script; |
281 |
|
if (ptr_perl_script->prev_script) |
282 |
|
{ |
283 |
|
(ptr_perl_script->prev_script)->next_script = ptr_perl_script->next_script; |
284 |
|
new_perl_scripts = perl_scripts; |
285 |
|
} |
286 |
|
else |
287 |
|
new_perl_scripts = ptr_perl_script->next_script; |
288 |
|
|
289 |
|
if (ptr_perl_script->next_script) |
290 |
|
(ptr_perl_script->next_script)->prev_script = ptr_perl_script->prev_script; |
291 |
|
|
292 |
|
/* free data */ |
293 |
|
if (ptr_perl_script->name) |
294 |
|
free (ptr_perl_script->name); |
295 |
|
if (ptr_perl_script->version) |
296 |
|
free (ptr_perl_script->version); |
297 |
|
if (ptr_perl_script->shutdown_func) |
298 |
|
free (ptr_perl_script->shutdown_func); |
299 |
|
if (ptr_perl_script->description) |
300 |
|
free (ptr_perl_script->description); |
301 |
|
free (ptr_perl_script); |
302 |
|
perl_scripts = new_perl_scripts; |
303 |
|
} |
304 |
|
|
305 |
|
/* |
306 |
* wee_perl_unload: unload a Perl script |
* wee_perl_unload: unload a Perl script |
307 |
*/ |
*/ |
308 |
|
|
317 |
/* call shutdown callback function */ |
/* call shutdown callback function */ |
318 |
if (ptr_perl_script->shutdown_func[0]) |
if (ptr_perl_script->shutdown_func[0]) |
319 |
wee_perl_exec (ptr_perl_script->shutdown_func, ""); |
wee_perl_exec (ptr_perl_script->shutdown_func, ""); |
320 |
|
wee_perl_script_free (ptr_perl_script); |
|
/* free data */ |
|
|
if (ptr_perl_script->name) |
|
|
free (ptr_perl_script->name); |
|
|
if (ptr_perl_script->version) |
|
|
free (ptr_perl_script->version); |
|
|
if (ptr_perl_script->shutdown_func) |
|
|
free (ptr_perl_script->shutdown_func); |
|
|
if (ptr_perl_script->description) |
|
|
free (ptr_perl_script->description); |
|
321 |
} |
} |
322 |
} |
} |
323 |
|
|
328 |
void |
void |
329 |
wee_perl_unload_all () |
wee_perl_unload_all () |
330 |
{ |
{ |
|
t_perl_script *ptr_perl_script; |
|
|
|
|
331 |
while (perl_scripts) |
while (perl_scripts) |
|
{ |
|
332 |
wee_perl_unload (perl_scripts); |
wee_perl_unload (perl_scripts); |
|
ptr_perl_script = perl_scripts->next_script; |
|
|
free (perl_scripts); |
|
|
perl_scripts = ptr_perl_script; |
|
|
} |
|
333 |
} |
} |
334 |
|
|
335 |
/* |
/* |