summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-05 13:51:40 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-05 13:51:40 (GMT)
commitf895a94995b918779425b178ebbb865d689d06ed (patch)
tree576c892595970d2043918447876b399e92eff829 /Source/cmSystemTools.cxx
parent8ac50c4aad81f3b2e5ac026ce3ac5cf6f9aca307 (diff)
downloadCMake-f895a94995b918779425b178ebbb865d689d06ed.zip
CMake-f895a94995b918779425b178ebbb865d689d06ed.tar.gz
CMake-f895a94995b918779425b178ebbb865d689d06ed.tar.bz2
Add a simple globbing of files and directories
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 4c2f81c..1b6a41a 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2259,6 +2259,59 @@ bool cmSystemTools::GetShortPath(const char* path, std::string& shortPath)
#endif
}
+bool cmSystemTools::SimpleGlob(const std::string& glob,
+ std::vector<std::string>& files,
+ int type /* = 0 */)
+{
+ if ( glob[glob.size()-1] != '*' )
+ {
+ return false;
+ }
+ std::string path = cmSystemTools::GetFilenamePath(glob);
+ std::string ppath = cmSystemTools::GetFilenameName(glob);
+ ppath = ppath.substr(0, ppath.size()-1);
+ if ( path.size() == 0 )
+ {
+ path = "/";
+ }
+
+ bool res;
+ cmDirectory d;
+ if (d.Load(path.c_str()))
+ {
+ for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i)
+ {
+ if((std::string(d.GetFile(i)) != ".")
+ && (std::string(d.GetFile(i)) != ".."))
+ {
+ std::string fname = path;
+ if ( path[path.size()-1] != '/' )
+ {
+ fname +="/";
+ }
+ fname += d.GetFile(i);
+ std::string sfname = d.GetFile(i);
+ if ( type > 0 && cmSystemTools::FileIsDirectory(fname.c_str()) )
+ {
+ continue;
+ }
+ if ( type < 0 && !cmSystemTools::FileIsDirectory(fname.c_str()) )
+ {
+ continue;
+ }
+ if ( sfname.size() >= ppath.size() &&
+ sfname.substr(0, ppath.size()) ==
+ ppath )
+ {
+ files.push_back(fname);
+ res = true;
+ }
+ }
+ }
+ }
+ return res;
+}
+
cmSystemTools::e_FileFormat cmSystemTools::GetFileFormat(const char* cext)
{
if ( ! cext || *cext == 0 )