diff options
-rw-r--r-- | src/common/command.c | 87 | ||||
-rw-r--r-- | src/plugins/perl/wee-perl.c | 94 | ||||
-rw-r--r-- | src/plugins/perl/wee-perl.h | 16 | ||||
-rw-r--r-- | src/plugins/plugins.c | 83 | ||||
-rw-r--r-- | src/plugins/plugins.h | 22 | ||||
-rw-r--r-- | weechat/src/common/command.c | 87 | ||||
-rw-r--r-- | weechat/src/plugins/perl/wee-perl.c | 94 | ||||
-rw-r--r-- | weechat/src/plugins/perl/wee-perl.h | 16 | ||||
-rw-r--r-- | weechat/src/plugins/plugins.c | 83 | ||||
-rw-r--r-- | weechat/src/plugins/plugins.h | 22 |
10 files changed, 416 insertions, 188 deletions
diff --git a/src/common/command.c b/src/common/command.c index 10a9eecd0..769edcd6b 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -61,9 +61,8 @@ t_weechat_command weechat_commands[] = N_("[command]"), N_("command: name of a WeeChat or IRC command"), 0, 1, weechat_cmd_help, NULL }, { "perl", N_("list/load/unload Perl scripts"), - N_("[load filename] | [unload scriptname]"), + N_("[load filename] | [unload]"), N_("filename: Perl script (file) to load\n" - "scriptname: name of script to unload\n" "Without argument, /perl command lists all loaded Perl scripts."), 0, 2, weechat_cmd_perl, NULL }, { "server", N_("list, add or remove servers"), @@ -990,32 +989,86 @@ weechat_cmd_help (int argc, char **argv) int weechat_cmd_perl (int argc, char **argv) { + #ifdef PLUGINS + t_plugin_script *ptr_plugin_script; + t_plugin_handler *ptr_plugin_handler; + int handler_found; + #ifdef PLUGIN_PERL switch (argc) { case 0: - /* list all Perl scripts */ - /* TODO: get list and display it */ - break; - case 2: - if (strcmp (argv[0], "load") == 0) + /* list registered Perl scripts */ + gui_printf (NULL, _("Registered Perl scripts:\n")); + if (perl_scripts) { - /* load Perl script */ - plugin_load (PLUGIN_PERL, argv[1]); + for (ptr_plugin_script = perl_scripts; ptr_plugin_script; + ptr_plugin_script = ptr_plugin_script->next_script) + { + gui_printf (NULL, " %s v%s%s%s\n", + ptr_plugin_script->name, + ptr_plugin_script->version, + (ptr_plugin_script->description[0]) ? " - " : "", + ptr_plugin_script->description); + } } else + gui_printf (NULL, _(" (none)\n")); + + /* list Perl message handlers */ + gui_printf (NULL, _("Perl message handlers:\n")); + handler_found = 0; + for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler; + ptr_plugin_handler = ptr_plugin_handler->next_handler) { - if (strcmp (argv[0], "unload") == 0) + if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL) { - /* unload Perl script */ + handler_found = 1; + gui_printf (NULL, " IRC(%s) => Perl(%s)\n", + ptr_plugin_handler->name, + ptr_plugin_handler->function_name); } - else + } + if (!handler_found) + gui_printf (NULL, _(" (none)\n")); + + /* list Perl command handlers */ + gui_printf (NULL, _("Perl command handlers:\n")); + handler_found = 0; + for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler; + ptr_plugin_handler = ptr_plugin_handler->next_handler) + { + if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL) { - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "perl"); + handler_found = 1; + gui_printf (NULL, " Command /%s => Perl(%s)\n", + ptr_plugin_handler->name, + ptr_plugin_handler->function_name); } } + if (!handler_found) + gui_printf (NULL, _(" (none)\n")); + + break; + case 1: + if (strcmp (argv[0], "unload") == 0) + { + /* unload all Perl scripts */ + plugin_unload (PLUGIN_TYPE_PERL, NULL); + } + break; + case 2: + if (strcmp (argv[0], "load") == 0) + { + /* load Perl script */ + plugin_load (PLUGIN_TYPE_PERL, argv[1]); + } + else + { + gui_printf (NULL, + _("%s unknown option for \"%s\" command\n"), + WEECHAT_ERROR, "perl"); + } break; default: gui_printf (NULL, @@ -1030,7 +1083,9 @@ weechat_cmd_perl (int argc, char **argv) /* make gcc happy */ (void) argc; (void) argv; - #endif + #endif /* PLUGIN_PERL */ + + #endif /* PLUGINS */ return 0; } 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 *); diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c index 10a9eecd0..769edcd6b 100644 --- a/weechat/src/common/command.c +++ b/weechat/src/common/command.c @@ -61,9 +61,8 @@ t_weechat_command weechat_commands[] = N_("[command]"), N_("command: name of a WeeChat or IRC command"), 0, 1, weechat_cmd_help, NULL }, { "perl", N_("list/load/unload Perl scripts"), - N_("[load filename] | [unload scriptname]"), + N_("[load filename] | [unload]"), N_("filename: Perl script (file) to load\n" - "scriptname: name of script to unload\n" "Without argument, /perl command lists all loaded Perl scripts."), 0, 2, weechat_cmd_perl, NULL }, { "server", N_("list, add or remove servers"), @@ -990,32 +989,86 @@ weechat_cmd_help (int argc, char **argv) int weechat_cmd_perl (int argc, char **argv) { + #ifdef PLUGINS + t_plugin_script *ptr_plugin_script; + t_plugin_handler *ptr_plugin_handler; + int handler_found; + #ifdef PLUGIN_PERL switch (argc) { case 0: - /* list all Perl scripts */ - /* TODO: get list and display it */ - break; - case 2: - if (strcmp (argv[0], "load") == 0) + /* list registered Perl scripts */ + gui_printf (NULL, _("Registered Perl scripts:\n")); + if (perl_scripts) { - /* load Perl script */ - plugin_load (PLUGIN_PERL, argv[1]); + for (ptr_plugin_script = perl_scripts; ptr_plugin_script; + ptr_plugin_script = ptr_plugin_script->next_script) + { + gui_printf (NULL, " %s v%s%s%s\n", + ptr_plugin_script->name, + ptr_plugin_script->version, + (ptr_plugin_script->description[0]) ? " - " : "", + ptr_plugin_script->description); + } } else + gui_printf (NULL, _(" (none)\n")); + + /* list Perl message handlers */ + gui_printf (NULL, _("Perl message handlers:\n")); + handler_found = 0; + for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler; + ptr_plugin_handler = ptr_plugin_handler->next_handler) { - if (strcmp (argv[0], "unload") == 0) + if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL) { - /* unload Perl script */ + handler_found = 1; + gui_printf (NULL, " IRC(%s) => Perl(%s)\n", + ptr_plugin_handler->name, + ptr_plugin_handler->function_name); } - else + } + if (!handler_found) + gui_printf (NULL, _(" (none)\n")); + + /* list Perl command handlers */ + gui_printf (NULL, _("Perl command handlers:\n")); + handler_found = 0; + for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler; + ptr_plugin_handler = ptr_plugin_handler->next_handler) + { + if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL) { - gui_printf (NULL, - _("%s unknown option for \"%s\" command\n"), - WEECHAT_ERROR, "perl"); + handler_found = 1; + gui_printf (NULL, " Command /%s => Perl(%s)\n", + ptr_plugin_handler->name, + ptr_plugin_handler->function_name); } } + if (!handler_found) + gui_printf (NULL, _(" (none)\n")); + + break; + case 1: + if (strcmp (argv[0], "unload") == 0) + { + /* unload all Perl scripts */ + plugin_unload (PLUGIN_TYPE_PERL, NULL); + } + break; + case 2: + if (strcmp (argv[0], "load") == 0) + { + /* load Perl script */ + plugin_load (PLUGIN_TYPE_PERL, argv[1]); + } + else + { + gui_printf (NULL, + _("%s unknown option for \"%s\" command\n"), + WEECHAT_ERROR, "perl"); + } break; default: gui_printf (NULL, @@ -1030,7 +1083,9 @@ weechat_cmd_perl (int argc, char **argv) /* make gcc happy */ (void) argc; (void) argv; - #endif + #endif /* PLUGIN_PERL */ + + #endif /* PLUGINS */ return 0; } diff --git a/weechat/src/plugins/perl/wee-perl.c b/weechat/src/plugins/perl/wee-perl.c index eb5941944..69ab59b4e 100644 --- a/weechat/src/plugins/perl/wee-perl.c +++ b/weechat/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/weechat/src/plugins/perl/wee-perl.h b/weechat/src/plugins/perl/wee-perl.h index c018bf44a..36b2986d7 100644 --- a/weechat/src/plugins/perl/wee-perl.h +++ b/weechat/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/weechat/src/plugins/plugins.c b/weechat/src/plugins/plugins.c index c78f2fe3e..f1d180d1a 100644 --- a/weechat/src/plugins/plugins.c +++ b/weechat/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/weechat/src/plugins/plugins.h b/weechat/src/plugins/plugins.h index 96c7ca130..0a46d7136 100644 --- a/weechat/src/plugins/plugins.h +++ b/weechat/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 *); |