39 |
|
|
40 |
static PerlInterpreter *my_perl = NULL; |
static PerlInterpreter *my_perl = NULL; |
41 |
|
|
42 |
t_perl_script *perl_scripts = NULL; |
t_plugin_script *perl_scripts = NULL; |
43 |
t_perl_script *last_perl_script = NULL; |
t_plugin_script *last_perl_script = NULL; |
44 |
|
|
45 |
extern void boot_DynaLoader (pTHX_ CV* cv); |
extern void boot_DynaLoader (pTHX_ CV* cv); |
46 |
|
|
53 |
{ |
{ |
54 |
char *name, *version, *shutdown_func, *description; |
char *name, *version, *shutdown_func, *description; |
55 |
int integer; |
int integer; |
56 |
t_perl_script *new_perl_script; |
t_plugin_script *ptr_perl_script, *perl_script_found, *new_perl_script; |
57 |
dXSARGS; |
dXSARGS; |
58 |
|
|
59 |
name = SvPV (ST (0), integer); |
name = SvPV (ST (0), integer); |
61 |
shutdown_func = SvPV (ST (2), integer); |
shutdown_func = SvPV (ST (2), integer); |
62 |
description = SvPV (ST (3), integer); |
description = SvPV (ST (3), integer); |
63 |
|
|
64 |
new_perl_script = (t_perl_script *)malloc (sizeof (t_perl_script)); |
perl_script_found = NULL; |
65 |
if (new_perl_script) |
for (ptr_perl_script = perl_scripts; ptr_perl_script; |
66 |
|
ptr_perl_script = ptr_perl_script->next_script) |
67 |
{ |
{ |
68 |
new_perl_script->name = strdup (name); |
if (strcasecmp (ptr_perl_script->name, name) == 0) |
69 |
new_perl_script->version = strdup (version); |
{ |
70 |
new_perl_script->shutdown_func = strdup (shutdown_func); |
perl_script_found = ptr_perl_script; |
71 |
new_perl_script->description = strdup (description); |
break; |
72 |
|
} |
73 |
/* add new script to list */ |
} |
74 |
new_perl_script->prev_script = last_perl_script; |
|
75 |
new_perl_script->next_script = NULL; |
if (perl_script_found) |
76 |
if (perl_scripts) |
{ |
77 |
last_perl_script->next_script = new_perl_script; |
/* error: another scripts already exists with this name! */ |
78 |
else |
gui_printf (NULL, |
79 |
perl_scripts = new_perl_script; |
_("Perl error: unable to register Perl script \"%s\" (another script " |
80 |
last_perl_script = new_perl_script; |
"already exists with this name)\n"), |
81 |
|
name); |
|
wee_log_printf (_("registered Perl script: \"%s\", version %s (%s)\n"), |
|
|
name, version, description); |
|
82 |
} |
} |
83 |
else |
else |
84 |
gui_printf (gui_current_window, |
{ |
85 |
_("%s unable to load Perl script \"%s\" (not enough memory)\n"), |
/* registering script */ |
86 |
WEECHAT_ERROR, name); |
new_perl_script = (t_plugin_script *)malloc (sizeof (t_plugin_script)); |
87 |
|
if (new_perl_script) |
88 |
|
{ |
89 |
|
new_perl_script->name = strdup (name); |
90 |
|
new_perl_script->version = strdup (version); |
91 |
|
new_perl_script->shutdown_func = strdup (shutdown_func); |
92 |
|
new_perl_script->description = strdup (description); |
93 |
|
|
94 |
|
/* add new script to list */ |
95 |
|
new_perl_script->prev_script = last_perl_script; |
96 |
|
new_perl_script->next_script = NULL; |
97 |
|
if (perl_scripts) |
98 |
|
last_perl_script->next_script = new_perl_script; |
99 |
|
else |
100 |
|
perl_scripts = new_perl_script; |
101 |
|
last_perl_script = new_perl_script; |
102 |
|
|
103 |
|
wee_log_printf (_("registered Perl script: \"%s\", version %s (%s)\n"), |
104 |
|
name, version, description); |
105 |
|
} |
106 |
|
else |
107 |
|
gui_printf (NULL, |
108 |
|
_("%s unable to load Perl script \"%s\" (not enough memory)\n"), |
109 |
|
WEECHAT_ERROR, name); |
110 |
|
} |
111 |
XST_mPV (0, VERSION); |
XST_mPV (0, VERSION); |
112 |
XSRETURN (1); |
XSRETURN (1); |
113 |
} |
} |
125 |
for (i = 0; i < items; i++) |
for (i = 0; i < items; i++) |
126 |
{ |
{ |
127 |
message = SvPV (ST (i), integer); |
message = SvPV (ST (i), integer); |
128 |
gui_printf (gui_current_window, "%s%s", |
gui_printf (gui_current_window, "%s", message); |
|
message, |
|
|
(message[strlen (message) - 1] == '\n') ? "" : "\n"); |
|
129 |
} |
} |
130 |
|
|
131 |
XSRETURN_EMPTY; |
XSRETURN_EMPTY; |
144 |
name = SvPV (ST (0), integer); |
name = SvPV (ST (0), integer); |
145 |
function = SvPV (ST (1), integer); |
function = SvPV (ST (1), integer); |
146 |
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler, |
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler, |
147 |
PLUGIN_PERL, name, function); |
PLUGIN_TYPE_PERL, name, function); |
148 |
XSRETURN_EMPTY; |
XSRETURN_EMPTY; |
149 |
} |
} |
150 |
|
|
171 |
} |
} |
172 |
else |
else |
173 |
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler, |
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler, |
174 |
PLUGIN_PERL, name, function); |
PLUGIN_TYPE_PERL, name, function); |
175 |
XSRETURN_EMPTY; |
XSRETURN_EMPTY; |
176 |
} |
} |
177 |
|
|
241 |
* wee_perl_search: search a (loaded) Perl script by name |
* wee_perl_search: search a (loaded) Perl script by name |
242 |
*/ |
*/ |
243 |
|
|
244 |
t_perl_script * |
t_plugin_script * |
245 |
wee_perl_search (char *name) |
wee_perl_search (char *name) |
246 |
{ |
{ |
247 |
t_perl_script *ptr_perl_script; |
t_plugin_script *ptr_perl_script; |
248 |
|
|
249 |
for (ptr_perl_script = perl_scripts; ptr_perl_script; |
for (ptr_perl_script = perl_scripts; ptr_perl_script; |
250 |
ptr_perl_script = ptr_perl_script->next_script) |
ptr_perl_script = ptr_perl_script->next_script) |
283 |
return_code = 1; |
return_code = 1; |
284 |
if (SvTRUE (sv)) |
if (SvTRUE (sv)) |
285 |
{ |
{ |
286 |
gui_printf (gui_current_window, |
gui_printf (NULL, |
287 |
_("Perl error: %s\n"), |
_("Perl error: %s\n"), |
288 |
SvPV (sv, count)); |
SvPV (sv, count)); |
289 |
POPs; |
POPs; |
292 |
{ |
{ |
293 |
if (count != 1) |
if (count != 1) |
294 |
{ |
{ |
295 |
gui_printf (gui_current_window, |
gui_printf (NULL, |
296 |
_("Perl error: too much values from \"%s\" (%d). Expected: 1.\n"), |
_("Perl error: too much values from \"%s\" (%d). Expected: 1.\n"), |
297 |
function, count); |
function, count); |
298 |
} |
} |
324 |
*/ |
*/ |
325 |
|
|
326 |
void |
void |
327 |
wee_perl_script_free (t_perl_script *ptr_perl_script) |
wee_perl_script_free (t_plugin_script *ptr_perl_script) |
328 |
{ |
{ |
329 |
t_perl_script *new_perl_scripts; |
t_plugin_script *new_perl_scripts; |
330 |
|
|
331 |
/* remove script from list */ |
/* remove script from list */ |
332 |
if (last_perl_script == ptr_perl_script) |
if (last_perl_script == ptr_perl_script) |
360 |
*/ |
*/ |
361 |
|
|
362 |
void |
void |
363 |
wee_perl_unload (t_perl_script *ptr_perl_script) |
wee_perl_unload (t_plugin_script *ptr_perl_script) |
364 |
{ |
{ |
365 |
if (ptr_perl_script) |
if (ptr_perl_script) |
366 |
{ |
{ |
381 |
void |
void |
382 |
wee_perl_unload_all () |
wee_perl_unload_all () |
383 |
{ |
{ |
384 |
|
wee_log_printf (_("unloading all Perl scripts...\n")); |
385 |
while (perl_scripts) |
while (perl_scripts) |
386 |
wee_perl_unload (perl_scripts); |
wee_perl_unload (perl_scripts); |
387 |
} |
} |