Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5ab086e3
Commit
5ab086e3
authored
Jan 16, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/OptionParser: loop in ParseNext() until a new option is found
parent
68f660db
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
32 deletions
+24
-32
CommandLine.cxx
src/CommandLine.cxx
+1
-3
OptionDef.hxx
src/util/OptionDef.hxx
+2
-0
OptionParser.cxx
src/util/OptionParser.cxx
+15
-15
OptionParser.hxx
src/util/OptionParser.hxx
+6
-14
No files found.
src/CommandLine.cxx
View file @
5ab086e3
...
...
@@ -313,9 +313,7 @@ ParseCommandLine(int argc, char **argv, struct options *options)
// First pass: handle command line options
OptionParser
parser
(
argc
,
argv
);
while
(
parser
.
HasEntries
())
{
if
(
!
parser
.
ParseNext
())
continue
;
while
(
parser
.
ParseNext
())
{
if
(
parser
.
CheckOption
(
opt_kill
))
{
options
->
kill
=
true
;
continue
;
...
...
src/util/OptionDef.hxx
View file @
5ab086e3
...
...
@@ -20,6 +20,8 @@
#ifndef MPD_UTIL_OPTIONDEF_HXX
#define MPD_UTIL_OPTIONDEF_HXX
#include <assert.h>
/**
* Command line option definition.
*/
...
...
src/util/OptionParser.cxx
View file @
5ab086e3
...
...
@@ -39,23 +39,23 @@ OptionParser::CheckOption(const OptionDef &opt) const noexcept
bool
OptionParser
::
ParseNext
()
noexcept
{
assert
(
HasEntries
());
const
char
*
arg
=
args
.
shift
();
if
(
arg
[
0
]
==
'-'
)
{
if
(
arg
[
1
]
==
'-'
)
{
option
=
arg
+
2
;
is_long
=
true
;
while
(
!
args
.
empty
())
{
const
char
*
arg
=
args
.
shift
();
if
(
arg
[
0
]
==
'-'
)
{
if
(
arg
[
1
]
==
'-'
)
{
option
=
arg
+
2
;
is_long
=
true
;
}
else
{
option
=
arg
+
1
;
is_long
=
false
;
}
option_raw
=
arg
;
return
true
;
}
else
{
option
=
arg
+
1
;
is_long
=
false
;
}
option_raw
=
arg
;
return
true
;
*
remaining_tail
++
=
arg
;
}
option
=
nullptr
;
option_raw
=
nullptr
;
*
remaining_tail
++
=
arg
;
return
false
;
}
src/util/OptionParser.hxx
View file @
5ab086e3
...
...
@@ -22,8 +22,6 @@
#include "util/ConstBuffer.hxx"
#include <assert.h>
class
OptionDef
;
/**
...
...
@@ -32,8 +30,8 @@ class OptionDef;
class
OptionParser
{
ConstBuffer
<
const
char
*>
args
;
const
char
*
option
=
nullptr
;
const
char
*
option_raw
=
nullptr
;
const
char
*
option
;
const
char
*
option_raw
;
bool
is_long
=
false
;
const
char
**
const
remaining_head
,
**
remaining_tail
;
...
...
@@ -42,23 +40,15 @@ public:
/**
* Constructs #OptionParser.
*/
constexpr
OptionParser
(
int
_argc
,
char
**
_argv
)
noexcept
OptionParser
(
int
_argc
,
char
**
_argv
)
noexcept
:
args
(
_argv
+
1
,
_argc
-
1
),
remaining_head
(
const_cast
<
const
char
**>
(
_argv
+
1
)),
remaining_tail
(
remaining_head
)
{}
/**
* Checks if there are command line entries to process.
*/
constexpr
bool
HasEntries
()
const
noexcept
{
return
!
args
.
empty
();
}
/**
* Gets the last parsed option.
*/
const
char
*
GetOption
()
noexcept
{
assert
(
option_raw
!=
nullptr
);
return
option_raw
;
}
...
...
@@ -78,9 +68,11 @@ public:
/**
* Parses current command line entry.
* Returns true on success, false otherwise.
* Regardless of result, advances current position to the next
* command line entry.
*
* @return true if an option was found, false if there are no
* more options
*/
bool
ParseNext
()
noexcept
;
...
...
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