summaryrefslogtreecommitdiff
path: root/tex/context/base/l-dir.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2007-12-17 14:54:00 +0100
committerHans Hagen <pragma@wxs.nl>2007-12-17 14:54:00 +0100
commit77b453ae2a132853da3e64286d612af49147b30f (patch)
treed8ec3e487d30fd32849e5108316b8fcc998a03ec /tex/context/base/l-dir.lua
parent01d65014d1238772b80f2c69dffca51b09c3a7a9 (diff)
downloadcontext-77b453ae2a132853da3e64286d612af49147b30f.tar.gz
stable 2007.12.17 14:54
Diffstat (limited to 'tex/context/base/l-dir.lua')
-rw-r--r--tex/context/base/l-dir.lua40
1 files changed, 26 insertions, 14 deletions
diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua
index dfacfb291..4ee2871ce 100644
--- a/tex/context/base/l-dir.lua
+++ b/tex/context/base/l-dir.lua
@@ -10,26 +10,32 @@ dir = { }
-- optimizing for no string.find (*) does not save time
-if lfs then
+if lfs then do
- function dir.glob_pattern(path,patt,recurse,action)
- local ok, scanner = xpcall(function() return lfs.dir(path) end, function() end) -- kepler safe
+ local attributes = lfs.attributes
+ local walkdir = lfs.dir
+
+ local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
if ok and type(scanner) == "function" then
+ if not path:find("/$") then path = path .. '/' end
for name in scanner do
- local full = path .. '/' .. name
- local mode = lfs.attributes(full,'mode')
+ local full = path .. name
+ local mode = attributes(full,'mode')
if mode == 'file' then
if name:find(patt) then
action(full)
end
elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- dir.glob_pattern(full,patt,recurse,action)
+ glob_pattern(full,patt,recurse,action)
end
end
end
end
- function dir.glob(pattern, action)
+ dir.glob_pattern = glob_pattern
+
+ local function glob(pattern, action)
local t = { }
local action = action or function(name) table.insert(t,name) end
local path, patt = pattern:match("^(.*)/*%*%*/*(.-)$")
@@ -45,22 +51,26 @@ if lfs then
patt = patt:gsub("%?", ".")
patt = "^" .. patt .. "$"
-- print('path: ' .. path .. ' | pattern: ' .. patt .. ' | recurse: ' .. tostring(recurse))
- dir.glob_pattern(path,patt,recurse,action)
+ glob_pattern(path,patt,recurse,action)
return t
end
- function dir.globfiles(path,recurse,func,files)
+ dir.glob = glob
+
+ -- todo: speedup
+
+ local function globfiles(path,recurse,func,files)
if type(func) == "string" then
local s = func -- alas, we need this indirect way
func = function(name) return name:find(s) end
end
files = files or { }
- for name in lfs.dir(path) do
+ for name in walkdir(path) do
if name:find("^%.") then
--- skip
- elseif lfs.attributes(name,'mode') == "directory" then
+ elseif attributes(name,'mode') == "directory" then
if recurse then
- dir.globfiles(path .. "/" .. name,recurse,func,files)
+ globfiles(path .. "/" .. name,recurse,func,files)
end
elseif func then
if func(name) then
@@ -73,6 +83,8 @@ if lfs then
return files
end
+ dir.globfiles = globfiles
+
-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
@@ -81,7 +93,7 @@ if lfs then
-- print(dir.ls("*.tex"))
function dir.ls(pattern)
- return table.concat(dir.glob(pattern),"\n")
+ return table.concat(glob(pattern),"\n")
end
--~ mkdirs("temp")
@@ -108,4 +120,4 @@ if lfs then
dir.makedirs = dir.mkdirs
-end
+end end