reduce: add -D

This commit is contained in:
Robert Reif 2013-08-18 07:24:30 +02:00 committed by Daniel Marjamäki
parent 99cb04306d
commit 865ff82425
1 changed files with 17 additions and 9 deletions

View File

@ -34,7 +34,7 @@ private:
std::time_t stopTime; std::time_t stopTime;
public: public:
CppcheckExecutor(const char *defines, const char * const includePaths[100], std::size_t linenr, bool hang) CppcheckExecutor(const std::string &defines, const char * const includePaths[100], std::size_t linenr, bool hang)
: ErrorLogger() : ErrorLogger()
, cppcheck(*this,false) , cppcheck(*this,false)
, foundLine(false) , foundLine(false)
@ -43,8 +43,7 @@ public:
if (!hang) if (!hang)
pattern = ":" + MathLib::longToString(linenr) + "]"; pattern = ":" + MathLib::longToString(linenr) + "]";
if (defines) cppcheck.settings().userDefines = defines;
cppcheck.settings().userDefines = defines;
for (int i = 0; includePaths[i]; i++) { for (int i = 0; includePaths[i]; i++) {
std::string path = Path::fromNativeSeparators(includePaths[i]); std::string path = Path::fromNativeSeparators(includePaths[i]);
@ -93,7 +92,7 @@ struct ReduceSettings {
std::size_t linenr; std::size_t linenr;
bool hang; bool hang;
unsigned int maxtime; unsigned int maxtime;
const char *defines; std::string defines;
const char *includePaths[100]; const char *includePaths[100];
}; };
@ -599,13 +598,22 @@ int main(int argc, char *argv[])
print = true; print = true;
else if (strcmp(argv[i], "--hang") == 0) else if (strcmp(argv[i], "--hang") == 0)
settings.hang = true; settings.hang = true;
else if ((strcmp(argv[i],"-I")==0) && (i+1<argc)) else if (strncmp(argv[i],"-D", 2) == 0) {
if (!settings.defines.empty())
settings.defines += " ";
if ((strcmp(argv[i], "-D") == 0) && (i+1<argc))
settings.defines += argv[++i];
else
settings.defines += argv[i] + 2;
} else if ((strcmp(argv[i],"-I")==0) && (i+1<argc))
settings.includePaths[includePathIndex++] = argv[++i]; settings.includePaths[includePathIndex++] = argv[++i];
else if (strncmp(argv[i], "--maxtime=", 10) == 0) else if (strncmp(argv[i], "--maxtime=", 10) == 0)
settings.maxtime = std::atoi(argv[i] + 10); settings.maxtime = std::atoi(argv[i] + 10);
else if (strncmp(argv[i],"--cfg=",6)==0) else if (strncmp(argv[i],"--cfg=",6)==0) {
settings.defines = argv[i] + 6; if (!settings.defines.empty())
else if (settings.filename==NULL && strchr(argv[i],'.')) settings.defines += " ";
settings.defines += argv[i] + 6;
} else if (settings.filename==NULL && strchr(argv[i],'.'))
settings.filename = argv[i]; settings.filename = argv[i];
else if (settings.linenr == 0U && MathLib::isInt(argv[i])) else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
settings.linenr = std::atoi(argv[i]); settings.linenr = std::atoi(argv[i]);
@ -617,7 +625,7 @@ int main(int argc, char *argv[])
if ((!settings.hang && settings.linenr == 0U) || settings.filename == NULL) { if ((!settings.hang && settings.linenr == 0U) || settings.filename == NULL) {
std::cerr << "Syntax:" << std::endl std::cerr << "Syntax:" << std::endl
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-I includepath] filename [linenr]" << std::endl; << argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] filename [linenr]" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }