| 82 | Settings & Settings::operator=(Settings &&) CPPCHECK_NOEXCEPT = default; |
| 83 | |
| 84 | std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions, bool debug) |
| 85 | { |
| 86 | static const std::string cfgFilename = "cppcheck.cfg"; |
| 87 | std::string fileName; |
| 88 | #ifdef FILESDIR |
| 89 | { |
| 90 | const std::string filesdirCfg = Path::join(FILESDIR, cfgFilename); |
| 91 | if (debug) |
| 92 | std::cout << "looking for '" << filesdirCfg << "'" << std::endl; |
| 93 | if (Path::isFile(filesdirCfg)) |
| 94 | fileName = filesdirCfg; |
| 95 | } |
| 96 | #endif |
| 97 | // cppcheck-suppress knownConditionTrueFalse |
| 98 | if (fileName.empty()) { |
| 99 | // TODO: make sure that exename is set |
| 100 | fileName = Path::join(Path::getPathFromFilename(settings.exename), cfgFilename); |
| 101 | if (debug) |
| 102 | std::cout << "looking for '" << fileName << "'" << std::endl; |
| 103 | if (!Path::isFile(fileName)) |
| 104 | { |
| 105 | if (debug) |
| 106 | std::cout << "no configuration found" << std::endl; |
| 107 | return ""; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | std::ifstream fin(fileName); |
| 112 | if (!fin.is_open()) |
| 113 | return "could not open file"; |
| 114 | picojson::value json; |
| 115 | fin >> json; |
| 116 | { |
| 117 | const std::string& lastErr = picojson::get_last_error(); |
| 118 | if (!lastErr.empty()) |
| 119 | return "not a valid JSON - " + lastErr; |
| 120 | } |
| 121 | const picojson::object& obj = json.get<picojson::object>(); |
| 122 | { |
| 123 | const auto it = obj.find("productName"); |
| 124 | if (it != obj.cend()) { |
| 125 | const auto& v = it->second; |
| 126 | if (!v.is<std::string>()) |
| 127 | return "'productName' is not a string"; |
| 128 | settings.cppcheckCfgProductName = v.get<std::string>(); |
| 129 | } |
| 130 | } |
| 131 | { |
| 132 | const auto it = obj.find("manualUrl"); |
| 133 | if (it != obj.cend()) { |
| 134 | const auto& v = it->second; |
| 135 | if (!v.is<std::string>()) |
| 136 | return "'manualUrl' is not a string"; |
| 137 | settings.manualUrl = v.get<std::string>(); |
| 138 | } |
| 139 | } |
| 140 | { |
| 141 | const auto it = obj.find("about"); |
nothing calls this directly
no test coverage detected