Skip to content

Commit ec733e7

Browse files
committed
CLI: added --platform=<file> interface
1 parent a014920 commit ec733e7

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
683683
_settings->platform(Settings::Unix64);
684684
else if (platform == "native")
685685
_settings->platform(Settings::Unspecified);
686-
else {
686+
else if (!_settings->platformFile(platform)) {
687687
std::string message("cppcheck: error: unrecognized platform: \"");
688688
message += platform;
689689
message += "\".";
@@ -898,8 +898,9 @@ void CmdLineParser::PrintHelp()
898898
" before skipping it. Default is '12'. If used together\n"
899899
" with '--force', the last option is the one that is\n"
900900
" effective.\n"
901-
" --platform=<type> Specifies platform specific types and sizes. The\n"
902-
" available platforms are:\n"
901+
" --platform=<type>, --platform=<file>\n"
902+
" Specifies platform specific types and sizes. The\n"
903+
" available builtin platforms are:\n"
903904
" * unix32\n"
904905
" 32 bit unix variant\n"
905906
" * unix64\n"

lib/settings.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "settings.h"
2020
#include "preprocessor.h" // Preprocessor
2121
#include "utils.h"
22+
#include "tinyxml2.h"
2223

2324
#include <fstream>
2425
#include <set>
@@ -272,8 +273,40 @@ bool Settings::platform(PlatformType type)
272273

273274
bool Settings::platformFile(const std::string &filename)
274275
{
275-
(void)filename;
276-
/** @todo TBD */
276+
// open file..
277+
tinyxml2::XMLDocument doc;
278+
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_NO_ERROR)
279+
return false;
277280

278-
return false;
281+
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
282+
283+
if (!rootnode || std::strcmp(rootnode->Name(),"platform") != 0)
284+
return false;
285+
286+
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
287+
if (std::strcmp(node->Name(), "defaultSign") == 0)
288+
defaultSign = *node->GetText();
289+
else if (std::strcmp(node->Name(), "char_bit") == 0)
290+
char_bit = std::atoi(node->GetText());
291+
else if (std::strcmp(node->Name(), "sizeof") == 0) {
292+
for (const tinyxml2::XMLElement *sz = node->FirstChildElement(); sz; sz = sz->NextSiblingElement()) {
293+
if (std::strcmp(node->Name(), "short") == 0)
294+
sizeof_short = std::atoi(node->GetText());
295+
if (std::strcmp(node->Name(), "int") == 0)
296+
sizeof_int = std::atoi(node->GetText());
297+
if (std::strcmp(node->Name(), "long") == 0)
298+
sizeof_long = std::atoi(node->GetText());
299+
if (std::strcmp(node->Name(), "long-long") == 0)
300+
sizeof_long_long = std::atoi(node->GetText());
301+
if (std::strcmp(node->Name(), "float") == 0)
302+
sizeof_float = std::atoi(node->GetText());
303+
if (std::strcmp(node->Name(), "double") == 0)
304+
sizeof_double = std::atoi(node->GetText());
305+
if (std::strcmp(node->Name(), "pointer") == 0)
306+
sizeof_pointer = std::atoi(node->GetText());
307+
}
308+
}
309+
}
310+
311+
return true;
279312
}

0 commit comments

Comments
 (0)