scc

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

commit 1dc58d5e18fc688f2eb7cb6590e3241a31e511f9
parent 07b012b6529ddca3385618900328b77cfa73c5ba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  5 Oct 2015 21:49:51 +0200

Emit #lines when it is needed in the cpp output

Diffstat:
Mcc1/cpp.c | 1+
Mcc1/lex.c | 17++++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -758,5 +758,6 @@ outcpp(void) } } } + putchar('\n'); } diff --git a/cc1/lex.c b/cc1/lex.c @@ -215,6 +215,10 @@ repeat: bool moreinput(void) { + static char file[FILENAME_MAX]; + static unsigned nline; + char *s; + repeat: if (!readline()) return 0; @@ -226,8 +230,19 @@ repeat: goto repeat; } - if (onlycpp) + if (onlycpp) { putchar('\n'); + if (strcmp(file, input->fname)) { + strcpy(file, input->fname); + s = "#line %u %s\n"; + } else if (nline+1 != input->nline) { + s = "#line %u\n"; + } else { + s = ""; + } + nline = input->nline; + printf(s, nline, file); + } input->begin = input->p; return 1; }