summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comsat/comsat.c12
-rw-r--r--comsat/tests/testsuite.at2
-rw-r--r--imap4d/imap4d.c11
-rw-r--r--imap4d/tests/testsuite.at1
-rw-r--r--include/mailutils/cfg.h65
-rw-r--r--include/mailutils/cli.h5
-rw-r--r--libmailutils/cfg/driver.c28
-rw-r--r--libmailutils/cfg/format.c12
-rw-r--r--libmailutils/cfg/lexer.l34
-rw-r--r--libmailutils/cfg/parser.y43
-rw-r--r--libmailutils/cli/cli.c218
-rw-r--r--mail/testsuite/lib/mail.exp2
-rw-r--r--mu/acl.c4
-rw-r--r--mu/mu.c17
-rw-r--r--mu/query.c14
-rw-r--r--pop3d/pop3d.c7
-rw-r--r--pop3d/testsuite/lib/pop3d.exp3
-rw-r--r--testsuite/lib/mailutils.exp23
18 files changed, 292 insertions, 209 deletions
diff --git a/comsat/comsat.c b/comsat/comsat.c
index e16f91a23..2a6d69fca 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -194,11 +194,11 @@ struct mu_cfg_param comsat_cfg_param[] = {
static char const *alt_args[] = { N_("--test MBOX-URL MSG-QID"), NULL };
static struct mu_cli_setup cli = {
- options,
- comsat_cfg_param,
- N_("GNU comsatd -- notify users about incoming mail"),
- "",
- alt_args,
+ .optv = options,
+ .cfg =comsat_cfg_param,
+ .prog_doc = N_("GNU comsatd -- notify users about incoming mail"),
+ .prog_alt_args = alt_args,
+ .server = 1
};
static char *capa[] = {
@@ -568,7 +568,7 @@ main (int argc, char **argv)
save_argv = argv;
- mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
+ mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
if (test_mode)
{
diff --git a/comsat/tests/testsuite.at b/comsat/tests/testsuite.at
index 4c042238d..a37ad5ba2 100644
--- a/comsat/tests/testsuite.at
+++ b/comsat/tests/testsuite.at
@@ -22,7 +22,7 @@ m4_pushdef([BIFF_MBOX],[`pwd`/mailbox])
dnl ------------------------------------------------------------
dnl comsatcmd
-m4_pushdef([comsatcmd],[comsatd --no-site --no-user --file ./biff.rc dnl
+m4_pushdef([comsatcmd],[comsatd --no-site-config --file ./biff.rc dnl
--set logging.syslog=no --test])
dnl ------------------------------------------------------------
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 031c3cc4b..df9cc7a2b 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -449,9 +449,10 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
};
struct mu_cli_setup cli = {
- options,
- imap4d_cfg_param,
- N_("GNU imap4d -- the IMAP4D daemon.")
+ .optv = options,
+ .cfg = imap4d_cfg_param,
+ .prog_doc = N_("GNU imap4d -- the IMAP4D daemon."),
+ .server = 1
};
int
@@ -659,7 +660,7 @@ get_client_address (int fd, struct sockaddr_in *pcs)
}
static int
-set_strerr_flt ()
+set_strerr_flt (void)
{
mu_stream_t flt, trans[2];
int rc;
@@ -700,7 +701,7 @@ set_strerr_flt ()
}
static void
-clr_strerr_flt ()
+clr_strerr_flt (void)
{
mu_stream_t flt, trans[2];
int rc;
diff --git a/imap4d/tests/testsuite.at b/imap4d/tests/testsuite.at
index 8b98295cf..c6e84cb87 100644
--- a/imap4d/tests/testsuite.at
+++ b/imap4d/tests/testsuite.at
@@ -20,7 +20,6 @@ m4_define([IMAP4D_HOMEDIR])
m4_define([IMAP4D_DEFAULT_OPTIONS],[dnl
--no-site-config dnl
---no-user-config dnl
--test dnl
--set logging.syslog=0 dnl
--set logging.severity=notice dnl
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 1a69c82cb..9b8e951f8 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -72,17 +72,43 @@ struct mu_cfg_node
mu_list_t nodes; /* a list of mu_cfg_node_t */
struct mu_cfg_node *parent; /* parent node */
};
-
+
struct mu_cfg_parse_hints
{
int flags;
- char *site_rcfile;
- char *custom_rcfile;
+ char *site_file;
+ char *custom_file;
char *program;
- struct mu_cfg_tree *append_tree;
- void *data;
};
+/* Bit constants for the flags field of struct mu_cfg_parse_hints */
+/* Parse site-wide configuration file hints.site_file */
+#define MU_CFHINT_SITE_FILE 0x0001
+/* Parse custom configuration file hints.custom_file */
+#define MU_CFHINT_CUSTOM_FILE 0x0002
+/* The hints.program field is set. The "program PROGNAME" section
+ will be processed, if PROGNAME is the same as hints.program.
+ If include statement is used with the directory name DIR as its
+ argument, the file DIR/PROGNAME will be looked up and read in,
+ if it exists. */
+#define MU_CFHINT_PROGRAM 0x0004
+
+/* If MU_CFHINT_PROGRAM is set, look for the file ~/.PROGNAME after parsing
+ site-wide configuration */
+#define MU_CFHINT_PER_USER_FILE 0x0008
+
+/* Verbosely log files being processed */
+#define MU_CF_VERBOSE 0x0010
+/* Dump the pare tree on stderr */
+#define MU_CF_DUMP 0x0020
+
+/* Format location of the statement */
+#define MU_CF_FMT_LOCUS 0x0100
+/* Print only value */
+#define MU_CF_FMT_VALUE_ONLY 0x0200
+/* Print full parameter path */
+#define MU_CF_FMT_PARAM_PATH 0x0400
+
struct mu_cfg_tree
{
mu_list_t nodes; /* a list of mu_cfg_node_t */
@@ -140,9 +166,6 @@ struct mu_cfg_param
const char *argname;
};
-#define MU_TARGET_REF(f) &f, 0
-#define MU_TARGET_OFF(s,f) NULL, mu_offsetof(s,f)
-
enum mu_cfg_section_stage
{
mu_cfg_section_start,
@@ -230,29 +253,7 @@ int mu_config_register_plain_section (const char *parent_path,
const char *ident,
struct mu_cfg_param *params);
-#define MU_PARSE_CONFIG_GLOBAL 0x001
-#define MU_PARSE_CONFIG_VERBOSE 0x002
-#define MU_PARSE_CONFIG_DUMP 0x004
-#define MU_PARSE_CONFIG_PLAIN 0x008
-#define MU_CFG_PARSE_SITE_RCFILE 0x010
-#define MU_CFG_PARSE_CUSTOM_RCFILE 0x020
-#define MU_CFG_PARSE_PROGRAM 0x040
-#define MU_CFG_FMT_LOCUS 0x080
-#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
-#else
-# define MU_CFG_DEPRECATED MU_DEPRECATED
-#endif
-
-int mu_parse_config (const char *file, const char *progname,
- struct mu_cfg_param *progparam, int flags,
- void *target_ptr) MU_CFG_DEPRECATED;
-
extern int mu_cfg_parser_verbose;
extern size_t mu_cfg_error_count;
@@ -279,10 +280,6 @@ int mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file,
int flags);
-int mu_get_config (const char *file, const char *progname,
- struct mu_cfg_param *progparam, int flags,
- void *target_ptr) MU_CFG_DEPRECATED;
-
int mu_cfg_tree_create (struct mu_cfg_tree **ptree);
mu_cfg_node_t *mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
enum mu_cfg_node_type type,
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index eaf0f8d58..b2ed7ce48 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -50,11 +50,14 @@ struct mu_cli_setup
int ex_usage; /* If not 0, exit code on usage errors */
int ex_config; /* If not 0, exit code on configuration
errors */
- int inorder;
+ int inorder:1; /* Don't permute options and arguments */
+ int server:1; /* This is a server: don't read per-user
+ configuration files */
void (*prog_doc_hook) (mu_stream_t);
};
extern const char mu_version_copyright[];
+extern const char mu_general_help_text[];
void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream);
void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
diff --git a/libmailutils/cfg/driver.c b/libmailutils/cfg/driver.c
index f2a43a367..1b1ff050e 100644
--- a/libmailutils/cfg/driver.c
+++ b/libmailutils/cfg/driver.c
@@ -27,7 +27,6 @@
#include <ctype.h>
#include <mailutils/argcv.h>
#include <mailutils/nls.h>
-#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
#include <mailutils/cfg.h>
#include <mailutils/errno.h>
#include <mailutils/error.h>
@@ -466,14 +465,14 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree,
struct mu_cfg_cont *cont;
if (!parse_tree)
return 0;
- if (hints && (hints->flags & MU_PARSE_CONFIG_DUMP))
+ if (hints && (hints->flags & MU_CF_DUMP))
{
int yes = 1;
mu_stream_t stream;
mu_stdio_stream_create (&stream, MU_STDERR_FD, 0);
mu_stream_ioctl (stream, MU_IOCTL_FD, MU_IOCTL_FD_SET_BORROW, &yes);
- mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS);
+ mu_cfg_format_parse_tree (stream, parse_tree, MU_CF_FMT_LOCUS);
mu_stream_destroy (&stream);
}
@@ -492,29 +491,6 @@ mu_format_config_tree (mu_stream_t stream, struct mu_cfg_param *progparam)
mu_config_destroy_container (&cont);
}
-int
-mu_parse_config (const char *file, const char *progname,
- struct mu_cfg_param *progparam, int flags,
- void *target_ptr)
-{
- int rc;
- char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
- if (full_name)
- {
- if (access (full_name, R_OK) == 0)
- {
- rc = mu_get_config (full_name, progname, progparam, flags,
- target_ptr);
- }
- else
- rc = ENOENT;
- free (full_name);
- }
- else
- rc = ENOMEM;
- return rc;
-}
-
static const char *
_first_value_ptr (mu_config_value_t *val)
{
diff --git a/libmailutils/cfg/format.c b/libmailutils/cfg/format.c
index d94c8786c..926c9d59a 100644
--- a/libmailutils/cfg/format.c
+++ b/libmailutils/cfg/format.c
@@ -152,7 +152,7 @@ format_node (const mu_cfg_node_t *node, void *data)
{
struct tree_print *tp = data;
- if ((tp->flags & MU_CFG_FMT_LOCUS) && node->locus.mu_file)
+ if ((tp->flags & MU_CF_FMT_LOCUS) && node->locus.mu_file)
mu_stream_printf (tp->stream, "# %lu \"%s\"\n",
(unsigned long) node->locus.mu_line,
node->locus.mu_file);
@@ -165,7 +165,7 @@ format_node (const mu_cfg_node_t *node, void *data)
break;
case mu_cfg_node_statement:
- if (tp->flags & MU_CFG_FMT_PARAM_PATH)
+ if (tp->flags & MU_CF_FMT_PARAM_PATH)
return MU_CFG_ITER_OK;
else
{
@@ -181,9 +181,9 @@ format_node (const mu_cfg_node_t *node, void *data)
break;
case mu_cfg_node_param:
- if (tp->flags & MU_CFG_FMT_VALUE_ONLY)
+ if (tp->flags & MU_CF_FMT_VALUE_ONLY)
format_value (tp, node->label);
- else if (tp->flags & MU_CFG_FMT_PARAM_PATH)
+ else if (tp->flags & MU_CF_FMT_PARAM_PATH)
{
format_path (tp, node, ':');
mu_stream_write (tp->stream, " ", 1, NULL);
@@ -209,7 +209,7 @@ static int
format_node_end (const mu_cfg_node_t *node, void *data)
{
struct tree_print *tp = data;
- if (!(tp->flags & MU_CFG_FMT_PARAM_PATH))
+ if (!(tp->flags & MU_CF_FMT_PARAM_PATH))
{
tp->level--;
format_level (tp->stream, tp->level);
@@ -242,7 +242,7 @@ mu_cfg_format_node (mu_stream_t stream, const mu_cfg_node_t *node, int flags)
struct tree_print t;
if (node->type == mu_cfg_node_statement)
- flags &= ~MU_CFG_FMT_VALUE_ONLY;
+ flags &= ~MU_CF_FMT_VALUE_ONLY;
t.flags = flags;
t.level = 0;
t.stream = stream;
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index 2ecefce87..5e8cbf522 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -330,14 +330,14 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
int rc;
char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
- if (flags & MU_PARSE_CONFIG_VERBOSE)
+ if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("opening configuration file %s"),
full_name);
if (stat (full_name, &st))
{
if (errno != ENOENT)
mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno));
- else if (flags & MU_PARSE_CONFIG_VERBOSE)
+ else if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("configuration file %s doesn't exist"),
full_name);
free (full_name);
@@ -345,7 +345,7 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
}
else if (!S_ISREG (st.st_mode))
{
- if (flags & MU_PARSE_CONFIG_VERBOSE)
+ if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("%s: not a regular file"), full_name);
free (full_name);
return ENOENT;
@@ -360,7 +360,7 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
return errno;
}
- if (flags & MU_PARSE_CONFIG_VERBOSE)
+ if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("parsing file `%s'"), full_name);
mu_cfg_set_lex_debug ();
@@ -379,37 +379,13 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
yyrestart (fp);
rc = mu_cfg_parse (return_tree);
fclose (fp);
- if (flags & MU_PARSE_CONFIG_VERBOSE)
+ if (flags & MU_CF_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"),
mu_cfg_locus.mu_file);
return rc == 0 ? 0 : MU_ERR_FAILURE;
}
-/* FIXME: Deprecated interface */
-int
-mu_get_config (const char *file, const char *progname,
- struct mu_cfg_param *progparam, int flags, void *target_ptr)
-{
- mu_cfg_tree_t *parse_tree;
- int rc = mu_cfg_parse_file (&parse_tree, file, flags);
- if (rc == 0)
- {
- struct mu_cfg_parse_hints hints;
-
- hints.flags = flags | MU_CFG_PARSE_PROGRAM;
- hints.program = (char*)progname;
-
- rc = mu_cfg_tree_postprocess (parse_tree, &hints);
- if (rc == 0)
- rc = mu_cfg_tree_reduce (parse_tree, &hints, progparam, target_ptr);
- mu_cfg_destroy_tree (&parse_tree);
- }
-
- return rc == 0 ? 0 : MU_ERR_FAILURE;
-}
-
-
mu_opool_t
mu_cfg_lexer_pool ()
{
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 9ad8e8d60..0b362a803 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -501,8 +501,7 @@ do_include (const char *name, struct mu_cfg_parse_hints *hints,
if (S_ISDIR (sb.st_mode))
{
- if ((hints->flags & (MU_PARSE_CONFIG_GLOBAL|MU_CFG_PARSE_PROGRAM)) ==
- (MU_PARSE_CONFIG_GLOBAL|MU_CFG_PARSE_PROGRAM))
+ if (hints->flags & MU_CFHINT_PROGRAM)
{
char *file = mu_make_file_name (name, hints->program);
rc = mu_cfg_parse_file (&tree, file, hints->flags);
@@ -515,7 +514,7 @@ do_include (const char *name, struct mu_cfg_parse_hints *hints,
if (rc == 0 && tree)
{
struct mu_cfg_parse_hints xhints = *hints;
- xhints.flags &= ~MU_PARSE_CONFIG_GLOBAL;
+ xhints.flags &= ~MU_CFHINT_PROGRAM;
mu_cfg_tree_postprocess (tree, &xhints);
}
}
@@ -538,8 +537,7 @@ do_include (const char *name, struct mu_cfg_parse_hints *hints,
}
int
-mu_cfg_tree_postprocess (mu_cfg_tree_t *tree,
- struct mu_cfg_parse_hints *hints)
+mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, struct mu_cfg_parse_hints *hints)
{
int rc;
mu_iterator_t itr;
@@ -558,13 +556,12 @@ mu_cfg_tree_postprocess (mu_cfg_tree_t *tree,
if (node->type == mu_cfg_node_statement)
{
- if ((hints->flags & MU_PARSE_CONFIG_GLOBAL) &&
+ if ((hints->flags & MU_CFHINT_PROGRAM) &&
strcmp (node->tag, "program") == 0)
{
if (node->label->type == MU_CFG_STRING)
{
- if ((hints->flags & MU_CFG_PARSE_PROGRAM)
- && strcmp (node->label->v.string, hints->program) == 0)
+ if (strcmp (node->label->v.string, hints->program) == 0)
{
/* Reset the parent node */
mu_list_foreach (node->nodes, _node_set_parent,
@@ -1527,10 +1524,11 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
{
int rc = 0;
mu_cfg_tree_t *tree = NULL, *tmp;
+ struct mu_cfg_parse_hints xhints;
- if ((hints->flags & MU_CFG_PARSE_SITE_RCFILE) && hints->site_rcfile)
+ if ((hints->flags & MU_CFHINT_SITE_FILE) && hints->site_file)
{
- rc = mu_cfg_parse_file (&tmp, hints->site_rcfile, hints->flags);
+ rc = mu_cfg_parse_file (&tmp, hints->site_file, hints->flags);
if (rc == ENOMEM)
{
@@ -1539,14 +1537,16 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
}
else if (rc == 0)
{
- struct mu_cfg_parse_hints xhints = *hints;
- xhints.flags |= MU_PARSE_CONFIG_GLOBAL;
- mu_cfg_tree_postprocess (tmp, &xhints);
+ mu_cfg_tree_postprocess (tmp, hints);
mu_cfg_tree_union (&tree, &tmp);
}
}
+
+ xhints = *hints;
+ xhints.flags &= ~MU_CFHINT_PROGRAM;
- if ((hints->flags & MU_CFG_PARSE_PROGRAM) && hints->program)
+ if ((hints->flags & MU_CFHINT_PER_USER_FILE)
+ && (hints->flags & MU_CFHINT_PROGRAM))
{
size_t size = 3 + strlen (hints->program) + 1;
char *file_name = malloc (size);
@@ -1555,7 +1555,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
strcpy (file_name, "~/.");
strcat (file_name, hints->program);
- rc = mu_cfg_parse_file (&tmp, file_name, hints->flags);
+ rc = mu_cfg_parse_file (&tmp, file_name, xhints.flags);
if (rc == ENOMEM)
{
mu_error ("%s", mu_strerror (rc));
@@ -1564,7 +1564,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
}
else if (rc == 0)
{
- mu_cfg_tree_postprocess (tmp, hints);
+ mu_cfg_tree_postprocess (tmp, &xhints);
mu_cfg_tree_union (&tree, &tmp);
}
else if (rc == ENOENT)
@@ -1573,26 +1573,23 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
}
}
- if ((hints->flags & MU_CFG_PARSE_CUSTOM_RCFILE) && hints->custom_rcfile)
+ if ((hints->flags & MU_CFHINT_CUSTOM_FILE) && hints->custom_file)
{
- rc = mu_cfg_parse_file (&tmp, hints->custom_rcfile, hints->flags);
+ rc = mu_cfg_parse_file (&tmp, hints->custom_file, xhints.flags);
if (rc)
{
- mu_error (_("errors parsing file %s: %s"), hints->custom_rcfile,
+ mu_error (_("errors parsing file %s: %s"), hints->custom_file,
mu_strerror (rc));
mu_cfg_destroy_tree (&tree);
return rc;
}
else
{
- mu_cfg_tree_postprocess (tmp, hints);
+ mu_cfg_tree_postprocess (tmp, &xhints);
mu_cfg_tree_union (&tree, &tmp);
}
}
- if (hints->flags & MU_CFG_APPEND_TREE)
- mu_cfg_tree_union (&tree, &hints->append_tree);
-
*ptree = tree;
return rc;
}
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 793a3e285..b6e4ad03d 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -76,23 +76,29 @@ There is NO WARRANTY, to the extent permitted by law.\n\
"));
}
-static char gnu_general_help_url[] =
+const char mu_general_help_text[] =
N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
+struct app_data
+{
+ struct mu_cli_setup *setup;
+ struct mu_cfg_parse_hints *hints;
+ struct mu_cfg_tree *append_tree;
+ int lint;
+};
+
static void
extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- struct mu_cli_setup *setup = hints->data;
- mu_stream_printf (stream, "%s\n", _(setup->prog_extra_doc));
+ struct app_data *dp = po->po_data;
+ mu_stream_printf (stream, "%s\n", gettext (dp->setup->prog_extra_doc));
}
static void
prog_doc_hook (struct mu_parseopt *po, mu_stream_t stream)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- struct mu_cli_setup *setup = hints->data;
- setup->prog_doc_hook (stream);
+ struct app_data *dp = po->po_data;
+ dp->setup->prog_doc_hook (stream);
}
static void
@@ -100,87 +106,108 @@ change_progname (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
po->po_prog_name = mu_strdup (arg);
+ free (mu_program_name);
+ mu_program_name = mu_strdup (arg);
}
static void
no_user_config (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- hints->flags &= ~MU_CFG_PARSE_PROGRAM;
+ struct app_data *dp = po->po_data;
+ dp->hints->flags &= ~MU_CFHINT_PER_USER_FILE;
}
static void
no_site_config (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- hints->flags &= ~MU_CFG_PARSE_SITE_RCFILE;
+ struct app_data *dp = po->po_data;
+ dp->hints->flags &= ~MU_CFHINT_SITE_FILE;
+}
+
+static void
+no_config (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ struct app_data *dp = po->po_data;
+ dp->hints->flags &= ~(MU_CFHINT_SITE_FILE|MU_CFHINT_PER_USER_FILE);
}
static void
config_file (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- hints->flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
- hints->custom_rcfile = mu_strdup (arg);
+ struct app_data *dp = po->po_data;
+ dp->hints->flags = (dp->hints->flags
+ & ~(MU_CFHINT_SITE_FILE|MU_CFHINT_PROGRAM))
+ | MU_CFHINT_CUSTOM_FILE;
+ dp->hints->custom_file = mu_strdup (arg);
}
static void
config_verbose (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- if (hints->flags & MU_PARSE_CONFIG_VERBOSE)
- hints->flags |= MU_PARSE_CONFIG_DUMP;
+ struct app_data *dp = po->po_data;
+ if (dp->hints->flags & MU_CF_VERBOSE)
+ dp->hints->flags |= MU_CF_DUMP;
else
- hints->flags |= MU_PARSE_CONFIG_VERBOSE;
+ dp->hints->flags |= MU_CF_VERBOSE;
}
static void
config_lint (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
- hints->flags |= MU_PARSE_CONFIG_VERBOSE|MU_PARSE_CONFIG_LINT;
+ struct app_data *dp = po->po_data;
+ dp->lint = 1;
+ dp->hints->flags |= MU_CF_VERBOSE;
}
static void
param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
+ struct app_data *dp = po->po_data;
mu_cfg_node_t *node;
int rc = mu_cfg_create_subtree (arg, &node);
if (rc)
mu_parseopt_error (po, "%s: cannot create node: %s",
arg, mu_strerror (rc));
- if (!(hints->flags & MU_CFG_APPEND_TREE))
+ if (!dp->append_tree)
{
- mu_cfg_tree_create (&hints->append_tree);
- hints->flags |= MU_CFG_APPEND_TREE;
+ mu_cfg_tree_create (&dp->append_tree);
}
- mu_cfg_tree_add_node (hints->append_tree, node);
+ mu_cfg_tree_add_node (dp->append_tree, node);
}
struct mu_option mu_common_options[] = {
- MU_OPTION_GROUP(N_("Common options")),
+ /* MU_OPTION_GROUP(N_("Common options")),*/
{ "program-name", 0, N_("NAME"), MU_OPTION_IMMEDIATE|MU_OPTION_HIDDEN,
N_("set program name"),
mu_c_string, NULL, change_progname },
+ MU_OPTION_END
+};
+
+struct mu_option mu_config_option_header =
+ MU_OPTION_GROUP (N_("Configuration handling"));
- { "no-user-config", 0, NULL, MU_OPTION_IMMEDIATE,
- N_("do not load user configuration file"),
- mu_c_string, NULL, no_user_config },
- { "no-user-rcfile", 0, NULL, MU_OPTION_ALIAS },
-
+struct mu_option mu_site_config_options[] = {
{ "no-site-config", 0, NULL, MU_OPTION_IMMEDIATE,
N_("do not load site-wide configuration file"),
mu_c_string, NULL, no_site_config },
{ "no-site-rcfile", 0, NULL, MU_OPTION_ALIAS },
+ MU_OPTION_END
+};
+
+struct mu_option mu_no_config_option = {
+ "no-config", 0, NULL, MU_OPTION_IMMEDIATE,
+ N_("do not load site and user configuration files"),
+ mu_c_string, NULL, no_config
+};
+struct mu_option mu_config_options[] = {
{ "config-file", 0, N_("FILE"), MU_OPTION_IMMEDIATE,
- N_("load this configuration file"),
+ N_("load this configuration file; implies --no-config"),
mu_c_string, NULL, config_file },
{ "rcfile", 0, NULL, MU_OPTION_ALIAS },
@@ -197,7 +224,15 @@ struct mu_option mu_common_options[] = {
{ "set", 0, N_("PARAM=VALUE"), MU_OPTION_IMMEDIATE,
N_("set configuration parameter"),
mu_c_string, NULL, param_set },
-
+
+ MU_OPTION_END
+};
+
+struct mu_option mu_user_config_options[] = {
+ { "no-user-config", 0, NULL, MU_OPTION_IMMEDIATE,
+ N_("do not load user configuration file"),
+ mu_c_string, NULL, no_user_config },
+ { "no-user-rcfile", 0, NULL, MU_OPTION_ALIAS },
MU_OPTION_END
};
@@ -213,7 +248,7 @@ static void
show_config_help (struct mu_parseopt *po, struct mu_option *opt,
char const *unused)
{
- struct mu_cfg_parse_hints *hints = po->po_data;
+ struct app_data *dp = po->po_data;
char *comment;
mu_stream_t stream;
@@ -253,11 +288,10 @@ show_config_help (struct mu_parseopt *po, struct mu_option *opt,
cont = mu_config_clone_root_container ();
mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
dummy_include_param, NULL);
- if (hints->data)
+ if (dp->setup)
{
- struct mu_cli_setup *setup = hints->data;
mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
- setup->cfg, NULL);
+ dp->setup->cfg, NULL);
}
mu_cfg_format_container (stream, cont);
@@ -267,11 +301,15 @@ show_config_help (struct mu_parseopt *po, struct mu_option *opt,
exit (0);
}
-struct mu_option mu_extra_help_options[] = {
+static struct mu_option mu_extra_help_options[] = {
MU_OPTION_GROUP (N_("Informational options")),
{ "show-config-options", 0, NULL, MU_OPTION_IMMEDIATE,
N_("show compilation options"),
mu_c_string, NULL, show_comp_defaults },
+ MU_OPTION_END
+};
+
+static struct mu_option mu_config_help_options[] = {
{ "config-help", 0, NULL, MU_OPTION_IMMEDIATE,
N_("show configuration file summary"),
mu_c_string, NULL, show_config_help },
@@ -288,9 +326,38 @@ add_opt_group (void *item, void *data)
return 0;
}
+#define CONFIG_ENABLED \
+ (MU_CFHINT_SITE_FILE | MU_CFHINT_CUSTOM_FILE | MU_CFHINT_PER_USER_FILE)
+
+static void
+opool_add_option (mu_opool_t pool, struct mu_option *opt)
+{
+ mu_opool_append (pool, opt, sizeof *opt);
+}
+
+static void
+opool_add_options (mu_opool_t pool, struct mu_option *opt)
+{
+ while (!MU_OPTION_IS_END (opt))
+ {
+ opool_add_option (pool, opt);
+ opt++;
+ }
+}
+
+static struct mu_option *
+opool_end_option (mu_opool_t pool)
+{
+ struct mu_option end = MU_OPTION_END;
+ opool_add_option (pool, &end);
+ return mu_opool_finish (pool, NULL);
+}
+
/* Build the list of option groups and configuration sections */
static struct mu_option **
-init_options (char **capa, struct mu_cli_setup *setup,
+init_options (mu_opool_t pool,
+ char **capa, struct mu_cli_setup *setup,
+ struct mu_cfg_parse_hints const *hints,
mu_list_t *ret_comlist)
{
size_t i, s;
@@ -316,8 +383,41 @@ init_options (char **capa, struct mu_cli_setup *setup,
*ret_comlist = comlist;
mu_list_append (oplist, mu_common_options);
- mu_list_append (oplist, mu_extra_help_options);
+
+ /* Construct configuration option section */
+ if (hints->flags & CONFIG_ENABLED)
+ {
+ opool_add_option (pool, &mu_config_option_header);
+ opool_add_options (pool, mu_config_options);
+ if (hints->flags & MU_CFHINT_SITE_FILE)
+ {
+ opool_add_options (pool, mu_site_config_options);
+ if (hints->flags & MU_CFHINT_PER_USER_FILE)
+ {
+ opool_add_options (pool, mu_user_config_options);
+ opool_add_option (pool, &mu_no_config_option);
+ }
+ else
+ {
+ struct mu_option opt = mu_no_config_option;
+ opt.opt_flags = MU_OPTION_ALIAS;
+ opool_add_option (pool, &opt);
+ }
+ }
+ else if (hints->flags & MU_CFHINT_PER_USER_FILE)
+ {
+ struct mu_option opt = mu_no_config_option;
+ opool_add_options (pool, mu_user_config_options);
+ opt.opt_flags = MU_OPTION_ALIAS;
+ opool_add_option (pool, &opt);
+ }
+ mu_list_append (oplist, opool_end_option (pool));
+ }
+ mu_list_append (oplist, mu_extra_help_options);
+ if (hints->flags & CONFIG_ENABLED)
+ mu_list_append (oplist, mu_config_help_options);
+
mu_list_count (oplist, &s);
po.po_optv = mu_calloc (s + 1, sizeof (po.po_optv[0]));
@@ -367,6 +467,8 @@ mu_cli_ext (int argc, char **argv,
char const *dfl_args[DFLARGC];
char **args = NULL;
size_t argcnt;
+ struct app_data appd;
+ mu_opool_t pool;
/* Set up defaults */
if (setup->ex_usage == 0)
@@ -375,10 +477,11 @@ mu_cli_ext (int argc, char **argv,
setup->ex_config = EX_CONFIG;
hints = *cfhint;
- hints.data = setup;
+ if (setup->server)
+ hints.flags &= ~MU_CFHINT_PER_USER_FILE;
/* Set program name */
- if (hints.flags & MU_CFG_PARSE_PROGRAM)
+ if (hints.flags & MU_CFHINT_PROGRAM)
{
if (!mu_log_tag)
mu_log_tag = (char*)hints.program;
@@ -389,7 +492,7 @@ mu_cli_ext (int argc, char **argv,
if (!mu_log_tag)
mu_log_tag = (char*)mu_program_name;
hints.program = (char*) mu_program_name;
- hints.flags |= MU_CFG_PARSE_PROGRAM;
+ hints.flags |= MU_CFHINT_PROGRAM;
}
/* Initialize standard streams */
@@ -478,12 +581,17 @@ mu_cli_ext (int argc, char **argv,
if (flags & MU_PARSEOPT_NEGATION)
po.po_negation = pohint->po_negation;
- po.po_data = &hints;
+ appd.setup = setup;
+ appd.hints = &hints;
+ appd.append_tree = NULL;
+ appd.lint = 0;
+ po.po_data = &appd;
flags |= MU_PARSEOPT_DATA;
po.po_exit_error = setup->ex_usage;
- optv = init_options (capa, setup, &com_list);
+ mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
+ optv = init_options (pool, capa, setup, &hints, &com_list);
if (mu_parseopt (&po, argc, argv, optv, flags))
exit (po.po_exit_error);
@@ -502,6 +610,9 @@ mu_cli_ext (int argc, char **argv,
if (mu_cfg_parse_config (&parse_tree, &hints))
exit (setup->ex_config);
+ if (appd.append_tree)
+ mu_cfg_tree_union (&parse_tree, &appd.append_tree);
+
if (mu_cfg_tree_reduce (parse_tree, &hints, setup->cfg, data))
exit (setup->ex_config);
@@ -513,15 +624,14 @@ mu_cli_ext (int argc, char **argv,
mu_list_foreach (com_list, run_commit, NULL);
mu_list_destroy (&com_list);
- if (hints.flags & MU_PARSE_CONFIG_LINT)
- exit (0);
-
mu_cfg_destroy_tree (&parse_tree);
free (optv);
-
free (args);
-
- mu_parseopt_free (&po);
+ mu_parseopt_free (&po);
+ mu_opool_destroy (&pool);
+
+ if (appd.lint)
+ exit (0);
}