2004-10-27  Juan Manuell Guerrero  <st001906@hrz1.hrz.tu-darmstadt.de>

	* src/m4.c: Added HAVE_SYS_SIGNAL_H. If undefined signal.h
	will be included instead of sys/signal.h.


2004-10-28  Juan Manuell Guerrero  <st001906@hrz1.hrz.tu-darmstadt.de>

	* src/m4.h: Added O_BINARY. This macro is used to define a
	serie of macros to parametrize OS specific issues like path
	separators, directory separators, drive letters
	will be included instead of sys/signal.h.
	* src/m4.c (main): Added GET_PROGRAM_NAME. On DJGPP systems
	it strips the complete path and extension from argv[0]. For
	all other systems it simply copies argv[0] to the variable.
	* src/output.c (make_room_for): Added SET_BINARY. On systems
	that distinguish between text and binary files, tmpfiles are
	opened in binary mode.
	* src/path.c (include_env_init): Added PATH_SEP. Macro defines
	form of path separator according the OS used.
	(path_search): Added IS_ABSOLUTE. Macro defines	form of absolute
	path according the OS used.
	* src/builtin.c: Include sys/wait.h for WEXITSTATUS definition.
	(m4_esyscmd): The return value of system() is set to the value
	in a way that will be correct for big and little endian systems.
	(m4_esyscmd): Use WEXITSTATUS to get exit status.



diff -apruNU3 m4-1.4.2.orig/src/builtin.c m4-1.4.2/src/builtin.c
--- m4-1.4.2.orig/src/builtin.c	2004-08-21 10:29:00.000000000 +0000
+++ m4-1.4.2/src/builtin.c	2004-10-31 03:50:30.000000000 +0000
@@ -23,6 +23,8 @@
 
 #include "m4.h"
 
+#include <sys/wait.h>
+
 extern FILE *popen ();
 
 #include "regex.h"
@@ -773,7 +775,7 @@ m4_esyscmd (struct obstack *obs, int arg
     {
       M4ERROR ((warning_status, errno,
 		"Cannot open pipe to command \"%s\"", ARG (1)));
-      sysval = 0xff << 8;
+      sysval = -1;
     }
   else
     {
@@ -786,7 +788,7 @@ m4_esyscmd (struct obstack *obs, int arg
 static void
 m4_sysval (struct obstack *obs, int argc, token_data **argv)
 {
-  shipout_int (obs, (sysval >> 8) & 0xff);
+  shipout_int (obs, sysval == -1 ? 127 : WEXITSTATUS (sysval));
 }
 
 /*-------------------------------------------------------------------------.
diff -apruNU3 m4-1.4.2.orig/src/m4.c m4-1.4.2/src/m4.c
--- m4-1.4.2.orig/src/m4.c	2004-08-21 10:29:00.000000000 +0000
+++ m4-1.4.2/src/m4.c	2004-10-31 03:50:30.000000000 +0000
@@ -21,7 +21,11 @@
 #include "m4.h"
 
 #include <getopt.h>
-#include <sys/signal.h>
+#if HAVE_SYS_SIGNAL_H
+# include <sys/signal.h>
+#else
+# include <signal.h>
+#endif
 
 static void usage _((int));
 
@@ -261,7 +265,7 @@ main (int argc, char *const *argv, char 
   macro_definition *defines;
   FILE *fp;
 
-  program_name = argv[0];
+  GET_PROGRAM_NAME(program_name, argv[0]);
 
   include_init ();
   debug_init ();
diff -apruNU3 m4-1.4.2.orig/src/m4.h m4-1.4.2/src/m4.h
--- m4-1.4.2.orig/src/m4.h	2004-08-21 10:29:00.000000000 +0000
+++ m4-1.4.2/src/m4.h	2004-10-31 03:50:30.000000000 +0000
@@ -162,6 +162,76 @@ void reference_error _((void));
 void setup_stackovf_trap _((char *const *, char *const *,
 			    void (*handler) (void)));
 #endif
+
+
+/* MS-DOS and similar non-Posix systems have some peculiarities:
+    - they distinguish between binary and text files;
+    - they use both `/' and `\\' as directory separator in file names;
+    - they can have a drive letter X: prepended to a file name;
+    - they have a separate root directory on each drive;
+    - their filesystems are case-insensitive;
+    - directories in environment variables (like PATH) are separated
+        by `;' rather than `:';
+    - text files can have their lines ended either with \n or with \r\n pairs;
+   These are all parameterized here except.  */
+#ifndef O_BINARY
+# ifdef _O_BINARY
+#  define O_BINARY _O_BINARY
+# else
+#  define O_BINARY 0
+# endif
+#endif /* O_BINARY */
+
+#if O_BINARY
+# include <fcntl.h>
+# include <io.h>
+# ifdef __MSDOS__
+#  ifdef __DJGPP__
+#   ifndef HAVE_LC_MESSAGES
+#    define LC_MESSAGES (-1)
+#   endif
+#  define GET_PROGRAM_NAME(progname, name)  \
+   do {                                     \
+     char *p, *my_program_name;             \
+                                            \
+     p = strrchr((name), '/');              \
+     if (p == NULL)                         \
+       p = (name);                          \
+     else                                   \
+       p++;                                 \
+                                            \
+     my_program_name = strdup(p);           \
+     p = strrchr(my_program_name, '.');     \
+     if (p != NULL)                         \
+       *p = '\0';                           \
+                                            \
+     progname = my_program_name;            \
+   } while (0)
+#  endif /* O_BINARY && __DJGPP__ */
+# else   /* O_BINARY && !__MSDOS__ */
+#  define setmode(f,m)                      _setmode(f,m)
+# endif  /* O_BINARY && !__MSDOS__ */
+# ifdef __CYGWIN__
+#  define PATH_SEP                          ':'
+# else  /* O_BINARY && !__CYGWIN__ */
+#  define PATH_SEP                          ';'
+# endif /* O_BINARY && !__CYGWIN__ */
+  /* Back to any O_BINARY system.  */
+# define HAVE_DRIVE(n)                      ((n)[0] && (n)[1] == ':')
+# define IS_SLASH(c)                        ((c) == '/' || (c) == '\\')
+# define IS_ABSOLUTE(n)                     (IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':'))
+# define SET_BINARY(f)                      do {if (!isatty(f)) setmode(f,O_BINARY);} while (0)
+# ifndef GET_PROGRAM_NAME
+#  define GET_PROGRAM_NAME(progname, name)  do {(progname) = (name);} while (0)
+# endif
+#else  /* not O_BINARY, i.e., Unix */
+# define SET_BINARY(f)                      (void)0
+# define IS_SLASH(c)                        ((c) == '/')
+# define HAVE_DRIVE(n)                      (0)
+# define IS_ABSOLUTE(n)                     ((n)[0] == '/')
+# define PATH_SEP                           ':'
+# define GET_PROGRAM_NAME(progname, name)   do {(progname) = (name);} while (0)
+#endif /* not O_BINARY */
 
 /* File: debug.c  --- debugging and tracing function.  */
 
diff -apruNU3 m4-1.4.2.orig/src/output.c m4-1.4.2/src/output.c
--- m4-1.4.2.orig/src/output.c	2004-08-21 10:29:00.000000000 +0000
+++ m4-1.4.2/src/output.c	2004-10-31 03:50:30.000000000 +0000
@@ -195,6 +195,7 @@ make_room_for (int length)
 	 diversion to this file, then release the buffer.  */
 
       selected_diversion->file = tmpfile ();
+      SET_BINARY(selected_diversion->file);
       if (selected_diversion->file == NULL)
 	M4ERROR ((EXIT_FAILURE, errno,
 		  "ERROR: Cannot create temporary file for diversion"));
diff -apruNU3 m4-1.4.2.orig/src/path.c m4-1.4.2/src/path.c
--- m4-1.4.2.orig/src/path.c	2004-08-21 10:29:00.000000000 +0000
+++ m4-1.4.2/src/path.c	2004-10-31 03:50:30.000000000 +0000
@@ -59,7 +59,7 @@ include_env_init (void)
 
   do
     {
-      path_end = strchr (path, ':');
+      path_end = strchr (path, PATH_SEP);
       if (path_end)
 	*path_end = '\0';
       add_include_directory (path);
@@ -112,7 +112,7 @@ path_search (const char *dir)
     return fp;
 
   /* If file not found, and filename absolute, fail.  */
-  if (*dir == '/' || no_gnu_extensions)
+  if (IS_ABSOLUTE(dir) || no_gnu_extensions)
     return NULL;
   e = errno;
 
