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