diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-04-07 17:58:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-04-07 17:58:00 +0200 |
commit | c63da592cc7ecde38ec1749525c072e79adebdcf (patch) | |
tree | 1c1f26222d9c7867d56ef32ecc5c993aec980354 /scripts | |
parent | 6de1d37f23278896de0a7f022c700ba5ff714904 (diff) | |
download | context-c63da592cc7ecde38ec1749525c072e79adebdcf.tar.gz |
beta 2010.04.07 17:58
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/luatools.lua | 128 | ||||
-rw-r--r-- | scripts/context/lua/mtx-tools.lua | 40 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 126 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/luatools.lua | 128 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 126 | ||||
-rwxr-xr-x | scripts/context/stubs/unix/luatools | 128 | ||||
-rwxr-xr-x | scripts/context/stubs/unix/mtxrun | 126 |
7 files changed, 341 insertions, 461 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua index 36c6c6e38..afff8a535 100644 --- a/scripts/context/lua/luatools.lua +++ b/scripts/context/lua/luatools.lua @@ -2548,6 +2548,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2626,29 +2632,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then + local t = t or { } + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2780,8 +2805,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2791,15 +2815,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -5253,64 +5275,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -5348,7 +5323,7 @@ function resolvers.getownpath() if not ownpath or ownpath == "" then ownpath = "." logs.report("fileio","forcing fallback ownpath .") - else + elseif trace_locating then logs.report("fileio","using ownpath '%s'",ownpath) end end @@ -5362,7 +5337,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -5729,7 +5704,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split diff --git a/scripts/context/lua/mtx-tools.lua b/scripts/context/lua/mtx-tools.lua index 5c90df071..5614b3c14 100644 --- a/scripts/context/lua/mtx-tools.lua +++ b/scripts/context/lua/mtx-tools.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['mtx-tools'] = { license = "see context related readme files" } -local find, format, sub, rep, gsub = string.find, string.format, string.sub, string.rep, string.gsub +local find, format, sub, rep, gsub, lower = string.find, string.format, string.sub, string.rep, string.gsub, string.lower scripts = scripts or { } scripts.tools = scripts.tools or { } @@ -42,6 +42,35 @@ function scripts.tools.disarmutfbomb() end end +function scripts.tools.downcase() + local pattern = environment.argument('pattern') or "*" + local recurse = environment.argument('recurse') + local force = environment.argument('force') + local n = 0 + if recurse and not find(pattern,"^%*%*%/") then + pattern = "**/*" .. pattern + end + dir.glob(pattern,function(name) + local basename = file.basename(name) + if lower(basename) ~= basename then + n = n + 1 + if force then + os.rename(name,lower(name)) + end + end + end) + if n > 0 then + if force then + logs.simple("%s files renamed",n) + else + logs.simple("use --force to do a real rename (%s files involved)",n) + end + else + logs.simple("nothing to do") + end +end + + function scripts.tools.dirtoxml() local join, removesuffix, extname, date = file.join, file.removesuffix, file.extname, os.date @@ -120,19 +149,26 @@ messages.help = [[ --force remove indeed --dirtoxml glob directory into xml - --pattern glob pattern (default: .*) + --pattern glob pattern (default: *) --url url attribute (no processing) --root the root of the globbed path (default: .) --output output filename (console by default) --recurse recurse into subdirecories --stripname take pathpart of given pattern --longname set name attributes to full path name + +--downcase + --pattern glob pattern (default: *) + --recurse recurse into subdirecories + --force downcase indeed ]] if environment.argument("disarmutfbomb") then scripts.tools.disarmutfbomb() elseif environment.argument("dirtoxml") then scripts.tools.dirtoxml() +elseif environment.argument("downcase") then + scripts.tools.downcase() else logs.help(messages.help) end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index d940eae46..d3942f7b3 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -2557,6 +2557,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2635,29 +2641,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then + local t = t or { } + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2789,8 +2814,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2800,15 +2824,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -8343,64 +8365,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -8452,7 +8427,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -8819,7 +8794,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua index 36c6c6e38..afff8a535 100644 --- a/scripts/context/stubs/mswin/luatools.lua +++ b/scripts/context/stubs/mswin/luatools.lua @@ -2548,6 +2548,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2626,29 +2632,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then + local t = t or { } + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2780,8 +2805,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2791,15 +2815,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -5253,64 +5275,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -5348,7 +5323,7 @@ function resolvers.getownpath() if not ownpath or ownpath == "" then ownpath = "." logs.report("fileio","forcing fallback ownpath .") - else + elseif trace_locating then logs.report("fileio","using ownpath '%s'",ownpath) end end @@ -5362,7 +5337,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -5729,7 +5704,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index d940eae46..d3942f7b3 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -2557,6 +2557,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2635,29 +2641,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then + local t = t or { } + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2789,8 +2814,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2800,15 +2824,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -8343,64 +8365,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -8452,7 +8427,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -8819,7 +8794,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split diff --git a/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools index 36c6c6e38..afff8a535 100755 --- a/scripts/context/stubs/unix/luatools +++ b/scripts/context/stubs/unix/luatools @@ -2548,6 +2548,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2626,29 +2632,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then + local t = t or { } + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2780,8 +2805,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2791,15 +2815,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -5253,64 +5275,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -5348,7 +5323,7 @@ function resolvers.getownpath() if not ownpath or ownpath == "" then ownpath = "." logs.report("fileio","forcing fallback ownpath .") - else + elseif trace_locating then logs.report("fileio","using ownpath '%s'",ownpath) end end @@ -5362,7 +5337,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -5729,7 +5704,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index d940eae46..d3942f7b3 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -2557,6 +2557,12 @@ local lpegmatch = lpeg.match dir = dir or { } +-- handy + +function dir.current() + return (gsub(lfs.currentdir(),"\\","/")) +end + -- optimizing for no string.find (*) does not save time local attributes = lfs.attributes @@ -2635,29 +2641,48 @@ local filter = Cs ( ( )^0 ) local function glob(str,t) - if type(str) == "table" then - local t = t or { } - for s=1,#str do - glob(str[s],t) + if type(t) == "function" then + if type(str) == "table" then + for s=1,#str do + glob(str[s],t) + end + elseif lfs.isfile(str) then + t(str) + else + local split = lpegmatch(pattern,str) + if split then + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,t) + end end - return t - elseif lfs.isfile(str) then - local t = t or { } - t[#t+1] = str - return t else - local split = lpegmatch(pattern,str) - if split then + if type(str) == "table" then local t = t or { } - local action = action or function(name) t[#t+1] = name end - local root, path, base = split[1], split[2], split[3] - local recurse = find(base,"%*%*") - local start = root .. path - local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + for s=1,#str do + glob(str[s],t) + end + return t + elseif lfs.isfile(str) then + local t = t or { } + t[#t+1] = str return t else - return { } + local split = lpegmatch(pattern,str) + if split then + local t = t or { } + local action = action or function(name) t[#t+1] = name end + local root, path, base = split[1], split[2], split[3] + local recurse = find(base,"%*%*") + local start = root .. path + local result = lpegmatch(filter,start .. base) + glob_pattern(start,result,recurse,action) + return t + else + return { } + end end end end @@ -2789,8 +2814,7 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" function dir.expand_name(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then - first = lfs.currentdir() .. "/" - first = gsub(first,"\\","/") + first = dir.current() .. "/" end if not first then first, last = match(str,"^(//)/*(.*)$") @@ -2800,15 +2824,13 @@ if string.find(os.getenv("PATH"),";") then -- os.type == "windows" if first and not find(last,"^/") then local d = lfs.currentdir() if lfs.chdir(first) then - first = lfs.currentdir() - first = gsub(first,"\\","/") + first = dir.current() end lfs.chdir(d) end end if not first then - first, last = lfs.currentdir(), str - first = gsub(first,"\\","/") + first, last = dir.current(), str end last = gsub(last,"//","/") last = gsub(last,"/%./","/") @@ -8343,64 +8365,17 @@ end local args = environment and environment.original_arguments or arg -- this needs a cleanup ---~ resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex" ---~ resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") ---~ resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin) - ---~ resolvers.autoselfdir = true -- false may be handy for debugging - ---~ function resolvers.getownpath() ---~ if not resolvers.ownpath then ---~ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then ---~ resolvers.ownpath = os.selfdir ---~ else ---~ local binary = resolvers.ownbin ---~ if os.binsuffix ~= "" then ---~ binary = file.replacesuffix(binary,os.binsuffix) ---~ end ---~ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do ---~ local b = file.join(p,binary) ---~ if lfs.isfile(b) then ---~ -- we assume that after changing to the path the currentdir function ---~ -- resolves to the real location and use this side effect here; this ---~ -- trick is needed because on the mac installations use symlinks in the ---~ -- path instead of real locations ---~ local olddir = lfs.currentdir() ---~ if lfs.chdir(p) then ---~ local pp = lfs.currentdir() ---~ if trace_locating and p ~= pp then ---~ logs.report("fileio","following symlink '%s' to '%s'",p,pp) ---~ end ---~ resolvers.ownpath = pp ---~ lfs.chdir(olddir) ---~ else ---~ if trace_locating then ---~ logs.report("fileio","unable to check path '%s'",p) ---~ end ---~ resolvers.ownpath = p ---~ end ---~ break ---~ end ---~ end ---~ end ---~ if not resolvers.ownpath then resolvers.ownpath = '.' end ---~ end ---~ return resolvers.ownpath ---~ end - -local args = environment and environment.original_arguments or arg -- this needs a cleanup - resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" -resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/") +resolvers.ownbin = gsub(resolvers.ownbin,"\\","/") function resolvers.getownpath() local ownpath = resolvers.ownpath or os.selfdir if not ownpath or ownpath == "" then ownpath = args[-1] or arg[-1] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) if not ownpath or ownpath == "" then ownpath = args[-0] or arg[-0] - ownpath = ownpath and file.dirname(string.gsub(ownpath,"\\","/")) + ownpath = ownpath and file.dirname(gsub(ownpath,"\\","/")) end local binary = resolvers.ownbin if not ownpath or ownpath == "" then @@ -8452,7 +8427,7 @@ end local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" } local function identify_own() - local ownpath = resolvers.getownpath() or lfs.currentdir() + local ownpath = resolvers.getownpath() or dir.current() local ie = instance.environment if ownpath then if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end @@ -8819,7 +8794,6 @@ end -- we join them and split them after the expansion has taken place. This -- is more convenient. - local checkedsplit = string.checkedsplit local normalsplit = string.split |