cppcheck: output errorlist to stdout

This commit is contained in:
Daniel Marjamäki 2011-01-16 17:18:09 +01:00
parent 61aa86f201
commit 657c22d23b
3 changed files with 14 additions and 4 deletions

View File

@ -29,6 +29,7 @@
CppCheckExecutor::CppCheckExecutor() CppCheckExecutor::CppCheckExecutor()
{ {
time1 = 0; time1 = 0;
errorlist = false;
} }
CppCheckExecutor::~CppCheckExecutor() CppCheckExecutor::~CppCheckExecutor()
@ -52,7 +53,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
if (parser.GetShowErrorMessages()) if (parser.GetShowErrorMessages())
{ {
errorlist = true;
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
cppcheck->getErrorMessages(); cppcheck->getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
std::exit(0); std::exit(0);
} }
} }
@ -199,7 +203,11 @@ void CppCheckExecutor::reportStatus(unsigned int index, unsigned int max)
void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg) void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
{ {
if (_settings._xml) if (errorlist)
{
reportOut(msg.toXML(false, _settings._xml_version));
}
else if (_settings._xml)
{ {
reportErr(msg.toXML(_settings._verbose, _settings._xml_version)); reportErr(msg.toXML(_settings._verbose, _settings._xml_version));
} }

View File

@ -102,6 +102,11 @@ private:
* Report progress time * Report progress time
*/ */
std::time_t time1; std::time_t time1;
/**
* Has --errorlist been given?
*/
bool errorlist;
}; };
#endif // CPPCHECKEXECUTOR_H #endif // CPPCHECKEXECUTOR_H

View File

@ -440,7 +440,6 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
void CppCheck::getErrorMessages() void CppCheck::getErrorMessages()
{ {
// call all "getErrorMessages" in all registered Check classes // call all "getErrorMessages" in all registered Check classes
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
(*it)->getErrorMessages(this, &_settings); (*it)->getErrorMessages(this, &_settings);
@ -448,6 +447,4 @@ void CppCheck::getErrorMessages()
tokenizer.getErrorMessages(this, &_settings); tokenizer.getErrorMessages(this, &_settings);
Preprocessor::getErrorMessages(this, &_settings); Preprocessor::getErrorMessages(this, &_settings);
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
} }