]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/tools/quickbook/src/quickbook.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / quickbook.cpp
index 3447a4663b1edfba36b58d457e2ac41323590f06..11a7c704f809682755c2e697eac638d1d080a5e9 100644 (file)
@@ -14,7 +14,8 @@
 #include "post_process.hpp"
 #include "utils.hpp"
 #include "files.hpp"
-#include "native_text.hpp"
+#include "stream.hpp"
+#include "path.hpp"
 #include "document_state.hpp"
 #include <boost/program_options.hpp>
 #include <boost/filesystem/path.hpp>
@@ -40,7 +41,7 @@
 #pragma warning(disable:4355)
 #endif
 
-#define QUICKBOOK_VERSION "Quickbook Version 1.6.2"
+#define QUICKBOOK_VERSION "Quickbook Version 1.7.0"
 
 namespace quickbook
 {
@@ -62,7 +63,7 @@ namespace quickbook
                 end = preset_defines.end();
                 it != end; ++it)
         {
-            boost::string_ref val(*it);
+            quickbook::string_view val(*it);
             parse_iterator first(val.begin());
             parse_iterator last(val.end());
 
@@ -95,8 +96,7 @@ namespace quickbook
 
         if (!state.error_count)
         {
-            parse_iterator pos = info.stop;
-            std::string doc_type = pre(state, pos, include_doc_id, nested_file);
+            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);
 
@@ -118,12 +118,14 @@ namespace quickbook
             indent(-1),
             linewidth(-1),
             pretty_print(true),
+            strict_mode(false),
             deps_out_flags(quickbook::dependency_tracker::default_)
         {}
 
         int indent;
         int linewidth;
         bool pretty_print;
+        bool strict_mode;
         fs::path deps_out;
         quickbook::dependency_tracker::flags deps_out_flags;
         fs::path locations_out;
@@ -143,6 +145,7 @@ namespace quickbook
 
         try {
             quickbook::state state(filein_, options_.xinclude_base, buffer, output);
+            state.strict_mode = options_.strict_mode;
             set_macros(state);
 
             if (state.error_count == 0) {
@@ -254,6 +257,7 @@ main(int argc, char* argv[])
         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.
@@ -279,13 +283,14 @@ main(int argc, char* argv[])
             ("help", "produce help message")
             ("version", "print version string")
             ("no-pretty-print", "disable XML pretty printing")
+            ("strict", "strict mode")
             ("no-self-linked-headers", "stop headers linking to themselves")
             ("indent", PO_VALUE<int>(), "indent spaces")
             ("linewidth", PO_VALUE<int>(), "line width")
             ("input-file", PO_VALUE<command_line_string>(), "input file")
             ("output-file", PO_VALUE<command_line_string>(), "output file")
+            ("no-output", "don't write out the result (overriden by --output-file)")
             ("output-deps", PO_VALUE<command_line_string>(), "output dependency file")
-            ("debug", "debug mode (for developers)")
             ("ms-errors", "use Microsoft Visual Studio style error & warn message format")
             ("include-path,I", PO_VALUE< std::vector<command_line_string> >(), "include path")
             ("define,D", PO_VALUE< std::vector<command_line_string> >(), "define macro")
@@ -293,6 +298,7 @@ main(int argc, char* argv[])
         ;
 
         hidden.add_options()
+            ("debug", "debug mode")
             ("expect-errors",
                 "Succeed if the input file contains a correctly handled "
                 "error, fail otherwise.")
@@ -349,7 +355,7 @@ main(int argc, char* argv[])
 
         // Process the command line options
 
-        quickbook::parse_document_options parse_document_options;
+        parse_document_options options;
         bool expect_errors = vm.count("expect-errors");
         int error_count = 0;
 
@@ -380,15 +386,17 @@ main(int argc, char* argv[])
         quickbook::detail::set_ms_errors(vm.count("ms-errors"));
 
         if (vm.count("no-pretty-print"))
-            parse_document_options.pretty_print = false;
+            options.pretty_print = false;
 
-        quickbook::self_linked_headers = !vm.count("no-self-link-headers");
+        options.strict_mode = !!vm.count("strict");
+
+        quickbook::self_linked_headers = !vm.count("no-self-linked-headers");
 
         if (vm.count("indent"))
-            parse_document_options.indent = vm["indent"].as<int>();
+            options.indent = vm["indent"].as<int>();
 
         if (vm.count("linewidth"))
-            parse_document_options.linewidth = vm["linewidth"].as<int>();
+            options.linewidth = vm["linewidth"].as<int>();
 
         if (vm.count("debug"))
         {
@@ -439,11 +447,24 @@ main(int argc, char* argv[])
                 vm["input-file"].as<command_line_string>());
             fs::path fileout;
 
+            if (!fs::exists(filein)) {
+                quickbook::detail::outerr()
+                    << "file not found: "
+                    << filein
+                    << std::endl;
+                ++error_count;
+            }
+
             bool default_output = true;
 
+            if (vm.count("no-output"))
+            {
+                default_output = false;
+            }
+
             if (vm.count("output-deps"))
             {
-                parse_document_options.deps_out =
+                options.deps_out =
                     quickbook::detail::command_line_to_path(
                         vm["output-deps"].as<command_line_string>());
                 default_output = false;
@@ -479,13 +500,13 @@ main(int argc, char* argv[])
                     }
                 }
 
-                parse_document_options.deps_out_flags =
+                options.deps_out_flags =
                     quickbook::dependency_tracker::flags(flags);
             }
 
             if (vm.count("output-checked-locations"))
             {
-                parse_document_options.locations_out =
+                options.locations_out =
                     quickbook::detail::command_line_to_path(
                         vm["output-checked-locations"].as<command_line_string>());
                 default_output = false;
@@ -495,6 +516,15 @@ main(int argc, char* argv[])
             {
                 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))
+                {
+                    quickbook::detail::outerr()
+                        << "parent directory not found for output file"
+                        << std::endl;
+                    ++error_count;
+                }
             }
             else if (default_output)
             {
@@ -504,24 +534,32 @@ main(int argc, char* argv[])
 
             if (vm.count("xinclude-base"))
             {
-                parse_document_options.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))
+                {
+                    quickbook::detail::outerr()
+                        << "xinclude-base is not a directory"
+                        << std::endl;
+                    ++error_count;
+                }
             }
             else
             {
-                parse_document_options.xinclude_base = fileout.parent_path();
-                if (parse_document_options.xinclude_base.empty())
-                    parse_document_options.xinclude_base = ".";
-            }
+                options.xinclude_base = fileout.parent_path();
+                if (options.xinclude_base.empty()) {
+                    options.xinclude_base = ".";
+                }
 
-            if (!fs::is_directory(parse_document_options.xinclude_base))
-            {
-                quickbook::detail::outerr()
-                    << (vm.count("xinclude-base") ?
-                        "xinclude-base is not a directory" :
-                        "parent directory not found for output file");
-                ++error_count;
+                // 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"))
@@ -534,15 +572,16 @@ main(int argc, char* argv[])
                 quickbook::image_location = filein.parent_path() / "html";
             }
 
-            if (!fileout.empty()) {
-                quickbook::detail::out() << "Generating Output File: "
-                    << fileout
-                    << std::endl;
-            }
+            if (!error_count) {
+                if (!fileout.empty()) {
+                    quickbook::detail::out() << "Generating Output File: "
+                        << fileout
+                        << std::endl;
+                }
 
-            if (!error_count)
                 error_count += quickbook::parse_document(
-                        filein, fileout, parse_document_options);
+                        filein, fileout, options);
+            }
 
             if (expect_errors)
             {