From cfb91e263c22f6f81ae05a2027a2befac6d41e06 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 4 Oct 2009 10:50:50 +0200 Subject: Add --reserved-name option --- cli/options.cxx | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 4 deletions(-) (limited to 'cli/options.cxx') diff --git a/cli/options.cxx b/cli/options.cxx index 803e22b..b47a5c8 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -4,6 +4,7 @@ #include "options.hxx" +#include #include #include #include @@ -146,6 +147,64 @@ namespace cli } }; + template + struct parser > + { + static int + parse (std::map& m, char** argv, int n) + { + if (n > 1) + { + std::string s (argv[1]); + std::string::size_type p (s.find ('=')); + + if (p == std::string::npos) + { + K k = K (); + + if (!s.empty ()) + { + std::istringstream ks (s); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + m[k] = V (); + } + else + { + K k = K (); + V v = V (); + std::string kstr (s, 0, p); + std::string vstr (s, p + 1); + + if (!kstr.empty ()) + { + std::istringstream ks (kstr); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + if (!vstr.empty ()) + { + std::istringstream vs (vstr); + + if (!(vs >> v && vs.eof ())) + throw invalid_value (argv[0], argv[1]); + } + + m[k] = v; + } + + return 2; + } + else + throw missing_value (argv[0]); + } + }; + template int thunk (X& x, char** argv, int n) @@ -174,7 +233,8 @@ options (int argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { _parse (1, argc, argv, opt, arg); } @@ -194,7 +254,8 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { _parse (start, argc, argv, opt, arg); } @@ -214,7 +275,8 @@ options (int argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { end = _parse (1, argc, argv, opt, arg); } @@ -235,7 +297,8 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - guard_prefix_ () + guard_prefix_ (), + reserved_name_ () { end = _parse (start, argc, argv, opt, arg); } @@ -270,6 +333,8 @@ struct _cli_options_map_init &::cli::thunk; _cli_options_map_["--guard-prefix"] = &::cli::thunk; + _cli_options_map_["--reserved-name"] = + &::cli::thunk, &options::reserved_name_>; } } _cli_options_map_init_; -- cgit v1.1