diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 16:48:45 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 16:54:19 +0200 |
commit | 0c2f9cd46d7defc7df7112848c5eb817bd4564df (patch) | |
tree | 05bcf057ee64b3e9f9e066ac182d46b8a7f4a126 | |
parent | 407bde189a8cd0009e9e3cad8d8ba80d45833979 (diff) | |
download | wydawca-0c2f9cd46d7defc7df7112848c5eb817bd4564df.tar.gz wydawca-0c2f9cd46d7defc7df7112848c5eb817bd4564df.tar.bz2 |
New informative options.
* modules/mailutils/mod_mailutils.c (wy_help): Implement
module help.
* src/wydawca.c (main): Using -t and -d options together produces a
print out of the configuration parse tree. Additional -d
option includes source file locations.
* src/module.c (module_help): New function.
* src/module.h (module_help): New proto.
-rw-r--r-- | modules/mailutils/mod_mailutils.c | 40 | ||||
-rw-r--r-- | src/cmdline.opt | 7 | ||||
-rw-r--r-- | src/module.c | 41 | ||||
-rw-r--r-- | src/wydawca.c | 8 | ||||
-rw-r--r-- | src/wydawca.h | 1 |
5 files changed, 91 insertions, 6 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c index a3d903c..ae437ff 100644 --- a/modules/mailutils/mod_mailutils.c +++ b/modules/mailutils/mod_mailutils.c @@ -480,18 +480,12 @@ static struct grecs_keyword mail_kw[] = { grecs_type_section, GRECS_DFLT, NULL, 0, NULL, NULL, mail_statistics_kw }, { NULL } }; -void -wy_help(void) -{ - /* FIXME */ -} - int wy_open(grecs_node_t *node) { int rc = 0; mu_register_all_mailer_formats(); @@ -819,6 +813,40 @@ wy_notify(void *data, int ev, wy_triplet_t trp) if (trp) t_notify(evt, ev, trp); else if (ev == wy_ev_statistics) mail_stats(evt); } + +void +wy_help(void) +{ + static char *docstring = "\n\ +Mod_mailutils sends notifications about various Wydawca events\n\ +via electronic mail.\n"; + + static struct grecs_keyword init_top[] = { + { "module-init", "'mailutils", + "module initialization", + grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, + mail_kw }, + { NULL } + }; + + static struct grecs_keyword config_top[] = { + { "module-config", NULL, + "module configuration", + grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, + notify_event_kw }, + { NULL } + }; + + puts(docstring); + printf("Configuration statements:\n\n"); + grecs_print_statement_array(init_top, 1, 0, stdout); + + printf("\n\n# Usage in notify-event statement:\n"); + printf("notify-event {\n ..."); + grecs_print_statement_array(config_top, 1, 1, stdout); + printf("}\n"); +} + diff --git a/src/cmdline.opt b/src/cmdline.opt index 039dc6b..5862d87 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -198,12 +198,19 @@ OPTION(config-help,,, [<show configuration file summary>]) BEGIN config_help(); exit(0); END +OPTION(module-help,,MODULE, + [<show help for MODULE>]) +BEGIN + module_help(optarg); + exit(0); +END + OPTIONS_END void parse_options(int argc, char *argv[]) { GETOPT(argc, argv); diff --git a/src/module.c b/src/module.c index 212b740..c009971 100644 --- a/src/module.c +++ b/src/module.c @@ -254,6 +254,47 @@ module_flush(const char *name, void *modcfg) wy_log(LOG_ERR, "no such module: %s", name); return; } if (mod->flush) mod->flush(modcfg); } + +void +module_help(const char *modname) +{ + lt_dladvise advise = NULL; + struct module mod; + void (*help)(void); + + if (lt_dlinit()) { + wy_log(LOG_ERR, _("failed to initialize libtool")); + exit(EX_UNAVAILABLE); + } + + lt_dladdsearchdir(WYDAWCA_MODDIR); + + if (lt_dladvise_init(&advise)) + wy_log(LOG_ERR, "lt_dladvise_init: %s", lt_dlerror()); + else { + if (lt_dladvise_ext(&advise)) + wy_log(LOG_ERR, "lt_dladvise_ext: %s", lt_dlerror()); + if (lt_dladvise_global(&advise)) + wy_log(LOG_ERR, "lt_dladvise_global: %s", + lt_dlerror()); + } + + memset(&mod, 0, sizeof(mod)); + mod.path = modname; + + if (modload(&mod, advise)) + exit(EX_UNAVAILABLE); + + lt_dladvise_destroy(&advise); + + help = resolve_sym(&mod, "help"); + if (!help) + wy_log(LOG_NOTICE, "no help for %s", modname); + else + help(); + + lt_dlclose(mod.handle); +} diff --git a/src/wydawca.c b/src/wydawca.c index 3561994..2f7332d 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -365,12 +365,20 @@ main(int argc, char **argv) tree = grecs_parse(conffile); if (!tree) exit(EX_CONFIG); config_finish(tree); modules_load(); + if (lint_mode && wy_debug_level) { + grecs_print_node(tree, + GRECS_NODE_FLAG_DEFAULT| + (wy_debug_level > 1 ? + GRECS_NODE_FLAG_LOCUS : 0), + stdout); + fputc('\n', stdout); + } grecs_tree_free(tree); if (lint_mode) exit(0); if (wy_dry_run || selected_spools()) diff --git a/src/wydawca.h b/src/wydawca.h index 55929ee..2336851 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -309,12 +309,13 @@ struct module { }; int cb_module(enum grecs_callback_command cmd, grecs_node_t *node, void *varptr, void *cb_data); void modules_load(void); void modules_close(void); +void modules_help(void); int module_set_init(const char *name, grecs_node_t *node); extern struct grecs_list *module_load_path, *module_prepend_load_path; void module_notify(const char *name, void *modcfg, enum wy_event ev, struct wy_triplet *tpl); |