diff options
author | Timo Sirainen <cras@irssi.org> | 2001-08-14 00:41:59 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-08-14 00:41:59 +0000 |
commit | 803d8050164eaaefdd52fd4ae967c1e038b3c571 (patch) | |
tree | 615ff88add7d3682beebed692f41f5135c799713 /src/fe-common/core | |
parent | f584c1013c74a98bfb43b79280c4ee20b775970a (diff) | |
download | irssi-803d8050164eaaefdd52fd4ae967c1e038b3c571.zip |
Module loading updates - /LOAD shows now also the statically loaded modules.
You can't /LOAD the same module twice. Syntax changed to /LOAD <module>
[<submodule>], /UNLOAD <module> [<submodule>].
NOTE: all modules now need to call register_module() in their init()
function.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1748 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common/core')
-rw-r--r-- | src/fe-common/core/fe-common-core.c | 2 | ||||
-rw-r--r-- | src/fe-common/core/fe-modules.c | 155 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.c | 15 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.h | 1 |
4 files changed, 139 insertions, 34 deletions
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 66a2e602..0f5ce6ea 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -206,6 +206,8 @@ void fe_common_core_init(void) signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected); signal_add_first("channel created", (SIGNAL_FUNC) sig_channel_created); signal_add_last("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed); + + module_register("core", "fe"); } void fe_common_core_deinit(void) diff --git a/src/fe-common/core/fe-modules.c b/src/fe-common/core/fe-modules.c index e351dc71..5bbcf0b5 100644 --- a/src/fe-common/core/fe-modules.c +++ b/src/fe-common/core/fe-modules.c @@ -20,6 +20,7 @@ #include "module.h" #include "modules.h" +#include "modules-load.h" #include "module-formats.h" #include "signals.h" #include "commands.h" @@ -28,49 +29,99 @@ #include "printtext.h" -static void sig_module_error(void *number, const char *module, - const char *data) +#ifdef HAVE_GMODULE + +static void sig_module_error(void *number, const char *data, + const char *rootmodule, const char *submodule) { switch (GPOINTER_TO_INT(number)) { case MODULE_ERROR_ALREADY_LOADED: printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_MODULE_ALREADY_LOADED, module); + TXT_MODULE_ALREADY_LOADED, rootmodule, submodule); break; case MODULE_ERROR_LOAD: printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_MODULE_LOAD_ERROR, module, data); + TXT_MODULE_LOAD_ERROR, rootmodule, submodule, data); break; case MODULE_ERROR_INVALID: printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_MODULE_INVALID, module); + TXT_MODULE_INVALID, rootmodule, submodule); break; } } -static void sig_module_loaded(MODULE_REC *rec) +static void sig_module_loaded(MODULE_REC *module, MODULE_FILE_REC *file) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - TXT_MODULE_LOADED, rec->name); + TXT_MODULE_LOADED, module->name, file->name); } -static void sig_module_unloaded(MODULE_REC *rec) +static void sig_module_unloaded(MODULE_REC *module, MODULE_FILE_REC *file) { - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - TXT_MODULE_UNLOADED, rec->name); + if (file != NULL && file->gmodule != NULL) { + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + TXT_MODULE_UNLOADED, module->name, file->name); + } +} + +static int module_list_sub(MODULE_REC *module, int mark_type, + GString *submodules) +{ + GSList *tmp; + int all_dynamic, dynamic; + + g_string_truncate(submodules, 0); + + all_dynamic = -1; + for (tmp = module->files; tmp != NULL; tmp = tmp->next) { + MODULE_FILE_REC *file = tmp->data; + + /* if there's dynamic and static modules mixed, we'll need + to specify them separately */ + if (!mark_type) { + dynamic = file->gmodule != NULL; + if (all_dynamic != -1 && all_dynamic != dynamic) { + return module_list_sub(module, TRUE, + submodules); + } + all_dynamic = dynamic; + } + + if (submodules->len > 0) + g_string_append_c(submodules, ' '); + g_string_append(submodules, file->name); + if (mark_type) { + g_string_append(submodules, file->gmodule == NULL ? + " (static)" : " (dynamic)"); + } + } + + return all_dynamic; } static void cmd_load_list(void) { GSList *tmp; + GString *submodules; + const char *type; + int dynamic; + + submodules = g_string_new(NULL); - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_HEADER); + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_MODULE_HEADER); for (tmp = modules; tmp != NULL; tmp = tmp->next) { MODULE_REC *rec = tmp->data; - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - TXT_MODULE_LINE, rec->name); + dynamic = module_list_sub(rec, FALSE, submodules); + type = dynamic == -1 ? "mixed" : + dynamic ? "dynamic" : "static"; + + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, + TXT_MODULE_LINE, rec->name, type, submodules->str); } - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_FOOTER); + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_MODULE_FOOTER); + + g_string_free(submodules, TRUE); } static char **module_prefixes_get(void) @@ -108,36 +159,67 @@ static void module_prefixes_free(char **list) g_free(list); } -/* SYNTAX: LOAD <module> */ +/* SYNTAX: LOAD <module> [<submodule>] */ static void cmd_load(const char *data) { -#ifdef HAVE_GMODULE + char *rootmodule, *submodule; char **module_prefixes; + void *free_arg; g_return_if_fail(data != NULL); - if (*data == '\0') + + if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule)) + return; + + if (*rootmodule == '\0') cmd_load_list(); else { module_prefixes = module_prefixes_get(); - module_load(data, module_prefixes); + if (*submodule == '\0') + module_load(rootmodule, module_prefixes); + else { + module_load_sub(rootmodule, submodule, + module_prefixes); + } module_prefixes_free(module_prefixes); } -#else - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, - "Dynamic modules loading not supported"); -#endif + + cmd_params_free(free_arg); } -/* SYNTAX: UNLOAD <module> */ +/* SYNTAX: UNLOAD <module> [<submodule>] */ static void cmd_unload(const char *data) { - MODULE_REC *rec; + MODULE_REC *module; + MODULE_FILE_REC *file; + char *rootmodule, *submodule; + void *free_arg; g_return_if_fail(data != NULL); - if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); - rec = module_find(data); - if (rec != NULL) module_unload(rec); + if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule)) + return; + if (*rootmodule == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); + + module = module_find(rootmodule); + if (module != NULL) { + if (*submodule == '\0') + module_unload(module); + else { + file = module_file_find(module, submodule); + if (file != NULL) + module_file_unload(file); + else + module = NULL; + } + } + + if (module == NULL) { + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_MODULE_NOT_LOADED, rootmodule, submodule); + } + + cmd_params_free(free_arg); } void fe_modules_init(void) @@ -159,3 +241,22 @@ void fe_modules_deinit(void) command_unbind("load", (SIGNAL_FUNC) cmd_load); command_unbind("unload", (SIGNAL_FUNC) cmd_unload); } + +#else /* !HAVE_GMODULE */ + +static void cmd_load(const char *data) +{ + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + "Dynamic modules loading not supported"); +} + +void fe_modules_init(void) +{ + command_bind("load", NULL, (SIGNAL_FUNC) cmd_load); +} + +void fe_modules_deinit(void) +{ + command_unbind("load", (SIGNAL_FUNC) cmd_load); +} +#endif diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 46fe4de0..dbb8bb3e 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -179,14 +179,15 @@ FORMAT_REC fecommon_core_formats[] = { /* ---- */ { NULL, "Modules", 0 }, - { "module_header", "Loaded modules:", 0, }, - { "module_line", " $0", 1, { 0 } }, + { "module_header", "Module Type Submodules", 0, }, + { "module_line", "$[!20]0 $[7]1 $2", 3, { 0, 0, 0 } }, { "module_footer", "", 0, }, - { "module_already_loaded", "Module {hilight $0} already loaded", 1, { 0 } }, - { "module_load_error", "Error loading module {hilight $0}: $1", 2, { 0, 0 } }, - { "module_invalid", "{hilight $0} isn't Irssi module", 1, { 0 } }, - { "module_loaded", "Loaded module {hilight $0}", 1, { 0 } }, - { "module_unloaded", "Unloaded module {hilight $0}", 1, { 0 } }, + { "module_already_loaded", "Module {hilight $0/$1} already loaded", 2, { 0, 0 } }, + { "module_not_loaded", "Module {hilight $0/$1} is not loaded", 2, { 0, 0 } }, + { "module_load_error", "Error loading module {hilight $0/$1}: $2", 3, { 0, 0, 0 } }, + { "module_invalid", "{hilight $0/$1} isn't Irssi module", 2, { 0, 0 } }, + { "module_loaded", "Loaded module {hilight $0/$1}", 2, { 0, 0 } }, + { "module_unloaded", "Unloaded module {hilight $0/$1}", 2, { 0, 0 } }, /* ---- */ { NULL, "Commands", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index eacbc8aa..6e93f70c 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -153,6 +153,7 @@ enum { TXT_MODULE_LINE, TXT_MODULE_FOOTER, TXT_MODULE_ALREADY_LOADED, + TXT_MODULE_NOT_LOADED, TXT_MODULE_LOAD_ERROR, TXT_MODULE_INVALID, TXT_MODULE_LOADED, |