output: Added preferred file extension field

This fixes parts of bug #541.
This commit is contained in:
Joel Holdsworth 2015-01-21 01:02:14 -05:00 committed by Uwe Hermann
parent c7bc82ffa1
commit 8a174d2342
17 changed files with 52 additions and 0 deletions

View File

@ -1534,6 +1534,15 @@ string OutputFormat::description()
return valid_string(sr_output_description_get(_structure));
}
vector<string> OutputFormat::extensions()
{
vector<string> exts;
for (const char *const *e = sr_output_extensions_get(_structure);
e && *e; e++)
exts.push_back(*e);
return exts;
}
map<string, shared_ptr<Option>> OutputFormat::options()
{
const struct sr_option **options = sr_output_options_get(_structure);

View File

@ -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<string> extensions();
/** Options supported by this output format. */
map<string, shared_ptr<Option> > options();
/** Create an output using this format.

View File

@ -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);

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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,
};

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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,