24 #ifndef TCLAP_DOCBOOKOUTPUT_H
25 #define TCLAP_DOCBOOKOUTPUT_H
44 class DocBookOutput :
public CmdLineOutput
54 virtual void usage(CmdLineInterface& c);
61 virtual void version(CmdLineInterface& c);
69 virtual void failure(CmdLineInterface& c,
94 std::cout << _cmd.getVersion() << std::endl;
99 std::list<Arg*> argList = _cmd.getArgList();
100 std::string progName = _cmd.getProgramName();
101 std::string xversion = _cmd.getVersion();
103 XorHandler xorHandler = _cmd.getXorHandler();
104 const std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
107 std::cout <<
"<?xml version='1.0'?>" << std::endl;
108 std::cout <<
"<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
109 std::cout <<
"\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
111 std::cout <<
"<refentry>" << std::endl;
113 std::cout <<
"<refmeta>" << std::endl;
114 std::cout <<
"<refentrytitle>" << progName <<
"</refentrytitle>" << std::endl;
115 std::cout <<
"<manvolnum>1</manvolnum>" << std::endl;
116 std::cout <<
"</refmeta>" << std::endl;
118 std::cout <<
"<refnamediv>" << std::endl;
119 std::cout <<
"<refname>" << progName <<
"</refname>" << std::endl;
120 std::cout <<
"<refpurpose>" << _cmd.getMessage() <<
"</refpurpose>" << std::endl;
121 std::cout <<
"</refnamediv>" << std::endl;
123 std::cout <<
"<refsynopsisdiv>" << std::endl;
124 std::cout <<
"<cmdsynopsis>" << std::endl;
126 std::cout <<
"<command>" << progName <<
"</command>" << std::endl;
129 for (
int i = 0; (
unsigned int)i < xorList.size(); i++ )
131 std::cout <<
"<group choice='req'>" << std::endl;
133 it != xorList[i].end(); it++ )
136 std::cout <<
"</group>" << std::endl;
141 if ( !xorHandler.contains( (*it) ) )
144 std::cout <<
"</cmdsynopsis>" << std::endl;
145 std::cout <<
"</refsynopsisdiv>" << std::endl;
147 std::cout <<
"<refsect1>" << std::endl;
148 std::cout <<
"<title>Description</title>" << std::endl;
149 std::cout <<
"<para>" << std::endl;
150 std::cout << _cmd.getMessage() << std::endl;
151 std::cout <<
"</para>" << std::endl;
152 std::cout <<
"</refsect1>" << std::endl;
154 std::cout <<
"<refsect1>" << std::endl;
155 std::cout <<
"<title>Options</title>" << std::endl;
157 std::cout <<
"<variablelist>" << std::endl;
162 std::cout <<
"</variablelist>" << std::endl;
163 std::cout <<
"</refsect1>" << std::endl;
165 std::cout <<
"<refsect1>" << std::endl;
166 std::cout <<
"<title>Version</title>" << std::endl;
167 std::cout <<
"<para>" << std::endl;
168 std::cout << xversion << std::endl;
169 std::cout <<
"</para>" << std::endl;
170 std::cout <<
"</refsect1>" << std::endl;
172 std::cout <<
"</refentry>" << std::endl;
179 static_cast<void>(_cmd);
180 std::cout << e.what() << std::endl;
181 throw ExitException(1);
189 while ( (p = s.find_first_of(r)) != std::string::npos )
199 while ( (p = s.find_first_of(r)) != std::string::npos )
207 size_t p = s.find_last_of(
'/');
208 if ( p != std::string::npos )
216 std::string lt =
"<";
217 std::string gt =
">";
219 std::string
id = a->shortID();
225 std::string choice =
"opt";
226 if ( a->isRequired() )
229 std::cout <<
"<arg choice='" << choice <<
'\'';
230 if ( a->acceptsMultipleValues() )
231 std::cout <<
" rep='repeat'";
235 if ( !a->getFlag().empty() )
236 std::cout << a->flagStartChar() << a->getFlag();
238 std::cout << a->nameStartString() << a->getName();
239 if ( a->isValueRequired() )
241 std::string arg = a->shortID();
247 arg.erase(0, arg.find_last_of(theDelimiter) + 1);
248 std::cout << theDelimiter;
249 std::cout << "<replaceable>" << arg << "</replaceable>";
251 std::cout << "</arg>" << std::endl;
255 inline void DocBookOutput::printLongArg(Arg* a)
257 std::string lt = "<";
258 std::string gt = ">";
260 std::string desc = a->getDescription();
261 substituteSpecialChars(desc,'<
',lt);
262 substituteSpecialChars(desc,'>
',gt);
264 std::cout << "<varlistentry>" << std::endl;
266 if ( !a->getFlag().empty() )
268 std::cout << "<term>" << std::endl;
269 std::cout << "<option>";
270 std::cout << a->flagStartChar() << a->getFlag();
271 std::cout << "</option>" << std::endl;
272 std::cout << "</term>" << std::endl;
275 std::cout << "<term>" << std::endl;
276 std::cout << "<option>";
277 std::cout << a->nameStartString() << a->getName();
278 if ( a->isValueRequired() )
280 std::string arg = a->shortID();
286 arg.erase(0, arg.find_last_of(theDelimiter) + 1);
287 std::cout << theDelimiter;
288 std::cout << "<replaceable>" << arg << "</replaceable>";
290 std::cout << "</option>" << std::endl;
291 std::cout << "</term>" << std::endl;
293 std::cout << "<listitem>" << std::endl;
294 std::cout << "<para>" << std::endl;
295 std::cout << desc << std::endl;
296 std::cout << "</para>" << std::endl;
297 std::cout << "</listitem>" << std::endl;
299 std::cout << "</varlistentry>" << std::endl;