From e9950f2fa8e45e86396371e91443dc04f14fb5f2 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 16 Oct 2009 13:06:36 +0300 Subject: Implement -D and -U options (preprocessor control). * Makefile.am (dist-hook,alpha,alphacheck): New rules. (ChangeLog): Be silent. * NEWS: Update. * doc/pies.texi: Update. * gnulib.modules: Add quote and quotearg * src/pies.c: Implement -D and -U options. Improve --help output. * src/pies.h: Include quotearg.h --- src/pies.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 10 deletions(-) (limited to 'src/pies.c') diff --git a/src/pies.c b/src/pies.c index f2ed365..52abc80 100644 --- a/src/pies.c +++ b/src/pies.c @@ -40,9 +40,38 @@ char *mailer_program = "/usr/sbin/sendmail"; char *mailer_command_line = "/usr/sbin/sendmail -oi -t"; int mailer_argc; char **mailer_argv; +struct obstack pp_stk; +struct quoting_options *pp_qopt; +static void +add_pp_option (const char *opt, const char *arg) +{ + if (!DEFAULT_PREPROCESSOR) + { + logmsg (LOG_ERR, _("no preprocessor configured")); + exit (EX_CONFIG); + } + + obstack_1grow (&pp_stk, ' '); + obstack_grow (&pp_stk, opt, strlen (opt)); + if (arg) + { + char *qarg; + size_t qlen; + + if (!pp_qopt) + { + pp_qopt = clone_quoting_options (NULL); + set_quoting_style (pp_qopt, shell_quoting_style); + } + qarg = quotearg_alloc_mem (arg, strlen (arg), &qlen, pp_qopt); + obstack_grow (&pp_stk, qarg, qlen); + free (qarg); + } +} + /* Logging */ void log_setup (int want_stderr) @@ -1206,8 +1235,13 @@ config_init () grecs_set_keywords (pies_keywords); grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR, DEFAULT_INCLUDE_DIR, NULL); - grecs_preprocessor = DEFAULT_PREPROCESSOR; grecs_log_to_stderr = log_to_stderr; + if (DEFAULT_PREPROCESSOR) + { + obstack_init (&pp_stk); + obstack_grow (&pp_stk, DEFAULT_PREPROCESSOR, + sizeof (DEFAULT_PREPROCESSOR) - 1); + } } void @@ -1245,13 +1279,10 @@ enum static struct argp_option options[] = { #define GRP 0 + {NULL, 0, NULL, 0, N_("Operation Mode"), GRP}, {"foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP + 1}, {"stderr", OPT_STDERR, NULL, 0, N_("log to stderr"),}, {"syslog", OPT_SYSLOG, NULL, 0, N_("log to syslog"),}, - {"debug", 'x', N_("LEVEL"), 0, - N_("set debug verbosity level"), GRP + 1}, - {"source-info", OPT_SOURCE_INFO, NULL, 0, - N_("show source info with debugging messages"), GRP + 1}, {"force", OPT_FORCE, NULL, 0, N_("force startup even if another instance may be running"), GRP + 1}, {"lint", 't', NULL, 0, @@ -1264,7 +1295,16 @@ static struct argp_option options[] = { N_("show configuration file summary"), GRP + 1}, #undef GRP +#define GRP 5 + {NULL, 0, NULL, 0, N_("Preprocessor"), GRP}, + {"define", 'D', N_("NAME[=VALUE]"), 0, + N_("define a preprocessor symbol NAME as having VALUE, or empty"), GRP+1 }, + {"undefine", 'U', N_("NAME"), 0, + N_("undefine a preprocessor symbol NAME"), GRP+1 }, +#undef GRP + #define GRP 10 + {NULL, 0, NULL, 0, N_("Component Management"), GRP}, {"restart-component", OPT_RESTART, NULL, 0, N_("restart components named in the command line"), GRP + 1}, {"reload", OPT_RELOAD, NULL, 0, @@ -1277,6 +1317,11 @@ static struct argp_option options[] = { #undef GRP #define GRP 20 + {NULL, 0, NULL, 0, N_("Debugging and Additional Diagnostics"), GRP}, + {"debug", 'x', N_("LEVEL"), 0, + N_("set debug verbosity level"), GRP + 1}, + {"source-info", OPT_SOURCE_INFO, NULL, 0, + N_("show source info with debugging messages"), GRP + 1}, {"dump-prereq", OPT_DUMP_PREREQ, NULL, 0, N_("dump prerequisite charts"), GRP + 1}, {"dump-depmap", OPT_DUMP_DEPMAP, NULL, 0, @@ -1290,17 +1335,25 @@ parse_opt (int key, char *arg, struct argp_state *state) { switch (key) { - case 't': - log_to_stderr = 1; - lint_mode = 1; + case 'c': + conffile = arg; break; + case 'D': + add_pp_option ("-D", arg); + break; + + case 'U': + add_pp_option ("-U", arg); + break; + case 'E': preprocess_only = 1; break; - case 'c': - conffile = arg; + case 't': + log_to_stderr = 1; + lint_mode = 1; break; case OPT_CONFIG_HELP: @@ -1780,6 +1833,14 @@ main (int argc, char **argv) if (argp_parse (&argp, argc, argv, 0, &index, NULL)) exit (EX_USAGE); + if (!DEFAULT_PREPROCESSOR) + grecs_preprocessor = NULL; + else + { + grecs_preprocessor = obstack_finish (&pp_stk); + free (pp_qopt); + } + if (preprocess_only) exit (grecs_preproc_run (conffile, grecs_preprocessor) ? EX_CONFIG : 0); -- cgit v1.2.1