#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>
#pragma warning(disable:4355)
#endif
-#define QUICKBOOK_VERSION "Quickbook Version 1.6.2"
+#define QUICKBOOK_VERSION "Quickbook Version 1.7.0"
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());
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);
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;
try {
quickbook::state state(filein_, options_.xinclude_base, buffer, output);
+ state.strict_mode = options_.strict_mode;
set_macros(state);
if (state.error_count == 0) {
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.
("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")
;
hidden.add_options()
+ ("debug", "debug mode")
("expect-errors",
"Succeed if the input file contains a correctly handled "
"error, fail otherwise.")
// 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;
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"))
{
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;
}
}
- 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;
{
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)
{
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"))
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)
{