scc

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

commit 817575c96465deae85f3eca3730293972276b46c
parent 59595d29e5776583938bb14ccba7967be75d9c46
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 18 Jan 2024 17:13:42 +0100

make: Handle escaped newlines in comments

Comments happens until the first unescaped newline in the
makefile, but nextline() was stopping the comment in the
first newline independently of being espcaped or not.

Diffstat:
Msrc/cmd/make/parser.c | 24+++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/cmd/make/parser.c b/src/cmd/make/parser.c @@ -267,34 +267,44 @@ end: free(fil); } +static void +comment(FILE *fp) +{ + int c; + + while ((c = getc(fp)) != EOF && c != '\n') { + if (c == '\\' && getc(fp) == EOF) + break; + } +} + static char * nextline(void) { char *s, *lim; - int c, comment; + int c; FILE *fp = input->fp; assert(input->type == FTFILE); repeat: - comment = 0; if (feof(fp)) return NULL; lim = &input->buf[input->siz]; - for (s = input->buf; s < lim; ) { + for (s = input->buf; s < lim; *s++ = c) { c = getc(fp); if (c == '\n' || c == EOF) { input->loc.lineno++; *s++ = c; break; } - if (c == '#') - comment = 1; + if (c == '#') { + comment(fp); + break; + } if (c > UCHAR_MAX || c < 0) error("invalid character '%c' (%d)", c, c); - if (!comment) - *s++ = c; }