From 2a758e9286d05a90edf71791bff493829085b098 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 7 May 2010 11:06:00 +0200 Subject: Handle --version and --help Also add the --proprietary license option. --- odb/odb.cxx | 78 ++++++++++++++++++++++++++++++++++++++++++--------------- odb/options.cli | 8 +++++- odb/options.cxx | 36 ++++++++++++++++---------- odb/options.hxx | 8 ++++-- odb/options.ixx | 10 ++++++-- 5 files changed, 102 insertions(+), 38 deletions(-) diff --git a/odb/odb.cxx b/odb/odb.cxx index 0c5322f..8e864c7 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -28,6 +28,8 @@ main (int argc, char* argv[]) { typedef vector strings; + ostream& e (cerr); + // Find the plugin. It should be in the same directory as the // driver. // @@ -35,9 +37,9 @@ main (int argc, char* argv[]) if (plugin.empty ()) { - cerr << argv[0] << ": error: unable to locate ODB GCC plugin" << endl; - cerr << argv[0] << ": info: make sure '" << argv[0] << ".so' is in " - << "the same directory as '" << argv[0] << "'" << endl; + e << argv[0] << ": error: unable to locate ODB GCC plugin" << endl; + e << argv[0] << ": info: make sure '" << argv[0] << ".so' is in " + << "the same directory as '" << argv[0] << "'" << endl; return 1; } @@ -77,8 +79,7 @@ main (int argc, char* argv[]) { if (++i == argc || argv[i][0] == '\0') { - cerr << argv[0] << ": error: expected argument for the -x option" - << endl; + e << argv[0] << ": error: expected argument for the -x option" << endl; return 1; } @@ -104,8 +105,8 @@ main (int argc, char* argv[]) { if (++i == argc || argv[i][0] == '\0') { - cerr << argv[0] << ": error: expected argument for the -I option" - << endl; + e << argv[0] << ": error: expected argument for the -I option" + << endl; return 1; } @@ -122,8 +123,8 @@ main (int argc, char* argv[]) { if (++i == argc || argv[i][0] == '\0') { - cerr << argv[0] << ": error: expected argument for the -D option" - << endl; + e << argv[0] << ": error: expected argument for the -D option" + << endl; return 1; } @@ -140,8 +141,8 @@ main (int argc, char* argv[]) { if (++i == argc || argv[i][0] == '\0') { - cerr << argv[0] << ": error: expected argument for the -U option" - << endl; + e << argv[0] << ": error: expected argument for the -U option" + << endl; return 1; } @@ -163,8 +164,8 @@ main (int argc, char* argv[]) vector av; av.push_back (argv[0]); - for (strings::iterator i (plugin_args.begin ()), e (plugin_args.end ()); - i != e; ++i) + for (strings::iterator i (plugin_args.begin ()), end (plugin_args.end ()); + i != end; ++i) { av.push_back (const_cast (i->c_str ())); } @@ -173,11 +174,48 @@ main (int argc, char* argv[]) cli::argv_file_scanner scan (ac, &av[0], "--options-file"); options ops (scan); + + // Handle --version. + // + if (ops.version ()) + { + e << "CodeSynthesis ODB object persistence compiler for C++ " << + ODB_COMPILER_VERSION_STR << endl + << "Copyright (C) 2009-2010 Code Synthesis Tools CC" << endl; + + if (ops.proprietary_license ()) + { + e << "The compiler was invoked in the Proprietary License mode. You " + << "should have\nreceived a proprietary license from Code Synthesis " + << "Tools CC that entitles\nyou to use it in this mode." << endl; + } + else + { + e << "This is free software; see the source for copying conditions. " + << "There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS " + << "FOR A PARTICULAR PURPOSE." << endl; + } + + return 0; + } + + // Handle --help. + // + if (ops.help ()) + { + e << "Usage: " << argv[0] << " [options] file [file ...]" + << endl + << "Options:" << endl; + + options::print_usage (e); + return 0; + } + size_t end (scan.end () - 1); // We have one less in plugin_args. if (end == plugin_args.size ()) { - cerr << argv[0] << ": error: input file expected" << endl; + e << argv[0] << ": error: input file expected" << endl; return 1; } @@ -230,7 +268,7 @@ main (int argc, char* argv[]) } catch (cli::exception const& ex) { - cerr << ex << endl; + e << ex << endl; return 1; } @@ -238,23 +276,23 @@ main (int argc, char* argv[]) // vector exec_args; - for (strings::const_iterator i (args.begin ()), e (args.end ()); - i != e; ++i) + for (strings::const_iterator i (args.begin ()), end (args.end ()); + i != end; ++i) { exec_args.push_back (i->c_str ()); if (v) - cerr << *i << ' '; + e << *i << ' '; } if (v) - cerr << endl; + e << endl; exec_args.push_back (0); if (execvp (exec_args[0], const_cast (&exec_args[0])) < 0) { - cerr << exec_args[0] << ": error: " << strerror (errno) << endl; + e << exec_args[0] << ": error: " << strerror (errno) << endl; return 1; } } diff --git a/odb/options.cli b/odb/options.cli index 19c3b4c..0418eb5 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -64,7 +64,11 @@ class options "Add to the generated \cb{#include} directive paths." }; - bool --trace {"Trace the compilation process."}; + bool --proprietary-license + { + "Indicate that the generated code is licensed under a proprietary + license instead of the GPL." + }; // This is a "fake" option in that it is actually handled by // argv_file_scanner. We have it here to get the documentation. @@ -81,4 +85,6 @@ class options quoting is not required. Repeat this option to specify more than one options files." }; + + bool --trace {"Trace the compilation process."}; }; diff --git a/odb/options.cxx b/odb/options.cxx index 5e72ff4..295d22c 100644 --- a/odb/options.cxx +++ b/odb/options.cxx @@ -497,8 +497,9 @@ options (int& argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - trace_ (), - options_file_ () + proprietary_license_ (), + options_file_ (), + trace_ () { ::cli::argv_scanner s (argc, argv, erase); _parse (s, opt, arg); @@ -520,8 +521,9 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - trace_ (), - options_file_ () + proprietary_license_ (), + options_file_ (), + trace_ () { ::cli::argv_scanner s (start, argc, argv, erase); _parse (s, opt, arg); @@ -543,8 +545,9 @@ options (int& argc, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - trace_ (), - options_file_ () + proprietary_license_ (), + options_file_ (), + trace_ () { ::cli::argv_scanner s (argc, argv, erase); _parse (s, opt, arg); @@ -568,8 +571,9 @@ options (int start, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - trace_ (), - options_file_ () + proprietary_license_ (), + options_file_ (), + trace_ () { ::cli::argv_scanner s (start, argc, argv, erase); _parse (s, opt, arg); @@ -589,8 +593,9 @@ options (::cli::scanner& s, cxx_suffix_ (".cxx"), include_with_brackets_ (), include_prefix_ (), - trace_ (), - options_file_ () + proprietary_license_ (), + options_file_ (), + trace_ () { _parse (s, opt, arg); } @@ -623,11 +628,14 @@ print_usage (::std::ostream& os) os << "--include-prefix Add to the generated '#include' directive" << ::std::endl << " paths." << ::std::endl; - os << "--trace Trace the compilation process." << ::std::endl; + os << "--proprietary-license Indicate that the generated code is licensed under a" << ::std::endl + << " proprietary license instead of the GPL." << ::std::endl; os << "--options-file Read additional options from with each option" << ::std::endl << " appearing on a separate line optionally followed by" << ::std::endl << " space and an option value." << ::std::endl; + + os << "--trace Trace the compilation process." << ::std::endl; } typedef @@ -660,10 +668,12 @@ struct _cli_options_map_init &::cli::thunk< options, bool, &options::include_with_brackets_ >; _cli_options_map_["--include-prefix"] = &::cli::thunk< options, std::string, &options::include_prefix_ >; - _cli_options_map_["--trace"] = - &::cli::thunk< options, bool, &options::trace_ >; + _cli_options_map_["--proprietary-license"] = + &::cli::thunk< options, bool, &options::proprietary_license_ >; _cli_options_map_["--options-file"] = &::cli::thunk< options, std::string, &options::options_file_ >; + _cli_options_map_["--trace"] = + &::cli::thunk< options, bool, &options::trace_ >; } } _cli_options_map_init_; diff --git a/odb/options.hxx b/odb/options.hxx index 92fc595..cbd112e 100644 --- a/odb/options.hxx +++ b/odb/options.hxx @@ -323,11 +323,14 @@ class options include_prefix () const; const bool& - trace () const; + proprietary_license () const; const std::string& options_file () const; + const bool& + trace () const; + // Print usage information. // static void @@ -349,8 +352,9 @@ class options std::string cxx_suffix_; bool include_with_brackets_; std::string include_prefix_; - bool trace_; + bool proprietary_license_; std::string options_file_; + bool trace_; }; #include diff --git a/odb/options.ixx b/odb/options.ixx index a511e0c..087a3ef 100644 --- a/odb/options.ixx +++ b/odb/options.ixx @@ -202,9 +202,9 @@ include_prefix () const } inline const bool& options:: -trace () const +proprietary_license () const { - return this->trace_; + return this->proprietary_license_; } inline const std::string& options:: @@ -213,3 +213,9 @@ options_file () const return this->options_file_; } +inline const bool& options:: +trace () const +{ + return this->trace_; +} + -- cgit v1.1