// 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 BOOST_PROGRAM_OPTIONS_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace program_options { using namespace std; using namespace boost::program_options::command_line_style; invalid_syntax:: invalid_syntax(const string& tokens, kind_t kind) : error(error_message(kind).append(" in '").append(tokens).append("'")) , m_tokens(tokens) , m_kind(kind) {} string invalid_syntax::error_message(kind_t kind) { // Initially, store the message in 'const char*' variable, // to avoid conversion to 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; case unrecognized_line: msg = "unrecognized line"; break; default: msg = "unknown error"; } return msg; } invalid_syntax::kind_t invalid_syntax::kind() const { return m_kind; } const string& invalid_syntax::tokens() const { return m_tokens; } invalid_command_line_syntax:: invalid_command_line_syntax(const string& tokens, kind_t kind) : invalid_syntax(tokens, kind) {} }} namespace boost { namespace program_options { namespace detail { // vc6 needs this, but borland chokes when this is added. #if BOOST_WORKAROUND(_MSC_VER, < 1300) using namespace std; using namespace program_options; #endif cmdline::cmdline(const vector& args) { init(args); } cmdline::cmdline(int argc, const char*const * argv) { #if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) vector args; copy(argv+1, argv+argc+!argc, inserter(args, args.end())); init(args); #else init(vector(argv+1, argv+argc+!argc)); #endif } void cmdline::init(const 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) boost::throw_exception(invalid_command_line_style(error)); // Need to check that if guessing and long disguise are enabled // -f will mean the same as -foo } bool cmdline::is_style_active(style_t style) const { return ((m_style & style) ? true : false); } 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