diff --git a/src/actions.cpp b/src/actions.cpp index a8ddda5..58f91ea 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1338,9 +1338,8 @@ namespace quickbook } // Search in each of the include path locations. - BOOST_FOREACH(std::string const & p, include_path) + BOOST_FOREACH(fs::path full, include_path) { - fs::path full(p); full /= path; if (fs::exists(full)) { diff --git a/src/actions_class.cpp b/src/actions_class.cpp index 8695db1..692a0f5 100644 --- a/src/actions_class.cpp +++ b/src/actions_class.cpp @@ -19,7 +19,7 @@ namespace quickbook { - actions::actions(char const* filein_, fs::path const& outdir_, string_stream& out_) + actions::actions(fs::path const& filein_, fs::path const& outdir_, string_stream& out_) : grammar_() // header info @@ -44,7 +44,7 @@ namespace quickbook , list_buffer() // state - , filename(fs::absolute(fs::path(filein_))) + , filename(fs::absolute(filein_)) , outdir(outdir_) , macro_change_depth(0) , macro() diff --git a/src/actions_class.hpp b/src/actions_class.hpp index d764a97..57bd619 100644 --- a/src/actions_class.hpp +++ b/src/actions_class.hpp @@ -22,7 +22,7 @@ namespace quickbook struct actions { - actions(char const* filein_, fs::path const& outdir, string_stream& out_); + actions(fs::path const& filein_, fs::path const& outdir, string_stream& out_); private: boost::scoped_ptr grammar_; diff --git a/src/doc_info_actions.cpp b/src/doc_info_actions.cpp index 2a4c81e..4669f88 100644 --- a/src/doc_info_actions.cpp +++ b/src/doc_info_actions.cpp @@ -77,7 +77,7 @@ namespace quickbook qbk_major_version = 1; qbk_minor_version = 1; qbk_version_n = 101; - detail::outwarn(actions.filename.string(),1) + detail::outwarn(actions.filename,1) << "Warning: Quickbook version undefined. " "Version 1.1 is assumed" << std::endl; } @@ -89,13 +89,13 @@ namespace quickbook if (qbk_version_n == 106) { - detail::outwarn(actions.filename.string(),1) + detail::outwarn(actions.filename,1) << "Quickbook 1.6 is still under development and is " "likely to change in the future." << std::endl; } else if(qbk_version_n < 100 || qbk_version_n > 106) { - detail::outerr(actions.filename.string(),1) + detail::outerr(actions.filename,1) << "Unknown version of quickbook: quickbook " << qbk_major_version << "." @@ -121,7 +121,7 @@ namespace quickbook if(!invalid_attributes.empty()) { - detail::outwarn(actions.filename.string(),1) + detail::outwarn(actions.filename,1) << (invalid_attributes.size() > 1 ? "Invalid attributes" : "Invalid attribute") << " for '" << actions.doc_type << " document info': " diff --git a/src/input_path.hpp b/src/input_path.hpp index 91badca..a0d1eb7 100644 --- a/src/input_path.hpp +++ b/src/input_path.hpp @@ -9,6 +9,7 @@ #if !defined(BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP) #define BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP +#include #include #include #include @@ -29,7 +30,7 @@ namespace quickbook { namespace detail public: explicit input_path(char const* c) : path_(c) {} explicit input_path(std::string const& c) : path_(c) {} - operator std::string() const { return path_; } + operator boost::filesystem::path() const { return boost::filesystem::path(path_); } friend void validate(boost::any&, const std::vector&, input_path*, int); diff --git a/src/quickbook.cpp b/src/quickbook.cpp index 436e820..d5efda6 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -16,11 +16,10 @@ #include #include #include +#include #include #include -#include -#include #include #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310)) @@ -38,7 +37,7 @@ namespace quickbook tm* current_gm_time; // the current UTC time bool debug_mode; // for quickbook developers only bool ms_errors = false; // output errors/warnings as if for VS - std::vector include_path; + std::vector include_path; std::vector preset_defines; static void set_macros(actions& actor) @@ -48,7 +47,7 @@ namespace quickbook end = preset_defines.end(); it != end; ++it) { - // TODO: Set filename in actor??? + // TODO: Set filename in actor??? iterator first(it->begin()); iterator last(it->end()); @@ -63,7 +62,7 @@ namespace quickbook // /////////////////////////////////////////////////////////////////////////// int - parse_file(char const* filein_, actions& actor, bool ignore_docinfo) + parse_file(fs::path const& filein_, actions& actor, bool ignore_docinfo) { using std::cerr; using std::vector; @@ -94,7 +93,7 @@ namespace quickbook if (!info.full) { - file_position const& pos = info.stop.get_position(); + file_position const& pos = info.stop.get_position(); detail::outerr(actor.filename, pos.line) << "Syntax Error near column " << pos.column << ".\n"; ++actor.error_count; @@ -104,7 +103,7 @@ namespace quickbook } static int - parse_document(char const* filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false) + parse_document(fs::path const& filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false) { actions actor(filein_, outdir, out); @@ -126,14 +125,14 @@ namespace quickbook static int parse_document( - char const* filein_ - , char const* fileout_ + fs::path const& filein_ + , fs::path const& fileout_ , int indent , int linewidth , bool pretty_print) { int result = 0; - fs::path outdir = fs::path(fileout_).parent_path(); + fs::path outdir = fileout_.parent_path(); if (outdir.empty()) outdir = "."; string_stream buffer; @@ -141,7 +140,7 @@ namespace quickbook if (result == 0) { - std::ofstream fileout(fileout_); + fs::ofstream fileout(fileout_); if (pretty_print) { @@ -258,7 +257,7 @@ main(int argc, char* argv[]) = vm["include-path"].as< std::vector >(); quickbook::include_path - = std::vector(paths.begin(), paths.end()); + = std::vector(paths.begin(), paths.end()); } if (vm.count("define")) @@ -269,9 +268,9 @@ main(int argc, char* argv[]) if (vm.count("input-file")) { - std::string filein - = vm["input-file"].as(); - std::string fileout; + boost::filesystem::path filein( + vm["input-file"].as()); + boost::filesystem::path fileout; if (vm.count("output-file")) { @@ -279,15 +278,15 @@ main(int argc, char* argv[]) } else { - fileout = quickbook::detail::remove_extension(filein.c_str()); - fileout += ".xml"; + fileout = filein; + fileout.replace_extension("xml"); } std::cout << "Generating Output File: " - << fileout + << fileout.string() // TODO << std::endl; - return quickbook::parse_document(filein.c_str(), fileout.c_str(), indent, linewidth, pretty_print); + return quickbook::parse_document(filein, fileout, indent, linewidth, pretty_print); } else { diff --git a/src/quickbook.hpp b/src/quickbook.hpp index de480ef..a65a2f8 100644 --- a/src/quickbook.hpp +++ b/src/quickbook.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "fwd.hpp" namespace quickbook @@ -22,10 +23,10 @@ namespace quickbook extern tm* current_time; // the current time extern tm* current_gm_time; // the current UTC time extern bool debug_mode; - extern std::vector include_path; + extern std::vector include_path; extern std::vector preset_defines; - int parse_file(char const* filein_, actions& actor, bool ignore_docinfo = false); + int parse_file(boost::filesystem::path const& filein_, actions& actor, bool ignore_docinfo = false); } #endif diff --git a/src/utils.cpp b/src/utils.cpp index 9fd589a..ba8625e 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -9,6 +9,7 @@ =============================================================================*/ #include "utils.hpp" #include +#include #include #include @@ -118,21 +119,6 @@ namespace quickbook { namespace detail } } - // remove the extension from a filename - std::string - remove_extension(std::string const& filename) - { - std::string::size_type const n = filename.find_last_of('.'); - if(std::string::npos == n) - { - return filename; - } - else - { - return std::string(filename.begin(), filename.begin()+n); - } - } - std::string escape_uri(std::string uri) { for (std::string::size_type n = 0; n < uri.size(); ++n) @@ -243,7 +229,7 @@ namespace quickbook { namespace detail template bool normalize(InputIterator begin, InputIterator end, - OutputIterator out, std::string const& filename) + OutputIterator out, boost::filesystem::path const& filename) { std::string encoding = read_bom(begin, end, out); @@ -268,7 +254,7 @@ namespace quickbook { namespace detail return true; } - int load(std::string const& filename, std::string& storage) + int load(boost::filesystem::path const& filename, std::string& storage) { using std::cerr; using std::endl; @@ -276,7 +262,7 @@ namespace quickbook { namespace detail using std::ifstream; using std::istream_iterator; - ifstream in(filename.c_str(), std::ios_base::in); + boost::filesystem::ifstream in(filename, std::ios_base::in); if (!in) { diff --git a/src/utils.hpp b/src/utils.hpp index 9a18cc4..6218a26 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -55,9 +55,6 @@ namespace quickbook { namespace detail // un-indent a code segment void unindent(std::string& program); - // remove the extension from a filename - std::string remove_extension(std::string const& filename); - std::string escape_uri(std::string uri); // Preformats an error/warning message so that it can be parsed by @@ -70,7 +67,7 @@ namespace quickbook { namespace detail // load file into memory with extra trailing newlines to eliminate // the need to check for end of file in the grammar. - int load(std::string const& filename, std::string& storage); + int load(boost::filesystem::path const& filename, std::string& storage); // given a file extension, return the type of the source file // we'll have an internal database for known file types.