bool Config::ReadConfig(std::istream &in, const char *path) { string line, errstr=""; std::tuple<string, function<bool(string&)>> rules[] = { std::make_tuple("database", cfg_path(database_)), std::make_tuple("verbosity", cfg_numeric(verbosity_)), std::make_tuple("quiet", cfg_bool(quiet_)), std::make_tuple("package_depends", cfg_bool(package_depends_)), std::make_tuple("json", cfg_json(json_,errstr)), std::make_tuple("jobs", cfg_numeric(max_jobs_)), std::make_tuple("file_lists", cfg_bool(package_filelist_)), }; size_t lineno = 0; while (std::getline(in, line)) { ++lineno; size_t start = line.find_first_not_of(" \t\n\r"); // no content if (start == string::npos) continue; // comment lines if (line[start] == '#' || line[start] == '/' || line[start] == ';') continue; errstr = ""; for (auto &r : rules) { string &name(std::get<0>(r)); auto fn = std::get<1>(r); if (line.compare(start, name.length(), name) == 0) { size_t eq = line.find_first_not_of(" \t\n\r", start+name.length()); if (eq == string::npos) { Log(Warn, "%s:%lu: invalid config entry\n", path, (unsigned long)lineno); break; } if (line[eq] != '=') { Log(Warn, "%s:%lu: missing `=` in config entry\n", path, (unsigned long)lineno); break; } start = line.find_first_not_of(" \t\n\r", eq+1); line = move(line.substr(start)); if (!fn(line)) { if (!errstr.empty()) Log(Error, "%s:%lu: %s\n", path, (unsigned long)lineno, errstr.c_str()); return false; } break; } } } return true; }
const char * PrintPathTest::path(const char * p, const char * r) { EXPECT_TRUE(m_root) << "root not set!"; cfg_t input = cfg_find_cfg(m_root, p); EXPECT_TRUE(input) << "input path " << p << " not exist"; cfg_t to = 0; if (r) { to = cfg_find_cfg(m_root, r); EXPECT_TRUE(input) << "root path " << r << " not exist"; } struct mem_buffer buffer; mem_buffer_init(&buffer, t_tmp_allocrator()); return cfg_path(&buffer, input, to); }