diff options
author | Kim van der Riet <kpvdr@apache.org> | 2008-05-15 21:37:46 +0000 |
---|---|---|
committer | Kim van der Riet <kpvdr@apache.org> | 2008-05-15 21:37:46 +0000 |
commit | 4d72a636b1abc66f124d8fddad6f325093b6aa0f (patch) | |
tree | 49f1ec8e01a4cd87570094790e78ceeae4aa2f80 | |
parent | 66528d5ed7916352bd2ebbddd413874773020c6a (diff) | |
download | qpid-python-4d72a636b1abc66f124d8fddad6f325093b6aa0f.tar.gz |
Patch from michael goulish: QPID-1063: "under Boost 103200, command line args with = didn't work"
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@656855 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | cpp/src/Makefile.am | 2 | ||||
-rw-r--r-- | cpp/src/qpid/Options.cpp | 142 | ||||
-rw-r--r-- | cpp/src/tests/.valgrindrc | 1 |
3 files changed, 103 insertions, 42 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 3183aefd6c..160c0ffaae 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -126,7 +126,7 @@ endif # New 0-10 codec, to be integrated in future. # libqpidamqp_0_10_la_SOURCES= -EXTRA_DIST+=\ +EXTRA_DIST +=\ $(rgen_amqp_0_10_srcs) \ qpid/amqp_0_10/apply.h \ qpid/amqp_0_10/built_in_types.h \ diff --git a/cpp/src/qpid/Options.cpp b/cpp/src/qpid/Options.cpp index 9b59e83744..c1d3261f5f 100644 --- a/cpp/src/qpid/Options.cpp +++ b/cpp/src/qpid/Options.cpp @@ -179,51 +179,113 @@ void Options::parse(int argc, char** argv, const std::string& configFile, bool a if (!i->unregistered) filtopts.options.push_back (*i); po::store(filtopts, vm); + #elif ( BOOST_VERSION == 103200 ) - char ** filtered_argv = new char * [ argc ]; - filtered_argv[0] = strdup(argv[0]); - int filtered_argc = 1; - int i = 1; - while ( i < argc ) + /* + * "Tokenize" the argv to get rid of equals signs. + */ + vector<string> tokenized_argv; + vector<string>::iterator iter; + + for ( int i = 0; i < argc; ++ i ) { - /* - * If this is an argument that is registered, - * copy it to filtered_argv and also copy all - * of its arguments. - */ - if ( is_registered_option ( argv[i] ) ) - { - // Store this recognized arg. - filtered_argv [ filtered_argc ] = strdup ( argv[i] ); - ++ filtered_argc; - ++ i; - - // Copy all values for the above arg. - // Args are tokens that do not start with a minus. - while ( (i < argc) && ( '-' != argv[i][0] ) ) - { - filtered_argv [ filtered_argc ] = strdup ( argv[i] ); - ++ filtered_argc; - ++ i; - } - } - else - { - // Skip this unrecognized arg. - ++ i; - - // Copy all values for the above arg. - // Values are tokens that do not start with a minus. - while ( (i < argc) && ( '-' != argv[i][0] ) ) - { - ++ i; - } - } + string s = argv[i]; + int equals_pos = s.find_first_of ( '=' ); + + if ( string::npos == equals_pos ) // There's no equals sign. This is a token. + { + tokenized_argv.push_back(s); + } + else + { + // Two tokens -- before and after the equals position. + tokenized_argv.push_back ( s.substr(0, equals_pos) ); + tokenized_argv.push_back ( s.substr(equals_pos+1) ); + } } - po::basic_parsed_options<char> bpo = po::parse_command_line(filtered_argc, const_cast<char**>(filtered_argv), *this); - po::store(bpo, vm); + + /* + * Now "filter" the tokenized argv, to get rid of all + * unrecognized options. Because Boost 103200 has no + * facility for dealing gracefully with "unregistered" + * options. + */ + vector<string> filtered_argv; + vector<string>::iterator the_end = tokenized_argv.end(); + + // The program-name gets in for free... + iter = tokenized_argv.begin(); + filtered_argv.push_back ( * iter ); + ++ iter; + + // ...but all other args get checked. + while ( iter < the_end ) + { + /* + * If this is an argument that is registered, + * copy it to filtered_argv and also copy all + * of its arguments. + */ + if ( is_registered_option ( * iter ) ) + { + // Store this recognized arg. + filtered_argv.push_back ( * iter ); + ++ iter; + + // Copy all values for the above arg. + // Args are tokens that do not start with a minus. + while ( (iter < the_end) && ((* iter)[0] != '-') ) + { + filtered_argv.push_back ( * iter ); + ++ iter; + } + } + else + { + // Skip this unrecognized arg. + ++ iter; + + // Copy all values for the above arg. + // Values are tokens that do not start with a minus. + while ( (iter < the_end) && ( '-' != (*iter)[0] ) ) + { + ++ iter; + } + } + } + + // Make an array of temporary C strings, because + // the interface I can use wants it that way. + int new_argc = filtered_argv.size(); + char ** new_argv = new char * [ new_argc ]; + int i = 0; + + // cout << "NEW ARGV: |"; + for ( iter = filtered_argv.begin(); + iter < filtered_argv.end(); + ++ iter, ++ i + ) + { + new_argv[i] = strdup( (* iter).c_str() ); + // cout << " " << new_argv[i] ; + } + // cout << "|\n"; + + + // Use the array of C strings. + po::basic_parsed_options<char> bpo = po::parse_command_line(new_argc, const_cast<char**>(new_argv), *this); + po::store(bpo, vm); + + + // Now free the temporary C strings. + for ( i = 0; i < new_argc; ++ i ) + { + free ( new_argv[i] ); + } + delete[] new_argv; + #endif } else diff --git a/cpp/src/tests/.valgrindrc b/cpp/src/tests/.valgrindrc index 76bac021d8..4aba7661de 100644 --- a/cpp/src/tests/.valgrindrc +++ b/cpp/src/tests/.valgrindrc @@ -4,5 +4,4 @@ --suppressions=.valgrind.supp --num-callers=25 --trace-children=yes ---error-exitcode=1 |