Commit 9a972686 9a972686a656dcbe2eabb7e176f9649c128fb373 by Sergey Poznyakoff

* include/mailutils/cfg.h (mu_cfg_parser_verbose): New variable.

* include/mailutils/libargp.h (OPT_RCFILE_VERBOSE): New value.
* libargp/Makefile.am (AM_CFLAGS): Rename to AM_CPPFLAGS, define
SYSCONFDIR.
* libargp/common.c (mu_common_argp, mu_common_argp_parser): New
option rcfile-verbose.
* mailbox/Makefile.am (AM_CPPFLAGS): define SYSCONFDIR.
* mailbox/cfg_lexer.c (_mu_parse_config): Implement `include'
statement. Add verbose logging.
* mailbox/cfg_parser.y (mu_cfg_parser_verbose): New variable.
(mu_cfg_parse): Zero out parse_tree before returning.
(_scan_tree_helper): Remove dependency on MU_CONFIG_VERBOSE envar.
Use mu_cfg_parser_verbose instead.
1 parent e2201397
2007-11-19 Sergey Poznyakoff <gray@gnu.org.ua>
* include/mailutils/cfg.h (mu_cfg_parser_verbose): New variable.
* include/mailutils/libargp.h (OPT_RCFILE_VERBOSE): New value.
* libargp/Makefile.am (AM_CFLAGS): Rename to AM_CPPFLAGS, define
SYSCONFDIR.
* libargp/common.c (mu_common_argp, mu_common_argp_parser): New
option rcfile-verbose.
* mailbox/Makefile.am (AM_CPPFLAGS): define SYSCONFDIR.
* mailbox/cfg_lexer.c (_mu_parse_config): Implement `include'
statement. Add verbose logging.
* mailbox/cfg_parser.y (mu_cfg_parser_verbose): New variable.
(mu_cfg_parse): Zero out parse_tree before returning.
(_scan_tree_helper): Remove dependency on MU_CONFIG_VERBOSE envar.
Use mu_cfg_parser_verbose instead.
* config/mailutils.m4: New file
* config/Makefile.am: Install mailutils.m4 to $(datadir)/aclocal
......
......@@ -189,4 +189,5 @@ int mu_parse_config (char *file, char *progname,
int mu_cfg_parse_boolean (const char *str, int *res);
extern int mu_cfg_parser_verbose;
#endif
......
......@@ -75,6 +75,7 @@ enum {
OPT_NO_USER_RCFILE,
OPT_NO_SITE_RCFILE,
OPT_RCFILE,
OPT_RCFILE_VERBOSE,
OPT_CLEAR_INCLUDE_PATH,
OPT_CLEAR_LIBRARY_PATH
};
......
......@@ -17,8 +17,10 @@
# 02110-1301 USA
INCLUDES = @MU_COMMON_INCLUDES@
AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \
-DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
AM_CPPFLAGS = \
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
-DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
lib_LIBRARIES = libmuargp.a
......
......@@ -73,6 +73,8 @@ static struct argp_option mu_common_argp_options[] =
N_("Do not load site configuration file"), 0 },
{ "rcfile", OPT_RCFILE, N_("FILE"), 0,
N_("Load this configuration file"), 0, },
{ "rcfile-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
N_("Verbosely log parsing of the configuration files"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
......@@ -96,6 +98,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state)
case OPT_RCFILE:
mu_load_rcfile = arg;
break;
case OPT_RCFILE_VERBOSE:
mu_cfg_parser_verbose++;
break;
default:
return ARGP_ERR_UNKNOWN;
......
......@@ -29,6 +29,7 @@ lib_LTLIBRARIES = libmailutils.la
localedir = $(datadir)/locale
AM_CPPFLAGS = \
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
-DLOCALEDIR=\"$(localedir)\"
......
......@@ -589,6 +589,73 @@ prog_parser (enum mu_cfg_section_stage stage,
return 0;
}
static char *
make_file_name (const char *dir, const char *file)
{
char *tmp;
size_t len = strlen (dir) + 1 + strlen (file);
tmp = malloc (len + 1);
if (!tmp)
{
mu_error ("%s", mu_strerror (errno));
exit (1);
}
strcpy (tmp, dir);
strcat (tmp, "/");
strcat (tmp, file);
return tmp;
}
struct include_data
{
const char *progname;
struct mu_cfg_param *progparam;
int global;
};
static int _mu_parse_config (char *file, char *progname,
struct mu_cfg_param *progparam, int global);
static int
_cb_include (mu_cfg_locus_t *locus, void *data, char *arg)
{
int ret = 0;
struct stat sb;
char *dirname = arg;
struct include_data *idp = data;
char *tmp = NULL;
if (dirname[0] != '/')
dirname = tmp = make_file_name (SYSCONFDIR, dirname);
if (stat (dirname, &sb) == 0)
{
if (S_ISDIR (sb.st_mode))
{
char *file = make_file_name (dirname, idp->progname);
ret = _mu_parse_config (file, idp->progname, idp->progparam, 0);
}
else
ret = _mu_parse_config (dirname, idp->progname, idp->progparam,
idp->global);
}
else if (errno == ENOENT)
{
mu_cfg_perror (NULL, locus,
_("include directory does not exist"));
ret = 1;
}
else
{
mu_cfg_perror (NULL, locus,
_("cannot stat include directory: %s"),
mu_strerror (errno));
ret = 1;
}
free (tmp);
return ret;
}
static int
_mu_parse_config (char *file, char *progname,
struct mu_cfg_param *progparam, int global)
......@@ -600,23 +667,22 @@ _mu_parse_config (char *file, char *progname,
int rc;
mu_cfg_node_t *parse_tree;
mu_cfg_locus.file = file;
mu_cfg_locus.line = 1;
if (stat (mu_cfg_locus.file, &st))
if (stat (file, &st))
{
mu_error (_("can't stat `%s'"), mu_cfg_locus.file);
if (errno != ENOENT)
mu_error (_("can't stat `%s'"), file);
return -1;
}
fd = open (mu_cfg_locus.file, O_RDONLY);
fd = open (file, O_RDONLY);
if (fd == -1)
{
if (errno != ENOENT)
mu_error (_("can't open config file `%s'"),
mu_cfg_locus.file);
mu_error (_("cannot open config file `%s'"), file);
return -1;
}
if (mu_cfg_parser_verbose)
mu_error (_("Info: parsing file `%s'"), file);
memset (&data, 0, sizeof data);
data.buffer = malloc (st.st_size+1);
......@@ -625,9 +691,15 @@ _mu_parse_config (char *file, char *progname,
close (fd);
data.curp = data.buffer;
mu_cfg_yydebug = strncmp (data.curp, "#debug", 6) == 0;
if (mu_cfg_parser_verbose > 1
|| strncmp (data.curp, "#debug", 6) == 0)
mu_cfg_yydebug = 1;
else
mu_cfg_yydebug = 0;
/* Parse configuration */
mu_cfg_locus.file = file;
mu_cfg_locus.line = 1;
rc = mu_cfg_parse (&parse_tree,
&data,
default_lexer,
......@@ -638,8 +710,18 @@ _mu_parse_config (char *file, char *progname,
if (rc == 0 && root_container)
{
struct mu_cfg_cont *cont = root_container;
struct include_data idata;
struct mu_cfg_param mu_include_param[] = {
{ "include", mu_cfg_callback, &idata, _cb_include },
{ NULL }
};
mu_config_clone_container (cont);
idata.progname = progname;
idata.progparam = progparam;
idata.global = global;
_mu_config_register_section (&cont, NULL, NULL, NULL,
progname, mu_include_param, NULL);
if (global)
{
mu_iterator_t iter;
......@@ -685,10 +767,9 @@ _mu_parse_config (char *file, char *progname,
}
}
else if (progparam)
{
_mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
progparam, NULL);
}
_mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
progparam, NULL);
rc = mu_cfg_scan_tree (parse_tree, &cont->v.section,
progname, NULL, NULL, NULL);
mu_config_destroy_container (&cont);
......@@ -698,6 +779,9 @@ _mu_parse_config (char *file, char *progname,
mu_list_destroy (&data.mpool);
free (data.cbuf);
free (data.buffer);
if (mu_cfg_parser_verbose)
mu_error (_("Info: finished parsing file `%s'"), file);
return rc;
}
......
......@@ -28,7 +28,8 @@
#include <mailutils/error.h>
#include <mailutils/list.h>
#include <mailutils/iterator.h>
int mu_cfg_parser_verbose;
static mu_cfg_node_t *parse_tree;
mu_cfg_locus_t mu_cfg_locus;
int mu_cfg_tie_in;
......@@ -199,6 +200,7 @@ mu_cfg_parse (mu_cfg_node_t **ptree,
rc = 1;
/* FIXME if (rc) free_memory; else */
*ptree = parse_tree;
parse_tree = NULL;
return rc;
}
......@@ -954,13 +956,12 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
sec = find_subsection (sdata->list->sec, node->tag_name, 0);
if (!sec)
{
if (getenv ("MU_CONFIG_VERBOSE"))
if (mu_cfg_parser_verbose)
{
mu_cfg_perror (sdata->call_data,
&node->locus,
_("unknown section `%s'"),
node->tag_name);
sdata->error++;
}
return MU_CFG_ITER_SKIP;
}
......