[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/src/main.c,v
From: |
Eric Blake |
Subject: |
Changes to m4/src/main.c,v |
Date: |
Fri, 29 Sep 2006 18:20:14 +0000 |
CVSROOT: /sources/m4
Module name: m4
Changes by: Eric Blake <ericb> 06/09/29 18:20:13
Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -b -r1.90 -r1.91
--- src/main.c 29 Sep 2006 13:33:14 -0000 1.90
+++ src/main.c 29 Sep 2006 18:20:13 -0000 1.91
@@ -256,17 +256,17 @@
int
main (int argc, char *const *argv, char *const *envp)
{
- macro_definition *head; /* head of deferred argument list */
- macro_definition *tail;
+ macro_definition *head = NULL; /* head of deferred argument list */
+ macro_definition *tail = NULL;
macro_definition *defn;
int optchar; /* option character */
size_t size; /* for parsing numeric option arguments */
macro_definition *defines;
FILE *fp;
- char *filename;
bool read_stdin = false; /* true iff we have read from stdin */
bool import_environment = false; /* true to import environment */
+ const char *debugfile = NULL;
const char *frozen_file_to_read = NULL;
const char *frozen_file_to_write = NULL;
enum interactive_choice interactive = INTERACTIVE_UNKNOWN;
@@ -296,10 +296,9 @@
if (getenv ("POSIXLY_CORRECT"))
m4_set_posixly_correct_opt (context, true);
- /* First, we decode the arguments, to size up tables and stuff. */
-
- head = tail = NULL;
-
+ /* First, we decode the arguments, to size up tables and stuff.
+ Avoid lasting side effects; for example 'm4 --debugfile=oops
+ --help' must not create the file `oops'. */
while ((optchar = getopt_long (argc, (char **) argv, OPTSTRING,
long_options, NULL)) != -1)
switch (optchar)
@@ -465,8 +464,8 @@
optchar == 'o' ? "-o" : "--error-output", "--debugfile");
/* fall through */
case DEBUGFILE_OPTION:
- if (!m4_debug_set_output (context, optarg))
- error (0, errno, "%s", optarg);
+ /* Don't call m4_debug_set_output here, as it has side effects. */
+ debugfile = optarg;
break;
case 's':
@@ -502,7 +501,8 @@
&& isatty (STDERR_FILENO))));
/* Do the basic initializations. */
-
+ if (debugfile && !m4_debug_set_output (context, debugfile))
+ m4_error (context, 0, errno, _("cannot set debug file `%s'"), debugfile);
m4_input_init (context);
m4_output_init ();
m4_include_env_init (context);
@@ -625,7 +625,8 @@
}
else
{
- fp = m4_path_search (context, argv[optind], &filename);
+ char *name;
+ fp = m4_path_search (context, argv[optind], &name);
if (fp == NULL)
{
error (0, errno, "%s", argv[optind]);
@@ -634,8 +635,8 @@
}
else
{
- m4_push_file (context, fp, filename, true);
- free (filename);
+ m4_push_file (context, fp, name, true);
+ free (name);
}
}
m4_macro_expand_input (context);
@@ -645,13 +646,6 @@
while (m4_pop_wrapup ())
m4_macro_expand_input (context);
- /* Change debug stream back to stderr, to force flushing the debug
- stream and detect any errors it might have encountered. Close
- stdin if we read from it, to detect any errors. */
- m4_debug_set_output (context, NULL);
- if (read_stdin && fclose (stdin) == EOF)
- m4_error (context, 0, errno, _("error closing stdin"));
-
if (frozen_file_to_write)
produce_frozen_state (context, frozen_file_to_write);
else
@@ -670,6 +664,13 @@
m4_output_exit ();
m4_input_exit ();
+ /* Change debug stream back to stderr, to force flushing the debug
+ stream and detect any errors it might have encountered. Close
+ stdin if we read from it, to detect any errors. */
+ m4_debug_set_output (context, NULL);
+ if (read_stdin && fclose (stdin) == EOF)
+ m4_error (context, 0, errno, _("error closing stdin"));
+
if (exit_status == EXIT_SUCCESS)
exit_status = m4_get_exit_status (context);
m4_delete (context);
- Changes to m4/src/main.c,v, (continued)
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/13
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/14
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/18
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/19
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/20
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/20
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/21
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/26
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/29
- Changes to m4/src/main.c,v, Eric Blake, 2006/09/29
- Changes to m4/src/main.c,v,
Eric Blake <=