summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2003-11-23 17:40:19 +0000
committerSebastien Helleu <flashcode@flashtux.org>2003-11-23 17:40:19 +0000
commit10a170bf7d75a4731583182f40422c0ac23d4c78 (patch)
tree33604d9a1e2026dc181647e97866dbf075e4e8d6 /src/plugins
parent7a3ee901a469fe554697c499efc8711f8084c564 (diff)
downloadweechat-10a170bf7d75a4731583182f40422c0ac23d4c78.zip
- Perl unloading is now ok (unload all scripts),
- /perl prints all Perl scripts, - error if registering 2 Perl scripts with same (internal) name.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/perl/wee-perl.c94
-rw-r--r--src/plugins/perl/wee-perl.h16
-rw-r--r--src/plugins/plugins.c83
-rw-r--r--src/plugins/plugins.h22
4 files changed, 137 insertions, 78 deletions
diff --git a/src/plugins/perl/wee-perl.c b/src/plugins/perl/wee-perl.c
index eb5941944..69ab59b4e 100644
--- a/src/plugins/perl/wee-perl.c
+++ b/src/plugins/perl/wee-perl.c
@@ -39,8 +39,8 @@
static PerlInterpreter *my_perl = NULL;
-t_perl_script *perl_scripts = NULL;
-t_perl_script *last_perl_script = NULL;
+t_plugin_script *perl_scripts = NULL;
+t_plugin_script *last_perl_script = NULL;
extern void boot_DynaLoader (pTHX_ CV* cv);
@@ -53,7 +53,7 @@ static XS (XS_IRC_register)
{
char *name, *version, *shutdown_func, *description;
int integer;
- t_perl_script *new_perl_script;
+ t_plugin_script *ptr_perl_script, *perl_script_found, *new_perl_script;
dXSARGS;
name = SvPV (ST (0), integer);
@@ -61,30 +61,53 @@ static XS (XS_IRC_register)
shutdown_func = SvPV (ST (2), integer);
description = SvPV (ST (3), integer);
- new_perl_script = (t_perl_script *)malloc (sizeof (t_perl_script));
- if (new_perl_script)
+ perl_script_found = NULL;
+ for (ptr_perl_script = perl_scripts; ptr_perl_script;
+ ptr_perl_script = ptr_perl_script->next_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 Perl script: \"%s\", version %s (%s)\n"),
- name, version, description);
+ if (strcasecmp (ptr_perl_script->name, name) == 0)
+ {
+ perl_script_found = ptr_perl_script;
+ break;
+ }
+ }
+
+ if (perl_script_found)
+ {
+ /* error: another scripts already exists with this name! */
+ gui_printf (NULL,
+ _("Perl error: unable to register Perl script \"%s\" (another script "
+ "already exists with this name)\n"),
+ name);
}
else
- gui_printf (gui_current_window,
- _("%s unable to load Perl script \"%s\" (not enough memory)\n"),
- WEECHAT_ERROR, name);
+ {
+ /* 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 Perl script: \"%s\", version %s (%s)\n"),
+ name, version, description);
+ }
+ else
+ gui_printf (NULL,
+ _("%s unable to load Perl script \"%s\" (not enough memory)\n"),
+ WEECHAT_ERROR, name);
+ }
XST_mPV (0, VERSION);
XSRETURN (1);
}
@@ -102,9 +125,7 @@ static XS (XS_IRC_print)
for (i = 0; i < items; i++)
{
message = SvPV (ST (i), integer);
- gui_printf (gui_current_window, "%s%s",
- message,
- (message[strlen (message) - 1] == '\n') ? "" : "\n");
+ gui_printf (gui_current_window, "%s", message);
}
XSRETURN_EMPTY;
@@ -123,7 +144,7 @@ static XS (XS_IRC_add_message_handler)
name = SvPV (ST (0), integer);
function = SvPV (ST (1), integer);
plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler,
- PLUGIN_PERL, name, function);
+ PLUGIN_TYPE_PERL, name, function);
XSRETURN_EMPTY;
}
@@ -150,7 +171,7 @@ static XS (XS_IRC_add_command_handler)
}
else
plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler,
- PLUGIN_PERL, name, function);
+ PLUGIN_TYPE_PERL, name, function);
XSRETURN_EMPTY;
}
@@ -220,10 +241,10 @@ wee_perl_init ()
* wee_perl_search: search a (loaded) Perl script by name
*/
-t_perl_script *
+t_plugin_script *
wee_perl_search (char *name)
{
- t_perl_script *ptr_perl_script;
+ t_plugin_script *ptr_perl_script;
for (ptr_perl_script = perl_scripts; ptr_perl_script;
ptr_perl_script = ptr_perl_script->next_script)
@@ -262,7 +283,7 @@ wee_perl_exec (char *function, char *arguments)
return_code = 1;
if (SvTRUE (sv))
{
- gui_printf (gui_current_window,
+ gui_printf (NULL,
_("Perl error: %s\n"),
SvPV (sv, count));
POPs;
@@ -271,7 +292,7 @@ wee_perl_exec (char *function, char *arguments)
{
if (count != 1)
{
- gui_printf (gui_current_window,
+ gui_printf (NULL,
_("Perl error: too much values from \"%s\" (%d). Expected: 1.\n"),
function, count);
}
@@ -303,9 +324,9 @@ wee_perl_load (char *filename)
*/
void
-wee_perl_script_free (t_perl_script *ptr_perl_script)
+wee_perl_script_free (t_plugin_script *ptr_perl_script)
{
- t_perl_script *new_perl_scripts;
+ t_plugin_script *new_perl_scripts;
/* remove script from list */
if (last_perl_script == ptr_perl_script)
@@ -339,7 +360,7 @@ wee_perl_script_free (t_perl_script *ptr_perl_script)
*/
void
-wee_perl_unload (t_perl_script *ptr_perl_script)
+wee_perl_unload (t_plugin_script *ptr_perl_script)
{
if (ptr_perl_script)
{
@@ -360,6 +381,7 @@ wee_perl_unload (t_perl_script *ptr_perl_script)
void
wee_perl_unload_all ()
{
+ wee_log_printf (_("unloading all Perl scripts...\n"));
while (perl_scripts)
wee_perl_unload (perl_scripts);
}
diff --git a/src/plugins/perl/wee-perl.h b/src/plugins/perl/wee-perl.h
index c018bf44a..36b2986d7 100644
--- a/src/plugins/perl/wee-perl.h
+++ b/src/plugins/perl/wee-perl.h
@@ -23,23 +23,13 @@
#ifndef __WEECHAT_PERL_H
#define __WEECHAT_PERL_H 1
-typedef struct t_perl_script t_perl_script;
-
-struct t_perl_script
-{
- char *name; /* name of script */
- char *version; /* version of script */
- char *shutdown_func; /* function when script ends */
- char *description; /* description of script */
- t_perl_script *prev_script; /* link to previous Perl script */
- t_perl_script *next_script; /* link to next Perl script */
-};
+#include "../plugins.h"
extern void wee_perl_init ();
-extern t_perl_script *wee_perl_search (char *);
+extern t_plugin_script *wee_perl_search (char *);
extern int wee_perl_exec (char *, char *);
extern int wee_perl_load (char *);
-extern void wee_perl_unload (t_perl_script *);
+extern void wee_perl_unload (t_plugin_script *);
extern void wee_perl_unload_all ();
extern void wee_perl_end ();
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index c78f2fe3e..f1d180d1a 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -82,31 +82,6 @@ plugin_load (int plugin_type, char *filename)
}
/*
- * plugin_unload: unload a plugin
- */
-
-void
-plugin_unload (int plugin_type, char *scriptname)
-{
- #ifdef PLUGINS
- switch (plugin_type)
- {
- case PLUGIN_TYPE_PERL:
- #ifdef PLUGIN_PERL
- wee_perl_unload (wee_perl_search (scriptname));
- #endif
- break;
- case PLUGIN_TYPE_PYTHON:
- /* TODO: load Python script */
- break;
- case PLUGIN_TYPE_RUBY:
- /* TODO: load Ruby script */
- break;
- }
- #endif
-}
-
-/*
* plugin_handler_search: look for message/command handler
*/
@@ -205,6 +180,32 @@ plugin_handler_free_all (t_plugin_handler **plugin_handlers,
}
/*
+ * plugin_handler_free_all_type: remove all message/command handlers for one type
+ */
+
+void
+plugin_handler_free_all_type (t_plugin_handler **plugin_handlers,
+ t_plugin_handler **last_plugin_handler,
+ int plugin_type)
+{
+ t_plugin_handler *ptr_plugin_handler, *new_plugin_handler;
+
+ ptr_plugin_handler = *plugin_handlers;
+ while (ptr_plugin_handler)
+ {
+ if (ptr_plugin_handler->plugin_type == plugin_type)
+ {
+ new_plugin_handler = ptr_plugin_handler->next_handler;
+ plugin_handler_free (plugin_handlers, last_plugin_handler,
+ ptr_plugin_handler);
+ ptr_plugin_handler = new_plugin_handler;
+ }
+ else
+ ptr_plugin_handler = ptr_plugin_handler->next_handler;
+ }
+}
+
+/*
* plugin_event_msg: IRC message received => call all handlers for this message
*/
@@ -267,6 +268,38 @@ plugin_exec_command (char *user_command, char *arguments)
}
/*
+ * plugin_unload: unload all scripts for a plugin type
+ */
+
+void
+plugin_unload (int plugin_type, char *scriptname)
+{
+ #ifdef PLUGINS
+ switch (plugin_type)
+ {
+ case PLUGIN_TYPE_PERL:
+ #ifdef PLUGIN_PERL
+ wee_perl_unload_all ();
+ /* impossible to unload only one Perl script */
+ plugin_handler_free_all_type (&plugin_msg_handlers,
+ &last_plugin_msg_handler,
+ PLUGIN_TYPE_PERL);
+ plugin_handler_free_all_type (&plugin_cmd_handlers,
+ &last_plugin_cmd_handler,
+ PLUGIN_TYPE_PERL);
+ #endif
+ break;
+ case PLUGIN_TYPE_PYTHON:
+ /* TODO: unload Python scripts */
+ break;
+ case PLUGIN_TYPE_RUBY:
+ /* TODO: unload Ruby scripts */
+ break;
+ }
+ #endif
+}
+
+/*
* plugin_end: shutdown plugin interface
*/
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 96c7ca130..0a46d7136 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -23,10 +23,21 @@
#ifndef __WEECHAT_PLUGINS_H
#define __WEECHAT_PLUGINS_H 1
-#define PLUGIN_TYPE_UNKNOWN 0
-#define PLUGIN_TYPE_PERL 1
-#define PLUGIN_TYPE_PYTHON 2
-#define PLUGIN_TYPE_RUBY 3
+#define PLUGIN_TYPE_PERL 0
+#define PLUGIN_TYPE_PYTHON 1
+#define PLUGIN_TYPE_RUBY 2
+
+typedef struct t_plugin_script t_plugin_script;
+
+struct t_plugin_script
+{
+ char *name; /* name of script */
+ char *version; /* version of script */
+ char *shutdown_func; /* function when script ends */
+ char *description; /* description of script */
+ t_plugin_script *prev_script; /* link to previous Perl script */
+ t_plugin_script *next_script; /* link to next Perl script */
+};
typedef struct t_plugin_handler t_plugin_handler;
@@ -46,6 +57,9 @@ extern t_plugin_handler *last_plugin_msg_handler;
extern t_plugin_handler *plugin_cmd_handlers;
extern t_plugin_handler *last_plugin_cmd_handler;
+#ifdef PLUGIN_PERL
+extern t_plugin_script *perl_scripts;
+#endif
extern void plugin_init ();
extern void plugin_load (int, char *);