summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2010-05-27 13:47:00 +0200
committerHans Hagen <pragma@wxs.nl>2010-05-27 13:47:00 +0200
commit37850ef35f93a14936b4d7d33790d14c050bbbb4 (patch)
tree74e469e150bd989ced66e107bd1d73a640149521 /scripts
parente08195a7149edffddb4b69b480676fad336a7613 (diff)
downloadcontext-37850ef35f93a14936b4d7d33790d14c050bbbb4.tar.gz
beta 2010.05.27 13:47
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/luatools.lua172
-rw-r--r--scripts/context/lua/mtxrun.lua126
-rw-r--r--scripts/context/ruby/base/kpse.rb18
-rw-r--r--scripts/context/stubs/mswin/luatools.lua172
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua126
-rwxr-xr-xscripts/context/stubs/unix/luatools172
-rwxr-xr-xscripts/context/stubs/unix/mtxrun126
7 files changed, 683 insertions, 229 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua
index 1d87322c1..d6d88b4fa 100644
--- a/scripts/context/lua/luatools.lua
+++ b/scripts/context/lua/luatools.lua
@@ -516,7 +516,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab
local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match
local getmetatable, setmetatable = getmetatable, setmetatable
local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs
-local unpack = unpack or table.unpack
+
+-- Starting with version 5.2 Lua no longer provide ipairs, which makes
+-- sense. As we already used the for loop and # in most places the
+-- impact on ConTeXt was not that large; the remaining ipairs already
+-- have been replaced. In a similar fashio we also hardly used pairs.
+--
+-- Just in case, we provide the fallbacks as discussed in Programming
+-- in Lua (http://www.lua.org/pil/7.3.html):
+
+if not ipairs then
+
+ -- for k, v in ipairs(t) do ... end
+ -- for k=1,#t do local v = t[k] ... end
+
+ local function iterate(a,i)
+ i = i + 1
+ local v = a[i]
+ if v ~= nil then
+ return i, v --, nil
+ end
+ end
+
+ function ipairs(a)
+ return iterate, a, 0
+ end
+
+end
+
+if not pairs then
+
+ -- for k, v in pairs(t) do ... end
+ -- for k, v in next, t do ... end
+
+ function pairs(t)
+ return next, t -- , nil
+ end
+
+end
+
+-- Also, unpack has been moved to the table table, and for compatiility
+-- reasons we provide both now.
+
+if not table.unpack then
+ table.unpack = _G.unpack
+elseif not unpack then
+ _G.unpack = table.unpack
+end
+
+-- extra functions, some might go (when not used)
function table.strip(tab)
local lst = { }
@@ -703,7 +751,7 @@ end
table.fastcopy = fastcopy
table.copy = copy
--- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
function table.sub(t,i,j)
return { unpack(t,i,j) }
@@ -726,7 +774,7 @@ function table.one_entry(t) -- obolete, use inline code instead
return n and not next(t,n)
end
---~ function table.starts_at(t) -- obsolete, not nice
+--~ function table.starts_at(t) -- obsolete, not nice anyway
--~ return ipairs(t,1)(t,0)
--~ end
@@ -1365,6 +1413,7 @@ function table.insert_after_value(t,value,extra)
end
+
end -- of closure
do -- create closure to overcome 200 locals limit
@@ -2039,41 +2088,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2126,7 +2210,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -3665,6 +3749,10 @@ function aux.accesstable(target)
return t
end
+--~ function string.commaseparated(str)
+--~ return gmatch(str,"([^,%s]+)")
+--~ end
+
-- as we use this a lot ...
--~ function aux.cachefunction(action,weak)
@@ -6078,8 +6166,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -6483,7 +6574,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -6545,6 +6637,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -6553,7 +6649,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -6567,10 +6663,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -6647,16 +6743,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -7501,11 +7597,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index b99327692..5a4919bab 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -2097,41 +2097,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2184,7 +2219,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -9328,8 +9363,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -9733,7 +9771,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -9795,6 +9834,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -9803,7 +9846,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -9817,10 +9860,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -9897,16 +9940,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -10104,6 +10147,8 @@ function resolvers.load(option)
resolvers.automount()
end
statistics.stoptiming(instance)
+ local files = instance.files
+ return files and next(files)
end
function resolvers.for_files(command, files, filetype, mustexist)
@@ -10866,11 +10911,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
@@ -12165,7 +12210,7 @@ function runners.execute_program(fullname)
return false
end
--- the --usekpse flag will fallback on kpse (hm, we can better update mtx-stubs)
+-- the --usekpse flag will fallback (not default) on kpse (hm, we can better update mtx-stubs)
local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
@@ -12560,7 +12605,14 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk
else
- resolvers.load()
+ if not resolvers.load() then
+ logs.simple("forcing cache reload")
+ instance.renewcache = true
+ logs.setverbose(true)
+ if not resolvers.load() then
+ logs.simple("there is something wrong with your system")
+ end
+ end
end
diff --git a/scripts/context/ruby/base/kpse.rb b/scripts/context/ruby/base/kpse.rb
index 0f9868784..313ebbe62 100644
--- a/scripts/context/ruby/base/kpse.rb
+++ b/scripts/context/ruby/base/kpse.rb
@@ -351,15 +351,25 @@ module Kpse
end
end
+ # def Kpse.runscript(name,filename=[],options=[])
+ # setscript(name,`texmfstart --locate #{name}`) unless @@scripts.key?(name)
+ # cmd = "#{@@scripts[name]} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
+ # system(cmd)
+ # end
+
+ # def Kpse.pipescript(name,filename=[],options=[])
+ # setscript(name,`texmfstart --locate #{name}`) unless @@scripts.key?(name)
+ # cmd = "#{@@scripts[name]} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
+ # `#{cmd}`
+ # end
+
def Kpse.runscript(name,filename=[],options=[])
- setscript(name,`texmfstart --locate #{name}`) unless @@scripts.key?(name)
- cmd = "#{@@scripts[name]} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
+ cmd = "mtxrun --script #{name} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
system(cmd)
end
def Kpse.pipescript(name,filename=[],options=[])
- setscript(name,`texmfstart --locate #{name}`) unless @@scripts.key?(name)
- cmd = "#{@@scripts[name]} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
+ cmd = "mtxrun --script #{name} #{[options].flatten.join(' ')} #{[filename].flatten.join(' ')}"
`#{cmd}`
end
diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua
index 1d87322c1..d6d88b4fa 100644
--- a/scripts/context/stubs/mswin/luatools.lua
+++ b/scripts/context/stubs/mswin/luatools.lua
@@ -516,7 +516,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab
local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match
local getmetatable, setmetatable = getmetatable, setmetatable
local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs
-local unpack = unpack or table.unpack
+
+-- Starting with version 5.2 Lua no longer provide ipairs, which makes
+-- sense. As we already used the for loop and # in most places the
+-- impact on ConTeXt was not that large; the remaining ipairs already
+-- have been replaced. In a similar fashio we also hardly used pairs.
+--
+-- Just in case, we provide the fallbacks as discussed in Programming
+-- in Lua (http://www.lua.org/pil/7.3.html):
+
+if not ipairs then
+
+ -- for k, v in ipairs(t) do ... end
+ -- for k=1,#t do local v = t[k] ... end
+
+ local function iterate(a,i)
+ i = i + 1
+ local v = a[i]
+ if v ~= nil then
+ return i, v --, nil
+ end
+ end
+
+ function ipairs(a)
+ return iterate, a, 0
+ end
+
+end
+
+if not pairs then
+
+ -- for k, v in pairs(t) do ... end
+ -- for k, v in next, t do ... end
+
+ function pairs(t)
+ return next, t -- , nil
+ end
+
+end
+
+-- Also, unpack has been moved to the table table, and for compatiility
+-- reasons we provide both now.
+
+if not table.unpack then
+ table.unpack = _G.unpack
+elseif not unpack then
+ _G.unpack = table.unpack
+end
+
+-- extra functions, some might go (when not used)
function table.strip(tab)
local lst = { }
@@ -703,7 +751,7 @@ end
table.fastcopy = fastcopy
table.copy = copy
--- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
function table.sub(t,i,j)
return { unpack(t,i,j) }
@@ -726,7 +774,7 @@ function table.one_entry(t) -- obolete, use inline code instead
return n and not next(t,n)
end
---~ function table.starts_at(t) -- obsolete, not nice
+--~ function table.starts_at(t) -- obsolete, not nice anyway
--~ return ipairs(t,1)(t,0)
--~ end
@@ -1365,6 +1413,7 @@ function table.insert_after_value(t,value,extra)
end
+
end -- of closure
do -- create closure to overcome 200 locals limit
@@ -2039,41 +2088,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2126,7 +2210,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -3665,6 +3749,10 @@ function aux.accesstable(target)
return t
end
+--~ function string.commaseparated(str)
+--~ return gmatch(str,"([^,%s]+)")
+--~ end
+
-- as we use this a lot ...
--~ function aux.cachefunction(action,weak)
@@ -6078,8 +6166,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -6483,7 +6574,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -6545,6 +6637,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -6553,7 +6649,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -6567,10 +6663,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -6647,16 +6743,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -7501,11 +7597,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index b99327692..5a4919bab 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -2097,41 +2097,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2184,7 +2219,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -9328,8 +9363,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -9733,7 +9771,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -9795,6 +9834,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -9803,7 +9846,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -9817,10 +9860,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -9897,16 +9940,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -10104,6 +10147,8 @@ function resolvers.load(option)
resolvers.automount()
end
statistics.stoptiming(instance)
+ local files = instance.files
+ return files and next(files)
end
function resolvers.for_files(command, files, filetype, mustexist)
@@ -10866,11 +10911,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
@@ -12165,7 +12210,7 @@ function runners.execute_program(fullname)
return false
end
--- the --usekpse flag will fallback on kpse (hm, we can better update mtx-stubs)
+-- the --usekpse flag will fallback (not default) on kpse (hm, we can better update mtx-stubs)
local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
@@ -12560,7 +12605,14 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk
else
- resolvers.load()
+ if not resolvers.load() then
+ logs.simple("forcing cache reload")
+ instance.renewcache = true
+ logs.setverbose(true)
+ if not resolvers.load() then
+ logs.simple("there is something wrong with your system")
+ end
+ end
end
diff --git a/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools
index 1d87322c1..d6d88b4fa 100755
--- a/scripts/context/stubs/unix/luatools
+++ b/scripts/context/stubs/unix/luatools
@@ -516,7 +516,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab
local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match
local getmetatable, setmetatable = getmetatable, setmetatable
local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs
-local unpack = unpack or table.unpack
+
+-- Starting with version 5.2 Lua no longer provide ipairs, which makes
+-- sense. As we already used the for loop and # in most places the
+-- impact on ConTeXt was not that large; the remaining ipairs already
+-- have been replaced. In a similar fashio we also hardly used pairs.
+--
+-- Just in case, we provide the fallbacks as discussed in Programming
+-- in Lua (http://www.lua.org/pil/7.3.html):
+
+if not ipairs then
+
+ -- for k, v in ipairs(t) do ... end
+ -- for k=1,#t do local v = t[k] ... end
+
+ local function iterate(a,i)
+ i = i + 1
+ local v = a[i]
+ if v ~= nil then
+ return i, v --, nil
+ end
+ end
+
+ function ipairs(a)
+ return iterate, a, 0
+ end
+
+end
+
+if not pairs then
+
+ -- for k, v in pairs(t) do ... end
+ -- for k, v in next, t do ... end
+
+ function pairs(t)
+ return next, t -- , nil
+ end
+
+end
+
+-- Also, unpack has been moved to the table table, and for compatiility
+-- reasons we provide both now.
+
+if not table.unpack then
+ table.unpack = _G.unpack
+elseif not unpack then
+ _G.unpack = table.unpack
+end
+
+-- extra functions, some might go (when not used)
function table.strip(tab)
local lst = { }
@@ -703,7 +751,7 @@ end
table.fastcopy = fastcopy
table.copy = copy
--- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
function table.sub(t,i,j)
return { unpack(t,i,j) }
@@ -726,7 +774,7 @@ function table.one_entry(t) -- obolete, use inline code instead
return n and not next(t,n)
end
---~ function table.starts_at(t) -- obsolete, not nice
+--~ function table.starts_at(t) -- obsolete, not nice anyway
--~ return ipairs(t,1)(t,0)
--~ end
@@ -1365,6 +1413,7 @@ function table.insert_after_value(t,value,extra)
end
+
end -- of closure
do -- create closure to overcome 200 locals limit
@@ -2039,41 +2088,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2126,7 +2210,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -3665,6 +3749,10 @@ function aux.accesstable(target)
return t
end
+--~ function string.commaseparated(str)
+--~ return gmatch(str,"([^,%s]+)")
+--~ end
+
-- as we use this a lot ...
--~ function aux.cachefunction(action,weak)
@@ -6078,8 +6166,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -6483,7 +6574,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -6545,6 +6637,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -6553,7 +6649,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -6567,10 +6663,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -6647,16 +6743,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -7501,11 +7597,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index b99327692..5a4919bab 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -2097,41 +2097,76 @@ local concat = table.concat
local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char
local lpegmatch = lpeg.match
-function file.removesuffix(filename)
- return (gsub(filename,"%.[%a%d]+$",""))
+local function dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
-function file.addsuffix(filename, suffix)
- if not suffix or suffix == "" then
- return filename
- elseif not find(filename,"%.[%a%d]+$") then
- return filename .. "." .. suffix
- else
- return filename
- end
+local function basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
end
-function file.replacesuffix(filename, suffix)
- return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+local function nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
-function file.dirname(name,default)
- return match(name,"^(.+)[/\\].-$") or (default or "")
+local function extname(name,default)
+ return match(name,"^.+%.([^/\\]-)$") or default or ""
end
-function file.basename(name)
- return match(name,"^.+[/\\](.-)$") or name
+local function splitname(name)
+ local n, s = match(name,"^(.+)%.([^/\\]-)$")
+ return n or name, s or ""
end
-function file.nameonly(name)
- return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+file.basename = basename
+file.dirname = dirname
+file.nameonly = nameonly
+file.extname = extname
+file.suffix = extname
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-function file.extname(name,default)
- return match(name,"^.+%.([^/\\]-)$") or default or ""
+function file.addsuffix(filename, suffix, criterium)
+ if not suffix or suffix == "" then
+ return filename
+ elseif criterium == true then
+ return filename .. "." .. suffix
+ else
+ local n, s = splitname(filename)
+ if s and s ~= "" then
+ local t = type(criterium)
+ if t == "table" then
+ -- keep if in criterium
+ for i=1,#criterium do
+ if s == criterium[i] then
+ return filename
+ end
+ end
+ elseif t == "string" then
+ -- keep if criterium
+ if s == criterium then
+ return filename
+ end
+ end
+ end
+ return n .. "." .. suffix
+ end
end
-file.suffix = file.extname
+--~ print(file.addsuffix("name","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new",true) .. "-> name.old.new")
+--~ print(file.addsuffix("name.old","new","new") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new","old") .. "-> name.old")
+--~ print(file.addsuffix("name.old","new","foo") .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"foo","bar"}) .. "-> name.new")
+--~ print(file.addsuffix("name.old","new",{"old","bar"}) .. "-> name.old")
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
--~ function file.join(...)
--~ local pth = concat({...},"/")
@@ -2184,7 +2219,7 @@ end
--~ print(file.join("//nas-1","/y"))
function file.iswritable(name)
- local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ local a = lfs.attributes(name) or lfs.attributes(dirname(name,"."))
return a and sub(a.permissions,2,2) == "w"
end
@@ -9328,8 +9363,11 @@ function resolvers.expand_variables()
local expansions, environment, variables = { }, instance.environment, instance.variables
local env = resolvers.env
instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
+ local engine, progname = instance.engine, instance.progname
+ if type(engine) ~= "string" then instance.engine, engine = "", "" end
+ if type(progname) ~= "string" then instance.progname, progname = "", "" end
+ if engine ~= "" then environment['engine'] = engine end
+ if progname ~= "" then environment['progname'] = progname end
for k,v in next, environment do
local a, b = match(k,"^(%a+)%_(.*)%s*$")
if a and b then
@@ -9733,7 +9771,8 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
else
local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
+ for i=1,#suffixes do
+ local s = suffixes[i]
forcedname = filename .. "." .. s
if resolvers.isreadable.file(forcedname) then
if trace_locating then
@@ -9795,6 +9834,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
else
-- search spec
local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ -- tricky as filename can be bla.1.2.3
+--~ if not suffixmap[ext] then --- probably needs to be done elsewhere too
+--~ wantedfiles[#wantedfiles+1] = filename
+--~ end
if ext == "" then
if not instance.force_suffixes then
wantedfiles[#wantedfiles+1] = filename
@@ -9803,7 +9846,7 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
wantedfiles[#wantedfiles+1] = filename
end
if instance.format == "" then
- if ext == "" then
+ if ext == "" or not suffixmap[ext] then
local forcedname = filename .. '.tex'
wantedfiles[#wantedfiles+1] = forcedname
filetype = resolvers.format_of_suffix(forcedname)
@@ -9817,10 +9860,10 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
end
end
else
- if ext == "" then
- local suffixes = resolvers.suffixes_of_format(instance.format)
- for _, s in next, suffixes do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ if ext == "" or not suffixmap[ext] then
+ for i=1,#suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. suffixes[i]
end
end
filetype = instance.format
@@ -9897,16 +9940,16 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = true
if instance.allresults then
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', continue scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d)
end
else
if trace_detail then
- logs.report("fileio","match in hash for file '%s' on path '%s', quit scanning",f,d)
+ logs.report("fileio","match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d)
end
break
end
elseif trace_detail then
- logs.report("fileio","no match in hash for file '%s' on path '%s'",f,d)
+ logs.report("fileio","no match to '%s' in hash for file '%s' and path '%s'",expression,f,d)
end
end
end
@@ -10104,6 +10147,8 @@ function resolvers.load(option)
resolvers.automount()
end
statistics.stoptiming(instance)
+ local files = instance.files
+ return files and next(files)
end
function resolvers.for_files(command, files, filetype, mustexist)
@@ -10866,11 +10911,11 @@ function statistics.check_fmt_status(texname)
local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
local luvbanner = luv.enginebanner or "?"
if luvbanner ~= enginebanner then
- return string.format("engine mismatch (luv:%s <> bin:%s)",luvbanner,enginebanner)
+ return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
end
local luvhash = luv.sourcehash or "?"
if luvhash ~= sourcehash then
- return string.format("source mismatch (luv:%s <> bin:%s)",luvhash,sourcehash)
+ return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
end
else
return "invalid status file"
@@ -12165,7 +12210,7 @@ function runners.execute_program(fullname)
return false
end
--- the --usekpse flag will fallback on kpse (hm, we can better update mtx-stubs)
+-- the --usekpse flag will fallback (not default) on kpse (hm, we can better update mtx-stubs)
local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
@@ -12560,7 +12605,14 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk
else
- resolvers.load()
+ if not resolvers.load() then
+ logs.simple("forcing cache reload")
+ instance.renewcache = true
+ logs.setverbose(true)
+ if not resolvers.load() then
+ logs.simple("there is something wrong with your system")
+ end
+ end
end