scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit b5557403903f5e92a35ae7505ae38f345f5d29b2
parent e0eed9f03d22464740c57d5baea245791ef84f23
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 26 May 2015 09:47:25 +0200

Add system dependend include paths

File included that enclosed with <> are searched in a location
that is implementation dependant.

Diffstat:
cc1/cc1.h | 3+++
cc1/cpp.c | 23+++++++++++++++++++----
2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -1,5 +1,8 @@ #define INPUTSIZ 120 +#ifndef PREFIX +#define PREFIX "/usr/" +#endif /* * Definition of structures diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -383,7 +383,13 @@ define(char *s) static void include(char *s) { - char delim, c, *p, *file; + char **bp, delim, c, *p, *file, buff[FILENAME_MAX]; + char *sysinclude[] = { + PREFIX"/include/", + PREFIX"/local/include/", + NULL + }; + size_t filelen, dirlen; if (cppoff) return; @@ -399,10 +405,19 @@ include(char *s) cleanup(s); if (delim == '"' && addinput(file, NULL)) return; - abort(); -not_found: - error("included file '%s' not found", s); + filelen = strlen(file); + for (bp = sysinclude; *bp; ++bp) { + dirlen = strlen(*bp); + if (dirlen + filelen > FILENAME_MAX) + continue; + memcpy(buff, *bp, dirlen); + memcpy(buff+dirlen, file, filelen); + if (addinput(buff, NULL)) + return; + } + error("included file '%s' not found", file); + bad_include: error("#include expects \"FILENAME\" or <FILENAME>"); }