diff --git a/error.c b/error.c index 64de2c5..31197bf 100644 --- a/error.c +++ b/error.c @@ -364,7 +364,7 @@ static char *ErrorFileName(void) } else { - strcat(errFileName, DIRECTORY_DELIMITER ERROR_FILE_NAME); + strcat(errFileName, ERROR_FILE_NAME); } return errFileName; } diff --git a/misc.c b/misc.c index 94b9b7e..db4f84e 100644 --- a/misc.c +++ b/misc.c @@ -279,8 +279,7 @@ void MS_SuggestFileExt(char *base, char *extension) char *search; search = base+strlen(base)-1; - while(*search != ASCII_SLASH && *search != ASCII_BACKSLASH - && search != base) + while(!MS_IsDirectoryDelimiter(*search) && search != base) { if(*search-- == '.') { @@ -290,6 +289,22 @@ void MS_SuggestFileExt(char *base, char *extension) strcat(base, extension); } +//========================================================================== +// +// MS_IsDirectoryDelimiter +// +//========================================================================== + +boolean MS_IsDirectoryDelimiter(char foo) +{ +#if defined(_WIN32) || defined(__MSDOS__) + return foo == '/' || foo == '\\' || foo == ':'; +#else + return foo == '/'; +#endif +} + + //========================================================================== // // MS_StripFileExt @@ -301,8 +316,7 @@ void MS_StripFileExt(char *name) char *search; search = name+strlen(name)-1; - while(*search != ASCII_SLASH && *search != ASCII_BACKSLASH - && search != name) + while(!MS_IsDirectoryDelimiter(*search) && search != name) { if(*search == '.') { @@ -317,6 +331,8 @@ void MS_StripFileExt(char *name) // // MS_StripFilename // +// [RH] This now leaves the directory delimiter in place. +// //========================================================================== boolean MS_StripFilename(char *name) @@ -330,8 +346,8 @@ boolean MS_StripFilename(char *name) { // No directory delimiter return NO; } - } while(*c != DIRECTORY_DELIMITER_CHAR); - *c = 0; + } while(!MS_IsDirectoryDelimiter(*c)); + *(c+1) = 0; return YES; } @@ -380,15 +396,13 @@ void MS_Message(msg_t type, char *text, ...) boolean MS_IsPathAbsolute(char *name) { -#ifdef WIN32 - // In windows, the second character must be : if it is an +#if defined(_WIN32) || defined(__MSDOS__) + // In Windows, the second character must be : if it is an // absolute path (the first character indicates the drive) - if(name[0] != '\0') - return (name[1] == ':') ? TRUE : FALSE; - else - return FALSE; -#else - // In linux, the first character must be / for a root path - return (name[0] == '/') ? TRUE : FALSE; + // or the first character is either / or \ for absolute path + if((name[0] != '\0') && (name[1] == ':')) + return TRUE; #endif + // In Unix-land, the first character must be / for a root path + return MS_IsDirectoryDelimiter(name[0]); } diff --git a/misc.h b/misc.h index 9234db0..4e57baf 100644 --- a/misc.h +++ b/misc.h @@ -15,9 +15,6 @@ // MACROS ------------------------------------------------------------------ -#define ASCII_SLASH 47 -#define ASCII_BACKSLASH 92 - // TYPES ------------------------------------------------------------------- typedef enum @@ -45,6 +42,7 @@ void MS_StripFileExt(char *name); boolean MS_StripFilename(char *path); void MS_Message(msg_t type, char *text, ...); boolean MS_IsPathAbsolute(char *name); +boolean MS_IsDirectoryDelimiter(char test); // PUBLIC DATA DECLARATIONS ------------------------------------------------ diff --git a/token.c b/token.c index 1c2ae41..bc19cc9 100644 --- a/token.c +++ b/token.c @@ -320,10 +320,10 @@ void TK_AddIncludePath(char *sourcePath) strcpy(IncludePaths[NumIncludePaths], sourcePath); // Not ending with directory delimiter? - if(*(IncludePaths[NumIncludePaths] + strlen(IncludePaths[NumIncludePaths]) - 1) != DIRECTORY_DELIMITER_CHAR) + if(!MS_IsDirectoryDelimiter(*(IncludePaths[NumIncludePaths] + strlen(IncludePaths[NumIncludePaths]) - 1))) { // Add a directory delimiter to the include path - strcat(IncludePaths[NumIncludePaths], DIRECTORY_DELIMITER); + strcat(IncludePaths[NumIncludePaths], "/"); } NumIncludePaths++; } @@ -346,11 +346,6 @@ static void SetLocalIncludePath(char *sourceName) { IncludePaths[0][0] = 0; } - else - { - // Add a directory delimiter to the include path - strcat(IncludePaths[0], DIRECTORY_DELIMITER); - } } @@ -386,7 +381,24 @@ void TK_Include(char *fileName) // Handle absolute paths if(MS_IsPathAbsolute(fileName)) { +#if defined(_WIN32) || defined(__MSDOS__) + sourceName[0] = '\0'; + if(MS_IsDirectoryDelimiter(fileName[0])) + { + // The source file is absolute for the drive, but does not + // specify a drive. Use the path for the current file to + // get the drive letter, if it has one. + if(IncludePaths[0][0] != '\0' && IncludePaths[0][1] == ':') + { + sourceName[0] = IncludePaths[0][0]; + sourceName[1] = ':'; + sourceName[2] = '\0'; + } + } + strcat(sourceName, fileName); +#else strcpy(sourceName, fileName); +#endif foundfile = MS_FileExists(sourceName); } else @@ -410,7 +422,9 @@ void TK_Include(char *fileName) ERR_ErrorAt(tk_SourceName, tk_Line); ERR_Exit(ERR_CANT_FIND_INCLUDE, YES, fileName, tk_SourceName, tk_Line); } - + + MS_Message(MSG_DEBUG, "*Include file found at %s\n", sourceName); + // Now change the first include path to the file directory SetLocalIncludePath(sourceName); @@ -1018,8 +1032,8 @@ static void ProcessQuoteToken(void) *text++ = Chr; } // escape the character after a backslash [JB] - if(Chr == ASCII_BACKSLASH) - escaped ^= (Chr == ASCII_BACKSLASH); + if(Chr == '\\') + escaped ^= (Chr == '\\'); else escaped = FALSE; NextChr();