24#ifndef TCLAP_DOCBOOKOUTPUT_H
25#define TCLAP_DOCBOOKOUTPUT_H
75 static std::string
escapeXml(
const std::string &text) {
77 for (std::string::const_iterator it = text.begin(); it != text.end(); ++it) {
79 case '&': result +=
"&";
break;
80 case '<': result +=
"<";
break;
81 case '>': result +=
">";
break;
82 case '\"': result +=
""";
break;
83 case '\'': result +=
"'";
break;
84 default: result += *it;
break;
91 const std::string
id = arg.
shortID();
92 const std::string label = arg.
getFlag().empty()
95 const std::string::size_type labelStart =
id.find(label);
96 if (labelStart != std::string::npos) {
97 const std::string::size_type open = labelStart + label.size() + 1;
98 const std::string::size_type close =
id.rfind(
'>');
99 if (open <
id.size() &&
id[open] ==
'<' &&
100 close != std::string::npos && close > open)
101 return id.substr(open + 1, close - open - 1);
136 const std::vector< std::vector<Arg*> > xorList = xorHandler.
getXorList();
139 std::cout <<
"<?xml version='1.0'?>" << std::endl;
140 std::cout <<
"<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
141 std::cout <<
"\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
143 std::cout <<
"<refentry>" << std::endl;
145 std::cout <<
"<refmeta>" << std::endl;
146 std::cout <<
"<refentrytitle>" <<
escapeXml(progName) <<
"</refentrytitle>" << std::endl;
147 std::cout <<
"<manvolnum>1</manvolnum>" << std::endl;
148 std::cout <<
"</refmeta>" << std::endl;
150 std::cout <<
"<refnamediv>" << std::endl;
151 std::cout <<
"<refname>" <<
escapeXml(progName) <<
"</refname>" << std::endl;
152 std::cout <<
"<refpurpose>" <<
escapeXml(_cmd.
getMessage()) <<
"</refpurpose>" << std::endl;
153 std::cout <<
"</refnamediv>" << std::endl;
155 std::cout <<
"<refsynopsisdiv>" << std::endl;
156 std::cout <<
"<cmdsynopsis>" << std::endl;
158 std::cout <<
"<command>" <<
escapeXml(progName) <<
"</command>" << std::endl;
162 for (
unsigned int i = 0; i < xorList.size(); ++i) {
163 bool hasOperand =
false;
165 if (!(*it)->hasLabel()) hasOperand =
true;
166 if (hasOperand)
continue;
167 std::cout <<
"<group choice='req'>" << std::endl;
170 std::cout <<
"</group>" << std::endl;
174 std::vector<bool> shown(xorList.size(),
false);
175 for (
ArgListIterator it = argList.begin(); it != argList.end(); ++it) {
178 unsigned int owner = 0;
179 for (; owner < xorList.size(); ++owner)
180 if (std::find(xorList[owner].begin(), xorList[owner].end(), arg) !=
181 xorList[owner].end())
break;
182 if (owner == xorList.size()) {
184 }
else if (!shown[owner]) {
185 std::cout <<
"<group choice='req'>" << std::endl;
187 member != xorList[owner].end(); ++member)
printShortArg(*member);
188 std::cout <<
"</group>" << std::endl;
193 std::cout <<
"</cmdsynopsis>" << std::endl;
194 std::cout <<
"</refsynopsisdiv>" << std::endl;
196 std::cout <<
"<refsect1>" << std::endl;
197 std::cout <<
"<title>Description</title>" << std::endl;
198 std::cout <<
"<para>" << std::endl;
200 std::cout <<
"</para>" << std::endl;
201 std::cout <<
"</refsect1>" << std::endl;
203 std::cout <<
"<refsect1>" << std::endl;
204 std::cout <<
"<title>Options</title>" << std::endl;
206 std::cout <<
"<variablelist>" << std::endl;
211 std::cout <<
"</variablelist>" << std::endl;
212 std::cout <<
"</refsect1>" << std::endl;
214 std::cout <<
"<refsect1>" << std::endl;
215 std::cout <<
"<title>Version</title>" << std::endl;
216 std::cout <<
"<para>" << std::endl;
217 std::cout <<
escapeXml(xversion) << std::endl;
218 std::cout <<
"</para>" << std::endl;
219 std::cout <<
"</refsect1>" << std::endl;
221 std::cout <<
"</refentry>" << std::endl;
228 static_cast<void>(_cmd);
229 std::cout << e.
what() << std::endl;
238 while ( (p = s.find_first_of(r)) != std::string::npos )
248 while ( (p = s.find_first_of(r)) != std::string::npos )
256 size_t p = s.find_last_of(
'/');
257 if ( p != std::string::npos )
267 std::string choice =
"opt";
271 std::cout <<
"<arg choice='" << choice <<
'\'';
273 std::cout <<
" rep='repeat'";
279 <<
"</replaceable></arg>" << std::endl;
291 std::cout <<
"<replaceable>" <<
escapeXml(arg) <<
"</replaceable>";
293 std::cout <<
"</arg>" << std::endl;
304 std::cout <<
"<varlistentry>" << std::endl;
307 <<
"</replaceable></term>\n<listitem><para>"
308 <<
escapeXml(desc) <<
"</para></listitem>\n</varlistentry>"
315 std::cout <<
"<term>" << std::endl;
316 std::cout <<
"<option>";
318 std::cout <<
"</option>" << std::endl;
319 std::cout <<
"</term>" << std::endl;
322 std::cout <<
"<term>" << std::endl;
323 std::cout <<
"<option>";
329 std::cout <<
"<replaceable>" <<
escapeXml(arg) <<
"</replaceable>";
331 std::cout <<
"</option>" << std::endl;
332 std::cout <<
"</term>" << std::endl;
334 std::cout <<
"<listitem>" << std::endl;
335 std::cout <<
"<para>" << std::endl;
336 std::cout <<
escapeXml(desc) << std::endl;
337 std::cout <<
"</para>" << std::endl;
338 std::cout <<
"</listitem>" << std::endl;
340 std::cout <<
"</varlistentry>" << std::endl;
A simple class that defines and argument exception.
const char * what() const
Returns the arg id and error text.
A virtual base class that defines the essential data for all arguments.
static const std::string nameStartString()
const std::string & getFlag() const
Returns the argument flag.
bool isValueRequired() const
Indicates whether a value must be specified for argument.
static char flagStartChar()
const std::string & getName() const
Returns the argument name.
std::string getDescription() const
Returns the argument description.
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
virtual bool hasLabel() const
Whether this argument has an option label rather than being an operand.
virtual bool isRequired() const
Indicates whether the argument is required.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
static const std::string flagStartString()
The base class that manages the command line definition and passes along the parsing to the appropria...
virtual XorHandler & getXorHandler()=0
Returns the XorHandler.
virtual std::list< Arg * > & getArgList()=0
Returns the argList.
virtual std::string & getProgramName()=0
Returns the program name string.
virtual char getDelimiter()=0
Returns the delimiter string.
virtual std::string & getVersion()=0
Returns the version string.
virtual std::string & getMessage()=0
Returns the message string.
The interface that any output object must implement.
A class that generates DocBook output for usage() method for the given CmdLine and its Args.
static std::string valueLabel(const Arg &arg)
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
static std::string escapeXml(const std::string &text)
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior.
void substituteSpecialChars(std::string &s, char r, std::string &x)
Substitutes the char r for string x in string s.
void basename(std::string &s)
void printLongArg(Arg *it)
void printShortArg(Arg *it)
void removeChar(std::string &s, char r)
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
Thrown when TCLAP thinks the program should exit.
This class handles lists of Arg's that are to be XOR'd on the command line.
bool contains(const Arg *a)
Simply checks whether the Arg is contained in one of the arg lists.
const std::vector< std::vector< Arg * > > & getXorList() const
std::vector< Arg * >::const_iterator ArgVectorIterator
Typedef of an Arg vector iterator.
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.