about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@conformal.com>2013-08-26 14:55:19 -0400
committerJosh Rickmar <jrick@conformal.com>2013-09-10 09:35:36 -0400
commit2d8388995f65c7d734d1bdc528bf478e69c5f390 (patch)
treec14c37427f0edde6b9329da3696858cc1071ee8d
parent3de0232094d1393f7cdf4c0bb22dc1b44779490c (diff)
downloadxombrero-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.c6
-rw-r--r--settings.c25
-rw-r--r--xombrero.h4
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;
>349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633