CLI: added --platform=<file> interface

This commit is contained in:
Daniel Marjamäki 2016-01-07 20:19:08 +01:00
parent a014920280
commit ec733e7e71
2 changed files with 40 additions and 6 deletions

View File

@ -683,7 +683,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->platform(Settings::Unix64);
else if (platform == "native")
_settings->platform(Settings::Unspecified);
else {
else if (!_settings->platformFile(platform)) {
std::string message("cppcheck: error: unrecognized platform: \"");
message += platform;
message += "\".";
@ -898,8 +898,9 @@ void CmdLineParser::PrintHelp()
" before skipping it. Default is '12'. If used together\n"
" with '--force', the last option is the one that is\n"
" effective.\n"
" --platform=<type> Specifies platform specific types and sizes. The\n"
" available platforms are:\n"
" --platform=<type>, --platform=<file>\n"
" Specifies platform specific types and sizes. The\n"
" available builtin platforms are:\n"
" * unix32\n"
" 32 bit unix variant\n"
" * unix64\n"

View File

@ -19,6 +19,7 @@
#include "settings.h"
#include "preprocessor.h" // Preprocessor
#include "utils.h"
#include "tinyxml2.h"
#include <fstream>
#include <set>
@ -272,8 +273,40 @@ bool Settings::platform(PlatformType type)
bool Settings::platformFile(const std::string &filename)
{
(void)filename;
/** @todo TBD */
// open file..
tinyxml2::XMLDocument doc;
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_NO_ERROR)
return false;
return false;
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
if (!rootnode || std::strcmp(rootnode->Name(),"platform") != 0)
return false;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (std::strcmp(node->Name(), "defaultSign") == 0)
defaultSign = *node->GetText();
else if (std::strcmp(node->Name(), "char_bit") == 0)
char_bit = std::atoi(node->GetText());
else if (std::strcmp(node->Name(), "sizeof") == 0) {
for (const tinyxml2::XMLElement *sz = node->FirstChildElement(); sz; sz = sz->NextSiblingElement()) {
if (std::strcmp(node->Name(), "short") == 0)
sizeof_short = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "int") == 0)
sizeof_int = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "long") == 0)
sizeof_long = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "long-long") == 0)
sizeof_long_long = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "float") == 0)
sizeof_float = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "double") == 0)
sizeof_double = std::atoi(node->GetText());
if (std::strcmp(node->Name(), "pointer") == 0)
sizeof_pointer = std::atoi(node->GetText());
}
}
}
return true;
}