a5999a2b434d37a93c2f57de57a1f1f996aac5ea
[sigrok-cli.git] / show.c
1 /*
2  * This file is part of the sigrok-cli project.
3  *
4  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "sigrok-cli.h"
21 #include <glib.h>
22 #include <string.h>
23
24 static gint sort_inputs(gconstpointer a, gconstpointer b)
25 {
26         return strcmp(sr_input_id_get((struct sr_input_module *)a),
27                         sr_input_id_get((struct sr_input_module *)b));
28 }
29
30 static gint sort_outputs(gconstpointer a, gconstpointer b)
31 {
32         return strcmp(sr_output_id_get((struct sr_output_module *)a),
33                         sr_output_id_get((struct sr_output_module *)b));
34 }
35
36 static gint sort_transforms(gconstpointer a, gconstpointer b)
37 {
38         return strcmp(sr_transform_id_get((struct sr_transform_module *)a),
39                         sr_transform_id_get((struct sr_transform_module *)b));
40 }
41
42 static gint sort_drivers(gconstpointer a, gconstpointer b)
43 {
44         const struct sr_dev_driver *sdda = a, *sddb = b;
45
46         return strcmp(sdda->name, sddb->name);
47 }
48
49 #ifdef HAVE_SRD
50 static gint sort_pds(gconstpointer a, gconstpointer b)
51 {
52         const struct srd_decoder *sda = a, *sdb = b;
53
54         return strcmp(sda->id, sdb->id);
55 }
56 #endif
57
58 void show_version(void)
59 {
60         struct sr_dev_driver **drivers, *driver;
61         const struct sr_input_module **inputs, *input;
62         const struct sr_output_module **outputs, *output;
63         const struct sr_transform_module **transforms, *transform;
64         const GSList *l;
65         GSList *sl;
66         int i;
67 #ifdef HAVE_SRD
68         struct srd_decoder *dec;
69 #endif
70
71         printf("sigrok-cli %s\n\n", VERSION);
72
73         printf("Using libsigrok %s (lib version %s).\n",
74                sr_package_version_string_get(), sr_lib_version_string_get());
75 #ifdef HAVE_SRD
76         printf("Using libsigrokdecode %s (lib version %s).\n\n",
77                srd_package_version_string_get(), srd_lib_version_string_get());
78 #endif
79
80         printf("Supported hardware drivers:\n");
81         drivers = sr_driver_list();
82         for (sl = NULL, i = 0; drivers[i]; i++)
83                 sl = g_slist_append(sl, drivers[i]);
84         sl = g_slist_sort(sl, sort_drivers);
85         for (l = sl; l; l = l->next) {
86                 driver = l->data;
87                 printf("  %-20s %s\n", driver->name, driver->longname);
88         }
89         printf("\n");
90         g_slist_free(sl);
91
92         printf("Supported input formats:\n");
93         inputs = sr_input_list();
94         for (sl = NULL, i = 0; inputs[i]; i++)
95                 sl = g_slist_append(sl, (gpointer)inputs[i]);
96         sl = g_slist_sort(sl, sort_inputs);
97         for (l = sl; l; l = l->next) {
98                 input = l->data;
99                 printf("  %-20s %s\n", sr_input_id_get(input),
100                                 sr_input_description_get(input));
101         }
102         printf("\n");
103         g_slist_free(sl);
104
105         printf("Supported output formats:\n");
106         outputs = sr_output_list();
107         for (sl = NULL, i = 0; outputs[i]; i++)
108                 sl = g_slist_append(sl, (gpointer)outputs[i]);
109         sl = g_slist_sort(sl, sort_outputs);
110         for (l = sl; l; l = l->next) {
111                 output = l->data;
112                 printf("  %-20s %s\n", sr_output_id_get(output),
113                                 sr_output_description_get(output));
114         }
115         printf("\n");
116         g_slist_free(sl);
117
118         printf("Supported transform modules:\n");
119         transforms = sr_transform_list();
120         for (sl = NULL, i = 0; transforms[i]; i++)
121                 sl = g_slist_append(sl, (gpointer)transforms[i]);
122         sl = g_slist_sort(sl, sort_transforms);
123         for (l = sl; l; l = l->next) {
124                 transform = l->data;
125                 printf("  %-20s %s\n", sr_transform_id_get(transform),
126                                 sr_transform_description_get(transform));
127         }
128         printf("\n");
129         g_slist_free(sl);
130
131 #ifdef HAVE_SRD
132         if (srd_init(NULL) == SRD_OK) {
133                 printf("Supported protocol decoders:\n");
134                 srd_decoder_load_all();
135                 sl = g_slist_copy((GSList *)srd_decoder_list());
136                 sl = g_slist_sort(sl, sort_pds);
137                 for (l = sl; l; l = l->next) {
138                         dec = l->data;
139                         printf("  %-20s %s\n", dec->id, dec->longname);
140                         /* Print protocol description upon "-l 3" or higher. */
141                         if (opt_loglevel >= SR_LOG_INFO)
142                                 printf("  %-20s %s\n", "", dec->desc);
143                 }
144                 g_slist_free(sl);
145                 srd_exit();
146         }
147         printf("\n");
148 #endif
149 }
150
151 static gint sort_channels(gconstpointer a, gconstpointer b)
152 {
153         const struct sr_channel *pa = a, *pb = b;
154
155         return pa->index - pb->index;
156 }
157
158 static void print_dev_line(const struct sr_dev_inst *sdi)
159 {
160         struct sr_channel *ch;
161         GSList *sl, *l, *channels;
162         GString *s;
163         GVariant *gvar;
164         struct sr_dev_driver *driver;
165         const char *vendor, *model, *version;
166
167         driver = sr_dev_inst_driver_get(sdi);
168         vendor = sr_dev_inst_vendor_get(sdi);
169         model = sr_dev_inst_model_get(sdi);
170         version = sr_dev_inst_version_get(sdi);
171         channels = sr_dev_inst_channels_get(sdi);
172
173         s = g_string_sized_new(128);
174         g_string_assign(s, driver->name);
175         if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
176                 g_string_append(s, ":conn=");
177                 g_string_append(s, g_variant_get_string(gvar, NULL));
178                 g_variant_unref(gvar);
179         }
180         g_string_append(s, " - ");
181         if (vendor && vendor[0])
182                 g_string_append_printf(s, "%s ", vendor);
183         if (model && model[0])
184                 g_string_append_printf(s, "%s ", model);
185         if (version && version[0])
186                 g_string_append_printf(s, "%s ", version);
187         if (channels) {
188                 if (g_slist_length(channels) == 1) {
189                         ch = channels->data;
190                         g_string_append_printf(s, "with 1 channel: %s", ch->name);
191                 } else {
192                         sl = g_slist_sort(g_slist_copy(channels), sort_channels);
193                         g_string_append_printf(s, "with %d channels:", g_slist_length(sl));
194                         for (l = sl; l; l = l->next) {
195                                 ch = l->data;
196                                 g_string_append_printf(s, " %s", ch->name);
197                         }
198                         g_slist_free(sl);
199                 }
200         }
201         g_string_append_printf(s, "\n");
202         printf("%s", s->str);
203         g_string_free(s, TRUE);
204
205 }
206
207 void show_dev_list(void)
208 {
209         struct sr_dev_inst *sdi;
210         GSList *devices, *l;
211
212         if (!(devices = device_scan()))
213                 return;
214
215         printf("The following devices were found:\n");
216         for (l = devices; l; l = l->next) {
217                 sdi = l->data;
218                 print_dev_line(sdi);
219         }
220         g_slist_free(devices);
221
222 }
223
224 void show_drv_detail(struct sr_dev_driver *driver)
225 {
226         const struct sr_config_info *srci;
227         GVariant *gvar_opts;
228         const uint32_t *opts;
229         gsize num_elements, i;
230
231         if (sr_config_list(driver, NULL, NULL, SR_CONF_DEVICE_OPTIONS,
232                         &gvar_opts) == SR_OK) {
233                 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
234                                 sizeof(uint32_t));
235                 if (num_elements) {
236                         printf("Driver functions:\n");
237                         for (i = 0; i < num_elements; i++) {
238                                 if (!(srci = sr_config_info_get(opts[i] & SR_CONF_MASK)))
239                                         continue;
240                                 printf("    %s\n", srci->name);
241                         }
242                 }
243                 g_variant_unref(gvar_opts);
244         }
245
246         if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
247                         &gvar_opts) == SR_OK) {
248                 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
249                                 sizeof(uint32_t));
250                 if (num_elements) {
251                         printf("Scan options:\n");
252                         for (i = 0; i < num_elements; i++) {
253                                 if (!(srci = sr_config_info_get(opts[i] & SR_CONF_MASK)))
254                                         continue;
255                                 printf("    %s\n", srci->id);
256                         }
257                 }
258                 g_variant_unref(gvar_opts);
259         }
260 }
261
262 void show_dev_detail(void)
263 {
264         struct sr_dev_driver *driver_from_opt, *driver;
265         struct sr_dev_inst *sdi;
266         const struct sr_config_info *srci;
267         struct sr_channel *ch;
268         struct sr_channel_group *channel_group, *cg;
269         GSList *devices, *cgl, *chl, *channel_groups;
270         GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
271         gsize num_opts, num_elements;
272         double dlow, dhigh, dcur_low, dcur_high;
273         const uint64_t *uint64, p, q, low, high;
274         uint64_t tmp_uint64, cur_low, cur_high, cur_p, cur_q;
275         const uint32_t *opts;
276         const int32_t *int32;
277         uint32_t key, o;
278         unsigned int num_devices, i;
279         char *tmp_str, *s, c;
280         const char **stropts;
281
282         if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
283                 /* A driver was specified, report driver-wide options now. */
284                 show_drv_detail(driver_from_opt);
285         }
286
287         if (!(devices = device_scan())) {
288                 g_critical("No devices found.");
289                 return;
290         }
291
292         num_devices = g_slist_length(devices);
293         if (num_devices > 1) {
294                 g_critical("%d devices found. Use --scan to show them, "
295                                 "and select one to show.", num_devices);
296                 return;
297         }
298
299         sdi = devices->data;
300         g_slist_free(devices);
301         print_dev_line(sdi);
302
303         driver = sr_dev_inst_driver_get(sdi);
304         channel_groups = sr_dev_inst_channel_groups_get(sdi);
305
306         if (sr_dev_open(sdi) != SR_OK) {
307                 g_critical("Failed to open device.");
308                 return;
309         }
310
311         /* Selected channels and channel group may affect which options are
312          * returned, or which values for them. */
313         select_channels(sdi);
314         channel_group = select_channel_group(sdi);
315
316         if (sr_config_list(driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
317                         &gvar_opts) != SR_OK)
318                 /* Driver supports no device instance options. */
319                 return;
320
321         if (channel_groups) {
322                 printf("Channel groups:\n");
323                 for (cgl = channel_groups; cgl; cgl = cgl->next) {
324                         cg = cgl->data;
325                         printf("    %s: channel%s", cg->name,
326                                         g_slist_length(cg->channels) > 1 ? "s" : "");
327                         for (chl = cg->channels; chl; chl = chl->next) {
328                                 ch = chl->data;
329                                 printf(" %s", ch->name);
330                         }
331                         printf("\n");
332                 }
333         }
334
335         printf("Supported configuration options");
336         if (channel_groups) {
337                 if (!channel_group)
338                         printf(" across all channel groups");
339                 else
340                         printf(" on channel group %s", channel_group->name);
341         }
342         printf(":\n");
343         opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
344         for (o = 0; o < num_opts; o++) {
345                 key = opts[o] & SR_CONF_MASK;
346                 if (!(srci = sr_config_info_get(key)))
347                         continue;
348
349                 if (key == SR_CONF_TRIGGER_MATCH) {
350                         if (maybe_config_list(driver, sdi, channel_group, key,
351                                         &gvar_list) != SR_OK) {
352                                 printf("\n");
353                                 continue;
354                         }
355                         int32 = g_variant_get_fixed_array(gvar_list,
356                                         &num_elements, sizeof(int32_t));
357                         printf("    Supported triggers: ");
358                         for (i = 0; i < num_elements; i++) {
359                                 switch(int32[i]) {
360                                 case SR_TRIGGER_ZERO:
361                                         c = '0';
362                                         break;
363                                 case SR_TRIGGER_ONE:
364                                         c = '1';
365                                         break;
366                                 case SR_TRIGGER_RISING:
367                                         c = 'r';
368                                         break;
369                                 case SR_TRIGGER_FALLING:
370                                         c = 'f';
371                                         break;
372                                 case SR_TRIGGER_EDGE:
373                                         c = 'e';
374                                         break;
375                                 case SR_TRIGGER_OVER:
376                                         c = 'o';
377                                         break;
378                                 case SR_TRIGGER_UNDER:
379                                         c = 'u';
380                                         break;
381                                 default:
382                                         c = 0;
383                                         break;
384                                 }
385                                 if (c)
386                                         printf("%c ", c);
387                         }
388                         printf("\n");
389                         g_variant_unref(gvar_list);
390
391                 } else if (key == SR_CONF_LIMIT_SAMPLES
392                                 && config_key_has_cap(driver, sdi, cg, key, SR_CONF_LIST)) {
393                         /* If implemented in config_list(), this denotes the
394                          * maximum number of samples a device can send. This
395                          * really applies only to logic analyzers, and then
396                          * only to those that don't support compression, or
397                          * have it turned off by default. The values returned
398                          * are the low/high limits. */
399                         if (sr_config_list(driver, sdi, channel_group, key,
400                                         &gvar) == SR_OK) {
401                                 g_variant_get(gvar, "(tt)", &low, &high);
402                                 g_variant_unref(gvar);
403                                 printf("    Maximum number of samples: %"PRIu64"\n", high);
404                         }
405
406                 } else if (key == SR_CONF_SAMPLERATE) {
407                         /* Supported samplerates */
408                         printf("    %s", srci->id);
409                         if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
410                                         &gvar_dict) != SR_OK) {
411                                 printf("\n");
412                                 continue;
413                         }
414                         if ((gvar_list = g_variant_lookup_value(gvar_dict,
415                                         "samplerates", G_VARIANT_TYPE("at")))) {
416                                 uint64 = g_variant_get_fixed_array(gvar_list,
417                                                 &num_elements, sizeof(uint64_t));
418                                 printf(" - supported samplerates:\n");
419                                 for (i = 0; i < num_elements; i++) {
420                                         if (!(s = sr_samplerate_string(uint64[i])))
421                                                 continue;
422                                         printf("      %s\n", s);
423                                         g_free(s);
424                                 }
425                                 g_variant_unref(gvar_list);
426                         } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
427                                         "samplerate-steps", G_VARIANT_TYPE("at")))) {
428                                 uint64 = g_variant_get_fixed_array(gvar_list,
429                                                 &num_elements, sizeof(uint64_t));
430                                 /* low */
431                                 if (!(s = sr_samplerate_string(uint64[0])))
432                                         continue;
433                                 printf(" (%s", s);
434                                 g_free(s);
435                                 /* high */
436                                 if (!(s = sr_samplerate_string(uint64[1])))
437                                         continue;
438                                 printf(" - %s", s);
439                                 g_free(s);
440                                 /* step */
441                                 if (!(s = sr_samplerate_string(uint64[2])))
442                                         continue;
443                                 printf(" in steps of %s)\n", s);
444                                 g_free(s);
445                                 g_variant_unref(gvar_list);
446                         }
447                         g_variant_unref(gvar_dict);
448
449                 } else if (srci->datatype == SR_T_UINT64) {
450                         printf("    %s: ", srci->id);
451                         gvar = NULL;
452                         if (maybe_config_get(driver, sdi, channel_group, key,
453                                         &gvar) == SR_OK) {
454                                 tmp_uint64 = g_variant_get_uint64(gvar);
455                                 g_variant_unref(gvar);
456                         } else
457                                 tmp_uint64 = 0;
458                         if (maybe_config_list(driver, sdi, channel_group,
459                                         key, &gvar_list) != SR_OK) {
460                                 if (gvar) {
461                                         /* Can't list it, but we have a value to show. */
462                                         printf("%"PRIu64" (current)", tmp_uint64);
463                                 }
464                                 printf("\n");
465                                 continue;
466                         }
467                         uint64 = g_variant_get_fixed_array(gvar_list,
468                                         &num_elements, sizeof(uint64_t));
469                         printf(" - supported values:\n");
470                         for (i = 0; i < num_elements; i++) {
471                                 printf("      %"PRIu64, uint64[i]);
472                                 if (gvar && tmp_uint64 == uint64[i])
473                                         printf(" (current)");
474                                 printf("\n");
475                         }
476                         g_variant_unref(gvar_list);
477
478                 } else if (srci->datatype == SR_T_STRING) {
479                         printf("    %s: ", srci->id);
480                         if (maybe_config_get(driver, sdi, channel_group, key,
481                                         &gvar) == SR_OK) {
482                                 tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
483                                 g_variant_unref(gvar);
484                         } else
485                                 tmp_str = NULL;
486
487                         if (maybe_config_list(driver, sdi, channel_group, key,
488                                         &gvar) != SR_OK) {
489                                 if (tmp_str) {
490                                         /* Can't list it, but we have a value to show. */
491                                         printf("%s (current)", tmp_str);
492                                 }
493                                 printf("\n");
494                                 g_free(tmp_str);
495                                 continue;
496                         }
497
498                         stropts = g_variant_get_strv(gvar, &num_elements);
499                         for (i = 0; i < num_elements; i++) {
500                                 if (i)
501                                         printf(", ");
502                                 printf("%s", stropts[i]);
503                                 if (tmp_str && !strcmp(tmp_str, stropts[i]))
504                                         printf(" (current)");
505                         }
506                         printf("\n");
507                         g_free(stropts);
508                         g_free(tmp_str);
509                         g_variant_unref(gvar);
510
511                 } else if (srci->datatype == SR_T_UINT64_RANGE) {
512                         printf("    %s: ", srci->id);
513                         if (maybe_config_list(driver, sdi, channel_group, key,
514                                         &gvar_list) != SR_OK) {
515                                 printf("\n");
516                                 continue;
517                         }
518
519                         if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
520                                 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
521                                 g_variant_unref(gvar);
522                         } else {
523                                 cur_low = 0;
524                                 cur_high = 0;
525                         }
526
527                         num_elements = g_variant_n_children(gvar_list);
528                         for (i = 0; i < num_elements; i++) {
529                                 gvar = g_variant_get_child_value(gvar_list, i);
530                                 g_variant_get(gvar, "(tt)", &low, &high);
531                                 g_variant_unref(gvar);
532                                 if (i)
533                                         printf(", ");
534                                 printf("%"PRIu64"-%"PRIu64, low, high);
535                                 if (low == cur_low && high == cur_high)
536                                         printf(" (current)");
537                         }
538                         printf("\n");
539                         g_variant_unref(gvar_list);
540
541                 } else if (srci->datatype == SR_T_BOOL) {
542                         printf("    %s: ", srci->id);
543                         if (maybe_config_get(driver, sdi, channel_group, key,
544                                         &gvar) == SR_OK) {
545                                 if (g_variant_get_boolean(gvar))
546                                         printf("on (current), off\n");
547                                 else
548                                         printf("on, off (current)\n");
549                                 g_variant_unref(gvar);
550                         } else
551                                 printf("on, off\n");
552
553                 } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
554                         printf("    %s: ", srci->id);
555                         if (maybe_config_list(driver, sdi, channel_group, key,
556                                         &gvar_list) != SR_OK) {
557                                 printf("\n");
558                                 continue;
559                         }
560
561                         if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
562                                 g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
563                                 g_variant_unref(gvar);
564                         } else {
565                                 dcur_low = 0;
566                                 dcur_high = 0;
567                         }
568
569                         num_elements = g_variant_n_children(gvar_list);
570                         for (i = 0; i < num_elements; i++) {
571                                 gvar = g_variant_get_child_value(gvar_list, i);
572                                 g_variant_get(gvar, "(dd)", &dlow, &dhigh);
573                                 g_variant_unref(gvar);
574                                 if (i)
575                                         printf(", ");
576                                 printf("%.1f-%.1f", dlow, dhigh);
577                                 if (dlow == dcur_low && dhigh == dcur_high)
578                                         printf(" (current)");
579                         }
580                         printf("\n");
581                         g_variant_unref(gvar_list);
582
583                 } else if (srci->datatype == SR_T_FLOAT) {
584                         printf("    %s: ", srci->id);
585                         if (maybe_config_get(driver, sdi, channel_group, key,
586                                         &gvar) == SR_OK) {
587                                 printf("%f\n", g_variant_get_double(gvar));
588                                 g_variant_unref(gvar);
589                         } else
590                                 printf("\n");
591
592                 } else if (srci->datatype == SR_T_RATIONAL_PERIOD
593                                 || srci->datatype == SR_T_RATIONAL_VOLT) {
594                         printf("    %s", srci->id);
595                         if (maybe_config_get(driver, sdi, channel_group, key,
596                                         &gvar) == SR_OK) {
597                                 g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
598                                 g_variant_unref(gvar);
599                         } else
600                                 cur_p = cur_q = 0;
601
602                         if (maybe_config_list(driver, sdi, channel_group,
603                                         key, &gvar_list) != SR_OK) {
604                                 printf("\n");
605                                 continue;
606                         }
607                         printf(" - supported values:\n");
608                         num_elements = g_variant_n_children(gvar_list);
609                         for (i = 0; i < num_elements; i++) {
610                                 gvar = g_variant_get_child_value(gvar_list, i);
611                                 g_variant_get(gvar, "(tt)", &p, &q);
612                                 if (srci->datatype == SR_T_RATIONAL_PERIOD)
613                                         s = sr_period_string(p * q);
614                                 else
615                                         s = sr_voltage_string(p, q);
616                                 printf("      %s", s);
617                                 g_free(s);
618                                 if (p == cur_p && q == cur_q)
619                                         printf(" (current)");
620                                 printf("\n");
621                         }
622                         g_variant_unref(gvar_list);
623
624                 } else {
625
626                         /* Everything else */
627                         printf("    %s\n", srci->id);
628                 }
629         }
630         g_variant_unref(gvar_opts);
631
632         sr_dev_close(sdi);
633
634 }
635
636 #ifdef HAVE_SRD
637 void show_pd_detail(void)
638 {
639         struct srd_decoder *dec;
640         struct srd_decoder_option *o;
641         struct srd_channel *pdch;
642         struct srd_decoder_annotation_row *r;
643         GSList *l, *ll, *ol;
644         int idx;
645         char **pdtokens, **pdtok, *optsep, **ann, *val, *doc;
646
647         pdtokens = g_strsplit(opt_pds, ",", -1);
648         for (pdtok = pdtokens; *pdtok; pdtok++) {
649                 /* Strip options. */
650                 if ((optsep = strchr(*pdtok, ':')))
651                         *optsep = '\0';
652                 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
653                         g_critical("Protocol decoder %s not found.", *pdtok);
654                         return;
655                 }
656                 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
657                                 dec->id, dec->name, dec->longname, dec->desc);
658                 printf("License: %s\n", dec->license);
659                 printf("Annotation classes:\n");
660                 if (dec->annotations) {
661                         for (l = dec->annotations; l; l = l->next) {
662                                 ann = l->data;
663                                 printf("- %s: %s\n", ann[0], ann[1]);
664                         }
665                 } else {
666                         printf("None.\n");
667                 }
668                 printf("Annotation rows:\n");
669                 if (dec->annotation_rows) {
670                         for (l = dec->annotation_rows; l; l = l->next) {
671                                 r = l->data;
672                                 printf("- %s (%s): ", r->id, r->desc);
673                                 for (ll = r->ann_classes; ll; ll = ll->next) {
674                                         idx = GPOINTER_TO_INT(ll->data);
675                                         ann = g_slist_nth_data(dec->annotations, idx);
676                                         printf("%s", ann[0]);
677                                         if (ll->next)
678                                                 printf(", ");
679                                 }
680                                 printf("\n");
681                         }
682                 } else {
683                         printf("None.\n");
684                 }
685                 printf("Required channels:\n");
686                 if (dec->channels) {
687                         for (l = dec->channels; l; l = l->next) {
688                                 pdch = l->data;
689                                 printf("- %s (%s): %s\n",
690                                        pdch->id, pdch->name, pdch->desc);
691                         }
692                 } else {
693                         printf("None.\n");
694                 }
695                 printf("Optional channels:\n");
696                 if (dec->opt_channels) {
697                         for (l = dec->opt_channels; l; l = l->next) {
698                                 pdch = l->data;
699                                 printf("- %s (%s): %s\n",
700                                        pdch->id, pdch->name, pdch->desc);
701                         }
702                 } else {
703                         printf("None.\n");
704                 }
705                 printf("Options:\n");
706                 if (dec->options) {
707                         for (l = dec->options; l; l = l->next) {
708                                 o = l->data;
709                                 printf("- %s: %s (", o->id, o->desc);
710                                 for (ol = o->values; ol; ol = ol->next) {
711                                         val = g_variant_print(ol->data, FALSE);
712                                         printf("%s, ", val);
713                                         g_free(val);
714                                 }
715                                 val = g_variant_print(o->def, FALSE);
716                                 printf("default %s)\n", val);
717                                 g_free(val);
718                         }
719                 } else {
720                         printf("None.\n");
721                 }
722                 if ((doc = srd_decoder_doc_get(dec))) {
723                         printf("Documentation:\n%s\n",
724                                doc[0] == '\n' ? doc + 1 : doc);
725                         g_free(doc);
726                 }
727         }
728
729         g_strfreev(pdtokens);
730 }
731 #endif
732
733 void show_input(void)
734 {
735         const struct sr_input_module *imod;
736         const struct sr_option **opts;
737         GSList *l;
738         int i;
739         char *s, **tok;
740
741         tok = g_strsplit(opt_input_format, ":", 0);
742         if (!tok[0] || !(imod = sr_input_find(tok[0])))
743                 g_critical("Input module '%s' not found.", opt_input_format);
744
745         printf("ID: %s\nName: %s\n", sr_input_id_get(imod),
746                         sr_input_name_get(imod));
747         printf("Description: %s\n", sr_input_description_get(imod));
748         if ((opts = sr_input_options_get(imod))) {
749                 printf("Options:\n");
750                 for (i = 0; opts[i]; i++) {
751                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
752                         if (opts[i]->def) {
753                                 s = g_variant_print(opts[i]->def, FALSE);
754                                 printf(" (default %s", s);
755                                 g_free(s);
756                                 if (opts[i]->values) {
757                                         printf(", possible values ");
758                                         for (l = opts[i]->values; l; l = l->next) {
759                                                 s = g_variant_print((GVariant *)l->data, FALSE);
760                                                 printf("%s%s", s, l->next ? ", " : "");
761                                                 g_free(s);
762                                         }
763                                 }
764                                 printf(")");
765                         }
766                         printf("\n");
767                 }
768                 sr_input_options_free(opts);
769         }
770         g_strfreev(tok);
771 }
772
773 void show_output(void)
774 {
775         const struct sr_output_module *omod;
776         const struct sr_option **opts;
777         GSList *l;
778         int i;
779         char *s, **tok;
780
781         tok = g_strsplit(opt_output_format, ":", 0);
782         if (!tok[0] || !(omod = sr_output_find(tok[0])))
783                 g_critical("Output module '%s' not found.", opt_output_format);
784
785         printf("ID: %s\nName: %s\n", sr_output_id_get(omod),
786                         sr_output_name_get(omod));
787         printf("Description: %s\n", sr_output_description_get(omod));
788         if ((opts = sr_output_options_get(omod))) {
789                 printf("Options:\n");
790                 for (i = 0; opts[i]; i++) {
791                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
792                         if (opts[i]->def) {
793                                 s = g_variant_print(opts[i]->def, FALSE);
794                                 printf(" (default %s", s);
795                                 g_free(s);
796                                 if (opts[i]->values) {
797                                         printf(", possible values ");
798                                         for (l = opts[i]->values; l; l = l->next) {
799                                                 s = g_variant_print((GVariant *)l->data, FALSE);
800                                                 printf("%s%s", s, l->next ? ", " : "");
801                                                 g_free(s);
802                                         }
803                                 }
804                                 printf(")");
805                         }
806                         printf("\n");
807                 }
808                 sr_output_options_free(opts);
809         }
810         g_strfreev(tok);
811 }
812
813 void show_transform(void)
814 {
815         const struct sr_transform_module *tmod;
816         const struct sr_option **opts;
817         GSList *l;
818         int i;
819         char *s, **tok;
820
821         tok = g_strsplit(opt_transform_module, ":", 0);
822         if (!tok[0] || !(tmod = sr_transform_find(tok[0])))
823                 g_critical("Transform module '%s' not found.", opt_transform_module);
824
825         printf("ID: %s\nName: %s\n", sr_transform_id_get(tmod),
826                         sr_transform_name_get(tmod));
827         printf("Description: %s\n", sr_transform_description_get(tmod));
828         if ((opts = sr_transform_options_get(tmod))) {
829                 printf("Options:\n");
830                 for (i = 0; opts[i]; i++) {
831                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
832                         if (opts[i]->def) {
833                                 s = g_variant_print(opts[i]->def, FALSE);
834                                 printf(" (default %s", s);
835                                 g_free(s);
836                                 if (opts[i]->values) {
837                                         printf(", possible values ");
838                                         for (l = opts[i]->values; l; l = l->next) {
839                                                 s = g_variant_print((GVariant *)l->data, FALSE);
840                                                 printf("%s%s", s, l->next ? ", " : "");
841                                                 g_free(s);
842                                         }
843                                 }
844                                 printf(")");
845                         }
846                         printf("\n");
847                 }
848                 sr_transform_options_free(opts);
849         }
850         g_strfreev(tok);
851 }