diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index d28d0ada5..82bf6e166 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -482,8 +482,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // --library else if (std::strncmp(argv[i], "--library=", 10) == 0) { - if (!_settings->library.load(argv[i]+10)) { - PrintMessage("cppcheck: Failed to load library file '" + std::string(argv[i]+10) + "'"); + if (!_settings->library.load(argv[0], argv[i]+10)) { + PrintMessage("cppcheck: Failed to load library configuration file '" + std::string(argv[i]+10) + "'"); return false; } } diff --git a/lib/library.cpp b/lib/library.cpp index 97f24811e..6ad6deddc 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -48,12 +48,39 @@ Library::Library(const Library &lib) : Library::~Library() { } -bool Library::load(const char path[]) +bool Library::load(const char exename[], const char path[]) { tinyxml2::XMLDocument doc; - const tinyxml2::XMLError error = doc.LoadFile(path); - if (error != tinyxml2::XML_NO_ERROR) + if (std::strchr(path,',') != NULL) { + 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; const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); diff --git a/lib/library.h b/lib/library.h index 300a71d83..03556e253 100644 --- a/lib/library.h +++ b/lib/library.h @@ -36,7 +36,7 @@ public: Library(const Library &); ~Library(); - bool load(const char path[]); + bool load(const char exename[], const char path[]); /** get allocation id for function (by name) */ int alloc(const std::string &name) const {