Makefile.in (gcc.o, [...]): Depend on prefix.h.
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Tue, 5 Jan 1999 19:11:22 +0000 (19:11 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Tue, 5 Jan 1999 19:11:22 +0000 (19:11 +0000)
        * Makefile.in (gcc.o, prefix.o, cccp.o, cpplib.o): Depend on prefix.h.
        * cccp.c: Include prefix.h, don't prototype prefix.c functions.
        (new_include_prefix): Constify char* parameters.
        * cppfiles.c (read_name_map): Likewise.
        (append_include_chain): Likewise.  Also, use a writable char* copy
        of parameter `dir' which we then modify, rather than using the
        parameter itself to store the new writable string.
        (remap_filename): Constify some variables.  Also, use a writable
        char* to store an allocated string which we will be modifying.
        * cpplib.c: Include prefix.h, don't prototype prefix.c functions.
        (cpp_start_read): Constify variable `str'.
        * cpplib.h (append_include_chain): Constify a char* parameter.
        * gcc.c Include prefix.h, don't prototype prefix.c functions.
        (add_prefix, save_string): Constify char* parameters.
        (fatal, error): Add ATTRIBUTE_PRINTF_1 to prototypes.
        * prefix.c: Include prefix.h.
        (get_key_value, translate_name, save_string, update_path,
        set_std_prefix): Constify various char* parameters and variables.
        (save_string): Use xmalloc, not malloc.
        (translate_name): Use a writable temporary variable to create and
        modify a string before setting it to a const char*.
        * prefix.h: New file to prototype functions exported from prefix.c.

From-SVN: r24498

gcc/ChangeLog
gcc/Makefile.in
gcc/cccp.c
gcc/cppfiles.c
gcc/cpplib.c
gcc/cpplib.h
gcc/gcc.c
gcc/prefix.c
gcc/prefix.h [new file with mode: 0644]

index d234ca0678dc0a1b13feceb1185c00b35e951f9a..caa7e12fb50def2b0d4016d5841bbc79eeb9ab85 100644 (file)
@@ -1,3 +1,35 @@
+Tue Jan  5 21:57:42 1999  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * Makefile.in (gcc.o, prefix.o, cccp.o, cpplib.o): Depend on prefix.h.
+
+       * cccp.c: Include prefix.h, don't prototype prefix.c functions.
+       (new_include_prefix): Constify char* parameters.
+
+       * cppfiles.c (read_name_map): Likewise.
+       (append_include_chain): Likewise.  Also, use a writable char* copy
+       of parameter `dir' which we then modify, rather than using the
+       parameter itself to store the new writable string.
+       (remap_filename): Constify some variables.  Also, use a writable
+       char* to store an allocated string which we will be modifying.
+
+       * cpplib.c: Include prefix.h, don't prototype prefix.c functions.
+       (cpp_start_read): Constify variable `str'.
+
+       * cpplib.h (append_include_chain): Constify a char* parameter.
+
+       * gcc.c Include prefix.h, don't prototype prefix.c functions.
+       (add_prefix, save_string): Constify char* parameters.
+       (fatal, error): Add ATTRIBUTE_PRINTF_1 to prototypes.
+
+       * prefix.c: Include prefix.h.
+       (get_key_value, translate_name, save_string, update_path,
+       set_std_prefix): Constify various char* parameters and variables.
+       (save_string): Use xmalloc, not malloc.
+       (translate_name): Use a writable temporary variable to create and
+       modify a string before setting it to a const char*.
+       
+       * prefix.h: New file to prototype functions exported from prefix.c.
+
 Mon Jan  4 15:37:30 1999  Zack Weinberg  <zack@rabi.phys.columbia.edu>
 
        * cpplib.c (skip_if_group): Split out the logic that handles
index feb47dd41ba82c95d1344bef593af5a1dd14b0fa..754dc26f20e6bf92dff94d758bc38a8439df890b 100644 (file)
@@ -1365,7 +1365,7 @@ DRIVER_DEFINES = \
   -DDEFAULT_TARGET_VERSION=\"$(version)\" \
   -DDEFAULT_TARGET_MACHINE=\"$(target_alias)\" \
   -DTOOLDIR_BASE_PREFIX=\"$(exec_prefix)/\"
-gcc.o: gcc.c $(CONFIG_H) system.h multilib.h Makefile \
+gcc.o: gcc.c $(CONFIG_H) system.h multilib.h Makefile prefix.h \
        $(lang_specs_files)
        $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
   $(DRIVER_DEFINES) \
@@ -1402,7 +1402,7 @@ mkstemp.o: $(srcdir)/../libiberty/mkstemp.c $(CONFIG_H) system.h
        $(LN_S) $(srcdir)/../libiberty/mkstemp.c mkstemp.c
        $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) mkstemp.c
 
-prefix.o: prefix.c $(CONFIG_H) system.h Makefile
+prefix.o: prefix.c $(CONFIG_H) system.h Makefile prefix.h
        $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
        -DPREFIX=\"$(prefix)\" \
          -c `echo $(srcdir)/prefix.c | sed 's,^\./,,'`
@@ -1882,7 +1882,7 @@ $(srcdir)/cexp.c: $(srcdir)/cexp.y
 # We use $(libsubdir)/$(unlibsubdir) to match the
 # -iprefix argument which gcc will pass if GCC_EXEC_PREFIX is used.
 cccp.o: cccp.c $(CONFIG_H) pcp.h version.c config.status system.h \
-           mbchar.h
+           mbchar.h prefix.h
        $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
          -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
          -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \
@@ -1910,7 +1910,8 @@ cppmain$(exeext): cppmain.o libcpp.a $(LIBDEPS)
 
 cppmain.o: cppmain.c $(CONFIG_H) cpplib.h machmode.h system.h
 
-cpplib.o: cpplib.c $(CONFIG_H) cpplib.h machmode.h cpphash.h config.status system.h
+cpplib.o: cpplib.c $(CONFIG_H) cpplib.h machmode.h cpphash.h config.status \
+       system.h prefix.h
        $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
          -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
          -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \
index 440081c72f05d17bc3834309cc38db97a916f325..5271960b580724b63ddd707e4c090607b2591454 100644 (file)
@@ -37,6 +37,7 @@ Boston, MA 02111-1307, USA. */
 typedef unsigned char U_CHAR;
 
 #include "pcp.h"
+#include "prefix.h"
 
 #ifdef MULTIBYTE_CHARS
 #include "mbchar.h"
@@ -122,7 +123,6 @@ static int hack_vms_include_specification ();
 /* External declarations.  */
 
 extern char *version_string;
-extern char *update_path PROTO((char *, char *));
 HOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));
 HOST_WIDE_INT parse_c_expression PROTO((char *, int));
 \f
@@ -1029,7 +1029,7 @@ static void make_undef PROTO((char *, FILE_BUF *));
 
 static void make_assertion PROTO((char *, char *));
 
-static struct file_name_list *new_include_prefix PROTO((struct file_name_list *, char *, char *, char *));
+static struct file_name_list *new_include_prefix PROTO((struct file_name_list *, const char *, const char *, const char *));
 static void append_include_chain PROTO((struct file_name_list *, struct file_name_list *));
 
 static int quote_string_for_make PROTO((char *, char *));
@@ -10436,9 +10436,9 @@ make_assertion (option, str)
 static struct file_name_list *
 new_include_prefix (prev_file_name, component, prefix, name)
      struct file_name_list *prev_file_name;
-     char *component;
-     char *prefix;
-     char *name;
+     const char *component;
+     const char *prefix;
+     const char *name;
 {
   if (name == 0)
     fatal ("Directory name missing after command line option");
index 108bf8751fb581330d7617dc5623096042ce7ac0..169809d11badf5d29fe62540c1a7330ed834df6b 100644 (file)
@@ -36,7 +36,8 @@ static struct include_hash *redundant_include_p
                                        PROTO ((cpp_reader *,
                                                struct include_hash *,
                                                struct file_name_list *));
-static struct file_name_map *read_name_map     PROTO ((cpp_reader *, char *));
+static struct file_name_map *read_name_map     PROTO ((cpp_reader *,
+                                                       const char *));
 static char *read_filename_string      PROTO ((int, FILE *));
 static char *remap_filename            PROTO ((cpp_reader *, char *,
                                                struct file_name_list *));
@@ -67,35 +68,35 @@ void
 append_include_chain (pfile, list, dir, sysp)
      cpp_reader *pfile;
      struct file_name_list **list;
-     char *dir;
+     const char *dir;
      int sysp;
 {
   struct file_name_list *new;
   struct stat st;
   unsigned int len;
+  char * newdir = xstrdup (dir);
 
-  dir = xstrdup (dir);
-  simplify_pathname (dir);
-  if (stat (dir, &st))
+  simplify_pathname (newdir);
+  if (stat (newdir, &st))
     {
       /* Dirs that don't exist are silently ignored. */
       if (errno != ENOENT)
-       cpp_perror_with_name (pfile, dir);
+       cpp_perror_with_name (pfile, newdir);
       return;
     }
 
   if (!S_ISDIR (st.st_mode))
     {
-      cpp_message (pfile, 1, "%s: %s: Not a directory", progname, dir);
+      cpp_message (pfile, 1, "%s: %s: Not a directory", progname, newdir);
       return;
     }
 
-  len = strlen(dir);
+  len = strlen(newdir);
   if (len > pfile->max_include_len)
     pfile->max_include_len = len;
   
   new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
-  new->name = dir;
+  new->name = newdir;
   new->nlen = len;
   new->next = *list;
   new->ino  = st.st_ino;
@@ -526,7 +527,7 @@ struct file_name_map_list
 static struct file_name_map *
 read_name_map (pfile, dirname)
      cpp_reader *pfile;
-     char *dirname;
+     const char *dirname;
 {
   register struct file_name_map_list *map_list_ptr;
   char *name;
@@ -607,8 +608,7 @@ remap_filename (pfile, name, loc)
      struct file_name_list *loc;
 {
   struct file_name_map *map;
-  char *from;
-  char *p, *dir;
+  const char *from, *p, *dir;
 
   if (! loc->name_map)
     loc->name_map = read_name_map (pfile,
@@ -644,9 +644,10 @@ remap_filename (pfile, name, loc)
     }
   else
     {
-      dir = (char *) alloca (p - name + 1);
-      bcopy (name, dir, p - name);
-      dir[p - name] = '\0';
+      char * newdir = (char *) alloca (p - name + 1);
+      bcopy (name, newdir, p - name);
+      newdir[p - name] = '\0';
+      dir = newdir;
       from = p + 1;
     }
   
index f9990c85125862f909e32708f16ef46babe54e60..50187026d18355406763f2e9907c9ee13917a4e0 100644 (file)
@@ -38,13 +38,12 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "cpplib.h"
 #include "cpphash.h"
 #include "output.h"
+#include "prefix.h"
 
 #ifndef GET_ENV_PATH_LIST
 #define GET_ENV_PATH_LIST(VAR,NAME)    do { (VAR) = getenv (NAME); } while (0)
 #endif
 
-extern char *update_path PARAMS ((char *, char *));
-
 /* By default, colon separates directories in a path.  */
 #ifndef PATH_SEPARATOR
 #define PATH_SEPARATOR ':'
@@ -4942,7 +4941,7 @@ cpp_start_read (pfile, fname)
       /* Some standard dirs are only for C++.  */
       if (!p->cplusplus
          || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
-       char *str = update_path (p->fname, p->component);
+       const char *str = update_path (p->fname, p->component);
        append_include_chain (pfile, &opts->system_include,
                              str, !p->cxx_aware);
       }
index 68c77a1aeab9b1c0b6383dc34c8ab3b8c5b8fd94..233eedbe4cedccc8dc0504bdf033f9f2c0f2094b 100644 (file)
@@ -714,7 +714,7 @@ extern void cpp_print_containing_files PROTO ((cpp_reader *));
 /* In cppfiles.c */
 extern void append_include_chain       PROTO ((cpp_reader *,
                                                struct file_name_list **,
-                                               char *, int));
+                                               const char *, int));
 extern void merge_include_chains       PROTO ((struct cpp_options *));
 extern int find_include_file           PROTO ((cpp_reader *, char *,
                                                struct file_name_list *,
index cda78b6dd933010fc7fbdef285b36fd1c76389a1..854ed2395a6c5157e635044119d5c29b3f3b716b 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -36,10 +36,7 @@ compilation is specified by a string called a "spec".  */
 #include <signal.h>
 
 #include "obstack.h"
-
-/* ??? Need to find a GCC header to put these in.  */
-extern char *update_path PROTO((char *, char *));
-extern void set_std_prefix PROTO((char *, int));
+#include "prefix.h"
 
 #ifdef VMS
 #define exit __posix_exit
@@ -174,8 +171,8 @@ static struct compiler *lookup_compiler PROTO((char *, size_t, char *));
 static char *build_search_list PROTO((struct path_prefix *, char *, int));
 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
 static char *find_a_file       PROTO((struct path_prefix *, char *, int));
-static void add_prefix         PROTO((struct path_prefix *, char *, char *,
-                                      int, int, int *));
+static void add_prefix         PROTO((struct path_prefix *, const char *,
+                                      const char *, int, int, int *));
 static char *skip_whitespace   PROTO((char *));
 static void record_temp_file   PROTO((char *, int, int));
 static void delete_if_ordinary PROTO((char *));
@@ -184,7 +181,7 @@ static void delete_failure_queue PROTO((void));
 static void clear_failure_queue PROTO((void));
 static int check_live_switch   PROTO((int, int));
 static char *handle_braces     PROTO((char *));
-static char *save_string       PROTO((char *, int));
+static char *save_string       PROTO((const char *, int));
 extern int do_spec             PROTO((char *));
 static int do_spec_1           PROTO((char *, int, char *));
 static char *find_file         PROTO((char *));
@@ -199,8 +196,9 @@ static void print_multilib_info     PROTO((void));
 static void pfatal_with_name   PROTO((char *)) ATTRIBUTE_NORETURN;
 static void perror_with_name   PROTO((char *));
 static void pfatal_pexecute    PROTO((char *, char *)) ATTRIBUTE_NORETURN;
-static void fatal              PVPROTO((char *, ...)) ATTRIBUTE_NORETURN;
-static void error              PVPROTO((char *, ...));
+static void fatal              PVPROTO((char *, ...))
+  ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
+static void error              PVPROTO((char *, ...)) ATTRIBUTE_PRINTF_1;
 static void display_help       PROTO((void));
 
 void fancy_abort               PROTO((void)) ATTRIBUTE_NORETURN;
@@ -2101,8 +2099,8 @@ find_a_file (pprefix, name, mode)
 static void
 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
      struct path_prefix *pprefix;
-     char *prefix;
-     char *component;
+     const char *prefix;
+     const char *component;
      int first;
      int require_machine_suffix;
      int *warn;
@@ -5233,8 +5231,8 @@ xrealloc (ptr, size)
 
 static char *
 save_string (s, len)
-     char *s;
-     int len;
+  const char *s;
+  int len;
 {
   register char *result = xmalloc (len + 1);
 
index 3e98ded4d73796b01d0f643201e1eea034675ded..5e4fdb1505e2e2a05ac97976a09e778ee6a8ca98 100644 (file)
@@ -68,12 +68,13 @@ Boston, MA 02111-1307, USA.  */
 #ifdef _WIN32
 #include <windows.h>
 #endif
+#include "prefix.h"
 
-static char *std_prefix = PREFIX;
+static const char *std_prefix = PREFIX;
 
-static char *get_key_value     PROTO((char *));
-static char *translate_name    PROTO((char *));
-static char *save_string       PROTO((char *, int));
+static const char *get_key_value       PROTO((char *));
+static const char *translate_name      PROTO((const char *));
+static char *save_string               PROTO((const char *, int));
 
 #ifdef _WIN32
 static char *lookup_key                PROTO((char *));
@@ -82,11 +83,11 @@ static HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE;
 
 /* Given KEY, as above, return its value.  */
 
-static char *
+static const char *
 get_key_value (key)
      char *key;
 {
-  char *prefix = 0;
+  const char *prefix = 0;
   char *temp = 0;
 
 #ifdef _WIN32
@@ -165,10 +166,10 @@ concat VPROTO((const char *first, ...))
 
 static char *
 save_string (s, len)
-     char *s;
-     int len;
+  const char *s;
+  int len;
 {
-  register char *result = (char *) malloc (len + 1);
+  register char *result = xmalloc (len + 1);
 
   bcopy (s, result, len);
   result[len] = 0;
@@ -227,12 +228,13 @@ lookup_key (key)
 /* If NAME starts with a '@' or '$', apply the translation rules above
    and return a new name.  Otherwise, return the given name.  */
 
-static char *
+static const char *
 translate_name (name)
-     char *name;
+  const char *name;
 {
   char code = name[0];
-  char *key, *prefix = 0;
+  char *key;
+  const char *prefix = 0;
   int keylen;
 
   if (code != '@' && code != '$')
@@ -272,8 +274,9 @@ translate_name (name)
 #endif
       )
     {
-      prefix = save_string (prefix, strlen (prefix));
-      prefix[strlen (prefix) - 1] = 0;
+      char * temp = save_string (prefix, strlen (prefix));
+      temp[strlen (temp) - 1] = 0;
+      prefix = temp;
     }
 
   return concat (prefix, name, NULL_PTR);
@@ -281,10 +284,10 @@ translate_name (name)
 
 /* Update PATH using KEY if PATH starts with PREFIX.  */
 
-char *
+const char *
 update_path (path, key)
-     char *path;
-     char *key;
+  const char *path;
+  const char *key;
 {
   if (! strncmp (path, std_prefix, strlen (std_prefix)) && key != 0)
     {
@@ -316,8 +319,8 @@ update_path (path, key)
 /* Reset the standard prefix */
 void
 set_std_prefix (prefix, len)
-     char *prefix;
-     int len;
+  const char *prefix;
+  int len;
 {
   std_prefix = save_string (prefix, len);
 }
diff --git a/gcc/prefix.h b/gcc/prefix.h
new file mode 100644 (file)
index 0000000..96dd122
--- /dev/null
@@ -0,0 +1,9 @@
+/* Provide prototypes for functions exported from prefix.c. */
+
+#ifndef __GCC_PREFIX_H__
+#define __GCC_PREFIX_H__
+
+extern const char *update_path PARAMS ((const char *, const char *));
+extern void set_std_prefix PARAMS ((const char *, int));
+
+#endif /* ! __GCC_PREFIX_H__ */