Forgot to actually add most files in previous commit (#217)

felipesanches-svg
Marius Kintel 2013-05-09 12:12:58 +02:00
parent 0e938364fe
commit 14e1ad2363
14 changed files with 46 additions and 23 deletions

View File

@ -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 \

View File

@ -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")

View File

@ -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) );

View File

@ -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,

View File

@ -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))) {

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -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}

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -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();

View File

@ -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