Selaa lähdekoodia

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
KWSys Robot 11 vuotta sitten
vanhempi
sitoutus
158c6d1cff
7 muutettua tiedostoa jossa 290 lisäystä ja 208 poistoa
  1. 16 25
      Directory.cxx
  2. 15 2
      Directory.hxx.in
  3. 7 7
      Glob.cxx
  4. 1 1
      SharedForward.h.in
  5. 197 138
      SystemTools.cxx
  6. 48 29
      SystemTools.hxx.in
  7. 6 6
      testSystemTools.cxx

+ 16 - 25
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,24 +112,24 @@ bool Directory::Load(const char* name)
   intptr_t srchHandle;
 #endif
   char* buf;
-  size_t n = strlen(name);
-  if ( name[n - 1] == '/' || 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];
-    if ( strchr(name, '\\') )
+    if ( name.find('\\') != name.npos )
       {
-      sprintf(buf, "%s\\*", name);
+      sprintf(buf, "%s\\*", name.c_str());
       }
     else
       {
-      sprintf(buf, "%s/*", name);
+      sprintf(buf, "%s/*", name.c_str());
       }
     }
   struct _wfinddata_t data;      // data of current file
@@ -153,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;
@@ -161,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
 
@@ -215,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)
     {
@@ -239,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) )

+ 15 - 2
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

+ 7 - 7
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;
     }
@@ -257,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) )
       {
@@ -297,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;
     }
@@ -342,12 +342,12 @@ 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 )
         {
@@ -371,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;

+ 1 - 1
SharedForward.h.in

@@ -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);

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 197 - 138
SystemTools.cxx


+ 48 - 29
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
@@ -265,13 +267,13 @@ public:
    * 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
@@ -279,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.
@@ -288,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
@@ -307,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.
@@ -315,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);
 
   /**
@@ -377,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
@@ -470,6 +475,7 @@ public:
   /**
    * Return whether the path represents a full path (not relative)
    */
+  static bool FileIsFullPath(const kwsys_stl::string&);
   static bool FileIsFullPath(const char*);
   
   /**
@@ -493,7 +499,7 @@ 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
@@ -508,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
@@ -516,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);
 
   /**
@@ -553,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
@@ -594,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);
 
@@ -607,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)
@@ -686,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;
@@ -706,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
@@ -793,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)
@@ -900,6 +914,11 @@ private:
     return &SystemToolsManagerInstance;
     }
 
+  /**
+   * 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.

+ 6 - 6
testSystemTools.cxx

@@ -132,7 +132,7 @@ static bool CheckFileOperations()
     res = false;
     }
 
-  if (!kwsys::SystemTools::MakeDirectory(testNewDir.c_str()))
+  if (!kwsys::SystemTools::MakeDirectory(testNewDir))
     {
     kwsys_ios::cerr
       << "Problem with MakeDirectory for: "
@@ -148,7 +148,7 @@ static bool CheckFileOperations()
     res = false;
     }
 
-  if (!kwsys::SystemTools::RemoveFile(testNewFile.c_str()))
+  if (!kwsys::SystemTools::RemoveFile(testNewFile))
     {
     kwsys_ios::cerr
       << "Problem with RemoveFile: "
@@ -157,7 +157,7 @@ static bool CheckFileOperations()
     }
 
   kwsys::SystemTools::Touch(testNewFile.c_str(), true);
-  if (!kwsys::SystemTools::RemoveADirectory(testNewDir.c_str()))
+  if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
     {
     kwsys_ios::cerr
       << "Problem with RemoveADirectory for: "
@@ -183,7 +183,7 @@ static bool CheckFileOperations()
     "012345678901234567890123456789012345678901234567890123456789"
     "0123456789.txt");
 
-  if (!kwsys::SystemTools::MakeDirectory(testNewLongDir.c_str()))
+  if (!kwsys::SystemTools::MakeDirectory(testNewLongDir))
     {
     kwsys_ios::cerr
       << "Problem with MakeDirectory for: "
@@ -199,7 +199,7 @@ static bool CheckFileOperations()
     res = false;
     }
 
-  if (!kwsys::SystemTools::RemoveFile(testNewLongFile.c_str()))
+  if (!kwsys::SystemTools::RemoveFile(testNewLongFile))
     {
     kwsys_ios::cerr
       << "Problem with RemoveFile: "
@@ -208,7 +208,7 @@ static bool CheckFileOperations()
     }
 
   kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
-  if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir.c_str()))
+  if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir))
     {
     kwsys_ios::cerr
       << "Problem with RemoveADirectory for: "

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä