recursive checking when compiled by borland c++

This commit is contained in:
Daniel Marjamäki 2008-02-21 17:56:51 +00:00
parent 08b3b2ab63
commit b6ea2e43ff
1 changed files with 52 additions and 14 deletions

View File

@ -24,6 +24,42 @@ bool CheckCodingStyle = false;
static void CppCheck(const char FileName[]); static void CppCheck(const char FileName[]);
static void AddFiles( std::vector<std::string> &filenames, const char path[], const char pattern[] )
{
#ifndef __GNUC__
struct ffblk f;
for ( int done = findfirst(pattern, &f, 0); ! done; done = findnext(&f) )
{
std::ostringstream fname;
fname << path << f.ff_name;
filenames.push_back( fname.str() );
}
findclose(&f);
#endif
}
static void RecursiveAddFiles( std::vector<std::string> &filenames, const char path[] )
{
AddFiles( filenames, path, "*.cpp" );
AddFiles( filenames, path, "*.cc" );
AddFiles( filenames, path, "*.c" );
#ifndef __GNUC__
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 << "/";
RecursiveAddFiles( filenames, curdir.str().c_str() );
chdir( ".." );
}
findclose(&f);
#endif
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Main function of cppcheck // Main function of cppcheck
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -32,6 +68,8 @@ int main(int argc, char* argv[])
{ {
std::vector<std::string> filenames; std::vector<std::string> filenames;
bool Recursive = false;
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
if (strcmp(argv[i],"--debug") == 0) if (strcmp(argv[i],"--debug") == 0)
@ -45,38 +83,38 @@ int main(int argc, char* argv[])
else if (strcmp(argv[i],"--style")==0) else if (strcmp(argv[i],"--style")==0)
CheckCodingStyle = true; CheckCodingStyle = true;
// Filenames else if (strcmp(argv[i],"--recursive")==0)
else if ( strchr(argv[i], '*') ) Recursive = true;
else if (strchr(argv[i],'*'))
{ {
#ifndef __GNUC__ AddFiles( filenames, "", argv[i] );
struct ffblk f;
int done = findfirst(argv[i], &f, 0);
while ( ! done )
{
filenames.push_back( f.ff_name );
done = findnext(&f);
}
findclose(&f);
#endif
} }
else else
{
filenames.push_back( argv[i] ); filenames.push_back( argv[i] );
} }
}
// No filename given.. automaticly search for available files.
if ( Recursive )
RecursiveAddFiles( filenames, "" );
if (filenames.empty()) if (filenames.empty())
{ {
std::cout << "C/C++ code checking.\n" std::cout << "C/C++ code checking.\n"
"\n" "\n"
"Syntax:\n" "Syntax:\n"
" cppcheck [--all] [--style] filename1 [filename2]\n" " cppcheck [--all] [--style] [--recursive] [filename1] [filename2]\n"
"\n" "\n"
"Options:\n" "Options:\n"
" --all Normally a message is only shown if cppcheck is sure\n" " --all Normally a message is only shown if cppcheck is sure\n"
" it has found a bug.\n" " it has found a bug.\n"
" When this option is given, all messages are shown.\n" " When this option is given, all messages are shown.\n"
"\n" "\n"
" --style Check coding style.\n"; " --style Check coding style.\n"
" --recursive Recursily check all *.cpp, *.cc and *.c files\n";
return 0; return 0;
} }