m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: branch-1_4 error message cleanup


From: Eric Blake
Subject: Re: branch-1_4 error message cleanup
Date: Tue, 8 Aug 2006 23:11:50 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> 
> I wanted to do this, too, to avoid "m4:NONE:0: message" for things like `m4 -
R 
> none' or `echo "m4wrap(\`dnl()')"|m4':
> 
> verror_at_line (status, errnum, current_line ? current_file : NULL,
>                 current_line, message, args);

Well, I fixed verror in gnulib, so here goes.

2006-08-08  Eric Blake  <address@hidden>

        Avoid printing `NONE:0:' in error messages.
        * src/m4.h (m4_error_at_line): New function.
        * src/m4.c (m4_error_at_line): Implement.
        * src/input.c (skip_line, input_init, next_token): Use "", not
        "NONE", for no file, since NONE can be a real file name.
        * src/macro.c (expand_argument): Likewise.
        * src/debug.c (debug_message_prefix, trace_header): Check for
        current file.
        * doc/m4.texinfo (Dnl, M4wrap): Adjust accordingly.
        (Location): Document that synclines and internal message format
        are not impacted by redefining these macros.
        (M4exit): Hint at bug in fatal_error.
        (Answers): Provide workaround to match m4 output.

Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.61
diff -u -r1.1.1.1.2.61 m4.texinfo
--- doc/m4.texinfo      4 Aug 2006 13:19:41 -0000       1.1.1.1.2.61
+++ doc/m4.texinfo      8 Aug 2006 23:10:01 -0000
@@ -2317,7 +2317,7 @@
 ')0 hi dnl 1 hi')
 @result{}
 ^D
address@hidden:NONE:0: Warning: end of file treated as newline
address@hidden: Warning: end of file treated as newline
 @result{}0 HI 2 HI
 @end example
 
@@ -2839,7 +2839,7 @@
 m4wrap(`m4wrap(`)')len(abc')
 @result{}
 ^D
address@hidden:NONE:0: ERROR: end of file in argument list
address@hidden: ERROR: end of file in argument list
 @end example
 
 @node File Inclusion
@@ -4103,8 +4103,11 @@
 
 Line numbers start at 1 for each file.  If the file was found due to the
 @option{-I} option or @env{M4PATH} environment variable, that is
-reflected in the file name.  The syncline option (@option{-s}) uses the
-same notion of current file and line.  Assume this example is run in the
+reflected in the file name.  The syncline option (@option{-s}), and the
address@hidden and @samp{l} flags of @code{debugmode} (@pxref{Debug Levels}),
+also use this notion of current file and line.  Redefining the three
+location macros has no effect on syncline, debug, or warning message
+output.  Assume this example is run in the
 @file{checks} directory of the @acronym{GNU} M4 package, using
 @samp{--include=../examples} in the command line to find the file
 @file{incl.m4} mentioned earlier:
@@ -4122,7 +4125,7 @@
 @end example
 
 Currently, all text wrapped with @code{m4wrap} (@pxref{M4wrap}) behaves
-as though it came from line 0 of the file ``NONE''.  It is hoped that a
+as though it came from line 0 of the file ``''.  It is hoped that a
 future release of @code{m4} can overcome this limitation and remember
 which file invoked the call to @code{m4wrap}.
 
@@ -4171,7 +4174,9 @@
 After this macro call, @code{m4} will exit with exit status 1.  This macro
 is only intended for error exits, since the normal exit procedures are
 not followed, e.g., diverted text is not undiverted, and saved text
-(@pxref{M4wrap}) is not reread.
+(@pxref{M4wrap}) is not reread.  (This macro has a subtle bug, when
+invoked from wrapped text.  You should try to see if you can find it and
+correct it.  @pxref{Answers})
 
 @example
 m4wrap(`This text is lost to `m4exit'.')
@@ -4727,6 +4732,29 @@
 @result{}
 @end example
 
+The @code{fatal_error} macro (@pxref{M4exit}) does not quite match the
+format of internal error messages when invoked inside wrapped text, due
+to the current limitations of @code{__file__} (@pxref{Location}) when
+invoked inside @code{m4wrap}.  Since @code{m4} omits the file and line
+number from its warning messages when there is no current file (or
+equivalently, when the current line is 0, since all files start at line
+1), a better implementation would be:
+
address@hidden
+define(`fatal_error',
+  `errprint(__program__:ifelse(__line__, `0', `',
+    `__file__:__line__:')` fatal error: $*
+')m4exit(`1')')
address@hidden
+m4wrap(`divnum(`demo of internal message')
+fatal_error(`inside wrapped text')')
address@hidden
+^D
address@hidden: Warning: excess arguments to builtin `divnum' ignored
address@hidden
address@hidden: fatal error: inside wrapped text
address@hidden example
+
 @c ========================================================== Appendices
 
 @node Copying This Manual
Index: src/debug.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/debug.c,v
retrieving revision 1.1.1.1.2.6
diff -u -r1.1.1.1.2.6 debug.c
--- src/debug.c 27 Jul 2006 21:41:12 -0000      1.1.1.1.2.6
+++ src/debug.c 8 Aug 2006 23:10:01 -0000
@@ -215,11 +215,14 @@
 void
 debug_message_prefix (void)
 {
-  fprintf (debug, "m4 debug: ");
-  if (debug_level & DEBUG_TRACE_FILE)
-    fprintf (debug, "%s: ", current_file);
-  if (debug_level & DEBUG_TRACE_LINE)
-    fprintf (debug, "%d: ", current_line);
+  fprintf (debug, "m4debug:");
+  if (current_line)
+  {
+    if (debug_level & DEBUG_TRACE_FILE)
+      fprintf (debug, "%s:", current_file);
+    if (debug_level & DEBUG_TRACE_LINE)
+      fprintf (debug, "%d:", current_line);
+  }
 }
 
 /* The rest of this file contains the functions for macro tracing output.
@@ -320,10 +323,13 @@
 trace_header (int id)
 {
   trace_format ("m4trace:");
-  if (debug_level & DEBUG_TRACE_FILE)
-    trace_format ("%s:", current_file);
-  if (debug_level & DEBUG_TRACE_LINE)
-    trace_format ("%d:", current_line);
+  if (current_line)
+    {
+      if (debug_level & DEBUG_TRACE_FILE)
+        trace_format ("%s:", current_file);
+      if (debug_level & DEBUG_TRACE_LINE)
+        trace_format ("%d:", current_line);
+    }
   trace_format (" -%d- ", expansion_level);
   if (debug_level & DEBUG_TRACE_CALLID)
     trace_format ("id %d: ", id);
Index: src/input.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/input.c,v
retrieving revision 1.1.1.1.2.18
diff -u -r1.1.1.1.2.18 input.c
--- src/input.c 4 Aug 2006 13:19:41 -0000       1.1.1.1.2.18
+++ src/input.c 8 Aug 2006 23:10:01 -0000
@@ -535,7 +535,7 @@
   while ((ch = next_char ()) != CHAR_EOF && ch != '\n')
     ;
   if (ch == CHAR_EOF)
-    /* current_file changed to "NONE" if we see CHAR_EOF, use the
+    /* current_file changed to "" if we see CHAR_EOF, use the
        previous value we stored earlier.  */
     M4ERROR_AT_LINE ((warning_status, 0, file, line,
                      "Warning: end of file treated as newline"));
@@ -617,7 +617,7 @@
 void
 input_init (void)
 {
-  current_file = "NONE";
+  current_file = "";
   current_line = 0;
 
   obstack_init (&token_stack);
@@ -806,7 +806,7 @@
       if (ch != CHAR_EOF)
        obstack_grow (&token_stack, ecomm.string, ecomm.length);
       else
-       /* current_file changed to "NONE" if we see CHAR_EOF, use the
+       /* current_file changed to "" if we see CHAR_EOF, use the
           previous value we stored earlier.  */
        M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
                          "ERROR: end of file in comment"));
@@ -888,7 +888,7 @@
        {
          ch = next_char ();
          if (ch == CHAR_EOF)
-           /* current_file changed to "NONE" if we see CHAR_EOF, use
+           /* current_file changed to "" if we see CHAR_EOF, use
               the previous value we stored earlier.  */
            M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
                              "ERROR: end of file in string"));
Index: src/m4.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/m4.c,v
retrieving revision 1.1.1.1.2.26
diff -u -r1.1.1.1.2.26 m4.c
--- src/m4.c    8 Aug 2006 16:23:58 -0000       1.1.1.1.2.26
+++ src/m4.c    8 Aug 2006 23:10:01 -0000
@@ -95,7 +95,21 @@
 {
   va_list args;
   va_start (args, format);
-  verror_at_line (status, errnum, current_file, current_line, format, args);
+  verror_at_line (status, errnum, current_line ? current_file : NULL,
+                  current_line, format, args);
+}
+
+/*-------------------------------.
+| Wrapper around error_at_line.  |
+`-------------------------------*/
+
+void
+m4_error_at_line (int status, int errnum, const char *file, int line,
+                  const char *format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  verror_at_line (status, errnum, line ? file : NULL, line, format, args);
 }
 
 #ifdef USE_STACKOVF
Index: src/m4.h
===================================================================
RCS file: /sources/m4/m4/src/m4.h,v
retrieving revision 1.1.1.1.2.26
diff -u -r1.1.1.1.2.26 m4.h
--- src/m4.h    8 Aug 2006 16:23:58 -0000       1.1.1.1.2.26
+++ src/m4.h    8 Aug 2006 23:10:01 -0000
@@ -125,9 +125,11 @@
 extern const char *program_name;
 
 void m4_error (int, int, const char *, ...) M4_GNUC_PRINTF(3, 4);
+void m4_error_at_line (int, int, const char *, int,
+                       const char *, ...) M4_GNUC_PRINTF(5, 6);
 
 #define M4ERROR(Arglist) (m4_error Arglist)
-#define M4ERROR_AT_LINE(Arglist) (error_at_line Arglist)
+#define M4ERROR_AT_LINE(Arglist) (m4_error_at_line Arglist)
 
 #ifdef USE_STACKOVF
 void setup_stackovf_trap (char *const *, char *const *,
Index: src/macro.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/macro.c,v
retrieving revision 1.1.1.1.2.10
diff -u -r1.1.1.1.2.10 macro.c
--- src/macro.c 4 Aug 2006 13:19:41 -0000       1.1.1.1.2.10
+++ src/macro.c 8 Aug 2006 23:10:01 -0000
@@ -165,7 +165,7 @@
          break;
 
        case TOKEN_EOF:
-         /* current_file changed to "NONE" if we see TOKEN_EOF, use the
+         /* current_file changed to "" if we see TOKEN_EOF, use the
             previous value we stored earlier.  */
          M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
                            "ERROR: end of file in argument list"));
Index: src/output.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/output.c,v
retrieving revision 1.1.1.1.2.8
diff -u -r1.1.1.1.2.8 output.c
--- src/output.c        24 Jul 2006 20:02:16 -0000      1.1.1.1.2.8
+++ src/output.c        8 Aug 2006 23:10:01 -0000
@@ -339,7 +339,7 @@
                sprintf (line, "#line %d", current_line);
                for (cursor = line; *cursor; cursor++)
                  OUTPUT_CHARACTER (*cursor);
-               if (output_current_line < 1)
+               if (output_current_line < 1 && current_file[0] != '\0')
                  {
                    OUTPUT_CHARACTER (' ');
                    OUTPUT_CHARACTER ('"');







reply via email to

[Prev in Thread] Current Thread [Next in Thread]