Merge pull request #1469 from rainers/multi_config

Allow different configurations in the ldc2.conf
This commit is contained in:
David Nadlinger 2016-05-23 00:02:34 +01:00
commit f68ebbf1ec
4 changed files with 44 additions and 5 deletions

View file

@ -162,7 +162,7 @@ bool ConfigFile::locate() {
return false;
}
bool ConfigFile::read(const char *explicitConfFile) {
bool ConfigFile::read(const char *explicitConfFile, const char* section) {
// explicitly provided by user in command line?
if (explicitConfFile) {
const std::string clPath = explicitConfFile;
@ -192,14 +192,21 @@ bool ConfigFile::read(const char *explicitConfFile) {
return false;
}
config_setting_t *root = nullptr;
if (section && *section)
root = config_lookup(cfg, section);
// make sure there's a default group
config_setting_t *root = config_lookup(cfg, "default");
if (!root) {
section = "default";
root = config_lookup(cfg, section);
}
if (!root) {
std::cerr << "no default settings in configuration file" << std::endl;
return false;
}
if (!config_setting_is_group(root)) {
std::cerr << "default is not a group" << std::endl;
std::cerr << section << " is not a group" << std::endl;
return false;
}