*** cccp.c.orig	Mon Nov  9 10:49:30 1992
--- cccp.c	Sat Nov 14 04:29:11 1992
***************
*** 223,228 ****
--- 223,238 ----
  static int do_unassert ();
  static int do_warning ();
  
+ void idir_initialize ();
+ void idir_do_defaults ();
+ void idir_do_standard_includes ();
+ void dump_include_dirs ();
+ void idir_add_to_end ();
+ void idir_add_path ();
+ void idir_add_to_cwd ();
+ void idir_add_to_cwd_path ();
+ void idir_reset_cwd_path ();
+ 
  static void add_import ();
  static void append_include_chain ();
  static void deps_output ();
***************
*** 229,235 ****
  static void make_undef ();
  static void make_definition ();
  static void make_assertion ();
- static void path_include ();
  static void initialize_builtins ();
  static void initialize_char_syntax ();
  static void dump_arg_n ();
--- 239,244 ----
***************
*** 371,377 ****
     dump_definitions means pass the whole definition (plus #define) through
  */
  
! static enum {dump_none, dump_only, dump_names, dump_definitions}
       dump_macros = dump_none;
  
  /* Nonzero means pass all #define and #undef directives which we actually
--- 380,386 ----
     dump_definitions means pass the whole definition (plus #define) through
  */
  
! static enum {dump_none, dump_only, dump_names, dump_definitions, dump_paths}
       dump_macros = dump_none;
  
  /* Nonzero means pass all #define and #undef directives which we actually
***************
*** 515,582 ****
    (((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED))   \
     ? grow_outbuf ((OBUF), (NEEDED)) : 0)
  
- 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;
-   };
- 
- /* #include "file" looks in source file dir, then stack. */
- /* #include <file> just looks in the stack. */
- /* -I directories are added to the end, then the defaults are added. */
- static struct default_include { char *fname; int cplusplus; } include_defaults_array[]
- #ifdef INCLUDE_DEFAULTS
-   = INCLUDE_DEFAULTS;
- #else
-   = {
-     /* Pick up GNU C++ specific include files.  */
-     { GPLUSPLUS_INCLUDE_DIR, 1},
-     { GCC_INCLUDE_DIR, 0},
- #ifdef CROSS_COMPILE
-     /* For cross-compilation, this dir name is generated
-        automatically in Makefile.in.  */
-     { CROSS_INCLUDE_DIR, 0 },
- #else /* not CROSS_COMPILE */
-     { LOCAL_INCLUDE_DIR, 0},
-     /* Some systems have an extra dir of include files.  */
- #ifdef SYSTEM_INCLUDE_DIR
-     { SYSTEM_INCLUDE_DIR, 0},
- #endif
-     { STANDARD_INCLUDE_DIR, 0},
- #endif /* not CROSS_COMPILE */
-     { 0, 0}
-     };
- #endif /* no INCLUDE_DEFAULTS */
- 
- /* The code looks at the defaults through this pointer, rather than through
-    the constant structure above.  This pointer gets changed if an environment
-    variable specifies other defaults.  */
- static struct default_include *include_defaults = include_defaults_array;
- 
- static struct file_name_list *include = 0;	/* First dir to search */
- 	/* First dir to search for <file> */
- /* This is the first element to use for #include <...>.
-    If it is 0, use the entire chain for such includes.  */
- static struct file_name_list *first_bracket_include = 0;
  /* This is the first element in the chain that corresponds to
     a directory of system header files.  */
  static struct file_name_list *first_system_include = 0;
- static struct file_name_list *last_include = 0;	/* Last in chain */
- 
- /* Chain of include directories to put at the end of the other chain.  */
- static struct file_name_list *after_include = 0;
- static struct file_name_list *last_after_include = 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.  */
--- 524,532 ----
***************
*** 1008,1013 ****
--- 958,965 ----
    cplusplus = 0;
    cplusplus_comments = 0;
  
+   idir_initialize();
+ 
    bzero (pend_files, argc * sizeof (char *));
    bzero (pend_defs, argc * sizeof (char *));
    bzero (pend_undefs, argc * sizeof (char *));
***************
*** 1048,1069 ****
  	}
  	/* 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;
  	  if (i + 1 == argc)
  	    fatal ("Directory name missing after -idirafter option");
  	  else
! 	    dirtmp->fname = argv[++i];
! 
! 	  if (after_include == 0)
! 	    after_include = dirtmp;
  	  else
! 	    last_after_include->next = dirtmp;
! 	  last_after_include = dirtmp; /* Tail follows the last one */
  	}
  	break;
  
--- 1000,1017 ----
  	}
  	/* Add directory to end of path for includes.  */
  	if (!strcmp (argv[i], "-idirafter")) {
  	  if (i + 1 == argc)
  	    fatal ("Directory name missing after -idirafter option");
  	  else
! 	   idir_add_to_end(argv[++i]);
!        }
! 	/* Add directory to end of current source directory path.  */
! 	/* The directory may be a colon separated list of directories */
! 	if (!strcmp (argv[i], "-isource")) {
! 	  if (i + 1 == argc)
! 	    fatal ("Directory name missing after -isource option");
  	  else
! 	    idir_add_to_cwd_path(argv[++i]);
  	}
  	break;
  
***************
*** 1199,1204 ****
--- 1147,1156 ----
  	    case 'D':
  	      dump_macros = dump_definitions;
  	      break;
+ 	    case 'P':
+ 	      dump_macros = dump_paths;
+ 	      no_output = 1;
+ 	      break;
  	    }
  	  }
  	}
***************
*** 1289,1313 ****
  
        case 'I':			/* Add directory to path for includes.  */
  	{
! 	  struct file_name_list *dirtmp;
! 
! 	  if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) {
  	    ignore_srcdir = 1;
- 	    /* Don't use any preceding -I directories for #include <...>.  */
- 	    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;
  	    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];
! 	    append_include_chain (dirtmp, dirtmp);
  	  }
  	}
  	break;
--- 1241,1255 ----
  
        case 'I':			/* Add directory to path for includes.  */
  	{
!           if (! ignore_srcdir && !strcmp (argv[i] + 2, "-"))
  	    ignore_srcdir = 1;
  	  else {
  	    if (argv[i][2] != 0)
! 	      idir_add (argv[i] + 2);
  	    else if (i + 1 == argc)
  	      fatal ("Directory name missing after -I option");
  	    else
! 	      idir_add (argv[++i]);
  	  }
  	}
  	break;
***************
*** 1314,1322 ****
--- 1256,1267 ----
  
        case 'n':
  	if (!strcmp (argv[i], "-nostdinc"))
+ 	  {
  	  /* -nostdinc causes no default include directories.
  	     You must specify all include-file directories with -I.  */
  	  no_standard_includes = 1;
+ 	  idir_reset_cwd_path();
+ 	}
  	else if (!strcmp (argv[i], "-nostdinc++"))
  	  /* -nostdinc++ causes no default C++-specific include directories. */
  	  no_standard_cplusplus_includes = 1;
***************
*** 1345,1360 ****
      }
    }
  
-   /* Add dirs from CPATH after dirs from -I.  */
-   /* There seems to be confusion about what CPATH should do,
-      so for the moment it is not documented.  */
-   /* Some people say that CPATH should replace the standard include dirs,
-      but that seems pointless: it comes before them, so it overrides them
-      anyway.  */
-   p = (char *) getenv ("CPATH");
-   if (p != 0 && ! no_standard_includes)
-     path_include (p);
- 
    /* Now that dollars_in_ident is known, initialize is_idchar.  */
    initialize_char_syntax ();
  
--- 1290,1295 ----
***************
*** 1474,1599 ****
  
    done_initializing = 1;
  
!   { /* read the appropriate environment variable and if it exists
!        replace include_defaults with the listed path. */
!     char *epath = 0;
!     switch ((objc << 1) + cplusplus)
!       {
!       case 0:
! 	epath = getenv ("C_INCLUDE_PATH");
! 	break;
!       case 1:
! 	epath = getenv ("CPLUS_INCLUDE_PATH");
! 	break;
!       case 2:
! 	epath = getenv ("OBJC_INCLUDE_PATH");
! 	break;
!       case 3:
! 	epath = getenv ("OBJCPLUS_INCLUDE_PATH");
! 	break;
!       }
!     /* 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;
! 
!       for (num_dirs = 1, startp = epath; *startp; startp++)
! 	if (*startp == PATH_SEPARATOR)
! 	  num_dirs++;
!       include_defaults
! 	= (struct default_include *) xmalloc ((num_dirs
! 					       * sizeof (struct default_include))
! 					      + sizeof (include_defaults_array));
!       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);
! 	  include_defaults[num_dirs].cplusplus = cplusplus;
! 	  num_dirs++;
! 	  if (*endp == '\0')
! 	    break;
! 	  endp = startp = endp + 1;
! 	} else
! 	  endp++;
!       }
!       /* Put the usual defaults back in at the end.  */
!       bcopy (include_defaults_array, &include_defaults[num_dirs],
! 	     sizeof (include_defaults_array));
!     }
!   }
! 
!   first_system_include = 0;
!   /* Unless -fnostdinc,
!      tack on the standard include file dirs to the specified list */
!   if (!no_standard_includes) {
!     struct default_include *p = include_defaults;
!     char *specd_prefix = include_prefix;
!     char *default_prefix = savestring (GCC_INCLUDE_DIR);
!     int default_len = 0;
!     /* Remove the `include' from /usr/local/lib/gcc.../include.  */
!     if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
!       default_len = strlen (default_prefix) - 7;
!       default_prefix[default_len] = 0;
!     }
!     /* Search "translated" versions of GNU directories.
!        These have /usr/local/lib/gcc... replaced by specd_prefix.  */
!     if (specd_prefix != 0 && default_len != 0)
!       for (p = include_defaults; p->fname; p++) {
! 	/* Some standard dirs are only for C++.  */
! 	if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
! 	  /* Does this dir start with the prefix?  */
! 	  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 = (char *) xmalloc (this_len + 1);
! 	    strcpy (str, specd_prefix);
! 	    strcat (str, p->fname + default_len);
! 	    new->fname = str;
! 	    new->control_macro = 0;
! 	    append_include_chain (new, new);
! 	    if (first_system_include == 0)
! 	      first_system_include = new;
! 	  }
! 	}
!       }
!     /* Search ordinary names for GNU include directories.  */
!     for (p = include_defaults; p->fname; p++) {
!       /* 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->fname = p->fname;
! 	append_include_chain (new, new);
! 	if (first_system_include == 0)
! 	  first_system_include = new;
!       }
!     }
!   }
! 
!   /* Tack the after_include chain at the end of the include chain.  */
!   append_include_chain (after_include, last_after_include);
!   if (first_system_include == 0)
!     first_system_include = after_include;
  
    /* Scan the -imacros files before the main input.
       Much like #including them, but with no_output set
--- 1409,1416 ----
  
    done_initializing = 1;
  
!   /* default include directories */
!   idir_do_defaults (no_standard_includes);
  
    /* Scan the -imacros files before the main input.
       Much like #including them, but with no_output set
***************
*** 1808,1814 ****
    /* Now we have processed the entire input
       Write whichever kind of output has been requested.  */
  
!   if (dump_macros == dump_only)
      dump_all_macros ();
    else if (! inhibit_output) {
      write_output ();
--- 1625,1633 ----
    /* Now we have processed the entire input
       Write whichever kind of output has been requested.  */
  
!   if (dump_macros == dump_paths)
!     dump_include_dirs ();
!   else if (dump_macros == dump_only)
      dump_all_macros ();
    else if (! inhibit_output) {
      write_output ();
***************
*** 1840,1857 ****
    return 0;
  }
  
! /* Given a colon-separated list of file names PATH,
!    add all the names to the search path for include files.  */
  
! static void
! path_include (path)
!      char *path;
  {
    char *p;
  
!   p = path;
  
!   if (*p)
      while (1) {
        char *q = p;
        char *name;
--- 1659,1794 ----
    return 0;
  }
  
! /***** Include path processing ****************/
  
! 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;
!   };
! 
! /* #include "file" looks in source file dir, then stack. */
! /* #include <file> just looks in the stack. */
! /* -I directories are added to the end, then the defaults are added. */
! static struct default_include { char *fname; int cplusplus; } include_defaults_array[]
! #ifdef INCLUDE_DEFAULTS
!   = INCLUDE_DEFAULTS;
! #else
!   = {
!     /* Pick up GNU C++ specific include files.  */
!     { GPLUSPLUS_INCLUDE_DIR, 1},
!     { GCC_INCLUDE_DIR, 0},
! #ifdef CROSS_COMPILE
!     /* For cross-compilation, this dir name is generated
!        automatically in Makefile.in.  */
!     { CROSS_INCLUDE_DIR, 0 },
! #else /* not CROSS_COMPILE */
!     { LOCAL_INCLUDE_DIR, 0},
!     /* Some systems have an extra dir of include files.  */
! #ifdef SYSTEM_INCLUDE_DIR
!     { SYSTEM_INCLUDE_DIR, 0},
! #endif
!     { STANDARD_INCLUDE_DIR, 0},
! #endif /* not CROSS_COMPILE */
!     { 0, 0}
!     };
! #endif /* no INCLUDE_DEFAULTS */
! 
! /* The current source directories as specified by MAKECPP and/or -isource */
! static struct file_name_list *cwd_list = 0;
! static struct file_name_list *last_cwd = 0;
! 
! /* The code looks at the defaults through this pointer, rather than through
!    the constant structure above.  This pointer gets changed if an environment
!    variable specifies other defaults.  */
! static struct default_include *include_defaults = include_defaults_array;
! 
! static struct file_name_list *include = 0;	/* First dir to search */
! 	/* First dir to search for <file> */
! static struct file_name_list *first_bracket_include = 0;
! static struct file_name_list *last_include = 0;	/* Last in chain */
! 
! /* Chain of include directories to put at the end of the other chain.  */
! static struct file_name_list *after_include = 0;
! static struct file_name_list *last_after_include = 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;
! 
! 
! void
! dump_include_dirs()
! {
! 	struct file_name_list *fl;
! 
! 	printf ("#\n# Files included using \"\" are searched ");
! 	if (ignore_srcdir)
! 	    printf ("only using path.\n");
! 	else
! 	    printf ("primarily from the directory where\n%s\n",
! 		    "# the including file is found from.");
! 	if (cwd_list)
! 	    printf ("#\n# Current directory (cwd path):\n");
! 	for (fl = cwd_list; fl; fl = fl->next) {
! 		if (fl == first_bracket_include)
! 		    break;
! 		printf ("%s\n", fl->fname);
! 	}
! 	if (first_bracket_include)
! 	    printf ("#\n# Include path (\"\" only):\n");
! 	else
! 	    printf ("#\n# Include path:\n");
! 	for (fl = include; fl; fl = fl->next) {
! 		if (first_bracket_include == fl)
! 		    printf("# Bracket <> includes:\n");
! 		printf ("%s\n", fl->fname);
! 	}
! 	printf ("#\n");
! }
! 
! void
! idir_initialize()
  {
+   int i;
    char *p;
  
!   for (i = 0; include_defaults[i].fname; i++)
!     max_include_len = MAX (max_include_len,
! 			   strlen (include_defaults[i].fname));
!   /* Leave room for making file name longer when converting to VMS syntax.  */
! #ifdef VMS
!   max_include_len += 10;
! #endif
  
!   p = getenv ("MAKECPP");
!   if (p)
!       idir_add_to_cwd_path (p);
! }
! 
! /* Called when -nostdinc is seen to reset the effect of MAKECPP and previous
!  * -isource options
!  */
! void
! idir_reset_cwd_path ()
! {
! 	/* Leaks some memory. So what? */
! 	cwd_list = last_cwd = 0;
! }
! 
! void
! idir_add_to_cwd_path (p)
! 	char *p;
! {
! 
!   if (p && *p) {
      while (1) {
        char *q = p;
        char *name;
***************
*** 1860,1866 ****
        /* 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 = (char *) xmalloc (2);
  	name[0] = '.';
  	name[1] = 0;
--- 1797,1803 ----
        /* 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. why? */
  	name = (char *) xmalloc (2);
  	name[0] = '.';
  	name[1] = 0;
***************
*** 1871,1882 ****
  	name[q - p] = 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->fname = name;
!       append_include_chain (dirtmp, dirtmp);
  
        /* Advance past this name.  */
        p = q;
--- 1808,2084 ----
  	name[q - p] = 0;
        }
  
+       idir_add_to_cwd(name);
+ 
+       /* Advance past this name.  */
+       p = q;
+       if (*p == 0)
+       break;
+       /* Skip the colon.  */
+       p++;
+     }
+   }
+ }
+ 
+ void
+ idir_add_to_cwd(directory)
+       char *directory;
+ {
+   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;
+   if (cwd_list == 0)
+     cwd_list = dirtmp;
+   else
+     last_cwd->next = dirtmp;
+   last_cwd = dirtmp;  /* Tail follows the last one */
+   
+   dirtmp->fname = directory;
+   
+   if (strlen (dirtmp->fname) > max_include_len)
+     max_include_len = strlen (dirtmp->fname);
+ }
+ 
+ void
+ idir_do_defaults(no_standard_includes)
+       int no_standard_includes;
+ {
+       if (!no_standard_includes) {
+ 	      /* read the appropriate environment variable and if it exists
+ 		 replace include_defaults with the listed path. */
+ 	      char *p = 0;
+ 	      char *path_name = 0;
+ 
+ 	      switch ((objc << 1) + cplusplus)
+ 	      {
+ 		    case 0:
+ 		      path_name = "C_INCLUDE_PATH";
+ 		      break;
+ 		    case 1:
+ 		      path_name = "C++_INCLUDE_PATH";
+ 		      break;
+ 		    case 2:
+ 		      path_name = "OBJC_INCLUDE_PATH";
+ 		      break;
+ 		    case 3:
+ 		      path_name = "OBJC++_INCLUDE_PATH";
+ 		      break;
+ 	      }
+ 	      if (path_name)
+ 		  p = getenv (path_name);
+ 	      /* If the environment var for this language is set,
+                  add to the default list of include directories.  */
+               if (p) {
+                       idir_add_path (p);
+               }
+ 
+               p = (char *) getenv ("CPATH");
+               if (p) {
+                       idir_add_path (p);
+               } else {
+                       /* Add the usual defaults to the end.  */
+                       /* CPATH overrides these defaults */
+                       idir_do_standard_includes();
+               }
+               
+       }
+ 
+   /* Tack the after_include chain at the end of the include chain.  */
+   if (last_include)
+     last_include->next = after_include;
+   else
+     include = after_include;
+   if (ignore_srcdir && first_bracket_include == 0)
+     first_bracket_include = after_include;
+ 
+   /* Terminate the after_include chain.  */
+   if (last_after_include)
+     last_after_include->next = 0;
+ 
+   /* Add current source directory path to "" path if no -I- option given and
+    * there is a current directory path (MAKECPP or -isource)
+    */
+   if (!ignore_srcdir  /* -I- seen */
+       && cwd_list) {
+         ignore_srcdir = 1;
+         last_cwd->next = include;
+         first_bracket_include = include;
+         include = cwd_list;
+   }
+ }
+ 
+ void
+ idir_do_standard_includes()
+ {
+     struct default_include *p = include_defaults;
+     char *specd_prefix = getenv ("GCC_EXEC_PREFIX");
+     char *default_prefix = savestring (GCC_INCLUDE_DIR);
+     int default_len = 0;
+     /* Remove the `include' from /usr/local/lib/gcc.../include.  */
+     if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
+       default_len = strlen (default_prefix) - 7;
+       default_prefix[default_len] = 0;
+     }
+     /* Search "translated" versions of GNU directories.
+        These have /usr/local/lib/gcc... replaced by specd_prefix.  */
+     if (specd_prefix != 0 && default_len != 0)
+       for (p = include_defaults; p->fname; p++) {
+       /* Some standard dirs are only for C++.  */
+       if (!p->cplusplus || cplusplus) {
+         /* Does this dir start with the prefix?  */
+         if (!strncmp (p->fname, default_prefix, default_len)) {
+           /* Yes; change prefix and add to search list.  */
+           int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
+           char *str = (char *) xmalloc (this_len + 1);
+           strcpy (str, specd_prefix);
+           strcat (str, p->fname + default_len);
+ 
+           idir_add (str);
+ 
+         }
+       }
+       }
+     /* Search ordinary names for GNU include directories.  */
+     for (p = include_defaults; p->fname; p++) {
+       /* Some standard dirs are only for C++.  */
+       if (!p->cplusplus || cplusplus) {
+       idir_add (p->fname);
+       }
+     }
+ }
+ 
+ /* add directory to end of path for includes */
+ void 
+ idir_add_to_end (directory)
+       char *directory;
+ {
+         struct file_name_list *dirtmp, *p;
+ 
+         if (directory[0] == '/' || !cwd_list) {
        dirtmp = (struct file_name_list *)
  	xmalloc (sizeof (struct file_name_list));
        dirtmp->next = 0;		/* New one goes on the end */
        dirtmp->control_macro = 0;
+                 if (after_include == 0)
+                     after_include = dirtmp;
+                 else
+                     last_after_include->next = dirtmp;
+                 last_after_include = dirtmp; /* Tail follows the last one */
+ 
+                 dirtmp->fname = directory;
+ 
+                 if (strlen (dirtmp->fname) > max_include_len)
+                     max_include_len = strlen (dirtmp->fname);
+         } else for (p = cwd_list; p; p = p->next) {
+                 char *name;
+                 name = xmalloc (strlen (directory) + strlen (p->fname) + 2);
+                 sprintf (name, "%s/%s", p->fname, directory);
+ 
+                 dirtmp = (struct file_name_list *)
+                     xmalloc (sizeof (struct file_name_list));
+                 dirtmp->next = 0;     /* New one goes on the end */
+                 dirtmp->control_macro = 0;
+                 if (after_include == 0)
+                     after_include = dirtmp;
+                 else
+                     last_after_include->next = dirtmp;
+                 last_after_include = dirtmp; /* Tail follows the last one */
+ 
        dirtmp->fname = name;
! 
!                 if (strlen (dirtmp->fname) > max_include_len)
!                     max_include_len = strlen (dirtmp->fname);
!         }
! }
! 
! /* add directory to tail of head of path for includes */
! idir_add(directory)
!       char *directory;
! {
!         struct file_name_list *dirtmp, *p;
! 
!         if (directory[0] == '/' || !cwd_list) {
!                 
!                 dirtmp = (struct file_name_list *)
!                     xmalloc (sizeof (struct file_name_list));
!                 dirtmp->next = 0;             /* New one goes on the end */
!                 dirtmp->control_macro = 0;
!         if (include == 0)
!         include = dirtmp;
!         else
!         last_include->next = dirtmp;
!         last_include = dirtmp;  /* Tail follows the last one */
!                 
!                 dirtmp->fname = directory;
!                 
!                 if (strlen (dirtmp->fname) > max_include_len)
!                     max_include_len = strlen (dirtmp->fname);
!                 if (ignore_srcdir && first_bracket_include == 0)
!                     first_bracket_include = dirtmp;
!         } else for (p = cwd_list; p; p = p->next) {
!                 char *name;
!                 name = xmalloc (strlen (directory) + strlen (p->fname) + 2);
!                 sprintf (name, "%s/%s", p->fname, directory);
! 		/* XXX simplify path */
!                 
!                 dirtmp = (struct file_name_list *)
!                     xmalloc (sizeof (struct file_name_list));
!                 dirtmp->next = 0;             /* New one goes on the end */
!                 dirtmp->control_macro = 0;
!                 if (include == 0)
!                     include = dirtmp;
!                 else
!                     last_include->next = dirtmp;
!                 last_include = dirtmp;        /* Tail follows the last one */
!                 
!         dirtmp->fname = name;
!                 
!         if (strlen (dirtmp->fname) > max_include_len)
!         max_include_len = strlen (dirtmp->fname);
!         if (ignore_srcdir && first_bracket_include == 0)
!         first_bracket_include = dirtmp;
!         }
! }
! 
! /* Given a colon-separated list of file names PATH,
!    add all the names to the search path for include files.  */
! 
! void
! idir_add_path (path)
!      char *path;
! {
!   char *p;
! 
!   p = path;
! 
!   if (*p)
!     while (1) {
!       char *q = p;
!       char *name;
!       struct file_name_list *dirtmp;
! 
!       /* Find the end of this name.  */
! #ifdef __MSDOS__
!       /* Handle cases like c:/usr/lib:d:/gcc/lib */
!       while (*q != 0 && (*q != ':' || (q - p == 1 && isalpha (*p)))) q++;
! #else
!       while (*q != 0 && *q != ':') q++;
! #endif
!       if (p == q) {
!       /* An empty name in the path stands for the current directory.  */
!       name = (char *) xmalloc (2);
!       name[0] = '.';
!       name[1] = 0;
!       } else {
!       /* Otherwise use the directory that is named.  */
!       name = (char *) xmalloc (q - p + 1);
!       bcopy (p, name, q - p);
!       name[q - p] = 0;
!       }
! 
!       idir_add(name);
  
        /* Advance past this name.  */
        p = q;
