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