This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[BIB] Small clean up of cppinit.c include handling
- From: Neil Booth <neil at daikokuya dot co dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Zack Weinberg <zack at codesourcery dot com>
- Date: Wed, 11 Dec 2002 22:23:40 +0000
- Subject: [BIB] Small clean up of cppinit.c include handling
This tidies up the code for handling include paths in environment
variables, as part of preparation for moving the remaining cpplib
switch handling to c-opts.c.
Whilst doing this, I noticed something that I think is unintended:
that -nostdinc causes cpplib to ignore the environment variable
paths. I can't imagine this is the right thing to do.
Do you agree Zack? If so, I'll apply this.
Neil.
* cppinit.c (path_include): Take an environment variable name.
Tidy up.
(init_standard_includes): Simplify environment handling, and
move to ...
(cpp_read_main_file): ...here as -nostdinc should not affect
environment variable paths.
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.260.2.6
diff -u -p -r1.260.2.6 cppinit.c
--- cppinit.c 10 Dec 2002 19:16:44 -0000 1.260.2.6
+++ cppinit.c 11 Dec 2002 22:17:48 -0000
@@ -89,7 +89,7 @@ struct cpp_pending
#endif
static void path_include PARAMS ((cpp_reader *,
- char *, int));
+ const char *, int));
static void init_library PARAMS ((void));
static void init_builtins PARAMS ((cpp_reader *));
static void mark_named_operators PARAMS ((cpp_reader *));
@@ -152,19 +152,21 @@ END
#undef END
#undef TRIGRAPH_MAP
-/* Given a colon-separated list of file names PATH,
+/* Read ENV_VAR for a colon-separated list of file names; and
add all the names to the search path for include files. */
static void
-path_include (pfile, list, path)
+path_include (pfile, env_var, path)
cpp_reader *pfile;
- char *list;
+ const char *env_var;
int path;
{
char *p, *q, *name;
- p = list;
+ GET_ENVIRONMENT (q, env_var);
+ if (!q)
+ return;
- do
+ for (p = q; *q; p = q + 1)
{
/* Find the end of this name. */
q = p;
@@ -185,13 +187,7 @@ path_include (pfile, list, path)
}
append_include_chain (pfile, name, path, path == SYSTEM);
-
- /* Advance past this name. */
- if (*q == 0)
- break;
- p = q + 1;
}
- while (1);
}
/* Append DIR to include path PATH. DIR must be allocated on the
@@ -758,38 +754,9 @@ static void
init_standard_includes (pfile)
cpp_reader *pfile;
{
- char *path;
const struct default_include *p;
const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
- /* Several environment variables may add to the include search path.
- CPATH specifies an additional list of directories to be searched
- as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
- etc. specify an additional list of directories to be searched as
- if specified with -isystem, for the language indicated. */
-
- GET_ENVIRONMENT (path, "CPATH");
- if (path != 0 && *path != 0)
- path_include (pfile, path, BRACKET);
-
- switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
- {
- case 0:
- GET_ENVIRONMENT (path, "C_INCLUDE_PATH");
- break;
- case 1:
- GET_ENVIRONMENT (path, "CPLUS_INCLUDE_PATH");
- break;
- case 2:
- GET_ENVIRONMENT (path, "OBJC_INCLUDE_PATH");
- break;
- case 3:
- GET_ENVIRONMENT (path, "OBJCPLUS_INCLUDE_PATH");
- break;
- }
- if (path != 0 && *path != 0)
- path_include (pfile, path, SYSTEM);
-
/* Search "translated" versions of GNU directories.
These have /usr/local/lib/gcc... replaced by specd_prefix. */
if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
@@ -953,6 +920,11 @@ cpp_read_main_file (pfile, fname, table)
const char *fname;
hash_table *table;
{
+ static const char *const lang_env_vars[] =
+ { "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
+ "OBJC_INCLUDE_PATH", "OBJCPLUS_INCLUDE_PATH" };
+ size_t lang;
+
sanity_checks (pfile);
post_options (pfile);
@@ -961,6 +933,15 @@ cpp_read_main_file (pfile, fname, table)
finished processing the command line options, so initializing the
hashtable is deferred until now. */
_cpp_init_hashtable (pfile, table);
+
+ /* Several environment variables may add to the include search path.
+ CPATH specifies an additional list of directories to be searched
+ as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
+ etc. specify an additional list of directories to be searched as
+ if specified with -isystem, for the language indicated. */
+ path_include (pfile, "CPATH", BRACKET);
+ lang = (CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus);
+ path_include (pfile, lang_env_vars[lang], SYSTEM);
/* Set up the include search path now. */
if (! CPP_OPTION (pfile, no_standard_includes))