Commit 8f48bcaf8bebbfbddec8adcef498d7c92c85d0a2

Con Kolivas 2014-07-17T14:27:26

Fix processarg parameters loaded from a config file not being saveable

diff --git a/ccan/opt/opt.c b/ccan/opt/opt.c
index 8ff00ea..48cd386 100644
--- a/ccan/opt/opt.c
+++ b/ccan/opt/opt.c
@@ -138,7 +138,7 @@ static void check_opt(const struct opt_table *entry)
 				errx(1, "Option %s: invalid short option"
 				     " '%.*s'", entry->names, len+1, p-1);
 			opt_num_short++;
-			if (entry->type == OPT_HASARG)
+			if (entry->type == OPT_HASARG || entry->type == OPT_PROCESSARG)
 				opt_num_short_arg++;
 		}
 		/* Don't document args unless there are some. */
diff --git a/cgminer.c b/cgminer.c
index b71cceb..f4fb060 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1544,6 +1544,7 @@ static char *parse_config(json_t *config, bool fileconf)
 {
 	static char err_buf[200];
 	struct opt_table *opt;
+	const char *str;
 	json_t *val;
 
 	if (fileconf && !fileconf_load)
@@ -1572,16 +1573,24 @@ static char *parse_config(json_t *config, bool fileconf)
 				continue;
 
 			if ((opt->type & (OPT_HASARG | OPT_PROCESSARG)) && json_is_string(val)) {
-				err = opt->cb_arg(json_string_value(val),
-						  opt->u.arg);
+				str = json_string_value(val);
+				err = opt->cb_arg(str, opt->u.arg);
+				if (opt->type == OPT_PROCESSARG)
+					opt_set_charp(str, opt->u.arg);
 			} else if ((opt->type & (OPT_HASARG | OPT_PROCESSARG)) && json_is_array(val)) {
-				int n, size = json_array_size(val);
-
-				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);
+				json_t *arr_val;
+				size_t index;
+
+				json_array_foreach(val, index, arr_val) {
+					if (json_is_string(arr_val)) {
+						str = json_string_value(arr_val);
+						err = opt->cb_arg(str, opt->u.arg);
+						if (opt->type == OPT_PROCESSARG)
+							opt_set_charp(str, opt->u.arg);
+					} else if (json_is_object(arr_val))
+						err = parse_config(arr_val, false);
+					if (err)
+						break;
 				}
 			} else if ((opt->type & OPT_NOARG) && json_is_true(val))
 				err = opt->cb(opt->u.arg);