scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit bde0ef892aeb95d7aaa95ffb11b0bd82b2a31d9c
parent 89bb136a4e5fc5a942f34ff2d0e284c783f8b771
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 12 Jan 2017 08:51:17 +0100

[cc1] Fix readline()

After the modification of macro expansions to use push up buffers
readline was broken, because after expanding a macro we have
to return always from readline, otherwise we can remove some
newline from the input. This new version also makes better use
of 'goto' than the previous version.

Diffstat:
Mcc1/lex.c | 18++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -202,27 +202,21 @@ readline(void) char *bp, *lim; char c, peekc = 0; -repeat_from_file: - *input->line = '\0'; - input->p = input->line; - -repeat_from_expand: - input->begin = input->p; - - if (*input->begin) - return 1; +repeat: if (eof) return 0; - if (!input->fp) { delinput(); - goto repeat_from_expand; + return 1; } if (feof(input->fp)) { delinput(); - goto repeat_from_file; + goto repeat; } + + *input->line = '\0'; + input->begin = input->p = input->line; lim = &input->line[INPUTSIZ-1]; for (bp = input->line; bp < lim; *bp++ = c) { c = (peekc) ? peekc : readchar();