Fix memory leak.
[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                                 g_free(tmp_str);
457                                 continue;
458                         }
459
460                         stropts = g_variant_get_strv(gvar, &num_elements);
461                         for (i = 0; i < num_elements; i++) {
462                                 if (i)
463                                         printf(", ");
464                                 printf("%s", stropts[i]);
465                                 if (tmp_str && !strcmp(tmp_str, stropts[i]))
466                                         printf(" (current)");
467                         }
468                         printf("\n");
469                         g_free(stropts);
470                         g_free(tmp_str);
471                         g_variant_unref(gvar);
472
473                 } else if (srci->datatype == SR_T_UINT64_RANGE) {
474                         printf("    %s: ", srci->id);
475                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
476                                         &gvar_list) != SR_OK) {
477                                 printf("\n");
478                                 continue;
479                         }
480
481                         if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
482                                 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
483                                 g_variant_unref(gvar);
484                         } else {
485                                 cur_low = 0;
486                                 cur_high = 0;
487                         }
488
489                         num_elements = g_variant_n_children(gvar_list);
490                         for (i = 0; i < num_elements; i++) {
491                                 gvar = g_variant_get_child_value(gvar_list, i);
492                                 g_variant_get(gvar, "(tt)", &low, &high);
493                                 g_variant_unref(gvar);
494                                 if (i)
495                                         printf(", ");
496                                 printf("%"PRIu64"-%"PRIu64, low, high);
497                                 if (low == cur_low && high == cur_high)
498                                         printf(" (current)");
499                         }
500                         printf("\n");
501                         g_variant_unref(gvar_list);
502
503                 } else if (srci->datatype == SR_T_BOOL) {
504                         printf("    %s: ", srci->id);
505                         if (sr_config_get(sdi->driver, sdi, channel_group, key,
506                                         &gvar) == SR_OK) {
507                                 if (g_variant_get_boolean(gvar))
508                                         printf("on (current), off\n");
509                                 else
510                                         printf("on, off (current)\n");
511                                 g_variant_unref(gvar);
512                         } else
513                                 printf("on, off\n");
514
515                 } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
516                         printf("    %s: ", srci->id);
517                         if (sr_config_list(sdi->driver, sdi, channel_group, key,
518                                         &gvar_list) != SR_OK) {
519                                 printf("\n");
520                                 continue;
521                         }
522
523                         if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
524                                 g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
525                                 g_variant_unref(gvar);
526                         } else {
527                                 dcur_low = 0;
528                                 dcur_high = 0;
529                         }
530
531                         num_elements = g_variant_n_children(gvar_list);
532                         for (i = 0; i < num_elements; i++) {
533                                 gvar = g_variant_get_child_value(gvar_list, i);
534                                 g_variant_get(gvar, "(dd)", &dlow, &dhigh);
535                                 g_variant_unref(gvar);
536                                 if (i)
537                                         printf(", ");
538                                 printf("%.1f-%.1f", dlow, dhigh);
539                                 if (dlow == dcur_low && dhigh == dcur_high)
540                                         printf(" (current)");
541                         }
542                         printf("\n");
543                         g_variant_unref(gvar_list);
544
545                 } else if (srci->datatype == SR_T_FLOAT) {
546                         printf("    %s: ", srci->id);
547                         if (sr_config_get(sdi->driver, sdi, channel_group, key,
548                                         &gvar) == SR_OK) {
549                                 printf("%f\n", g_variant_get_double(gvar));
550                                 g_variant_unref(gvar);
551                         } else
552                                 printf("on, off\n");
553
554                 } else {
555
556                         /* Everything else */
557                         printf("    %s\n", srci->id);
558                 }
559         }
560         g_variant_unref(gvar_opts);
561
562         sr_dev_close(sdi);
563
564 }
565
566 #ifdef HAVE_SRD
567 void show_pd_detail(void)
568 {
569         struct srd_decoder *dec;
570         struct srd_decoder_option *o;
571         struct srd_channel *pdch;
572         struct srd_decoder_annotation_row *r;
573         GSList *l, *ll, *ol;
574         int idx;
575         char **pdtokens, **pdtok, *optsep, **ann, *val, *doc;
576
577         pdtokens = g_strsplit(opt_pds, ",", -1);
578         for (pdtok = pdtokens; *pdtok; pdtok++) {
579                 /* Strip options. */
580                 if ((optsep = strchr(*pdtok, ':')))
581                         *optsep = '\0';
582                 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
583                         g_critical("Protocol decoder %s not found.", *pdtok);
584                         return;
585                 }
586                 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
587                                 dec->id, dec->name, dec->longname, dec->desc);
588                 printf("License: %s\n", dec->license);
589                 printf("Annotation classes:\n");
590                 if (dec->annotations) {
591                         for (l = dec->annotations; l; l = l->next) {
592                                 ann = l->data;
593                                 printf("- %s: %s\n", ann[0], ann[1]);
594                         }
595                 } else {
596                         printf("None.\n");
597                 }
598                 printf("Annotation rows:\n");
599                 if (dec->annotation_rows) {
600                         for (l = dec->annotation_rows; l; l = l->next) {
601                                 r = l->data;
602                                 printf("- %s (%s): ", r->id, r->desc);
603                                 for (ll = r->ann_classes; ll; ll = ll->next) {
604                                         idx = GPOINTER_TO_INT(ll->data);
605                                         ann = g_slist_nth_data(dec->annotations, idx);
606                                         printf("%s", ann[0]);
607                                         if (ll->next)
608                                                 printf(", ");
609                                 }
610                                 printf("\n");
611                         }
612                 } else {
613                         printf("None.\n");
614                 }
615                 printf("Required channels:\n");
616                 if (dec->channels) {
617                         for (l = dec->channels; l; l = l->next) {
618                                 pdch = l->data;
619                                 printf("- %s (%s): %s\n",
620                                        pdch->id, pdch->name, pdch->desc);
621                         }
622                 } else {
623                         printf("None.\n");
624                 }
625                 printf("Optional channels:\n");
626                 if (dec->opt_channels) {
627                         for (l = dec->opt_channels; l; l = l->next) {
628                                 pdch = l->data;
629                                 printf("- %s (%s): %s\n",
630                                        pdch->id, pdch->name, pdch->desc);
631                         }
632                 } else {
633                         printf("None.\n");
634                 }
635                 printf("Options:\n");
636                 if (dec->options) {
637                         for (l = dec->options; l; l = l->next) {
638                                 o = l->data;
639                                 printf("- %s: %s (", o->id, o->desc);
640                                 for (ol = o->values; ol; ol = ol->next) {
641                                         val = g_variant_print(ol->data, FALSE);
642                                         printf("%s, ", val);
643                                         g_free(val);
644                                 }
645                                 val = g_variant_print(o->def, FALSE);
646                                 printf("default %s)\n", val);
647                                 g_free(val);
648                         }
649                 } else {
650                         printf("None.\n");
651                 }
652                 if ((doc = srd_decoder_doc_get(dec))) {
653                         printf("Documentation:\n%s\n",
654                                doc[0] == '\n' ? doc + 1 : doc);
655                         g_free(doc);
656                 }
657         }
658
659         g_strfreev(pdtokens);
660 }
661 #endif
662
663 void show_input(void)
664 {
665         const struct sr_input_module *imod;
666         const struct sr_option **opts;
667         GSList *l;
668         int i;
669         char *s, **tok;
670
671         tok = g_strsplit(opt_input_format, ":", 0);
672         if (!tok[0] || !(imod = sr_input_find(tok[0])))
673                 g_critical("Input module '%s' not found.", opt_input_format);
674
675         printf("ID: %s\nName: %s\n", sr_input_id_get(imod),
676                         sr_input_name_get(imod));
677         printf("Description: %s\n", sr_input_description_get(imod));
678         if ((opts = sr_input_options_get(imod))) {
679                 printf("Options:\n");
680                 for (i = 0; opts[i]; i++) {
681                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
682                         if (opts[i]->def) {
683                                 s = g_variant_print(opts[i]->def, FALSE);
684                                 printf(" (default %s", s);
685                                 g_free(s);
686                                 if (opts[i]->values) {
687                                         printf(", possible values ");
688                                         for (l = opts[i]->values; l; l = l->next) {
689                                                 s = g_variant_print((GVariant *)l->data, FALSE);
690                                                 printf("%s%s", s, l->next ? ", " : "");
691                                                 g_free(s);
692                                         }
693                                 }
694                                 printf(")");
695                         }
696                         printf("\n");
697                 }
698                 sr_input_options_free(opts);
699         }
700         g_strfreev(tok);
701 }
702
703 void show_output(void)
704 {
705         const struct sr_output_module *omod;
706         const struct sr_option **opts;
707         GSList *l;
708         int i;
709         char *s, **tok;
710
711         tok = g_strsplit(opt_output_format, ":", 0);
712         if (!tok[0] || !(omod = sr_output_find(tok[0])))
713                 g_critical("Output module '%s' not found.", opt_output_format);
714
715         printf("ID: %s\nName: %s\n", sr_output_id_get(omod),
716                         sr_output_name_get(omod));
717         printf("Description: %s\n", sr_output_description_get(omod));
718         if ((opts = sr_output_options_get(omod))) {
719                 printf("Options:\n");
720                 for (i = 0; opts[i]; i++) {
721                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
722                         if (opts[i]->def) {
723                                 s = g_variant_print(opts[i]->def, FALSE);
724                                 printf(" (default %s", s);
725                                 g_free(s);
726                                 if (opts[i]->values) {
727                                         printf(", possible values ");
728                                         for (l = opts[i]->values; l; l = l->next) {
729                                                 s = g_variant_print((GVariant *)l->data, FALSE);
730                                                 printf("%s%s", s, l->next ? ", " : "");
731                                                 g_free(s);
732                                         }
733                                 }
734                                 printf(")");
735                         }
736                         printf("\n");
737                 }
738                 sr_output_options_free(opts);
739         }
740         g_strfreev(tok);
741 }
742