diff options
author | Marius Kintel <marius@kintel.net> | 2012-06-24 14:29:28 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-06-24 14:29:28 (GMT) |
commit | 22c5f37424e42b69442ef6b020b650c0e685a8c3 (patch) | |
tree | 4246e75e0c9b133df4513d13186a3ece3c288118 | |
parent | 0e6b80015504b36363c5545744b6627554c4d10b (diff) |
Search for libraries from a list of paths. Preparations for issue #125
-rw-r--r-- | src/lexer.l | 4 | ||||
-rw-r--r-- | src/parsersettings.cc | 31 | ||||
-rw-r--r-- | src/parsersettings.h | 4 | ||||
-rw-r--r-- | testdata/scad/features/import_dxf-tests.scad | 10 | ||||
-rw-r--r-- | testdata/scad/features/import_stl-tests.scad | 4 | ||||
-rw-r--r-- | tests/cgalcachetest.cc | 2 | ||||
-rw-r--r-- | tests/cgalpngtest.cc | 2 | ||||
-rw-r--r-- | tests/cgalstlsanitytest.cc | 2 | ||||
-rw-r--r-- | tests/cgaltest.cc | 2 | ||||
-rw-r--r-- | tests/csgtermtest.cc | 2 | ||||
-rw-r--r-- | tests/csgtestcore.cc | 2 | ||||
-rw-r--r-- | tests/csgtexttest.cc | 2 | ||||
-rw-r--r-- | tests/dumptest.cc | 2 | ||||
-rw-r--r-- | tests/echotest.cc | 2 | ||||
-rw-r--r-- | tests/modulecachetest.cc | 2 |
15 files changed, 35 insertions, 38 deletions
diff --git a/src/lexer.l b/src/lexer.l index 188046f..f939330 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -118,7 +118,7 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); } else { usepath = sourcepath() / filename; if (!fs::exists(usepath)) { - usepath = boosty::absolute(fs::path(get_librarydir()) / filename); + usepath = locate_file(filename); } } /* Only accept regular files which exists */ @@ -214,7 +214,7 @@ void includefile() fs::path finfo = dirinfo / filename; if (!exists(finfo)) { - finfo = fs::path(get_librarydir()) / filepath / filename; + finfo = locate_file((fs::path(filepath) / filename).string()); } filepath.clear(); diff --git a/src/parsersettings.cc b/src/parsersettings.cc index a3a02b7..53b34f4 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,27 +1,38 @@ #include "parsersettings.h" #include <boost/filesystem.hpp> +#include <boost/foreach.hpp> +#include "boosty.h" #include <qglobal.h> // Needed for Q_ defines - move the offending code somewhere else -using namespace boost::filesystem; -#include "boosty.h" +namespace fs = boost::filesystem; -std::string librarydir; +std::vector<std::string> librarypath; -void set_librarydir(const std::string &libdir) +void add_librarydir(const std::string &libdir) { - librarydir = libdir; + librarypath.push_back(libdir); } -const std::string &get_librarydir() +/*! + Searces for the given file in library paths and returns the full path if found. + Returns an empty path if file cannot be found. +*/ +std::string locate_file(const std::string &filename) { - return librarydir; + BOOST_FOREACH(const std::string &dir, librarypath) { + fs::path usepath = fs::path(dir) / filename; + if (fs::exists(usepath)) return usepath.string(); + } + return std::string(); } void parser_init(const std::string &applicationpath) { + // FIXME: Append paths from OPENSCADPATH before adding built-in paths + std::string librarydir; - path libdir(applicationpath); - path tmpdir; + fs::path libdir(applicationpath); + fs::path tmpdir; #ifdef Q_WS_MAC libdir /= "../Resources"; // Libraries can be bundled if (!is_directory(libdir / "libraries")) libdir /= "../../.."; @@ -37,5 +48,5 @@ void parser_init(const std::string &applicationpath) if (is_directory(tmpdir = libdir / "libraries")) { librarydir = boosty::stringy( tmpdir ); } - set_librarydir(librarydir); + if (!librarydir.empty()) add_librarydir(librarydir); } diff --git a/src/parsersettings.h b/src/parsersettings.h index a5dc939..007aa9c 100644 --- a/src/parsersettings.h +++ b/src/parsersettings.h @@ -6,7 +6,7 @@ extern int parser_error_pos; void parser_init(const std::string &applicationpath); -void set_librarydir(const std::string &libdir); -const std::string &get_librarydir(); +void add_librarydir(const std::string &libdir); +std::string locate_file(const std::string &filename); #endif diff --git a/testdata/scad/features/import_dxf-tests.scad b/testdata/scad/features/import_dxf-tests.scad deleted file mode 100644 index 50a5416..0000000 --- a/testdata/scad/features/import_dxf-tests.scad +++ /dev/null @@ -1,10 +0,0 @@ -import(); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf"); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[0,110]); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[110,110], scale=0.5); -import(file="../../dxf/multiple-layers.dxf"); -translate([-200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); -translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); -translate([200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="noname"); -translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="Layer with a pretty long name including \\ \"special\" /'\\\\ characters"); -translate([200,0,0]) import(file="/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/dxf/polygons.dxf"); diff --git a/testdata/scad/features/import_stl-tests.scad b/testdata/scad/features/import_stl-tests.scad deleted file mode 100644 index af42e8d..0000000 --- a/testdata/scad/features/import_stl-tests.scad +++ /dev/null @@ -1,4 +0,0 @@ -import_stl("import.stl"); -translate([2,0,0]) import("import.stl"); -translate([4,0,0]) import("import_bin.stl"); -translate([0,2,0]) import("/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/scad/features/import.stl"); diff --git a/tests/cgalcachetest.cc b/tests/cgalcachetest.cc index 18e9efa..46e0e9a 100644 --- a/tests/cgalcachetest.cc +++ b/tests/cgalcachetest.cc @@ -139,7 +139,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 7c9684a..08e539e 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -112,7 +112,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalstlsanitytest.cc b/tests/cgalstlsanitytest.cc index d0d0077..92b4ac1 100644 --- a/tests/cgalstlsanitytest.cc +++ b/tests/cgalstlsanitytest.cc @@ -98,7 +98,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 98617a3..e4761db 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -91,7 +91,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 1bd2468..e793c4a 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -77,7 +77,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index cb96940..02cf73c 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -258,7 +258,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) std::string currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 6e18f20..e050232 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -81,7 +81,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index c1fe55b..6851fb1 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -87,7 +87,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy(fs::current_path()); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/echotest.cc b/tests/echotest.cc index d731ee3..bf2f4a4 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -89,7 +89,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/modulecachetest.cc b/tests/modulecachetest.cc index 2ef7a6c..0028114 100644 --- a/tests/modulecachetest.cc +++ b/tests/modulecachetest.cc @@ -77,7 +77,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); |