aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-03-26 12:16:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-03-26 12:16:49 +0200
commit161efedd3ddca75c1cd3ad7f8592653c5070614e (patch)
treee31316ac4f52ed6e217f784bbb1ef2b08ccfc489
parent929918703db8943894a24efbd6fdcb67899f7953 (diff)
Add option file and the build infrastructure
-rw-r--r--build/import/cli/LICENSE21
-rw-r--r--build/import/cli/cli-cxx.make42
-rw-r--r--build/import/cli/configuration-rules.make15
-rwxr-xr-xbuild/import/cli/configure55
-rw-r--r--build/import/cli/stub.make30
-rw-r--r--odb/makefile21
-rw-r--r--odb/options.cli34
-rw-r--r--odb/options.cxx658
-rw-r--r--odb/options.hxx326
-rw-r--r--odb/options.ixx167
10 files changed, 1366 insertions, 3 deletions
diff --git a/build/import/cli/LICENSE b/build/import/cli/LICENSE
new file mode 100644
index 0000000..db16aa3
--- /dev/null
+++ b/build/import/cli/LICENSE
@@ -0,0 +1,21 @@
+Copyright (c) 2009-2010 Code Synthesis Tools CC.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/build/import/cli/cli-cxx.make b/build/import/cli/cli-cxx.make
new file mode 100644
index 0000000..73ec32c
--- /dev/null
+++ b/build/import/cli/cli-cxx.make
@@ -0,0 +1,42 @@
+# file : build/import/cli/cli-cxx.make
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+# Here we are operating in the importing project's space, not in
+# cli's.
+#
+
+# Get the C++ file extensions.
+#
+$(call include,$(bld_root)/cxx/configuration-static.make)
+
+cli_pattern := \
+$(out_base)/%.$(cxx_s_suffix) \
+$(out_base)/%.$(cxx_h_suffix) \
+$(out_base)/%.$(cxx_i_suffix) \
+$(out_base)/%-fwd.$(cxx_h_suffix)
+
+.PRECIOUS: $(cli_pattern)
+
+ifeq ($(out_base),$(src_base))
+
+$(cli_pattern): $(src_base)/%.cli
+ $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<)
+
+else
+
+$(cli_pattern): $(src_base)/%.cli | $$(dir $$@).
+ $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<)
+
+$(cli_pattern): $(out_base)/%.cli | $$(dir $$@).
+ $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<)
+endif
+
+.PHONY: $(out_base)/%.cxx.cli.clean
+
+$(out_base)/%.cxx.cli.clean:
+ $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_s_suffix)))
+ $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_h_suffix)))
+ $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_i_suffix)))
+ $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=-fwd.$(cxx_h_suffix)))
diff --git a/build/import/cli/configuration-rules.make b/build/import/cli/configuration-rules.make
new file mode 100644
index 0000000..aeabd7a
--- /dev/null
+++ b/build/import/cli/configuration-rules.make
@@ -0,0 +1,15 @@
+# file : build/import/cli/configuration-rules.make
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+$(dcf_root)/import/cli/configuration-dynamic.make: | $(dcf_root)/import/cli/.
+ $(call message,,$(scf_root)/import/cli/configure $@)
+
+ifndef %foreign%
+
+disfigure::
+ $(call message,rm $(dcf_root)/import/cli/configuration-dynamic.make,\
+rm -f $(dcf_root)/import/cli/configuration-dynamic.make)
+
+endif
diff --git a/build/import/cli/configure b/build/import/cli/configure
new file mode 100755
index 0000000..23f3080
--- /dev/null
+++ b/build/import/cli/configure
@@ -0,0 +1,55 @@
+#! /usr/bin/env bash
+
+# file : build/import/cli/configure
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+
+# $1 - out file
+#
+# bld_root - build root
+# project_name - project name
+#
+
+source $bld_root/dialog.bash
+
+
+$echo
+$echo "Configuring external dependency on 'CLI' for '$project_name'."
+$echo
+
+$echo
+$echo "Would you like to configure dependency on the installed "
+$echo "version of 'CLI' as opposed to the development build?"
+$echo
+
+installed=`read_y_n y`
+
+path=
+
+if [ "$installed" = "n" ]; then
+
+$echo
+$echo "Please enter the src_root for 'CLI'."
+$echo
+
+src_root=`read_path --directory --exist`
+
+$echo
+$echo "Please enter the out_root for 'CLI'."
+$eche
+
+out_root=`read_path --directory $src_root`
+
+fi
+
+echo cli_installed := $installed >$1
+
+if [ "$installed" = "n" ]; then
+
+echo src_root := $src_root >>$1
+echo scf_root := \$\(src_root\)/build >>$1
+echo out_root := $out_root >>$1
+
+fi
diff --git a/build/import/cli/stub.make b/build/import/cli/stub.make
new file mode 100644
index 0000000..250a5ee
--- /dev/null
+++ b/build/import/cli/stub.make
@@ -0,0 +1,30 @@
+# file : build/import/cli/stub.make
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+$(call include-once,$(scf_root)/import/cli/configuration-rules.make,$(dcf_root))
+
+cli_installed :=
+
+$(call -include,$(dcf_root)/import/cli/configuration-dynamic.make)
+
+ifdef cli_installed
+
+ifeq ($(cli_installed),y)
+
+$(call export,cli: cli,cli-rules: $(scf_root)/import/cli/cli-cxx.make)
+
+else
+
+# Include export stub.
+#
+$(call include,$(scf_root)/export/cli/stub.make)
+
+endif
+
+else
+
+.NOTPARALLEL:
+
+endif
diff --git a/odb/makefile b/odb/makefile
index f1dd9be..7ca87d2 100644
--- a/odb/makefile
+++ b/odb/makefile
@@ -22,14 +22,18 @@ semantics/union.cxx \
semantics/union-template.cxx \
semantics/unit.cxx
-# Driver units
+# Driver units.
#
cxx_dtun := odb.cxx
+# Options file.
+#
+cli_tun := options.cli
+
#
#
-cxx_pobj := $(addprefix $(out_base)/,$(cxx_ptun:.cxx=.o))
-cxx_dobj := $(addprefix $(out_base)/,$(cxx_dtun:.cxx=.o))
+cxx_pobj := $(addprefix $(out_base)/,$(cxx_ptun:.cxx=.o) $(cli_tun:.cli=.o))
+cxx_dobj := $(addprefix $(out_base)/,$(cxx_dtun:.cxx=.o) $(cli_tun:.cli=.o))
cxx_pod := $(cxx_pobj:.o=.o.d)
cxx_dod := $(cxx_dobj:.o=.o.d)
@@ -41,6 +45,10 @@ install := $(out_base)/.install
# Import.
#
$(call import,\
+ $(scf_root)/import/cli/stub.make,\
+ cli: cli,cli-rules: cli_rules)
+
+$(call import,\
$(scf_root)/import/libcutl/stub.make,\
l: cutl.l,cpp-options: cutl.l.cpp-options)
@@ -52,6 +60,12 @@ $(odb_so): $(cxx_pobj) $(cutl.l)
$(cxx_dobj) $(cxx_dod): cpp_options := -I$(src_base)
$(cxx_pobj) $(cxx_dobj) $(cxx_pod) $(cxx_dod): $(cutl.l.cpp-options)
+genf := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) $(cli_tun:.cli=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): cli := $(cli)
+$(gen): cli_options := --generate-file-scanner --guard-prefix ODB
+
$(call include-dep,$(cxx_pod))
$(call include-dep,$(cxx_dod))
@@ -89,6 +103,7 @@ endif
# Rules.
#
$(call include,$(bld_root)/install.make)
+$(call include,$(cli_rules))
$(call include,$(bld_root)/cxx/cxx-d.make)
$(call include,$(bld_root)/cxx/cxx-o.make)
$(call include,$(bld_root)/cxx/o-e.make)
diff --git a/odb/options.cli b/odb/options.cli
new file mode 100644
index 0000000..bda8f1c
--- /dev/null
+++ b/odb/options.cli
@@ -0,0 +1,34 @@
+// file : odb/options.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+include <string>;
+include <vector>;
+
+class options
+{
+ //
+ // Wrapper options. These are not passed to the plugin.
+ //
+
+ bool --help {"Print usage information and exit."};
+ bool --version {"Print version and exit."};
+
+
+ // This is a "fake" option in that it is actually handled by
+ // argv_file_scanner. We have it here to get the documentation.
+ //
+ std::string --options-file
+ {
+ "<file>",
+ "Read additional options from <file> with each option appearing on a
+ separate line optionally followed by space and an option value. Empty
+ lines and lines starting with \cb{#} are ignored. The semantics of
+ providing options in a file is equivalent to providing the same set
+ of options in the same order on the command line at the point where the
+ \cb{--options-file} option is specified except that shell escaping and
+ quoting is not required. Repeat this option to specify more than one
+ options files."
+ };
+};
diff --git a/odb/options.cxx b/odb/options.cxx
new file mode 100644
index 0000000..d0e80b4
--- /dev/null
+++ b/odb/options.cxx
@@ -0,0 +1,658 @@
+// This code was generated by CLI, a command line interface
+// compiler for C++.
+//
+
+#include "options.hxx"
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+#include <ostream>
+#include <sstream>
+#include <cstring>
+#include <fstream>
+
+namespace cli
+{
+ // unknown_option
+ //
+ unknown_option::
+ ~unknown_option () throw ()
+ {
+ }
+
+ void unknown_option::
+ print (std::ostream& os) const
+ {
+ os << "unknown option '" << option () << "'";
+ }
+
+ const char* unknown_option::
+ what () const throw ()
+ {
+ return "unknown option";
+ }
+
+ // unknown_argument
+ //
+ unknown_argument::
+ ~unknown_argument () throw ()
+ {
+ }
+
+ void unknown_argument::
+ print (std::ostream& os) const
+ {
+ os << "unknown argument '" << argument () << "'";
+ }
+
+ const char* unknown_argument::
+ what () const throw ()
+ {
+ return "unknown argument";
+ }
+
+ // missing_value
+ //
+ missing_value::
+ ~missing_value () throw ()
+ {
+ }
+
+ void missing_value::
+ print (std::ostream& os) const
+ {
+ os << "missing value for option '" << option () << "'";
+ }
+
+ const char* missing_value::
+ what () const throw ()
+ {
+ return "missing option value";
+ }
+
+ // invalid_value
+ //
+ invalid_value::
+ ~invalid_value () throw ()
+ {
+ }
+
+ void invalid_value::
+ print (std::ostream& os) const
+ {
+ os << "invalid value '" << value () << "' for option '"
+ << option () << "'";
+ }
+
+ const char* invalid_value::
+ what () const throw ()
+ {
+ return "invalid option value";
+ }
+
+ // eos_reached
+ //
+ void eos_reached::
+ print (std::ostream& os) const
+ {
+ os << what ();
+ }
+
+ const char* eos_reached::
+ what () const throw ()
+ {
+ return "end of argument stream reached";
+ }
+
+ // file_io_failure
+ //
+ file_io_failure::
+ ~file_io_failure () throw ()
+ {
+ }
+
+ void file_io_failure::
+ print (std::ostream& os) const
+ {
+ os << "unable to open file '" << file () << "' or read failure";
+ }
+
+ const char* file_io_failure::
+ what () const throw ()
+ {
+ return "unable to open file or read failure";
+ }
+
+ // scanner
+ //
+ scanner::
+ ~scanner ()
+ {
+ }
+
+ // argv_scanner
+ //
+ bool argv_scanner::
+ more ()
+ {
+ return i_ < argc_;
+ }
+
+ const char* argv_scanner::
+ peek ()
+ {
+ if (i_ < argc_)
+ return argv_[i_];
+ else
+ throw eos_reached ();
+ }
+
+ const char* argv_scanner::
+ next ()
+ {
+ if (i_ < argc_)
+ {
+ const char* r (argv_[i_]);
+
+ if (erase_)
+ {
+ for (int i (i_ + 1); i < argc_; ++i)
+ argv_[i - 1] = argv_[i];
+
+ --argc_;
+ argv_[argc_] = 0;
+ }
+ else
+ ++i_;
+
+ return r;
+ }
+ else
+ throw eos_reached ();
+ }
+
+ void argv_scanner::
+ skip ()
+ {
+ if (i_ < argc_)
+ ++i_;
+ else
+ throw eos_reached ();
+ }
+
+ // argv_file_scanner
+ //
+ bool argv_file_scanner::
+ more ()
+ {
+ if (!args_.empty ())
+ return true;
+
+ while (base::more ())
+ {
+ // See if the next argument is the file option.
+ //
+ const char* a (base::peek ());
+
+ if (!skip_ && a == option_)
+ {
+ base::next ();
+
+ if (!base::more ())
+ throw missing_value (option_);
+
+ load (base::next ());
+
+ if (!args_.empty ())
+ return true;
+ }
+ else
+ {
+ if (!skip_)
+ skip_ = (std::strcmp (a, "--") == 0);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ const char* argv_file_scanner::
+ peek ()
+ {
+ if (!more ())
+ throw eos_reached ();
+
+ return args_.empty () ? base::peek () : args_.front ().c_str ();
+ }
+
+ const char* argv_file_scanner::
+ next ()
+ {
+ if (!more ())
+ throw eos_reached ();
+
+ if (args_.empty ())
+ return base::next ();
+ else
+ {
+ hold_.swap (args_.front ());
+ args_.pop_front ();
+ return hold_.c_str ();
+ }
+ }
+
+ void argv_file_scanner::
+ skip ()
+ {
+ if (!more ())
+ throw eos_reached ();
+
+ if (args_.empty ())
+ return base::skip ();
+ else
+ args_.pop_front ();
+ }
+
+ void argv_file_scanner::
+ load (const char* file)
+ {
+ using namespace std;
+
+ ifstream is (file);
+
+ if (!is.is_open ())
+ throw file_io_failure (file);
+
+ while (!is.eof ())
+ {
+ string line;
+ getline (is, line);
+
+ if (is.fail () && !is.eof ())
+ throw file_io_failure (file);
+
+ string::size_type n (line.size ());
+
+ // Trim the line from leading and trailing whitespaces.
+ //
+ if (n != 0)
+ {
+ const char* f (line.c_str ());
+ const char* l (f + n);
+
+ const char* of (f);
+ while (f < l && (*f == ' ' || *f == '\t' || *f == '\r'))
+ ++f;
+
+ --l;
+
+ const char* ol (l);
+ while (l > f && (*l == ' ' || *l == '\t' || *l == '\r'))
+ --l;
+
+ if (f != of || l != ol)
+ line = f <= l ? string (f, l - f + 1) : string ();
+ }
+
+ // Ignore empty lines, those that start with #.
+ //
+ if (line.empty () || line[0] == '#')
+ continue;
+
+ string::size_type p (line.find (' '));
+
+ if (p == string::npos)
+ {
+ if (!skip_)
+ skip_ = (line == "--");
+
+ args_.push_back (line);
+ }
+ else
+ {
+ string s1 (line, 0, p);
+
+ // Skip leading whitespaces in the argument.
+ //
+ n = line.size ();
+ for (++p; p < n; ++p)
+ {
+ char c (line[p]);
+
+ if (c != ' ' && c != '\t' && c != '\r')
+ break;
+ }
+
+ string s2 (line, p);
+
+ if (!skip_ && s1 == option_)
+ load (s2.c_str ());
+ else
+ {
+ args_.push_back (s1);
+ args_.push_back (s2);
+ }
+ }
+ }
+ }
+
+ template <typename X>
+ struct parser
+ {
+ static void
+ parse (X& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ const char* v (s.next ());
+ std::istringstream is (v);
+ if (!(is >> x && is.eof ()))
+ throw invalid_value (o, v);
+ }
+ else
+ throw missing_value (o);
+ }
+ };
+
+ template <>
+ struct parser<bool>
+ {
+ static void
+ parse (bool& x, scanner& s)
+ {
+ s.next ();
+ x = true;
+ }
+ };
+
+ template <>
+ struct parser<std::string>
+ {
+ static void
+ parse (std::string& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (s.more ())
+ x = s.next ();
+ else
+ throw missing_value (o);
+ }
+ };
+
+ template <typename X>
+ struct parser<std::vector<X> >
+ {
+ static void
+ parse (std::vector<X>& c, scanner& s)
+ {
+ X x;
+ parser<X>::parse (x, s);
+ c.push_back (x);
+ }
+ };
+
+ template <typename X>
+ struct parser<std::set<X> >
+ {
+ static void
+ parse (std::set<X>& c, scanner& s)
+ {
+ X x;
+ parser<X>::parse (x, s);
+ c.insert (x);
+ }
+ };
+
+ template <typename K, typename V>
+ struct parser<std::map<K, V> >
+ {
+ static void
+ parse (std::map<K, V>& m, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ std::string ov (s.next ());
+ std::string::size_type p = ov.find ('=');
+
+ if (p == std::string::npos)
+ {
+ K k = K ();
+
+ if (!ov.empty ())
+ {
+ std::istringstream ks (ov);
+
+ if (!(ks >> k && ks.eof ()))
+ throw invalid_value (o, ov);
+ }
+
+ m[k] = V ();
+ }
+ else
+ {
+ K k = K ();
+ V v = V ();
+ std::string kstr (ov, 0, p);
+ std::string vstr (ov, p + 1);
+
+ if (!kstr.empty ())
+ {
+ std::istringstream ks (kstr);
+
+ if (!(ks >> k && ks.eof ()))
+ throw invalid_value (o, ov);
+ }
+
+ if (!vstr.empty ())
+ {
+ std::istringstream vs (vstr);
+
+ if (!(vs >> v && vs.eof ()))
+ throw invalid_value (o, ov);
+ }
+
+ m[k] = v;
+ }
+ }
+ else
+ throw missing_value (o);
+ }
+ };
+
+ template <typename X, typename T, T X::*P>
+ void
+ thunk (X& x, scanner& s)
+ {
+ parser<T>::parse (x.*P, s);
+ }
+}
+
+#include <map>
+#include <cstring>
+
+// options
+//
+
+options::
+options (int& argc,
+ char** argv,
+ bool erase,
+ ::cli::unknown_mode opt,
+ ::cli::unknown_mode arg)
+: help_ (),
+ version_ (),
+ options_file_ ()
+{
+ ::cli::argv_scanner s (argc, argv, erase);
+ _parse (s, opt, arg);
+}
+
+options::
+options (int start,
+ int& argc,
+ char** argv,
+ bool erase,
+ ::cli::unknown_mode opt,
+ ::cli::unknown_mode arg)
+: help_ (),
+ version_ (),
+ options_file_ ()
+{
+ ::cli::argv_scanner s (start, argc, argv, erase);
+ _parse (s, opt, arg);
+}
+
+options::
+options (int& argc,
+ char** argv,
+ int& end,
+ bool erase,
+ ::cli::unknown_mode opt,
+ ::cli::unknown_mode arg)
+: help_ (),
+ version_ (),
+ options_file_ ()
+{
+ ::cli::argv_scanner s (argc, argv, erase);
+ _parse (s, opt, arg);
+ end = s.end ();
+}
+
+options::
+options (int start,
+ int& argc,
+ char** argv,
+ int& end,
+ bool erase,
+ ::cli::unknown_mode opt,
+ ::cli::unknown_mode arg)
+: help_ (),
+ version_ (),
+ options_file_ ()
+{
+ ::cli::argv_scanner s (start, argc, argv, erase);
+ _parse (s, opt, arg);
+ end = s.end ();
+}
+
+options::
+options (::cli::scanner& s,
+ ::cli::unknown_mode opt,
+ ::cli::unknown_mode arg)
+: help_ (),
+ version_ (),
+ options_file_ ()
+{
+ _parse (s, opt, arg);
+}
+
+void options::
+print_usage (::std::ostream& os)
+{
+ os << "--help Print usage information and exit." << ::std::endl;
+
+ os << "--version Print version and exit." << ::std::endl;
+
+ os << "--options-file <file> Read additional options from <file> with each option" << ::std::endl
+ << " appearing on a separate line optionally followed by space" << ::std::endl
+ << " and an option value." << ::std::endl;
+}
+
+typedef
+std::map<std::string, void (*) (options&, ::cli::scanner&)>
+_cli_options_map;
+
+static _cli_options_map _cli_options_map_;
+
+struct _cli_options_map_init
+{
+ _cli_options_map_init ()
+ {
+ _cli_options_map_["--help"] =
+ &::cli::thunk< options, bool, &options::help_ >;
+ _cli_options_map_["--version"] =
+ &::cli::thunk< options, bool, &options::version_ >;
+ _cli_options_map_["--options-file"] =
+ &::cli::thunk< options, std::string, &options::options_file_ >;
+ }
+} _cli_options_map_init_;
+
+void options::
+_parse (::cli::scanner& s,
+ ::cli::unknown_mode opt_mode,
+ ::cli::unknown_mode arg_mode)
+{
+ bool opt = true;
+
+ while (s.more ())
+ {
+ const char* o = s.peek ();
+
+ if (std::strcmp (o, "--") == 0)
+ {
+ s.skip ();
+ opt = false;
+ continue;
+ }
+
+ _cli_options_map::const_iterator i (
+ opt ? _cli_options_map_.find (o) : _cli_options_map_.end ());
+
+ if (i != _cli_options_map_.end ())
+ {
+ (*(i->second)) (*this, s);
+ }
+ else if (opt && std::strncmp (o, "-", 1) == 0 && o[1] != '\0')
+ {
+ switch (opt_mode)
+ {
+ case ::cli::unknown_mode::skip:
+ {
+ s.skip ();
+ continue;
+ }
+ case ::cli::unknown_mode::stop:
+ {
+ break;
+ }
+ case ::cli::unknown_mode::fail:
+ {
+ throw ::cli::unknown_option (o);
+ }
+ }
+
+ break;
+ }
+ else
+ {
+ switch (arg_mode)
+ {
+ case ::cli::unknown_mode::skip:
+ {
+ s.skip ();
+ continue;
+ }
+ case ::cli::unknown_mode::stop:
+ {
+ break;
+ }
+ case ::cli::unknown_mode::fail:
+ {
+ throw ::cli::unknown_argument (o);
+ }
+ }
+
+ break;
+ }
+ }
+}
+
diff --git a/odb/options.hxx b/odb/options.hxx
new file mode 100644
index 0000000..9074410
--- /dev/null
+++ b/odb/options.hxx
@@ -0,0 +1,326 @@
+// This code was generated by CLI, a command line interface
+// compiler for C++.
+//
+
+#ifndef ODB_OPTIONS_HXX
+#define ODB_OPTIONS_HXX
+
+#include <deque>
+#include <iosfwd>
+#include <string>
+#include <exception>
+
+namespace cli
+{
+ class unknown_mode
+ {
+ public:
+ enum value
+ {
+ skip,
+ stop,
+ fail
+ };
+
+ unknown_mode (value v);
+
+ operator value () const
+ {
+ return v_;
+ }
+
+ private:
+ value v_;
+ };
+
+ // Exceptions.
+ //
+
+ class exception: public std::exception
+ {
+ public:
+ virtual void
+ print (std::ostream&) const = 0;
+ };
+
+ std::ostream&
+ operator<< (std::ostream&, const exception&);
+
+ class unknown_option: public exception
+ {
+ public:
+ virtual
+ ~unknown_option () throw ();
+
+ unknown_option (const std::string& option);
+
+ const std::string&
+ option () const;
+
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ what () const throw ();
+
+ private:
+ std::string option_;
+ };
+
+ class unknown_argument: public exception
+ {
+ public:
+ virtual
+ ~unknown_argument () throw ();
+
+ unknown_argument (const std::string& argument);
+
+ const std::string&
+ argument () const;
+
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ what () const throw ();
+
+ private:
+ std::string argument_;
+ };
+
+ class missing_value: public exception
+ {
+ public:
+ virtual
+ ~missing_value () throw ();
+
+ missing_value (const std::string& option);
+
+ const std::string&
+ option () const;
+
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ what () const throw ();
+
+ private:
+ std::string option_;
+ };
+
+ class invalid_value: public exception
+ {
+ public:
+ virtual
+ ~invalid_value () throw ();
+
+ invalid_value (const std::string& option,
+ const std::string& value);
+
+ const std::string&
+ option () const;
+
+ const std::string&
+ value () const;
+
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ what () const throw ();
+
+ private:
+ std::string option_;
+ std::string value_;
+ };
+
+ class eos_reached: public exception
+ {
+ public:
+ virtual void
+ print (std::ostream&) const;
+
+ virtual const char*
+ 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:
+ virtual
+ ~scanner ();
+
+ virtual bool
+ more () = 0;
+
+ virtual const char*
+ peek () = 0;
+
+ virtual const char*
+ next () = 0;
+
+ virtual void
+ skip () = 0;
+ };
+
+ class argv_scanner: public scanner
+ {
+ public:
+ argv_scanner (int& argc, char** argv, bool erase = false);
+ argv_scanner (int start, int& argc, char** argv, bool erase = false);
+
+ int
+ end () const;
+
+ virtual bool
+ more ();
+
+ virtual const char*
+ peek ();
+
+ virtual const char*
+ next ();
+
+ virtual void
+ skip ();
+
+ private:
+ int i_;
+ int& argc_;
+ 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<std::string> args_;
+ bool skip_;
+ };
+}
+
+#include <string>
+
+#include <vector>
+
+class options
+{
+ public:
+
+ options (int& argc,
+ char** argv,
+ bool erase = false,
+ ::cli::unknown_mode option = ::cli::unknown_mode::fail,
+ ::cli::unknown_mode argument = ::cli::unknown_mode::stop);
+
+ options (int start,
+ int& argc,
+ char** argv,
+ bool erase = false,
+ ::cli::unknown_mode option = ::cli::unknown_mode::fail,
+ ::cli::unknown_mode argument = ::cli::unknown_mode::stop);
+
+ options (int& argc,
+ char** argv,
+ int& end,
+ bool erase = false,
+ ::cli::unknown_mode option = ::cli::unknown_mode::fail,
+ ::cli::unknown_mode argument = ::cli::unknown_mode::stop);
+
+ options (int start,
+ int& argc,
+ char** argv,
+ int& end,
+ bool erase = false,
+ ::cli::unknown_mode option = ::cli::unknown_mode::fail,
+ ::cli::unknown_mode argument = ::cli::unknown_mode::stop);
+
+ options (::cli::scanner&,
+ ::cli::unknown_mode option = ::cli::unknown_mode::fail,
+ ::cli::unknown_mode argument = ::cli::unknown_mode::stop);
+
+ // Option accessors.
+ //
+
+ const bool&
+ help () const;
+
+ const bool&
+ version () const;
+
+ const std::string&
+ options_file () const;
+
+ // Print usage information.
+ //
+ static void
+ print_usage (::std::ostream&);
+
+ private:
+ void
+ _parse (::cli::scanner&,
+ ::cli::unknown_mode option,
+ ::cli::unknown_mode argument);
+
+ public:
+ bool help_;
+ bool version_;
+ std::string options_file_;
+};
+
+#include "options.ixx"
+
+#endif // ODB_OPTIONS_HXX
diff --git a/odb/options.ixx b/odb/options.ixx
new file mode 100644
index 0000000..2d06e58
--- /dev/null
+++ b/odb/options.ixx
@@ -0,0 +1,167 @@
+// This code was generated by CLI, a command line interface
+// compiler for C++.
+//
+
+namespace cli
+{
+ // unknown_mode
+ //
+ inline unknown_mode::
+ unknown_mode (value v)
+ : v_ (v)
+ {
+ }
+
+ // exception
+ //
+ inline std::ostream&
+ operator<< (std::ostream& os, const exception& e)
+ {
+ e.print (os);
+ return os;
+ }
+
+ // unknown_option
+ //
+ inline unknown_option::
+ unknown_option (const std::string& option)
+ : option_ (option)
+ {
+ }
+
+ inline const std::string& unknown_option::
+ option () const
+ {
+ return option_;
+ }
+
+ // unknown_argument
+ //
+ inline unknown_argument::
+ unknown_argument (const std::string& argument)
+ : argument_ (argument)
+ {
+ }
+
+ inline const std::string& unknown_argument::
+ argument () const
+ {
+ return argument_;
+ }
+
+ // missing_value
+ //
+ inline missing_value::
+ missing_value (const std::string& option)
+ : option_ (option)
+ {
+ }
+
+ inline const std::string& missing_value::
+ option () const
+ {
+ return option_;
+ }
+
+ // invalid_value
+ //
+ inline invalid_value::
+ invalid_value (const std::string& option,
+ const std::string& value)
+ : option_ (option), value_ (value)
+ {
+ }
+
+ inline const std::string& invalid_value::
+ option () const
+ {
+ return option_;
+ }
+
+ inline const std::string& invalid_value::
+ value () const
+ {
+ return value_;
+ }
+
+ // file_io_failure
+ //
+ inline file_io_failure::
+ file_io_failure (const std::string& file)
+ : file_ (file)
+ {
+ }
+
+ inline const std::string& file_io_failure::
+ file () const
+ {
+ return file_;
+ }
+
+ // argv_scanner
+ //
+ inline argv_scanner::
+ argv_scanner (int& argc, char** argv, bool erase)
+ : i_ (1), argc_ (argc), argv_ (argv), erase_ (erase)
+ {
+ }
+
+ inline argv_scanner::
+ argv_scanner (int start, int& argc, char** argv, bool erase)
+ : i_ (start), argc_ (argc), argv_ (argv), erase_ (erase)
+ {
+ }
+
+ inline int argv_scanner::
+ end () const
+ {
+ return i_;
+ }
+
+ // argv_file_scanner
+ //
+ inline argv_file_scanner::
+ argv_file_scanner (int& argc,
+ char** argv,
+ const std::string& option,
+ bool erase)
+ : argv_scanner (argc, argv, erase),
+ option_ (option),
+ skip_ (false)
+ {
+ }
+
+ inline argv_file_scanner::
+ argv_file_scanner (int start,
+ int& argc,
+ char** argv,
+ const std::string& option,
+ bool erase)
+ : argv_scanner (start, argc, argv, erase),
+ option_ (option),
+ skip_ (false)
+ {
+ }
+}
+
+// options
+//
+
+inline const bool& options::
+help () const
+{
+ return this->help_;
+}
+
+inline const bool& options::
+version () const
+{
+ return this->version_;
+}
+
+inline const std::string& options::
+options_file () const
+{
+ return this->options_file_;
+}
+