Add config_file_dump to avoid calling on SSNES stuff from config file.

This commit is contained in:
Themaister 2011-01-09 15:50:30 +01:00
parent 413a261f44
commit 9a4158aac8
3 changed files with 20 additions and 26 deletions

View File

@ -22,10 +22,6 @@
#include <stdio.h>
#include <ctype.h>
#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;
}

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
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

View File

@ -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;