diff -r 7a96bd401351 -r 32f499cbe874 options.cpp --- a/options.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/options.cpp Fri Mar 05 19:15:08 2010 +0000 @@ -1,7 +1,8 @@ #include "options.h" + #include +#include -#include using namespace std; @@ -11,12 +12,20 @@ name=""; sName=""; lName=""; - type=SwitchOption; + type=Switch; sarg=""; active=false; } -void Option::set(const QString &n, const OptionType &t, const QString &s, const QString &l) +Option::Option (const QString &n, const Type &t, const QString &s, const QString &l) +{ + sName="-"+s; + lName="--"+l; + type=t; + name=n; +} + +void Option::set(const QString &n, const Type &t, const QString &s, const QString &l) { sName="-"+s; lName="--"+l; @@ -27,7 +36,7 @@ QString Option::getName () { return name; } QString Option::getShort () { return sName; } QString Option::getLong() { return lName; } -OptionType Option::getType() { return type; } +Option::Type Option::getType() { return type; } void Option::setArg(const QString& s) { sarg=s; } QString Option::getArg() { return sarg; } void Option::setActive() { active=true; } @@ -38,13 +47,7 @@ int Options::parse() { - QStringList arglist; - int i=0; - while (iargc()) - { - arglist.append (qApp->argv()[i]); - i++; - } + QStringList arglist=qApp->arguments(); // Get program name progname=arglist.first(); @@ -52,51 +55,50 @@ // Work through rest of options bool isFile; - OptionList::iterator itopt; - QStringList::iterator itarg; - itarg=arglist.begin(); - while (itarg!=arglist.end()) + for (int i=0; i< arglist.size(); ++i) { isFile=true; - if ((*itarg).left(1)=="-") + if (arglist[i].left(1)=="-") { // Compare given option to all defined options - itopt=optlist.begin(); - while (itopt!=optlist.end()) + for (int j=0; j < optlist.size(); ++j) { - if ((*itarg)==(*itopt).getShort() || - (*itarg)==(*itopt).getLong()) + if (arglist.at(i)==optlist.value(j).getShort() || + arglist.at(i)==optlist.value(j).getLong()) { - (*itopt).setActive(); + optlist[j].setActive(); isFile=false; - if ((*itopt).getType()==StringOption) + if (optlist[j].getType()==Option::String) { - itarg++; - if (itarg==arglist.end()) + i++; + if (i==arglist.size()) { - cout << "Error: argument to option missing\n"; + qWarning ("Error: argument to option missing"); return 1; } - (*itopt).setArg (*itarg); + optlist[j].setArg (arglist[i]); isFile=false; } break; } - itopt++; } if (isFile) { - cout << "Error: Unknown argument "<<*itarg<