X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fgetopt.cpp;h=34e53172aeb194d1cebc29c7df4de8719add8c27;hp=911b673d9b1d28358966a302de44aaf6428735e3;hb=9f8d6a18f68fb54b62e9f4a5cf1a1650282b3667;hpb=736d15fbdee0ea47b38a4d5fcd321e86eb21b465 diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index 911b673..34e5317 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -21,7 +21,7 @@ GetOpt::OptBase &GetOpt::add_option(OptBase *opt) { for(list::iterator i=opts.begin(); i!=opts.end(); ) { - if((*i)->get_short()==opt->get_short() || (*i)->get_long()==opt->get_long()) + if((opt->get_short()!=0 && (*i)->get_short()==opt->get_short()) || (*i)->get_long()==opt->get_long()) { delete *i; opts.erase(i++); @@ -227,6 +227,7 @@ GetOpt::OptBase::OptBase(char s, const std::string &l, ArgType a): lng(l), arg_type(a), seen_count(0), + ext_seen_count(0), metavar("ARG") { if(lng.empty()) @@ -246,11 +247,19 @@ GetOpt::OptBase &GetOpt::OptBase::set_help(const string &h, const string &m) return *this; } +GetOpt::OptBase &GetOpt::OptBase::bind_seen_count(unsigned &c) +{ + ext_seen_count = &c; + return *this; +} + void GetOpt::OptBase::process() { if(arg_type==REQUIRED_ARG) throw usage_error("--"+lng+" requires an argument"); ++seen_count; + if(ext_seen_count) + *ext_seen_count = seen_count; store(); } @@ -260,6 +269,8 @@ void GetOpt::OptBase::process(const string &arg) if(arg_type==NO_ARG) throw usage_error("--"+lng+" takes no argument"); ++seen_count; + if(ext_seen_count) + *ext_seen_count = seen_count; store(arg); }