shithub: scc

Download patch

ref: 2d6aaa2a9cb928a69bdef0ed307fe8ea85389b72
parent: 5398bfe4e68b7926f301beb47299a92ff0540c10
author: Quentin Rameau <[email protected]>
date: Mon Jun 27 11:22:30 EDT 2016

[cc1] move file open handling from ilex to addinput

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -383,7 +383,7 @@
 extern void discard(void);
 extern int addinput(char *fname);
 extern void setsafe(int type);
-extern void ilex(char *fname);
+extern void ilex(void);
 #define accept(t) ((yytoken == (t)) ? next() : 0)
 
 /* code.c */
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -38,7 +38,7 @@
 }
 
 void
-ilex(char *fname)
+ilex(void)
 {
 	static struct keyword keys[] = {
 		{"auto", SCLASS, AUTO},
@@ -78,18 +78,6 @@
 		{"while", WHILE, WHILE},
 		{NULL, 0, 0},
 	};
-	FILE *fp;
-
-	if (!fname) {
-		fp = stdin;
-		fname = "<stdin>";
-	} else {
-		if ((fp = fopen(fname, "r")) == NULL) {
-			die("error: failed to open input file '%s': %s",
-			    fname, strerror(errno));
-		}
-	}
-	allocinput(fname, fp);
 	keywords(keys, NS_KEYWORD);
 }
 
@@ -98,8 +86,13 @@
 {
 	FILE *fp;
 
-	if ((fp = fopen(fname, "r")) == NULL)
-		return 0;
+	if (fname) {
+		if ((fp = fopen(fname, "r")) == NULL)
+			return 0;
+	} else {
+		fp = stdin;
+		fname = "<stdin>";
+	}
 	allocinput(fname, fp);
 	return 1;
 }
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -46,6 +46,7 @@
 
 	atexit(clean);
 	icpp();
+	ilex();
 
 	/* if run as cpp, only run the preprocessor */
 	name = (cp = strrchr(*argv, '/')) ? cp + 1 : *argv;
@@ -88,7 +89,10 @@
 	for (i = 0; i < uflags.n; ++i)
 		undefmacro(uflags.s[i]);
 
-	ilex(*argv);
+	if (!addinput(*argv)) {
+		die("error: failed to open input file '%s': %s",
+		    *argv, strerror(errno));
+	}
 	if (onlycpp) {
 		outcpp();
 	} else {