Reduce: Added --cfg command
This commit is contained in:
parent
42dd956dff
commit
0a88a136ca
|
@ -33,7 +33,7 @@ private:
|
||||||
std::time_t stopTime;
|
std::time_t stopTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppcheckExecutor(std::size_t linenr, bool hang)
|
CppcheckExecutor(const char *defines, std::size_t linenr, bool hang)
|
||||||
: ErrorLogger()
|
: ErrorLogger()
|
||||||
, cppcheck(*this,false)
|
, cppcheck(*this,false)
|
||||||
, foundLine(false)
|
, foundLine(false)
|
||||||
|
@ -42,6 +42,8 @@ public:
|
||||||
if (!hang)
|
if (!hang)
|
||||||
pattern = ":" + MathLib::longToString(linenr) + "]";
|
pattern = ":" + MathLib::longToString(linenr) + "]";
|
||||||
|
|
||||||
|
if (defines)
|
||||||
|
cppcheck.settings().userDefines = defines;
|
||||||
cppcheck.settings().addEnabled("all");
|
cppcheck.settings().addEnabled("all");
|
||||||
cppcheck.settings().inconclusive = true;
|
cppcheck.settings().inconclusive = true;
|
||||||
cppcheck.settings()._force = true;
|
cppcheck.settings()._force = true;
|
||||||
|
@ -78,6 +80,7 @@ struct ReduceSettings {
|
||||||
std::size_t linenr;
|
std::size_t linenr;
|
||||||
bool hang;
|
bool hang;
|
||||||
unsigned int maxtime;
|
unsigned int maxtime;
|
||||||
|
const char *defines;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool test(const ReduceSettings &settings, const std::vector<std::string> &filedata, const std::size_t line1, const std::size_t line2)
|
static bool test(const ReduceSettings &settings, const std::vector<std::string> &filedata, const std::size_t line1, const std::size_t line2)
|
||||||
|
@ -94,7 +97,7 @@ static bool test(const ReduceSettings &settings, const std::vector<std::string>
|
||||||
fout << ((i>=line1 && i<=line2) ? "" : filedata[i]) << std::endl;
|
fout << ((i>=line1 && i<=line2) ? "" : filedata[i]) << std::endl;
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
CppcheckExecutor cppcheck(settings.linenr, settings.hang);
|
CppcheckExecutor cppcheck(settings.defines, settings.linenr, settings.hang);
|
||||||
return cppcheck.run(tempfilename.c_str(), settings.maxtime);
|
return cppcheck.run(tempfilename.c_str(), settings.maxtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,6 +587,8 @@ int main(int argc, char *argv[])
|
||||||
settings.hang = true;
|
settings.hang = true;
|
||||||
} 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)
|
||||||
|
settings.defines = argv[i] + 6;
|
||||||
else if (settings.filename==NULL && strchr(argv[i],'.'))
|
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]))
|
||||||
|
@ -596,7 +601,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] [--hang] filename [linenr]" << std::endl;
|
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] filename [linenr]" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,7 +609,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Execute Cppcheck on the file..
|
// Execute Cppcheck on the file..
|
||||||
{
|
{
|
||||||
CppcheckExecutor cppcheck(settings.linenr, settings.hang);
|
CppcheckExecutor cppcheck(settings.defines, settings.linenr, settings.hang);
|
||||||
if (!cppcheck.run(settings.filename, settings.maxtime)) {
|
if (!cppcheck.run(settings.filename, settings.maxtime)) {
|
||||||
std::cerr << "Can't reproduce false positive at line " << settings.linenr << std::endl;
|
std::cerr << "Can't reproduce false positive at line " << settings.linenr << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
Loading…
Reference in New Issue