From 61349dcf5fbfeab888ea345ebec3d887777a2782 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 8 Oct 2018 23:01:16 +0300 Subject: Add support for openssl qualified options --- bpkg/types-parsers.txx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bpkg/types-parsers.txx (limited to 'bpkg/types-parsers.txx') diff --git a/bpkg/types-parsers.txx b/bpkg/types-parsers.txx new file mode 100644 index 0000000..7a40b0e --- /dev/null +++ b/bpkg/types-parsers.txx @@ -0,0 +1,69 @@ +// file : bpkg/types-parsers.txx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +namespace bpkg +{ + namespace cli + { + template + void parser>:: + parse (qualified_option& x, bool& xs, scanner& s) + { + xs = true; + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + string v (s.next ()); + + // Extract the qualifier from the option value. + // + string qv; + size_t n (v.find (':')); + + if (n != string::npos) + { + const char** q (Q); + for (; *q != nullptr; ++q) + { + if (v.compare (0, n, *q) == 0) + { + qv = *q; + v = string (v, n + 1); + break; + } + } + + // Fail it the qualifier is not recognized, unless it is a special + // empty qualifier. + // + if (*q == nullptr && n != 0) + throw invalid_value (o, v); + } + + // Parse the value for the extracted (possibly empty) qualifier. + // + int ac (2); + char* av[] = {const_cast (o), const_cast (v.c_str ())}; + bool dummy; + + { + argv_scanner s (0, ac, av); + parser::parse (x[qv], dummy, s); + } + + // Parse an unqualified value for all qualifiers. + // + if (qv.empty ()) + { + for (const char** q (Q); *q != nullptr; ++q) + { + argv_scanner s (0, ac, av); + parser::parse (x[*q], dummy, s); + } + } + } + } +} -- cgit v1.1