Merge pull request #314 from dbrotz/fix-314

Fix #314
This commit is contained in:
Antonio Niño Díaz
2018-12-10 23:09:28 +00:00
3 changed files with 10 additions and 6 deletions

View File

@@ -42,7 +42,7 @@ void fstk_Dump(void);
void fstk_AddIncludePath(char *s); void fstk_AddIncludePath(char *s);
uint32_t fstk_RunMacro(char *s); uint32_t fstk_RunMacro(char *s);
void fstk_RunRept(uint32_t count); void fstk_RunRept(uint32_t count);
FILE *fstk_FindFile(char *fname); FILE *fstk_FindFile(char *fname, char **incPathUsed);
int32_t fstk_GetLine(void); int32_t fstk_GetLine(void);
#endif /* RGBDS_ASM_FSTACK_H */ #endif /* RGBDS_ASM_FSTACK_H */

View File

@@ -234,7 +234,7 @@ void fstk_AddIncludePath(char *s)
fatalerror("Include path too long '%s'", s); fatalerror("Include path too long '%s'", s);
} }
FILE *fstk_FindFile(char *fname) FILE *fstk_FindFile(char *fname, char **incPathUsed)
{ {
char path[_MAX_PATH]; char path[_MAX_PATH];
int32_t i; int32_t i;
@@ -275,6 +275,8 @@ FILE *fstk_FindFile(char *fname)
fprintf(dependfile, "%s: %s\n", tzObjectname, fprintf(dependfile, "%s: %s\n", tzObjectname,
path); path);
} }
if (incPathUsed)
*incPathUsed = IncludePaths[i];
return f; return f;
} }
} }
@@ -288,7 +290,8 @@ FILE *fstk_FindFile(char *fname)
*/ */
void fstk_RunInclude(char *tzFileName) void fstk_RunInclude(char *tzFileName)
{ {
FILE *f = fstk_FindFile(tzFileName); char *incPathUsed = "";
FILE *f = fstk_FindFile(tzFileName, &incPathUsed);
if (f == NULL) if (f == NULL)
err(1, "Unable to open included file '%s'", tzFileName); err(1, "Unable to open included file '%s'", tzFileName);
@@ -296,7 +299,8 @@ void fstk_RunInclude(char *tzFileName)
pushcontext(); pushcontext();
nLineNo = 1; nLineNo = 1;
nCurrentStatus = STAT_isInclude; nCurrentStatus = STAT_isInclude;
strcpy(tzCurrentFileName, tzFileName); snprintf(tzCurrentFileName, sizeof(tzCurrentFileName), "%s%s",
incPathUsed, tzFileName);
pCurrentFile = f; pCurrentFile = f;
CurrentFlexHandle = yy_create_buffer(pCurrentFile); CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);

View File

@@ -902,7 +902,7 @@ void out_BinaryFile(char *s)
{ {
FILE *f; FILE *f;
f = fstk_FindFile(s); f = fstk_FindFile(s, NULL);
if (f == NULL) if (f == NULL)
err(1, "Unable to open incbin file '%s'", s); err(1, "Unable to open incbin file '%s'", s);
@@ -938,7 +938,7 @@ void out_BinaryFileSlice(char *s, int32_t start_pos, int32_t length)
if (length < 0) if (length < 0)
fatalerror("Number of bytes to read must be greater than zero"); fatalerror("Number of bytes to read must be greater than zero");
f = fstk_FindFile(s); f = fstk_FindFile(s, NULL);
if (f == NULL) if (f == NULL)
err(1, "Unable to open included file '%s'", s); err(1, "Unable to open included file '%s'", s);