aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/builtin-options.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/script/builtin-options.cxx')
-rw-r--r--libbuild2/script/builtin-options.cxx799
1 files changed, 498 insertions, 301 deletions
diff --git a/libbuild2/script/builtin-options.cxx b/libbuild2/script/builtin-options.cxx
index c27f266..b71b9d3 100644
--- a/libbuild2/script/builtin-options.cxx
+++ b/libbuild2/script/builtin-options.cxx
@@ -15,201 +15,17 @@
#include <set>
#include <string>
#include <vector>
+#include <utility>
#include <ostream>
#include <sstream>
+#include <cstring>
namespace build2
{
- namespace script
+ namespace build
{
namespace cli
{
- // unknown_option
- //
- unknown_option::
- ~unknown_option () throw ()
- {
- }
-
- void unknown_option::
- print (::std::ostream& os) const
- {
- os << "unknown option '" << option ().c_str () << "'";
- }
-
- const char* unknown_option::
- what () const throw ()
- {
- return "unknown option";
- }
-
- // unknown_argument
- //
- unknown_argument::
- ~unknown_argument () throw ()
- {
- }
-
- void unknown_argument::
- print (::std::ostream& os) const
- {
- os << "unknown argument '" << argument ().c_str () << "'";
- }
-
- const char* unknown_argument::
- what () const throw ()
- {
- return "unknown argument";
- }
-
- // missing_value
- //
- missing_value::
- ~missing_value () throw ()
- {
- }
-
- void missing_value::
- print (::std::ostream& os) const
- {
- os << "missing value for option '" << option ().c_str () << "'";
- }
-
- const char* missing_value::
- what () const throw ()
- {
- return "missing option value";
- }
-
- // invalid_value
- //
- invalid_value::
- ~invalid_value () throw ()
- {
- }
-
- void invalid_value::
- print (::std::ostream& os) const
- {
- os << "invalid value '" << value ().c_str () << "' for option '"
- << option ().c_str () << "'";
-
- if (!message ().empty ())
- os << ": " << message ().c_str ();
- }
-
- const char* invalid_value::
- what () const throw ()
- {
- return "invalid option value";
- }
-
- // eos_reached
- //
- void eos_reached::
- print (::std::ostream& os) const
- {
- os << what ();
- }
-
- const char* eos_reached::
- what () const throw ()
- {
- return "end of argument stream reached";
- }
-
- // scanner
- //
- scanner::
- ~scanner ()
- {
- }
-
- // argv_scanner
- //
- bool argv_scanner::
- more ()
- {
- return i_ < argc_;
- }
-
- const char* argv_scanner::
- peek ()
- {
- if (i_ < argc_)
- return argv_[i_];
- else
- throw eos_reached ();
- }
-
- const char* argv_scanner::
- next ()
- {
- if (i_ < argc_)
- {
- const char* r (argv_[i_]);
-
- if (erase_)
- {
- for (int i (i_ + 1); i < argc_; ++i)
- argv_[i - 1] = argv_[i];
-
- --argc_;
- argv_[argc_] = 0;
- }
- else
- ++i_;
-
- return r;
- }
- else
- throw eos_reached ();
- }
-
- void argv_scanner::
- skip ()
- {
- if (i_ < argc_)
- ++i_;
- else
- throw eos_reached ();
- }
-
- // vector_scanner
- //
- bool vector_scanner::
- more ()
- {
- return i_ < v_.size ();
- }
-
- const char* vector_scanner::
- peek ()
- {
- if (i_ < v_.size ())
- return v_[i_].c_str ();
- else
- throw eos_reached ();
- }
-
- const char* vector_scanner::
- next ()
- {
- if (i_ < v_.size ())
- return v_[i_++].c_str ();
- else
- throw eos_reached ();
- }
-
- void vector_scanner::
- skip ()
- {
- if (i_ < v_.size ())
- ++i_;
- else
- throw eos_reached ();
- }
-
template <typename X>
struct parser
{
@@ -237,10 +53,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;
}
};
@@ -262,6 +99,17 @@ namespace build2
};
template <typename X>
+ struct parser<std::pair<X, std::size_t> >
+ {
+ static void
+ parse (std::pair<X, std::size_t>& x, bool& xs, scanner& s)
+ {
+ x.second = s.position ();
+ parser<X>::parse (x.first, xs, s);
+ }
+ };
+
+ template <typename X>
struct parser<std::vector<X> >
{
static void
@@ -299,6 +147,7 @@ namespace build2
if (s.more ())
{
+ std::size_t pos (s.position ());
std::string ov (s.next ());
std::string::size_type p = ov.find ('=');
@@ -318,14 +167,14 @@ namespace build2
if (!kstr.empty ())
{
av[1] = const_cast<char*> (kstr.c_str ());
- argv_scanner s (0, ac, av);
+ 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);
+ argv_scanner s (0, ac, av, false, pos);
parser<V>::parse (v, dummy, s);
}
@@ -338,6 +187,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)
@@ -345,6 +244,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)
@@ -356,7 +263,6 @@ namespace build2
}
#include <map>
-#include <cstring>
namespace build2
{
@@ -377,13 +283,13 @@ namespace build2
set_options (int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: exact_ (),
newline_ (),
whitespace_ ()
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
}
@@ -392,13 +298,13 @@ namespace build2
int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: exact_ (),
newline_ (),
whitespace_ ()
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
}
@@ -407,13 +313,13 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: exact_ (),
newline_ (),
whitespace_ ()
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
@@ -424,21 +330,21 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: exact_ (),
newline_ (),
whitespace_ ()
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
set_options::
- set_options (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ set_options (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: exact_ (),
newline_ (),
whitespace_ ()
@@ -447,7 +353,7 @@ namespace build2
}
typedef
- std::map<std::string, void (*) (set_options&, ::build2::script::cli::scanner&)>
+ std::map<std::string, void (*) (set_options&, ::build2::build::cli::scanner&)>
_cli_set_options_map;
static _cli_set_options_map _cli_set_options_map_;
@@ -457,24 +363,24 @@ namespace build2
_cli_set_options_map_init ()
{
_cli_set_options_map_["--exact"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::exact_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::exact_ >;
_cli_set_options_map_["-e"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::exact_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::exact_ >;
_cli_set_options_map_["--newline"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::newline_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::newline_ >;
_cli_set_options_map_["-n"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::newline_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::newline_ >;
_cli_set_options_map_["--whitespace"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::whitespace_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::whitespace_ >;
_cli_set_options_map_["-w"] =
- &::build2::script::cli::thunk< set_options, bool, &set_options::whitespace_ >;
+ &::build2::build::cli::thunk< set_options, &set_options::whitespace_ >;
}
};
static _cli_set_options_map_init _cli_set_options_map_init_;
bool set_options::
- _parse (const char* o, ::build2::script::cli::scanner& s)
+ _parse (const char* o, ::build2::build::cli::scanner& s)
{
_cli_set_options_map::const_iterator i (_cli_set_options_map_.find (o));
@@ -488,13 +394,13 @@ namespace build2
}
bool set_options::
- _parse (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt_mode,
- ::build2::script::cli::unknown_mode arg_mode)
+ _parse (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt_mode,
+ ::build2::build::cli::unknown_mode arg_mode)
{
// Can't skip combined flags (--no-combined-flags).
//
- assert (opt_mode != ::build2::script::cli::unknown_mode::skip);
+ assert (opt_mode != ::build2::build::cli::unknown_mode::skip);
bool r = false;
bool opt = true;
@@ -536,14 +442,14 @@ namespace build2
const_cast<char*> (v)
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (_parse (co.c_str (), ns))
{
// Parsed the option but not its value?
//
if (ns.end () != 2)
- throw ::build2::script::cli::invalid_value (co, v);
+ throw ::build2::build::cli::invalid_value (co, v);
s.next ();
r = true;
@@ -584,7 +490,7 @@ namespace build2
cf
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (!_parse (cf, ns))
break;
@@ -609,19 +515,19 @@ namespace build2
switch (opt_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_option (o);
+ throw ::build2::build::cli::unknown_option (o);
}
}
@@ -631,19 +537,19 @@ namespace build2
switch (arg_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_argument (o);
+ throw ::build2::build::cli::unknown_argument (o);
}
}
@@ -666,11 +572,11 @@ namespace build2
timeout_options (int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: success_ ()
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
}
@@ -679,11 +585,11 @@ namespace build2
int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: success_ ()
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
}
@@ -692,11 +598,11 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: success_ ()
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
@@ -707,26 +613,26 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: success_ ()
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
timeout_options::
- timeout_options (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ timeout_options (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: success_ ()
{
_parse (s, opt, arg);
}
typedef
- std::map<std::string, void (*) (timeout_options&, ::build2::script::cli::scanner&)>
+ std::map<std::string, void (*) (timeout_options&, ::build2::build::cli::scanner&)>
_cli_timeout_options_map;
static _cli_timeout_options_map _cli_timeout_options_map_;
@@ -736,16 +642,16 @@ namespace build2
_cli_timeout_options_map_init ()
{
_cli_timeout_options_map_["--success"] =
- &::build2::script::cli::thunk< timeout_options, bool, &timeout_options::success_ >;
+ &::build2::build::cli::thunk< timeout_options, &timeout_options::success_ >;
_cli_timeout_options_map_["-s"] =
- &::build2::script::cli::thunk< timeout_options, bool, &timeout_options::success_ >;
+ &::build2::build::cli::thunk< timeout_options, &timeout_options::success_ >;
}
};
static _cli_timeout_options_map_init _cli_timeout_options_map_init_;
bool timeout_options::
- _parse (const char* o, ::build2::script::cli::scanner& s)
+ _parse (const char* o, ::build2::build::cli::scanner& s)
{
_cli_timeout_options_map::const_iterator i (_cli_timeout_options_map_.find (o));
@@ -759,13 +665,13 @@ namespace build2
}
bool timeout_options::
- _parse (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt_mode,
- ::build2::script::cli::unknown_mode arg_mode)
+ _parse (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt_mode,
+ ::build2::build::cli::unknown_mode arg_mode)
{
// Can't skip combined flags (--no-combined-flags).
//
- assert (opt_mode != ::build2::script::cli::unknown_mode::skip);
+ assert (opt_mode != ::build2::build::cli::unknown_mode::skip);
bool r = false;
bool opt = true;
@@ -807,14 +713,14 @@ namespace build2
const_cast<char*> (v)
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (_parse (co.c_str (), ns))
{
// Parsed the option but not its value?
//
if (ns.end () != 2)
- throw ::build2::script::cli::invalid_value (co, v);
+ throw ::build2::build::cli::invalid_value (co, v);
s.next ();
r = true;
@@ -855,7 +761,7 @@ namespace build2
cf
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (!_parse (cf, ns))
break;
@@ -880,19 +786,19 @@ namespace build2
switch (opt_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_option (o);
+ throw ::build2::build::cli::unknown_option (o);
}
}
@@ -902,19 +808,19 @@ namespace build2
switch (arg_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_argument (o);
+ throw ::build2::build::cli::unknown_argument (o);
}
}
@@ -940,14 +846,14 @@ namespace build2
export_options (int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: unset_ (),
unset_specified_ (false),
clear_ (),
clear_specified_ (false)
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
}
@@ -956,14 +862,14 @@ namespace build2
int& argc,
char** argv,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: unset_ (),
unset_specified_ (false),
clear_ (),
clear_specified_ (false)
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
}
@@ -972,14 +878,14 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: unset_ (),
unset_specified_ (false),
clear_ (),
clear_specified_ (false)
{
- ::build2::script::cli::argv_scanner s (argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
@@ -990,22 +896,22 @@ namespace build2
char** argv,
int& end,
bool erase,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: unset_ (),
unset_specified_ (false),
clear_ (),
clear_specified_ (false)
{
- ::build2::script::cli::argv_scanner s (start, argc, argv, erase);
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
_parse (s, opt, arg);
end = s.end ();
}
export_options::
- export_options (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt,
- ::build2::script::cli::unknown_mode arg)
+ export_options (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
: unset_ (),
unset_specified_ (false),
clear_ (),
@@ -1015,7 +921,7 @@ namespace build2
}
typedef
- std::map<std::string, void (*) (export_options&, ::build2::script::cli::scanner&)>
+ std::map<std::string, void (*) (export_options&, ::build2::build::cli::scanner&)>
_cli_export_options_map;
static _cli_export_options_map _cli_export_options_map_;
@@ -1025,16 +931,16 @@ namespace build2
_cli_export_options_map_init ()
{
_cli_export_options_map_["--unset"] =
- &::build2::script::cli::thunk< export_options, vector<string>, &export_options::unset_,
+ &::build2::build::cli::thunk< export_options, vector<string>, &export_options::unset_,
&export_options::unset_specified_ >;
_cli_export_options_map_["-u"] =
- &::build2::script::cli::thunk< export_options, vector<string>, &export_options::unset_,
+ &::build2::build::cli::thunk< export_options, vector<string>, &export_options::unset_,
&export_options::unset_specified_ >;
_cli_export_options_map_["--clear"] =
- &::build2::script::cli::thunk< export_options, vector<string>, &export_options::clear_,
+ &::build2::build::cli::thunk< export_options, vector<string>, &export_options::clear_,
&export_options::clear_specified_ >;
_cli_export_options_map_["-c"] =
- &::build2::script::cli::thunk< export_options, vector<string>, &export_options::clear_,
+ &::build2::build::cli::thunk< export_options, vector<string>, &export_options::clear_,
&export_options::clear_specified_ >;
}
};
@@ -1042,7 +948,7 @@ namespace build2
static _cli_export_options_map_init _cli_export_options_map_init_;
bool export_options::
- _parse (const char* o, ::build2::script::cli::scanner& s)
+ _parse (const char* o, ::build2::build::cli::scanner& s)
{
_cli_export_options_map::const_iterator i (_cli_export_options_map_.find (o));
@@ -1056,13 +962,304 @@ namespace build2
}
bool export_options::
- _parse (::build2::script::cli::scanner& s,
- ::build2::script::cli::unknown_mode opt_mode,
- ::build2::script::cli::unknown_mode arg_mode)
+ _parse (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt_mode,
+ ::build2::build::cli::unknown_mode arg_mode)
+ {
+ // Can't skip combined flags (--no-combined-flags).
+ //
+ assert (opt_mode != ::build2::build::cli::unknown_mode::skip);
+
+ bool r = false;
+ bool opt = true;
+
+ while (s.more ())
+ {
+ const char* o = s.peek ();
+
+ if (std::strcmp (o, "--") == 0)
+ {
+ opt = false;
+ s.skip ();
+ r = true;
+ continue;
+ }
+
+ if (opt)
+ {
+ if (_parse (o, s))
+ {
+ r = true;
+ continue;
+ }
+
+ if (std::strncmp (o, "-", 1) == 0 && o[1] != '\0')
+ {
+ // Handle combined option values.
+ //
+ std::string co;
+ if (const char* v = std::strchr (o, '='))
+ {
+ co.assign (o, 0, v - o);
+ ++v;
+
+ int ac (2);
+ char* av[] =
+ {
+ const_cast<char*> (co.c_str ()),
+ const_cast<char*> (v)
+ };
+
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
+
+ if (_parse (co.c_str (), ns))
+ {
+ // Parsed the option but not its value?
+ //
+ if (ns.end () != 2)
+ throw ::build2::build::cli::invalid_value (co, v);
+
+ s.next ();
+ r = true;
+ continue;
+ }
+ else
+ {
+ // Set the unknown option and fall through.
+ //
+ o = co.c_str ();
+ }
+ }
+
+ // Handle combined flags.
+ //
+ char cf[3];
+ {
+ const char* p = o + 1;
+ for (; *p != '\0'; ++p)
+ {
+ if (!((*p >= 'a' && *p <= 'z') ||
+ (*p >= 'A' && *p <= 'Z') ||
+ (*p >= '0' && *p <= '9')))
+ break;
+ }
+
+ if (*p == '\0')
+ {
+ for (p = o + 1; *p != '\0'; ++p)
+ {
+ std::strcpy (cf, "-");
+ cf[1] = *p;
+ cf[2] = '\0';
+
+ int ac (1);
+ char* av[] =
+ {
+ cf
+ };
+
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
+
+ if (!_parse (cf, ns))
+ break;
+ }
+
+ if (*p == '\0')
+ {
+ // All handled.
+ //
+ s.next ();
+ r = true;
+ continue;
+ }
+ else
+ {
+ // Set the unknown option and fall through.
+ //
+ o = cf;
+ }
+ }
+ }
+
+ switch (opt_mode)
+ {
+ case ::build2::build::cli::unknown_mode::skip:
+ {
+ s.skip ();
+ r = true;
+ continue;
+ }
+ case ::build2::build::cli::unknown_mode::stop:
+ {
+ break;
+ }
+ case ::build2::build::cli::unknown_mode::fail:
+ {
+ throw ::build2::build::cli::unknown_option (o);
+ }
+ }
+
+ break;
+ }
+ }
+
+ switch (arg_mode)
+ {
+ case ::build2::build::cli::unknown_mode::skip:
+ {
+ s.skip ();
+ r = true;
+ continue;
+ }
+ case ::build2::build::cli::unknown_mode::stop:
+ {
+ break;
+ }
+ case ::build2::build::cli::unknown_mode::fail:
+ {
+ throw ::build2::build::cli::unknown_argument (o);
+ }
+ }
+
+ break;
+ }
+
+ return r;
+ }
+
+ // for_options
+ //
+
+ for_options::
+ for_options ()
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ }
+
+ for_options::
+ for_options (int& argc,
+ char** argv,
+ bool erase,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
+ _parse (s, opt, arg);
+ }
+
+ for_options::
+ for_options (int start,
+ int& argc,
+ char** argv,
+ bool erase,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
+ _parse (s, opt, arg);
+ }
+
+ for_options::
+ for_options (int& argc,
+ char** argv,
+ int& end,
+ bool erase,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ ::build2::build::cli::argv_scanner s (argc, argv, erase);
+ _parse (s, opt, arg);
+ end = s.end ();
+ }
+
+ for_options::
+ for_options (int start,
+ int& argc,
+ char** argv,
+ int& end,
+ bool erase,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ ::build2::build::cli::argv_scanner s (start, argc, argv, erase);
+ _parse (s, opt, arg);
+ end = s.end ();
+ }
+
+ for_options::
+ for_options (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt,
+ ::build2::build::cli::unknown_mode arg)
+ : exact_ (),
+ newline_ (),
+ whitespace_ ()
+ {
+ _parse (s, opt, arg);
+ }
+
+ typedef
+ std::map<std::string, void (*) (for_options&, ::build2::build::cli::scanner&)>
+ _cli_for_options_map;
+
+ static _cli_for_options_map _cli_for_options_map_;
+
+ struct _cli_for_options_map_init
+ {
+ _cli_for_options_map_init ()
+ {
+ _cli_for_options_map_["--exact"] =
+ &::build2::build::cli::thunk< for_options, &for_options::exact_ >;
+ _cli_for_options_map_["-e"] =
+ &::build2::build::cli::thunk< for_options, &for_options::exact_ >;
+ _cli_for_options_map_["--newline"] =
+ &::build2::build::cli::thunk< for_options, &for_options::newline_ >;
+ _cli_for_options_map_["-n"] =
+ &::build2::build::cli::thunk< for_options, &for_options::newline_ >;
+ _cli_for_options_map_["--whitespace"] =
+ &::build2::build::cli::thunk< for_options, &for_options::whitespace_ >;
+ _cli_for_options_map_["-w"] =
+ &::build2::build::cli::thunk< for_options, &for_options::whitespace_ >;
+ }
+ };
+
+ static _cli_for_options_map_init _cli_for_options_map_init_;
+
+ bool for_options::
+ _parse (const char* o, ::build2::build::cli::scanner& s)
+ {
+ _cli_for_options_map::const_iterator i (_cli_for_options_map_.find (o));
+
+ if (i != _cli_for_options_map_.end ())
+ {
+ (*(i->second)) (*this, s);
+ return true;
+ }
+
+ return false;
+ }
+
+ bool for_options::
+ _parse (::build2::build::cli::scanner& s,
+ ::build2::build::cli::unknown_mode opt_mode,
+ ::build2::build::cli::unknown_mode arg_mode)
{
// Can't skip combined flags (--no-combined-flags).
//
- assert (opt_mode != ::build2::script::cli::unknown_mode::skip);
+ assert (opt_mode != ::build2::build::cli::unknown_mode::skip);
bool r = false;
bool opt = true;
@@ -1104,14 +1301,14 @@ namespace build2
const_cast<char*> (v)
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (_parse (co.c_str (), ns))
{
// Parsed the option but not its value?
//
if (ns.end () != 2)
- throw ::build2::script::cli::invalid_value (co, v);
+ throw ::build2::build::cli::invalid_value (co, v);
s.next ();
r = true;
@@ -1152,7 +1349,7 @@ namespace build2
cf
};
- ::build2::script::cli::argv_scanner ns (0, ac, av);
+ ::build2::build::cli::argv_scanner ns (0, ac, av);
if (!_parse (cf, ns))
break;
@@ -1177,19 +1374,19 @@ namespace build2
switch (opt_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_option (o);
+ throw ::build2::build::cli::unknown_option (o);
}
}
@@ -1199,19 +1396,19 @@ namespace build2
switch (arg_mode)
{
- case ::build2::script::cli::unknown_mode::skip:
+ case ::build2::build::cli::unknown_mode::skip:
{
s.skip ();
r = true;
continue;
}
- case ::build2::script::cli::unknown_mode::stop:
+ case ::build2::build::cli::unknown_mode::stop:
{
break;
}
- case ::build2::script::cli::unknown_mode::fail:
+ case ::build2::build::cli::unknown_mode::fail:
{
- throw ::build2::script::cli::unknown_argument (o);
+ throw ::build2::build::cli::unknown_argument (o);
}
}