shithub: rgbds

Download patch

ref: a99b7f69029b1a7f7e1f4020c03c25fcd32ffae5
parent: b3391f699f85391267e17c6a0182f1cebcecf9b9
parent: a05fd9b8185b59b53fe4b3dc61269182da3b5446
author: Antonio Niño Díaz <antonio_nd@outlook.com>
date: Mon Dec 10 18:09:28 EST 2018

Merge pull request #314 from dbrotz/fix-314

Fix #314

--- a/include/asm/fstack.h
+++ b/include/asm/fstack.h
@@ -42,7 +42,7 @@
 void fstk_AddIncludePath(char *s);
 uint32_t fstk_RunMacro(char *s);
 void fstk_RunRept(uint32_t count);
-FILE *fstk_FindFile(char *fname);
+FILE *fstk_FindFile(char *fname, char **incPathUsed);
 int32_t fstk_GetLine(void);
 
 #endif /* RGBDS_ASM_FSTACK_H */
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -234,7 +234,7 @@
 		fatalerror("Include path too long '%s'", s);
 }
 
-FILE *fstk_FindFile(char *fname)
+FILE *fstk_FindFile(char *fname, char **incPathUsed)
 {
 	char path[_MAX_PATH];
 	int32_t i;
@@ -275,6 +275,8 @@
 				fprintf(dependfile, "%s: %s\n", tzObjectname,
 					path);
 			}
+			if (incPathUsed)
+				*incPathUsed = IncludePaths[i];
 			return f;
 		}
 	}
@@ -288,7 +290,8 @@
  */
 void fstk_RunInclude(char *tzFileName)
 {
-	FILE *f = fstk_FindFile(tzFileName);
+	char *incPathUsed = "";
+	FILE *f = fstk_FindFile(tzFileName, &incPathUsed);
 
 	if (f == NULL)
 		err(1, "Unable to open included file '%s'", tzFileName);
@@ -296,7 +299,8 @@
 	pushcontext();
 	nLineNo = 1;
 	nCurrentStatus = STAT_isInclude;
-	strcpy(tzCurrentFileName, tzFileName);
+	snprintf(tzCurrentFileName, sizeof(tzCurrentFileName), "%s%s",
+		 incPathUsed, tzFileName);
 	pCurrentFile = f;
 	CurrentFlexHandle = yy_create_buffer(pCurrentFile);
 	yy_switch_to_buffer(CurrentFlexHandle);
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -902,7 +902,7 @@
 {
 	FILE *f;
 
-	f = fstk_FindFile(s);
+	f = fstk_FindFile(s, NULL);
 	if (f == NULL)
 		err(1, "Unable to open incbin file '%s'", s);
 
@@ -938,7 +938,7 @@
 	if (length < 0)
 		fatalerror("Number of bytes to read must be greater than zero");
 
-	f = fstk_FindFile(s);
+	f = fstk_FindFile(s, NULL);
 	if (f == NULL)
 		err(1, "Unable to open included file '%s'", s);