diff -r 000000000000 -r 4426ecd854bb options.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/options.cpp Mon Aug 08 16:16:42 2005 +0000 @@ -0,0 +1,144 @@ +#include "options.h" +#include + +#include + +using namespace std; + + +Option::Option() +{ + name=""; + sName=""; + lName=""; + type=SwitchOption; + sarg=""; + active=false; +} + +void Option::set(const QString &n, const OptionType &t, const QString &s, const QString &l) +{ + sName="-"+s; + lName="--"+l; + type=t; + name=n; +} + +QString Option::getName () { return name; } +QString Option::getShort () { return sName; } +QString Option::getLong() { return lName; } +OptionType Option::getType() { return type; } +void Option::setArg(const QString& s) { sarg=s; } +QString Option::getArg() { return sarg; } +void Option::setActive() { active=true; } +bool Option::isActive() { return active; } + +/////////////////////////////////////////////////////////////// +Options::Options() {} + +int Options::parse() +{ + QStringList arglist; + int i=0; + while (iargc()) + { + arglist.append (qApp->argv()[i]); + i++; + } + + // Get program name + progname=arglist.first(); + arglist.pop_front(); + + // Work through rest of options + bool isFile; + OptionList::iterator itopt; + QStringList::iterator itarg; + itarg=arglist.begin(); + while (itarg!=arglist.end()) + { + isFile=true; + if ((*itarg).left(1)=="-") + { + // Compare given option to all defined options + itopt=optlist.begin(); + while (itopt!=optlist.end()) + { + if ((*itarg)==(*itopt).getShort() || + (*itarg)==(*itopt).getLong()) + { + (*itopt).setActive(); + isFile=false; + if ((*itopt).getType()==StringOption) + { + itarg++; + if (itarg==arglist.end()) + { + cout << "Error: argument to option missing\n"; + return 1; + } + (*itopt).setArg (*itarg); + isFile=false; + } + break; + } + itopt++; + } + if (isFile) + { + cout << "Error: Unknown argument "<<*itarg<