Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvain Joubert
KWSys
Commits
82879a82
Commit
82879a82
authored
19 years ago
by
Andy Cedilnik
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Add support for relative paths and cleanup
parent
5cc92fcb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Glob.cxx
+64
-24
64 additions, 24 deletions
Glob.cxx
Glob.hxx.in
+13
-5
13 additions, 5 deletions
Glob.hxx.in
with
77 additions
and
29 deletions
Glob.cxx
+
64
−
24
View file @
82879a82
...
@@ -61,22 +61,23 @@ public:
...
@@ -61,22 +61,23 @@ public:
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
Glob
::
Glob
()
Glob
::
Glob
()
{
{
m_Internals
=
new
GlobInternals
;
this
->
Internals
=
new
GlobInternals
;
m_Recurse
=
false
;
this
->
Recurse
=
false
;
this
->
Relative
=
""
;
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
Glob
::~
Glob
()
Glob
::~
Glob
()
{
{
delete
m_
Internals
;
delete
this
->
Internals
;
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void
Glob
::
Escape
(
int
ch
,
char
*
buffer
)
void
Glob
::
Escape
(
int
ch
,
char
*
buffer
)
{
{
if
(
!
(
if
(
!
(
'a'
<=
ch
&&
ch
<=
'z'
||
'a'
<=
ch
&&
ch
<=
'z'
||
'A'
<=
ch
&&
ch
<=
'Z'
||
'A'
<=
ch
&&
ch
<=
'Z'
||
'0'
<=
ch
&&
ch
<=
'9'
)
)
'0'
<=
ch
&&
ch
<=
'9'
)
)
{
{
sprintf
(
buffer
,
"
\\
%c"
,
ch
);
sprintf
(
buffer
,
"
\\
%c"
,
ch
);
...
@@ -95,13 +96,13 @@ void Glob::Escape(int ch, char* buffer)
...
@@ -95,13 +96,13 @@ void Glob::Escape(int ch, char* buffer)
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
kwsys_stl
::
vector
<
kwsys_stl
::
string
>&
Glob
::
GetFiles
()
kwsys_stl
::
vector
<
kwsys_stl
::
string
>&
Glob
::
GetFiles
()
{
{
return
m_
Internals
->
Files
;
return
this
->
Internals
->
Files
;
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
kwsys_stl
::
string
Glob
::
ConvertExpression
(
const
kwsys_stl
::
string
&
expr
)
kwsys_stl
::
string
Glob
::
ConvertExpression
(
const
kwsys_stl
::
string
&
expr
)
{
{
kwsys_stl
::
string
::
size_type
i
=
0
;
kwsys_stl
::
string
::
size_type
i
=
0
;
kwsys_stl
::
string
::
size_type
n
=
expr
.
size
();
kwsys_stl
::
string
::
size_type
n
=
expr
.
size
();
...
@@ -130,7 +131,7 @@ kwsys_stl::string Glob::ConvertExpression(const kwsys_stl::string& expr)
...
@@ -130,7 +131,7 @@ kwsys_stl::string Glob::ConvertExpression(const kwsys_stl::string& expr)
if
(
j
<
n
&&
expr
[
j
]
==
']'
)
if
(
j
<
n
&&
expr
[
j
]
==
']'
)
{
{
j
=
j
+
1
;
j
=
j
+
1
;
}
}
while
(
j
<
n
&&
expr
[
j
]
!=
']'
)
while
(
j
<
n
&&
expr
[
j
]
!=
']'
)
{
{
j
=
j
+
1
;
j
=
j
+
1
;
...
@@ -224,9 +225,10 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
...
@@ -224,9 +225,10 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
if
(
!
dir_only
||
!
kwsys
::
SystemTools
::
FileIsDirectory
(
realname
.
c_str
())
)
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
())
)
if
(
kwsys
::
SystemTools
::
FileIsDirectory
(
realname
.
c_str
())
)
...
@@ -237,12 +239,12 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
...
@@ -237,12 +239,12 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void
Glob
::
ProcessDirectory
(
kwsys_stl
::
string
::
size_type
start
,
void
Glob
::
ProcessDirectory
(
kwsys_stl
::
string
::
size_type
start
,
const
kwsys_stl
::
string
&
dir
,
bool
dir_only
)
const
kwsys_stl
::
string
&
dir
,
bool
dir_only
)
{
{
//kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
//kwsys_ios::cout << "ProcessDirectory: " << dir << kwsys_ios::endl;
bool
last
=
(
start
==
m_
Internals
->
Expressions
.
size
()
-
1
);
bool
last
=
(
start
==
this
->
Internals
->
Expressions
.
size
()
-
1
);
if
(
last
&&
m_
Recurse
)
if
(
last
&&
this
->
Recurse
)
{
{
this
->
RecurseDirectory
(
start
,
dir
,
dir_only
);
this
->
RecurseDirectory
(
start
,
dir
,
dir_only
);
return
;
return
;
...
@@ -289,19 +291,21 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
...
@@ -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 << "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;
//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
;
continue
;
}
}
if
(
m_
Internals
->
Expressions
[
start
].
find
(
fname
.
c_str
())
)
if
(
this
->
Internals
->
Expressions
[
start
].
find
(
fname
.
c_str
())
)
{
{
if
(
last
)
if
(
last
)
{
{
m_Internals
->
Files
.
push_back
(
realname
);
this
->
AddFile
(
this
->
Internals
->
Files
,
realname
.
c_str
()
);
}
}
else
else
{
{
...
@@ -318,8 +322,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
...
@@ -318,8 +322,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
kwsys_stl
::
string
::
size_type
cc
;
kwsys_stl
::
string
::
size_type
cc
;
kwsys_stl
::
string
expr
=
inexpr
;
kwsys_stl
::
string
expr
=
inexpr
;
m_
Internals
->
Expressions
.
clear
();
this
->
Internals
->
Expressions
.
clear
();
m_
Internals
->
Files
.
clear
();
this
->
Internals
->
Files
.
clear
();
if
(
!
kwsys
::
SystemTools
::
FileIsFullPath
(
expr
.
c_str
())
)
if
(
!
kwsys
::
SystemTools
::
FileIsFullPath
(
expr
.
c_str
())
)
{
{
...
@@ -336,7 +340,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
...
@@ -336,7 +340,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
{
{
last_slash
=
cc
;
last_slash
=
cc
;
}
}
if
(
cc
>
0
&&
if
(
cc
>
0
&&
(
expr
[
cc
]
==
'['
||
expr
[
cc
]
==
'?'
||
expr
[
cc
]
==
'*'
)
&&
(
expr
[
cc
]
==
'['
||
expr
[
cc
]
==
'?'
||
expr
[
cc
]
==
'*'
)
&&
expr
[
cc
-
1
]
!=
'\\'
)
expr
[
cc
-
1
]
!=
'\\'
)
{
{
...
@@ -345,7 +349,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
...
@@ -345,7 +349,8 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
}
}
if
(
last_slash
>
0
)
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
;
skip
=
last_slash
;
}
}
if
(
skip
==
0
)
if
(
skip
==
0
)
...
@@ -408,7 +413,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
...
@@ -408,7 +413,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
if
(
skip
>
0
)
if
(
skip
>
0
)
{
{
this
->
ProcessDirectory
(
0
,
fexpr
.
substr
(
0
,
skip
)
+
"/"
,
this
->
ProcessDirectory
(
0
,
fexpr
.
substr
(
0
,
skip
)
+
"/"
,
true
);
true
);
}
}
else
else
{
{
...
@@ -417,12 +422,47 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
...
@@ -417,12 +422,47 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr)
return
true
;
return
true
;
}
}
//----------------------------------------------------------------------------
void
Glob
::
AddExpression
(
const
char
*
expr
)
void
Glob
::
AddExpression
(
const
char
*
expr
)
{
{
m_
Internals
->
Expressions
.
push_back
(
this
->
Internals
->
Expressions
.
push_back
(
kwsys
::
RegularExpression
(
kwsys
::
RegularExpression
(
this
->
ConvertExpression
(
expr
).
c_str
()));
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
}
// namespace KWSYS_NAMESPACE
...
...
This diff is collapsed.
Click to expand it.
Glob.hxx.in
+
13
−
5
View file @
82879a82
...
@@ -54,12 +54,16 @@ public:
...
@@ -54,12 +54,16 @@ public:
//! Set recurse to true to match subdirectories.
//! Set recurse to true to match subdirectories.
void RecurseOn() { this->SetRecurse(true); }
void RecurseOn() { this->SetRecurse(true); }
void RecurseOff() { this->SetRecurse(false); }
void RecurseOff() { this->SetRecurse(false); }
void SetRecurse(bool i) { m_Recurse = i; }
void SetRecurse(bool i) { this->Recurse = i; }
bool GetRecurse() { return m_Recurse; }
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:
protected:
//! Process directory
//! Process directory
void ProcessDirectory(kwsys_stl::string::size_type start,
void ProcessDirectory(kwsys_stl::string::size_type start,
const kwsys_stl::string& dir, bool dir_only);
const kwsys_stl::string& dir, bool dir_only);
//! Process last directory, but only when recurse flags is on. That is
//! Process last directory, but only when recurse flags is on. That is
...
@@ -78,8 +82,12 @@ protected:
...
@@ -78,8 +82,12 @@ protected:
//! Add regular expression
//! Add regular expression
void AddExpression(const char* expr);
void AddExpression(const char* expr);
GlobInternals* m_Internals;
//! Add a file to the list
bool m_Recurse;
void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file);
GlobInternals* Internals;
bool Recurse;
kwsys_stl::string Relative;
};
};
} // namespace @KWSYS_NAMESPACE@
} // namespace @KWSYS_NAMESPACE@
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment