diff options
author | Marius Kintel <marius@kintel.net> | 2013-05-09 10:12:58 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-05-09 10:12:58 (GMT) |
commit | 14e1ad23635a65d98c59ae14e35484abbd3ba6c4 (patch) | |
tree | 0ef8483812496e456023a9341dcf76f0bbba7006 | |
parent | 0e938364fea8c3ab07b06491fd21cb34a403bf99 (diff) |
Forgot to actually add most files in previous commit (#217)
-rw-r--r-- | openscad.pro | 2 | ||||
-rw-r--r-- | src/dxfdim.cc | 4 | ||||
-rw-r--r-- | src/import.cc | 3 | ||||
-rw-r--r-- | src/linearextrude.cc | 3 | ||||
-rw-r--r-- | src/module.cc | 5 | ||||
-rw-r--r-- | src/openscad.cc | 3 | ||||
-rw-r--r-- | src/rotateextrude.cc | 3 | ||||
-rw-r--r-- | src/surface.cc | 3 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/cgalpngtest.cc | 7 | ||||
-rw-r--r-- | tests/csgtestcore.cc | 7 | ||||
-rw-r--r-- | tests/dumptest.cc | 13 | ||||
-rw-r--r-- | tests/tests-common.cc | 11 | ||||
-rw-r--r-- | tests/tests-common.h | 4 |
14 files changed, 46 insertions, 23 deletions
diff --git a/openscad.pro b/openscad.pro index 81f5e6f..96a0a2a 100644 --- a/openscad.pro +++ b/openscad.pro @@ -227,6 +227,7 @@ HEADERS += src/typedefs.h \ src/handle_dep.h \ src/polyset.h \ src/printutils.h \ + src/fileutils.h \ src/value.h \ src/progress.h \ src/editor.h \ @@ -291,6 +292,7 @@ SOURCES += src/version_check.cc \ src/linearextrude.cc \ src/rotateextrude.cc \ src/printutils.cc \ + src/fileutils.cc \ src/progress.cc \ src/parsersettings.cc \ src/stl-utils.cc \ diff --git a/src/dxfdim.cc b/src/dxfdim.cc index 555ed49..66842d2 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -30,6 +30,7 @@ #include "dxfdata.h" #include "builtin.h" #include "printutils.h" +#include "fileutils.h" #include "evalcontext.h" #include "mathc99.h" @@ -54,7 +55,8 @@ Value builtin_dxf_dim(const Context *ctx, const EvalContext *evalctx) // See issue #217 for (size_t i = 0; i < evalctx->numArgs(); i++) { if (evalctx->getArgName(i) == "file") - filename = evalctx->getAbsolutePath(evalctx->getArgValue(i).toString()); + filename = lookup_file(evalctx->getArgValue(i).toString(), + evalctx->documentPath(), ctx->documentPath()); if (evalctx->getArgName(i) == "layer") layername = evalctx->getArgValue(i).toString(); if (evalctx->getArgName(i) == "origin") diff --git a/src/import.cc b/src/import.cc index bd8f830..bb44d70 100644 --- a/src/import.cc +++ b/src/import.cc @@ -33,6 +33,7 @@ #include "dxfdata.h" #include "dxftess.h" #include "printutils.h" +#include "fileutils.h" #include "handle_dep.h" // handle_dep() #ifdef ENABLE_CGAL @@ -97,7 +98,7 @@ AbstractNode *ImportModule::instantiate(const Context *ctx, const ModuleInstanti PRINT("DEPRECATED: filename= is deprecated. Please use file="); } } - std::string filename = inst->getAbsolutePath(v.isUndefined() ? "" : v.toString()); + std::string filename = lookup_file(v.isUndefined() ? "" : v.toString(), inst->path(), ctx->documentPath()); import_type_e actualtype = this->type; if (actualtype == TYPE_UNKNOWN) { std::string extraw = boosty::extension_str( fs::path(filename) ); diff --git a/src/linearextrude.cc b/src/linearextrude.cc index c64a235..3b9db02 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -29,6 +29,7 @@ #include "module.h" #include "evalcontext.h" #include "printutils.h" +#include "fileutils.h" #include "builtin.h" #include "PolySetEvaluator.h" #include "openscad.h" // get_fragments_from_r() @@ -74,7 +75,7 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI if (!file.isUndefined()) { PRINT("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead."); - node->filename = inst->getAbsolutePath(file.toString()); + node->filename = lookup_file(file.toString(), inst->path(), c.documentPath()); } // if height not given, and first argument is a number, diff --git a/src/module.cc b/src/module.cc index 9503f05..8b84c07 100644 --- a/src/module.cc +++ b/src/module.cc @@ -71,7 +71,10 @@ IfElseModuleInstantiation::~IfElseModuleInstantiation() /*! Returns the absolute path to the given filename, unless it's empty. - */ + + NB! This will actually search for the file, to be backwards compatible with <= 2013.01 + (see issue #217) +*/ std::string ModuleInstantiation::getAbsolutePath(const std::string &filename) const { if (!filename.empty() && !boosty::is_absolute(fs::path(filename))) { diff --git a/src/openscad.cc b/src/openscad.cc index 6a0d057..7c54762 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -359,7 +359,8 @@ int main(int argc, char **argv) fs::path fpath = boosty::absolute(fs::path(filename)); fs::path fparent = fpath.parent_path(); fs::current_path(fparent); - + top_ctx.setDocumentPath(fparent.string()); + AbstractNode::resetIndexCounter(); absolute_root_node = root_module->instantiate(&top_ctx, &root_inst, NULL); diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc index 2f9a28b..e073a69 100644 --- a/src/rotateextrude.cc +++ b/src/rotateextrude.cc @@ -28,6 +28,7 @@ #include "module.h" #include "evalcontext.h" #include "printutils.h" +#include "fileutils.h" #include "builtin.h" #include "polyset.h" #include "visitor.h" @@ -70,7 +71,7 @@ AbstractNode *RotateExtrudeModule::instantiate(const Context *ctx, const ModuleI if (!file.isUndefined()) { PRINT("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead."); - node->filename = inst->getAbsolutePath(file.toString()); + node->filename = lookup_file(file.toString(), inst->path(), c.documentPath()); } node->layername = layer.isUndefined() ? "" : layer.toString(); diff --git a/src/surface.cc b/src/surface.cc index b3246c1..46ddc07 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -30,6 +30,7 @@ #include "evalcontext.h" #include "builtin.h" #include "printutils.h" +#include "fileutils.h" #include "handle_dep.h" // handle_dep() #include "visitor.h" @@ -82,7 +83,7 @@ AbstractNode *SurfaceModule::instantiate(const Context *ctx, const ModuleInstant c.setVariables(args, evalctx); Value fileval = c.lookup_variable("file"); - node->filename = inst->getAbsolutePath(fileval.isUndefined() ? "" : fileval.toString()); + node->filename = lookup_file(fileval.isUndefined() ? "" : fileval.toString(), inst->path(), c.documentPath()); Value center = c.lookup_variable("center", true); if (center.type() == Value::BOOL) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7833572..964adc2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -429,6 +429,7 @@ set(CORE_SOURCES ../src/linearextrude.cc ../src/rotateextrude.cc ../src/printutils.cc + ../src/fileutils.cc ../src/progress.cc ../src/boost-utils.cc ${FLEX_OpenSCADlexer_OUTPUTS} diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 81fc6b4..7b958de 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -113,9 +113,10 @@ int main(int argc, char **argv) exit(1); } - if (fs::path(filename).has_parent_path()) { - fs::current_path(fs::path(filename).parent_path()); - } + fs::path fpath = boosty::absolute(fs::path(filename)); + fs::path fparent = fpath.parent_path(); + fs::current_path(fparent); + top_ctx.setDocumentPath(fparent.string()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->instantiate(&top_ctx, &root_inst); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 320b533..7b9dbab 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -148,9 +148,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } if (!sysinfo_dump) { - if (fs::path(filename).has_parent_path()) { - fs::current_path(fs::path(filename).parent_path()); - } + fs::path fpath = boosty::absolute(fs::path(filename)); + fs::path fparent = fpath.parent_path(); + fs::current_path(fparent); + top_ctx.setDocumentPath(fparent.string()); } AbstractNode::resetIndexCounter(); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index e4876fa..4477703 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -97,9 +97,10 @@ int main(int argc, char **argv) exit(1); } - if (fs::path(filename).has_parent_path()) { - fs::current_path(fs::path(filename).parent_path()); - } + fs::path fpath = boosty::absolute(fs::path(filename)); + fs::path fparent = fpath.parent_path(); + fs::current_path(fparent); + top_ctx.setDocumentPath(fparent.string()); AbstractNode::resetIndexCounter(); root_node = root_module->instantiate(&top_ctx, &root_inst); @@ -130,7 +131,7 @@ int main(int argc, char **argv) delete root_module; fs::current_path(original_path); - root_module = parsefile(outfilename); + root_module = parsefile(outfilename, fparent.string().c_str()); if (!root_module) { fprintf(stderr, "Error: Unable to read back dumped file\n"); exit(1); @@ -141,9 +142,7 @@ int main(int argc, char **argv) tree.setRoot(root_node); - if (fs::path(outfilename).has_parent_path()) { - fs::current_path(fs::path(outfilename).parent_path()); - } + fs::current_path(fparent); string readbackstr = dumptree(tree, *root_node); if (dumpstdstr != readbackstr) { diff --git a/tests/tests-common.cc b/tests/tests-common.cc index ac85e37..3c66e1b 100644 --- a/tests/tests-common.cc +++ b/tests/tests-common.cc @@ -7,7 +7,12 @@ #include <sstream> #include <fstream> -FileModule *parsefile(const char *filename) +/*! + fakepath is used to force the parser to believe that the file is + read from this location, in order to ensure that filepaths are + eavluated relative to this path (for testing purposes). +*/ +FileModule *parsefile(const char *filename, const char *fakepath) { FileModule *root_module = NULL; @@ -19,7 +24,9 @@ FileModule *parsefile(const char *filename) else { std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); text += "\n" + commandline_commands; - std::string pathname = boosty::stringy(fs::path(filename).parent_path()); + std::string pathname; + if (fakepath) pathname = fakepath; + else pathname = boosty::stringy(fs::path(filename).parent_path()); root_module = parse(text.c_str(), pathname.c_str(), false); if (root_module) { root_module->handleDependencies(); diff --git a/tests/tests-common.h b/tests/tests-common.h index 3393884..e16bcda 100644 --- a/tests/tests-common.h +++ b/tests/tests-common.h @@ -1,6 +1,8 @@ #ifndef TESTS_COMMON_H_ #define TESTS_COMMON_H_ -class FileModule *parsefile(const char *filename); +#include <stdlib.h> + +class FileModule *parsefile(const char *filename, const char *fakepath = NULL); #endif |