diff --git a/src/quickbook.cpp b/src/quickbook.cpp index 31c3005..14b7a19 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -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) { @@ -279,6 +282,7 @@ 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(), "indent spaces") ("linewidth", PO_VALUE(), "line width") @@ -383,6 +387,8 @@ main(int argc, char* argv[]) if (vm.count("no-pretty-print")) parse_document_options.pretty_print = false; + parse_document_options.strict_mode = !!vm.count("strict"); + quickbook::self_linked_headers = !vm.count("no-self-linked-headers"); if (vm.count("indent")) diff --git a/src/state.cpp b/src/state.cpp index be14604..790933a 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -46,6 +46,7 @@ namespace quickbook , callout_depth(0) , dependencies() , explicit_list(false) + , strict_mode(false) , imported(false) , macro() diff --git a/src/state.hpp b/src/state.hpp index e427190..c4efb73 100644 --- a/src/state.hpp +++ b/src/state.hpp @@ -56,6 +56,7 @@ namespace quickbook int callout_depth; // they don't nest. dependency_tracker dependencies; bool explicit_list; // set when using a list + bool strict_mode; // state saved for files and templates. bool imported; diff --git a/test/src/text_diff.cpp b/test/src/text_diff.cpp index bcac672..1617f9c 100644 --- a/test/src/text_diff.cpp +++ b/test/src/text_diff.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -20,17 +22,37 @@ typedef spirit::scanner scanner; int main(int argc, char * argv[]) { - if (argc != 3) + std::vector args; + bool usage_error = false; + + for (int i = 1; i < argc; ++i) { + if (std::strncmp(argv[i], "--", 2) == 0) { + if (strcmp(argv[i], "--strict") == 0) { + // Ignore --strict because the build file accidentally + // uses it. Why yes, this is a horrible hack. + } else { + std::cerr << "ERROR: Invalid flag: " << argv[i] << std::endl; + usage_error = true; + } + } else { + args.push_back(argv[i]); + } + } + + if (!usage_error && args.size() != 2) { std::cerr << "ERROR: Wrong number of arguments." << std::endl; - std::cout << "Usage:\n\t" << argv[0] << " file1 file2" << std::endl; + usage_error = true; + } + if (usage_error) { + std::cout << "Usage:\n\t" << argv[0] << " file1 file2" << std::endl; return 1; } std::ifstream - file1(argv[1], std::ios_base::binary | std::ios_base::in), - file2(argv[2], std::ios_base::binary | std::ios_base::in); + file1(args[0], std::ios_base::binary | std::ios_base::in), + file2(args[1], std::ios_base::binary | std::ios_base::in); if (!file1 || !file2) {