aboutsummaryrefslogtreecommitdiff
path: root/bpkg/types-parsers.txx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-08 23:01:16 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-10 23:54:18 +0300
commit61349dcf5fbfeab888ea345ebec3d887777a2782 (patch)
tree958d7f34185d987b21ae24ad137b7a2e0a1593ec /bpkg/types-parsers.txx
parenteb58dc7c9ec9877c645585b7fb163d2bcc251b5d (diff)
Add support for openssl qualified options
Diffstat (limited to 'bpkg/types-parsers.txx')
-rw-r--r--bpkg/types-parsers.txx69
1 files changed, 69 insertions, 0 deletions
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 <const char* Q[], typename V>
+ void parser<qualified_option<Q, V>>::
+ parse (qualified_option<Q, V>& 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<char*> (o), const_cast<char*> (v.c_str ())};
+ bool dummy;
+
+ {
+ argv_scanner s (0, ac, av);
+ parser<V>::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<V>::parse (x[*q], dummy, s);
+ }
+ }
+ }
+ }
+}