2009-10-02 01:21:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
KWSys - Kitware System Library
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2005-10-18 22:08:55 +04:00
|
|
|
#include "kwsysPrivate.h"
|
|
|
|
#include KWSYS_HEADER(Glob.hxx)
|
|
|
|
|
|
|
|
#include KWSYS_HEADER(Configure.hxx)
|
|
|
|
|
|
|
|
#include KWSYS_HEADER(RegularExpression.hxx)
|
|
|
|
#include KWSYS_HEADER(SystemTools.hxx)
|
|
|
|
#include KWSYS_HEADER(Directory.hxx)
|
|
|
|
#include KWSYS_HEADER(stl/string)
|
|
|
|
#include KWSYS_HEADER(stl/vector)
|
|
|
|
|
|
|
|
// Work-around CMake dependency scanning limitation. This must
|
|
|
|
// duplicate the above list of headers.
|
|
|
|
#if 0
|
|
|
|
# include "Glob.hxx.in"
|
2006-03-06 21:34:33 +03:00
|
|
|
# include "Directory.hxx.in"
|
2005-10-18 22:08:55 +04:00
|
|
|
# include "Configure.hxx.in"
|
|
|
|
# include "RegularExpression.hxx.in"
|
|
|
|
# include "SystemTools.hxx.in"
|
|
|
|
# include "kwsys_stl.hxx.in"
|
|
|
|
# include "kwsys_stl_string.hxx.in"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
2006-01-17 18:21:45 +03:00
|
|
|
#include <string.h>
|
2005-10-18 22:08:55 +04:00
|
|
|
namespace KWSYS_NAMESPACE
|
|
|
|
{
|
2006-08-22 06:39:03 +04:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
|
2006-08-21 22:17:58 +04:00
|
|
|
// On Windows and apple, no difference between lower and upper case
|
|
|
|
# define KWSYS_GLOB_CASE_INDEPENDENT
|
2005-10-18 22:08:55 +04:00
|
|
|
#endif
|
|
|
|
|
2006-08-21 22:17:58 +04:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
// Handle network paths
|
|
|
|
# define KWSYS_GLOB_SUPPORT_NETWORK_PATHS
|
2005-10-18 22:08:55 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
class GlobInternals
|
|
|
|
{
|
|
|
|
public:
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::vector<kwsys_stl::string> Files;
|
|
|
|
kwsys_stl::vector<kwsys::RegularExpression> Expressions;
|
2005-10-18 22:08:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Glob::Glob()
|
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
this->Internals = new GlobInternals;
|
|
|
|
this->Recurse = false;
|
|
|
|
this->Relative = "";
|
2008-08-20 21:24:16 +04:00
|
|
|
|
|
|
|
this->RecurseThroughSymlinks = true;
|
|
|
|
// RecurseThroughSymlinks is true by default for backwards compatibility,
|
|
|
|
// not because it's a good idea...
|
2008-09-11 22:34:04 +04:00
|
|
|
this->FollowedSymlinkCount = 0;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Glob::~Glob()
|
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
delete this->Internals;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::vector<kwsys_stl::string>& Glob::GetFiles()
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
return this->Internals->Files;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-08-21 22:17:58 +04:00
|
|
|
kwsys_stl::string Glob::PatternToRegex(const kwsys_stl::string& pattern,
|
2009-09-14 21:45:40 +04:00
|
|
|
bool require_whole_string,
|
|
|
|
bool preserve_case)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// Incrementally build the regular expression from the pattern.
|
|
|
|
kwsys_stl::string regex = require_whole_string? "^" : "";
|
|
|
|
kwsys_stl::string::const_iterator pattern_first = pattern.begin();
|
|
|
|
kwsys_stl::string::const_iterator pattern_last = pattern.end();
|
|
|
|
for(kwsys_stl::string::const_iterator i = pattern_first;
|
|
|
|
i != pattern_last; ++i)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
int c = *i;
|
|
|
|
if(c == '*')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// A '*' (not between brackets) matches any string.
|
2006-08-25 20:13:37 +04:00
|
|
|
// We modify this to not match slashes since the orignal glob
|
|
|
|
// pattern documentation was meant for matching file name
|
|
|
|
// components separated by slashes.
|
|
|
|
regex += "[^/]*";
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
else if(c == '?')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// A '?' (not between brackets) matches any single character.
|
2006-08-25 20:13:37 +04:00
|
|
|
// We modify this to not match slashes since the orignal glob
|
|
|
|
// pattern documentation was meant for matching file name
|
|
|
|
// components separated by slashes.
|
|
|
|
regex += "[^/]";
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
else if(c == '[')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// Parse out the bracket expression. It begins just after the
|
|
|
|
// opening character.
|
|
|
|
kwsys_stl::string::const_iterator bracket_first = i+1;
|
|
|
|
kwsys_stl::string::const_iterator bracket_last = bracket_first;
|
|
|
|
|
|
|
|
// The first character may be complementation '!' or '^'.
|
|
|
|
if(bracket_last != pattern_last &&
|
|
|
|
(*bracket_last == '!' || *bracket_last == '^'))
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
++bracket_last;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
// If the next character is a ']' it is included in the brackets
|
|
|
|
// because the bracket string may not be empty.
|
|
|
|
if(bracket_last != pattern_last && *bracket_last == ']')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
++bracket_last;
|
2006-03-22 00:02:47 +03:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
// Search for the closing ']'.
|
|
|
|
while(bracket_last != pattern_last && *bracket_last != ']')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
++bracket_last;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
// Check whether we have a complete bracket string.
|
|
|
|
if(bracket_last == pattern_last)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// The bracket string did not end, so it was opened simply by
|
|
|
|
// a '[' that is supposed to be matched literally.
|
|
|
|
regex += "\\[";
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// Convert the bracket string to its regex equivalent.
|
|
|
|
kwsys_stl::string::const_iterator k = bracket_first;
|
|
|
|
|
|
|
|
// Open the regex block.
|
|
|
|
regex += "[";
|
|
|
|
|
|
|
|
// A regex range complement uses '^' instead of '!'.
|
|
|
|
if(k != bracket_last && *k == '!')
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
regex += "^";
|
|
|
|
++k;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
// Convert the remaining characters.
|
|
|
|
for(; k != bracket_last; ++k)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// Backslashes must be escaped.
|
|
|
|
if(*k == '\\')
|
|
|
|
{
|
|
|
|
regex += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store this character.
|
|
|
|
regex += *k;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
// Close the regex block.
|
|
|
|
regex += "]";
|
|
|
|
|
|
|
|
// Jump to the end of the bracket string.
|
|
|
|
i = bracket_last;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-21 22:17:58 +04:00
|
|
|
// A single character matches itself.
|
|
|
|
int ch = c;
|
|
|
|
if(!(('a' <= ch && ch <= 'z') ||
|
|
|
|
('A' <= ch && ch <= 'Z') ||
|
|
|
|
('0' <= ch && ch <= '9')))
|
|
|
|
{
|
|
|
|
// Escape the non-alphanumeric character.
|
|
|
|
regex += "\\";
|
|
|
|
}
|
|
|
|
#if defined(KWSYS_GLOB_CASE_INDEPENDENT)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// On case-insensitive systems file names are converted to lower
|
|
|
|
// case before matching.
|
2009-09-14 21:45:40 +04:00
|
|
|
if(!preserve_case)
|
|
|
|
{
|
|
|
|
ch = tolower(ch);
|
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
}
|
|
|
|
#endif
|
2009-09-14 21:45:40 +04:00
|
|
|
(void)preserve_case;
|
2006-08-21 22:17:58 +04:00
|
|
|
// Store the character.
|
|
|
|
regex.append(1, static_cast<char>(ch));
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-21 22:17:58 +04:00
|
|
|
|
|
|
|
if(require_whole_string)
|
|
|
|
{
|
|
|
|
regex += "$";
|
|
|
|
}
|
|
|
|
return regex;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2005-10-19 18:47:19 +04:00
|
|
|
void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
|
|
|
|
const kwsys_stl::string& dir, bool dir_only)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2005-10-19 16:42:22 +04:00
|
|
|
kwsys::Directory d;
|
2005-10-18 22:08:55 +04:00
|
|
|
if ( !d.Load(dir.c_str()) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unsigned long cc;
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::string fullname;
|
|
|
|
kwsys_stl::string realname;
|
|
|
|
kwsys_stl::string fname;
|
2005-10-18 22:08:55 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:42:22 +04:00
|
|
|
#if defined( KWSYS_GLOB_CASE_INDEPENDENT )
|
2005-10-18 22:08:55 +04:00
|
|
|
// On Windows and apple, no difference between lower and upper case
|
2005-10-19 16:42:22 +04:00
|
|
|
fname = kwsys::SystemTools::LowerCase(fname);
|
2005-10-18 22:08:55 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( start == 0 )
|
|
|
|
{
|
|
|
|
fullname = dir + fname;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fullname = dir + "/" + fname;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:42:22 +04:00
|
|
|
if ( !dir_only || !kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2007-08-21 23:30:07 +04:00
|
|
|
if ( (this->Internals->Expressions.size() > 0) &&
|
|
|
|
this->Internals->Expressions[
|
|
|
|
this->Internals->Expressions.size()-1].find(fname.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
this->AddFile(this->Internals->Files, realname.c_str());
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
2005-10-19 16:42:22 +04:00
|
|
|
if ( kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2008-09-11 22:34:04 +04:00
|
|
|
bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str());
|
|
|
|
if (!isSymLink || this->RecurseThroughSymlinks)
|
2008-08-20 21:24:16 +04:00
|
|
|
{
|
2008-09-11 22:34:04 +04:00
|
|
|
if (isSymLink)
|
|
|
|
{
|
|
|
|
++this->FollowedSymlinkCount;
|
|
|
|
}
|
2008-08-20 21:24:16 +04:00
|
|
|
this->RecurseDirectory(start+1, realname, dir_only);
|
|
|
|
}
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-03-22 00:02:47 +03:00
|
|
|
void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
|
2005-10-19 18:47:19 +04:00
|
|
|
const kwsys_stl::string& dir, bool dir_only)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2005-10-19 18:47:19 +04:00
|
|
|
//kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
|
2006-03-22 00:02:47 +03:00
|
|
|
bool last = ( start == this->Internals->Expressions.size()-1 );
|
|
|
|
if ( last && this->Recurse )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
|
|
|
this->RecurseDirectory(start, dir, dir_only);
|
|
|
|
return;
|
|
|
|
}
|
2007-08-21 23:30:07 +04:00
|
|
|
|
|
|
|
if ( start >= this->Internals->Expressions.size() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:42:22 +04:00
|
|
|
kwsys::Directory d;
|
2005-10-18 22:08:55 +04:00
|
|
|
if ( !d.Load(dir.c_str()) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unsigned long cc;
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::string fullname;
|
|
|
|
kwsys_stl::string realname;
|
|
|
|
kwsys_stl::string fname;
|
2005-10-18 22:08:55 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-08-21 22:17:58 +04:00
|
|
|
#if defined(KWSYS_GLOB_CASE_INDEPENDENT)
|
|
|
|
// On case-insensitive file systems convert to lower case for matching.
|
2005-10-19 16:42:22 +04:00
|
|
|
fname = kwsys::SystemTools::LowerCase(fname);
|
2005-10-18 22:08:55 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( start == 0 )
|
|
|
|
{
|
|
|
|
fullname = dir + fname;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fullname = dir + "/" + fname;
|
|
|
|
}
|
|
|
|
|
2005-10-19 18:47:19 +04:00
|
|
|
//kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl;
|
2006-03-22 00:02:47 +03:00
|
|
|
//kwsys_ios::cout << "Match: "
|
|
|
|
// << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
|
2005-10-19 18:47:19 +04:00
|
|
|
//kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl;
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
if ( (!dir_only || !last) &&
|
|
|
|
!kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
if ( this->Internals->Expressions[start].find(fname.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
|
|
|
if ( last )
|
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
this->AddFile(this->Internals->Files, realname.c_str());
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ProcessDirectory(start+1, realname + "/", dir_only);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2005-10-19 18:47:19 +04:00
|
|
|
bool Glob::FindFiles(const kwsys_stl::string& inexpr)
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::string cexpr;
|
|
|
|
kwsys_stl::string::size_type cc;
|
|
|
|
kwsys_stl::string expr = inexpr;
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
this->Internals->Expressions.clear();
|
|
|
|
this->Internals->Files.clear();
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2005-10-19 16:42:22 +04:00
|
|
|
if ( !kwsys::SystemTools::FileIsFullPath(expr.c_str()) )
|
2005-10-18 22:08:55 +04:00
|
|
|
{
|
2005-10-19 16:42:22 +04:00
|
|
|
expr = kwsys::SystemTools::GetCurrentWorkingDirectory();
|
2005-10-18 22:08:55 +04:00
|
|
|
expr += "/" + inexpr;
|
|
|
|
}
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::string fexpr = expr;
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2009-03-17 17:48:24 +03:00
|
|
|
kwsys_stl::string::size_type skip = 0;
|
|
|
|
kwsys_stl::string::size_type last_slash = 0;
|
2005-10-18 22:08:55 +04:00
|
|
|
for ( cc = 0; cc < expr.size(); cc ++ )
|
|
|
|
{
|
|
|
|
if ( cc > 0 && expr[cc] == '/' && expr[cc-1] != '\\' )
|
|
|
|
{
|
2009-03-17 17:48:24 +03:00
|
|
|
last_slash = cc;
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
2006-03-22 00:02:47 +03:00
|
|
|
if ( cc > 0 &&
|
2005-10-18 22:08:55 +04:00
|
|
|
(expr[cc] == '[' || expr[cc] == '?' || expr[cc] == '*') &&
|
|
|
|
expr[cc-1] != '\\' )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( last_slash > 0 )
|
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
//kwsys_ios::cout << "I can skip: " << fexpr.substr(0, last_slash)
|
|
|
|
//<< kwsys_ios::endl;
|
2005-10-18 22:08:55 +04:00
|
|
|
skip = last_slash;
|
|
|
|
}
|
|
|
|
if ( skip == 0 )
|
|
|
|
{
|
2005-10-19 16:42:22 +04:00
|
|
|
#if defined( KWSYS_GLOB_SUPPORT_NETWORK_PATHS )
|
2005-10-18 22:08:55 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-30 22:49:56 +04:00
|
|
|
skip = int(cc + 1);
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2006-03-10 20:01:29 +03:00
|
|
|
cexpr.append(1, static_cast<char>(ch));
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( cexpr.size() > 0 )
|
|
|
|
{
|
|
|
|
this->AddExpression(cexpr.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle network paths
|
|
|
|
if ( skip > 0 )
|
|
|
|
{
|
|
|
|
this->ProcessDirectory(0, fexpr.substr(0, skip) + "/",
|
2006-03-22 00:02:47 +03:00
|
|
|
true);
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ProcessDirectory(0, "/", true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2005-10-18 22:08:55 +04:00
|
|
|
void Glob::AddExpression(const char* expr)
|
|
|
|
{
|
2006-03-22 00:02:47 +03:00
|
|
|
this->Internals->Expressions.push_back(
|
2005-10-19 16:42:22 +04:00
|
|
|
kwsys::RegularExpression(
|
2006-08-21 22:17:58 +04:00
|
|
|
this->PatternToRegex(expr).c_str()));
|
2006-03-22 00:02:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Glob::SetRelative(const char* dir)
|
|
|
|
{
|
|
|
|
if ( !dir )
|
|
|
|
{
|
|
|
|
this->Relative = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->Relative = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const char* Glob::GetRelative()
|
|
|
|
{
|
|
|
|
if ( this->Relative.empty() )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return this->Relative.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file)
|
|
|
|
{
|
|
|
|
if ( !this->Relative.empty() )
|
|
|
|
{
|
|
|
|
files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
files.push_back(file);
|
|
|
|
}
|
2005-10-18 22:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWSYS_NAMESPACE
|
|
|
|
|