scc

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

commit 7ecbfcb7da78a8c794f981c179c5431edbbc4326
parent 924b7323d1b84dd30f98e3a03a30d914f5731a5e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 14 Mar 2018 10:16:21 +0100

[cc1] Make addinput() a void funtcion

It allows to give the message error as soon as possible.

Diffstat:
Mcc1/cc1.h | 4++--
Mcc1/cpp.c | 3++-
Mcc1/lex.c | 9++++-----
Mcc1/main.c | 5+----
4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -416,11 +416,11 @@ extern int ahead(void); extern int next(void); extern void expect(int tok); extern void discard(void); -extern int addinput(char *fname, Symbol *hide, char *buffer); +extern void addinput(char *fname, Symbol *hide, char *buffer); extern void delinput(void); extern void setsafe(int type); extern void ilex(void); -extern int setloc(char *fname, unsigned line); +extern void setloc(char *fname, unsigned line); #define accept(t) ((yytoken == (t)) ? next() : 0) /* code.c */ diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -441,7 +441,8 @@ includefile(char *dir, char *file, size_t filelen) memcpy(path+dirlen, file, filelen); path[dirlen + filelen] = '\0'; - return addinput(path, NULL, NULL); + addinput(path, NULL, NULL); + return 1; } static char * diff --git a/cc1/lex.c b/cc1/lex.c @@ -69,7 +69,7 @@ ilex(void) keywords(keys, NS_KEYWORD); } -int +void setloc(char *fname, unsigned line) { size_t len; @@ -82,10 +82,9 @@ setloc(char *fname, unsigned line) free(input->filenam); input->filenam = xstrdup(fname); lineno = input->lineno = line; - return 1; } -int +void addinput(char *fname, Symbol *hide, char *buffer) { FILE *fp; @@ -104,7 +103,7 @@ addinput(char *fname, Symbol *hide, char *buffer) } else if (fname) { /* a new file */ if ((fp = fopen(fname, "r")) == NULL) - return 0; + die("cc1: %s: %s", fname, strerror(errno)); flags = IFILE; if (curip && onlyheader) { infileln = strlen(infile); @@ -139,7 +138,7 @@ addinput(char *fname, Symbol *hide, char *buffer) newip->flags = flags; input = newip; - return setloc(fname, (curip) ? curip->lineno : newip->lineno); + setloc(fname, (curip) ? curip->lineno : newip->lineno); } void diff --git a/cc1/main.c b/cc1/main.c @@ -82,10 +82,7 @@ main(int argc, char *argv[]) undefmacro(uflags.s[i]); infile = (*argv) ? *argv : "<stdin>"; - if (!addinput(*argv, NULL, NULL)) { - die("error: failed to open input file '%s': %s", - *argv, strerror(errno)); - } + addinput(*argv, NULL, NULL); /* * we cannot initialize arch until we have an