Browse Source

Accept JSON Numbers in config file parameters

Luke Dashjr 13 years ago
parent
commit
cd82ab2f0b
2 changed files with 18 additions and 7 deletions
  1. 11 0
      cgminer.c
  2. 7 7
      example.conf

+ 11 - 0
cgminer.c

@@ -1054,6 +1054,17 @@ static char *parse_config(json_t *config, bool fileconf)
 			  if (json_is_string(val)) {
 				err = opt->cb_arg(json_string_value(val),
 						  opt->u.arg);
+			  } else if (json_is_number(val)) {
+					char buf[256], *p, *q;
+					snprintf(buf, 256, "%f", json_number_value(val));
+					if ( (p = strchr(buf, '.')) ) {
+						// Trim /\.0*$/ to work properly with integer-only arguments
+						q = p;
+						while (*(++q) == '0') {}
+						if (*q == '\0')
+							*p = '\0';
+					}
+					err = opt->cb_arg(buf, opt->u.arg);
 			  } else if (json_is_array(val)) {
 				int n, size = json_array_size(val);
 

+ 7 - 7
example.conf

@@ -28,14 +28,14 @@
 
 "auto-fan" : true,
 "auto-gpu" : true,
-"expiry" : "120",
+"expiry" : 120,
 "failover-only" : true,
-"gpu-threads" : "2",
-"log" : "5",
-"queue" : "1",
-"retry-pause" : "5",
-"scan-time" : "60",
-"temp-hysteresis" : "3",
+"gpu-threads" : 2,
+"log" : 5,
+"queue" : 1,
+"retry-pause" : 5,
+"scan-time" : 60,
+"temp-hysteresis" : 3,
 
 "scan-serial" : [
 	"/dev/ttyUSB0",