From 12cdd6eeb3206a2d7d63d943f82a2e900adefd88 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Tue, 3 Dec 2024 14:26:36 +0100 Subject: Implement config constraints --- src/config.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 43b7928..6b8fc58 100644 --- a/src/config.c +++ b/src/config.c @@ -762,31 +762,29 @@ skip_pair: int config_validate(config_t *config) { - int errors = 0; + int n_errors = 0; block_group_t *bar = (block_group_t *)config->blocks[0]; if (bar->children == NULL) { log_error("Section '%s' requires at least one child", "bar"); - errors++; + n_errors++; } // Validate the config itself if (config->scale < 1 && config->scale != 0) { log_error("Bar '%s' should be at least 1", "scale"); - errors++; + n_errors++; } // Validate blocks for (size_t i = 0; i < config->n_blocks; i++) { block_t *block = config->blocks[i]; - const block_scheme_t *scheme = block->scheme; - if (scheme->validate_fn == NULL) continue; log_debug("Validating 'block.%s'", block->label); + int errors = block_validate(block, config); - int tmp = scheme->validate_fn(block, config); - errors += tmp; - block->validated = tmp == 0; + block->validated = errors == 0; + n_errors += errors; } // Validate actions @@ -794,10 +792,10 @@ int config_validate(config_t *config) for (size_t i = 0; i < config->n_actions; i++) { action_t *action = &config->actions[i]; log_debug("Validating 'action.%s'", action->label); - errors += action_validate(action, config); + n_errors += action_validate(action, config); } - return errors; + return n_errors; } bool config_resolve_action(config_t *config, const char *label, action_t **action) -- cgit v1.2.3