From 1b2f39c24bb6591a4192377d9393f5c3e45cb5bd Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 8 Oct 2018 19:36:25 +0100 Subject: [PATCH] settings.c: allow load_open_settings(NULL). All the lowest-level helper functions in settings.c that read a single setting from a settings_r are now prepared to tolerate being passed a null settings_r pointer, which will be treated as if reading from it always failed. This means you can call load_open_settings(NULL, conf) to populate a Conf with all of the _built-in_ internal defaults, without ever loading from the saved-session storage at all (not even Default Settings). (Doing this will still call the platform_default_foo function family, if nothing else because Filenames and FontSpecs can't be constructed in any platform-independent way at all.) --- settings.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/settings.c b/settings.c index 6ba04720..e5d40714 100644 --- a/settings.c +++ b/settings.c @@ -107,7 +107,7 @@ char *get_remote_username(Conf *conf) static char *gpps_raw(settings_r *sesskey, const char *name, const char *def) { - char *ret = read_setting_s(sesskey, name); + char *ret = sesskey ? read_setting_s(sesskey, name) : NULL; if (!ret) ret = platform_default_s(name); if (!ret) @@ -131,7 +131,7 @@ static void gpps(settings_r *sesskey, const char *name, const char *def, static void gppfont(settings_r *sesskey, char *name, Conf *conf, int primary) { - FontSpec *result = read_setting_fontspec(sesskey, name); + FontSpec *result = sesskey ? read_setting_fontspec(sesskey, name) : NULL; if (!result) result = platform_default_fontspec(name); conf_set_fontspec(conf, primary, result); @@ -140,7 +140,7 @@ static void gppfont(settings_r *sesskey, char *name, static void gppfile(settings_r *sesskey, const char *name, Conf *conf, int primary) { - Filename *result = read_setting_filename(sesskey, name); + Filename *result = sesskey ? read_setting_filename(sesskey, name) : NULL; if (!result) result = platform_default_filename(name); conf_set_filename(conf, primary, result); @@ -150,7 +150,7 @@ static void gppfile(settings_r *sesskey, const char *name, static int gppi_raw(settings_r *sesskey, const char *name, int def) { def = platform_default_i(name, def); - return read_setting_i(sesskey, name, def); + return sesskey ? read_setting_i(sesskey, name, def) : def; } static void gppi(settings_r *sesskey, const char *name, int def,