From 46aa080edc059d96c0ef7ce9c2e31fa7173c63bd Mon Sep 17 00:00:00 2001 From: John Biddiscombe Date: Tue, 5 Jun 2001 17:41:16 -0400 Subject: [PATCH] ENH: Some tweaks, hacks and #ifdefs required to compile cmake on Borland C++Builder --- Source/cmSystemTools.cxx | 39 +++++++++++++++++++++++++++++++++++++-- Source/cmSystemTools.h | 8 +++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index a878e1fae..dd1dc80d7 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -59,7 +59,11 @@ inline const char* Getcwd(char* buf, unsigned int len) } inline int Chdir(const char* dir) { + #if defined(__BORLANDC__) + return chdir(dir); + #else return _chdir(dir); + #endif } #else #include @@ -147,12 +151,21 @@ bool cmSystemTools::MakeDirectory(const char* path) } if(Mkdir(path) != 0) { + // There is a bug in the Borland Run time library which makes MKDIR + // return EACCES when it should return EEXISTS + #ifdef __BORLANDC__ + if( (errno != EEXIST) && (errno != EACCES) ) + { + return false; + } + #else // if it is some other error besides directory exists // then return false if(errno != EEXIST) { return false; } + #endif } return true; } @@ -329,7 +342,7 @@ std::string cmSystemTools::Capitalized(const std::string& s) n[i] = tolower(s[i]); } return n; -} +} // convert windows slashes to unix slashes \ with / @@ -348,8 +361,30 @@ void cmSystemTools::ConvertToUnixSlashes(std::string& path) } } +// convert windows slashes to unix slashes \ with / +void cmSystemTools::CleanUpWindowsSlashes(std::string& path) +{ + std::string::size_type pos = 0; + while((pos = path.find('/', pos)) != std::string::npos) + { + path[pos] = '\\'; + pos++; + } + // remove any trailing slash + if(path[path.size()-1] == '\\') + { + path = path.substr(0, path.size()-1); + } + // remove any duplicate // slashes + pos = 0; + while((pos = path.find("\\\\", pos)) != std::string::npos) + { + path.erase(pos, 1); + } +} -int cmSystemTools::Grep(const char* dir, const char* file, + +int cmSystemTools::Grep(const char* dir, const char* file, const char* expression) { std::string path = dir; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a0f672f4b..749b2e804 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -88,7 +88,13 @@ public: * Replace Windows file system slashes with Unix-style slashes. */ static void ConvertToUnixSlashes(std::string& path); - + + /** + * Replace Unix file system slashes with Windows-style slashes and + * remove any duplicate slashes to clean the path. + */ + static void CleanUpWindowsSlashes(std::string& path); + ///! Return true if a file exists in the current directory. static bool FileExists(const char* filename);