From: Uwe Hermann Date: Fri, 29 Mar 2019 15:01:06 +0000 (+0100) Subject: Add --list-supported-wiki option. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c45dd41c508bd84b3886eebfa0ca4b2230b2630b;p=sigrok-cli.git Add --list-supported-wiki option. This is meant for developers only, to easily update the list of supported protocol decoders in the sigrok wiki. --- diff --git a/doc/sigrok-cli.1 b/doc/sigrok-cli.1 index b8940cb..de0093f 100644 --- a/doc/sigrok-cli.1 +++ b/doc/sigrok-cli.1 @@ -1,4 +1,4 @@ -.TH SIGROK\-CLI 1 "October 22, 2018" +.TH SIGROK\-CLI 1 "March 28, 2019" .SH "NAME" sigrok\-cli \- Command-line client for the sigrok software .SH "SYNOPSIS" @@ -28,9 +28,14 @@ version and the versions of libraries used. Show information about supported hardware drivers, input file formats, output file formats, and protocol decoders. .TP +.B "\-\-list\-supported\-wiki" +Show information about supported protocol decoders in MediaWiki syntax. +This is generally only used by developers to easily update the list of +supported protocol decoders in the sigrok wiki. +.TP \fB\-d, \-\-driver\fP A driver must always be selected (unless doing a global scan). Use the -.BR "\-L " ( "\-\-list-supported" ")" +.BR "\-L " ( "\-\-list\-supported" ")" option to get a list of available drivers. .sp Drivers can take options, in the form \fBkey=value\fP diff --git a/main.c b/main.c index c038b6f..701da8e 100644 --- a/main.c +++ b/main.c @@ -266,6 +266,8 @@ int main(int argc, char **argv) show_version(); else if (opt_list_supported) show_supported(); + else if (opt_list_supported_wiki) + show_supported_wiki(); else if (opt_input_format && opt_show) show_input(); else if (opt_output_format && opt_show) diff --git a/options.c b/options.c index b9e1494..af6a7fe 100644 --- a/options.c +++ b/options.c @@ -23,6 +23,7 @@ gboolean opt_version = FALSE; gboolean opt_list_supported = FALSE; +gboolean opt_list_supported_wiki = FALSE; gint opt_loglevel = SR_LOG_WARN; /* Show errors+warnings by default. */ gboolean opt_scan_devs = FALSE; gboolean opt_wait_trigger = FALSE; @@ -102,6 +103,8 @@ static const GOptionEntry optargs[] = { "Show version", NULL}, {"list-supported", 'L', 0, G_OPTION_ARG_NONE, &opt_list_supported, "List supported devices/modules/decoders", NULL}, + {"list-supported-wiki", 0, 0, G_OPTION_ARG_NONE, &opt_list_supported_wiki, + "List supported decoders (MediaWiki)", NULL}, {"loglevel", 'l', 0, G_OPTION_ARG_INT, &opt_loglevel, "Set loglevel (5 is most verbose)", NULL}, {"driver", 'd', 0, G_OPTION_ARG_CALLBACK, &check_opt_drv, diff --git a/show.c b/show.c index dbbc632..090be4a 100644 --- a/show.c +++ b/show.c @@ -204,6 +204,74 @@ void show_supported(void) #endif } +void show_supported_wiki(void) +{ +#ifndef HAVE_SRD + printf("Error, libsigrokdecode support not compiled in."); +#else + const GSList *l; + GSList *sl; + struct srd_decoder *dec; + + if (srd_init(NULL) != SRD_OK) + return; + + srd_decoder_load_all(); + sl = g_slist_copy((GSList *)srd_decoder_list()); + sl = g_slist_sort(sl, sort_pds); + + printf("== Supported protocol decoders ==\n\n"); + + printf("\n\n"); + + printf("Number of currently supported protocol decoders: " + "'''%d'''.\n\n", g_slist_length(sl)); + + printf("{| border=\"0\" style=\"font-size: smaller\" " + "class=\"alternategrey sortable sigroktable\"\n" + "|-\n!Protocol\n!Tags\n!Input IDs\n!Output IDs\n!Status\n" + "!Full name\n!Description\n\n"); + + for (l = sl; l; l = l->next) { + dec = l->data; + + GString *tags = g_string_new(NULL); + for (GSList *t = dec->tags; t; t = t->next) + g_string_append_printf(tags, "%s, ", (char *)t->data); + if (tags->len != 0) + g_string_truncate(tags, tags->len - 2); + + GString *in = g_string_new(NULL); + for (GSList *t = dec->inputs; t; t = t->next) + g_string_append_printf(in, "%s, ", (char *)t->data); + if (in->len == 0) + g_string_append_printf(in, "—"); + else + g_string_truncate(in, in->len - 2); + + GString *out = g_string_new(NULL); + for (GSList *t = dec->outputs; t; t = t->next) + g_string_append_printf(out, "%s, ", (char *)t->data); + if (out->len == 0) + g_string_append_printf(out, "—"); + else + g_string_truncate(out, out->len - 2); + + printf("{{pd|%s|%s|%s|%s|%s|%s|%s|supported}}\n", + dec->id, dec->name, dec->longname, dec->desc, + tags->str, in->str, out->str); + + g_string_free(tags, TRUE); + g_string_free(in, TRUE); + g_string_free(out, TRUE); + } + g_slist_free(sl); + srd_exit(); + + printf("\n|}\n"); +#endif +} + static gint sort_channels(gconstpointer a, gconstpointer b) { const struct sr_channel *pa = a, *pb = b; diff --git a/sigrok-cli.h b/sigrok-cli.h index f564448..c71586a 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -45,6 +45,7 @@ int maybe_config_list(struct sr_dev_driver *driver, /* show.c */ void show_version(void); void show_supported(void); +void show_supported_wiki(void); void show_dev_list(void); void show_dev_detail(void); void show_pd_detail(void); @@ -95,6 +96,7 @@ void clear_anykey(void); /* options.c */ extern gboolean opt_version; extern gboolean opt_list_supported; +extern gboolean opt_list_supported_wiki; extern gint opt_loglevel; extern gboolean opt_scan_devs; extern gboolean opt_wait_trigger;