OSDN Git Service

Remove CYGNUS LOCAL tags.
[pf3gnuchains/gcc-fork.git] / gcc / cccp.c
index 8834163..33d783d 100644 (file)
@@ -1,5 +1,5 @@
 /* C Compatible Compiler Preprocessor (CCCP)
-   Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1986, 87, 89, 92-95, 1996 Free Software Foundation, Inc.
    Written by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
 
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
 
  In other words, you are welcome to use, share and improve this program.
  You are forbidden to forbid anyone else to use, share and improve
@@ -47,14 +48,6 @@ typedef unsigned char U_CHAR;
 #define LOCAL_INCLUDE_DIR "/usr/local/include"
 #endif
 
-#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE.  */
-#ifdef __STDC__
-#define PTR_INT_TYPE ptrdiff_t
-#else
-#define PTR_INT_TYPE long
-#endif
-#endif /* 0 */
-
 #include "pcp.h"
 
 /* By default, colon separates directories in a path.  */
@@ -116,7 +109,6 @@ typedef unsigned char U_CHAR;
 # include <fcntl.h>
 #endif
 
-/* This defines "errno" properly for VMS, and gives us EACCES. */
 #include <errno.h>
 
 #if HAVE_STDLIB_H
@@ -238,20 +230,17 @@ my_bzero (b, length)
 #define open(fname,mode,prot)  VMS_open (fname,mode,prot)
 #define fopen(fname,mode)      VMS_fopen (fname,mode)
 #define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
-#define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt)
 #define fstat(fd,stbuf)                VMS_fstat (fd,stbuf)
-#define stat(name,stbuf)       VMS_stat (name,stbuf)
 static int VMS_fstat (), VMS_stat ();
-static char * VMS_strncat ();
 static int VMS_read ();
 static int VMS_write ();
 static int VMS_open ();
 static FILE * VMS_fopen ();
 static FILE * VMS_freopen ();
 static void hack_vms_include_specification ();
-typedef struct { unsigned :16, :16, :16; } vms_ino_t;
-#define ino_t vms_ino_t
-#define INCLUDE_LEN_FUDGE 10   /* leave room for VMS syntax conversion */
+#define INO_T_EQ(a, b) (!bcmp((char *) &(a), (char *) &(b), sizeof (a)))
+#define INO_T_HASH(a) 0
+#define INCLUDE_LEN_FUDGE 12   /* leave room for VMS syntax conversion */
 #ifdef __GNUC__
 #define BSTRING                        /* VMS/GCC supplies the bstring routines */
 #endif /* __GNUC__ */
@@ -266,7 +255,8 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
 
-/* Find the largest host integer type and set its size and type.  */
+/* Find the largest host integer type and set its size and type.
+   Don't blindly use `long'; on some crazy hosts it is shorter than `int'.  */
 
 #ifndef HOST_BITS_PER_WIDE_INT
 
@@ -288,6 +278,14 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #endif
 
+#ifndef INO_T_EQ
+#define INO_T_EQ(a, b) ((a) == (b))
+#endif
+
+#ifndef INO_T_HASH
+#define INO_T_HASH(a) (a)
+#endif
+
 /* Define a generic NULL if one hasn't already been defined.  */
 
 #ifndef NULL
@@ -321,27 +319,19 @@ extern const char *const sys_errlist[];
 #else
 extern char *sys_errlist[];
 #endif
-#else  /* HAVE_STERRROR */
+#else  /* HAVE_STRERROR */
 char *strerror ();
 #endif
 #else  /* VMS */
 char *strerror (int,...);
 #endif
-int parse_escape PROTO((char **));
+HOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));
 HOST_WIDE_INT parse_c_expression PROTO((char *));
 
 #ifndef errno
 extern int errno;
 #endif
 \f
-#ifndef FAILURE_EXIT_CODE
-#define FAILURE_EXIT_CODE 33   /* gnu cc command understands this */
-#endif
-
-#ifndef SUCCESS_EXIT_CODE
-#define SUCCESS_EXIT_CODE 0    /* 0 means success on Unix.  */
-#endif
-
 /* Name under which this program was invoked.  */
 
 static char *progname;
@@ -457,7 +447,8 @@ static int pedantic_errors;
 
 static int inhibit_warnings = 0;
 
-/* Nonzero means warn if slash-star appears in a comment.  */
+/* Nonzero means warn if slash-star appears in a slash-star comment,
+   or if newline-backslash appears in a slash-slash comment.  */
 
 static int warn_comments;
 
@@ -513,6 +504,8 @@ static struct file_buf {
   char *fname;
   /* Filename specified with #line directive.  */
   char *nominal_fname;
+  /* Include file description.  */
+  struct include_file *inc;
   /* Record where in the search path this file was found.
      For #include_next.  */
   struct file_name_list *dir;
@@ -569,17 +562,19 @@ static FILE_BUF outbuf;
 struct file_name_list
   {
     struct file_name_list *next;
-    char *fname;
-    /* If the following is nonzero, it is a macro name.
-       Don't include the file again if that macro is defined.  */
-    U_CHAR *control_macro;
-    /* If the following is nonzero, it is a C-language system include
+    /* If the following is 1, it is a C-language system include
        directory.  */
     int c_system_include_path;
     /* Mapping of file names for this directory.  */
     struct file_name_map *name_map;
     /* Non-zero if name_map is valid.  */
     int got_name_map;
+    /* The include directory status.  */
+    struct stat st;
+    /* The include prefix: "" denotes the working directory,
+       otherwise fname must end in '/'.
+       The actual size is dynamically allocated.  */
+    char fname[1];
   };
 
 /* #include "file" looks in source file dir, then stack. */
@@ -599,6 +594,7 @@ static struct default_include {
   = {
     /* Pick up GNU C++ specific include files.  */
     { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
+    { OLD_GPLUSPLUS_INCLUDE_DIR, 1, 1 },
 #ifdef CROSS_COMPILE
     /* This is the dir for fixincludes.  Put it just before
        the files that we fix.  */
@@ -651,18 +647,33 @@ static struct file_name_list *last_after_include = 0;     /* Last in chain */
 static struct file_name_list *before_system = 0;
 static struct file_name_list *last_before_system = 0;  /* Last in chain */
 
-/* List of included files that contained #pragma once.  */
-static struct file_name_list *dont_repeat_files = 0;
-
-/* List of other included files.
-   If ->control_macro if nonzero, the file had a #ifndef
-   around the entire contents, and ->control_macro gives the macro name.  */
-static struct file_name_list *all_include_files = 0;
-
 /* Directory prefix that should replace `/usr' in the standard
    include file directories.  */
 static char *include_prefix;
 
+/* Maintain and search list of included files.  */
+
+struct include_file {
+  struct include_file *next; /* for include_hashtab */
+  struct include_file *next_ino; /* for include_ino_hashtab */
+  char *fname;
+  /* If the following is the empty string, it means #pragma once
+     was seen in this include file, or #import was applied to the file.
+     Otherwise, if it is nonzero, it is a macro name.
+     Don't include the file again if that macro is defined.  */
+  U_CHAR *control_macro;
+  /* Nonzero if the dependency on this include file has been output.  */
+  int deps_output;
+  struct stat st;
+};
+
+/* Hash tables of files already included with #include or #import.
+   include_hashtab is by full name; include_ino_hashtab is by inode number.  */
+
+#define INCLUDE_HASHSIZE 61
+static struct include_file *include_hashtab[INCLUDE_HASHSIZE];
+static struct include_file *include_ino_hashtab[INCLUDE_HASHSIZE];
+
 /* Global list of strings read in from precompiled files.  This list
    is kept in the order the strings are read in, with new strings being
    added at the end through stringlist_tailp.  We use this list to output
@@ -682,7 +693,7 @@ struct macrodef
 };
 \f
 enum sharp_token_type {
-  NO_SHARP_TOKEN,              /* token not present */
+  NO_SHARP_TOKEN = 0,          /* token not present */
 
   SHARP_TOKEN = '#',           /* token spelled with # only */
   WHITE_SHARP_TOKEN,           /* token spelled with # and white space */
@@ -805,6 +816,7 @@ enum node_type {
  T_WCHAR_TYPE,   /* `__WCHAR_TYPE__' */
  T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
  T_REGISTER_PREFIX_TYPE,   /* `__REGISTER_PREFIX__' */
+ T_IMMEDIATE_PREFIX_TYPE,  /* `__IMMEDIATE_PREFIX__' */
  T_TIME,       /* `__TIME__' */
  T_CONST,      /* Constant value, used by `__STDC__' */
  T_MACRO,      /* macro defined by `#define' */
@@ -885,6 +897,12 @@ char * wchar_type = WCHAR_TYPE;
 #ifndef REGISTER_PREFIX
 #define REGISTER_PREFIX ""
 #endif
+
+/* The string value for __IMMEDIATE_PREFIX__ */
+
+#ifndef IMMEDIATE_PREFIX
+#define IMMEDIATE_PREFIX ""
+#endif
 \f
 /* In the definition of a #assert name, this structure forms
    a list of the individual values asserted.
@@ -1082,21 +1100,21 @@ static int handle_directive PROTO((FILE_BUF *, FILE_BUF *));
 static struct tm *timestamp PROTO((void));
 static void special_symbol PROTO((HASHNODE *, FILE_BUF *));
 
-static int redundant_include_p PROTO((char *));
-static is_system_include PROTO((char *));
+static int is_system_include PROTO((char *));
+static char *base_name PROTO((char *));
+static int absolute_filename PROTO((char *));
+static size_t simplify_filename PROTO((char *));
 
 static char *read_filename_string PROTO((int, FILE *));
 static struct file_name_map *read_name_map PROTO((char *));
-static int open_include_file PROTO((char *, struct file_name_list *));
+static int open_include_file PROTO((char *, struct file_name_list *, U_CHAR *, struct include_file **));
+static char *remap_include_file PROTO((char *, struct file_name_list *));
+static int lookup_ino_include PROTO((struct include_file *));
 
-static void finclude PROTO((int, char *, FILE_BUF *, int, struct file_name_list *));
-static void record_control_macro PROTO((char *, U_CHAR *));
+static void finclude PROTO((int, struct include_file *, FILE_BUF *, int, struct file_name_list *));
+static void record_control_macro PROTO((struct include_file *, U_CHAR *));
 
-static int import_hash PROTO((char *));
-static int lookup_import PROTO((char *, struct file_name_list *));
-static void add_import PROTO((int, char *));
-
-static char *check_precompiled PROTO((int, char *, char **));
+static char *check_precompiled PROTO((int, struct stat *, char *, char **));
 static int check_preconditions PROTO((char *));
 static void pcfinclude PROTO((U_CHAR *, U_CHAR *, U_CHAR *, FILE_BUF *));
 static void pcstring_used PROTO((HASHNODE *));
@@ -1126,7 +1144,7 @@ static void do_once PROTO((void));
 static HOST_WIDE_INT eval_if_expression PROTO((U_CHAR *, int));
 static void conditional_skip PROTO((FILE_BUF *, int, enum node_type, U_CHAR *, FILE_BUF *));
 static void skip_if_group PROTO((FILE_BUF *, int, FILE_BUF *));
-static void validate_else PROTO((U_CHAR *));
+static void validate_else PROTO((U_CHAR *, U_CHAR *));
 
 static U_CHAR *skip_to_end_of_comment PROTO((FILE_BUF *, int *, int));
 static U_CHAR *skip_quoted_string PROTO((U_CHAR *, U_CHAR *, int, int *, int *, int *));
@@ -1157,6 +1175,7 @@ static void vwarning PROTO((char *, va_list));
 static void error_with_line PRINTF_PROTO_2((int, char *, ...));
 static void verror_with_line PROTO((int, char *, va_list));
 static void vwarning_with_line PROTO((int, char *, va_list));
+static void warning_with_line PRINTF_PROTO_2((int, char *, ...));
 void pedwarn PRINTF_PROTO_1((char *, ...));
 void pedwarn_with_line PRINTF_PROTO_2((int, char *, ...));
 static void pedwarn_with_file_and_line PRINTF_PROTO_3((char *, int, char *, ...));
@@ -1184,6 +1203,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 *));
 static void append_include_chain PROTO((struct file_name_list *, struct file_name_list *));
 
 static void deps_output PROTO((char *, int));
@@ -1199,9 +1219,6 @@ GENERIC_PTR xmalloc PROTO((size_t));
 static GENERIC_PTR xrealloc PROTO((GENERIC_PTR, size_t));
 static GENERIC_PTR xcalloc PROTO((size_t, size_t));
 static char *savestring PROTO((char *));
-
-static int file_size_and_mode PROTO((int, int *, long int *));
-static void output_dots PROTO((FILE *, int));
 \f
 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
    retrying if necessary.  Return a negative value if an error occurs,
@@ -1262,8 +1279,7 @@ main (argc, argv)
      int argc;
      char **argv;
 {
-  int st_mode;
-  long st_size;
+  struct stat st;
   char *in_fname;
   char *cp;
   int f, i;
@@ -1315,25 +1331,14 @@ main (argc, argv)
   signal (SIGPIPE, pipe_closed);
 #endif
 
-  cp = argv[0] + strlen (argv[0]);
-  while (cp != argv[0] && cp[-1] != '/'
-#ifdef DIR_SEPARATOR
-        && cp[-1] != DIR_SEPARATOR
-#endif
-        )
-    --cp;
-  progname = cp;
+  progname = base_name (argv[0]);
 
 #ifdef VMS
   {
-    /* Remove directories from PROGNAME.  */
+    /* Remove extension from PROGNAME.  */
     char *p;
-    char *s = progname;
+    char *s = progname = savestring (progname);
 
-    if ((p = rindex (s, ':')) != 0) s = p + 1; /* skip device */
-    if ((p = rindex (s, ']')) != 0) s = p + 1; /* skip directory */
-    if ((p = rindex (s, '>')) != 0) s = p + 1; /* alternate (int'n'l) dir */
-    s = progname = savestring (s);
     if ((p = rindex (s, ';')) != 0) *p = '\0'; /* strip version number */
     if ((p = rindex (s, '.')) != 0             /* strip type iff ".exe" */
        && (p[1] == 'e' || p[1] == 'E')
@@ -1357,7 +1362,7 @@ main (argc, argv)
   dump_macros = dump_none;
   no_output = 0;
   cplusplus = 0;
-  cplusplus_comments = 0;
+  cplusplus_comments = 1;
 
   bzero ((char *) pend_files, argc * sizeof (char *));
   bzero ((char *) pend_defs, argc * sizeof (char *));
@@ -1383,13 +1388,13 @@ main (argc, argv)
          if (i + 1 == argc)
            fatal ("Filename missing after `-include' option");
          else
-           pend_includes[i] = argv[i+1], i++;
+           simplify_filename (pend_includes[i] = argv[++i]);
        }
        if (!strcmp (argv[i], "-imacros")) {
          if (i + 1 == argc)
            fatal ("Filename missing after `-imacros' option");
          else
-           pend_files[i] = argv[i+1], i++;
+           simplify_filename (pend_files[i] = argv[++i]);
        }
        if (!strcmp (argv[i], "-iprefix")) {
          if (i + 1 == argc)
@@ -1403,17 +1408,9 @@ main (argc, argv)
        if (!strcmp (argv[i], "-isystem")) {
          struct file_name_list *dirtmp;
 
-         if (i + 1 == argc)
-           fatal ("Filename missing after `-isystem' option");
-
-         dirtmp = (struct file_name_list *)
-           xmalloc (sizeof (struct file_name_list));
-         dirtmp->next = 0;
-         dirtmp->control_macro = 0;
+         if (! (dirtmp = new_include_prefix (NULL_PTR, "", argv[++i])))
+           break;
          dirtmp->c_system_include_path = 1;
-         dirtmp->fname = xmalloc (strlen (argv[i+1]) + 1);
-         strcpy (dirtmp->fname, argv[++i]);
-         dirtmp->got_name_map = 0;
 
          if (before_system == 0)
            before_system = dirtmp;
@@ -1436,18 +1433,8 @@ main (argc, argv)
              prefix[strlen (prefix) - 7] = 0;
          }
 
-         dirtmp = (struct file_name_list *)
-           xmalloc (sizeof (struct file_name_list));
-         dirtmp->next = 0;     /* New one goes on the end */
-         dirtmp->control_macro = 0;
-         dirtmp->c_system_include_path = 0;
-         if (i + 1 == argc)
-           fatal ("Directory name missing after `-iwithprefix' option");
-
-         dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1);
-         strcpy (dirtmp->fname, prefix);
-         strcat (dirtmp->fname, argv[++i]);
-         dirtmp->got_name_map = 0;
+         if (! (dirtmp = new_include_prefix (NULL_PTR, prefix, argv[++i])))
+           break;
 
          if (after_include == 0)
            after_include = dirtmp;
@@ -1470,35 +1457,15 @@ main (argc, argv)
              prefix[strlen (prefix) - 7] = 0;
          }
 
-         dirtmp = (struct file_name_list *)
-           xmalloc (sizeof (struct file_name_list));
-         dirtmp->next = 0;     /* New one goes on the end */
-         dirtmp->control_macro = 0;
-         dirtmp->c_system_include_path = 0;
-         if (i + 1 == argc)
-           fatal ("Directory name missing after `-iwithprefixbefore' option");
-
-         dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1);
-         strcpy (dirtmp->fname, prefix);
-         strcat (dirtmp->fname, argv[++i]);
-         dirtmp->got_name_map = 0;
-
+         dirtmp = new_include_prefix (NULL_PTR, prefix, argv[++i]);
          append_include_chain (dirtmp, dirtmp);
        }
        /* Add directory to end of path for includes.  */
        if (!strcmp (argv[i], "-idirafter")) {
          struct file_name_list *dirtmp;
 
-         dirtmp = (struct file_name_list *)
-           xmalloc (sizeof (struct file_name_list));
-         dirtmp->next = 0;     /* New one goes on the end */
-         dirtmp->control_macro = 0;
-         dirtmp->c_system_include_path = 0;
-         if (i + 1 == argc)
-           fatal ("Directory name missing after `-idirafter' option");
-         else
-           dirtmp->fname = argv[++i];
-         dirtmp->got_name_map = 0;
+         if (! (dirtmp = new_include_prefix (NULL_PTR, "", argv[++i])))
+           break;
 
          if (after_include == 0)
            after_include = dirtmp;
@@ -1542,6 +1509,7 @@ main (argc, argv)
       case 't':
        if (!strcmp (argv[i], "-traditional")) {
          traditional = 1;
+         cplusplus_comments = 0;
          if (dollars_in_ident > 0)
            dollars_in_ident = 1;
        } else if (!strcmp (argv[i], "-trigraphs")) {
@@ -1551,11 +1519,11 @@ main (argc, argv)
 
       case 'l':
        if (! strcmp (argv[i], "-lang-c"))
+         cplusplus = 0, cplusplus_comments = 1, objc = 0;
+       if (! strcmp (argv[i], "-lang-c89"))
          cplusplus = 0, cplusplus_comments = 0, objc = 0;
        if (! strcmp (argv[i], "-lang-c++"))
          cplusplus = 1, cplusplus_comments = 1, objc = 0;
-       if (! strcmp (argv[i], "-lang-c-c++-comments"))
-         cplusplus = 0, cplusplus_comments = 1, objc = 0;
        if (! strcmp (argv[i], "-lang-objc"))
          objc = 1, cplusplus = 0, cplusplus_comments = 1;
        if (! strcmp (argv[i], "-lang-objc++"))
@@ -1758,18 +1726,8 @@ main (argc, argv)
            first_bracket_include = 0;
          }
          else {
-           dirtmp = (struct file_name_list *)
-             xmalloc (sizeof (struct file_name_list));
-           dirtmp->next = 0;           /* New one goes on the end */
-           dirtmp->control_macro = 0;
-           dirtmp->c_system_include_path = 0;
-           if (argv[i][2] != 0)
-             dirtmp->fname = argv[i] + 2;
-           else if (i + 1 == argc)
-             fatal ("Directory name missing after -I option");
-           else
-             dirtmp->fname = argv[++i];
-           dirtmp->got_name_map = 0;
+           dirtmp = new_include_prefix (last_include, "",
+                                        argv[i][2] ? argv[i] + 2 : argv[++i]);
            append_include_chain (dirtmp, dirtmp);
          }
        }
@@ -1958,7 +1916,6 @@ main (argc, argv)
     /* If the environment var for this language is set,
        add to the default list of include directories.  */
     if (epath) {
-      char *nstore = (char *) alloca (strlen (epath) + 2);
       int num_dirs;
       char *startp, *endp;
 
@@ -1972,30 +1929,19 @@ main (argc, argv)
       startp = endp = epath;
       num_dirs = 0;
       while (1) {
-        /* Handle cases like c:/usr/lib:d:/gcc/lib */
-        if ((*endp == PATH_SEPARATOR
-#if 0 /* Obsolete, now that we use semicolons as the path separator.  */
-#ifdef __MSDOS__
-            && (endp-startp != 1 || !isalpha (*startp))
-#endif
-#endif
-            )
-            || *endp == 0) {
-         strncpy (nstore, startp, endp-startp);
-         if (endp == startp)
-           strcpy (nstore, ".");
-         else
-           nstore[endp-startp] = '\0';
-
-         include_defaults[num_dirs].fname = savestring (nstore);
+       char c = *endp++;
+       if (c == PATH_SEPARATOR || !c) {
+         endp[-1] = 0;
+         include_defaults[num_dirs].fname
+           = startp == endp ? "." : savestring (startp);
+         endp[-1] = c;
          include_defaults[num_dirs].cplusplus = cplusplus;
          include_defaults[num_dirs].cxx_aware = 1;
          num_dirs++;
-         if (*endp == '\0')
+         if (!c)
            break;
-         endp = startp = endp + 1;
-       } else
-         endp++;
+         startp = endp;
+       }
       }
       /* Put the usual defaults back in at the end.  */
       bcopy ((char *) include_defaults_array,
@@ -2029,18 +1975,14 @@ main (argc, argv)
          if (!strncmp (p->fname, default_prefix, default_len)) {
            /* Yes; change prefix and add to search list.  */
            struct file_name_list *new
-             = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
-           int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
-           char *str = xmalloc (this_len + 1);
-           strcpy (str, specd_prefix);
-           strcat (str, p->fname + default_len);
-           new->fname = str;
-           new->control_macro = 0;
-           new->c_system_include_path = !p->cxx_aware;
-           new->got_name_map = 0;
-           append_include_chain (new, new);
-           if (first_system_include == 0)
-             first_system_include = new;
+             = new_include_prefix (NULL_PTR, specd_prefix,
+                                   p->fname + default_len);
+           if (new) {
+             new->c_system_include_path = !p->cxx_aware;
+             append_include_chain (new, new);
+             if (first_system_include == 0)
+               first_system_include = new;
+           }
          }
        }
       }
@@ -2049,14 +1991,13 @@ main (argc, argv)
       /* Some standard dirs are only for C++.  */
       if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
        struct file_name_list *new
-         = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
-       new->control_macro = 0;
-       new->c_system_include_path = !p->cxx_aware;
-       new->fname = p->fname;
-       new->got_name_map = 0;
-       append_include_chain (new, new);
-       if (first_system_include == 0)
-         first_system_include = new;
+         = new_include_prefix (NULL_PTR, "", p->fname);
+       if (new) {
+         new->c_system_include_path = !p->cxx_aware;
+         append_include_chain (new, new);
+         if (first_system_include == 0)
+           first_system_include = new;
+       }
       }
     }
   }
@@ -2073,37 +2014,17 @@ main (argc, argv)
     for (p = include; p; p = p->next) {
       if (p == first_bracket_include)
        fprintf (stderr, "#include <...> search starts here:\n");
-      fprintf (stderr, " %s\n", p->fname);
+      if (!p->fname[0])
+       fprintf (stderr, " .\n");
+      else if (!strcmp (p->fname, "/") || !strcmp (p->fname, "//"))
+       fprintf (stderr, " %s\n", p->fname);
+      else
+       /* Omit trailing '/'.  */
+       fprintf (stderr, " %.*s\n", (int) strlen (p->fname) - 1, p->fname);
     }
     fprintf (stderr, "End of search list.\n");
   }
 
-  /* Scan the -imacros files before the main input.
-     Much like #including them, but with no_output set
-     so that only their macro definitions matter.  */
-
-  no_output++; no_record_file++;
-  for (i = 1; i < argc; i++)
-    if (pend_files[i]) {
-      int fd = open (pend_files[i], O_RDONLY, 0666);
-      if (fd < 0) {
-       perror_with_name (pend_files[i]);
-       return FAILURE_EXIT_CODE;
-      }
-      finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR);
-    }
-  no_output--; no_record_file--;
-
-  /* Copy the entire contents of the main input file into
-     the stacked input buffer previously allocated for it.  */
-
-  /* JF check for stdin */
-  if (in_fname == NULL || *in_fname == 0) {
-    in_fname = "";
-    f = 0;
-  } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
-    goto perror;
-
   /* -MG doesn't select the form of output and must be specified with one of
      -M or -MM.  -MG doesn't make sense with -MD or -MMD since they don't
      inhibit compilation.  */
@@ -2165,15 +2086,7 @@ main (argc, argv)
       char *p, *q;
       int len;
 
-      /* Discard all directory prefixes from filename.  */
-      if ((q = rindex (in_fname, '/')) != NULL
-#ifdef DIR_SEPARATOR
-         && (q = rindex (in_fname, DIR_SEPARATOR)) != NULL
-#endif
-         )
-       ++q;
-      else
-       q = in_fname;
+      q = base_name (in_fname);
 
       /* Copy remainder to mungable area.  */
       p = (char *) alloca (strlen(q) + 8);
@@ -2216,12 +2129,40 @@ main (argc, argv)
     }
   }
 
-  file_size_and_mode (f, &st_mode, &st_size);
+  /* Scan the -imacros files before the main input.
+     Much like #including them, but with no_output set
+     so that only their macro definitions matter.  */
+
+  no_output++; no_record_file++;
+  for (i = 1; i < argc; i++)
+    if (pend_files[i]) {
+      struct include_file *inc;
+      int fd = open_include_file (pend_files[i], NULL_PTR, NULL_PTR, &inc);
+      if (fd < 0) {
+       perror_with_name (pend_files[i]);
+       return FATAL_EXIT_CODE;
+      }
+      finclude (fd, inc, &outbuf, 0, NULL_PTR);
+    }
+  no_output--; no_record_file--;
+
+  /* Copy the entire contents of the main input file into
+     the stacked input buffer previously allocated for it.  */
+
+  /* JF check for stdin */
+  if (in_fname == NULL || *in_fname == 0) {
+    in_fname = "";
+    f = 0;
+  } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
+    goto perror;
+
+  if (fstat (f, &st) != 0)
+    pfatal_with_name (in_fname);
   fp->nominal_fname = fp->fname = in_fname;
   fp->lineno = 1;
   fp->system_header_p = 0;
   /* JF all this is mine about reading pipes and ttys */
-  if (! S_ISREG (st_mode)) {
+  if (! S_ISREG (st.st_mode)) {
     /* Read input from a file that is not a normal disk file.
        We cannot preallocate a buffer with the correct size,
        so we must read in the file a piece at the time and make it bigger.  */
@@ -2229,6 +2170,9 @@ main (argc, argv)
     int bsize;
     int cnt;
 
+    if (S_ISDIR (st.st_mode))
+      fatal ("Input file `%s' is a directory", in_fname);
+
     bsize = 2000;
     size = 0;
     fp->buf = (U_CHAR *) xmalloc (bsize + 2);
@@ -2243,9 +2187,9 @@ main (argc, argv)
     fp->length = size;
   } else {
     /* Read a file whose size we can determine in advance.
-       For the sake of VMS, st_size is just an upper bound.  */
-    fp->buf = (U_CHAR *) xmalloc (st_size + 2);
-    fp->length = safe_read (f, (char *) fp->buf, st_size);
+       For the sake of VMS, st.st_size is just an upper bound.  */
+    fp->buf = (U_CHAR *) xmalloc (st.st_size + 2);
+    fp->length = safe_read (f, (char *) fp->buf, st.st_size);
     if (fp->length < 0) goto perror;
   }
   fp->bufp = fp->buf;
@@ -2280,12 +2224,13 @@ main (argc, argv)
   no_record_file++;
   for (i = 1; i < argc; i++)
     if (pend_includes[i]) {
-      int fd = open (pend_includes[i], O_RDONLY, 0666);
+      struct include_file *inc;
+      int fd = open_include_file (pend_includes[i], NULL_PTR, NULL_PTR, &inc);
       if (fd < 0) {
        perror_with_name (pend_includes[i]);
-       return FAILURE_EXIT_CODE;
+       return FATAL_EXIT_CODE;
       }
-      finclude (fd, pend_includes[i], &outbuf, 0, NULL_PTR);
+      finclude (fd, inc, &outbuf, 0, NULL_PTR);
     }
   no_record_file--;
 
@@ -2330,7 +2275,7 @@ main (argc, argv)
     fatal ("I/O error on output");
 
   if (errors)
-    exit (FAILURE_EXIT_CODE);
+    exit (FATAL_EXIT_CODE);
   exit (SUCCESS_EXIT_CODE);
 
  perror:
@@ -2352,38 +2297,22 @@ path_include (path)
   if (*p)
     while (1) {
       char *q = p;
-      char *name;
+      char c;
       struct file_name_list *dirtmp;
 
       /* Find the end of this name.  */
-      while (*q != 0 && *q != PATH_SEPARATOR) q++;
-      if (p == q) {
-       /* An empty name in the path stands for the current directory.  */
-       name = xmalloc (2);
-       name[0] = '.';
-       name[1] = 0;
-      } else {
-       /* Otherwise use the directory that is named.  */
-       name = xmalloc (q - p + 1);
-       bcopy (p, name, q - p);
-       name[q - p] = 0;
-      }
+      while ((c = *q++) != PATH_SEPARATOR && c)
+       continue;
 
-      dirtmp = (struct file_name_list *)
-       xmalloc (sizeof (struct file_name_list));
-      dirtmp->next = 0;                /* New one goes on the end */
-      dirtmp->control_macro = 0;
-      dirtmp->c_system_include_path = 0;
-      dirtmp->fname = name;
-      dirtmp->got_name_map = 0;
+      q[-1] = 0;
+      dirtmp = new_include_prefix (last_include, "", p == q ? "." : p);
+      q[-1] = c;
       append_include_chain (dirtmp, dirtmp);
 
       /* Advance past this name.  */
       p = q;
-      if (*p == 0)
+      if (! c)
        break;
-      /* Skip the colon.  */
-      p++;
     }
 }
 \f
@@ -2487,7 +2416,8 @@ trigraph_pcp (buf)
   buf->length -= fptr - bptr;
   buf->buf[buf->length] = '\0';
   if (warn_trigraphs && fptr != bptr)
-    warning ("%d trigraph(s) encountered", (fptr - bptr) / 2);
+    warning_with_line (0, "%lu trigraph(s) encountered",
+                      (unsigned long) (fptr - bptr) / 2);
 }
 \f
 /* Move all backslash-newline pairs out of embarrassing places.
@@ -2577,7 +2507,7 @@ get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
      U_CHAR **argstart;                /* point to command arg */
      int *arglen, *cmdlen;     /* how long they are */
 {
-  long linsize;
+  HOST_WIDE_INT linsize;
   register U_CHAR *numptr;     /* temp for arg parsing */
 
   *arglen = 0;
@@ -2769,6 +2699,8 @@ do { ip = &instack[indepth];              \
 
     case '#':
       if (assertions_flag) {
+       if (ident_length)
+         goto specialchar;
        /* Copy #foo (bar lose) without macro expansion.  */
        obp[-1] = '#';  /* In case it was '%'. */
        SKIP_WHITE_SPACE (ibp);
@@ -2782,6 +2714,7 @@ do { ip = &instack[indepth];              \
          obp += ip->bufp - ibp;
          ibp = ip->bufp;
        }
+       break;
       }
 
       /* If this is expanding a macro definition, don't recognize
@@ -2938,12 +2871,12 @@ do { ip = &instack[indepth];            \
                             "unterminated character constant");
            goto while2end;
          }
-         if (pedantic && multiline_string_line == 0) {
-           pedwarn_with_line (line_for_error (start_line),
-                              "string constant runs past end of line");
-         }
-         if (multiline_string_line == 0)
+         if (multiline_string_line == 0) {
+           if (pedantic)
+             pedwarn_with_line (line_for_error (start_line),
+                                "string constant runs past end of line");
            multiline_string_line = ip->lineno - 1;
+         }
          break;
 
        case '\\':
@@ -2992,38 +2925,31 @@ do { ip = &instack[indepth];            \
        /* C++ style comment... */
        start_line = ip->lineno;
 
-       --ibp;                  /* Back over the slash */
-       --obp;
-
        /* Comments are equivalent to spaces. */
        if (! put_out_comments)
-         *obp++ = ' ';
-       else {
-         /* must fake up a comment here */
-         *obp++ = '/';
-         *obp++ = '/';
-       }
-       {
-         U_CHAR *before_bp = ibp+2;
+         obp[-1] = ' ';
 
-         while (ibp < limit) {
-           if (ibp[-1] != '\\' && *ibp == '\n') {
-             if (put_out_comments) {
-               bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
-               obp += ibp - before_bp;
-             }
-             break;
-           } else {
-             if (*ibp == '\n') {
-               ++ip->lineno;
-               /* Copy the newline into the output buffer, in order to
-                  avoid the pain of a #line every time a multiline comment
-                  is seen.  */
-               if (!put_out_comments)
-                 *obp++ = '\n';
-               ++op->lineno;
+       {
+         U_CHAR *before_bp = ibp;
+
+         while (++ibp < limit) {
+           if (*ibp == '\n') {
+             if (ibp[-1] != '\\') {
+               if (put_out_comments) {
+                 bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
+                 obp += ibp - before_bp;
+               }
+               break;
              }
-             ibp++;
+             if (warn_comments)
+               warning ("multiline `//' comment");
+             ++ip->lineno;
+             /* Copy the newline into the output buffer, in order to
+                avoid the pain of a #line every time a multiline comment
+                is seen.  */
+             if (!put_out_comments)
+               *obp++ = '\n';
+             ++op->lineno;
            }
          }
          break;
@@ -3085,18 +3011,17 @@ do { ip = &instack[indepth];            \
       {
        U_CHAR *before_bp = ibp;
 
-       while (ibp < limit) {
+       for (;;) {
          switch (*ibp++) {
-         case '/':
-           if (warn_comments && *ibp == '*')
-             warning ("`/*' within comment");
-           break;
          case '*':
+           if (ibp[-2] == '/' && warn_comments)
+             warning ("`/*' within comment");
            if (*ibp == '\\' && ibp[1] == '\n')
              newline_fix (ibp);
-           if (ibp >= limit || *ibp == '/')
+           if (*ibp == '/')
              goto comment_end;
            break;
+
          case '\n':
            ++ip->lineno;
            /* Copy the newline into the output buffer, in order to
@@ -3105,19 +3030,23 @@ do { ip = &instack[indepth];            \
            if (!put_out_comments)
              *obp++ = '\n';
            ++op->lineno;
+           break;
+
+         case 0:
+           if (limit < ibp) {
+             error_with_line (line_for_error (start_line),
+                              "unterminated comment");
+             goto limit_reached;
+           }
+           break;
          }
        }
       comment_end:
 
-       if (ibp >= limit)
-         error_with_line (line_for_error (start_line),
-                          "unterminated comment");
-       else {
-         ibp++;
-         if (put_out_comments) {
-           bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
-           obp += ibp - before_bp;
-         }
+       ibp++;
+       if (put_out_comments) {
+         bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
+         obp += ibp - before_bp;
        }
       }
       break;
@@ -3256,6 +3185,7 @@ do { ip = &instack[indepth];              \
        /* Our input really contains a null character.  */
        goto randomchar;
 
+    limit_reached:
       /* At end of a macro-expansion level, pop it and read next level.  */
       if (ip->macro != 0) {
        obp--;
@@ -3620,6 +3550,7 @@ expand_to_temp_buffer (buf, limit, output_marks, assertions)
   ip = &instack[indepth];
   ip->fname = 0;
   ip->nominal_fname = 0;
+  ip->inc = 0;
   ip->system_header_p = 0;
   ip->macro = 0;
   ip->free_ptr = 0;
@@ -3943,11 +3874,11 @@ handle_directive (ip, op)
            if (*xp == '\n') {
              xp++;
              cp--;
-             if (cp != buf && is_space[cp[-1]]) {
-               while (cp != buf && is_space[cp[-1]]) cp--;
-               cp++;
+             if (cp != buf && is_hor_space[cp[-1]]) {
+               while (cp - 1 != buf && is_hor_space[cp[-2]])
+                 cp--;
                SKIP_WHITE_SPACE (xp);
-             } else if (is_space[*xp]) {
+             } else if (is_hor_space[*xp]) {
                *cp++ = *xp++;
                SKIP_WHITE_SPACE (xp);
              }
@@ -4163,6 +4094,10 @@ special_symbol (hp, op)
     buf = REGISTER_PREFIX;
     break;
 
+  case T_IMMEDIATE_PREFIX_TYPE:
+    buf = IMMEDIATE_PREFIX;
+    break;
+
   case T_CONST:
     buf = hp->value.cpval;
     if (pcp_inside_if && pcp_outfile)
@@ -4255,20 +4190,22 @@ do_include (buf, limit, op, keyword)
      FILE_BUF *op;
      struct directive *keyword;
 {
-  int importing = (keyword->type == T_IMPORT);
+  U_CHAR *importing = keyword->type == T_IMPORT ? (U_CHAR *) "" : (U_CHAR *) 0;
   int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
   static int import_warning = 0;
   char *fname;         /* Dynamically allocated fname buffer */
   char *pcftry;
   char *pcfname;
-  U_CHAR *fbeg, *fend;         /* Beginning and end of fname */
+  char *fbeg, *fend;           /* Beginning and end of fname */
+  U_CHAR *fin;
 
   struct file_name_list *search_start = include; /* Chain of dirs to search */
-  struct file_name_list dsp[1];        /* First in chain, if #include "..." */
+  struct file_name_list *dsp;  /* First in chain, if #include "..." */
   struct file_name_list *searchptr = 0;
-  int flen;
+  size_t flen;
 
-  int f;                       /* file number */
+  int f = -3;                  /* file number */
+  struct include_file *inc = 0;
 
   int retried = 0;             /* Have already tried macro
                                   expanding the include line*/
@@ -4277,7 +4214,6 @@ do_include (buf, limit, op, keyword)
   char *pcfbuf;
   char *pcfbuflimit;
   int pcfnum;
-  f= -1;                       /* JF we iz paranoid! */
 
   if (importing && warn_import && !inhibit_warnings
       && !instack[indepth].system_header_p && !import_warning) {
@@ -4297,21 +4233,19 @@ do_include (buf, limit, op, keyword)
 
 get_filename:
 
-  fbeg = buf;
-  SKIP_WHITE_SPACE (fbeg);
+  fin = buf;
+  SKIP_WHITE_SPACE (fin);
   /* Discard trailing whitespace so we can easily see
      if we have parsed all the significant chars we were given.  */
-  while (limit != fbeg && is_hor_space[limit[-1]]) limit--;
+  while (limit != fin && is_hor_space[limit[-1]]) limit--;
+  fbeg = fend = (char *) alloca (limit - fin);
 
-  switch (*fbeg++) {
+  switch (*fin++) {
   case '\"':
     {
       FILE_BUF *fp;
       /* Copy the operand text, concatenating the strings.  */
       {
-       U_CHAR *fin = fbeg;
-       fbeg = (U_CHAR *) alloca (limit - fbeg + 1);
-       fend = fbeg;
        while (fin != limit) {
          while (fin != limit && *fin != '\"')
            *fend++ = *fin++;
@@ -4327,7 +4261,6 @@ get_filename:
            goto fail;
        }
       }
-      *fend = 0;
 
       /* We have "filename".  Figure out directory this source
         file is coming from and put it on the front of the list. */
@@ -4338,37 +4271,25 @@ get_filename:
       for (fp = &instack[indepth]; fp >= instack; fp--)
        {
          int n;
-         char *ep,*nam;
+         char *nam;
 
          if ((nam = fp->nominal_fname) != NULL) {
            /* Found a named file.  Figure out dir of the file,
               and put it in front of the search list.  */
-           dsp[0].next = search_start;
-           search_start = dsp;
-#ifndef VMS
-           ep = rindex (nam, '/');
-#ifdef DIR_SEPARATOR
-           if (ep == NULL) ep = rindex (nam, DIR_SEPARATOR);
-           else {
-             char *tmp = rindex (nam, DIR_SEPARATOR);
-             if (tmp != NULL && tmp > ep) ep = tmp;
-           }
-#endif
-#else                          /* VMS */
-           ep = rindex (nam, ']');
-           if (ep == NULL) ep = rindex (nam, '>');
-           if (ep == NULL) ep = rindex (nam, ':');
-           if (ep != NULL) ep++;
-#endif                         /* VMS */
-           if (ep != NULL) {
-             n = ep - nam;
-             dsp[0].fname = (char *) alloca (n + 1);
-             strncpy (dsp[0].fname, nam, n);
-             dsp[0].fname[n] = '\0';
+           dsp = ((struct file_name_list *)
+                  alloca (sizeof (struct file_name_list) + strlen (nam)));
+           strcpy (dsp->fname, nam);
+           simplify_filename (dsp->fname);
+           nam = base_name (dsp->fname);
+           *nam = 0;
+           /* But for efficiency's sake, do not insert the dir
+              if it matches the search list's first dir.  */
+           dsp->next = search_start;
+           if (!search_start || strcmp (dsp->fname, search_start->fname)) {
+             search_start = dsp;
+             n = nam - dsp->fname;
              if (n + INCLUDE_LEN_FUDGE > max_include_len)
                max_include_len = n + INCLUDE_LEN_FUDGE;
-           } else {
-             dsp[0].fname = 0; /* Current directory */
            }
            dsp[0].got_name_map = 0;
            break;
@@ -4378,13 +4299,12 @@ get_filename:
     }
 
   case '<':
-    fend = fbeg;
-    while (fend != limit && *fend != '>') fend++;
-    if (*fend == '>' && fend + 1 == limit) {
+    while (fin != limit && *fin != '>')
+      *fend++ = *fin++;
+    if (*fin == '>' && fin + 1 == limit) {
       angle_brackets = 1;
       /* If -I-, start with the first -I dir after the -I-.  */
-      if (first_bracket_include)
-       search_start = first_bracket_include;
+      search_start = first_bracket_include;
       break;
     }
     goto fail;
@@ -4397,15 +4317,14 @@ get_filename:
      * code from case '<' is repeated here) and generates a warning.
      * (Note: macro expansion of `xyz' takes precedence.)
      */
-    if (retried && isalpha(*(--fbeg))) {
-      fend = fbeg;
-      while (fend != limit && (!isspace(*fend))) fend++;
+    if (retried && isalpha(*(U_CHAR *)(--fbeg))) {
+      while (fin != limit && (!isspace(*fin)))
+       *fend++ = *fin++;
       warning ("VAX-C-style include specification found, use '#include <filename.h>' !");
-      if (fend  == limit) {
+      if (fin == limit) {
        angle_brackets = 1;
        /* If -I-, start with the first -I dir after the -I-.  */
-       if (first_bracket_include)
-         search_start = first_bracket_include;
+       search_start = first_bracket_include;
        break;
       }
     }
@@ -4464,7 +4383,8 @@ get_filename:
       }
   }
 
-  flen = fend - fbeg;
+  *fend = 0;
+  flen = simplify_filename (fbeg);
 
   if (flen == 0)
     {
@@ -4474,121 +4394,117 @@ get_filename:
 
   /* Allocate this permanently, because it gets stored in the definitions
      of macros.  */
-  fname = xmalloc (max_include_len + flen + 4);
-  /* + 2 above for slash and terminating null.  */
-  /* + 2 added for '.h' on VMS (to support '#include filename') */
+  fname = xmalloc (max_include_len + flen + 1);
+  /* + 1 above for terminating null.  */
+
+  system_include_depth += angle_brackets;
 
   /* If specified file name is absolute, just open it.  */
 
-  if (*fbeg == '/'
-#ifdef DIR_SEPARATOR
-      || *fbeg == DIR_SEPARATOR
-#endif
-      ) {
-    strncpy (fname, (char *) fbeg, flen);
-    fname[flen] = 0;
-    if (redundant_include_p (fname))
-      return 0;
-    if (importing)
-      f = lookup_import (fname, NULL_PTR);
-    else
-      f = open_include_file (fname, NULL_PTR);
-    if (f == -2)
-      return 0;                /* Already included this file */
+  if (absolute_filename (fbeg)) {
+    strcpy (fname, fbeg);
+    f = open_include_file (fname, NULL_PTR, importing, &inc);
   } else {
+
+    struct bypass_dir {
+      struct bypass_dir *next;
+      char *fname;
+      struct file_name_list *searchptr;
+    } **bypass_slot = 0;
+
     /* Search directory path, trying to open the file.
        Copy each filename tried into FNAME.  */
 
     for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
-      if (searchptr->fname) {
-       /* The empty string in a search path is ignored.
-          This makes it possible to turn off entirely
-          a standard piece of the list.  */
-       if (searchptr->fname[0] == 0)
-         continue;
-       strcpy (fname, searchptr->fname);
-       strcat (fname, "/");
-       fname[strlen (fname) + flen] = 0;
-      } else {
-       fname[0] = 0;
+
+      if (searchptr == first_bracket_include) {
+       /* Go to bypass directory if we know we've seen this file before.  */
+       static struct bypass_dir *bypass_hashtab[INCLUDE_HASHSIZE];
+       struct bypass_dir *p;
+       bypass_slot = &bypass_hashtab[hashf ((U_CHAR *) fbeg, flen,
+                                            INCLUDE_HASHSIZE)];
+       for (p = *bypass_slot; p; p = p->next)
+         if (!strcmp (fbeg, p->fname)) {
+           searchptr = p->searchptr;
+           bypass_slot = 0;
+           break;
+         }
       }
-      strncat (fname, (char *) fbeg, flen);
+
+      strcpy (fname, searchptr->fname);
+      strcat (fname, fbeg);
 #ifdef VMS
       /* Change this 1/2 Unix 1/2 VMS file specification into a
          full VMS file specification */
-      if (searchptr->fname && (searchptr->fname[0] != 0)) {
+      if (searchptr->fname[0]) {
        /* Fix up the filename */
        hack_vms_include_specification (fname);
       } else {
        /* This is a normal VMS filespec, so use it unchanged.  */
-       strncpy (fname, fbeg, flen);
-       fname[flen] = 0;
+       strcpy (fname, fbeg);
        /* if it's '#include filename', add the missing .h */
        if (index(fname,'.')==NULL) {
          strcat (fname, ".h");
        }
       }
 #endif /* VMS */
-      /* ??? There are currently 3 separate mechanisms for avoiding processing
-        of redundant include files: #import, #pragma once, and
-        redundant_include_p.  It would be nice if they were unified.  */
-      if (redundant_include_p (fname))
-       return 0;
-      if (importing)
-       f = lookup_import (fname, searchptr);
-      else
-       f = open_include_file (fname, searchptr);
-      if (f == -2)
-       return 0;                       /* Already included this file */
-#ifdef EACCES
-      else if (f == -1 && errno == EACCES)
-       warning ("Header file %s exists, but is not readable", fname);
-#endif
-      if (f >= 0)
+      f = open_include_file (fname, searchptr, importing, &inc);
+      if (f != -1) {
+       if (bypass_slot && searchptr != first_bracket_include) {
+         /* This is the first time we found this include file,
+            and we found it after first_bracket_include.
+            Record its location so that we can bypass to here next time.  */
+         struct bypass_dir *p
+           = (struct bypass_dir *) xmalloc (sizeof (struct bypass_dir));
+         p->next = *bypass_slot;
+         p->fname = fname + strlen (searchptr->fname);
+         p->searchptr = searchptr;
+         *bypass_slot = p;
+       }
+       break;
+      }
+#ifdef VMS
+      /* Our VMS hacks can produce invalid filespecs, so don't worry
+        about errors other than EACCES.  */
+      if (errno == EACCES)
        break;
+#else
+      if (errno != ENOENT)
+       break;
+#endif
     }
   }
 
+
   if (f < 0) {
-    /* A file that was not found.  */
 
-    strncpy (fname, (char *) fbeg, flen);
-    fname[flen] = 0;
+    if (f == -2) {
+      /* The file was already included.  */
+
     /* If generating dependencies and -MG was specified, we assume missing
        files are leaf files, living in the same directory as the source file
        or other similar place; these missing files may be generated from
        other files and may not exist yet (eg: y.tab.h).  */
-    if (print_deps_missing_files
-       && print_deps > (angle_brackets || (system_include_depth > 0)))
+    } else if (print_deps_missing_files
+              && (system_include_depth != 0) < print_deps)
       {
        /* If it was requested as a system header file,
           then assume it belongs in the first place to look for such.  */
        if (angle_brackets)
          {
-           for (searchptr = search_start; searchptr; searchptr = searchptr->next)
-             {
-               if (searchptr->fname)
-                 {
-                   char *p;
-
-                   if (searchptr->fname[0] == 0)
-                     continue;
-                   p = xmalloc (strlen (searchptr->fname)
-                                + strlen (fname) + 2);
-                   strcpy (p, searchptr->fname);
-                   strcat (p, "/");
-                   strcat (p, fname);
-                   deps_output (p, ' ');
-                   free (p);
-                   break;
-                 }
-             }
+           if (search_start) {
+             char *p = (char *) alloca (strlen (search_start->fname)
+                                        + strlen (fbeg) + 1);
+             strcpy (p, search_start->fname);
+             strcat (p, fbeg);
+             deps_output (p, ' ');
+           }
          }
        else
          {
            /* Otherwise, omit the directory, as if the file existed
               in the directory with the source.  */
-           deps_output (fname, ' ');
+           deps_output (fbeg, ' ');
          }
       }
     /* If -M was specified, and this header file won't be added to the
@@ -4596,59 +4512,16 @@ get_filename:
        still produce correct output.  Otherwise, we can't produce correct
        output, because there may be dependencies we need inside the missing
        file, and we don't know what directory this missing file exists in.  */
-    else if (print_deps
-       && (print_deps <= (angle_brackets || (system_include_depth > 0))))
-      warning ("No include path in which to find %s", fname);
-    else if (search_start)
-      error_from_errno (fname);
+    else if (0 < print_deps  &&  print_deps <= (system_include_depth != 0))
+      warning ("No include path in which to find %s", fbeg);
+    else if (f != -3)
+      error_from_errno (fbeg);
     else
-      error ("No include path in which to find %s", fname);
-  } else {
-    /* Check to see if this include file is a once-only include file.
-       If so, give up.  */
+      error ("No include path in which to find %s", fbeg);
 
-    struct file_name_list* ptr;
-
-    for (ptr = dont_repeat_files; ptr; ptr = ptr->next) {
-      if (!strcmp (ptr->fname, fname)) {
-       close (f);
-        return 0;                              /* This file was once'd. */
-      }
-    }
-
-    for (ptr = all_include_files; ptr; ptr = ptr->next) {
-      if (!strcmp (ptr->fname, fname))
-        break;                         /* This file was included before. */
-    }
-
-    if (ptr == 0) {
-      /* This is the first time for this file.  */
-      /* Add it to list of files included.  */
-
-      ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
-      ptr->control_macro = 0;
-      ptr->c_system_include_path = 0;
-      ptr->next = all_include_files;
-      all_include_files = ptr;
-      ptr->fname = savestring (fname);
-      ptr->got_name_map = 0;
-
-      /* For -M, add this file to the dependencies.  */
-      if (print_deps > (angle_brackets || (system_include_depth > 0)))
-       deps_output (fname, ' ');
-    }   
-
-    /* Handle -H option.  */
-    if (print_include_names) {
-      output_dots (stderr, indepth);
-      fprintf (stderr, "%s\n", fname);
-    }
-
-    if (angle_brackets)
-      system_include_depth++;
+  } else {
 
     /* Actually process the file.  */
-    add_import (f, fname);     /* Record file on "seen" list for #import. */
 
     pcftry = (char *) alloca (strlen (fname) + 30);
     pcfbuf = 0;
@@ -4656,10 +4529,6 @@ get_filename:
 
     if (!no_precomp)
       {
-       struct stat stat_f;
-
-       fstat (f, &stat_f);
-
        do {
          sprintf (pcftry, "%s%d", fname, pcfnum++);
 
@@ -4668,12 +4537,12 @@ get_filename:
            {
              struct stat s;
 
-             fstat (pcf, &s);
-             if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
-                       sizeof (s.st_ino))
-                 || stat_f.st_dev != s.st_dev)
+             if (fstat (pcf, &s) != 0)
+               pfatal_with_name (pcftry);
+             if (! INO_T_EQ (inc->st.st_ino, s.st_ino)
+                 || inc->st.st_dev != s.st_dev)
                {
-                 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
+                 pcfbuf = check_precompiled (pcf, &s, fname, &pcfbuflimit);
                  /* Don't need it any more.  */
                  close (pcf);
                }
@@ -4695,28 +4564,11 @@ get_filename:
                  (U_CHAR *) fname, op);
     }
     else
-      finclude (f, fname, op, is_system_include (fname), searchptr);
-
-    if (angle_brackets)
-      system_include_depth--;
+      finclude (f, inc, op, is_system_include (fname), searchptr);
   }
-  return 0;
-}
 
-/* Return nonzero if there is no need to include file NAME
-   because it has already been included and it contains a conditional
-   to make a repeated include do nothing.  */
+  system_include_depth -= angle_brackets;
 
-static int
-redundant_include_p (name)
-     char *name;
-{
-  struct file_name_list *l = all_include_files;
-  for (; l; l = l->next)
-    if (! strcmp (name, l->fname)
-       && l->control_macro
-       && lookup (l->control_macro, -1, -1))
-      return 1;
   return 0;
 }
 
@@ -4739,23 +4591,116 @@ is_system_include (filename)
 
   for (searchptr = first_system_include; searchptr;
        searchptr = searchptr->next)
-    if (searchptr->fname) {
-      register char *sys_dir = searchptr->fname;
-      register unsigned length = strlen (sys_dir);
+    if (! strncmp (searchptr->fname, filename, strlen (searchptr->fname)))
+      return searchptr->c_system_include_path + 1;
+  return 0;
+}
+\f
+/* Yield the non-directory suffix of a file name.  */
 
-      if (! strncmp (sys_dir, filename, length)
-         && (filename[length] == '/'
+static char *
+base_name (fname)
+     char *fname;
+{
+  char *s = fname;
+  char *p;
+#if defined (__MSDOS__) || defined (_WIN32)
+  if (isalpha (s[0]) && s[1] == ':') s += 2;
+#endif
+#ifdef VMS
+  if ((p = rindex (s, ':'))) s = p + 1;        /* Skip device.  */
+  if ((p = rindex (s, ']'))) s = p + 1;        /* Skip directory.  */
+  if ((p = rindex (s, '>'))) s = p + 1;        /* Skip alternate (int'n'l) dir.  */
+  if (s != fname)
+    return s;
+#endif
+  if ((p = rindex (s, '/'))) s = p + 1;
 #ifdef DIR_SEPARATOR
-             || filename[length] == DIR_SEPARATOR
+  if ((p = rindex (s, DIR_SEPARATOR))) s = p + 1;
 #endif
-             )) {
-       if (searchptr->c_system_include_path)
-         return 2;
-       else
-         return 1;
+  return s;
+}
+
+/* Yield nonzero if FILENAME is absolute (i.e. not relative).  */
+static int
+absolute_filename (filename)
+     char *filename;
+{
+#if defined (__MSDOS__) || defined (_WIN32)
+  if (isalpha (filename[0]) && filename[1] == ':') filename += 2;
+#endif
+  if (filename[0] == '/') return 1;
+#ifdef DIR_SEPARATOR
+  if (filename[0] == DIR_SEPARATOR) return 1;
+#endif
+  return 0;
+}
+
+/* Remove unnecessary characters from FILENAME in place,
+   to avoid unnecessary filename aliasing.
+   Return the length of the resulting string.
+
+   Do only the simplifications allowed by Posix.
+   It is OK to miss simplifications on non-Posix hosts,
+   since this merely leads to suboptimial results.  */
+
+static size_t
+simplify_filename (filename)
+     char *filename;
+{
+  register char *from = filename;
+  register char *to = filename;
+  char *to0;
+
+  /* Remove redundant initial /s.  */
+  if (*from == '/') {
+    *to++ = '/';
+    if (*++from == '/') {
+      if (*++from == '/') {
+       /* 3 or more initial /s are equivalent to 1 /.  */
+       while (*++from == '/')
+         continue;
+      } else {
+       /* On some hosts // differs from /; Posix allows this.  */
+       static int slashslash_vs_slash;
+       if (slashslash_vs_slash == 0) {
+         struct stat s1, s2;
+         slashslash_vs_slash = ((stat ("/", &s1) == 0 && stat ("//", &s2) == 0
+                                 && INO_T_EQ (s1.st_ino, s2.st_ino)
+                                 && s1.st_dev == s2.st_dev)
+                                ? 1 : -1);
+       }
+       if (slashslash_vs_slash < 0)
+         *to++ = '/';
       }
     }
-  return 0;
+  }
+  to0 = to;
+
+  for (;;) {
+    if (from[0] == '.' && from[1] == '/')
+      from += 2;
+    else {
+      /* Copy this component and trailing /, if any.  */
+      while ((*to++ = *from++) != '/') {
+       if (!to[-1]) {
+         /* Trim . component at end of nonempty name.  */
+         to -= filename <= to - 3 && to[-3] == '/' && to[-2] == '.';
+
+         /* Trim unnecessary trailing /s.  */
+         while (to0 < --to && to[-1] == '/')
+           continue;
+
+         *to = 0;
+         return to - filename;
+       }
+      }
+    }
+
+    /* Skip /s after a /.  */
+    while (*from == '/')
+      from++;
+  }
 }
 \f
 /* The file_name_map structure holds a mapping of file names for a
@@ -4807,7 +4752,9 @@ read_filename_string (ch, f)
   return alloc;
 }
 
-/* Read the file name map file for DIRNAME.  */
+/* Read the file name map file for DIRNAME.
+   If DIRNAME is empty, read the map file for the working directory;
+   otherwise DIRNAME must end in '/'.  */
 
 static struct file_name_map *
 read_name_map (dirname)
@@ -4825,6 +4772,7 @@ read_name_map (dirname)
   register struct file_name_map_list *map_list_ptr;
   char *name;
   FILE *f;
+  size_t dirlen;
 
   for (map_list_ptr = map_list; map_list_ptr;
        map_list_ptr = map_list_ptr->map_list_next)
@@ -4836,10 +4784,9 @@ read_name_map (dirname)
   map_list_ptr->map_list_name = savestring (dirname);
   map_list_ptr->map_list_map = NULL;
 
-  name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
+  dirlen = strlen (dirname);
+  name = (char *) alloca (dirlen + strlen (FILE_NAME_MAP_FILE) + 1);
   strcpy (name, dirname);
-  if (*dirname)
-    strcat (name, "/");
   strcat (name, FILE_NAME_MAP_FILE);
   f = fopen (name, "r");
   if (!f)
@@ -4847,12 +4794,12 @@ read_name_map (dirname)
   else
     {
       int ch;
-      int dirlen = strlen (dirname);
 
       while ((ch = getc (f)) != EOF)
        {
          char *from, *to;
          struct file_name_map *ptr;
+         size_t tolen;
 
          if (is_space[ch])
            continue;
@@ -4861,19 +4808,21 @@ read_name_map (dirname)
            ;
          to = read_filename_string (ch, f);
 
+         simplify_filename (from);
+         tolen = simplify_filename (to);
+
          ptr = ((struct file_name_map *)
                 xmalloc (sizeof (struct file_name_map)));
          ptr->map_from = from;
 
          /* Make the real filename absolute.  */
-         if (*to == '/')
+         if (absolute_filename (to))
            ptr->map_to = to;
          else
            {
-             ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
+             ptr->map_to = xmalloc (dirlen + tolen + 1);
              strcpy (ptr->map_to, dirname);
-             ptr->map_to[dirlen] = '/';
-             strcpy (ptr->map_to + dirlen + 1, to);
+             strcat (ptr->map_to, to);
              free (to);
            }         
 
@@ -4894,85 +4843,153 @@ read_name_map (dirname)
 }  
 
 /* Try to open include file FILENAME.  SEARCHPTR is the directory
-   being tried from the include file search path.  This function maps
-   filenames on file systems based on information read by
+   being tried from the include file search path.
+   IMPORTING is "" if we are importing, null otherwise.
+   Return -2 if found, either a matching name or a matching inode.
+   Otherwise, open the file and return a file descriptor if successful
+   or -1 if unsuccessful.
+   Unless unsuccessful, put a descriptor of the included file into *PINC.
+   This function maps filenames on file systems based on information read by
    read_name_map.  */
 
 static int
-open_include_file (filename, searchptr)
+open_include_file (filename, searchptr, importing, pinc)
+     char *filename;
+     struct file_name_list *searchptr;
+     U_CHAR *importing;
+     struct include_file **pinc;
+{
+  char *fname = remap_include_file (filename, searchptr);
+  int fd = -2;
+
+  /* Look up FNAME in include_hashtab.  */
+  struct include_file **phead = &include_hashtab[hashf ((U_CHAR *) fname,
+                                                       strlen (fname),
+                                                       INCLUDE_HASHSIZE)];
+  struct include_file *inc, *head = *phead;
+  for (inc = head; inc; inc = inc->next)
+    if (!strcmp (fname, inc->fname))
+      break;
+
+  if (!inc
+      || ! inc->control_macro
+      || (inc->control_macro[0] && ! lookup (inc->control_macro, -1, -1))) {
+
+    fd = open (fname, O_RDONLY, 0);
+
+    if (fd < 0)
+      return fd;
+
+    if (!inc) {
+      /* FNAME was not in include_hashtab; insert a new entry.  */
+      inc = (struct include_file *) xmalloc (sizeof (struct include_file));
+      inc->next = head;
+      inc->fname = fname;
+      inc->control_macro = 0;
+      inc->deps_output = 0;
+      if (fstat (fd, &inc->st) != 0)
+       pfatal_with_name (fname);
+      *phead = inc;
+
+      /* Look for another file with the same inode and device.  */
+      if (lookup_ino_include (inc)
+         && inc->control_macro
+         && (!inc->control_macro[0] || lookup (inc->control_macro, -1, -1))) {
+       close (fd);
+       fd = -2;
+      }
+    }
+
+    /* For -M, add this file to the dependencies.  */
+    if (! inc->deps_output  &&  (system_include_depth != 0) < print_deps) {
+      inc->deps_output = 1;
+      deps_output (fname, ' ');
+    }   
+
+    /* Handle -H option.  */
+    if (print_include_names)
+      fprintf (stderr, "%*s%s\n", indepth, "", fname);
+  }
+
+  if (importing)
+    inc->control_macro = importing;
+
+  *pinc = inc;
+  return fd;
+}
+
+/* Return the remapped name of the the include file FILENAME.
+   SEARCHPTR is the directory being tried from the include file path.  */
+
+static char *
+remap_include_file (filename, searchptr)
      char *filename;
      struct file_name_list *searchptr;
 {
   register struct file_name_map *map;
   register char *from;
-  char *p, *dir;
-
-  if (searchptr && ! searchptr->got_name_map)
-    {
-      searchptr->name_map = read_name_map (searchptr->fname
-                                          ? searchptr->fname : ".");
-      searchptr->got_name_map = 1;
-    }
 
-  /* First check the mapping for the directory we are using.  */
-  if (searchptr && searchptr->name_map)
+  if (searchptr)
     {
-      from = filename;
-      if (searchptr->fname)
-       from += strlen (searchptr->fname) + 1;
-      for (map = searchptr->name_map; map; map = map->map_next)
+      if (! searchptr->got_name_map)
        {
-         if (! strcmp (map->map_from, from))
-           {
-             /* Found a match.  */
-             return open (map->map_to, O_RDONLY, 0666);
-           }
+         searchptr->name_map = read_name_map (searchptr->fname);
+         searchptr->got_name_map = 1;
        }
-    }
 
-  /* Try to find a mapping file for the particular directory we are
-     looking in.  Thus #include <sys/types.h> will look up sys/types.h
-     in /usr/include/header.gcc and look up types.h in
-     /usr/include/sys/header.gcc.  */
-  p = rindex (filename, '/');
-#ifdef DIR_SEPARATOR
-  if (! p) p = rindex (filename, DIR_SEPARATOR);
-  else {
-    char *tmp = rindex (filename, DIR_SEPARATOR);
-    if (tmp != NULL && tmp > p) p = tmp;
-  }
-#endif
-  if (! p)
-    p = filename;
-  if (searchptr
-      && searchptr->fname
-      && strlen (searchptr->fname) == p - filename
-      && ! strncmp (searchptr->fname, filename, p - filename))
-    {
-      /* FILENAME is in SEARCHPTR, which we've already checked.  */
-      return open (filename, O_RDONLY, 0666);
+      /* Check the mapping for the directory we are using.  */
+      from = filename + strlen (searchptr->fname);
+      for (map = searchptr->name_map; map; map = map->map_next)
+       if (! strcmp (map->map_from, from))
+         return map->map_to;
     }
 
-  if (p == filename)
+  from = base_name (filename);
+
+  if (from != filename || !searchptr)
     {
-      dir = ".";
-      from = filename;
+      /* Try to find a mapping file for the particular directory we are
+        looking in.  Thus #include <sys/types.h> will look up sys/types.h
+        in /usr/include/header.gcc and look up types.h in
+        /usr/include/sys/header.gcc.  */
+
+      char *dir = (char *) alloca (from - filename + 1);
+      bcopy (filename, dir, from - filename);
+      dir[from - filename] = '\0';
+
+      for (map = read_name_map (dir); map; map = map->map_next)
+       if (! strcmp (map->map_from, from))
+         return map->map_to;
     }
-  else
-    {
-      dir = (char *) alloca (p - filename + 1);
-      bcopy (filename, dir, p - filename);
-      dir[p - filename] = '\0';
-      from = p + 1;
+
+  return filename;
+}
+
+/* Insert INC into the include file table, hashed by device and inode number.
+   If a file with different name but same dev+ino was already in the table,
+   return 1 and set INC's control macro to the already-known macro.  */
+
+static int
+lookup_ino_include (inc)
+     struct include_file *inc;
+{
+  int hash = ((unsigned) (inc->st.st_dev + INO_T_HASH (inc->st.st_ino))
+             % INCLUDE_HASHSIZE);
+  struct include_file *i = include_ino_hashtab[hash];
+  inc->next_ino = i;
+  include_ino_hashtab[hash] = inc;
+
+  for (; i; i = i->next_ino)
+    if (INO_T_EQ (inc->st.st_ino, i->st.st_ino)
+       && inc->st.st_dev == i->st.st_dev) {
+      inc->control_macro = i->control_macro;
+      return 1;
     }
-  for (map = read_name_map (dir); map; map = map->map_next)
-    if (! strcmp (map->map_from, from))
-      return open (map->map_to, O_RDONLY, 0666);
 
-  return open (filename, O_RDONLY, 0666);
+  return 0;
 }
 \f
-/* Process the contents of include file FNAME, already open on descriptor F,
+/* Process file descriptor F, which corresponds to include file INC,
    with output to OP.
    SYSTEM_HEADER_P is 1 if this file resides in any one of the known
    "system" include directories (as decided by the `is_system_include'
@@ -4981,47 +4998,40 @@ open_include_file (filename, searchptr)
    or 0 if the file name was absolute.  */
 
 static void
-finclude (f, fname, op, system_header_p, dirptr)
+finclude (f, inc, op, system_header_p, dirptr)
      int f;
-     char *fname;
+     struct include_file *inc;
      FILE_BUF *op;
      int system_header_p;
      struct file_name_list *dirptr;
 {
-  int st_mode;
-  long st_size;
-  long i;
+  char *fname = inc->fname;
+  int i;
   FILE_BUF *fp;                        /* For input stack frame */
   int missing_newline = 0;
 
   CHECK_DEPTH (return;);
 
-  if (file_size_and_mode (f, &st_mode, &st_size) < 0)
-    {
-      perror_with_name (fname);
-      close (f);
-      return;
-    }
-
   fp = &instack[indepth + 1];
   bzero ((char *) fp, sizeof (FILE_BUF));
   fp->nominal_fname = fp->fname = fname;
+  fp->inc = inc;
   fp->length = 0;
   fp->lineno = 1;
   fp->if_stack = if_stack;
   fp->system_header_p = system_header_p;
   fp->dir = dirptr;
 
-  if (S_ISREG (st_mode)) {
-    fp->buf = (U_CHAR *) xmalloc (st_size + 2);
+  if (S_ISREG (inc->st.st_mode)) {
+    fp->buf = (U_CHAR *) xmalloc (inc->st.st_size + 2);
     fp->bufp = fp->buf;
 
-    /* Read the file contents, knowing that st_size is an upper bound
+    /* Read the file contents, knowing that inc->st.st_size is an upper bound
        on the number of bytes we can read.  */
-    fp->length = safe_read (f, (char *) fp->buf, st_size);
+    fp->length = safe_read (f, (char *) fp->buf, inc->st.st_size);
     if (fp->length < 0) goto nope;
   }
-  else if (S_ISDIR (st_mode)) {
+  else if (S_ISDIR (inc->st.st_mode)) {
     error ("directory `%s' specified in #include", fname);
     close (f);
     return;
@@ -5031,8 +5041,8 @@ finclude (f, fname, op, system_header_p, dirptr)
        copy them into buffer on stack. */
 
     int bsize = 2000;
+    int st_size = 0;
 
-    st_size = 0;
     fp->buf = (U_CHAR *) xmalloc (bsize + 2);
 
     for (;;) {
@@ -5091,129 +5101,25 @@ finclude (f, fname, op, system_header_p, dirptr)
   free (fp->buf);
 }
 
-/* Record that inclusion of the file named FILE
+/* Record that inclusion of the include file INC
    should be controlled by the macro named MACRO_NAME.
    This means that trying to include the file again
    will do something if that macro is defined.  */
 
 static void
-record_control_macro (file, macro_name)
-     char *file;
+record_control_macro (inc, macro_name)
+     struct include_file *inc;
      U_CHAR *macro_name;
 {
-  struct file_name_list *new;
-
-  for (new = all_include_files; new; new = new->next) {
-    if (!strcmp (new->fname, file)) {
-      new->control_macro = macro_name;
-      return;
-    }
-  }
-
-  /* If the file is not in all_include_files, something's wrong.  */
-  abort ();
-}
-\f
-/* Maintain and search list of included files, for #import.  */
-
-#define IMPORT_HASH_SIZE 31
-
-struct import_file {
-  char *name;
-  ino_t inode;
-  dev_t dev;
-  struct import_file *next;
-};
-
-/* Hash table of files already included with #include or #import.  */
-
-static struct import_file *import_hash_table[IMPORT_HASH_SIZE];
-
-/* Hash a file name for import_hash_table.  */
-
-static int 
-import_hash (f)
-     char *f;
-{
-  int val = 0;
-
-  while (*f) val += *f++;
-  return (val%IMPORT_HASH_SIZE);
-}
-
-/* Search for file FILENAME in import_hash_table.
-   Return -2 if found, either a matching name or a matching inode.
-   Otherwise, open the file and return a file descriptor if successful
-   or -1 if unsuccessful.  */
-
-static int
-lookup_import (filename, searchptr)
-     char *filename;
-     struct file_name_list *searchptr;
-{
-  struct import_file *i;
-  int h;
-  int hashval;
-  struct stat sb;
-  int fd;
-
-  hashval = import_hash (filename);
-
-  /* Attempt to find file in list of already included files */
-  i = import_hash_table[hashval];
-
-  while (i) {
-    if (!strcmp (filename, i->name))
-      return -2;               /* return found */
-    i = i->next;
-  }
-  /* Open it and try a match on inode/dev */
-  fd = open_include_file (filename, searchptr);
-  if (fd < 0)
-    return fd;
-  fstat (fd, &sb);
-  for (h = 0; h < IMPORT_HASH_SIZE; h++) {
-    i = import_hash_table[h];
-    while (i) {
-      /* Compare the inode and the device.
-        Supposedly on some systems the inode is not a scalar.  */
-      if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
-         && i->dev == sb.st_dev) {
-        close (fd);
-        return -2;             /* return found */
-      }
-      i = i->next;
-    }
-  }
-  return fd;                   /* Not found, return open file */
-}
-
-/* Add the file FNAME, open on descriptor FD, to import_hash_table.  */
-
-static void
-add_import (fd, fname)
-     int fd;
-     char *fname;
-{
-  struct import_file *i;
-  int hashval;
-  struct stat sb;
-
-  hashval = import_hash (fname);
-  fstat (fd, &sb);
-  i = (struct import_file *)xmalloc (sizeof (struct import_file));
-  i->name = xmalloc (strlen (fname)+1);
-  strcpy (i->name, fname);
-  bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
-  i->dev = sb.st_dev;
-  i->next = import_hash_table[hashval];
-  import_hash_table[hashval] = i;
+  if (!inc->control_macro || inc->control_macro[0])
+    inc->control_macro = macro_name;
 }
 \f
 /* Load the specified precompiled header into core, and verify its
    preconditions.  PCF indicates the file descriptor to read, which must
-   be a regular file.  FNAME indicates the file name of the original 
-   header.  *LIMIT will be set to an address one past the end of the file.
+   be a regular file.  *ST is its file status.
+   FNAME indicates the file name of the original header.
+   *LIMIT will be set to an address one past the end of the file.
    If the preconditions of the file are not satisfied, the buffer is 
    freed and we return 0.  If the preconditions are satisfied, return
    the address of the buffer following the preconditions.  The buffer, in
@@ -5222,27 +5128,23 @@ add_import (fd, fname)
    the run.
 */
 static char *
-check_precompiled (pcf, fname, limit)
+check_precompiled (pcf, st, fname, limit)
      int pcf;
+     struct stat *st;
      char *fname;
      char **limit;
 {
-  int st_mode;
-  long st_size;
   int length = 0;
   char *buf;
   char *cp;
 
   if (pcp_outfile)
     return 0;
-  
-  if (file_size_and_mode (pcf, &st_mode, &st_size) < 0)
-    return 0;
 
-  if (S_ISREG (st_mode))
+  if (S_ISREG (st->st_mode))
     {
-      buf = xmalloc (st_size + 2);
-      length = safe_read (pcf, buf, st_size);
+      buf = xmalloc (st->st_size + 2);
+      length = safe_read (pcf, buf, st->st_size);
       if (length < 0)
        goto nope;
     }
@@ -6024,7 +5926,7 @@ collect_expansion (buf, end, nargs, arglist)
          p++;
          concat_sharp_token_type = c;
          if (is_hor_space[*p]) {
-           concat_sharp_token_type++;
+           concat_sharp_token_type = c + 1;
            p++;
            SKIP_WHITE_SPACE (p);
          }
@@ -6038,7 +5940,7 @@ collect_expansion (buf, end, nargs, arglist)
          exp_p--;
          stringify_sharp_token_type = c;
          if (is_hor_space[*p]) {
-           stringify_sharp_token_type++;
+           stringify_sharp_token_type = c + 1;
            p++;
            SKIP_WHITE_SPACE (p);
          }
@@ -6081,9 +5983,12 @@ collect_expansion (buf, end, nargs, arglist)
             this must be -traditional.  So replace the comment with
             nothing at all.  */
          exp_p--;
-         p += 1;
-         while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
-           p++;
+         while (++p < limit) {
+           if (p[0] == '*' && p[1] == '/') {
+             p += 2;
+             break;
+           }
+         }
 #if 0
          /* Mark this as a concatenation-point, as if it had been ##.  */
          concat = p;
@@ -6677,7 +6582,7 @@ do_line (buf, limit, op, keyword)
       case '\\':
        {
          char *bpc = (char *) bp;
-         int c = parse_escape (&bpc);
+         HOST_WIDE_INT c = parse_escape (&bpc, (HOST_WIDE_INT) (U_CHAR) (-1));
          bp = (U_CHAR *) bpc;
          if (c < 0)
            p--;
@@ -6848,25 +6753,12 @@ static void
 do_once ()
 {
   int i;
-  FILE_BUF *ip = NULL;
 
   for (i = indepth; i >= 0; i--)
-    if (instack[i].fname != NULL) {
-      ip = &instack[i];
+    if (instack[i].inc) {
+      record_control_macro (instack[i].inc, (U_CHAR *) "");
       break;
     }
-
-  if (ip != NULL) {
-    struct file_name_list *new;
-    
-    new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
-    new->next = dont_repeat_files;
-    dont_repeat_files = new;
-    new->fname = savestring (ip->fname);
-    new->control_macro = 0;
-    new->got_name_map = 0;
-    new->c_system_include_path = 0;
-  }
 }
 
 /* #ident has already been copied to the output file, so just ignore it.  */
@@ -6925,8 +6817,9 @@ do_pragma (buf, limit, op, keyword)
   if (!strncmp ((char *) buf, "implementation", 14)) {
     /* Be quiet about `#pragma implementation' for a file only if it hasn't
        been included yet.  */
-    struct file_name_list *ptr;
-    U_CHAR *p = buf + 14, *fname, *inc_fname;
+
+    int h;
+    U_CHAR *p = buf + 14, *fname;
     SKIP_WHITE_SPACE (p);
     if (*p == '\n' || *p != '\"')
       return 0;
@@ -6935,15 +6828,16 @@ do_pragma (buf, limit, op, keyword)
     if ((p = (U_CHAR *) index ((char *) fname, '\"')))
       *p = '\0';
     
-    for (ptr = all_include_files; ptr; ptr = ptr->next) {
-      inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
-      inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
-      if (inc_fname && !strcmp ((char *) inc_fname, (char *) fname))
-       warning ("`#pragma implementation' for `%s' appears after file is included",
-                fname);
+    for (h = 0; h < INCLUDE_HASHSIZE; h++) {
+      struct include_file *inc;
+      for (inc = include_hashtab[h]; inc; inc = inc->next) {
+       if (!strcmp (base_name (inc->fname), (char *) fname)) {
+         warning ("`#pragma implementation' for \"%s\" appears after its #include",fname);
+         return 0;
+       }
+      }
     }
   }
-
   return 0;
 }
 
@@ -7081,6 +6975,7 @@ eval_if_expression (buf, length)
   pcp_inside_if = 0;
   delete_macro (save_defined); /* clean up special symbol */
 
+  temp_obuf.buf[temp_obuf.length] = '\n';
   value = parse_c_expression ((char *) temp_obuf.buf);
 
   free (temp_obuf.buf);
@@ -7149,10 +7044,12 @@ do_xifdef (buf, limit, op, keyword)
   } else {
     HASHNODE *hp;
 
-    if (pedantic && buf[0] >= '0' && buf[0] <= '9')
-      pedwarn ("`#%s' argument starts with a digit", keyword->name);
-    else if (end != limit && !traditional)
-      pedwarn ("garbage at end of `#%s' argument", keyword->name);
+    if (! traditional) {
+      if (isdigit (buf[0]))
+       pedwarn ("`#%s' argument starts with a digit", keyword->name);
+      else if (end != limit)
+       pedwarn ("garbage at end of `#%s' argument", keyword->name);
+    }
 
     hp = lookup (buf, end-buf, -1);
 
@@ -7341,23 +7238,33 @@ skip_if_group (ip, any, op)
          bp++;
        else if (*bp == '\\' && bp[1] == '\n')
          bp += 2;
-       else if (*bp == '/' && bp[1] == '*') {
-         bp += 2;
-         while (!(*bp == '*' && bp[1] == '/')) {
-           if (*bp == '\n')
-             ip->lineno++;
-           bp++;
-         }
-         bp += 2;
-       } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
-         bp += 2;
-         while (bp[-1] == '\\' || *bp != '\n') {
-           if (*bp == '\n')
-             ip->lineno++;
-           bp++;
-         }
-        }
-       else break;
+       else if (*bp == '/') {
+         if (bp[1] == '*') {
+           for (bp += 2; ; bp++) {
+             if (*bp == '\n')
+               ip->lineno++;
+             else if (*bp == '*') {
+               if (bp[-1] == '/' && warn_comments)
+                 warning ("`/*' within comment");
+               if (bp[1] == '/')
+                 break;
+             }
+           }
+           bp += 2;
+         } else if (bp[1] == '/' && cplusplus_comments) {
+           for (bp += 2; ; bp++) {
+             if (*bp == '\n') {
+               if (bp[-1] != '\\')
+                 break;
+               if (warn_comments)
+                 warning ("multiline `//' comment");
+               ip->lineno++;
+             }
+           }
+         } else
+           break;
+        } else
+         break;
       }
 
       cp = bp;
@@ -7438,7 +7345,7 @@ skip_if_group (ip, any, op)
          case T_ELSE:
          case T_ENDIF:
            if (pedantic && if_stack != save_if_stack)
-             validate_else (bp);
+             validate_else (bp, endb);
          case T_ELIF:
            if (if_stack == instack[indepth].if_stack) {
              error ("`#%s' not within a conditional", kt->name);
@@ -7599,7 +7506,7 @@ do_endif (buf, limit, op, keyword)
       if (indepth != 0
          && ! (indepth == 1 && no_record_file)
          && ! (no_record_file && no_output))
-       record_control_macro (ip->fname, temp->control_macro);
+       record_control_macro (ip->inc, temp->control_macro);
     fail: ;
     }
     free (temp);
@@ -7613,40 +7520,41 @@ do_endif (buf, limit, op, keyword)
    the directive name.  P points to the first char after the directive name.  */
 
 static void
-validate_else (p)
+validate_else (p, limit)
      register U_CHAR *p;
+     register U_CHAR *limit;
 {
   /* Advance P over whitespace and comments.  */
   while (1) {
-    if (*p == '\\' && p[1] == '\n')
+    while (*p == '\\' && p[1] == '\n')
       p += 2;
     if (is_hor_space[*p])
       p++;
     else if (*p == '/') {
-      if (p[1] == '\\' && p[2] == '\n')
-       newline_fix (p + 1);
-      if (p[1] == '*') {
+      while (p[1] == '\\' && p[2] == '\n')
        p += 2;
+      if (p[1] == '*') {
        /* Don't bother warning about unterminated comments
           since that will happen later.  Just be sure to exit.  */
-       while (*p) {
-         if (p[1] == '\\' && p[2] == '\n')
-           newline_fix (p + 1);
-         if (*p == '*' && p[1] == '/') {
-           p += 2;
-           break;
+       for (p += 2; ; p++) {
+         if (p == limit)
+           return;
+         if (*p == '*') {
+           while (p[1] == '\\' && p[2] == '\n')
+             p += 2;
+           if (p[1] == '/') {
+             p += 2;
+             break;
+           }
          }
-         p++;
        }
       }
-      else if (cplusplus_comments && p[1] == '/') {
-       p += 2;
-       while (*p && (*p != '\n' || p[-1] == '\\'))
-         p++;
-      }
+      else if (cplusplus_comments && p[1] == '/')
+       return;
+      else break;
     } else break;
   }
-  if (*p && *p != '\n')
+  if (*p != '\n')
     pedwarn ("text following `#else' or `#endif' violates ANSI standard");
 }
 \f
@@ -7669,54 +7577,38 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
 {
   register U_CHAR *limit = ip->buf + ip->length;
   register U_CHAR *bp = ip->bufp;
-  FILE_BUF *op = &outbuf;      /* JF */
-  int output = put_out_comments && !line_counter;
+  FILE_BUF *op = put_out_comments && !line_counter ? &outbuf : (FILE_BUF *) 0;
   int start_line = line_counter ? *line_counter : 0;
 
        /* JF this line_counter stuff is a crock to make sure the
           comment is only put out once, no matter how many times
           the comment is skipped.  It almost works */
-  if (output) {
+  if (op) {
     *op->bufp++ = '/';
-    *op->bufp++ = '*';
+    *op->bufp++ = bp[-1];
   }
   if (cplusplus_comments && bp[-1] == '/') {
-    if (output) {
-      while (bp < limit) {
+    for (; bp < limit; bp++) {
+      if (op)
        *op->bufp++ = *bp;
-       if (*bp == '\n' && bp[-1] != '\\')
+      if (*bp == '\n') {
+       if (bp[-1] != '\\')
          break;
-       if (*bp == '\n') {
+       if (!nowarn && warn_comments)
+         warning ("multiline `//' comment");
+       if (line_counter)
          ++*line_counter;
+       if (op)
          ++op->lineno;
-       }
-       bp++;
-      }
-      op->bufp[-1] = '*';
-      *op->bufp++ = '/';
-      *op->bufp++ = '\n';
-    } else {
-      while (bp < limit) {
-       if (bp[-1] != '\\' && *bp == '\n') {
-         break;
-       } else {
-         if (*bp == '\n' && line_counter)
-           ++*line_counter;
-         bp++;
-       }
       }
     }
     ip->bufp = bp;
     return bp;
   }
   while (bp < limit) {
-    if (output)
+    if (op)
       *op->bufp++ = *bp;
     switch (*bp++) {
-    case '/':
-      if (warn_comments && !nowarn && bp < limit && *bp == '*')
-       warning ("`/*' within comment");
-      break;
     case '\n':
       /* If this is the end of the file, we have an unterminated comment.
         Don't swallow the newline.  We are guaranteed that there will be a
@@ -7729,14 +7621,16 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
        }
       if (line_counter != NULL)
        ++*line_counter;
-      if (output)
+      if (op)
        ++op->lineno;
       break;
     case '*':
+      if (bp[-2] == '/' && !nowarn && warn_comments)
+       warning ("`/*' within comment");
       if (*bp == '\\' && bp[1] == '\n')
        newline_fix (bp);
       if (*bp == '/') {
-        if (output)
+        if (op)
          *op->bufp++ = '/';
        ip->bufp = ++bp;
        return bp;
@@ -7813,7 +7707,7 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
          *eofp = 1;
        break;
       }
-      if (pedantic || match == '\'') {
+      if (match == '\'') {
        error_with_line (line_for_error (start_line),
                         "unterminated string or character constant");
        bp--;
@@ -7824,8 +7718,12 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
       /* If not traditional, then allow newlines inside strings.  */
       if (count_newlines)
        ++*count_newlines;
-      if (multiline_string_line == 0)
+      if (multiline_string_line == 0) {
+       if (pedantic)
+         pedwarn_with_line (line_for_error (start_line),
+                            "string constant runs past end of line");
        multiline_string_line = start_line;
+      }
     } else if (c == match)
       break;
   }
@@ -8156,7 +8054,7 @@ macroexpand (hp, op)
       for (ap = defn->pattern; ap != NULL; ap = ap->next) {
        if (ap->stringify)
          xbuf_len += args[ap->argno].stringified_length;
-       else if (ap->raw_before || ap->raw_after || traditional)
+       else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional)
          /* Add 4 for two newline-space markers to prevent
             token concatenation.  */
          xbuf_len += args[ap->argno].raw_length + 4;
@@ -8202,9 +8100,9 @@ macroexpand (hp, op)
        /* If followed by an empty rest arg with concatenation,
           delete the last run of nonwhite chars.  */
        if (rest_zero && totlen > count_before
-           && ((ap->rest_args && ap->raw_before)
+           && ((ap->rest_args && ap->raw_before != 0)
                || (last_ap != NULL && last_ap->rest_args
-                   && last_ap->raw_after))) {
+                   && last_ap->raw_after != 0))) {
          /* Delete final whitespace.  */
          while (totlen > count_before && is_space[xbuf[totlen - 1]]) {
            totlen--;
@@ -8282,10 +8180,10 @@ macroexpand (hp, op)
          }
          if (!traditional)
            xbuf[totlen++] = '\"'; /* insert ending quote */
-       } else if (ap->raw_before || ap->raw_after || traditional) {
+       } else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional) {
          U_CHAR *p1 = arg->raw;
          U_CHAR *l1 = p1 + arg->raw_length;
-         if (ap->raw_before) {
+         if (ap->raw_before != 0) {
            while (p1 != l1 && is_space[*p1]) p1++;
            while (p1 != l1 && is_idchar[*p1])
              xbuf[totlen++] = *p1++;
@@ -8300,7 +8198,7 @@ macroexpand (hp, op)
            xbuf[totlen++] = '\n';
            xbuf[totlen++] = ' ';
          }
-         if (ap->raw_after) {
+         if (ap->raw_after != 0) {
            /* Arg is concatenated after: delete trailing whitespace,
               whitespace markers, and no-reexpansion markers.  */
            while (p1 != l1) {
@@ -8321,7 +8219,7 @@ macroexpand (hp, op)
 
          bcopy ((char *) p1, (char *) (xbuf + totlen), l1 - p1);
          totlen += l1 - p1;
-         if (!traditional && !ap->raw_after) {
+         if (!traditional && ap->raw_after == 0) {
            /* Ordinary expanded use of the argument.
               Put in newline-space markers to prevent token pasting.  */
            xbuf[totlen++] = '\n';
@@ -8366,7 +8264,7 @@ macroexpand (hp, op)
        if (exp[i] == ')')
          rest_zero = 0;
        if (! (rest_zero && last_ap != NULL && last_ap->rest_args
-              && last_ap->raw_after))
+              && last_ap->raw_after != 0))
          xbuf[totlen++] = exp[i];
       }
 
@@ -8394,6 +8292,7 @@ macroexpand (hp, op)
 
     ip2->fname = 0;
     ip2->nominal_fname = 0;
+    ip2->inc = 0;
     /* This may not be exactly correct, but will give much better error
        messages for nested macro calls than using a line number of zero.  */
     ip2->lineno = start_line;
@@ -8429,6 +8328,7 @@ macarg (argptr, rest_args)
   int paren = 0;
   int newlines = 0;
   int comments = 0;
+  char *result = 0;
 
   /* Try to parse as much of the argument as exists at this
      input stack level.  */
@@ -8461,8 +8361,8 @@ macarg (argptr, rest_args)
 
     while (bp == ip->buf + ip->length) {
       if (instack[indepth].macro == 0) {
-       free (buffer);
-       return "unterminated macro call";
+       result = "unterminated macro call";
+       break;
       }
       ip->macro->type = T_MACRO;
       if (ip->free_ptr)
@@ -8538,7 +8438,7 @@ macarg (argptr, rest_args)
     }
     argptr->stringified_length = totlen;
   }
-  return 0;
+  return result;
 }
 \f
 /* Scan text from START (inclusive) up to LIMIT (exclusive),
@@ -8588,29 +8488,33 @@ macarg1 (start, limit, depthptr, newlines, comments, rest_args)
     case '/':
       if (bp[1] == '\\' && bp[2] == '\n')
        newline_fix (bp + 1);
-      if (cplusplus_comments && bp[1] == '/') {
+      if (bp[1] == '*') {
        *comments = 1;
-       bp += 2;
-       while (bp < limit && (*bp != '\n' || bp[-1] == '\\')) {
-         if (*bp == '\n') ++*newlines;
-         bp++;
+       for (bp += 2; bp < limit; bp++) {
+         if (*bp == '\n')
+           ++*newlines;
+         else if (*bp == '*') {
+           if (bp[-1] == '/' && warn_comments)
+             warning ("`/*' within comment");
+           if (bp[1] == '\\' && bp[2] == '\n')
+             newline_fix (bp + 1);
+           if (bp[1] == '/') {
+             bp++;
+             break;
+           }
+         }
+       }
+      } else if (bp[1] == '/' && cplusplus_comments) {
+       *comments = 1;
+       for (bp += 2; bp < limit; bp++) {
+         if (*bp == '\n') {
+           ++*newlines;
+           if (bp[-1] != '\\')
+             break;
+           if (warn_comments)
+             warning ("multiline `//' comment");
+         }
        }
-       /* Now count the newline that we are about to skip.  */
-       ++*newlines;
-       break;
-      }
-      if (bp[1] != '*' || bp + 1 >= limit)
-       break;
-      *comments = 1;
-      bp += 2;
-      while (bp + 1 < limit) {
-       if (bp[0] == '*'
-           && bp[1] == '\\' && bp[2] == '\n')
-         newline_fix (bp + 1);
-       if (bp[0] == '*' && bp[1] == '/')
-         break;
-       if (*bp == '\n') ++*newlines;
-       bp++;
       }
       break;
     case '\'':
@@ -8990,6 +8894,22 @@ verror_with_line (line, msg, args)
 }
 
 static void
+#if defined (__STDC__) && defined (HAVE_VPRINTF)
+warning_with_line (int line, PRINTF_ALIST (msg))
+#else
+warning_with_line (line, PRINTF_ALIST (msg))
+     int line;
+     PRINTF_DCL (msg)
+#endif
+{
+  va_list args;
+
+  VA_START (args, msg);
+  vwarning_with_line (line, msg, args);
+  va_end (args);
+}
+
+static void
 vwarning_with_line (line, msg, args)
      int line;
      char *msg;
@@ -9013,7 +8933,7 @@ vwarning_with_line (line, msg, args)
     }
 
   if (ip != NULL)
-    fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
+    fprintf (stderr, line ? "%s:%d: " : "%s: ", ip->nominal_fname, line);
   fprintf (stderr, "warning: ");
   vfprintf (stderr, msg, args);
   fprintf (stderr, "\n");
@@ -9399,7 +9319,7 @@ dump_single_macro (hp, of)
         default: abort ();
        }
       }
-      if (ap->raw_before) {
+      if (ap->raw_before != 0) {
        if (concat) {
          switch (ap->raw_before) {
           case WHITE_SHARP_TOKEN:
@@ -9422,7 +9342,7 @@ dump_single_macro (hp, of)
       concat = 0;
     }
     dump_arg_n (defn, ap->argno, of);
-    if (!traditional && ap->raw_after) {
+    if (!traditional && ap->raw_after != 0) {
       switch (ap->raw_after) {
        case SHARP_TOKEN: fprintf (of, "##"); break;
        case WHITE_SHARP_TOKEN: fprintf (of, " ##"); break;
@@ -9580,6 +9500,8 @@ initialize_builtins (inp, outp)
           NULL_PTR, -1);
   install ((U_CHAR *) "__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE,
           NULL_PTR, -1);
+  install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE,
+          NULL_PTR, -1);
   install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
   if (!traditional) {
     install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
@@ -9590,6 +9512,7 @@ initialize_builtins (inp, outp)
 /*  This is supplied using a -D by the compiler driver
     so that it is present only when truly compiling with GNU C.  */
 /*  install ((U_CHAR *) "__GNUC__", -1, T_CONST, "2", -1);  */
+  install ((U_CHAR *) "__HAVE_BUILTIN_SETJMP__", -1, T_CONST, "1", -1);
 
   if (debug_output)
     {
@@ -9836,6 +9759,84 @@ make_assertion (option, str)
   --indepth;
 }
 \f
+/* The previous include prefix, if any, is PREV_FILE_NAME.
+   Allocate a new include prefix whose name is the
+   simplified concatenation of PREFIX and NAME,
+   with a trailing / added if needed.
+   But return 0 if the include prefix should be ignored,
+   e.g. because it is a duplicate of PREV_FILE_NAME.  */
+
+static struct file_name_list *
+new_include_prefix (prev_file_name, prefix, name)
+     struct file_name_list *prev_file_name;
+     char *prefix;
+     char *name;
+{
+  if (!name)
+    fatal ("Directory name missing after command line option");
+
+  if (!*name)
+    /* Ignore the empty string.  */
+    return 0;
+  else {
+    struct file_name_list *dir
+      = ((struct file_name_list *)
+        xmalloc (sizeof (struct file_name_list)
+                 + strlen (prefix) + strlen (name) + 1 /* for trailing / */));
+    size_t len;
+    strcpy (dir->fname, prefix);
+    strcat (dir->fname, name);
+    len = simplify_filename (dir->fname);
+
+    /* Convert directory name to a prefix.  */
+    if (dir->fname[len - 1] != '/') {
+      if (len == 1 && dir->fname[len - 1] == '.')
+       len = 0;
+      else
+       dir->fname[len++] = '/';
+      dir->fname[len] = 0;
+    }
+
+    /* Ignore a directory whose name matches the previous one.  */
+    if (prev_file_name && !strcmp (prev_file_name->fname, dir->fname)) {
+      /* But treat `-Idir -I- -Idir' as `-I- -Idir'.  */
+      if (!first_bracket_include)
+       first_bracket_include = prev_file_name;
+      free (dir);
+      return 0;
+    }
+
+#ifndef VMS
+    /* VMS can't stat dir prefixes, so skip these optimizations in VMS.  */
+
+    /* Ignore a nonexistent directory.  */
+    if (stat (len ? dir->fname : ".", &dir->st) != 0) {
+      if (errno != ENOENT && errno != ENOTDIR)
+       error_from_errno (dir->fname);
+      free (dir);
+      return 0;
+    }
+
+    /* Ignore a directory whose identity matches the previous one.  */
+    if (prev_file_name
+       && INO_T_EQ (prev_file_name->st.st_ino, dir->st.st_ino)
+       && prev_file_name->st.st_dev == dir->st.st_dev) {
+      /* But treat `-Idir -I- -Idir' as `-I- -Idir'.  */
+      if (!first_bracket_include)
+       first_bracket_include = prev_file_name;
+      free (dir);
+      return 0;
+    }
+#endif /* ! VMS */
+
+    dir->next = 0;
+    dir->c_system_include_path = 0;
+    dir->got_name_map = 0;
+
+    return dir;
+  }
+}
+
 /* Append a chain of `struct file_name_list's
    to the end of the main include chain.
    FIRST is the beginning of the chain to append, and LAST is the end.  */
@@ -9924,7 +9925,7 @@ fatal (PRINTF_ALIST (msg))
   vfprintf (stderr, msg, args);
   va_end (args);
   fprintf (stderr, "\n");
-  exit (FAILURE_EXIT_CODE);
+  exit (FATAL_EXIT_CODE);
 }
 
 /* More 'friendly' abort that prints the line and file.
@@ -9953,7 +9954,7 @@ pfatal_with_name (name)
 #ifdef VMS
   exit (vaxc$errno);
 #else
-  exit (FAILURE_EXIT_CODE);
+  exit (FATAL_EXIT_CODE);
 #endif
 }
 
@@ -10017,35 +10018,6 @@ savestring (input)
   return output;
 }
 \f
-/* Get the file-mode and data size of the file open on FD
-   and store them in *MODE_POINTER and *SIZE_POINTER.  */
-
-static int
-file_size_and_mode (fd, mode_pointer, size_pointer)
-     int fd;
-     int *mode_pointer;
-     long int *size_pointer;
-{
-  struct stat sbuf;
-
-  if (fstat (fd, &sbuf) < 0) return (-1);
-  if (mode_pointer) *mode_pointer = sbuf.st_mode;
-  if (size_pointer) *size_pointer = sbuf.st_size;
-  return 0;
-}
-
-static void
-output_dots (fd, depth)
-     FILE* fd;
-     int depth;
-{
-  while (depth > 0) {
-    putc ('.', fd);
-    depth--;
-  }
-}
-  
-\f
 #ifdef VMS
 
 /* Under VMS we need to fix up the "include" specification
@@ -10057,38 +10029,19 @@ hack_vms_include_specification (fname)
      char *fname;
 {
   register char *cp, *cp1, *cp2;
-  int f, check_filename_before_returning, no_prefix_seen;
+  int f, check_filename_before_returning;
   char Local[512];
 
   check_filename_before_returning = 0;
-  no_prefix_seen = 0;
-
-  /* Ignore leading "./"s */
-  while (fname[0] == '.' && fname[1] == '/') {
-    strcpy (fname, fname+2);
-    no_prefix_seen = 1;                /* mark this for later */
-  }
-  /* Look for the boundary between the VMS and UNIX filespecs */
-  cp = rindex (fname, ']');    /* Look for end of dirspec. */
-  if (cp == 0) cp = rindex (fname, '>'); /* ... Ditto              */
-  if (cp == 0) cp = rindex (fname, ':'); /* Look for end of devspec. */
-  if (cp) {
-    cp++;
-  } else {
-    cp = index (fname, '/');   /* Look for the "/" */
-  }
+
+  cp = base_name (fname);
 
   /*
    * Check if we have a vax-c style '#include filename'
    * and add the missing .h
    */
-  if (cp == 0) {
-    if (index(fname,'.') == 0)
-      strcat(fname, ".h");
-  } else {
-    if (index(cp,'.') == 0)
-      strcat(cp, ".h");
-  }
+  if (!index (cp,'.'))
+    strcat (cp, ".h");
 
   cp2 = Local;                 /* initialize */
 
@@ -10195,7 +10148,7 @@ hack_vms_include_specification (fname)
      to the user in that they can use both rooted and non-rooted logical names
      to point to the location of the file.  */
 
-  if (check_filename_before_returning && no_prefix_seen) {
+  if (check_filename_before_returning) {
     f = open (fname, O_RDONLY, 0666);
     if (f >= 0) {
       /* The file name is OK as it is, so return it as is.  */
@@ -10296,7 +10249,7 @@ fopen (fname, type)
 #undef fopen   /* Get back the REAL fopen routine */
   /* The gcc-vms-1.42 distribution's header files prototype fopen with two
      fixed arguments, which matches ANSI's specification but not VAXCRTL's
-     pre-ANSI implmentation.  This hack circumvents the mismatch problem.  */
+     pre-ANSI implementation.  This hack circumvents the mismatch problem.  */
   FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
 
   if (*type == 'w')
@@ -10315,26 +10268,6 @@ open (fname, flags, prot)
 #undef open    /* Get back the REAL open routine */
   return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef");
 }
-
-/* Avoid run-time library bug, where copying M out of N+M characters with
-   N >= 65535 results in VAXCRTL's strncat falling into an infinite loop.
-   gcc-cpp exercises this particular bug.  [Fixed in V5.5-2's VAXCRTL.]  */
-
-static char *
-strncat (dst, src, cnt)
-     char *dst;
-     const char *src;
-     unsigned cnt;
-{
-  register char *d = dst, *s = (char *) src;
-  register int n = cnt;        /* convert to _signed_ type */
-
-  while (*d) d++;      /* advance to end */
-  while (--n >= 0)
-    if (!(*d++ = *s++)) break;
-  if (n < 0) *d = '\0';
-  return dst;
-}
 \f
 /* more VMS hackery */
 #include <fab.h>
@@ -10354,12 +10287,13 @@ extern unsigned long sys$parse(), sys$search();
    bad enough, but then compounding the problem by reporting the reason for
    failure as "normal successful completion."  */
 
+#undef fstat   /* get back to library version */
+
 static int
-fstat (fd, statbuf)
+VMS_fstat (fd, statbuf)
      int fd;
      struct stat *statbuf;
 {
-#undef fstat
   int result = fstat (fd, statbuf);
 
   if (result < 0)
@@ -10368,7 +10302,7 @@ fstat (fd, statbuf)
       char nambuf[NAM$C_MAXRSS+1];
 
       if ((fp = fdopen (fd, "r")) != 0 && fgetname (fp, nambuf) != 0)
-       result = stat (nambuf, statbuf);
+       result = VMS_stat (nambuf, statbuf);
       /* No fclose(fp) here; that would close(fd) as well.  */
     }
 
@@ -10376,11 +10310,10 @@ fstat (fd, statbuf)
 }
 
 static int
-stat (name, statbuf)
+VMS_stat (name, statbuf)
      const char *name;
      struct stat *statbuf;
 {
-#undef stat
   int result = stat (name, statbuf);
 
   if (result < 0)