Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
34414960
Commit
34414960
authored
Nov 26, 2014
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for option argument
parent
55bc70ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
CmdLineOptParser.cc
src/CmdLineOptParser.cc
+14
-3
CmdLineOptParser.h
src/CmdLineOptParser.h
+4
-2
No files found.
src/CmdLineOptParser.cc
View file @
34414960
...
...
@@ -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
];
...
...
src/CmdLineOptParser.h
View file @
34414960
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment