From f8edfd22cb45b554a573d2722900196758e9e958 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Dec 2009 09:47:29 +0200 Subject: Scanner-based parsing with support for element erasing Also implement argv_file_scanner which provides support for reading command line arguments from the argv array as well as files specified with command line options. New examples: file. New tests: ctor, erase, file. --- cli/runtime-inline.cxx | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) (limited to 'cli/runtime-inline.cxx') diff --git a/cli/runtime-inline.cxx b/cli/runtime-inline.cxx index d4ce3ec..c99739c 100644 --- a/cli/runtime-inline.cxx +++ b/cli/runtime-inline.cxx @@ -103,18 +103,36 @@ generate_runtime_inline (context& ctx) << "return value_;" << "}"; + if (ctx.options.generate_file_scanner ()) + { + os << "// file_io_failure" << endl + << "//" << endl + + << inl << "file_io_failure::" << endl + << "file_io_failure (const std::string& file)" << endl + << ": file_ (file)" + << "{" + << "}" + + << inl << "const std::string& file_io_failure::" << endl + << "file () const" + << "{" + << "return file_;" + << "}"; + } + os << "// argv_scanner" << endl << "//" << endl; os << inl << "argv_scanner::" << endl - << "argv_scanner (int argc, char** argv)" << endl - << ": i_ (1), argc_ (argc), argv_ (argv)" + << "argv_scanner (int& argc, char** argv, bool erase)" << endl + << ": i_ (1), argc_ (argc), argv_ (argv), erase_ (erase)" << "{" << "}"; os << inl << "argv_scanner::" << endl - << "argv_scanner (int start, int argc, char** argv)" << endl - << ": i_ (start), argc_ (argc), argv_ (argv)" + << "argv_scanner (int start, int& argc, char** argv, bool erase)" << endl + << ": i_ (start), argc_ (argc), argv_ (argv), erase_ (erase)" << "{" << "}"; @@ -124,5 +142,42 @@ generate_runtime_inline (context& ctx) << "return i_;" << "}"; + // argv_file_scanner + // + if (ctx.options.generate_file_scanner ()) + { + bool sep (!ctx.opt_sep.empty ()); + + os << "// argv_file_scanner" << endl + << "//" << endl; + + os << inl << "argv_file_scanner::" << endl + << "argv_file_scanner (int& argc," << endl + << "char** argv," << endl + << "const std::string& option," << endl + << "bool erase)" << endl + << ": argv_scanner (argc, argv, erase)," << endl + << " option_ (option)"; + if (sep) + os << "," << endl + << " skip_ (false)"; + os << "{" + << "}"; + + os << inl << "argv_file_scanner::" << endl + << "argv_file_scanner (int start," << endl + << "int& argc," << endl + << "char** argv," << endl + << "const std::string& option," << endl + << "bool erase)" << endl + << ": argv_scanner (start, argc, argv, erase)," << endl + << " option_ (option)"; + if (sep) + os << "," << endl + << " skip_ (false)"; + os << "{" + << "}"; + } + os << "}"; // namespace cli } -- cgit v1.1