From 8665b36f547e968ebbd691040889d31d225618cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 18 Dec 2009 18:50:38 +0100 Subject: [PATCH] lanurmi: Fixed #1016 (Patch: Refactor #ifdefs in filelister.cpp) --- lib/filelister.cpp | 88 ++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/filelister.cpp b/lib/filelister.cpp index 560956366..01e5c5a1d 100644 --- a/lib/filelister.cpp +++ b/lib/filelister.cpp @@ -24,15 +24,14 @@ #include #include -#if defined(__GNUC__) && !defined(__MINGW32__) -#include -#include -#endif -#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_WIN32) #include #ifndef __BORLANDC__ #include #endif +#else // POSIX-style system +#include +#include #endif std::string FileLister::simplifyPath(const char *originalPath) @@ -112,50 +111,12 @@ bool FileLister::acceptFile(const std::string &filename) return false; } -/////////////////////////////////////////////////////////////////////////////// -////// This code is for __GNUC__ only ///////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -#if defined(__GNUC__) && !defined(__MINGW32__) -// gcc / cygwin.. -void FileLister::recursiveAddFiles(std::vector &filenames, const std::string &path, bool recursive) -{ - std::ostringstream oss; - oss << path; - if (path.length() > 0 && path[path.length()-1] == '/') - oss << "*"; - - glob_t glob_results; - glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results); - for (unsigned int i = 0; i < glob_results.gl_pathc; i++) - { - std::string filename = glob_results.gl_pathv[i]; - if (filename == "." || filename == ".." || filename.length() == 0) - continue; - - if (filename[filename.length()-1] != '/') - { - // File - - // If recursive is not used, accept all files given by user - if (!recursive || FileLister::acceptFile(filename)) - filenames.push_back(filename); - } - else if (recursive) - { - // Directory - FileLister::recursiveAddFiles(filenames, filename, recursive); - } - } - globfree(&glob_results); -} -#endif /////////////////////////////////////////////////////////////////////////////// -////// This code is for Borland C++ and Visual C++ //////////////////////////// +////// This code is for Microsoft Windows ///////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -#if (defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)) +#if defined(_WIN32) // Here is the catch: cppcheck core is Ansi code (using char type). // When compiling Unicode targets WinAPI automatically uses *W Unicode versions @@ -302,6 +263,43 @@ void FileLister::recursiveAddFiles(std::vector &filenames, const st } } +#else // other than _WIN32 + +/////////////////////////////////////////////////////////////////////////////// +////// This code is POSIX-style systems /////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +void FileLister::recursiveAddFiles(std::vector &filenames, const std::string &path, bool recursive) +{ + std::ostringstream oss; + oss << path; + if (path.length() > 0 && path[path.length()-1] == '/') + oss << "*"; + + glob_t glob_results; + glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results); + for (unsigned int i = 0; i < glob_results.gl_pathc; i++) + { + std::string filename = glob_results.gl_pathv[i]; + if (filename == "." || filename == ".." || filename.length() == 0) + continue; + + if (filename[filename.length()-1] != '/') + { + // File + + // If recursive is not used, accept all files given by user + if (!recursive || FileLister::acceptFile(filename)) + filenames.push_back(filename); + } + else if (recursive) + { + // Directory + FileLister::recursiveAddFiles(filenames, filename, recursive); + } + } + globfree(&glob_results); +} #endif //---------------------------------------------------------------------------