Add config_get_array() for simpler and faster config access.
This commit is contained in:
parent
58758d2818
commit
5993fffb64
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ include config.mk
|
||||||
TARGET = ssnes tools/ssnes-joyconfig
|
TARGET = ssnes tools/ssnes-joyconfig
|
||||||
|
|
||||||
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o
|
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o
|
||||||
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
|
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o strl.o
|
||||||
HEADERS = $(wildcard */*.h) $(wildcard *.h)
|
HEADERS = $(wildcard */*.h) $(wildcard *.h)
|
||||||
|
|
||||||
LIBS = -lm
|
LIBS = -lm
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
TARGET = ssnes.exe
|
TARGET = ssnes.exe
|
||||||
JTARGET = ssnes-joyconfig.exe
|
JTARGET = ssnes-joyconfig.exe
|
||||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o
|
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o
|
||||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
|
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o strl.o
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
TARGET = ssnes.exe
|
TARGET = ssnes.exe
|
||||||
JTARGET = ssnes-joyconfig.exe
|
JTARGET = ssnes-joyconfig.exe
|
||||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o
|
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o
|
||||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
|
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o strl.o
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include "strl.h"
|
||||||
|
|
||||||
struct entry_list
|
struct entry_list
|
||||||
{
|
{
|
||||||
|
@ -247,7 +248,7 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
|
||||||
{
|
{
|
||||||
if (strcmp(key, list->key) == 0)
|
if (strcmp(key, list->key) == 0)
|
||||||
{
|
{
|
||||||
if (strlen(list->value) > 1)
|
if (list->value[0] && list->value[1])
|
||||||
return false;
|
return false;
|
||||||
*in = *list->value;
|
*in = *list->value;
|
||||||
return true;
|
return true;
|
||||||
|
@ -273,6 +274,22 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool config_get_array(config_file_t *conf, const char *key, char *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct entry_list *list = conf->entries;
|
||||||
|
|
||||||
|
while (list != NULL)
|
||||||
|
{
|
||||||
|
if (strcmp(key, list->key) == 0)
|
||||||
|
{
|
||||||
|
strlcpy(buf, list->value, size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
||||||
{
|
{
|
||||||
struct entry_list *list = conf->entries;
|
struct entry_list *list = conf->entries;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct config_file config_file_t;
|
typedef struct config_file config_file_t;
|
||||||
|
|
||||||
|
@ -48,6 +49,8 @@ bool config_get_hex(config_file_t *conf, const char *entry, unsigned *in);
|
||||||
bool config_get_char(config_file_t *conf, const char *entry, char *in);
|
bool config_get_char(config_file_t *conf, const char *entry, char *in);
|
||||||
// Extracts an allocated string in *in. This must be free()-d if this function succeeds.
|
// Extracts an allocated string in *in. This must be free()-d if this function succeeds.
|
||||||
bool config_get_string(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);
|
||||||
// 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.
|
// 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);
|
bool config_get_bool(config_file_t *conf, const char *entry, bool *in);
|
||||||
|
|
||||||
|
|
|
@ -261,10 +261,9 @@ static config_file_t *open_default_config_file(void)
|
||||||
g_settings.var = tmp_double
|
g_settings.var = tmp_double
|
||||||
|
|
||||||
#define CONFIG_GET_STRING(var, key) do { \
|
#define CONFIG_GET_STRING(var, key) do { \
|
||||||
if (config_get_string(conf, key, &tmp_str)) \
|
if (config_get_array(conf, key, tmp_str, sizeof(tmp_str))) \
|
||||||
{ \
|
{ \
|
||||||
strlcpy(g_settings.var, tmp_str, sizeof(g_settings.var)); \
|
strlcpy(g_settings.var, tmp_str, sizeof(g_settings.var)); \
|
||||||
free(tmp_str); \
|
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
@ -294,7 +293,7 @@ static void parse_config_file(void)
|
||||||
int tmp_int;
|
int tmp_int;
|
||||||
double tmp_double;
|
double tmp_double;
|
||||||
bool tmp_bool;
|
bool tmp_bool;
|
||||||
char *tmp_str;
|
char tmp_str[MAXPATHLEN];
|
||||||
|
|
||||||
CONFIG_GET_DOUBLE(video.xscale, "video_xscale");
|
CONFIG_GET_DOUBLE(video.xscale, "video_xscale");
|
||||||
CONFIG_GET_DOUBLE(video.yscale, "video_yscale");
|
CONFIG_GET_DOUBLE(video.yscale, "video_yscale");
|
||||||
|
@ -339,7 +338,7 @@ static void parse_config_file(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_CG) || defined(HAVE_XML)
|
#if defined(HAVE_CG) || defined(HAVE_XML)
|
||||||
if (config_get_string(conf, "video_shader_type", &tmp_str))
|
if (config_get_array(conf, "video_shader_type", tmp_str, sizeof(tmp_str)))
|
||||||
{
|
{
|
||||||
if (strcmp("cg", tmp_str) == 0)
|
if (strcmp("cg", tmp_str) == 0)
|
||||||
g_settings.video.shader_type = SSNES_SHADER_CG;
|
g_settings.video.shader_type = SSNES_SHADER_CG;
|
||||||
|
@ -349,8 +348,6 @@ static void parse_config_file(void)
|
||||||
g_settings.video.shader_type = SSNES_SHADER_AUTO;
|
g_settings.video.shader_type = SSNES_SHADER_AUTO;
|
||||||
else if (strcmp("none", tmp_str) == 0)
|
else if (strcmp("none", tmp_str) == 0)
|
||||||
g_settings.video.shader_type = SSNES_SHADER_NONE;
|
g_settings.video.shader_type = SSNES_SHADER_NONE;
|
||||||
|
|
||||||
free(tmp_str);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue