From 577a38358b295379511ea8bb130ef1dcb7157c0f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Nov 2009 21:28:46 +0200 Subject: Implement HTML pages generation --- cli/generator.cxx | 259 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 158 insertions(+), 101 deletions(-) (limited to 'cli/generator.cxx') diff --git a/cli/generator.cxx b/cli/generator.cxx index e0e5d4a..6043825 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -21,6 +21,8 @@ #include "runtime-inline.hxx" #include "runtime-source.hxx" +#include "html.hxx" + #include "context.hxx" #include "generator.hxx" #include "name-processor.hxx" @@ -73,156 +75,211 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) { try { - bool inl (!ops.suppress_inline ()); - path file (p.leaf ()); string base (file.base ().string ()); - string hxx_name (base + ops.hxx_suffix ()); - string ixx_name (base + ops.ixx_suffix ()); - string cxx_name (base + ops.cxx_suffix ()); + bool gen_cxx (ops.generate_cxx ()); + bool gen_man (ops.generate_man ()); + bool gen_html (ops.generate_html ()); - path hxx_path (hxx_name); - path ixx_path (ixx_name); - path cxx_path (cxx_name); + if (!gen_cxx && !gen_man && !gen_html) + gen_cxx = true; - if (!ops.output_dir ().empty ()) + if (ops.stdout ()) { - path dir (ops.output_dir ()); + if (gen_cxx) + { + cerr << "error: --stdout cannot be used with C++ output" << endl; + throw failed (); + } - hxx_path = dir / hxx_path; - ixx_path = dir / ixx_path; - cxx_path = dir / cxx_path; + if (gen_man && gen_html) + { + cerr << "error: --stdout cannot be used with man and html output" + << endl; + throw failed (); + } } - // Process names. - // + fs::auto_removes auto_rm; + + if (gen_cxx) { - context ctx (cerr, unit, ops); - process_names (ctx); - } + bool inl (!ops.suppress_inline ()); - fs::auto_removes auto_rm; + string hxx_name (base + ops.hxx_suffix ()); + string ixx_name (base + ops.ixx_suffix ()); + string cxx_name (base + ops.cxx_suffix ()); - // - // - ofstream hxx (hxx_path.string ().c_str ()); + path hxx_path (hxx_name); + path ixx_path (ixx_name); + path cxx_path (cxx_name); - if (!hxx.is_open ()) - { - cerr << "error: unable to open '" << hxx_path << "' in write mode" - << endl; - throw failed (); - } + if (!ops.output_dir ().empty ()) + { + path dir (ops.output_dir ()); - auto_rm.add (hxx_path); + hxx_path = dir / hxx_path; + ixx_path = dir / ixx_path; + cxx_path = dir / cxx_path; + } - // - // - ofstream ixx; + // Process names. + // + { + context ctx (cerr, unit, ops); + process_names (ctx); + } - if (inl) - { - ixx.open (ixx_path.string ().c_str (), ios_base::out); + // + // + ofstream hxx (hxx_path.string ().c_str ()); - if (!ixx.is_open ()) + if (!hxx.is_open ()) { - cerr << "error: unable to open '" << ixx_path << "' in write mode" + cerr << "error: unable to open '" << hxx_path << "' in write mode" << endl; throw failed (); } - auto_rm.add (ixx_path); - } + auto_rm.add (hxx_path); - // - // - ofstream cxx (cxx_path.string ().c_str ()); + // + // + ofstream ixx; - if (!cxx.is_open ()) - { - cerr << "error: unable to open '" << cxx_path << "' in write mode" - << endl; - throw failed (); - } + if (inl) + { + ixx.open (ixx_path.string ().c_str (), ios_base::out); - auto_rm.add (cxx_path); + if (!ixx.is_open ()) + { + cerr << "error: unable to open '" << ixx_path << "' in write mode" + << endl; + throw failed (); + } - // Print headers. - // - hxx << header; - if (inl) - ixx << header; - cxx << header; + auto_rm.add (ixx_path); + } - typedef compiler::ostream_filter cxx_filter; + // + // + ofstream cxx (cxx_path.string ().c_str ()); - // Include settings. - // - bool br (ops.include_with_brackets ()); - string ip (ops.include_prefix ()); - string gp (ops.guard_prefix ()); + if (!cxx.is_open ()) + { + cerr << "error: unable to open '" << cxx_path << "' in write mode" + << endl; + throw failed (); + } - if (!ip.empty () && ip[ip.size () - 1] != '/') - ip.append ("/"); + auto_rm.add (cxx_path); - if (!gp.empty () && gp[gp.size () - 1] != '_') - gp.append ("_"); + // Print headers. + // + hxx << header; + if (inl) + ixx << header; + cxx << header; - // HXX - // - { - cxx_filter filt (hxx); - context ctx (hxx, unit, ops); + typedef + compiler::ostream_filter + cxx_filter; + + // Include settings. + // + bool br (ops.include_with_brackets ()); + string ip (ops.include_prefix ()); + string gp (ops.guard_prefix ()); + + if (!ip.empty () && ip[ip.size () - 1] != '/') + ip.append ("/"); - string guard (make_guard (gp + hxx_name, ctx)); + if (!gp.empty () && gp[gp.size () - 1] != '_') + gp.append ("_"); - hxx << "#ifndef " << guard << endl - << "#define " << guard << endl - << endl; + // HXX + // + { + cxx_filter filt (hxx); + context ctx (hxx, unit, ops); + + string guard (make_guard (gp + hxx_name, ctx)); + + hxx << "#ifndef " << guard << endl + << "#define " << guard << endl + << endl; + + generate_runtime_header (ctx); + generate_header (ctx); - generate_runtime_header (ctx); - generate_header (ctx); + if (inl) + { + hxx << "#include " << (br ? '<' : '"') << ip << ixx_name << + (br ? '>' : '"') << endl + << endl; + } + hxx << "#endif // " << guard << endl; + } + + // IXX + // if (inl) { - hxx << "#include " << (br ? '<' : '"') << ip << ixx_name << + cxx_filter filt (ixx); + context ctx (ixx, unit, ops); + generate_runtime_inline (ctx); + generate_inline (ctx); + } + + // CXX + // + { + cxx_filter filt (cxx); + context ctx (cxx, unit, ops); + + cxx << "#include " << (br ? '<' : '"') << ip << hxx_name << (br ? '>' : '"') << endl << endl; - } - hxx << "#endif // " << guard << endl; - } + if (!inl) + generate_runtime_inline (ctx); - // IXX - // - if (inl) - { - cxx_filter filt (ixx); - context ctx (ixx, unit, ops); - generate_runtime_inline (ctx); - generate_inline (ctx); + generate_runtime_source (ctx); + + if (!inl) + generate_inline (ctx); + + generate_source (ctx); + } } - // CXX - // + if (gen_html) { - cxx_filter filt (cxx); - context ctx (cxx, unit, ops); + ofstream html; + + if (!ops.stdout ()) + { + path html_path (base + ops.html_suffix ()); - cxx << "#include " << (br ? '<' : '"') << ip << hxx_name << - (br ? '>' : '"') << endl - << endl; + if (!ops.output_dir ().empty ()) + html_path = path (ops.output_dir ()) / html_path; - if (!inl) - generate_runtime_inline (ctx); + html.open (html_path.string ().c_str ()); - generate_runtime_source (ctx); + if (!html.is_open ()) + { + cerr << "error: unable to open '" << html_path << "' in write mode" + << endl; + throw failed (); + } - if (!inl) - generate_inline (ctx); + auto_rm.add (html_path); + } - generate_source (ctx); + context ctx (ops.stdout () ? cout : html, unit, ops); + generate_html (ctx); } auto_rm.cancel (); -- cgit v1.1