Boost logo

Boost-Commit :

From: grafikrobot_at_[hidden]
Date: 2007-10-25 01:41:41


Author: grafik
Date: 2007-10-25 01:41:40 EDT (Thu, 25 Oct 2007)
New Revision: 40452
URL: http://svn.boost.org/trac/boost/changeset/40452

Log:
Add include-path (I) option so that one can refer to files to import or include outside of the usual quickbook tree without using absolute paths.
Text files modified:
   branches/quickbook/backend/boost/tools/quickbook/detail/actions.cpp | 46 ++++++++++++++++++++++++++-------------
   branches/quickbook/backend/boost/tools/quickbook/detail/actions.hpp | 1
   branches/quickbook/backend/boost/tools/quickbook/detail/quickbook.cpp | 8 ++++++
   3 files changed, 40 insertions(+), 15 deletions(-)

Modified: branches/quickbook/backend/boost/tools/quickbook/detail/actions.cpp
==============================================================================
--- branches/quickbook/backend/boost/tools/quickbook/detail/actions.cpp (original)
+++ branches/quickbook/backend/boost/tools/quickbook/detail/actions.cpp 2007-10-25 01:41:40 EDT (Thu, 25 Oct 2007)
@@ -1044,17 +1044,40 @@
         boost::spirit::parse(first, last, g);
     }
 
- void import_action::operator()(iterator first, iterator last) const
+ namespace
     {
- fs::path path(std::string(first, last), fs::native);
-
- // check to see if the path is complete and if not, make it relative to the current path
- if (!path.is_complete())
+ fs::path include_search(fs::path const & current, std::string const & name)
         {
- path = actions.filename.branch_path() / path;
- path.normalize();
+ fs::path path(name,fs::native);
+
+ // If the path is relative, try and resolve it.
+ if (!path.is_complete())
+ {
+ // See if it can be found locally first.
+ if (fs::exists(current / path))
+ {
+ return current / path;
+ }
+
+ // Search in each of the include path locations.
+ BOOST_FOREACH(std::string const & p, include_path)
+ {
+ fs::path full(p,fs::native);
+ full /= path;
+ if (fs::exists(full))
+ {
+ return full;
+ }
+ }
+ }
+
+ return path;
         }
+ }
 
+ void import_action::operator()(iterator first, iterator last) const
+ {
+ fs::path path = include_search(actions.filename.branch_path(), std::string(first,last));
         std::string ext = fs::extension(path);
         std::vector<template_symbol> storage;
         load_snippets(path.string(), storage, ext, actions.doc_id);
@@ -1077,16 +1100,9 @@
 
     void include_action::operator()(iterator first, iterator last) const
     {
- fs::path filein(std::string(first, last), fs::native);
+ fs::path filein = include_search(actions.filename.branch_path(), std::string(first,last));
         std::string doc_type, doc_id, doc_dirname, doc_last_revision;
 
- // check to see if the path is complete and if not, make it relative to the current path
- if (!filein.is_complete())
- {
- filein = actions.filename.branch_path() / filein;
- filein.normalize();
- }
-
         // swap the filenames
         std::swap(actions.filename, filein);
 

Modified: branches/quickbook/backend/boost/tools/quickbook/detail/actions.hpp
==============================================================================
--- branches/quickbook/backend/boost/tools/quickbook/detail/actions.hpp (original)
+++ branches/quickbook/backend/boost/tools/quickbook/detail/actions.hpp 2007-10-25 01:41:40 EDT (Thu, 25 Oct 2007)
@@ -51,6 +51,7 @@
     extern unsigned qbk_major_version;
     extern unsigned qbk_minor_version;
     extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version
+ extern std::vector<std::string> include_path;
 
     // forward declarations
     struct actions;

Modified: branches/quickbook/backend/boost/tools/quickbook/detail/quickbook.cpp
==============================================================================
--- branches/quickbook/backend/boost/tools/quickbook/detail/quickbook.cpp (original)
+++ branches/quickbook/backend/boost/tools/quickbook/detail/quickbook.cpp 2007-10-25 01:41:40 EDT (Thu, 25 Oct 2007)
@@ -21,6 +21,7 @@
 #include <stdexcept>
 #include <fstream>
 #include <iostream>
+#include <vector>
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -39,6 +40,7 @@
     unsigned qbk_minor_version = 0;
     unsigned qbk_version_n = 0; // qbk_major_version * 100 + qbk_minor_version
     bool ms_errors = false; // output errors/warnings as if for VS
+ std::vector<std::string> include_path;
 
     ///////////////////////////////////////////////////////////////////////////
     //
@@ -181,6 +183,7 @@
             ("output-file", value<std::string>(), "output file")
             ("debug", "debug mode (for developers)")
             ("ms-errors", "use Microsoft Visual Studio style error & warn message format")
+ ("include-path,I", value< std::vector<std::string> >(), "include path")
         ;
 
         positional_options_description p;
@@ -241,6 +244,11 @@
             quickbook::current_gm_time = &gmt;
             quickbook::debug_mode = false;
         }
+
+ if (vm.count("include-path"))
+ {
+ quickbook::include_path = vm["include-path"].as< std::vector<std::string> >();
+ }
 
         if (vm.count("input-file"))
         {


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