From 4fa5538e2bed36903b403e1aaee2462d22b456dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 21 Jan 2015 22:13:44 +0100 Subject: config/Param: split block-specific attributes to new struct ConfigBlock The old struct config_param remains only for top-level string options. --- src/config/ConfigGlobal.cxx | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/config/ConfigGlobal.cxx') diff --git a/src/config/ConfigGlobal.cxx b/src/config/ConfigGlobal.cxx index 5c04ea93e..192baffec 100644 --- a/src/config/ConfigGlobal.cxx +++ b/src/config/ConfigGlobal.cxx @@ -22,6 +22,7 @@ #include "ConfigParser.hxx" #include "Data.hxx" #include "Param.hxx" +#include "Block.hxx" #include "ConfigFile.hxx" #include "ConfigPath.hxx" #include "ConfigError.hxx" @@ -51,15 +52,15 @@ ReadConfigFile(Path path, Error &error) } static void -Check(const config_param *param) +Check(const ConfigBlock &block) { - if (!param->used) - /* this whole config_param was not queried at all - + if (!block.used) + /* this whole block was not queried at all - the feature might be disabled at compile time? Silently ignore it here. */ return; - for (const auto &i : param->block_params) { + for (const auto &i : block.block_params) { if (!i.used) FormatWarning(config_domain, "option '%s' on line %i was not recognized", @@ -69,9 +70,9 @@ Check(const config_param *param) void config_global_check(void) { - for (auto i : config_data.params) - for (const config_param *p = i; p != nullptr; p = p->next) - Check(p); + for (auto i : config_data.blocks) + for (const auto *p = i; p != nullptr; p = p->next) + Check(*p); } const config_param * @@ -83,18 +84,27 @@ config_get_param(ConfigOption option) return param; } -const config_param * -config_find_block(ConfigOption option, const char *key, const char *value) +const ConfigBlock * +config_get_block(ConfigBlockOption option) +{ + ConfigBlock *block = config_data.blocks[unsigned(option)]; + if (block != nullptr) + block->used = true; + return block; +} + +const ConfigBlock * +config_find_block(ConfigBlockOption option, const char *key, const char *value) { - for (const config_param *param = config_get_param(option); - param != nullptr; param = param->next) { - const char *value2 = param->GetBlockValue(key); + for (const auto *block = config_get_block(option); + block != nullptr; block = block->next) { + const char *value2 = block->GetBlockValue(key); if (value2 == nullptr) FormatFatalError("block without '%s' name in line %d", - key, param->line); + key, block->line); if (strcmp(value2, value) == 0) - return param; + return block; } return nullptr; -- cgit v1.2.3