# # # patch "lua.cc" # from [549417b24694d4668d02e6b3143bc9f9cd806a10] # to [86dd5f2354857f44b75a7c2c229bad870031b562] # ============================================================ --- lua.cc 549417b24694d4668d02e6b3143bc9f9cd806a10 +++ lua.cc 86dd5f2354857f44b75a7c2c229bad870031b562 @@ -5,13 +5,12 @@ #include "globish.hh" #include "sanity.hh" +#include "platform.hh" #include #include #include -#include -#include #include using std::pair; @@ -22,7 +21,6 @@ using std::free; using std::strerror; using std::malloc; using std::free; -namespace fs = boost::filesystem; // adapted from "programming in lua", section 24.2.3 // http://www.lua.org/pil/24.2.3.html @@ -542,35 +540,63 @@ run_file(lua_State * st, char const * fi .ok(); } +namespace +{ + struct ignore_directories : public dirent_consumer + { virtual void consume(const char *) {} }; + struct record_if_matches : public dirent_consumer + { + record_if_matches(string const & b, char const * p, + vector & t) + : base(b + "/"), glob(globish(p), globish()), target(t) + { target.clear(); } + + virtual void consume(const char * component) + { + if (glob(component)) + target.push_back(base + component); + } + private: + string base; + globish_matcher glob; + vector & target; + }; +} + +// ??? should maybe deal in system_paths and use read_directory. void run_directory(lua_State * st, char const * pathstr, char const * pattern) { - fs::path locpath(pathstr, fs::native); - N(fs::exists(locpath), F("Directory '%s' does not exist") % pathstr); - N(fs::is_directory(locpath), F("'%s' is not a directory") % pathstr); + string path(pathstr); + switch (get_path_status(path)) + { + case path::nonexistent: + N(false, F("Directory '%s' does not exist") % pathstr); + case path::file: + N(false, F("'%s' is not a directory") % pathstr); + case path::directory: + break; + } // directory, iterate over it, skipping subdirs, taking every filename // matching the pattern, sorting them and loading in sorted order - fs::directory_iterator it(locpath); - globish r = globish(pattern); - globish_matcher glob(r, globish()); - vector arr; - while (it != fs::directory_iterator()) - { - if (!fs::is_directory(*it) && glob(it->string())) - arr.push_back(*it); - ++it; - } + vector arr; + { + ignore_directories id; + record_if_matches rim(path, pattern, arr); + do_read_directory(path, rim, id); + } + sort(arr.begin(), arr.end()); - for (vector::iterator i= arr.begin(); i != arr.end(); ++i) + for (vector::iterator i= arr.begin(); i != arr.end(); ++i) { - L(FL("opening rcfile '%s'") % i->string()); + L(FL("opening rcfile '%s'") % *i); bool res = Lua(st) - .loadfile(i->string().c_str()) + .loadfile(i->c_str()) .call(0,1) .ok(); - N(res, F("lua error while loading rcfile '%s'") % i->string()); - L(FL("'%s' is ok") % i->string()); + N(res, F("lua error while loading rcfile '%s'") % *i); + L(FL("'%s' is ok") % *i); } }