diff --git a/conf/config_file.c b/conf/config_file.c index eccbdddfa2..41e07187fe 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -22,10 +22,6 @@ #include #include -#ifndef STANDALONE -#include "general.h" -#endif - struct entry_list { char *key; @@ -130,20 +126,6 @@ static bool parse_line(struct entry_list *list, char *line) return true; } -static void print_config(config_file_t *conf) -{ - struct entry_list *tmp = conf->entries; - while (tmp != NULL) - { -#ifdef STANDALONE - fprintf(stderr, "Config => Key: \"%s\", Value: \"%s\"\n", tmp->key, tmp->value); -#else - SSNES_LOG("Config => Key: \"%s\", Value: \"%s\"\n", tmp->key, tmp->value); -#endif - tmp = tmp->next; - } -} - config_file_t *config_file_new(const char *path) { @@ -188,8 +170,6 @@ config_file_t *config_file_new(const char *path) } fclose(file); - print_config(conf); - return conf; } @@ -368,6 +348,16 @@ bool config_file_write(config_file_t *conf, const char *path) else file = stdout; + config_file_dump(conf, file); + + if (path) + fclose(file); + + return true; +} + +void config_file_dump(config_file_t *conf, FILE *file) +{ struct entry_list *list = conf->entries; while (list != NULL) @@ -375,9 +365,4 @@ bool config_file_write(config_file_t *conf, const char *path) fprintf(file, "%s = \"%s\"\n", list->key, list->value); list = list->next; } - - if (path) - fclose(file); - - return true; } diff --git a/conf/config_file.h b/conf/config_file.h index a893fdac18..1f19d6d177 100644 --- a/conf/config_file.h +++ b/conf/config_file.h @@ -21,6 +21,7 @@ #include #include +#include typedef struct config_file config_file_t; @@ -48,14 +49,19 @@ bool config_get_string(config_file_t *conf, const char *entry, char **in); // Extracts a boolean from config. Valid boolean true are "true" and "1". Valid false are "false" and "0". Other values will be treated as an error. bool config_get_bool(config_file_t *conf, const char *entry, bool *in); -// Setters. +// Setters. Similiar to the getters. void config_set_double(config_file_t *conf, const char *entry, double value); void config_set_int(config_file_t *conf, const char *entry, int val); void config_set_char(config_file_t *conf, const char *entry, char val); void config_set_string(config_file_t *conf, const char *entry, const char *val); void config_set_bool(config_file_t *conf, const char *entry, bool val); + +// Write the current config to a file. bool config_file_write(config_file_t *conf, const char *path); +// Dump the current config to an already opened file. Does not close the file. +void config_file_dump(config_file_t *conf, FILE *file); + #endif diff --git a/settings.c b/settings.c index 219b77119d..8a5c453103 100644 --- a/settings.c +++ b/settings.c @@ -160,6 +160,9 @@ void parse_config(void) if (conf == NULL) return; + if (g_extern.verbose) + config_file_dump(conf, stderr); + int tmp_int; double tmp_double; bool tmp_bool;