Added command line option "--errorsonly"
This commit is contained in:
parent
0b1ee10353
commit
34507f73ce
21
main.cpp
21
main.cpp
|
@ -38,6 +38,7 @@
|
||||||
bool Debug = false;
|
bool Debug = false;
|
||||||
bool ShowAll = false;
|
bool ShowAll = false;
|
||||||
bool CheckCodingStyle = false;
|
bool CheckCodingStyle = false;
|
||||||
|
bool ErrorsOnly = false;
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
static void CppCheck(const std::string &code, const char FileName[], unsigned int FileId);
|
static void CppCheck(const std::string &code, const char FileName[], unsigned int FileId);
|
||||||
|
@ -65,6 +66,10 @@ int main(int argc, char* argv[])
|
||||||
else if (strcmp(argv[i],"--style")==0)
|
else if (strcmp(argv[i],"--style")==0)
|
||||||
CheckCodingStyle = true;
|
CheckCodingStyle = true;
|
||||||
|
|
||||||
|
// Only print something when there are errors
|
||||||
|
else if (strcmp(argv[i],"--errorsonly")==0)
|
||||||
|
ErrorsOnly = true;
|
||||||
|
|
||||||
else if (strcmp(argv[i],"--recursive")==0)
|
else if (strcmp(argv[i],"--recursive")==0)
|
||||||
Recursive = true;
|
Recursive = true;
|
||||||
else
|
else
|
||||||
|
@ -104,7 +109,7 @@ int main(int argc, char* argv[])
|
||||||
std::cout << "C/C++ code checking.\n"
|
std::cout << "C/C++ code checking.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Syntax:\n"
|
"Syntax:\n"
|
||||||
" cppcheck [--all] [--style] [--recursive] [filename1] [filename2]\n"
|
" cppcheck [--all] [--style] [--errorsonly] [--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"
|
||||||
|
@ -112,6 +117,7 @@ int main(int argc, char* argv[])
|
||||||
" 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"
|
||||||
|
" --errorsonly Only print something when there is an error\n"
|
||||||
" --recursive Recursively check all *.cpp, *.cc and *.c files\n";
|
" --recursive Recursively check all *.cpp, *.cc and *.c files\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -123,6 +129,8 @@ int main(int argc, char* argv[])
|
||||||
errout.str("");
|
errout.str("");
|
||||||
std::string fname = filenames[c];
|
std::string fname = filenames[c];
|
||||||
|
|
||||||
|
// If only errors are printed, print filename after the check
|
||||||
|
if (!ErrorsOnly)
|
||||||
std::cout << "Checking " << fname << "...\n";
|
std::cout << "Checking " << fname << "...\n";
|
||||||
|
|
||||||
std::ifstream fin( fname.c_str() );
|
std::ifstream fin( fname.c_str() );
|
||||||
|
@ -132,11 +140,22 @@ int main(int argc, char* argv[])
|
||||||
for ( std::map<std::string,std::string>::const_iterator it = code.begin(); it != code.end(); ++it )
|
for ( std::map<std::string,std::string>::const_iterator it = code.begin(); it != code.end(); ++it )
|
||||||
CppCheck(it->second, filenames[c].c_str(), c);
|
CppCheck(it->second, filenames[c].c_str(), c);
|
||||||
|
|
||||||
|
if (ErrorsOnly)
|
||||||
|
{
|
||||||
|
if ( !errout.str().empty() )
|
||||||
|
{
|
||||||
|
std::cout << "Errors found in " << fname << ":\n";
|
||||||
|
std::cerr << errout.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if ( errout.str().empty() )
|
if ( errout.str().empty() )
|
||||||
std::cout << "No errors found\n";
|
std::cout << "No errors found\n";
|
||||||
else
|
else
|
||||||
std::cerr << errout.str();
|
std::cerr << errout.str();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This generates false positives - especially for libraries
|
// This generates false positives - especially for libraries
|
||||||
if ( ShowAll && CheckCodingStyle && filenames.size() > 1 )
|
if ( ShowAll && CheckCodingStyle && filenames.size() > 1 )
|
||||||
|
|
Loading…
Reference in New Issue