From 471556a19e68b372155095c1b11aa568735fe867 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Feb 2016 04:25:00 +0200 Subject: First part of TOC generation support (no links yet) Currently only supported in the HTML output. --- cli/generator.cxx | 101 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 31 deletions(-) (limited to 'cli/generator.cxx') diff --git a/cli/generator.cxx b/cli/generator.cxx index 5964c25..cbb3ec7 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -80,14 +80,32 @@ namespace } void - append (ostream& os, - vector const& text, - string const& file, - semantics::cli_unit& u) + append (context& ctx, string const& s, const path* d = 0) + { + // Detect the switch to/from TOC mode. + // + unsigned short t (ctx.toc); + string const& r (ctx.substitute (s, d)); + + if (t != ctx.toc) + { + if (!r.empty ()) // TOC prologue/epilogue (returned by start/end_toc()). + ctx.os << r << endl; + } + // Skip it if we are in the TOC mode. + // + else if (!t) + ctx.os << r << endl; + } + + void + append (context& ctx, vector const& text, string const& file) { for (vector::const_iterator i (text.begin ()); i != text.end (); ++i) - os << context::substitute (*i, u) << endl; + { + append (ctx, *i); + } if (!file.empty ()) { @@ -101,7 +119,7 @@ namespace // the delimiter. // for (string s; getline (ifs, s); ) - os << context::substitute (s, u, &d) << endl; + append (ctx, s, &d); } } } @@ -176,7 +194,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // Process names. // { - context ctx (cerr, unit, ops); + context ctx (cerr, context::ot_plain, unit, ops); process_names (ctx); } @@ -265,7 +283,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // HXX // { - context ctx (hxx, unit, ops); + context ctx (hxx, context::ot_plain, unit, ops); string guard (make_guard (gp + hxx_name, ctx)); @@ -277,7 +295,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // hxx << "// Begin prologue." << endl << "//" << endl; - append (hxx, ops.hxx_prologue (), ops.hxx_prologue_file (), unit); + append (ctx, ops.hxx_prologue (), ops.hxx_prologue_file ()); hxx << "//" << endl << "// End prologue." << endl << endl; @@ -304,7 +322,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // hxx << "// Begin epilogue." << endl << "//" << endl; - append (hxx, ops.hxx_epilogue (), ops.hxx_epilogue_file (), unit); + append (ctx, ops.hxx_epilogue (), ops.hxx_epilogue_file ()); hxx << "//" << endl << "// End epilogue." << endl << endl; @@ -316,13 +334,13 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // if (inl) { - context ctx (ixx, unit, ops); + context ctx (ixx, context::ot_plain, unit, ops); // Copy prologue. // ixx << "// Begin prologue." << endl << "//" << endl; - append (ixx, ops.ixx_prologue (), ops.ixx_prologue_file (), unit); + append (ctx, ops.ixx_prologue (), ops.ixx_prologue_file ()); ixx << "//" << endl << "// End prologue." << endl << endl; @@ -342,7 +360,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // ixx << "// Begin epilogue." << endl << "//" << endl; - append (ixx, ops.ixx_epilogue (), ops.ixx_epilogue_file (), unit); + append (ctx, ops.ixx_epilogue (), ops.ixx_epilogue_file ()); ixx << "//" << endl << "// End epilogue." << endl; } @@ -350,13 +368,13 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // CXX // { - context ctx (cxx, unit, ops); + context ctx (cxx, context::ot_plain, unit, ops); // Copy prologue. // cxx << "// Begin prologue." << endl << "//" << endl; - append (cxx, ops.cxx_prologue (), ops.cxx_prologue_file (), unit); + append (ctx, ops.cxx_prologue (), ops.cxx_prologue_file ()); cxx << "//" << endl << "// End prologue." << endl << endl; @@ -385,7 +403,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // cxx << "// Begin epilogue." << endl << "//" << endl; - append (cxx, ops.cxx_epilogue (), ops.cxx_epilogue_file (), unit); + append (ctx, ops.cxx_epilogue (), ops.cxx_epilogue_file ()); cxx << "//" << endl << "// End epilogue." << endl << endl; @@ -420,13 +438,20 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // The explicit cast helps VC++ 8.0 overcome its issues. // ostream& os (ops.stdout_ () ? cout : static_cast (man)); + context ctx (os, context::ot_man, unit, ops); - append (os, ops.man_prologue (), ops.man_prologue_file (), unit); - - context ctx (os, unit, ops); - generate_man (ctx); + for (bool first (true); first || ctx.toc; first = false) + { + append (ctx, ops.man_prologue (), ops.man_prologue_file ()); + generate_man (ctx); + append (ctx, ops.man_epilogue (), ops.man_epilogue_file ()); - append (os, ops.man_epilogue (), ops.man_epilogue_file (), unit); + if (ctx.toc) + { + assert (first); // Second run should end in non-TOC mode. + ctx.toc++; // TOC phase after restart. + } + } } // HTML output @@ -460,13 +485,20 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // The explicit cast helps VC++ 8.0 overcome its issues. // ostream& os (ops.stdout_ () ? cout : static_cast (html)); + context ctx (os, context::ot_html, unit, ops); - append (os, ops.html_prologue (), ops.html_prologue_file (), unit); - - context ctx (os, unit, ops); - generate_html (ctx); + for (bool first (true); first || ctx.toc; first = false) + { + append (ctx, ops.html_prologue (), ops.html_prologue_file ()); + generate_html (ctx); + append (ctx, ops.html_epilogue (), ops.html_epilogue_file ()); - append (os, ops.html_epilogue (), ops.html_epilogue_file (), unit); + if (ctx.toc) + { + assert (first); // Second run should end in non-TOC mode. + ctx.toc++; // TOC phase after restart. + } + } } // txt output @@ -497,13 +529,20 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) // The explicit cast helps VC++ 8.0 overcome its issues. // ostream& os (ops.stdout_ () ? cout : static_cast (txt)); + context ctx (os, context::ot_plain, unit, ops); - append (os, ops.txt_prologue (), ops.txt_prologue_file (), unit); - - context ctx (os, unit, ops); - generate_txt (ctx); + for (bool first (true); first || ctx.toc; first = false) + { + append (ctx, ops.txt_prologue (), ops.txt_prologue_file ()); + generate_txt (ctx); + append (ctx, ops.txt_epilogue (), ops.txt_epilogue_file ()); - append (os, ops.txt_epilogue (), ops.txt_epilogue_file (), unit); + if (ctx.toc) + { + assert (first); // Second run should end in non-TOC mode. + ctx.toc++; // TOC phase after restart. + } + } } auto_rm.cancel (); -- cgit v1.1