Commit 158c6d1c authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2014-08-04 (e787837a)

Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ e787837a | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' 65b36ede..e787837a
Ben Boeckel (4):
      9927862c SystemTools: more string replacements
      b3d598b0 strings: remove unnecessary c_str calls
      ffe94132 SystemTools: use char instead of const char*
      f29fec7c Directory: accept strings in methods

Rashad M (1):
      e787837a SharedForward: Cast away const to call execvp on MinGW 64-bit

Change-Id: I96437b332971670cfcd953717c5563e9ba0f2b99
parent d4d1b7f7
...@@ -103,7 +103,7 @@ void Directory::Clear() ...@@ -103,7 +103,7 @@ void Directory::Clear()
namespace KWSYS_NAMESPACE namespace KWSYS_NAMESPACE
{ {
bool Directory::Load(const char* name) bool Directory::Load(const kwsys_stl::string& name)
{ {
this->Clear(); this->Clear();
#if _MSC_VER < 1300 #if _MSC_VER < 1300
...@@ -112,24 +112,24 @@ bool Directory::Load(const char* name) ...@@ -112,24 +112,24 @@ bool Directory::Load(const char* name)
intptr_t srchHandle; intptr_t srchHandle;
#endif #endif
char* buf; char* buf;
size_t n = strlen(name); size_t n = name.size();
if ( name[n - 1] == '/' || name[n - 1] == '\\' ) if ( *name.rbegin() == '/' || *name.rbegin() == '\\' )
{ {
buf = new char[n + 1 + 1]; buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name); sprintf(buf, "%s*", name.c_str());
} }
else else
{ {
// Make sure the slashes in the wildcard suffix are consistent with the // Make sure the slashes in the wildcard suffix are consistent with the
// rest of the path // rest of the path
buf = new char[n + 2 + 1]; buf = new char[n + 2 + 1];
if ( strchr(name, '\\') ) if ( name.find('\\') != name.npos )
{ {
sprintf(buf, "%s\\*", name); sprintf(buf, "%s\\*", name.c_str());
} }
else else
{ {
sprintf(buf, "%s/*", name); sprintf(buf, "%s/*", name.c_str());
} }
} }
struct _wfinddata_t data; // data of current file struct _wfinddata_t data; // data of current file
...@@ -153,7 +153,7 @@ bool Directory::Load(const char* name) ...@@ -153,7 +153,7 @@ bool Directory::Load(const char* name)
return _findclose(srchHandle) != -1; return _findclose(srchHandle) != -1;
} }
unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
{ {
#if _MSC_VER < 1300 #if _MSC_VER < 1300
long srchHandle; long srchHandle;
...@@ -161,16 +161,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) ...@@ -161,16 +161,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
intptr_t srchHandle; intptr_t srchHandle;
#endif #endif
char* buf; char* buf;
size_t n = strlen(name); size_t n = name.size();
if ( name[n - 1] == '/' ) if ( *name.rbegin() == '/' )
{ {
buf = new char[n + 1 + 1]; buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name); sprintf(buf, "%s*", name.c_str());
} }
else else
{ {
buf = new char[n + 2 + 1]; buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name); sprintf(buf, "%s/*", name.c_str());
} }
struct _wfinddata_t data; // data of current file struct _wfinddata_t data; // data of current file
...@@ -215,15 +215,11 @@ p=1992&sid=f16167f51964f1a68fe5041b8eb213b6 ...@@ -215,15 +215,11 @@ p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
namespace KWSYS_NAMESPACE namespace KWSYS_NAMESPACE
{ {
bool Directory::Load(const char* name) bool Directory::Load(const kwsys_stl::string& name)
{ {
this->Clear(); this->Clear();
if (!name) DIR* dir = opendir(name.c_str());
{
return 0;
}
DIR* dir = opendir(name);
if (!dir) if (!dir)
{ {
...@@ -239,14 +235,9 @@ bool Directory::Load(const char* name) ...@@ -239,14 +235,9 @@ bool Directory::Load(const char* name)
return 1; return 1;
} }
unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
{ {
DIR* dir = opendir(name); DIR* dir = opendir(name.c_str());
if (!dir)
{
return 0;
}
unsigned long count = 0; unsigned long count = 0;
for (dirent* d = readdir(dir); d; d = readdir(dir) ) for (dirent* d = readdir(dir); d; d = readdir(dir) )
......
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
#define @KWSYS_NAMESPACE@_Directory_hxx #define @KWSYS_NAMESPACE@_Directory_hxx
#include <@KWSYS_NAMESPACE@/Configure.h> #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@ namespace @KWSYS_NAMESPACE@
{ {
...@@ -38,7 +45,7 @@ public: ...@@ -38,7 +45,7 @@ public:
* in that directory. 0 is returned if the directory can not be * in that directory. 0 is returned if the directory can not be
* opened, 1 if it is opened. * 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. * Return the number of files in the current directory.
...@@ -49,7 +56,7 @@ public: ...@@ -49,7 +56,7 @@ public:
* Return the number of files in the specified directory. * Return the number of files in the specified directory.
* A higher performance static method. * 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 * Return the file at the given index, the indexing is 0 based
...@@ -77,4 +84,10 @@ private: ...@@ -77,4 +84,10 @@ private:
} // namespace @KWSYS_NAMESPACE@ } // namespace @KWSYS_NAMESPACE@
/* Undefine temporary macros. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
# undef kwsys_ios
#endif
#endif #endif
...@@ -218,7 +218,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, ...@@ -218,7 +218,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir) const kwsys_stl::string& dir)
{ {
kwsys::Directory d; kwsys::Directory d;
if ( !d.Load(dir.c_str()) ) if ( !d.Load(dir) )
{ {
return; return;
} }
...@@ -257,8 +257,8 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, ...@@ -257,8 +257,8 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
fullname = dir + "/" + fname; fullname = dir + "/" + fname;
} }
bool isDir = kwsys::SystemTools::FileIsDirectory(realname.c_str()); bool isDir = kwsys::SystemTools::FileIsDirectory(realname);
bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str()); bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname);
if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) ) if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) )
{ {
...@@ -297,7 +297,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, ...@@ -297,7 +297,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
} }
kwsys::Directory d; kwsys::Directory d;
if ( !d.Load(dir.c_str()) ) if ( !d.Load(dir) )
{ {
return; return;
} }
...@@ -342,12 +342,12 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, ...@@ -342,12 +342,12 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
//kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl; //kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl;
if ( !last && if ( !last &&
!kwsys::SystemTools::FileIsDirectory(realname.c_str()) ) !kwsys::SystemTools::FileIsDirectory(realname) )
{ {
continue; continue;
} }
if ( this->Internals->Expressions[start].find(fname.c_str()) ) if ( this->Internals->Expressions[start].find(fname) )
{ {
if ( last ) if ( last )
{ {
...@@ -371,7 +371,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) ...@@ -371,7 +371,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
this->Internals->Expressions.clear(); this->Internals->Expressions.clear();
this->Internals->Files.clear(); this->Internals->Files.clear();
if ( !kwsys::SystemTools::FileIsFullPath(expr.c_str()) ) if ( !kwsys::SystemTools::FileIsFullPath(expr) )
{ {
expr = kwsys::SystemTools::GetCurrentWorkingDirectory(); expr = kwsys::SystemTools::GetCurrentWorkingDirectory();
expr += "/" + inexpr; expr += "/" + inexpr;
......
...@@ -512,7 +512,7 @@ static void kwsys_shared_forward_execvp(const char* cmd, ...@@ -512,7 +512,7 @@ static void kwsys_shared_forward_execvp(const char* cmd,
/* Invoke the child process. */ /* Invoke the child process. */
#if defined(_MSC_VER) #if defined(_MSC_VER)
_execvp(cmd, argv); _execvp(cmd, argv);
#elif defined(__MINGW32__) #elif defined(__MINGW32__) && !defined(__MINGW64__)
execvp(cmd, argv); execvp(cmd, argv);
#else #else
execvp(cmd, (char* const*)argv); execvp(cmd, (char* const*)argv);
......
This diff is collapsed.
...@@ -158,7 +158,9 @@ public: ...@@ -158,7 +158,9 @@ public:
* Returns true if str1 starts (respectively ends) with str2 * Returns true if str1 starts (respectively ends) with str2
*/ */
static bool StringStartsWith(const char* str1, const char* 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 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 * Returns a pointer to the last occurence of str2 in str1
...@@ -183,7 +185,7 @@ public: ...@@ -183,7 +185,7 @@ public:
s starts with a / then the first element of the returned array will s starts with a / then the first element of the returned array will
be /, so /foo/bar will be [/, foo, bar] 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); bool isPath = false);
/** /**
* Perform a case-independent string comparison * Perform a case-independent string comparison
...@@ -201,8 +203,8 @@ public: ...@@ -201,8 +203,8 @@ public:
* Split a string on its newlines into multiple lines * Split a string on its newlines into multiple lines
* Return false only if the last line stored had no newline * 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 kwsys_stl::string& 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, char separator);
/** /**
* Return string with space added between capitalized words * Return string with space added between capitalized words
...@@ -265,13 +267,13 @@ public: ...@@ -265,13 +267,13 @@ public:
* For windows this calls ConvertToWindowsOutputPath and for unix * For windows this calls ConvertToWindowsOutputPath and for unix
* it calls ConvertToUnixOutputPath * 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. * Convert the path to a string that can be used in a unix makefile.
* double slashes are removed, and spaces are escaped. * 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 * Convert the path to string that can be used in a windows project or
...@@ -279,7 +281,7 @@ public: ...@@ -279,7 +281,7 @@ public:
* the string, the slashes are converted to windows style backslashes, and * the string, the slashes are converted to windows style backslashes, and
* if there are spaces in the string it is double quoted. * 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. * Return true if a file exists in the current directory.
...@@ -288,7 +290,9 @@ public: ...@@ -288,7 +290,9 @@ public:
* if it is a file or a directory. * if it is a file or a directory.
*/ */
static bool FileExists(const char* filename, bool isFile); 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 char* filename);
static bool FileExists(const kwsys_stl::string& filename);
/** /**
* Converts Cygwin path to Win32 path. Uses dictionary container for * Converts Cygwin path to Win32 path. Uses dictionary container for
...@@ -307,7 +311,7 @@ public: ...@@ -307,7 +311,7 @@ public:
/** /**
Change the modification time or create a file 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. * Compare file modification times.
...@@ -315,7 +319,8 @@ public: ...@@ -315,7 +319,8 @@ public:
* When true is returned, result has -1, 0, +1 for * When true is returned, result has -1, 0, +1 for
* f1 older, same, or newer than f2. * 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); int* result);
/** /**
...@@ -377,7 +382,7 @@ public: ...@@ -377,7 +382,7 @@ public:
* the event of an error (non-existent path, permissions issue, * the event of an error (non-existent path, permissions issue,
* etc.) the original path is returned. * 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 * Split a path name into its root component and the rest of the
...@@ -470,6 +475,7 @@ public: ...@@ -470,6 +475,7 @@ public:
/** /**
* Return whether the path represents a full path (not relative) * Return whether the path represents a full path (not relative)
*/ */
static bool FileIsFullPath(const kwsys_stl::string&);
static bool FileIsFullPath(const char*); static bool FileIsFullPath(const char*);
/** /**
...@@ -493,7 +499,7 @@ public: ...@@ -493,7 +499,7 @@ public:
/** /**
* Get the parent directory of the directory or file * 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 * Check if the given file or directory is in subdirectory of dir
...@@ -508,7 +514,7 @@ public: ...@@ -508,7 +514,7 @@ public:
/** /**
* Open a file considering unicode. * 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 * Make a new directory if it is not there. This function
...@@ -516,35 +522,36 @@ public: ...@@ -516,35 +522,36 @@ public:
* prior to calling this function. * prior to calling this function.
*/ */
static bool MakeDirectory(const char* path); static bool MakeDirectory(const char* path);
static bool MakeDirectory(const kwsys_stl::string& path);
/** /**
* Copy the source file to the destination file only * Copy the source file to the destination file only
* if the two files differ. * if the two files differ.
*/ */
static bool CopyFileIfDifferent(const char* source, static bool CopyFileIfDifferent(const kwsys_stl::string& source,
const char* destination); const kwsys_stl::string& destination);
/** /**
* Compare the contents of two files. Return true if different * 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 * 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. * 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 * 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 * copied. If it is false, the file is copied only if it is new or
* has changed. * 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); bool always = true);
/** /**
...@@ -553,18 +560,18 @@ public: ...@@ -553,18 +560,18 @@ public:
* always copied. If it is false, only files that have changed or * always copied. If it is false, only files that have changed or
* are new are copied. * 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); bool always = true);
/** /**
* Remove a file * Remove a file
*/ */
static bool RemoveFile(const char* source); static bool RemoveFile(const kwsys_stl::string& source);
/** /**
* Remove a directory * Remove a directory
*/ */
static bool RemoveADirectory(const char* source); static bool RemoveADirectory(const kwsys_stl::string& source);
/** /**
* Get the maximum full file path length * Get the maximum full file path length
...@@ -594,12 +601,17 @@ public: ...@@ -594,12 +601,17 @@ public:
*/ */
static kwsys_stl::string FindProgram( static kwsys_stl::string FindProgram(
const char* name, 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>(), kwsys_stl::vector<kwsys_stl::string>(),
bool no_system_path = false); bool no_system_path = false);
static kwsys_stl::string FindProgram( static kwsys_stl::string FindProgram(
const kwsys_stl::vector<kwsys_stl::string>& names, 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>(), kwsys_stl::vector<kwsys_stl::string>(),
bool no_system_path = false); bool no_system_path = false);
...@@ -607,18 +619,18 @@ public: ...@@ -607,18 +619,18 @@ public:
* Find a library in the system PATH, with optional extra paths * Find a library in the system PATH, with optional extra paths
*/ */
static kwsys_stl::string FindLibrary( static kwsys_stl::string FindLibrary(
const char* name, const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& path); const kwsys_stl::vector<kwsys_stl::string>& path);
/** /**
* Return true if the file is a directory * 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 * 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) * Return true if the file has a given signature (first set of bytes)
...@@ -686,17 +698,17 @@ public: ...@@ -686,17 +698,17 @@ public:
/a/b/c/d to /a/b/c1/d1 -> ../../c1/d1 /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 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 * Return file's modified time
*/ */
static long int ModifiedTime(const char* filename); static long int ModifiedTime(const kwsys_stl::string& filename);