diff options
Diffstat (limited to 'src/kwsys')
30 files changed, 1385 insertions, 624 deletions
diff --git a/src/kwsys/CMakeLists.txt b/src/kwsys/CMakeLists.txt index 736e30a..8ca4360 100644 --- a/src/kwsys/CMakeLists.txt +++ b/src/kwsys/CMakeLists.txt @@ -85,6 +85,9 @@ # written. CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) +IF(POLICY CMP0025) + CMAKE_POLICY(SET CMP0025 NEW) +ENDIF() #----------------------------------------------------------------------------- # If a namespace is not specified, use "kwsys" and enable testing. @@ -296,6 +299,13 @@ IF(NOT CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*") IF(CMAKE_SYSTEM MATCHES "HP-UX") SET(KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS "+p") + IF(CMAKE_CXX_COMPILER_ID MATCHES "HP") + # it is known that version 3.85 fails and 6.25 works without these flags + IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4) + # use new C++ library and improved template support + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA +hpxstd98") + ENDIF() + ENDIF() ENDIF(CMAKE_SYSTEM MATCHES "HP-UX") ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX) @@ -682,6 +692,7 @@ IF(KWSYS_USE_SystemInformation) # usually it's in libc but on FreeBSD # it's in libexecinfo FIND_LIBRARY(EXECINFO_LIB "execinfo") + MARK_AS_ADVANCED(EXECINFO_LIB) IF (NOT EXECINFO_LIB) SET(EXECINFO_LIB "") ENDIF() @@ -1073,6 +1084,11 @@ IF(MSVC OR (WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")) ) ENDIF() +IF(WIN32) + # Help enforce the use of wide Windows apis. + ADD_DEFINITIONS(-DUNICODE -D_UNICODE) +ENDIF() + IF(KWSYS_USE_String) # Activate code in "String.c". See the comment in the source. SET_SOURCE_FILES_PROPERTIES(String.c PROPERTIES @@ -1155,10 +1171,9 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS}) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE}) TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE}) - SET(TEST_SYSTEMTOOLS_BIN_FILE - "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.bin") - SET(TEST_SYSTEMTOOLS_SRC_FILE - "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.cxx") + + SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") CONFIGURE_FILE( ${PROJECT_SOURCE_DIR}/testSystemTools.h.in ${PROJECT_BINARY_DIR}/testSystemTools.h) @@ -1219,6 +1234,9 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # Some Apple compilers produce bad optimizations in this source. IF(APPLE AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|LLVM)$") SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0) + ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL") + # Tell IBM XL not to warn about our test infinite loop + SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010) ENDIF() # Test SharedForward diff --git a/src/kwsys/CPU.h.in b/src/kwsys/CPU.h.in index 2e1a584..626914b 100644 --- a/src/kwsys/CPU.h.in +++ b/src/kwsys/CPU.h.in @@ -80,6 +80,10 @@ #elif defined(__mips) || defined(__mips__) || defined(__MIPS__) # define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG +/* OpenRISC 1000 */ +#elif defined(__or1k__) +# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG + /* RS/6000 */ #elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER) # define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG diff --git a/src/kwsys/CommandLineArguments.cxx b/src/kwsys/CommandLineArguments.cxx index ece88ae..9fa9802 100644 --- a/src/kwsys/CommandLineArguments.cxx +++ b/src/kwsys/CommandLineArguments.cxx @@ -178,7 +178,7 @@ bool CommandLineArguments::GetMatchedArguments( matches->push_back(parg); } } - return matches->size() > 0; + return !matches->empty(); } //---------------------------------------------------------------------------- @@ -235,7 +235,7 @@ int CommandLineArguments::Parse() return 0; } CommandLineArguments_DEBUG("This is a space argument: " << arg - << " value: " << this->Internals->Argv[cc+1].c_str()); + << " value: " << this->Internals->Argv[cc+1]); // Value is the next argument if ( !this->PopulateVariable(cs, this->Internals->Argv[cc+1].c_str()) ) { @@ -244,7 +244,7 @@ int CommandLineArguments::Parse() cc ++; break; case EQUAL_ARGUMENT: - if ( arg.size() == sarg.size() || *(arg.c_str() + sarg.size()) != '=' ) + if ( arg.size() == sarg.size() || arg.at(sarg.size()) != '=' ) { this->Internals->LastArgument --; return 0; @@ -309,11 +309,11 @@ int CommandLineArguments::Parse() else if ( this->StoreUnusedArgumentsFlag ) { CommandLineArguments_DEBUG("Store unused argument " << arg); - this->Internals->UnusedArguments.push_back(arg.c_str()); + this->Internals->UnusedArguments.push_back(arg); } else { - kwsys_ios::cerr << "Got unknown argument: \"" << arg.c_str() << "\"" << kwsys_ios::endl; + kwsys_ios::cerr << "Got unknown argument: \"" << arg << "\"" << kwsys_ios::endl; this->Internals->LastArgument --; return 0; } diff --git a/src/kwsys/Directory.cxx b/src/kwsys/Directory.cxx index d54e607..741bcba 100644 --- a/src/kwsys/Directory.cxx +++ b/src/kwsys/Directory.cxx @@ -103,7 +103,7 @@ void Directory::Clear() namespace KWSYS_NAMESPACE { -bool Directory::Load(const char* name) +bool Directory::Load(const kwsys_stl::string& name) { this->Clear(); #if _MSC_VER < 1300 @@ -112,16 +112,25 @@ bool Directory::Load(const char* name) intptr_t srchHandle; #endif char* buf; - size_t n = strlen(name); - if ( name[n - 1] == '/' ) + size_t n = name.size(); + if ( *name.rbegin() == '/' || *name.rbegin() == '\\' ) { buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name); + sprintf(buf, "%s*", name.c_str()); } else { + // Make sure the slashes in the wildcard suffix are consistent with the + // rest of the path buf = new char[n + 2 + 1]; - sprintf(buf, "%s/*", name); + if ( name.find('\\') != name.npos ) + { + sprintf(buf, "%s\\*", name.c_str()); + } + else + { + sprintf(buf, "%s/*", name.c_str()); + } } struct _wfinddata_t data; // data of current file @@ -144,7 +153,7 @@ bool Directory::Load(const char* name) return _findclose(srchHandle) != -1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) +unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name) { #if _MSC_VER < 1300 long srchHandle; @@ -152,16 +161,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) intptr_t srchHandle; #endif char* buf; - size_t n = strlen(name); - if ( name[n - 1] == '/' ) + size_t n = name.size(); + if ( *name.rbegin() == '/' ) { buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name); + sprintf(buf, "%s*", name.c_str()); } else { buf = new char[n + 2 + 1]; - sprintf(buf, "%s/*", name); + sprintf(buf, "%s/*", name.c_str()); } struct _wfinddata_t data; // data of current file @@ -206,15 +215,11 @@ p=1992&sid=f16167f51964f1a68fe5041b8eb213b6 namespace KWSYS_NAMESPACE { -bool Directory::Load(const char* name) +bool Directory::Load(const kwsys_stl::string& name) { this->Clear(); - if (!name) - { - return 0; - } - DIR* dir = opendir(name); + DIR* dir = opendir(name.c_str()); if (!dir) { @@ -230,14 +235,9 @@ bool Directory::Load(const char* name) return 1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) +unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name) { - DIR* dir = opendir(name); - - if (!dir) - { - return 0; - } + DIR* dir = opendir(name.c_str()); unsigned long count = 0; for (dirent* d = readdir(dir); d; d = readdir(dir) ) diff --git a/src/kwsys/Directory.hxx.in b/src/kwsys/Directory.hxx.in index 05217c4..0acb191 100644 --- a/src/kwsys/Directory.hxx.in +++ b/src/kwsys/Directory.hxx.in @@ -13,6 +13,13 @@ #define @KWSYS_NAMESPACE@_Directory_hxx #include <@KWSYS_NAMESPACE@/Configure.h> +#include <@KWSYS_NAMESPACE@/stl/string> + +/* Define these macros temporarily to keep the code readable. */ +#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS +# define kwsys_stl @KWSYS_NAMESPACE@_stl +# define kwsys_ios @KWSYS_NAMESPACE@_ios +#endif namespace @KWSYS_NAMESPACE@ { @@ -38,7 +45,7 @@ public: * in that directory. 0 is returned if the directory can not be * opened, 1 if it is opened. */ - bool Load(const char*); + bool Load(const kwsys_stl::string&); /** * Return the number of files in the current directory. @@ -49,7 +56,7 @@ public: * Return the number of files in the specified directory. * A higher performance static method. */ - static unsigned long GetNumberOfFilesInDirectory(const char*); + static unsigned long GetNumberOfFilesInDirectory(const kwsys_stl::string&); /** * Return the file at the given index, the indexing is 0 based @@ -77,4 +84,10 @@ private: } // namespace @KWSYS_NAMESPACE@ +/* Undefine temporary macros. */ +#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS +# undef kwsys_stl +# undef kwsys_ios +#endif + #endif diff --git a/src/kwsys/EncodingCXX.cxx b/src/kwsys/EncodingCXX.cxx index f76deb5..251a56d 100644 --- a/src/kwsys/EncodingCXX.cxx +++ b/src/kwsys/EncodingCXX.cxx @@ -110,16 +110,19 @@ Encoding::CommandLineArguments:: Encoding::CommandLineArguments& Encoding::CommandLineArguments::operator=(const CommandLineArguments& other) { - size_t i; - for(i=0; i<this->argv_.size(); i++) + if(this != &other) { - free(this->argv_[i]); - } + size_t i; + for(i=0; i<this->argv_.size(); i++) + { + free(this->argv_[i]); + } - this->argv_.resize(other.argv_.size()); - for(i=0; i<this->argv_.size(); i++) - { - this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0; + this->argv_.resize(other.argv_.size()); + for(i=0; i<this->argv_.size(); i++) + { + this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0; + } } return *this; diff --git a/src/kwsys/FStream.cxx b/src/kwsys/FStream.cxx new file mode 100644 index 0000000..018652c --- /dev/null +++ b/src/kwsys/FStream.cxx @@ -0,0 +1,76 @@ +/*============================================================================ + KWSys - Kitware System Library + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "kwsysPrivate.h" +#include KWSYS_HEADER(FStream.hxx) + +// Work-around CMake dependency scanning limitation. This must +// duplicate the above list of headers. +#if 0 +# include "FStream.hxx.in" +#endif + +namespace KWSYS_NAMESPACE +{ +namespace FStream +{ + +BOM ReadBOM(std::istream& in) +{ + if(!in.good()) + { + return BOM_None; + } + unsigned long orig = in.tellg(); + unsigned char bom[4]; + in.read(reinterpret_cast<char*>(bom), 2); + if(!in.good()) + { + in.seekg(orig); + return BOM_None; + } + if(bom[0] == 0xEF && bom[1] == 0xBB) + { + in.read(reinterpret_cast<char*>(bom+2), 1); + if(in.good() && bom[2] == 0xBF) + { + return BOM_UTF8; + } + } + else if(bom[0] == 0xFE && bom[1] == 0xFF) + { + return BOM_UTF16BE; + } + else if(bom[0] == 0x00 && bom[1] == 0x00) + { + in.read(reinterpret_cast<char*>(bom+2), 2); + if(in.good() && bom[2] == 0xFE && bom[3] == 0xFF) + { + return BOM_UTF32BE; + } + } + else if(bom[0] == 0xFF && bom[1] == 0xFE) + { + unsigned long p = in.tellg(); + in.read(reinterpret_cast<char*>(bom+2), 2); + if(in.good() && bom[2] == 0x00 && bom[3] == 0x00) + { + return BOM_UTF32LE; + } + in.seekg(p); + return BOM_UTF16LE; + } + in.seekg(orig); + return BOM_None; +} + +} // FStream namespace +} //KWSYS_NAMESPACE diff --git a/src/kwsys/FStream.hxx.in b/src/kwsys/FStream.hxx.in index 916a93e..45425ff 100644 --- a/src/kwsys/FStream.hxx.in +++ b/src/kwsys/FStream.hxx.in @@ -161,13 +161,28 @@ class basic_ofstream : public std::basic_ostream<CharType,Traits> typedef basic_ofstream<char> ofstream; #else - using @KWSYS_NAMESPACE@_ios_namespace::basic_filebuf; using @KWSYS_NAMESPACE@_ios_namespace::ofstream; using @KWSYS_NAMESPACE@_ios_namespace::ifstream; #endif + namespace FStream + { + enum BOM + { + BOM_None, + BOM_UTF8, + BOM_UTF16BE, + BOM_UTF16LE, + BOM_UTF32BE, + BOM_UTF32LE + }; + + // Read a BOM, if one exists. + // If a BOM exists, the stream is advanced to after the BOM. + // This function requires a seekable stream (but not a relative + // seekable stream). + BOM ReadBOM(std::istream& in); + } } - - #endif diff --git a/src/kwsys/Glob.cxx b/src/kwsys/Glob.cxx index 46a7e4f..0916d2e 100644 --- a/src/kwsys/Glob.cxx +++ b/src/kwsys/Glob.cxx @@ -218,7 +218,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, const kwsys_stl::string& dir) { kwsys::Directory d; - if ( !d.Load(dir.c_str()) ) + if ( !d.Load(dir) ) { return; } @@ -229,8 +229,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) { fname = d.GetFile(cc); - if ( strcmp(fname.c_str(), ".") == 0 || - strcmp(fname.c_str(), "..") == 0 ) + if ( fname == "." || fname == ".." ) { continue; } @@ -258,8 +257,8 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, fullname = dir + "/" + fname; } - bool isDir = kwsys::SystemTools::FileIsDirectory(realname.c_str()); - bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str()); + bool isDir = kwsys::SystemTools::FileIsDirectory(realname); + bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname); if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) ) { @@ -271,11 +270,10 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, } else { - if ( (this->Internals->Expressions.size() > 0) && - this->Internals->Expressions[ - this->Internals->Expressions.size()-1].find(fname.c_str()) ) + if ( !this->Internals->Expressions.empty() && + this->Internals->Expressions.rbegin()->find(fname) ) { - this->AddFile(this->Internals->Files, realname.c_str()); + this->AddFile(this->Internals->Files, realname); } } } @@ -299,7 +297,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, } kwsys::Directory d; - if ( !d.Load(dir.c_str()) ) + if ( !d.Load(dir) ) { return; } @@ -310,8 +308,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) { fname = d.GetFile(cc); - if ( strcmp(fname.c_str(), ".") == 0 || - strcmp(fname.c_str(), "..") == 0 ) + if ( fname == "." || fname == ".." ) { continue; } @@ -345,16 +342,16 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, //kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl; if ( !last && - !kwsys::SystemTools::FileIsDirectory(realname.c_str()) ) + !kwsys::SystemTools::FileIsDirectory(realname) ) { continue; } - if ( this->Internals->Expressions[start].find(fname.c_str()) ) + if ( this->Internals->Expressions[start].find(fname) ) { if ( last ) { - this->AddFile(this->Internals->Files, realname.c_str()); + this->AddFile(this->Internals->Files, realname); } else { @@ -374,7 +371,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) this->Internals->Expressions.clear(); this->Internals->Files.clear(); - if ( !kwsys::SystemTools::FileIsFullPath(expr.c_str()) ) + if ( !kwsys::SystemTools::FileIsFullPath(expr) ) { expr = kwsys::SystemTools::GetCurrentWorkingDirectory(); expr += "/" + inexpr; @@ -442,9 +439,9 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) int ch = expr[cc]; if ( ch == '/' ) { - if ( cexpr.size() > 0 ) + if ( !cexpr.empty() ) { - this->AddExpression(cexpr.c_str()); + this->AddExpression(cexpr); } cexpr = ""; } @@ -453,9 +450,9 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) cexpr.append(1, static_cast<char>(ch)); } } - if ( cexpr.size() > 0 ) + if ( !cexpr.empty() ) { - this->AddExpression(cexpr.c_str()); + this->AddExpression(cexpr); } // Handle network paths @@ -471,11 +468,11 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) } //---------------------------------------------------------------------------- -void Glob::AddExpression(const char* expr) +void Glob::AddExpression(const kwsys_stl::string& expr) { this->Internals->Expressions.push_back( kwsys::RegularExpression( - this->PatternToRegex(expr).c_str())); + this->PatternToRegex(expr))); } //---------------------------------------------------------------------------- @@ -500,11 +497,11 @@ const char* Glob::GetRelative() } //---------------------------------------------------------------------------- -void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file) +void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file) { if ( !this->Relative.empty() ) { - files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file)); + files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file.c_str())); } else { diff --git a/src/kwsys/Glob.hxx.in b/src/kwsys/Glob.hxx.in index 88c343c..d8b8491 100644 --- a/src/kwsys/Glob.hxx.in +++ b/src/kwsys/Glob.hxx.in @@ -91,10 +91,10 @@ protected: const kwsys_stl::string& dir); //! Add regular expression - void AddExpression(const char* expr); + void AddExpression(const kwsys_stl::string& expr); //! Add a file to the list - void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file); + void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file); GlobInternals* Internals; bool Recurse; diff --git a/src/kwsys/MD5.c b/src/kwsys/MD5.c index 56776a3..a147057 100644 --- a/src/kwsys/MD5.c +++ b/src/kwsys/MD5.c @@ -478,11 +478,16 @@ void kwsysMD5_Initialize(kwsysMD5* md5) /*--------------------------------------------------------------------------*/ void kwsysMD5_Append(kwsysMD5* md5, unsigned char const* data, int length) { + size_t dlen; if(length < 0) { - length = (int)strlen((char const*)data); + dlen = strlen((char const*)data); } - md5_append(&md5->md5_state, (md5_byte_t const*)data, (size_t)length); + else + { + dlen = (size_t)length; + } + md5_append(&md5->md5_state, (md5_byte_t const*)data, dlen); } /*--------------------------------------------------------------------------*/ diff --git a/src/kwsys/ProcessUNIX.c b/src/kwsys/ProcessUNIX.c index faeb967..ca9d424 100644 --- a/src/kwsys/ProcessUNIX.c +++ b/src/kwsys/ProcessUNIX.c @@ -68,6 +68,7 @@ do. #include <signal.h> /* sigaction */ #include <dirent.h> /* DIR, dirent */ #include <ctype.h> /* isspace */ +#include <assert.h> /* assert */ #if defined(__VMS) # define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK @@ -450,6 +451,7 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) } for(i=0; i < n; ++i) { + assert(command[i]); /* Quiet Clang scan-build. */ newCommands[cp->NumberOfCommands][i] = strdup(command[i]); if(!newCommands[cp->NumberOfCommands][i]) { @@ -2413,6 +2415,12 @@ static void kwsysProcessKill(pid_t process_id) /* Suspend the process to be sure it will not create more children. */ kill(process_id, SIGSTOP); +#if defined(__CYGWIN__) + /* Some Cygwin versions seem to need help here. Give up our time slice + so that the child can process SIGSTOP before we send SIGKILL. */ + usleep(1); +#endif + /* Kill all children if we can find them. */ #if defined(__linux__) || defined(__CYGWIN__) /* First try using the /proc filesystem. */ diff --git a/src/kwsys/RegularExpression.cxx b/src/kwsys/RegularExpression.cxx index c829787..598e7ca 100644 --- a/src/kwsys/RegularExpression.cxx +++ b/src/kwsys/RegularExpression.cxx @@ -882,13 +882,6 @@ void regdump (); static char* regprop (); #endif -bool RegularExpression::find (kwsys_stl::string const& s) -{ - return find(s.c_str()); -} - - - // find -- Matches the regular expression to the given string. // Returns true if found, and sets start and end indexes accordingly. diff --git a/src/kwsys/RegularExpression.hxx.in b/src/kwsys/RegularExpression.hxx.in index 62e9cad..502fbe2 100644 --- a/src/kwsys/RegularExpression.hxx.in +++ b/src/kwsys/RegularExpression.hxx.in @@ -198,13 +198,18 @@ public: * Instantiate RegularExpression with compiled char*. */ inline RegularExpression (char const*); - + /** * Instantiate RegularExpression as a copy of another regular expression. */ RegularExpression (RegularExpression const&); /** + * Instantiate RegularExpression with compiled string. + */ + inline RegularExpression (kwsys_stl::string const&); + + /** * Destructor. */ inline ~RegularExpression(); @@ -216,6 +221,12 @@ public: bool compile (char const*); /** + * Compile a regular expression into internal code + * for later pattern matching. + */ + inline bool compile (kwsys_stl::string const&); + + /** * Matches the regular expression to the given string. * Returns true if found, and sets start and end indexes accordingly. */ @@ -225,7 +236,7 @@ public: * Matches the regular expression to the given std string. * Returns true if found, and sets start and end indexes accordingly. */ - bool find (kwsys_stl::string const&); + inline bool find (kwsys_stl::string const&); /** * Index to start of first find. @@ -313,6 +324,16 @@ inline RegularExpression::RegularExpression (const char* s) } /** + * Creates a regular expression from string s, and + * compiles s. + */ +inline RegularExpression::RegularExpression (const kwsys_stl::string& s) +{ + this->program = 0; + this->compile(s); +} + +/** * Destroys and frees space allocated for the regular expression. */ inline RegularExpression::~RegularExpression () @@ -323,6 +344,24 @@ inline RegularExpression::~RegularExpression () } /** + * Compile a regular expression into internal code + * for later pattern matching. + */ +inline bool RegularExpression::compile (kwsys_stl::string const& s) +{ + return this->compile(s.c_str()); +} + +/** + * Matches the regular expression to the given std string. + * Returns true if found, and sets start and end indexes accordingly. + */ +inline bool RegularExpression::find (kwsys_stl::string const& s) +{ + return this->find(s.c_str()); +} + +/** * Set the start position for the regular expression. */ inline kwsys_stl::string::size_type RegularExpression::start () const diff --git a/src/kwsys/SharedForward.h.in b/src/kwsys/SharedForward.h.in index 8bbc74a..7ff29b4 100644 --- a/src/kwsys/SharedForward.h.in +++ b/src/kwsys/SharedForward.h.in @@ -415,7 +415,7 @@ static int kwsys_shared_forward_realpath(const char* in_path, char* out_path) { #if defined(_WIN32) && !defined(__CYGWIN__) /* Implementation for Windows. */ - DWORD n = GetFullPathName(in_path, KWSYS_SHARED_FORWARD_MAXPATH, + DWORD n = GetFullPathNameA(in_path, KWSYS_SHARED_FORWARD_MAXPATH, out_path, 0); return n > 0 && n <= KWSYS_SHARED_FORWARD_MAXPATH; #else @@ -429,9 +429,9 @@ static int kwsys_shared_forward_samepath(const char* file1, const char* file2) { #if defined(_WIN32) int result = 0; - HANDLE h1 = CreateFile(file1, GENERIC_READ, FILE_SHARE_READ, NULL, + HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - HANDLE h2 = CreateFile(file2, GENERIC_READ, FILE_SHARE_READ, NULL, + HANDLE h2 = CreateFileA(file2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if(h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE) { @@ -462,7 +462,7 @@ static void kwsys_shared_forward_strerror(char* message) #if defined(_WIN32) && !defined(__CYGWIN__) /* Implementation for Windows. */ DWORD original = GetLastError(); - DWORD length = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + DWORD length = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, original, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), message, KWSYS_SHARED_FORWARD_MAXPATH, 0); @@ -512,7 +512,7 @@ static void kwsys_shared_forward_execvp(const char* cmd, /* Invoke the child process. */ #if defined(_MSC_VER) _execvp(cmd, argv); -#elif defined(__MINGW32__) +#elif defined(__MINGW32__) && !defined(__MINGW64__) execvp(cmd, argv); #else execvp(cmd, (char* const*)argv); diff --git a/src/kwsys/System.c b/src/kwsys/System.c index 5d178bf..1ee26fa 100644 --- a/src/kwsys/System.c +++ b/src/kwsys/System.c @@ -353,6 +353,10 @@ static int kwsysSystem_Shell__GetArgumentSize(const char* in, if(kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags)) { /* Surrounding quotes are needed. Allocate space for them. */ + if((flags & kwsysSystem_Shell_Flag_WatcomQuote) && (isUnix)) + { + size += 2; + } size += 2; /* We must escape all ending backslashes when quoting on windows. */ @@ -377,7 +381,18 @@ static char* kwsysSystem_Shell__GetArgument(const char* in, char* out, if(needQuotes) { /* Add the opening quote for this argument. */ - *out++ = '"'; + if(flags & kwsysSystem_Shell_Flag_WatcomQuote) + { + if(isUnix) + { + *out++ = '"'; + } + *out++ = '\''; + } + else + { + *out++ = '"'; + } } /* Scan the string for characters that require escaping or quoting. */ @@ -549,7 +564,18 @@ static char* kwsysSystem_Shell__GetArgument(const char* in, char* out, } /* Add the closing quote for this argument. */ - *out++ = '"'; + if(flags & kwsysSystem_Shell_Flag_WatcomQuote) + { + *out++ = '\''; + if(isUnix) + { + *out++ = '"'; + } + } + else + { + *out++ = '"'; + } } /* Store a terminating null without incrementing. */ diff --git a/src/kwsys/System.h.in b/src/kwsys/System.h.in index 549db90..f21bf0d 100644 --- a/src/kwsys/System.h.in +++ b/src/kwsys/System.h.in @@ -36,6 +36,7 @@ # define kwsysSystem_Shell_Flag_MinGWMake kwsys_ns(System_Shell_Flag_MinGWMake) # define kwsysSystem_Shell_Flag_NMake kwsys_ns(System_Shell_Flag_NMake) # define kwsysSystem_Shell_Flag_AllowMakeVariables kwsys_ns(System_Shell_Flag_AllowMakeVariables) +# define kwsysSystem_Shell_Flag_WatcomQuote kwsys_ns(System_Shell_Flag_WatcomQuote) #endif #ifdef __VMS @@ -102,14 +103,17 @@ enum kwsysSystem_Shell_Flag_e kwsysSystem_Shell_Flag_MinGWMake = (1<<4), /** The target shell is in a NMake makefile. */ - kwsysSystem_Shell_Flag_NMake = (1<<6), + kwsysSystem_Shell_Flag_NMake = (1<<5), /** Make variable reference syntax $(MAKEVAR) should not be escaped to allow a build tool to replace it. Replacement values containing spaces, quotes, backslashes, or other non-alphanumeric characters that have significance to some makes or shells produce undefined behavior. */ - kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<5) + kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<6), + + /** The target shell quoting uses extra single Quotes for Watcom tools. */ + kwsysSystem_Shell_Flag_WatcomQuote = (1<<7) }; /** @@ -156,6 +160,7 @@ kwsysEXPORT char** kwsysSystem_Parse_CommandForUnix(const char* command, # undef kwsysSystem_Shell_Flag_MinGWMake # undef kwsysSystem_Shell_Flag_NMake # undef kwsysSystem_Shell_Flag_AllowMakeVariables +# undef kwsysSystem_Shell_Flag_WatcomQuote # endif #endif diff --git a/src/kwsys/SystemInformation.cxx b/src/kwsys/SystemInformation.cxx index 5f20853..f9248f0 100644 --- a/src/kwsys/SystemInformation.cxx +++ b/src/kwsys/SystemInformation.cxx @@ -88,15 +88,6 @@ typedef int siginfo_t; # include <ifaddrs.h> # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN # endif -# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) -# include <execinfo.h> -# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) -# include <cxxabi.h> -# endif -# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) -# include <dlfcn.h> -# endif -# endif #endif #if defined(__OpenBSD__) || defined(__NetBSD__) @@ -126,16 +117,8 @@ typedef int siginfo_t; # include <ifaddrs.h> # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN # endif -# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050 -# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) -# include <execinfo.h> -# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) -# include <cxxabi.h> -# endif -# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) -# include <dlfcn.h> -# endif -# endif +# if !(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050) +# undef KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE # endif #endif @@ -150,15 +133,6 @@ typedef int siginfo_t; # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN # endif # endif -# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) -# include <execinfo.h> -# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) -# include <cxxabi.h> -# endif -# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) -# include <dlfcn.h> -# endif -# endif # if defined(KWSYS_CXX_HAS_RLIMIT64) typedef struct rlimit64 ResourceLimitType; # define GetResourceLimit getrlimit64 @@ -178,6 +152,19 @@ typedef struct rlimit ResourceLimitType; # include <OS.h> #endif +#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) +# include <execinfo.h> +# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) +# include <cxxabi.h> +# endif +# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) +# include <dlfcn.h> +# endif +#else +# undef KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE +# undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP +#endif + #include <memory.h> #include <stdlib.h> #include <stdio.h> @@ -3709,7 +3696,10 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable) // install ours struct sigaction sa; sa.sa_sigaction=(SigAction)StacktraceSignalHandler; - sa.sa_flags=SA_SIGINFO|SA_RESTART|SA_RESETHAND; + sa.sa_flags=SA_SIGINFO|SA_RESETHAND; +# ifdef SA_RESTART + sa.sa_flags|=SA_RESTART; +# endif sigemptyset(&sa.sa_mask); sigaction(SIGABRT,&sa,0); @@ -3796,7 +3786,7 @@ bool SystemInformationImplementation::QueryLinuxMemory() return false; } - if( unameInfo.release!=0 && strlen(unameInfo.release)>=3 ) + if( strlen(unameInfo.release)>=3 ) { // release looks like "2.6.3-15mdk-i686-up-4GB" char majorChar=unameInfo.release[0]; @@ -4698,11 +4688,28 @@ bool SystemInformationImplementation::QueryHaikuInfo() { #if defined(__HAIKU__) + // CPU count system_info info; get_system_info(&info); - this->NumberOfPhysicalCPU = info.cpu_count; - this->CPUSpeedInMHz = info.cpu_clock_speed / 1000000.0F; + + // CPU speed + uint32 topologyNodeCount = 0; + cpu_topology_node_info* topology = 0; + get_cpu_topology_info(0, &topologyNodeCount); + if (topologyNodeCount != 0) + topology = new cpu_topology_node_info[topologyNodeCount]; + get_cpu_topology_info(topology, &topologyNodeCount); + + for (uint32 i = 0; i < topologyNodeCount; i++) { + if (topology[i].type == B_TOPOLOGY_CORE) { + this->CPUSpeedInMHz = topology[i].data.core.default_frequency / + 1000000.0f; + break; + } + } + + delete[] topology; // Physical Memory this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ; @@ -5006,21 +5013,26 @@ bool SystemInformationImplementation::QueryHPUXProcessor() case CPU_PA_RISC1_0: this->ChipID.Vendor = "Hewlett-Packard"; this->ChipID.Family = 0x100; + break; case CPU_PA_RISC1_1: this->ChipID.Vendor = "Hewlett-Packard"; this->ChipID.Family = 0x110; + break; case CPU_PA_RISC2_0: this->ChipID.Vendor = "Hewlett-Packard"; this->ChipID.Family = 0x200; -# ifdef CPU_HP_INTEL_EM_1_0 + break; +# if defined(CPU_HP_INTEL_EM_1_0) || defined(CPU_IA64_ARCHREV_0) +# ifdef CPU_HP_INTEL_EM_1_0 case CPU_HP_INTEL_EM_1_0: -# endif -# ifdef CPU_IA64_ARCHREV_0 +# endif +# ifdef CPU_IA64_ARCHREV_0 case CPU_IA64_ARCHREV_0: -# endif +# endif this->ChipID.Vendor = "GenuineIntel"; this->Features.HasIA64 = true; break; +# endif default: return false; } diff --git a/src/kwsys/SystemTools.cxx b/src/kwsys/SystemTools.cxx index f4a443f..8a61267 100644 --- a/src/kwsys/SystemTools.cxx +++ b/src/kwsys/SystemTools.cxx @@ -92,7 +92,7 @@ extern char **environ; #endif #ifdef __CYGWIN__ -extern "C" void cygwin_conv_to_win32_path(const char *path, char *win32_path); +# include <sys/cygwin.h> #endif // getpwnam doesn't exist on Windows and Cray Xt3/Catamount @@ -187,14 +187,34 @@ static inline char *realpath(const char *path, char *resolved_path) } #endif +#ifdef _WIN32 +static time_t windows_filetime_to_posix_time(const FILETIME& ft) +{ + LARGE_INTEGER date; + date.HighPart = ft.dwHighDateTime; + date.LowPart = ft.dwLowDateTime; + + // removes the diff between 1970 and 1601 + date.QuadPart -= ((LONGLONG)(369 * 365 + 89) * 24 * 3600 * 10000000); + + // converts back from 100-nanoseconds to seconds + return date.QuadPart / 10000000; +} +#endif + #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) -inline int Mkdir(const char* dir) + +#include <wctype.h> + +inline int Mkdir(const kwsys_stl::string& dir) { - return _wmkdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); + return _wmkdir( + KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); } -inline int Rmdir(const char* dir) +inline int Rmdir(const kwsys_stl::string& dir) { - return _wrmdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); + return _wrmdir( + KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); } inline const char* Getcwd(char* buf, unsigned int len) { @@ -212,15 +232,15 @@ inline const char* Getcwd(char* buf, unsigned int len) } return 0; } -inline int Chdir(const char* dir) +inline int Chdir(const kwsys_stl::string& dir) { #if defined(__BORLANDC__) - return chdir(dir); + return chdir(dir.c_str()); #else return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); #endif } -inline void Realpath(const char *path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) { kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); wchar_t *ptemp; @@ -240,28 +260,28 @@ inline void Realpath(const char *path, kwsys_stl::string & resolved_path) #include <sys/types.h> #include <fcntl.h> #include <unistd.h> -inline int Mkdir(const char* dir) +inline int Mkdir(const kwsys_stl::string& dir) { - return mkdir(dir, 00777); + return mkdir(dir.c_str(), 00777); } -inline int Rmdir(const char* dir) +inline int Rmdir(const kwsys_stl::string& dir) { - return rmdir(dir); + return rmdir(dir.c_str()); } inline const char* Getcwd(char* buf, unsigned int len) { return getcwd(buf, len); } -inline int Chdir(const char* dir) +inline int Chdir(const kwsys_stl::string& dir) { - return chdir(dir); + return chdir(dir.c_str()); } -inline void Realpath(const char *path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) { char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH]; - char *ret = realpath(path, resolved_name); + char *ret = realpath(path.c_str(), resolved_name); if(ret) { resolved_path = ret; @@ -314,9 +334,9 @@ class SystemToolsTranslationMap : void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char* env) { #if defined(_WIN32) && !defined(__CYGWIN__) - const char* pathSep = ";"; + const char pathSep = ';'; #else - const char* pathSep = ":"; + const char pathSep = ':'; #endif if(!env) { @@ -331,7 +351,7 @@ void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char kwsys_stl::string pathEnv = cpathEnv; // A hack to make the below algorithm work. - if(!pathEnv.empty() && pathEnv[pathEnv.length()-1] != pathSep[0]) + if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep) { pathEnv += pathSep; } @@ -603,13 +623,13 @@ const char* SystemTools::GetExecutableExtension() #endif } -FILE* SystemTools::Fopen(const char* file, const char* mode) +FILE* SystemTools::Fopen(const kwsys_stl::string& file, const char* mode) { #ifdef _WIN32 - return _wfopen(Encoding::ToWide(file).c_str(), + return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), Encoding::ToWide(mode).c_str()); #else - return fopen(file, mode); + return fopen(file.c_str(), mode); #endif } @@ -619,15 +639,20 @@ bool SystemTools::MakeDirectory(const char* path) { return false; } + return SystemTools::MakeDirectory(kwsys_stl::string(path)); +} + +bool SystemTools::MakeDirectory(const kwsys_stl::string& path) +{ if(SystemTools::FileExists(path)) { return SystemTools::FileIsDirectory(path); } - kwsys_stl::string dir = path; - if(dir.size() == 0) + if(path.empty()) { return false; } + kwsys_stl::string dir = path; SystemTools::ConvertToUnixSlashes(dir); kwsys_stl::string::size_type pos = 0; @@ -635,11 +660,11 @@ bool SystemTools::MakeDirectory(const char* path) while((pos = dir.find('/', pos)) != kwsys_stl::string::npos) { topdir = dir.substr(0, pos); - Mkdir(topdir.c_str()); + Mkdir(topdir); pos++; } topdir = dir; - if(Mkdir(topdir.c_str()) != 0) + if(Mkdir(topdir) != 0) { // There is a bug in the Borland Run time library which makes MKDIR // return EACCES when it should return EEXISTS @@ -1001,7 +1026,7 @@ bool SystemTools::DeleteRegistryValue(const char *, KeyWOW64) } #endif -bool SystemTools::SameFile(const char* file1, const char* file2) +bool SystemTools::SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2) { #ifdef _WIN32 HANDLE hFile1, hFile2; @@ -1046,7 +1071,7 @@ bool SystemTools::SameFile(const char* file1, const char* file2) fiBuf1.nFileIndexLow == fiBuf2.nFileIndexLow); #else struct stat fileStat1, fileStat2; - if (stat(file1, &fileStat1) == 0 && stat(file2, &fileStat2) == 0) + if (stat(file1.c_str(), &fileStat1) == 0 && stat(file2.c_str(), &fileStat2) == 0) { // see if the files are the same file // check the device inode and size @@ -1065,23 +1090,34 @@ bool SystemTools::SameFile(const char* file1, const char* file2) //---------------------------------------------------------------------------- bool SystemTools::FileExists(const char* filename) { - if(!(filename && *filename)) + if(!filename) + { + return false; + } + return SystemTools::FileExists(kwsys_stl::string(filename)); +} + +//---------------------------------------------------------------------------- +bool SystemTools::FileExists(const kwsys_stl::string& filename) +{ + if(filename.empty()) { return false; } #if defined(__CYGWIN__) // Convert filename to native windows path if possible. char winpath[MAX_PATH]; - if(SystemTools::PathCygwinToWin32(filename, winpath)) + if(SystemTools::PathCygwinToWin32(filename.c_str(), winpath)) { return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES); } - return access(filename, R_OK) == 0; + return access(filename.c_str(), R_OK) == 0; #elif defined(_WIN32) - return (GetFileAttributesW(Encoding::ToWide(filename).c_str()) + return (GetFileAttributesW( + SystemTools::ConvertToWindowsExtendedPath(filename).c_str()) != INVALID_FILE_ATTRIBUTES); #else - return access(filename, R_OK) == 0; + return access(filename.c_str(), R_OK) == 0; #endif } @@ -1098,6 +1134,18 @@ bool SystemTools::FileExists(const char* filename, bool isFile) } //---------------------------------------------------------------------------- +bool SystemTools::FileExists(const kwsys_stl::string& filename, bool isFile) +{ + if(SystemTools::FileExists(filename)) + { + // If isFile is set return not FileIsDirectory, + // so this will only be true if it is a file + return !isFile || !SystemTools::FileIsDirectory(filename); + } + return false; +} + +//---------------------------------------------------------------------------- #ifdef __CYGWIN__ bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path) { @@ -1110,7 +1158,10 @@ bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path) } else { - cygwin_conv_to_win32_path(path, win32_path); + if(cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, win32_path, MAX_PATH) != 0) + { + win32_path[0] = 0; + } SystemToolsTranslationMap::value_type entry(path, win32_path); SystemTools::Cyg2Win32Map->insert(entry); } @@ -1118,7 +1169,7 @@ bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path) } #endif -bool SystemTools::Touch(const char* filename, bool create) +bool SystemTools::Touch(const kwsys_stl::string& filename, bool create) { if(create && !SystemTools::FileExists(filename)) { @@ -1131,10 +1182,11 @@ bool SystemTools::Touch(const char* filename, bool create) return false; } #if defined(_WIN32) && !defined(__CYGWIN__) - HANDLE h = CreateFileW(Encoding::ToWide(filename).c_str(), - FILE_WRITE_ATTRIBUTES, - FILE_SHARE_WRITE, 0, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, 0); + HANDLE h = CreateFileW( + SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), + FILE_WRITE_ATTRIBUTES, + FILE_SHARE_WRITE, 0, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, 0); if(!h) { return false; @@ -1149,13 +1201,13 @@ bool SystemTools::Touch(const char* filename, bool create) CloseHandle(h); #elif KWSYS_CXX_HAS_UTIMENSAT struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}}; - if(utimensat(AT_FDCWD, filename, times, 0) < 0) + if(utimensat(AT_FDCWD, filename.c_str(), times, 0) < 0) { return false; } #else struct stat st; - if(stat(filename, &st) < 0) + if(stat(filename.c_str(), &st) < 0) { return false; } @@ -1171,13 +1223,13 @@ bool SystemTools::Touch(const char* filename, bool create) # endif mtime }; - if(utimes(filename, times) < 0) + if(utimes(filename.c_str(), times) < 0) { return false; } # else struct utimbuf times = {st.st_atime, mtime.tv_sec}; - if(utime(filename, ×) < 0) + if(utime(filename.c_str(), ×) < 0) { return false; } @@ -1186,7 +1238,8 @@ bool SystemTools::Touch(const char* filename, bool create) return true; } -bool SystemTools::FileTimeCompare(const char* f1, const char* f2, +bool SystemTools::FileTimeCompare(const kwsys_stl::string& f1, + const kwsys_stl::string& f2, int* result) { // Default to same time. @@ -1194,12 +1247,12 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2, #if !defined(_WIN32) || defined(__CYGWIN__) // POSIX version. Use stat function to get file modification time. struct stat s1; - if(stat(f1, &s1) != 0) + if(stat(f1.c_str(), &s1) != 0) { return false; } struct stat s2; - if(stat(f2, &s2) != 0) + if(stat(f2.c_str(), &s2) != 0) { return false; } @@ -1236,13 +1289,15 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2, // Windows version. Get the modification time from extended file attributes. WIN32_FILE_ATTRIBUTE_DATA f1d; WIN32_FILE_ATTRIBUTE_DATA f2d; - if(!GetFileAttributesExW(Encoding::ToWide(f1).c_str(), - GetFileExInfoStandard, &f1d)) + if(!GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(f1).c_str(), + GetFileExInfoStandard, &f1d)) { return false; } - if(!GetFileAttributesExW(Encoding::ToWide(f2).c_str(), - GetFileExInfoStandard, &f2d)) + if(!GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(f2).c_str(), + GetFileExInfoStandard, &f2d)) { return false; } @@ -1259,7 +1314,7 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2, kwsys_stl::string SystemTools::Capitalized(const kwsys_stl::string& s) { kwsys_stl::string n; - if(s.size() == 0) + if(s.empty()) { return n; } @@ -1319,7 +1374,7 @@ kwsys_stl::string SystemTools::AddSpaceBetweenCapitalizedWords( const kwsys_stl::string& s) { kwsys_stl::string n; - if (s.size()) + if (!s.empty()) { n.reserve(s.size()); n += s[0]; @@ -1508,6 +1563,17 @@ bool SystemTools::StringStartsWith(const char* str1, const char* str2) return len1 >= len2 && !strncmp(str1, str2, len2) ? true : false; } +// Returns if string starts with another string +bool SystemTools::StringStartsWith(const kwsys_stl::string& str1, const char* str2) +{ + if (!str2) + { + return false; + } + size_t len1 = str1.size(), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1.c_str(), str2, len2) ? true : false; +} + // Returns if string ends with another string bool SystemTools::StringEndsWith(const char* str1, const char* str2) { @@ -1519,6 +1585,17 @@ bool SystemTools::StringEndsWith(const char* str1, const char* str2) return len1 >= len2 && !strncmp(str1 + (len1 - len2), str2, len2) ? true : false; } +// Returns if string ends with another string +bool SystemTools::StringEndsWith(const kwsys_stl::string& str1, const char* str2) +{ + if (!str2) + { + return false; + } + size_t len1 = str1.size(), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1.c_str() + (len1 - len2), str2, len2) ? true : false; +} + // Returns a pointer to the last occurence of str2 in str1 const char* SystemTools::FindLastString(const char* str1, const char* str2) { @@ -1588,7 +1665,7 @@ kwsys_stl::string SystemTools::CropString(const kwsys_stl::string& s, } //---------------------------------------------------------------------------- -kwsys_stl::vector<kwsys::String> SystemTools::SplitString(const char* p, char sep, bool isPath) +kwsys_stl::vector<kwsys::String> SystemTools::SplitString(const kwsys_stl::string& p, char sep, bool isPath) { kwsys_stl::string path = p; kwsys_stl::vector<kwsys::String> paths; @@ -1812,19 +1889,85 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path) // remove trailing slash if the path is more than // a single / pathCString = path.c_str(); - if(path.size() > 1 && *(pathCString+(path.size()-1)) == '/') + size_t size = path.size(); + if(size > 1 && *path.rbegin() == '/') { // if it is c:/ then do not remove the trailing slash - if(!((path.size() == 3 && pathCString[1] == ':'))) + if(!((size == 3 && pathCString[1] == ':'))) { - path = path.substr(0, path.size()-1); + path.resize(size - 1); } } } } +#ifdef _WIN32 +// Convert local paths to UNC style paths +kwsys_stl::wstring +SystemTools::ConvertToWindowsExtendedPath(const kwsys_stl::string &source) +{ + kwsys_stl::wstring wsource = Encoding::ToWide(source); + + // Resolve any relative paths + DWORD wfull_len; + + /* The +3 is a workaround for a bug in some versions of GetFullPathNameW that + * won't return a large enough buffer size if the input is too small */ + wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3; + kwsys_stl::vector<wchar_t> wfull(wfull_len); + GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL); + + /* This should get the correct size without any extra padding from the + * previous size workaround. */ + wfull_len = static_cast<DWORD>(wcslen(&wfull[0])); + + if(wfull_len >= 2 && isalpha(wfull[0]) && wfull[1] == L':') + { /* C:\Foo\bar\FooBar.txt */ + return L"\\\\?\\" + kwsys_stl::wstring(&wfull[0]); + } + else if(wfull_len >= 2 && wfull[0] == L'\\' && wfull[1] == L'\\') + { /* Starts with \\ */ + if(wfull_len >= 4 && wfull[2] == L'?' && wfull[3] == L'\\') + { /* Starts with \\?\ */ + if(wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' && + wfull[6] == L'C' && wfull[7] == L'\\') + { /* \\?\UNC\Foo\bar\FooBar.txt */ + return kwsys_stl::wstring(&wfull[0]); + } + else if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':') + { /* \\?\C:\Foo\bar\FooBar.txt */ + return kwsys_stl::wstring(&wfull[0]); + } + else if(wfull_len >= 5) + { /* \\?\Foo\bar\FooBar.txt */ + return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[4]); + } + } + else if(wfull_len >= 4 && wfull[2] == L'.' && wfull[3] == L'\\') + { /* Starts with \\.\ a device name */ + if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':') + { /* \\.\C:\Foo\bar\FooBar.txt */ + return L"\\\\?\\" + kwsys_stl::wstring(&wfull[4]); + } + else if(wfull_len >= 5) + { /* \\.\Foo\bar\ Device name is left unchanged */ + return kwsys_stl::wstring(&wfull[0]); + } + } + else if(wfull_len >= 3) + { /* \\Foo\bar\FooBar.txt */ + return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[2]); + } + } + + // If this case has been reached, then the path is invalid. Leave it + // unchanged + return Encoding::ToWide(source); +} +#endif + // change // to /, and escape any spaces in the path -kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const kwsys_stl::string& path) { kwsys_stl::string ret = path; @@ -1854,7 +1997,7 @@ kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const char* path) return ret; } -kwsys_stl::string SystemTools::ConvertToOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToOutputPath(const kwsys_stl::string& path) { #if defined(_WIN32) && !defined(__CYGWIN__) return SystemTools::ConvertToWindowsOutputPath(path); @@ -1864,13 +2007,12 @@ kwsys_stl::string SystemTools::ConvertToOutputPath(const char* path) } // remove double slashes not at the start -kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const kwsys_stl::string& path) { kwsys_stl::string ret; // make it big enough for all of path and double quotes - ret.reserve(strlen(path)+3); + ret.reserve(path.size()+3); // put path into the string - ret.assign(path); ret = path; kwsys_stl::string::size_type pos = 0; // first convert all of the slashes @@ -1912,8 +2054,8 @@ kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const char* path) return ret; } -bool SystemTools::CopyFileIfDifferent(const char* source, - const char* destination) +bool SystemTools::CopyFileIfDifferent(const kwsys_stl::string& source, + const kwsys_stl::string& destination) { // special check for a destination that is a directory // FilesDiffer does not handle file to directory compare @@ -1924,7 +2066,7 @@ bool SystemTools::CopyFileIfDifferent(const char* source, new_destination += '/'; kwsys_stl::string source_name = source; new_destination += SystemTools::GetFilenameName(source_name); - if(SystemTools::FilesDiffer(source, new_destination.c_str())) + if(SystemTools::FilesDiffer(source, new_destination)) { return SystemTools::CopyFileAlways(source, destination); } @@ -1947,23 +2089,25 @@ bool SystemTools::CopyFileIfDifferent(const char* source, #define KWSYS_ST_BUFFER 4096 -bool SystemTools::FilesDiffer(const char* source, - const char* destination) +bool SystemTools::FilesDiffer(const kwsys_stl::string& source, + const kwsys_stl::string& destination) { #if defined(_WIN32) WIN32_FILE_ATTRIBUTE_DATA statSource; - if (GetFileAttributesExW(Encoding::ToWide(source).c_str(), - GetFileExInfoStandard, - &statSource) == 0) + if (GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(source).c_str(), + GetFileExInfoStandard, + &statSource) == 0) { return true; } WIN32_FILE_ATTRIBUTE_DATA statDestination; - if (GetFileAttributesExW(Encoding::ToWide(destination).c_str(), - GetFileExInfoStandard, - &statDestination) == 0) + if (GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(destination).c_str(), + GetFileExInfoStandard, + &statDestination) == 0) { return true; } @@ -1984,13 +2128,13 @@ bool SystemTools::FilesDiffer(const char* source, #else struct stat statSource; - if (stat(source, &statSource) != 0) + if (stat(source.c_str(), &statSource) != 0) { return true; } struct stat statDestination; - if (stat(destination, &statDestination) != 0) + if (stat(destination.c_str(), &statDestination) != 0) { return true; } @@ -2008,15 +2152,15 @@ bool SystemTools::FilesDiffer(const char* source, #endif #if defined(_WIN32) - kwsys::ifstream finSource(source, + kwsys::ifstream finSource(source.c_str(), (kwsys_ios::ios::binary | kwsys_ios::ios::in)); - kwsys::ifstream finDestination(destination, + kwsys::ifstream finDestination(destination.c_str(), (kwsys_ios::ios::binary | kwsys_ios::ios::in)); #else - kwsys::ifstream finSource(source); - kwsys::ifstream finDestination(destination); + kwsys::ifstream finSource(source.c_str()); + kwsys::ifstream finDestination(destination.c_str()); #endif if(!finSource || !finDestination) { @@ -2061,7 +2205,7 @@ bool SystemTools::FilesDiffer(const char* source, /** * Copy a file named by "source" to the file named by "destination". */ -bool SystemTools::CopyFileAlways(const char* source, const char* destination) +bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination) { // If files are the same do not copy if ( SystemTools::SameFile(source, destination) ) @@ -2077,31 +2221,33 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) // If destination is a directory, try to create a file with the same // name as the source in that directory. - kwsys_stl::string new_destination; + kwsys_stl::string real_destination = destination; + kwsys_stl::string destination_dir; if(SystemTools::FileExists(destination) && SystemTools::FileIsDirectory(destination)) { - new_destination = destination; - SystemTools::ConvertToUnixSlashes(new_destination); - new_destination += '/'; + destination_dir = real_destination; + SystemTools::ConvertToUnixSlashes(real_destination); + real_destination += '/'; kwsys_stl::string source_name = source; - new_destination += SystemTools::GetFilenameName(source_name); - destination = new_destination.c_str(); + real_destination += SystemTools::GetFilenameName(source_name); + } + else + { + destination_dir = SystemTools::GetFilenamePath(destination); } // Create destination directory - kwsys_stl::string destination_dir = destination; - destination_dir = SystemTools::GetFilenamePath(destination_dir); - SystemTools::MakeDirectory(destination_dir.c_str()); + SystemTools::MakeDirectory(destination_dir); // Open files #if defined(_WIN32) || defined(__CYGWIN__) - kwsys::ifstream fin(source, + kwsys::ifstream fin(source.c_str(), kwsys_ios::ios::binary | kwsys_ios::ios::in); #else - kwsys::ifstream fin(source); + kwsys::ifstream fin(source.c_str()); #endif if(!fin) { @@ -2112,13 +2258,13 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) // can be written to. // If the remove fails continue so that files in read only directories // that do not allow file removal can be modified. - SystemTools::RemoveFile(destination); + SystemTools::RemoveFile(real_destination); #if defined(_WIN32) || defined(__CYGWIN__) - kwsys::ofstream fout(destination, + kwsys::ofstream fout(real_destination.c_str(), kwsys_ios::ios::binary | kwsys_ios::ios::out | kwsys_ios::ios::trunc); #else - kwsys::ofstream fout(destination, + kwsys::ofstream fout(real_destination.c_str(), kwsys_ios::ios::out | kwsys_ios::ios::trunc); #endif if(!fout) @@ -2154,7 +2300,7 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) } if ( perms ) { - if ( !SystemTools::SetPermissions(destination, perm) ) + if ( !SystemTools::SetPermissions(real_destination, perm) ) { return false; } @@ -2163,7 +2309,7 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) } //---------------------------------------------------------------------------- -bool SystemTools::CopyAFile(const char* source, const char* destination, +bool SystemTools::CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always) { if(always) @@ -2180,11 +2326,16 @@ bool SystemTools::CopyAFile(const char* source, const char* destination, * Copy a directory content from "source" directory to the directory named by * "destination". */ -bool SystemTools::CopyADirectory(const char* source, const char* destination, +bool SystemTools::CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always) { Directory dir; +#ifdef _WIN32 + dir.Load(Encoding::ToNarrow( + SystemTools::ConvertToWindowsExtendedPath(source))); +#else dir.Load(source); +#endif size_t fileNum; if ( !SystemTools::MakeDirectory(destination) ) { @@ -2198,13 +2349,13 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination, kwsys_stl::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if(SystemTools::FileIsDirectory(fullPath.c_str())) + if(SystemTools::FileIsDirectory(fullPath)) { kwsys_stl::string fullDestPath = destination; fullDestPath += "/"; fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if (!SystemTools::CopyADirectory(fullPath.c_str(), - fullDestPath.c_str(), + if (!SystemTools::CopyADirectory(fullPath, + fullDestPath, always)) { return false; @@ -2212,7 +2363,7 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination, } else { - if(!SystemTools::CopyAFile(fullPath.c_str(), destination, always)) + if(!SystemTools::CopyAFile(fullPath, destination, always)) { return false; } @@ -2227,15 +2378,28 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination, // return size of file; also returns zero if no file exists unsigned long SystemTools::FileLength(const char* filename) { - struct stat fs; - if (stat(filename, &fs) != 0) + unsigned long length = 0; +#ifdef _WIN32 + WIN32_FILE_ATTRIBUTE_DATA fs; + if (GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), + GetFileExInfoStandard, &fs) != 0) { - return 0; + /* To support the full 64-bit file size, use fs.nFileSizeHigh + * and fs.nFileSizeLow to construct the 64 bit size + + length = ((__int64)fs.nFileSizeHigh << 32) + fs.nFileSizeLow; + */ + length = static_cast<unsigned long>(fs.nFileSizeLow); } - else +#else + struct stat fs; + if (stat(filename, &fs) == 0) { - return static_cast<unsigned long>(fs.st_size); + length = static_cast<unsigned long>(fs.st_size); } +#endif + return length; } int SystemTools::Strucmp(const char *s1, const char *s2) @@ -2252,31 +2416,49 @@ int SystemTools::Strucmp(const char *s1, const char *s2) } // return file's modified time -long int SystemTools::ModifiedTime(const char* filename) +long int SystemTools::ModifiedTime(const kwsys_stl::string& filename) { - struct stat fs; - if (stat(filename, &fs) != 0) + long int mt = 0; +#ifdef _WIN32 + WIN32_FILE_ATTRIBUTE_DATA fs; + if (GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), + GetFileExInfoStandard, + &fs) != 0) { - return 0; + mt = windows_filetime_to_posix_time(fs.ftLastWriteTime); } - else +#else + struct stat fs; + if (stat(filename.c_str(), &fs) == 0) { - return static_cast<long int>(fs.st_mtime); + mt = static_cast<long int>(fs.st_mtime); } +#endif + return mt; } // return file's creation time -long int SystemTools::CreationTime(const char* filename) +long int SystemTools::CreationTime(const kwsys_stl::string& filename) { - struct stat fs; - if (stat(filename, &fs) != 0) + long int ct = 0; +#ifdef _WIN32 + WIN32_FILE_ATTRIBUTE_DATA fs; + if (GetFileAttributesExW( + SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), + GetFileExInfoStandard, + &fs) != 0) { - return 0; + ct = windows_filetime_to_posix_time(fs.ftCreationTime); } - else +#else + struct stat fs; + if (stat(filename.c_str(), &fs) == 0) { - return fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0; + ct = fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0; } +#endif + return ct; } bool SystemTools::ConvertDateMacroString(const char *str, time_t *tmt) @@ -2387,7 +2569,7 @@ kwsys_stl::string SystemTools::GetLastSystemError() return strerror(e); } -bool SystemTools::RemoveFile(const char* source) +bool SystemTools::RemoveFile(const kwsys_stl::string& source) { #ifdef _WIN32 mode_t mode; @@ -2399,9 +2581,10 @@ bool SystemTools::RemoveFile(const char* source) SystemTools::SetPermissions(source, S_IWRITE); #endif #ifdef _WIN32 - bool res = _wunlink(Encoding::ToWide(source).c_str()) != 0 ? false : true; + bool res = + _wunlink(SystemTools::ConvertToWindowsExtendedPath(source).c_str()) == 0; #else - bool res = unlink(source) != 0 ? false : true; + bool res = unlink(source.c_str()) != 0 ? false : true; #endif #ifdef _WIN32 if ( !res ) @@ -2412,7 +2595,7 @@ bool SystemTools::RemoveFile(const char* source) return res; } -bool SystemTools::RemoveADirectory(const char* source) +bool SystemTools::RemoveADirectory(const kwsys_stl::string& source) { // Add write permission to the directory so we can modify its // content to remove files and directories from it. @@ -2428,7 +2611,12 @@ bool SystemTools::RemoveADirectory(const char* source) } Directory dir; +#ifdef _WIN32 + dir.Load(Encoding::ToNarrow( + SystemTools::ConvertToWindowsExtendedPath(source))); +#else dir.Load(source); +#endif size_t fileNum; for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { @@ -2438,17 +2626,17 @@ bool SystemTools::RemoveADirectory(const char* source) kwsys_stl::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if(SystemTools::FileIsDirectory(fullPath.c_str()) && - !SystemTools::FileIsSymlink(fullPath.c_str())) + if(SystemTools::FileIsDirectory(fullPath) && + !SystemTools::FileIsSymlink(fullPath)) { - if (!SystemTools::RemoveADirectory(fullPath.c_str())) + if (!SystemTools::RemoveADirectory(fullPath)) { return false; } } else { - if(!SystemTools::RemoveFile(fullPath.c_str())) + if(!SystemTools::RemoveFile(fullPath)) { return false; } @@ -2497,7 +2685,7 @@ kwsys_stl::string SystemTools i != path.end(); ++i) { kwsys_stl::string& p = *i; - if(p.empty() || p[p.size()-1] != '/') + if(p.empty() || *p.rbegin() != '/') { p += "/"; } @@ -2510,7 +2698,7 @@ kwsys_stl::string SystemTools { tryPath = *p; tryPath += name; - if(SystemTools::FileExists(tryPath.c_str())) + if(SystemTools::FileExists(tryPath)) { return tryPath; } @@ -2530,9 +2718,9 @@ kwsys_stl::string SystemTools bool no_system_path) { kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path); - if(tryPath != "" && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(!tryPath.empty() && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } // Couldn't find the file. return ""; @@ -2549,9 +2737,9 @@ kwsys_stl::string SystemTools bool no_system_path) { kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path); - if(tryPath != "" && SystemTools::FileIsDirectory(tryPath.c_str())) + if(!tryPath.empty() && SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } // Couldn't find the file. return ""; @@ -2571,7 +2759,14 @@ kwsys_stl::string SystemTools::FindProgram( { return ""; } - kwsys_stl::string name = nameIn; + return SystemTools::FindProgram(kwsys_stl::string(nameIn), userPaths, no_system_path); +} + +kwsys_stl::string SystemTools::FindProgram( + const kwsys_stl::string& name, + const kwsys_stl::vector<kwsys_stl::string>& userPaths, + bool no_system_path) +{ kwsys_stl::vector<kwsys_stl::string> extensions; #if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) bool hasExtension = false; @@ -2591,26 +2786,23 @@ kwsys_stl::string SystemTools::FindProgram( kwsys_stl::string tryPath; // first try with extensions if the os supports them - if(extensions.size()) + for(kwsys_stl::vector<kwsys_stl::string>::iterator i = + extensions.begin(); i != extensions.end(); ++i) { - for(kwsys_stl::vector<kwsys_stl::string>::iterator i = - extensions.begin(); i != extensions.end(); ++i) + tryPath = name; + tryPath += *i; + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { - tryPath = name; - tryPath += *i; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) - { - return SystemTools::CollapseFullPath(tryPath.c_str()); - } + return SystemTools::CollapseFullPath(tryPath); } } // now try just the name tryPath = name; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } // now construct the path kwsys_stl::vector<kwsys_stl::string> path; @@ -2633,7 +2825,7 @@ kwsys_stl::string SystemTools::FindProgram( i != path.end(); ++i) { kwsys_stl::string& p = *i; - if(p.empty() || p[p.size()-1] != '/') + if(p.empty() || *p.rbegin() != '/') { p += "/"; } @@ -2648,28 +2840,25 @@ kwsys_stl::string SystemTools::FindProgram( SystemTools::ReplaceString(*p, "\"", ""); #endif // first try with extensions - if(extensions.size()) + for(kwsys_stl::vector<kwsys_stl::string>::iterator ext + = extensions.begin(); ext != extensions.end(); ++ext) { - for(kwsys_stl::vector<kwsys_stl::string>::iterator ext - = extensions.begin(); ext != extensions.end(); ++ext) + tryPath = *p; + tryPath += name; + tryPath += *ext; + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { - tryPath = *p; - tryPath += name; - tryPath += *ext; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) - { - return SystemTools::CollapseFullPath(tryPath.c_str()); - } + return SystemTools::CollapseFullPath(tryPath); } } // now try it without them tryPath = *p; tryPath += name; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } } // Couldn't find the program. @@ -2685,7 +2874,7 @@ kwsys_stl::string SystemTools::FindProgram( it != names.end() ; ++it) { // Try to find the program. - kwsys_stl::string result = SystemTools::FindProgram(it->c_str(), + kwsys_stl::string result = SystemTools::FindProgram(*it, path, noSystemPath); if ( !result.empty() ) @@ -2702,7 +2891,7 @@ kwsys_stl::string SystemTools::FindProgram( * found. Otherwise, the empty string is returned. */ kwsys_stl::string SystemTools -::FindLibrary(const char* name, +::FindLibrary(const kwsys_stl::string& name, const kwsys_stl::vector<kwsys_stl::string>& userPaths) { // See if the executable exists as written. @@ -2729,7 +2918,7 @@ kwsys_stl::string SystemTools i != path.end(); ++i) { kwsys_stl::string& p = *i; - if(p.empty() || p[p.size()-1] != '/') + if(p.empty() || *p.rbegin() != '/') { p += "/"; } @@ -2743,66 +2932,66 @@ kwsys_stl::string SystemTools tryPath = *p; tryPath += name; tryPath += ".framework"; - if(SystemTools::FileExists(tryPath.c_str()) - && SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } #endif #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) tryPath = *p; tryPath += name; tryPath += ".lib"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } #else tryPath = *p; tryPath += "lib"; tryPath += name; tryPath += ".so"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } tryPath = *p; tryPath += "lib"; tryPath += name; tryPath += ".a"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } tryPath = *p; tryPath += "lib"; tryPath += name; tryPath += ".sl"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } tryPath = *p; tryPath += "lib"; tryPath += name; tryPath += ".dylib"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } tryPath = *p; tryPath += "lib"; tryPath += name; tryPath += ".dll"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath.c_str()); + return SystemTools::CollapseFullPath(tryPath); } #endif } @@ -2811,32 +3000,33 @@ kwsys_stl::string SystemTools return ""; } -kwsys_stl::string SystemTools::GetRealPath(const char* path) +kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path) { kwsys_stl::string ret; Realpath(path, ret); return ret; } -bool SystemTools::FileIsDirectory(const char* name) +bool SystemTools::FileIsDirectory(const kwsys_stl::string& inName) { - size_t length = strlen(name); - if (length == 0) + if (inName.empty()) { return false; } + size_t length = inName.size(); + const char* name = inName.c_str(); // Remove any trailing slash from the name except in a root component. char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; std::string string_buffer; size_t last = length-1; if(last > 0 && (name[last] == '/' || name[last] == '\\') - && strcmp(name, "/") !=0 && name[last-1] != ':') + && strcmp(name, "/") != 0 && name[last-1] != ':') { - if(last < sizeof(local_buffer)) + if (last < sizeof(local_buffer)) { memcpy(local_buffer, name, last); - local_buffer[last] = 0; + local_buffer[last] = '\0'; name = local_buffer; } else @@ -2848,7 +3038,8 @@ bool SystemTools::FileIsDirectory(const char* name) // Now check the file node type. #if defined( _WIN32 ) - DWORD attr = GetFileAttributesW(Encoding::ToWide(name).c_str()); + DWORD attr = GetFileAttributesW( + SystemTools::ConvertToWindowsExtendedPath(name).c_str()); if (attr != INVALID_FILE_ATTRIBUTES) { return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; @@ -2865,14 +3056,14 @@ bool SystemTools::FileIsDirectory(const char* name) } } -bool SystemTools::FileIsSymlink(const char* name) +bool SystemTools::FileIsSymlink(const kwsys_stl::string& name) { #if defined( _WIN32 ) (void)name; return false; #else struct stat fs; - if(lstat(name, &fs) == 0) + if(lstat(name.c_str(), &fs) == 0) { return S_ISLNK(fs.st_mode); } @@ -2921,7 +3112,7 @@ bool SystemTools::ReadSymlink(const char* newName, } #endif -int SystemTools::ChangeDirectory(const char *dir) +int SystemTools::ChangeDirectory(const kwsys_stl::string& dir) { return Chdir(dir); } @@ -2937,7 +3128,7 @@ kwsys_stl::string SystemTools::GetCurrentWorkingDirectory(bool collapse) } if(collapse) { - return SystemTools::CollapseFullPath(path.c_str()); + return SystemTools::CollapseFullPath(path); } return path; } @@ -2958,7 +3149,7 @@ bool SystemTools::SplitProgramPath(const char* in_name, file = ""; SystemTools::ConvertToUnixSlashes(dir); - if(!SystemTools::FileIsDirectory(dir.c_str())) + if(!SystemTools::FileIsDirectory(dir)) { kwsys_stl::string::size_type slashPos = dir.rfind("/"); if(slashPos != kwsys_stl::string::npos) @@ -2972,7 +3163,7 @@ bool SystemTools::SplitProgramPath(const char* in_name, dir = ""; } } - if(!(dir == "") && !SystemTools::FileIsDirectory(dir.c_str())) + if(!(dir.empty()) && !SystemTools::FileIsDirectory(dir)) { kwsys_stl::string oldDir = in_name; SystemTools::ConvertToUnixSlashes(oldDir); @@ -2993,8 +3184,8 @@ bool SystemTools::FindProgramPath(const char* argv0, kwsys_stl::string self = argv0 ? argv0 : ""; failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); - self = SystemTools::FindProgram(self.c_str()); - if(!SystemTools::FileExists(self.c_str())) + self = SystemTools::FindProgram(self); + if(!SystemTools::FileExists(self)) { if(buildDir) { @@ -3012,7 +3203,7 @@ bool SystemTools::FindProgramPath(const char* argv0, } if(installPrefix) { - if(!SystemTools::FileExists(self.c_str())) + if(!SystemTools::FileExists(self)) { failures.push_back(self); self = installPrefix; @@ -3020,7 +3211,7 @@ bool SystemTools::FindProgramPath(const char* argv0, self += exeName; } } - if(!SystemTools::FileExists(self.c_str())) + if(!SystemTools::FileExists(self)) { failures.push_back(self); kwsys_ios::ostringstream msg; @@ -3038,7 +3229,7 @@ bool SystemTools::FindProgramPath(const char* argv0, kwsys_stl::vector<kwsys_stl::string>::iterator i; for(i=failures.begin(); i != failures.end(); ++i) { - msg << " \"" << i->c_str() << "\"\n"; + msg << " \"" << *i << "\"\n"; } errorMsg = msg.str(); return false; @@ -3048,12 +3239,12 @@ bool SystemTools::FindProgramPath(const char* argv0, } -kwsys_stl::string SystemTools::CollapseFullPath(const char* in_relative) +kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_relative) { return SystemTools::CollapseFullPath(in_relative, 0); } -void SystemTools::AddTranslationPath(const char * a, const char * b) +void SystemTools::AddTranslationPath(const kwsys_stl::string& a, const kwsys_stl::string& b) { kwsys_stl::string path_a = a; kwsys_stl::string path_b = b; @@ -3061,20 +3252,20 @@ void SystemTools::AddTranslationPath(const char * a, const char * b) SystemTools::ConvertToUnixSlashes(path_b); // First check this is a directory path, since we don't want the table to // grow too fat - if( SystemTools::FileIsDirectory( path_a.c_str() ) ) + if( SystemTools::FileIsDirectory( path_a ) ) { // Make sure the path is a full path and does not contain no '..' // Ken--the following code is incorrect. .. can be in a valid path // for example /home/martink/MyHubba...Hubba/Src - if( SystemTools::FileIsFullPath(path_b.c_str()) && path_b.find("..") + if( SystemTools::FileIsFullPath(path_b) && path_b.find("..") == kwsys_stl::string::npos ) { // Before inserting make sure path ends with '/' - if(path_a.size() && path_a[path_a.size() -1] != '/') + if(!path_a.empty() && *path_a.rbegin() != '/') { path_a += '/'; } - if(path_b.size() && path_b[path_b.size() -1] != '/') + if(!path_b.empty() && *path_b.rbegin() != '/') { path_b += '/'; } @@ -3087,11 +3278,11 @@ void SystemTools::AddTranslationPath(const char * a, const char * b) } } -void SystemTools::AddKeepPath(const char* dir) +void SystemTools::AddKeepPath(const kwsys_stl::string& dir) { kwsys_stl::string cdir; Realpath(SystemTools::CollapseFullPath(dir).c_str(), cdir); - SystemTools::AddTranslationPath(cdir.c_str(), dir); + SystemTools::AddTranslationPath(cdir, dir); } void SystemTools::CheckTranslationPath(kwsys_stl::string & path) @@ -3132,24 +3323,26 @@ SystemToolsAppendComponents( kwsys_stl::vector<kwsys_stl::string>::const_iterator first, kwsys_stl::vector<kwsys_stl::string>::const_iterator last) { + static const kwsys_stl::string up = ".."; + static const kwsys_stl::string cur = "."; for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = first; i != last; ++i) { - if(*i == "..") + if(*i == up) { if(out_components.size() > 1) { - out_components.erase(out_components.end()-1, out_components.end()); + out_components.resize(out_components.size()-1); } } - else if(!(*i == ".") && !(*i == "")) + else if(!i->empty() && *i != cur) { out_components.push_back(*i); } } } -kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path, +kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path, const char* in_base) { // Collect the output path components. @@ -3209,7 +3402,7 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path, // collapsed, so I am going to try to comment it out, and see what hits the // fan, hopefully quickly. // Commented out line below: - //SystemTools::AddTranslationPath(newPath.c_str(), in_path); + //SystemTools::AddTranslationPath(newPath, in_path); SystemTools::CheckTranslationPath(newPath); #ifdef _WIN32 @@ -3221,7 +3414,7 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path, } // compute the relative path from here to there -kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remote) +kwsys_stl::string SystemTools::RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote) { if(!SystemTools::FileIsFullPath(local)) { @@ -3232,9 +3425,12 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot return ""; } + kwsys_stl::string l = SystemTools::CollapseFullPath(local); + kwsys_stl::string r = SystemTools::CollapseFullPath(remote); + // split up both paths into arrays of strings using / as a separator - kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(local, '/', true); - kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(remote, '/', true); + kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(l, '/', true); + kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(r, '/', true); kwsys_stl::vector<kwsys::String> commonPath; // store shared parts of path in this array kwsys_stl::vector<kwsys::String> finalPath; // store the final relative path here // count up how many matching directory names there are from the start @@ -3274,7 +3470,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot // path into the remote dir for(unsigned int i = 0; i < localSplit.size(); ++i) { - if(localSplit[i].size()) + if(!localSplit[i].empty()) { finalPath.push_back("../"); } @@ -3284,7 +3480,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot for(kwsys_stl::vector<String>::iterator vit = remoteSplit.begin(); vit != remoteSplit.end(); ++vit) { - if(vit->size()) + if(!vit->empty()) { finalPath.push_back(*vit); } @@ -3295,7 +3491,7 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot for(kwsys_stl::vector<String>::iterator vit1 = finalPath.begin(); vit1 != finalPath.end(); ++vit1) { - if(relativePath.size() && relativePath[relativePath.size()-1] != '/') + if(!relativePath.empty() && *relativePath.rbegin() != '/') { relativePath += "/"; } @@ -3309,7 +3505,7 @@ static int GetCasePathName(const kwsys_stl::string & pathIn, kwsys_stl::string & casePath) { kwsys_stl::vector<kwsys_stl::string> path_components; - SystemTools::SplitPath(pathIn.c_str(), path_components); + SystemTools::SplitPath(pathIn, path_components); if(path_components[0].empty()) // First component always exists. { // Relative paths cannot be converted. @@ -3340,6 +3536,16 @@ static int GetCasePathName(const kwsys_stl::string & pathIn, kwsys_stl::string test_str = casePath; test_str += path_components[idx]; + // If path component contains wildcards, we skip matching + // because these filenames are not allowed on windows, + // and we do not want to match a different file. + if(path_components[idx].find('*') != kwsys_stl::string::npos || + path_components[idx].find('?') != kwsys_stl::string::npos) + { + casePath = ""; + return 0; + } + WIN32_FIND_DATAW findData; HANDLE hFind = ::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData); @@ -3391,11 +3597,11 @@ kwsys_stl::string SystemTools::GetActualCaseForPath(const char* p) } //---------------------------------------------------------------------------- -const char* SystemTools::SplitPathRootComponent(const char* p, +const char* SystemTools::SplitPathRootComponent(const std::string& p, kwsys_stl::string* root) { // Identify the root component. - const char* c = p; + const char* c = p.c_str(); if((c[0] == '/' && c[1] == '/') || (c[0] == '\\' && c[1] == '\\')) { // Network path. @@ -3477,17 +3683,17 @@ const char* SystemTools::SplitPathRootComponent(const char* p, } //---------------------------------------------------------------------------- -void SystemTools::SplitPath(const char* p, +void SystemTools::SplitPath(const std::string& p, kwsys_stl::vector<kwsys_stl::string>& components, bool expand_home_dir) { - const char* c = p; + const char* c; components.clear(); // Identify the root component. { kwsys_stl::string root; - c = SystemTools::SplitPathRootComponent(c, &root); + c = SystemTools::SplitPathRootComponent(p, &root); // Expand home directory references if requested. if(expand_home_dir && !root.empty() && root[0] == '~') @@ -3517,12 +3723,12 @@ void SystemTools::SplitPath(const char* p, } } #endif - if(!homedir.empty() && (homedir[homedir.size()-1] == '/' || - homedir[homedir.size()-1] == '\\')) + if(!homedir.empty() && (*homedir.rbegin() == '/' || + *homedir.rbegin() == '\\')) { - homedir = homedir.substr(0, homedir.size()-1); + homedir.resize(homedir.size() - 1); } - SystemTools::SplitPath(homedir.c_str(), components); + SystemTools::SplitPath(homedir, components); } else { @@ -3538,9 +3744,7 @@ void SystemTools::SplitPath(const char* p, if(*last == '/' || *last == '\\') { // End of a component. Save it. - components.push_back( - kwsys_stl::string(first,static_cast<kwsys_stl::string::size_type>( - last-first))); + components.push_back(kwsys_stl::string(first, last)); first = last+1; } } @@ -3548,9 +3752,7 @@ void SystemTools::SplitPath(const char* p, // Save the last component unless there were no components. if(last != c) { - components.push_back( - kwsys_stl::string(first,static_cast<kwsys_stl::string::size_type>( - last-first))); + components.push_back(kwsys_stl::string(first, last)); } } @@ -3569,6 +3771,13 @@ SystemTools { // Construct result in a single string. kwsys_stl::string result; + size_t len = 0; + kwsys_stl::vector<kwsys_stl::string>::const_iterator i; + for(i = first; i != last; ++i) + { + len += 1 + i->size(); + } + result.reserve(len); // The first two components do not add a slash. if(first != last) @@ -3592,23 +3801,23 @@ SystemTools } //---------------------------------------------------------------------------- -bool SystemTools::ComparePath(const char* c1, const char* c2) +bool SystemTools::ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2) { #if defined(_WIN32) || defined(__APPLE__) # ifdef _MSC_VER - return _stricmp(c1, c2) == 0; + return _stricmp(c1.c_str(), c2.c_str()) == 0; # elif defined(__APPLE__) || defined(__GNUC__) - return strcasecmp(c1, c2) == 0; + return strcasecmp(c1.c_str(), c2.c_str()) == 0; #else - return SystemTools::Strucmp(c1, c2) == 0; + return SystemTools::Strucmp(c1.c_str(), c2.c_str()) == 0; # endif #else - return strcmp(c1, c2) == 0; + return c1 == c2; #endif } //---------------------------------------------------------------------------- -bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator) +bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator) { kwsys_stl::string data(str); kwsys_stl::string::size_type lpos = 0; @@ -3632,7 +3841,7 @@ bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& l } //---------------------------------------------------------------------------- -bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines) +bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines) { kwsys_stl::string data(str); kwsys_stl::string::size_type lpos = 0; @@ -3677,7 +3886,7 @@ kwsys_stl::string SystemTools::GetFilenamePath(const kwsys_stl::string& filename { return ret + '/'; } - if(ret.size() == 0) + if(ret.empty()) { return "/"; } @@ -3698,7 +3907,7 @@ kwsys_stl::string SystemTools::GetFilenameName(const kwsys_stl::string& filename #if defined(_WIN32) kwsys_stl::string::size_type slash_pos = filename.find_last_of("/\\"); #else - kwsys_stl::string::size_type slash_pos = filename.find_last_of("/"); + kwsys_stl::string::size_type slash_pos = filename.rfind('/'); #endif if(slash_pos != kwsys_stl::string::npos) { @@ -3912,7 +4121,7 @@ bool SystemTools::LocateFileInDir(const char *filename, // Try to find the file in 'dir' bool res = false; - if (filename_base.size() && dir) + if (!filename_base.empty() && dir) { size_t dir_len = strlen(dir); int need_slash = @@ -3925,7 +4134,7 @@ bool SystemTools::LocateFileInDir(const char *filename, } temp += filename_base; - if (SystemTools::FileExists(temp.c_str())) + if (SystemTools::FileExists(temp)) { res = true; filename_found = temp; @@ -3946,10 +4155,10 @@ bool SystemTools::LocateFileInDir(const char *filename, filename_dir = SystemTools::GetFilenamePath(filename_dir); filename_dir_base = SystemTools::GetFilenameName(filename_dir); #if defined( _WIN32 ) - if (!filename_dir_base.size() || - filename_dir_base[filename_dir_base.size() - 1] == ':') + if (filename_dir_base.empty() || + *filename_dir_base.rbegin() == ':') #else - if (!filename_dir_base.size()) + if (filename_dir_base.empty()) #endif { break; @@ -3967,39 +4176,48 @@ bool SystemTools::LocateFileInDir(const char *filename, res = SystemTools::LocateFileInDir( filename_base.c_str(), temp.c_str(), filename_found, 0); - } while (!res && filename_dir_base.size()); + } while (!res && !filename_dir_base.empty()); } } return res; } +bool SystemTools::FileIsFullPath(const kwsys_stl::string& in_name) +{ + return SystemTools::FileIsFullPath(in_name.c_str(), in_name.size()); +} + bool SystemTools::FileIsFullPath(const char* in_name) { - kwsys_stl::string name = in_name; + return SystemTools::FileIsFullPath(in_name, in_name[0] ? (in_name[1] ? 2 : 1) : 0); +} + +bool SystemTools::FileIsFullPath(const char* in_name, size_t len) +{ #if defined(_WIN32) || defined(__CYGWIN__) // On Windows, the name must be at least two characters long. - if(name.length() < 2) + if(len < 2) { return false; } - if(name[1] == ':') + if(in_name[1] == ':') { return true; } - if(name[0] == '\\') + if(in_name[0] == '\\') { return true; } #else // On UNIX, the name must be at least one character long. - if(name.length() < 1) + if(len < 1) { return false; } #endif #if !defined(_WIN32) - if(name[0] == '~') + if(in_name[0] == '~') { return true; } @@ -4007,35 +4225,35 @@ bool SystemTools::FileIsFullPath(const char* in_name) // On UNIX, the name must begin in a '/'. // On Windows, if the name begins in a '/', then it is a full // network path. - if(name[0] == '/') + if(in_name[0] == '/') { return true; } return false; } -bool SystemTools::GetShortPath(const char* path, kwsys_stl::string& shortPath) +bool SystemTools::GetShortPath(const kwsys_stl::string& path, kwsys_stl::string& shortPath) { #if defined(WIN32) && !defined(__CYGWIN__) - const int size = int(strlen(path)) +1; // size of return + const int size = int(path.size()) +1; // size of return char *tempPath = new char[size]; // create a buffer DWORD ret; // if the path passed in has quotes around it, first remove the quotes - if (path[0] == '"' && path[strlen(path)-1] == '"') + if (!path.empty() && path[0] == '"' && *path.rbegin() == '"') { - strcpy(tempPath,path+1); - tempPath[strlen(tempPath)-1] = '\0'; + strcpy(tempPath,path.c_str()+1); + tempPath[size-2] = '\0'; } else { - strcpy(tempPath,path); + strcpy(tempPath,path.c_str()); } kwsys_stl::wstring wtempPath = Encoding::ToWide(tempPath); kwsys_stl::vector<wchar_t> buffer(wtempPath.size()+1); buffer[0] = 0; - ret = GetShortPathNameW(Encoding::ToWide(tempPath).c_str(), + ret = GetShortPathNameW(wtempPath.c_str(), &buffer[0], static_cast<DWORD>(wtempPath.size())); if(buffer[0] == 0 || ret > wtempPath.size()) @@ -4070,7 +4288,7 @@ void SystemTools::SplitProgramFromArgs(const char* path, // may have spaces in its name so we have to look for it kwsys_stl::vector<kwsys_stl::string> e; kwsys_stl::string findProg = SystemTools::FindProgram(path, e); - if(findProg.size()) + if(!findProg.empty()) { program = findProg; args = ""; @@ -4085,7 +4303,7 @@ void SystemTools::SplitProgramFromArgs(const char* path, { kwsys_stl::string tryProg = dir.substr(0, spacePos); // See if the file exists - if(SystemTools::FileExists(tryProg.c_str())) + if(SystemTools::FileExists(tryProg)) { program = tryProg; // remove trailing spaces from program @@ -4099,8 +4317,8 @@ void SystemTools::SplitProgramFromArgs(const char* path, return; } // Now try and find the program in the path - findProg = SystemTools::FindProgram(tryProg.c_str(), e); - if(findProg.size()) + findProg = SystemTools::FindProgram(tryProg, e); + if(!findProg.empty()) { program = findProg; // remove trailing spaces from program @@ -4271,9 +4489,14 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) { return false; } + return SystemTools::GetPermissions(kwsys_stl::string(file), mode); +} +bool SystemTools::GetPermissions(const kwsys_stl::string& file, mode_t& mode) +{ #if defined(_WIN32) - DWORD attr = GetFileAttributesW(Encoding::ToWide(file).c_str()); + DWORD attr = GetFileAttributesW( + SystemTools::ConvertToWindowsExtendedPath(file).c_str()); if(attr == INVALID_FILE_ATTRIBUTES) { return false; @@ -4295,7 +4518,8 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) { mode |= S_IFREG; } - const char* ext = strrchr(file, '.'); + size_t dotPos = file.rfind('.'); + const char* ext = dotPos == file.npos ? 0 : (file.c_str() + dotPos); if(ext && (Strucmp(ext, ".exe") == 0 || Strucmp(ext, ".com") == 0 || Strucmp(ext, ".cmd") == 0 || @@ -4305,7 +4529,7 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) } #else struct stat st; - if ( stat(file, &st) < 0 ) + if ( stat(file.c_str(), &st) < 0 ) { return false; } @@ -4320,14 +4544,20 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) { return false; } + return SystemTools::SetPermissions(kwsys_stl::string(file), mode); +} + +bool SystemTools::SetPermissions(const kwsys_stl::string& file, mode_t mode) +{ if ( !SystemTools::FileExists(file) ) { return false; } #ifdef _WIN32 - if ( _wchmod(Encoding::ToWide(file).c_str(), mode) < 0 ) + if ( _wchmod(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), + mode) < 0 ) #else - if ( chmod(file, mode) < 0 ) + if ( chmod(file.c_str(), mode) < 0 ) #endif { return false; @@ -4336,14 +4566,14 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) return true; } -kwsys_stl::string SystemTools::GetParentDirectory(const char* fileOrDir) +kwsys_stl::string SystemTools::GetParentDirectory(const kwsys_stl::string& fileOrDir) { return SystemTools::GetFilenamePath(fileOrDir); } -bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir) +bool SystemTools::IsSubDirectory(const kwsys_stl::string& cSubdir, const kwsys_stl::string& cDir) { - if(!*cDir) + if(cDir.empty()) { return false; } @@ -4354,7 +4584,7 @@ bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir) if(subdir.size() > dir.size() && subdir[dir.size()] == '/') { std::string s = subdir.substr(0, dir.size()); - return SystemTools::ComparePath(s.c_str(), dir.c_str()); + return SystemTools::ComparePath(s, dir); } return false; } @@ -4383,111 +4613,6 @@ void SystemTools::Delay(unsigned int msec) #endif } -void SystemTools::ConvertWindowsCommandLineToUnixArguments( - const char *cmd_line, int *argc, char ***argv) -{ - if (!cmd_line || !argc || !argv) - { - return; - } - - // A space delimites an argument except when it is inside a quote - - (*argc) = 1; - - size_t cmd_line_len = strlen(cmd_line); - - size_t i; - for (i = 0; i < cmd_line_len; i++) - { - while (isspace(cmd_line[i]) && i < cmd_line_len) - { - i++; - } - if (i < cmd_line_len) - { - if (cmd_line[i] == '\"') - { - i++; - while (cmd_line[i] != '\"' && i < cmd_line_len) - { - i++; - } - (*argc)++; - } - else - { - while (!isspace(cmd_line[i]) && i < cmd_line_len) - { - i++; - } - (*argc)++; - } - } - } - - (*argv) = new char* [(*argc) + 1]; - (*argv)[(*argc)] = NULL; - - // Set the first arg to be the exec name - - (*argv)[0] = new char [1024]; -#ifdef _WIN32 - wchar_t tmp[1024]; - ::GetModuleFileNameW(0, tmp, 1024); - strcpy((*argv)[0], Encoding::ToNarrow(tmp).c_str()); -#else - (*argv)[0][0] = '\0'; -#endif - - // Allocate the others - - int j; - for (j = 1; j < (*argc); j++) - { - (*argv)[j] = new char [cmd_line_len + 10]; - } - - // Grab the args - - size_t pos; - int argc_idx = 1; - - for (i = 0; i < cmd_line_len; i++) - { - while (isspace(cmd_line[i]) && i < cmd_line_len) - { - i++; - } - if (i < cmd_line_len) - { - if (cmd_line[i] == '\"') - { - i++; - pos = i; - while (cmd_line[i] != '\"' && i < cmd_line_len) - { - i++; - } - memcpy((*argv)[argc_idx], &cmd_line[pos], i - pos); - (*argv)[argc_idx][i - pos] = '\0'; - argc_idx++; - } - else - { - pos = i; - while (!isspace(cmd_line[i]) && i < cmd_line_len) - { - i++; - } - memcpy((*argv)[argc_idx], &cmd_line[pos], i - pos); - (*argv)[argc_idx][i - pos] = '\0'; - argc_idx++; - } - } - } - } - kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion() { kwsys_stl::string res; @@ -4915,16 +5040,16 @@ void SystemTools::ClassInitialize() // Strip off one directory level and see if the logical // mapping still works. - pwd_str = SystemTools::GetFilenamePath(pwd_str.c_str()); - cwd_str = SystemTools::GetFilenamePath(cwd_str.c_str()); + pwd_str = SystemTools::GetFilenamePath(pwd_str); + cwd_str = SystemTools::GetFilenamePath(cwd_str); Realpath(pwd_str.c_str(), pwd_path); } // Add the translation to keep the logical path name. if(!cwd_changed.empty() && !pwd_changed.empty()) { - SystemTools::AddTranslationPath(cwd_changed.c_str(), - pwd_changed.c_str()); + SystemTools::AddTranslationPath(cwd_changed, + pwd_changed); } } } diff --git a/src/kwsys/SystemTools.hxx.in b/src/kwsys/SystemTools.hxx.in index 9457a4e..e88bc8f 100644 --- a/src/kwsys/SystemTools.hxx.in +++ b/src/kwsys/SystemTools.hxx.in @@ -158,7 +158,9 @@ public: * Returns true if str1 starts (respectively ends) with str2 */ static bool StringStartsWith(const char* str1, const char* str2); + static bool StringStartsWith(const kwsys_stl::string& str1, const char* str2); static bool StringEndsWith(const char* str1, const char* str2); + static bool StringEndsWith(const kwsys_stl::string& str1, const char* str2); /** * Returns a pointer to the last occurence of str2 in str1 @@ -183,7 +185,7 @@ public: s starts with a / then the first element of the returned array will be /, so /foo/bar will be [/, foo, bar] */ - static kwsys_stl::vector<String> SplitString(const char* s, char separator = '/', + static kwsys_stl::vector<String> SplitString(const kwsys_stl::string& s, char separator = '/', bool isPath = false); /** * Perform a case-independent string comparison @@ -201,8 +203,8 @@ public: * Split a string on its newlines into multiple lines * Return false only if the last line stored had no newline */ - static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l); - static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l, char separator); + static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l); + static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l, char separator); /** * Return string with space added between capitalized words @@ -249,18 +251,29 @@ public: * Replace Windows file system slashes with Unix-style slashes. */ static void ConvertToUnixSlashes(kwsys_stl::string& path); - + +#ifdef _WIN32 + /** + * Convert the path to an extended length path to avoid MAX_PATH length + * limitations on Windows. If the input is a local path the result will be + * prefixed with \\?\; if the input is instead a network path, the result + * will be prefixed with \\?\UNC\. All output will also be converted to + * absolute paths with Windows-style backslashes. + **/ + static kwsys_stl::wstring ConvertToWindowsExtendedPath(const kwsys_stl::string&); +#endif + /** * For windows this calls ConvertToWindowsOutputPath and for unix * it calls ConvertToUnixOutputPath */ - static kwsys_stl::string ConvertToOutputPath(const char*); + static kwsys_stl::string ConvertToOutputPath(const kwsys_stl::string&); /** * Convert the path to a string that can be used in a unix makefile. * double slashes are removed, and spaces are escaped. */ - static kwsys_stl::string ConvertToUnixOutputPath(const char*); + static kwsys_stl::string ConvertToUnixOutputPath(const kwsys_stl::string&); /** * Convert the path to string that can be used in a windows project or @@ -268,7 +281,7 @@ public: * the string, the slashes are converted to windows style backslashes, and * if there are spaces in the string it is double quoted. */ - static kwsys_stl::string ConvertToWindowsOutputPath(const char*); + static kwsys_stl::string ConvertToWindowsOutputPath(const kwsys_stl::string&); /** * Return true if a file exists in the current directory. @@ -277,7 +290,9 @@ public: * if it is a file or a directory. */ static bool FileExists(const char* filename, bool isFile); + static bool FileExists(const kwsys_stl::string& filename, bool isFile); static bool FileExists(const char* filename); + static bool FileExists(const kwsys_stl::string& filename); /** * Converts Cygwin path to Win32 path. Uses dictionary container for @@ -296,7 +311,7 @@ public: /** Change the modification time or create a file */ - static bool Touch(const char* filename, bool create); + static bool Touch(const kwsys_stl::string& filename, bool create); /** * Compare file modification times. @@ -304,7 +319,8 @@ public: * When true is returned, result has -1, 0, +1 for * f1 older, same, or newer than f2. */ - static bool FileTimeCompare(const char* f1, const char* f2, + static bool FileTimeCompare(const kwsys_stl::string& f1, + const kwsys_stl::string& f2, int* result); /** @@ -357,8 +373,8 @@ public: * (which defaults to the current working directory). The full path * is returned. */ - static kwsys_stl::string CollapseFullPath(const char* in_relative); - static kwsys_stl::string CollapseFullPath(const char* in_relative, + static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative); + static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative, const char* in_base); /** @@ -366,7 +382,7 @@ public: * the event of an error (non-existent path, permissions issue, * etc.) the original path is returned. */ - static kwsys_stl::string GetRealPath(const char* path); + static kwsys_stl::string GetRealPath(const kwsys_stl::string& path); /** * Split a path name into its root component and the rest of the @@ -383,7 +399,7 @@ public: * returned. The root component is stored in the "root" string if * given. */ - static const char* SplitPathRootComponent(const char* p, + static const char* SplitPathRootComponent(const std::string& p, kwsys_stl::string* root=0); /** @@ -396,7 +412,7 @@ public: * automatically expanded if expand_home_dir is true and this * platform supports them. */ - static void SplitPath(const char* p, + static void SplitPath(const std::string& p, kwsys_stl::vector<kwsys_stl::string>& components, bool expand_home_dir = true); @@ -413,7 +429,7 @@ public: /** * Compare a path or components of a path. */ - static bool ComparePath(const char* c1, const char* c2); + static bool ComparePath(const kwsys_stl::string& c1, const kwsys_stl::string& c2); /** @@ -459,13 +475,14 @@ public: /** * Return whether the path represents a full path (not relative) */ + static bool FileIsFullPath(const kwsys_stl::string&); static bool FileIsFullPath(const char*); /** * For windows return the short path for the given path, * Unix just a pass through */ - static bool GetShortPath(const char* path, kwsys_stl::string& result); + static bool GetShortPath(const kwsys_stl::string& path, kwsys_stl::string& result); /** * Read line from file. Make sure to get everything. Due to a buggy stream @@ -482,12 +499,12 @@ public: /** * Get the parent directory of the directory or file */ - static kwsys_stl::string GetParentDirectory(const char* fileOrDir); + static kwsys_stl::string GetParentDirectory(const kwsys_stl::string& fileOrDir); /** * Check if the given file or directory is in subdirectory of dir */ - static bool IsSubDirectory(const char* fileOrDir, const char* dir); + static bool IsSubDirectory(const kwsys_stl::string& fileOrDir, const kwsys_stl::string& dir); /** ----------------------------------------------------------------- * File Manipulation Routines @@ -497,7 +514,7 @@ public: /** * Open a file considering unicode. */ - static FILE* Fopen(const char* file, const char* mode); + static FILE* Fopen(const kwsys_stl::string& file, const char* mode); /** * Make a new directory if it is not there. This function @@ -505,35 +522,36 @@ public: * prior to calling this function. */ static bool MakeDirectory(const char* path); + static bool MakeDirectory(const kwsys_stl::string& path); /** * Copy the source file to the destination file only * if the two files differ. */ - static bool CopyFileIfDifferent(const char* source, - const char* destination); + static bool CopyFileIfDifferent(const kwsys_stl::string& source, + const kwsys_stl::string& destination); /** * Compare the contents of two files. Return true if different */ - static bool FilesDiffer(const char* source, const char* destination); + static bool FilesDiffer(const kwsys_stl::string& source, const kwsys_stl::string& destination); /** * Return true if the two files are the same file */ - static bool SameFile(const char* file1, const char* file2); + static bool SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2); /** * Copy a file. */ - static bool CopyFileAlways(const char* source, const char* destination); + static bool CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination); /** * Copy a file. If the "always" argument is true the file is always * copied. If it is false, the file is copied only if it is new or * has changed. */ - static bool CopyAFile(const char* source, const char* destination, + static bool CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always = true); /** @@ -542,18 +560,18 @@ public: * always copied. If it is false, only files that have changed or * are new are copied. */ - static bool CopyADirectory(const char* source, const char* destination, + static bool CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always = true); /** * Remove a file */ - static bool RemoveFile(const char* source); + static bool RemoveFile(const kwsys_stl::string& source); /** * Remove a directory */ - static bool RemoveADirectory(const char* source); + static bool RemoveADirectory(const kwsys_stl::string& source); /** * Get the maximum full file path length @@ -583,12 +601,17 @@ public: */ static kwsys_stl::string FindProgram( const char* name, - const kwsys_stl::vector<kwsys_stl::string>& path = + const kwsys_stl::vector<kwsys_stl::string>& path = + kwsys_stl::vector<kwsys_stl::string>(), + bool no_system_path = false); + static kwsys_stl::string FindProgram( + const kwsys_stl::string& name, + const kwsys_stl::vector<kwsys_stl::string>& path = kwsys_stl::vector<kwsys_stl::string>(), bool no_system_path = false); static kwsys_stl::string FindProgram( const kwsys_stl::vector<kwsys_stl::string>& names, - const kwsys_stl::vector<kwsys_stl::string>& path = + const kwsys_stl::vector<kwsys_stl::string>& path = kwsys_stl::vector<kwsys_stl::string>(), bool no_system_path = false); @@ -596,18 +619,18 @@ public: * Find a library in the system PATH, with optional extra paths */ static kwsys_stl::string FindLibrary( - const char* name, + const kwsys_stl::string& name, const kwsys_stl::vector<kwsys_stl::string>& path); /** * Return true if the file is a directory */ - static bool FileIsDirectory(const char* name); + static bool FileIsDirectory(const kwsys_stl::string& name); /** * Return true if the file is a symlink */ - static bool FileIsSymlink(const char* name); + static bool FileIsSymlink(const kwsys_stl::string& name); /** * Return true if the file has a given signature (first set of bytes) @@ -675,17 +698,17 @@ public: /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1 from /usr/src to /usr/src/test/blah/foo.cpp -> test/blah/foo.cpp */ - static kwsys_stl::string RelativePath(const char* local, const char* remote); + static kwsys_stl::string RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote); /** * Return file's modified time */ - static long int ModifiedTime(const char* filename); + static long int ModifiedTime(const kwsys_stl::string& filename); /** * Return file's creation time (Win32: works only for NTFS, not FAT) */ - static long int CreationTime(const char* filename); + static long int CreationTime(const kwsys_stl::string& filename); #if defined( _MSC_VER ) typedef unsigned short mode_t; @@ -695,7 +718,9 @@ public: * Get and set permissions of the file. */ static bool GetPermissions(const char* file, mode_t& mode); + static bool GetPermissions(const kwsys_stl::string& file, mode_t& mode); static bool SetPermissions(const char* file, mode_t mode); + static bool SetPermissions(const kwsys_stl::string& file, mode_t mode); /** ----------------------------------------------------------------- * Time Manipulation Routines @@ -782,7 +807,7 @@ public: /** * Change directory to the directory specified */ - static int ChangeDirectory(const char* dir); + static int ChangeDirectory(const kwsys_stl::string& dir); /** * Get the result of strerror(errno) @@ -806,13 +831,13 @@ public: /** * Add an entry in the path translation table. */ - static void AddTranslationPath(const char * dir, const char * refdir); + static void AddTranslationPath(const kwsys_stl::string& dir, const kwsys_stl::string& refdir); /** * If dir is different after CollapseFullPath is called, * Then insert it into the path translation table */ - static void AddKeepPath(const char* dir); + static void AddKeepPath(const kwsys_stl::string& dir); /** * Update path by going through the Path Translation table; @@ -831,15 +856,6 @@ public: */ static kwsys_stl::string GetOperatingSystemNameAndVersion(); - /** - * Convert windows-style arguments given as a command-line string - * into more traditional argc/argv arguments. - * Note that argv[0] will be assigned the executable name using - * the GetModuleFileName() function. - */ - static void ConvertWindowsCommandLineToUnixArguments( - const char *cmd_line, int *argc, char ***argv); - /** ----------------------------------------------------------------- * URL Manipulation Routines * ----------------------------------------------------------------- @@ -890,6 +906,11 @@ private: } /** + * Actual implementation of FileIsFullPath. + */ + static bool FileIsFullPath(const char*, size_t); + + /** * Find a filename (file or directory) in the system PATH, with * optional extra paths. */ diff --git a/src/kwsys/Terminal.c b/src/kwsys/Terminal.c index 6d7ec41..e13003f 100644 --- a/src/kwsys/Terminal.c +++ b/src/kwsys/Terminal.c @@ -104,11 +104,11 @@ void kwsysTerminal_cfprintf(int color, FILE* stream, const char* format, ...) } /*--------------------------------------------------------------------------*/ -/* Detect cases when a stream is definately not interactive. */ +/* Detect cases when a stream is definitely not interactive. */ #if !defined(KWSYS_TERMINAL_ISATTY_WORKS) static int kwsysTerminalStreamIsNotInteractive(FILE* stream) { - /* The given stream is definately not interactive if it is a regular + /* The given stream is definitely not interactive if it is a regular file. */ struct stat stream_stat; if(fstat(fileno(stream), &stream_stat) == 0) @@ -212,7 +212,7 @@ static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100, (void)default_tty; return isatty(fileno(stream))? 1:0; #else - /* Check for cases in which the stream is definately not a tty. */ + /* Check for cases in which the stream is definitely not a tty. */ if(kwsysTerminalStreamIsNotInteractive(stream)) { return 0; diff --git a/src/kwsys/hashtable.hxx.in b/src/kwsys/hashtable.hxx.in index 62aa3f3..b93e9be 100644 --- a/src/kwsys/hashtable.hxx.in +++ b/src/kwsys/hashtable.hxx.in @@ -310,6 +310,9 @@ struct _Hashtable_node { _Hashtable_node* _M_next; _Val _M_val; + void public_method_to_quiet_warning_about_all_methods_private(); +private: + void operator=(_Hashtable_node<_Val> const&); // poison node assignment }; template <class _Val, class _Key, class _HashFcn, diff --git a/src/kwsys/kwsysPlatformTests.cmake b/src/kwsys/kwsysPlatformTests.cmake index f9ee254..16bc969 100644 --- a/src/kwsys/kwsysPlatformTests.cmake +++ b/src/kwsys/kwsysPlatformTests.cmake @@ -13,7 +13,7 @@ SET(KWSYS_PLATFORM_TEST_FILE_C kwsysPlatformTestsC.c) SET(KWSYS_PLATFORM_TEST_FILE_CXX kwsysPlatformTestsCXX.cxx) MACRO(KWSYS_PLATFORM_TEST lang var description invert) - IF("${var}_COMPILED" MATCHES "^${var}_COMPILED$") + IF(NOT DEFINED ${var}_COMPILED) MESSAGE(STATUS "${description}") TRY_COMPILE(${var}_COMPILED ${CMAKE_CURRENT_BINARY_DIR} @@ -43,7 +43,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert) MESSAGE(STATUS "${description} - no") ENDIF(${var}_COMPILED) ENDIF(${invert} MATCHES INVERT) - ENDIF("${var}_COMPILED" MATCHES "^${var}_COMPILED$") + ENDIF() IF(${invert} MATCHES INVERT) IF(${var}_COMPILED) SET(${var} 0) @@ -60,7 +60,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert) ENDMACRO(KWSYS_PLATFORM_TEST) MACRO(KWSYS_PLATFORM_TEST_RUN lang var description invert) - IF("${var}" MATCHES "^${var}$") + IF(NOT DEFINED ${var}) MESSAGE(STATUS "${description}") TRY_RUN(${var} ${var}_COMPILED ${CMAKE_CURRENT_BINARY_DIR} @@ -107,7 +107,7 @@ MACRO(KWSYS_PLATFORM_TEST_RUN lang var description invert) MESSAGE(STATUS "${description} - failed to compile") ENDIF(${var}_COMPILED) ENDIF(${invert} MATCHES INVERT) - ENDIF("${var}" MATCHES "^${var}$") + ENDIF() IF(${invert} MATCHES INVERT) IF(${var}_COMPILED) diff --git a/src/kwsys/testCommandLineArguments.cxx b/src/kwsys/testCommandLineArguments.cxx index 72e6544..6a03c0f 100644 --- a/src/kwsys/testCommandLineArguments.cxx +++ b/src/kwsys/testCommandLineArguments.cxx @@ -171,7 +171,7 @@ int testCommandLineArguments(int argc, char* argv[]) CompareTwoLists(strings_argument, valid_strings, 4); CompareTwoLists(stl_strings_argument, valid_stl_strings, 4); - kwsys_ios::cout << "Some STL String variable was set to: " << some_stl_string_variable.c_str() << kwsys_ios::endl; + kwsys_ios::cout << "Some STL String variable was set to: " << some_stl_string_variable << kwsys_ios::endl; kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable << kwsys_ios::endl; kwsys_ios::cout << "Some bool variable was set to: " << some_bool_variable1 << kwsys_ios::endl; kwsys_ios::cout << "bool_arg1 variable was set to: " << bool_arg1 << kwsys_ios::endl; diff --git a/src/kwsys/testCommandLineArguments1.cxx b/src/kwsys/testCommandLineArguments1.cxx index 0860c2a..b65c37f 100644 --- a/src/kwsys/testCommandLineArguments1.cxx +++ b/src/kwsys/testCommandLineArguments1.cxx @@ -21,6 +21,7 @@ # include "kwsys_ios_iostream.h.in" #endif +#include <assert.h> /* assert */ #include <string.h> /* strcmp */ int testCommandLineArguments1(int argc, char* argv[]) @@ -57,12 +58,12 @@ int testCommandLineArguments1(int argc, char* argv[]) } if ( p != "1" ) { - kwsys_ios::cout << "Problem setting P. Value of P: " << p.c_str() << kwsys_ios::endl; + kwsys_ios::cout << "Problem setting P. Value of P: " << p << kwsys_ios::endl; res = 1; } kwsys_ios::cout << "Value of N: " << n << kwsys_ios::endl; kwsys_ios::cout << "Value of M: " << m << kwsys_ios::endl; - kwsys_ios::cout << "Value of P: " << p.c_str() << kwsys_ios::endl; + kwsys_ios::cout << "Value of P: " << p << kwsys_ios::endl; if ( m ) { delete [] m; @@ -83,6 +84,7 @@ int testCommandLineArguments1(int argc, char* argv[]) } for ( cc = 0; cc < newArgc; ++ cc ) { + assert(newArgv[cc]); /* Quiet Clang scan-build. */ kwsys_ios::cout << "Unused argument[" << cc << "] = [" << newArgv[cc] << "]" << kwsys_ios::endl; if ( cc >= 9 ) diff --git a/src/kwsys/testDynamicLoader.cxx b/src/kwsys/testDynamicLoader.cxx index 1bff707..58adb84 100644 --- a/src/kwsys/testDynamicLoader.cxx +++ b/src/kwsys/testDynamicLoader.cxx @@ -108,7 +108,7 @@ int testDynamicLoader(int argc, char *argv[]) // Make sure that inexistent lib is giving correct result res += TestDynamicLoader("azerty_", "foo_bar",0,0,0); // Make sure that random binary file cannot be assimilated as dylib - res += TestDynamicLoader(TEST_SYSTEMTOOLS_BIN_FILE, "wp",0,0,0); + res += TestDynamicLoader(TEST_SYSTEMTOOLS_SOURCE_DIR "/testSystemTools.bin", "wp",0,0,0); #endif #ifdef __linux__ diff --git a/src/kwsys/testFStream.cxx b/src/kwsys/testFStream.cxx index 8942549..9abfd4c 100644 --- a/src/kwsys/testFStream.cxx +++ b/src/kwsys/testFStream.cxx @@ -16,11 +16,17 @@ #endif #include KWSYS_HEADER(FStream.hxx) +#include KWSYS_HEADER(ios/iostream) +#include <string.h> +#ifdef __BORLANDC__ +# include <mem.h> /* memcmp */ +#endif // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. #if 0 # include "FStream.hxx.in" +# include "kwsys_ios_iostream.h.in" #endif @@ -36,6 +42,141 @@ static int testNoFile() return 0; } +static kwsys::FStream::BOM expected_bom[5] = +{ + kwsys::FStream::BOM_UTF8, + kwsys::FStream::BOM_UTF16LE, + kwsys::FStream::BOM_UTF16BE, + kwsys::FStream::BOM_UTF32LE, + kwsys::FStream::BOM_UTF32BE +}; + +static unsigned char expected_bom_data[5][5] = +{ + {3, 0xEF, 0xBB, 0xBF}, + {2, 0xFF, 0xFE}, + {2, 0xFE, 0xFF}, + {4, 0xFF, 0xFE, 0x00, 0x00}, + {4, 0x00, 0x00, 0xFE, 0xFF}, +}; + +static unsigned char file_data[5][45] = +{ + {11, 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'}, + {22, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x20, 0x00, + 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00}, + {22, 0x00, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x20, + 0x00, 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64}, + {44, 0x48, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, + 0x6C, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x57, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, + 0x6C, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00}, + {44, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x6C, + 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x72, + 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x64}, +}; + +//---------------------------------------------------------------------------- +static int testBOM() +{ + // test various encodings in binary mode + for(int i=0; i<5; i++) + { + { + kwsys::ofstream out("bom.txt", kwsys::ofstream::binary); + out.write(reinterpret_cast<const char*>(expected_bom_data[i]+1), + *expected_bom_data[i]); + out.write(reinterpret_cast<const char*>(file_data[i]+1), + file_data[i][0]); + } + + kwsys::ifstream in("bom.txt", kwsys::ofstream::binary); + kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in); + if(bom != expected_bom[i]) + { + kwsys_ios::cout << "Unexpected BOM " << i << std::endl; + return 1; + } + char data[45]; + in.read(data, file_data[i][0]); + if(!in.good()) + { + kwsys_ios::cout << "Unable to read data " << i << std::endl; + return 1; + } + + if(memcmp(data, file_data[i]+1, file_data[i][0]) != 0) + { + kwsys_ios::cout << "Incorrect read data " << i << std::endl; + return 1; + } + + } + + // test text file without bom + { + { + kwsys::ofstream out("bom.txt"); + out << "Hello World"; + } + + kwsys::ifstream in("bom.txt"); + kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in); + if(bom != kwsys::FStream::BOM_None) + { + kwsys_ios::cout << "Unexpected BOM for none case" << std::endl; + return 1; + } + char data[45]; + in.read(data, file_data[0][0]); + if(!in.good()) + { + kwsys_ios::cout << "Unable to read data for none case" << std::endl; + return 1; + } + + if(memcmp(data, file_data[0]+1, file_data[0][0]) != 0) + { + kwsys_ios::cout << "Incorrect read data for none case" << std::endl; + return 1; + } + } + + // test text file with utf-8 bom + { + { + kwsys::ofstream out("bom.txt"); + out.write(reinterpret_cast<const char*>(expected_bom_data[0]+1), + *expected_bom_data[0]); + out << "Hello World"; + } + + kwsys::ifstream in("bom.txt"); + kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in); + if(bom != kwsys::FStream::BOM_UTF8) + { + kwsys_ios::cout << "Unexpected BOM for utf-8 case" << std::endl; + return 1; + } + char data[45]; + in.read(data, file_data[0][0]); + if(!in.good()) + { + kwsys_ios::cout << "Unable to read data for utf-8 case" << std::endl; + return 1; + } + + if(memcmp(data, file_data[0]+1, file_data[0][0]) != 0) + { + kwsys_ios::cout << "Incorrect read data for utf-8 case" << std::endl; + return 1; + } + } + + return 0; +} + //---------------------------------------------------------------------------- int testFStream(int, char*[]) @@ -43,6 +184,7 @@ int testFStream(int, char*[]) int ret = 0; ret |= testNoFile(); + ret |= testBOM(); return ret; } diff --git a/src/kwsys/testProcess.c b/src/kwsys/testProcess.c index 6d5eb71..47c3fb0 100644 --- a/src/kwsys/testProcess.c +++ b/src/kwsys/testProcess.c @@ -11,13 +11,16 @@ ============================================================================*/ #include "kwsysPrivate.h" #include KWSYS_HEADER(Process.h) +#include KWSYS_HEADER(Encoding.h) /* Work-around CMake dependency scanning limitation. This must duplicate the above list of headers. */ #if 0 # include "Process.h.in" +# include "Encoding.h.in" #endif +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -102,6 +105,7 @@ static int test4(int argc, const char* argv[]) fprintf(stderr, "Output before crash on stderr from crash test.\n"); fflush(stdout); fflush(stderr); + assert(invalidAddress); /* Quiet Clang scan-build. */ /* Provoke deliberate crash by writing to the invalid address. */ *invalidAddress = 0; fprintf(stdout, "Output after crash on stdout from crash test.\n"); @@ -393,6 +397,19 @@ int runChild(const char* cmd[], int state, int exception, int value, int main(int argc, const char* argv[]) { int n = 0; + +#ifdef _WIN32 + int i; + char new_args[10][_MAX_PATH]; + LPWSTR* w_av = CommandLineToArgvW(GetCommandLineW(), &argc); + for(i=0; i<argc; i++) + { + kwsysEncoding_wcstombs(new_args[i], w_av[i], _MAX_PATH); + argv[i] = new_args[i]; + } + LocalFree(w_av); +#endif + #if 0 { HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); diff --git a/src/kwsys/testSystemTools.cxx b/src/kwsys/testSystemTools.cxx index 1690fd5..b41532b 100644 --- a/src/kwsys/testSystemTools.cxx +++ b/src/kwsys/testSystemTools.cxx @@ -60,8 +60,8 @@ static bool CheckConvertToUnixSlashes(kwsys_stl::string input, if ( result != output ) { kwsys_ios::cerr - << "Problem with ConvertToUnixSlashes - input: " << input.c_str() - << " output: " << result.c_str() << " expected: " << output.c_str() + << "Problem with ConvertToUnixSlashes - input: " << input + << " output: " << result << " expected: " << output << kwsys_ios::endl; return false; } @@ -86,8 +86,8 @@ static bool CheckEscapeChars(kwsys_stl::string input, if (result != output) { kwsys_ios::cerr - << "Problem with CheckEscapeChars - input: " << input.c_str() - << " output: " << result.c_str() << " expected: " << output.c_str() + << "Problem with CheckEscapeChars - input: " << input + << " output: " << result << " expected: " << output << kwsys_ios::endl; return false; } @@ -98,32 +98,124 @@ static bool CheckEscapeChars(kwsys_stl::string input, static bool CheckFileOperations() { bool res = true; - - if (kwsys::SystemTools::DetectFileType(TEST_SYSTEMTOOLS_BIN_FILE) != + const kwsys_stl::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR + "/testSystemTools.bin"); + const kwsys_stl::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR + "/testSystemTools.cxx"); + const kwsys_stl::string testNewDir(TEST_SYSTEMTOOLS_BINARY_DIR + "/testSystemToolsNewDir"); + const kwsys_stl::string testNewFile(testNewDir + "/testNewFile.txt"); + + if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) != kwsys::SystemTools::FileTypeBinary) { kwsys_ios::cerr << "Problem with DetectFileType - failed to detect type of: " - << TEST_SYSTEMTOOLS_BIN_FILE << kwsys_ios::endl; + << testBinFile << kwsys_ios::endl; res = false; } - if (kwsys::SystemTools::DetectFileType(TEST_SYSTEMTOOLS_SRC_FILE) != + if (kwsys::SystemTools::DetectFileType(testTxtFile.c_str()) != kwsys::SystemTools::FileTypeText) { kwsys_ios::cerr << "Problem with DetectFileType - failed to detect type of: " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << testTxtFile << kwsys_ios::endl; res = false; } - - if (kwsys::SystemTools::FileLength(TEST_SYSTEMTOOLS_BIN_FILE) != 766) + + if (kwsys::SystemTools::FileLength(testBinFile.c_str()) != 766) { kwsys_ios::cerr << "Problem with FileLength - incorrect length for: " - << TEST_SYSTEMTOOLS_BIN_FILE << kwsys_ios::endl; - res = false; + << testBinFile << kwsys_ios::endl; + res = false; + } + + if (!kwsys::SystemTools::MakeDirectory(testNewDir)) + { + kwsys_ios::cerr + << "Problem with MakeDirectory for: " + << testNewDir << kwsys_ios::endl; + res = false; + } + + if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true)) + { + kwsys_ios::cerr + << "Problem with Touch for: " + << testNewFile << kwsys_ios::endl; + res = false; + } + + if (!kwsys::SystemTools::RemoveFile(testNewFile)) + { + kwsys_ios::cerr + << "Problem with RemoveFile: " + << testNewFile << kwsys_ios::endl; + res = false; + } + + kwsys::SystemTools::Touch(testNewFile.c_str(), true); + if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) + { + kwsys_ios::cerr + << "Problem with RemoveADirectory for: " + << testNewDir << kwsys_ios::endl; + res = false; + } + +#ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS + // Perform the same file and directory creation and deletion tests but + // with paths > 256 characters in length. + + const kwsys_stl::string testNewLongDir( + TEST_SYSTEMTOOLS_BINARY_DIR "/" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "01234567890123"); + const kwsys_stl::string testNewLongFile(testNewLongDir + "/" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "0123456789.txt"); + + if (!kwsys::SystemTools::MakeDirectory(testNewLongDir)) + { + kwsys_ios::cerr + << "Problem with MakeDirectory for: " + << testNewLongDir << kwsys_ios::endl; + res = false; + } + + if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true)) + { + kwsys_ios::cerr + << "Problem with Touch for: " + << testNewLongFile << kwsys_ios::endl; + res = false; + } + + if (!kwsys::SystemTools::RemoveFile(testNewLongFile)) + { + kwsys_ios::cerr + << "Problem with RemoveFile: " + << testNewLongFile << kwsys_ios::endl; + res = false; + } + + kwsys::SystemTools::Touch(testNewLongFile.c_str(), true); + if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir)) + { + kwsys_ios::cerr + << "Problem with RemoveADirectory for: " + << testNewLongDir << kwsys_ios::endl; + res = false; } +#endif return res; } @@ -138,7 +230,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with CapitalizedWords " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << '"' << test << '"' << kwsys_ios::endl; res = false; } @@ -148,7 +240,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with UnCapitalizedWords " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << '"' << test << '"' << kwsys_ios::endl; res = false; } @@ -158,7 +250,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with AddSpaceBetweenCapitalizedWords " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << '"' << test << '"' << kwsys_ios::endl; res = false; } @@ -168,7 +260,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with AppendStrings " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A\" \" Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres; @@ -179,7 +271,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with AppendStrings " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had\" \" A \" \"Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres; @@ -188,7 +280,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with CountChar " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } @@ -198,7 +290,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with RemoveChars " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres; @@ -209,7 +301,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with RemoveCharsButUpperHex " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres; @@ -221,7 +313,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with ReplaceChars " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres2; @@ -231,7 +323,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with StringStartsWith " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } @@ -240,7 +332,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with StringEndsWith " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } @@ -249,7 +341,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with DuplicateString " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } delete [] cres; @@ -260,7 +352,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with CropString " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; res = false; } @@ -271,16 +363,124 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with Split " - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; - res = false; + << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl; + res = false; + } + +#ifdef _WIN32 + if (kwsys::SystemTools::ConvertToWindowsExtendedPath + ("L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") != + L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath + ("L:/Local Mojo/Hex Power Pack/Iffy Voodoo") != + L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath + ("\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") != + L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath + ("//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") != + L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\"" + << kwsys_ios::endl; + res = false; } + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") != + L"//") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"//\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") != + L"\\\\.\\") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"\\\\.\\\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") != + L"\\\\.\\X") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"\\\\.\\X\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") != + L"\\\\?\\X:") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"\\\\.\\X:\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") != + L"\\\\?\\X:\\") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"\\\\.\\X:\\\"" + << kwsys_ios::endl; + res = false; + } + + if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") != + L"\\\\.\\NUL") + { + kwsys_ios::cerr + << "Problem with ConvertToWindowsExtendedPath " + << "\"NUL\"" + << kwsys_ios::endl; + res = false; + } + +#endif + if (kwsys::SystemTools::ConvertToWindowsOutputPath ("L://Local Mojo/Hex Power Pack/Iffy Voodoo") != "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") { kwsys_ios::cerr << "Problem with ConvertToWindowsOutputPath " + << "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\"" << kwsys_ios::endl; res = false; } @@ -291,6 +491,7 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with ConvertToWindowsOutputPath " + << "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\"" << kwsys_ios::endl; res = false; } @@ -301,29 +502,11 @@ static bool CheckStringOperations() { kwsys_ios::cerr << "Problem with ConvertToUnixOutputPath " + << "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\"" << kwsys_ios::endl; res = false; } - int targc; - char **targv; - kwsys::SystemTools::ConvertWindowsCommandLineToUnixArguments - ("\"Local Mojo\\Voodoo.asp\" -CastHex \"D:\\My Secret Mojo\\Voodoo.mp3\"", &targc, &targv); - if (targc != 4 || strcmp(targv[1],"Local Mojo\\Voodoo.asp") || - strcmp(targv[2],"-CastHex") || - strcmp(targv[3],"D:\\My Secret Mojo\\Voodoo.mp3")) - { - kwsys_ios::cerr - << "Problem with ConvertWindowsCommandLineToUnixArguments" - << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl; - res = false; - } - for (;targc >=0; --targc) - { - delete [] targv[targc]; - } - delete [] targv; - return res; } @@ -379,6 +562,55 @@ static bool CheckEnvironmentOperations() return res; } + +static bool CheckRelativePath( + const kwsys_stl::string& local, + const kwsys_stl::string& remote, + const kwsys_stl::string& expected) +{ + kwsys_stl::string result = kwsys::SystemTools::RelativePath(local, remote); + if(expected != result) + { + kwsys_ios::cerr << "RelativePath(" << local << ", " << remote + << ") yielded " << result << " instead of " << expected << kwsys_ios::endl; + return false; + } + return true; +} + +static bool CheckRelativePaths() +{ + bool res = true; + res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash"); + res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash"); + res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash"); + res &= CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash"); + res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin"); + return res; +} + +static bool CheckCollapsePath( + const kwsys_stl::string& path, + const kwsys_stl::string& expected) +{ + kwsys_stl::string result = kwsys::SystemTools::CollapseFullPath(path); + if(expected != result) + { + kwsys_ios::cerr << "CollapseFullPath(" << path + << ") yielded " << result << " instead of " << expected << kwsys_ios::endl; + return false; + } + return true; +} + +static bool CheckCollapsePath() +{ + bool res = true; + res &= CheckCollapsePath("/usr/share/*", "/usr/share/*"); + res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*"); + return res; +} + //---------------------------------------------------------------------------- int testSystemTools(int, char*[]) { @@ -410,5 +642,9 @@ int testSystemTools(int, char*[]) res &= CheckEnvironmentOperations(); + res &= CheckRelativePaths(); + + res &= CheckCollapsePath(); + return res ? 0 : 1; } diff --git a/src/kwsys/testSystemTools.h.in b/src/kwsys/testSystemTools.h.in index 4b94bb6..66f0f72 100644 --- a/src/kwsys/testSystemTools.h.in +++ b/src/kwsys/testSystemTools.h.in @@ -14,7 +14,8 @@ #define EXECUTABLE_OUTPUT_PATH "@CMAKE_CURRENT_BINARY_DIR@" -#define TEST_SYSTEMTOOLS_BIN_FILE "@TEST_SYSTEMTOOLS_BIN_FILE@" -#define TEST_SYSTEMTOOLS_SRC_FILE "@TEST_SYSTEMTOOLS_SRC_FILE@" +#define TEST_SYSTEMTOOLS_SOURCE_DIR "@TEST_SYSTEMTOOLS_SOURCE_DIR@" +#define TEST_SYSTEMTOOLS_BINARY_DIR "@TEST_SYSTEMTOOLS_BINARY_DIR@" +#cmakedefine KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS #endif |