From: Joel Holdsworth Date: Wed, 21 Jan 2015 06:02:14 +0000 (-0500) Subject: output: Added preferred file extension field X-Git-Tag: libsigrok-0.4.0~669 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=8a174d23427735617d69c7502ed8dcade786bbf9 output: Added preferred file extension field This fixes parts of bug #541. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index c915c8a7..a5c9e4cd 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -1534,6 +1534,15 @@ string OutputFormat::description() return valid_string(sr_output_description_get(_structure)); } +vector OutputFormat::extensions() +{ + vector exts; + for (const char *const *e = sr_output_extensions_get(_structure); + e && *e; e++) + exts.push_back(*e); + return exts; +} + map> OutputFormat::options() { const struct sr_option **options = sr_output_options_get(_structure); diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index 0542a1be..324cd01e 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -948,6 +948,9 @@ public: string name(); /** Description of this output format. */ string description(); + /** A list of preferred file name extensions for this file format. + * @note This list is a recommendation only. */ + vector extensions(); /** Options supported by this output format. */ map > options(); /** Create an output using this format. diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index 9b540c1f..70bb5978 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -170,6 +170,8 @@ SR_API const struct sr_output_module **sr_output_list(void); SR_API const char *sr_output_id_get(const struct sr_output_module *o); SR_API const char *sr_output_name_get(const struct sr_output_module *o); SR_API const char *sr_output_description_get(const struct sr_output_module *o); +SR_API const char *const *sr_output_extensions_get( + const struct sr_output_module *o); SR_API const struct sr_output_module *sr_output_find(char *id); SR_API const struct sr_option **sr_output_options_get(const struct sr_output_module *o); SR_API void sr_output_options_free(const struct sr_option **opts); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index debd2771..71f65616 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -371,6 +371,13 @@ struct sr_output_module { */ char *desc; + /** + * A NULL terminated array of strings containing a list of file name + * extensions typical for the input file format, or NULL if there is + * no typical extension for this file format. + */ + const char *const *exts; + /** * Returns a NULL-terminated list of options this module can take. * Can be NULL, if the module has no options. diff --git a/src/output/analog.c b/src/output/analog.c index e99c3c00..3b9a5812 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -344,6 +344,7 @@ SR_PRIV struct sr_output_module output_analog = { .id = "analog", .name = "Analog", .desc = "Analog data and types", + .exts = NULL, .options = get_options, .init = init, .receive = receive, diff --git a/src/output/ascii.c b/src/output/ascii.c index b6baab1b..c6b4290f 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -252,6 +252,7 @@ SR_PRIV struct sr_output_module output_ascii = { .id = "ascii", .name = "ASCII", .desc = "ASCII art", + .exts = (const char*[]){"txt", NULL}, .options = get_options, .init = init, .receive = receive, diff --git a/src/output/binary.c b/src/output/binary.c index 10f0409f..04627f32 100644 --- a/src/output/binary.c +++ b/src/output/binary.c @@ -46,6 +46,7 @@ SR_PRIV struct sr_output_module output_binary = { .id = "binary", .name = "Binary", .desc = "Raw binary", + .exts = NULL, .options = NULL, .receive = receive, }; diff --git a/src/output/bits.c b/src/output/bits.c index 0a9ccc1a..180ea563 100644 --- a/src/output/bits.c +++ b/src/output/bits.c @@ -238,6 +238,7 @@ SR_PRIV struct sr_output_module output_bits = { .id = "bits", .name = "Bits", .desc = "0/1 digits", + .exts = (const char*[]){"txt", NULL}, .options = get_options, .init = init, .receive = receive, diff --git a/src/output/chronovu_la8.c b/src/output/chronovu_la8.c index c5012384..1c0953f7 100644 --- a/src/output/chronovu_la8.c +++ b/src/output/chronovu_la8.c @@ -187,6 +187,7 @@ SR_PRIV struct sr_output_module output_chronovu_la8 = { .id = "chronovu-la8", .name = "ChronoVu LA8", .desc = "ChronoVu LA8 native file format", + .exts = (const char*[]){"kdt", NULL}, .options = NULL, .init = init, .receive = receive, diff --git a/src/output/csv.c b/src/output/csv.c index 86df2613..77b62285 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -217,6 +217,7 @@ SR_PRIV struct sr_output_module output_csv = { .id = "csv", .name = "CSV", .desc = "Comma-separated values", + .exts = (const char*[]){"csv", NULL}, .options = NULL, .init = init, .receive = receive, diff --git a/src/output/gnuplot.c b/src/output/gnuplot.c index 8cd67b3e..134fd904 100644 --- a/src/output/gnuplot.c +++ b/src/output/gnuplot.c @@ -221,6 +221,7 @@ SR_PRIV struct sr_output_module output_gnuplot = { .id = "gnuplot", .name = "Gnuplot", .desc = "Gnuplot file format", + .exts = (const char*[]){"pl", NULL}, .options = NULL, .init = init, .receive = receive, diff --git a/src/output/hex.c b/src/output/hex.c index 67a349e5..6b24fdf5 100644 --- a/src/output/hex.c +++ b/src/output/hex.c @@ -252,6 +252,7 @@ SR_PRIV struct sr_output_module output_hex = { .id = "hex", .name = "Hexadecimal", .desc = "Hexadecimal digits", + .exts = (const char*[]){"txt", NULL}, .options = get_options, .init = init, .receive = receive, diff --git a/src/output/ols.c b/src/output/ols.c index 7feb4db9..bf1aacbd 100644 --- a/src/output/ols.c +++ b/src/output/ols.c @@ -150,6 +150,7 @@ SR_PRIV struct sr_output_module output_ols = { .id = "ols", .name = "OLS", .desc = "OpenBench Logic Sniffer", + .exts = (const char*[]){"ols", NULL}, .options = NULL, .init = init, .receive = receive, diff --git a/src/output/output.c b/src/output/output.c index 1ddbd61e..7eaa489e 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -135,6 +135,25 @@ SR_API const char *sr_output_description_get(const struct sr_output_module *o) return o->desc; } +/** + * Returns the specified output module's file extensions typical for the file + * format, as a NULL terminated array, or returns a NULL pointer if there is + * no preferred extension. + * @note these are a suggestions only. + * + * @since 0.4.0 + */ +SR_API const char *const *sr_output_extensions_get( + const struct sr_output_module *o) +{ + if (!o) { + sr_err("Invalid output module NULL!"); + return NULL; + } + + return o->exts; +} + /** * Return the output module with the specified ID, or NULL if no module * with that id is found. diff --git a/src/output/srzip.c b/src/output/srzip.c index 18a79d5b..356a8ab4 100644 --- a/src/output/srzip.c +++ b/src/output/srzip.c @@ -312,6 +312,7 @@ SR_PRIV struct sr_output_module output_srzip = { .id = "srzip", .name = "srzip", .desc = "srzip session file", + .exts = (const char*[]){"sr", NULL}, .options = get_options, .init = init, .receive = receive, diff --git a/src/output/vcd.c b/src/output/vcd.c index f1b45f1a..9d3516b7 100644 --- a/src/output/vcd.c +++ b/src/output/vcd.c @@ -263,6 +263,7 @@ struct sr_output_module output_vcd = { .id = "vcd", .name = "VCD", .desc = "Value Change Dump", + .exts = (const char*[]){"vcd", NULL}, .options = NULL, .init = init, .receive = receive, diff --git a/src/output/wav.c b/src/output/wav.c index e01f3afd..6ffe905a 100644 --- a/src/output/wav.c +++ b/src/output/wav.c @@ -351,6 +351,7 @@ SR_PRIV struct sr_output_module output_wav = { .id = "wav", .name = "WAV", .desc = "WAVE file format", + .exts = (const char*[]){"wav", NULL}, .options = get_options, .init = init, .receive = receive,