From 0bb1f7292cd2a519d5631bb3f1a64ee93c03b8d2 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 29 Jan 2012 15:52:59 +0100 Subject: [PATCH] Cleanup settings handling a bit to avoid lots of dummy variables. --- conf/config_file_macros.h | 69 +++++++++++++++++++-------------------- ps3/main.c | 5 --- settings.c | 13 +++----- 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/conf/config_file_macros.h b/conf/config_file_macros.h index 9d4f4cb29e..0c9c3e11be 100644 --- a/conf/config_file_macros.h +++ b/conf/config_file_macros.h @@ -16,49 +16,48 @@ * If not, see . */ -#ifndef _CONFIG_FILE_MACROS_H -#define _CONFIG_FILE_MACROS_H +#ifndef CONFIG_FILE_MACROS_H__ +#define CONFIG_FILE_MACROS_H__ /* Macros to ease config getting. */ -#define CONFIG_GET_BOOL(var, key) if (config_get_bool(conf, key, &tmp_bool)) \ - g_settings.var = tmp_bool +#define CONFIG_GET_BOOL_BASE(conf, base, var, key) do { \ + bool tmp; \ + if (config_get_bool(conf, key, &tmp)) \ + base.var = tmp; \ +} while(0) -#define CONFIG_GET_INT(var, key) if (config_get_int(conf, key, &tmp_int)) \ - g_settings.var = tmp_int +#define CONFIG_GET_INT_BASE(conf, base, var, key) do { \ + int tmp; \ + if (config_get_int(conf, key, &tmp)) \ + base.var = tmp; \ +} while(0) -#define CONFIG_GET_DOUBLE(var, key) if (config_get_double(conf, key, &tmp_double)) \ - g_settings.var = tmp_double +#define CONFIG_GET_DOUBLE_BASE(conf, base, var, key) do { \ + double tmp; \ + if (config_get_double(conf, key, &tmp)) \ + base.var = tmp; \ +} while(0) -#define CONFIG_GET_STRING(var, key) \ - config_get_array(conf, key, g_settings.var, sizeof(g_settings.var)) +#define CONFIG_GET_STRING_BASE(conf, base, var, key) \ + config_get_array(conf, key, base.var, sizeof(base.var)) + +#define CONFIG_GET_BOOL(var, key) CONFIG_GET_BOOL_BASE(conf, g_settings, var, key) +#define CONFIG_GET_INT(var, key) CONFIG_GET_INT_BASE(conf, g_settings, var, key) +#define CONFIG_GET_DOUBLE(var, key) CONFIG_GET_DOUBLE_BASE(conf, g_settings, var, key) +#define CONFIG_GET_STRING(var, key) CONFIG_GET_STRING_BASE(conf, g_settings, var, key) + +#define CONFIG_GET_BOOL_EXTERN(var, key) CONFIG_GET_BOOL_BASE(conf, g_extern, var, key) +#define CONFIG_GET_INT_EXTERN(var, key) CONFIG_GET_INT_BASE(conf, g_extern, var, key) +#define CONFIG_GET_DOUBLE_EXTERN(var, key) CONFIG_GET_DOUBLE_BASE(conf, g_extern, var, key) +#define CONFIG_GET_STRING_EXTERN(var, key) CONFIG_GET_STRING_BASE(conf, g_extern, var, key) #ifdef SSNES_CONSOLE - -#define CONFIG_GET_BOOL_CONSOLE(var, key) if (config_get_bool(conf, key, &tmp_bool)) \ - g_console.var = tmp_bool - -#define CONFIG_GET_INT_CONSOLE(var, key) if (config_get_int(conf, key, &tmp_int)) \ - g_console.var = tmp_int - -#define CONFIG_GET_DOUBLE_CONSOLE(var, key) if (config_get_double(conf, key, &tmp_double)) \ - g_console.var = tmp_double - -#define CONFIG_GET_STRING_CONSOLE(var, key) \ - config_get_array(conf, key, g_console.var, sizeof(g_console.var)) +#define CONFIG_GET_BOOL_EXTERN(var, key) CONFIG_GET_BOOL_BASE(conf, g_console, var, key) +#define CONFIG_GET_INT_EXTERN(var, key) CONFIG_GET_INT_BASE(conf, g_console, var, key) +#define CONFIG_GET_DOUBLE_EXTERN(var, key) CONFIG_GET_DOUBLE_BASE(conf, g_console, var, key) +#define CONFIG_GET_STRING_EXTERN(var, key) CONFIG_GET_STRING_BASE(conf, g_console, var, key) +#endif #endif -#define CONFIG_GET_BOOL_EXTERN(var, key) if (config_get_bool(conf, key, &tmp_bool)) \ - g_extern.var = tmp_bool - -#define CONFIG_GET_INT_EXTERN(var, key) if (config_get_int(conf, key, &tmp_int)) \ - g_extern.var = tmp_int - -#define CONFIG_GET_DOUBLE_EXTERN(var, key) if (config_get_double(conf, key, &tmp_double)) \ - g_extern.var = tmp_double - -#define CONFIG_GET_STRING_EXTERN(var, key) \ - config_get_array(conf, key, g_extern.var, sizeof(g_extern.var)) - -#endif diff --git a/ps3/main.c b/ps3/main.c index 05f0f23196..dd17d1ce1a 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -120,11 +120,6 @@ static bool init_settings(void) if (!conf) return 1; - int tmp_int; - double tmp_double; - bool tmp_bool; - char tmp_str[PATH_MAX]; - CONFIG_GET_BOOL(video.smooth, "video_smooth"); CONFIG_GET_BOOL(video.second_pass_smooth, "video_second_pass_smooth"); CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader"); diff --git a/settings.c b/settings.c index 0f5b890e91..f5d0c09c71 100644 --- a/settings.c +++ b/settings.c @@ -351,9 +351,6 @@ bool config_load_file(const char *path) fprintf(stderr, "=== Config end ===\n"); } - int tmp_int; - double tmp_double; - bool tmp_bool; char tmp_str[PATH_MAX]; CONFIG_GET_DOUBLE(video.xscale, "video_xscale"); @@ -362,9 +359,7 @@ bool config_load_file(const char *path) CONFIG_GET_INT(video.fullscreen_y, "video_fullscreen_y"); if (!g_extern.force_fullscreen) - { CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen"); - } CONFIG_GET_BOOL(video.force_16bit, "video_force_16bit"); CONFIG_GET_BOOL(video.disable_composition, "video_disable_composition"); @@ -449,9 +444,7 @@ bool config_load_file(const char *path) CONFIG_GET_STRING(input.driver, "input_driver"); if (!*g_settings.libsnes) - { CONFIG_GET_STRING(libsnes, "libsnes_path"); - } CONFIG_GET_STRING(screenshot_directory, "screenshot_directory"); if (*g_settings.screenshot_directory && !path_is_directory(g_settings.screenshot_directory)) @@ -462,8 +455,9 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); - if (config_get_int(conf, "rewind_buffer_size", &tmp_int)) - g_settings.rewind_buffer_size = tmp_int * UINT64_C(1000000); + int buffer_size; + if (config_get_int(conf, "rewind_buffer_size", &buffer_size)) + g_settings.rewind_buffer_size = buffer_size * UINT64_C(1000000); CONFIG_GET_INT(rewind_granularity, "rewind_granularity"); @@ -776,3 +770,4 @@ static void read_keybinds(config_file_t *conf) } } #endif +