summaryrefslogtreecommitdiff
path: root/src/parsersettings.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/parsersettings.cc')
-rw-r--r--src/parsersettings.cc56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/parsersettings.cc b/src/parsersettings.cc
index 8d82744..799949c 100644
--- a/src/parsersettings.cc
+++ b/src/parsersettings.cc
@@ -20,13 +20,63 @@ 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.
*/
-std::string locate_file(const std::string &filename)
+fs::path search_libs(const std::string &filename)
{
BOOST_FOREACH(const std::string &dir, librarypath) {
fs::path usepath = fs::path(dir) / filename;
- if (fs::exists(usepath) && !fs::is_directory(usepath)) return usepath.string();
+ if (fs::exists(usepath) && !fs::is_directory(usepath)) {
+ PRINTB("found %s in %s", filename % dir );
+ return usepath.string();
+ }
+ }
+ return fs::path();
+}
+
+// files must be 'ordinary' - they mus exist and be non-directories
+bool check_valid( fs::path p, std::vector<std::string> openfilenames )
+{
+ if (p.empty()) {
+ PRINTB("WARNING: %s invalid - file path is blank",p);
+ return false;
+ }
+ if (!p.has_parent_path()) {
+ PRINTB("WARNING: %s invalid - no parent path",p);
+ return false;
+ }
+ if (!fs::exists(p)) {
+ PRINTB("WARNING: %s invalid - file not found",p);
+ // searched ===
+ return false;
+ }
+ if (fs::is_directory(p)) {
+ PRINTB("WARNING: %s invalid - points to a directory",p);
+ return false;
}
- return std::string();
+ std::string fullname = boosty::stringy( p );
+ BOOST_FOREACH(std::string &s, openfilenames) {
+ PRINTB("WARNING: circular include with %s", fullname);
+ if (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 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;
+ return fs::path();
}
void parser_init(const std::string &applicationpath)
contact: Jan Huwald // Impressum