m4-commit
[Top][All Lists]
Advanced

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

Changes to m4/src/Attic/builtin.c,v [branch-1_4]


From: Eric Blake
Subject: Changes to m4/src/Attic/builtin.c,v [branch-1_4]
Date: Fri, 30 Jun 2006 18:58:13 +0000

CVSROOT:        /sources/m4
Module name:    m4
Branch:         branch-1_4
Changes by:     Eric Blake <ericb>      06/06/30 18:58:12

Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.15
retrieving revision 1.1.1.1.2.16
diff -u -b -r1.1.1.1.2.15 -r1.1.1.1.2.16
--- src/builtin.c       30 Jun 2006 15:06:53 -0000      1.1.1.1.2.15
+++ src/builtin.c       30 Jun 2006 18:58:11 -0000      1.1.1.1.2.16
@@ -28,6 +28,10 @@
 
 #include "regex.h"
 
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
 #define ARG(i) (argc > (i) ? TOKEN_DATA_TEXT (argv[i]) : "")
 
 /* Initialisation of builtin and predefined macros.  The table
@@ -765,9 +769,34 @@
 | and "sysval".  "esyscmd" is GNU specific.                              |
 `------------------------------------------------------------------------*/
 
+/* Helper macros for readability.  */
+#if UNIX || defined WEXITSTATUS
+# define M4SYSVAL_EXITBITS(status)                       \
+   (WIFEXITED (status) ? WEXITSTATUS (status) : 0)
+# define M4SYSVAL_TERMSIGBITS(status)                    \
+   (WIFSIGNALED (status) ? WTERMSIG (status) << 8 : 0)
+
+#else /* ! UNIX && ! defined WEXITSTATUS */
+/* Platforms such as mingw do not support the notion of reporting
+   which signal terminated a process.  Furthermore if WEXITSTATUS was
+   not provided, then the exit value is in the low eight bits.  */
+# define M4SYSVAL_EXITBITS(status) status
+# define M4SYSVAL_TERMSIGBITS(status) 0
+#endif /* ! UNIX && ! defined WEXITSTATUS */
+
+/* Fallback definitions if <stdlib.h> or <sys/wait.h> are inadequate.  */
 #ifndef WEXITSTATUS
 # define WEXITSTATUS(status) (((status) >> 8) & 0xff)
 #endif
+#ifndef WTERMSIG
+# define WTERMSIG(status) ((status) & 0x7f)
+#endif
+#ifndef WIFSIGNALED
+# define WIFSIGNALED(status) (WTERMSIG (status) != 0)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(status) (WTERMSIG (status) == 0)
+#endif
 
 /* Exit code from last "syscmd" command.  */
 static int sysval;
@@ -806,7 +835,7 @@
     {
       M4ERROR ((warning_status, errno,
                "cannot open pipe to command \"%s\"", ARG (1)));
-      sysval = 0xffff;
+      sysval = -1;
     }
   else
     {
@@ -819,7 +848,9 @@
 static void
 m4_sysval (struct obstack *obs, int argc, token_data **argv)
 {
-  shipout_int (obs, WEXITSTATUS (sysval));
+  shipout_int (obs, (sysval == -1 ? 127
+                    : (M4SYSVAL_EXITBITS (sysval)
+                       | M4SYSVAL_TERMSIGBITS (sysval))));
 }
 
 /*-------------------------------------------------------------------------.




reply via email to

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