From 59e7ca8e3c83b7fee8282c043107acf4d7c3bab1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 31 Mar 2020 12:40:54 +0200 Subject: Regenerate options parsing code --- odb/options.cxx | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'odb/options.cxx') diff --git a/odb/options.cxx b/odb/options.cxx index 829a96a..fedf8c5 100644 --- a/odb/options.cxx +++ b/odb/options.cxx @@ -215,6 +215,7 @@ namespace cli // argv_file_scanner // int argv_file_scanner::zero_argc_ = 0; + std::string argv_file_scanner::empty_string_; bool argv_file_scanner:: more () @@ -288,7 +289,25 @@ namespace cli if (!more ()) throw eos_reached (); - return args_.empty () ? base::peek () : args_.front ().c_str (); + return args_.empty () ? base::peek () : args_.front ().value.c_str (); + } + + const std::string& argv_file_scanner:: + peek_file () + { + if (!more ()) + throw eos_reached (); + + return args_.empty () ? empty_string_ : *args_.front ().file; + } + + std::size_t argv_file_scanner:: + peek_line () + { + if (!more ()) + throw eos_reached (); + + return args_.empty () ? 0 : args_.front ().line; } const char* argv_file_scanner:: @@ -301,7 +320,7 @@ namespace cli return base::next (); else { - hold_[i_ == 0 ? ++i_ : --i_].swap (args_.front ()); + hold_[i_ == 0 ? ++i_ : --i_].swap (args_.front ().value); args_.pop_front (); return hold_[i_].c_str (); } @@ -339,7 +358,12 @@ namespace cli if (!is.is_open ()) throw file_io_failure (file); - while (!is.eof ()) + files_.push_back (file); + + arg a; + a.file = &*files_.rbegin (); + + for (a.line = 1; !is.eof (); ++a.line) { string line; getline (is, line); @@ -446,10 +470,12 @@ namespace cli continue; } - args_.push_back (s1); + a.value = s1; + args_.push_back (a); } - args_.push_back (s2); + a.value = s2; + args_.push_back (a); } } -- cgit v1.1