config/Param: split block-specific attributes to new struct ConfigBlock

The old struct config_param remains only for top-level string options.
This commit is contained in:
Max Kellermann
2015-01-21 22:13:44 +01:00
parent 84e74173de
commit 4fa5538e2b
114 changed files with 871 additions and 732 deletions

View File

@@ -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)
{
for (const config_param *param = config_get_param(option);
param != nullptr; param = param->next) {
const char *value2 = param->GetBlockValue(key);
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 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;