shithub: scc

Download patch

ref: 1dc58d5e18fc688f2eb7cb6590e3241a31e511f9
parent: 07b012b6529ddca3385618900328b77cfa73c5ba
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 5 17:49:51 EDT 2015

Emit #lines when it is needed in the cpp output

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -758,5 +758,6 @@
 			}
 		}
 	}
+	putchar('\n');
 }
 
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -215,6 +215,10 @@
 bool
 moreinput(void)
 {
+	static char file[FILENAME_MAX];
+	static unsigned nline;
+	char *s;
+
 repeat:
 	if (!readline())
 		return 0;
@@ -226,8 +230,19 @@
 		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;
 }