OSDN Git Service

[pf3gnuchains/gcc-fork.git] / gcc / protoize.c
index b577b2a..a7a5ae9 100644 (file)
@@ -1,5 +1,5 @@
 /* Protoize program - Original version by Ron Guilmette (rfg@segfault.us.com).
-   Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1989, 92-97, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -20,7 +20,7 @@ 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
@@ -57,15 +57,9 @@ Boston, MA 02111-1307, USA.  */
 #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 "system.h"
 #include <sys/stat.h>
-#ifndef _WIN32
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
 #if defined(POSIX) || defined(CONCURRENT)
 #include <dirent.h>
 #else
@@ -73,6 +67,19 @@ Boston, MA 02111-1307, USA.  */
 #endif
 #endif
 #include <setjmp.h>
+#include "gansidecl.h"
+
+/* Some systems like Linux don't declare rindex if _POSIX_SOURCE is declared,
+   but it normally does declare it.  This means that configure thinks we don't
+   need to declare it.  Favor using strrchr if it is available.  */
+
+#ifndef strrchr
+#ifndef HAVE_STRRCHR
+#ifdef  HAVE_RINDEX
+#define strrchr rindex
+#endif
+#endif
+#endif
 
 /* Include getopt.h for the sake of getopt_long.
    We don't need the declaration of getopt, and it could conflict
@@ -81,21 +88,6 @@ Boston, MA 02111-1307, USA.  */
 #include "getopt.h"
 #undef getopt
 
-#ifndef errno
-extern int errno;
-#endif
-
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-#if defined(bsd4_4)
-extern const char *const sys_errlist[];
-#else
-extern char *sys_errlist[];
-#endif
-#else
-extern char *strerror();
-#endif
-
 extern char *version_string;
 
 /* Systems which are compatible only with POSIX 1003.1-1988 (but *not*
@@ -107,14 +99,28 @@ extern char *version_string;
 
 #define my_access(file,flag)   access((char *)file, flag)
 #define my_stat(file,pkt)      stat((char *)file, pkt)
-#define my_execvp(prog,argv)   execvp((char *)prog, (char **)argv)
+#ifdef __MINGW32__
+#define my_link(file1, file2)  -1
+#else
 #define my_link(file1, file2)  link((char *)file1, (char *)file2)
+#endif
 #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 char * my_strerror PROTO ((int));
+
+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.  */
@@ -129,27 +135,11 @@ typedef char * const_pointer_type;
 
 #if defined(POSIX)
 
-#include <stdlib.h>
-#include <unistd.h>
 #include <signal.h>
-#include <fcntl.h>
 #include <sys/wait.h>
 
 #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
-#endif
-
-#ifndef O_WRONLY
-#define O_WRONLY        1
-#endif
-
 #ifndef WIFSIGNALED
 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
 #endif
@@ -166,33 +156,22 @@ typedef char * const_pointer_type;
 /* Declaring stat or __flsbuf with a prototype
    causes conflicts with system headers on some systems.  */
 
-#ifndef abort
-typedef void voidfn ();
-extern VOLATILE voidfn abort;
-#endif
-#ifndef _WIN32
-extern int kill ();
-#endif
-extern int creat ();
 #if 0 /* These conflict with stdio.h on some systems.  */
+extern int creat ();
 extern int fprintf (FILE *, const char *, ...);
 extern int printf (const char *, ...);
 extern int open (const char *, int, ...);
-#endif /* 0 */
-extern void exit ();
-extern void free ();
 extern int read ();
 extern int write ();
+#endif /* 0 */
 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 ();
-extern int execvp ();
 
 #if 0 /* size_t from sys/types.h may fail to match GCC.
         If so, we would get a warning from this.  */
@@ -207,20 +186,10 @@ extern size_t   strlen ()
 
 #endif /* !defined (POSIX) */
 
-extern char *rindex ();
-
 /* Look for these where the `const' qualifier is intentionally cast aside.  */
 
 #define NONCONST
 
-/* Define a STRINGIFY macro that's right for ANSI or traditional C.  */
-
-#ifdef __STDC__
-#define STRINGIFY(STRING) #STRING
-#else
-#define STRINGIFY(STRING) "STRING"
-#endif
-
 /* Define a default place to find the SYSCALLS.X file.  */
 
 #ifndef STD_PROTO_DIR
@@ -254,7 +223,7 @@ static char * syscalls_absolute_filename;
 
 #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;
@@ -295,39 +264,41 @@ static const int hash_mask = (HASH_TABLE_SIZE - 1);
 #define LOCAL_INCLUDE_DIR "/usr/local/include"
 #endif
 
-struct default_include { const char *fname; int x1, x2; } include_defaults[]
+struct default_include { const char *fname; 
+                        const char *component;
+                        int x1, x2; } include_defaults[]
 #ifdef INCLUDE_DEFAULTS
   = INCLUDE_DEFAULTS;
 #else
   = {
     /* Pick up GNU C++ specific include files.  */
-    { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
+    { GPLUSPLUS_INCLUDE_DIR, "G++", 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 },
+    { GCC_INCLUDE_DIR, "GCC", 0, 0 },
     /* For cross-compilation, this dir name is generated
        automatically in Makefile.in.  */
-    { CROSS_INCLUDE_DIR, 0, 0 },
+    { CROSS_INCLUDE_DIR, 0, 0, 0 },
     /* This is another place that the target system's headers might be.  */
-    { TOOL_INCLUDE_DIR, 0, 0 },
+    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 0 },
 #else /* not CROSS_COMPILE */
     /* This should be /use/local/include and should come before
        the fixincludes-fixed header files.  */
-    { LOCAL_INCLUDE_DIR, 0, 1 },
+    { LOCAL_INCLUDE_DIR, 0, 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 },
+    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 0 },
     /* This is the dir for fixincludes.  Put it just before
        the files that we fix.  */
-    { GCC_INCLUDE_DIR, 0, 0 },
+    { GCC_INCLUDE_DIR, "GCC", 0, 0 },
     /* Some systems have an extra dir of include files.  */
 #ifdef SYSTEM_INCLUDE_DIR
-    { SYSTEM_INCLUDE_DIR, 0, 0 },
+    { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
 #endif
-    { STANDARD_INCLUDE_DIR, 0, 0},
+    { STANDARD_INCLUDE_DIR, 0, 0, 0},
 #endif /* not CROSS_COMPILE */
-    { 0, 0, 0}
+    { 0, 0, 0, 0}
     };
 #endif /* no INCLUDE_DEFAULTS */
 
@@ -501,7 +472,7 @@ static const char *indent_string = "     "; /* Indentation for newly
 static int local_flag = 0;             /* Insert new local decls (when?).  */
 static int global_flag = 0;            /* set by -g option */
 static int cplusplus_flag = 0;         /* Rename converted files to *.C.  */
-static const charnondefault_syscalls_dir = 0; /* Dir to look for
+static const char *nondefault_syscalls_dir = 0; /* Dir to look for
                                                   SYSCALLS.c.X in.  */
 #endif /* !defined (UNPROTOIZE) */
 
@@ -536,7 +507,7 @@ static const char *convert_filename;
 
 /* Pointer to relative root string (taken from aux_info file) which indicates
    where directory the user was in when he did the compilation step that
-   produced the containing aux_info file. */
+   produced the containing aux_info file.  */
 
 static const char *invocation_filename;
 
@@ -659,7 +630,7 @@ xmalloc (byte_count)
   if (rv == NULL)
     {
       fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);
-      exit (1);
+      exit (FATAL_EXIT_CODE);
       return 0;                /* avoid warnings */
     }
   else
@@ -679,7 +650,7 @@ xrealloc (old_space, byte_count)
   if (rv == NULL)
     {
       fprintf (stderr, "\n%s: virtual memory exceeded\n", pname);
-      exit (1);
+      exit (FATAL_EXIT_CODE);
       return 0;                /* avoid warnings */
     }
   else
@@ -732,7 +703,7 @@ void
 fancy_abort ()
 {
   fprintf (stderr, "%s: internal abort\n", pname);
-  exit (1);
+  exit (FATAL_EXIT_CODE);
 }
 \f
 /* Make a duplicate of the first N bytes of a given string in a newly
@@ -764,7 +735,7 @@ substr (s1, s2)
       const char *p2;
       int c;
 
-      for (p1 = s1, p2 = s2; c = *p2; p1++, p2++)
+      for (p1 = s1, p2 = s2; (c = *p2); p1++, p2++)
         if (*p1 != c)
           goto outer;
       return s1;
@@ -816,12 +787,13 @@ safe_write (desc, ptr, len, out_fname)
     int written = write (desc, ptr, len);
     if (written < 0)
       {
+       int errno_val = errno;
 #ifdef EINTR
-       if (errno == EINTR)
+       if (errno_val == EINTR)
          continue;
 #endif
        fprintf (stderr, "%s: error writing file `%s': %s\n",
-                pname, shortpath (NULL, out_fname), my_strerror(errno));
+                pname, shortpath (NULL, out_fname), my_strerror (errno_val));
        return;
       }
     ptr += written;
@@ -854,7 +826,7 @@ static int
 is_id_char (ch)
      char ch;
 {
-  return (isalnum (ch) || (ch == '_') || (ch == '$'));
+  return (ISALNUM (ch) || (ch == '_') || (ch == '$'));
 }
 
 /* Give a message indicating the proper way to invoke this program and then
@@ -867,10 +839,10 @@ usage ()
   fprintf (stderr, "%s: usage '%s [ -VqfnkN ] [ -i <istring> ] [ filename ... ]'\n",
           pname, pname);
 #else /* !defined (UNPROTOIZE) */
-  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <diname> ] [ filename ... ]'\n",
+  fprintf (stderr, "%s: usage '%s [ -VqfnkNlgC ] [ -B <dirname> ] [ filename ... ]'\n",
           pname, pname);
 #endif /* !defined (UNPROTOIZE) */
-  exit (1);
+  exit (FATAL_EXIT_CODE);
 }
 
 /* Return true if the given filename (assumed to be an absolute filename)
@@ -910,7 +882,7 @@ file_could_be_converted (const char *path)
     char *dir_last_slash;
 
     strcpy (dir_name, path);
-    dir_last_slash = rindex (dir_name, '/');
+    dir_last_slash = strrchr (dir_name, '/');
     if (dir_last_slash)
       *dir_last_slash = '\0';
     else
@@ -944,7 +916,7 @@ file_normally_convertible (const char *path)
     char *dir_last_slash;
 
     strcpy (dir_name, path);
-    dir_last_slash = rindex (dir_name, '/');
+    dir_last_slash = strrchr (dir_name, '/');
     if (dir_last_slash)
       *dir_last_slash = '\0';
     else
@@ -1023,14 +995,14 @@ needs_to_be_converted (file_p)
 
 #ifndef UNPROTOIZE
 
-      /* ... and if we a protoizing and this function is in old style ... */
+      /* ... and if we a protoizing and this function is in old style ...  */
       !ddp->prototyped
-      /* ... and if this a definition or is a decl with an associated def ... */
+      /* ... and if this a definition or is a decl with an associated def ...  */
       && (ddp->is_func_def || (!ddp->is_func_def && ddp->definition))
 
 #else /* defined (UNPROTOIZE) */
 
-      /* ... 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) */
@@ -1216,7 +1188,7 @@ unexpand_if_needed (aux_info_line)
 {
   static char *line_buf = 0;
   static int line_buf_size = 0;
-  const unexpansionunexp_p;
+  const unexpansion *unexp_p;
   int got_unexpanded = 0;
   const char *s;
   char *copy_p = line_buf;
@@ -1314,12 +1286,12 @@ abspath (cwd, rel_filename)
     if (rel_filename[0] != '/')
       {
         src_p = cwd2;
-        while (*endp++ = *src_p++)
+        while ((*endp++ = *src_p++))
           continue;
         *(endp-1) = '/';                       /* overwrite null */
       }
     src_p = rel_filename;
-    while (*endp++ = *src_p++)
+    while ((*endp++ = *src_p++))
       continue;
   }
 
@@ -1357,18 +1329,18 @@ abspath (cwd, rel_filename)
                     while (outp >= abs_buffer && *outp != '/')
                outp--;
                     if (outp < abs_buffer)
-                {
-                  /* Catch cases like /.. where we try to backup to a
-                     point above the absolute root of the logical file
-                     system.  */
-
-                 fprintf (stderr, "%s: invalid file name: %s\n",
-                          pname, rel_filename);
-                 exit (1);
-               }
+                     {
+                       /* Catch cases like /.. where we try to backup to a
+                          point above the absolute root of the logical file
+                          system.  */
+
+                       fprintf (stderr, "%s: invalid file name: %s\n",
+                                pname, rel_filename);
+                       exit (FATAL_EXIT_CODE);
+                     }
                     *++outp = '\0';
                     continue;
-            }
+                 }
         }
       *outp++ = *inp++;
     }
@@ -1471,7 +1443,7 @@ shortpath (cwd, filename)
          if (rel_buffer + filename_len <= rel_buf_p)
            return filename;
        }
-      while (*rel_buf_p++ = *path_p++);
+      while ((*rel_buf_p++ = *path_p++));
 
       --rel_buf_p;
       if (*(rel_buf_p-1) == '/')
@@ -1512,8 +1484,10 @@ find_file (filename, do_not_stat)
         {
           if (my_stat (filename, &stat_buf) == -1)
             {
+             int errno_val = errno;
               fprintf (stderr, "%s: %s: can't get status: %s\n",
-                      pname, shortpath (NULL, filename), my_strerror(errno));
+                      pname, shortpath (NULL, filename),
+                      my_strerror (errno_val));
               stat_buf.st_mtime = (time_t) -1;
             }
         }
@@ -1534,7 +1508,7 @@ aux_info_corrupted ()
 {
   fprintf (stderr, "\n%s: fatal error: aux info file corrupted at line %d\n",
           pname, current_aux_info_lineno);
-  exit (1);
+  exit (FATAL_EXIT_CODE);
 }
 
 /* ??? This comment is vague.  Say what the condition is for.  */
@@ -1690,7 +1664,7 @@ save_def_or_dec (l, is_syscalls)
   /* Check that this record describes a new-style, old-style, or implicit
      definition or declaration.  */
 
-  p++; /* Skip over the `:'. */
+  p++; /* Skip over the `:'.  */
   check_aux_info ((*p == 'N') || (*p == 'O') || (*p == 'I'));
 
   /* Is this a new style (ANSI prototyped) definition or declaration? */
@@ -1781,8 +1755,8 @@ save_def_or_dec (l, is_syscalls)
       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)));
@@ -1860,7 +1834,7 @@ save_def_or_dec (l, is_syscalls)
                         def_dec_p->file->hash_entry->symbol,
                         def_dec_p->line,
                         def_dec_p->hash_entry->symbol);
-                exit (1);
+                exit (FATAL_EXIT_CODE);
               }
             free_def_dec (def_dec_p);
             return;
@@ -1896,7 +1870,7 @@ save_def_or_dec (l, is_syscalls)
       check_aux_info (*++p == '(');
 
       {
-        const char *kr_names_start = ++p;   /* Point just inside '('. */
+        const char *kr_names_start = ++p;   /* Point just inside '('.  */
 
         while (*p++ != ')')
           continue;
@@ -1938,7 +1912,7 @@ save_def_or_dec (l, is_syscalls)
         }
 
       /* Handle a special case.  If we have a function definition marked as
-         being in "old" style, and if it's formal names list is empty, then
+         being in "old" style, and if its formal names list is empty, then
          it may actually have the string "void" in its real formals list
          in the original source code.  Just to make sure, we will get setup
          to convert such things anyway.
@@ -2028,12 +2002,12 @@ munge_compile_params (params_list)
   temp_params[param_count++] = compiler_file_name;
   for (;;)
     {
-      while (isspace (*params_list))
+      while (ISSPACE (*params_list))
         params_list++;
       if (!*params_list)
         break;
       param = params_list;
-      while (*params_list && !isspace (*params_list))
+      while (*params_list && !ISSPACE (*params_list))
         params_list++;
       if (param[0] != '-')
         temp_params[param_count++]
@@ -2048,9 +2022,9 @@ munge_compile_params (params_list)
               case 'c':
                 break;         /* Don't copy these.  */
               case 'o':
-                while (isspace (*params_list))
+                while (ISSPACE (*params_list))
                   params_list++;
-                while (*params_list && !isspace (*params_list))
+                while (*params_list && !ISSPACE (*params_list))
                   params_list++;
                 break;
               default:
@@ -2085,14 +2059,14 @@ munge_compile_params (params_list)
 }
 
 /* Do a recompilation for the express purpose of generating a new aux_info
-   file to go with a specific base source file.  */
+   file to go with a specific base source file.
+
+   The result is a boolean indicating success.  */
 
 static int
 gen_aux_info_file (base_filename)
      const char *base_filename;
 {
-  int child_pid;
-
   if (!input_file_name_index)
     munge_compile_params ("");
 
@@ -2109,79 +2083,48 @@ gen_aux_info_file (base_filename)
     fprintf (stderr, "%s: compiling `%s'\n",
             pname, compile_params[input_file_name_index]);
 
-  if (child_pid = fork ())
-    {
-      if (child_pid == -1)
-        {
-          fprintf (stderr, "%s: could not fork process: %s\n",
-                  pname, my_strerror(errno));
-          return 0;
-        }
-
-#if 0
-      /* Print out the command line that the other process is now executing.  */
+  {
+    char *errmsg_fmt, *errmsg_arg;
+    int wait_status, pid;
+    char *temp_base = choose_temp_base ();
 
-      if (!quiet_flag)
-        {
-          const char **arg;
-  
-          fputs ("\t", stderr);
-          for (arg = compile_params; *arg; arg++)
-            {
-              fputs (*arg, stderr);
-              fputc (' ', stderr);
-            }
-          fputc ('\n', stderr);
-          fflush (stderr);
-        }
-#endif /* 0 */
+    pid = pexecute (compile_params[0], (char * const *) compile_params,
+                   pname, temp_base, &errmsg_fmt, &errmsg_arg,
+                   PEXECUTE_FIRST | PEXECUTE_LAST | PEXECUTE_SEARCH);
 
+    if (pid == -1)
       {
-        int wait_status;
+       int errno_val = errno;
+       fprintf (stderr, "%s: ", pname);
+       fprintf (stderr, errmsg_fmt, errmsg_arg);
+       fprintf (stderr, ": %s\n", my_strerror (errno_val));
+       return 0;
+      }
 
-        if (wait (&wait_status) == -1)
-          {
-            fprintf (stderr, "%s: wait failed: %s\n",
-                    pname, my_strerror(errno));
-            return 0;
-          }
-       if (WIFSIGNALED (wait_status))
-         {
-           fprintf (stderr, "%s: subprocess got fatal signal %d",
-                    pname, WTERMSIG (wait_status));
-           return 0;
-         }
-       if (WIFEXITED (wait_status) && WEXITSTATUS (wait_status) != 0)
+    pid = pwait (pid, &wait_status, 0);
+    if (pid == -1)
+      {
+       fprintf (stderr, "%s: wait: %s\n", pname, my_strerror (errno));
+       return 0;
+      }
+    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, base_filename, WEXITSTATUS (wait_status));
+                    pname, compile_params[0], WEXITSTATUS (wait_status));
            return 0;
          }
        return 1;
       }
-    }
-  else
-    {
-      if (my_execvp (compile_params[0], (char *const *) compile_params))
-        {
-         int e = errno, f = fileno (stderr);
-         write (f, pname, strlen (pname));
-         write (f, ": ", 2);
-         write (f, compile_params[0], strlen (compile_params[0]));
-         write (f, ": ", 2);
-#ifdef HAVE_STRERROR
-         {
-           char *p = strerror(e);
-           write (f, p, strlen (p));
-         }
-#else
-         write (f, sys_errlist[e], strlen (sys_errlist[e]));
-#endif
-         write (f, "\n", 1);
-          _exit (1);
-        }
-      return 1;                /* Never executed.  */
-    }
+    abort ();
+  }
 }
 \f
 /* Read in all of the information contained in a single aux_info file.
@@ -2234,9 +2177,10 @@ start_over: ;
        }
       else
        {
+         int errno_val = errno;
          fprintf (stderr, "%s: can't read aux info file `%s': %s\n",
                   pname, shortpath (NULL, aux_info_filename),
-                  my_strerror(errno));
+                  my_strerror (errno_val));
          errors++;
          return;
        }
@@ -2262,9 +2206,10 @@ start_over: ;
        }
       if (my_access (aux_info_filename, R_OK) == -1)
        {
+         int errno_val = errno;
          fprintf (stderr, "%s: can't read aux info file `%s': %s\n",
                   pname, shortpath (NULL, aux_info_filename),
-                  my_strerror(errno));
+                  my_strerror (errno_val));
          errors++;
          return;
        }
@@ -2277,9 +2222,10 @@ start_over: ;
   
     if (my_stat (aux_info_filename, &stat_buf) == -1)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: can't get status of aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         errors++;
         return;
       }
@@ -2304,9 +2250,10 @@ start_over: ;
 
        if (my_stat (base_source_filename, &stat_buf) == -1)
          {
+           int errno_val = errno;
            fprintf (stderr, "%s: can't get status of aux info file `%s': %s\n",
                     pname, shortpath (NULL, base_source_filename),
-                    my_strerror(errno));
+                    my_strerror (errno_val));
            errors++;
            return;
          }
@@ -2325,9 +2272,10 @@ start_over: ;
   
     if ((aux_info_file = my_open (aux_info_filename, O_RDONLY, 0444 )) == -1)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: can't open aux info file `%s' for reading: %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         return;
       }
   
@@ -2341,9 +2289,10 @@ start_over: ;
   
     if (safe_read (aux_info_file, aux_info_base, aux_info_size) != aux_info_size)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: error reading aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2353,9 +2302,10 @@ start_over: ;
   
     if (close (aux_info_file))
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: error closing aux info file `%s': %s\n",
                 pname, shortpath (NULL, aux_info_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         free (aux_info_base);
         close (aux_info_file);
         return;
@@ -2367,9 +2317,12 @@ start_over: ;
 
   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));
+      {
+       int errno_val = errno;
+       fprintf (stderr, "%s: can't delete aux info file `%s': %s\n",
+                pname, shortpath (NULL, aux_info_filename),
+                my_strerror (errno_val));
+      }
 
   /* Save a pointer into the first line of the aux_info file which
      contains the filename of the directory from which the compiler
@@ -2402,7 +2355,7 @@ start_over: ;
        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, '/');
+       dir_end = strrchr (aux_info_relocated_name, '/');
        if (dir_end)
          dir_end++;
        else
@@ -2433,9 +2386,10 @@ start_over: ;
                xfree (aux_info_relocated_name);
                 if (keep_it && my_unlink (aux_info_filename) == -1)
                   {
+                   int errno_val = errno;
                     fprintf (stderr, "%s: can't delete file `%s': %s\n",
                             pname, shortpath (NULL, aux_info_filename),
-                            my_strerror(errno));
+                            my_strerror (errno_val));
                     return;
                   }
                must_create = 1;
@@ -2509,17 +2463,19 @@ rename_c_file (hp)
 
   if (my_link (filename, new_filename) == -1)
     {
+      int errno_val = errno;
       fprintf (stderr, "%s: warning: can't link file `%s' to `%s': %s\n",
               pname, shortpath (NULL, filename),
-              shortpath (NULL, new_filename), my_strerror(errno));
+              shortpath (NULL, new_filename), my_strerror (errno_val));
       errors++;
       return;
     }
 
   if (my_unlink (filename) == -1)
     {
+      int errno_val = errno;
       fprintf (stderr, "%s: warning: can't delete file `%s': %s\n",
-              pname, shortpath (NULL, filename), my_strerror(errno));
+              pname, shortpath (NULL, filename), my_strerror (errno_val));
       errors++;
       return;
     }
@@ -2541,20 +2497,20 @@ reverse_def_dec_list (hp)
 {
   file_info *file_p = hp->fip;
   def_dec_info *prev = NULL;
-  def_dec_info *current = file_p->defs_decs;
+  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 */
 
   prev->next_in_file = NULL;
 
   while (current)
     {
-      def_dec_info *next = current->next_in_file;
+      def_dec_info *next = (def_dec_info *)current->next_in_file;
 
       current->next_in_file = prev;
       prev = current;
@@ -2618,7 +2574,7 @@ find_extern_def (head, user)
     if (dd_p->is_func_def && !dd_p->is_static)
       {
         if (!extern_def_p)     /* Previous definition? */
-          extern_def_p = dd_p; /* Remember the first definition found. */
+          extern_def_p = dd_p; /* Remember the first definition found.  */
         else
           {
             /* Ignore definition just found if it came from SYSCALLS.c.X.  */
@@ -2738,7 +2694,7 @@ find_extern_def (head, user)
 \f
 /* Find the (only?) static definition for a particular function name in a
    given file.  Here we get the function-name and the file info indirectly
-   from the def_dec_info record pointer which is passed in. */
+   from the def_dec_info record pointer which is passed in.  */
 
 static const def_dec_info *
 find_static_definition (user)
@@ -2806,7 +2762,7 @@ connect_defs_and_decs (hp)
 
      Also, for each item which is only a function declaration, but which
      nonetheless has its own prototype already (obviously supplied by the user)
-     declare the item as it's own definition.
+     declare the item as its own definition.
 
      Note that when/if there are multiple user-supplied prototypes already
      present for multiple declarations of any given function, these multiple
@@ -2999,7 +2955,7 @@ static const char *
 forward_to_next_token_char (ptr)
      const char *ptr;
 {
-  for (++ptr; isspace (*ptr); check_source (++ptr < clean_text_limit, 0))
+  for (++ptr; ISSPACE (*ptr); check_source (++ptr < clean_text_limit, 0))
     continue;
   return ptr;
 }
@@ -3367,7 +3323,7 @@ edit_formals_lists (end_formals, f_list_count, def_dec_p)
 
       next_end = start_formals - 1;
       check_source (next_end > clean_read_ptr, 0);
-      while (isspace (*next_end))
+      while (ISSPACE (*next_end))
         check_source (--next_end > clean_read_ptr, 0);
       check_source (*next_end == ')', next_end);
       check_source (--next_end > clean_read_ptr, 0);
@@ -3387,7 +3343,7 @@ edit_formals_lists (end_formals, f_list_count, def_dec_p)
       const char *func_name_limit;
       size_t func_name_len;
 
-      for (func_name_limit = start_formals-1; isspace (*func_name_limit); )
+      for (func_name_limit = start_formals-1; ISSPACE (*func_name_limit); )
         check_source (--func_name_limit > clean_read_ptr, 0);
 
       for (func_name_start = func_name_limit++;
@@ -3434,11 +3390,11 @@ edit_formals_lists (end_formals, f_list_count, def_dec_p)
   return 0;
 }
 
-/* Given a pointer to a byte in the clean text buffer which points to the
-   beginning of a line that contains a "follower" token for a function
-   definition header, do whatever is necessary to find the right closing
-   paren for the rightmost formals list of the function definition header.
-*/
+/* Given a pointer to a byte in the clean text buffer which points to
+   the beginning of a line that contains a "follower" token for a
+   function definition header, do whatever is necessary to find the
+   right closing paren for the rightmost formals list of the function
+   definition header.  */
 
 static const char *
 find_rightmost_formals_list (clean_text_p)
@@ -3483,8 +3439,8 @@ find_rightmost_formals_list (clean_text_p)
 
     while (*end_formals != ')')
       {
-       if (isspace (*end_formals))
-         while (isspace (*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);
@@ -3513,8 +3469,8 @@ find_rightmost_formals_list (clean_text_p)
 
       while (*end_formals != ')')
         {
-          if (isspace (*end_formals))
-            while (isspace (*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);
@@ -3532,7 +3488,7 @@ find_rightmost_formals_list (clean_text_p)
          by an alphabetic character, while others *cannot* validly be followed
          by such characters.  */
 
-      if ((ch == '{') || isalpha (ch))
+      if ((ch == '{') || ISALPHA (ch))
         break;
 
       /* At this point, we have found a right paren, but we know that it is
@@ -3628,7 +3584,7 @@ add_local_decl (def_dec_p, clean_text_p)
        We can now just scan backwards and find the left end of the existing
        indentation string, and then copy it to the output buffer.  */
 
-    for (sp = ep; isspace (*sp) && *sp != '\n'; sp--)
+    for (sp = ep; ISSPACE (*sp) && *sp != '\n'; sp--)
       continue;
 
     /* Now write out the open { which began this block, and any following
@@ -3706,10 +3662,10 @@ add_global_decls (file_p, clean_text_p)
 
   /* Now scan forward for the first non-whitespace character.  In theory,
      this should be the first character of the following function definition
-     header.  We will put in the added declarations just prior to that. */
+     header.  We will put in the added declarations just prior to that.  */
 
   scan_p++;
-  while (isspace (*scan_p))
+  while (ISSPACE (*scan_p))
     scan_p++;
   scan_p--;
 
@@ -3878,7 +3834,7 @@ edit_fn_definition (def_dec_p, clean_text_p)
           {
             have_newlines |= (*scan_orig == '\n');
             /* Leave identical whitespace alone.  */
-            if (!isspace (*scan_orig))
+            if (!ISSPACE (*scan_orig))
               *((NONCONST char *)scan_orig) = ' '; /* identical - so whiteout */
           }
         else
@@ -3922,7 +3878,7 @@ do_cleaning (new_clean_text_base, new_clean_text_limit)
             scan_p += 2;
             while (scan_p[1] != '/' || scan_p[0] != '*')
               {
-                if (!isspace (*scan_p))
+                if (!ISSPACE (*scan_p))
                   *scan_p = ' ';
                 if (++scan_p >= new_clean_text_limit)
                   abort ();
@@ -3937,7 +3893,7 @@ do_cleaning (new_clean_text_base, new_clean_text_limit)
             *scan_p = ' ';
             while (scan_p[1] != '\n' || scan_p[0] == '\\')
               {
-                if (!isspace (*scan_p))
+                if (!ISSPACE (*scan_p))
                   *scan_p = ' ';
                 if (++scan_p >= new_clean_text_limit)
                   abort ();
@@ -3949,9 +3905,9 @@ do_cleaning (new_clean_text_base, new_clean_text_limit)
             non_whitespace_since_newline = 1;
             while (scan_p[1] != '\'' || scan_p[0] == '\\')
               {
-                if (scan_p[0] == '\\' && !isspace (scan_p[1]))
+                if (scan_p[0] == '\\' && !ISSPACE (scan_p[1]))
                   scan_p[1] = ' ';
-                if (!isspace (*scan_p))
+                if (!ISSPACE (*scan_p))
                   *scan_p = ' ';
                 if (++scan_p >= new_clean_text_limit)
                   abort ();
@@ -3963,14 +3919,14 @@ do_cleaning (new_clean_text_base, new_clean_text_limit)
             non_whitespace_since_newline = 1;
             while (scan_p[1] != '"' || scan_p[0] == '\\')
               {
-                if (scan_p[0] == '\\' && !isspace (scan_p[1]))
+                if (scan_p[0] == '\\' && !ISSPACE (scan_p[1]))
                   scan_p[1] = ' ';
-                if (!isspace (*scan_p))
+                if (!ISSPACE (*scan_p))
                   *scan_p = ' ';
                 if (++scan_p >= new_clean_text_limit)
                   abort ();
               }
-           if (!isspace (*scan_p))
+           if (!ISSPACE (*scan_p))
              *scan_p = ' ';
            scan_p++;
             break;
@@ -4063,12 +4019,12 @@ scan_for_missed_items (file_p)
 
           last_r_paren = scan_p;
 
-          for (ahead_p = scan_p + 1; isspace (*ahead_p); )
+          for (ahead_p = scan_p + 1; ISSPACE (*ahead_p); )
             check_source (++ahead_p < limit, limit);
 
           scan_p = ahead_p - 1;
 
-          if (isalpha (*ahead_p) || *ahead_p == '{')
+          if (ISALPHA (*ahead_p) || *ahead_p == '{')
             {
               const char *last_l_paren;
               const int lineno = identify_lineno (ahead_p);
@@ -4082,7 +4038,7 @@ scan_for_missed_items (file_p)
               do
                 {
                   last_l_paren = careful_find_l_paren (last_r_paren);
-                  for (last_r_paren = last_l_paren-1; isspace (*last_r_paren); )
+                  for (last_r_paren = last_l_paren-1; ISSPACE (*last_r_paren); )
                     check_source (--last_r_paren >= backup_limit, backup_limit);
                 }
               while (*last_r_paren == ')');
@@ -4216,8 +4172,10 @@ edit_file (hp)
   /* The cast avoids an erroneous warning on AIX.  */
   if (my_stat ((char *)convert_filename, &stat_buf) == -1)
     {
+      int errno_val = errno;
       fprintf (stderr, "%s: can't get status for file `%s': %s\n",
-              pname, shortpath (NULL, convert_filename), my_strerror(errno));
+              pname, shortpath (NULL, convert_filename),
+              my_strerror (errno_val));
       return;
     }
   orig_size = stat_buf.st_size;
@@ -4250,9 +4208,10 @@ edit_file (hp)
 
     if ((input_file = my_open (convert_filename, O_RDONLY, 0444)) == -1)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: can't open file `%s' for reading: %s\n",
                 pname, shortpath (NULL, convert_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         return;
       }
 
@@ -4262,10 +4221,11 @@ edit_file (hp)
 
     if (safe_read (input_file, new_orig_text_base, orig_size) != orig_size)
       {
+       int errno_val = errno;
         close (input_file);
         fprintf (stderr, "\n%s: error reading input file `%s': %s\n",
                 pname, shortpath (NULL, convert_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         return;
       }
 
@@ -4296,9 +4256,10 @@ edit_file (hp)
     strcat (clean_filename, ".clean");
     if ((clean_file = creat (clean_filename, 0666)) == -1)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: can't create/open clean file `%s': %s\n",
                 pname, shortpath (NULL, clean_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         return;
       }
   
@@ -4386,14 +4347,15 @@ edit_file (hp)
 
   if (!nosave_flag)
     {
-      char *new_filename =
-          (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
+      char *new_filename
+       = (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
   
       strcpy (new_filename, convert_filename);
       strcat (new_filename, save_suffix);
       if (my_link (convert_filename, new_filename) == -1)
         {
-          if (errno == EEXIST)
+         int errno_val = errno;
+         if (errno_val == EEXIST)
             {
               if (!quiet_flag)
                 fprintf (stderr, "%s: warning: file `%s' already saved in `%s'\n",
@@ -4407,7 +4369,7 @@ edit_file (hp)
                       pname,
                       shortpath (NULL, convert_filename),
                       shortpath (NULL, new_filename),
-                      my_strerror(errno));
+                      my_strerror (errno_val));
               return;
             }
         }
@@ -4415,8 +4377,10 @@ edit_file (hp)
 
   if (my_unlink (convert_filename) == -1)
     {
+      int errno_val = errno;
       fprintf (stderr, "%s: can't delete file `%s': %s\n",
-              pname, shortpath (NULL, convert_filename), my_strerror(errno));
+              pname, shortpath (NULL, convert_filename),
+              my_strerror (errno_val));
       return;
     }
 
@@ -4427,9 +4391,10 @@ edit_file (hp)
   
     if ((output_file = creat (convert_filename, 0666)) == -1)
       {
+       int errno_val = errno;
         fprintf (stderr, "%s: can't create/open output file `%s': %s\n",
                 pname, shortpath (NULL, convert_filename),
-                my_strerror(errno));
+                my_strerror (errno_val));
         return;
       }
   
@@ -4454,8 +4419,12 @@ edit_file (hp)
 
   /* The cast avoids an erroneous warning on AIX.  */
   if (my_chmod ((char *)convert_filename, stat_buf.st_mode) == -1)
-    fprintf (stderr, "%s: can't change mode of file `%s': %s\n",
-            pname, shortpath (NULL, convert_filename), my_strerror(errno));
+    {
+      int errno_val = errno;
+      fprintf (stderr, "%s: can't change mode of file `%s': %s\n",
+              pname, shortpath (NULL, convert_filename),
+              my_strerror (errno_val));
+    }
 
   /* 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
@@ -4591,7 +4560,7 @@ main (argc, argv)
   int c;
   const char *params = "";
 
-  pname = rindex (argv[0], '/');
+  pname = strrchr (argv[0], '/');
   pname = pname ? pname+1 : argv[0];
 
   cwd_buffer = getpwd ();
@@ -4599,7 +4568,7 @@ main (argc, argv)
     {
       fprintf (stderr, "%s: cannot get working directory: %s\n",
               pname, my_strerror(errno));
-      exit (1);
+      exit (FATAL_EXIT_CODE);
     }
 
   /* By default, convert the files in the current directory.  */
@@ -4613,7 +4582,7 @@ main (argc, argv)
 #endif
                           longopts, &longind)) != EOF)
     {
-      if (c == 0)              /* Long option. */
+      if (c == 0)              /* Long option.  */
        c = longopts[longind].val;
       switch (c)
        {
@@ -4683,8 +4652,8 @@ main (argc, argv)
 
   /* Now actually make a list of the base source filenames.  */
 
-  base_source_filenames =
-    (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
+  base_source_filenames
+    (const char **) xmalloc ((n_base_source_files + 1) * sizeof (char *));
   n_base_source_files = 0;
   for (; optind < argc; optind++)
     {
@@ -4708,7 +4677,7 @@ main (argc, argv)
   {
     const char *cp;
 
-    for (cp = varargs_style_indicator; isalnum (*cp) || *cp == '_'; cp++)
+    for (cp = varargs_style_indicator; ISALNUM (*cp) || *cp == '_'; cp++)
       continue;
     if (*cp != 0)
       varargs_style_indicator = savestring (varargs_style_indicator,
@@ -4724,9 +4693,8 @@ main (argc, argv)
         fprintf (stderr, "%s: %s\n", pname, version_string);
       do_processing ();
     }
-  if (errors)
-    exit (1);
-  else
-    exit (0);
+
+  exit (errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+
   return 1;
 }