ENH: Add support for relative paths and cleanup
This commit is contained in:
parent
1cdd8b4fbd
commit
9dbf4438dc
|
@ -61,14 +61,15 @@ public:
|
|||
//----------------------------------------------------------------------------
|
||||
Glob::Glob()
|
||||
{
|
||||
m_Internals = new GlobInternals;
|
||||
m_Recurse = false;
|
||||
this->Internals = new GlobInternals;
|
||||
this->Recurse = false;
|
||||
this->Relative = "";
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Glob::~Glob()
|
||||
{
|
||||
delete m_Internals;
|
||||
delete this->Internals;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -95,7 +96,7 @@ void Glob::Escape(int ch, char* buffer)
|
|||
//----------------------------------------------------------------------------
|
||||
kwsys_stl::vector<kwsys_stl::string>& Glob::GetFiles()
|
||||
{
|
||||
return m_Internals->Files;
|
||||
return this->Internals->Files;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -224,9 +225,10 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
|
|||
|
||||
if ( !dir_only || !kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
||||
{
|
||||
if ( m_Internals->Expressions[m_Internals->Expressions.size()-1].find(fname.c_str()) )
|
||||
if ( this->Internals->Expressions[
|
||||
this->Internals->Expressions.size()-1].find(fname.c_str()) )
|
||||
{
|
||||
m_Internals->Files.push_back(realname);
|
||||
this->AddFile(this->Internals->Files, realname.c_str());
|
||||
}
|
||||
}
|
||||
if ( kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
||||
|
@ -241,8 +243,8 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
|
|||
const kwsys_stl::string& dir, bool dir_only)
|
||||
{
|
||||
//kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
|
||||
bool last = ( start == m_Internals->Expressions.size()-1 );
|
||||
if ( last && m_Recurse )
|
||||
bool last = ( start == this->Internals->Expressions.size()-1 );
|
||||
if ( last && this->Recurse )
|
||||
{
|
||||
this->RecurseDirectory(start, dir, dir_only);
|
||||
return;
|
||||
|
@ -289,19 +291,21 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
|
|||
}
|
||||
|
||||
//kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl;
|
||||
//kwsys_ios::cout << "Match: " << m_Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
|
||||
//kwsys_ios::cout << "Match: "
|
||||
// << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
|
||||
//kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl;
|
||||
|
||||
if ( (!dir_only || !last) && !kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
||||
if ( (!dir_only || !last) &&
|
||||
!kwsys::SystemTools::FileIsDirectory(realname.c_str()) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( m_Internals->Expressions[start].find(fname.c_str()) )
|
||||
if ( this->Internals->Expressions[start].find(fname.c_str()) )
|
||||
{
|
||||
if ( last )
|
||||
{
|
||||
m_Internals->Files.push_back(realname);
|
||||
this->AddFile(this->Internals->Files, realname.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -318,8 +322,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
|
|||
kwsys_stl::string::size_type cc;
|
||||
kwsys_stl::string expr = inexpr;
|
||||
|
||||
m_Internals->Expressions.clear();
|
||||
m_Internals->Files.clear();
|
||||
this->Internals->Expressions.clear();
|
||||
this->Internals->Files.clear();
|
||||
|
||||
if ( !kwsys::SystemTools::FileIsFullPath(expr.c_str()) )
|
||||
{
|
||||
|
@ -345,7 +349,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
|
|||
}
|
||||
if ( last_slash > 0 )
|
||||
{
|
||||
//kwsys_ios::cout << "I can skip: " << fexpr.substr(0, last_slash) << kwsys_ios::endl;
|
||||
//kwsys_ios::cout << "I can skip: " << fexpr.substr(0, last_slash)
|
||||
//<< kwsys_ios::endl;
|
||||
skip = last_slash;
|
||||
}
|
||||
if ( skip == 0 )
|
||||
|
@ -417,12 +422,47 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
|
|||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Glob::AddExpression(const char* expr)
|
||||
{
|
||||
m_Internals->Expressions.push_back(
|
||||
this->Internals->Expressions.push_back(
|
||||
kwsys::RegularExpression(
|
||||
this->ConvertExpression(expr).c_str()));
|
||||
m_Internals->TextExpressions.push_back(this->ConvertExpression(expr));
|
||||
this->Internals->TextExpressions.push_back(this->ConvertExpression(expr));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace KWSYS_NAMESPACE
|
||||
|
|
|
@ -54,8 +54,12 @@ public:
|
|||
//! Set recurse to true to match subdirectories.
|
||||
void RecurseOn() { this->SetRecurse(true); }
|
||||
void RecurseOff() { this->SetRecurse(false); }
|
||||
void SetRecurse(bool i) { m_Recurse = i; }
|
||||
bool GetRecurse() { return m_Recurse; }
|
||||
void SetRecurse(bool i) { this->Recurse = i; }
|
||||
bool GetRecurse() { return this->Recurse; }
|
||||
|
||||
//! Set relative to true to only show relative path to files.
|
||||
void SetRelative(const char* dir);
|
||||
const char* GetRelative();
|
||||
|
||||
protected:
|
||||
//! Process directory
|
||||
|
@ -78,8 +82,12 @@ protected:
|
|||
//! Add regular expression
|
||||
void AddExpression(const char* expr);
|
||||
|
||||
GlobInternals* m_Internals;
|
||||
bool m_Recurse;
|
||||
//! Add a file to the list
|
||||
void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file);
|
||||
|
||||
GlobInternals* Internals;
|
||||
bool Recurse;
|
||||
kwsys_stl::string Relative;
|
||||
};
|
||||
|
||||
} // namespace @KWSYS_NAMESPACE@
|
||||
|
|
Loading…
Reference in New Issue