From 68c2013504b9ed951178dd8c77ba479f1b134614 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 28 May 2013 21:36:10 +0100 Subject: add provenance to about:config --- content/fetchers/about.c | 4 +- utils/nsoption.c | 145 ++++++++++++++++++++++++++++++++--------------- utils/nsoption.h | 1 + 3 files changed, 102 insertions(+), 48 deletions(-) diff --git a/content/fetchers/about.c b/content/fetchers/about.c index ee2ea5477..cac8b2b01 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -331,13 +331,13 @@ static bool fetch_about_config_handler(struct fetch_about_context *ctx) "

\n" "

NetSurf Browser Config

\n" "\n" - "\n"); + "\n"); do { res = nsoption_snoptionf(buffer + slen, sizeof buffer - slen, opt_loop, - "\n"); + "\n"); if (res <= 0) break; /* last option */ diff --git a/utils/nsoption.c b/utils/nsoption.c index b5add5f91..d64adec72 100644 --- a/utils/nsoption.c +++ b/utils/nsoption.c @@ -155,6 +155,58 @@ static void nsoption_validate(struct nsoption_s *opts) } } +static bool +nsoption_is_set(struct nsoption_s *opts, + struct nsoption_s *defs, + enum nsoption_e entry) +{ + bool ret = false; + + switch (opts[entry].type) { + case OPTION_BOOL: + if (opts[entry].value.b != defs[entry].value.b) { + ret = true; + } + break; + + case OPTION_INTEGER: + if (opts[entry].value.i != defs[entry].value.i) { + ret = true; + } + break; + + case OPTION_UINT: + if (opts[entry].value.u != defs[entry].value.u) { + ret = true; + } + break; + + case OPTION_COLOUR: + if (opts[entry].value.c != defs[entry].value.c) { + ret = true; + } + break; + + case OPTION_STRING: + /* set if: + * - defs is null. + * - default is null but value is not. + * - default and value pointers are different + * (acts as a null check because of previous check) + * and the strings content differ. + */ + if (((defs[entry].value.s == NULL) && + (opts[entry].value.s != NULL)) || + ((defs[entry].value.s != opts[entry].value.s) && + (strcmp(opts[entry].value.s, defs[entry].value.s) != 0))) { + ret = true; + } + break; + + } + return ret; +} + /** Output choices to file stream * * @param fp the file stream to write to @@ -169,66 +221,52 @@ nsoption_output(FILE *fp, bool all) { unsigned int entry; + bool show; + colour rgbcolour; /* RRGGBB */ + for (entry = 0; entry < NSOPTION_LISTEND; entry++) { + show = all || nsoption_is_set(opts, defs, entry); + + if (show == false) { + continue; + } + switch (opts[entry].type) { case OPTION_BOOL: - if (all || - (opts[entry].value.b != defs[entry].value.b)) { - fprintf(fp, "%s:%c\n", - opts[entry].key, - opts[entry].value.b ? '1' : '0'); - } + fprintf(fp, "%s:%c\n", + opts[entry].key, + opts[entry].value.b ? '1' : '0'); break; case OPTION_INTEGER: - if (all || - (opts[entry].value.i != defs[entry].value.i)) { - fprintf(fp, "%s:%i\n", - opts[entry].key, - opts[entry].value.i); - } + fprintf(fp, "%s:%i\n", + opts[entry].key, + opts[entry].value.i); + break; case OPTION_UINT: - if (all || - (opts[entry].value.u != defs[entry].value.u)) { - fprintf(fp, "%s:%u\n", - opts[entry].key, - opts[entry].value.u); - } + fprintf(fp, "%s:%u\n", + opts[entry].key, + opts[entry].value.u); break; case OPTION_COLOUR: - if (all || - (opts[entry].value.c != defs[entry].value.c)) { - colour rgbcolour; /* RRGGBB */ - rgbcolour = (((0x000000FF & opts[entry].value.c) << 16) | - ((0x0000FF00 & opts[entry].value.c) << 0) | - ((0x00FF0000 & opts[entry].value.c) >> 16)); - fprintf(fp, "%s:%06x\n", - opts[entry].key, - rgbcolour); - } + rgbcolour = (((0x000000FF & opts[entry].value.c) << 16) | + ((0x0000FF00 & opts[entry].value.c) << 0) | + ((0x00FF0000 & opts[entry].value.c) >> 16)); + fprintf(fp, "%s:%06x\n", + opts[entry].key, + rgbcolour); + break; case OPTION_STRING: - /* output the key if: - * - defs is null. - * - default is null but value is not. - * - default and value pointers are different - * (acts as a null check because of previous check) - * and the strings content differ. - */ - if (all || - ((defs[entry].value.s == NULL) && - (opts[entry].value.s != NULL)) || - ((defs[entry].value.s != opts[entry].value.s) && - (strcmp(opts[entry].value.s, defs[entry].value.s) != 0))) { - fprintf(fp, "%s:%s\n", - opts[entry].key, - ((opts[entry].value.s == NULL) || - (*opts[entry].value.s == 0)) ? "" : opts[entry].value.s); - } + fprintf(fp, "%s:%s\n", + opts[entry].key, + ((opts[entry].value.s == NULL) || + (*opts[entry].value.s == 0)) ? "" : opts[entry].value.s); + break; } } @@ -283,7 +321,8 @@ nsoption_output_value_html(struct nsoption_s *option, slen = snprintf(string + pos, size - pos, "#%06x", + "color: #%06x; " + "font-family:Monospace; \">#%06X", rgbcolour, (~rgbcolour) & 0xffffff, rgbcolour); @@ -630,6 +669,20 @@ nsoption_snoptionf(char *string, option->key); break; + case 'p': + if (nsoption_is_set(nsoptions, + nsoptions_default, + option_idx)) { + slen += snprintf(string + slen, + size - slen, + "user"); + } else { + slen += snprintf(string + slen, + size - slen, + "default"); + } + break; + case 't': switch (option->type) { case OPTION_BOOL: diff --git a/utils/nsoption.h b/utils/nsoption.h index 32e9e6634..868e077bd 100644 --- a/utils/nsoption.h +++ b/utils/nsoption.h @@ -220,6 +220,7 @@ nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts); * %t - The options type * %V - value (HTML formatting) * %v - value (plain formatting) + * %p - provenance either "user" or "default" * * @param string The buffer in which to place the results. * @param size The size of the string buffer. -- cgit v1.2.3
OptionTypeProvenanceSetting
%k%t%V
%k%t%p%V