From d72f3a1d85405e7309ee06c7f91048718ce398cd Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 12 May 2020 13:12:13 +0200 Subject: [PATCH] Can now print default config --- inc/lektor/config.h | 4 ++++ src/config.c | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/inc/lektor/config.h b/inc/lektor/config.h index 46f25380..afba36ba 100644 --- a/inc/lektor/config.h +++ b/inc/lektor/config.h @@ -3,6 +3,7 @@ #include <common/common.h> #include <stddef.h> #include <sqlite3.h> +#include <stdio.h> /* Forward definition of the lkt_state structure */ struct lkt_state; @@ -34,3 +35,6 @@ int config_new(volatile sqlite3 *db, const char *conf); type is done, it is up to the user to check if the structure passed as a `void*` is the right structure. */ int load_module_by_name(struct lkt_state *srv, const char *name, void *mod); + +/* Prints the default config file. */ +void config_default(FILE *output); diff --git a/src/config.c b/src/config.c index 9bc21ea8..7fd1c905 100644 --- a/src/config.c +++ b/src/config.c @@ -248,16 +248,27 @@ int config_new(volatile sqlite3 *db, const char *conf) { if (ini_parse(conf, handler, db)) { - LOG_ERROR("Failed to parse file %s", conf); - return 1; + LOG_ERROR_SCT("CONFIG", "Failed to parse file %s", conf); + goto error; } if (validate_conf(db)) { - LOG_ERROR("Configuration file %s is incomplete", conf); - return 1; + LOG_ERROR_SCT("CONFIG", "Configuration file %s is incomplete", conf); + goto error; } return 0; +error: + LOG_ERROR_SCT("CONFIG", "%s", "Errors detected in config, here is a default config:"); + config_default(stdout); + return 1; +} + +void +config_default(FILE *output) +{ + fwrite(lkt_default_config_file, sizeof(char), + strlen(lkt_default_config_file), output); } int -- GitLab