summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/l-dir.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/l-dir.lua82
1 files changed, 37 insertions, 45 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua b/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua
index b0b2c52836a..bc691d53635 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/l-dir.lua
@@ -75,8 +75,7 @@ function dir.current()
return (gsub(currentdir(),"\\","/"))
end
--- The next one is somewhat optimized but still slow but it's a pitty that the iterator
--- doesn't return a mode too.
+-- somewhat optimized
local function glob_pattern_function(path,patt,recurse,action)
if isdir(path) then
@@ -90,7 +89,6 @@ local function glob_pattern_function(path,patt,recurse,action)
usedpath = path
end
local dirs
- local nofdirs = 0
for name in walkdir(usedpath) do
if name ~= "." and name ~= ".." then
local full = path .. name
@@ -100,18 +98,16 @@ local function glob_pattern_function(path,patt,recurse,action)
action(full)
end
elseif recurse and mode == "directory" then
- if dirs then
- nofdirs = nofdirs + 1
- dirs[nofdirs] = full
+ if not dirs then
+ dirs = { full }
else
- nofdirs = 1
- dirs = { full }
+ dirs[#dirs+1] = full
end
end
end
end
if dirs then
- for i=1,nofdirs do
+ for i=1,#dirs do
glob_pattern_function(dirs[i],patt,recurse,action)
end
end
@@ -122,41 +118,38 @@ local function glob_pattern_table(path,patt,recurse,result)
if not result then
result = { }
end
- local usedpath
- if path == "/" then
- usedpath = "/."
- elseif not find(path,"/$") then
- usedpath = path .. "/."
- path = path .. "/"
- else
- usedpath = path
- end
- local dirs
- local nofdirs = 0
- local noffiles = #result
- for name, a in walkdir(usedpath) do
- if name ~= "." and name ~= ".." then
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if not patt or find(full,patt) then
- noffiles = noffiles + 1
- result[noffiles] = full
- end
- elseif recurse and mode == "directory" then
- if dirs then
- nofdirs = nofdirs + 1
- dirs[nofdirs] = full
- else
- nofdirs = 1
- dirs = { full }
+ if isdir(path) then
+ local usedpath
+ if path == "/" then
+ usedpath = "/."
+ elseif not find(path,"/$") then
+ usedpath = path .. "/."
+ path = path .. "/"
+ else
+ usedpath = path
+ end
+ local dirs
+ for name in walkdir(usedpath) do
+ if name ~= "." and name ~= ".." then
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if not patt or find(full,patt) then
+ result[#result+1] = full
+ end
+ elseif recurse and mode == "directory" then
+ if not dirs then
+ dirs = { full }
+ else
+ dirs[#dirs+1] = full
+ end
end
end
end
- end
- if dirs then
- for i=1,nofdirs do
- glob_pattern_table(dirs[i],patt,recurse,result)
+ if dirs then
+ for i=1,#dirs do
+ glob_pattern_table(dirs[i],patt,recurse,result)
+ end
end
end
return result
@@ -167,13 +160,12 @@ local function globpattern(path,patt,recurse,method)
if patt and sub(patt,1,-3) == path then
patt = false
end
- local okay = isdir(path)
if kind == "function" then
- return okay and glob_pattern_function(path,patt,recurse,method) or { }
+ return glob_pattern_function(path,patt,recurse,method)
elseif kind == "table" then
- return okay and glob_pattern_table(path,patt,recurse,method) or method
+ return glob_pattern_table(path,patt,recurse,method)
else
- return okay and glob_pattern_table(path,patt,recurse,{ }) or { }
+ return glob_pattern_table(path,patt,recurse,{ })
end
end