Commit 34414960 authored by Don Gagne's avatar Don Gagne

Add support for option argument

parent 55bc70ff
......@@ -39,13 +39,24 @@ void ParseCmdLineOptions(int& argc, ///< count of ar
{
// Start with all options off
for (size_t iOption=0; iOption<cOpts; iOption++) {
*prgOpts[iOption].flag = false;
*prgOpts[iOption].optionFound = false;
}
for (int iArg=1; iArg<argc; iArg++) {
for (size_t iOption=0; iOption<cOpts; iOption++) {
if (QString(argv[iArg]).compare(prgOpts[iOption].optionStr, Qt::CaseInsensitive) == 0) {
*prgOpts[iOption].flag = true;
bool found = false;
QString arg(argv[iArg]);
QString optionStr(prgOpts[iOption].optionStr);
if (arg.startsWith(QString("%1:").arg(optionStr), Qt::CaseInsensitive)) {
found = true;
prgOpts[iOption].optionArg = arg.right(arg.length() - (optionStr.length() + 1));
} else if (arg.compare(optionStr, Qt::CaseInsensitive) == 0) {
found = true;
}
if (found) {
*prgOpts[iOption].optionFound = true;
if (removeParsedOptions) {
for (int iShift=iArg; iShift<argc-1; iShift++) {
argv[iShift] = argv[iShift+1];
......
......@@ -29,12 +29,14 @@
#ifndef CMDLINEOPTPARSER_H
#define CMDLINEOPTPARSER_H
#include <QString>
#include <cstring>
/// @brief Structure used to pass command line options to the ParseCmdLineOptions function.
typedef struct {
const char* optionStr; ///< command line option, for example "--foo"
bool* flag; ///< if option is found this variable will be set to true
const char* optionStr; ///< command line option, for example "--foo"
bool* optionFound; ///< if option is found this variable will be set to true
QString optionArg; ///< Option has additional argument, form is option:arg
} CmdLineOpt_t;
void ParseCmdLineOptions(int& argc,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment