FileLister: minor cleanup
This commit is contained in:
parent
508c171945
commit
81cac166d6
|
@ -64,7 +64,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
// Execute recursiveAddFiles() to each given file parameter
|
// Execute recursiveAddFiles() to each given file parameter
|
||||||
std::vector<std::string>::const_iterator iter;
|
std::vector<std::string>::const_iterator iter;
|
||||||
for (iter = pathnames.begin(); iter != pathnames.end(); ++iter)
|
for (iter = pathnames.begin(); iter != pathnames.end(); ++iter)
|
||||||
getFileLister()->recursiveAddFiles(filenames, iter->c_str(), true);
|
getFileLister()->recursiveAddFiles(filenames, iter->c_str());
|
||||||
|
|
||||||
for (iter = filenames.begin(); iter != filenames.end(); ++iter)
|
for (iter = filenames.begin(); iter != filenames.end(); ++iter)
|
||||||
cppcheck->addFile(*iter);
|
cppcheck->addFile(*iter);
|
||||||
|
|
|
@ -53,7 +53,7 @@ void CppCheck::settings(const Settings ¤tSettings)
|
||||||
|
|
||||||
void CppCheck::addFile(const std::string &path)
|
void CppCheck::addFile(const std::string &path)
|
||||||
{
|
{
|
||||||
getFileLister()->recursiveAddFiles(_filenames, path.c_str(), true);
|
getFileLister()->recursiveAddFiles(_filenames, path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheck::addFile(const std::string &path, const std::string &content)
|
void CppCheck::addFile(const std::string &path, const std::string &content)
|
||||||
|
|
|
@ -45,10 +45,9 @@ public:
|
||||||
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
||||||
* @param filenames output vector that filenames are written to
|
* @param filenames output vector that filenames are written to
|
||||||
* @param path root path
|
* @param path root path
|
||||||
* @param recursive Should files be added recursively or not?
|
|
||||||
*/
|
*/
|
||||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames,
|
virtual void recursiveAddFiles(std::vector<std::string> &filenames,
|
||||||
const std::string &path, bool recursive) = 0;
|
const std::string &path) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compare filenames to see if they are the same.
|
* @brief Compare filenames to see if they are the same.
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
////// This code is POSIX-style systems ///////////////////////////////////////
|
////// This code is POSIX-style systems ///////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
|
void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << path;
|
oss << path;
|
||||||
|
@ -46,22 +46,20 @@ void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, cons
|
||||||
glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results);
|
glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results);
|
||||||
for (unsigned int i = 0; i < glob_results.gl_pathc; i++)
|
for (unsigned int i = 0; i < glob_results.gl_pathc; i++)
|
||||||
{
|
{
|
||||||
std::string filename = glob_results.gl_pathv[i];
|
const std::string filename = glob_results.gl_pathv[i];
|
||||||
if (filename == "." || filename == ".." || filename.length() == 0)
|
if (filename == "." || filename == ".." || filename.length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (filename[filename.length()-1] != '/')
|
if (filename[filename.length()-1] != '/')
|
||||||
{
|
{
|
||||||
// File
|
// File
|
||||||
|
if (FileLister::acceptFile(filename))
|
||||||
// If recursive is not used, accept all files given by user
|
|
||||||
if (!recursive || FileLister::acceptFile(filename))
|
|
||||||
filenames.push_back(filename);
|
filenames.push_back(filename);
|
||||||
}
|
}
|
||||||
else if (recursive)
|
else
|
||||||
{
|
{
|
||||||
// Directory
|
// Directory
|
||||||
getFileLister()->recursiveAddFiles(filenames, filename, recursive);
|
getFileLister()->recursiveAddFiles(filenames, filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globfree(&glob_results);
|
globfree(&glob_results);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
class FileListerUnix : public FileLister
|
class FileListerUnix : public FileLister
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive);
|
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
||||||
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
||||||
// virtual static bool acceptFile(const std::string &filename);
|
// virtual static bool acceptFile(const std::string &filename);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -100,7 +100,7 @@ static HANDLE MyFindFirstFile(std::string path, LPWIN32_FIND_DATA findData)
|
||||||
|
|
||||||
#endif // defined(UNICODE)
|
#endif // defined(UNICODE)
|
||||||
|
|
||||||
void FileListerWin32::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
|
void FileListerWin32::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path)
|
||||||
{
|
{
|
||||||
// oss is the search string passed into FindFirst and FindNext.
|
// oss is the search string passed into FindFirst and FindNext.
|
||||||
// bdir is the base directory which is used to form pathnames.
|
// bdir is the base directory which is used to form pathnames.
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
class FileListerWin32 : public FileLister
|
class FileListerWin32 : public FileLister
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive);
|
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
||||||
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ static void compilefiles(std::ostream &fout, const std::vector<std::string> &fil
|
||||||
|
|
||||||
static void getCppFiles(std::vector<std::string> &files, const std::string &path)
|
static void getCppFiles(std::vector<std::string> &files, const std::string &path)
|
||||||
{
|
{
|
||||||
getFileLister()->recursiveAddFiles(files, path, true);
|
getFileLister()->recursiveAddFiles(files, path);
|
||||||
// only get *.cpp files..
|
// only get *.cpp files..
|
||||||
for (std::vector<std::string>::iterator it = files.begin(); it != files.end();)
|
for (std::vector<std::string>::iterator it = files.begin(); it != files.end();)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue