scc

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

commit 86f0bd836d6ae1320126ed4c8d46afa628f5beec
parent 06b6530a32e99483eec6a54b9510de6f40d0e6f0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 25 Jan 2018 21:34:08 +0100

Merge branch 'master' of ssh://simple-cc.org/var/gitrepos/scc

Diffstat:
Mas/parser.c | 53++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/as/parser.c b/as/parser.c @@ -361,27 +361,58 @@ extract(char *s, size_t len, struct line *lp) return r; } +static void +comment(FILE *fp) +{ + int c; + + while ((c = getc(fp)) != EOF) { + if (c != '*') + continue; + if ((c = getc(fp)) == '/') + return; + ungetc(c, fp); + } +} + +static size_t +getline(FILE *fp, char buff[MAXLINE]) +{ + int c; + char *bp; + + for (bp = buff; (c = getc(fp)) != EOF; *bp++ = c) { + if (c == '\n') + break; + if (c == '/') { + if ((c = getc(fp)) != '*') { + ungetc(c, fp); + } else { + comment(fp); + c = ' '; + } + } else if (c > UCHAR_MAX) { + error("invalid character '%x'", c); + } + if (bp == &buff[MAXLINE]) + error("line too long"); + } + return bp - buff; +} + int nextline(FILE *fp, struct line *lp) { size_t n; - char *p; static char buff[MAXLINE]; repeat: - if (!fgets(buff, sizeof(buff), fp)) + if (feof(fp)) return 0; - + if ((n = getline(fp, buff)) == 0) + goto repeat; if (++lineno == 0) die("as: file too long"); - - n = strlen(buff); - if (n == 0) - goto repeat; - if (buff[n-1] != '\n') - error("line too long"); - buff[n-1] = '\0'; - if (extract(buff, n, lp) == 0) goto repeat; return 1;