diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-23 23:44:09 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-23 23:44:09 +0100 |
| commit | 9ff1b4a86bd44d4dfe984de41a85062c2b014655 (patch) | |
| tree | 679e02b6d7f87290c8c81d3709e698be9c0d09f2 /src/config.c | |
| parent | 828c4af8886b970fba9edcbaa5c6a97916ad4aa8 (diff) | |
Separate config validation
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/config.c b/src/config.c index a85fee7..5855109 100644 --- a/src/config.c +++ b/src/config.c @@ -228,7 +228,7 @@ static bool config_read_gradient(const char *value, gradient_t *result) static bool config_read_enum(const char *value, config_enum_t *data, int *result) { - for (int i = 0; data[i].label != NULL; i++) { + for (size_t i = 0; data[i].label != NULL; i++) { if (!strcmp(value, data[i].label)) { *result = data[i].value; return true; @@ -304,7 +304,7 @@ static config_status_t config_read_entry(const config_entry_t *entries, void *re "list", }; - for (int i = 0; entries[i].key != NULL; i++) { + for (size_t i = 0; entries[i].key != NULL; i++) { if (!strcmp(key, entries[i].key)) { if (type != NULL) *type = types[entries[i].type]; @@ -501,7 +501,7 @@ int config_read(config_t *config, FILE *file) goto skip_pair; } - for (int i = 0; block_schemes[i] != NULL; i++) { + for (size_t i = 0; block_schemes[i] != NULL; i++) { if (strcmp(block_schemes[i]->name, value)) continue; @@ -581,15 +581,6 @@ skip_pair: free(value); } - if (block != NULL && scheme != NULL && scheme->validate_fn != NULL) { - if (errors != 0) - log_trace("Skipped validation for block '%s'", section); - else { - errors = scheme->validate_fn(block, scheme); - block->validated = errors == 0; - } - } - free(section); n_errors += errors; } while ((section = any_ini_stream_next_section(&ini)) != NULL); @@ -597,6 +588,29 @@ skip_pair: return n_errors; } +int config_validate(config_t *config) +{ + int errors = 0; + + // Validate the config itself + // ... + + // 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 t = scheme->validate_fn(block, scheme); + errors += t; + block->validated = t == 0; + } + + return errors; +} + bool config_resolve_children(config_t *config, block_t *block) { block->resolved = true; @@ -672,7 +686,7 @@ int config_resolve(config_t *config, block_t **block) void config_free(config_t *config) { - for (int i = 0; i < config->n_blocks; i++) + for (size_t i = 0; i < config->n_blocks; i++) block_free(config->blocks[i]); gradient_free(&config->background); |
