diff options
author | Marius Kintel <marius@kintel.net> | 2012-10-30 13:43:49 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-10-30 13:43:49 (GMT) |
commit | 467f8968434c9a46c17edae1bfdba5eb1c756eff (patch) | |
tree | b44bfd37aaa8a835af72bbde9426895ea9c85b04 /src | |
parent | 73d8d3cca4de55e81d47732f2b1f9507cc0d23b4 (diff) | |
parent | 65c57886769b86cf785ab2049d32311c4c52126a (diff) |
Merge branch 'master' into issue202svg
Diffstat (limited to 'src')
-rw-r--r-- | src/ModuleCache.cc | 6 | ||||
-rw-r--r-- | src/lexer.l | 11 | ||||
-rw-r--r-- | src/parsersettings.cc | 10 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/ModuleCache.cc b/src/ModuleCache.cc index c215342..19a3f84 100644 --- a/src/ModuleCache.cc +++ b/src/ModuleCache.cc @@ -72,7 +72,9 @@ Module *ModuleCache::evaluate(const std::string &filename) PRINTB("WARNING: Can't open library file '%s'\n", filename); return NULL; } - std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); + std::stringstream textbuf; + textbuf << ifs.rdbuf(); + textbuf << "\n" << commandline_commands; print_messages_push(); @@ -84,7 +86,7 @@ Module *ModuleCache::evaluate(const std::string &filename) this->entries[filename] = e; std::string pathname = boosty::stringy(fs::path(filename).parent_path()); - lib_mod = dynamic_cast<Module*>(parse(text.c_str(), pathname.c_str(), false)); + lib_mod = dynamic_cast<Module*>(parse(textbuf.str().c_str(), pathname.c_str(), false)); PRINTB_NOCACHE(" compiled module: %p", lib_mod); if (lib_mod) { diff --git a/src/lexer.l b/src/lexer.l index 1e3bd5b..63b0047 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -80,6 +80,7 @@ void includefile(); fs::path sourcepath(); std::vector<fs::path> path_stack; std::vector<FILE*> openfiles; +std::vector<std::string> openfilenames; std::string filename; std::string filepath; @@ -142,6 +143,7 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); } assert(!openfiles.empty()); fclose(openfiles.back()); openfiles.pop_back(); + openfilenames.pop_back(); } yypop_buffer_state(); if (!YY_CURRENT_BUFFER) @@ -227,10 +229,15 @@ void includefile() PRINTB("WARNING: Can't find 'include' file '%s'.", filename); } + std::string fullname = boosty::absolute(finfo).string(); + // Detect circular includes + BOOST_FOREACH(std::string &s, openfilenames) { + if (s == fullname) return; + } + filepath.clear(); path_stack.push_back(finfo.parent_path()); - std::string fullname = boosty::absolute(finfo).string(); handle_dep(fullname); currmodule->registerInclude(fullname); yyin = fopen(fullname.c_str(), "r"); @@ -240,6 +247,7 @@ void includefile() return; } openfiles.push_back(yyin); + openfilenames.push_back(fullname); filename.clear(); yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); @@ -253,5 +261,6 @@ void lexerdestroy() { BOOST_FOREACH (FILE *f, openfiles) fclose(f); openfiles.clear(); + openfilenames.clear(); path_stack.clear(); } diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 47859c7..3dda132 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -28,7 +28,15 @@ std::string locate_file(const std::string &filename) void parser_init(const std::string &applicationpath) { - // FIXME: Append paths from OPENSCADPATH before adding built-in paths + // Add path from OPENSCADPATH before adding built-in paths + const char *openscadpath = getenv("OPENSCADPATH"); + if (openscadpath) { + add_librarydir(boosty::absolute(fs::path(openscadpath)).string()); + } + + // FIXME: Support specifying more than one path in OPENSCADPATH + // FIXME: Add ~/.openscad/libraries + // FIXME: Add ~/Documents/OpenSCAD/libraries on Mac? std::string librarydir; fs::path libdir(applicationpath); |