]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/tools/quickbook/src/quickbook.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / tools / quickbook / src / quickbook.cpp
index 11a7c704f809682755c2e697eac638d1d080a5e9..7c6c3b45cc7d6e29941c3275f76b2ac738b8f15f 100644 (file)
@@ -7,30 +7,30 @@
     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     http://www.boost.org/LICENSE_1_0.txt)
 =============================================================================*/
-#include "grammar.hpp"
 #include "quickbook.hpp"
-#include "state.hpp"
-#include "actions.hpp"
-#include "post_process.hpp"
-#include "utils.hpp"
-#include "files.hpp"
-#include "stream.hpp"
-#include "path.hpp"
-#include "document_state.hpp"
-#include <boost/program_options.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
 #include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/foreach.hpp>
+#include <boost/program_options.hpp>
 #include <boost/range/algorithm.hpp>
 #include <boost/ref.hpp>
 #include <boost/version.hpp>
-#include <boost/foreach.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string/classification.hpp>
+#include "actions.hpp"
+#include "document_state.hpp"
+#include "files.hpp"
+#include "grammar.hpp"
+#include "path.hpp"
+#include "post_process.hpp"
+#include "state.hpp"
+#include "stream.hpp"
+#include "utils.hpp"
 
+#include <iterator>
 #include <stdexcept>
 #include <vector>
-#include <iterator>
 
 #if defined(_WIN32)
 #include <windows.h>
 #endif
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
-#pragma warning(disable:4355)
+#pragma warning(disable : 4355)
 #endif
 
-#define QUICKBOOK_VERSION "Quickbook Version 1.7.0"
+#define QUICKBOOK_VERSION "Quickbook Version 1.7.1"
 
 namespace quickbook
 {
     namespace cl = boost::spirit::classic;
     namespace fs = boost::filesystem;
 
-    tm* current_time; // the current time
+    tm* current_time;    // the current time
     tm* current_gm_time; // the current UTC time
-    bool debug_mode; // for quickbook developers only
+    bool debug_mode;     // for quickbook developers only
     bool self_linked_headers;
     std::vector<fs::path> include_path;
     std::vector<std::string> preset_defines;
@@ -58,11 +58,10 @@ namespace quickbook
 
     static void set_macros(quickbook::state& state)
     {
-        for(std::vector<std::string>::const_iterator
-                it = preset_defines.begin(),
-                end = preset_defines.end();
-                it != end; ++it)
-        {
+        for (std::vector<std::string>::const_iterator
+                 it = preset_defines.begin(),
+                 end = preset_defines.end();
+             it != end; ++it) {
             quickbook::string_view val(*it);
             parse_iterator first(val.begin());
             parse_iterator last(val.end());
@@ -71,11 +70,8 @@ namespace quickbook
                 cl::parse(first, last, state.grammar().command_line_macro);
 
             if (!info.full) {
-                detail::outerr()
-                    << "Error parsing command line definition: '"
-                    << *it
-                    << "'"
-                    << std::endl;
+                detail::outerr() << "Error parsing command line definition: '"
+                                 << *it << "'" << std::endl;
                 ++state.error_count;
             }
         }
@@ -86,25 +82,29 @@ namespace quickbook
     //  Parse a file
     //
     ///////////////////////////////////////////////////////////////////////////
-    void parse_file(quickbook::state& state, value include_doc_id, bool nested_file)
+    void parse_file(
+        quickbook::state& state, value include_doc_id, bool nested_file)
     {
         parse_iterator first(state.current_file->source().begin());
         parse_iterator last(state.current_file->source().end());
 
-        cl::parse_info<parse_iterator> info = cl::parse(first, last, state.grammar().doc_info);
+        cl::parse_info<parse_iterator> info =
+            cl::parse(first, last, state.grammar().doc_info);
         assert(info.hit);
 
-        if (!state.error_count)
-        {
-            std::string doc_type = pre(state, info.stop, include_doc_id, nested_file);
+        if (!state.error_count) {
+            std::string doc_type =
+                pre(state, info.stop, include_doc_id, nested_file);
 
-            info = cl::parse(info.hit ? info.stop : first, last, state.grammar().block_start);
+            info = cl::parse(
+                info.hit ? info.stop : first, last,
+                state.grammar().block_start);
 
             post(state, doc_type);
 
-            if (!info.full)
-            {
-                file_position const& pos = state.current_file->position_of(info.stop.base());
+            if (!info.full) {
+                file_position const& pos =
+                    state.current_file->position_of(info.stop.base());
                 detail::outerr(state.current_file->path, pos.line)
                     << "Syntax Error near column " << pos.column << ".\n";
                 ++state.error_count;
@@ -114,13 +114,14 @@ namespace quickbook
 
     struct parse_document_options
     {
-        parse_document_options() :
-            indent(-1),
-            linewidth(-1),
-            pretty_print(true),
-            strict_mode(false),
-            deps_out_flags(quickbook::dependency_tracker::default_)
-        {}
+        parse_document_options()
+            : indent(-1)
+            , linewidth(-1)
+            , pretty_print(true)
+            , strict_mode(false)
+            , deps_out_flags(quickbook::dependency_tracker::default_)
+        {
+        }
 
         int indent;
         int linewidth;
@@ -132,11 +133,10 @@ namespace quickbook
         fs::path xinclude_base;
     };
 
-    static int
-    parse_document(
-        fs::path const& filein_
-      , fs::path const& fileout_
-      , parse_document_options const& options_)
+    static int parse_document(
+        fs::path const& filein_,
+        fs::path const& fileout_,
+        parse_document_options const& options_)
     {
         string_stream buffer;
         document_state output;
@@ -144,7 +144,8 @@ namespace quickbook
         int result = 0;
 
         try {
-            quickbook::state state(filein_, options_.xinclude_base, buffer, output);
+            quickbook::state state(
+                filein_, options_.xinclude_base, buffer, output);
             state.strict_mode = options_.strict_mode;
             set_macros(state);
 
@@ -154,7 +155,7 @@ namespace quickbook
 
                 parse_file(state);
 
-                if(state.error_count) {
+                if (state.error_count) {
                     detail::outerr()
                         << "Error count: " << state.error_count << ".\n";
                 }
@@ -162,70 +163,55 @@ namespace quickbook
 
             result = state.error_count ? 1 : 0;
 
-            if (!options_.deps_out.empty())
-            {
-                state.dependencies.write_dependencies(options_.deps_out,
-                        options_.deps_out_flags);
+            if (!options_.deps_out.empty()) {
+                state.dependencies.write_dependencies(
+                    options_.deps_out, options_.deps_out_flags);
             }
 
-            if (!options_.locations_out.empty())
-            {
+            if (!options_.locations_out.empty()) {
                 fs::ofstream out(options_.locations_out);
-                state.dependencies.write_dependencies(options_.locations_out,
-                        dependency_tracker::checked);
+                state.dependencies.write_dependencies(
+                    options_.locations_out, dependency_tracker::checked);
             }
-        }
-        catch (load_error& e) {
+        } catch (load_error& e) {
             detail::outerr(filein_) << e.what() << std::endl;
             result = 1;
-        }
-        catch (std::runtime_error& e) {
+        } catch (std::runtime_error& e) {
             detail::outerr() << e.what() << std::endl;
             result = 1;
         }
 
-        if (!fileout_.empty() && result == 0)
-        {
+        if (!fileout_.empty() && result == 0) {
             std::string stage2 = output.replace_placeholders(buffer.str());
 
             fs::ofstream fileout(fileout_);
 
             if (fileout.fail()) {
                 ::quickbook::detail::outerr()
-                    << "Error opening output file "
-                    << fileout_
-                    << std::endl;
+                    << "Error opening output file " << fileout_ << std::endl;
 
                 return 1;
             }
 
-            if (options_.pretty_print)
-            {
-                try
-                {
-                    fileout << post_process(stage2, options_.indent,
-                        options_.linewidth);
-                }
-                catch (quickbook::post_process_failure&)
-                {
+            if (options_.pretty_print) {
+                try {
+                    fileout << post_process(
+                        stage2, options_.indent, options_.linewidth);
+                } catch (quickbook::post_process_failure&) {
                     // fallback!
                     ::quickbook::detail::outerr()
-                        << "Post Processing Failed."
-                        << std::endl;
+                        << "Post Processing Failed." << std::endl;
                     fileout << stage2;
                     return 1;
                 }
             }
-            else
-            {
+            else {
                 fileout << stage2;
             }
 
             if (fileout.fail()) {
                 ::quickbook::detail::outerr()
-                    << "Error writing to output file "
-                    << fileout_
-                    << std::endl;
+                    << "Error writing to output file " << fileout_ << std::endl;
 
                 return 1;
             }
@@ -240,11 +226,9 @@ namespace quickbook
 //  Main program
 //
 ///////////////////////////////////////////////////////////////////////////
-int
-main(int argc, char* argv[])
+int main(int argc, char* argv[])
 {
-    try
-    {
+    try {
         namespace fs = boost::filesystem;
         namespace po = boost::program_options;
 
@@ -256,13 +240,14 @@ main(int argc, char* argv[])
         using boost::program_options::command_line_parser;
         using boost::program_options::notify;
         using boost::program_options::positional_options_description;
-        
+
         using namespace quickbook;
         using quickbook::detail::command_line_string;
 
-        // First thing, the filesystem should record the current working directory.
+        // First thing, the filesystem should record the current working
+        // directory.
         fs::initial_path<fs::path>();
-        
+
         // Various initialisation methods
         quickbook::detail::initialise_output();
         quickbook::detail::initialise_markups();
@@ -279,6 +264,8 @@ main(int argc, char* argv[])
 #define PO_VALUE po::value
 #endif
 
+        // clang-format off
+
         desc.add_options()
             ("help", "produce help message")
             ("version", "print version string")
@@ -316,6 +303,8 @@ main(int argc, char* argv[])
              "write the deps file in this format.")
         ;
 
+        // clang-format on
+
         all.add(desc).add(hidden);
 
         positional_options_description p;
@@ -331,9 +320,9 @@ main(int argc, char* argv[])
 
         int wide_argc;
         LPWSTR* wide_argv = CommandLineToArgvW(GetCommandLineW(), &wide_argc);
-        if (!wide_argv)
-        {
-            quickbook::detail::outerr() << "Error getting argument values." << std::endl;
+        if (!wide_argv) {
+            quickbook::detail::outerr()
+                << "Error getting argument values." << std::endl;
             return 1;
         }
 
@@ -341,14 +330,14 @@ main(int argc, char* argv[])
             wcommand_line_parser(wide_argc, wide_argv)
                 .options(all)
                 .positional(p)
-                .run(), vm);
+                .run(),
+            vm);
 
         LocalFree(wide_argv);
 #else
-        store(command_line_parser(argc, argv)
-                .options(all)
-                .positional(p)
-                .run(), vm);
+        store(
+            command_line_parser(argc, argv).options(all).positional(p).run(),
+            vm);
 #endif
 
         notify(vm);
@@ -359,8 +348,7 @@ main(int argc, char* argv[])
         bool expect_errors = vm.count("expect-errors");
         int error_count = 0;
 
-        if (vm.count("help"))
-        {
+        if (vm.count("help")) {
             std::ostringstream description_text;
             description_text << desc;
 
@@ -369,37 +357,29 @@ main(int argc, char* argv[])
             return 0;
         }
 
-        if (vm.count("version"))
-        {
+        if (vm.count("version")) {
             std::string boost_version = BOOST_LIB_VERSION;
             boost::replace(boost_version, '_', '.');
-        
-            quickbook::detail::out()
-                << QUICKBOOK_VERSION
-                << " (Boost "
-                << boost_version
-                << ")"
-                << std::endl;
+
+            quickbook::detail::out() << QUICKBOOK_VERSION << " (Boost "
+                                     << boost_version << ")" << std::endl;
             return 0;
         }
 
         quickbook::detail::set_ms_errors(vm.count("ms-errors"));
 
-        if (vm.count("no-pretty-print"))
-            options.pretty_print = false;
+        if (vm.count("no-pretty-print")) options.pretty_print = false;
 
         options.strict_mode = !!vm.count("strict");
 
         quickbook::self_linked_headers = !vm.count("no-self-linked-headers");
 
-        if (vm.count("indent"))
-            options.indent = vm["indent"].as<int>();
+        if (vm.count("indent")) options.indent = vm["indent"].as<int>();
 
         if (vm.count("linewidth"))
             options.linewidth = vm["linewidth"].as<int>();
 
-        if (vm.count("debug"))
-        {
+        if (vm.count("debug")) {
             static tm timeinfo;
             timeinfo.tm_year = 2000 - 1900;
             timeinfo.tm_mon = 12 - 1;
@@ -413,8 +393,7 @@ main(int argc, char* argv[])
             quickbook::current_gm_time = &timeinfo;
             quickbook::debug_mode = true;
         }
-        else
-        {
+        else {
             time_t t = std::time(0);
             static tm lt = *localtime(&t);
             static tm gmt = *gmtime(&t);
@@ -422,10 +401,9 @@ main(int argc, char* argv[])
             quickbook::current_gm_time = &gmt;
             quickbook::debug_mode = false;
         }
-        
+
         quickbook::include_path.clear();
-        if (vm.count("include-path"))
-        {
+        if (vm.count("include-path")) {
             boost::transform(
                 vm["include-path"].as<std::vector<command_line_string> >(),
                 std::back_inserter(quickbook::include_path),
@@ -433,57 +411,49 @@ main(int argc, char* argv[])
         }
 
         quickbook::preset_defines.clear();
-        if (vm.count("define"))
-        {
+        if (vm.count("define")) {
             boost::transform(
                 vm["define"].as<std::vector<command_line_string> >(),
                 std::back_inserter(quickbook::preset_defines),
                 quickbook::detail::command_line_to_utf8);
         }
 
-        if (vm.count("input-file"))
-        {
+        if (vm.count("input-file")) {
             fs::path filein = quickbook::detail::command_line_to_path(
                 vm["input-file"].as<command_line_string>());
             fs::path fileout;
 
             if (!fs::exists(filein)) {
                 quickbook::detail::outerr()
-                    << "file not found: "
-                    << filein
-                    << std::endl;
+                    << "file not found: " << filein << std::endl;
                 ++error_count;
             }
 
             bool default_output = true;
 
-            if (vm.count("no-output"))
-            {
+            if (vm.count("no-output")) {
                 default_output = false;
             }
 
-            if (vm.count("output-deps"))
-            {
-                options.deps_out =
-                    quickbook::detail::command_line_to_path(
-                        vm["output-deps"].as<command_line_string>());
+            if (vm.count("output-deps")) {
+                options.deps_out = quickbook::detail::command_line_to_path(
+                    vm["output-deps"].as<command_line_string>());
                 default_output = false;
             }
 
-            if (vm.count("output-deps-format"))
-            {
+            if (vm.count("output-deps-format")) {
                 std::string format_flags =
                     quickbook::detail::command_line_to_utf8(
                         vm["output-deps-format"].as<command_line_string>());
 
                 std::vector<std::string> flag_names;
-                boost::algorithm::split(flag_names, format_flags,
-                        boost::algorithm::is_any_of(", "),
-                        boost::algorithm::token_compress_on);
+                boost::algorithm::split(
+                    flag_names, format_flags, boost::algorithm::is_any_of(", "),
+                    boost::algorithm::token_compress_on);
 
                 unsigned flags = 0;
 
-                BOOST_FOREACH(std::string const& flag, flag_names) {
+                BOOST_FOREACH (std::string const& flag, flag_names) {
                     if (flag == "checked") {
                         flags |= quickbook::dependency_tracker::checked;
                     }
@@ -492,9 +462,8 @@ main(int argc, char* argv[])
                     }
                     else if (!flag.empty()) {
                         quickbook::detail::outerr()
-                            << "Unknown dependency format flag: "
-                            << flag
-                            <<std::endl;
+                            << "Unknown dependency format flag: " << flag
+                            << std::endl;
 
                         ++error_count;
                     }
@@ -504,114 +473,102 @@ main(int argc, char* argv[])
                     quickbook::dependency_tracker::flags(flags);
             }
 
-            if (vm.count("output-checked-locations"))
-            {
-                options.locations_out =
-                    quickbook::detail::command_line_to_path(
-                        vm["output-checked-locations"].as<command_line_string>());
+            if (vm.count("output-checked-locations")) {
+                options.locations_out = quickbook::detail::command_line_to_path(
+                    vm["output-checked-locations"].as<command_line_string>());
                 default_output = false;
             }
 
-            if (vm.count("output-file"))
-            {
+            if (vm.count("output-file")) {
                 fileout = quickbook::detail::command_line_to_path(
                     vm["output-file"].as<command_line_string>());
 
                 fs::path parent = fileout.parent_path();
-                if (!parent.empty() && !fs::is_directory(parent))
-                {
+                if (!parent.empty() && !fs::is_directory(parent)) {
                     quickbook::detail::outerr()
                         << "parent directory not found for output file"
                         << std::endl;
                     ++error_count;
                 }
             }
-            else if (default_output)
-            {
+            else if (default_output) {
                 fileout = filein;
                 fileout.replace_extension(".xml");
             }
 
-            if (vm.count("xinclude-base"))
-            {
-                options.xinclude_base =
-                    quickbook::detail::command_line_to_path(
-                        vm["xinclude-base"].as<command_line_string>());
+            if (vm.count("xinclude-base")) {
+                options.xinclude_base = quickbook::detail::command_line_to_path(
+                    vm["xinclude-base"].as<command_line_string>());
 
                 // I'm not sure if this error check is necessary.
                 // There might be valid reasons to use a path that doesn't
                 // exist yet, or a path that just generates valid relative
                 // paths.
-                if (!fs::is_directory(options.xinclude_base))
-                {
+                if (!fs::is_directory(options.xinclude_base)) {
                     quickbook::detail::outerr()
-                        << "xinclude-base is not a directory"
-                        << std::endl;
+                        << "xinclude-base is not a directory" << std::endl;
                     ++error_count;
                 }
             }
-            else
-            {
+            else {
                 options.xinclude_base = fileout.parent_path();
                 if (options.xinclude_base.empty()) {
                     options.xinclude_base = ".";
                 }
 
-                // If fileout was implicitly created from filein, then it should be in filein's directory.
-                // If fileout was explicitly specified, then it's already been checked.
+                // If fileout was implicitly created from filein, then it should
+                // be in filein's directory.
+                // If fileout was explicitly specified, then it's already been
+                // checked.
                 assert(error_count || fs::is_directory(options.xinclude_base));
             }
 
-            if (vm.count("image-location"))
-            {
-                quickbook::image_location = quickbook::detail::command_line_to_path(
-                    vm["image-location"].as<command_line_string>());
+            if (vm.count("image-location")) {
+                quickbook::image_location =
+                    quickbook::detail::command_line_to_path(
+                        vm["image-location"].as<command_line_string>());
             }
-            else
-            {
+            else {
                 quickbook::image_location = filein.parent_path() / "html";
             }
 
             if (!error_count) {
                 if (!fileout.empty()) {
-                    quickbook::detail::out() << "Generating Output File: "
-                        << fileout
-                        << std::endl;
+                    quickbook::detail::out()
+                        << "Generating Output File: " << fileout << std::endl;
                 }
 
-                error_count += quickbook::parse_document(
-                        filein, fileout, options);
+                error_count +=
+                    quickbook::parse_document(filein, fileout, options);
             }
 
-            if (expect_errors)
-            {
-                if (!error_count) quickbook::detail::outerr() << "No errors detected for --expect-errors." << std::endl;
+            if (expect_errors) {
+                if (!error_count)
+                    quickbook::detail::outerr()
+                        << "No errors detected for --expect-errors."
+                        << std::endl;
                 return !error_count;
             }
-            else
-            {
+            else {
                 return error_count;
             }
         }
-        else
-        {
+        else {
             std::ostringstream description_text;
             description_text << desc;
-        
+
             quickbook::detail::outerr() << "No filename given\n\n"
-                << description_text.str() << std::endl;
+                                        << description_text.str() << std::endl;
             return 1;
-        }        
+        }
     }
 
-    catch(std::exception& e)
-    {
+    catch (std::exception& e) {
         quickbook::detail::outerr() << e.what() << "\n";
         return 1;
     }
 
-    catch(...)
-    {
+    catch (...) {
         quickbook::detail::outerr() << "Exception of unknown type caught\n";
         return 1;
     }