scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 35323a998387f84bd2352cec431b6f3482bd42a9
parent 08eba63ef5e08838e091afc8533368c1cecdc5ac
Author: Quentin Rameau <quinq@fifth.space>
Date:   Wed, 21 Apr 2021 23:07:31 +0200

cc1: Fix include files searching

This partially reverts a bug introduced in 7ecbfcb, where a not found
file would directly abort the program, while it is necessary to be able
to continue, like when searching for a file in the different include
paths.

Diffstat:
Msrc/cmd/cc/cc1/cc1.h | 5++++-
Msrc/cmd/cc/cc1/cpp.c | 7+++----
Msrc/cmd/cc/cc1/lex.c | 10+++++++---
Msrc/cmd/cc/cc1/main.c | 2+-
4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/cmd/cc/cc1/cc1.h b/src/cmd/cc/cc1/cc1.h @@ -5,6 +5,9 @@ #define NR_USWITCHES 20 +#define FAIL 0 +#define NOFAIL 1 + /* * Definition of enumerations */ @@ -447,7 +450,7 @@ extern int ahead(void); extern int next(void); extern void expect(int tok); extern void discard(void); -extern void addinput(char *fname, Symbol *hide, char *buffer); +extern int addinput(char *fname, Symbol *hide, char *buffer, int fail); extern void delinput(void); extern void setsafe(int type); extern void ilex(void); diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c @@ -32,7 +32,7 @@ defdefine(char *macro, char *val, char *source) sprintf(def, fmt, macro, val); lineno = ++ncmdlines; - addinput(source, &dummy, def); + addinput(source, &dummy, def, FAIL); cpp(); delinput(); } @@ -273,7 +273,7 @@ expand(char *begin, Symbol *sym) substitute: DBG("MACRO '%s' expanded to :'%s'", macroname, buffer); buffer[elen] = '\0'; - addinput(filenam, sym, xstrdup(buffer)); + addinput(filenam, sym, xstrdup(buffer), FAIL); return 1; } @@ -440,8 +440,7 @@ includefile(char *dir, char *file, size_t filelen) memcpy(path+dirlen, file, filelen); path[dirlen + filelen] = '\0'; - addinput(path, NULL, NULL); - return 1; + return addinput(path, NULL, NULL, NOFAIL); } static char * diff --git a/src/cmd/cc/cc1/lex.c b/src/cmd/cc/cc1/lex.c @@ -83,8 +83,8 @@ setloc(char *fname, unsigned line) lineno = input->lineno = line; } -void -addinput(char *fname, Symbol *hide, char *buffer) +int +addinput(char *fname, Symbol *hide, char *buffer, int fail) { FILE *fp; char *extp; @@ -101,8 +101,11 @@ addinput(char *fname, Symbol *hide, char *buffer) flags = IMACRO; } else if (fname) { /* a new file */ - if ((fp = fopen(fname, "r")) == NULL) + if ((fp = fopen(fname, "r")) == NULL) { + if (!fail) + return 0; die("cc1: %s: %s", fname, strerror(errno)); + } flags = IFILE; if (curip && onlyheader) { infileln = strlen(infile); @@ -138,6 +141,7 @@ addinput(char *fname, Symbol *hide, char *buffer) input = newip; setloc(fname, (curip) ? curip->lineno : newip->lineno); + return 1; } void diff --git a/src/cmd/cc/cc1/main.c b/src/cmd/cc/cc1/main.c @@ -93,7 +93,7 @@ main(int argc, char *argv[]) undefmacro(uflags.s[i]); infile = (*argv) ? *argv : "<stdin>"; - addinput(*argv, NULL, NULL); + addinput(*argv, NULL, NULL, FAIL); if (onlycpp || onlyheader) { outcpp();