Fix processarg parameters loaded from a config file not being saveable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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);