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
7 years ago
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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
20 deletions
+12
-20
CommandLine.cxx
src/CommandLine.cxx
+1
-3
OptionDef.hxx
src/util/OptionDef.hxx
+2
-0
OptionParser.cxx
src/util/OptionParser.cxx
+3
-3
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)
...
@@ -313,9 +313,7 @@ ParseCommandLine(int argc, char **argv, struct options *options)
// First pass: handle command line options
// First pass: handle command line options
OptionParser
parser
(
argc
,
argv
);
OptionParser
parser
(
argc
,
argv
);
while
(
parser
.
HasEntries
())
{
while
(
parser
.
ParseNext
())
{
if
(
!
parser
.
ParseNext
())
continue
;
if
(
parser
.
CheckOption
(
opt_kill
))
{
if
(
parser
.
CheckOption
(
opt_kill
))
{
options
->
kill
=
true
;
options
->
kill
=
true
;
continue
;
continue
;
...
...
This diff is collapsed.
Click to expand it.
src/util/OptionDef.hxx
View file @
5ab086e3
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#ifndef MPD_UTIL_OPTIONDEF_HXX
#ifndef MPD_UTIL_OPTIONDEF_HXX
#define MPD_UTIL_OPTIONDEF_HXX
#define MPD_UTIL_OPTIONDEF_HXX
#include <assert.h>
/**
/**
* Command line option definition.
* Command line option definition.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/util/OptionParser.cxx
View file @
5ab086e3
...
@@ -39,7 +39,7 @@ OptionParser::CheckOption(const OptionDef &opt) const noexcept
...
@@ -39,7 +39,7 @@ OptionParser::CheckOption(const OptionDef &opt) const noexcept
bool
bool
OptionParser
::
ParseNext
()
noexcept
OptionParser
::
ParseNext
()
noexcept
{
{
assert
(
HasEntries
());
while
(
!
args
.
empty
())
{
const
char
*
arg
=
args
.
shift
();
const
char
*
arg
=
args
.
shift
();
if
(
arg
[
0
]
==
'-'
)
{
if
(
arg
[
0
]
==
'-'
)
{
if
(
arg
[
1
]
==
'-'
)
{
if
(
arg
[
1
]
==
'-'
)
{
...
@@ -54,8 +54,8 @@ OptionParser::ParseNext() noexcept
...
@@ -54,8 +54,8 @@ OptionParser::ParseNext() noexcept
return
true
;
return
true
;
}
}
option
=
nullptr
;
option_raw
=
nullptr
;
*
remaining_tail
++
=
arg
;
*
remaining_tail
++
=
arg
;
}
return
false
;
return
false
;
}
}
This diff is collapsed.
Click to expand it.
src/util/OptionParser.hxx
View file @
5ab086e3
...
@@ -22,8 +22,6 @@
...
@@ -22,8 +22,6 @@
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include <assert.h>
class
OptionDef
;
class
OptionDef
;
/**
/**
...
@@ -32,8 +30,8 @@ class OptionDef;
...
@@ -32,8 +30,8 @@ class OptionDef;
class
OptionParser
class
OptionParser
{
{
ConstBuffer
<
const
char
*>
args
;
ConstBuffer
<
const
char
*>
args
;
const
char
*
option
=
nullptr
;
const
char
*
option
;
const
char
*
option_raw
=
nullptr
;
const
char
*
option_raw
;
bool
is_long
=
false
;
bool
is_long
=
false
;
const
char
**
const
remaining_head
,
**
remaining_tail
;
const
char
**
const
remaining_head
,
**
remaining_tail
;
...
@@ -42,23 +40,15 @@ public:
...
@@ -42,23 +40,15 @@ public:
/**
/**
* Constructs #OptionParser.
* Constructs #OptionParser.
*/
*/
constexpr
OptionParser
(
int
_argc
,
char
**
_argv
)
noexcept
OptionParser
(
int
_argc
,
char
**
_argv
)
noexcept
:
args
(
_argv
+
1
,
_argc
-
1
),
:
args
(
_argv
+
1
,
_argc
-
1
),
remaining_head
(
const_cast
<
const
char
**>
(
_argv
+
1
)),
remaining_head
(
const_cast
<
const
char
**>
(
_argv
+
1
)),
remaining_tail
(
remaining_head
)
{}
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.
* Gets the last parsed option.
*/
*/
const
char
*
GetOption
()
noexcept
{
const
char
*
GetOption
()
noexcept
{
assert
(
option_raw
!=
nullptr
);
return
option_raw
;
return
option_raw
;
}
}
...
@@ -78,9 +68,11 @@ public:
...
@@ -78,9 +68,11 @@ public:
/**
/**
* Parses current command line entry.
* Parses current command line entry.
* Returns true on success, false otherwise.
* Regardless of result, advances current position to the next
* Regardless of result, advances current position to the next
* command line entry.
* command line entry.
*
* @return true if an option was found, false if there are no
* more options
*/
*/
bool
ParseNext
()
noexcept
;
bool
ParseNext
()
noexcept
;
...
...
This diff is collapsed.
Click to expand it.
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