shithub: scc

Download patch

ref: 9751bfd656a98f47f301db6265f28937d3857590
parent: 1ebd02c28ba4d5969e349942e2ec7334ca13d195
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Mar 14 06:16:21 EDT 2018

[cc1] Make addinput() a void funtcion

It allows to give the message error as soon as possible.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -416,11 +416,11 @@
 extern int next(void);
 extern void expect(int tok);
 extern void discard(void);
-extern int addinput(char *fname, Symbol *hide, char *buffer);
+extern void addinput(char *fname, Symbol *hide, char *buffer);
 extern void delinput(void);
 extern void setsafe(int type);
 extern void ilex(void);
-extern int setloc(char *fname, unsigned line);
+extern void setloc(char *fname, unsigned line);
 #define accept(t) ((yytoken == (t)) ? next() : 0)
 
 /* code.c */
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -441,7 +441,8 @@
 	memcpy(path+dirlen, file, filelen);
 	path[dirlen + filelen] = '\0';
 
-	return addinput(path, NULL, NULL);
+	addinput(path, NULL, NULL);
+	return 1;
 }
 
 static char *
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -69,7 +69,7 @@
 	keywords(keys, NS_KEYWORD);
 }
 
-int
+void
 setloc(char *fname, unsigned line)
 {
 	size_t len;
@@ -82,10 +82,9 @@
 	free(input->filenam);
 	input->filenam = xstrdup(fname);
 	lineno = input->lineno = line;
-	return 1;
 }
 
-int
+void
 addinput(char *fname, Symbol *hide, char *buffer)
 {
 	FILE *fp;
@@ -104,7 +103,7 @@
 	} else  if (fname) {
 		/* a new file */
 		if ((fp = fopen(fname, "r")) == NULL)
-			return 0;
+			die("cc1: %s: %s", fname, strerror(errno));
 		flags = IFILE;
 		if (curip && onlyheader) {
 			infileln = strlen(infile);
@@ -139,7 +138,7 @@
 	newip->flags = flags;
 	input = newip;
 
-	return setloc(fname, (curip) ? curip->lineno : newip->lineno);
+	setloc(fname, (curip) ? curip->lineno : newip->lineno);
 }
 
 void
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -82,10 +82,7 @@
 		undefmacro(uflags.s[i]);
 
 	infile = (*argv) ? *argv : "<stdin>";
-	if (!addinput(*argv, NULL, NULL)) {
-		die("error: failed to open input file '%s': %s",
-		    *argv, strerror(errno));
-	}
+	addinput(*argv, NULL, NULL);
 
 	/*
 	 * we cannot initialize arch until we have an