diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-10-22 18:39:50 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-10-22 18:39:50 +0300 |
commit | 97fb4785661350ab0ff8ae5605d1bdf7f6566386 (patch) | |
tree | c8c8110991cd8249597e42c937a92073bd34e226 | |
parent | 6856669720c066769f82b90fee521fd05794dec0 (diff) | |
download | mailutils-97fb4785661350ab0ff8ae5605d1bdf7f6566386.tar.gz mailutils-97fb4785661350ab0ff8ae5605d1bdf7f6566386.tar.bz2 |
Provide extended interface to mu_cli.
* include/mailutils/cfg.h (MU_CFG_APPEND_TREE): New flag.
* include/mailutils/cli.h (mu_version_copyright): New extern.
(mu_cli_ext): New proto.
* libmailutils/cfg/parser.y (mu_cfg_parse_config): Check for
MU_CFG_APPEND_TREE bit set before accessing hints->append_tree.
* libmailutils/cli/cli.c (param_set): Likewise.
(mu_cli_ext): New function.
(mu_cli): Rewrite as an entry point to mu_cli_ext.
* comsat/comsat.c: Remove inclusion of obsolete headers.
* mu/help.c: Likewise.
* pop3d/extra.c: Likewise.
-rw-r--r-- | comsat/comsat.c | 3 | ||||
-rw-r--r-- | include/mailutils/cfg.h | 1 | ||||
-rw-r--r-- | include/mailutils/cli.h | 9 | ||||
-rw-r--r-- | libmailutils/cfg/parser.y | 2 | ||||
-rw-r--r-- | libmailutils/cli/cli.c | 139 | ||||
-rw-r--r-- | mu/help.c | 1 | ||||
-rw-r--r-- | pop3d/extra.c | 1 |
7 files changed, 113 insertions, 43 deletions
diff --git a/comsat/comsat.c b/comsat/comsat.c index c12ed2082..e16f91a23 100644 --- a/comsat/comsat.c +++ b/comsat/comsat.c @@ -16,8 +16,7 @@ along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ #include "comsat.h" -#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */ -#include "mailutils/libcfg.h" +#include "mailutils/syslog.h" #include "mailutils/cli.h" #ifndef PATH_DEV diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h index e9f3587ef..1a69c82cb 100644 --- a/include/mailutils/cfg.h +++ b/include/mailutils/cfg.h @@ -241,6 +241,7 @@ int mu_config_register_plain_section (const char *parent_path, #define MU_CFG_FMT_VALUE_ONLY 0x100 #define MU_CFG_FMT_PARAM_PATH 0x200 #define MU_PARSE_CONFIG_LINT 0x400 +#define MU_CFG_APPEND_TREE 0x800 #ifdef MU_CFG_COMPATIBILITY # define MU_CFG_DEPRECATED diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h index fbf31f3b1..eaf0f8d58 100644 --- a/include/mailutils/cli.h +++ b/include/mailutils/cli.h @@ -54,10 +54,19 @@ struct mu_cli_setup void (*prog_doc_hook) (mu_stream_t); }; +extern const char mu_version_copyright[]; + void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream); void mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, void *data, int *ret_argc, char ***ret_argv); +void mu_cli_ext (int argc, char **argv, + struct mu_cli_setup *setup, + struct mu_parseopt *pohint, + struct mu_cfg_parse_hints *cfhint, + char **capa, + void *data, + int *ret_argc, char ***ret_argv); char *mu_site_config_file (void); diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y index 043f7e0c7..a530f10f5 100644 --- a/libmailutils/cfg/parser.y +++ b/libmailutils/cfg/parser.y @@ -1590,7 +1590,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints) } } - if (hints->append_tree) + if (hints->flags & MU_CFG_APPEND_TREE) mu_cfg_tree_union (&tree, &hints->append_tree); *ptree = tree; diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c index d60755157..bf3edaeaa 100644 --- a/libmailutils/cli/cli.c +++ b/libmailutils/cli/cli.c @@ -155,8 +155,11 @@ param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg) if (rc) mu_parseopt_error (po, "%s: cannot create node: %s", arg, mu_strerror (rc)); - if (!hints->append_tree) - mu_cfg_tree_create (&hints->append_tree); + if (!(hints->flags & MU_CFG_APPEND_TREE)) + { + mu_cfg_tree_create (&hints->append_tree); + hints->flags |= MU_CFG_APPEND_TREE; + } mu_cfg_tree_add_node (hints->append_tree, node); } @@ -334,11 +337,25 @@ run_commit (void *item, void *data) commit (data); return 0; } - + +#define PRESERVE_FLAGS \ + ( MU_PARSEOPT_NO_SORT \ + | MU_PARSEOPT_SINGLE_DASH \ + | MU_PARSEOPT_PACKAGE_NAME \ + | MU_PARSEOPT_PACKAGE_URL \ + | MU_PARSEOPT_BUG_ADDRESS \ + | MU_PARSEOPT_EXTRA_INFO \ + | MU_PARSEOPT_VERSION_HOOK \ + | MU_PARSEOPT_NEGATION) + void -mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, - void *data, - int *ret_argc, char ***ret_argv) +mu_cli_ext (int argc, char **argv, + struct mu_cli_setup *setup, + struct mu_parseopt *pohint, + struct mu_cfg_parse_hints *cfhint, + char **capa, + void *data, + int *ret_argc, char ***ret_argv) { struct mu_parseopt po; int flags = 0; @@ -356,14 +373,22 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, setup->ex_usage = EX_USAGE; if (setup->ex_config == 0) setup->ex_config = EX_CONFIG; - if (setup->inorder) - flags |= MU_PARSEOPT_IN_ORDER; - - /* Set program name */ - mu_set_program_name (argv[0]); - if (!mu_log_tag) - mu_log_tag = (char*)mu_program_name; + hints = *cfhint; + /* Set program name */ + if (hints.flags & MU_CFG_PARSE_PROGRAM) + { + if (!mu_log_tag) + mu_log_tag = (char*)hints.program; + } + else + { + mu_set_program_name (argv[0]); + if (!mu_log_tag) + mu_log_tag = (char*)mu_program_name; + hints.program = (char*) mu_program_name; + hints.flags |= MU_CFG_PARSE_PROGRAM; + } /* Initialize standard streams */ mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); @@ -371,16 +396,6 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, /* Initialize standard capabilities */ mu_cli_capa_init (); - /* Initialize hints */ - memset (&hints, 0, sizeof (hints)); - hints.flags |= MU_CFG_PARSE_SITE_RCFILE; - hints.site_rcfile = mu_site_config_file (); - - hints.flags |= MU_CFG_PARSE_PROGRAM; - hints.program = (char*) mu_program_name; - - hints.data = setup; - /* Initialize po */ if (setup->prog_doc) @@ -388,6 +403,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, po.po_prog_doc = setup->prog_doc; flags |= MU_PARSEOPT_PROG_DOC; } + else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC) + { + po.po_prog_doc = pohint->po_prog_doc; + flags |= MU_PARSEOPT_PROG_DOC; + } if (setup->prog_args) { @@ -415,21 +435,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, flags |= MU_PARSEOPT_PROG_ARGS; } - - po.po_package_name = PACKAGE_NAME; - flags |= MU_PARSEOPT_PACKAGE_NAME; - - po.po_package_url = PACKAGE_URL; - flags |= MU_PARSEOPT_PACKAGE_URL; - - po.po_bug_address = PACKAGE_BUGREPORT; - flags |= MU_PARSEOPT_BUG_ADDRESS; - - po.po_extra_info = gnu_general_help_url; - flags |= MU_PARSEOPT_EXTRA_INFO; - - po.po_version_hook = mu_version_hook; - flags |= MU_PARSEOPT_VERSION_HOOK; + else if (pohint->po_flags & MU_PARSEOPT_PROG_ARGS) + { + po.po_prog_args = pohint->po_prog_args; + flags |= MU_PARSEOPT_PROG_ARGS; + } if (setup->prog_extra_doc) { @@ -442,7 +452,30 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, po.po_prog_doc_hook = prog_doc_hook; flags |= MU_PARSEOPT_PROG_DOC_HOOK; } + else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC_HOOK) + { + po.po_prog_doc_hook = pohint->po_prog_doc_hook; + flags |= MU_PARSEOPT_PROG_DOC_HOOK; + } + + if (setup->inorder) + flags |= MU_PARSEOPT_IN_ORDER; + flags |= pohint->po_flags & PRESERVE_FLAGS; + + if (flags & MU_PARSEOPT_PACKAGE_NAME) + po.po_package_name = pohint->po_package_name; + if (flags & MU_PARSEOPT_PACKAGE_URL) + po.po_package_url = pohint->po_package_url; + if (flags & MU_PARSEOPT_BUG_ADDRESS) + po.po_bug_address = pohint->po_bug_address; + if (flags & MU_PARSEOPT_EXTRA_INFO) + po.po_extra_info = pohint->po_extra_info; + if (flags & MU_PARSEOPT_VERSION_HOOK) + po.po_version_hook = pohint->po_version_hook; + if (flags & MU_PARSEOPT_NEGATION) + po.po_negation = pohint->po_negation; + po.po_data = &hints; flags |= MU_PARSEOPT_DATA; @@ -488,3 +521,33 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, mu_parseopt_free (&po); } + +void +mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, + void *data, + int *ret_argc, char ***ret_argv) +{ + struct mu_parseopt pohint; + struct mu_cfg_parse_hints cfhint; + + pohint.po_package_name = PACKAGE_NAME; + pohint.po_flags |= MU_PARSEOPT_PACKAGE_NAME; + + pohint.po_package_url = PACKAGE_URL; + pohint.po_flags |= MU_PARSEOPT_PACKAGE_URL; + + pohint.po_bug_address = PACKAGE_BUGREPORT; + pohint.po_flags |= MU_PARSEOPT_BUG_ADDRESS; + + pohint.po_extra_info = gnu_general_help_url; + pohint.po_flags |= MU_PARSEOPT_EXTRA_INFO; + + pohint.po_version_hook = mu_version_hook; + pohint.po_flags |= MU_PARSEOPT_VERSION_HOOK; + + cfhint.site_rcfile = mu_site_config_file (); + cfhint.flags = MU_CFG_PARSE_SITE_RCFILE; + + mu_cli_ext (argc, argv, setup, &pohint, &cfhint, capa, data, + ret_argc, ret_argv); +} @@ -22,7 +22,6 @@ #include <stdlib.h> #include <mailutils/nls.h> #include <mailutils/io.h> -#include "mailutils/libargp.h" #include "mu.h" static char help_doc[] = N_("mu help - display a terse help summary"); diff --git a/pop3d/extra.c b/pop3d/extra.c index 608d8fc5f..aa15f79b6 100644 --- a/pop3d/extra.c +++ b/pop3d/extra.c @@ -16,7 +16,6 @@ along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ #include "pop3d.h" -#include "mailutils/libargp.h" #include "mailutils/property.h" mu_stream_t iostream; |