OSDN Git Service

* configure.in (all_headers, all_lib2funcs): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / protoize.c
index a12e0a7..6c6ceee 100644 (file)
@@ -1,22 +1,23 @@
 /* Protoize program - Original version by Ron Guilmette (rfg@segfault.us.com).
-   Copyright (C) 1989, 92-98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001 Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
 
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the 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, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -24,17 +25,21 @@ Boston, MA 02111-1307, USA.  */
 
 #include <setjmp.h>
 #include <signal.h>
+#if ! defined( SIGCHLD ) && defined( SIGCLD )
+#  define SIGCHLD SIGCLD
+#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #undef abort
+#include "version.h"
 
-/* Include getopt.h for the sake of getopt_long. */
+/* Include getopt.h for the sake of getopt_long.  */
 #include "getopt.h"
 
 /* Macro to see if the path elements match.  */
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
-#define IS_SAME_PATH_CHAR(a,b) (toupper (a) == toupper (b))
+#define IS_SAME_PATH_CHAR(a,b) (TOUPPER (a) == TOUPPER (b))
 #else
 #define IS_SAME_PATH_CHAR(a,b) ((a) == (b))
 #endif
@@ -46,6 +51,20 @@ Boston, MA 02111-1307, USA.  */
 #define IS_SAME_PATH(a,b) (strcmp (a, b) == 0)
 #endif
 
+/* Suffix for aux-info files.  */
+#ifdef __MSDOS__
+#define AUX_INFO_SUFFIX "X"
+#else
+#define AUX_INFO_SUFFIX ".X"
+#endif
+
+/* Suffix for saved files.  */
+#ifdef __MSDOS__
+#define SAVE_SUFFIX "sav"
+#else
+#define SAVE_SUFFIX ".save"
+#endif
+
 /* Suffix for renamed C++ files.  */
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
 #define CPLUS_FILE_SUFFIX "cc"
@@ -53,8 +72,6 @@ Boston, MA 02111-1307, USA.  */
 #define CPLUS_FILE_SUFFIX "C"
 #endif
 
-extern char *version_string;
-
 static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
 static void aux_info_corrupted PARAMS ((void)) ATTRIBUTE_NORETURN;
 static void declare_source_confusing PARAMS ((const char *)) ATTRIBUTE_NORETURN;
@@ -74,7 +91,7 @@ static int directory_specified_p PARAMS ((const char *));
 static int file_excluded_p PARAMS ((const char *));
 static char *unexpand_if_needed PARAMS ((const char *));
 static char *abspath PARAMS ((const char *, const char *));
-static int is_abspath PVPROTO ((const char *));
+static int is_abspath PARAMS ((const char *));
 static void check_aux_info PARAMS ((int));
 static const char *find_corresponding_lparen PARAMS ((const char *));
 static int referenced_file_is_newer PARAMS ((const char *, time_t));
@@ -118,11 +135,11 @@ static const char * const target_version = DEFAULT_TARGET_VERSION;
 
 /* Suffix of aux_info files.  */
 
-static const char * const aux_info_suffix = ".X";
+static const char * const aux_info_suffix = AUX_INFO_SUFFIX;
 
 /* String to attach to filenames for saved versions of original files.  */
 
-static const char * const save_suffix = ".save";
+static const char * const save_suffix = SAVE_SUFFIX;
 
 /* String to attach to C filenames renamed to C++.  */
 
@@ -150,8 +167,8 @@ static char * syscalls_absolute_filename;
 /* Type of the structure that holds information about macro unexpansions.  */
 
 struct unexpansion_struct {
-  const char *expanded;
-  const char *contracted;
+  const char *const expanded;
+  const char *const contracted;
 };
 typedef struct unexpansion_struct unexpansion;
 
@@ -178,7 +195,7 @@ static const unexpansion unexpansions[] = {
 static const int hash_mask = (HASH_TABLE_SIZE - 1);
 
 /* Make a table of default system include directories
-   just as it is done in cccp.c.  */
+   just as it is done in cpp.  */
 
 #ifndef STANDARD_INCLUDE_DIR
 #define STANDARD_INCLUDE_DIR "/usr/include"
@@ -188,8 +205,8 @@ static const int hash_mask = (HASH_TABLE_SIZE - 1);
 #define LOCAL_INCLUDE_DIR "/usr/local/include"
 #endif
 
-struct default_include { const char *fname; 
-                        const char *component;
+static const struct default_include { const char *const fname; 
+                        const char *const component;
                         int x1, x2; } include_defaults[]
 #ifdef INCLUDE_DEFAULTS
   = INCLUDE_DEFAULTS;
@@ -261,7 +278,7 @@ static const char * const other_var_style = "stdarg";
 static const char * const other_var_style = "varargs";
 /* Note that this is a string containing the expansion of va_alist.
    But in `main' we discard all but the first token.  */
-static const char *varargs_style_indicator = STRINGIFY (va_alist);
+static const char *varargs_style_indicator = STRINGX (va_alist);
 #endif /* !defined (UNPROTOIZE) */
 
 /* The following two types are used to create hash tables.  In this program,
@@ -547,19 +564,11 @@ static char * saved_repl_write_ptr;
 static void
 notice VPARAMS ((const char *msgid, ...))
 {
-#ifndef ANSI_PROTOTYPES
-  const char *msgid;
-#endif
-  va_list ap;
-
-  VA_START (ap, msgid);
-
-#ifndef ANSI_PROTOTYPES
-  msgid = va_arg (ap, const char *);
-#endif
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
 
   vfprintf (stderr, _(msgid), ap);
-  va_end (ap);
+  VA_CLOSE (ap);
 }
 
 \f
@@ -646,7 +655,7 @@ safe_read (desc, ptr, len)
       }
     if (nchars == 0)
       break;
-    /* Arithmetic on void pointers is a gcc extention.  */
+    /* Arithmetic on void pointers is a gcc extension.  */
     ptr = (char *) ptr + nchars;
     left -= nchars;
   }
@@ -676,7 +685,7 @@ safe_write (desc, ptr, len, out_fname)
                pname, shortpath (NULL, out_fname), xstrerror (errno_val));
        return;
       }
-    /* Arithmetic on void pointers is a gcc extention.  */
+    /* Arithmetic on void pointers is a gcc extension.  */
     ptr = (char *) ptr + written;
     len -= written;
   }
@@ -707,7 +716,7 @@ static int
 is_id_char (ch)
      int ch;
 {
-  return (ISALNUM (ch) || (ch == '_') || (ch == '$'));
+  return (ISIDNUM (ch) || (ch == '$'));
 }
 
 /* Give a message indicating the proper way to invoke this program and then
@@ -734,7 +743,7 @@ static int
 in_system_include_dir (path)
      const char *path;
 {
-  struct default_include *p;
+  const struct default_include *p;
 
   if (! is_abspath (path))
     abort ();          /* Must be an absolutized filename.  */
@@ -1126,7 +1135,7 @@ unexpand_if_needed (aux_info_line)
               strcpy (copy_p, unexp_p->contracted);
               copy_p += size;
 
-              /* Assume the there will not be another replacement required
+              /* Assume that there will not be another replacement required
                  within the text just replaced.  */
 
               s += len;
@@ -1156,7 +1165,7 @@ continue_outer: ;
   return (got_unexpanded ? savestring (line_buf, copy_p - line_buf) : 0);
 }
 \f
-/* Return 1 if pathname is absolute. */
+/* Return 1 if pathname is absolute.  */
 
 static int
 is_abspath (path)
@@ -1186,7 +1195,7 @@ abspath (cwd, rel_filename)
      const char *rel_filename;
 {
   /* Setup the current working directory as needed.  */
-  const char *cwd2 = (cwd) ? cwd : cwd_buffer;
+  const char *const cwd2 = (cwd) ? cwd : cwd_buffer;
   char *const abs_buffer
     = (char *) alloca (strlen (cwd2) + strlen (rel_filename) + 2);
   char *endp = abs_buffer;
@@ -1938,6 +1947,7 @@ munge_compile_params (params_list)
     = (const char **) alloca ((strlen (params_list) + 8) * sizeof (char *));
   int param_count = 0;
   const char *param;
+  struct stat st;
 
   temp_params[param_count++] = compiler_file_name;
   for (;;)
@@ -1984,11 +1994,16 @@ munge_compile_params (params_list)
 
   temp_params[param_count++] = "-S";
   temp_params[param_count++] = "-o";
-#if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN__) && ! defined (_UWIN))
-  temp_params[param_count++] = "NUL:";
-#else
-  temp_params[param_count++] = "/dev/null";
-#endif
+  
+  if ((stat (HOST_BIT_BUCKET, &st) == 0)
+      && (!S_ISDIR (st.st_mode))
+      && (access (HOST_BIT_BUCKET, W_OK) == 0))
+    temp_params[param_count++] = HOST_BIT_BUCKET;
+  else
+    /* FIXME: This is hardly likely to be right, if HOST_BIT_BUCKET is not
+       writable.  But until this is rejigged to use make_temp_file(), this
+       is the best we can do.  */
+    temp_params[param_count++] = "/dev/null";
 
   /* Leave room for the input file name argument.  */
   input_file_name_index = param_count;
@@ -2019,7 +2034,7 @@ gen_aux_info_file (base_filename)
   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] =
-    concat (compile_params[input_file_name_index], ".X", NULL);
+    concat (compile_params[input_file_name_index], aux_info_suffix, NULL);
   
   if (!quiet_flag)
     notice ("%s: compiling `%s'\n",
@@ -2214,7 +2229,7 @@ start_over: ;
   
     fd_flags = O_RDONLY;
 #ifdef O_BINARY
-    /* Use binary mode to avoid having to deal with different EOL characters. */
+    /* Use binary mode to avoid having to deal with different EOL characters.  */
     fd_flags |= O_BINARY;
 #endif
     if ((aux_info_file = open (aux_info_filename, fd_flags, 0444 )) == -1)
@@ -2523,7 +2538,7 @@ find_extern_def (head, user)
      code being converted contains its own definition of a function which
      could have been supplied by libc.a.  In such cases, we should avoid
      issuing the normal warning, and defer to the definition given in the
-     user's own code.   */
+     user's own code.  */
 
   for (dd_p = head; dd_p; dd_p = dd_p->next_for_func)
     if (dd_p->is_func_def && !dd_p->is_static)
@@ -3630,7 +3645,7 @@ add_global_decls (file_p, clean_text_p)
   /* Now write out full prototypes for all of the things that had been
      implicitly declared in this file (but only those for which we were
      actually able to find unique matching definitions).  Avoid duplicates
-     by marking things that we write out as we go.   */
+     by marking things that we write out as we go.  */
 
   {
     int some_decls_added = 0;
@@ -4168,7 +4183,7 @@ edit_file (hp)
 
     fd_flags = O_RDONLY;
 #ifdef O_BINARY
-    /* Use binary mode to avoid having to deal with different EOL characters. */
+    /* Use binary mode to avoid having to deal with different EOL characters.  */
     fd_flags |= O_BINARY;
 #endif
     if ((input_file = open (convert_filename, fd_flags, 0444)) == -1)
@@ -4317,6 +4332,11 @@ edit_file (hp)
        = (char *) xmalloc (strlen (convert_filename) + strlen (save_suffix) + 2);
   
       strcpy (new_filename, convert_filename);
+#ifdef __MSDOS__
+      /* MSDOS filenames are restricted to 8.3 format, so we save `foo.c'
+         as `foo.<save_suffix>'.  */
+      new_filename[(strlen (convert_filename) - 1] = '\0';
+#endif
       strcat (new_filename, save_suffix);
 
       /* Don't overwrite existing file.  */
@@ -4558,11 +4578,13 @@ main (argc, argv)
 #endif
   pname = pname ? pname+1 : argv[0];
 
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_MESSAGES, "");
+#ifdef SIGCHLD
+  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
+     receive the signal.  A different setting is inheritable */
+  signal (SIGCHLD, SIG_DFL);
 #endif
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+
+  gcc_init_libintl ();
 
   cwd_buffer = getpwd ();
   if (!cwd_buffer)
@@ -4678,8 +4700,7 @@ main (argc, argv)
   {
     const char *cp;
 
-    for (cp = varargs_style_indicator;
-        ISALNUM ((const unsigned char)*cp) || *cp == '_'; cp++)
+    for (cp = varargs_style_indicator; ISIDNUM (*cp); cp++)
       continue;
     if (*cp != 0)
       varargs_style_indicator = savestring (varargs_style_indicator,