diff options
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/b-options.cxx | 79 | ||||
-rw-r--r-- | libbuild2/build/script/builtin-options.cxx | 41 | ||||
-rw-r--r-- | libbuild2/common-options.cxx | 36 | ||||
-rw-r--r-- | libbuild2/script/builtin-options.cxx | 53 |
4 files changed, 162 insertions, 47 deletions
diff --git a/libbuild2/b-options.cxx b/libbuild2/b-options.cxx index 531e453..8d82d61 100644 --- a/libbuild2/b-options.cxx +++ b/libbuild2/b-options.cxx @@ -19,6 +19,7 @@ #include <utility> #include <ostream> #include <sstream> +#include <cstring> namespace build2 { @@ -59,10 +60,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; } static void @@ -218,6 +240,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) @@ -229,7 +259,6 @@ namespace build2 } #include <map> -#include <cstring> namespace build2 { @@ -929,24 +958,24 @@ namespace build2 &::build2::build::cli::thunk< b_options, uint64_t, &b_options::build2_metadata_, &b_options::build2_metadata_specified_ >; _cli_b_options_map_["-v"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::v_ >; + &::build2::build::cli::thunk< b_options, &b_options::v_ >; _cli_b_options_map_["-V"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::V_ >; + &::build2::build::cli::thunk< b_options, &b_options::V_ >; _cli_b_options_map_["--quiet"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::quiet_ >; + &::build2::build::cli::thunk< b_options, &b_options::quiet_ >; _cli_b_options_map_["-q"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::quiet_ >; + &::build2::build::cli::thunk< b_options, &b_options::quiet_ >; _cli_b_options_map_["--silent"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::silent_ >; + &::build2::build::cli::thunk< b_options, &b_options::silent_ >; _cli_b_options_map_["--verbose"] = &::build2::build::cli::thunk< b_options, uint16_t, &b_options::verbose_, &b_options::verbose_specified_ >; _cli_b_options_map_["--stat"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::stat_ >; + &::build2::build::cli::thunk< b_options, &b_options::stat_ >; _cli_b_options_map_["--progress"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::progress_ >; + &::build2::build::cli::thunk< b_options, &b_options::progress_ >; _cli_b_options_map_["--no-progress"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_progress_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_progress_ >; _cli_b_options_map_["--jobs"] = &::build2::build::cli::thunk< b_options, size_t, &b_options::jobs_, &b_options::jobs_specified_ >; @@ -972,24 +1001,24 @@ namespace build2 &::build2::build::cli::thunk< b_options, size_t, &b_options::max_stack_, &b_options::max_stack_specified_ >; _cli_b_options_map_["--serial-stop"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::serial_stop_ >; + &::build2::build::cli::thunk< b_options, &b_options::serial_stop_ >; _cli_b_options_map_["-s"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::serial_stop_ >; + &::build2::build::cli::thunk< b_options, &b_options::serial_stop_ >; _cli_b_options_map_["--dry-run"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::dry_run_ >; + &::build2::build::cli::thunk< b_options, &b_options::dry_run_ >; _cli_b_options_map_["-n"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::dry_run_ >; + &::build2::build::cli::thunk< b_options, &b_options::dry_run_ >; _cli_b_options_map_["--match-only"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::match_only_ >; + &::build2::build::cli::thunk< b_options, &b_options::match_only_ >; _cli_b_options_map_["--no-external-modules"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_external_modules_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_external_modules_ >; _cli_b_options_map_["--structured-result"] = &::build2::build::cli::thunk< b_options, structured_result_format, &b_options::structured_result_, &b_options::structured_result_specified_ >; _cli_b_options_map_["--mtime-check"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::mtime_check_ >; + &::build2::build::cli::thunk< b_options, &b_options::mtime_check_ >; _cli_b_options_map_["--no-mtime-check"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_mtime_check_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_mtime_check_ >; _cli_b_options_map_["--dump"] = &::build2::build::cli::thunk< b_options, std::set<string>, &b_options::dump_, &b_options::dump_specified_ >; @@ -1000,9 +1029,9 @@ namespace build2 &::build2::build::cli::thunk< b_options, std::vector<name>, &b_options::trace_execute_, &b_options::trace_execute_specified_ >; _cli_b_options_map_["--no-column"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_column_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_column_ >; _cli_b_options_map_["--no-line"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_line_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_line_ >; _cli_b_options_map_["--buildfile"] = &::build2::build::cli::thunk< b_options, path, &b_options::buildfile_, &b_options::buildfile_specified_ >; @@ -1025,11 +1054,11 @@ namespace build2 &::build2::build::cli::thunk< b_options, dir_path, &b_options::default_options_, &b_options::default_options_specified_ >; _cli_b_options_map_["--no-default-options"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::no_default_options_ >; + &::build2::build::cli::thunk< b_options, &b_options::no_default_options_ >; _cli_b_options_map_["--help"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::help_ >; + &::build2::build::cli::thunk< b_options, &b_options::help_ >; _cli_b_options_map_["--version"] = - &::build2::build::cli::thunk< b_options, bool, &b_options::version_ >; + &::build2::build::cli::thunk< b_options, &b_options::version_ >; } }; diff --git a/libbuild2/build/script/builtin-options.cxx b/libbuild2/build/script/builtin-options.cxx index 6fae0b4..f7ba0e7 100644 --- a/libbuild2/build/script/builtin-options.cxx +++ b/libbuild2/build/script/builtin-options.cxx @@ -19,6 +19,7 @@ #include <utility> #include <ostream> #include <sstream> +#include <cstring> namespace build2 { @@ -53,10 +54,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; } }; @@ -173,6 +195,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) @@ -184,7 +214,6 @@ namespace build2 } #include <map> -#include <cstring> namespace build2 { @@ -306,12 +335,12 @@ namespace build2 &::build2::build::cli::thunk< depdb_dyndep_options, string, &depdb_dyndep_options::default_type_, &depdb_dyndep_options::default_type_specified_ >; _cli_depdb_dyndep_options_map_["--adhoc"] = - &::build2::build::cli::thunk< depdb_dyndep_options, bool, &depdb_dyndep_options::adhoc_ >; + &::build2::build::cli::thunk< depdb_dyndep_options, &depdb_dyndep_options::adhoc_ >; _cli_depdb_dyndep_options_map_["--cwd"] = &::build2::build::cli::thunk< depdb_dyndep_options, dir_path, &depdb_dyndep_options::cwd_, &depdb_dyndep_options::cwd_specified_ >; _cli_depdb_dyndep_options_map_["--drop-cycles"] = - &::build2::build::cli::thunk< depdb_dyndep_options, bool, &depdb_dyndep_options::drop_cycles_ >; + &::build2::build::cli::thunk< depdb_dyndep_options, &depdb_dyndep_options::drop_cycles_ >; } }; diff --git a/libbuild2/common-options.cxx b/libbuild2/common-options.cxx index 5c58a62..4be0289 100644 --- a/libbuild2/common-options.cxx +++ b/libbuild2/common-options.cxx @@ -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; } }; @@ -707,6 +728,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 +747,6 @@ namespace build2 } #include <map> -#include <cstring> namespace build2 { diff --git a/libbuild2/script/builtin-options.cxx b/libbuild2/script/builtin-options.cxx index 7589faf..8e15ddd 100644 --- a/libbuild2/script/builtin-options.cxx +++ b/libbuild2/script/builtin-options.cxx @@ -18,6 +18,7 @@ #include <utility> #include <ostream> #include <sstream> +#include <cstring> namespace build2 { @@ -52,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; } }; @@ -172,6 +194,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) @@ -183,7 +213,6 @@ namespace build2 } #include <map> -#include <cstring> namespace build2 { @@ -284,17 +313,17 @@ namespace build2 _cli_set_options_map_init () { _cli_set_options_map_["--exact"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::exact_ >; + &::build2::build::cli::thunk< set_options, &set_options::exact_ >; _cli_set_options_map_["-e"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::exact_ >; + &::build2::build::cli::thunk< set_options, &set_options::exact_ >; _cli_set_options_map_["--newline"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::newline_ >; + &::build2::build::cli::thunk< set_options, &set_options::newline_ >; _cli_set_options_map_["-n"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::newline_ >; + &::build2::build::cli::thunk< set_options, &set_options::newline_ >; _cli_set_options_map_["--whitespace"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::whitespace_ >; + &::build2::build::cli::thunk< set_options, &set_options::whitespace_ >; _cli_set_options_map_["-w"] = - &::build2::build::cli::thunk< set_options, bool, &set_options::whitespace_ >; + &::build2::build::cli::thunk< set_options, &set_options::whitespace_ >; } }; @@ -563,9 +592,9 @@ namespace build2 _cli_timeout_options_map_init () { _cli_timeout_options_map_["--success"] = - &::build2::build::cli::thunk< timeout_options, bool, &timeout_options::success_ >; + &::build2::build::cli::thunk< timeout_options, &timeout_options::success_ >; _cli_timeout_options_map_["-s"] = - &::build2::build::cli::thunk< timeout_options, bool, &timeout_options::success_ >; + &::build2::build::cli::thunk< timeout_options, &timeout_options::success_ >; } }; |