* 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.
Showing
8 changed files
with
130 additions
and
20 deletions
1 | 2007-11-19 Sergey Poznyakoff <gray@gnu.org.ua> | 1 | 2007-11-19 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 2 | ||
3 | * include/mailutils/cfg.h (mu_cfg_parser_verbose): New variable. | ||
4 | * include/mailutils/libargp.h (OPT_RCFILE_VERBOSE): New value. | ||
5 | * libargp/Makefile.am (AM_CFLAGS): Rename to AM_CPPFLAGS, define | ||
6 | SYSCONFDIR. | ||
7 | * libargp/common.c (mu_common_argp, mu_common_argp_parser): New | ||
8 | option rcfile-verbose. | ||
9 | * mailbox/Makefile.am (AM_CPPFLAGS): define SYSCONFDIR. | ||
10 | * mailbox/cfg_lexer.c (_mu_parse_config): Implement `include' | ||
11 | statement. Add verbose logging. | ||
12 | * mailbox/cfg_parser.y (mu_cfg_parser_verbose): New variable. | ||
13 | (mu_cfg_parse): Zero out parse_tree before returning. | ||
14 | (_scan_tree_helper): Remove dependency on MU_CONFIG_VERBOSE envar. | ||
15 | Use mu_cfg_parser_verbose instead. | ||
16 | |||
3 | * config/mailutils.m4: New file | 17 | * config/mailutils.m4: New file |
4 | * config/Makefile.am: Install mailutils.m4 to $(datadir)/aclocal | 18 | * config/Makefile.am: Install mailutils.m4 to $(datadir)/aclocal |
5 | 19 | ... | ... |
... | @@ -189,4 +189,5 @@ int mu_parse_config (char *file, char *progname, | ... | @@ -189,4 +189,5 @@ int mu_parse_config (char *file, char *progname, |
189 | 189 | ||
190 | int mu_cfg_parse_boolean (const char *str, int *res); | 190 | int mu_cfg_parse_boolean (const char *str, int *res); |
191 | 191 | ||
192 | extern int mu_cfg_parser_verbose; | ||
192 | #endif | 193 | #endif | ... | ... |
... | @@ -75,6 +75,7 @@ enum { | ... | @@ -75,6 +75,7 @@ enum { |
75 | OPT_NO_USER_RCFILE, | 75 | OPT_NO_USER_RCFILE, |
76 | OPT_NO_SITE_RCFILE, | 76 | OPT_NO_SITE_RCFILE, |
77 | OPT_RCFILE, | 77 | OPT_RCFILE, |
78 | OPT_RCFILE_VERBOSE, | ||
78 | OPT_CLEAR_INCLUDE_PATH, | 79 | OPT_CLEAR_INCLUDE_PATH, |
79 | OPT_CLEAR_LIBRARY_PATH | 80 | OPT_CLEAR_LIBRARY_PATH |
80 | }; | 81 | }; | ... | ... |
... | @@ -17,8 +17,10 @@ | ... | @@ -17,8 +17,10 @@ |
17 | # 02110-1301 USA | 17 | # 02110-1301 USA |
18 | 18 | ||
19 | INCLUDES = @MU_COMMON_INCLUDES@ | 19 | INCLUDES = @MU_COMMON_INCLUDES@ |
20 | AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \ | 20 | AM_CPPFLAGS = \ |
21 | -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\" | 21 | -DSYSCONFDIR=\"$(sysconfdir)\"\ |
22 | -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\ | ||
23 | -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\" | ||
22 | 24 | ||
23 | lib_LIBRARIES = libmuargp.a | 25 | lib_LIBRARIES = libmuargp.a |
24 | 26 | ... | ... |
... | @@ -73,6 +73,8 @@ static struct argp_option mu_common_argp_options[] = | ... | @@ -73,6 +73,8 @@ static struct argp_option mu_common_argp_options[] = |
73 | N_("Do not load site configuration file"), 0 }, | 73 | N_("Do not load site configuration file"), 0 }, |
74 | { "rcfile", OPT_RCFILE, N_("FILE"), 0, | 74 | { "rcfile", OPT_RCFILE, N_("FILE"), 0, |
75 | N_("Load this configuration file"), 0, }, | 75 | N_("Load this configuration file"), 0, }, |
76 | { "rcfile-verbose", OPT_RCFILE_VERBOSE, NULL, 0, | ||
77 | N_("Verbosely log parsing of the configuration files"), 0 }, | ||
76 | { NULL, 0, NULL, 0, NULL, 0 } | 78 | { NULL, 0, NULL, 0, NULL, 0 } |
77 | }; | 79 | }; |
78 | 80 | ||
... | @@ -96,6 +98,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ... | @@ -96,6 +98,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
96 | case OPT_RCFILE: | 98 | case OPT_RCFILE: |
97 | mu_load_rcfile = arg; | 99 | mu_load_rcfile = arg; |
98 | break; | 100 | break; |
101 | |||
102 | case OPT_RCFILE_VERBOSE: | ||
103 | mu_cfg_parser_verbose++; | ||
104 | break; | ||
99 | 105 | ||
100 | default: | 106 | default: |
101 | return ARGP_ERR_UNKNOWN; | 107 | return ARGP_ERR_UNKNOWN; | ... | ... |
... | @@ -29,6 +29,7 @@ lib_LTLIBRARIES = libmailutils.la | ... | @@ -29,6 +29,7 @@ lib_LTLIBRARIES = libmailutils.la |
29 | 29 | ||
30 | localedir = $(datadir)/locale | 30 | localedir = $(datadir)/locale |
31 | AM_CPPFLAGS = \ | 31 | AM_CPPFLAGS = \ |
32 | -DSYSCONFDIR=\"$(sysconfdir)\"\ | ||
32 | -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\ | 33 | -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\ |
33 | -DLOCALEDIR=\"$(localedir)\" | 34 | -DLOCALEDIR=\"$(localedir)\" |
34 | 35 | ... | ... |
... | @@ -589,6 +589,73 @@ prog_parser (enum mu_cfg_section_stage stage, | ... | @@ -589,6 +589,73 @@ prog_parser (enum mu_cfg_section_stage stage, |
589 | return 0; | 589 | return 0; |
590 | } | 590 | } |
591 | 591 | ||
592 | static char * | ||
593 | make_file_name (const char *dir, const char *file) | ||
594 | { | ||
595 | char *tmp; | ||
596 | size_t len = strlen (dir) + 1 + strlen (file); | ||
597 | tmp = malloc (len + 1); | ||
598 | if (!tmp) | ||
599 | { | ||
600 | mu_error ("%s", mu_strerror (errno)); | ||
601 | exit (1); | ||
602 | } | ||
603 | strcpy (tmp, dir); | ||
604 | strcat (tmp, "/"); | ||
605 | strcat (tmp, file); | ||
606 | return tmp; | ||
607 | } | ||
608 | |||
609 | struct include_data | ||
610 | { | ||
611 | const char *progname; | ||
612 | struct mu_cfg_param *progparam; | ||
613 | int global; | ||
614 | }; | ||
615 | |||
616 | static int _mu_parse_config (char *file, char *progname, | ||
617 | struct mu_cfg_param *progparam, int global); | ||
618 | |||
619 | static int | ||
620 | _cb_include (mu_cfg_locus_t *locus, void *data, char *arg) | ||
621 | { | ||
622 | int ret = 0; | ||
623 | struct stat sb; | ||
624 | char *dirname = arg; | ||
625 | struct include_data *idp = data; | ||
626 | char *tmp = NULL; | ||
627 | |||
628 | if (dirname[0] != '/') | ||
629 | dirname = tmp = make_file_name (SYSCONFDIR, dirname); | ||
630 | |||
631 | if (stat (dirname, &sb) == 0) | ||
632 | { | ||
633 | if (S_ISDIR (sb.st_mode)) | ||
634 | { | ||
635 | char *file = make_file_name (dirname, idp->progname); | ||
636 | ret = _mu_parse_config (file, idp->progname, idp->progparam, 0); | ||
637 | } | ||
638 | else | ||
639 | ret = _mu_parse_config (dirname, idp->progname, idp->progparam, | ||
640 | idp->global); | ||
641 | } | ||
642 | else if (errno == ENOENT) | ||
643 | { | ||
644 | mu_cfg_perror (NULL, locus, | ||
645 | _("include directory does not exist")); | ||
646 | ret = 1; | ||
647 | } | ||
648 | else | ||
649 | { | ||
650 | mu_cfg_perror (NULL, locus, | ||
651 | _("cannot stat include directory: %s"), | ||
652 | mu_strerror (errno)); | ||
653 | ret = 1; | ||
654 | } | ||
655 | free (tmp); | ||
656 | return ret; | ||
657 | } | ||
658 | |||
592 | static int | 659 | static int |
593 | _mu_parse_config (char *file, char *progname, | 660 | _mu_parse_config (char *file, char *progname, |
594 | struct mu_cfg_param *progparam, int global) | 661 | struct mu_cfg_param *progparam, int global) |
... | @@ -600,23 +667,22 @@ _mu_parse_config (char *file, char *progname, | ... | @@ -600,23 +667,22 @@ _mu_parse_config (char *file, char *progname, |
600 | int rc; | 667 | int rc; |
601 | mu_cfg_node_t *parse_tree; | 668 | mu_cfg_node_t *parse_tree; |
602 | 669 | ||
603 | mu_cfg_locus.file = file; | 670 | if (stat (file, &st)) |
604 | mu_cfg_locus.line = 1; | ||
605 | |||
606 | if (stat (mu_cfg_locus.file, &st)) | ||
607 | { | 671 | { |
608 | mu_error (_("can't stat `%s'"), mu_cfg_locus.file); | 672 | if (errno != ENOENT) |
673 | mu_error (_("can't stat `%s'"), file); | ||
609 | return -1; | 674 | return -1; |
610 | } | 675 | } |
611 | fd = open (mu_cfg_locus.file, O_RDONLY); | 676 | fd = open (file, O_RDONLY); |
612 | if (fd == -1) | 677 | if (fd == -1) |
613 | { | 678 | { |
614 | if (errno != ENOENT) | 679 | mu_error (_("cannot open config file `%s'"), file); |
615 | mu_error (_("can't open config file `%s'"), | ||
616 | mu_cfg_locus.file); | ||
617 | return -1; | 680 | return -1; |
618 | } | 681 | } |
619 | 682 | ||
683 | if (mu_cfg_parser_verbose) | ||
684 | mu_error (_("Info: parsing file `%s'"), file); | ||
685 | |||
620 | memset (&data, 0, sizeof data); | 686 | memset (&data, 0, sizeof data); |
621 | data.buffer = malloc (st.st_size+1); | 687 | data.buffer = malloc (st.st_size+1); |
622 | 688 | ||
... | @@ -625,9 +691,15 @@ _mu_parse_config (char *file, char *progname, | ... | @@ -625,9 +691,15 @@ _mu_parse_config (char *file, char *progname, |
625 | close (fd); | 691 | close (fd); |
626 | data.curp = data.buffer; | 692 | data.curp = data.buffer; |
627 | 693 | ||
628 | mu_cfg_yydebug = strncmp (data.curp, "#debug", 6) == 0; | 694 | if (mu_cfg_parser_verbose > 1 |
629 | 695 | || strncmp (data.curp, "#debug", 6) == 0) | |
696 | mu_cfg_yydebug = 1; | ||
697 | else | ||
698 | mu_cfg_yydebug = 0; | ||
699 | |||
630 | /* Parse configuration */ | 700 | /* Parse configuration */ |
701 | mu_cfg_locus.file = file; | ||
702 | mu_cfg_locus.line = 1; | ||
631 | rc = mu_cfg_parse (&parse_tree, | 703 | rc = mu_cfg_parse (&parse_tree, |
632 | &data, | 704 | &data, |
633 | default_lexer, | 705 | default_lexer, |
... | @@ -638,8 +710,18 @@ _mu_parse_config (char *file, char *progname, | ... | @@ -638,8 +710,18 @@ _mu_parse_config (char *file, char *progname, |
638 | if (rc == 0 && root_container) | 710 | if (rc == 0 && root_container) |
639 | { | 711 | { |
640 | struct mu_cfg_cont *cont = root_container; | 712 | struct mu_cfg_cont *cont = root_container; |
713 | struct include_data idata; | ||
714 | struct mu_cfg_param mu_include_param[] = { | ||
715 | { "include", mu_cfg_callback, &idata, _cb_include }, | ||
716 | { NULL } | ||
717 | }; | ||
641 | 718 | ||
642 | mu_config_clone_container (cont); | 719 | mu_config_clone_container (cont); |
720 | idata.progname = progname; | ||
721 | idata.progparam = progparam; | ||
722 | idata.global = global; | ||
723 | _mu_config_register_section (&cont, NULL, NULL, NULL, | ||
724 | progname, mu_include_param, NULL); | ||
643 | if (global) | 725 | if (global) |
644 | { | 726 | { |
645 | mu_iterator_t iter; | 727 | mu_iterator_t iter; |
... | @@ -685,10 +767,9 @@ _mu_parse_config (char *file, char *progname, | ... | @@ -685,10 +767,9 @@ _mu_parse_config (char *file, char *progname, |
685 | } | 767 | } |
686 | } | 768 | } |
687 | else if (progparam) | 769 | else if (progparam) |
688 | { | 770 | _mu_config_register_section (&cont, NULL, NULL, NULL, NULL, |
689 | _mu_config_register_section (&cont, NULL, NULL, NULL, NULL, | 771 | progparam, NULL); |
690 | progparam, NULL); | 772 | |
691 | } | ||
692 | rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, | 773 | rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, |
693 | progname, NULL, NULL, NULL); | 774 | progname, NULL, NULL, NULL); |
694 | mu_config_destroy_container (&cont); | 775 | mu_config_destroy_container (&cont); |
... | @@ -698,6 +779,9 @@ _mu_parse_config (char *file, char *progname, | ... | @@ -698,6 +779,9 @@ _mu_parse_config (char *file, char *progname, |
698 | mu_list_destroy (&data.mpool); | 779 | mu_list_destroy (&data.mpool); |
699 | free (data.cbuf); | 780 | free (data.cbuf); |
700 | free (data.buffer); | 781 | free (data.buffer); |
782 | |||
783 | if (mu_cfg_parser_verbose) | ||
784 | mu_error (_("Info: finished parsing file `%s'"), file); | ||
701 | 785 | ||
702 | return rc; | 786 | return rc; |
703 | } | 787 | } | ... | ... |
... | @@ -28,7 +28,8 @@ | ... | @@ -28,7 +28,8 @@ |
28 | #include <mailutils/error.h> | 28 | #include <mailutils/error.h> |
29 | #include <mailutils/list.h> | 29 | #include <mailutils/list.h> |
30 | #include <mailutils/iterator.h> | 30 | #include <mailutils/iterator.h> |
31 | 31 | ||
32 | int mu_cfg_parser_verbose; | ||
32 | static mu_cfg_node_t *parse_tree; | 33 | static mu_cfg_node_t *parse_tree; |
33 | mu_cfg_locus_t mu_cfg_locus; | 34 | mu_cfg_locus_t mu_cfg_locus; |
34 | int mu_cfg_tie_in; | 35 | int mu_cfg_tie_in; |
... | @@ -199,6 +200,7 @@ mu_cfg_parse (mu_cfg_node_t **ptree, | ... | @@ -199,6 +200,7 @@ mu_cfg_parse (mu_cfg_node_t **ptree, |
199 | rc = 1; | 200 | rc = 1; |
200 | /* FIXME if (rc) free_memory; else */ | 201 | /* FIXME if (rc) free_memory; else */ |
201 | *ptree = parse_tree; | 202 | *ptree = parse_tree; |
203 | parse_tree = NULL; | ||
202 | return rc; | 204 | return rc; |
203 | } | 205 | } |
204 | 206 | ||
... | @@ -954,13 +956,12 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) | ... | @@ -954,13 +956,12 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) |
954 | sec = find_subsection (sdata->list->sec, node->tag_name, 0); | 956 | sec = find_subsection (sdata->list->sec, node->tag_name, 0); |
955 | if (!sec) | 957 | if (!sec) |
956 | { | 958 | { |
957 | if (getenv ("MU_CONFIG_VERBOSE")) | 959 | if (mu_cfg_parser_verbose) |
958 | { | 960 | { |
959 | mu_cfg_perror (sdata->call_data, | 961 | mu_cfg_perror (sdata->call_data, |
960 | &node->locus, | 962 | &node->locus, |
961 | _("unknown section `%s'"), | 963 | _("unknown section `%s'"), |
962 | node->tag_name); | 964 | node->tag_name); |
963 | sdata->error++; | ||
964 | } | 965 | } |
965 | return MU_CFG_ITER_SKIP; | 966 | return MU_CFG_ITER_SKIP; |
966 | } | 967 | } | ... | ... |
-
Please register or sign in to post a comment