summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-11-17 13:59:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-11-17 13:59:39 +0200
commit0e56fe29a9afeee00e02e722496678df89d37d50 (patch)
treeada5f6ea6978344f2e75e6194d65a1191cc6e649 /doc
parent577a38358b295379511ea8bb130ef1dcb7157c0f (diff)
Complete the implementation of the option documentation
Add the man page generator. Port CLI usage, HTML documentation and the man page to the auto-generated version. Update examples and documentation.
Diffstat (limited to 'doc')
-rw-r--r--doc/cli-epilogue.121
-rw-r--r--doc/cli-epilogue.xhtml24
-rw-r--r--doc/cli-prologue.159
-rw-r--r--doc/cli-prologue.xhtml79
-rw-r--r--doc/cli.1223
-rw-r--r--doc/cli.xhtml199
-rw-r--r--doc/guide/index.xhtml284
-rw-r--r--doc/makefile26
8 files changed, 727 insertions, 188 deletions
diff --git a/doc/cli-epilogue.1 b/doc/cli-epilogue.1
new file mode 100644
index 0000000..cd2348d
--- /dev/null
+++ b/doc/cli-epilogue.1
@@ -0,0 +1,21 @@
+.\"
+.\" DIAGNOSTICS
+.\"
+.SH DIAGNOSTICS
+If the input file is not a valid CLI definition,
+.B cli
+will issue diagnostic messages to STDERR and exit with non-zero exit code.
+.\"
+.\" BUGS
+.\"
+.SH BUGS
+Send bug reports to the cli-users@codesynthesis.com mailing list.
+.\"
+.\" COPYRIGHT
+.\"
+.SH COPYRIGHT
+Copyright (c) 2009 Code Synthesis Tools CC.
+
+Permission is granted to copy, distribute and/or modify this document under
+the terms of the MIT License. Copy of this license can be obtained from
+http://www.codesynthesis.com/licenses/mit.txt
diff --git a/doc/cli-epilogue.xhtml b/doc/cli-epilogue.xhtml
new file mode 100644
index 0000000..ea0a34a
--- /dev/null
+++ b/doc/cli-epilogue.xhtml
@@ -0,0 +1,24 @@
+ <h1>DIAGNOSTICS</h1>
+
+ <p>If the input file is not a valid CLI definition, <code><b>cli</b></code>
+ will issue diagnostic messages to STDERR and exit with non-zero exit
+ code.</p>
+
+ <h1>BUGS</h1>
+
+ <p>Send bug reports to the
+ <a href="mailto:cli-users@codesynthesis.com">cli-users@codesynthesis.com</a> mailing list.</p>
+
+ </div>
+ <div id="footer">
+ &copy;2009 <a href="http://www.codesynthesis.com">Code Synthesis Tools CC</a>
+
+ <div id="terms">
+ Permission is granted to copy, distribute and/or modify this
+ document under the terms of the
+ <a href="http://www.codesynthesis.com/licenses/mit.txt">MIT License</a>.
+ </div>
+ </div>
+</div>
+</body>
+</html>
diff --git a/doc/cli-prologue.1 b/doc/cli-prologue.1
new file mode 100644
index 0000000..5d3953b
--- /dev/null
+++ b/doc/cli-prologue.1
@@ -0,0 +1,59 @@
+.\" Process this file with
+.\" groff -man -Tascii cli.1
+.\"
+.TH CLI 1 "October 2009" "CLI 1.0.0"
+.SH NAME
+cli \- command line interface compiler for C++
+.\"
+.\"
+.\"
+.\"--------------------------------------------------------------------
+.SH SYNOPSIS
+.\"--------------------------------------------------------------------
+.B cli
+.B [
+.I options
+.B ]
+.I file
+.\"
+.\"
+.\"
+.\"--------------------------------------------------------------------
+.SH DESCRIPTION
+.\"--------------------------------------------------------------------
+.B cli
+generates C++ implementation and documentation in various formats for a
+command line interface defined in the CLI language. For an input file in
+the form
+.B name.cli
+the following is generated. By default or if the
+.B --generate-cxx
+option is specified, the following C++ files are generated:
+.B name.hxx
+(header file),
+.B name.ixx
+(inline file, generated unless the
+.B --suppress-inline
+option is specified), and
+.B name.cxx (source file).
+If the
+.B --generate-html
+option is specified, then the
+.B name.html
+HTML documentation file is generated. If the
+.B --generate-man
+option is specified, then the
+.B name.1
+man page file is generated. When
+.B --generate-html
+or
+.B --generate-man
+is specified, the
+.B --stdout
+option can be used to redirect the output to STDOUT instead of a file.
+.\"
+.\"
+.\"
+.\"--------------------------------------------------------------------
+.SH OPTIONS
+.\"--------------------------------------------------------------------
diff --git a/doc/cli-prologue.xhtml b/doc/cli-prologue.xhtml
new file mode 100644
index 0000000..71108e1
--- /dev/null
+++ b/doc/cli-prologue.xhtml
@@ -0,0 +1,79 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+
+<head>
+ <title>CLI 1.0.0 Compiler Command Line Manual</title>
+
+ <meta name="copyright" content="&copy; 2009 Code Synthesis Tools CC"/>
+ <meta name="keywords" content="cli,command,line,interface,compiler,c++"/>
+ <meta name="description" content="CLI Compiler Command Line Manual"/>
+
+ <link rel="stylesheet" type="text/css" href="default.css" />
+
+<style type="text/css">
+
+ #synopsis {
+ list-style-type: none;
+ }
+
+ #synopsis li {
+ padding-top : 0.0em;
+ padding-bottom : 0.0em;
+ }
+
+ #commands dt {
+ padding-top : 0.4em;
+ }
+
+ #commands dd {
+ padding-bottom : 0.4em;
+ padding-left : 2em;
+ }
+
+ .options dt {
+ padding-top : 0.4em;
+ }
+
+ .options dd {
+ padding-top : 0.1em;
+ padding-bottom : 0.4em;
+ padding-left : 1.4em;
+ }
+
+</style>
+</head>
+
+<body>
+<div id="container">
+ <div id="content">
+
+ <h1>NAME</h1>
+
+ <p>cli - command line interface compiler for C++</p>
+
+ <h1>SYNOPSIS</h1>
+
+ <dl id="synopsis">
+ <dt><code><b>cli</b> [<i>options</i>] <i>file</i></code></dt>
+ </dl>
+
+ <h1>DESCRIPTION</h1>
+
+ <p><code><b>cli</b></code> generates C++ implementation and
+ documentation in various formats for a command line interface
+ defined in the CLI language. For an input file in the form
+ <code><b>name.cli</b></code> the following is generated. By
+ default or if the <code><b>--generate-cxx</b></code> option is
+ specified, the following C++ files are generated:
+ <code><b>name.hxx</b></code> (header file), <code><b>name.ixx</b></code>
+ (inline file, generated unless the <code><b>--suppress-inline</b></code>
+ option is specified), and <code><b>name.cxx</b></code> (source file).
+ If the <code><b>--generate-html</b></code> option is specified, then
+ the <code><b>name.html</b></code> HTML documentation file is generated.
+ If the <code><b>--generate-man</b></code> option is specified, then
+ the <code><b>name.1</b></code> man page file is generated. When
+ <code><b>--generate-html</b></code> or <code><b>--generate-man</b></code>
+ is specified, the <code><b>--stdout</b></code> option can be used to
+ redirect the output to STDOUT instead of a file.</p>
+
+ <h1>OPTIONS</h1>
diff --git a/doc/cli.1 b/doc/cli.1
index 80e3bc6..2e9f180 100644
--- a/doc/cli.1
+++ b/doc/cli.1
@@ -22,10 +22,13 @@ cli \- command line interface compiler for C++
.SH DESCRIPTION
.\"--------------------------------------------------------------------
.B cli
-generates a C++ implementation for a command line interface defined in the CLI
-language. For an input file in the form
+generates C++ implementation and documentation in various formats for a
+command line interface defined in the CLI language. For an input file in
+the form
.B name.cli
-the following C++ files are generated:
+the following is generated. By default or if the
+.B --generate-cxx
+option is specified, the following C++ files are generated:
.B name.hxx
(header file),
.B name.ixx
@@ -33,95 +36,139 @@ the following C++ files are generated:
.B --suppress-inline
option is specified), and
.B name.cxx (source file).
+If the
+.B --generate-html
+option is specified, then the
+.B name.html
+HTML documentation file is generated. If the
+.B --generate-man
+option is specified, then the
+.B name.1
+man page file is generated. When
+.B --generate-html
+or
+.B --generate-man
+is specified, the
+.B --stdout
+option can be used to redirect the output to STDOUT instead of a file.
.\"
.\"
.\"
.\"--------------------------------------------------------------------
.SH OPTIONS
.\"--------------------------------------------------------------------
-.IP "\fB\--help\fR"
-Print usage information and exit.
-
-.IP "\fB\--version\fR"
-Print version and exit.
-
-.IP "\fB\--output-dir\fR | \fB\-o \fIdir\fR"
-Write generated files to
-.I dir
-instead of the current directory.
-
-.IP "\fB\--suppress-inline\fR"
-Generate all functions non-inline. By default simple functions are made
-inline. This option suppresses creation of the inline file.
-
-.IP "\fB\--hxx-suffix \fIsuffix\fR"
-Use the provided
-.I suffix
-instead of the default
-.B .hxx
-to construct the name of the generated header file.
-
-.IP "\fB\--ixx-suffix \fIsuffix\fR"
-Use the provided
-.I suffix
-instead of the default
-.B .ixx
-to construct the name of the generated inline file.
-
-.IP "\fB\--cxx-suffix \fIsuffix\fR"
-Use the provided
-.I suffix
-instead of the default
-.B .cxx
-to construct the name of the generated source file.
-
-.IP "\fB\--option-prefix \fIprefix\fR"
-Use the provided
-.I prefix
-instead of the default
-.B -
-as an option prefix. Unknown command line arguments that start with this
-prefix are treated as unknown options. If you set the option prefix to the
-empty value, then all the unknown command line arguments will be treated as
-program arguments.
-
-.IP "\fB\--option-separator \fIseparator\fR"
-Use the provided
-.I separator
-instead of the default
-.B --
-as an optional separator between options and arguments. All the command line
-arguments that are parsed after this separator are treated as program
-arguments. Set the option separator to the empty value if you don't want
-this functionality.
-
-.IP "\fB\--include-with-brackets\fR"
-Use angle brackets (<>) instead of quotes ("") in generated
-.B #include
-directives.
-
-.IP "\fB\--include-prefix \fIprefix\fR"
-Add
-.I prefix
-to generated
-.B #include
-directive paths.
-
-.IP "\fB\--guard-prefix \fIprefix\fR"
-Add
-.I prefix
-to generated header inclusion guards. The prefix is transformed to upper
-case and characters that are illegal in a preprocessor macro name are
-replaced with underscores.
-
-.IP "\fB\--reserved-name \fIname\fR[\fB=\fIrep\fR]"
-Add
-.I name
-to the list of names that should not be used as identifiers. The name
-can optionally be followed by
-.B =
-and the replacement name that should be used instead. All C++ keywords
-are already in this list.
+.\"
+.\" The following documentation was generated by CLI, a command
+.\" line interface compiler for C++.
+.\"
+.IP "\fB--help\fP"
+Print usage information and exit\.
+
+.IP "\fB--version\fP"
+Print version and exit\.
+
+.IP "\fB--output-dir\fP|\fB-o\fP \fIdir\fP"
+Write the generated files to \fIdir\fP instead of the current directory\.
+
+.IP "\fB--suppress-inline\fP"
+Generate all functions non-inline\. By default simple functions are made
+inline\. This option suppresses creation of the inline file\.
+
+.IP "\fB--suppress-usage\fP"
+Suppress the generation of the usage printing code\.
+
+.IP "\fB--long-usage\fP"
+If no short documentation string is provided, use the complete long
+documentation string in usage\. By default, in this situation only the first
+sentence from the long string is used\.
+
+.IP "\fB--option-length\fP \fIlen\fP"
+Indent option descriptions \fIlen\fP characters when printing usage\. This
+is useful when you have multiple options classes, potentially in separate
+files, and would like their usage to have the same indentation level\.
+
+.IP "\fB--generate-cxx\fP"
+Generate C++ code\. If neither \fB--generate-man\fP nor
+\fB--generate-html\fP is specified, this mode is assumed by default\.
+
+.IP "\fB--generate-man\fP"
+Generate documentation in the man page format\.
+
+.IP "\fB--generate-html\fP"
+Generate documentation in the HTML format\.
+
+.IP "\fB--man-prologue\fP \fIfile\fP"
+Insert the content of \fIfile\fP at the beginning of the man page file\.
+
+.IP "\fB--man-epilogue\fP \fIfile\fP"
+Insert the content of \fIfile\fP at the end of the man page file\.
+
+.IP "\fB--html-prologue\fP \fIfile\fP"
+Insert the content of \fIfile\fP at the beginning of the HTML file\.
+
+.IP "\fB--html-epilogue\fP \fIfile\fP"
+Insert the content of \fIfile\fP at the end of the HTML file\.
+
+.IP "\fB--class\fP \fIfq-name\fP"
+Generate the man page or HTML documentation only for the \fIfq-name\fP
+options class\. The \fIfq-name\fP name should be a fully-qualified options
+class name, for example, \fBapp::options\fP\. This functionality is useful
+if you need to insert custom documentation between options belonging to
+different classes\.
+
+.IP "\fB--stdout\fP"
+Write output to STDOUT instead of a file\. This option is not valid when
+generating C++ code and is normally used to combine generated documentation
+for several option classes in a single file\.
+
+.IP "\fB--hxx-suffix\fP \fIsuffix\fP"
+Use \fIsuffix\fP instead of the default \fB\.hxx\fP to construct the name of
+the generated header file\.
+
+.IP "\fB--ixx-suffix\fP \fIsuffix\fP"
+Use \fIsuffix\fP instead of the default \fB\.ixx\fP to construct the name of
+the generated inline file\.
+
+.IP "\fB--cxx-suffix\fP \fIsuffix\fP"
+Use \fIsuffix\fP instead of the default \fB\.cxx\fP to construct the name of
+the generated source file\.
+
+.IP "\fB--man-suffix\fP \fIsuffix\fP"
+Use \fIsuffix\fP instead of the default \fB\.1\fP to construct the name of
+the generated man page file\.
+
+.IP "\fB--html-suffix\fP \fIsuffix\fP"
+Use \fIsuffix\fP instead of the default \fB\.html\fP to construct the name
+of the generated HTML file\.
+
+.IP "\fB--option-prefix\fP \fIprefix\fP"
+Use \fIprefix\fP instead of the default \fB-\fP as an option prefix\.
+Unknown command line arguments that start with this prefix are treated as
+unknown options\. If you set the option prefix to the empty value, then all
+the unknown command line arguments will be treated as program arguments\.
+
+.IP "\fB--option-separator\fP \fIsep\fP"
+Use \fIsep\fP instead of the default \fB--\fP as an optional separator
+between options and arguments\. All the command line arguments that are
+parsed after this separator are treated as program arguments\. Set the
+option separator to the empty value if you don't want this functionality\.
+
+.IP "\fB--include-with-brackets\fP"
+Use angle brackets (<>) instead of quotes ("") in the generated
+\fB#include\fP directives\.
+
+.IP "\fB--include-prefix\fP \fIprefix\fP"
+Add \fIprefix\fP to the generated \fB#include\fP directive paths\.
+
+.IP "\fB--guard-prefix\fP \fIprefix\fP"
+Add \fIprefix\fP to the generated header inclusion guards\. The prefix is
+transformed to upper case and characters that are illegal in a preprocessor
+macro name are replaced with underscores\.
+
+.IP "\fB--reserved-name\fP \fIname\fP=\fIrep\fP"
+Add \fIname\fP with an optional \fIrep\fP replacement to the list of names
+that should not be used as identifiers\. If provided, the replacement name
+is used instead\. All C++ keywords are already in this list\.
.\"
.\" DIAGNOSTICS
@@ -129,9 +176,7 @@ are already in this list.
.SH DIAGNOSTICS
If the input file is not a valid CLI definition,
.B cli
-will issue diagnostic messages to
-.B STDERR
-and exit with non-zero exit code.
+will issue diagnostic messages to STDERR and exit with non-zero exit code.
.\"
.\" BUGS
.\"
diff --git a/doc/cli.xhtml b/doc/cli.xhtml
index b026b6e..85dd4b9 100644
--- a/doc/cli.xhtml
+++ b/doc/cli.xhtml
@@ -59,81 +59,144 @@
<h1>DESCRIPTION</h1>
- <p><code><b>cli</b></code> generates a C++ implementation for a command
- line interface defined in the CLI language. For an input file in the
- form <code><b>name.cli</b></code> the following C++ files are generated:
+ <p><code><b>cli</b></code> generates C++ implementation and
+ documentation in various formats for a command line interface
+ defined in the CLI language. For an input file in the form
+ <code><b>name.cli</b></code> the following is generated. By
+ default or if the <code><b>--generate-cxx</b></code> option is
+ specified, the following C++ files are generated:
<code><b>name.hxx</b></code> (header file), <code><b>name.ixx</b></code>
(inline file, generated unless the <code><b>--suppress-inline</b></code>
- option is specified), and <code><b>name.cxx</b></code> (source file).</p>
+ option is specified), and <code><b>name.cxx</b></code> (source file).
+ If the <code><b>--generate-html</b></code> option is specified, then
+ the <code><b>name.html</b></code> HTML documentation file is generated.
+ If the <code><b>--generate-man</b></code> option is specified, then
+ the <code><b>name.1</b></code> man page file is generated. When
+ <code><b>--generate-html</b></code> or <code><b>--generate-man</b></code>
+ is specified, the <code><b>--stdout</b></code> option can be used to
+ redirect the output to STDOUT instead of a file.</p>
<h1>OPTIONS</h1>
- <dl class="options">
- <dt><code><b>--help</b></code></dt>
- <dd>Print usage information and exit.</dd>
-
- <dt><code><b>--version</b></code></dt>
- <dd>Print version and exit.</dd>
-
- <dt><code><b>--output-dir</b> | <b>-o</b> <i>dir</i></code></dt>
- <dd>Write generated files to <code><i>dir</i></code> instead of
- the current directory.</dd>
-
- <dt><code><b>--suppress-inline</b></code></dt>
- <dd>Generate all functions non-inline. By default simple functions
- are made inline. This option suppresses creation of the inline
- file.</dd>
-
- <dt><code><b>--hxx-suffix</b> <i>suffix</i></code></dt>
- <dd>Use the provided <code><i>suffix</i></code> instead of the default
- <code><b>.hxx</b></code> to construct the name of the generated header
- file.</dd>
-
- <dt><code><b>--ixx-suffix</b> <i>suffix</i></code></dt>
- <dd>Use the provided <code><i>suffix</i></code> instead of the default
- <code><b>.ixx</b></code> to construct the name of the generated inline
- file.</dd>
-
- <dt><code><b>--cxx-suffix</b> <i>suffix</i></code></dt>
- <dd>Use the provided <code><i>suffix</i></code> instead of the default
- <code><b>.cxx</b></code> to construct the name of the generated source
- file.</dd>
-
- <dt><code><b>--option-prefix</b> <i>prefix</i></code></dt>
- <dd>Use the provided <code><i>prefix</i></code> instead of the default
- <code><b>-</b></code> as an option prefix. Unknown command line
- arguments that start with this prefix are treated as unknown options.
- If you set the option prefix to the empty value, then all the unknown
- command line arguments will be treated as program arguments.</dd>
-
- <dt><code><b>--option-separator</b> <i>separator</i></code></dt>
- <dd>Use the provided <code><i>separator</i></code> instead of the default
- <code><b>--</b></code> as an optional separator between options and
- arguments. All the command line arguments that are parsed after this
- separator are treated as program arguments. Set the option separator
- to the empty value if you don't want this functionality.</dd>
-
- <dt><code><b>--include-with-brackets</b></code></dt>
- <dd>Use angle brackets (&lt;&gt;) instead of quotes ("") in generated
- <code><b>#include</b></code> directives.</dd>
-
- <dt><code><b>--include-prefix</b> <i>prefix</i></code></dt>
- <dd>Add <code><i>prefix</i></code> to generated <code><b>#include</b></code>
- directive paths.</dd>
-
- <dt><code><b>--guard-prefix</b> <i>prefix</i></code></dt>
- <dd>Add <code><i>prefix</i></code> to generated header inclusion guards.
- The prefix is transformed to upper case and characters that are
- illegal in a preprocessor macro name are replaced with underscores.</dd>
-
- <dt><code><b>--reserved-name</b> <i>name</i>[<b>=</b><i>rep</i>]</code></dt>
- <dd>Add <code><i>name</i></code> to the list of names that should not
- be used as identifiers. The name can optionally be followed by
- <code><b>=</b></code> and the replacement name that should be
- used instead. All C++ keywords are already in this list.</dd>
+<!--
+ The following documentation was generated by CLI, a command
+ line interface compiler for C++.
+-->
- </dl>
+<dl class="options">
+ <dt><code><b>--help</b></code></dt>
+ <dd>Print usage information and exit.</dd>
+ <dt><code><b>--version</b></code></dt>
+ <dd>Print version and exit.</dd>
+
+ <dt><code><b>--output-dir</b></code>|<code><b>-o</b></code> <i>dir</i></dt>
+ <dd>Write the generated files to <i>dir</i> instead of the current directory.</dd>
+
+ <dt><code><b>--suppress-inline</b></code></dt>
+ <dd>Generate all functions non-inline. By default simple functions are made
+ inline. This option suppresses creation of the inline file.</dd>
+
+ <dt><code><b>--suppress-usage</b></code></dt>
+ <dd>Suppress the generation of the usage printing code.</dd>
+
+ <dt><code><b>--long-usage</b></code></dt>
+ <dd>If no short documentation string is provided, use the complete long
+ documentation string in usage. By default, in this situation only the first
+ sentence from the long string is used.</dd>
+
+ <dt><code><b>--option-length</b></code> <i>len</i></dt>
+ <dd>Indent option descriptions <i>len</i> characters when printing usage. This
+ is useful when you have multiple options classes, potentially in separate
+ files, and would like their usage to have the same indentation level.</dd>
+
+ <dt><code><b>--generate-cxx</b></code></dt>
+ <dd>Generate C++ code. If neither <code><b>--generate-man</b></code> nor
+ <code><b>--generate-html</b></code> is specified, this mode is assumed by
+ default.</dd>
+
+ <dt><code><b>--generate-man</b></code></dt>
+ <dd>Generate documentation in the man page format.</dd>
+
+ <dt><code><b>--generate-html</b></code></dt>
+ <dd>Generate documentation in the HTML format.</dd>
+
+ <dt><code><b>--man-prologue</b></code> <i>file</i></dt>
+ <dd>Insert the content of <i>file</i> at the beginning of the man page file.</dd>
+
+ <dt><code><b>--man-epilogue</b></code> <i>file</i></dt>
+ <dd>Insert the content of <i>file</i> at the end of the man page file.</dd>
+
+ <dt><code><b>--html-prologue</b></code> <i>file</i></dt>
+ <dd>Insert the content of <i>file</i> at the beginning of the HTML file.</dd>
+
+ <dt><code><b>--html-epilogue</b></code> <i>file</i></dt>
+ <dd>Insert the content of <i>file</i> at the end of the HTML file.</dd>
+
+ <dt><code><b>--class</b></code> <i>fq-name</i></dt>
+ <dd>Generate the man page or HTML documentation only for the <i>fq-name</i>
+ options class. The <i>fq-name</i> name should be a fully-qualified options
+ class name, for example, <code><b>app::options</b></code>. This
+ functionality is useful if you need to insert custom documentation between
+ options belonging to different classes.</dd>
+
+ <dt><code><b>--stdout</b></code></dt>
+ <dd>Write output to STDOUT instead of a file. This option is not valid when
+ generating C++ code and is normally used to combine generated documentation
+ for several option classes in a single file.</dd>
+
+ <dt><code><b>--hxx-suffix</b></code> <i>suffix</i></dt>
+ <dd>Use <i>suffix</i> instead of the default <code><b>.hxx</b></code> to
+ construct the name of the generated header file.</dd>
+
+ <dt><code><b>--ixx-suffix</b></code> <i>suffix</i></dt>
+ <dd>Use <i>suffix</i> instead of the default <code><b>.ixx</b></code> to
+ construct the name of the generated inline file.</dd>
+
+ <dt><code><b>--cxx-suffix</b></code> <i>suffix</i></dt>
+ <dd>Use <i>suffix</i> instead of the default <code><b>.cxx</b></code> to
+ construct the name of the generated source file.</dd>
+
+ <dt><code><b>--man-suffix</b></code> <i>suffix</i></dt>
+ <dd>Use <i>suffix</i> instead of the default <code><b>.1</b></code> to construct
+ the name of the generated man page file.</dd>
+
+ <dt><code><b>--html-suffix</b></code> <i>suffix</i></dt>
+ <dd>Use <i>suffix</i> instead of the default <code><b>.html</b></code> to
+ construct the name of the generated HTML file.</dd>
+
+ <dt><code><b>--option-prefix</b></code> <i>prefix</i></dt>
+ <dd>Use <i>prefix</i> instead of the default <code><b>-</b></code> as an option
+ prefix. Unknown command line arguments that start with this prefix are
+ treated as unknown options. If you set the option prefix to the empty value,
+ then all the unknown command line arguments will be treated as program
+ arguments.</dd>
+
+ <dt><code><b>--option-separator</b></code> <i>sep</i></dt>
+ <dd>Use <i>sep</i> instead of the default <code><b>--</b></code> as an optional
+ separator between options and arguments. All the command line arguments that
+ are parsed after this separator are treated as program arguments. Set the
+ option separator to the empty value if you don't want this functionality.</dd>
+
+ <dt><code><b>--include-with-brackets</b></code></dt>
+ <dd>Use angle brackets (&lt;>) instead of quotes ("") in the generated
+ <code><b>#include</b></code> directives.</dd>
+
+ <dt><code><b>--include-prefix</b></code> <i>prefix</i></dt>
+ <dd>Add <i>prefix</i> to the generated <code><b>#include</b></code> directive
+ paths.</dd>
+
+ <dt><code><b>--guard-prefix</b></code> <i>prefix</i></dt>
+ <dd>Add <i>prefix</i> to the generated header inclusion guards. The prefix is
+ transformed to upper case and characters that are illegal in a preprocessor
+ macro name are replaced with underscores.</dd>
+
+ <dt><code><b>--reserved-name</b></code> <i>name</i>=<i>rep</i></dt>
+ <dd>Add <i>name</i> with an optional <i>rep</i> replacement to the list of names
+ that should not be used as identifiers. If provided, the replacement name is
+ used instead. All C++ keywords are already in this list.</dd>
+
+</dl>
<h1>DIAGNOSTICS</h1>
<p>If the input file is not a valid CLI definition, <code><b>cli</b></code>
diff --git a/doc/guide/index.xhtml b/doc/guide/index.xhtml
index 24d76fa..a7ae6e7 100644
--- a/doc/guide/index.xhtml
+++ b/doc/guide/index.xhtml
@@ -125,6 +125,17 @@
padding : 0em 0 0em 0.7em;
text-align : left;
}
+
+ /* Sample options documentation. */
+ .options dt {
+ padding-top : 0.4em;
+ }
+
+ .options dd {
+ padding-top : 0.1em;
+ padding-bottom : 0.4em;
+ padding-left : 1.4em;
+ }
</style>
@@ -168,6 +179,7 @@
<tr><th>2.2</th><td><a href="#2.2">Translating CLI Definitions to C++</a></td></tr>
<tr><th>2.3</th><td><a href="#2.3">Implementing Application Logic</a></td></tr>
<tr><th>2.4</th><td><a href="#2.4">Compiling and Running</a></td></tr>
+ <tr><th>2.5</th><td><a href="#2.5">Adding Documentation</a></td></tr>
</table>
</td>
</tr>
@@ -177,8 +189,9 @@
<table class="toc">
<tr><th>3.1</th><td><a href="#3.1">Options Class Definition</a></td></tr>
<tr><th>3.2</th><td><a href="#3.2">Option Definition</a></td></tr>
- <tr><th>3.3</th><td><a href="#3.3">Include Directive</a></td></tr>
- <tr><th>3.4</th><td><a href="#3.4">Namespace Definition</a></td></tr>
+ <tr><th>3.3</th><td><a href="#3.3">Option Documentation</a></td></tr>
+ <tr><th>3.4</th><td><a href="#3.4">Include Directive</a></td></tr>
+ <tr><th>3.5</th><td><a href="#3.5">Namespace Definition</a></td></tr>
</table>
</td>
</tr>
@@ -332,10 +345,9 @@ using namespace std;
void
usage ()
{
- cerr &lt;&lt; "usage: driver &lt;options> &lt;names>" &lt;&lt; endl
- &lt;&lt; " [--help]" &lt;&lt; endl
- &lt;&lt; " [--greeting &lt;string>]" &lt;&lt; endl
- &lt;&lt; " [--exclamations &lt;integer>]" &lt;&lt; endl;
+ cerr &lt;&lt; "usage: driver [options] &lt;names>" &lt;&lt; endl
+ &lt;&lt; "options:" &lt;&lt; endl;
+ options::print_usage (cerr);
}
int
@@ -411,19 +423,110 @@ Hi, Jane!!!
<pre class="terminal">
$ ./driver -n 3 Jane
unknown option '-n'
-usage: driver &lt;options> &lt;names>
- [--help]
- [--greeting &lt;string>]
- [--exclamations &lt;integer>]
+usage: driver [options] &lt;names>
+options:
+--help
+--greeting &lt;arg>
+--exclamations &lt;arg>
$ ./driver --exclamations abc Jane
invalid value 'abc' for option '--exclamations'
-usage: driver &lt;options> &lt;names>
- [--help]
- [--greeting &lt;string>]
- [--exclamations &lt;integer>]
+usage: driver [options] &lt;names>
+options:
+--help
+--greeting &lt;arg>
+--exclamations &lt;arg>
+ </pre>
+
+ <h2><a name="2.5">2.5 Adding Documentation</a></h2>
+
+ <p>As we have seen in the previous sections, the <code>options</code>
+ C++ class provides the <code>print_usage()</code> function which we
+ can use to display the application usage information. Right now this
+ information is very basic and does not include any description of
+ the purpose of each option:</p>
+
+ <pre class="terminal">
+$ ./driver --help
+usage: driver [options] &lt;names>
+options:
+--help
+--greeting &lt;arg>
+--exclamations &lt;arg>
+ </pre>
+
+ <p>To make the usage information more descriptive we can document each
+ option in the command line interface definition. This information can
+ also be used to automatically generate program documentation in various
+ formats, such as HTML and man page. For example:</p>
+
+ <pre>
+include &lt;string>;
+
+class options
+{
+ bool --help {"Print usage information and exit."};
+
+ std::string --greeting = "Hello"
+ {
+ "&lt;text>",
+ "Use &lt;text> as a greeting phrase instead of the default \"Hello\"."
+ };
+
+ unsigned int --exclamations = 1
+ {
+ "&lt;num>",
+ "Print &lt;num> exclamation marks instead of 1 by default."
+ };
+};
</pre>
+ <p>If we now save this updated command line interface to
+ <code>hello.cli</code> and recompile our application, the usage
+ information printed by the program will look like this:</p>
+
+ <pre class="terminal">
+usage: driver [options] &lt;names>
+options:
+--help Print usage information and exit.
+--greeting &lt;text> Use &lt;text> as a greeting phrase instead of the
+ default "Hello".
+--exclamations &lt;num> Print &lt;num> exclamation marks instead of 1 by
+ default.
+ </pre>
+
+ <p>We can also generate the program documentation in the HTML
+ (<code>--generate-html</code> CLI option) and man page
+ (<code>--generate-man</code> CLI option) formats. For example:</p>
+
+ <pre class="terminal">
+$ cli --generate-html hello.cli
+ </pre>
+
+ <p>The resulting <code>hello.html</code> file contains the following
+ documentation:</p>
+
+<dl class="options">
+ <dt><code><b>--help</b></code></dt>
+ <dd>Print usage information and exit.</dd>
+
+ <dt><code><b>--greeting</b></code> <i>text</i></dt>
+ <dd>Use <i>text</i> as a greeting phrase instead of the default "Hello".</dd>
+
+ <dt><code><b>--exclamations</b></code> <i>num</i></dt>
+ <dd>Print <i>num</i> exclamation marks instead of 1 by default.</dd>
+
+</dl>
+
+ <p>This HTML fragment can be combined with custom prologue and epilogue
+ to create a complete program documentation
+ (<code>--html-prologue/--html-epilogue</code> options for the HTML
+ output, <code>--man-prologue/--man-epilogue</code> options for the
+ man page output). For an example of such complete documentation see
+ the <a href="http://www.codesynthesis.com/projects/cli/doc/cli.xhtml">CLI
+ Compiler Command Line Manual</a> and the <code>cli(1)</code> man
+ page. For more information on the option documentation syntax,
+ see <a href="#3.3">Section 3.3, Option Documentation</a>.</p>
<!-- CLI Language -->
@@ -431,8 +534,8 @@ usage: driver &lt;options> &lt;names>
<h1><a name="3">3 CLI Language</a></h1>
<p>This chapter describes the CLI language and its mapping to C++.
- A CLI file consists of zero or more <a href="#3.3">Include
- Directives</a> followed by one or more <a href="#3.4">Namespace Definitions</a>
+ A CLI file consists of zero or more <a href="#3.4">Include
+ Directives</a> followed by one or more <a href="#3.5">Namespace Definitions</a>
or <a href="#3.1">Option Class Definitions</a>. C and C++-style comments
can be used anywhere in the CLI file except in character and
string literals.</p>
@@ -488,6 +591,10 @@ public:
operator= (const options&amp;);
public:
+ static void
+ print_usage (std::ostream&amp;);
+
+public:
bool
help () const;
@@ -500,7 +607,10 @@ public:
<p>An option class is mapped to a C++ class with the same name. The
C++ class defines a set of public overloaded constructors, a public
copy constructor and an assignment operator, as well as a set of public
- accessor functions corresponding to option definitions.</p>
+ accessor functions corresponding to option definitions. It also
+ defines a public static <code>print_usage()</code> function that
+ can be used to print the usage information for the options
+ defined by the class.</p>
<p>The <code>argc/argv</code> arguments in the overloaded constructors
are used to pass the command line arguments array, normally as passed
@@ -654,12 +764,12 @@ namespace cli
<h2><a name="3.2">3.2 Option Definition</a></h2>
-<p>An option definition consists of there components: <em>type</em>,
- <em>name</em>, and <em>default value</em>. An option type can be any
- C++ type as long as its string representation can be parsed using
- the <code>std::istream</code> interface. If the option type is
- user-defined then you will need to include its declaration using
- the <a href="#3.3">Include Directive</a>.</p>
+<p>An option definition consists of four components: <em>type</em>,
+ <em>name</em>, <em>default value</em>, and <em>documentation</em>.
+ An option type can be any C++ type as long as its string representation
+ can be parsed using the <code>std::istream</code> interface. If the option
+ type is user-defined then you will need to include its declaration using
+ the <a href="#3.4">Include Directive</a>.</p>
<p>An option of a type other than <code>bool</code> is expected to
have a value. An option of type <code>bool</code> is treated as
@@ -672,7 +782,7 @@ namespace cli
by <code>|</code>. The C++ accessor function name is derived from the
first name by removing any leading special characters, such as
<code>-</code>, <code>/</code>, etc., and replacing special characters
- in other places with underscore. For example, the following option
+ in other places with underscores. For example, the following option
definition:</p>
<pre>
@@ -705,7 +815,7 @@ class options
};
</pre>
- <p>The final component of the option definition is the optional default
+ <p>The following component of the option definition is the optional default
value. If the default value is not specified, then the option is
initialized with the default constructor. In particular, this means
that a <code>bool</code> option will be initialized to <code>false</code>,
@@ -797,7 +907,127 @@ class options
<code>-m =B</code> (key is an empty string), <code>-m c=</code> (value
is an empty string), or <code>-m d</code> (same as <code>-m d=</code>).</p>
- <h2><a name="3.3">3.3 Include Directive</a></h2>
+ <p>The last component in the option definition is optional documentation.
+ It is discussed in the next section.</p>
+
+ <h2><a name="3.3">3.3 Option Documentation</a></h2>
+
+ <p>Option documentation mimics C++ string array initialization:
+ it is enclosed in <code>{}</code> and consists of one or more
+ documentation strings separated by a comma, for example:</p>
+
+ <pre>
+class options
+{
+ int --compression = 5
+ {
+ "&lt;level>",
+ "Set compression to &lt;level> instead of 5 by default.
+
+ With the higher compression levels the program may produce a
+ smaller output but may also take longer and use more memory."
+ };
+};
+ </pre>
+
+ <p>The option documentation consists of a maximum of three documentation
+ strings. The first string is the value documentation string.
+ It describes the option value and is only applicable to options
+ with types other than <code>bool</code> (options of type
+ <code>bool</code> are flags and don't have an explicit value).
+ The second string (or the first string for options of type
+ <code>bool</code>) is the short documentation string. It
+ provides a brief description of the option. The last entry
+ in the option documentation is the long documentation string.
+ It provides a detailed description of the option. The short
+ documentation string is optional. If only two strings are
+ present in the option documentation (one string for options
+ of type <code>bool</code>), then the second (first) string is
+ assumed to be the long documentation string.</p>
+
+ <p>Option documentation is used to print the usage information
+ as well as to generate program documentation in the HTML and
+ man page formats. For usage information the short documentation
+ string is used if provided. If only the long string is available,
+ then, by default, only the first sentence from the long string
+ is used. You can override this behavior and include the complete
+ long string in the usage information by specifying the
+ <code>--long-usage</code> CLI compiler option. When generating
+ the program documentation, the long documentation strings are
+ always used.</p>
+
+ <p>The value documentation string can contain text enclosed in
+ <code>&lt;></code> which is automatically recognized by the CLI
+ compiler and typeset according to the selected output in all three
+ documentation strings. For example, in usage the <code>level</code>
+ value for the <code>--compression</code> option presented above
+ will be displayed as <code>&lt;level></code> while in the HTML and
+ man page output it will be typeset in italic as
+ <code><i>level</i></code>. Here is another example using the
+ <code>std::map</code> type:</p>
+
+ <pre>
+include &lt;map>;
+include &lt;string>;
+
+class options
+{
+ std::map&lt;std::string, std::string> --map
+ {
+ "&lt;key>=&lt;value>",
+ "Add the &lt;key>, &lt;value> pair to the map."
+ };
+};
+ </pre>
+
+ <p>The resulting HTML output for this option would look like this:</p>
+
+<dl class="options">
+ <dt><code><b>--map</b></code> <i>key</i>=<i>value</i></dt>
+ <dd>Add the <i>key</i>, <i>value</i> pair to the map.</dd>
+</dl>
+
+ <p>As you might have noticed from the examples presented so far, the
+ documentation strings can span multiple lines which is not possible
+ in C++. Also, all three documentation strings support the following
+ basic formatting mechanisms. The start of a new paragraph is indicated
+ by a blank line. A fragment of text can be typeset in monospace font
+ (normally used for code fragments) by enclosing it in the
+ <code>\c{}</code> block. Similarly, text can be typeset in bold or
+ italic fonts using the <code>\b{}</code> and <code>\i{}</code> blocks,
+ respectively. You can also combine several font properties in a single
+ block, for example, <code>\cb{bold code}</code>. If you need to include
+ literal <code>}</code> in a formatting block, you can use the
+ <code>\}</code> escape sequence, for example,
+ <code>\c{int a[] = {1, 2\}}</code>. The following example shows how we
+ can use these mechanisms:</p>
+
+ <pre>
+class options
+{
+ int --compression = 5
+ {
+ "&lt;level>",
+ "Set compression to &lt;level> instead of 5 by default.
+
+ With the higher compression levels the program \i{may}
+ produce a smaller output but may also \b{take longer}
+ and \b{use more memory}."
+ };
+};
+ </pre>
+
+ <p>The resulting HTML output for this option would look like this:</p>
+
+<dl class="options">
+ <dt><code><b>--compression</b></code> <i>level</i></dt>
+ <dd>Set compression to <i>level</i> instead of 5 by default.
+
+ <p>With the higher compression levels the program <i>may</i> produce a
+ smaller output but may also <b>take longer</b> and <b>use more memory</b>.</p></dd>
+</dl>
+
+ <h2><a name="3.4">3.4 Include Directive</a></h2>
<p>If you are using user-defined types in your option definitions,
you will need to include their declarations with the include
@@ -843,7 +1073,7 @@ class options
and <code>name_type</code> types in the <code>options</code> class would
be undeclared and result in compilation errors.</p>
- <h2><a name="3.4">3.4 Namespace Definition</a></h2>
+ <h2><a name="3.5">3.5 Namespace Definition</a></h2>
<p>Option classes can be placed into namespaces which are translated
directly to C++ namespaces. For example:</p>
diff --git a/doc/makefile b/doc/makefile
index 7b97ba2..c9267a7 100644
--- a/doc/makefile
+++ b/doc/makefile
@@ -9,14 +9,32 @@ default := $(out_base)/
install := $(out_base)/.install
cleandoc := $(out_base)/.cleandoc
-$(default): $(out_base)/guide/
+$(default): $(out_base)/cli.xhtml $(out_base)/cli.1 $(out_base)/guide/
+
+# Generated documentation.
+#
+$(out_base)/cli.xhtml: $(src_root)/cli/options.cli \
+ $(src_base)/cli-prologue.xhtml \
+ $(src_base)/cli-epilogue.xhtml
+ $(call message,cli-html $<,$(out_root)/cli/cli --generate-html \
+--output-dir $(out_base) --html-prologue $(src_base)/cli-prologue.xhtml \
+--html-epilogue $(src_base)/cli-epilogue.xhtml $<)
+ $(call message,,mv $(out_base)/options.html $(out_base)/cli.xhtml)
+
+$(out_base)/cli.1: $(src_root)/cli/options.cli \
+ $(src_base)/cli-prologue.1 \
+ $(src_base)/cli-epilogue.1
+ $(call message,cli-man $<,$(out_root)/cli/cli --generate-man \
+--output-dir $(out_base) --man-prologue $(src_base)/cli-prologue.1 \
+--man-epilogue $(src_base)/cli-epilogue.1 $<)
+ $(call message,,mv $(out_base)/options.1 $(out_base)/cli.1)
# Install.
#
-$(install): $(out_base)/guide/.install
+$(install): $(out_base)/guide/.install $(out_base)/cli.xhtml $(out_base)/cli.1
$(call install-data,$(src_base)/default.css,$(install_doc_dir)/cli/default.css)
- $(call install-data,$(src_base)/cli.xhtml,$(install_doc_dir)/cli/cli.xhtml)
- $(call install-data,$(src_base)/cli.1,$(install_man_dir)/man1/cli.1)
+ $(call install-data,$(out_base)/cli.xhtml,$(install_doc_dir)/cli/cli.xhtml)
+ $(call install-data,$(out_base)/cli.1,$(install_man_dir)/man1/cli.1)
# Clean.
#