summaryrefslogtreecommitdiff
path: root/tex/context/base/l-dir.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2009-12-13 23:27:00 +0100
committerHans Hagen <pragma@wxs.nl>2009-12-13 23:27:00 +0100
commit3a75fc96a5e7607afbead86fd9a3a9a8831494aa (patch)
treec3972f260ed3957fb4a742fd259f3067c2d9c1bb /tex/context/base/l-dir.lua
parenta88d77afdd9ea519815a25698e446908aec42ff9 (diff)
downloadcontext-3a75fc96a5e7607afbead86fd9a3a9a8831494aa.tar.gz
beta 2009.12.13 23:27
Diffstat (limited to 'tex/context/base/l-dir.lua')
-rw-r--r--tex/context/base/l-dir.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua
index db0737e5b..7ee565b30 100644
--- a/tex/context/base/l-dir.lua
+++ b/tex/context/base/l-dir.lua
@@ -41,6 +41,35 @@ end
dir.glob_pattern = glob_pattern
+local function collect_pattern(path,patt,recurse,result)
+ local ok, scanner
+ result = result or { }
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local attr = attributes(full)
+ local mode = attr.mode
+ if mode == 'file' then
+ if find(full,patt) then
+ result[name] = attr
+ end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ attr.list = collect_pattern(full,patt,recurse)
+ result[name] = attr
+ end
+ end
+ end
+ return result
+end
+
+dir.collect_pattern = collect_pattern
+
local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
local pattern = Ct {