aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/common-options.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/common-options.cxx')
-rw-r--r--libbuild2/common-options.cxx112
1 files changed, 95 insertions, 17 deletions
diff --git a/libbuild2/common-options.cxx b/libbuild2/common-options.cxx
index 5c58a62..03e7e60 100644
--- a/libbuild2/common-options.cxx
+++ b/libbuild2/common-options.cxx
@@ -30,7 +30,7 @@ namespace build2
// unknown_option
//
unknown_option::
- ~unknown_option () throw ()
+ ~unknown_option () noexcept
{
}
@@ -41,7 +41,7 @@ namespace build2
}
const char* unknown_option::
- what () const throw ()
+ what () const noexcept
{
return "unknown option";
}
@@ -49,7 +49,7 @@ namespace build2
// unknown_argument
//
unknown_argument::
- ~unknown_argument () throw ()
+ ~unknown_argument () noexcept
{
}
@@ -60,7 +60,7 @@ namespace build2
}
const char* unknown_argument::
- what () const throw ()
+ what () const noexcept
{
return "unknown argument";
}
@@ -68,7 +68,7 @@ namespace build2
// missing_value
//
missing_value::
- ~missing_value () throw ()
+ ~missing_value () noexcept
{
}
@@ -79,7 +79,7 @@ namespace build2
}
const char* missing_value::
- what () const throw ()
+ what () const noexcept
{
return "missing option value";
}
@@ -87,7 +87,7 @@ namespace build2
// invalid_value
//
invalid_value::
- ~invalid_value () throw ()
+ ~invalid_value () noexcept
{
}
@@ -102,7 +102,7 @@ namespace build2
}
const char* invalid_value::
- what () const throw ()
+ what () const noexcept
{
return "invalid option value";
}
@@ -116,7 +116,7 @@ namespace build2
}
const char* eos_reached::
- what () const throw ()
+ what () const noexcept
{
return "end of argument stream reached";
}
@@ -124,7 +124,7 @@ namespace build2
// file_io_failure
//
file_io_failure::
- ~file_io_failure () throw ()
+ ~file_io_failure () noexcept
{
}
@@ -135,7 +135,7 @@ namespace build2
}
const char* file_io_failure::
- what () const throw ()
+ what () const noexcept
{
return "unable to open file or read failure";
}
@@ -143,7 +143,7 @@ namespace build2
// unmatched_quote
//
unmatched_quote::
- ~unmatched_quote () throw ()
+ ~unmatched_quote () noexcept
{
}
@@ -154,7 +154,7 @@ namespace build2
}
const char* unmatched_quote::
- what () const throw ()
+ what () const noexcept
{
return "unmatched quote";
}
@@ -587,10 +587,31 @@ namespace build2
struct parser<bool>
{
static void
- parse (bool& x, scanner& s)
+ parse (bool& x, bool& xs, scanner& s)
{
- s.next ();
- x = true;
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ const char* v (s.next ());
+
+ if (std::strcmp (v, "1") == 0 ||
+ std::strcmp (v, "true") == 0 ||
+ std::strcmp (v, "TRUE") == 0 ||
+ std::strcmp (v, "True") == 0)
+ x = true;
+ else if (std::strcmp (v, "0") == 0 ||
+ std::strcmp (v, "false") == 0 ||
+ std::strcmp (v, "FALSE") == 0 ||
+ std::strcmp (v, "False") == 0)
+ x = false;
+ else
+ throw invalid_value (o, v);
+ }
+ else
+ throw missing_value (o);
+
+ xs = true;
}
};
@@ -700,6 +721,56 @@ namespace build2
}
};
+ template <typename K, typename V, typename C>
+ struct parser<std::multimap<K, V, C> >
+ {
+ static void
+ parse (std::multimap<K, V, C>& m, bool& xs, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ std::size_t pos (s.position ());
+ std::string ov (s.next ());
+ std::string::size_type p = ov.find ('=');
+
+ K k = K ();
+ V v = V ();
+ std::string kstr (ov, 0, p);
+ std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ()));
+
+ int ac (2);
+ char* av[] =
+ {
+ const_cast<char*> (o),
+ 0
+ };
+
+ bool dummy;
+ if (!kstr.empty ())
+ {
+ av[1] = const_cast<char*> (kstr.c_str ());
+ argv_scanner s (0, ac, av, false, pos);
+ parser<K>::parse (k, dummy, s);
+ }
+
+ if (!vstr.empty ())
+ {
+ av[1] = const_cast<char*> (vstr.c_str ());
+ argv_scanner s (0, ac, av, false, pos);
+ parser<V>::parse (v, dummy, s);
+ }
+
+ m.insert (typename std::multimap<K, V, C>::value_type (k, v));
+ }
+ else
+ throw missing_value (o);
+
+ xs = true;
+ }
+ };
+
template <typename X, typename T, T X::*M>
void
thunk (X& x, scanner& s)
@@ -707,6 +778,14 @@ namespace build2
parser<T>::parse (x.*M, s);
}
+ template <typename X, bool X::*M>
+ void
+ thunk (X& x, scanner& s)
+ {
+ s.next ();
+ x.*M = true;
+ }
+
template <typename X, typename T, T X::*M, bool X::*S>
void
thunk (X& x, scanner& s)
@@ -718,7 +797,6 @@ namespace build2
}
#include <map>
-#include <cstring>
namespace build2
{