shithub: scc

Download patch

ref: d247a4947ccba430d36a7470b3da7fd9499fd08c
parent: e3faa977e595a145da79c58967f931319853b626
author: Quentin Rameau <quinq@fifth.space>
date: Wed Apr 21 19:07:31 EDT 2021

cc1: Fix include files searching

This partially reverts a bug introduced in 7ecbfcb, where a not found
file would directly abort the program, while it is necessary to be able
to continue, like when searching for a file in the different include
paths.

--- a/src/cmd/cc/cc1/cc1.h
+++ b/src/cmd/cc/cc1/cc1.h
@@ -5,6 +5,9 @@
 
 #define NR_USWITCHES 20
 
+#define FAIL   0
+#define NOFAIL 1
+
 /*
  * Definition of enumerations
  */
@@ -447,7 +450,7 @@
 extern int next(void);
 extern void expect(int tok);
 extern void discard(void);
-extern void addinput(char *fname, Symbol *hide, char *buffer);
+extern int addinput(char *fname, Symbol *hide, char *buffer, int fail);
 extern void delinput(void);
 extern void setsafe(int type);
 extern void ilex(void);
--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -32,7 +32,7 @@
 
 	sprintf(def, fmt, macro, val);
 	lineno = ++ncmdlines;
-	addinput(source, &dummy, def);
+	addinput(source, &dummy, def, FAIL);
 	cpp();
 	delinput();
 }
@@ -273,7 +273,7 @@
 substitute:
 	DBG("MACRO '%s' expanded to :'%s'", macroname, buffer);
 	buffer[elen] = '\0';
-	addinput(filenam, sym, xstrdup(buffer));
+	addinput(filenam, sym, xstrdup(buffer), FAIL);
 
 	return 1;
 }
@@ -440,8 +440,7 @@
 	memcpy(path+dirlen, file, filelen);
 	path[dirlen + filelen] = '\0';
 
-	addinput(path, NULL, NULL);
-	return 1;
+	return addinput(path, NULL, NULL, NOFAIL);
 }
 
 static char *
--- a/src/cmd/cc/cc1/lex.c
+++ b/src/cmd/cc/cc1/lex.c
@@ -83,8 +83,8 @@
 	lineno = input->lineno = line;
 }
 
-void
-addinput(char *fname, Symbol *hide, char *buffer)
+int
+addinput(char *fname, Symbol *hide, char *buffer, int fail)
 {
 	FILE *fp;
 	char *extp;
@@ -101,8 +101,11 @@
 		flags = IMACRO;
 	} else  if (fname) {
 		/* a new file */
-		if ((fp = fopen(fname, "r")) == NULL)
+		if ((fp = fopen(fname, "r")) == NULL) {
+			if (!fail)
+				return 0;
 			die("cc1: %s: %s", fname, strerror(errno));
+		}
 		flags = IFILE;
 		if (curip && onlyheader) {
 			infileln = strlen(infile);
@@ -138,6 +141,7 @@
 	input = newip;
 
 	setloc(fname, (curip) ? curip->lineno : newip->lineno);
+	return 1;
 }
 
 void
--- a/src/cmd/cc/cc1/main.c
+++ b/src/cmd/cc/cc1/main.c
@@ -93,7 +93,7 @@
 		undefmacro(uflags.s[i]);
 
 	infile = (*argv) ? *argv : "<stdin>";
-	addinput(*argv, NULL, NULL);
+	addinput(*argv, NULL, NULL, FAIL);
 
 	if (onlycpp || onlyheader) {
 		outcpp();