From 5a01a260c368d3045f0870cc09620a772027e911 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Jan 2016 12:50:12 +0200 Subject: Initial support for plain text documentation (--generate-txt) Support for option documentation generation is still a TODO. --- cli/generator.cxx | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'cli/generator.cxx') diff --git a/cli/generator.cxx b/cli/generator.cxx index b086089..486c793 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -23,6 +23,7 @@ #include "man.hxx" #include "html.hxx" +#include "txt.hxx" #include "context.hxx" #include "generator.hxx" @@ -122,8 +123,9 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) bool gen_cxx (ops.generate_cxx ()); bool gen_man (ops.generate_man ()); bool gen_html (ops.generate_html ()); + bool gen_txt (ops.generate_txt ()); - if (!gen_cxx && !gen_man && !gen_html) + if (!gen_cxx && !gen_man && !gen_html && !gen_txt) gen_cxx = true; if (ops.stdout_ ()) @@ -134,9 +136,11 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) throw failed (); } - if (gen_man && gen_html) + if ((gen_man && gen_html) || + (gen_man && gen_txt) || + (gen_html && gen_txt)) { - cerr << "error: --stdout cannot be used with man and html output" + cerr << "error: --stdout cannot only be used with one output format" << endl; throw failed (); } @@ -463,6 +467,43 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) append (os, ops.html_epilogue (), ops.html_epilogue_file (), unit); } + // txt output + // + if (gen_txt) + { + ofstream txt; + + if (!ops.stdout_ ()) + { + path txt_path (pfx + base + sfx + ops.txt_suffix ()); + + if (!ops.output_dir ().empty ()) + txt_path = path (ops.output_dir ()) / txt_path; + + txt.open (txt_path.string ().c_str ()); + + if (!txt.is_open ()) + { + cerr << "error: unable to open '" << txt_path << "' in write mode" + << endl; + throw failed (); + } + + auto_rm.add (txt_path); + } + + // The explicit cast helps VC++ 8.0 overcome its issues. + // + ostream& os (ops.stdout_ () ? cout : static_cast (txt)); + + append (os, ops.txt_prologue (), ops.txt_prologue_file (), unit); + + context ctx (os, unit, ops); + generate_txt (ctx); + + append (os, ops.txt_epilogue (), ops.txt_epilogue_file (), unit); + } + auto_rm.cancel (); } catch (const generation_failed&) -- cgit v1.1