From 724f29f311db4f8b47169e58f3f3b50e6a50ed08 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 25 Jun 2017 19:40:14 +0200 Subject: [PATCH] session: Add support for input format options (-I cmdline parameter) The previous implementation supported the selection of an input format by means of the -I command line option. This commit extends the feature by adding support for colon separated input format options similar to sigrok-cli. This allows users to open files from the command line which previously became only available after filling in dialogs, and resulted in errors in the absence of options. Here is an example of how to use the option: $ pulseview -I csv:header:first-channel=2 -i filename.csv This fixes bug #951. --- pv/session.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++--- pv/session.hpp | 7 +++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/pv/session.cpp b/pv/session.cpp index aa528d19..516e1acd 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -434,26 +434,76 @@ void Session::set_default_device() set_device((iter == devices.end()) ? devices.front() : *iter); } +/** + * Convert generic options to data types that are specific to InputFormat. + * + * @param[in] user_spec vector of tokenized words, string format + * @param[in] fmt_opts input format's options, result of InputFormat::options() + * + * @return map of options suitable for InputFormat::create_input() + */ +map +Session::input_format_options(vector user_spec, + map> fmt_opts) +{ + map result; + + for (auto entry : user_spec) { + /* + * Split key=value specs. Accept entries without separator + * (for simplified boolean specifications). + */ + string key, val; + size_t pos = entry.find("="); + if (pos == std::string::npos) { + key = entry; + val = ""; + } else { + key = entry.substr(0, pos); + val = entry.substr(pos + 1); + } + + /* + * Skip user specifications that are not a member of the + * format's set of supported options. Have the text input + * spec converted to the required input format specific + * data type. + */ + auto found = fmt_opts.find(key); + if (found == fmt_opts.end()) + continue; + shared_ptr