diff options
author | Eric Blake <ebb9@byu.net> | 2007-11-22 19:54:32 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2007-11-22 19:54:32 -0700 |
commit | 9de0b8950ca83762363605805c40f8f8614acbc8 (patch) | |
tree | 0c6e7f7b7bafa0088648c65edc3d3cdf1f7a51e4 | |
parent | 910837ec453663d0423f73eb79c17740486450a0 (diff) | |
download | m4-9de0b8950ca83762363605805c40f8f8614acbc8.tar.gz |
More error messages tied to macro names.
* src/input.c (set_word_regexp): Take additional parameter.
(input_init): Adjust caller.
* src/debug.c (debug_set_file, debug_set_output): Take additional
parameter.
(debug_init): Adjust caller.
(expansion_level): Move declaration...
* src/m4.h (expansion_level): ...here.
(debug_set_output, set_word_regexp): Adjust prototypes.
* src/builtin.c (m4_changeword, m4_m4exit, m4_debugfile): Adjust
callers.
* src/m4.c (main): Likewise.
Signed-off-by: Eric Blake <ebb9@byu.net>
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | src/builtin.c | 15 | ||||
-rw-r--r-- | src/debug.c | 36 | ||||
-rw-r--r-- | src/input.c | 6 | ||||
-rw-r--r-- | src/m4.c | 4 | ||||
-rw-r--r-- | src/m4.h | 6 |
6 files changed, 45 insertions, 35 deletions
@@ -1,5 +1,18 @@ 2007-11-22 Eric Blake <ebb9@byu.net> + More error messages tied to macro names. + * src/input.c (set_word_regexp): Take additional parameter. + (input_init): Adjust caller. + * src/debug.c (debug_set_file, debug_set_output): Take additional + parameter. + (debug_init): Adjust caller. + (expansion_level): Move declaration... + * src/m4.h (expansion_level): ...here. + (debug_set_output, set_word_regexp): Adjust prototypes. + * src/builtin.c (m4_changeword, m4_m4exit, m4_debugfile): Adjust + callers. + * src/m4.c (main): Likewise. + Refactor error messages to avoid macros. * src/m4.h (_): Define, as a placeholder for now. (M4ERROR, M4ERROR_AT_LINE): Delete. diff --git a/src/builtin.c b/src/builtin.c index e10bbde2..cc4e469f 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -24,8 +24,6 @@ #include "m4.h" -extern FILE *popen (); - #include "regex.h" #if HAVE_SYS_WAIT_H @@ -1365,10 +1363,11 @@ m4_changecom (struct obstack *obs, int argc, token_data **argv) static void m4_changeword (struct obstack *obs, int argc, token_data **argv) { - if (bad_argc (ARG (0), argc, 1, 1)) - return; + const char *me = ARG (0); - set_word_regexp (ARG (1)); + if (bad_argc (me, argc, 1, 1)) + return; + set_word_regexp (me, ARG (1)); } #endif /* ENABLE_CHANGEWORD */ @@ -1584,7 +1583,7 @@ m4_m4exit (struct obstack *obs, int argc, token_data **argv) } /* Change debug stream back to stderr, to force flushing debug stream and detect any errors it might have encountered. */ - debug_set_output (NULL); + debug_set_output (me, NULL); debug_flush_files (); if (exit_code == EXIT_SUCCESS && retcode != EXIT_SUCCESS) exit_code = retcode; @@ -1735,8 +1734,8 @@ m4_debugfile (struct obstack *obs, int argc, token_data **argv) bad_argc (me, argc, 0, 1); if (argc == 1) - debug_set_output (NULL); - else if (!debug_set_output (ARG (1))) + debug_set_output (me, NULL); + else if (!debug_set_output (me, ARG (1))) m4_warn (errno, me, _("cannot set error file: `%s'"), ARG (1)); } diff --git a/src/debug.c b/src/debug.c index 4173f9b4..c22a4820 100644 --- a/src/debug.c +++ b/src/debug.c @@ -30,9 +30,7 @@ FILE *debug = NULL; /* Obstack for trace messages. */ static struct obstack trace; -extern int expansion_level; - -static void debug_set_file (FILE *); +static void debug_set_file (const char *, FILE *); /*----------------------------------. | Initialise the debugging module. | @@ -41,7 +39,7 @@ static void debug_set_file (FILE *); void debug_init (void) { - debug_set_file (stderr); + debug_set_file (NULL, stderr); obstack_init (&trace); } @@ -128,14 +126,13 @@ debug_decode (const char *opts) `------------------------------------------------------------------------*/ static void -debug_set_file (FILE *fp) +debug_set_file (const char *caller, FILE *fp) { struct stat stdout_stat, debug_stat; if (debug != NULL && debug != stderr && debug != stdout && close_stream (debug) != 0) - /* FIXME - report on behalf of macro caller. */ - m4_error (0, errno, NULL, _("error writing to debug stream")); + m4_error (0, errno, caller, _("error writing to debug stream")); debug = fp; if (debug != NULL && debug != stdout) @@ -152,8 +149,7 @@ debug_set_file (FILE *fp) && stdout_stat.st_ino != 0) { if (debug != stderr && close_stream (debug) != 0) - /* FIXME - report on behalf of macro caller. */ - m4_error (0, errno, NULL, _("error writing to debug stream")); + m4_error (0, errno, caller, _("error writing to debug stream")); debug = stdout; } } @@ -190,21 +186,22 @@ debug_flush_files (void) } } -/*-------------------------------------------------------------------------. -| Change the debug output to file NAME. If NAME is NULL, debug output is | -| reverted to stderr, and if empty debug output is discarded. Return true | -| iff the output stream was changed. | -`-------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------. +| Change the debug output to file NAME. If NAME is NULL, debug | +| output is reverted to stderr, and if empty, debug output is | +| discarded. Return true iff the output stream was changed. Report | +| errors on behalf of CALLER. | +`-------------------------------------------------------------------*/ bool -debug_set_output (const char *name) +debug_set_output (const char *caller, const char *name) { FILE *fp; if (name == NULL) - debug_set_file (stderr); + debug_set_file (caller, stderr); else if (*name == '\0') - debug_set_file (NULL); + debug_set_file (caller, NULL); else { fp = fopen (name, "a"); @@ -212,9 +209,8 @@ debug_set_output (const char *name) return false; if (set_cloexec_flag (fileno (fp), true) != 0) - /* FIXME - report on behalf of macro caller. */ - m4_warn (errno, NULL, _("cannot protect debug file across forks")); - debug_set_file (fp); + m4_warn (errno, caller, _("cannot protect debug file across forks")); + debug_set_file (caller, fp); } return true; } diff --git a/src/input.c b/src/input.c index 156df330..3d96ec7a 100644 --- a/src/input.c +++ b/src/input.c @@ -687,7 +687,7 @@ input_init (void) ecomm.length = strlen (ecomm.string); #ifdef ENABLE_CHANGEWORD - set_word_regexp (user_word_regexp); + set_word_regexp (NULL, user_word_regexp); #endif } @@ -752,7 +752,7 @@ set_comment (const char *bc, const char *ec) #ifdef ENABLE_CHANGEWORD void -set_word_regexp (const char *regexp) +set_word_regexp (const char *caller, const char *regexp) { int i; char test[2]; @@ -773,7 +773,7 @@ set_word_regexp (const char *regexp) if (msg != NULL) { /* FIXME - report on behalf of macro caller. */ - m4_warn (0, NULL, _("bad regular expression `%s': %s"), regexp, msg); + m4_warn (0, caller, _("bad regular expression `%s': %s"), regexp, msg); return; } @@ -587,7 +587,7 @@ main (int argc, char *const *argv, char *const *envp) defines = head; /* Do the basic initializations. */ - if (debugfile && !debug_set_output (debugfile)) + if (debugfile && !debug_set_output (NULL, debugfile)) m4_error (0, errno, NULL, _("cannot set debug file `%s'"), debugfile); input_init (); @@ -676,7 +676,7 @@ main (int argc, char *const *argv, char *const *envp) /* Change debug stream back to stderr, to force flushing the debug stream and detect any errors it might have encountered. The three standard streams are closed by close_stdin. */ - debug_set_output (NULL); + debug_set_output (NULL, NULL); if (frozen_file_to_write) produce_frozen_state (frozen_file_to_write); @@ -231,7 +231,7 @@ extern FILE *debug; void debug_init (void); int debug_decode (const char *); void debug_flush_files (void); -bool debug_set_output (const char *); +bool debug_set_output (const char *, const char *); void debug_message_prefix (void); void trace_prepre (const char *, int); @@ -318,7 +318,7 @@ extern STRING lquote, rquote; void set_quotes (const char *, const char *); void set_comment (const char *, const char *); #ifdef ENABLE_CHANGEWORD -void set_word_regexp (const char *); +void set_word_regexp (const char *, const char *); #endif /* File: output.c --- output functions. */ @@ -388,6 +388,8 @@ void hack_all_symbols (hack_symbol *, void *); /* File: macro.c --- macro expansion. */ +extern int expansion_level; + void expand_input (void); void call_macro (symbol *, int, token_data **, struct obstack *); |