Fix a regression with new file extensions finding different files.

This commit is contained in:
Y_Less 2022-03-19 18:20:06 +00:00
parent c724dc146e
commit 39b8255173
3 changed files with 11 additions and 10 deletions

View File

@ -727,7 +727,7 @@ SC_FUNC cell do_static_check(int use_warning);
SC_FUNC void pushstk(stkitem val); SC_FUNC void pushstk(stkitem val);
SC_FUNC stkitem popstk(void); SC_FUNC stkitem popstk(void);
SC_FUNC void clearstk(void); SC_FUNC void clearstk(void);
SC_FUNC int plungequalifiedfile(char *name); /* explicit path included */ SC_FUNC int plungequalifiedfile(char *name,char new_extensions); /* explicit path included */
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths); /* search through "include" paths */ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths); /* search through "include" paths */
SC_FUNC int number(cell *val,const unsigned char *curptr); SC_FUNC int number(cell *val,const unsigned char *curptr);
SC_FUNC void preprocess(void); SC_FUNC void preprocess(void);

View File

@ -664,7 +664,7 @@ int pc_compile(int argc, char *argv[])
if (strcmp(incfname,sDEF_PREFIX)==0) { if (strcmp(incfname,sDEF_PREFIX)==0) {
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */ plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */
} else { } else {
if (!plungequalifiedfile(incfname)) /* parse "prefix" include file */ if (!plungequalifiedfile(incfname,1)) /* parse "prefix" include file */
error(100,incfname); /* cannot read from ... (fatal error) */ error(100,incfname); /* cannot read from ... (fatal error) */
} /* if */ } /* if */
} /* if */ } /* if */
@ -755,7 +755,7 @@ int pc_compile(int argc, char *argv[])
if (strcmp(incfname,sDEF_PREFIX)==0) if (strcmp(incfname,sDEF_PREFIX)==0)
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" (again) */ plungefile(incfname,FALSE,TRUE); /* parse "default.inc" (again) */
else else
plungequalifiedfile(incfname); /* parse implicit include file (again) */ plungequalifiedfile(incfname,1); /* parse implicit include file (again) */
} /* if */ } /* if */
warnstack_init(); warnstack_init();
preprocess(); /* fetch first line */ preprocess(); /* fetch first line */

View File

@ -132,16 +132,17 @@ SC_FUNC void clearstk(void)
assert(stktop==0); assert(stktop==0);
} }
SC_FUNC int plungequalifiedfile(char *name) SC_FUNC int plungequalifiedfile(char *name,char new_extensions)
{ {
static char extensions[][6] = { "", ".inc", ".p", ".pawn", ".pwn" }; unsigned int skipped_extensions=new_extensions?0:1;
static char extensions[][6] = { "", ".inc", ".p", ".pawn", ".pwn"};
int found; int found;
struct stat st; struct stat st;
FILE *fp; FILE *fp;
char *path; char *path;
char *real_path; char *real_path;
char *ext; char *ext;
int ext_idx; unsigned int ext_idx;
fp=NULL; fp=NULL;
ext_idx=0; ext_idx=0;
@ -178,7 +179,7 @@ SC_FUNC int plungequalifiedfile(char *name)
found=FALSE; found=FALSE;
} /* if */ } /* if */
ext_idx++; ext_idx++;
} while (!found && ext_idx<arraysize(extensions)); } while (!found && ext_idx<arraysize(extensions)-skipped_extensions);
if (!found) { if (!found) {
*ext='\0'; /* restore filename */ *ext='\0'; /* restore filename */
free(path); free(path);
@ -227,7 +228,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
int result=FALSE; int result=FALSE;
if (try_currentpath) { if (try_currentpath) {
result=plungequalifiedfile(name); result=plungequalifiedfile(name,0);
if (!result) { if (!result) {
/* failed to open the file in the active directory, try to open the file /* failed to open the file in the active directory, try to open the file
* in the same directory as the current file --but first check whether * in the same directory as the current file --but first check whether
@ -240,7 +241,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
char path[_MAX_PATH]; char path[_MAX_PATH];
strlcpy(path,inpfname,len+1); strlcpy(path,inpfname,len+1);
strlcat(path,name,arraysize(path)); strlcat(path,name,arraysize(path));
result=plungequalifiedfile(path); result=plungequalifiedfile(path,1);
} /* if */ } /* if */
} /* if */ } /* if */
} /* if */ } /* if */
@ -253,7 +254,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
char path[_MAX_PATH]; char path[_MAX_PATH];
strlcpy(path,ptr,arraysize(path)); strlcpy(path,ptr,arraysize(path));
strlcat(path,name,arraysize(path)); strlcat(path,name,arraysize(path));
result=plungequalifiedfile(path); result=plungequalifiedfile(path,1);
} /* for */ } /* for */
} /* if */ } /* if */
return result; return result;