]> sigrok.org Git - sigrok-cli.git/blob - show.c
Make sure to treat all config keys as uint32_t.
[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_dev_detail(void)
197 {
198         struct sr_dev_inst *sdi;
199         const struct sr_config_info *srci;
200         struct sr_channel *ch;
201         struct sr_channel_group *channel_group, *cg;
202         GSList *devices, *cgl, *chl;
203         GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
204         gsize num_opts, num_elements;
205         double dlow, dhigh, dcur_low, dcur_high;
206         const uint64_t *uint64, p, q, low, high;
207         uint64_t cur_low, cur_high;
208         const uint32_t *opts;
209         const int32_t *int32;
210         uint32_t key, o;
211         unsigned int num_devices, i;
212         char *tmp_str, *s, c;
213         const char **stropts;
214
215         if (!(devices = device_scan())) {
216                 g_critical("No devices found.");
217                 return;
218         }
219
220         num_devices = g_slist_length(devices);
221         if (num_devices > 1) {
222                 g_critical("%d devices found. Use --scan to show them, "
223                                 "and select one to show.", num_devices);
224                 return;
225         }
226
227         sdi = devices->data;
228         g_slist_free(devices);
229         print_dev_line(sdi);
230
231         if (sr_dev_open(sdi) != SR_OK) {
232                 g_critical("Failed to open device.");
233                 return;
234         }
235
236         if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
237                         &gvar_opts) == SR_OK)) {
238                 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
239                                 sizeof(int32_t));
240                 printf("Supported driver options:\n");
241                 for (i = 0; i < num_elements; i++) {
242                         if (!(srci = sr_config_info_get(opts[i])))
243                                 continue;
244                         printf("    %s\n", srci->id);
245                 }
246                 g_variant_unref(gvar_opts);
247         }
248
249         /* Selected channels and channel group may affect which options are
250          * returned, or which values for them. */
251         select_channels(sdi);
252         channel_group = select_channel_group(sdi);
253
254         if ((sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
255                         &gvar_opts)) != SR_OK)
256                 /* Driver supports no device instance options. */
257                 return;
258
259         if (sdi->channel_groups) {
260                 printf("Channel groups:\n");
261                 for (cgl = sdi->channel_groups; cgl; cgl = cgl->next) {
262                         cg = cgl->data;
263                         printf("    %s: channel%s", cg->name,
264                                         g_slist_length(cg->channels) > 1 ? "s" : "");
265                         for (chl = cg->channels; chl; chl = chl->next) {
266                                 ch = chl->data;
267                                 printf(" %s", ch->name);
268                         }
269                         printf("\n");
270                 }
271         }
272
273         printf("Supported configuration options");
274         if (sdi->channel_groups) {
275                 if (!channel_group)
276                         printf(" across all channel groups");
277                 else
278                         printf(" on channel group %s", channel_group->name);
279         }
280         printf(":\n");
281         opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
282         for (o = 0; o < num_opts; o++) {
283                 key = opts[o] & SR_CONF_MASK;
284                 if (!(srci = sr_config_info_get(key)))
285                         continue;
286
287                 if (key == SR_CONF_TRIGGER_MATCH) {
288                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
289                                         &gvar_list) != SR_OK) {
290                                 printf("\n");
291                                 continue;
292                         }
293                         int32 = g_variant_get_fixed_array(gvar_list,
294                                         &num_elements, sizeof(int32_t));
295                         printf("    Supported triggers: ");
296                         for (i = 0; i < num_elements; i++) {
297                                 switch(int32[i]) {
298                                 case SR_TRIGGER_ZERO:
299                                         c = '0';
300                                         break;
301                                 case SR_TRIGGER_ONE:
302                                         c = '1';
303                                         break;
304                                 case SR_TRIGGER_RISING:
305                                         c = 'r';
306                                         break;
307                                 case SR_TRIGGER_FALLING:
308                                         c = 'f';
309                                         break;
310                                 case SR_TRIGGER_EDGE:
311                                         c = 'e';
312                                         break;
313                                 case SR_TRIGGER_OVER:
314                                         c = 'o';
315                                         break;
316                                 case SR_TRIGGER_UNDER:
317                                         c = 'u';
318                                         break;
319                                 default:
320                                         c = 0;
321                                         break;
322                                 }
323                                 if (c)
324                                         printf("%c ", c);
325                         }
326                         printf("\n");
327                         g_variant_unref(gvar_list);
328
329                 } else if (key == SR_CONF_LIMIT_SAMPLES) {
330                         /* If implemented in config_list(), this denotes the
331                          * maximum number of samples a device can send. This
332                          * really applies only to logic analyzers, and then
333                          * only to those that don't support compression, or
334                          * have it turned off by default. The values returned
335                          * are the low/high limits. */
336                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
337                                         &gvar) != SR_OK) {
338                                 continue;
339                         }
340                         g_variant_get(gvar, "(tt)", &low, &high);
341                         g_variant_unref(gvar);
342                         printf("    Maximum number of samples: %"PRIu64"\n", high);
343
344                 } else if (key == SR_CONF_SAMPLERATE) {
345                         /* Supported samplerates */
346                         printf("    %s", srci->id);
347                         if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_SAMPLERATE,
348                                         &gvar_dict) != SR_OK) {
349                                 printf("\n");
350                                 continue;
351                         }
352                         if ((gvar_list = g_variant_lookup_value(gvar_dict,
353                                         "samplerates", G_VARIANT_TYPE("at")))) {
354                                 uint64 = g_variant_get_fixed_array(gvar_list,
355                                                 &num_elements, sizeof(uint64_t));
356                                 printf(" - supported samplerates:\n");
357                                 for (i = 0; i < num_elements; i++) {
358                                         if (!(s = sr_samplerate_string(uint64[i])))
359                                                 continue;
360                                         printf("      %s\n", s);
361                                         g_free(s);
362                                 }
363                                 g_variant_unref(gvar_list);
364                         } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
365                                         "samplerate-steps", G_VARIANT_TYPE("at")))) {
366                                 uint64 = g_variant_get_fixed_array(gvar_list,
367                                                 &num_elements, sizeof(uint64_t));
368                                 /* low */
369                                 if (!(s = sr_samplerate_string(uint64[0])))
370                                         continue;
371                                 printf(" (%s", s);
372                                 g_free(s);
373                                 /* high */
374                                 if (!(s = sr_samplerate_string(uint64[1])))
375                                         continue;
376                                 printf(" - %s", s);
377                                 g_free(s);
378                                 /* step */
379                                 if (!(s = sr_samplerate_string(uint64[2])))
380                                         continue;
381                                 printf(" in steps of %s)\n", s);
382                                 g_free(s);
383                                 g_variant_unref(gvar_list);
384                         }
385                         g_variant_unref(gvar_dict);
386
387                 } else if (key == SR_CONF_BUFFERSIZE) {
388                         /* Supported buffer sizes */
389                         printf("    %s", srci->id);
390                         if (sr_config_list(sdi->driver, sdi, channel_group,
391                                         SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) {
392                                 printf("\n");
393                                 continue;
394                         }
395                         uint64 = g_variant_get_fixed_array(gvar_list,
396                                         &num_elements, sizeof(uint64_t));
397                         printf(" - supported buffer sizes:\n");
398                         for (i = 0; i < num_elements; i++)
399                                 printf("      %"PRIu64"\n", uint64[i]);
400                         g_variant_unref(gvar_list);
401
402                 } else if (key == SR_CONF_TIMEBASE) {
403                         /* Supported time bases */
404                         printf("    %s", srci->id);
405                         if (sr_config_list(sdi->driver, sdi, channel_group,
406                                         SR_CONF_TIMEBASE, &gvar_list) != SR_OK) {
407                                 printf("\n");
408                                 continue;
409                         }
410                         printf(" - supported time bases:\n");
411                         num_elements = g_variant_n_children(gvar_list);
412                         for (i = 0; i < num_elements; i++) {
413                                 gvar = g_variant_get_child_value(gvar_list, i);
414                                 g_variant_get(gvar, "(tt)", &p, &q);
415                                 s = sr_period_string(p * q);
416                                 printf("      %s\n", s);
417                                 g_free(s);
418                         }
419                         g_variant_unref(gvar_list);
420
421                 } else if (key == SR_CONF_VDIV) {
422                         /* Supported volts/div values */
423                         printf("    %s", srci->id);
424                         if (sr_config_list(sdi->driver, sdi, channel_group,
425                                         SR_CONF_VDIV, &gvar_list) != SR_OK) {
426                                 printf("\n");
427                                 continue;
428                         }
429                         printf(" - supported volts/div:\n");
430                         num_elements = g_variant_n_children(gvar_list);
431                         for (i = 0; i < num_elements; i++) {
432                                 gvar = g_variant_get_child_value(gvar_list, i);
433                                 g_variant_get(gvar, "(tt)", &p, &q);
434                                 s = sr_voltage_string(p, q);
435                                 printf("      %s\n", s);
436                                 g_free(s);
437                         }
438                         g_variant_unref(gvar_list);
439
440                 } else if (srci->datatype == SR_T_STRING) {
441                         printf("    %s: ", srci->id);
442                         if (sr_config_get(sdi->driver, sdi, channel_group, key,
443                                         &gvar) == SR_OK) {
444                                 tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
445                                 g_variant_unref(gvar);
446                         } else
447                                 tmp_str = NULL;
448
449                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
450                                         &gvar) != SR_OK) {
451                                 if (tmp_str) {
452                                         /* Can't list it, but we have a value to show. */
453                                         printf("%s (current)", tmp_str);
454                                 }
455                                 printf("\n");
456                                 continue;
457                         }
458
459                         stropts = g_variant_get_strv(gvar, &num_elements);
460                         for (i = 0; i < num_elements; i++) {
461                                 if (i)
462                                         printf(", ");
463                                 printf("%s", stropts[i]);
464                                 if (tmp_str && !strcmp(tmp_str, stropts[i]))
465                                         printf(" (current)");
466                         }
467                         printf("\n");
468                         g_free(stropts);
469                         g_free(tmp_str);
470                         g_variant_unref(gvar);
471
472                 } else if (srci->datatype == SR_T_UINT64_RANGE) {
473                         printf("    %s: ", srci->id);
474                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
475                                         &gvar_list) != SR_OK) {
476                                 printf("\n");
477                                 continue;
478                         }
479
480                         if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
481                                 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
482                                 g_variant_unref(gvar);
483                         } else {
484                                 cur_low = 0;
485                                 cur_high = 0;
486                         }
487
488                         num_elements = g_variant_n_children(gvar_list);
489                         for (i = 0; i < num_elements; i++) {
490                                 gvar = g_variant_get_child_value(gvar_list, i);
491                                 g_variant_get(gvar, "(tt)", &low, &high);
492                                 g_variant_unref(gvar);
493                                 if (i)
494                                         printf(", ");
495                                 printf("%"PRIu64"-%"PRIu64, low, high);
496                                 if (low == cur_low && high == cur_high)
497                                         printf(" (current)");
498                         }
499                         printf("\n");
500                         g_variant_unref(gvar_list);
501
502                 } else if (srci->datatype == SR_T_BOOL) {
503                         printf("    %s: ", srci->id);
504                         if (sr_config_get(sdi->driver, sdi, channel_group, key,
505                                         &gvar) == SR_OK) {
506                                 if (g_variant_get_boolean(gvar))
507                                         printf("on (current), off\n");
508                                 else
509                                         printf("on, off (current)\n");
510                                 g_variant_unref(gvar);
511                         } else
512                                 printf("on, off\n");
513
514                 } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
515                         printf("    %s: ", srci->id);
516                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
517                                         &gvar_list) != SR_OK) {
518                                 printf("\n");
519                                 continue;
520                         }
521
522                         if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
523                                 g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
524                                 g_variant_unref(gvar);
525                         } else {
526                                 dcur_low = 0;
527                                 dcur_high = 0;
528                         }
529
530                         num_elements = g_variant_n_children(gvar_list);
531                         for (i = 0; i < num_elements; i++) {
532                                 gvar = g_variant_get_child_value(gvar_list, i);
533                                 g_variant_get(gvar, "(dd)", &dlow, &dhigh);
534                                 g_variant_unref(gvar);
535                                 if (i)
536                                         printf(", ");
537                                 printf("%.1f-%.1f", dlow, dhigh);
538                                 if (dlow == dcur_low && dhigh == dcur_high)
539                                         printf(" (current)");
540                         }
541                         printf("\n");
542                         g_variant_unref(gvar_list);
543
544                 } else if (srci->datatype == SR_T_FLOAT) {
545                         printf("    %s: ", srci->id);
546                         if (sr_config_get(sdi->driver, sdi, channel_group, key,
547                                         &gvar) == SR_OK) {
548                                 printf("%f\n", g_variant_get_double(gvar));
549                                 g_variant_unref(gvar);
550                         } else
551                                 printf("on, off\n");
552
553                 } else {
554
555                         /* Everything else */
556                         printf("    %s\n", srci->id);
557                 }
558         }
559         g_variant_unref(gvar_opts);
560
561         sr_dev_close(sdi);
562
563 }
564
565 #ifdef HAVE_SRD
566 void show_pd_detail(void)
567 {
568         struct srd_decoder *dec;
569         struct srd_decoder_option *o;
570         struct srd_channel *pdch;
571         struct srd_decoder_annotation_row *r;
572         GSList *l, *ll, *ol;
573         int idx;
574         char **pdtokens, **pdtok, *optsep, **ann, *val, *doc;
575
576         pdtokens = g_strsplit(opt_pds, ",", -1);
577         for (pdtok = pdtokens; *pdtok; pdtok++) {
578                 /* Strip options. */
579                 if ((optsep = strchr(*pdtok, ':')))
580                         *optsep = '\0';
581                 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
582                         g_critical("Protocol decoder %s not found.", *pdtok);
583                         return;
584                 }
585                 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
586                                 dec->id, dec->name, dec->longname, dec->desc);
587                 printf("License: %s\n", dec->license);
588                 printf("Annotation classes:\n");
589                 if (dec->annotations) {
590                         for (l = dec->annotations; l; l = l->next) {
591                                 ann = l->data;
592                                 printf("- %s: %s\n", ann[0], ann[1]);
593                         }
594                 } else {
595                         printf("None.\n");
596                 }
597                 printf("Annotation rows:\n");
598                 if (dec->annotation_rows) {
599                         for (l = dec->annotation_rows; l; l = l->next) {
600                                 r = l->data;
601                                 printf("- %s (%s): ", r->id, r->desc);
602                                 for (ll = r->ann_classes; ll; ll = ll->next) {
603                                         idx = GPOINTER_TO_INT(ll->data);
604                                         ann = g_slist_nth_data(dec->annotations, idx);
605                                         printf("%s", ann[0]);
606                                         if (ll->next)
607                                                 printf(", ");
608                                 }
609                                 printf("\n");
610                         }
611                 } else {
612                         printf("None.\n");
613                 }
614                 printf("Required channels:\n");
615                 if (dec->channels) {
616                         for (l = dec->channels; l; l = l->next) {
617                                 pdch = l->data;
618                                 printf("- %s (%s): %s\n",
619                                        pdch->id, pdch->name, pdch->desc);
620                         }
621                 } else {
622                         printf("None.\n");
623                 }
624                 printf("Optional channels:\n");
625                 if (dec->opt_channels) {
626                         for (l = dec->opt_channels; l; l = l->next) {
627                                 pdch = l->data;
628                                 printf("- %s (%s): %s\n",
629                                        pdch->id, pdch->name, pdch->desc);
630                         }
631                 } else {
632                         printf("None.\n");
633                 }
634                 printf("Options:\n");
635                 if (dec->options) {
636                         for (l = dec->options; l; l = l->next) {
637                                 o = l->data;
638                                 printf("- %s: %s (", o->id, o->desc);
639                                 for (ol = o->values; ol; ol = ol->next) {
640                                         val = g_variant_print(ol->data, FALSE);
641                                         printf("%s, ", val);
642                                         g_free(val);
643                                 }
644                                 val = g_variant_print(o->def, FALSE);
645                                 printf("default %s)\n", val);
646                                 g_free(val);
647                         }
648                 } else {
649                         printf("None.\n");
650                 }
651                 if ((doc = srd_decoder_doc_get(dec))) {
652                         printf("Documentation:\n%s\n",
653                                doc[0] == '\n' ? doc + 1 : doc);
654                         g_free(doc);
655                 }
656         }
657
658         g_strfreev(pdtokens);
659 }
660 #endif
661
662 void show_input(void)
663 {
664         const struct sr_input_module *imod;
665         const struct sr_option **opts;
666         GSList *l;
667         int i;
668         char *s, **tok;
669
670         tok = g_strsplit(opt_input_format, ":", 0);
671         if (!tok[0] || !(imod = sr_input_find(tok[0])))
672                 g_critical("Input module '%s' not found.", opt_input_format);
673
674         printf("ID: %s\nName: %s\n", sr_input_id_get(imod),
675                         sr_input_name_get(imod));
676         printf("Description: %s\n", sr_input_description_get(imod));
677         if ((opts = sr_input_options_get(imod))) {
678                 printf("Options:\n");
679                 for (i = 0; opts[i]; i++) {
680                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
681                         if (opts[i]->def) {
682                                 s = g_variant_print(opts[i]->def, FALSE);
683                                 printf(" (default %s", s);
684                                 g_free(s);
685                                 if (opts[i]->values) {
686                                         printf(", possible values ");
687                                         for (l = opts[i]->values; l; l = l->next) {
688                                                 s = g_variant_print((GVariant *)l->data, FALSE);
689                                                 printf("%s%s", s, l->next ? ", " : "");
690                                                 g_free(s);
691                                         }
692                                 }
693                                 printf(")");
694                         }
695                         printf("\n");
696                 }
697                 sr_input_options_free(opts);
698         }
699         g_strfreev(tok);
700 }
701
702 void show_output(void)
703 {
704         const struct sr_output_module *omod;
705         const struct sr_option **opts;
706         GSList *l;
707         int i;
708         char *s, **tok;
709
710         tok = g_strsplit(opt_output_format, ":", 0);
711         if (!tok[0] || !(omod = sr_output_find(tok[0])))
712                 g_critical("Output module '%s' not found.", opt_output_format);
713
714         printf("ID: %s\nName: %s\n", sr_output_id_get(omod),
715                         sr_output_name_get(omod));
716         printf("Description: %s\n", sr_output_description_get(omod));
717         if ((opts = sr_output_options_get(omod))) {
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_output_options_free(opts);
738         }
739         g_strfreev(tok);
740 }
741