From 15d7dd9937f63e33dc98c75169d34953a222a20c Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Tue, 21 Mar 2006 12:54:31 -0500 Subject: ENH: Remove cmGlob and use glob from kwsys --- Source/CMakeLists.txt | 1 - Source/CTest/cmCTestCoverageHandler.cxx | 5 +- Source/cmCTest.cxx | 4 +- Source/cmCacheManager.cxx | 5 +- Source/cmFileCommand.cxx | 26 +-- Source/cmFindPathCommand.cxx | 3 +- Source/cmGlob.cxx | 401 -------------------------------- Source/cmGlob.h | 73 ------ bootstrap | 1 - 9 files changed, 23 insertions(+), 496 deletions(-) delete mode 100644 Source/cmGlob.cxx delete mode 100644 Source/cmGlob.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f176751..8a309c9 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -110,7 +110,6 @@ SET(SRCS cmExprParser.cxx cmExprParserHelper.cxx cmGeneratedFileStream.cxx - cmGlob.cxx cmGlobalGenerator.cxx cmGlobalGenerator.h cmGlobalUnixMakefileGenerator3.cxx diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index f6280a3..11424b9 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -21,9 +21,10 @@ #include "cmake.h" #include "cmSystemTools.h" #include "cmGeneratedFileStream.h" -#include "cmGlob.h" + #include #include +#include #include #include @@ -237,7 +238,7 @@ int cmCTestCoverageHandler::ProcessHandler() cmSystemTools::MakeDirectory(tempDir.c_str()); cmSystemTools::ChangeDirectory(tempDir.c_str()); - cmGlob gl; + cmsys::Glob gl; gl.RecurseOn(); std::string daGlob = binaryDir + "/*.da"; gl.FindFiles(daGlob); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 3822947..ee40dff 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -22,7 +22,6 @@ #include "cmLocalGenerator.h" #include "cmGlobalGenerator.h" #include -#include "cmGlob.h" #include "cmDynamicLoader.h" #include "cmGeneratedFileStream.h" #include "cmCTestCommand.h" @@ -41,6 +40,7 @@ #include #include +#include #include #include @@ -1876,7 +1876,7 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir) std::string rexpr = dir; rexpr += "/CTestCustom.ctest"; - cmGlob gl; + cmsys::Glob gl; gl.RecurseOn(); gl.FindFiles(rexpr); std::vector& files = gl.GetFiles(); diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 7d3c151..fb6385e 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -19,8 +19,9 @@ #include "cmSystemTools.h" #include "cmCacheManager.h" #include "cmMakefile.h" -#include "cmGlob.h" + #include +#include #include @@ -163,7 +164,7 @@ void cmCacheManager::CleanCMakeFiles(const char* path) { std::string glob = path; glob += "/CMakeFiles/*.cmake"; - cmGlob globIt; + cmsys::Glob globIt; globIt.FindFiles(glob); std::vector files = globIt.GetFiles(); for(std::vector::iterator i = files.begin(); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fb75d05..a93e517 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -9,18 +9,17 @@ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "cmFileCommand.h" -#include "cmGlob.h" - #include #include #include +#include // cmLibraryCommand bool cmFileCommand::InitialPass(std::vector const& args) @@ -82,7 +81,7 @@ bool cmFileCommand::InitialPass(std::vector const& args) } //---------------------------------------------------------------------------- -bool cmFileCommand::HandleWriteCommand(std::vector const& args, +bool cmFileCommand::HandleWriteCommand(std::vector const& args, bool append) { std::string message; @@ -205,7 +204,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, std::string variable = *i; i++; - cmGlob g; + cmsys::Glob g; g.SetRecurse(recurse); std::string output = ""; bool first = true; @@ -509,7 +508,7 @@ bool cmFileCommand::HandleInstallCommand( { if ( ch2 == '/' ) { - // looks like a network path. + // looks like a network path. this->SetError("called with network path DESTINATION. This " "does not make sense when using DESTDIR. Specify local " "absolute path or remove DESTDIR environment variable."); @@ -530,11 +529,11 @@ bool cmFileCommand::HandleInstallCommand( { itype = cmTarget::EXECUTABLE; } - else if ( stype == "PROGRAM" ) + else if ( stype == "PROGRAM" ) { itype = cmTarget::INSTALL_PROGRAMS; } - else if ( stype == "STATIC_LIBRARY" ) + else if ( stype == "STATIC_LIBRARY" ) { itype = cmTarget::STATIC_LIBRARY; } @@ -620,7 +619,7 @@ bool cmFileCommand::HandleInstallCommand( } // Get the current manifest. - const char* manifest_files = + const char* manifest_files = this->Makefile->GetDefinition("CMAKE_INSTALL_MANIFEST_FILES"); std::string smanifest_files; if ( manifest_files ) @@ -871,7 +870,7 @@ bool cmFileCommand::HandleRelativePathCommand( //---------------------------------------------------------------------------- -bool cmFileCommand::HandleRemove(std::vector const& args, +bool cmFileCommand::HandleRemove(std::vector const& args, bool recurse) { @@ -893,9 +892,10 @@ bool cmFileCommand::HandleRemove(std::vector const& args, return true; } -bool cmFileCommand::HandleSystemPathCommand(std::vector +//---------------------------------------------------------------------------- +bool cmFileCommand::HandleSystemPathCommand(std::vector const& args) -{ +{ std::vector::const_iterator i = args.begin(); if(args.size() != 3) { diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index c24d127..2845e86 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -17,6 +17,7 @@ #include "cmFindPathCommand.h" #include "cmCacheManager.h" +#include cmFindPathCommand::cmFindPathCommand() { @@ -170,7 +171,7 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string& file, cmStdString glob = dir; glob += "/*/Headers/"; glob += file; - cmGlob globIt; + cmsys::Glob globIt; globIt.FindFiles(glob); std::vector files = globIt.GetFiles(); if(files.size()) diff --git a/Source/cmGlob.cxx b/Source/cmGlob.cxx deleted file mode 100644 index 6a793e2..0000000 --- a/Source/cmGlob.cxx +++ /dev/null @@ -1,401 +0,0 @@ -/*========================================================================= - - Program: CMake - Cross-Platform Makefile Generator - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. - See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "cmGlob.h" - -#include -#include -#include - -#include - -#if defined( _WIN32 ) || defined( APPLE ) || defined( __CYGWIN__ ) - // On Windows and apple, no difference between lower and upper case - #define CM_GLOB_CASE_INDEPENDENT -#endif - -#if defined( _WIN32 ) || defined( __CYGWIN__ ) - // Handle network paths - #define CM_GLOB_SUPPORT_NETWORK_PATHS -#endif - -class cmGlobInternal -{ -public: - std::vector Files; - std::vector Expressions; - std::vector TextExpressions; -}; - -cmGlob::cmGlob() -{ - this->Internals = new cmGlobInternal; - this->Recurse = false; -} - -cmGlob::~cmGlob() -{ - delete this->Internals; -} - -void cmGlob::Escape(int ch, char* buffer) -{ - if (! ( - 'a' <= ch && ch <= 'z' || - 'A' <= ch && ch <= 'Z' || - '0' <= ch && ch <= '9') ) - { - sprintf(buffer, "\\%c", ch); - } - else - { -#if defined( CM_GLOB_CASE_INDEPENDENT ) - // On Windows and apple, no difference between lower and upper case - sprintf(buffer, "%c", tolower(ch)); -#else - sprintf(buffer, "%c", ch); -#endif - } -} - -std::vector& cmGlob::GetFiles() -{ - return this->Internals->Files; -} - -std::string cmGlob::ConvertExpression(const std::string& expr) -{ - - std::string::size_type i = 0; - std::string::size_type n = expr.size(); - - std::string res = "^"; - std::string stuff = ""; - - while ( i < n ) - { - int c = expr[i]; - i = i+1; - if ( c == '*' ) - { - res = res + ".*"; - } - else if ( c == '?' ) - { - res = res + "."; - } - else if ( c == '[' ) - { - std::string::size_type j = i; - if ( j < n && ( expr[j] == '!' || expr[j] == '^' ) ) - { - j = j+1; - } - if ( j < n && expr[j] == ']' ) - { - j = j+1; - } - while ( j < n && expr[j] != ']' ) - { - j = j+1; - } - if ( j >= n ) - { - res = res + "\\["; - } - else - { - stuff = ""; - std::string::size_type cc; - for ( cc = i; cc < j; cc ++ ) - { - if ( expr[cc] == '\\' ) - { - stuff += "\\\\"; - } - else - { - stuff += expr[cc]; - } - } - i = j+1; - if ( stuff[0] == '!' || stuff[0] == '^' ) - { - stuff = '^' + stuff.substr(1); - } - else if ( stuff[0] == '^' ) - { - stuff = '\\' + stuff; - } - res = res + "[" + stuff + "]"; - } - } - else - { - char buffer[100]; - buffer[0] = 0; - this->Escape(c, buffer); - res = res + buffer; - } - } - return res + "$"; -} - -void cmGlob::RecurseDirectory(std::string::size_type start, - const std::string& dir, bool dir_only) -{ - cmsys::Directory d; - if ( !d.Load(dir.c_str()) ) - { - return; - } - unsigned long cc; - std::string fullname; - std::string realname; - std::string fname; - for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) - { - fname = d.GetFile(cc); - if ( strcmp(fname.c_str(), ".") == 0 || - strcmp(fname.c_str(), "..") == 0 ) - { - continue; - } - - if ( start == 0 ) - { - realname = dir + fname; - } - else - { - realname = dir + "/" + fname; - } - -#if defined( CM_GLOB_CASE_INDEPENDENT ) - // On Windows and apple, no difference between lower and upper case - fname = cmsys::SystemTools::LowerCase(fname); -#endif - - if ( start == 0 ) - { - fullname = dir + fname; - } - else - { - fullname = dir + "/" + fname; - } - - if ( !dir_only || !cmsys::SystemTools::FileIsDirectory(realname.c_str()) ) - { - if ( this->Internals->Expressions[this->Internals->Expressions.size()-1].find(fname.c_str()) ) - { - this->Internals->Files.push_back(realname); - } - } - if ( cmsys::SystemTools::FileIsDirectory(realname.c_str()) ) - { - this->RecurseDirectory(start+1, realname, dir_only); - } - } -} - -void cmGlob::ProcessDirectory(std::string::size_type start, - const std::string& dir, bool dir_only) -{ - //std::cout << "ProcessDirectory: " << dir << std::endl; - bool last = ( start == this->Internals->Expressions.size()-1 ); - if ( last && this->Recurse ) - { - this->RecurseDirectory(start, dir, dir_only); - return; - } - cmsys::Directory d; - if ( !d.Load(dir.c_str()) ) - { - return; - } - unsigned long cc; - std::string fullname; - std::string realname; - std::string fname; - for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) - { - fname = d.GetFile(cc); - if ( strcmp(fname.c_str(), ".") == 0 || - strcmp(fname.c_str(), "..") == 0 ) - { - continue; - } - - if ( start == 0 ) - { - realname = dir + fname; - } - else - { - realname = dir + "/" + fname; - } - -#if defined( CM_GLOB_CASE_INDEPENDENT ) - // On Windows and apple, no difference between lower and upper case - fname = cmsys::SystemTools::LowerCase(fname); -#endif - - if ( start == 0 ) - { - fullname = dir + fname; - } - else - { - fullname = dir + "/" + fname; - } - - //std::cout << "Look at file: " << fname << std::endl; - //std::cout << "Match: " << this->Internals->TextExpressions[start].c_str() << std::endl; - //std::cout << "Full name: " << fullname << std::endl; - - if ( (!dir_only || !last) && !cmsys::SystemTools::FileIsDirectory(realname.c_str()) ) - { - continue; - } - - if ( this->Internals->Expressions[start].find(fname.c_str()) ) - { - if ( last ) - { - this->Internals->Files.push_back(realname); - } - else - { - this->ProcessDirectory(start+1, realname + "/", dir_only); - } - } - } -} - -bool cmGlob::FindFiles(const std::string& inexpr) -{ - std::string cexpr; - std::string::size_type cc; - std::string expr = inexpr; - - this->Internals->Expressions.clear(); - this->Internals->Files.clear(); - - if ( !cmsys::SystemTools::FileIsFullPath(expr.c_str()) ) - { - expr = cmsys::SystemTools::GetCurrentWorkingDirectory(); - expr += "/" + inexpr; - } - std::string fexpr = expr; - - int skip = 0; - int last_slash = 0; - for ( cc = 0; cc < expr.size(); cc ++ ) - { - if ( cc > 0 && expr[cc] == '/' && expr[cc-1] != '\\' ) - { - last_slash = cc; - } - if ( cc > 0 && - (expr[cc] == '[' || expr[cc] == '?' || expr[cc] == '*') && - expr[cc-1] != '\\' ) - { - break; - } - } - if ( last_slash > 0 ) - { - //std::cout << "I can skip: " << fexpr.substr(0, last_slash) << std::endl; - skip = last_slash; - } - if ( skip == 0 ) - { -#if defined( CM_GLOB_SUPPORT_NETWORK_PATHS ) - // Handle network paths - if ( expr[0] == '/' && expr[1] == '/' ) - { - int cnt = 0; - for ( cc = 2; cc < expr.size(); cc ++ ) - { - if ( expr[cc] == '/' ) - { - cnt ++; - if ( cnt == 2 ) - { - break; - } - } - } - skip = cc + 1; - } - else -#endif - // Handle drive letters on Windows - if ( expr[1] == ':' && expr[0] != '/' ) - { - skip = 2; - } - } - - if ( skip > 0 ) - { - expr = expr.substr(skip); - } - - cexpr = ""; - for ( cc = 0; cc < expr.size(); cc ++ ) - { - int ch = expr[cc]; - if ( ch == '/' ) - { - if ( cexpr.size() > 0 ) - { - this->AddExpression(cexpr.c_str()); - } - cexpr = ""; - } - else - { - cexpr.append(1, (char)ch); - } - } - if ( cexpr.size() > 0 ) - { - this->AddExpression(cexpr.c_str()); - } - - // Handle network paths - if ( skip > 0 ) - { - this->ProcessDirectory(0, fexpr.substr(0, skip) + "/", - true); - } - else - { - this->ProcessDirectory(0, "/", true); - } - return true; -} - -void cmGlob::AddExpression(const char* expr) -{ - this->Internals->Expressions.push_back( - cmsys::RegularExpression( - this->ConvertExpression(expr).c_str())); - this->Internals->TextExpressions.push_back(this->ConvertExpression(expr)); -} - diff --git a/Source/cmGlob.h b/Source/cmGlob.h deleted file mode 100644 index ad27a59..0000000 --- a/Source/cmGlob.h +++ /dev/null @@ -1,73 +0,0 @@ -/*========================================================================= - - Program: CMake - Cross-Platform Makefile Generator - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. - See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef cmGlob_h -#define cmGlob_h - -#include "cmStandardIncludes.h" - -class cmGlobInternal; - -/** \class cmGlob - * \brief Helper class for performing globbing searches. - * - * Finds all files that match a given globbing expression. - */ -class cmGlob -{ -public: - cmGlob(); - ~cmGlob(); - - //! Find all files that match the pattern. - bool FindFiles(const std::string& inexpr); - - //! Return the list of files that matched. - std::vector& GetFiles(); - - //! Set recurse to true to match subdirectories. - void RecurseOn() { this->SetRecurse(true); } - void RecurseOff() { this->SetRecurse(false); } - void SetRecurse(bool i) { this->Recurse = i; } - bool GetRecurse() { return this->Recurse; } - -protected: - //! Process directory - void ProcessDirectory(std::string::size_type start, - const std::string& dir, bool dir_only); - - //! Process last directory, but only when recurse flags is on. That is - // effectively like saying: /path/to/file/**/file - void RecurseDirectory(std::string::size_type start, - const std::string& dir, bool dir_only); - - //! Escape all non-alphanumeric characters in pattern. - void Escape(int ch, char* buffer); - - //! - // Translate a shell PATTERN to a regular expression. - // There is no way to quote meta-characters. - std::string ConvertExpression(const std::string& expr); - - //! Add regular expression - void AddExpression(const char* expr); - - cmGlobInternal* Internals; - bool Recurse; -}; - - -#endif diff --git a/bootstrap b/bootstrap index 057973e..4a79b02 100755 --- a/bootstrap +++ b/bootstrap @@ -95,7 +95,6 @@ CMAKE_CXX_SOURCES="\ cmMakefile \ cmGeneratedFileStream \ cmGlobalGenerator \ - cmGlob \ cmLocalGenerator \ cmInstallGenerator \ cmInstallFilesGenerator \ -- cgit v0.12