summaryrefslogtreecommitdiff
path: root/scripts/context/lua/luatools.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/lua/luatools.lua')
-rw-r--r--scripts/context/lua/luatools.lua138
1 files changed, 67 insertions, 71 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua
index e46337223..cd7ee1ed5 100644
--- a/scripts/context/lua/luatools.lua
+++ b/scripts/context/lua/luatools.lua
@@ -1774,6 +1774,8 @@ end
-- Beware, loading and saving is overloaded in luat-tmp!
+-- todo: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+
if not versions then versions = { } end versions['luat-inp'] = 1.001
if not environment then environment = { } end
if not file then file = { } end
@@ -1881,6 +1883,7 @@ function input.reset()
instance.files = { }
instance.remap = { }
instance.configuration = { }
+ instance.order = { }
instance.found = { }
instance.foundintrees = { }
instance.kpsevars = { }
@@ -2135,14 +2138,14 @@ function input.load_cnf(instance)
end
function input.loadconfigdata(instance)
- for _, fname in pairs(instance.cnffiles) do
+ for _, fname in ipairs(instance.cnffiles) do
input.aux.load_cnf(instance,fname)
end
end
if os.env then
function input.aux.collapse_cnf_data(instance)
- for _,c in pairs(instance.configuration) do
+ for _,c in ipairs(instance.order) do
for k,v in pairs(c) do
if not instance.variables[k] then
if instance.environment[k] then
@@ -2157,7 +2160,7 @@ if os.env then
end
else
function input.aux.collapse_cnf_data(instance)
- for _,c in pairs(instance.configuration) do
+ for _,c in ipairs(instance.order) do
for k,v in pairs(c) do
if not instance.variables[k] then
local e = os.getenv(k)
@@ -2180,7 +2183,11 @@ function input.aux.load_cnf(instance,fname)
local f = io.open(lname)
if f then
f:close()
- input.aux.load_data(instance,file.dirname(lname),'configuration',file.basename(lname))
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ input.aux.load_data(instance,dname,'configuration',file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
else
f = io.open(fname)
if f then
@@ -2189,6 +2196,7 @@ function input.aux.load_cnf(instance,fname)
local dname = file.dirname(fname)
if not instance.configuration[dname] then
instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
end
local data = instance.configuration[dname]
while true do
@@ -2344,7 +2352,7 @@ function input.generators.tex(instance,specification)
input.report("scanning path",specification)
instance.files[tag] = { }
local files = instance.files[tag]
- local n, m = 0, 0
+ local n, m, r = 0, 0, 0
local spec = specification .. '/'
local attributes = lfs.attributes
local directory = lfs.dir
@@ -2384,6 +2392,7 @@ function input.generators.tex(instance,specification)
local lower = name:lower()
if name ~= lower then
files["remap:"..lower] = name
+ r = r + 1
end
end
end
@@ -2391,7 +2400,7 @@ function input.generators.tex(instance,specification)
end
end
action()
- input.report(n,"files found on",m,"directories")
+ input.report(string.format("%s files found on %s directories with %s uppercase remappings",n,m,r))
else
local fullname = file.join(specification,input.lsrname)
local path = '.'
@@ -2442,7 +2451,7 @@ end
-- is more convenient.
function input.splitconfig(instance)
- for i,c in pairs(instance.configuration) do
+ for i,c in ipairs(instance.order) do
for k,v in pairs(c) do
if type(v) == 'string' then
local t = file.split_path(v)
@@ -2454,7 +2463,7 @@ function input.splitconfig(instance)
end
end
function input.joinconfig(instance)
- for i,c in pairs(instance.configuration) do
+ for i,c in ipairs(instance.order) do
for k,v in pairs(c) do
if type(v) == 'table' then
c[k] = file.join_path(v)
@@ -2567,10 +2576,12 @@ function input.aux.save_data(instance, dataname, check)
end
function input.loadconfig(instance)
- instance.configuration, instance.loaderror = { }, false
+ instance.configuration, instance.order, instance.loaderror = { }, { }, false
if not instance.renewcache then
- for _, cnf in pairs(instance.cnffiles) do
- input.aux.load_data(instance,file.dirname(cnf),'configuration')
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ input.aux.load_data(instance,dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
if instance.loaderror then break end
end
end
@@ -2726,7 +2737,7 @@ function input.list_configurations(instance)
for _,key in pairs(table.sortedkeys(instance.kpsevars)) do
if not instance.pattern or (instance.pattern=="") or key:find(instance.pattern) then
print(key.."\n")
- for i,c in pairs(instance.configuration) do
+ for i,c in ipairs(instance.order) do
local str = c[key]
if str then
print("\t" .. i .. "\t\t" .. input.aux.tabstr(str))
@@ -2879,8 +2890,7 @@ function input.aux.expanded_path(instance,pathlist)
local pre, mid, post = v:match(pattern)
if pre and mid and post then
more = true
---~ for vv in string.gmatch(mid..',',"(.-),") do
- for vv in string.gmatch(mid,"([^,]+)") do
+ for vv in string.gmatch(mid..',',"(.-),") do
if vv == '.' then
t[#t+1] = pre..post
else
@@ -2895,13 +2905,12 @@ function input.aux.expanded_path(instance,pathlist)
if not more then break end
end
end
- for _,v in pairs(oldlist) do
+ for _,v in ipairs(oldlist) do
v = file.collapse_path(v)
if v ~= "" and not v:find(instance.dummy_path_expr) then newlist[#newlist+1] = v end
end
else
- for _,v in pairs(pathlist) do
- -- for _,vv in pairs(v:split(",")) do
+ for _,v in ipairs(pathlist) do
for vv in string.gmatch(v..',',"(.-),") do
vv = file.collapse_path(v)
if vv ~= "" then newlist[#newlist+1] = vv end
@@ -2952,7 +2961,7 @@ function input.aux.collect_files(instance,names)
else
dname = "/" .. dname .. "$"
end
- for _, hash in pairs(instance.hashes) do
+ for _, hash in ipairs(instance.hashes) do
local blobpath = hash.tag
local files = blobpath and instance.files[blobpath]
if files then
@@ -3086,15 +3095,15 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
if ext == "" then
if not instance.force_suffixes then
- table.insert(wantedfiles, filename)
+ wantedfiles[#wantedfiles+1] = filename
end
else
- table.insert(wantedfiles, filename)
+ wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
if ext == "" then
local forcedname = filename .. '.tex'
- table.insert(wantedfiles, forcedname)
+ wantedfiles[#wantedfiles+1] = forcedname
filetype = input.format_of_suffix(forcedname)
input.logger('! forcing filetype',filetype)
else
@@ -3104,7 +3113,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
else
if ext == "" then
for _, s in pairs(input.suffixes_of_format(instance.format)) do
- table.insert(wantedfiles, filename .. "." .. s)
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
end
end
filetype = instance.format
@@ -3122,7 +3131,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
for _, fname in pairs(wantedfiles) do
if fname and input.is_readable.file(fname) then
filename, done = fname, true
- table.insert(result, file.join('.',fname))
+ result[#result+1] = file.join('.',fname)
break
end
end
@@ -3130,7 +3139,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
local filelist = input.aux.collect_files(instance,wantedfiles)
filename = filelist and filelist[1]
if filename then
- table.insert(result, filename)
+ result[#result+1] = filename
done = true
end
else
@@ -3162,7 +3171,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
if input.trace > 2 then
input.logger('= found in hash',f)
end
- table.insert(result,f)
+ result[#result+1] = f
input.aux.register_in_trees(instance,f) -- for tracing used files
done = true
if not instance.allresults then break end
@@ -3184,7 +3193,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec
if input.trace > 2 then
input.logger('= found by scanning',fname)
end
- table.insert(result,fname)
+ result[#result+1] = fname
done = true
if not instance.allresults then break end
end
@@ -3275,15 +3284,23 @@ end
function input.find_given_files(instance,filename)
local bname, result = file.basename(filename), { }
- for k, hash in pairs(instance.hashes) do
+ for k, hash in ipairs(instance.hashes) do
local blist = instance.files[hash.tag][bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
if blist then
if type(blist) == 'string' then
- table.insert(result,input.concatinators[hash.type](hash.tag,blist,bname) or "")
+ result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
if not instance.allresults then break end
else
for kk,vv in pairs(blist) do
- table.insert(result,input.concatinators[hash.type](hash.tag,vv,bname) or "")
+ result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
if not instance.allresults then break end
end
end
@@ -3296,35 +3313,7 @@ function input.find_given_file(instance,filename)
return (input.find_given_files(instance,filename)[1] or "")
end
---~ function input.find_wildcard_files(instance,filename)
---~ local result = { }
---~ local bname, dname = file.basename(filename), file.dirname(filename)
---~ local expr = dname:gsub("^*/","")
---~ expr = expr:gsub("*",".*")
---~ expr = expr:gsub("-","%-")
---~ for k, hash in pairs(instance.hashes) do
---~ local blist = instance.files[hash.tag][bname]
---~ if blist then
---~ if type(blist) == 'string' then
---~ -- make function and share code
---~ if blist:find(expr) then
---~ table.insert(result,input.concatinators[hash.type](hash.tag,blist,bname) or "")
---~ if not instance.allresults then break end
---~ end
---~ else
---~ for kk,vv in pairs(blist) do
---~ if vv:find(expr) then
---~ table.insert(result,input.concatinators[hash.type](hash.tag,vv,bname) or "")
---~ if not instance.allresults then break end
---~ end
---~ end
---~ end
---~ end
---~ end
---~ return result
---~ end
-
-function input.find_wildcard_files(instance,filename)
+function input.find_wildcard_files(instance,filename) -- todo: remap:
local result = { }
local bname, dname = file.basename(filename), file.dirname(filename)
local path = dname:gsub("^*/","")
@@ -3344,13 +3333,13 @@ function input.find_wildcard_files(instance,filename)
if type(blist) == 'string' then
-- make function and share code
if (blist:lower()):find(path) then
- table.insert(result,input.concatinators[hash.type](hash.tag,blist,bname) or "")
+ result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
done = true
end
else
for kk,vv in pairs(blist) do
if (vv:lower()):find(path) then
- table.insert(result,input.concatinators[hash.type](hash.tag,vv,bname) or "")
+ result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
done = true
if not allresults then break end
end
@@ -3361,7 +3350,7 @@ function input.find_wildcard_files(instance,filename)
end
local files, allresults, done = instance.files, instance.allresults, false
if name:find("%*") then
- for k, hash in pairs(instance.hashes) do
+ for k, hash in ipairs(instance.hashes) do
for kk, hh in pairs(files[hash.tag]) do
if (kk:lower()):find(name) then
if doit(hh,kk,hash,allresults) then done = true end
@@ -3370,7 +3359,7 @@ function input.find_wildcard_files(instance,filename)
end
end
else
- for k, hash in pairs(instance.hashes) do
+ for k, hash in ipairs(instance.hashes) do
if doit(files[hash.tag][bname],bname,hash,allresults) then done = true end
if done and not allresults then break end
end
@@ -3610,17 +3599,24 @@ function input.do_with_var(name,func)
end
function input.with_files(instance,pattern,handle)
- for _, hash in pairs(instance.hashes) do
+ for _, hash in ipairs(instance.hashes) do
local blobpath = hash.tag
local blobtype = hash.type
- if blobpath and instance.files[blobpath] then -- sort them?
- for k,v in pairs(instance.files[blobpath]) do
- if k:find(pattern) then
- if type(v) == "string" then
- handle(blobtype,blobpath,v,k)
- else
- for _,vv in pairs(v) do
- handle(blobtype,blobpath,vv,k)
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in pairs(files) do
+ if k:find("^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if k:find(pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do
+ handle(blobtype,blobpath,vv,k)
+ end
end
end
end