summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-context.lua6
-rw-r--r--scripts/context/lua/mtxrun.lua204
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua204
-rw-r--r--scripts/context/stubs/unix/mtxrun204
4 files changed, 363 insertions, 255 deletions
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua
index 36c71e463..8f2363229 100644
--- a/scripts/context/lua/mtx-context.lua
+++ b/scripts/context/lua/mtx-context.lua
@@ -66,7 +66,6 @@ expert options:
--update update context from website (not to be confused with contextgarden)
--profile profile job (use: mtxrun --script profile --analyze)
--timing generate timing and statistics overview
---tracefiles show some extra info when locating files (at the tex end)
--extra=name process extra (mtx-context-<name> in distribution)
--extras show extras
@@ -526,14 +525,15 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
--
setalways("%% feedback and basic job control")
--
- -- Option file, we can pass more on the commandline some day soon.
+ -- Option file, we can pass more on the commandline some day soon. Actually we
+ -- should use directives and trackers.
--
setfixed ("timing" , "\\usemodule[timing]")
setfixed ("batchmode" , "\\batchmode")
setfixed ("batch" , "\\batchmode")
setfixed ("nonstopmode" , "\\nonstopmode")
setfixed ("nonstop" , "\\nonstopmode")
- setfixed ("tracefiles" , "\\tracefilestrue")
+ -- setfixed ("tracefiles" , "\\tracefilestrue")
setfixed ("nostats" , "\\nomkivstatistics")
setfixed ("paranoid" , "\\def\\maxreadlevel{1}")
--
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 488594892..af7298858 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -3920,7 +3920,7 @@ local tables = utilities.tables
local format, gmatch, rep = string.format, string.gmatch, string.rep
local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
-local type, next, rawset = type, next, rawset
+local type, next, rawset, tonumber = type, next, rawset, tonumber
function tables.definetable(target) -- defines undefined tables
local composed, t, n = nil, { }, 0
@@ -3990,10 +3990,16 @@ end
local function toxml(t,d,result,step)
for k, v in table.sortedpairs(t) do
if type(v) == "table" then
- result[#result+1] = format("%s<%s>",d,k)
- toxml(v,d..step,result)
- result[#result+1] = format("%s</%s>",d,k)
- elseif tonumber(k) then
+ if type(k) == "number" then
+ result[#result+1] = format("%s<entry n='%s'>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</entry>",d,k)
+ else
+ result[#result+1] = format("%s<%s>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</%s>",d,k)
+ end
+ elseif type(k) == "number" then
result[#result+1] = format("%s<entry n='%s'>%s</entry>",d,k,v,k)
else
result[#result+1] = format("%s<%s>%s</%s>",d,k,tostring(v),k)
@@ -10739,7 +10745,7 @@ end
resolvers.updaterelations() -- push this in the metatable -> newindex
local function simplified(t,k)
- return rawget(t,lower(gsub(k," ","")))
+ return k and rawget(t,lower(gsub(k," ",""))) or nil
end
setmetatableindex(formats, simplified)
@@ -12197,9 +12203,22 @@ local function collect_files(names)
return noffiles > 0 and filelist or nil
end
-function resolvers.registerintrees(name)
- if not find(name,"^%.") then
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+local fit = { }
+
+function resolvers.registerintrees(filename,format,filetype,usedmethod,foundname)
+ local foundintrees = instance.foundintrees
+ if usedmethod == "direct" and filename == foundname and fit[foundname] then
+ -- just an extra lookup after a test on presence
+ else
+ local t = {
+ filename = filename,
+ format = format ~= "" and format or nil,
+ filetype = filetype ~= "" and filetype or nil,
+ usedmethod = usedmethod,
+ foundname = foundname,
+ }
+ fit[foundname] = t
+ foundintrees[#foundintrees+1] = t
end
end
@@ -12223,12 +12242,54 @@ local preparetreepattern = Cs((P(".")/"%%." + P("-")/"%%-" + P(1))^0 * Cc("$"))
local collect_instance_files
+local function find_analyze(filename,askedformat,allresults)
+ local filetype, wantedfiles, ext = '', { }, fileextname(filename)
+ -- too tricky as filename can be bla.1.2.3:
+ --
+ -- if not suffixmap[ext] then
+ -- wantedfiles[#wantedfiles+1] = filename
+ -- end
+ wantedfiles[#wantedfiles+1] = filename
+ if askedformat == "" then
+ if ext == "" or not suffixmap[ext] then
+ local defaultsuffixes = resolvers.defaultsuffixes
+ for i=1,#defaultsuffixes do
+ local forcedname = filename .. '.' .. defaultsuffixes[i]
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.formatofsuffix(forcedname)
+ if trace_locating then
+ report_resolving("forcing filetype '%s'",filetype)
+ end
+ end
+ else
+ filetype = resolvers.formatofsuffix(filename)
+ if trace_locating then
+ report_resolving("using suffix based filetype '%s'",filetype)
+ end
+ end
+ else
+ if ext == "" or not suffixmap[ext] then
+ local format_suffixes = suffixes[askedformat]
+ if format_suffixes then
+ for i=1,#format_suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
+ end
+ end
+ end
+ filetype = askedformat
+ if trace_locating then
+ report_resolving("using given filetype '%s'",filetype)
+ end
+ end
+ return filetype, wantedfiles
+end
+
local function find_direct(filename,allresults)
if not dangerous[askedformat] and isreadable(filename) then
if trace_detail then
report_resolving("file '%s' found directly",filename)
end
- return { filename }
+ return "direct", { filename }
end
end
@@ -12237,7 +12298,10 @@ local function find_wildcard(filename,allresults)
if trace_locating then
report_resolving("checking wildcard '%s'", filename)
end
- return resolvers.findwildcardfiles(filename) -- we can use the local
+ local method, result = resolvers.findwildcardfiles(filename)
+ if result then
+ return "wildcard", result
+ end
end
end
@@ -12252,7 +12316,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_detail then
report_resolving("qualified file '%s' found", filename)
end
- return { filename }
+ return "qualified", { filename }
end
if trace_detail then
report_resolving("locating qualified file '%s'", filename)
@@ -12268,12 +12332,12 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_locating then
report_resolving("no suffix, forcing format filetype '%s'", s)
end
- return { forcedname }
+ return "qualified", { forcedname }
end
end
end
end
- if suffix ~= "" then
+ if suffix and suffix ~= "" then
-- try to find in tree (no suffix manipulation), here we search for the
-- matching last part of the name
local basename = filebasename(filename)
@@ -12307,7 +12371,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
end
end
if #result > 0 then
- return result
+ return "qualified", result
end
end
end
@@ -12322,53 +12386,11 @@ local function find_qualified(filename,allresults) -- this one will be split too
-- end
-- end
-- if #result > 0 then
- -- return result
+ -- return "qualified", result
-- end
end
end
-local function find_analyze(filename,askedformat,allresults)
- local filetype, wantedfiles, ext = '', { }, fileextname(filename)
- -- too tricky as filename can be bla.1.2.3:
- --
- -- if not suffixmap[ext] then
- -- wantedfiles[#wantedfiles+1] = filename
- -- end
- wantedfiles[#wantedfiles+1] = filename
- if askedformat == "" then
- if ext == "" or not suffixmap[ext] then
- local defaultsuffixes = resolvers.defaultsuffixes
- for i=1,#defaultsuffixes do
- local forcedname = filename .. '.' .. defaultsuffixes[i]
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = resolvers.formatofsuffix(forcedname)
- if trace_locating then
- report_resolving("forcing filetype '%s'",filetype)
- end
- end
- else
- filetype = resolvers.formatofsuffix(filename)
- if trace_locating then
- report_resolving("using suffix based filetype '%s'",filetype)
- end
- end
- else
- if ext == "" or not suffixmap[ext] then
- local format_suffixes = suffixes[askedformat]
- if format_suffixes then
- for i=1,#format_suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
- end
- end
- end
- filetype = askedformat
- if trace_locating then
- report_resolving("using given filetype '%s'",filetype)
- end
- end
- return filetype, wantedfiles
-end
-
local function check_subpath(fname)
if isreadable(fname) then
if trace_detail then
@@ -12499,9 +12521,12 @@ local function find_intree(filename,filetype,wantedfiles,allresults)
end
-- todo recursive scanning
if done and not allresults then
- return #result > 0 and result
+ break
end
end
+ if #result > 0 then
+ return "intree", result
+ end
end
end
@@ -12520,36 +12545,40 @@ local function find_onpath(filename,filetype,wantedfiles,allresults)
end
end
end
- return #result > 0 and result
+ if #result > 0 then
+ return "onpath", result
+ end
end
local function find_otherwise(filename,filetype,wantedfiles,allresults) -- other text files | any | whatever
local filelist = collect_files(wantedfiles)
local fl = filelist and filelist[1]
if fl then
- return { resolvers.resolve(fl[3]) } -- filename
+ return "otherwise", { resolvers.resolve(fl[3]) } -- filename
end
end
+-- we could have a loop over the 6 functions but then we'd have to
+-- always analyze
+
collect_instance_files = function(filename,askedformat,allresults) -- uses nested
- local result, stamp, filetype, wantedfiles
askedformat = askedformat or ""
filename = collapsepath(filename)
if allresults then
-- no need for caching, only used for tracing
local filetype, wantedfiles = find_analyze(filename,askedformat)
local results = {
- { method = "direct", list = find_direct (filename,stamp,true) },
- { method = "wildcard", list = find_wildcard (filename,true) },
- { method = "qualified", list = find_qualified(filename,true) },
- { method = "in tree", list = find_intree (filename,filetype,wantedfiles,true) },
- { method = "on path", list = find_onpath (filename,filetype,wantedfiles,true) },
- { method = "otherwise", list = find_otherwise(filename,filetype,wantedfiles,true) },
+ { find_direct (filename,true) },
+ { find_wildcard (filename,true) },
+ { find_qualified(filename,true) },
+ { find_intree (filename,filetype,wantedfiles,true) },
+ { find_onpath (filename,filetype,wantedfiles,true) },
+ { find_otherwise(filename,filetype,wantedfiles,true) },
}
local result, status, done = { }, { }, { }
for k, r in next, results do
- local method, list = r.method, r.list
- if list then
+ local method, list = r[1], r[2]
+ if method and list then
for i=1,#list do
local c = collapsepath(list[i])
if not done[c] then
@@ -12565,6 +12594,7 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
end
return result, status
else
+ local method, result, stamp, filetype, wantedfiles
if instance.remember then
stamp = format("%s--%s", filename, askedformat)
result = stamp and instance.found[stamp]
@@ -12575,21 +12605,27 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
return result
end
end
- result = find_direct (filename,stamp) or
- find_wildcard (filename) or
- find_qualified(filename)
+ method, result = find_direct(filename)
if not result then
- local filetype, wantedfiles = find_analyze(filename,askedformat)
- result = find_intree (filename,filetype,wantedfiles) or
- find_onpath (filename,filetype,wantedfiles) or
- find_otherwise(filename,filetype,wantedfiles)
- end
- if result then
- for k=1,#result do
- local rk = collapsepath(result[k])
- result[k] = rk
- resolvers.registerintrees(rk) -- for tracing used files
+ method, result = find_wildcard(filename)
+ if not result then
+ method, result = find_qualified(filename)
+ if not result then
+ filetype, wantedfiles = find_analyze(filename,askedformat)
+ method, result = find_intree(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_onpath(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_otherwise(filename,filetype,wantedfiles)
+ end
+ end
+ end
end
+ end
+ if result and #result > 0 then
+ local foundname = collapsepath(result[1])
+ resolvers.registerintrees(filename,askedformat,filetype,method,foundname)
+ result = { foundname }
else
result = { } -- maybe false
end
@@ -14971,11 +15007,11 @@ function runners.execute_script(fullname,internal,nosplit)
environment.ownscript = result
dofile(result)
else
+ local binary = runners.applications[file.extname(result)]
result = string.quoted(string.unquoted(result))
-- if string.match(result,' ') and not string.match(result,"^\".*\"$") then
-- result = '"' .. result .. '"'
-- end
- local binary = runners.applications[file.extname(result)]
if binary and binary ~= "" then
result = binary .. " " .. result
end
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 488594892..af7298858 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -3920,7 +3920,7 @@ local tables = utilities.tables
local format, gmatch, rep = string.format, string.gmatch, string.rep
local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
-local type, next, rawset = type, next, rawset
+local type, next, rawset, tonumber = type, next, rawset, tonumber
function tables.definetable(target) -- defines undefined tables
local composed, t, n = nil, { }, 0
@@ -3990,10 +3990,16 @@ end
local function toxml(t,d,result,step)
for k, v in table.sortedpairs(t) do
if type(v) == "table" then
- result[#result+1] = format("%s<%s>",d,k)
- toxml(v,d..step,result)
- result[#result+1] = format("%s</%s>",d,k)
- elseif tonumber(k) then
+ if type(k) == "number" then
+ result[#result+1] = format("%s<entry n='%s'>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</entry>",d,k)
+ else
+ result[#result+1] = format("%s<%s>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</%s>",d,k)
+ end
+ elseif type(k) == "number" then
result[#result+1] = format("%s<entry n='%s'>%s</entry>",d,k,v,k)
else
result[#result+1] = format("%s<%s>%s</%s>",d,k,tostring(v),k)
@@ -10739,7 +10745,7 @@ end
resolvers.updaterelations() -- push this in the metatable -> newindex
local function simplified(t,k)
- return rawget(t,lower(gsub(k," ","")))
+ return k and rawget(t,lower(gsub(k," ",""))) or nil
end
setmetatableindex(formats, simplified)
@@ -12197,9 +12203,22 @@ local function collect_files(names)
return noffiles > 0 and filelist or nil
end
-function resolvers.registerintrees(name)
- if not find(name,"^%.") then
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+local fit = { }
+
+function resolvers.registerintrees(filename,format,filetype,usedmethod,foundname)
+ local foundintrees = instance.foundintrees
+ if usedmethod == "direct" and filename == foundname and fit[foundname] then
+ -- just an extra lookup after a test on presence
+ else
+ local t = {
+ filename = filename,
+ format = format ~= "" and format or nil,
+ filetype = filetype ~= "" and filetype or nil,
+ usedmethod = usedmethod,
+ foundname = foundname,
+ }
+ fit[foundname] = t
+ foundintrees[#foundintrees+1] = t
end
end
@@ -12223,12 +12242,54 @@ local preparetreepattern = Cs((P(".")/"%%." + P("-")/"%%-" + P(1))^0 * Cc("$"))
local collect_instance_files
+local function find_analyze(filename,askedformat,allresults)
+ local filetype, wantedfiles, ext = '', { }, fileextname(filename)
+ -- too tricky as filename can be bla.1.2.3:
+ --
+ -- if not suffixmap[ext] then
+ -- wantedfiles[#wantedfiles+1] = filename
+ -- end
+ wantedfiles[#wantedfiles+1] = filename
+ if askedformat == "" then
+ if ext == "" or not suffixmap[ext] then
+ local defaultsuffixes = resolvers.defaultsuffixes
+ for i=1,#defaultsuffixes do
+ local forcedname = filename .. '.' .. defaultsuffixes[i]
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.formatofsuffix(forcedname)
+ if trace_locating then
+ report_resolving("forcing filetype '%s'",filetype)
+ end
+ end
+ else
+ filetype = resolvers.formatofsuffix(filename)
+ if trace_locating then
+ report_resolving("using suffix based filetype '%s'",filetype)
+ end
+ end
+ else
+ if ext == "" or not suffixmap[ext] then
+ local format_suffixes = suffixes[askedformat]
+ if format_suffixes then
+ for i=1,#format_suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
+ end
+ end
+ end
+ filetype = askedformat
+ if trace_locating then
+ report_resolving("using given filetype '%s'",filetype)
+ end
+ end
+ return filetype, wantedfiles
+end
+
local function find_direct(filename,allresults)
if not dangerous[askedformat] and isreadable(filename) then
if trace_detail then
report_resolving("file '%s' found directly",filename)
end
- return { filename }
+ return "direct", { filename }
end
end
@@ -12237,7 +12298,10 @@ local function find_wildcard(filename,allresults)
if trace_locating then
report_resolving("checking wildcard '%s'", filename)
end
- return resolvers.findwildcardfiles(filename) -- we can use the local
+ local method, result = resolvers.findwildcardfiles(filename)
+ if result then
+ return "wildcard", result
+ end
end
end
@@ -12252,7 +12316,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_detail then
report_resolving("qualified file '%s' found", filename)
end
- return { filename }
+ return "qualified", { filename }
end
if trace_detail then
report_resolving("locating qualified file '%s'", filename)
@@ -12268,12 +12332,12 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_locating then
report_resolving("no suffix, forcing format filetype '%s'", s)
end
- return { forcedname }
+ return "qualified", { forcedname }
end
end
end
end
- if suffix ~= "" then
+ if suffix and suffix ~= "" then
-- try to find in tree (no suffix manipulation), here we search for the
-- matching last part of the name
local basename = filebasename(filename)
@@ -12307,7 +12371,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
end
end
if #result > 0 then
- return result
+ return "qualified", result
end
end
end
@@ -12322,53 +12386,11 @@ local function find_qualified(filename,allresults) -- this one will be split too
-- end
-- end
-- if #result > 0 then
- -- return result
+ -- return "qualified", result
-- end
end
end
-local function find_analyze(filename,askedformat,allresults)
- local filetype, wantedfiles, ext = '', { }, fileextname(filename)
- -- too tricky as filename can be bla.1.2.3:
- --
- -- if not suffixmap[ext] then
- -- wantedfiles[#wantedfiles+1] = filename
- -- end
- wantedfiles[#wantedfiles+1] = filename
- if askedformat == "" then
- if ext == "" or not suffixmap[ext] then
- local defaultsuffixes = resolvers.defaultsuffixes
- for i=1,#defaultsuffixes do
- local forcedname = filename .. '.' .. defaultsuffixes[i]
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = resolvers.formatofsuffix(forcedname)
- if trace_locating then
- report_resolving("forcing filetype '%s'",filetype)
- end
- end
- else
- filetype = resolvers.formatofsuffix(filename)
- if trace_locating then
- report_resolving("using suffix based filetype '%s'",filetype)
- end
- end
- else
- if ext == "" or not suffixmap[ext] then
- local format_suffixes = suffixes[askedformat]
- if format_suffixes then
- for i=1,#format_suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
- end
- end
- end
- filetype = askedformat
- if trace_locating then
- report_resolving("using given filetype '%s'",filetype)
- end
- end
- return filetype, wantedfiles
-end
-
local function check_subpath(fname)
if isreadable(fname) then
if trace_detail then
@@ -12499,9 +12521,12 @@ local function find_intree(filename,filetype,wantedfiles,allresults)
end
-- todo recursive scanning
if done and not allresults then
- return #result > 0 and result
+ break
end
end
+ if #result > 0 then
+ return "intree", result
+ end
end
end
@@ -12520,36 +12545,40 @@ local function find_onpath(filename,filetype,wantedfiles,allresults)
end
end
end
- return #result > 0 and result
+ if #result > 0 then
+ return "onpath", result
+ end
end
local function find_otherwise(filename,filetype,wantedfiles,allresults) -- other text files | any | whatever
local filelist = collect_files(wantedfiles)
local fl = filelist and filelist[1]
if fl then
- return { resolvers.resolve(fl[3]) } -- filename
+ return "otherwise", { resolvers.resolve(fl[3]) } -- filename
end
end
+-- we could have a loop over the 6 functions but then we'd have to
+-- always analyze
+
collect_instance_files = function(filename,askedformat,allresults) -- uses nested
- local result, stamp, filetype, wantedfiles
askedformat = askedformat or ""
filename = collapsepath(filename)
if allresults then
-- no need for caching, only used for tracing
local filetype, wantedfiles = find_analyze(filename,askedformat)
local results = {
- { method = "direct", list = find_direct (filename,stamp,true) },
- { method = "wildcard", list = find_wildcard (filename,true) },
- { method = "qualified", list = find_qualified(filename,true) },
- { method = "in tree", list = find_intree (filename,filetype,wantedfiles,true) },
- { method = "on path", list = find_onpath (filename,filetype,wantedfiles,true) },
- { method = "otherwise", list = find_otherwise(filename,filetype,wantedfiles,true) },
+ { find_direct (filename,true) },
+ { find_wildcard (filename,true) },
+ { find_qualified(filename,true) },
+ { find_intree (filename,filetype,wantedfiles,true) },
+ { find_onpath (filename,filetype,wantedfiles,true) },
+ { find_otherwise(filename,filetype,wantedfiles,true) },
}
local result, status, done = { }, { }, { }
for k, r in next, results do
- local method, list = r.method, r.list
- if list then
+ local method, list = r[1], r[2]
+ if method and list then
for i=1,#list do
local c = collapsepath(list[i])
if not done[c] then
@@ -12565,6 +12594,7 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
end
return result, status
else
+ local method, result, stamp, filetype, wantedfiles
if instance.remember then
stamp = format("%s--%s", filename, askedformat)
result = stamp and instance.found[stamp]
@@ -12575,21 +12605,27 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
return result
end
end
- result = find_direct (filename,stamp) or
- find_wildcard (filename) or
- find_qualified(filename)
+ method, result = find_direct(filename)
if not result then
- local filetype, wantedfiles = find_analyze(filename,askedformat)
- result = find_intree (filename,filetype,wantedfiles) or
- find_onpath (filename,filetype,wantedfiles) or
- find_otherwise(filename,filetype,wantedfiles)
- end
- if result then
- for k=1,#result do
- local rk = collapsepath(result[k])
- result[k] = rk
- resolvers.registerintrees(rk) -- for tracing used files
+ method, result = find_wildcard(filename)
+ if not result then
+ method, result = find_qualified(filename)
+ if not result then
+ filetype, wantedfiles = find_analyze(filename,askedformat)
+ method, result = find_intree(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_onpath(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_otherwise(filename,filetype,wantedfiles)
+ end
+ end
+ end
end
+ end
+ if result and #result > 0 then
+ local foundname = collapsepath(result[1])
+ resolvers.registerintrees(filename,askedformat,filetype,method,foundname)
+ result = { foundname }
else
result = { } -- maybe false
end
@@ -14971,11 +15007,11 @@ function runners.execute_script(fullname,internal,nosplit)
environment.ownscript = result
dofile(result)
else
+ local binary = runners.applications[file.extname(result)]
result = string.quoted(string.unquoted(result))
-- if string.match(result,' ') and not string.match(result,"^\".*\"$") then
-- result = '"' .. result .. '"'
-- end
- local binary = runners.applications[file.extname(result)]
if binary and binary ~= "" then
result = binary .. " " .. result
end
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 488594892..af7298858 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -3920,7 +3920,7 @@ local tables = utilities.tables
local format, gmatch, rep = string.format, string.gmatch, string.rep
local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
-local type, next, rawset = type, next, rawset
+local type, next, rawset, tonumber = type, next, rawset, tonumber
function tables.definetable(target) -- defines undefined tables
local composed, t, n = nil, { }, 0
@@ -3990,10 +3990,16 @@ end
local function toxml(t,d,result,step)
for k, v in table.sortedpairs(t) do
if type(v) == "table" then
- result[#result+1] = format("%s<%s>",d,k)
- toxml(v,d..step,result)
- result[#result+1] = format("%s</%s>",d,k)
- elseif tonumber(k) then
+ if type(k) == "number" then
+ result[#result+1] = format("%s<entry n='%s'>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</entry>",d,k)
+ else
+ result[#result+1] = format("%s<%s>",d,k)
+ toxml(v,d..step,result,step)
+ result[#result+1] = format("%s</%s>",d,k)
+ end
+ elseif type(k) == "number" then
result[#result+1] = format("%s<entry n='%s'>%s</entry>",d,k,v,k)
else
result[#result+1] = format("%s<%s>%s</%s>",d,k,tostring(v),k)
@@ -10739,7 +10745,7 @@ end
resolvers.updaterelations() -- push this in the metatable -> newindex
local function simplified(t,k)
- return rawget(t,lower(gsub(k," ","")))
+ return k and rawget(t,lower(gsub(k," ",""))) or nil
end
setmetatableindex(formats, simplified)
@@ -12197,9 +12203,22 @@ local function collect_files(names)
return noffiles > 0 and filelist or nil
end
-function resolvers.registerintrees(name)
- if not find(name,"^%.") then
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+local fit = { }
+
+function resolvers.registerintrees(filename,format,filetype,usedmethod,foundname)
+ local foundintrees = instance.foundintrees
+ if usedmethod == "direct" and filename == foundname and fit[foundname] then
+ -- just an extra lookup after a test on presence
+ else
+ local t = {
+ filename = filename,
+ format = format ~= "" and format or nil,
+ filetype = filetype ~= "" and filetype or nil,
+ usedmethod = usedmethod,
+ foundname = foundname,
+ }
+ fit[foundname] = t
+ foundintrees[#foundintrees+1] = t
end
end
@@ -12223,12 +12242,54 @@ local preparetreepattern = Cs((P(".")/"%%." + P("-")/"%%-" + P(1))^0 * Cc("$"))
local collect_instance_files
+local function find_analyze(filename,askedformat,allresults)
+ local filetype, wantedfiles, ext = '', { }, fileextname(filename)
+ -- too tricky as filename can be bla.1.2.3:
+ --
+ -- if not suffixmap[ext] then
+ -- wantedfiles[#wantedfiles+1] = filename
+ -- end
+ wantedfiles[#wantedfiles+1] = filename
+ if askedformat == "" then
+ if ext == "" or not suffixmap[ext] then
+ local defaultsuffixes = resolvers.defaultsuffixes
+ for i=1,#defaultsuffixes do
+ local forcedname = filename .. '.' .. defaultsuffixes[i]
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.formatofsuffix(forcedname)
+ if trace_locating then
+ report_resolving("forcing filetype '%s'",filetype)
+ end
+ end
+ else
+ filetype = resolvers.formatofsuffix(filename)
+ if trace_locating then
+ report_resolving("using suffix based filetype '%s'",filetype)
+ end
+ end
+ else
+ if ext == "" or not suffixmap[ext] then
+ local format_suffixes = suffixes[askedformat]
+ if format_suffixes then
+ for i=1,#format_suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
+ end
+ end
+ end
+ filetype = askedformat
+ if trace_locating then
+ report_resolving("using given filetype '%s'",filetype)
+ end
+ end
+ return filetype, wantedfiles
+end
+
local function find_direct(filename,allresults)
if not dangerous[askedformat] and isreadable(filename) then
if trace_detail then
report_resolving("file '%s' found directly",filename)
end
- return { filename }
+ return "direct", { filename }
end
end
@@ -12237,7 +12298,10 @@ local function find_wildcard(filename,allresults)
if trace_locating then
report_resolving("checking wildcard '%s'", filename)
end
- return resolvers.findwildcardfiles(filename) -- we can use the local
+ local method, result = resolvers.findwildcardfiles(filename)
+ if result then
+ return "wildcard", result
+ end
end
end
@@ -12252,7 +12316,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_detail then
report_resolving("qualified file '%s' found", filename)
end
- return { filename }
+ return "qualified", { filename }
end
if trace_detail then
report_resolving("locating qualified file '%s'", filename)
@@ -12268,12 +12332,12 @@ local function find_qualified(filename,allresults) -- this one will be split too
if trace_locating then
report_resolving("no suffix, forcing format filetype '%s'", s)
end
- return { forcedname }
+ return "qualified", { forcedname }
end
end
end
end
- if suffix ~= "" then
+ if suffix and suffix ~= "" then
-- try to find in tree (no suffix manipulation), here we search for the
-- matching last part of the name
local basename = filebasename(filename)
@@ -12307,7 +12371,7 @@ local function find_qualified(filename,allresults) -- this one will be split too
end
end
if #result > 0 then
- return result
+ return "qualified", result
end
end
end
@@ -12322,53 +12386,11 @@ local function find_qualified(filename,allresults) -- this one will be split too
-- end
-- end
-- if #result > 0 then
- -- return result
+ -- return "qualified", result
-- end
end
end
-local function find_analyze(filename,askedformat,allresults)
- local filetype, wantedfiles, ext = '', { }, fileextname(filename)
- -- too tricky as filename can be bla.1.2.3:
- --
- -- if not suffixmap[ext] then
- -- wantedfiles[#wantedfiles+1] = filename
- -- end
- wantedfiles[#wantedfiles+1] = filename
- if askedformat == "" then
- if ext == "" or not suffixmap[ext] then
- local defaultsuffixes = resolvers.defaultsuffixes
- for i=1,#defaultsuffixes do
- local forcedname = filename .. '.' .. defaultsuffixes[i]
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = resolvers.formatofsuffix(forcedname)
- if trace_locating then
- report_resolving("forcing filetype '%s'",filetype)
- end
- end
- else
- filetype = resolvers.formatofsuffix(filename)
- if trace_locating then
- report_resolving("using suffix based filetype '%s'",filetype)
- end
- end
- else
- if ext == "" or not suffixmap[ext] then
- local format_suffixes = suffixes[askedformat]
- if format_suffixes then
- for i=1,#format_suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. format_suffixes[i]
- end
- end
- end
- filetype = askedformat
- if trace_locating then
- report_resolving("using given filetype '%s'",filetype)
- end
- end
- return filetype, wantedfiles
-end
-
local function check_subpath(fname)
if isreadable(fname) then
if trace_detail then
@@ -12499,9 +12521,12 @@ local function find_intree(filename,filetype,wantedfiles,allresults)
end
-- todo recursive scanning
if done and not allresults then
- return #result > 0 and result
+ break
end
end
+ if #result > 0 then
+ return "intree", result
+ end
end
end
@@ -12520,36 +12545,40 @@ local function find_onpath(filename,filetype,wantedfiles,allresults)
end
end
end
- return #result > 0 and result
+ if #result > 0 then
+ return "onpath", result
+ end
end
local function find_otherwise(filename,filetype,wantedfiles,allresults) -- other text files | any | whatever
local filelist = collect_files(wantedfiles)
local fl = filelist and filelist[1]
if fl then
- return { resolvers.resolve(fl[3]) } -- filename
+ return "otherwise", { resolvers.resolve(fl[3]) } -- filename
end
end
+-- we could have a loop over the 6 functions but then we'd have to
+-- always analyze
+
collect_instance_files = function(filename,askedformat,allresults) -- uses nested
- local result, stamp, filetype, wantedfiles
askedformat = askedformat or ""
filename = collapsepath(filename)
if allresults then
-- no need for caching, only used for tracing
local filetype, wantedfiles = find_analyze(filename,askedformat)
local results = {
- { method = "direct", list = find_direct (filename,stamp,true) },
- { method = "wildcard", list = find_wildcard (filename,true) },
- { method = "qualified", list = find_qualified(filename,true) },
- { method = "in tree", list = find_intree (filename,filetype,wantedfiles,true) },
- { method = "on path", list = find_onpath (filename,filetype,wantedfiles,true) },
- { method = "otherwise", list = find_otherwise(filename,filetype,wantedfiles,true) },
+ { find_direct (filename,true) },
+ { find_wildcard (filename,true) },
+ { find_qualified(filename,true) },
+ { find_intree (filename,filetype,wantedfiles,true) },
+ { find_onpath (filename,filetype,wantedfiles,true) },
+ { find_otherwise(filename,filetype,wantedfiles,true) },
}
local result, status, done = { }, { }, { }
for k, r in next, results do
- local method, list = r.method, r.list
- if list then
+ local method, list = r[1], r[2]
+ if method and list then
for i=1,#list do
local c = collapsepath(list[i])
if not done[c] then
@@ -12565,6 +12594,7 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
end
return result, status
else
+ local method, result, stamp, filetype, wantedfiles
if instance.remember then
stamp = format("%s--%s", filename, askedformat)
result = stamp and instance.found[stamp]
@@ -12575,21 +12605,27 @@ collect_instance_files = function(filename,askedformat,allresults) -- uses neste
return result
end
end
- result = find_direct (filename,stamp) or
- find_wildcard (filename) or
- find_qualified(filename)
+ method, result = find_direct(filename)
if not result then
- local filetype, wantedfiles = find_analyze(filename,askedformat)
- result = find_intree (filename,filetype,wantedfiles) or
- find_onpath (filename,filetype,wantedfiles) or
- find_otherwise(filename,filetype,wantedfiles)
- end
- if result then
- for k=1,#result do
- local rk = collapsepath(result[k])
- result[k] = rk
- resolvers.registerintrees(rk) -- for tracing used files
+ method, result = find_wildcard(filename)
+ if not result then
+ method, result = find_qualified(filename)
+ if not result then
+ filetype, wantedfiles = find_analyze(filename,askedformat)
+ method, result = find_intree(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_onpath(filename,filetype,wantedfiles)
+ if not result then
+ method, result = find_otherwise(filename,filetype,wantedfiles)
+ end
+ end
+ end
end
+ end
+ if result and #result > 0 then
+ local foundname = collapsepath(result[1])
+ resolvers.registerintrees(filename,askedformat,filetype,method,foundname)
+ result = { foundname }
else
result = { } -- maybe false
end
@@ -14971,11 +15007,11 @@ function runners.execute_script(fullname,internal,nosplit)
environment.ownscript = result
dofile(result)
else
+ local binary = runners.applications[file.extname(result)]
result = string.quoted(string.unquoted(result))
-- if string.match(result,' ') and not string.match(result,"^\".*\"$") then
-- result = '"' .. result .. '"'
-- end
- local binary = runners.applications[file.extname(result)]
if binary and binary ~= "" then
result = binary .. " " .. result
end