diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/comet.c | 10 | ||||
| -rw-r--r-- | src/config.c | 40 | ||||
| -rw-r--r-- | src/config.h | 2 |
3 files changed, 37 insertions, 15 deletions
diff --git a/src/comet.c b/src/comet.c index 1b26bfb..be07826 100644 --- a/src/comet.c +++ b/src/comet.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) any_log_level_t log_level = ANY_LOG_DEBUG; if (argc != 1 && !strcmp(argv[1], "--trace")) - log_level = ANY_LOG_TRACE; + log_level = ANY_LOG_TRACE; any_log_init(stdout, log_level); @@ -81,11 +81,17 @@ int main(int argc, char **argv) log_info("Reading config '%s'", config_path); int errors = config_read(&config, config_file); if (errors > 0) { - log_error("Config file contained %d errors", errors); + log_error("Config file contained %d syntax errors", errors); return EXIT_FAILURE; } } + int errors = config_validate(&config); + if (errors > 0) { + log_error("Config file contained %d errors", errors); + return EXIT_FAILURE; + } + signal(SIGINT, signal_quit); signal(SIGTERM, signal_quit); 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); diff --git a/src/config.h b/src/config.h index 7212717..297a285 100644 --- a/src/config.h +++ b/src/config.h @@ -48,6 +48,8 @@ void config_init(config_t *config); int config_read(config_t *config, FILE *file); +int config_validate(config_t *config); + bool config_resolve_children(config_t *config, block_t *block); int config_resolve(config_t *config, block_t **block); |
