Re: split -E functionality

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
Eric Blake <ebb9 <at> byu.net> writes:

> 
> 2007-02-01  Eric Blake  <ebb9 <at> byu.net>
> 
> 	* src/m4.c (fatal_warnings): New variable.
> 	(usage): Document new -E behavior.
> 	(main): Make -E an additive option.

Ported to head as follows.


Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.95
diff -u -r1.95 m4.texinfo
--- doc/m4.texinfo	3 Feb 2007 23:45:43 -0000	1.95
+++ doc/m4.texinfo	5 Feb 2007 16:48:42 -0000
@@ -611,8 +611,14 @@
 
 @item -E
 @itemx --fatal-warnings
-Stop execution and exit @code{m4} once the first warning or error has
-been issued, considering all of them to be fatal.
+Controls the effect of warnings.  If unspecified, then execution
+continues and exit status is unaffected when a warning is printed.  If
+specified exactly once, warnings become fatal; when one is issued,
+execution continues, but the exit status will be non-zero.  If specified
+multiple times, then execution halts with non-zero status the first time
+a warning is issued.  The introduction of behavior levels is new to M4
+1.4.9; for behavior consistent with earlier versions, you should specify
+@option{-E} twice.
 
 @item -i
 @itemx --interactive
Index: m4/m4module.h
===================================================================
RCS file: /sources/m4/m4/m4/m4module.h,v
retrieving revision 1.105
diff -u -r1.105 m4module.h
--- m4/m4module.h	23 Jan 2007 14:28:22 -0000	1.105
+++ m4/m4module.h	5 Feb 2007 16:48:42 -0000
@@ -156,6 +156,7 @@
 	M4OPT_BIT(M4_OPT_SYNCOUTPUT_BIT,	syncoutput_opt)		\
 	M4OPT_BIT(M4_OPT_POSIXLY_CORRECT_BIT,	posixly_correct_opt)	\
 	M4OPT_BIT(M4_OPT_FATAL_WARN_BIT,	fatal_warnings_opt)	\
+	M4OPT_BIT(M4_OPT_WARN_EXIT_BIT,		warnings_exit_opt)	\
 	M4OPT_BIT(M4_OPT_SAFER_BIT,		safer_opt)		\
 
 
Index: m4/m4private.h
===================================================================
RCS file: /sources/m4/m4/m4/m4private.h,v
retrieving revision 1.76
diff -u -r1.76 m4private.h
--- m4/m4private.h	13 Jan 2007 13:55:37 -0000	1.76
+++ m4/m4private.h	5 Feb 2007 16:48:42 -0000
@@ -80,8 +80,9 @@
 #define M4_OPT_INTERACTIVE_BIT		(1 << 3) /* -e */
 #define M4_OPT_SYNCOUTPUT_BIT		(1 << 4) /* -s */
 #define M4_OPT_POSIXLY_CORRECT_BIT	(1 << 5) /* -G/POSIXLY_CORRECT */
-#define M4_OPT_FATAL_WARN_BIT		(1 << 6) /* -E */
-#define M4_OPT_SAFER_BIT		(1 << 7) /* --safer */
+#define M4_OPT_FATAL_WARN_BIT		(1 << 6) /* -E once */
+#define M4_OPT_WARN_EXIT_BIT		(1 << 7) /* -E twice */
+#define M4_OPT_SAFER_BIT		(1 << 8) /* --safer */
 
 /* Fast macro versions of accessor functions for public fields of m4,
    that also have an identically named function exported in m4module.h.  */
@@ -127,6 +128,8 @@
 		(BIT_TEST((C)->opt_flags, M4_OPT_POSIXLY_CORRECT_BIT))
 #  define m4_get_fatal_warnings_opt(C)					\
 		(BIT_TEST((C)->opt_flags, M4_OPT_FATAL_WARN_BIT))
+#  define m4_get_warnings_exit_opt(C)					\
+		(BIT_TEST((C)->opt_flags, M4_OPT_WARN_EXIT_BIT))
 #  define m4_get_safer_opt(C)						\
 		(BIT_TEST((C)->opt_flags, M4_OPT_SAFER_BIT))
 
Index: m4/utility.c
===================================================================
RCS file: /sources/m4/m4/m4/utility.c,v
retrieving revision 1.56
diff -u -r1.56 utility.c
--- m4/utility.c	14 Nov 2006 05:58:01 -0000	1.56
+++ m4/utility.c	5 Feb 2007 16:48:42 -0000
@@ -1,6 +1,6 @@
 /* GNU m4 -- A simple macro processor
    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2003,
-   2006 Free Software Foundation, Inc.
+   2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -154,7 +154,7 @@
   int line = m4_get_current_line (context);
   assert (m4_get_current_file (context) || ! line);
   va_start (args, format);
-  if (status == EXIT_SUCCESS && m4_get_fatal_warnings_opt (context))
+  if (status == EXIT_SUCCESS && m4_get_warnings_exit_opt (context))
     status = EXIT_FAILURE;
   verror_at_line (status, errnum, line ? m4_get_current_file (context) : NULL,
 		  line, format, args);
@@ -174,7 +174,7 @@
 {
   va_list args;
   va_start (args, format);
-  if (status == EXIT_SUCCESS && m4_get_fatal_warnings_opt (context))
+  if (status == EXIT_SUCCESS && m4_get_warnings_exit_opt (context))
     status = EXIT_FAILURE;
   verror_at_line (status, errnum, line ? file : NULL,
 		  line, format, args);
@@ -199,7 +199,7 @@
 
       assert (m4_get_current_file (context) || ! line);
       va_start (args, format);
-      if (m4_get_fatal_warnings_opt (context))
+      if (m4_get_warnings_exit_opt (context))
 	status = EXIT_FAILURE;
       /* If the full_format failed (unlikely though that may be), at
 	 least fall back on the original format.  */
@@ -207,6 +207,9 @@
 		      line ? m4_get_current_file (context) : NULL, line,
 		      full_format ? full_format : format, args);
       free (full_format);
+      if (m4_get_fatal_warnings_opt (context)
+	  && ! m4_get_exit_status (context))
+	m4_set_exit_status (context, EXIT_FAILURE);
     }
 }
 
@@ -226,13 +229,16 @@
       int status = EXIT_SUCCESS;
       char *full_format = xasprintf(_("Warning: %s"), format);
       va_start (args, format);
-      if (m4_get_fatal_warnings_opt (context))
+      if (m4_get_warnings_exit_opt (context))
 	status = EXIT_FAILURE;
       /* If the full_format failed (unlikely though that may be), at
 	 least fall back on the original format.  */
       verror_at_line (status, errnum, line ? file : NULL, line,
 		      full_format ? full_format : format, args);
       free (full_format);
+      if (m4_get_fatal_warnings_opt (context)
+	  && ! m4_get_exit_status (context))
+	m4_set_exit_status (context, EXIT_FAILURE);
     }
 }
 
Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.107
diff -u -r1.107 main.c
--- src/main.c	13 Jan 2007 13:55:37 -0000	1.107
+++ src/main.c	5 Feb 2007 16:48:42 -0000
@@ -87,7 +87,8 @@
       fputs (_("\
   -b, --batch                  buffer output, process interrupts\n\
   -c, --discard-comments       do not copy comments to the output\n\
-  -E, --fatal-warnings         stop execution after first warning or error\n\
+  -E, --fatal-warnings         once: warnings become errors, twice: stop\n\
+                               execution at first error\n\
   -i, --interactive            unbuffer output, ignore interrupts\n\
   -P, --prefix-builtins        force a `m4_' prefix to all builtins\n\
   -Q, --quiet, --silent        suppress some warnings for builtins\n\
@@ -460,7 +461,10 @@
 	break;
 
       case 'E':
-	m4_set_fatal_warnings_opt (context, true);
+	if (m4_get_fatal_warnings_opt (context))
+	  m4_set_warnings_exit_opt (context, true);
+	else
+	  m4_set_fatal_warnings_opt (context, true);
 	break;
 
       case 'F':
Index: tests/options.at
===================================================================
RCS file: /sources/m4/m4/tests/options.at,v
retrieving revision 1.24
diff -u -r1.24 options.at
--- tests/options.at	14 Nov 2006 05:58:01 -0000	1.24
+++ tests/options.at	5 Feb 2007 16:48:42 -0000
@@ -1,5 +1,5 @@
 # Hand crafted tests for GNU M4.                               -*- Autotest -*-
-# Copyright (C) 2001, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2006, 2007 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -458,6 +458,43 @@
 AT_CLEANUP
 
 
+## -------------- ##
+## fatal warnings ##
+## -------------- ##
+
+AT_SETUP([--fatal-warnings])
+
+AT_DATA([[in]],
+[[dnl()
+dnl()
+dnl()
+]])
+
+dnl By default, warnings don't affect exit status
+AT_CHECK_M4([in], [0], [],
+[[m4:in:1: Warning: dnl: extra arguments ignored: 1 > 0
+m4:in:2: Warning: dnl: extra arguments ignored: 1 > 0
+m4:in:3: Warning: dnl: extra arguments ignored: 1 > 0
+]])
+
+dnl With one -E, exit status changes, but execution continues
+AT_CHECK_M4([-E in], [1], [],
+[[m4:in:1: Warning: dnl: extra arguments ignored: 1 > 0
+m4:in:2: Warning: dnl: extra arguments ignored: 1 > 0
+m4:in:3: Warning: dnl: extra arguments ignored: 1 > 0
+]])
+
+dnl With two -E, execution halts immediately
+AT_CHECK_M4([--fatal-warnings --fatal-warnings in], [1], [],
+[[m4:in:1: Warning: dnl: extra arguments ignored: 1 > 0
+]])
+
+dnl Exit status can't be affected if there were no warnings
+AT_CHECK_M4([-EEQ in], [0])
+
+AT_CLEANUP
+
+
 ## ---------------- ##
 ## help and version ##
 ## ---------------- ##
Index: tests/others.at
===================================================================
RCS file: /sources/m4/m4/tests/others.at,v
retrieving revision 1.30
diff -u -r1.30 others.at
--- tests/others.at	5 Feb 2007 16:20:25 -0000	1.30
+++ tests/others.at	5 Feb 2007 16:48:42 -0000
@@ -484,7 +484,7 @@
 AT_DATA([in.m4], [[dnl(
 0)trailing data
 ]])
-AT_CHECK([(m4 -E; cat) < in.m4], [0], [[trailing data
+AT_CHECK([(m4 -EE; cat) < in.m4], [0], [[trailing data
 ]], [stderr])
 AT_CHECK([[sed 's/^[^:]*[lt-]*m4[.ex]*:/m4:/' stderr]], [0],
 [[m4:stdin:1: Warning: dnl: extra arguments ignored: 1 > 0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.