From 3fd94abcd3d3aef1455841cbfe4cb5506f26a6a7 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Tue, 23 Sep 2014 11:11:38 +0200 Subject: [PATCH] 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 --- src/core/util/CommandLine.cc | 15 ++++++++++----- src/core/util/CommandLine.hpp | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/util/CommandLine.cc b/src/core/util/CommandLine.cc index 33f6c333..6116beb0 100644 --- a/src/core/util/CommandLine.cc +++ b/src/core/util/CommandLine.cc @@ -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(); diff --git a/src/core/util/CommandLine.hpp b/src/core/util/CommandLine.hpp index 21dfd2a3..a89ad9c8 100644 --- a/src/core/util/CommandLine.hpp +++ b/src/core/util/CommandLine.hpp @@ -30,7 +30,7 @@ public: private: static CommandLine m_instance; - std::vector argv; + std::vector argv, argv_reordered; std::vector options; option::Option *parsed_options, *parsed_buffer; option::Parser *m_parser;