config_file.c - get rid of general.h dependency

This commit is contained in:
twinaphex 2014-10-22 03:22:08 +02:00
parent cbae1583f3
commit d6890783da
3 changed files with 51 additions and 56 deletions

View File

@ -23,7 +23,6 @@
#include <compat/posix_string.h>
#include <compat/msvc.h>
#include <file/file_path.h>
#include "../general.h"
#if !defined(_WIN32) && !defined(__CELLOS_LV2__) && !defined(_XBOX)
#include <sys/param.h> /* PATH_MAX */
@ -36,31 +35,6 @@
#define MAX_INCLUDE_DEPTH 16
struct config_entry_list
{
/* If we got this from an #include,
* do not allow overwrite. */
bool readonly;
char *key;
char *value;
struct config_entry_list *next;
};
struct include_list
{
char *path;
struct include_list *next;
};
struct config_file
{
char *path;
struct config_entry_list *entries;
struct config_entry_list *tail;
unsigned include_depth;
struct include_list *includes;
};
static config_file_t *config_file_new_internal(const char *path, unsigned depth);
void config_file_free(config_file_t *conf);
@ -184,8 +158,8 @@ static void add_child_list(config_file_t *parent, config_file_t *child)
static void add_include_list(config_file_t *conf, const char *path)
{
struct include_list *head = conf->includes;
struct include_list *node = (struct include_list*)calloc(1, sizeof(*node));
struct config_include_list *head = conf->includes;
struct config_include_list *node = (struct config_include_list*)calloc(1, sizeof(*node));
if (!node)
return;
@ -507,11 +481,11 @@ void config_file_free(config_file_t *conf)
free(hold);
}
struct include_list *inc_tmp = conf->includes;
struct config_include_list *inc_tmp = conf->includes;
while (inc_tmp)
{
free(inc_tmp->path);
struct include_list *hold = inc_tmp;
struct config_include_list *hold = inc_tmp;
inc_tmp = inc_tmp->next;
free(hold);
}
@ -858,7 +832,7 @@ bool config_file_write(config_file_t *conf, const char *path)
void config_file_dump(config_file_t *conf, FILE *file)
{
struct include_list *includes = conf->includes;
struct config_include_list *includes = conf->includes;
while (includes)
{
fprintf(file, "#include \"%s\"\n", includes->path);
@ -874,26 +848,6 @@ void config_file_dump(config_file_t *conf, FILE *file)
}
}
#ifdef RARCH_INTERNAL
void config_file_dump_all(config_file_t *conf)
{
struct include_list *includes = conf->includes;
while (includes)
{
RARCH_LOG("#include \"%s\"\n", includes->path);
includes = includes->next;
}
struct config_entry_list *list = conf->entries;
while (list)
{
RARCH_LOG("%s = \"%s\" %s\n", list->key,
list->value, list->readonly ? "(included)" : "");
list = list->next;
}
}
#endif
bool config_entry_exists(config_file_t *conf, const char *entry)
{
struct config_entry_list *list = conf->entries;

View File

@ -26,6 +26,32 @@ extern "C" {
#include <stdio.h>
#include <stddef.h>
struct config_entry_list
{
/* If we got this from an #include,
* do not allow overwrite. */
bool readonly;
char *key;
char *value;
struct config_entry_list *next;
};
struct config_include_list
{
char *path;
struct config_include_list *next;
};
struct config_file
{
char *path;
struct config_entry_list *entries;
struct config_entry_list *tail;
unsigned include_depth;
struct config_include_list *includes;
};
typedef struct config_file config_file_t;
/* Config file format
@ -126,11 +152,6 @@ bool config_file_write(config_file_t *conf, const char *path);
* Does not close the file. */
void config_file_dump(config_file_t *conf, FILE *file);
#ifdef RARCH_INTERNAL
/* Also dumps inherited values, useful for logging. */
void config_file_dump_all(config_file_t *conf);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -801,6 +801,26 @@ static config_file_t *open_default_config_file(void)
static void config_read_keybinds_conf(config_file_t *conf);
/* Also dumps inherited values, useful for logging. */
static void config_file_dump_all(config_file_t *conf)
{
struct config_include_list *includes = conf->includes;
while (includes)
{
RARCH_LOG("#include \"%s\"\n", includes->path);
includes = includes->next;
}
struct config_entry_list *list = conf->entries;
while (list)
{
RARCH_LOG("%s = \"%s\" %s\n", list->key,
list->value, list->readonly ? "(included)" : "");
list = list->next;
}
}
static bool config_load_file(const char *path, bool set_defaults)
{
unsigned i;