Commit 6489924b by Richard Stallman

(main): Clear first_bracket_include for -I-.

Set first_system_include for first system header directory.
(is_system_include): Start search at first_system_include.

(INCLUDE_LEN_FUDGE): Defined.
(append_include_chain): New function.  Adds directory(ies)
to include chain and updates value of max_include_len.
(main, path_include): Use append_include_chain.
(do_include): Use INCLUDE_LEN_FUDGE.

From-SVN: r1488
parent 47877ade
...@@ -102,6 +102,7 @@ static FILE * VMS_freopen (); ...@@ -102,6 +102,7 @@ static FILE * VMS_freopen ();
static void hack_vms_include_specification (); static void hack_vms_include_specification ();
typedef struct { unsigned :16, :16, :16; } vms_ino_t; typedef struct { unsigned :16, :16, :16; } vms_ino_t;
#define ino_t vms_ino_t #define ino_t vms_ino_t
#define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */
#ifdef __GNUC__ #ifdef __GNUC__
#define BSTRING /* VMS/GCC supplies the bstring routines */ #define BSTRING /* VMS/GCC supplies the bstring routines */
#endif /* __GNUC__ */ #endif /* __GNUC__ */
...@@ -128,6 +129,10 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t; ...@@ -128,6 +129,10 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
#define NULL_PTR (char *) NULL #define NULL_PTR (char *) NULL
#endif #endif
#ifndef INCLUDE_LEN_FUDGE
#define INCLUDE_LEN_FUDGE 0
#endif
/* Exported declarations. */ /* Exported declarations. */
char *xmalloc (); char *xmalloc ();
...@@ -185,6 +190,7 @@ static int do_unassert (); ...@@ -185,6 +190,7 @@ static int do_unassert ();
static int do_warning (); static int do_warning ();
static void add_import (); static void add_import ();
static void append_include_chain ();
static void deps_output (); static void deps_output ();
static void make_undef (); static void make_undef ();
static void make_definition (); static void make_definition ();
...@@ -515,7 +521,12 @@ static struct default_include *include_defaults = include_defaults_array; ...@@ -515,7 +521,12 @@ static struct default_include *include_defaults = include_defaults_array;
static struct file_name_list *include = 0; /* First dir to search */ static struct file_name_list *include = 0; /* First dir to search */
/* First dir to search for <file> */ /* 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; 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 */ static struct file_name_list *last_include = 0; /* Last in chain */
/* Chain of include directories to put at the end of the other chain. */ /* Chain of include directories to put at the end of the other chain. */
...@@ -957,14 +968,6 @@ main (argc, argv) ...@@ -957,14 +968,6 @@ main (argc, argv)
no_output = 0; no_output = 0;
cplusplus = 0; cplusplus = 0;
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
bzero (pend_files, argc * sizeof (char *)); bzero (pend_files, argc * sizeof (char *));
bzero (pend_defs, argc * sizeof (char *)); bzero (pend_defs, argc * sizeof (char *));
bzero (pend_undefs, argc * sizeof (char *)); bzero (pend_undefs, argc * sizeof (char *));
...@@ -1011,19 +1014,16 @@ main (argc, argv) ...@@ -1011,19 +1014,16 @@ main (argc, argv)
xmalloc (sizeof (struct file_name_list)); xmalloc (sizeof (struct file_name_list));
dirtmp->next = 0; /* New one goes on the end */ dirtmp->next = 0; /* New one goes on the end */
dirtmp->control_macro = 0; 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 */
if (i + 1 == argc) if (i + 1 == argc)
fatal ("Directory name missing after -idirafter option"); fatal ("Directory name missing after -idirafter option");
else else
dirtmp->fname = argv[++i]; dirtmp->fname = argv[++i];
if (strlen (dirtmp->fname) > max_include_len) if (after_include == 0)
max_include_len = strlen (dirtmp->fname); after_include = dirtmp;
else
last_after_include->next = dirtmp;
last_after_include = dirtmp; /* Tail follows the last one */
} }
break; break;
...@@ -1251,28 +1251,23 @@ main (argc, argv) ...@@ -1251,28 +1251,23 @@ main (argc, argv)
{ {
struct file_name_list *dirtmp; struct file_name_list *dirtmp;
if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) {
ignore_srcdir = 1; ignore_srcdir = 1;
/* Don't use any preceding -I directories for #include <...>. */
first_bracket_include = 0;
}
else { else {
dirtmp = (struct file_name_list *) dirtmp = (struct file_name_list *)
xmalloc (sizeof (struct file_name_list)); xmalloc (sizeof (struct file_name_list));
dirtmp->next = 0; /* New one goes on the end */ dirtmp->next = 0; /* New one goes on the end */
dirtmp->control_macro = 0; dirtmp->control_macro = 0;
if (include == 0)
include = dirtmp;
else
last_include->next = dirtmp;
last_include = dirtmp; /* Tail follows the last one */
if (argv[i][2] != 0) if (argv[i][2] != 0)
dirtmp->fname = argv[i] + 2; dirtmp->fname = argv[i] + 2;
else if (i + 1 == argc) else if (i + 1 == argc)
fatal ("Directory name missing after -I option"); fatal ("Directory name missing after -I option");
else else
dirtmp->fname = argv[++i]; dirtmp->fname = argv[++i];
if (strlen (dirtmp->fname) > max_include_len) append_include_chain (dirtmp, dirtmp);
max_include_len = strlen (dirtmp->fname);
if (ignore_srcdir && first_bracket_include == 0)
first_bracket_include = dirtmp;
} }
} }
break; break;
...@@ -1478,7 +1473,7 @@ main (argc, argv) ...@@ -1478,7 +1473,7 @@ main (argc, argv)
if ((*endp == PATH_SEPARATOR if ((*endp == PATH_SEPARATOR
#if 0 /* Obsolete, now that we use semicolons as the path separator. */ #if 0 /* Obsolete, now that we use semicolons as the path separator. */
#ifdef __MSDOS__ #ifdef __MSDOS__
&& (endp-startp != 1 || !isalpha (*startp))) && (endp-startp != 1 || !isalpha (*startp))
#endif #endif
#endif #endif
) )
...@@ -1489,7 +1484,6 @@ main (argc, argv) ...@@ -1489,7 +1484,6 @@ main (argc, argv)
else else
nstore[endp-startp] = '\0'; nstore[endp-startp] = '\0';
max_include_len = MAX (max_include_len, endp-startp+2);
include_defaults[num_dirs].fname = savestring (nstore); include_defaults[num_dirs].fname = savestring (nstore);
include_defaults[num_dirs].cplusplus = cplusplus; include_defaults[num_dirs].cplusplus = cplusplus;
num_dirs++; num_dirs++;
...@@ -1505,6 +1499,7 @@ main (argc, argv) ...@@ -1505,6 +1499,7 @@ main (argc, argv)
} }
} }
first_system_include = 0;
/* Unless -fnostdinc, /* Unless -fnostdinc,
tack on the standard include file dirs to the specified list */ tack on the standard include file dirs to the specified list */
if (!no_standard_includes) { if (!no_standard_includes) {
...@@ -1534,20 +1529,9 @@ main (argc, argv) ...@@ -1534,20 +1529,9 @@ main (argc, argv)
strcat (str, p->fname + default_len); strcat (str, p->fname + default_len);
new->fname = str; new->fname = str;
new->control_macro = 0; new->control_macro = 0;
append_include_chain (new, new);
/* Add elt to tail of list. */ if (first_system_include == 0)
if (include == 0) first_system_include = new;
include = new;
else
last_include->next = new;
/* Make sure list for #include <...> also has the standard dirs. */
if (ignore_srcdir && first_bracket_include == 0)
first_bracket_include = new;
/* Record new tail. */
last_include = new;
/* Update max_include_len if necessary. */
if (this_len > max_include_len)
max_include_len = this_len;
} }
} }
} }
...@@ -1558,32 +1542,18 @@ main (argc, argv) ...@@ -1558,32 +1542,18 @@ main (argc, argv)
struct file_name_list *new struct file_name_list *new
= (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
new->control_macro = 0; new->control_macro = 0;
/* Add elt to tail of list. */
if (include == 0)
include = new;
else
last_include->next = new;
/* Make sure list for #include <...> also has the standard dirs. */
if (ignore_srcdir && first_bracket_include == 0)
first_bracket_include = new;
/* Record new tail. */
last_include = new;
new->fname = p->fname; 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. */ /* Tack the after_include chain at the end of the include chain. */
if (last_include) append_include_chain (after_include, last_after_include);
last_include->next = after_include; if (first_system_include == 0)
else first_system_include = after_include;
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;
/* Scan the -imacros files before the main input. /* Scan the -imacros files before the main input.
Much like #including them, but with no_output set Much like #including them, but with no_output set
...@@ -1861,16 +1831,8 @@ path_include (path) ...@@ -1861,16 +1831,8 @@ path_include (path)
xmalloc (sizeof (struct file_name_list)); xmalloc (sizeof (struct file_name_list));
dirtmp->next = 0; /* New one goes on the end */ dirtmp->next = 0; /* New one goes on the end */
dirtmp->control_macro = 0; 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; dirtmp->fname = name;
if (strlen (dirtmp->fname) > max_include_len) append_include_chain (dirtmp, dirtmp);
max_include_len = strlen (dirtmp->fname);
if (ignore_srcdir && first_bracket_include == 0)
first_bracket_include = dirtmp;
/* Advance past this name. */ /* Advance past this name. */
p = q; p = q;
...@@ -3698,7 +3660,8 @@ get_filename: ...@@ -3698,7 +3660,8 @@ get_filename:
dsp[0].fname = (char *) alloca (n + 1); dsp[0].fname = (char *) alloca (n + 1);
strncpy (dsp[0].fname, nam, n); strncpy (dsp[0].fname, nam, n);
dsp[0].fname[n] = '\0'; dsp[0].fname[n] = '\0';
if (n > max_include_len) max_include_len = n; if (n + INCLUDE_LEN_FUDGE > max_include_len)
max_include_len = n + INCLUDE_LEN_FUDGE;
} else { } else {
dsp[0].fname = 0; /* Current directory */ dsp[0].fname = 0; /* Current directory */
} }
...@@ -3974,7 +3937,7 @@ is_system_include (filename) ...@@ -3974,7 +3937,7 @@ is_system_include (filename)
{ {
struct file_name_list *searchptr; struct file_name_list *searchptr;
for (searchptr = first_bracket_include; searchptr; for (searchptr = first_system_include; searchptr;
searchptr = searchptr->next) searchptr = searchptr->next)
if (searchptr->fname) { if (searchptr->fname) {
register char *sys_dir = searchptr->fname; register char *sys_dir = searchptr->fname;
...@@ -8334,6 +8297,39 @@ make_assertion (option, str) ...@@ -8334,6 +8297,39 @@ make_assertion (option, str)
--indepth; --indepth;
} }
/* 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. */
static void
append_include_chain (first, last)
struct file_name_list *first, *last;
{
struct file_name_list *dir;
if (!first || !last)
return;
if (include == 0)
include = first;
else
last_include->next = first;
if (first_bracket_include == 0)
first_bracket_include = dir;
for (dir = first; ; dir = dir->next) {
size_t len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
if (len > max_include_len)
max_include_len = len;
if (dir == last)
break;
}
last->next = NULL;
last_include = last;
}
/* Add output to `deps_buffer' for the -M switch. /* Add output to `deps_buffer' for the -M switch.
STRING points to the text to be output. STRING points to the text to be output.
SIZE is the number of bytes, or 0 meaning output until a null. SIZE is the number of bytes, or 0 meaning output until a null.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment