summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtxrun.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/lua/mtxrun.lua')
-rw-r--r--scripts/context/lua/mtxrun.lua108
1 files changed, 55 insertions, 53 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 2f203c3bc..b1327ae52 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -370,7 +370,10 @@ patterns.integer = sign^0 * digit^1
patterns.float = sign^0 * digit^0 * P('.') * digit^1
patterns.number = patterns.float + patterns.integer
patterns.oct = P("0") * R("07")^1
-patterns.hex = P("0x") * R("09","AF")^1
+patterns.octal = patterns.oct
+patterns.HEX = P("0x") * R("09","AF")^1
+patterns.hex = P("0x") * R("09","af")^1
+patterns.hexadecimal = P("0x") * R("09","AF","af")^1
patterns.lowercase = R("az")
patterns.uppercase = R("AZ")
patterns.letter = patterns.lowercase + patterns.uppercase
@@ -460,40 +463,23 @@ end
--~ local p = pp
--~ for l=1,#list do
--~ if p then
---~ p = p + lpeg.P(list[l])
+--~ p = p + P(list[l])
--~ else
---~ p = lpeg.P(list[l])
+--~ p = P(list[l])
--~ end
--~ end
--~ return p
--~ end
--~ from roberto's site:
---~
---~ local function f1 = string.byte
---~
---~ local function f2(s)
---~ local c1, c2 = string.byte(s, 1, 2)
---~ return c1 * 64 + c2 - 12416
---~ end
---~
---~ local function f3(s)
---~ local c1, c2, c3 = string.byte(s, 1, 3)
---~ return (c1 * 64 + c2) * 64 + c3 - 925824
---~ end
---~
---~ local function f4(s)
---~ local c1, c2, c3, c4 = string.byte(s, 1, 4)
---~ return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168
---~ end
---~
---~ local cont = lpeg.R("\128\191") -- continuation byte
---~ local utf8 = lpeg.R("\0\127") / f1
---~ + lpeg.R("\194\223") * cont / f2
---~ + lpeg.R("\224\239") * cont * cont / f3
---~ + lpeg.R("\240\244") * cont * cont * cont / f4
---~
---~ local decode_pattern = lpeg.Ct(utf8^0) * -1
+
+local f1 = string.byte
+
+local function f2(s) local c1, c2 = f1(s,1,2) return c1 * 64 + c2 - 12416 end
+local function f3(s) local c1, c2, c3 = f1(s,1,3) return (c1 * 64 + c2) * 64 + c3 - 925824 end
+local function f4(s) local c1, c2, c3, c4 = f1(s,1,4) return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168 end
+
+patterns.utf8byte = patterns.utf8one/f1 + patterns.utf8two/f2 + patterns.utf8three/f3 + patterns.utf8four/f4
end -- of closure
@@ -2038,7 +2024,9 @@ function file.removesuffix(filename)
end
function file.addsuffix(filename, suffix)
- if not find(filename,"%.[%a%d]+$") then
+ if not suffix or suffix == "" then
+ return filename
+ elseif not find(filename,"%.[%a%d]+$") then
return filename .. "." .. suffix
else
return filename
@@ -3216,7 +3204,7 @@ local comma = lpeg.P(",")
local lbrace = lpeg.P("{")
local rbrace = lpeg.P("}")
local nobrace = 1 - (lbrace+rbrace)
-local nested = lpeg.P{ lbrace * (nobrace + lpeg.V(1))^0 * rbrace }
+local nested = lpeg.P { lbrace * (nobrace + lpeg.V(1))^0 * rbrace }
local spaces = space^0
local value = lpeg.P(lbrace * lpeg.C((nobrace + nested)^0) * rbrace) + lpeg.C((nested + (1-comma))^0)
@@ -5430,10 +5418,10 @@ local lp_or = P("|") / " or "
local lp_and = P("&") / " and "
local lp_builtin = P (
-P("firstindex") / "1" +
-P("lastindex") / "(#ll.__p__.dt or 1)" +
-P("firstelement") / "1" +
-P("lastelement") / "(ll.__p__.en or 1)" +
+ P("firstindex") / "1" +
+ P("lastindex") / "(#ll.__p__.dt or 1)" +
+ P("firstelement") / "1" +
+ P("lastelement") / "(ll.__p__.en or 1)" +
P("first") / "1" +
P("last") / "#list" +
P("rootposition") / "order" +
@@ -5443,7 +5431,7 @@ P("lastelement") / "(ll.__p__.en or 1)" +
P("index") / "(ll.ni or 1)" +
P("match") / "(ll.mi or 1)" +
P("text") / "(ll.dt[1] or '')" +
---~ P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+ -- P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
P("name") / "((ll.ns~='' and ll.ns..':'..ll.tg) or ll.tg)" +
P("tag") / "ll.tg" +
P("ns") / "ll.ns"
@@ -7402,6 +7390,8 @@ function statistics.starttiming(instance)
if not instance.loadtime then
instance.loadtime = 0
end
+ else
+--~ logs.report("system","nested timing (%s)",tostring(instance))
end
instance.timing = it + 1
end
@@ -7870,6 +7860,11 @@ end
--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
--~ end
+function logs.fatal(where,...)
+ logs.report(where,"fatal error: %s, aborting now",format(...))
+ os.exit()
+end
+
end -- of closure
@@ -8346,20 +8341,24 @@ end
-- also we now follow the stupid route: if not set then just assume *one*
-- cnf file under texmf (i.e. distribution)
-resolvers.ownpath = resolvers.ownpath or nil
-resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+local args = environment and environment.original_arguments or arg -- this needs a cleanup
+
+resolvers.ownbin = resolvers.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg [0] or "luatex"
+resolvers.ownbin = string.gsub(resolvers.ownbin,"\\","/")
+resolvers.ownpath = resolvers.ownpath or file.dirname(resolvers.ownbin)
+
resolvers.autoselfdir = true -- false may be handy for debugging
function resolvers.getownpath()
if not resolvers.ownpath then
- if resolvers.autoselfdir and os.selfdir then
+ if resolvers.autoselfdir and os.selfdir and os.selfdir ~= "" then
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
if os.binsuffix ~= "" then
binary = file.replacesuffix(binary,os.binsuffix)
end
- for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do -- can be helper
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
if lfs.isfile(b) then
-- we assume that after changing to the path the currentdir function
@@ -9490,19 +9489,21 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
end
--
- local resolved = collect_instance_files(basename)
- if #result == 0 then
- local lowered = lower(basename)
- if filename ~= lowered then
- resolved = collect_instance_files(lowered)
+ if basename ~= filename then
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
end
- end
- resolvers.format = savedformat
- --
- for r=1,#resolved do
- local rr = resolved[r]
- if find(rr,pattern) then
- result[#result+1], ok = rr, true
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if find(rr,pattern) then
+ result[#result+1], ok = rr, true
+ end
end
end
-- a real wildcard:
@@ -9714,7 +9715,7 @@ function resolvers.find_given_files(filename)
local hashes = instance.hashes
for k=1,#hashes do
local hash = hashes[k]
- local files = instance.files[hash.tag]
+ local files = instance.files[hash.tag] or { }
local blist = files[bname]
if not blist then
local rname = "remap:"..bname
@@ -11557,7 +11558,8 @@ end
-- End of hack.
-own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+
own.path = string.match(own.name,"^(.+)[\\/].-$") or "."
own.list = { '.' }