diff options
author | Marius Kintel <marius@kintel.net> | 2013-05-25 21:45:13 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-05-25 21:45:13 (GMT) |
commit | cc6ac10e47ff67fd1d4f5fb8c61fea300f163b1d (patch) | |
tree | 2226c6c1ded88cde597a6a882894dd0ae8f50320 /src/parsersettings.cc | |
parent | 9740232b080ac3d2fe87309fb51a892faf6ea913 (diff) |
Search paths when looking for previously missing includes. Should provide most of what's needed for #364
Diffstat (limited to 'src/parsersettings.cc')
-rw-r--r-- | src/parsersettings.cc | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 799949c..1f95719 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -20,12 +20,12 @@ void add_librarydir(const std::string &libdir) Searces for the given file in library paths and returns the full path if found. Returns an empty path if file cannot be found or filename is a directory. */ -fs::path search_libs(const std::string &filename) +fs::path search_libs(const fs::path &localpath) { BOOST_FOREACH(const std::string &dir, librarypath) { - fs::path usepath = fs::path(dir) / filename; + fs::path usepath = fs::path(dir) / localpath; if (fs::exists(usepath) && !fs::is_directory(usepath)) { - PRINTB("found %s in %s", filename % dir ); + PRINTB("found %s in %s", localpath.string() % dir); return usepath.string(); } } @@ -33,7 +33,7 @@ fs::path search_libs(const std::string &filename) } // files must be 'ordinary' - they mus exist and be non-directories -bool check_valid( fs::path p, std::vector<std::string> openfilenames ) +static bool check_valid(const fs::path &p, const std::vector<std::string> *openfilenames) { if (p.empty()) { PRINTB("WARNING: %s invalid - file path is blank",p); @@ -52,30 +52,34 @@ bool check_valid( fs::path p, std::vector<std::string> openfilenames ) PRINTB("WARNING: %s invalid - points to a directory",p); return false; } - std::string fullname = boosty::stringy( p ); - BOOST_FOREACH(std::string &s, openfilenames) { - PRINTB("WARNING: circular include with %s", fullname); - if (s == fullname) return false; + std::string fullname = boosty::stringy(p); + // Detect circular includes + if (openfilenames) { + BOOST_FOREACH(const std::string &s, *openfilenames) { + if (s == fullname) { + PRINTB("WARNING: circular include with %s", fullname); + return false; + } + } } return true; } // check if file is valid, search path for valid simple file // return empty path on failure -fs::path find_valid_path( fs::path sourcepath, std::string filename, - std::vector<std::string> openfilenames ) +fs::path find_valid_path(const fs::path &sourcepath, + const fs::path &localpath, + const std::vector<std::string> *openfilenames) { - fs::path fpath = fs::path( filename ); - - if ( boosty::is_absolute( fpath ) ) - if ( check_valid( fpath, openfilenames ) ) - return boosty::absolute( fpath ); - - - fpath = sourcepath / filename; - if ( check_valid( fpath, openfilenames ) ) return fpath; - fpath = search_libs( filename ); - if ( check_valid( fpath, openfilenames ) ) return fpath; + if (boosty::is_absolute(localpath)) { + if (check_valid(localpath, openfilenames)) return boosty::absolute(localpath); + } + else { + fs::path fpath = sourcepath / localpath; + if (check_valid(fpath, openfilenames)) return fpath; + fpath = search_libs(localpath); + if (check_valid(fpath, openfilenames)) return fpath; + } return fs::path(); } @@ -108,15 +112,15 @@ void parser_init(const std::string &applicationpath) if (!is_directory(libdir / "libraries")) libdir /= "../../.."; #elif !defined(WIN32) if (is_directory(tmpdir = libdir / "../share/openscad/libraries")) { - librarydir = boosty::stringy( tmpdir ); + librarydir = boosty::stringy(tmpdir); } else if (is_directory(tmpdir = libdir / "../../share/openscad/libraries")) { - librarydir = boosty::stringy( tmpdir ); + librarydir = boosty::stringy(tmpdir); } else if (is_directory(tmpdir = libdir / "../../libraries")) { - librarydir = boosty::stringy( tmpdir ); + librarydir = boosty::stringy(tmpdir); } else #endif if (is_directory(tmpdir = libdir / "libraries")) { - librarydir = boosty::stringy( tmpdir ); + librarydir = boosty::stringy(tmpdir); } if (!librarydir.empty()) add_librarydir(librarydir); } |