X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=show.c;h=0e865f8dbfe51faee9726b8b97a4778e1cd0eae4;hp=e1a5bad6cbb59981b1028953121c6046a3617c78;hb=dd2f206a287e1b13abf4307c940f874668d30113;hpb=02c659351bda97f77922356f48a7eed1d3137011 diff --git a/show.c b/show.c index e1a5bad..0e865f8 100644 --- a/show.c +++ b/show.c @@ -20,19 +20,49 @@ #include "sigrok-cli.h" #include "config.h" #include +#include extern gint opt_loglevel; extern gchar *opt_pds; +static gint sort_inputs(gconstpointer a, gconstpointer b) +{ + const struct sr_input_format *ia = a, *ib = b; + + return strcmp(ia->id, ib->id); +} + +static gint sort_outputs(gconstpointer a, gconstpointer b) +{ + const struct sr_output_format *oa = a, *ob = b; + + return strcmp(oa->id, ob->id); +} + +static gint sort_drivers(gconstpointer a, gconstpointer b) +{ + const struct sr_dev_driver *sdda = a, *sddb = b; + + return strcmp(sdda->name, sddb->name); +} + +static gint sort_pds(gconstpointer a, gconstpointer b) +{ + const struct srd_decoder *sda = a, *sdb = b; + + return strcmp(sda->id, sdb->id); +} + void show_version(void) { - struct sr_dev_driver **drivers; - struct sr_input_format **inputs; - struct sr_output_format **outputs; + struct sr_dev_driver **drivers, *driver; + struct sr_input_format **inputs, *input; + struct sr_output_format **outputs, *output; + const GSList *l; + GSList *sl; int i; #ifdef HAVE_SRD struct srd_decoder *dec; - const GSList *l; #endif printf("sigrok-cli %s\n\n", VERSION); @@ -46,45 +76,71 @@ void show_version(void) printf("Supported hardware drivers:\n"); drivers = sr_driver_list(); - for (i = 0; drivers[i]; i++) { - printf(" %-20s %s\n", drivers[i]->name, drivers[i]->longname); + for (sl = NULL, i = 0; drivers[i]; i++) + sl = g_slist_append(sl, drivers[i]); + sl = g_slist_sort(sl, sort_drivers); + for (l = sl; l; l = l->next) { + driver = l->data; + printf(" %-20s %s\n", driver->name, driver->longname); } printf("\n"); + g_slist_free(sl); printf("Supported input formats:\n"); inputs = sr_input_list(); - for (i = 0; inputs[i]; i++) - printf(" %-20s %s\n", inputs[i]->id, inputs[i]->description); + for (sl = NULL, i = 0; inputs[i]; i++) + sl = g_slist_append(sl, inputs[i]); + sl = g_slist_sort(sl, sort_inputs); + for (l = sl; l; l = l->next) { + input = l->data; + printf(" %-20s %s\n", input->id, input->description); + } printf("\n"); + g_slist_free(sl); printf("Supported output formats:\n"); outputs = sr_output_list(); - for (i = 0; outputs[i]; i++) - printf(" %-20s %s\n", outputs[i]->id, outputs[i]->description); - printf(" %-20s %s\n", "sigrok", "Default file output format"); + for (sl = NULL, i = 0; outputs[i]; i++) + sl = g_slist_append(sl, outputs[i]); + sl = g_slist_sort(sl, sort_outputs); + for (l = sl; l; l = l->next) { + output = l->data; + printf(" %-20s %s\n", output->id, output->description); + } printf("\n"); + g_slist_free(sl); #ifdef HAVE_SRD if (srd_init(NULL) == SRD_OK) { printf("Supported protocol decoders:\n"); srd_decoder_load_all(); - for (l = srd_decoder_list(); l; l = l->next) { + sl = g_slist_copy((GSList *)srd_decoder_list()); + sl = g_slist_sort(sl, sort_pds); + for (l = sl; l; l = l->next) { dec = l->data; printf(" %-20s %s\n", dec->id, dec->longname); /* Print protocol description upon "-l 3" or higher. */ if (opt_loglevel >= SR_LOG_INFO) printf(" %-20s %s\n", "", dec->desc); } + g_slist_free(sl); srd_exit(); } printf("\n"); #endif } +static gint sort_probes(gconstpointer a, gconstpointer b) +{ + const struct sr_probe *pa = a, *pb = b; + + return pa->index - pb->index; +} + static void print_dev_line(const struct sr_dev_inst *sdi) { struct sr_probe *probe; - GSList *l; + GSList *sl, *l; GString *s; GVariant *gvar; @@ -107,11 +163,13 @@ static void print_dev_line(const struct sr_dev_inst *sdi) probe = sdi->probes->data; g_string_append_printf(s, "with 1 probe: %s", probe->name); } else { - g_string_append_printf(s, "with %d probes:", g_slist_length(sdi->probes)); - for (l = sdi->probes; l; l = l->next) { + sl = g_slist_sort(g_slist_copy(sdi->probes), sort_probes); + g_string_append_printf(s, "with %d probes:", g_slist_length(sl)); + for (l = sl; l; l = l->next) { probe = l->data; g_string_append_printf(s, " %s", probe->name); } + g_slist_free(sl); } } g_string_append_printf(s, "\n"); @@ -436,11 +494,12 @@ void show_dev_detail(void) #ifdef HAVE_SRD void show_pd_detail(void) { - GSList *l; + GSList *l, *ll; struct srd_decoder *dec; struct srd_decoder_option *o; char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; struct srd_probe *p; + struct srd_decoder_annotation_row *r; pdtokens = g_strsplit(opt_pds, ",", -1); for (pdtok = pdtokens; *pdtok; pdtok++) { @@ -454,11 +513,23 @@ void show_pd_detail(void) printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n", dec->id, dec->name, dec->longname, dec->desc); printf("License: %s\n", dec->license); - printf("Annotations:\n"); + printf("Annotation classes:\n"); if (dec->annotations) { for (l = dec->annotations; l; l = l->next) { ann = l->data; - printf("- %s\n %s\n", ann[0], ann[1]); + printf("- %s: %s\n", ann[0], ann[1]); + } + } else { + printf("None.\n"); + } + printf("Annotation rows:\n"); + if (dec->annotation_rows) { + for (l = dec->annotation_rows; l; l = l->next) { + r = l->data; + printf("- %s (%s): ", r->id, r->desc); + for (ll = r->ann_classes; ll; ll = ll->next) + printf("%d ", GPOINTER_TO_INT(ll->data)); + printf("\n"); } } else { printf("None.\n"); @@ -468,7 +539,7 @@ void show_pd_detail(void) for (l = dec->probes; l; l = l->next) { p = l->data; printf("- %s (%s): %s\n", - p->name, p->id, p->desc); + p->id, p->name, p->desc); } } else { printf("None.\n"); @@ -478,19 +549,22 @@ void show_pd_detail(void) for (l = dec->opt_probes; l; l = l->next) { p = l->data; printf("- %s (%s): %s\n", - p->name, p->id, p->desc); + p->id, p->name, p->desc); } } else { printf("None.\n"); } + printf("Options:\n"); if (dec->options) { - printf("Options:\n"); for (l = dec->options; l; l = l->next) { o = l->data; val = g_variant_print(o->def, FALSE); - printf("- %s: %s (default %s)\n", o->id, o->desc, val); + printf("- %s: %s (default %s)\n", o->id, + o->desc, val); g_free(val); } + } else { + printf("None.\n"); } if ((doc = srd_decoder_doc_get(dec))) { printf("Documentation:\n%s\n",