Library: If load from current path fails, try to load 'default' configuration from cppcheck-executable path. Allow that '.cfg' extension is not used. Allow that multiple configurations are provided (comma separated).
This commit is contained in:
parent
1dc8b1706b
commit
1a2aaa6780
|
@ -482,8 +482,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --library
|
// --library
|
||||||
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
||||||
if (!_settings->library.load(argv[i]+10)) {
|
if (!_settings->library.load(argv[0], argv[i]+10)) {
|
||||||
PrintMessage("cppcheck: Failed to load library file '" + std::string(argv[i]+10) + "'");
|
PrintMessage("cppcheck: Failed to load library configuration file '" + std::string(argv[i]+10) + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,12 +48,39 @@ Library::Library(const Library &lib) :
|
||||||
|
|
||||||
Library::~Library() { }
|
Library::~Library() { }
|
||||||
|
|
||||||
bool Library::load(const char path[])
|
bool Library::load(const char exename[], const char path[])
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
|
|
||||||
const tinyxml2::XMLError error = doc.LoadFile(path);
|
if (std::strchr(path,',') != NULL) {
|
||||||
if (error != tinyxml2::XML_NO_ERROR)
|
bool ret = true;
|
||||||
|
std::string p(path);
|
||||||
|
while (p.find(",") != std::string::npos) {
|
||||||
|
const std::string::size_type pos = p.find(",");
|
||||||
|
ret &= load(exename, p.substr(0,pos).c_str());
|
||||||
|
p = p.substr(pos+1);
|
||||||
|
}
|
||||||
|
if (!p.empty())
|
||||||
|
ret &= load(exename, p.c_str());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *fp = fopen(path, "rt");
|
||||||
|
if (fp == NULL) {
|
||||||
|
std::string fullpath(exename);
|
||||||
|
if (fullpath.find_first_of("/\\") != std::string::npos)
|
||||||
|
fullpath = fullpath.substr(0, 1U + fullpath.find_last_of("/\\"));
|
||||||
|
fullpath += path;
|
||||||
|
fp = fopen(fullpath.c_str(), "rt");
|
||||||
|
if (fp == NULL) {
|
||||||
|
fullpath += ".cfg";
|
||||||
|
fp = fopen(fullpath.c_str(), "rt");
|
||||||
|
if (fp == NULL)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc.LoadFile(fp) != tinyxml2::XML_NO_ERROR)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
|
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
Library(const Library &);
|
Library(const Library &);
|
||||||
~Library();
|
~Library();
|
||||||
|
|
||||||
bool load(const char path[]);
|
bool load(const char exename[], const char path[]);
|
||||||
|
|
||||||
/** get allocation id for function (by name) */
|
/** get allocation id for function (by name) */
|
||||||
int alloc(const std::string &name) const {
|
int alloc(const std::string &name) const {
|
||||||
|
|
Loading…
Reference in New Issue