Replace input_path with manual path conversion.

[SVN r68395]
This commit is contained in:
Daniel James
2011-01-23 16:47:23 +00:00
parent 9557da3e43
commit 70c5398ec3
3 changed files with 26 additions and 51 deletions

View File

@@ -13,16 +13,10 @@
// Everything but cygwin
namespace quickbook { namespace detail
{
void validate(boost::any& v,
const std::vector<std::string>& values,
input_path*, int)
{
std::string path
= boost::program_options::validators::get_single_string(values);
v = input_path(path);
namespace quickbook {
namespace detail {
fs::path native_to_path(fs::path::string_type const& path) {
return fs::path(path);
}
}}
@@ -36,15 +30,10 @@ namespace quickbook { namespace detail
#include <windows.h>
#include <sys/cygwin.h>
namespace quickbook { namespace detail
{
void validate(boost::any& v,
const std::vector<std::string>& values,
input_path*, int)
{
std::string path
= boost::program_options::validators::get_single_string(values);
namespace quickbook {
namespace detail {
fs::path native_to_path(fs::path::string_type const& path) {
// TODO: Use unicode version
#if defined(BOOST_WINDOWS_PATH)
cygwin_conv_path_t flags = CCP_POSIX_TO_WIN_A | CCP_RELATIVE;
#elif defined(BOOST_POSIX_PATH)
@@ -56,6 +45,7 @@ namespace quickbook { namespace detail
ssize_t size = cygwin_conv_path(flags, path.c_str(), NULL, 0);
if (size < 0) {
// TODO: Better error.
throw boost::program_options::validation_error(
boost::program_options::validation_error::invalid_option_value);
}
@@ -67,7 +57,7 @@ namespace quickbook { namespace detail
boost::program_options::validation_error::invalid_option_value);
}
v = input_path(result.get());
return fs::path(result.get());
}
}}

View File

@@ -10,35 +10,19 @@
#define BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP
#include <boost/filesystem/v3/path.hpp>
#include <vector>
#include <boost/any.hpp>
#include <string>
namespace quickbook
{
namespace fs = boost::filesystem;
namespace detail
{
// Use this class with Boost.Program Options to convert paths to the format
// the Boost.Filesystem expects. This is needed on cygwin to convert cygwin
// paths to windows paths (or vice versa, depending on how filesystem is set
// up).
//
// Note that we don't want to convert paths in quickbook files, as they
// should be platform independent, and aren't necessarily relative to the
// current directory.
class input_path {
std::string path_;
public:
explicit input_path(char const* c) : path_(c) {}
explicit input_path(std::string const& c) : path_(c) {}
operator boost::filesystem::path() const { return boost::filesystem::path(path_); }
friend void validate(boost::any&, const std::vector<std::string>&,
input_path*, int);
};
}}
namespace detail
{
// Convert paths from the command line, or other native sources to
// our internal path type. Mainly used to convert cygwin paths, but
// might be useful elsewhere.
fs::path native_to_path(fs::path::string_type const&);
}
}
#endif

View File

@@ -186,11 +186,11 @@ main(int argc, char* argv[])
("no-pretty-print", "disable XML pretty printing")
("indent", value<int>(), "indent spaces")
("linewidth", value<int>(), "line width")
("input-file", value<quickbook::detail::input_path>(), "input file")
("output-file", value<quickbook::detail::input_path>(), "output file")
("input-file", value<fs::path::string_type>(), "input file")
("output-file", value<fs::path::string_type>(), "output file")
("debug", "debug mode (for developers)")
("ms-errors", "use Microsoft Visual Studio style error & warn message format")
("include-path,I", value< std::vector<quickbook::detail::input_path> >(), "include path")
("include-path,I", value< std::vector<fs::path::string_type> >(), "include path")
("define,D", value< std::vector<std::string> >(), "define macro")
;
@@ -255,9 +255,9 @@ main(int argc, char* argv[])
if (vm.count("include-path"))
{
std::vector<quickbook::detail::input_path> paths
std::vector<fs::path::string_type> paths
= vm["include-path"].as<
std::vector<quickbook::detail::input_path> >();
std::vector<fs::path::string_type> >();
quickbook::include_path
= std::vector<fs::path>(paths.begin(), paths.end());
}
@@ -270,13 +270,14 @@ main(int argc, char* argv[])
if (vm.count("input-file"))
{
// TODO: Convert cygwin paths
fs::path filein(
vm["input-file"].as<quickbook::detail::input_path>());
vm["input-file"].as<fs::path::string_type>());
fs::path fileout;
if (vm.count("output-file"))
{
fileout = vm["output-file"].as<quickbook::detail::input_path>();
fileout = vm["output-file"].as<fs::path::string_type>();
}
else
{