diff options
author | Josh Rickmar <jrick@conformal.com> | 2013-08-26 14:55:19 -0400 |
---|---|---|
committer | Josh Rickmar <jrick@conformal.com> | 2013-09-10 09:35:36 -0400 |
commit | 2d8388995f65c7d734d1bdc528bf478e69c5f390 (patch) | |
tree | c14c37427f0edde6b9329da3696858cc1071ee8d | |
parent | 3de0232094d1393f7cdf4c0bb22dc1b44779490c (diff) | |
download | xombrero-2d8388995f65c7d734d1bdc528bf478e69c5f390.tar.gz |
Fix several more issues with float/double settings.
All floats are now doubles, and are represented as such with the XT_S_DOUBLE macro. struct settings fval field is now renamed to dval. Doubles are read in as %lf (double precision) instead of %f (single precision). Finally, a floating point comparison using != was removed.
-rw-r--r-- | about.c | 6 | ||||
-rw-r--r-- | settings.c | 25 | ||||
-rw-r--r-- | xombrero.h | 4 |
3 files changed, 18 insertions, 17 deletions
diff --git a/about.c b/about.c index 655de9a..0359c0f 100644 --- a/about.c +++ b/about.c @@ -953,9 +953,9 @@ xtp_handle_rt(struct tab *t, uint8_t cmd, int id, const char *query) if (atoi(val) != *rs[i].ival) modify = 1; break; - case XT_S_FLOAT: - if (atof(val) < (*rs[i].fval - 0.0001) || - atof(val) > (*rs[i].fval + 0.0001)) + case XT_S_DOUBLE: + if (atof(val) < (*rs[i].dval - 0.0001) || + atof(val) > (*rs[i].dval + 0.0001)) modify = 1; break; case XT_S_STR: diff --git a/settings.c b/settings.c index 79d9ec3..8b1fbc9 100644 --- a/settings.c +++ b/settings.c @@ -517,7 +517,7 @@ struct settings rs[] = { { "cookies_enabled", XT_S_BOOL, 0, &cookies_enabled, NULL, NULL, NULL, set_cookies_enabled, check_cookies_enabled, TT_COOKIES_ENABLED }, { "ctrl_click_focus", XT_S_BOOL, 0, &ctrl_click_focus, NULL, NULL, NULL, set_ctrl_click_focus, check_ctrl_click_focus, TT_CTRL_CLICK_FOCUS }, { "default_script", XT_S_STR, 1, NULL, NULL,&s_default_script, NULL, set_default_script_rt, check_default_script, TT_DEFAULT_SCRIPT }, - { "default_zoom_level", XT_S_FLOAT, 0, NULL, NULL, NULL, &default_zoom_level, set_default_zoom_level, check_default_zoom_level, TT_DEFAULT_ZOOM_LEVEL }, + { "default_zoom_level", XT_S_DOUBLE, 0, NULL, NULL, NULL, &default_zoom_level, set_default_zoom_level, check_default_zoom_level, TT_DEFAULT_ZOOM_LEVEL }, { "do_not_track", XT_S_BOOL, 0, &do_not_track, NULL, NULL, NULL, set_do_not_track, check_do_not_track, TT_DO_NOT_TRACK }, { "download_dir", XT_S_STR, 0, NULL, NULL,&s_download_dir, NULL, NULL, check_download_dir, TT_DOWNLOAD_DIR }, { "download_mode", XT_S_STR, 0, NULL, NULL,&s_download_mode, NULL, set_download_mode_rt, check_download_mode, TT_DOWNLOAD_MODE }, @@ -698,7 +698,8 @@ int check_default_zoom_level(char **tt) { *tt = g_strdup_printf("Default: %f", XT_DS_DEFAULT_ZOOM_LEVEL); - return (default_zoom_level != XT_DS_DEFAULT_ZOOM_LEVEL); + return (default_zoom_level < (XT_DS_DEFAULT_ZOOM_LEVEL - 0.0001) || + default_zoom_level > (XT_DS_DEFAULT_ZOOM_LEVEL + 0.0001)); } int @@ -984,8 +985,8 @@ get_as_string(struct settings *s) r = g_strdup_printf("%d", *s->ival); else if (s->type == XT_S_STR) r = g_strdup(*s->sval); - else if (s->type == XT_S_FLOAT) - r = g_strdup_printf("%f", *s->fval); + else if (s->type == XT_S_DOUBLE) + r = g_strdup_printf("%lf", *s->dval); else if (s->type == XT_S_BOOL) r = g_strdup_printf("%d", *s->ival); else @@ -3609,7 +3610,7 @@ settings_add(char *var, char *val) { int i, rv, *p; int tmp; - double *f; + double *d; char c[PATH_MAX], **s; const char *errstr; @@ -3654,9 +3655,9 @@ settings_add(char *var, char *val) *s = g_strdup(val); rv = 1; break; - case XT_S_FLOAT: - f = rs[i].fval; - *f = g_ascii_strtod(val, NULL); + case XT_S_DOUBLE: + d = rs[i].dval; + *d = g_ascii_strtod(val, NULL); rv = 1; break; case XT_S_INVALID: @@ -3836,7 +3837,7 @@ print_runtime_setting(struct settings *s, char *val, void *cb_args) *sa->body, s->name, val); - else if (s->type == XT_S_FLOAT) + else if (s->type == XT_S_DOUBLE) *sa->body = g_strdup_printf( "%s<input type='number' step='0.000001' name='%s' value='%s'>" "</div></td></tr>", @@ -4052,10 +4053,10 @@ set(struct tab *t, struct karg *args) else show_oops(t, "%s = ", rs[i].name); break; - case XT_S_FLOAT: - if (rs[i].fval) + case XT_S_DOUBLE: + if (rs[i].dval) show_oops(t, "%s = %f", - rs[i].name, *rs[i].fval); + rs[i].name, *rs[i].dval); else if (rs[i].s && rs[i].s->get) show_oops(t, "%s = %s", rs[i].name, diff --git a/xombrero.h b/xombrero.h index 9179412..7fc9b50 100644 --- a/xombrero.h +++ b/xombrero.h @@ -805,7 +805,7 @@ struct settings { #define XT_S_INVALID (0) #define XT_S_INT (1) #define XT_S_STR (2) -#define XT_S_FLOAT (3) +#define XT_S_DOUBLE (3) #define XT_S_BOOL (4) uint32_t flags; #define XT_SF_RESTART (1<<0) @@ -814,7 +814,7 @@ struct settings { int *ival; char **sval; struct special *s; - double *fval; + double *dval; int (*activate)(char *); int (*ismodified)(char **); char *tt; |