From a4f67018faf7755d077778b750524f3a7555f5c7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 29 May 2013 07:59:27 +0100 Subject: fix import of old broken Choices --- utils/nsoption.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'utils') 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; } -- cgit v1.2.3