From cbacc90d8fdc6be7693762e13b20a43d044ee185 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 14 May 2010 06:55:15 +0000 Subject: [PATCH] Merge from trunk [SVN r61962] --- doc/tutorial.xml | 18 +++++++++--------- example/Jamfile.v2 | 1 + example/multiple_sources.cpp | 2 +- src/options_description.cpp | 7 +++++-- src/winmain.cpp | 6 +++++- test/options_description_test.cpp | 11 +++++++++++ 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/doc/tutorial.xml b/doc/tutorial.xml index 4a89eba..d3e447a 100644 --- a/doc/tutorial.xml +++ b/doc/tutorial.xml @@ -77,13 +77,13 @@ if (vm.count("compression")) { It's now a good time to try compiling the code yourself, but if you're not yet ready, here's an example session: -$bin/gcc/debug/first +$ bin/gcc/debug/first Compression level was not set. -$bin/gcc/debug/first --help +$ bin/gcc/debug/first --help Allowed options: --help : produce help message --compression arg : set compression level -$bin/gcc/debug/first --compression 10 +$ bin/gcc/debug/first --compression 10 Compression level was set to 10. @@ -199,16 +199,16 @@ cout << "Optimization level is " << opt << "\n& Here's an example session: -$bin/gcc/debug/options_description --help +$ bin/gcc/debug/options_description --help Usage: options_description [options] Allowed options: --help : produce help message --optimization arg : optimization level -I [ --include-path ] arg : include path --input-file arg : input file -$bin/gcc/debug/options_description +$ bin/gcc/debug/options_description Optimization level is 10 -$bin/gcc/debug/options_description --optimization 4 -I foo a.cpp +$ bin/gcc/debug/options_description --optimization 4 -I foo a.cpp Include paths are: foo Input files are: a.cpp Optimization level is 4 @@ -308,10 +308,10 @@ visible.add(generic).add(config); Here's an example session: -$bin/gcc/debug/multiple_sources +$ bin/gcc/debug/multiple_sources Include paths are: /opt Optimization level is 1 -$bin/gcc/debug/multiple_sources --help +$ bin/gcc/debug/multiple_sources --help Allows options: Generic options: @@ -322,7 +322,7 @@ Configuration: --optimization n : optimization level -I [ --include-path ] path : include path -$bin/gcc/debug/multiple_sources --optimization=4 -I foo a.cpp b.cpp +$ bin/gcc/debug/multiple_sources --optimization=4 -I foo a.cpp b.cpp Include paths are: foo /opt Input files are: a.cpp b.cpp Optimization level is 4 diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 4125e7d..d669d3e 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -2,6 +2,7 @@ project : requirements ../build//boost_program_options true + static ; exe first : first.cpp ; diff --git a/example/multiple_sources.cpp b/example/multiple_sources.cpp index cdc54d0..1daef45 100644 --- a/example/multiple_sources.cpp +++ b/example/multiple_sources.cpp @@ -79,7 +79,7 @@ int main(int ac, char* av[]) ifstream ifs(config_file.c_str()); if (!ifs) { - cout << "can not open config file: " << config_file << "\n"; + cout << "can not open config file: " << config_file << "\n"; return 0; } else diff --git a/src/options_description.cpp b/src/options_description.cpp index bfd113d..0d8dfd4 100644 --- a/src/options_description.cpp +++ b/src/options_description.cpp @@ -306,6 +306,7 @@ namespace boost { namespace program_options { bool short_ignore_case) const { shared_ptr found; + bool had_full_match = false; vector approximate_matches; vector full_matches; @@ -323,15 +324,17 @@ namespace boost { namespace program_options { if (r == option_description::full_match) { full_matches.push_back(m_options[i]->key(name)); + found = m_options[i]; + had_full_match = true; } else { // FIXME: the use of 'key' here might not // be the best approach. approximate_matches.push_back(m_options[i]->key(name)); + if (!had_full_match) + found = m_options[i]; } - - found = m_options[i]; } if (full_matches.size() > 1) boost::throw_exception( diff --git a/src/winmain.cpp b/src/winmain.cpp index 64cc790..8a7c43f 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -30,6 +30,7 @@ namespace boost { namespace program_options { std::string current; bool inside_quoted = false; + bool empty_quote = false; int backslash_count = 0; for(; i != e; ++i) { @@ -38,6 +39,7 @@ namespace boost { namespace program_options { // n/2 backslashes and is a quoted block delimiter if (backslash_count % 2 == 0) { current.append(backslash_count / 2, '\\'); + empty_quote = inside_quoted && current.empty(); inside_quoted = !inside_quoted; // '"' preceded by odd number (n) of backslashes generates // (n-1)/2 backslashes and is literal quote. @@ -59,6 +61,7 @@ namespace boost { namespace program_options { // Space outside quoted section terminate the current argument result.push_back(current); current.resize(0); + empty_quote = false; for(;i != e && isspace((unsigned char)*i); ++i) ; --i; @@ -74,7 +77,7 @@ namespace boost { namespace program_options { // If we have non-empty 'current' or we're still in quoted // section (even if 'current' is empty), add the last token. - if (!current.empty() || inside_quoted) + if (!current.empty() || inside_quoted || empty_quote) result.push_back(current); } return result; @@ -94,3 +97,4 @@ namespace boost { namespace program_options { }} #endif + diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp index 11d9cd5..59f6bac 100644 --- a/test/options_description_test.cpp +++ b/test/options_description_test.cpp @@ -53,6 +53,17 @@ void test_approximation() BOOST_CHECK_EQUAL(desc.find("all", true).long_name(), "all"); BOOST_CHECK_EQUAL(desc.find("all-ch", true).long_name(), "all-chroots"); + options_description desc2; + desc2.add_options() + ("help", "display this message") + ("config", value(), "config file name") + ("config-value", value(), "single config value") + ; + + BOOST_CHECK_EQUAL(desc2.find("config", true).long_name(), "config"); + BOOST_CHECK_EQUAL(desc2.find("config-value", true).long_name(), + "config-value"); + // BOOST_CHECK(desc.count_approx("foo") == 1); // set a = desc.approximations("f");