OSDN Git Service

* mn10300.md (adddi3, subdi3): Remove expanders and patterns.
[pf3gnuchains/gcc-fork.git] / gcc / protoize.c
index 32c87d0..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, 1991 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,77 +15,90 @@ 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
 #endif /* defined(__cplusplus) && !defined(__STDC__) */
 
-#if defined (__cplusplus)
-extern "C" {                   /* Start of extern "C" section.  */
-#endif /* defined(__cplusplus) */
+#if defined(__GNUC__) || defined (__GNUG__)
+#define VOLATILE volatile
+#else
+#define VOLATILE
+#endif
 
-/* It is incorrect to include config.h here, because this file is being
-   compiled for the target, and hence definitions concerning only the host
-   do not apply.  */
+#ifndef __STDC__
+#define const
+#define volatile
+#endif
 
-#include "tm.h"
+#include "config.h"
 
-/* On a POSIX system, request definition of all the POSIX facilities.  */
-/* We use TARGET_POSIX because protoize is compiled for the target system,
-   and TARGET_POSIX is the symbol that describes it in tm.h.  */
-#ifdef TARGET_POSIX
+#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  */ 
+/* If the user asked for POSIX via _POSIX_SOURCE, turn on POSIX code.  */
+#if defined(_POSIX_SOURCE) && !defined(POSIX)
+#define POSIX
+#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>
-#include <sys/wait.h>
+#endif
+#endif
 #include <setjmp.h>
-#include "gvarargs.h"
-#include "getopt.h"
 
-#include <limits.h>
-#ifndef PATH_MAX       /* <limits.h> defines this on most POSIX systems.  */
-#include <sys/param.h>
-#define PATH_MAX MAXPATHLEN
-/* 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
-#endif
+#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 errno
 extern int errno;
-extern char * sys_errlist[];
+#endif
 
-#if defined(TARGET_POSIX)
+#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
 
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
+extern char *version_string;
 
 /* Systems which are compatible only with POSIX 1003.1-1988 (but *not*
    with POSIX 1003.1-1990), e.g. Ultrix 4.2, might not have
@@ -97,123 +107,138 @@ extern char * sys_errlist[];
    calls to the following functions.  To eliminate these warnings we
    provide the following #defines.  */
 
-#if (_POSIX_VERSION < 199009)
+#define my_access(file,flag)   access((char *)file, flag)
+#define my_stat(file,pkt)      stat((char *)file, pkt)
+#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)
+
+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 old brain-dead DEC C
+   compilers which didn't properly grok `void*' types.  */
+
+#ifdef __STDC__
+typedef void * pointer_type;
+typedef const void * const_pointer_type;
+#else
+typedef char * pointer_type;
+typedef char * const_pointer_type;
+#endif
 
-#define access(file,flag)      access((char *)file, flag)
-#define stat(file,pkt)         stat((char *)file, pkt)
-#define execvp(prog,argv)      execvp((char *)prog, (char **)argv)
-#define link(file1, file2)     link((char *)file1, (char *)file2)
-#define unlink(file)           unlink((char *)file)
-#define open(file, mode, flag) open((char *)file, mode, flag)
-#define chmod(file, mode)      chmod((char *)file, mode)
+#if defined(POSIX)
 
-#endif /* (_POSIX_VERSION < 199009) */
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/wait.h>
 
-#else /* !defined(TARGET_POSIX) */
+#else /* !defined(POSIX) */
 
 #define R_OK    4       /* Test for Read permission */
 #define W_OK    2       /* Test for Write permission */
 #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 (char *);
-#define getcwd(buf,len) getwd(buf)
-#else /* (defined (USG) || defined (VMS)) */
-extern char *getcwd (char *, size_t);
-#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, kill or __flsbuf with a prototype
-   causes conflicts with system headers on some systems.
-   Declaring abort causes trouble if it is a macro.  */
+/* Declaring stat or __flsbuf with a prototype
+   causes conflicts with system headers on some systems.  */
 
-extern int creat (const char *, int);
-extern int open (const char *, int, ...);
+#ifndef abort
+typedef void voidfn ();
+extern VOLATILE voidfn abort;
+#endif
+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 void exit (int);
-extern void *malloc (size_t);
-extern void *realloc (void *, size_t);
-extern void free (void *);
-extern int read (int, void *, size_t);
-extern int write (int, const void *, size_t);
-extern int close (int);
-extern int link (const char *, const char *);
-extern int unlink (const char *);
-extern int fflush (FILE *);
-extern int atoi (const char *);
-extern int access (const char *, int);
-extern int puts (const char *);
-extern int fputs (const char *, FILE *);
-extern int fputc (int, FILE *);
-extern int execvp (const char *, char *const *);
-extern int setjmp (jmp_buf);
-extern void longjmp (jmp_buf, int);
-
-extern char *   strcat(char *, const char *);
-extern int      strcmp(const char *, const char *);
-extern char *   strcpy(char *, const char *);
-extern size_t   strlen(const char *);
-extern int      strncmp(const char *, const char *, size_t);
-extern char *   strncpy(char *, const char *, size_t);
-extern char *   strrchr(const char *, int);
+extern int open (const char *, int, ...);
+#endif /* 0 */
+extern void exit ();
+extern void free ();
+extern int read ();
+extern int write ();
+extern int close ();
+extern int fflush ();
+extern int atoi ();
+extern int puts ();
+extern int fputs ();
+extern int fputc ();
+extern int link ();
+extern int unlink ();
+extern int access ();
+
+#if 0 /* size_t from sys/types.h may fail to match GCC.
+        If so, we would get a warning from this.  */
+extern size_t   strlen ()
+#endif
 
+/* Fork is not declared because the declaration caused a conflict
+   on the HPPA.  */
 #if !(defined (USG) || defined (VMS))
-extern int vfork (void);
 #define fork vfork
-#endif /* !(defined (USG) || defined (VMS)) */
+#endif /* (defined (USG) || defined (VMS)) */
 
-#endif /* !defined(TARGET_POSIX) */
+#endif /* !defined (POSIX) */
 
-#if defined (__cplusplus)
-}                              /* End of extern "C" section.  */
-#endif /* defined(__cplusplus) */
+extern char *rindex ();
 
 /* Look for these where the `const' qualifier is intentionally cast aside.  */
 
 #define NONCONST
 
-/* Aliases for pointers to void.
-   These were made to facilitate compilation with other compilers.  */
-
-typedef void * pointer_type;
-typedef const void * const_pointer_type;
-
-/* Define a STRINGIFY macro that's right for ANSI C.  */
+/* Define a STRINGIFY macro that's right for ANSI or traditional C.  */
 
+#ifdef __STDC__
 #define STRINGIFY(STRING) #STRING
-
-/* 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)
+#else
+#define STRINGIFY(STRING) "STRING"
+#endif
 
 /* 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) */
-
-/* String to identify this version.  */
-
-static const char * const version_string = "Version 1.07";
+#endif /* !defined (STD_PROTO_DIR) */
 
 /* Suffix of aux_info files.  */
 
 static const char * const aux_info_suffix = ".X";
 
-/* String to attach to pathnames for saved versions of original files.  */
+/* String to attach to filenames for saved versions of original files.  */
 
 static const char * const save_suffix = ".save";
 
@@ -223,20 +248,20 @@ 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.  */
 
 static const char * const default_syscalls_dir = STD_PROTO_DIR;
 
-/* Variable to hold the complete absolutized pathname of the SYSCALLS.c.X
+/* Variable to hold the complete absolutized filename of the SYSCALLS.c.X
    file.  */
 
-static char * syscalls_pathname;
+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;
@@ -277,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 */
 
@@ -331,15 +366,17 @@ 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";
-static const char * const varargs_style_indicator = STRINGIFY(va_alist);
-#endif /* !defined(UNPROTOIZE) */
+/* 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) */
 
 /* 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
    different classes of strings.  The first type of strings stored in the
-   first hash table are absolute pathnames of files which protoize needs to
+   first hash table are absolute filenames of files which protoize needs to
    know about.  The second type of strings (stored in the second hash table)
    are function names.  It is this second class of strings which really
    inspired the use of the hash tables, because there may be a lot of them.  */
@@ -353,10 +390,10 @@ typedef struct file_info_struct file_info;
 typedef struct f_list_chain_item_struct f_list_chain_item;
 
 /* In the struct below, note that the "_info" field has two different uses
-   depending on the type of hash table we are in (i.e. either the pathnames
-   hash table or the function names hash table).  In the pathnames hash table
+   depending on the type of hash table we are in (i.e. either the filenames
+   hash table or the function names hash table).  In the filenames hash table
    the info fields of the entries point to the file_info struct which is
-   associated with each pathname (1 per pathname).  In the function names
+   associated with each filename (1 per filename).  In the function names
    hash table, the info field points to the head of a singly linked list of
    def_dec_info entries which are all defs or decs of the function whose
    name is pointed to by the "symbol" field.  Keeping all of the defs/decs
@@ -380,7 +417,7 @@ struct hash_table_entry_struct {
 typedef hash_table_entry hash_table[HASH_TABLE_SIZE];
 
 /* The following struct holds all of the important information about any
-   single pathname (e.g. file) which we need to know about.  */
+   single filename (e.g. file) which we need to know about.  */
 
 struct file_info_struct {
   const hash_table_entry *     hash_entry; /* -> to associated hash entry */
@@ -430,16 +467,16 @@ 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 pathname by which this program was
+/* Pointer to the tail component of the filename by which this program was
    invoked.  Used everywhere in error and warning messages.  */
 
 static const char *pname;
@@ -453,38 +490,46 @@ static int errors = 0;
 /* ??? These comments should say what the flag mean as well as the options
    that set them.  */
 
-static int version_flag = 0;           /* set by -V option */
-static int quiet_flag = 0;             /* set by -q option */
-#if 0
-static int force_flag = 0;             /* set by -f option */
-#endif
-static int nochange_flag = 0;          /* set by -n option */
-static int nosave_flag = 0;            /* set by -N option */
-static int keep_flag = 0;              /* set by -k option */
-static const char ** compile_params = 0;       /* set by -c option */
+/* 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
+                                          we would have converted.  */
+static int nosave_flag = 0;            /* Don't save the old version.  */
+static int keep_flag = 0;              /* Don't delete the .X files.  */
+static const char ** compile_params = 0;       /* Option string for gcc.  */
 #ifdef UNPROTOIZE
-static const char *indent_string = "     ";    /* set by -i option */
-#else /* !defined(UNPROTOIZE) */
-static int local_flag = 0;             /* set by -l option */
+static const char *indent_string = "     ";    /* Indentation for newly
+                                                  inserted parm decls.  */
+#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;         /* set by -C option */
-static const char* nondefault_syscalls_dir = 0; /* set by -B option */
-#endif /* !defined(UNPROTOIZE) */
+static int cplusplus_flag = 0;         /* Rename converted files to *.C.  */
+static const char *nondefault_syscalls_dir = 0; /* Dir to look for
+                                                  SYSCALLS.c.X in.  */
+#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 filename_index = 0;
+static int input_file_name_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.  */
 
-static int base_source_files = 0;
+static int n_base_source_files = 0;
 
 /* Points to a malloc'ed list of pointers to all of the filenames of base
    source files which were specified on the command line.  */
 
-static const char **base_source_paths;
+static const char **base_source_filenames;
 
 /* Line number of the line within the current aux_info file that we
    are currently processing.  Used for error messages in case the prototypes
@@ -494,13 +539,13 @@ static int current_aux_info_lineno;
 
 /* Pointer to the name of the source file currently being converted.  */
 
-static const char *convert_path;
+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_path;
+static const char *invocation_filename;
 
 /* Pointer to the base of the input buffer that holds the original text for the
    source file currently being converted.  */
@@ -545,19 +590,19 @@ 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;
 
-/* The pathnames hash table.  */
+/* The filenames hash table.  */
 
-static hash_table pathname_primary;
+static hash_table filename_primary;
 
 /* The function names hash table.  */
 
@@ -568,7 +613,7 @@ static hash_table function_name_primary;
 
 static jmp_buf source_confusion_recovery;
 
-/* A pointer to the current directory pathname (used by abspath).  */
+/* A pointer to the current directory filename (used by abspath).  */
 
 static char *cwd_buffer;
 
@@ -584,20 +629,44 @@ static char * saved_repl_write_ptr;
 
 /* Forward declaration.  */
 
-static const char *shortpath (const char *cwd, const char *pathname);
+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
-xmalloc (size_t byte_count)
+pointer_type
+xmalloc (byte_count)
+     size_t byte_count;
 {
   pointer_type rv;
 
-  if ((rv = malloc (byte_count)) == NULL)
+  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
@@ -606,16 +675,18 @@ xmalloc (size_t byte_count)
 
 /* Reallocate some space, but check that the reallocation was successful.  */
 
-static pointer_type
-xrealloc (pointer_type old_space, size_t byte_count)
+pointer_type
+xrealloc (old_space, byte_count)
+     pointer_type old_space;
+     size_t byte_count;
 {
   pointer_type rv;
 
-  if ((rv = realloc (old_space, byte_count)) == NULL)
+  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
@@ -626,8 +697,9 @@ xrealloc (pointer_type old_space, size_t byte_count)
    the `const' qualifier from it and also make sure that the pointer value
    is non-null.  */
 
-static void
-xfree (const_pointer_type p)
+void
+xfree (p)
+     const_pointer_type p;
 {
   if (p)
     free ((NONCONST pointer_type) p);
@@ -636,13 +708,30 @@ xfree (const_pointer_type p)
 /* Make a copy of a string INPUT with size SIZE.  */
 
 static char *
-savestring (char *input, int size)
+savestring (input, size)
+     const char *input;
+     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.  */
 
@@ -650,40 +739,37 @@ 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 (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.  */
 
 static char *
-dupnstr (const char *s, size_t n)
+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 *
-substr (const char *s1, const char *const s2)
+substr (s1, s2)
+     const char *s1;
+     const char *const s2;
 {
   for (; *s1 ; s1++)
     {
       const char *p1;
       const char *p2;
-      char c;
+      int c;
 
       for (p1 = s1, p2 = s2; c = *p2; p1++, p2++)
         if (*p1 != c)
@@ -695,10 +781,65 @@ 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
-save_pointers (void)
+save_pointers ()
 {
   saved_clean_read_ptr = clean_read_ptr;
   saved_repl_write_ptr = repl_write_ptr;
@@ -708,16 +849,17 @@ save_pointers (void)
    too confusing in the source code we are trying to edit.  */
 
 void
-restore_pointers (void)
+restore_pointers ()
 {
   clean_read_ptr = saved_clean_read_ptr;
   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.  */
 
-inline static int
-is_id_char (char ch)
+static int
+is_id_char (ch)
+     char ch;
 {
   return (isalnum (ch) || (ch == '_') || (ch == '$'));
 }
@@ -726,28 +868,30 @@ is_id_char (char ch)
    exit with non-zero status.  */
 
 static void
-usage (void)
+usage ()
 {
 #ifdef UNPROTOIZE
-  fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ pathname ... ]'\n",
-#else /* !defined(UNPROTOIZE) */
-  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ pathname ... ]'\n",
-#endif /* !defined(UNPROTOIZE) */
-    pname, pname);
-  exit (1);
+  fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",
+          pname, pname);
+#else /* !defined (UNPROTOIZE) */
+  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <dirname> ] [ filename ... ]'\n",
+          pname, pname);
+#endif /* !defined (UNPROTOIZE) */
+  exit (FATAL_EXIT_CODE);
 }
 
-/* Return true if the given pathname (assumed to be an absolute pathname)
+/* Return true if the given filename (assumed to be an absolute filename)
    designates a file residing anywhere beneath any one of the "system"
    include directories.  */
 
 static int
-in_system_include_dir (const char *path)
+in_system_include_dir (path)
+     const char *path;
 {
   struct default_include *p;
 
   if (path[0] != '/')
-    abort ();          /* Must be an absolutized pathname.  */
+    abort ();          /* Must be an absolutized filename.  */
 
   for (p = include_defaults; p->fname; p++)
     if (!strncmp (path, p->fname, strlen (p->fname))
@@ -757,7 +901,7 @@ in_system_include_dir (const char *path)
 }
 \f
 #if 0
-/* Return true if the given pathname designates a file that the user has
+/* Return true if the given filename designates a file that the user has
    read access to and for which the user has write access to the containing
    directory.  */
 
@@ -766,27 +910,27 @@ file_could_be_converted (const char *path)
 {
   char *const dir_name = (char *) alloca (strlen (path) + 1);
 
-  if (access (path, R_OK))
+  if (my_access (path, R_OK))
     return 0;
 
   {
     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
-      abort ();  /* Should have been an absolutized pathname.  */
+      abort ();  /* Should have been an absolutized filename.  */
   }
 
-  if (access (path, W_OK))
+  if (my_access (path, W_OK))
     return 0;
 
   return 1;
 }
 
-/* Return true if the given pathname designates a file that we are allowed
+/* Return true if the given filename designates a file that we are allowed
    to modify.  Files which we should not attempt to modify are (a) "system"
    include files, and (b) files which the user doesn't have write access to,
    and (c) files which reside in directories which the user doesn't have
@@ -796,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);
 
@@ -807,34 +951,34 @@ 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
-      abort ();  /* Should have been an absolutized pathname.  */
+      abort ();  /* Should have been an absolutized filename.  */
   }
 
-  if (access (path, R_OK))
+  if (my_access (path, R_OK))
     {
       if (!quiet_flag)
         fprintf (stderr, "%s: warning: no read access for file `%s'\n",
-          pname, shortpath (NULL, path));
+                pname, shortpath (NULL, path));
       return 0;
     }
 
-  if (access (path, W_OK))
+  if (my_access (path, W_OK))
     {
       if (!quiet_flag)
         fprintf (stderr, "%s: warning: no write access for file `%s'\n",
-          pname, shortpath (NULL, path));
+                pname, shortpath (NULL, path));
       return 0;
     }
 
-  if (access (dir_name, W_OK))
+  if (my_access (dir_name, W_OK))
     {
       if (!quiet_flag)
         fprintf (stderr, "%s: warning: no write access for dir containing `%s'\n",
-          pname, shortpath (NULL, path));
+                pname, shortpath (NULL, path));
       return 0;
     }
 
@@ -848,12 +992,15 @@ file_normally_convertable (const char *path)
    file.  Return false otherwise.  */
 
 static int
-is_syscalls_file (const file_info *fi_p)
+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
@@ -862,10 +1009,11 @@ is_syscalls_file (const file_info *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 (const file_info *file_p)
+needs_to_be_converted (file_p)
+     const file_info *file_p;
 {
   const def_dec_info *ddp;
 
@@ -874,7 +1022,7 @@ needs_to_be_converted (const file_info *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)
 
@@ -882,17 +1030,17 @@ needs_to_be_converted (const file_info *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;
@@ -903,14 +1051,26 @@ needs_to_be_converted (const file_info *file_p)
    that should be converted.  */
 
 static int
-directory_specified_p (const char *name)
+directory_specified_p (name)
+     const char *name;
 {
   struct string_list *p;
 
   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;
 }
@@ -918,7 +1078,8 @@ directory_specified_p (const char *name)
 /* Return 1 if the file named NAME should be excluded from conversion.  */
 
 static int
-file_excluded_p (const char *name)
+file_excluded_p (name)
+     const char *name;
 {
   struct string_list *p;
   int len = strlen (name);
@@ -935,9 +1096,13 @@ file_excluded_p (const char *name)
    STRING is the new element value, and REST holds the remaining elements.  */
 
 static struct string_list *
-string_list_cons (char *string, struct string_list *rest)      
+string_list_cons (string, rest)
+     char *string;
+     struct string_list *rest;
 {
-  struct string_list *temp = xmalloc (sizeof (struct string_list));
+  struct string_list *temp
+    = (struct string_list *) xmalloc (sizeof (struct string_list));
+
   temp->next = rest;
   temp->name = string;
   return temp;
@@ -953,7 +1118,9 @@ string_list_cons (char *string, struct string_list *rest)
    argument.  */
 
 static void
-visit_each_hash_node (const hash_table_entry *hash_tab_p, void (*func) (const hash_table_entry *))
+visit_each_hash_node (hash_tab_p, func)
+     const hash_table_entry *hash_tab_p;
+     void (*func)();
 {
   const hash_table_entry *primary;
 
@@ -974,22 +1141,26 @@ visit_each_hash_node (const hash_table_entry *hash_tab_p, void (*func) (const ha
    called.  */
 
 static hash_table_entry *
-add_symbol (hash_table_entry *p, const char *s)
+add_symbol (p, s)
+     hash_table_entry *p;
+     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;
 }
 
-/* Look for a particular function name or pathname in the particular
+/* Look for a particular function name or filename in the particular
    hash table indicated by "hash_tab_p".  If the name is not in the
    given hash table, add it.  Either way, return a pointer to the
    hash table entry for the given name.  */
 
 static hash_table_entry *
-lookup (hash_table_entry *hash_tab_p, const char *search_symbol)
+lookup (hash_tab_p, search_symbol)
+     hash_table_entry *hash_tab_p;
+     const char *search_symbol;
 {
   int hash_value = 0;
   const char *search_symbol_char_p = search_symbol;
@@ -1019,8 +1190,9 @@ lookup (hash_table_entry *hash_tab_p, const char *search_symbol)
    Also, since we are not using this record anymore, free up all of the
    stuff it pointed to.  */
 
-inline static void
-free_def_dec (def_dec_info *p)
+static void
+free_def_dec (p)
+     def_dec_info *p;
 {
   xfree (p->ansi_decl);
 
@@ -1035,7 +1207,7 @@ free_def_dec (def_dec_info *p)
         xfree (curr);
       }
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   xfree (p);
 }
@@ -1046,11 +1218,12 @@ free_def_dec (def_dec_info *p)
    return a pointer to the unexpanded copy.  Otherwise return NULL.  */
 
 static char *
-unexpand_if_needed (const char *aux_info_line)
+unexpand_if_needed (aux_info_line)
+     const char *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;
@@ -1112,56 +1285,60 @@ 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 pathname for the given relative
-   pathname.  Note that if that pathname is already absolute, it may
+/* Return the absolutized filename for the given relative
+   filename.  Note that if that filename is already absolute, it may
    still be returned in a modified form because this routine also
    eliminates redundant slashes and single dots and eliminates double
-   dots to get a shortest possible pathname from the given input
-   pathname.  The absolutization of relative pathnames is made by
-   assuming that the given pathname is to be taken as relative to
+   dots to get a shortest possible filename from the given input
+   filename.  The absolutization of relative filenames is made by
+   assuming that the given filename is to be taken as relative to
    the first argument (cwd) or to the current directory if cwd is
    NULL.  */
 
 static char *
-abspath (const char *cwd, const char *rel_pathname)
+abspath (cwd, rel_filename)
+     const char *cwd;
+     const char *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_pathname) + 1);
+    = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 2);
   char *endp = abs_buffer;
   char *outp, *inp;
 
-  /* Copy the  pathname (possibly preceeded by the current working
+  /* Copy the  filename (possibly preceded by the current working
      directory name) into the absolutization buffer.  */
 
   {
     const char *src_p;
 
-    if (rel_pathname[0] != '/')
+    if (rel_filename[0] != '/')
       {
         src_p = cwd2;
         while (*endp++ = *src_p++)
           continue;
         *(endp-1) = '/';                       /* overwrite null */
       }
-    src_p = rel_pathname;
+    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
-     pathname (by taking out slashes and dots) as we go.  */
+     filename (by taking out slashes and dots) as we go.  */
 
   outp = inp = abs_buffer;
   *outp++ = *inp++;            /* copy first slash */
+#ifdef apollo
+  if (inp[0] == '/')
+    *outp++ = *inp++;          /* copy second slash */
+#endif
   for (;;)
     {
       if (!inp[0])
@@ -1187,18 +1364,18 @@ abspath (const char *cwd, const char *rel_pathname)
                     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: fatal error: invalid pathname: %s\n",
-                    pname, rel_pathname);
-                 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++;
     }
@@ -1213,41 +1390,44 @@ abspath (const char *cwd, const char *rel_pathname)
   /* 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 pathname (and possibly a directory name from which the pathname
+/* Given a filename (and possibly a directory name from which the filename
    is relative) return a string which is the shortest possible
-   equivalent for the corresponding full (absolutized) pathname.  The
+   equivalent for the corresponding full (absolutized) filename.  The
    shortest possible equivalent may be constructed by converting the
-   absolutized pathname to be a relative pathname (i.e. relative to
-   the actual current working directory).  However if a relative pathname
-   is longer, then the full absolute pathname is returned.
+   absolutized filename to be a relative filename (i.e. relative to
+   the actual current working directory).  However if a relative filename
+   is longer, then the full absolute filename is returned.
 
    KNOWN BUG:
 
-   Note that "simple-minded" conversion of any given type of pathname (either
-   relative or absolute) may not result in a valid equivalent pathname if any
-   subpart of the original pathname is actually a symbolic link.  */
+   Note that "simple-minded" conversion of any given type of filename (either
+   relative or absolute) may not result in a valid equivalent filename if any
+   subpart of the original filename is actually a symbolic link.  */
 
 static const char *
-shortpath (const char *cwd, const char *pathname)
+shortpath (cwd, filename)
+     const char *cwd;
+     const char *filename;
 {
   char *rel_buffer;
   char *rel_buf_p;
   char *cwd_p = cwd_buffer;
   char *path_p;
   int unmatched_slash_count = 0;
+  size_t filename_len = strlen (filename);
 
-  path_p = abspath (cwd, pathname);
-  rel_buf_p = rel_buffer = (char *) xmalloc (strlen (path_p) + 1);
+  path_p = abspath (cwd, filename);
+  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 ".";
@@ -1269,39 +1449,60 @@ shortpath (const char *cwd, const char *pathname)
           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) > strlen (pathname))
-       strcpy (rel_buffer, pathname);
       return rel_buffer;
     }
-  /* NOTREACHED */
-  return 0;    /* Prevent warnings for old versions of GCC.  */
 }
 \f
-/* Lookup the given pathname in the hash table for pathnames.  If it is a
+/* Lookup the given filename in the hash table for filenames.  If it is a
    new one, then the hash table info pointer will be null.  In this case,
-   we create a new file_info record to go with the pathname, and we initialize
+   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 (const char *pathname, int do_not_stat)
+find_file (filename, do_not_stat)
+     char *filename;
+     int do_not_stat;
 {
   hash_table_entry *hash_entry_p;
 
-  hash_entry_p = lookup (pathname_primary, pathname);
+  hash_entry_p = lookup (filename_primary, filename);
   if (hash_entry_p->fip)
     return hash_entry_p->fip;
   else
@@ -1316,10 +1517,10 @@ find_file (const char *pathname, int do_not_stat)
         stat_buf.st_mtime = (time_t) 0;
       else
         {
-          if (stat (pathname, &stat_buf) == -1)
+          if (my_stat (filename, &stat_buf) == -1)
             {
-              fprintf (stderr, "%s: error: can't get status of `%s': %s\n",
-                pname, shortpath (NULL, pathname), 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;
             }
         }
@@ -1336,29 +1537,31 @@ find_file (const char *pathname, int do_not_stat)
    messed up.  */
 
 static void
-aux_info_corrupted (void)
+aux_info_corrupted ()
 {
   fprintf (stderr, "\n%s: fatal error: aux info file corrupted at line %d\n",
-    pname, current_aux_info_lineno);
-  exit (1);
+          pname, current_aux_info_lineno);
+  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.  */
 
-inline static void
-check_aux_info (int cond)
+static void
+check_aux_info (cond)
+     int cond;
 {
   if (! cond)
     aux_info_corrupted ();
 }
 
 /* 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 *
-find_corresponding_lparen (const char *p)
+find_corresponding_lparen (p)
+     const char *p;
 {
   const char *q;
   int paren_depth;
@@ -1384,7 +1587,9 @@ find_corresponding_lparen (const char *p)
    file was created.  If so, return non-zero, else return zero.  */
 
 static int
-referenced_file_is_newer (const char *l, time_t aux_info_mtime)
+referenced_file_is_newer (l, aux_info_mtime)
+     const char *l;
+     time_t aux_info_mtime;
 {
   const char *p;
   file_info *fi_p;
@@ -1409,7 +1614,7 @@ referenced_file_is_newer (const char *l, time_t aux_info_mtime)
      may cause a new file_info record to be created if this is the first time
      that we have ever known about this particular file.  */
 
-  fi_p = find_file (abspath (invocation_path, filename), 0);
+  fi_p = find_file (abspath (invocation_filename, filename), 0);
 
   return (fi_p->mtime > aux_info_mtime);
 }
@@ -1419,7 +1624,7 @@ referenced_file_is_newer (const char *l, time_t 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)
@@ -1430,7 +1635,9 @@ referenced_file_is_newer (const char *l, time_t aux_info_mtime)
    pertaining to this particular function name.  */
 
 static void
-save_def_or_dec (const char *l, int is_syscalls)
+save_def_or_dec (l, is_syscalls)
+     const char *l;
+     int is_syscalls;
 {
   const char *p;
   const char *semicolon_p;
@@ -1438,7 +1645,7 @@ save_def_or_dec (const char *l, int 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,
@@ -1464,16 +1671,16 @@ save_def_or_dec (const char *l, int is_syscalls)
        may cause a new file_info record to be created if this is the first time
        that we have ever known about this particular file.
   
-       Note that we started out by forcing all of the base source file pathnames
+       Note that we started out by forcing all of the base source file names
        (i.e. the names of the aux_info files with the .X stripped off) into the
-       pathnames hash table, and we simultaneously setup file_info records for
-       all of these base file pathnames (even if they may be useless later).
-       The file_info records for all of these "base" file pathnames (properly)
+       filenames hash table, and we simultaneously setup file_info records for
+       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_path, filename), is_syscalls);
+    def_dec_p->file = find_file (abspath (invocation_filename, filename), is_syscalls);
   }
 
   {
@@ -1490,7 +1697,7 @@ save_def_or_dec (const char *l, int 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? */
@@ -1503,7 +1710,7 @@ save_def_or_dec (const char *l, int is_syscalls)
 
   def_dec_p->is_implicit = (*p == 'I');
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   p++;
 
@@ -1517,7 +1724,7 @@ save_def_or_dec (const char *l, int 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++ == '*');
@@ -1526,14 +1733,14 @@ save_def_or_dec (const char *l, int 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;
@@ -1554,28 +1761,35 @@ save_def_or_dec (const char *l, int 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--;
+    p--;
+
+#ifndef UNPROTOIZE
+    def_dec_p->f_list_chain = NULL;
+#endif /* !defined (UNPROTOIZE) */
+
+    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)));
@@ -1585,7 +1799,7 @@ save_def_or_dec (const char *l, int 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;
@@ -1594,7 +1808,7 @@ save_def_or_dec (const char *l, int 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;
@@ -1617,7 +1831,7 @@ save_def_or_dec (const char *l, int is_syscalls)
     /* p now points to the leftmost character of the function name.  */
 
     {
-      char fn_string[past_fn - p + 1];
+      char *fn_string = (char *) alloca (past_fn - p + 1);
 
       strncpy (fn_string, p, (size_t) (past_fn - p));
       fn_string[past_fn-p] = '\0';
@@ -1649,12 +1863,11 @@ save_def_or_dec (const char *l, int 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;
@@ -1690,7 +1903,7 @@ save_def_or_dec (const char *l, int 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;
@@ -1753,7 +1966,7 @@ save_def_or_dec (const char *l, int 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.  */
@@ -1801,18 +2014,25 @@ save_def_or_dec (const char *l, int 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 (const char *params_list)
+munge_compile_params (params_list)
+     const char *params_list;
 {
-  const char *temp_params[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))
@@ -1848,158 +2068,194 @@ munge_compile_params (const char *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 = xmalloc (sizeof (char *) * (param_count+1));
+  compile_params
+    = (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 (const char *base_pathname)
+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_pathname);
+  /* 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]);
+            pname, compile_params[input_file_name_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;
-        }
+  {
+    char *errmsg_fmt, *errmsg_arg;
+    int wait_status, pid;
+    char *temp_base = choose_temp_base ();
 
-#if 0
-      /* Print out the command line that the other process is now executing.  */
-
-      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 (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.
    Save all of the important stuff for later.  */
 
 static void
-process_aux_info_file (const char *base_source_pathname, int keep_it, int is_syscalls)
+process_aux_info_file (base_source_filename, keep_it, is_syscalls)
+     const char *base_source_filename;
+     int keep_it;
+     int is_syscalls;
 {
-  char *const aux_info_pathname
-    = (char *) alloca (strlen (base_source_pathname)
-                      + 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 pathname from the base source pathname.  */
+  /* Construct the aux_info filename from the base source filename.  */
 
-  strcpy (aux_info_pathname, base_source_pathname);
-  strcat (aux_info_pathname, aux_info_suffix);
+  strcpy (aux_info_filename, base_source_filename);
+  strcat (aux_info_filename, aux_info_suffix);
 
   /* 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 (access (aux_info_pathname, R_OK) == -1)
-      {
-        if (errno == ENOENT && retries == 0)
-          {
-            if (is_syscalls)
-              {
-                fprintf (stderr, "%s: warning: missing SYSCALLS file `%s'\n",
-                  pname, aux_info_pathname);
-                return;
-              }
-            if (!gen_aux_info_file (base_source_pathname))
-              return;
-            retries++;
-            goto retry;
-          }
-        else
-          {
-            fprintf (stderr, "%s: error: can't read aux info file `%s': %s\n",
-              pname, shortpath (NULL, aux_info_pathname), 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;
 
     /* Get some status information about this aux_info file.  */
   
-    if (stat (aux_info_pathname, &stat_buf) == -1)
+    if (my_stat (aux_info_filename, &stat_buf) == -1)
       {
-        fprintf (stderr, "%s: error: can't get status of aux info file `%s': %s\n",
-          pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+        fprintf (stderr, "%s: can't get status of aux info file `%s': %s\n",
+                pname, shortpath (NULL, aux_info_filename),
+                my_strerror(errno));
         errors++;
         return;
       }
@@ -2015,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;
+         }
+      }
   }
 
   {
@@ -2022,10 +2299,11 @@ retry:
 
     /* Open the aux_info file.  */
   
-    if ((aux_info_file = open (aux_info_pathname, O_RDONLY, 0444 )) == -1)
+    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",
-          pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+        fprintf (stderr, "%s: can't open aux info file `%s' for reading: %s\n",
+                pname, shortpath (NULL, aux_info_filename),
+                my_strerror(errno));
         return;
       }
   
@@ -2037,10 +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",
-          pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+        fprintf (stderr, "%s: error reading aux info file `%s': %s\n",
+                pname, shortpath (NULL, aux_info_filename),
+                my_strerror(errno));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2050,8 +2329,9 @@ retry:
   
     if (close (aux_info_file))
       {
-        fprintf (stderr, "%s: error: while closing aux info file `%s': %s\n",
-          pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+        fprintf (stderr, "%s: error closing aux info file `%s': %s\n",
+                pname, shortpath (NULL, aux_info_filename),
+                my_strerror(errno));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2061,16 +2341,17 @@ 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 (unlink (aux_info_pathname) == -1)
-      fprintf (stderr, "%s: error: can't delete aux info file `%s': %s\n",
-        pname, shortpath (NULL, aux_info_pathname), sys_errlist[errno]);
+  if (must_create && !keep_it)
+    if (my_unlink (aux_info_filename) == -1)
+      fprintf (stderr, "%s: can't delete aux info file `%s': %s\n",
+              pname, shortpath (NULL, aux_info_filename),
+              my_strerror(errno));
 
   /* Save a pointer into the first line of the aux_info file which
-     contains the pathname of the directory from which the compiler
+     contains the filename of the directory from which the compiler
      was invoked when the associated source file was compiled.
      This information is used later to help create complete
-     pathnames out of the (potentially) relative pathnames in
+     filenames out of the (potentially) relative filenames in
      the aux_info file.  */
 
   {
@@ -2081,7 +2362,7 @@ retry:
     p++;
     while (*p == ' ')
       p++;
-    invocation_path = p;       /* Save a pointer to first byte of path.  */
+    invocation_filename = p;   /* Save a pointer to first byte of path.  */
     while (*p != ' ')
       p++;
     *p++ = '/';
@@ -2089,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;
+      }
   }
 
 
@@ -2109,14 +2406,15 @@ retry:
             if (referenced_file_is_newer (aux_info_p, aux_info_mtime))
               {
                 free (aux_info_base);
-                if (unlink (aux_info_pathname) == -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",
-                      pname,
-                      shortpath (NULL, aux_info_pathname),
-                      sys_errlist[errno]);
+                    fprintf (stderr, "%s: can't delete file `%s': %s\n",
+                            pname, shortpath (NULL, aux_info_filename),
+                            my_strerror(errno));
                     return;
                   }
+               must_create = 1;
                 goto start_over;
               }
     
@@ -2156,6 +2454,7 @@ retry:
   }
 
   free (aux_info_base);
+  xfree (aux_info_relocated_name);
 }
 \f
 #ifndef UNPROTOIZE
@@ -2165,11 +2464,12 @@ retry:
    function implements the -C option.  */
 
 static void
-rename_c_file (const hash_table_entry *hp)
+rename_c_file (hp)
+     const hash_table_entry *hp;
 {
-  const char *pathname = hp->symbol;
-  int last_char_index = strlen (pathname) - 1;
-  char *const new_pathname = (char *) alloca (strlen (pathname) + 1);
+  const char *filename = hp->symbol;
+  int last_char_index = strlen (filename) - 1;
+  char *const new_filename = (char *) alloca (strlen (filename) + 1);
 
   /* Note that we don't care here if the given file was converted or not.  It
      is possible that the given file was *not* converted, simply because there
@@ -2177,31 +2477,31 @@ rename_c_file (const hash_table_entry *hp)
      we want to do the renaming.  Note that we only rename files with the .c
      suffix.  */
 
-  if (pathname[last_char_index] != 'c' || pathname[last_char_index-1] != '.')
+  if (filename[last_char_index] != 'c' || filename[last_char_index-1] != '.')
     return;
 
-  strcpy (new_pathname, pathname);
-  new_pathname[last_char_index] = 'C';
+  strcpy (new_filename, filename);
+  new_filename[last_char_index] = 'C';
 
-  if (link (pathname, new_pathname) == -1)
+  if (my_link (filename, new_filename) == -1)
     {
       fprintf (stderr, "%s: warning: can't link file `%s' to `%s': %s\n",
-        pname, shortpath (NULL, pathname),
-          shortpath (NULL, new_pathname), sys_errlist[errno]);
+              pname, shortpath (NULL, filename),
+              shortpath (NULL, new_filename), my_strerror(errno));
       errors++;
       return;
     }
 
-  if (unlink (pathname) == -1)
+  if (my_unlink (filename) == -1)
     {
       fprintf (stderr, "%s: warning: can't delete file `%s': %s\n",
-        pname, shortpath (NULL, pathname), 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
@@ -2212,26 +2512,27 @@ rename_c_file (const hash_table_entry *hp)
    order here.  */
 
 static void
-reverse_def_dec_list (const hash_table_entry *hp)
+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;
     }
@@ -2253,7 +2554,9 @@ reverse_def_dec_list (const hash_table_entry *hp)
    contains all of the correct prototypes for system functions.  */
 
 static const def_dec_info *
-find_extern_def (const def_dec_info *head, const def_dec_info *user)
+find_extern_def (head, user)
+     const def_dec_info *head;
+     const def_dec_info *user;
 {
   const def_dec_info *dd_p;
   const def_dec_info *extern_def_p = NULL;
@@ -2291,7 +2594,7 @@ find_extern_def (const def_dec_info *head, const def_dec_info *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.  */
@@ -2315,27 +2618,25 @@ find_extern_def (const def_dec_info *head, const def_dec_info *user)
             if (!conflict_noted)       /* first time we noticed? */
               {
                 conflict_noted = 1;
-                fprintf (stderr, "%s: error: conflicting extern definitions of '%s'\n",
-                  pname, head->hash_entry->symbol);
+                fprintf (stderr, "%s: conflicting extern definitions of '%s'\n",
+                        pname, head->hash_entry->symbol);
                 if (!quiet_flag)
                   {
                     fprintf (stderr, "%s: declarations of '%s' will not be converted\n",
-                      pname, head->hash_entry->symbol);
+                            pname, head->hash_entry->symbol);
                     fprintf (stderr, "%s: conflict list for '%s' follows:\n",
-                      pname, head->hash_entry->symbol);
+                            pname, head->hash_entry->symbol);
                     fprintf (stderr, "%s:     %s(%d): %s\n",
-                      pname,
-                      shortpath (NULL, extern_def_p->file->hash_entry->symbol),
-                      extern_def_p->line,
-                      extern_def_p->ansi_decl);
+                            pname,
+                            shortpath (NULL, extern_def_p->file->hash_entry->symbol),
+                            extern_def_p->line, extern_def_p->ansi_decl);
                   }
               }
             if (!quiet_flag)
               fprintf (stderr, "%s:     %s(%d): %s\n",
-                pname,
-                shortpath (NULL, dd_p->file->hash_entry->symbol),
-                dd_p->line,
-                dd_p->ansi_decl);
+                      pname,
+                      shortpath (NULL, dd_p->file->hash_entry->symbol),
+                      dd_p->line, dd_p->ansi_decl);
           }
       }
 
@@ -2357,9 +2658,9 @@ find_extern_def (const def_dec_info *head, const def_dec_info *user)
             extern_def_p = dd_p;       /* save a pointer to the definition */
             if (!quiet_flag)
               fprintf (stderr, "%s: warning: using formals list from %s(%d) for function `%s'\n",
-                pname,
-                shortpath (NULL, dd_p->file->hash_entry->symbol),
-                dd_p->line, dd_p->hash_entry->symbol);
+                      pname,
+                      shortpath (NULL, dd_p->file->hash_entry->symbol),
+                      dd_p->line, dd_p->hash_entry->symbol);
             break;
           }
 
@@ -2384,26 +2685,28 @@ find_extern_def (const def_dec_info *head, const def_dec_info *user)
               {
                /* Why copy this string into `needed' at all?
                   Why not just use user->ansi_decl without copying?  */
-                char needed[strlen (user->ansi_decl) + 1];
+               char *needed = (char *) alloca (strlen (user->ansi_decl) + 1);
                 char *p;
 
                 strcpy (needed, user->ansi_decl);
                 p = (NONCONST char *) substr (needed, user->hash_entry->symbol)
                     + strlen (user->hash_entry->symbol) + 2;
-                strcpy (p, "???);");
-
-                fprintf (stderr, "%s: please add `%s' to SYSCALLS (see %s(%d))\n",
-                  pname,
-                  needed+7,    /* Don't print "extern " */
-                  shortpath (NULL, file),
-                  user->line);
+               /* 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: warning: no extern definition for `%s' (see %s(%d))\n",
-                pname,
-                user->hash_entry->symbol,
-                shortpath (NULL, file),
-                user->line);
+              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;
@@ -2411,10 +2714,11 @@ find_extern_def (const def_dec_info *head, const def_dec_info *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 (const def_dec_info *user)
+find_static_definition (user)
+     const def_dec_info *user;
 {
   const def_dec_info *head = user->hash_entry->ddip;
   const def_dec_info *dd_p;
@@ -2431,16 +2735,14 @@ find_static_definition (const def_dec_info *user)
     {
       if (!quiet_flag)
         fprintf (stderr, "%s: warning: no static definition for `%s' in file `%s'\n",
-          pname,
-          head->hash_entry->symbol,
-          shortpath (NULL, user->file->hash_entry->symbol));
+                pname, head->hash_entry->symbol,
+                shortpath (NULL, user->file->hash_entry->symbol));
     }
   else if (num_static_defs > 1)
     {
-      fprintf (stderr, "%s: error: multiple static defs of `%s' in file `%s'\n",
-        pname,
-        head->hash_entry->symbol,
-        shortpath (NULL, user->file->hash_entry->symbol));
+      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;
     }
   return static_def_p;
@@ -2465,7 +2767,8 @@ find_static_definition (const def_dec_info *user)
    more details.  */
 
 static void
-connect_defs_and_decs (const hash_table_entry *hp)
+connect_defs_and_decs (hp)
+     const hash_table_entry *hp;
 {
   const def_dec_info *dd_p;
   const def_dec_info *extern_def_p = NULL;
@@ -2486,7 +2789,7 @@ connect_defs_and_decs (const hash_table_entry *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)
@@ -2554,7 +2857,7 @@ connect_defs_and_decs (const hash_table_entry *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
@@ -2583,13 +2886,14 @@ connect_defs_and_decs (const hash_table_entry *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.  */
 
 static int
-identify_lineno (const char *clean_p)
+identify_lineno (clean_p)
+     const char *clean_p;
 {
   int line_num = 1;
   const char *scan_p;
@@ -2603,16 +2907,18 @@ identify_lineno (const char *clean_p)
 /* Issue an error message and give up on doing this particular edit.  */
 
 static void
-declare_source_confusing (const char *clean_p)
+declare_source_confusing (clean_p)
+     const char *clean_p;
 {
   if (!quiet_flag)
     {
       if (clean_p == 0)
-        fprintf (stderr, "%s: warning: source too confusing near %s(%d)\n",
-        pname, shortpath (NULL, convert_path), last_known_line_number);
+        fprintf (stderr, "%s: %d: warning: source too confusing\n",
+                shortpath (NULL, convert_filename), last_known_line_number);
       else
-        fprintf (stderr, "%s: warning: source too confusing at %s(%d)\n",
-        pname, shortpath (NULL, convert_path), identify_lineno (clean_p));
+        fprintf (stderr, "%s: %d: warning: source too confusing\n",
+                shortpath (NULL, convert_filename),
+                identify_lineno (clean_p));
     }
   longjmp (source_confusion_recovery, 1);
 }
@@ -2621,8 +2927,10 @@ declare_source_confusing (const char *clean_p)
    code is in fact true.  If not, issue an error message and give up on
    converting this particular source file.  */
 
-inline static void
-check_source (int cond, const char *clean_p)
+static void
+check_source (cond, clean_p)
+     int cond;
+     const char *clean_p;
 {
   if (!cond)
     declare_source_confusing (clean_p);
@@ -2644,7 +2952,8 @@ check_source (int cond, const char *clean_p)
    of the in-core cleaned buffer again.  */
 
 static const char *
-seek_to_line (int n)
+seek_to_line (n)
+     int n;
 {
   if (n < last_known_line_number)
     abort ();
@@ -2660,10 +2969,11 @@ seek_to_line (int 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 (const char *ptr)
+forward_to_next_token_char (ptr)
+     const char *ptr;
 {
   for (++ptr; isspace (*ptr); check_source (++ptr < clean_text_limit, 0))
     continue;
@@ -2675,7 +2985,9 @@ forward_to_next_token_char (const char *ptr)
    buffer ultimately go through here.  */
 
 static void
-output_bytes (const char *str, size_t len)
+output_bytes (str, len)
+     const char *str;
+     size_t len;
 {
   if ((repl_write_ptr + 1) + len >= repl_text_limit)
     {
@@ -2694,7 +3006,8 @@ output_bytes (const char *str, size_t len)
    the current output buffer.  */
 
 static void
-output_string (const char *str)
+output_string (str)
+     const char *str;
 {
   output_bytes (str, strlen (str));
 }
@@ -2715,11 +3028,12 @@ output_string (const char *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
-output_up_to (const char *p)
+output_up_to (p)
+     const char *p;
 {
   size_t copy_length = (size_t) (p - clean_read_ptr);
   const char *copy_start = orig_text_base+(clean_read_ptr-clean_text_base)+1;
@@ -2738,16 +3052,17 @@ output_up_to (const char *p)
    otherwise.  */
 
 static int
-other_variable_style_function (const char *ansi_header)
+other_variable_style_function (ansi_header)
+     const char *ansi_header;
 {
 #ifdef UNPROTOIZE
 
   /* 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.  */
@@ -2768,7 +3083,7 @@ other_variable_style_function (const char *ansi_header)
           p = candidate + 1;
     }
   return 0;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 }
 
 /* Do the editing operation specifically for a function "declaration".  Note
@@ -2776,8 +3091,9 @@ other_variable_style_function (const char *ansi_header)
    below.  */
 
 static void
-edit_fn_declaration (const def_dec_info *def_dec_p,
-                    const char *volatile clean_text_p)
+edit_fn_declaration (def_dec_p, clean_text_p)
+     const def_dec_info *def_dec_p;
+     const char *volatile clean_text_p;
 {
   const char *start_formals;
   const char *end_formals;
@@ -2805,14 +3121,13 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
   if (other_variable_style_function (definition->ansi_decl))
     {
       if (!quiet_flag)
-        fprintf (stderr, "%s: warning: varargs function declaration at %s(%d) not converted\n",
-          pname,
-          shortpath (NULL, def_dec_p->file->hash_entry->symbol),
-          def_dec_p->line);
+        fprintf (stderr, "%s: %d: warning: varargs function declaration not converted\n",
+                shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+                def_dec_p->line);
       return;
     }
 
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   /* Setup here to recover from confusing source code detected during this
      particular "edit".  */
@@ -2822,7 +3137,7 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
     {
       restore_pointers ();
       fprintf (stderr, "%s: declaration of function `%s' not converted\n",
-        pname, function_to_edit);
+              pname, function_to_edit);
       return;
     }
 
@@ -2883,7 +3198,7 @@ edit_fn_declaration (const def_dec_info *def_dec_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!  */
     
@@ -2902,7 +3217,7 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
 
 #ifndef UNPROTOIZE
   this_f_list_chain_item = definition->f_list_chain;
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   for (;;)
     {
@@ -2945,10 +3260,10 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
         {
           if (!quiet_flag)
             fprintf (stderr, "%s: warning: too many parameter lists in declaration of `%s'\n",
-              pname, def_dec_p->hash_entry->symbol);
+                    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
@@ -2966,10 +3281,10 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
               {
                 if (!quiet_flag)
                   fprintf (stderr, "\n%s: warning: too few parameter lists in declaration of `%s'\n",
-                    pname, def_dec_p->hash_entry->symbol);
+                          pname, def_dec_p->hash_entry->symbol);
                 check_source (0, start_formals); /* leave the decl intact */
               }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
             break;
   
           }
@@ -2992,7 +3307,10 @@ edit_fn_declaration (const def_dec_info *def_dec_p,
    function doesn't match the one expected).  */
 
 static int
-edit_formals_lists (const char *end_formals, unsigned f_list_count, const def_dec_info *def_dec_p)
+edit_formals_lists (end_formals, f_list_count, def_dec_p)
+     const char *end_formals;
+     unsigned int f_list_count;
+     const def_dec_info *def_dec_p;
 {
   const char *start_formals;
   int depth;
@@ -3057,14 +3375,13 @@ edit_formals_lists (const char *end_formals, unsigned f_list_count, const def_de
       if (func_name_len == 0)
         check_source (0, func_name_start);
       if (func_name_len != strlen (expected)
-        || strncmp (func_name_start, expected, func_name_len))
+         || strncmp (func_name_start, expected, func_name_len))
         {
-          fprintf (stderr, "%s: warning: found `%s' at %s(%d) but expected `%s'\n",
-            pname,
-            dupnstr (func_name_start, func_name_len),
-            shortpath (NULL, def_dec_p->file->hash_entry->symbol),
-            identify_lineno (func_name_start),
-            expected);
+          fprintf (stderr, "%s: %d: warning: found `%s' but expected `%s'\n",
+                  shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+                  identify_lineno (func_name_start),
+                  dupnstr (func_name_start, func_name_len),
+                  expected);
           return 1;
         }
     }
@@ -3074,7 +3391,7 @@ edit_formals_lists (const char *end_formals, unsigned f_list_count, const def_de
 #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;
@@ -3087,20 +3404,21 @@ edit_formals_lists (const char *end_formals, unsigned f_list_count, const def_de
       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 (const char *clean_text_p)
+find_rightmost_formals_list (clean_text_p)
+     const char *clean_text_p;
 {
   const char *end_formals;
 
@@ -3128,10 +3446,41 @@ find_rightmost_formals_list (const char *clean_text_p)
     continue;
   end_formals--;
 
+#ifdef UNPROTOIZE
+
   /* Now scan backwards while looking for the right end of the rightmost
      formals list associated with this function definition.  */
 
-  for (;;)
+  {
+    char ch;
+    const char *l_brace_p;
+
+    /* Look leftward and try to find a right-paren.  */
+
+    while (*end_formals != ')')
+      {
+       if (isspace (*end_formals))
+         while (isspace (*end_formals))
+           check_source (--end_formals > clean_read_ptr, 0);
+       else
+         check_source (--end_formals > clean_read_ptr, 0);
+      }
+
+    ch = *(l_brace_p = forward_to_next_token_char (end_formals));
+    /* Since we are unprotoizing an ANSI-style (prototyped) function
+       definition, there had better not be anything (except whitespace)
+       between the end of the ANSI formals list and the beginning of the
+       function body (i.e. the '{').  */
+
+    check_source (ch == '{', l_brace_p);
+  }
+
+#else /* !defined (UNPROTOIZE) */
+
+  /* Now scan backwards while looking for the right end of the rightmost
+     formals list associated with this function definition.  */
+
+  while (1)
     {
       char ch;
       const char *l_brace_p;
@@ -3149,18 +3498,6 @@ find_rightmost_formals_list (const char *clean_text_p)
 
       ch = *(l_brace_p = forward_to_next_token_char (end_formals));
 
-#ifdef UNPROTOIZE
-
-      /* Since we are unprotoizing an ANSI-style (prototyped) function
-         definition, there had better not be anything (except whitespace)
-         between the end of the ANSI formals list and the beginning of the
-         function body (i.e. the '{').  */
-
-      check_source (ch == '{', l_brace_p);
-      break;
-
-#else /* !defined(UNPROTOIZE) */
-
       /* Since it is possible that we found a right paren before the starting
          '{' of the body which IS NOT the one at the end of the real K&R
          formals list (say for instance, we found one embedded inside one of
@@ -3168,7 +3505,7 @@ find_rightmost_formals_list (const char *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))
@@ -3179,11 +3516,10 @@ find_rightmost_formals_list (const char *clean_text_p)
          looking.  */
 
       check_source (--end_formals > clean_read_ptr, 0);
-
-#endif /* !defined(UNPROTOIZE) */
-
     }
 
+#endif /* !defined (UNPROTOIZE) */
+
   return end_formals;
 }
 
@@ -3199,7 +3535,9 @@ find_rightmost_formals_list (const char *clean_text_p)
    parameter type checking.  */
 
 static void
-add_local_decl (const def_dec_info *def_dec_p, const char *clean_text_p)
+add_local_decl (def_dec_p, clean_text_p)
+     const def_dec_info *def_dec_p;
+     const char *clean_text_p;
 {
   const char *start_of_block;
   const char *function_to_edit = def_dec_p->hash_entry->symbol;
@@ -3218,7 +3556,7 @@ add_local_decl (const def_dec_info *def_dec_p, const char *clean_text_p)
     {
       restore_pointers ();
       fprintf (stderr, "%s: local declaration for function `%s' not inserted\n",
-        pname, function_to_edit);
+              pname, function_to_edit);
       return;
     }
 
@@ -3245,11 +3583,9 @@ add_local_decl (const def_dec_info *def_dec_p, const char *clean_text_p)
     {
       if (!quiet_flag)
         fprintf (stderr,
-          "\n%s: warning: can't add declaration of `%s' into macro call at %s(%d)\n",
-          pname,
-          def_dec_p->hash_entry->symbol,
-          def_dec_p->file->hash_entry->symbol,
-          def_dec_p->line);
+          "\n%s: %d: warning: can't add declaration of `%s' into macro call\n",
+          def_dec_p->file->hash_entry->symbol, def_dec_p->line, 
+          def_dec_p->hash_entry->symbol);
       return;
     }
 
@@ -3291,7 +3627,7 @@ add_local_decl (const def_dec_info *def_dec_p, const char *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.  */
 
@@ -3307,7 +3643,9 @@ add_local_decl (const def_dec_info *def_dec_p, const char *clean_text_p)
    and then insert the new explicit declaration at that point in the file.  */
 
 static void
-add_global_decls (const file_info *file_p, const char *clean_text_p)
+add_global_decls (file_p, clean_text_p)
+     const file_info *file_p;
+     const char *clean_text_p;
 {
   const def_dec_info *dd_p;
   const char *scan_p;
@@ -3320,7 +3658,7 @@ add_global_decls (const file_info *file_p, const char *clean_text_p)
     {
       restore_pointers ();
       fprintf (stderr, "%s: global declarations for file `%s' not inserted\n",
-        pname, shortpath (NULL, file_p->hash_entry->symbol));
+              pname, shortpath (NULL, file_p->hash_entry->symbol));
       return;
     }
 
@@ -3344,7 +3682,7 @@ add_global_decls (const file_info *file_p, const char *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))
@@ -3389,14 +3727,16 @@ add_global_decls (const file_info *file_p, const char *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
    separate routine above.  */
 
 static void
-edit_fn_definition (const def_dec_info *def_dec_p, const char *clean_text_p)
+edit_fn_definition (def_dec_p, clean_text_p)
+     const def_dec_info *def_dec_p;
+     const char *clean_text_p;
 {
   const char *end_formals;
   const char *function_to_edit = def_dec_p->hash_entry->symbol;
@@ -3409,7 +3749,7 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *clean_text_p)
     {
       restore_pointers ();
       fprintf (stderr, "%s: definition of function `%s' not converted\n",
-        pname, function_to_edit);
+              pname, function_to_edit);
       return;
     }
 
@@ -3427,11 +3767,10 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *clean_text_p)
   if (other_variable_style_function (def_dec_p->ansi_decl))
     {
       if (!quiet_flag)
-        fprintf (stderr, "%s: warning: %s function definition at %s(%d) not converted\n",
-          pname,
-          other_var_style,
-          shortpath (NULL, def_dec_p->file->hash_entry->symbol),
-          identify_lineno (end_formals));
+        fprintf (stderr, "%s: %d: warning: definition of %s not converted\n",
+                shortpath (NULL, def_dec_p->file->hash_entry->symbol),
+                identify_lineno (end_formals), 
+                other_var_style);
       output_up_to (end_formals);
       return;
     }
@@ -3440,7 +3779,7 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *clean_text_p)
     {
       restore_pointers ();
       fprintf (stderr, "%s: definition of function `%s' not converted\n",
-        pname, function_to_edit);
+              pname, function_to_edit);
       return;
     }
 
@@ -3485,8 +3824,8 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *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
@@ -3499,7 +3838,7 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *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 != '{';)
@@ -3519,9 +3858,9 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *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
@@ -3531,15 +3870,17 @@ edit_fn_definition (const def_dec_info *def_dec_p, const char *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
-do_cleaning (char *new_clean_text_base, char *new_clean_text_limit)
+do_cleaning (new_clean_text_base, new_clean_text_limit)
+     char *new_clean_text_base;
+     char *new_clean_text_limit;
 {
   char *scan_p;
   int non_whitespace_since_newline = 0;
@@ -3605,7 +3946,9 @@ do_cleaning (char *new_clean_text_base, char *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.  */
@@ -3639,7 +3982,8 @@ regular:
    and return a pointer to it.  */
 
 static const char *
-careful_find_l_paren (const char *p)
+careful_find_l_paren (p)
+     const char *p;
 {
   const char *q;
   int paren_depth;
@@ -3677,7 +4021,8 @@ careful_find_l_paren (const char *p)
    I will probably try to do this in a later version though.  */
 
 static void
-scan_for_missed_items (const file_info *file_p)
+scan_for_missed_items (file_p)
+     const file_info *file_p;
 {
   static const char *scan_p;
   const char *limit = clean_text_limit - 3;
@@ -3733,9 +4078,9 @@ scan_for_missed_items (const file_info *file_p)
                     goto not_missed;
 
                  {
-                   char func_name[id_length + 1];
+                   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);
@@ -3765,11 +4110,9 @@ scan_for_missed_items (const file_info *file_p)
                    /* If we make it here, then we did not know about this
                       function definition.  */
 
-                   fprintf (stderr, "%s: warning: `%s' at %s(%d) was #if 0\n",
-                            pname,
-                            func_name,
+                   fprintf (stderr, "%s: %d: warning: `%s' excluded by preprocessing\n",
                             shortpath (NULL, file_p->hash_entry->symbol),
-                            identify_lineno (id_start));
+                            identify_lineno (id_start), func_name);
                    fprintf (stderr, "%s: function definition not converted\n",
                             pname);
                  }
@@ -3783,17 +4126,18 @@ scan_for_missed_items (const file_info *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 (const hash_table_entry *hp)
+edit_file (hp)
+     const hash_table_entry *hp;
 {
   struct stat stat_buf;
   const file_info *file_p = hp->fip;
@@ -3811,45 +4155,45 @@ edit_file (const hash_table_entry *hp)
   if (!needs_to_be_converted (file_p))
     return;
 
-  convert_path = file_p->hash_entry->symbol;
+  convert_filename = file_p->hash_entry->symbol;
 
   /* Convert a file if it is in a directory where we want conversion
      and the file is not excluded.  */
 
-  if (!directory_specified_p (convert_path)
-      || file_excluded_p (convert_path))
+  if (!directory_specified_p (convert_filename)
+      || file_excluded_p (convert_filename))
     {
       if (!quiet_flag
 #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_path)
-#endif /* defined(UNPROTOIZE) */
+          && !in_system_include_dir (convert_filename)
+#endif /* defined (UNPROTOIZE) */
           )
-        fprintf (stderr, "%s: file `%s' not converted\n",
-          pname, shortpath (NULL, convert_path));
+        fprintf (stderr, "%s: `%s' not converted\n",
+                pname, shortpath (NULL, convert_filename));
       return;
     }
 
   /* Let the user know what we are up to.  */
 
   if (nochange_flag)
-      puts (shortpath (NULL, convert_path));
+    fprintf (stderr, "%s: would convert file `%s'\n",
+            pname, shortpath (NULL, convert_filename));
   else
-    {
-      fprintf (stderr, "%s: converting file `%s'\n",
-        pname, shortpath (NULL, convert_path));
-      fflush (stderr);
-    }
+    fprintf (stderr, "%s: converting file `%s'\n",
+            pname, shortpath (NULL, convert_filename));
+  fflush (stderr);
 
   /* Find out the size (in bytes) of the original file.  */
 
-  if (stat (convert_path, &stat_buf) == -1)
+  /* 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_path), 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;
@@ -3880,10 +4224,11 @@ edit_file (const hash_table_entry *hp)
 
     /* Open the file to be converted in READ ONLY mode.  */
 
-    if ((input_file = open (convert_path, O_RDONLY, 0444)) == -1)
+    if ((input_file = my_open (convert_filename, O_RDONLY, 0444)) == -1)
       {
-        fprintf (stderr, "%s: error: can't open file `%s' for reading: %s\n",
-          pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+        fprintf (stderr, "%s: can't open file `%s' for reading: %s\n",
+                pname, shortpath (NULL, convert_filename),
+                my_strerror(errno));
         return;
       }
 
@@ -3891,11 +4236,12 @@ edit_file (const hash_table_entry *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",
-          pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+        fprintf (stderr, "\n%s: error reading input file `%s': %s\n",
+                pname, shortpath (NULL, convert_filename),
+                my_strerror(errno));
         return;
       }
 
@@ -3918,26 +4264,23 @@ edit_file (const hash_table_entry *hp)
   {
     int clean_file;
     size_t clean_size = orig_text_limit - orig_text_base;
-    char *const clean_path = (char *) alloca (strlen (convert_path) + 6 + 1);
+    char *const clean_filename = (char *) alloca (strlen (convert_filename) + 6 + 1);
 
     /* Open (and create) the clean file.  */
   
-    strcpy (clean_path, convert_path);
-    strcat (clean_path, ".clean");
-    if ((clean_file = creat (clean_path, 0666)) == -1)
+    strcpy (clean_filename, convert_filename);
+    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",
-          pname,
-          shortpath (NULL, clean_path),
-          sys_errlist[errno]);
+        fprintf (stderr, "%s: can't create/open clean file `%s': %s\n",
+                pname, shortpath (NULL, clean_filename),
+                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_path), sys_errlist[errno]);
+    safe_write (clean_file, new_clean_text_base, clean_size, clean_filename);
   
     close (clean_file);
   }
@@ -3986,7 +4329,7 @@ edit_file (const hash_table_entry *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);
@@ -3995,7 +4338,7 @@ edit_file (const hash_table_entry *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);
       }
   }
@@ -4019,39 +4362,37 @@ edit_file (const hash_table_entry *hp)
 
   if (!nosave_flag)
     {
-      char *new_path =
-          (char *) xmalloc (strlen (convert_path) + strlen (save_suffix) + 2);
+      char *new_filename
+       = (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
   
-      strcpy (new_path, convert_path);
-      strcat (new_path, save_suffix);
-      if (link (convert_path, new_path) == -1)
+      strcpy (new_filename, convert_filename);
+      strcat (new_filename, save_suffix);
+      if (my_link (convert_filename, new_filename) == -1)
         {
           if (errno == EEXIST)
             {
               if (!quiet_flag)
                 fprintf (stderr, "%s: warning: file `%s' already saved in `%s'\n",
-                  pname,
-                  shortpath (NULL, convert_path),
-                  shortpath (NULL, new_path));
+                        pname,
+                        shortpath (NULL, convert_filename),
+                        shortpath (NULL, new_filename));
             }
           else
             {
-              fprintf (stderr, "%s: error: can't link file `%s' to `%s': %s\n",
-                pname,
-                shortpath (NULL, convert_path),
-                shortpath (NULL, new_path),
-                sys_errlist[errno]);
+              fprintf (stderr, "%s: can't link file `%s' to `%s': %s\n",
+                      pname,
+                      shortpath (NULL, convert_filename),
+                      shortpath (NULL, new_filename),
+                      my_strerror(errno));
               return;
             }
         }
     }
 
-  if (unlink (convert_path) == -1)
+  if (my_unlink (convert_filename) == -1)
     {
-      fprintf (stderr, "%s: error: can't delete file `%s': %s\n",
-        pname,
-        shortpath (NULL, convert_path),
-        sys_errlist[errno]);
+      fprintf (stderr, "%s: can't delete file `%s': %s\n",
+              pname, shortpath (NULL, convert_filename), my_strerror(errno));
       return;
     }
 
@@ -4060,12 +4401,11 @@ edit_file (const hash_table_entry *hp)
 
     /* Open (and create) the output file.  */
   
-    if ((output_file = creat (convert_path, 0666)) == -1)
+    if ((output_file = creat (convert_filename, 0666)) == -1)
       {
-        fprintf (stderr, "%s: error: can't create/open output file `%s': %s\n",
-          pname,
-          shortpath (NULL, convert_path),
-          sys_errlist[errno]);
+        fprintf (stderr, "%s: can't create/open output file `%s': %s\n",
+                pname, shortpath (NULL, convert_filename),
+                my_strerror(errno));
         return;
       }
   
@@ -4074,9 +4414,7 @@ edit_file (const hash_table_entry *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_path), sys_errlist[errno]);
+      safe_write (output_file, repl_text_base, out_size, convert_filename);
     }
   
     close (output_file);
@@ -4090,9 +4428,10 @@ edit_file (const hash_table_entry *hp)
 
   /* Change the mode of the output file to match the original file.  */
 
-  if (chmod (convert_path, stat_buf.st_mode) == -1)
-    fprintf (stderr, "%s: error: can't change mode of file `%s': %s\n",
-      pname, shortpath (NULL, convert_path), sys_errlist[errno]);
+  /* The cast avoids an erroneous warning on AIX.  */
+  if (my_chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
+    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
@@ -4105,21 +4444,22 @@ edit_file (const hash_table_entry *hp)
    in the command line.  */
 
 static void
-do_processing (void)
+do_processing ()
 {
   const char * const *base_pp;
-  const char * const * const end_pps = &base_source_paths[base_source_files];
+  const char * const * const end_pps
+    = &base_source_filenames[n_base_source_files];
 
 #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
      aux_info_file just read will be automatically deleted unless the
      keep_flag is set.  */
 
-  for (base_pp = base_source_paths; base_pp < end_pps; base_pp++)
+  for (base_pp = base_source_filenames; base_pp < end_pps; base_pp++)
     process_aux_info_file (*base_pp, keep_flag, 0);
 
 #ifndef UNPROTOIZE
@@ -4129,42 +4469,42 @@ do_processing (void)
 
   if (nondefault_syscalls_dir)
     {
-      syscalls_pathname
+      syscalls_absolute_filename
         = (char *) xmalloc (strlen (nondefault_syscalls_dir)
-                            + strlen (syscalls_filename) + 1);
-      strcpy (syscalls_pathname, nondefault_syscalls_dir);
+                            + sizeof (syscalls_filename) + 1);
+      strcpy (syscalls_absolute_filename, nondefault_syscalls_dir);
     }
   else
     {
-      syscalls_pathname
+      syscalls_absolute_filename
         = (char *) xmalloc (strlen (default_syscalls_dir)
-                            + strlen (syscalls_filename) + 1);
-      strcpy (syscalls_pathname, default_syscalls_dir);
+                            + sizeof (syscalls_filename) + 1);
+      strcpy (syscalls_absolute_filename, default_syscalls_dir);
     }
 
-  syscalls_len = strlen (syscalls_pathname);
-  if (*(syscalls_pathname + syscalls_len - 1) != '/')
+  syscalls_len = strlen (syscalls_absolute_filename);
+  if (*(syscalls_absolute_filename + syscalls_len - 1) != '/')
     {
-      *(syscalls_pathname + syscalls_len++) = '/';
-      *(syscalls_pathname + syscalls_len) = '\0';
+      *(syscalls_absolute_filename + syscalls_len++) = '/';
+      *(syscalls_absolute_filename + syscalls_len) = '\0';
     }
-  strcat (syscalls_pathname, syscalls_filename);
+  strcat (syscalls_absolute_filename, syscalls_filename);
   
   /* Call process_aux_info_file in such a way that it does not try to
      delete the SYSCALLS aux_info file.  */
 
-  process_aux_info_file (syscalls_pathname, 1, 1);
+  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
      these lists to be rearranged into ascending line number order.  */
 
-  visit_each_hash_node (pathname_primary, reverse_def_dec_list);
+  visit_each_hash_node (filename_primary, reverse_def_dec_list);
 
 #ifndef UNPROTOIZE
 
@@ -4177,11 +4517,11 @@ do_processing (void)
 
   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).  */
 
-  visit_each_hash_node (pathname_primary, edit_file);
+  visit_each_hash_node (filename_primary, edit_file);
 
 #ifndef UNPROTOIZE
 
@@ -4189,14 +4529,15 @@ do_processing (void)
      files.  Don't panic if some of the renames don't work.  */
 
   if (cplusplus_flag && !nochange_flag)
-    visit_each_hash_node (pathname_primary, rename_c_file);
+    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'},
@@ -4218,27 +4559,23 @@ static struct option longopts[] =
 };
 
 int
-main (int argc, char **const argv)
+main (argc, argv)
+     int argc;
+     char **const 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 = 100;
-  while (1)
+  cwd_buffer = getpwd ();
+  if (!cwd_buffer)
     {
-      int value;
-
-      cwd_buffer = (char *) xmalloc (size);
-      value = getcwd (cwd_buffer, size);
-      if (value > 0 && value < size)
-       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.  */
@@ -4246,16 +4583,19 @@ main (int argc, char **const 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);
@@ -4264,6 +4604,7 @@ main (int argc, char **const argv)
          exclude_list = string_list_cons (optarg, exclude_list);
          break;
            
+       case 'v':
        case 'V':
          version_flag = 1;
          break;
@@ -4286,13 +4627,13 @@ main (int argc, char **const 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;
@@ -4305,29 +4646,32 @@ main (int argc, char **const argv)
        case 'B':
          nondefault_syscalls_dir = optarg;
          break;
-#endif                         /* !defined(UNPROTOIZE) */
+#endif                         /* !defined (UNPROTOIZE) */
        default:
          usage ();
        }
     }
  
-  base_source_files = argc - optind;
+  /* 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 pathnames.  */
+  /* Now actually make a list of the base source filenames.  */
 
-  base_source_paths =
-    (const char **) xmalloc ((base_source_files + 1) * sizeof (char *));
-  base_source_files = 0;
+  base_source_filenames
+    = (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
+  n_base_source_files = 0;
   for (; optind < argc; optind++)
     {
       const char *path = abspath (NULL, argv[optind]);
       int len = strlen (path);
 
       if (path[len-1] == 'c' && path[len-2] == '.')
-       base_source_paths[base_source_files++] = path;
+       base_source_filenames[n_base_source_files++] = path;
       else
        {
-         fprintf (stderr, "%s: input pathnames must have .c suffixes: %s\n",
+         fprintf (stderr, "%s: input file names must have .c suffixes: %s\n",
                   pname, shortpath (NULL, path));
          errors++;
        }
@@ -4346,7 +4690,7 @@ main (int argc, char **const argv)
       varargs_style_indicator = savestring (varargs_style_indicator,
                                            cp - varargs_style_indicator);
   }
-#endif /* !defined(UNPROTOIZE) */
+#endif /* !defined (UNPROTOIZE) */
 
   if (errors)
     usage ();
@@ -4356,9 +4700,8 @@ main (int argc, char **const 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;
 }