Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52441 - in trunk/libs/program_options: src test
From: ghost_at_[hidden]
Date: 2009-04-17 06:01:38


Author: vladimir_prus
Date: 2009-04-17 06:01:38 EDT (Fri, 17 Apr 2009)
New Revision: 52441
URL: http://svn.boost.org/trac/boost/changeset/52441

Log:
Sync trunk&release branches
Text files modified:
   trunk/libs/program_options/src/cmdline.cpp | 17 ++++++++++++++---
   trunk/libs/program_options/test/parsers_test.cpp | 29 +++++++++++++++++++++++++++++
   2 files changed, 43 insertions(+), 3 deletions(-)

Modified: trunk/libs/program_options/src/cmdline.cpp
==============================================================================
--- trunk/libs/program_options/src/cmdline.cpp (original)
+++ trunk/libs/program_options/src/cmdline.cpp 2009-04-17 06:01:38 EDT (Fri, 17 Apr 2009)
@@ -23,6 +23,7 @@
 #include <cassert>
 #include <cstring>
 #include <cctype>
+#include <climits>
 
 #include <cstdio>
 
@@ -272,8 +273,8 @@
             if (!xd)
                 continue;
 
- int min_tokens = xd->semantic()->min_tokens();
- int max_tokens = xd->semantic()->max_tokens();
+ unsigned min_tokens = xd->semantic()->min_tokens();
+ unsigned max_tokens = xd->semantic()->max_tokens();
             if (min_tokens < max_tokens && opt.value.size() < max_tokens)
             {
                 // This option may grab some more tokens.
@@ -281,13 +282,21 @@
                 // recognized as key options.
 
                 int can_take_more = max_tokens - opt.value.size();
- int j = i+1;
+ unsigned j = i+1;
                 for (; can_take_more && j < result.size(); --can_take_more, ++j)
                 {
                     option& opt2 = result[j];
                     if (!opt2.string_key.empty())
                         break;
 
+ if (opt2.position_key == INT_MAX)
+ {
+ // We use INT_MAX to mark positional options that
+ // were found after the '--' terminator and therefore
+ // should stay positional forever.
+ break;
+ }
+
                     assert(opt2.value.size() == 1);
                     
                     opt.value.push_back(opt2.value[0]);
@@ -543,6 +552,8 @@
             {
                 option opt;
                 opt.value.push_back(args[i]);
+ opt.original_tokens.push_back(args[i]);
+ opt.position_key = INT_MAX;
                 result.push_back(opt);
             }
             args.clear();

Modified: trunk/libs/program_options/test/parsers_test.cpp
==============================================================================
--- trunk/libs/program_options/test/parsers_test.cpp (original)
+++ trunk/libs/program_options/test/parsers_test.cpp 2009-04-17 06:01:38 EDT (Fri, 17 Apr 2009)
@@ -163,6 +163,35 @@
     BOOST_CHECK_EQUAL(a5[1].value[1], "2");
     BOOST_CHECK_EQUAL(a5[1].value[2], "3");
     check_value(a5[2], "-x", "8");
+
+
+ po::options_description desc4( "" );
+ desc4.add_options()
+ ( "multitoken,m",
+ po::value< std::vector< std::string > >()->multitoken(),
+ "values"
+ )
+ ( "file",
+ po::value< std::string >(),
+ "the file to process"
+ )
+ ;
+
+ po::positional_options_description p;
+ p.add( "file", 1 );
+
+ char* cmdline6[] = {"", "-m", "token1", "token2", "--", "some_file"};
+ vector<option> a6 =
+ command_line_parser(6, cmdline6).options(desc4).positional(p)
+ .run().options;
+ BOOST_CHECK_EQUAL(a6.size(), 2u);
+ BOOST_REQUIRE(a6[0].value.size() == 2);
+ BOOST_CHECK_EQUAL(a6[0].string_key, "multitoken");
+ BOOST_CHECK_EQUAL(a6[0].value[0], "token1");
+ BOOST_CHECK_EQUAL(a6[0].value[1], "token2");
+ BOOST_CHECK_EQUAL(a6[1].string_key, "file");
+ BOOST_REQUIRE(a6[1].value.size() == 1);
+ BOOST_CHECK_EQUAL(a6[1].value[0], "some_file");
 }
 
 void test_config_file()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk