summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/boost-utils.cc18
-rw-r--r--src/boosty.h63
-rw-r--r--src/value.cc4
3 files changed, 73 insertions, 12 deletions
diff --git a/src/boost-utils.cc b/src/boost-utils.cc
index 5127047..534cbaa 100644
--- a/src/boost-utils.cc
+++ b/src/boost-utils.cc
@@ -1,3 +1,4 @@
+#include "boosty.h"
#include "boost-utils.h"
#include <stdio.h>
#include <iostream>
@@ -7,8 +8,8 @@
fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to)
{
// create absolute paths
- fs::path p = fs::absolute(boostfs_normalize(path));
- fs::path r = fs::absolute(relative_to);
+ fs::path p = boosty::absolute(boostfs_normalize(path));
+ fs::path r = boosty::absolute(relative_to);
// if root paths are different, return absolute path
if (p.root_path() != r.root_path())
@@ -46,16 +47,17 @@ fs::path boostfs_relative_path(const fs::path &path, const fs::path &relative_to
// Will normalize the given path, i.e. remove any redundant ".." path elements.
fs::path boostfs_normalize(const fs::path &path)
{
- fs::path absPath = absolute(path);
+ fs::path absPath = boosty::absolute(path);
fs::path::iterator it = absPath.begin();
- fs::path result = *it++;
+ fs::path result = *it;
+ if (it!=absPath.end()) it++;
// Get canonical version of the existing part
for(;exists(result) && it != absPath.end(); ++it) {
result /= *it;
}
- result = canonical(result.parent_path());
- --it;
+ result = boosty::canonical(result.parent_path());
+ if (it!=absPath.begin()) it--;
// For the rest remove ".." and "." in a path with no symlinks
for (; it != absPath.end(); ++it) {
@@ -98,8 +100,8 @@ boostfs_uncomplete(fs::path const p, fs::path const base)
which it most likely is... but then base shouldn't be a filename so... */
// create absolute paths
- fs::path abs_p = fs::absolute(boostfs_normalize(p));
- fs::path abs_base = fs::absolute(base);
+ fs::path abs_p = boosty::absolute(boostfs_normalize(p));
+ fs::path abs_base = boosty::absolute(base);
fs::path from_path, from_base, output;
diff --git a/src/boosty.h b/src/boosty.h
index 6ec417a..8b0c93e 100644
--- a/src/boosty.h
+++ b/src/boosty.h
@@ -10,9 +10,8 @@
versions of boost found on popular versions of linux, circa early 2012.
design
- hope that the user is compiling with boost>1.46 + filesystem v3
- if not, fall back to older deprecated functions, and rely on
- testing to find bugs. implement the minimum needed by OpenSCAD and no more.
+ the boost filsystem changed around 1.46-1.48. we do a large #ifdef
+ based on boost version that wraps various functions appropriately.
in a few years, this file should be deleted as unnecessary.
see also
@@ -28,6 +27,7 @@
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
+#include "printutils.h"
namespace boosty {
@@ -77,6 +77,63 @@ inline std::string extension_str( fs::path p)
#endif
+
+
+
+
+#if BOOST_VERSION >= 104800
+
+inline fs::path canonical( fs::path p, fs::path p2 )
+{
+ return fs::canonical( p, p2 );
+}
+
+inline fs::path canonical( fs::path p )
+{
+ return fs::canonical( p );
+}
+
+#else
+
+inline fs::path canonical( fs::path p, fs::path p2 )
+{
+ // dotpath: win32/mac builds will be using newer versions of boost
+ // so we can treat this as though it is unix only
+ const fs::path dot_path(".");
+ const fs::path dot_dot_path("..");
+ fs::path result;
+ if (p=="")
+ {
+ p=p2;
+ }
+ for (fs::path::iterator itr = p.begin(); itr != p.end(); itr++)
+ {
+ if (*itr == dot_path) continue;
+ if (*itr == dot_dot_path)
+ {
+ result.remove_filename();
+ continue;
+ }
+ result /= *itr;
+ if (fs::is_symlink(result))
+ {
+ PRINT("WARNING: canonical() wrapper can't do symlinks. rebuild openscad with boost >=1.48");
+ PRINT("WARNING: or don't use symbolic links");
+ }
+ }
+ return result;
+}
+
+inline fs::path canonical( fs::path p )
+{
+ return canonical( p, fs::current_path() );
+}
+
+#endif
+
+
+
+
} // namespace
#endif
diff --git a/src/value.cc b/src/value.cc
index ae810a2..ebb825d 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -39,7 +39,9 @@
std::ostream &operator<<(std::ostream &stream, const Filename &filename)
{
- stream << QuotedString(boosty::stringy(boostfs_uncomplete(filename, fs::current_path())));
+ fs::path fnpath = fs::path( (std::string)filename );
+ fs::path fpath = boostfs_uncomplete(fnpath, fs::current_path());
+ stream << QuotedString(boosty::stringy( fpath ));
return stream;
}
contact: Jan Huwald // Impressum