Browse Source

Merge branch 'cfg_json_types' into bfgminer

Luke Dashjr 13 years ago
parent
commit
0e0fc35e9e
2 changed files with 34 additions and 14 deletions
  1. 7 7
      example.conf
  2. 27 7
      miner.c

+ 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",

+ 27 - 7
miner.c

@@ -1048,7 +1048,7 @@ static char *parse_config(json_t *config, bool fileconf)
 		/* Pull apart the option name(s). */
 		name = strdup(opt->names);
 		for (p = strtok(name, "|"); p; p = strtok(NULL, "|")) {
-			char *err = NULL;
+			char *err = "Invalid value";
 
 			/* Ignore short options. */
 			if (p[1] != '-')
@@ -1058,22 +1058,42 @@ static char *parse_config(json_t *config, bool fileconf)
 			if (!val)
 				continue;
 
-			if ((opt->type & OPT_HASARG) && json_is_string(val)) {
+			if (opt->type & OPT_HASARG) {
+			  if (json_is_string(val)) {
 				err = opt->cb_arg(json_string_value(val),
 						  opt->u.arg);
-			} else if ((opt->type & OPT_HASARG) && json_is_array(val)) {
+			  } 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);
 
+				err = NULL;
 				for (n = 0; n < size && !err; n++) {
 					if (json_is_string(json_array_get(val, n)))
 						err = opt->cb_arg(json_string_value(json_array_get(val, n)), opt->u.arg);
 					else if (json_is_object(json_array_get(val, n)))
 						err = parse_config(json_array_get(val, n), false);
 				}
-			} else if ((opt->type & OPT_NOARG) && json_is_true(val))
-				err = opt->cb(opt->u.arg);
-			else
-				err = "Invalid value";
+			  }
+			} else if (opt->type & OPT_NOARG) {
+				if (json_is_true(val))
+					err = opt->cb(opt->u.arg);
+				else if (json_is_boolean(val)) {
+					if (opt->cb == (void*)opt_set_bool)
+						err = opt_set_invbool(opt->u.arg);
+					else if (opt->cb == (void*)opt_set_invbool)
+						err = opt_set_bool(opt->u.arg);
+				}
+			}
 
 			if (err) {
 				/* Allow invalid values to be in configuration