diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index ac24f3a88..e3c5b3f80 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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= Specifies platform specific types and sizes. The\n" - " available platforms are:\n" + " --platform=, --platform=\n" + " Specifies platform specific types and sizes. The\n" + " available builtin platforms are:\n" " * unix32\n" " 32 bit unix variant\n" " * unix64\n" diff --git a/lib/settings.cpp b/lib/settings.cpp index db56c008b..ef358b579 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -19,6 +19,7 @@ #include "settings.h" #include "preprocessor.h" // Preprocessor #include "utils.h" +#include "tinyxml2.h" #include #include @@ -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; }