diff options
author | don bright <hugh.m.bright@gmail.com> | 2012-08-18 16:38:24 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2012-08-18 16:38:24 (GMT) |
commit | 47a06c074fa6321224d5c6d6cc85bf9336fb8765 (patch) | |
tree | 9c1bcb078963477d522ece5a42dab106dd87b03a | |
parent | d87dd4821561fffec4d875a7f584fc25100b8d75 (diff) |
detect flaws in 'use' and 'include' statements. make locate_file consider directories as 'non files'.
-rw-r--r-- | src/lexer.l | 14 | ||||
-rw-r--r-- | src/parsersettings.cc | 4 | ||||
-rw-r--r-- | testdata/scad/templates/use-tests-template.scad | 3 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/lexer.l b/src/lexer.l index f939330..1e3bd5b 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -122,10 +122,16 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); } } } /* Only accept regular files which exists */ - if (usepath.has_parent_path() && fs::exists(usepath)) { + if (usepath.has_parent_path() && fs::exists(usepath) && !fs::is_directory(usepath)) { handle_dep(usepath.string()); parserlval.text = strdup(usepath.string().c_str()); return TOK_USE; + } else { + PRINTB("WARNING: Can't open 'use' file '%s'.", filename); + if ( filename.size() == 0 ) + PRINT("WARNING: 'use' filename is blank"); + else if ( fs::is_directory( usepath ) ) + PRINTB("WARNING: 'use' file points to a directory: %s",filename); } } } @@ -217,6 +223,10 @@ void includefile() finfo = locate_file((fs::path(filepath) / filename).string()); } + if (finfo.empty()) { + PRINTB("WARNING: Can't find 'include' file '%s'.", filename); + } + filepath.clear(); path_stack.push_back(finfo.parent_path()); @@ -225,7 +235,7 @@ void includefile() currmodule->registerInclude(fullname); yyin = fopen(fullname.c_str(), "r"); if (!yyin) { - PRINTB("WARNING: Can't open input file '%s'.", filename); + PRINTB("WARNING: Can't open 'include' file '%s'.", filename); path_stack.pop_back(); return; } diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 53b34f4..9409add 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -15,13 +15,13 @@ 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. + Returns an empty path if file cannot be found or filename is a directory. */ std::string locate_file(const std::string &filename) { BOOST_FOREACH(const std::string &dir, librarypath) { fs::path usepath = fs::path(dir) / filename; - if (fs::exists(usepath)) return usepath.string(); + if (fs::exists(usepath) && !fs::is_directory(usepath)) return usepath.string(); } return std::string(); } diff --git a/testdata/scad/templates/use-tests-template.scad b/testdata/scad/templates/use-tests-template.scad index 24591f8..f92e550 100644 --- a/testdata/scad/templates/use-tests-template.scad +++ b/testdata/scad/templates/use-tests-template.scad @@ -1,3 +1,6 @@ +//Test blank +use <> + //Test that the entire path is pushed onto the stack upto the last '/' use <sub1/sub2/sub3/sub4/use-test2.scad> |