Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86642 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-11-12 04:14:56


Author: danieljames
Date: 2013-11-12 04:14:56 EST (Tue, 12 Nov 2013)
New Revision: 86642
URL: http://svn.boost.org/trac/boost/changeset/86642

Log:
Pull some of the path handling code out of actions.cpp.

Added:
   trunk/tools/quickbook/src/include_paths.cpp (contents, props changed)
   trunk/tools/quickbook/src/include_paths.hpp (contents, props changed)
Text files modified:
   trunk/tools/quickbook/src/Jamfile.v2 | 1
   trunk/tools/quickbook/src/actions.cpp | 117 -------------------------------------
   trunk/tools/quickbook/src/include_paths.cpp | 124 ++++++++++++++++++++++++++++++++++++++++
   trunk/tools/quickbook/src/include_paths.hpp | 54 +++++++++++++++++
   4 files changed, 180 insertions(+), 116 deletions(-)

Modified: trunk/tools/quickbook/src/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/src/Jamfile.v2 Tue Nov 12 04:14:28 2013 (r86641)
+++ trunk/tools/quickbook/src/Jamfile.v2 2013-11-12 04:14:56 EST (Tue, 12 Nov 2013) (r86642)
@@ -31,6 +31,7 @@
     utils.cpp
     files.cpp
     input_path.cpp
+ include_paths.cpp
     values.cpp
     document_state.cpp
     id_generation.cpp

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Nov 12 04:14:28 2013 (r86641)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-12 04:14:56 EST (Tue, 12 Nov 2013) (r86642)
@@ -33,6 +33,7 @@
 #include "block_tags.hpp"
 #include "phrase_tags.hpp"
 #include "document_state.hpp"
+#include "include_paths.hpp"
 
 namespace quickbook
 {
@@ -1766,53 +1767,6 @@
         return result;
     }
 
- struct path_details {
- // Will possibly add 'url' and 'glob' to this list later:
- enum path_type { path };
-
- std::string value;
- path_type type;
-
- path_details(std::string const& value, path_type type) :
- value(value), type(type)
- {
- }
- };
-
- path_details check_path(value const& path, quickbook::state& state)
- {
- // Paths are encoded for quickbook 1.6+ and also xmlbase
- // values (technically xmlbase is a 1.6 feature, but that
- // isn't enforced as it's backwards compatible).
- //
- // Counter-intuitively: encoded == plain text here.
-
- std::string path_text = qbk_version_n >= 106u || path.is_encoded() ?
- path.get_encoded() : detail::to_s(path.get_quickbook());
-
- if(path_text.find('\\') != std::string::npos)
- {
- quickbook::detail::ostream* err;
-
- if (qbk_version_n >= 106u) {
- err = &detail::outerr(path.get_file(), path.get_position());
- ++state.error_count;
- }
- else {
- err = &detail::outwarn(path.get_file(), path.get_position());
- }
-
- *err << "Path isn't portable: '"
- << path_text
- << "'"
- << std::endl;
-
- boost::replace(path_text, '\\', '/');
- }
-
- return path_details(path_text, path_details::path);
- }
-
     xinclude_path calculate_xinclude_path(value const& p, quickbook::state& state)
     {
         path_details details = check_path(p, state);
@@ -1846,75 +1800,6 @@
         state.out << "\" />\n";
     }
 
- namespace
- {
- struct include_search_return
- {
- include_search_return(fs::path const& x, fs::path const& y)
- : filename(x), filename_relative(y) {}
-
- fs::path filename;
- fs::path filename_relative;
-
- bool operator < (include_search_return const & other) const
- {
- if (filename_relative < other.filename_relative) return true;
- else if (other.filename_relative < filename_relative) return false;
- else return filename < other.filename;
- }
- };
-
- std::set<include_search_return> include_search(path_details const& details,
- quickbook::state& state, string_iterator pos)
- {
- std::set<include_search_return> result;
-
- fs::path path = detail::generic_to_path(details.value);
-
- // If the path is relative, try and resolve it.
- if (!path.has_root_directory() && !path.has_root_name())
- {
- fs::path local_path =
- state.current_file->path.parent_path() / path;
-
- // See if it can be found locally first.
- if (state.dependencies.add_dependency(local_path))
- {
- result.insert(include_search_return(
- local_path,
- state.filename_relative.parent_path() / path));
- return result;
- }
-
- BOOST_FOREACH(fs::path full, include_path)
- {
- full /= path;
-
- if (state.dependencies.add_dependency(full))
- {
- result.insert(include_search_return(full, path));
- return result;
- }
- }
- }
- else
- {
- if (state.dependencies.add_dependency(path)) {
- result.insert(include_search_return(path, path));
- return result;
- }
- }
-
- detail::outerr(state.current_file, pos)
- << "Unable to find file: "
- << details.value
- << std::endl;
- ++state.error_count;
-
- return result;
- }
- }
-
     void load_quickbook(quickbook::state& state,
             include_search_return const& paths,
             value::tag_type load_type,

Added: trunk/tools/quickbook/src/include_paths.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/tools/quickbook/src/include_paths.cpp 2013-11-12 04:14:56 EST (Tue, 12 Nov 2013) (r86642)
@@ -0,0 +1,124 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2005 Thomas Guest
+ Copyright (c) 2013 Daniel James
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include "input_path.hpp"
+#include "include_paths.hpp"
+#include "state.hpp"
+#include "utils.hpp"
+#include "quickbook.hpp" // For the include_path global (yuck)
+#include <boost/foreach.hpp>
+#include <boost/range/algorithm/replace.hpp>
+
+namespace quickbook
+{
+ //
+ // check_path
+ //
+
+ path_details check_path(value const& path, quickbook::state& state)
+ {
+ // Paths are encoded for quickbook 1.6+ and also xmlbase
+ // values (technically xmlbase is a 1.6 feature, but that
+ // isn't enforced as it's backwards compatible).
+ //
+ // Counter-intuitively: encoded == plain text here.
+
+ std::string path_text = qbk_version_n >= 106u || path.is_encoded() ?
+ path.get_encoded() : detail::to_s(path.get_quickbook());
+
+ if(path_text.find('\\') != std::string::npos)
+ {
+ quickbook::detail::ostream* err;
+
+ if (qbk_version_n >= 106u) {
+ err = &detail::outerr(path.get_file(), path.get_position());
+ ++state.error_count;
+ }
+ else {
+ err = &detail::outwarn(path.get_file(), path.get_position());
+ }
+
+ *err << "Path isn't portable: '"
+ << path_text
+ << "'"
+ << std::endl;
+
+ boost::replace(path_text, '\\', '/');
+ }
+
+ return path_details(path_text, path_details::path);
+ }
+
+ //
+ // Search include path
+ //
+
+ std::set<include_search_return> include_search(path_details const& details,
+ quickbook::state& state, string_iterator pos)
+ {
+ std::set<include_search_return> result;
+
+ fs::path path = detail::generic_to_path(details.value);
+
+ // If the path is relative, try and resolve it.
+ if (!path.has_root_directory() && !path.has_root_name())
+ {
+ fs::path local_path =
+ state.current_file->path.parent_path() / path;
+
+ // See if it can be found locally first.
+ if (state.dependencies.add_dependency(local_path))
+ {
+ result.insert(include_search_return(
+ local_path,
+ state.filename_relative.parent_path() / path));
+ return result;
+ }
+
+ BOOST_FOREACH(fs::path full, include_path)
+ {
+ full /= path;
+
+ if (state.dependencies.add_dependency(full))
+ {
+ result.insert(include_search_return(full, path));
+ return result;
+ }
+ }
+ }
+ else
+ {
+ if (state.dependencies.add_dependency(path)) {
+ result.insert(include_search_return(path, path));
+ return result;
+ }
+ }
+
+ detail::outerr(state.current_file, pos)
+ << "Unable to find file: "
+ << details.value
+ << std::endl;
+ ++state.error_count;
+
+ return result;
+ }
+
+ //
+ // include_search_return
+ //
+
+ bool include_search_return::operator<(include_search_return const& other) const
+ {
+ if (filename_relative < other.filename_relative) return true;
+ else if (other.filename_relative < filename_relative) return false;
+ else return filename < other.filename;
+ }
+}

Added: trunk/tools/quickbook/src/include_paths.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/tools/quickbook/src/include_paths.hpp 2013-11-12 04:14:56 EST (Tue, 12 Nov 2013) (r86642)
@@ -0,0 +1,54 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ Copyright (c) 2005 Thomas Guest
+ Copyright (c) 2013 Daniel James
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#if !defined(BOOST_QUICKBOOK_INCLUDE_PATHS_HPP)
+#define BOOST_QUICKBOOK_INCLUDE_PATHS_HPP
+
+// Classes and functions for dealing with the values from include, import and
+// xinclude elements.
+
+#include "fwd.hpp"
+#include "values.hpp"
+#include <set>
+#include <string>
+#include <boost/filesystem/path.hpp>
+
+namespace quickbook
+{
+ struct path_details {
+ // Will possibly add 'url' and 'glob' to this list later:
+ enum path_type { path };
+
+ std::string value;
+ path_type type;
+
+ path_details(std::string const& value, path_type type) :
+ value(value), type(type) {}
+ };
+
+ path_details check_path(value const& path, quickbook::state& state);
+
+ struct include_search_return
+ {
+ include_search_return(fs::path const& x, fs::path const& y)
+ : filename(x), filename_relative(y) {}
+
+ fs::path filename;
+ fs::path filename_relative;
+
+ bool operator<(include_search_return const& other) const;
+ };
+
+ std::set<include_search_return> include_search(path_details const& details,
+ quickbook::state& state, string_iterator pos);
+}
+
+#endif


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