X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=session.c;h=0e426cdd1957268102797f37f0c95a5d981de7fb;hp=cb8a1b4f27ab742f796d46a7e9cc2e47c40088c9;hb=7ce834c1166fcf57ebb0e20bf4e7ba9e856aa6ce;hpb=9a6e8ec4bc84d94e27c9a004a7b75caaa0ba7124 diff --git a/session.c b/session.c index cb8a1b4..0e426cd 100644 --- a/session.c +++ b/session.c @@ -92,7 +92,7 @@ const struct sr_output *setup_output_format(const struct sr_dev_inst *sdi, FILE } } - fmtargs = parse_generic_arg(opt_output_format, TRUE); + fmtargs = parse_generic_arg(opt_output_format, TRUE, NULL); fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key"); if (!fmtspec) g_critical("Invalid output format."); @@ -101,9 +101,11 @@ const struct sr_output *setup_output_format(const struct sr_dev_inst *sdi, FILE g_hash_table_remove(fmtargs, "sigrok_key"); if ((options = sr_output_options_get(omod))) { fmtopts = generic_arg_to_opt(options, fmtargs); + (void)warn_unknown_keys(options, fmtargs, NULL); sr_output_options_free(options); - } else + } else { fmtopts = NULL; + } o = sr_output_new(omod, fmtopts, sdi, opt_output_file); if (opt_output_file) { @@ -136,7 +138,7 @@ const struct sr_transform *setup_transform_module(const struct sr_dev_inst *sdi) GHashTable *fmtargs, *fmtopts; char *fmtspec; - fmtargs = parse_generic_arg(opt_transform_module, TRUE); + fmtargs = parse_generic_arg(opt_transform_module, TRUE, NULL); fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key"); if (!fmtspec) g_critical("Invalid transform module."); @@ -145,9 +147,11 @@ const struct sr_transform *setup_transform_module(const struct sr_dev_inst *sdi) g_hash_table_remove(fmtargs, "sigrok_key"); if ((options = sr_transform_options_get(tmod))) { fmtopts = generic_arg_to_opt(options, fmtargs); + (void)warn_unknown_keys(options, fmtargs, NULL); sr_transform_options_free(options); - } else + } else { fmtopts = NULL; + } t = sr_transform_new(tmod, fmtopts, sdi); if (fmtopts) g_hash_table_destroy(fmtopts); @@ -650,19 +654,51 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src) return ret; } +int set_dev_options_array(struct sr_dev_inst *sdi, char **opts) +{ + size_t opt_idx; + const char *opt_text; + GHashTable *args; + int ret; + + for (opt_idx = 0; opts && opts[opt_idx]; opt_idx++) { + opt_text = opts[opt_idx]; + args = parse_generic_arg(opt_text, FALSE, "channel_group"); + if (!args) + continue; + ret = set_dev_options(sdi, args); + g_hash_table_destroy(args); + if (ret != SR_OK) + return ret; + } + + return SR_OK; +} + int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) { struct sr_config src; + const char *cg_name; struct sr_channel_group *cg; GHashTableIter iter; gpointer key, value; int ret; + /* + * Not finding the 'sigrok_key' key (optional user specified + * channel group name) in the current options group's hash table + * is perfectly fine. In that case the -g selection is used, + * which defaults to "the device" (global parameters). + */ + cg_name = g_hash_table_lookup(args, "sigrok_key"); + cg = lookup_channel_group(sdi, cg_name); + g_hash_table_iter_init(&iter, args); while (g_hash_table_iter_next(&iter, &key, &value)) { + if (g_ascii_strcasecmp(key, "sigrok_key") == 0) + continue; if ((ret = opt_to_gvar(key, value, &src)) != 0) return ret; - cg = lookup_channel_group(sdi); if ((ret = maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, cg, src.key, src.data)) != SR_OK) { g_critical("Failed to set device option '%s': %s.", @@ -678,7 +714,6 @@ void run_session(void) { struct df_arg_desc df_arg; GSList *devices, *real_devices, *sd; - GHashTable *devargs; GVariant *gvar; struct sr_session *session; struct sr_trigger *trigger; @@ -761,12 +796,9 @@ void run_session(void) return; } - if (opt_config) { - if ((devargs = parse_generic_arg(opt_config, FALSE))) { - if (set_dev_options(sdi, devargs) != SR_OK) - return; - g_hash_table_destroy(devargs); - } + if (opt_configs) { + if (set_dev_options_array(sdi, opt_configs) != SR_OK) + return; } if (select_channels(sdi) != SR_OK) {