diff options
author | Brad King <brad.king@kitware.com> | 2016-11-09 14:23:18 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-11-09 14:23:18 (GMT) |
commit | 95a97a40e48a0db2b206c4560d6962be3666812c (patch) | |
tree | e7f6f0e6ffca54ee18f8c276735e8a60e45f8833 /Source/kwsys/SystemTools.hxx.in | |
parent | 666bb0e3fa0d212c03f785bd9f6bc05d29925e1f (diff) | |
parent | 773b36e5d4af3ac040625e0ea16bcfd30fcdeb6d (diff) | |
download | CMake-95a97a40e48a0db2b206c4560d6962be3666812c.zip CMake-95a97a40e48a0db2b206c4560d6962be3666812c.tar.gz CMake-95a97a40e48a0db2b206c4560d6962be3666812c.tar.bz2 |
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys:
KWSys 2016-11-09 (18c65411)
Diffstat (limited to 'Source/kwsys/SystemTools.hxx.in')
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 294 |
1 files changed, 133 insertions, 161 deletions
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 5849145..f3d06fe 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -1,29 +1,20 @@ -/*============================================================================ - 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. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ #ifndef @KWSYS_NAMESPACE@_SystemTools_hxx #define @KWSYS_NAMESPACE@_SystemTools_hxx #include <@KWSYS_NAMESPACE@/Configure.hxx> #include <iosfwd> +#include <map> #include <string> #include <vector> -#include <map> #include <@KWSYS_NAMESPACE@/String.hxx> #include <sys/types.h> #if !defined(_WIN32) || defined(__CYGWIN__) -# include <unistd.h> // For access permissions for use with access() +#include <unistd.h> // For access permissions for use with access() #endif // Required for va_list @@ -36,20 +27,18 @@ // after stdarg.h does not solve things because we do not have control over // what the user does. This hack solves this problem by moving va_list to our // own namespace that is local for kwsys. -namespace std {} // Required for platforms that do not have std namespace -namespace @KWSYS_NAMESPACE@_VA_LIST -{ - using namespace std; - typedef va_list hack_va_list; +namespace std { +} // Required for platforms that do not have std namespace +namespace @KWSYS_NAMESPACE@_VA_LIST { +using namespace std; +typedef va_list hack_va_list; } -namespace @KWSYS_NAMESPACE@ -{ - typedef @KWSYS_NAMESPACE@_VA_LIST::hack_va_list va_list; +namespace @KWSYS_NAMESPACE@ { +typedef @KWSYS_NAMESPACE@_VA_LIST::hack_va_list va_list; } #endif // va_list -namespace @KWSYS_NAMESPACE@ -{ +namespace @KWSYS_NAMESPACE@ { class SystemToolsTranslationMap; class SystemToolsPathCaseMap; @@ -76,17 +65,17 @@ static SystemToolsManager SystemToolsManagerInstance; // combined using the | operator. typedef int TestFilePermissions; #if defined(_WIN32) && !defined(__CYGWIN__) - // On Windows (VC and Borland), no system header defines these constants... - static const TestFilePermissions TEST_FILE_OK = 0; - static const TestFilePermissions TEST_FILE_READ = 4; - static const TestFilePermissions TEST_FILE_WRITE = 2; - static const TestFilePermissions TEST_FILE_EXECUTE = 1; +// On Windows (VC and Borland), no system header defines these constants... +static const TestFilePermissions TEST_FILE_OK = 0; +static const TestFilePermissions TEST_FILE_READ = 4; +static const TestFilePermissions TEST_FILE_WRITE = 2; +static const TestFilePermissions TEST_FILE_EXECUTE = 1; #else - // Standard POSIX constants - static const TestFilePermissions TEST_FILE_OK = F_OK; - static const TestFilePermissions TEST_FILE_READ = R_OK; - static const TestFilePermissions TEST_FILE_WRITE = W_OK; - static const TestFilePermissions TEST_FILE_EXECUTE = X_OK; +// Standard POSIX constants +static const TestFilePermissions TEST_FILE_OK = F_OK; +static const TestFilePermissions TEST_FILE_READ = R_OK; +static const TestFilePermissions TEST_FILE_WRITE = W_OK; +static const TestFilePermissions TEST_FILE_EXECUTE = X_OK; #endif /** \class SystemTools @@ -95,7 +84,6 @@ typedef int TestFilePermissions; class @KWSYS_NAMESPACE@_EXPORT SystemTools { public: - /** ----------------------------------------------------------------- * String Manipulation Routines * ----------------------------------------------------------------- @@ -118,11 +106,9 @@ public: /** * Replace replace all occurences of the string in the source string. */ - static void ReplaceString(std::string& source, - const char* replace, + static void ReplaceString(std::string& source, const char* replace, const char* with); - static void ReplaceString(std::string& source, - const std::string& replace, + static void ReplaceString(std::string& source, const std::string& replace, const std::string& with); /** @@ -162,7 +148,7 @@ public: * Remove some characters from a string. * Return a pointer to the new resulting string (allocated with 'new') */ - static char* RemoveChars(const char* str, const char *toremove); + static char* RemoveChars(const char* str, const char* toremove); /** * Remove remove all but 0->9, A->F characters from a string. @@ -174,7 +160,8 @@ public: * Replace some characters by another character in a string (in-place) * Return a pointer to string */ - static char* ReplaceChars(char* str, const char *toreplace,char replacement); + static char* ReplaceChars(char* str, const char* toreplace, + char replacement); /** * Returns true if str1 starts (respectively ends) with str2 @@ -200,41 +187,42 @@ public: * Return the string cropped to a given length by removing chars in the * center of the string and replacing them with an ellipsis (...) */ - static std::string CropString(const std::string&,size_t max_len); + static std::string CropString(const std::string&, size_t max_len); /** split a path by separator into an array of strings, default is /. If isPath is true then the string is treated like a path and if s starts with a / then the first element of the returned array will be /, so /foo/bar will be [/, foo, bar] */ - static std::vector<String> SplitString(const std::string& s, char separator = '/', - bool isPath = false); + static std::vector<String> SplitString(const std::string& s, + char separator = '/', + bool isPath = false); /** * Perform a case-independent string comparison */ - static int Strucmp(const char *s1, const char *s2); + static int Strucmp(const char* s1, const char* s2); /** * Convert a string in __DATE__ or __TIMESTAMP__ format into a time_t. * Return false on error, true on success */ - static bool ConvertDateMacroString(const char *str, time_t *tmt); - static bool ConvertTimeStampMacroString(const char *str, time_t *tmt); + static bool ConvertDateMacroString(const char* str, time_t* tmt); + static bool ConvertTimeStampMacroString(const char* str, time_t* tmt); /** * Split a string on its newlines into multiple lines * Return false only if the last line stored had no newline */ static bool Split(const std::string& s, std::vector<std::string>& l); - static bool Split(const std::string& s, std::vector<std::string>& l, char separator); + static bool Split(const std::string& s, std::vector<std::string>& l, + char separator); /** * Return string with space added between capitalized words * (i.e. EatMyShorts becomes Eat My Shorts ) * (note that IEatShorts becomes IEat Shorts) */ - static std::string AddSpaceBetweenCapitalizedWords( - const std::string&); + static std::string AddSpaceBetweenCapitalizedWords(const std::string&); /** * Append two or more strings and produce new one. @@ -242,10 +230,9 @@ public: * with 'new'. * Return 0 if inputs are empty or there was an error */ - static char* AppendStrings( - const char* str1, const char* str2); - static char* AppendStrings( - const char* str1, const char* str2, const char* str3); + static char* AppendStrings(const char* str1, const char* str2); + static char* AppendStrings(const char* str1, const char* str2, + const char* str3); /** * Estimate the length of the string that will be produced @@ -256,13 +243,13 @@ public: * you will not be able to use this 'ap' anymore from the beginning. * It's up to you to call va_end though. */ - static int EstimateFormatLength(const char *format, va_list ap); + static int EstimateFormatLength(const char* format, va_list ap); /** * Escape specific characters in 'str'. */ - static std::string EscapeChars( - const char *str, const char *chars_to_escape, char escape_char = '\\'); + static std::string EscapeChars(const char* str, const char* chars_to_escape, + char escape_char = '\\'); /** ----------------------------------------------------------------- * Filename Manipulation Routines @@ -338,13 +325,13 @@ public: static bool TestFileAccess(const std::string& filename, TestFilePermissions permissions); - /** - * Converts Cygwin path to Win32 path. Uses dictionary container for - * caching and calls to cygwin_conv_to_win32_path from Cygwin dll - * for actual translation. Returns true on success, else false. - */ +/** + * Converts Cygwin path to Win32 path. Uses dictionary container for + * caching and calls to cygwin_conv_to_win32_path from Cygwin dll + * for actual translation. Returns true on success, else false. + */ #ifdef __CYGWIN__ - static bool PathCygwinToWin32(const char *path, char *win32_path); + static bool PathCygwinToWin32(const char* path, char* win32_path); #endif /** @@ -363,8 +350,7 @@ public: * When true is returned, result has -1, 0, +1 for * f1 older, same, or newer than f2. */ - static bool FileTimeCompare(const std::string& f1, - const std::string& f2, + static bool FileTimeCompare(const std::string& f1, const std::string& f2, int* result); /** @@ -388,10 +374,8 @@ public: * part, the empty string is returned. */ static std::string GetProgramPath(const std::string&); - static bool SplitProgramPath(const std::string& in_name, - std::string& dir, - std::string& file, - bool errorReport = true); + static bool SplitProgramPath(const std::string& in_name, std::string& dir, + std::string& file, bool errorReport = true); /** * Given argv[0] for a unix program find the full path to a running @@ -405,10 +389,8 @@ public: * buildDir is a possibly null path to the build directory. * installPrefix is a possibly null pointer to the install directory. */ - static bool FindProgramPath(const char* argv0, - std::string& pathOut, - std::string& errorMsg, - const char* exeName = 0, + static bool FindProgramPath(const char* argv0, std::string& pathOut, + std::string& errorMsg, const char* exeName = 0, const char* buildDir = 0, const char* installPrefix = 0); @@ -420,9 +402,9 @@ public: */ static std::string CollapseFullPath(const std::string& in_relative); static std::string CollapseFullPath(const std::string& in_relative, - const char* in_base); + const char* in_base); static std::string CollapseFullPath(const std::string& in_relative, - const std::string& in_base); + const std::string& in_base); /** * Get the real path for a given path, removing all symlinks. In @@ -432,7 +414,7 @@ public: * contains error description. */ static std::string GetRealPath(const std::string& path, - std::string* errorMessage = 0); + std::string* errorMessage = 0); /** * Split a path name into its root component and the rest of the @@ -450,7 +432,7 @@ public: * given. */ static const char* SplitPathRootComponent(const std::string& p, - std::string* root=0); + std::string* root = 0); /** * Split a path name into its basic components. The first component @@ -470,18 +452,15 @@ public: * Join components of a path name into a single string. See * SplitPath for the format of the components. */ - static std::string JoinPath( - const std::vector<std::string>& components); - static std::string JoinPath( - std::vector<std::string>::const_iterator first, - std::vector<std::string>::const_iterator last); + static std::string JoinPath(const std::vector<std::string>& components); + static std::string JoinPath(std::vector<std::string>::const_iterator first, + std::vector<std::string>::const_iterator last); /** * Compare a path or components of a path. */ static bool ComparePath(const std::string& c1, const std::string& c2); - /** * Return path of a full filename (no trailing slashes) */ @@ -495,9 +474,8 @@ public: /** * Split a program from its arguments and handle spaces in the paths */ - static void SplitProgramFromArgs( - const std::string& path, - std::string& program, std::string& args); + static void SplitProgramFromArgs(const std::string& path, + std::string& program, std::string& args); /** * Return longest file extension of a full filename (dot included) @@ -507,20 +485,17 @@ public: /** * Return shortest file extension of a full filename (dot included) */ - static std::string GetFilenameLastExtension( - const std::string& filename); + static std::string GetFilenameLastExtension(const std::string& filename); /** * Return file name without extension of a full filename */ - static std::string GetFilenameWithoutExtension( - const std::string&); + static std::string GetFilenameWithoutExtension(const std::string&); /** * Return file name without its last (shortest) extension */ - static std::string GetFilenameWithoutLastExtension( - const std::string&); + static std::string GetFilenameWithoutLastExtension(const std::string&); /** * Return whether the path represents a full path (not relative) @@ -541,10 +516,8 @@ public: * end-of-file was reached. If the has_newline argument is specified, it will * be true when the line read had a newline character. */ - static bool GetLineFromStream(std::istream& istr, - std::string& line, - bool* has_newline=0, - long sizeLimit=-1); + static bool GetLineFromStream(std::istream& istr, std::string& line, + bool* has_newline = 0, long sizeLimit = -1); /** * Get the parent directory of the directory or file @@ -554,7 +527,8 @@ public: /** * Check if the given file or directory is in subdirectory of dir */ - static bool IsSubDirectory(const std::string& fileOrDir, const std::string& dir); + static bool IsSubDirectory(const std::string& fileOrDir, + const std::string& dir); /** ----------------------------------------------------------------- * File Manipulation Routines @@ -584,7 +558,8 @@ public: /** * Compare the contents of two files. Return true if different */ - static bool FilesDiffer(const std::string& source, const std::string& destination); + static bool FilesDiffer(const std::string& source, + const std::string& destination); /** * Return true if the two files are the same file @@ -594,15 +569,16 @@ public: /** * Copy a file. */ - static bool CopyFileAlways(const std::string& source, const std::string& destination); + static bool CopyFileAlways(const std::string& source, + const std::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 std::string& source, const std::string& destination, - bool always = true); + static bool CopyAFile(const std::string& source, + const std::string& destination, bool always = true); /** * Copy content directory to another directory with all files and @@ -610,7 +586,8 @@ public: * always copied. If it is false, only files that have changed or * are new are copied. */ - static bool CopyADirectory(const std::string& source, const std::string& destination, + static bool CopyADirectory(const std::string& source, + const std::string& destination, bool always = true); /** @@ -633,8 +610,7 @@ public: */ static std::string FindFile( const std::string& name, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); /** @@ -642,8 +618,7 @@ public: */ static std::string FindDirectory( const std::string& name, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); /** @@ -651,26 +626,22 @@ public: */ static std::string FindProgram( const char* name, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); static std::string FindProgram( const std::string& name, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); static std::string FindProgram( const std::vector<std::string>& names, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); /** * Find a library in the system PATH, with optional extra paths */ - static std::string FindLibrary( - const std::string& name, - const std::vector<std::string>& path); + static std::string FindLibrary(const std::string& name, + const std::vector<std::string>& path); /** * Return true if the file is a directory @@ -685,8 +656,8 @@ public: /** * Return true if the file has a given signature (first set of bytes) */ - static bool FileHasSignature( - const char* filename, const char *signature, long offset = 0); + static bool FileHasSignature(const char* filename, const char* signature, + long offset = 0); /** * Attempt to detect and return the type of a file. @@ -703,16 +674,16 @@ public: FileTypeBinary, FileTypeText }; - static SystemTools::FileTypeEnum DetectFileType( - const char* filename, - unsigned long length = 256, - double percent_bin = 0.05); + static SystemTools::FileTypeEnum DetectFileType(const char* filename, + unsigned long length = 256, + double percent_bin = 0.05); /** * Create a symbolic link if the platform supports it. Returns whether * creation succeeded. */ - static bool CreateSymlink(const std::string& origName, const std::string& newName); + static bool CreateSymlink(const std::string& origName, + const std::string& newName); /** * Read the contents of a symbolic link. Returns whether reading @@ -735,8 +706,7 @@ public: * etc. * Return true if the file was found, false otherwise. */ - static bool LocateFileInDir(const char *filename, - const char *dir, + static bool LocateFileInDir(const char* filename, const char* dir, std::string& filename_found, int try_filename_dirs = 0); @@ -748,7 +718,8 @@ 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 std::string RelativePath(const std::string& local, const std::string& remote); + static std::string RelativePath(const std::string& local, + const std::string& remote); /** * Return file's modified time @@ -760,12 +731,12 @@ public: */ static long int CreationTime(const std::string& filename); - /** - * Visual C++ does not define mode_t (note that Borland does, however). - */ - #if defined( _MSC_VER ) +/** + * Visual C++ does not define mode_t (note that Borland does, however). + */ +#if defined(_MSC_VER) typedef unsigned short mode_t; - #endif +#endif /** * Get and set permissions of the file. If honor_umask is set, the umask @@ -777,8 +748,10 @@ public: */ static bool GetPermissions(const char* file, mode_t& mode); static bool GetPermissions(const std::string& file, mode_t& mode); - static bool SetPermissions(const char* file, mode_t mode, bool honor_umask = false); - static bool SetPermissions(const std::string& file, mode_t mode, bool honor_umask = false); + static bool SetPermissions(const char* file, mode_t mode, + bool honor_umask = false); + static bool SetPermissions(const std::string& file, mode_t mode, + bool honor_umask = false); /** ----------------------------------------------------------------- * Time Manipulation Routines @@ -803,7 +776,12 @@ public: * registry values. The default is to match the currently running * binary type. */ - enum KeyWOW64 { KeyWOW64_Default, KeyWOW64_32, KeyWOW64_64 }; + enum KeyWOW64 + { + KeyWOW64_Default, + KeyWOW64_32, + KeyWOW64_64 + }; /** * Get a list of subkeys. @@ -815,13 +793,14 @@ public: /** * Read a registry value */ - static bool ReadRegistryValue(const std::string& key, std::string &value, + static bool ReadRegistryValue(const std::string& key, std::string& value, KeyWOW64 view = KeyWOW64_Default); /** * Write a registry value */ - static bool WriteRegistryValue(const std::string& key, const std::string& value, + static bool WriteRegistryValue(const std::string& key, + const std::string& value, KeyWOW64 view = KeyWOW64_Default); /** @@ -840,8 +819,7 @@ public: * string vector passed in. If env is set then the value * of env will be used instead of PATH. */ - static void GetPath(std::vector<std::string>& path, - const char* env=0); + static void GetPath(std::vector<std::string>& path, const char* env = 0); /** * Read an environment variable @@ -864,7 +842,7 @@ public: /** * Get current working directory CWD */ - static std::string GetCurrentWorkingDirectory(bool collapse =true); + static std::string GetCurrentWorkingDirectory(bool collapse = true); /** * Change directory to the directory specified @@ -893,7 +871,8 @@ public: /** * Add an entry in the path translation table. */ - static void AddTranslationPath(const std::string& dir, const std::string& refdir); + static void AddTranslationPath(const std::string& dir, + const std::string& refdir); /** * If dir is different after CollapseFullPath is called, @@ -904,7 +883,7 @@ public: /** * Update path by going through the Path Translation table; */ - static void CheckTranslationPath(std::string & path); + static void CheckTranslationPath(std::string& path); /** * Delay the execution for a specified amount of time specified @@ -929,9 +908,8 @@ public: * and fill protocol as appropriate. * Return false if the URL does not have the required form, true otherwise. */ - static bool ParseURLProtocol( const std::string& URL, - std::string& protocol, - std::string& dataglom ); + static bool ParseURLProtocol(const std::string& URL, std::string& protocol, + std::string& dataglom); /** * Parse a string (a URL without protocol prefix) with the form: @@ -940,13 +918,10 @@ public: * when values are found. * Return true if the string matches the format; false otherwise. */ - static bool ParseURL( const std::string& URL, - std::string& protocol, - std::string& username, - std::string& password, - std::string& hostname, - std::string& dataport, - std::string& datapath ); + static bool ParseURL(const std::string& URL, std::string& protocol, + std::string& username, std::string& password, + std::string& hostname, std::string& dataport, + std::string& datapath); private: /** @@ -963,17 +938,15 @@ private: * This method prevents warning on SGI */ SystemToolsManager* GetSystemToolsManager() - { + { return &SystemToolsManagerInstance; - } + } /** * Actual implementation of ReplaceString. */ - static void ReplaceString(std::string& source, - const char* replace, - size_t replaceSize, - const std::string& with); + static void ReplaceString(std::string& source, const char* replace, + size_t replaceSize, const std::string& with); /** * Actual implementation of FileIsFullPath. @@ -986,8 +959,7 @@ private: */ static std::string FindName( const std::string& name, - const std::vector<std::string>& path = - std::vector<std::string>(), + const std::vector<std::string>& path = std::vector<std::string>(), bool no_system_path = false); static const char* GetEnvImpl(const char* key); @@ -996,13 +968,13 @@ private: * Path translation table from dir to refdir * Each time 'dir' will be found it will be replace by 'refdir' */ - static SystemToolsTranslationMap *TranslationMap; + static SystemToolsTranslationMap* TranslationMap; #ifdef _WIN32 - static SystemToolsPathCaseMap *PathCaseMap; - static SystemToolsEnvMap *EnvMap; + static SystemToolsPathCaseMap* PathCaseMap; + static SystemToolsEnvMap* EnvMap; #endif #ifdef __CYGWIN__ - static SystemToolsTranslationMap *Cyg2Win32Map; + static SystemToolsTranslationMap* Cyg2Win32Map; #endif friend class SystemToolsManager; }; |