Commit 96e44735 96e44735dce29f8cdf0f8512bd3bfccc4b350055 by Sergey Poznyakoff

Improve path parsing in mu_cfg_find_node.

* libmailutils/cfg_parser.y (split_cfg_path): New static.
(mu_cfg_find_node): Use the same parsing algorithm as
mu_cfg_create_subtree.  This complements 68b7dc9d.
(mu_cfg_create_subtree): Use split_cfg_path.  Handle
escaped '=' as a regular character.
* mu/mu.c (args_doc): Remove spurious word.
(main): Disable --version option in action handlers.
* mu/query.c (query_args_doc): Use `path' instead of `keyword'.
1 parent e32c2d80
......@@ -1576,6 +1576,49 @@ mu_cfg_value_eq (mu_config_value_t *a, mu_config_value_t *b)
}
static int
split_cfg_path (const char *path, int *pargc, char ***pargv)
{
int rc;
int argc;
char **argv;
char *delim = MU_CFG_PATH_DELIM_STR;
char static_delim[2] = { 0, 0 };
if (path[0] == '\\')
{
argv = calloc (2, sizeof (*argv));
if (!argv)
return ENOMEM;
argv[0] = strdup (path + 1);
if (!argv[0])
{
free (argv);
return ENOMEM;
}
argv[1] = NULL;
argc = 1;
rc = 0;
}
else
{
if (mu_ispunct (path[0]))
{
delim = static_delim;
delim[0] = path[0];
path++;
}
rc = mu_argcv_get_np (path, strlen (path), delim, NULL, 0,
&argc, &argv, NULL);
}
if (rc == 0)
{
*pargc = argc;
*pargv = argv;
}
return rc;
}
struct find_data
{
int argc;
......@@ -1714,9 +1757,7 @@ mu_cfg_find_node (mu_cfg_tree_t *tree, const char *path, mu_cfg_node_t **pval)
struct find_data data;
struct mu_cfg_iter_closure clos;
rc = mu_argcv_get_np (path, strlen (path),
MU_CFG_PATH_DELIM_STR, NULL,
0, &data.argc, &data.argv, NULL);
rc = split_cfg_path (path, &data.argc, &data.argv);
if (rc)
return rc;
data.tag = 0;
......@@ -1742,44 +1783,15 @@ mu_cfg_create_subtree (const char *path, mu_cfg_node_t **pnode)
{
int rc;
int argc, i;
char *p;
char **argv;
mu_cfg_locus_t locus;
enum mu_cfg_node_type type;
mu_cfg_node_t *node = NULL;
char *delim = MU_CFG_PATH_DELIM_STR;
char static_delim[2] = { 0, 0 };
mu_cfg_locus_t locus;
locus.file = "<int>";
locus.line = 0;
if (path[0] == '\\')
{
argv = calloc (2, sizeof (*argv));
if (!argv)
return ENOMEM;
argv[0] = strdup (path + 1);
if (!argv[0])
{
free (argv);
return ENOMEM;
}
argv[1] = NULL;
argc = 1;
rc = 0;
}
else
{
if (mu_ispunct (path[0]))
{
delim = static_delim;
delim[0] = path[0];
path++;
}
rc = mu_argcv_get_np (path, strlen (path), delim, NULL, 0,
&argc, &argv, NULL);
}
rc = split_cfg_path (path, &argc, &argv);
if (rc)
return rc;
......@@ -1787,16 +1799,26 @@ mu_cfg_create_subtree (const char *path, mu_cfg_node_t **pnode)
{
mu_list_t nodelist = NULL;
mu_config_value_t *label = NULL;
char *q = argv[i], *p;
p = strrchr (argv[i], '=');
type = mu_cfg_node_statement;
if (p)
do
{
p = strchr (q, '=');
if (p && p > argv[i] && p[-1] != '\\')
{
*p++ = 0;
label = parse_label (p);
if (i == argc - 1)
type = mu_cfg_node_param;
break;
}
else if (p)
q = p + 1;
else
break;
}
while (*q);
if (node)
{
......
......@@ -24,8 +24,8 @@
#include "mailutils/libargp.h"
#include "mu.h"
static char args_doc[] = N_("[OPTIONS] COMMAND [CMDOPTS]");
static char doc[] = N_("mu -- GNU Mailutils test tool.\n\
static char args_doc[] = N_("COMMAND [CMDOPTS]");
static char doc[] = N_("mu -- GNU Mailutils multi-purpose tool.\n\
Commands are:\n\
mu info - show Mailutils configuration\n\
mu query - query configuration values\n\
......@@ -33,7 +33,7 @@ Commands are:\n\
mu filter - filter program\n\
mu 2047 - decode/encode message headers as per RFC 2047\n\
\n\
Try `mu COMMAND --help' to get help on a particular COMMAND\n\
Try `mu COMMAND --help' to get help on a particular COMMAND.\n\
\n\
Options are:\n");
/* FIXME: add
......@@ -143,6 +143,10 @@ main (int argc, char **argv)
exit (1);
}
/* Disable --version option in action. */
argp_program_version = NULL;
argp_program_version_hook = NULL;
/* Run the action. */
exit (action (argc, argv));
}
......
......@@ -25,7 +25,7 @@
#include "mu.h"
static char query_doc[] = N_("mu query - query configuration values.");
static char query_args_doc[] = N_("keyword [keyword...]");
static char query_args_doc[] = N_("path [path...]");
char *file_name;
int verbose_option;
......