Fix incomplete '\' support in compat mode
See d0f3a9a8df (commitcomment-10583578)
This commit is contained in:
parent
6b3c30aa9e
commit
8b9af3a2e2
@ -131,34 +131,47 @@ SC_FUNC void clearstk(void)
|
|||||||
|
|
||||||
SC_FUNC int plungequalifiedfile(char *name)
|
SC_FUNC int plungequalifiedfile(char *name)
|
||||||
{
|
{
|
||||||
static char *extensions[] = { ".inc", ".p", ".pawn" };
|
static char extensions[][6] = { "", ".inc", ".p", ".pawn" };
|
||||||
int found;
|
int found;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char *path;
|
||||||
|
char *real_path;
|
||||||
char *ext;
|
char *ext;
|
||||||
|
char *ptr;
|
||||||
int ext_idx;
|
int ext_idx;
|
||||||
|
|
||||||
|
fp=NULL;
|
||||||
ext_idx=0;
|
ext_idx=0;
|
||||||
|
path=(char *)malloc(strlen(name)+sizeof(extensions[0]));
|
||||||
|
if (path==NULL)
|
||||||
|
error(103); /* insufficient memory */
|
||||||
|
strcpy(path,name);
|
||||||
|
real_path=(char *)malloc(strlen(name)+sizeof(extensions[0]));
|
||||||
|
if (real_path==NULL)
|
||||||
|
error(103); /* insufficient memory */
|
||||||
do {
|
do {
|
||||||
found=TRUE;
|
found=TRUE;
|
||||||
stat(name, &st);
|
ext=strchr(path,'\0'); /* save position */
|
||||||
if (S_ISDIR(st.st_mode)) {
|
|
||||||
found=FALSE; /* ignore directories with the same name */
|
|
||||||
} else {
|
|
||||||
fp=(FILE*)pc_opensrc(name);
|
|
||||||
if (fp==NULL)
|
|
||||||
found=FALSE;
|
|
||||||
} /* if */
|
|
||||||
ext=strchr(name,'\0'); /* save position */
|
|
||||||
if (!found) {
|
|
||||||
/* try to append an extension */
|
|
||||||
strcpy(ext,extensions[ext_idx]);
|
strcpy(ext,extensions[ext_idx]);
|
||||||
fp=(FILE*)pc_opensrc(name);
|
strcpy(real_path,path);
|
||||||
|
#if DIRSEP_CHAR!='\\'
|
||||||
|
if (pc_compat) {
|
||||||
|
/* convert backslashes to native directory separators for maximum
|
||||||
|
* compatibility with the Windows compiler
|
||||||
|
*/
|
||||||
|
for (ptr=real_path; *ptr!='\0'; ptr++)
|
||||||
|
if (*ptr=='\\')
|
||||||
|
*ptr=DIRSEP_CHAR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
stat(real_path, &st);
|
||||||
|
if (!S_ISDIR(st.st_mode)) /* ignore directories with the same name */
|
||||||
|
fp=(FILE*)pc_opensrc(real_path);
|
||||||
if (fp==NULL) {
|
if (fp==NULL) {
|
||||||
*ext='\0'; /* on failure, restore filename */
|
*ext='\0'; /* on failure, restore filename */
|
||||||
found=FALSE;
|
found=FALSE;
|
||||||
}
|
}
|
||||||
} /* if */
|
|
||||||
ext_idx++;
|
ext_idx++;
|
||||||
} while (!found && ext_idx<(sizeof extensions / sizeof extensions[0]));
|
} while (!found && ext_idx<(sizeof extensions / sizeof extensions[0]));
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@ -175,7 +188,7 @@ static char *extensions[] = { ".inc", ".p", ".pawn" };
|
|||||||
PUSHSTK_I(icomment);
|
PUSHSTK_I(icomment);
|
||||||
PUSHSTK_I(fcurrent);
|
PUSHSTK_I(fcurrent);
|
||||||
PUSHSTK_I(fline);
|
PUSHSTK_I(fline);
|
||||||
inpfname=duplicatestring(name);/* set name of include file */
|
inpfname=duplicatestring(path);/* set name of include file */
|
||||||
if (inpfname==NULL)
|
if (inpfname==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
inpf=fp; /* set input file pointer to include file */
|
inpf=fp; /* set input file pointer to include file */
|
||||||
@ -186,12 +199,21 @@ static char *extensions[] = { ".inc", ".p", ".pawn" };
|
|||||||
insert_dbgfile(inpfname);
|
insert_dbgfile(inpfname);
|
||||||
setfiledirect(inpfname);
|
setfiledirect(inpfname);
|
||||||
listline=-1; /* force a #line directive when changing the file */
|
listline=-1; /* force a #line directive when changing the file */
|
||||||
sc_is_utf8=(short)scan_utf8(inpf,name);
|
sc_is_utf8=(short)scan_utf8(inpf,real_path);
|
||||||
|
free(real_path);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
||||||
{
|
{
|
||||||
|
char dirsep=
|
||||||
|
#if DIRSEP_CHAR!='\\'
|
||||||
|
/* use Windows directory separators in compatibility mode and
|
||||||
|
* native separators otherwise */
|
||||||
|
pc_compat ? '\\' : DIRSEP_CHAR;
|
||||||
|
#else
|
||||||
|
DIRSEP_CHAR;
|
||||||
|
#endif
|
||||||
int result=FALSE;
|
int result=FALSE;
|
||||||
|
|
||||||
if (try_currentpath) {
|
if (try_currentpath) {
|
||||||
@ -202,7 +224,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
|||||||
* there is a (relative) path for the current file
|
* there is a (relative) path for the current file
|
||||||
*/
|
*/
|
||||||
char *ptr;
|
char *ptr;
|
||||||
if ((ptr=strrchr(inpfname,DIRSEP_CHAR))!=0) {
|
if ((ptr=strrchr(inpfname,dirsep))!=0) {
|
||||||
int len=(int)(ptr-inpfname)+1;
|
int len=(int)(ptr-inpfname)+1;
|
||||||
if (len+strlen(name)<_MAX_PATH) {
|
if (len+strlen(name)<_MAX_PATH) {
|
||||||
char path[_MAX_PATH];
|
char path[_MAX_PATH];
|
||||||
@ -214,7 +236,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
|||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (try_includepaths && name[0]!=DIRSEP_CHAR) {
|
if (try_includepaths && name[0]!=dirsep) {
|
||||||
int i;
|
int i;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
for (i=0; !result && (ptr=get_path(i))!=NULL; i++) {
|
for (i=0; !result && (ptr=get_path(i))!=NULL; i++) {
|
||||||
@ -283,20 +305,17 @@ static void doinclude(int silent)
|
|||||||
check_empty(lptr+1); /* verify that the rest of the line is whitespace */
|
check_empty(lptr+1); /* verify that the rest of the line is whitespace */
|
||||||
|
|
||||||
if (pc_compat) {
|
if (pc_compat) {
|
||||||
/* convert backslash to native directory separators for maximum
|
|
||||||
* compatibility with the Windows compiler
|
|
||||||
*/
|
|
||||||
#if DIRSEP_CHAR!='\\'
|
|
||||||
ptr=name;
|
|
||||||
while ((ptr=strchr(ptr,'\\'))!=NULL)
|
|
||||||
*ptr++=DIRSEP_CHAR;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* create a symbol from the name of the include file; this allows the system
|
/* create a symbol from the name of the include file; this allows the system
|
||||||
* to test for multiple inclusions
|
* to test for multiple inclusions
|
||||||
*/
|
*/
|
||||||
|
char dirsep=
|
||||||
|
#if DIRSEP_CHAR!='\\'
|
||||||
|
'\\';
|
||||||
|
#else
|
||||||
|
DIRSEP_CHAR;
|
||||||
|
#endif
|
||||||
strcpy(symname,"_inc_");
|
strcpy(symname,"_inc_");
|
||||||
if ((ptr=strrchr(name,DIRSEP_CHAR))!=NULL)
|
if ((ptr=strrchr(name,dirsep))!=NULL)
|
||||||
strlcat(symname,ptr+1,sizeof symname);
|
strlcat(symname,ptr+1,sizeof symname);
|
||||||
else
|
else
|
||||||
strlcat(symname,name,sizeof symname);
|
strlcat(symname,name,sizeof symname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user