/* * This file was automaticly generated by clo++ version 0.6.3 (REL-0_6_3) * http://pmade.org/pjones/software/clo++/ * * Hacked to work with gcc 2.96 (dhess). */ /** @file * This file contains the implementation of the parser class. * You can control the name of this source file using the * cxx_source_file variable. **/ #include "clo.h" #include #include #include namespace { const char const_usage[] = " -v, --version Print the version and then exit.\n"; const char const_help_comment[] = "use the -h option for help"; const char* expand_long_name (const std::string &name); } //######################################################################### clo::parser::parser (void) : state_(state_option) { std::memset(&locations_, 0, sizeof(locations_)); } //######################################################################### void clo::parser::parse (int argc, char *argv[], bool call_finalize) { for (int i=1; i= 2 && element[0] == '-' && element[1] == '-') { if (length == 2) { state_ = state_consume; return; } element += 2; const char *value = element; while (*value != 0 && *value != '=') ++value; if (*value == '=') { std::string selement(element, value - element), svalue(++value); parse_long_option(selement.c_str(), position, source); if (state_ != state_value) { std::string error("the '"); error += element; error += "' option does not take a value"; throw option_error(error); } parse_value(svalue.c_str()); state_ = state_option; } else { parse_long_option(element, position, source); } } else if (length >= 2 && element[0] == '-') { ++element; if (length > 2) { while (*element != 0) { parse_short_option(*element, position, source); ++element; if (state_ == state_value && *element != 0) { parse_value(element); state_ = state_option; break; } } } else { parse_short_option(*element, position, source); } } else { non_options_.push_back(element); } break; case state_value: parse_value(element); state_ = state_option; break; } } //######################################################################### void clo::parser::parse_short_option (char option, int position, opsource source) { switch (option) { case 'v': throw autoexcept(autothrow_version, "version"); case 'h': if (source != source_cl) break; throw autoexcept(autothrow_help, const_usage); case '?': if (source != source_cl) break; throw autoexcept(autothrow_help, const_usage); } std::string error("unknown option: '"); error += option; error += "'"; throw option_error(error); } //######################################################################### void clo::parser::parse_long_option (const char *option, int position, opsource source) { option = expand_long_name(option); if (std::strcmp(option, "version") == 0) { throw autoexcept(autothrow_version, "version"); } else if (source == source_cl && std::strcmp(option, "help") == 0) { throw autoexcept(autothrow_help, const_usage); } std::string error("unknown option '"); error += option; error += "'"; throw option_error(error); } //######################################################################### void clo::parser::parse_value (const char *value) { } //######################################################################### const char* clo::option_error::get_help_comment (void) const { return const_help_comment; } //######################################################################### namespace { const char* expand_long_name (const std::string &name) { std::string::size_type name_size = name.size(); std::vector matches; if (name == "version") matches.push_back("version"); if (name == "help") matches.push_back("help"); if (matches.empty()) { std::string error("unknown option '"); error += name; error += "'"; throw clo::option_error(error); } if (matches.size() == 1) { return matches[0]; } std::string error("the option name '"); error += name; error += "' is ambiguous"; throw clo::option_error(error); } } // end anonymous namespace