diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2013-05-29 07:59:27 +0100 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2013-05-29 07:59:27 +0100 |
commit | a4f67018faf7755d077778b750524f3a7555f5c7 (patch) | |
tree | 7da85325661ae7328d74624f926bfda9274f9989 /utils/nsoption.c | |
parent | 44f91c9fc8befb67211949008121cb0eae6de562 (diff) | |
download | netsurf-a4f67018faf7755d077778b750524f3a7555f5c7.tar.gz netsurf-a4f67018faf7755d077778b750524f3a7555f5c7.tar.bz2 |
fix import of old broken Choices
Diffstat (limited to 'utils/nsoption.c')
-rw-r--r-- | utils/nsoption.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/utils/nsoption.c b/utils/nsoption.c index 41a4d5748..a9264de6d 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -133,8 +133,11 @@ strtooption(const char *value, struct nsoption_s *option) } /* validate options to sane values */ -static void nsoption_validate(struct nsoption_s *opts) +static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs) { + int cloop; + bool black = true; + if (opts[NSOPTION_font_size].value.i < 50) { opts[NSOPTION_font_size].value.i = 50; } @@ -154,6 +157,27 @@ static void nsoption_validate(struct nsoption_s *opts) if (opts[NSOPTION_memory_cache_size].value.i < 0) { opts[NSOPTION_memory_cache_size].value.i = 0; } + + /* to aid migration from old, broken, configuration files this + * checks to see if all the system colours are set to black + * and returns them to defaults instead + */ + + for (cloop = NSOPTION_SYS_COLOUR_START; + cloop <= NSOPTION_SYS_COLOUR_END; + cloop++) { + if (opts[cloop].value.c != 0) { + black = false; + break; + } + } + if (black == true) { + for (cloop = NSOPTION_SYS_COLOUR_START; + cloop <= NSOPTION_SYS_COLOUR_END; + cloop++) { + opts[cloop].value.c = defs[cloop].value.c; + } + } } static bool @@ -468,6 +492,7 @@ nsoption_read(const char *path, struct nsoption_s *opts) { char s[100]; FILE *fp; + struct nsoption_s *defs; if (path == NULL) { return NSERROR_BAD_PARAMETER; @@ -478,6 +503,9 @@ nsoption_read(const char *path, struct nsoption_s *opts) opts = nsoptions; } + /* @todo is this and API bug not being a parameter */ + defs = nsoptions_default; + fp = fopen(path, "r"); if (!fp) { LOG(("Failed to open file '%s'", path)); @@ -515,7 +543,7 @@ nsoption_read(const char *path, struct nsoption_s *opts) fclose(fp); - nsoption_validate(opts); + nsoption_validate(opts, defs); return NSERROR_OK; } |