FileLister: Borland can use windows api for file searching

This commit is contained in:
Daniel Marjamäki 2008-12-10 19:11:48 +00:00
parent cf2262aaf0
commit 02f3196b24
2 changed files with 21 additions and 87 deletions

View File

@ -1,4 +1,4 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi * Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi
* *
@ -23,10 +23,7 @@
#include <glob.h> #include <glob.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef __BORLANDC__ #if defined(__BORLANDC__) || defined(_MSC_VER)
#include <dir.h>
#endif
#ifdef _MSC_VER
#include <windows.h> #include <windows.h>
#endif #endif
@ -93,66 +90,12 @@ void FileLister::RecursiveAddFiles( std::vector<std::string> &filenames, const s
} }
#endif #endif
///////////////////////////////////////////////////////////////////////////////
////// This code is for __BORLANDC__ only /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#ifdef __BORLANDC__
void FileLister::AddFiles( std::vector<std::string> &filenames, const std::string &path, const std::string &pattern )
{
struct ffblk f;
for ( int done = findfirst(pattern.c_str(), &f, 0); ! done; done = findnext(&f) )
{
std::ostringstream fname;
fname << path << f.ff_name;
filenames.push_back( fname.str() );
}
findclose(&f);
}
// TODO, this should be complitely rewritten to work similarly like with __GNUC__,
// but I don't have a compiler to do the work
void FileLister::RecursiveAddFiles( std::vector<std::string> &filenames, const std::string &path, bool recursive )
{
if( !recursive )
{
// Simulate old behaviour
if ( path.find( '*' ) == std::string::npos )
filenames.push_back( path );
else
FileLister::AddFiles( filenames, "", path );
return;
}
AddFiles( filenames, path, "*.cpp" );
AddFiles( filenames, path, "*.cxx" );
AddFiles( filenames, path, "*.cc" );
AddFiles( filenames, path, "*.c" );
struct ffblk f ;
for ( int done = findfirst("*", &f, FA_DIREC); ! done; done = findnext(&f) )
{
if ( f.ff_attrib != FA_DIREC || f.ff_name[0] == '.' )
continue;
chdir( f.ff_name );
std::ostringstream curdir;
curdir << path << f.ff_name << "/";
FileLister::RecursiveAddFiles( filenames, curdir.str().c_str(), true );
chdir( ".." );
}
findclose(&f);
}
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
////// This code is for _MSC_VER only ///////////////////////////////////////// ////// This code is for Borland C++ and Visual C++ ////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER #if defined(__BORLANDC__) || defined(_MSC_VER)
void FileLister::RecursiveAddFiles( std::vector<std::string> &filenames, const std::string &path, bool recursive ) void FileLister::RecursiveAddFiles( std::vector<std::string> &filenames, const std::string &path, bool recursive )
{ {

View File

@ -1,4 +1,4 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi * Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi
* *
@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/ * along with this program. If not, see <http://www.gnu.org/licenses/
*/ */
#ifndef FILELISTER_H #ifndef FileListerH
#define FILELISTER_H #define FileListerH
#include <vector> #include <vector>
#include <string> #include <string>
@ -42,15 +42,6 @@ public:
private: private:
static bool AcceptFile( const std::string &filename ); static bool AcceptFile( const std::string &filename );
#ifdef __BORLANDC__
static void AddFiles( std::vector<std::string> &filenames, const std::string &path, const std::string &pattern );
#endif
#ifdef _MSC_VER
static void AddFiles( std::vector<std::string> &filenames, const std::string &path, const std::string &pattern );
#endif
}; };
#endif // #ifndef FILELISTER_H #endif // #ifndef FILELISTER_H