From 74dfffa9df361e35a5910f1cf5b1734571bbef91 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Dec 2009 10:50:23 +0200 Subject: Allows additional options to be provided in files (--options-file) Implemented using the new argv_file_scanner scanner implementation. --- cli/options.hxx | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'cli/options.hxx') diff --git a/cli/options.hxx b/cli/options.hxx index 54143b9..1c7456c 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -5,6 +5,7 @@ #ifndef CLI_OPTIONS_HXX #define CLI_OPTIONS_HXX +#include #include #include #include @@ -144,6 +145,27 @@ namespace cli what () const throw (); }; + class file_io_failure: public exception + { + public: + virtual + ~file_io_failure () throw (); + + file_io_failure (const std::string& file); + + const std::string& + file () const; + + virtual void + print (std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string file_; + }; + class scanner { public: @@ -190,6 +212,44 @@ namespace cli char** argv_; bool erase_; }; + + class argv_file_scanner: public argv_scanner + { + public: + argv_file_scanner (int& argc, + char** argv, + const std::string& file_option, + bool erase = false); + + argv_file_scanner (int start, + int& argc, + char** argv, + const std::string& file_option, + bool erase = false); + + virtual bool + more (); + + virtual const char* + peek (); + + virtual const char* + next (); + + virtual void + skip (); + + private: + void + load (const char* file); + + typedef argv_scanner base; + + const std::string option_; + std::string hold_; + std::deque args_; + bool skip_; + }; } #include @@ -326,6 +386,9 @@ class options const std::map& reserved_name () const; + const std::string& + options_file () const; + // Print usage information. // static void @@ -367,6 +430,7 @@ class options std::string include_prefix_; std::string guard_prefix_; std::map reserved_name_; + std::string options_file_; }; #include "options.ixx" -- cgit v1.1