+ if (srd_init(NULL) != SRD_OK) {
+ printf("Failed to initialize sigrokdecode\n");
+ return 1;
+ }
+ if (register_pds(NULL, opt_pds) != 0) {
+ printf("Failed to register protocol decoders\n");
+ return 1;
+ }
+ if (srd_pd_output_callback_add(SRD_OUTPUT_ANN,
+ show_pd_annotation, NULL) != SRD_OK) {
+ 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;
+ }
+
+ 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]);
+ 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);
+
+ di_from = di_to;
+ }
+ g_strfreev(pds);