Cleanup config_file.c

This commit is contained in:
twinaphex 2015-11-15 22:28:57 +01:00
parent 0bd03a5fa5
commit 149d892910
3 changed files with 53 additions and 34 deletions

View File

@ -230,10 +230,18 @@ static bool input_autoconfigure_joypad_from_conf_dir(
if(index >= 0 && current_best > 0)
{
conf = config_file_new(list->elems[index].data);
RARCH_LOG("Autodetect: selected configuration: %s\n", conf->path);
input_autoconfigure_joypad_add(conf, params);
config_file_free(conf);
ret = 1;
if (conf)
{
char conf_path[PATH_MAX_LENGTH];
config_get_config_path(conf, conf_path, sizeof(conf_path));
RARCH_LOG("Autodetect: selected configuration: %s\n", conf_path);
input_autoconfigure_joypad_add(conf, params);
config_file_free(conf);
ret = 1;
}
}
else
ret = 0;

View File

@ -47,6 +47,34 @@
#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;
uint32_t key_hash;
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;
};
static config_file_t *config_file_new_internal(const char *path, unsigned depth);
void config_file_free(config_file_t *conf);
@ -662,6 +690,14 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
return entry != NULL;
}
bool config_get_config_path(config_file_t *conf, char *s, size_t len)
{
if (!conf)
return false;
return strlcpy(s, conf->path, len);
}
bool config_get_array(config_file_t *conf, const char *key,
char *buf, size_t size)
{

View File

@ -34,34 +34,6 @@ extern "C" {
#include <boolean.h>
struct config_entry_list
{
/* If we got this from an #include,
* do not allow overwrite. */
bool readonly;
char *key;
char *value;
uint32_t key_hash;
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
@ -132,11 +104,14 @@ bool config_get_char(config_file_t *conf, const char *entry, char *in);
bool config_get_string(config_file_t *conf, const char *entry, char **in);
/* Extracts a string to a preallocated buffer. Avoid memory allocation. */
bool config_get_array(config_file_t *conf, const char *entry, char *in, size_t size);
bool config_get_array(config_file_t *conf, const char *entry, char *s, size_t len);
/* Extracts a string to a preallocated buffer. Avoid memory allocation.
* Recognized magic like ~/. Similar to config_get_array() otherwise. */
bool config_get_path(config_file_t *conf, const char *entry, char *in, size_t size);
bool config_get_path(config_file_t *conf, const char *entry, char *s, size_t len);
/* Extracts a string to a preallocated buffer. Avoid memory allocation. */
bool config_get_config_path(config_file_t *conf, char *s, size_t len);
/* Extracts a boolean from config.
* Valid boolean true are "true" and "1". Valid false are "false" and "0".