|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84144 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-05-05 09:44:03
Author: danieljames
Date: 2013-05-05 09:44:03 EDT (Sun, 05 May 2013)
New Revision: 84144
URL: http://svn.boost.org/trac/boost/changeset/84144
Log:
Options class to reduce parameters to parse_document.
Text files modified:
trunk/tools/quickbook/src/quickbook.cpp | 83 +++++++++++++++++++++++----------------
1 files changed, 49 insertions(+), 34 deletions(-)
Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2013-05-05 09:44:03 EDT (Sun, 05 May 2013)
@@ -111,16 +111,27 @@
}
}
+ struct parse_document_options
+ {
+ parse_document_options() :
+ indent(-1),
+ linewidth(-1),
+ pretty_print(true)
+ {}
+
+ int indent;
+ int linewidth;
+ bool pretty_print;
+ fs::path deps_out;
+ fs::path locations_out;
+ fs::path xinclude_base;
+ };
+
static int
parse_document(
fs::path const& filein_
, fs::path const& fileout_
- , fs::path const& deps_out_
- , fs::path const& locations_out_
- , fs::path const& xinclude_base_
- , int indent
- , int linewidth
- , bool pretty_print)
+ , parse_document_options const& options_)
{
string_stream buffer;
id_manager ids;
@@ -128,7 +139,7 @@
int result = 0;
try {
- quickbook::state state(filein_, xinclude_base_, buffer, ids);
+ quickbook::state state(filein_, options_.xinclude_base, buffer, ids);
set_macros(state);
if (state.error_count == 0) {
@@ -145,15 +156,15 @@
result = state.error_count ? 1 : 0;
- if (!deps_out_.empty())
+ if (!options_.deps_out.empty())
{
- fs::ofstream out(deps_out_);
+ fs::ofstream out(options_.deps_out);
state.dependencies.write_dependencies(out);
}
- if (!locations_out_.empty())
+ if (!options_.locations_out.empty())
{
- fs::ofstream out(locations_out_);
+ fs::ofstream out(options_.locations_out);
state.dependencies.write_checked_locations(out);
}
}
@@ -177,11 +188,12 @@
return 1;
}
- if (pretty_print)
+ if (options_.pretty_print)
{
try
{
- fileout << post_process(stage2, indent, linewidth);
+ fileout << post_process(stage2, options_.indent,
+ options_.linewidth);
}
catch (quickbook::post_process_failure&)
{
@@ -243,6 +255,8 @@
quickbook::detail::initialise_output();
quickbook::detail::initialise_markups();
+ // Declare the program options
+
options_description desc("Allowed options");
options_description hidden("Hidden options");
options_description all("All options");
@@ -288,10 +302,9 @@
positional_options_description p;
p.add("input-file", -1);
+ // Read option from the command line
+
variables_map vm;
- int indent = -1;
- int linewidth = -1;
- bool pretty_print = true;
#if QUICKBOOK_WIDE_PATHS
quickbook::ignore_variable(&argc);
@@ -321,6 +334,9 @@
notify(vm);
+ // Process the command line options
+
+ quickbook::parse_document_options parse_document_options;
bool expect_errors = vm.count("expect-errors");
int error_count = 0;
@@ -352,15 +368,15 @@
quickbook::ms_errors = true;
if (vm.count("no-pretty-print"))
- pretty_print = false;
+ parse_document_options.pretty_print = false;
quickbook::self_linked_headers = !vm.count("no-self-link-headers");
if (vm.count("indent"))
- indent = vm["indent"].as<int>();
+ parse_document_options.indent = vm["indent"].as<int>();
if (vm.count("linewidth"))
- linewidth = vm["linewidth"].as<int>();
+ parse_document_options.linewidth = vm["linewidth"].as<int>();
if (vm.count("debug"))
{
@@ -410,22 +426,22 @@
fs::path filein = quickbook::detail::input_to_path(
vm["input-file"].as<input_string>());
fs::path fileout;
- fs::path deps_out;
- fs::path locations_out;
bool default_output = true;
if (vm.count("output-deps"))
{
- deps_out = quickbook::detail::input_to_path(
- vm["output-deps"].as<input_string>());
+ parse_document_options.deps_out =
+ quickbook::detail::input_to_path(
+ vm["output-deps"].as<input_string>());
default_output = false;
}
if (vm.count("output-checked-locations"))
{
- locations_out = quickbook::detail::input_to_path(
- vm["output-checked-locations"].as<input_string>());
+ parse_document_options.locations_out =
+ quickbook::detail::input_to_path(
+ vm["output-checked-locations"].as<input_string>());
default_output = false;
}
@@ -440,20 +456,20 @@
fileout.replace_extension(".xml");
}
- fs::path xinclude_base;
if (vm.count("xinclude-base"))
{
- xinclude_base = quickbook::detail::input_to_path(
- vm["xinclude-base"].as<input_string>());
+ parse_document_options.xinclude_base =
+ quickbook::detail::input_to_path(
+ vm["xinclude-base"].as<input_string>());
}
else
{
- xinclude_base = fileout.parent_path();
- if (xinclude_base.empty())
- xinclude_base = ".";
+ parse_document_options.xinclude_base = fileout.parent_path();
+ if (parse_document_options.xinclude_base.empty())
+ parse_document_options.xinclude_base = ".";
}
- if (!fs::is_directory(xinclude_base))
+ if (!fs::is_directory(parse_document_options.xinclude_base))
{
quickbook::detail::outerr()
<< (vm.count("xinclude-base") ?
@@ -480,8 +496,7 @@
if (!error_count)
error_count += quickbook::parse_document(
- filein, fileout, deps_out, locations_out,
- xinclude_base, indent, linewidth, pretty_print);
+ filein, fileout, parse_document_options);
if (expect_errors)
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk