OSDN Git Service

* except.c (expand_start_all_catch): If the machine needs to
[pf3gnuchains/gcc-fork.git] / gcc / protoize.c
index b74c3d4..d386664 100644 (file)
@@ -1,8 +1,5 @@
-/* Protoize program - Written by Ron Guilmette at the Microelectronics
-   and Computer Technology Corporation (MCC).  The author's current
-   E-mail address is <rfg@ncd.com>.
-
-   Copyright (C) 1989, 1992 Free Software Foundation, Inc.
+/* Protoize program - Original version by Ron Guilmette (rfg@segfault.us.com).
+   Copyright (C) 1989, 92-96, 1997 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -18,11 +15,12 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* Any reasonable C++ compiler should have all of the same features
    as __STDC__ plus more, so make sure that __STDC__ is defined if
-   __cplusplus is defined. */
+   __cplusplus is defined.  */
 
 #if defined(__cplusplus) && !defined(__STDC__)
 #define __STDC__ 1
@@ -36,18 +34,11 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifndef __STDC__
 #define const
+#define volatile
 #endif
 
 #include "config.h"
 
-#ifdef POSIX /* We should be able to define _POSIX_SOURCE unconditionally,
-               but some systems respond in buggy ways to it,
-               including Sunos 4.1.1.  Which we don't classify as POSIX.  */
-/* In case this is a POSIX system with an ANSI C compiler,
-   ask for definition of all POSIX facilities.  */
-#define _POSIX_SOURCE
-#endif
-
 #if 0
 /* Users are not supposed to use _POSIX_SOURCE to say the
    system is a POSIX system.  That is not what _POSIX_SOURCE means! -- rms  */ 
@@ -57,42 +48,56 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 #endif /* 0 */
 
+#ifdef POSIX /* We should be able to define _POSIX_SOURCE unconditionally,
+               but some systems respond in buggy ways to it,
+               including SunOS 4.1.1.  Which we don't classify as POSIX.  */
+/* In case this is a POSIX system with an ANSI C compiler,
+   ask for definition of all POSIX facilities.  */
+#undef _POSIX_SOURCE
+#define _POSIX_SOURCE
+#endif
+
+#include <varargs.h>
+/* On some systems stdio.h includes stdarg.h;
+   we must bring in varargs.h first.  */
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
+#if defined(POSIX) || defined(CONCURRENT)
+#include <dirent.h>
+#else
 #include <sys/dir.h>
-#if ! defined (USG) || defined (SVR4)
-#include <sys/wait.h>
+#endif
 #endif
 #include <setjmp.h>
-#include "gvarargs.h"
+
+#include "gansidecl.h"
+
+/* Include getopt.h for the sake of getopt_long.
+   We don't need the declaration of getopt, and it could conflict
+   with something from a system header file, so effectively nullify that.  */
+#define getopt getopt_loser
 #include "getopt.h"
+#undef getopt
 
-#ifndef PATH_MAX       /* <limits.h> defines this on most POSIX systems.  */
-#include <sys/param.h>
-/* Sometimes <sys/param.h> defines these macros.  */
-#undef CHAR_BIT
-#undef CHAR_MAX
-#undef CHAR_MIN
-#undef CLK_TCK
-#undef INT_MAX
-#undef INT_MIN
-#undef LONG_MAX
-#undef LONG_MIN
-#undef SCHAR_MAX
-#undef SCHAR_MIN
-#undef SHRT_MAX
-#undef SHRT_MIN
-#undef UCHAR_MAX
-#undef UINT_MAX
-#undef ULONG_MAX
-#undef USHRT_MAX
+#ifndef errno
+extern int errno;
 #endif
 
-extern int errno;
+#ifndef HAVE_STRERROR
+extern int sys_nerr;
+#if defined(bsd4_4)
+extern const char *const sys_errlist[];
+#else
 extern char *sys_errlist[];
+#endif
+#else
+extern char *strerror();
+#endif
+
 extern char *version_string;
 
 /* Systems which are compatible only with POSIX 1003.1-1988 (but *not*
@@ -104,21 +109,26 @@ extern char *version_string;
 
 #define my_access(file,flag)   access((char *)file, flag)
 #define my_stat(file,pkt)      stat((char *)file, pkt)
-#define my_execvp(prog,argv)   execvp((char *)prog, (char **)argv)
 #define my_link(file1, file2)  link((char *)file1, (char *)file2)
 #define my_unlink(file)                unlink((char *)file)
 #define my_open(file, mode, flag)      open((char *)file, mode, flag)
 #define my_chmod(file, mode)   chmod((char *)file, mode)
 
-#if !(defined (USG) || defined (VMS) || defined (POSIX))
-#define GUESSPATHLEN (MAXPATHLEN + 1)
-#else /* (defined (USG) || defined (VMS) || defined (POSIX)) */
-/* We actually use this as a starting point, not a limit.  */
-#define GUESSPATHLEN 200
-#endif /* (defined (USG) || defined (VMS) || defined (POSIX)) */
+extern char *getpwd ();
+
+extern char *choose_temp_base PROTO ((void));
+
+extern int pexecute PROTO ((const char *, char * const *, const char *,
+                           const char *, char **, char **, int));
+extern int pwait PROTO ((int, int *, int));
+/* Flag arguments to pexecute.  */
+#define PEXECUTE_FIRST  1
+#define PEXECUTE_LAST   2
+#define PEXECUTE_SEARCH 4
 
 /* Aliases for pointers to void.
-   These were made to facilitate compilation with other compilers.  */
+   These were made to facilitate compilation with old brain-dead DEC C
+   compilers which didn't properly grok `void*' types.  */
 
 #ifdef __STDC__
 typedef void * pointer_type;
@@ -134,7 +144,7 @@ typedef char * const_pointer_type;
 #include <unistd.h>
 #include <signal.h>
 #include <fcntl.h>
-#include <string.h>
+#include <sys/wait.h>
 
 #else /* !defined(POSIX) */
 
@@ -143,35 +153,41 @@ typedef char * const_pointer_type;
 #define X_OK    1       /* Test for eXecute permission */
 #define F_OK    0       /* Test for existence of File */
 
+#ifndef O_RDONLY
 #define O_RDONLY        0
-#define O_WRONLY        1
+#endif
 
-/* Virtually every UN*X system now in common use (except for pre-4.3-tahoe
-   BSD systems) now provides getcwd as called for by POSIX.  Allow for
-   the few exceptions to the general rule here.  */
+#ifndef O_WRONLY
+#define O_WRONLY        1
+#endif
 
-#if !(defined (USG) || defined (VMS))
-extern char *getwd ();
-#define getcwd(buf,len) getwd(buf)
-#else /* (defined (USG) || defined (VMS)) */
-extern char *getcwd ();
-#endif /* (defined (USG) || defined (VMS)) */
+#ifndef WIFSIGNALED
+#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
+#endif
+#ifndef WTERMSIG
+#define WTERMSIG(S) ((S) & 0x7f)
+#endif
+#ifndef WIFEXITED
+#define WIFEXITED(S) (((S) & 0xff) == 0)
+#endif
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
+#endif
 
 /* Declaring stat or __flsbuf with a prototype
    causes conflicts with system headers on some systems.  */
 
 #ifndef abort
-extern VOLATILE void abort ();
+typedef void voidfn ();
+extern VOLATILE voidfn abort;
 #endif
-extern int kill();
 extern int creat ();
 #if 0 /* These conflict with stdio.h on some systems.  */
 extern int fprintf (FILE *, const char *, ...);
 extern int printf (const char *, ...);
+extern int open (const char *, int, ...);
 #endif /* 0 */
 extern void exit ();
-extern pointer_type malloc ();
-extern pointer_type realloc ();
 extern void free ();
 extern int read ();
 extern int write ();
@@ -181,31 +197,24 @@ extern int atoi ();
 extern int puts ();
 extern int fputs ();
 extern int fputc ();
-#if 0 /* Causes trouble on some systems that define setjmp as a macro.  */
-extern int setjmp ();
-extern void longjmp ();
-#endif
+extern int link ();
+extern int unlink ();
+extern int access ();
 
-extern char *   strcat();
-extern int      strcmp();
-extern char *   strcpy();
 #if 0 /* size_t from sys/types.h may fail to match GCC.
-        If so, we would get a warning from this.
-        So do without the prototype.  */
-extern size_t   strlen(const char *);
+        If so, we would get a warning from this.  */
+extern size_t   strlen ()
 #endif
-extern int      strncmp();
-extern char *   strncpy();
-extern char *   strrchr();
 
+/* Fork is not declared because the declaration caused a conflict
+   on the HPPA.  */
 #if !(defined (USG) || defined (VMS))
-extern int vfork ();
 #define fork vfork
-#else
-extern int fork ();
-#endif /* !(defined (USG) || defined (VMS)) */
+#endif /* (defined (USG) || defined (VMS)) */
 
-#endif /* !defined(POSIX) */
+#endif /* !defined (POSIX) */
+
+extern char *rindex ();
 
 /* Look for these where the `const' qualifier is intentionally cast aside.  */
 
@@ -219,20 +228,11 @@ extern int fork ();
 #define STRINGIFY(STRING) "STRING"
 #endif
 
-/* POSIX systems will not have definitions for WIFEXITED or WEXITSTATUS.
-   Define them correctly and so that they work for all environments.  */
-
-#undef WIFEXITED
-#define WIFEXITED(status_word) ((*((int *)&status_word) & 0xff) == 0x00)
-
-#undef WEXITSTATUS
-#define WEXITSTATUS(status_word) ((*((int *)&status_word) & 0xff00) >> 8)
-
 /* Define a default place to find the SYSCALLS.X file.  */
 
 #ifndef STD_PROTO_DIR
 #define STD_PROTO_DIR "/usr/local/lib"
-#endif /* !defined(STD_PROTO_DIR) */
+#endif /* !defined (STD_PROTO_DIR) */
 
 /* Suffix of aux_info files.  */
 
@@ -248,7 +248,7 @@ static const char * const save_suffix = ".save";
    routines.  Note that we never actually do anything with this file per se,
    but we do read in its corresponding aux_info file.  */
 
-static const char * const syscalls_filename = "SYSCALLS.c";
+static const char syscalls_filename[] = "SYSCALLS.c";
 
 /* Default place to find the above file.  */
 
@@ -259,9 +259,9 @@ static const char * const default_syscalls_dir = STD_PROTO_DIR;
 
 static char * syscalls_absolute_filename;
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
-/* Type of the structure that holds information about macro unexpansions. */
+/* Type of the structure that holds information about macro unexpansions.  */
 
 struct unexpansion_struct {
   const char *expanded;
@@ -302,29 +302,39 @@ static const int hash_mask = (HASH_TABLE_SIZE - 1);
 #define LOCAL_INCLUDE_DIR "/usr/local/include"
 #endif
 
-struct default_include { char *fname; int cplusplus; } include_defaults[]
+struct default_include { const char *fname; int x1, x2; } include_defaults[]
 #ifdef INCLUDE_DEFAULTS
   = INCLUDE_DEFAULTS;
 #else
   = {
     /* Pick up GNU C++ specific include files.  */
-    { GPLUSPLUS_INCLUDE_DIR, 1},
-    { GCC_INCLUDE_DIR, 0},
+    { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
 #ifdef CROSS_COMPILE
+    /* This is the dir for fixincludes.  Put it just before
+       the files that we fix.  */
+    { GCC_INCLUDE_DIR, 0, 0 },
     /* For cross-compilation, this dir name is generated
        automatically in Makefile.in.  */
-    { CROSS_INCLUDE_DIR, 0 },
+    { CROSS_INCLUDE_DIR, 0, 0 },
+    /* This is another place that the target system's headers might be.  */
+    { TOOL_INCLUDE_DIR, 0, 0 },
 #else /* not CROSS_COMPILE */
-    { LOCAL_INCLUDE_DIR, 0},
+    /* This should be /use/local/include and should come before
+       the fixincludes-fixed header files.  */
+    { LOCAL_INCLUDE_DIR, 0, 1 },
+    /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
+       Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h.  */
+    { TOOL_INCLUDE_DIR, 0, 0 },
+    /* This is the dir for fixincludes.  Put it just before
+       the files that we fix.  */
+    { GCC_INCLUDE_DIR, 0, 0 },
     /* Some systems have an extra dir of include files.  */
 #ifdef SYSTEM_INCLUDE_DIR
-    { SYSTEM_INCLUDE_DIR, 0},
-#endif
-#ifndef NO_STANDARD_INCLUDE_DIR
-    { STANDARD_INCLUDE_DIR, 0},
+    { SYSTEM_INCLUDE_DIR, 0, 0 },
 #endif
+    { STANDARD_INCLUDE_DIR, 0, 0},
 #endif /* not CROSS_COMPILE */
-    { 0, 0}
+    { 0, 0, 0}
     };
 #endif /* no INCLUDE_DEFAULTS */
 
@@ -356,12 +366,12 @@ struct string_list *exclude_list;
 
 #ifdef UNPROTOIZE
 static const char * const other_var_style = "stdarg";
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
 static const char * const other_var_style = "varargs";
 /* Note that this is a string containing the expansion of va_alist.
    But in `main' we discard all but the first token.  */
-static const char *varargs_style_indicator = STRINGIFY(va_alist);
-#endif /* !defined(UNPROTOIZE) */
+static const char *varargs_style_indicator = STRINGIFY (va_alist);
+#endif /* !defined (UNPROTOIZE) */
 
 /* The following two types are used to create hash tables.  In this program,
    there are two hash tables which are used to store and quickly lookup two
@@ -457,13 +467,13 @@ struct def_dec_info_struct {
 #ifndef UNPROTOIZE
   const f_list_chain_item * f_list_chain;      /* -> chain of formals lists */
   const def_dec_info * definition;     /* -> def/dec containing related def */
-  char                 is_static;      /* = 0 means visiblilty is "extern"  */
+  char                 is_static;      /* = 0 means visibility is "extern"  */
   char                 is_implicit;    /* != 0 for implicit func decl's */
   char                 written;        /* != 0 means written for implicit */
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
   const char *         formal_names;   /* -> to list of names of formals */
-  const char *         formal_decls;   /* -> to string of formal declartions */
-#endif /* !defined(UNPROTOIZE) */
+  const char *         formal_decls;   /* -> to string of formal declarations */
+#endif /* !defined (UNPROTOIZE) */
 };
 
 /* Pointer to the tail component of the filename by which this program was
@@ -480,6 +490,10 @@ static int errors = 0;
 /* ??? These comments should say what the flag mean as well as the options
    that set them.  */
 
+/* File name to use for running gcc.  Allows GCC 2 to be named
+   something other than gcc.  */
+static const char *compiler_file_name = "gcc";
+
 static int version_flag = 0;           /* Print our version number.  */
 static int quiet_flag = 0;             /* Don't print messages normally.  */
 static int nochange_flag = 0;          /* Don't convert, just say what files
@@ -490,19 +504,23 @@ static const char ** compile_params = 0;  /* Option string for gcc.  */
 #ifdef UNPROTOIZE
 static const char *indent_string = "     ";    /* Indentation for newly
                                                   inserted parm decls.  */
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
 static int local_flag = 0;             /* Insert new local decls (when?).  */
 static int global_flag = 0;            /* set by -g option */
 static int cplusplus_flag = 0;         /* Rename converted files to *.C.  */
-static const charnondefault_syscalls_dir = 0; /* Dir to look for
+static const char *nondefault_syscalls_dir = 0; /* Dir to look for
                                                   SYSCALLS.c.X in.  */
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
-/* An index into the compile_params array where we should insert the filename
-   parameter when we are ready to exec the C compiler.  A zero value indicates
-   that we have not yet called munge_compile_params().  */
+/* An index into the compile_params array where we should insert the source
+   file name when we are ready to exec the C compiler.  A zero value indicates
+   that we have not yet called munge_compile_params.  */
+
+static int input_file_name_index = 0;
 
-static int filename_index = 0;
+/* An index into the compile_params array where we should insert the filename
+   for the aux info file, when we run the C compiler.  */
+static int aux_info_file_name_index = 0;
 
 /* Count of command line arguments which were "filename" arguments.  */
 
@@ -525,7 +543,7 @@ static const char *convert_filename;
 
 /* Pointer to relative root string (taken from aux_info file) which indicates
    where directory the user was in when he did the compilation step that
-   produced the containing aux_info file. */
+   produced the containing aux_info file.  */
 
 static const char *invocation_filename;
 
@@ -572,12 +590,12 @@ static char * repl_write_ptr;
 
 /* Pointer into the cleaned text buffer for the source file we are currently
    converting.  This points to the first character of the line that we last
-   did a "seek_to_line()" to (see below).  */
+   did a "seek_to_line" to (see below).  */
 
 static const char *last_known_line_start;
 
 /* Number of the line (in the cleaned text buffer) that we last did a
-   "seek_to_line()" to.  Will be one if we just read a new source file
+   "seek_to_line" to.  Will be one if we just read a new source file
    into the cleaned text buffer.  */
 
 static int last_known_line_number;
@@ -613,20 +631,42 @@ static char * saved_repl_write_ptr;
 
 static const char *shortpath ();
 \f
+char *
+my_strerror(e)
+     int e;
+{
+
+#ifdef HAVE_STRERROR
+  return strerror(e);
+
+#else
+
+  static char buffer[30];
+  if (!e)
+    return "";
+
+  if (e > 0 && e < sys_nerr)
+    return sys_errlist[e];
+
+  sprintf (buffer, "Unknown error %d", e);
+  return buffer;
+#endif
+}
+\f
 /* Allocate some space, but check that the allocation was successful.  */
+/* alloca.c uses this, so don't make it static.  */
 
-static pointer_type
+pointer_type
 xmalloc (byte_count)
      size_t byte_count;
 {
   pointer_type rv;
 
-  rv = malloc (byte_count);
+  rv = (pointer_type) malloc (byte_count);
   if (rv == NULL)
     {
-      fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
-              pname, byte_count);
-      exit (1);
+      fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);
+      exit (FATAL_EXIT_CODE);
       return 0;                /* avoid warnings */
     }
   else
@@ -635,19 +675,18 @@ xmalloc (byte_count)
 
 /* Reallocate some space, but check that the reallocation was successful.  */
 
-static pointer_type
+pointer_type
 xrealloc (old_space, byte_count)
      pointer_type old_space;
      size_t byte_count;
 {
   pointer_type rv;
 
-  rv = realloc (old_space, byte_count);
+  rv = (pointer_type) realloc (old_space, byte_count);
   if (rv == NULL)
     {
-      fprintf (stderr, "\n%s: fatal error: can't allocate %u more bytes of memory\n",
-              pname, byte_count);
-      exit (1);
+      fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);
+      exit (FATAL_EXIT_CODE);
       return 0;                /* avoid warnings */
     }
   else
@@ -658,7 +697,7 @@ xrealloc (old_space, byte_count)
    the `const' qualifier from it and also make sure that the pointer value
    is non-null.  */
 
-static void
+void
 xfree (p)
      const_pointer_type p;
 {
@@ -671,13 +710,28 @@ xfree (p)
 static char *
 savestring (input, size)
      const char *input;
-     int size;
+     unsigned int size;
 {
   char *output = (char *) xmalloc (size + 1);
   strcpy (output, input);
   return output;
 }
 
+/* Make a copy of the concatenation of INPUT1 and INPUT2.  */
+
+static char *
+savestring2 (input1, size1, input2, size2)
+     const char *input1;
+     unsigned int size1;
+     const char *input2;
+     unsigned int size2;
+{
+  char *output = (char *) xmalloc (size1 + size2 + 1);
+  strcpy (output, input1);
+  strcpy (&output[size1], input2);
+  return output;
+}
+
 /* More 'friendly' abort that prints the line and file.
    config.h can #define abort fancy_abort if you like that sort of thing.  */
 
@@ -685,18 +739,9 @@ void
 fancy_abort ()
 {
   fprintf (stderr, "%s: internal abort\n", pname);
-  exit (1);
+  exit (FATAL_EXIT_CODE);
 }
 \f
-/* Make a duplicate of a given string in a newly allocated area.  */
-
-static char *
-dupstr (s)
-     const char *s;
-{
-  return strcpy ((char *) xmalloc (strlen (s) + 1), s);
-}
-
 /* Make a duplicate of the first N bytes of a given string in a newly
    allocated area.  */
 
@@ -705,13 +750,14 @@ dupnstr (s, n)
      const char *s;
      size_t n;
 {
-  char *ret_val = strncpy ((char *) xmalloc (n + 1), s, n);
+  char *ret_val = (char *) xmalloc (n + 1);
 
+  strncpy (ret_val, s, n);
   ret_val[n] = '\0';
   return ret_val;
 }
 
-/* Return a pointer to the first occurance of s2 within s1 or NULL if s2
+/* Return a pointer to the first occurrence of s2 within s1 or NULL if s2
    does not occur within s1.  Assume neither s1 nor s2 are null pointers.  */
 
 static const char *
@@ -735,6 +781,61 @@ outer:
   return 0;
 }
 \f
+/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
+   retrying if necessary.  Return the actual number of bytes read.  */
+
+static int
+safe_read (desc, ptr, len)
+     int desc;
+     char *ptr;
+     int len;
+{
+  int left = len;
+  while (left > 0) {
+    int nchars = read (desc, ptr, left);
+    if (nchars < 0)
+      {
+#ifdef EINTR
+       if (errno == EINTR)
+         continue;
+#endif
+       return nchars;
+      }
+    if (nchars == 0)
+      break;
+    ptr += nchars;
+    left -= nchars;
+  }
+  return len - left;
+}
+
+/* Write LEN bytes at PTR to descriptor DESC,
+   retrying if necessary, and treating any real error as fatal.  */
+
+static void
+safe_write (desc, ptr, len, out_fname)
+     int desc;
+     char *ptr;
+     int len;
+     char *out_fname;
+{
+  while (len > 0) {
+    int written = write (desc, ptr, len);
+    if (written < 0)
+      {
+#ifdef EINTR
+       if (errno == EINTR)
+         continue;
+#endif
+       fprintf (stderr, "%s: error writing file `%s': %s\n",
+                pname, shortpath (NULL, out_fname), my_strerror(errno));
+       return;
+      }
+    ptr += written;
+    len -= written;
+  }
+}
+\f
 /* Get setup to recover in case the edit we are about to do goes awry.  */
 
 void
@@ -754,7 +855,7 @@ restore_pointers ()
   repl_write_ptr = saved_repl_write_ptr;
 }
 
-/* Return true if the given character is a legal identifier character.  */
+/* Return true if the given character is a valid identifier character.  */
 
 static int
 is_id_char (ch)
@@ -772,11 +873,11 @@ usage ()
 #ifdef UNPROTOIZE
   fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",
           pname, pname);
-#else /* !defined(UNPROTOIZE) */
-  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ filename ... ]'\n",
+#else /* !defined (UNPROTOIZE) */
+  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <dirname> ] [ filename ... ]'\n",
           pname, pname);
-#endif /* !defined(UNPROTOIZE) */
-  exit (1);
+#endif /* !defined (UNPROTOIZE) */
+  exit (FATAL_EXIT_CODE);
 }
 
 /* Return true if the given filename (assumed to be an absolute filename)
@@ -816,7 +917,7 @@ file_could_be_converted (const char *path)
     char *dir_last_slash;
 
     strcpy (dir_name, path);
-    dir_last_slash = strrchr (dir_name, '/');
+    dir_last_slash = rindex (dir_name, '/');
     if (dir_last_slash)
       *dir_last_slash = '\0';
     else
@@ -839,7 +940,7 @@ file_could_be_converted (const char *path)
    convert and for which we don't issue the usual warnings.  */
 
 static int
-file_normally_convertable (const char *path)
+file_normally_convertible (const char *path)
 {
   char *const dir_name = alloca (strlen (path) + 1);
 
@@ -850,7 +951,7 @@ file_normally_convertable (const char *path)
     char *dir_last_slash;
 
     strcpy (dir_name, path);
-    dir_last_slash = strrchr (dir_name, '/');
+    dir_last_slash = rindex (dir_name, '/');
     if (dir_last_slash)
       *dir_last_slash = '\0';
     else
@@ -894,10 +995,12 @@ static int
 is_syscalls_file (fi_p)
      const file_info *fi_p;
 {
-  return (substr (fi_p->hash_entry->symbol, syscalls_filename) != NULL);
+  char const *f = fi_p->hash_entry->symbol;
+  size_t fl = strlen (f), sysl = sizeof (syscalls_filename) - 1;
+  return sysl <= fl  &&  strcmp (f + fl - sysl, syscalls_filename) == 0;
 }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
 /* Check to see if this file will need to have anything done to it on this
    run.  If there is nothing in the given file which both needs conversion
@@ -906,7 +1009,7 @@ is_syscalls_file (fi_p)
 
    Note that (for protoize) it is only valid to call this function *after*
    the connections between declarations and definitions have all been made
-   by connect_defs_and_decs().  */
+   by connect_defs_and_decs.  */
 
 static int
 needs_to_be_converted (file_p)
@@ -919,7 +1022,7 @@ needs_to_be_converted (file_p)
   if (is_syscalls_file (file_p))
     return 0;
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   for (ddp = file_p->defs_decs; ddp; ddp = ddp->next_in_file)
 
@@ -927,17 +1030,17 @@ needs_to_be_converted (file_p)
 
 #ifndef UNPROTOIZE
 
-      /* ... and if we a protoizing and this function is in old style ... */
+      /* ... and if we a protoizing and this function is in old style ...  */
       !ddp->prototyped
-      /* ... and if this a definition or is a decl with an associated def ... */
+      /* ... and if this a definition or is a decl with an associated def ...  */
       && (ddp->is_func_def || (!ddp->is_func_def && ddp->definition))
 
-#else /* defined(UNPROTOIZE) */
+#else /* defined (UNPROTOIZE) */
 
-      /* ... and if we are unprotoizing and this function is in new style ... */
+      /* ... and if we are unprotoizing and this function is in new style ...  */
       ddp->prototyped
 
-#endif /* defined(UNPROTOIZE) */
+#endif /* defined (UNPROTOIZE) */
       )
           /* ... then the containing file needs converting.  */
           return -1;
@@ -956,7 +1059,18 @@ directory_specified_p (name)
   for (p = directory_list; p; p = p->next)
     if (!strncmp (name, p->name, strlen (p->name))
        && name[strlen (p->name)] == '/')
-      return 1;
+      {
+       const char *q = name + strlen (p->name) + 1;
+
+       /* If there are more slashes, it's in a subdir, so
+          this match doesn't count.  */
+       while (*q)
+         if (*q++ == '/')
+           goto lose;
+       return 1;
+
+      lose: ;
+      }
 
   return 0;
 }
@@ -984,7 +1098,7 @@ file_excluded_p (name)
 static struct string_list *
 string_list_cons (string, rest)
      char *string;
-     struct string_list *rest;      
+     struct string_list *rest;
 {
   struct string_list *temp
     = (struct string_list *) xmalloc (sizeof (struct string_list));
@@ -1032,7 +1146,7 @@ add_symbol (p, s)
      const char *s;
 {
   p->hash_next = NULL;
-  p->symbol = dupstr (s);
+  p->symbol = savestring (s, strlen (s));
   p->ddip = NULL;
   p->fip = NULL;
   return p;
@@ -1093,7 +1207,7 @@ free_def_dec (p)
         xfree (curr);
       }
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   xfree (p);
 }
@@ -1109,7 +1223,7 @@ unexpand_if_needed (aux_info_line)
 {
   static char *line_buf = 0;
   static int line_buf_size = 0;
-  const unexpansionunexp_p;
+  const unexpansion *unexp_p;
   int got_unexpanded = 0;
   const char *s;
   char *copy_p = line_buf;
@@ -1171,9 +1285,9 @@ continue_outer: ;
       copy_p = line_buf + offset;
     }
   *copy_p++ = '\n';
-  *copy_p++ = '\0';
+  *copy_p = '\0';
 
-  return (got_unexpanded ? dupstr (line_buf) : 0);
+  return (got_unexpanded ? savestring (line_buf, copy_p - line_buf) : 0);
 }
 \f
 /* Return the absolutized filename for the given relative
@@ -1194,11 +1308,11 @@ abspath (cwd, rel_filename)
   /* Setup the current working directory as needed.  */
   const char *cwd2 = (cwd) ? cwd : cwd_buffer;
   char *const abs_buffer
-    = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 1);
+    = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 2);
   char *endp = abs_buffer;
   char *outp, *inp;
 
-  /* Copy the  filename (possibly preceeded by the current working
+  /* Copy the  filename (possibly preceded by the current working
      directory name) into the absolutization buffer.  */
 
   {
@@ -1214,8 +1328,6 @@ abspath (cwd, rel_filename)
     src_p = rel_filename;
     while (*endp++ = *src_p++)
       continue;
-    if (endp[-1] == '/')
-      *endp = '\0';
   }
 
   /* Now make a copy of abs_buffer into abs_buffer, shortening the
@@ -1223,6 +1335,10 @@ abspath (cwd, rel_filename)
 
   outp = inp = abs_buffer;
   *outp++ = *inp++;            /* copy first slash */
+#ifdef apollo
+  if (inp[0] == '/')
+    *outp++ = *inp++;          /* copy second slash */
+#endif
   for (;;)
     {
       if (!inp[0])
@@ -1248,18 +1364,18 @@ abspath (cwd, rel_filename)
                     while (outp >= abs_buffer && *outp != '/')
                outp--;
                     if (outp < abs_buffer)
-                {
-                  /* Catch cases like /.. where we try to backup to a
-                     point above the absolute root of the logical file
-                     system.  */
-
-                 fprintf (stderr, "%s: invalid file name: %s\n",
-                          pname, rel_filename);
-                 exit (1);
-               }
+                     {
+                       /* Catch cases like /.. where we try to backup to a
+                          point above the absolute root of the logical file
+                          system.  */
+
+                       fprintf (stderr, "%s: invalid file name: %s\n",
+                                pname, rel_filename);
+                       exit (FATAL_EXIT_CODE);
+                     }
                     *++outp = '\0';
                     continue;
-            }
+                 }
         }
       *outp++ = *inp++;
     }
@@ -1274,7 +1390,7 @@ abspath (cwd, rel_filename)
   /* Make a copy (in the heap) of the stuff left in the absolutization
      buffer and return a pointer to the copy.  */
 
-  return dupstr (abs_buffer);
+  return savestring (abs_buffer, outp - abs_buffer);
 }
 \f
 /* Given a filename (and possibly a directory name from which the filename
@@ -1301,16 +1417,17 @@ shortpath (cwd, filename)
   char *cwd_p = cwd_buffer;
   char *path_p;
   int unmatched_slash_count = 0;
+  size_t filename_len = strlen (filename);
 
   path_p = abspath (cwd, filename);
-  rel_buf_p = rel_buffer = (char *) xmalloc (strlen (path_p) + 1);
+  rel_buf_p = rel_buffer = (char *) xmalloc (filename_len);
 
   while (*cwd_p && (*cwd_p == *path_p))
     {
       cwd_p++;
       path_p++;
     }
-  if (!*cwd_p)                 /* whole pwd matched */
+  if (!*cwd_p && (!*path_p || *path_p == '/')) /* whole pwd matched */
     {
       if (!*path_p)            /* input *is* the current path! */
         return ".";
@@ -1332,22 +1449,40 @@ shortpath (cwd, filename)
           path_p++;
           unmatched_slash_count++;
         }
+
+      /* Find out how many directory levels in cwd were *not* matched.  */
       while (*cwd_p)
         if (*cwd_p++ == '/')
-                unmatched_slash_count++;
+         unmatched_slash_count++;
+
+      /* Now we know how long the "short name" will be.
+        Reject it if longer than the input.  */
+      if (unmatched_slash_count * 3 + strlen (path_p) >= filename_len)
+       return filename;
+
+      /* For each of them, put a `../' at the beginning of the short name.  */
       while (unmatched_slash_count--)
         {
+         /* Give up if the result gets to be longer
+            than the absolute path name.  */
+         if (rel_buffer + filename_len <= rel_buf_p + 3)
+           return filename;
           *rel_buf_p++ = '.';
           *rel_buf_p++ = '.';
           *rel_buf_p++ = '/';
         }
-      while (*rel_buf_p++ = *path_p++)
-        continue;
+
+      /* Then tack on the unmatched part of the desired file's name.  */
+      do
+       {
+         if (rel_buffer + filename_len <= rel_buf_p)
+           return filename;
+       }
+      while (*rel_buf_p++ = *path_p++);
+
       --rel_buf_p;
       if (*(rel_buf_p-1) == '/')
         *--rel_buf_p = '\0';
-      if (strlen (rel_buffer) > (unsigned) strlen (filename))
-       strcpy (rel_buffer, filename);
       return rel_buffer;
     }
 }
@@ -1357,12 +1492,13 @@ shortpath (cwd, filename)
    we create a new file_info record to go with the filename, and we initialize
    that record with some reasonable values.  */
 
+/* FILENAME was const, but that causes a warning on AIX when calling stat.
+   That is probably a bug in AIX, but might as well avoid the warning.  */
+
 static file_info *
 find_file (filename, do_not_stat)
      char *filename;
      int do_not_stat;
-/* FILENAME was const, but that causes a warning on AIX when calling stat.
-   That is probably a bug in AIX, but might as well avoid the warning.  */
 {
   hash_table_entry *hash_entry_p;
 
@@ -1383,8 +1519,8 @@ find_file (filename, do_not_stat)
         {
           if (my_stat (filename, &stat_buf) == -1)
             {
-              fprintf (stderr, "%s: error: can't get status of `%s': %s\n",
-                      pname, shortpath (NULL, filename), sys_errlist[errno]);
+              fprintf (stderr, "%s: %s: can't get status: %s\n",
+                      pname, shortpath (NULL, filename), my_strerror(errno));
               stat_buf.st_mtime = (time_t) -1;
             }
         }
@@ -1405,11 +1541,11 @@ aux_info_corrupted ()
 {
   fprintf (stderr, "\n%s: fatal error: aux info file corrupted at line %d\n",
           pname, current_aux_info_lineno);
-  exit (1);
+  exit (FATAL_EXIT_CODE);
 }
 
 /* ??? This comment is vague.  Say what the condition is for.  */
-/* Check to see that a condition is true.  This is kind of like an assert().  */
+/* Check to see that a condition is true.  This is kind of like an assert.  */
 
 static void
 check_aux_info (cond)
@@ -1420,7 +1556,7 @@ check_aux_info (cond)
 }
 
 /* Given a pointer to the closing right parenthesis for a particular formals
-   list (in a aux_info file) find the corresponding left parenthesis and
+   list (in an aux_info file) find the corresponding left parenthesis and
    return a pointer to it.  */
 
 static const char *
@@ -1488,7 +1624,7 @@ referenced_file_is_newer (l, aux_info_mtime)
    a function definition or declaration.
 
    Link this record onto the list of such records for the particular file in
-   which it occured in proper (descending) line number order (for now).
+   which it occurred in proper (descending) line number order (for now).
 
    If there is an identical record already on the list for the file, throw
    this one away.  Doing so takes care of the (useless and troublesome)
@@ -1509,7 +1645,7 @@ save_def_or_dec (l, is_syscalls)
 
 #ifndef UNPROTOIZE
   def_dec_p->written = 0;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* Start processing the line by picking off 5 pieces of information from
      the left hand end of the line.  These are filename, line number,
@@ -1541,7 +1677,7 @@ save_def_or_dec (l, is_syscalls)
        all of these base file names (even if they may be useless later).
        The file_info records for all of these "base" file names (properly)
        act as file_info records for the "original" (i.e. un-included) files
-       which were submitted to gcc for compilation (when the -fgen-aux-info
+       which were submitted to gcc for compilation (when the -aux-info
        option was used).  */
   
     def_dec_p->file = find_file (abspath (invocation_filename, filename), is_syscalls);
@@ -1561,7 +1697,7 @@ save_def_or_dec (l, is_syscalls)
   /* Check that this record describes a new-style, old-style, or implicit
      definition or declaration.  */
 
-  p++; /* Skip over the `:'. */
+  p++; /* Skip over the `:'.  */
   check_aux_info ((*p == 'N') || (*p == 'O') || (*p == 'I'));
 
   /* Is this a new style (ANSI prototyped) definition or declaration? */
@@ -1574,7 +1710,7 @@ save_def_or_dec (l, is_syscalls)
 
   def_dec_p->is_implicit = (*p == 'I');
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   p++;
 
@@ -1588,7 +1724,7 @@ save_def_or_dec (l, is_syscalls)
 
 #ifndef UNPROTOIZE
   def_dec_p->definition = 0;   /* Fill this in later if protoizing.  */
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   check_aux_info (*p++ == ' ');
   check_aux_info (*p++ == '*');
@@ -1597,14 +1733,14 @@ save_def_or_dec (l, is_syscalls)
 
 #ifdef UNPROTOIZE
   check_aux_info ((!strncmp (p, "static", 6)) || (!strncmp (p, "extern", 6)));
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
   if (!strncmp (p, "static", 6))
     def_dec_p->is_static = -1;
   else if (!strncmp (p, "extern", 6))
     def_dec_p->is_static = 0;
   else
     check_aux_info (0);        /* Didn't find either `extern' or `static'.  */
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   {
     const char *ansi_start = p;
@@ -1625,28 +1761,35 @@ save_def_or_dec (l, is_syscalls)
 
     def_dec_p->ansi_decl
       = dupnstr (ansi_start, (size_t) ((semicolon_p+1) - ansi_start));
-  }
 
-  /* Backup and point at the final right paren of the final argument list.  */
+    /* Backup and point at the final right paren of the final argument list.  */
+
+    p--;
+
+#ifndef UNPROTOIZE
+    def_dec_p->f_list_chain = NULL;
+#endif /* !defined (UNPROTOIZE) */
 
-  p--;
+    while (p != ansi_start && (p[-1] == ' ' || p[-1] == '\t')) p--;
+    if (*p != ')')
+      {
+       free_def_dec (def_dec_p);
+       return;
+      }
+  }
 
   /* Now isolate a whole set of formal argument lists, one-by-one.  Normally,
      there will only be one list to isolate, but there could be more.  */
 
   def_dec_p->f_list_count = 0;
 
-#ifndef UNPROTOIZE
-  def_dec_p->f_list_chain = NULL;
-#endif /* !defined(UNPROTOIZE) */
-
   for (;;)
     {
       const char *left_paren_p = find_corresponding_lparen (p);
 #ifndef UNPROTOIZE
       {
-        f_list_chain_item *cip =
-          (f_list_chain_item *) xmalloc (sizeof (f_list_chain_item));
+        f_list_chain_item *cip
+         = (f_list_chain_item *) xmalloc (sizeof (f_list_chain_item));
 
         cip->formals_list
          = dupnstr (left_paren_p + 1, (size_t) (p - (left_paren_p+1)));
@@ -1656,7 +1799,7 @@ save_def_or_dec (l, is_syscalls)
         cip->chain_next = def_dec_p->f_list_chain;
         def_dec_p->f_list_chain = cip;
       }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
       def_dec_p->f_list_count++;
 
       p = left_paren_p - 2;
@@ -1665,7 +1808,7 @@ save_def_or_dec (l, is_syscalls)
          character of the name of the function that was declared/defined.
          If p points to another right paren, then this indicates that we
          are dealing with multiple formals lists.  In that case, there
-         really should be another right paren preceeding this right paren.  */
+         really should be another right paren preceding this right paren.  */
 
       if (*p != ')')
         break;
@@ -1720,12 +1863,11 @@ save_def_or_dec (l, is_syscalls)
           {
             if (strcmp (def_dec_p->ansi_decl, other->ansi_decl))
               {
-                fprintf (stderr, "%s: error: declaration of function `%s' at %s(%d) takes different forms\n",
-                        pname,
-                        def_dec_p->hash_entry->symbol,
+                fprintf (stderr, "%s:%d: declaration of function `%s' takes different forms\n",
                         def_dec_p->file->hash_entry->symbol,
-                        def_dec_p->line);
-                exit (1);
+                        def_dec_p->line,
+                        def_dec_p->hash_entry->symbol);
+                exit (FATAL_EXIT_CODE);
               }
             free_def_dec (def_dec_p);
             return;
@@ -1761,7 +1903,7 @@ save_def_or_dec (l, is_syscalls)
       check_aux_info (*++p == '(');
 
       {
-        const char *kr_names_start = ++p;   /* Point just inside '('. */
+        const char *kr_names_start = ++p;   /* Point just inside '('.  */
 
         while (*p++ != ')')
           continue;
@@ -1824,7 +1966,7 @@ save_def_or_dec (l, is_syscalls)
       return;
     }
 
-#endif /* defined(UNPROTOIZE) */
+#endif /* defined (UNPROTOIZE) */
 
   /* Add this record to the head of the list of records pertaining to this
      particular function name.  */
@@ -1872,19 +2014,25 @@ save_def_or_dec (l, is_syscalls)
     }
 }
 \f
-/* Rewrite the options list used to recompile base source files.  All we are
-   really doing here is removing -g, -O, -S, -c, and -o options, and then
-   adding a final group of options like '-fgen-aux-info -S  -o /dev/null'.  */
+/* Set up the vector COMPILE_PARAMS which is the argument list for running GCC.
+   Also set input_file_name_index and aux_info_file_name_index
+   to the indices of the slots where the file names should go.  */
+
+/* We initialize the vector by  removing -g, -O, -S, -c, and -o options,
+   and adding '-aux-info AUXFILE -S  -o /dev/null INFILE' at the end.  */
 
 static void
 munge_compile_params (params_list)
      const char *params_list;
 {
-  char **temp_params = (char **) alloca (strlen (params_list) + 10);
+  /* Build up the contents in a temporary vector
+     that is so big that to has to be big enough.  */
+  const char **temp_params
+    = (const char **) alloca ((strlen (params_list) + 8) * sizeof (char *));
   int param_count = 0;
   const char *param;
 
-  temp_params[param_count++] = "gcc";
+  temp_params[param_count++] = compiler_file_name;
   for (;;)
     {
       while (isspace (*params_list))
@@ -1920,95 +2068,96 @@ munge_compile_params (params_list)
       if (!*params_list)
         break;
     }
-  temp_params[param_count++] = "-fgen-aux-info";
+  temp_params[param_count++] = "-aux-info";
+
+  /* Leave room for the aux-info file name argument.  */
+  aux_info_file_name_index = param_count;
+  temp_params[param_count++] = NULL;
+
   temp_params[param_count++] = "-S";
   temp_params[param_count++] = "-o";
   temp_params[param_count++] = "/dev/null";
 
-  /* Leave room for the filename argument and a terminating null pointer.  */
-
-  temp_params[filename_index = param_count++] = NULL;
+  /* Leave room for the input file name argument.  */
+  input_file_name_index = param_count;
+  temp_params[param_count++] = NULL;
+  /* Terminate the list.  */
   temp_params[param_count++] = NULL;
 
   /* Make a copy of the compile_params in heap space.  */
 
   compile_params
-    = (char **) xmalloc (sizeof (char *) * (param_count+1));
+    = (const char **) xmalloc (sizeof (char *) * (param_count+1));
   memcpy (compile_params, temp_params, sizeof (char *) * param_count);
 }
 
 /* Do a recompilation for the express purpose of generating a new aux_info
-   file to go with a specific base source file.  */
+   file to go with a specific base source file.
+
+   The result is a boolean indicating success.  */
 
 static int
 gen_aux_info_file (base_filename)
      const char *base_filename;
 {
-  int child_pid;
-
-  if (!filename_index)
+  if (!input_file_name_index)
     munge_compile_params ("");
 
-  compile_params[filename_index] = shortpath (NULL, base_filename);
+  /* Store the full source file name in the argument vector.  */
+  compile_params[input_file_name_index] = shortpath (NULL, base_filename);
+  /* Add .X to source file name to get aux-info file name.  */
+  compile_params[aux_info_file_name_index]
+    = savestring2 (compile_params[input_file_name_index],
+                  strlen (compile_params[input_file_name_index]),
+                  ".X",
+                  2);
 
   if (!quiet_flag)
     fprintf (stderr, "%s: compiling `%s'\n",
-            pname, compile_params[filename_index]);
-
-  if (child_pid = fork ())
-    {
-      if (child_pid == -1)
-        {
-          fprintf (stderr, "%s: error: could not fork process: %s\n",
-                  pname, sys_errlist[errno]);
-          return 0;
-        }
+            pname, compile_params[input_file_name_index]);
 
-#if 0
-      /* Print out the command line that the other process is now executing.  */
+  {
+    char *errmsg_fmt, *errmsg_arg;
+    int wait_status, pid;
+    char *temp_base = choose_temp_base ();
 
-      if (!quiet_flag)
-        {
-          const char **arg;
-  
-          fputs ("\t", stderr);
-          for (arg = compile_params; *arg; arg++)
-            {
-              fputs (*arg, stderr);
-              fputc (' ', stderr);
-            }
-          fputc ('\n', stderr);
-          fflush (stderr);
-        }
-#endif /* 0 */
+    pid = pexecute (compile_params[0], (char * const *) compile_params,
+                   pname, temp_base, &errmsg_fmt, &errmsg_arg,
+                   PEXECUTE_FIRST | PEXECUTE_LAST | PEXECUTE_SEARCH);
 
+    if (pid == -1)
       {
-        int wait_status;
+       int errno_val = errno;
+       fprintf (stderr, "%s: ", pname);
+       fprintf (stderr, errmsg_fmt, errmsg_arg);
+       fprintf (stderr, ": %s\n", my_strerror (errno_val));
+       return 0;
+      }
 
-        if (wait (&wait_status) == -1)
-          {
-            fprintf (stderr, "%s: error: wait for process failed: %s\n",
-                    pname, sys_errlist[errno]);
-            return 0;
-          }
-        if (!WIFEXITED (wait_status))
-          {
-            kill (child_pid, 9);
-            return 0;
-          }
-        return (WEXITSTATUS (wait_status) == 0) ? 1 : 0;
+    pid = pwait (pid, &wait_status, 0);
+    if (pid == -1)
+      {
+       fprintf (stderr, "%s: wait: %s\n", pname, my_strerror (errno));
+       return 0;
       }
-    }
-  else
-    {
-      if (my_execvp (compile_params[0], (char *const *) compile_params))
-        {
-          fprintf (stderr, "%s: error: execvp returned: %s\n",
-                  pname, sys_errlist[errno]);
-          exit (errno);
-        }
-      return 1;                /* Never executed.  */
-    }
+    if (WIFSIGNALED (wait_status))
+      {
+       fprintf (stderr, "%s: subprocess got fatal signal %d\n",
+                pname, WTERMSIG (wait_status));
+       return 0;
+      }
+    if (WIFEXITED (wait_status))
+      {
+       if (WEXITSTATUS (wait_status) != 0)
+         {
+           fprintf (stderr, "%s: %s exited with status %d\n",
+                    pname, compile_params[0], WEXITSTATUS (wait_status));
+           return 0;
+         }
+       return 1;
+      }
+    abort ();
+  }
 }
 \f
 /* Read in all of the information contained in a single aux_info file.
@@ -2020,14 +2169,16 @@ process_aux_info_file (base_source_filename, keep_it, is_syscalls)
      int keep_it;
      int is_syscalls;
 {
-  char *const aux_info_filename
-    = (char *) alloca (strlen (base_source_filename)
-                      + strlen (aux_info_suffix) + 1);
+  size_t base_len = strlen (base_source_filename);
+  char * aux_info_filename
+    = (char *) alloca (base_len + strlen (aux_info_suffix) + 1);
   char *aux_info_base;
   char *aux_info_limit;
+  char *aux_info_relocated_name;
   const char *aux_info_second_line;
   time_t aux_info_mtime;
   size_t aux_info_size;
+  int must_create;
 
   /* Construct the aux_info filename from the base source filename.  */
 
@@ -2037,37 +2188,63 @@ process_aux_info_file (base_source_filename, keep_it, is_syscalls)
   /* Check that the aux_info file exists and is readable.  If it does not
      exist, try to create it (once only).  */
 
+  /* If file doesn't exist, set must_create.
+     Likewise if it exists and we can read it but it is obsolete.
+     Otherwise, report an error.  */
+  must_create = 0;
+
+  /* Come here with must_create set to 1 if file is out of date.  */
 start_over: ;
 
-  {
-    int retries = 0;
+  if (my_access (aux_info_filename, R_OK) == -1)
+    {
+      if (errno == ENOENT)
+       {
+         if (is_syscalls)
+           {
+             fprintf (stderr, "%s: warning: missing SYSCALLS file `%s'\n",
+                      pname, aux_info_filename);
+             return;
+           }
+         must_create = 1;
+       }
+      else
+       {
+         fprintf (stderr, "%s: can't read aux info file `%s': %s\n",
+                  pname, shortpath (NULL, aux_info_filename),
+                  my_strerror(errno));
+         errors++;
+         return;
+       }
+    }
+#if 0 /* There is code farther down to take care of this.  */
+  else
+    {
+      struct stat s1, s2;
+      stat (aux_info_file_name, &s1);
+      stat (base_source_file_name, &s2);
+      if (s2.st_mtime > s1.st_mtime)
+       must_create = 1;
+    }
+#endif /* 0 */
 
-retry:
-    if (my_access (aux_info_filename, R_OK) == -1)
-      {
-        if (errno == ENOENT && retries == 0)
-          {
-            if (is_syscalls)
-              {
-                fprintf (stderr, "%s: warning: missing SYSCALLS file `%s'\n",
-                        pname, aux_info_filename);
-                return;
-              }
-            if (!gen_aux_info_file (base_source_filename))
-              return;
-            retries++;
-            goto retry;
-          }
-        else
-          {
-            fprintf (stderr, "%s: error: can't read aux info file `%s': %s\n",
-                    pname, shortpath (NULL, aux_info_filename),
-                    sys_errlist[errno]);
-            errors++;
-            return;
-          }
-      }
-  }
+  /* If we need a .X file, create it, and verify we can read it.  */
+  if (must_create)
+    {
+      if (!gen_aux_info_file (base_source_filename))
+       {
+         errors++;
+         return;
+       }
+      if (my_access (aux_info_filename, R_OK) == -1)
+       {
+         fprintf (stderr, "%s: can't read aux info file `%s': %s\n",
+                  pname, shortpath (NULL, aux_info_filename),
+                  my_strerror(errno));
+         errors++;
+         return;
+       }
+    }
 
   {
     struct stat stat_buf;
@@ -2076,9 +2253,9 @@ retry:
   
     if (my_stat (aux_info_filename, &stat_buf) == -1)
       {
-        fprintf (stderr, "%s: error: can't get status of aux info file `%s': %s\n",
+        fprintf (stderr, "%s: can't get status of aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         errors++;
         return;
       }
@@ -2094,6 +2271,27 @@ retry:
        contains information about are at least this old or older.  */
   
     aux_info_mtime = stat_buf.st_mtime;
+
+    if (!is_syscalls)
+      {
+       /* Compare mod time with the .c file; update .X file if obsolete.
+          The code later on can fail to check the .c file
+          if it did not directly define any functions.  */
+
+       if (my_stat (base_source_filename, &stat_buf) == -1)
+         {
+           fprintf (stderr, "%s: can't get status of aux info file `%s': %s\n",
+                    pname, shortpath (NULL, base_source_filename),
+                    my_strerror(errno));
+           errors++;
+           return;
+         }
+       if (stat_buf.st_mtime > aux_info_mtime)
+         {
+           must_create = 1;
+           goto start_over;
+         }
+      }
   }
 
   {
@@ -2103,9 +2301,9 @@ retry:
   
     if ((aux_info_file = my_open (aux_info_filename, O_RDONLY, 0444 )) == -1)
       {
-        fprintf (stderr, "%s: error: can't open aux info file `%s' for reading: %s\n",
+        fprintf (stderr, "%s: can't open aux info file `%s' for reading: %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         return;
       }
   
@@ -2117,11 +2315,11 @@ retry:
   
     /* Read the aux_info file into memory.  */
   
-    if (read (aux_info_file, aux_info_base, aux_info_size) != aux_info_size)
+    if (safe_read (aux_info_file, aux_info_base, aux_info_size) != aux_info_size)
       {
-        fprintf (stderr, "%s: error: while reading aux info file `%s': %s\n",
+        fprintf (stderr, "%s: error reading aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2131,9 +2329,9 @@ retry:
   
     if (close (aux_info_file))
       {
-        fprintf (stderr, "%s: error: while closing aux info file `%s': %s\n",
+        fprintf (stderr, "%s: error closing aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2143,11 +2341,11 @@ retry:
   /* Delete the aux_info file (unless requested not to).  If the deletion
      fails for some reason, don't even worry about it.  */
 
-  if (!keep_it)
+  if (must_create && !keep_it)
     if (my_unlink (aux_info_filename) == -1)
-      fprintf (stderr, "%s: error: can't delete aux info file `%s': %s\n",
+      fprintf (stderr, "%s: can't delete aux info file `%s': %s\n",
               pname, shortpath (NULL, aux_info_filename),
-              sys_errlist[errno]);
+              my_strerror(errno));
 
   /* Save a pointer into the first line of the aux_info file which
      contains the filename of the directory from which the compiler
@@ -2172,6 +2370,22 @@ retry:
     while (*p++ != '\n')
       continue;
     aux_info_second_line = p;
+    aux_info_relocated_name = 0;
+    if (invocation_filename[0] != '/')
+      {
+       /* INVOCATION_FILENAME is relative;
+          append it to BASE_SOURCE_FILENAME's dir.  */
+       char *dir_end;
+       aux_info_relocated_name = xmalloc (base_len + (p-invocation_filename));
+       strcpy (aux_info_relocated_name, base_source_filename);
+       dir_end = rindex (aux_info_relocated_name, '/');
+       if (dir_end)
+         dir_end++;
+       else
+         dir_end = aux_info_relocated_name;
+       strcpy (dir_end, invocation_filename);
+       invocation_filename = aux_info_relocated_name;
+      }
   }
 
 
@@ -2192,13 +2406,15 @@ retry:
             if (referenced_file_is_newer (aux_info_p, aux_info_mtime))
               {
                 free (aux_info_base);
-                if (my_unlink (aux_info_filename) == -1)
+               xfree (aux_info_relocated_name);
+                if (keep_it && my_unlink (aux_info_filename) == -1)
                   {
-                    fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
+                    fprintf (stderr, "%s: can't delete file `%s': %s\n",
                             pname, shortpath (NULL, aux_info_filename),
-                            sys_errlist[errno]);
+                            my_strerror(errno));
                     return;
                   }
+               must_create = 1;
                 goto start_over;
               }
     
@@ -2238,6 +2454,7 @@ retry:
   }
 
   free (aux_info_base);
+  xfree (aux_info_relocated_name);
 }
 \f
 #ifndef UNPROTOIZE
@@ -2270,7 +2487,7 @@ rename_c_file (hp)
     {
       fprintf (stderr, "%s: warning: can't link file `%s' to `%s': %s\n",
               pname, shortpath (NULL, filename),
-              shortpath (NULL, new_filename), sys_errlist[errno]);
+              shortpath (NULL, new_filename), my_strerror(errno));
       errors++;
       return;
     }
@@ -2278,13 +2495,13 @@ rename_c_file (hp)
   if (my_unlink (filename) == -1)
     {
       fprintf (stderr, "%s: warning: can't delete file `%s': %s\n",
-              pname, shortpath (NULL, filename), sys_errlist[errno]);
+              pname, shortpath (NULL, filename), my_strerror(errno));
       errors++;
       return;
     }
 }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 \f
 /* Take the list of definitions and declarations attached to a particular
    file_info node and reverse the order of the list.  This should get the
@@ -2299,23 +2516,23 @@ reverse_def_dec_list (hp)
      const hash_table_entry *hp;
 {
   file_info *file_p = hp->fip;
-  const def_dec_info *prev = NULL;
-  const def_dec_info *current = file_p->defs_decs;
+  def_dec_info *prev = NULL;
+  def_dec_info *current = (def_dec_info *)file_p->defs_decs;
 
-  if (!( current = file_p->defs_decs))
+  if (!current)
     return;                    /* no list to reverse */
 
   prev = current;
-  if (! (current = current->next_in_file))
+  if (! (current = (def_dec_info *)current->next_in_file))
     return;                    /* can't reverse a single list element */
 
-  ((NONCONST def_dec_info *) prev)->next_in_file = NULL;
+  prev->next_in_file = NULL;
 
   while (current)
     {
-      const def_dec_info *next = current->next_in_file;
+      def_dec_info *next = (def_dec_info *)current->next_in_file;
 
-      ((NONCONST def_dec_info *) current)->next_in_file = prev;
+      current->next_in_file = prev;
       prev = current;
       current = next;
     }
@@ -2377,7 +2594,7 @@ find_extern_def (head, user)
     if (dd_p->is_func_def && !dd_p->is_static)
       {
         if (!extern_def_p)     /* Previous definition? */
-          extern_def_p = dd_p; /* Remember the first definition found. */
+          extern_def_p = dd_p; /* Remember the first definition found.  */
         else
           {
             /* Ignore definition just found if it came from SYSCALLS.c.X.  */
@@ -2401,7 +2618,7 @@ find_extern_def (head, user)
             if (!conflict_noted)       /* first time we noticed? */
               {
                 conflict_noted = 1;
-                fprintf (stderr, "%s: error: conflicting extern definitions of '%s'\n",
+                fprintf (stderr, "%s: conflicting extern definitions of '%s'\n",
                         pname, head->hash_entry->symbol);
                 if (!quiet_flag)
                   {
@@ -2474,16 +2691,22 @@ find_extern_def (head, user)
                 strcpy (needed, user->ansi_decl);
                 p = (NONCONST char *) substr (needed, user->hash_entry->symbol)
                     + strlen (user->hash_entry->symbol) + 2;
-                strcpy (p, "??\?);");
+               /* Avoid having ??? in the string.  */
+               *p++ = '?';
+               *p++ = '?';
+               *p++ = '?';
+                strcpy (p, ");");
 
                 fprintf (stderr, "%s: %d: `%s' used but missing from SYSCALLS\n",
                         shortpath (NULL, file), user->line,
                         needed+7);     /* Don't print "extern " */
               }
+#if 0
             else
               fprintf (stderr, "%s: %d: warning: no extern definition for `%s'\n",
                       shortpath (NULL, file), user->line,
                       user->hash_entry->symbol);
+#endif
         }
     }
   return extern_def_p;
@@ -2491,7 +2714,7 @@ find_extern_def (head, user)
 \f
 /* Find the (only?) static definition for a particular function name in a
    given file.  Here we get the function-name and the file info indirectly
-   from the def_dec_info record pointer which is passed in. */
+   from the def_dec_info record pointer which is passed in.  */
 
 static const def_dec_info *
 find_static_definition (user)
@@ -2517,7 +2740,7 @@ find_static_definition (user)
     }
   else if (num_static_defs > 1)
     {
-      fprintf (stderr, "%s: error: multiple static defs of `%s' in file `%s'\n",
+      fprintf (stderr, "%s: multiple static defs of `%s' in file `%s'\n",
               pname, head->hash_entry->symbol,
               shortpath (NULL, user->file->hash_entry->symbol));
       return NULL;
@@ -2566,7 +2789,7 @@ connect_defs_and_decs (hp)
      prototypes *should* all match exactly with one another and with the
      prototype for the actual function definition.  We don't check for this
      here however, since we assume that the compiler must have already done
-     this consistancy checking when it was creating the .X files.  */
+     this consistency checking when it was creating the .X files.  */
 
   for (dd_p = hp->ddip; dd_p; dd_p = dd_p->next_for_func)
     if (dd_p->prototyped)
@@ -2634,7 +2857,7 @@ connect_defs_and_decs (hp)
            do not already have definitions.
 
            Note that a trick is used here to prevent subsequent attempts to
-           call find_static_definition() for a given function-name & file
+           call find_static_definition for a given function-name & file
            if the first such call returns NULL.  Essentially, we convert
            these NULL return values to -1, and put the -1 into the definition
            field for each other static declaration from the same file which
@@ -2663,7 +2886,7 @@ connect_defs_and_decs (hp)
       ((NONCONST def_dec_info *) dd_p)->definition = NULL;
 }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
 /* Give a pointer into the clean text buffer, return a number which is the
    original source line number that the given pointer points into.  */
@@ -2746,7 +2969,7 @@ seek_to_line (n)
 }
 
 /* Given a pointer to a character in the cleaned text buffer, return a pointer
-   to the next non-whitepace character which follows it.  */
+   to the next non-whitespace character which follows it.  */
 
 static const char *
 forward_to_next_token_char (ptr)
@@ -2805,7 +3028,7 @@ output_string (str)
    buffer (which may include original comments and preprocessing directives)
    will be copied into the  output buffer.
 
-   Note that the request implide when this routine is called includes the
+   Note that the request implied when this routine is called includes the
    byte pointed to by the argument pointer `p'.  */
 
 static void
@@ -2837,9 +3060,9 @@ other_variable_style_function (ansi_header)
   /* See if we have a stdarg function, or a function which has stdarg style
      parameters or a stdarg style return type.  */
 
-  return (int) substr (ansi_header, "...");
+  return substr (ansi_header, "...") != 0;
 
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
 
   /* See if we have a varargs function, or a function which has varargs style
      parameters or a varargs style return type.  */
@@ -2860,7 +3083,7 @@ other_variable_style_function (ansi_header)
           p = candidate + 1;
     }
   return 0;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 }
 
 /* Do the editing operation specifically for a function "declaration".  Note
@@ -2870,7 +3093,7 @@ other_variable_style_function (ansi_header)
 static void
 edit_fn_declaration (def_dec_p, clean_text_p)
      const def_dec_info *def_dec_p;
-     const char *VOLATILE clean_text_p;
+     const char *volatile clean_text_p;
 {
   const char *start_formals;
   const char *end_formals;
@@ -2904,7 +3127,7 @@ edit_fn_declaration (def_dec_p, clean_text_p)
       return;
     }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* Setup here to recover from confusing source code detected during this
      particular "edit".  */
@@ -2975,7 +3198,7 @@ edit_fn_declaration (def_dec_p, clean_text_p)
          identifier we just found.  We ignore whitespace while hunting.  If
          the next non-whitespace byte we see is *not* an open left paren,
          then we must assume that we have been fooled and we start over
-         again accordingly.  Note that there is no guarrantee, that even if
+         again accordingly.  Note that there is no guarantee, that even if
          we do see the open paren, that we are in the right place.
          Programmers do the strangest things sometimes!  */
     
@@ -2994,7 +3217,7 @@ edit_fn_declaration (def_dec_p, clean_text_p)
 
 #ifndef UNPROTOIZE
   this_f_list_chain_item = definition->f_list_chain;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   for (;;)
     {
@@ -3040,7 +3263,7 @@ edit_fn_declaration (def_dec_p, clean_text_p)
                     pname, def_dec_p->hash_entry->symbol);
           check_source (0, end_formals);  /* leave the declaration intact */
         }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
       clean_read_ptr = end_formals - 1;
 
       /* Now see if it looks like there may be another formals list associated
@@ -3061,7 +3284,7 @@ edit_fn_declaration (def_dec_p, clean_text_p)
                           pname, def_dec_p->hash_entry->symbol);
                 check_source (0, start_formals); /* leave the decl intact */
               }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
             break;
   
           }
@@ -3168,7 +3391,7 @@ edit_formals_lists (end_formals, f_list_count, def_dec_p)
 #ifdef UNPROTOIZE
   if (f_list_count == 0)
     output_string (def_dec_p->formal_names);
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
   {
     unsigned f_list_depth;
     const f_list_chain_item *flci_p = def_dec_p->f_list_chain;
@@ -3181,17 +3404,17 @@ edit_formals_lists (end_formals, f_list_count, def_dec_p)
       flci_p = flci_p->chain_next;
     output_string (flci_p->formals_list);
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   clean_read_ptr = end_formals - 1;
   return 0;
 }
 
-/* Given a pointer to a byte in the clean text buffer which points to the
-   beginning of a line that contains a "follower" token for a function
-   definition header, do whatever is necessary to find the right closing
-   paren for the rightmost formals list of the function definition header.
-*/
+/* Given a pointer to a byte in the clean text buffer which points to
+   the beginning of a line that contains a "follower" token for a
+   function definition header, do whatever is necessary to find the
+   right closing paren for the rightmost formals list of the function
+   definition header.  */
 
 static const char *
 find_rightmost_formals_list (clean_text_p)
@@ -3252,7 +3475,7 @@ find_rightmost_formals_list (clean_text_p)
     check_source (ch == '{', l_brace_p);
   }
 
-#else /* !defined(UNPROTOIZE) */
+#else /* !defined (UNPROTOIZE) */
 
   /* Now scan backwards while looking for the right end of the rightmost
      formals list associated with this function definition.  */
@@ -3282,7 +3505,7 @@ find_rightmost_formals_list (clean_text_p)
          sure that this is in fact the right paren that we were looking for.
 
          The one we were looking for *must* be followed by either a '{' or
-         by an alphabetic character, while others *cannot* legally be followed
+         by an alphabetic character, while others *cannot* validly be followed
          by such characters.  */
 
       if ((ch == '{') || isalpha (ch))
@@ -3295,7 +3518,7 @@ find_rightmost_formals_list (clean_text_p)
       check_source (--end_formals > clean_read_ptr, 0);
     }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   return end_formals;
 }
@@ -3404,7 +3627,7 @@ add_local_decl (def_dec_p, clean_text_p)
       output_string (decl);
     }
 
-    /* Finally, write out a new indent string, just like the preceeding one
+    /* Finally, write out a new indent string, just like the preceding one
        that we found.  This will typically include a newline as the first
        character of the indent string.  */
 
@@ -3459,7 +3682,7 @@ add_global_decls (file_p, clean_text_p)
 
   /* Now scan forward for the first non-whitespace character.  In theory,
      this should be the first character of the following function definition
-     header.  We will put in the added declarations just prior to that. */
+     header.  We will put in the added declarations just prior to that.  */
 
   scan_p++;
   while (isspace (*scan_p))
@@ -3504,7 +3727,7 @@ add_global_decls (file_p, clean_text_p)
       ((NONCONST def_dec_info *) dd_p->definition)->written = 0;
 }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
 /* Do the editing operation specifically for a function "definition".  Note
    that editing operations for function "declarations" are handled by a
@@ -3601,8 +3824,8 @@ edit_fn_definition (def_dec_p, clean_text_p)
     if (!had_newlines)
       output_string ("\n");
   }
-#else /* !defined(UNPROTOIZE) */
-  /* If we are protoizing, there may be some flotsum & jetsum (like comments
+#else /* !defined (UNPROTOIZE) */
+  /* If we are protoizing, there may be some flotsam & jetsam (like comments
      and preprocessing directives) after the old formals list but before
      the following { and we would like to preserve that stuff while effectively
      deleting the existing K&R formal parameter declarations.  We do so here
@@ -3615,7 +3838,7 @@ edit_fn_definition (def_dec_p, clean_text_p)
     const char *start_body_orig;
     const char *scan;
     const char *scan_orig;
-    int have_flotsum = 0;
+    int have_flotsam = 0;
     int have_newlines = 0;
 
     for (start_body = end_formals + 1; *start_body != '{';)
@@ -3635,9 +3858,9 @@ edit_fn_definition (def_dec_p, clean_text_p)
               *((NONCONST char *)scan_orig) = ' '; /* identical - so whiteout */
           }
         else
-          have_flotsum = 1;
+          have_flotsam = 1;
       }
-    if (have_flotsum)
+    if (have_flotsam)
       output_bytes (end_formals_orig + 1,
                    (size_t) (start_body_orig - end_formals_orig) - 1);
     else
@@ -3647,11 +3870,11 @@ edit_fn_definition (def_dec_p, clean_text_p)
         output_string (" ");
     clean_read_ptr = start_body - 1;
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 }
 
 /* Clean up the clean text buffer.  Do this by converting comments and
-   preprocessor directives into spaces.   Also convert line continuations
+   preprocessing directives into spaces.   Also convert line continuations
    into whitespace.  Also, whiteout string and character literals.  */
 
 static void
@@ -3723,7 +3946,9 @@ do_cleaning (new_clean_text_base, new_clean_text_limit)
                 if (++scan_p >= new_clean_text_limit)
                   abort ();
               }
-            *scan_p++ = ' ';
+           if (!isspace (*scan_p))
+             *scan_p = ' ';
+           scan_p++;
             break;
 
           case '\\':                   /* Handle line continuations.  */
@@ -3855,7 +4080,7 @@ scan_for_missed_items (file_p)
                  {
                    char *func_name = (char *) alloca (id_length + 1);
                    static const char * const stmt_keywords[]
-                     = { "if", "while", "for", "switch", "return", 0 };
+                     = { "if", "else", "do", "while", "for", "switch", "case", "return", 0 };
                    const char * const *stmt_keyword;
 
                    strncpy (func_name, id_start, id_length);
@@ -3885,7 +4110,7 @@ scan_for_missed_items (file_p)
                    /* If we make it here, then we did not know about this
                       function definition.  */
 
-                   fprintf (stderr, "%s: %d: warning: `%s' was #if 0\n",
+                   fprintf (stderr, "%s: %d: warning: `%s' excluded by preprocessing\n",
                             shortpath (NULL, file_p->hash_entry->symbol),
                             identify_lineno (id_start), func_name);
                    fprintf (stderr, "%s: function definition not converted\n",
@@ -3901,14 +4126,14 @@ scan_for_missed_items (file_p)
 /* Do all editing operations for a single source file (either a "base" file
    or an "include" file).  To do this we read the file into memory, keep a
    virgin copy there, make another cleaned in-core copy of the original file
-   (i.e. one in which all of the comments and preprocessor directives have
+   (i.e. one in which all of the comments and preprocessing directives have
    been replaced with whitespace), then use these two in-core copies of the
    file to make a new edited in-core copy of the file.  Finally, rename the
    original file (as a way of saving it), and then write the edited version
    of the file from core to a disk file of the same name as the original.
 
    Note that the trick of making a copy of the original sans comments &
-   preprocessor directives make the editing a whole lot easier.  */
+   preprocessing directives make the editing a whole lot easier.  */
    
 static void
 edit_file (hp)
@@ -3942,12 +4167,12 @@ edit_file (hp)
 #ifdef UNPROTOIZE
           /* Don't even mention "system" include files unless we are
              protoizing.  If we are protoizing, we mention these as a
-             gentile way of prodding the user to convert his "system"
+             gentle way of prodding the user to convert his "system"
              include files to prototype format.  */
           && !in_system_include_dir (convert_filename)
-#endif /* defined(UNPROTOIZE) */
+#endif /* defined (UNPROTOIZE) */
           )
-        fprintf (stderr, "%s: file `%s' not converted\n",
+        fprintf (stderr, "%s: `%s' not converted\n",
                 pname, shortpath (NULL, convert_filename));
       return;
     }
@@ -3967,8 +4192,8 @@ edit_file (hp)
   /* The cast avoids an erroneous warning on AIX.  */
   if (my_stat ((char *)convert_filename, &stat_buf) == -1)
     {
-      fprintf (stderr, "%s: error: can't get status for file `%s': %s\n",
-              pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
+      fprintf (stderr, "%s: can't get status for file `%s': %s\n",
+              pname, shortpath (NULL, convert_filename), my_strerror(errno));
       return;
     }
   orig_size = stat_buf.st_size;
@@ -4001,9 +4226,9 @@ edit_file (hp)
 
     if ((input_file = my_open (convert_filename, O_RDONLY, 0444)) == -1)
       {
-        fprintf (stderr, "%s: error: can't open file `%s' for reading: %s\n",
+        fprintf (stderr, "%s: can't open file `%s' for reading: %s\n",
                 pname, shortpath (NULL, convert_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         return;
       }
 
@@ -4011,12 +4236,12 @@ edit_file (hp)
        in one swell fwoop.  Then figure out where the end of the text is and
        make sure that it ends with a newline followed by a null.  */
 
-    if (read (input_file, new_orig_text_base, orig_size) != orig_size)
+    if (safe_read (input_file, new_orig_text_base, orig_size) != orig_size)
       {
         close (input_file);
-        fprintf (stderr, "\n%s: error: while reading input file `%s': %s\n",
+        fprintf (stderr, "\n%s: error reading input file `%s': %s\n",
                 pname, shortpath (NULL, convert_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         return;
       }
 
@@ -4047,17 +4272,15 @@ edit_file (hp)
     strcat (clean_filename, ".clean");
     if ((clean_file = creat (clean_filename, 0666)) == -1)
       {
-        fprintf (stderr, "%s: error: can't create/open clean file `%s': %s\n",
+        fprintf (stderr, "%s: can't create/open clean file `%s': %s\n",
                 pname, shortpath (NULL, clean_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         return;
       }
   
     /* Write the clean file.  */
   
-    if (write (clean_file, new_clean_text_base, clean_size) != clean_size)
-      fprintf (stderr, "%s: error: while writing file `%s': %s\n",
-              pname, shortpath (NULL, clean_filename), sys_errlist[errno]);
+    safe_write (clean_file, new_clean_text_base, clean_size, clean_filename);
   
     close (clean_file);
   }
@@ -4106,7 +4329,7 @@ edit_file (hp)
          || (!def_dec_p->is_func_def && !def_dec_p->definition))
           continue;
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
         if (def_dec_p->is_func_def)
           edit_fn_definition (def_dec_p, clean_text_p);
@@ -4115,7 +4338,7 @@ edit_file (hp)
        if (def_dec_p->is_implicit)
          add_local_decl (def_dec_p, clean_text_p);
        else
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
             edit_fn_declaration (def_dec_p, clean_text_p);
       }
   }
@@ -4139,8 +4362,8 @@ edit_file (hp)
 
   if (!nosave_flag)
     {
-      char *new_filename =
-          (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
+      char *new_filename
+       = (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
   
       strcpy (new_filename, convert_filename);
       strcat (new_filename, save_suffix);
@@ -4156,11 +4379,11 @@ edit_file (hp)
             }
           else
             {
-              fprintf (stderr, "%s: error: can't link file `%s' to `%s': %s\n",
+              fprintf (stderr, "%s: can't link file `%s' to `%s': %s\n",
                       pname,
                       shortpath (NULL, convert_filename),
                       shortpath (NULL, new_filename),
-                      sys_errlist[errno]);
+                      my_strerror(errno));
               return;
             }
         }
@@ -4168,8 +4391,8 @@ edit_file (hp)
 
   if (my_unlink (convert_filename) == -1)
     {
-      fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
-              pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
+      fprintf (stderr, "%s: can't delete file `%s': %s\n",
+              pname, shortpath (NULL, convert_filename), my_strerror(errno));
       return;
     }
 
@@ -4180,9 +4403,9 @@ edit_file (hp)
   
     if ((output_file = creat (convert_filename, 0666)) == -1)
       {
-        fprintf (stderr, "%s: error: can't create/open output file `%s': %s\n",
+        fprintf (stderr, "%s: can't create/open output file `%s': %s\n",
                 pname, shortpath (NULL, convert_filename),
-                sys_errlist[errno]);
+                my_strerror(errno));
         return;
       }
   
@@ -4191,10 +4414,7 @@ edit_file (hp)
     {
       unsigned int out_size = (repl_write_ptr + 1) - repl_text_base;
   
-      if (write (output_file, repl_text_base, out_size) != out_size)
-        fprintf (stderr, "%s: error: while writing file `%s': %s\n",
-                pname, shortpath (NULL, convert_filename),
-                sys_errlist[errno]);
+      safe_write (output_file, repl_text_base, out_size, convert_filename);
     }
   
     close (output_file);
@@ -4210,8 +4430,8 @@ edit_file (hp)
 
   /* The cast avoids an erroneous warning on AIX.  */
   if (my_chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
-    fprintf (stderr, "%s: error: can't change mode of file `%s': %s\n",
-            pname, shortpath (NULL, convert_filename), sys_errlist[errno]);
+    fprintf (stderr, "%s: can't change mode of file `%s': %s\n",
+            pname, shortpath (NULL, convert_filename), my_strerror(errno));
 
   /* Note:  We would try to change the owner and group of the output file
      to match those of the input file here, except that may not be a good
@@ -4232,7 +4452,7 @@ do_processing ()
 
 #ifndef UNPROTOIZE
   int syscalls_len;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* One-by-one, check (and create if necessary), open, and read all of the
      stuff in each aux_info file.  After reading each aux_info file, the
@@ -4251,14 +4471,14 @@ do_processing ()
     {
       syscalls_absolute_filename
         = (char *) xmalloc (strlen (nondefault_syscalls_dir)
-                            + strlen (syscalls_filename) + 2);
+                            + sizeof (syscalls_filename) + 1);
       strcpy (syscalls_absolute_filename, nondefault_syscalls_dir);
     }
   else
     {
       syscalls_absolute_filename
         = (char *) xmalloc (strlen (default_syscalls_dir)
-                            + strlen (syscalls_filename) + 2);
+                            + sizeof (syscalls_filename) + 1);
       strcpy (syscalls_absolute_filename, default_syscalls_dir);
     }
 
@@ -4275,10 +4495,10 @@ do_processing ()
 
   process_aux_info_file (syscalls_absolute_filename, 1, 1);
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* When we first read in all of the information from the aux_info files
-     we saved in it decending line number order, because that was likely to
+     we saved in it descending line number order, because that was likely to
      be faster.  Now however, we want the chains of def & dec records to
      appear in ascending line number order as we get further away from the
      file_info record that they hang from.  The following line causes all of
@@ -4297,7 +4517,7 @@ do_processing ()
 
   visit_each_hash_node (function_name_primary, connect_defs_and_decs);
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* Now convert each file that can be converted (and needs to be).  */
 
@@ -4311,12 +4531,13 @@ do_processing ()
   if (cplusplus_flag && !nochange_flag)
     visit_each_hash_node (filename_primary, rename_c_file);
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 }
 \f
 static struct option longopts[] =
 {
   {"version", 0, 0, 'V'},
+  {"file_name", 0, 0, 'p'},
   {"quiet", 0, 0, 'q'},
   {"silent", 0, 0, 'q'},
   {"force", 0, 0, 'f'},
@@ -4344,23 +4565,17 @@ main (argc, argv)
 {
   int longind;
   int c;
-  int size;
+  const char *params = "";
 
-  pname = strrchr (argv[0], '/');
+  pname = rindex (argv[0], '/');
   pname = pname ? pname+1 : argv[0];
 
-  /* Read the working directory, avoiding arbitrary limit.  */
-  size = GUESSPATHLEN;
-  while (1)
+  cwd_buffer = getpwd ();
+  if (!cwd_buffer)
     {
-      char *value;
-
-      cwd_buffer = (char *) xmalloc (size);
-      value = getcwd (cwd_buffer, size);
-      if (value != 0 || errno != ERANGE)
-       break;
-      free (cwd_buffer);
-      size *= 2;
+      fprintf (stderr, "%s: cannot get working directory: %s\n",
+              pname, my_strerror(errno));
+      exit (FATAL_EXIT_CODE);
     }
 
   /* By default, convert the files in the current directory.  */
@@ -4368,16 +4583,19 @@ main (argc, argv)
 
   while ((c = getopt_long (argc, argv,
 #ifdef UNPROTOIZE
-                          "c:d:i:knNqVx:",
+                          "c:d:i:knNp:qvVx:",
 #else
-                          "B:c:Cd:gklnNqVx:",
+                          "B:c:Cd:gklnNp:qvVx:",
 #endif
                           longopts, &longind)) != EOF)
     {
-      if (c == 0)              /* Long option. */
+      if (c == 0)              /* Long option.  */
        c = longopts[longind].val;
       switch (c)
        {
+       case 'p':
+         compiler_file_name = optarg;
+         break;
        case 'd':
          directory_list
            = string_list_cons (abspath (NULL, optarg), directory_list);
@@ -4386,6 +4604,7 @@ main (argc, argv)
          exclude_list = string_list_cons (optarg, exclude_list);
          break;
            
+       case 'v':
        case 'V':
          version_flag = 1;
          break;
@@ -4408,13 +4627,13 @@ main (argc, argv)
          keep_flag = 1;
          break;
        case 'c':
-         munge_compile_params (optarg);
+         params = optarg;
          break;
 #ifdef UNPROTOIZE
        case 'i':
          indent_string = optarg;
          break;
-#else                          /* !defined(UNPROTOIZE) */
+#else                          /* !defined (UNPROTOIZE) */
        case 'l':
          local_flag = 1;
          break;
@@ -4427,18 +4646,21 @@ main (argc, argv)
        case 'B':
          nondefault_syscalls_dir = optarg;
          break;
-#endif                         /* !defined(UNPROTOIZE) */
+#endif                         /* !defined (UNPROTOIZE) */
        default:
          usage ();
        }
     }
  
+  /* Set up compile_params based on -p and -c options.  */
+  munge_compile_params (params);
+
   n_base_source_files = argc - optind;
 
   /* Now actually make a list of the base source filenames.  */
 
-  base_source_filenames =
-    (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
+  base_source_filenames
+    (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
   n_base_source_files = 0;
   for (; optind < argc; optind++)
     {
@@ -4468,7 +4690,7 @@ main (argc, argv)
       varargs_style_indicator = savestring (varargs_style_indicator,
                                            cp - varargs_style_indicator);
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   if (errors)
     usage ();
@@ -4478,9 +4700,8 @@ main (argc, argv)
         fprintf (stderr, "%s: %s\n", pname, version_string);
       do_processing ();
     }
-  if (errors)
-    exit (1);
-  else
-    exit (0);
+
+  exit (errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+
   return 1;
 }