From 1e76a7198e92b4382646643dd5fa479f3e9e329d Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 29 Mar 2010 18:49:00 +0200 Subject: beta 2010.03.29 18:49 --- scripts/context/lua/luatools.lua | 93 ++++++++++++------------- scripts/context/lua/mtx-context.lua | 4 +- scripts/context/lua/mtxrun.lua | 108 +++++++++++++++--------------- scripts/context/stubs/mswin/luatools.lua | 93 ++++++++++++------------- scripts/context/stubs/mswin/mtxrun.dll | Bin 9216 -> 9216 bytes scripts/context/stubs/mswin/mtxrun.lua | 108 +++++++++++++++--------------- scripts/context/stubs/source/mtxrun_dll.c | 94 +++++++++++++------------- scripts/context/stubs/unix/luatools | 93 ++++++++++++------------- scripts/context/stubs/unix/mtxrun | 108 +++++++++++++++--------------- 9 files changed, 356 insertions(+), 345 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua index ea3b47840..9a04cc0b2 100644 --- a/scripts/context/lua/luatools.lua +++ b/scripts/context/lua/luatools.lua @@ -361,7 +361,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 @@ -451,40 +454,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 @@ -2029,7 +2015,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 @@ -3406,7 +3394,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) @@ -4312,6 +4300,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 @@ -4780,6 +4770,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 @@ -5256,13 +5251,17 @@ 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 @@ -6400,19 +6399,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: @@ -6624,7 +6625,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 diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 446f5b78f..93a0577ea 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -1238,14 +1238,14 @@ end -- todo: we need to do a dummy run function scripts.context.trackers() - environment.files = { "m-trackers" } + environment.files = { resolvers.find_file("m-trackers.tex") } scripts.context.multipass.nofruns = 1 scripts.context.run() -- maybe filter from log end function scripts.context.directives() - environment.files = { "m-directives" } + environment.files = { resolvers.find_file("m-directives.tex") } scripts.context.multipass.nofruns = 1 scripts.context.run() -- maybe filter from log 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 = { '.' } diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua index ea3b47840..9a04cc0b2 100644 --- a/scripts/context/stubs/mswin/luatools.lua +++ b/scripts/context/stubs/mswin/luatools.lua @@ -361,7 +361,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 @@ -451,40 +454,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 @@ -2029,7 +2015,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 @@ -3406,7 +3394,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) @@ -4312,6 +4300,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 @@ -4780,6 +4770,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 @@ -5256,13 +5251,17 @@ 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 @@ -6400,19 +6399,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: @@ -6624,7 +6625,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 diff --git a/scripts/context/stubs/mswin/mtxrun.dll b/scripts/context/stubs/mswin/mtxrun.dll index 3b9e876d0..1ccb76efc 100644 Binary files a/scripts/context/stubs/mswin/mtxrun.dll and b/scripts/context/stubs/mswin/mtxrun.dll differ diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 2f203c3bc..b1327ae52 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/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 = { '.' } diff --git a/scripts/context/stubs/source/mtxrun_dll.c b/scripts/context/stubs/source/mtxrun_dll.c index 67acdd7f9..540bed38b 100644 --- a/scripts/context/stubs/source/mtxrun_dll.c +++ b/scripts/context/stubs/source/mtxrun_dll.c @@ -5,8 +5,8 @@ Public Domain Originally written in 2010 by Tomasz M. Trzeciak and Hans Hagen - This program is derived from the 'runscript' program originally - written in 2009 by T.M. Trzeciak. It has been adapted for use in + This program is derived from the 'runscript' program originally + written in 2009 by T.M. Trzeciak. It has been adapted for use in ConTeXt MkIV. Comment: @@ -18,26 +18,26 @@ mtxrun --script font --reload Here mtxrun is a lua script. In order to avoid the usage of a cmd - file on windows this runner will start texlua directly. If the - shared library luatex.dll is available, texlua will be started in - the same process avoiding thus any additional overhead. Otherwise + file on windows this runner will start texlua directly. If the + shared library luatex.dll is available, texlua will be started in + the same process avoiding thus any additional overhead. Otherwise it will be spawned in a new proces. We also don't want to use other runners, like those that use kpse to locate the script as this is exactly what mtxrun itself is doing already. Therefore the runscript program is adapted to a more direct approach suitable for mtxrun. - + Compilation: with gcc (size optimized): - gcc -Os -s -shared -o mtxrun.dll mtxrun_dll.c + gcc -Os -s -shared -o mtxrun.dll mtxrun_dll.c gcc -Os -s -o mtxrun.exe mtxrun_exe.c -L./ -lmtxrun with tcc (extra small size): - - tcc -shared -o mtxrun.dll mtxrun_dll.c + + tcc -shared -o mtxrun.dll mtxrun_dll.c tcc -o mtxrun.exe mtxrun_exe.c mtxrun.def ************************************************************************/ @@ -64,9 +64,9 @@ HMODULE dllluatex = NULL; typedef int ( *mainlikeproc )( int, char ** ); #ifdef STATIC -int main( int argc, char *argv[] ) +int main( int argc, char *argv[] ) #else -__declspec(dllexport) int dllrunscript( int argc, char *argv[] ) +__declspec(dllexport) int dllrunscript( int argc, char *argv[] ) #endif { char *s, *argstr, **lua_argv; @@ -74,30 +74,32 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) int passprogname = 0; // directory of this module/executable - - HMODULE module_handle = GetModuleHandle( "mtxrun.dll" ); + + HMODULE module_handle = GetModuleHandle( "mtxrun.dll" ); // if ( module_handle == NULL ) exe path will be used, which is OK too k = (int) GetModuleFileName( module_handle, dirpath, MAX_PATH ); - if ( !k || ( k == MAX_PATH ) ) + if ( !k || ( k == MAX_PATH ) ) DIE( "unable to determine a valid module name\n" ); s = strrchr(dirpath, '\\'); if ( s == NULL ) DIE( "no directory part in module path: %s\n", dirpath ); *(++s) = '\0'; //remove file name, leave trailing backslash - + // program name - + k = strlen(argv[0]); while ( k && (argv[0][k] != '/') && (argv[0][k] != '\\') ) k--; + if ((argv[0][k] == '/') || (argv[0][k] == '\\')) k++; // correct for slash + // while ( k && (argv[0][k-1] != '/') && (argv[0][k-1] != '\\') ) k--; strcpy(progname, &argv[0][k]); s = progname; if ( s = strrchr(s, '.') ) *s = '\0'; // remove file extension part - + // script path - + strcpy( scriptpath, dirpath ); k = strlen(progname); if ( k < 6 ) k = 6; // in case the program name is shorter than "mtxrun" - if ( strlen(dirpath) + k + 4 >= MAX_PATH ) + if ( strlen(dirpath) + k + 4 >= MAX_PATH ) DIE( "path too long: %s%s\n", dirpath, progname ); if ( ( strcmpi(progname,"mtxrun") == 0 ) || ( strcmpi(progname,"luatools") == 0 ) ) { strcat( scriptpath, progname ); @@ -106,19 +108,19 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) strcat( scriptpath, "mtxrun.lua" ); if ( strcmpi(progname,"texmfstart") != 0 ) passprogname = 1; } - if ( GetFileAttributes(scriptpath) == INVALID_FILE_ATTRIBUTES ) + if ( GetFileAttributes(scriptpath) == INVALID_FILE_ATTRIBUTES ) DIE( "file not found: %s\n", scriptpath ); - + // link with luatex.dll if available - + if ( dllluatex = LoadLibrary("luatex.dll") ) { mainlikeproc dllluatexmain = (mainlikeproc) GetProcAddress( dllluatex, "dllluatexmain" ); - if ( dllluatexmain == NULL ) + if ( dllluatexmain == NULL ) DIE( "unable to locate dllluatexmain procedure in luatex.dll" ); - + // set up argument list for texlua script - + lua_argv = (char **)malloc( (argc + 4) * sizeof(char *) ); if ( lua_argv == NULL ) DIE( "out of memory\n" ); lua_argv[lua_argc=0] = texlua_name; @@ -126,22 +128,22 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) if (passprogname) { lua_argv[++lua_argc] = "--script"; lua_argv[++lua_argc] = progname; - } + } for ( k = 1; k < argc; k++ ) lua_argv[++lua_argc] = argv[k]; lua_argv[++lua_argc] = NULL; // call texlua interpreter // dllluatexmain never returns, but we pretend that it does - + k = dllluatexmain( lua_argc, lua_argv ); if (lua_argv) free( lua_argv ); return k; } - + // we are still here, so no luatex.dll; spawn texlua.exe instead - + strcpy( cmdline, "\"" ); - if ( !SearchPath( + if ( !SearchPath( getenv( "PATH" ), // path to search (optional) "texlua.exe", // file name to search NULL, // file extension to add (optional) @@ -156,24 +158,24 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) strcat( cmdline, " --script " ); strcat( cmdline, progname ); } - + argstr = GetCommandLine(); // get the command line of this process if ( argstr == NULL ) DIE( "unable to retrieve the command line string\n" ); // skip over argv[0] in the argument string // (it can contain embedded double quotes if launched from cmd.exe!) - - for ( quoted = 0; (*argstr) && ( !IS_WHITESPACE(*argstr) || quoted ); argstr++ ) + + for ( quoted = 0; (*argstr) && ( !IS_WHITESPACE(*argstr) || quoted ); argstr++ ) if (*argstr == '"') quoted = !quoted; - + // pass through all the arguments - - if ( strlen(cmdline) + strlen(argstr) >= MAX_CMD ) + + if ( strlen(cmdline) + strlen(argstr) >= MAX_CMD ) DIE( "command line string too long:\n%s%s\n", cmdline, argstr ); - strcat( cmdline, argstr ); - + strcat( cmdline, argstr ); + // create child process - + STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); @@ -185,7 +187,7 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) si.hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE ); si.hStdError = GetStdHandle( STD_ERROR_HANDLE ); ZeroMemory( &pi, sizeof(pi) ); - + if( !CreateProcess( NULL, // module name (uses command line if NULL) cmdline, // command line @@ -198,17 +200,17 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] ) &si, // STARTUPINFO structure &pi ) // PROCESS_INFORMATION structure ) DIE( "command execution failed: %s\n", cmdline ); - + DWORD ret = 0; CloseHandle( pi.hThread ); // thread handle is not needed if ( WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0 ) { - if ( !GetExitCodeProcess( pi.hProcess, &ret) ) + if ( !GetExitCodeProcess( pi.hProcess, &ret) ) DIE( "unable to retrieve process exit code: %s\n", cmdline ); } else DIE( "failed to wait for process termination: %s\n", cmdline ); CloseHandle( pi.hProcess ); - + // propagate exit code from the child process - - return ret; - + + return ret; + } diff --git a/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools index ea3b47840..9a04cc0b2 100755 --- a/scripts/context/stubs/unix/luatools +++ b/scripts/context/stubs/unix/luatools @@ -361,7 +361,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 @@ -451,40 +454,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 @@ -2029,7 +2015,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 @@ -3406,7 +3394,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) @@ -4312,6 +4300,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 @@ -4780,6 +4770,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 @@ -5256,13 +5251,17 @@ 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 @@ -6400,19 +6399,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: @@ -6624,7 +6625,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 diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 2f203c3bc..b1327ae52 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -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 = { '.' } -- cgit v1.2.3