summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-11 15:45:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-11 15:45:06 +0200
commitcc62c09409021582d8b5ffe3b5c9d393524fd260 (patch)
tree67455202970e8ec4520f5c06e31c5a28a5180f33 /cli
parente228bb3ed878e071618b0f31856770c60cdf48df (diff)
Add usage information
Diffstat (limited to 'cli')
-rw-r--r--cli/cli.cxx29
-rw-r--r--cli/generator.cxx58
-rw-r--r--cli/generator.hxx3
-rw-r--r--cli/options.cli3
-rw-r--r--cli/options.cxx12
-rw-r--r--cli/options.hxx8
-rw-r--r--cli/options.ixx12
-rw-r--r--cli/usage.hxx181
8 files changed, 289 insertions, 17 deletions
diff --git a/cli/cli.cxx b/cli/cli.cxx
index 4aaa2d6..b2c6695 100644
--- a/cli/cli.cxx
+++ b/cli/cli.cxx
@@ -7,11 +7,15 @@
#include <fstream>
#include <iostream>
+#include <cutl/compiler/code-stream.hxx>
+
+#include "usage.hxx"
#include "options.hxx"
#include "parser.hxx"
#include "generator.hxx"
using namespace std;
+using namespace cutl;
int main (int argc, char* argv[])
{
@@ -22,6 +26,8 @@ int main (int argc, char* argv[])
int end;
options ops (argc, argv, end);
+ // Handle --version
+ //
if (ops.version ())
{
e << "CodeSynthesis CLI command line interface compiler 0.0.2" << endl
@@ -34,6 +40,29 @@ int main (int argc, char* argv[])
return 0;
}
+ // Handle --help
+ //
+ if (ops.help ())
+ {
+ e << "Usage: " << argv[0] << " [options] file"
+ << endl
+ << "Options:" << endl;
+
+ compiler::ostream_filter<usage_indenter, char> filt (e);
+
+ e << "--help" << endl
+ << " Print usage information and exit."
+ << endl;
+
+ e << "--version" << endl
+ << " Print version and exit."
+ << endl;
+
+ generator::usage ();
+
+ return 0;
+ }
+
if (end == argc)
{
e << "error: no input file specified" << endl
diff --git a/cli/generator.cxx b/cli/generator.cxx
index 801f7e5..89270bb 100644
--- a/cli/generator.cxx
+++ b/cli/generator.cxx
@@ -31,6 +31,64 @@ using namespace cutl;
using semantics::path;
+void generator::
+usage ()
+{
+ ostream& e (cerr);
+
+ e << "--output-dir | -o <dir>" << endl
+ << " Write generated files to <dir>." << endl;
+
+ e << "--suppress-inline" << endl
+ << " Generate all functions non-inline." << endl;
+
+ e << "--hxx-suffix <suffix>" << endl
+ << " Use <suffix> instead of the default '.hxx' to\n"
+ << " construct the name of the generated header file."
+ << endl;
+
+ e << "--ixx-suffix <suffix>" << endl
+ << " Use <suffix> instead of the default '.ixx' to\n"
+ << " construct the name of the generated inline file."
+ << endl;
+
+ e << "--cxx-suffix <suffix>" << endl
+ << " Use <suffix> instead of the default '.cxx' to\n"
+ << " construct the name of the generated source file."
+ << endl;
+
+ e << "--option-prefix <prefix>" << endl
+ << " Use <prefix> instead of the default '-' as an\n"
+ << " option prefix."
+ << endl;
+
+ e << "--option-separator <sep>" << endl
+ << " Use <sep> instead of the default '--' as an\n"
+ << " optional separator between options and arguments."
+ << endl;
+
+ e << "--include-with-brackets" << endl
+ << " Use angle brackets (<>) instead of quotes (\"\") in\n"
+ << " generated #include directives."
+ << endl;
+
+ e << "--include-prefix <prefix>" << endl
+ << " Add <prefix> to generated #include directive\n"
+ << " paths."
+ << endl;
+
+ e << "--guard-prefix <prefix>" << endl
+ << " Add <prefix> to generated header inclusion guards."
+ << endl;
+
+ e << "--reserved-name <name>" << endl
+ << " Add <name> to the list of names that should not\n"
+ << " be used as identifiers. The name can optionally\n"
+ << " be followed by '=' and the replacement name that\n"
+ << " should be used instead."
+ << endl;
+}
+
namespace
{
static char const header[] =
diff --git a/cli/generator.hxx b/cli/generator.hxx
index c9b449d..112c20d 100644
--- a/cli/generator.hxx
+++ b/cli/generator.hxx
@@ -14,6 +14,9 @@ class generator
public:
generator ();
+ static void
+ usage ();
+
class failed {};
void
diff --git a/cli/options.cli b/cli/options.cli
index e2549fa..a5fe0ae 100644
--- a/cli/options.cli
+++ b/cli/options.cli
@@ -16,9 +16,10 @@ class options
bool --help;
bool --version;
+ std::string --output-dir | -o;
+
bool --suppress-inline;
- std::string --output-dir | -o;
std::string --hxx-suffix = ".hxx";
std::string --ixx-suffix = ".ixx";
std::string --cxx-suffix = ".cxx";
diff --git a/cli/options.cxx b/cli/options.cxx
index d5e7e67..4264369 100644
--- a/cli/options.cxx
+++ b/cli/options.cxx
@@ -240,8 +240,8 @@ options (int argc,
::cli::unknown_mode arg)
: help_ (),
version_ (),
- suppress_inline_ (),
output_dir_ (),
+ suppress_inline_ (),
hxx_suffix_ (".hxx"),
ixx_suffix_ (".ixx"),
cxx_suffix_ (".cxx"),
@@ -263,8 +263,8 @@ options (int start,
::cli::unknown_mode arg)
: help_ (),
version_ (),
- suppress_inline_ (),
output_dir_ (),
+ suppress_inline_ (),
hxx_suffix_ (".hxx"),
ixx_suffix_ (".ixx"),
cxx_suffix_ (".cxx"),
@@ -286,8 +286,8 @@ options (int argc,
::cli::unknown_mode arg)
: help_ (),
version_ (),
- suppress_inline_ (),
output_dir_ (),
+ suppress_inline_ (),
hxx_suffix_ (".hxx"),
ixx_suffix_ (".ixx"),
cxx_suffix_ (".cxx"),
@@ -310,8 +310,8 @@ options (int start,
::cli::unknown_mode arg)
: help_ (),
version_ (),
- suppress_inline_ (),
output_dir_ (),
+ suppress_inline_ (),
hxx_suffix_ (".hxx"),
ixx_suffix_ (".ixx"),
cxx_suffix_ (".cxx"),
@@ -339,12 +339,12 @@ struct _cli_options_map_init
&::cli::thunk<options, bool, &options::help_>;
_cli_options_map_["--version"] =
&::cli::thunk<options, bool, &options::version_>;
- _cli_options_map_["--suppress-inline"] =
- &::cli::thunk<options, bool, &options::suppress_inline_>;
_cli_options_map_["--output-dir"] =
&::cli::thunk<options, std::string, &options::output_dir_>;
_cli_options_map_["-o"] =
&::cli::thunk<options, std::string, &options::output_dir_>;
+ _cli_options_map_["--suppress-inline"] =
+ &::cli::thunk<options, bool, &options::suppress_inline_>;
_cli_options_map_["--hxx-suffix"] =
&::cli::thunk<options, std::string, &options::hxx_suffix_>;
_cli_options_map_["--ixx-suffix"] =
diff --git a/cli/options.hxx b/cli/options.hxx
index b856fbc..4d33939 100644
--- a/cli/options.hxx
+++ b/cli/options.hxx
@@ -179,12 +179,12 @@ class options
bool const&
version () const;
- bool const&
- suppress_inline () const;
-
std::string const&
output_dir () const;
+ bool const&
+ suppress_inline () const;
+
std::string const&
hxx_suffix () const;
@@ -223,8 +223,8 @@ class options
public:
bool help_;
bool version_;
- bool suppress_inline_;
std::string output_dir_;
+ bool suppress_inline_;
std::string hxx_suffix_;
std::string ixx_suffix_;
std::string cxx_suffix_;
diff --git a/cli/options.ixx b/cli/options.ixx
index 0ca4c9e..7ec5579 100644
--- a/cli/options.ixx
+++ b/cli/options.ixx
@@ -100,18 +100,18 @@ version () const
return version_;
}
-inline bool const& options::
-suppress_inline () const
-{
- return suppress_inline_;
-}
-
inline std::string const& options::
output_dir () const
{
return output_dir_;
}
+inline bool const& options::
+suppress_inline () const
+{
+ return suppress_inline_;
+}
+
inline std::string const& options::
hxx_suffix () const
{
diff --git a/cli/usage.hxx b/cli/usage.hxx
new file mode 100644
index 0000000..3aeb30b
--- /dev/null
+++ b/cli/usage.hxx
@@ -0,0 +1,181 @@
+// file : cli/usage.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_USAGE_HXX
+#define CLI_USAGE_HXX
+
+#include <cstddef> // std::size_t
+#include <cstdlib> // std::abort
+
+#include <cutl/compiler/code-stream.hxx>
+
+template <typename C>
+class usage_indenter: public cutl::compiler::code_stream<C>
+{
+public:
+ usage_indenter (cutl::compiler::code_stream<C>& out)
+ : out_ (out),
+ option_length_ (0),
+ construct_ (con_newline)
+ {
+ }
+
+private:
+ usage_indenter (usage_indenter const&);
+
+ usage_indenter&
+ operator= (usage_indenter const&);
+
+public:
+ virtual void
+ put (C c)
+ {
+ switch (c)
+ {
+ case '\n':
+ {
+ switch (construct_)
+ {
+ case con_newline:
+ {
+ out_.put (c);
+ break;
+ }
+ case con_option:
+ {
+ construct_ = con_newline;
+ break;
+ }
+ case con_description:
+ {
+ out_.put (c);
+ construct_ = con_newline;
+ break;
+ }
+ default:
+ {
+ std::abort ();
+ }
+ }
+
+ break;
+ }
+ case '-':
+ {
+ switch (construct_)
+ {
+ case con_newline:
+ {
+ construct_ = con_option;
+ option_length_ = 0;
+ output_indentation ();
+ out_.put (c);
+ ++option_length_;
+ break;
+ }
+ case con_option:
+ {
+ ++option_length_;
+ //fall through
+ }
+ case con_description:
+ {
+ out_.put (c);
+ break;
+ }
+ default:
+ {
+ std::abort ();
+ }
+ }
+
+ break;
+ }
+ default:
+ {
+ switch (construct_)
+ {
+ case con_newline:
+ {
+ construct_ = con_description;
+ output_indentation ();
+ out_.put (c);
+ break;
+ }
+ case con_option:
+ {
+ ++option_length_;
+ //fall through
+ }
+ default:
+ {
+ out_.put (c);
+ break;
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
+ virtual void
+ unbuffer ()
+ {
+ }
+
+private:
+ void
+ output_indentation ()
+ {
+ std::size_t spaces;
+
+ switch (construct_)
+ {
+ case con_option:
+ {
+ spaces = 2;
+ option_length_ += 2;
+ break;
+ }
+ case con_description:
+ {
+ spaces = 29;
+
+ if (option_length_)
+ {
+ if (option_length_ > spaces)
+ spaces = 1;
+ else
+ spaces -= option_length_;
+
+ option_length_ = 0;
+ }
+
+ break;
+ }
+ default:
+ {
+ std::abort ();
+ }
+ }
+
+ while (spaces--)
+ out_.put (' ');
+ }
+
+private:
+ cutl::compiler::code_stream<C>& out_;
+ size_t option_length_;
+
+ enum construct
+ {
+ con_newline,
+ con_option,
+ con_description
+ } construct_;
+};
+
+#endif // CLI_USAGE_HXX