//---------------------------------------------------------------------------- // The following file was processed with boost/tools/bcp // to change namespace and paths to include files. The intention // of this processing is to allow non-boost library developers // to use the boost libararies internally in their product without // risking potential interfaring with the users of their non-boost // libraries use of other versions of the boost libraries in their // projects.namespace 'boost' has been replaced with namespace 'spoost'. // original file: BOOST_PATH/libs/program_options/src/cmdline.cpp //---------------------------------------------------------------------------- // Copyright Vladimir Prus 2002-2004. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #define SPOOST_PROGRAM_OPTIONS_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace spoost { namespace program_options { using namespace std; using namespace spoost::program_options::command_line_style; invalid_command_line_syntax:: invalid_command_line_syntax(const std::string& tokens, kind_t kind) : invalid_syntax(tokens, error_message(kind)), m_kind(kind) {} std::string invalid_command_line_syntax::error_message(kind_t kind) { // Initially, store the message in 'const char*' variable, // to avoid conversion to std::string in all cases. const char* msg; switch(kind) { case long_not_allowed: msg = "long options are not allowed"; break; case long_adjacent_not_allowed: msg = "parameters adjacent to long options not allowed"; break; case short_adjacent_not_allowed: msg = "parameters adjust to short options are not allowed"; break; case empty_adjacent_parameter: msg = "adjacent parameter is empty"; break; case missing_parameter: msg = "required parameter is missing"; break; case extra_parameter: msg = "extra parameter"; break; default: msg = "unknown error"; } return msg; } invalid_command_line_syntax::kind_t invalid_command_line_syntax::kind() const { return m_kind; } }} namespace spoost { namespace program_options { namespace detail { // vc6 needs this, but borland chokes when this is added. #if SPOOST_WORKAROUND(_MSC_VER, <= 1200) using namespace std; using namespace program_options; #endif cmdline::cmdline(const std::vector& args) { init(args); } cmdline::cmdline(int argc, const char*const * argv) { #if defined(SPOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) vector args; copy(argv+1, argv+argc, inserter(args, args.end())); init(args); #else init(vector(argv+1, argv+argc)); #endif } void cmdline::init(const std::vector& args) { this->args = args; m_style = command_line_style::default_style; m_desc = 0; m_positional = 0; m_allow_unregistered = false; } void cmdline::style(int style) { if (style == 0) style = default_style; check_style(style); this->m_style = style_t(style); } void cmdline::allow_unregistered() { this->m_allow_unregistered = true; } void cmdline::check_style(int style) const { bool allow_some_long = (style & allow_long) || (style & allow_long_disguise); const char* error = 0; if (allow_some_long && !(style & long_allow_adjacent) && !(style & long_allow_next)) error = "style disallows parameters for long options"; if (!error && (style & allow_short) && !(style & short_allow_adjacent) && !(style & short_allow_next)) error = "style disallows parameters for short options"; if (!error && (style & allow_short) && !(style & allow_dash_for_short) && !(style & allow_slash_for_short)) error = "style disallows all characters for short options"; if (error) throw invalid_command_line_style(error); // Need to check that if guessing and long disguise are enabled // -f will mean the same as -foo } void cmdline::set_options_description(const options_description& desc) { m_desc = &desc; } void cmdline::set_positional_options( const positional_options_description& positional) { m_positional = &positional; } vector