cmdline: parse parameters in GNU mode

This change sets the option parser to GNU mode, that is, allows
further option parameters after non-option parameters, e.g.:

dump-trace foo.tc -s

instead of

dump-trace -s foo.tc

As Fail* currently works on GNU platforms only, this behavior is the
one presumably expected from users.

Change-Id: I9c55eaf4560cde81ebd0b94214201c8ad02c2b74
This commit is contained in:
Horst Schirmeier
2014-09-23 11:11:38 +02:00
parent 020af0ef6f
commit 3fd94abcd3
2 changed files with 11 additions and 6 deletions

View File

@ -43,8 +43,13 @@ bool CommandLine::parse() {
option::Descriptor desc = {0, 0, 0, 0, 0, 0};
this->options.push_back(desc);
// Generate the options stats
option::Stats stats(this->options.data(), argv.size(), argv.data());
// Copy argv to preserve original argument order
// (for proper re-parsing after adding more options)
argv_reordered = argv;
// Generate the options stats (GNU mode)
option::Stats stats(true, this->options.data(),
argv_reordered.size(), argv_reordered.data());
if (parsed_options)
delete[] parsed_options;
@ -56,9 +61,9 @@ bool CommandLine::parse() {
parsed_options = new option::Option[stats.options_max];
parsed_buffer = new option::Option[stats.buffer_max];
m_parser = new option::Parser(this->options.data(), argv.size(), argv.data(),
parsed_options, parsed_buffer);
m_parser = new option::Parser(true, this->options.data(),
argv_reordered.size(), argv_reordered.data(),
parsed_options, parsed_buffer);
// Pop the terminating entry
this->options.pop_back();

View File

@ -30,7 +30,7 @@ public:
private:
static CommandLine m_instance;
std::vector<const char *> argv;
std::vector<const char *> argv, argv_reordered;
std::vector<option::Descriptor> options;
option::Option *parsed_options, *parsed_buffer;
option::Parser *m_parser;