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