From: Bert Vermeulen Date: Tue, 22 May 2012 18:16:56 +0000 (+0200) Subject: cli: no need to specify stacking order if it's the same as the PD list X-Git-Tag: sigrok-cli-0.3.1~20 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b0b056549cdc0ee590deb941453dcf219d5123c7;p=sigrok-cli.git cli: no need to specify stacking order if it's the same as the PD list --- diff --git a/sigrok-cli.c b/sigrok-cli.c index 560cbc5..12e8adf 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -1047,33 +1047,39 @@ int main(int argc, char **argv) printf("Failed to register protocol decoder callback\n"); return 1; } - } - if (opt_pd_stack) { - pds = g_strsplit(opt_pd_stack, ",", 0); - if (g_strv_length(pds) < 2) { - printf("Specify at least two protocol decoders to stack.\n"); - return 1; - } + pds = g_strsplit(opt_pds, ",", 0); + if (g_strv_length(pds) > 1) { + if (opt_pd_stack) { + /* A stack setup was specified, use that. */ + g_strfreev(pds); + pds = g_strsplit(opt_pd_stack, ",", 0); + if (g_strv_length(pds) < 2) { + g_strfreev(pds); + printf("Specify at least two protocol decoders to stack.\n"); + return 1; + } + } - if (!(di_from = srd_inst_find_by_id(pds[0]))) { - printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]); - return 1; - } - for (i = 1; pds[i]; i++) { - if (!(di_to = srd_inst_find_by_id(pds[i]))) { - printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]); + if (!(di_from = srd_inst_find_by_id(pds[0]))) { + printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]); return 1; } - if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK) - return ret; + for (i = 1; pds[i]; i++) { + if (!(di_to = srd_inst_find_by_id(pds[i]))) { + printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]); + return 1; + } + if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK) + return ret; - /* Don't show annotation from this PD. Only the last PD in - * the stack will be left on the annotation list. - */ - g_datalist_remove_data(&pd_ann_visible, di_from->inst_id); + /* Don't show annotation from this PD. Only the last PD in + * the stack will be left on the annotation list. + */ + g_datalist_remove_data(&pd_ann_visible, di_from->inst_id); - di_from = di_to; + di_from = di_to; + } } g_strfreev(pds); }