summaryrefslogtreecommitdiff
path: root/scripts/context/stubs/unix/mtxrun
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/stubs/unix/mtxrun')
-rw-r--r--scripts/context/stubs/unix/mtxrun425
1 files changed, 232 insertions, 193 deletions
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 0c3355fcc..6aae96c4f 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -2675,7 +2675,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-io"] = package.loaded["l-io"] or true
--- original size: 10421, stripped down to: 7499
+-- original size: 12255, stripped down to: 7256
if not modules then modules={} end modules ['l-io']={
version=1.001,
@@ -2695,44 +2695,30 @@ if string.find(os.getenv("PATH"),";",1,true) then
else
io.fileseparator,io.pathseparator="/",":"
end
-local function readall(f)
- return f:read("*all")
-end
+local large=2^24
+local medium=large/16
+local small=medium/8
local function readall(f)
local size=f:seek("end")
- if size==0 then
- return ""
- end
- f:seek("set",0)
- if size<1024*1024 then
- return f:read('*all')
+ if size>0 then
+ f:seek("set",0)
+ return f:read(size)
else
- local step
- if size>16*1024*1024 then
- step=16*1024*1024
- else
- step=floor(size/(1024*1024))*1024*1024/8
- end
- local data={}
- while true do
- local r=f:read(step)
- if not r then
- return concat(data)
- else
- data[#data+1]=r
- end
- end
+ return ""
end
end
io.readall=readall
function io.loaddata(filename,textmode)
local f=open(filename,(textmode and 'r') or 'rb')
if f then
- local data=readall(f)
- f:close()
- if #data>0 then
- return data
+ local size=f:seek("end")
+ local data=nil
+ if size>0 then
+ f:seek("set",0)
+ data=f:read(size)
end
+ f:close()
+ return data
end
end
function io.copydata(source,target,action)
@@ -2741,37 +2727,14 @@ function io.copydata(source,target,action)
local g=open(target,"wb")
if g then
local size=f:seek("end")
- if size==0 then
- else
+ if size>0 then
f:seek("set",0)
- if size<1024*1024 then
- local data=f:read('*all')
- if action then
- data=action(data)
- end
- if data then
- g:write(data)
- end
- else
- local step
- if size>16*1024*1024 then
- step=16*1024*1024
- else
- step=floor(size/(1024*1024))*1024*1024/8
- end
- while true do
- local data=f:read(step)
- if data then
- if action then
- data=action(data)
- end
- if data then
- g:write(data)
- end
- else
- break
- end
- end
+ local data=f:read(size)
+ if action then
+ data=action(data)
+ end
+ if data then
+ g:write(data)
end
end
g:close()
@@ -2797,29 +2760,59 @@ function io.savedata(filename,data,joiner)
return false
end
end
-function io.loadlines(filename,n)
- local f=open(filename,'r')
- if not f then
- elseif n then
- local lines={}
- for i=1,n do
- local line=f:read("*lines")
- if line then
- lines[#lines+1]=line
- else
- break
+if fio.readline then
+ local readline=fio.readline
+ function io.loadlines(filename,n)
+ local f=open(filename,'r')
+ if not f then
+ elseif n then
+ local lines={}
+ for i=1,n do
+ local line=readline(f)
+ if line then
+ lines[i]=line
+ else
+ break
+ end
+ end
+ f:close()
+ lines=concat(lines,"\n")
+ if #lines>0 then
+ return lines
+ end
+ else
+ local line=readline(f)
+ f:close()
+ if line and #line>0 then
+ return line
end
end
- f:close()
- lines=concat(lines,"\n")
- if #lines>0 then
- return lines
- end
- else
- local line=f:read("*line") or ""
- f:close()
- if #line>0 then
- return line
+ end
+else
+ function io.loadlines(filename,n)
+ local f=open(filename,'r')
+ if not f then
+ elseif n then
+ local lines={}
+ for i=1,n do
+ local line=f:read("*lines")
+ if line then
+ lines[i]=line
+ else
+ break
+ end
+ end
+ f:close()
+ lines=concat(lines,"\n")
+ if #lines>0 then
+ return lines
+ end
+ else
+ local line=f:read("*line") or ""
+ f:close()
+ if #line>0 then
+ return line
+ end
end
end
end
@@ -2980,7 +2973,7 @@ function io.ask(question,default,options)
end
end
end
-local function readnumber(f,n,m)
+local function readnumber(f,n,m)
if m then
f:seek("set",n)
n=m
@@ -2989,31 +2982,31 @@ local function readnumber(f,n,m)
return byte(f:read(1))
elseif n==2 then
local a,b=byte(f:read(2),1,2)
- return 256*a+b
+ return 0x100*a+b
elseif n==3 then
local a,b,c=byte(f:read(3),1,3)
- return 256*256*a+256*b+c
+ return 0x10000*a+0x100*b+c
elseif n==4 then
local a,b,c,d=byte(f:read(4),1,4)
- return 256*256*256*a+256*256*b+256*c+d
+ return 0x1000000*a+0x10000*b+0x100*c+d
elseif n==8 then
local a,b=readnumber(f,4),readnumber(f,4)
- return 256*a+b
+ return 0x100*a+b
elseif n==12 then
local a,b,c=readnumber(f,4),readnumber(f,4),readnumber(f,4)
- return 256*256*a+256*b+c
+ return 0x10000*a+0x100*b+c
elseif n==-2 then
local b,a=byte(f:read(2),1,2)
- return 256*a+b
+ return 0x100*a+b
elseif n==-3 then
local c,b,a=byte(f:read(3),1,3)
- return 256*256*a+256*b+c
+ return 0x10000*a+0x100*b+c
elseif n==-4 then
local d,c,b,a=byte(f:read(4),1,4)
- return 256*256*256*a+256*256*b+256*c+d
+ return 0x1000000*a+0x10000*b+0x100*c+d
elseif n==-8 then
local h,g,f,e,d,c,b,a=byte(f:read(8),1,8)
- return 256*256*256*256*256*256*256*a+256*256*256*256*256*256*b+256*256*256*256*256*c+256*256*256*256*d+256*256*256*e+256*256*f+256*g+h
+ return 0x100000000000000*a+0x1000000000000*b+0x10000000000*c+0x100000000*d+0x1000000*e+0x10000*f+0x100*g+h
else
return 0
end
@@ -3274,7 +3267,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["l-os"] = package.loaded["l-os"] or true
--- original size: 16520, stripped down to: 9519
+-- original size: 16834, stripped down to: 9513
if not modules then modules={} end modules ['l-os']={
version=1.001,
@@ -3610,7 +3603,7 @@ if not os.sleep then
end
end
local function isleapyear(year)
- return (year%400==0) or ((year%100~=0) and (year%4==0))
+ return (year%4==0) and (year%100~=0 or year%400==0)
end
os.isleapyear=isleapyear
local days={ 31,28,31,30,31,30,31,31,30,31,30,31 }
@@ -7042,7 +7035,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-fil"] = package.loaded["util-fil"] or true
--- original size: 6362, stripped down to: 4907
+-- original size: 7597, stripped down to: 5761
if not modules then modules={} end modules ['util-fil']={
version=1.001,
@@ -7111,6 +7104,10 @@ end
function files.readbytes(f,n)
return byte(f:read(n),1,n)
end
+function files.readbytetable(f,n)
+ local s=f:read(n or 1)
+ return { byte(s,1,#s) }
+end
function files.readchar(f)
return f:read(1)
end
@@ -7199,21 +7196,12 @@ function files.readcardinal4le(f)
end
function files.readinteger4(f)
local a,b,c,d=byte(f:read(4),1,4)
- local n=0x1000000*a+0x10000*b+0x100*c+d
- if n>=0x8000000 then
- return n-0x100000000
+ if a>=0x80 then
+ return 0x1000000*a+0x10000*b+0x100*c+d-0x100000000
else
- return n
+ return 0x1000000*a+0x10000*b+0x100*c+d
end
end
- function files.readinteger4(f)
- local a,b,c,d=byte(f:read(4),1,4)
- if a>=0x80 then
- return 0x1000000*a+0x10000*b+0x100*c+d-0x100000000
- else
- return 0x1000000*a+0x10000*b+0x100*c+d
- end
- end
function files.readinteger4le(f)
local d,c,b,a=byte(f:read(4),1,4)
local n=0x1000000*a+0x10000*b+0x100*c+d
@@ -7225,11 +7213,10 @@ function files.readinteger4le(f)
end
function files.readfixed4(f)
local a,b,c,d=byte(f:read(4),1,4)
- local n=0x100*a+b
- if n>=0x8000 then
- return n-0x10000+(0x100*c+d)/0xFFFF
+ if a>=0x80 then
+ return (0x1000000*a+0x10000*b+0x100*c+d-0x100000000)/65536.0
else
- return n+(0x100*c+d)/0xFFFF
+ return (0x1000000*a+0x10000*b+0x100*c+d)/65536.0
end
end
if extract then
@@ -7274,6 +7261,34 @@ end
function files.writebyte(f,b)
f:write(char(b))
end
+if fio and fio.readcardinal1 then
+ files.readcardinal1=fio.readcardinal1
+ files.readcardinal2=fio.readcardinal2
+ files.readcardinal3=fio.readcardinal3
+ files.readcardinal4=fio.readcardinal4
+ files.readinteger1=fio.readinteger1
+ files.readinteger2=fio.readinteger2
+ files.readinteger3=fio.readinteger3
+ files.readinteger4=fio.readinteger4
+ files.readfixed4=fio.readfixed4
+ files.read2dot14=fio.read2dot14
+ files.setposition=fio.setposition
+ files.getposition=fio.getposition
+ files.readbyte=files.readcardinel1
+ files.readsignedbyte=files.readinteger1
+ files.readcardinal=files.readcardinal1
+ files.readinteger=files.readinteger1
+ local skipposition=fio.skipposition
+ files.skipposition=skipposition
+ files.readbytes=fio.readbytes
+ files.readbytetable=fio.readbytetable
+ function files.skipshort(f,n)
+ skipposition(f,2*(n or 1))
+ end
+ function files.skiplong(f,n)
+ skipposition(f,4*(n or 1))
+ end
+end
end -- of closure
@@ -7282,7 +7297,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-sac"] = package.loaded["util-sac"] or true
--- original size: 4360, stripped down to: 3409
+-- original size: 4634, stripped down to: 3514
if not modules then modules={} end modules ['util-sac']={
version=1.001,
@@ -7350,6 +7365,12 @@ function streams.readbytes(f,n)
f[2]=j
return byte(f[1],i,j-1)
end
+function streams.readbytetable(f,n)
+ local i=f[2]
+ local j=i+n
+ f[2]=j
+ return { byte(f[1],i,j-1) }
+end
function streams.skipbytes(f,n)
f[2]=f[2]+n
end
@@ -7369,7 +7390,7 @@ function streams.readinteger1(f)
f[2]=i+1
local n=byte(f[1],i)
if n>=0x80 then
- return n-0xFF-1
+ return n-0x100
else
return n
end
@@ -7391,7 +7412,7 @@ function streams.readinteger2(f)
local a,b=byte(f[1],i,j)
local n=0x100*a+b
if n>=0x8000 then
- return n-0xFFFF-1
+ return n-0x10000
else
return n
end
@@ -7417,7 +7438,7 @@ function streams.readinteger4(f)
local a,b,c,d=byte(f[1],i,j)
local n=0x1000000*a+0x10000*b+0x100*c+d
if n>=0x8000000 then
- return n-0xFFFFFFFF-1
+ return n-0x100000000
else
return n
end
@@ -7429,7 +7450,7 @@ function streams.readfixed4(f)
local a,b,c,d=byte(f[1],i,j)
local n=0x100*a+b
if n>=0x8000 then
- return n-0xFFFF-1+(0x100*c+d)/0xFFFF
+ return n-0x10000+(0x100*c+d)/0xFFFF
else
return n+(0x100*c+d)/0xFFFF
end
@@ -9826,7 +9847,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-deb"] = package.loaded["util-deb"] or true
--- original size: 8473, stripped down to: 6211
+-- original size: 9211, stripped down to: 6727
if not modules then modules={} end modules ['util-deb']={
version=1.001,
@@ -9837,9 +9858,10 @@ if not modules then modules={} end modules ['util-deb']={
}
local debug=require "debug"
local getinfo,sethook=debug.getinfo,debug.sethook
-local type,next,tostring=type,next,tostring
+local type,next,tostring,tonumber=type,next,tostring,tonumber
local format,find,sub,gsub=string.format,string.find,string.sub,string.gsub
local insert,remove,sort=table.insert,table.remove,table.sort
+local setmetatableindex=table.setmetatableindex
utilities=utilities or {}
local debugger=utilities.debugger or {}
utilities.debugger=debugger
@@ -9850,55 +9872,62 @@ local overhead=0
local dummycalls=10*1000
local nesting=0
local names={}
-local function initialize()
- if FFISUPPORTED and ffi then
- if os.type=="windows" then
- local okay,kernel=pcall(ffi.load,"kernel32")
- if kernel then
- local tonumber=ffi.number or tonumber
-ffi.cdef[[
-int QueryPerformanceFrequency(int64_t *lpFrequency);
-int QueryPerformanceCounter(int64_t *lpPerformanceCount);
-]]
- local target=ffi.new("__int64[1]")
- ticks=function()
- if kernel.QueryPerformanceCounter(target)==1 then
- return tonumber(target[0])
- else
- return 0
- end
- end
- local target=ffi.new("__int64[1]")
- seconds=function(ticks)
- if kernel.QueryPerformanceFrequency(target)==1 then
- return ticks/tonumber(target[0])
- else
- return 0
- end
- end
- end
- elseif os.type=="unix" then
- local C=ffi.C
+local initialize=false
+if not (FFISUPPORTED and ffi) then
+elseif os.type=="windows" then
+ initialize=function()
+ local kernel=ffilib("kernel32","system")
+ if kernel then
local tonumber=ffi.number or tonumber
-ffi.cdef [[
-struct timespec { long sec; long nsec; };
-int clock_gettime(int timerid, struct timespec *t);
- ]]
- local target=ffi.new("timespec[?]",1)
- function ticks()
- C.clock_gettime(2,target)
- return tonumber(target[0].sec*1000000000+target[0].nsec)
+ ffi.cdef[[
+ int QueryPerformanceFrequency(int64_t *lpFrequency);
+ int QueryPerformanceCounter(int64_t *lpPerformanceCount);
+ ]]
+ local target=ffi.new("__int64[1]")
+ ticks=function()
+ if kernel.QueryPerformanceCounter(target)==1 then
+ return tonumber(target[0])
+ else
+ return 0
+ end
end
+ local target=ffi.new("__int64[1]")
seconds=function(ticks)
- return ticks/1000000000
+ if kernel.QueryPerformanceFrequency(target)==1 then
+ return ticks/tonumber(target[0])
+ else
+ return 0
+ end
end
end
+ initialize=false
end
- initialize=false
-end
-table.setmetatableindex(names,function(t,name)
- local v=table.setmetatableindex(function(t,source)
- local v=table.setmetatableindex(function(t,line)
+elseif os.type=="unix" then
+ initialize=function()
+ local C=ffi.C
+ local tonumber=ffi.number or tonumber
+ ffi.cdef [[
+ /* what a mess */
+ typedef int clk_id_t;
+ typedef enum { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID } clk_id;
+ typedef struct timespec { long sec; long nsec; } ctx_timespec;
+ int clock_gettime(clk_id_t timerid, struct timespec *t);
+ ]]
+ local target=ffi.new("ctx_timespec[?]",1)
+ local clock=C.CLOCK_PROCESS_CPUTIME_ID
+ ticks=function ()
+ C.clock_gettime(clock,target)
+ return tonumber(target[0].sec*1000000000+target[0].nsec)
+ end
+ seconds=function(ticks)
+ return ticks/1000000000
+ end
+ initialize=false
+ end
+end
+setmetatableindex(names,function(t,name)
+ local v=setmetatableindex(function(t,source)
+ local v=setmetatableindex(function(t,line)
local v={ total=0,count=0 }
t[line]=v
return v
@@ -9938,33 +9967,36 @@ local function hook(where)
end
end
end
-function debugger.showstats(printer)
+function debugger.showstats(printer,threshold)
local printer=printer or report
local calls=0
local functions=0
local dataset={}
local length=0
local wholetime=0
+ local threshold=threshold or 0
for name,sources in next,names do
for source,lines in next,sources do
for line,data in next,lines do
- if #name>length then
- length=#name
- end
- local total=data.total
local count=data.count
- local real=total
- if real>0 then
- real=total-(count*overhead/dummycalls)
- if real<0 then
- real=0
+ if count>threshold then
+ if #name>length then
+ length=#name
end
- wholetime=wholetime+real
- end
- if line<0 then
- line=0
+ local total=data.total
+ local real=total
+ if real>0 then
+ real=total-(count*overhead/dummycalls)
+ if real<0 then
+ real=0
+ end
+ wholetime=wholetime+real
+ end
+ if line<0 then
+ line=0
+ end
+ dataset[#dataset+1]={ real,total,count,name,source,line }
end
- dataset[#dataset+1]={ real,total,count,name,source,line }
end
end
end
@@ -10017,10 +10049,10 @@ function debugger.showstats(printer)
printer(format("calls : %i",calls))
printer(format("overhead : %f",seconds(overhead/1000)))
end
-function debugger.savestats(filename)
+function debugger.savestats(filename,threshold)
local f=io.open(filename,'w')
if f then
- debugger.showstats(function(str) f:write(str,"\n") end)
+ debugger.showstats(function(str) f:write(str,"\n") end,threshold)
f:close()
end
end
@@ -11231,7 +11263,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["lxml-tab"] = package.loaded["lxml-tab"] or true
--- original size: 58068, stripped down to: 36652
+-- original size: 58012, stripped down to: 36637
if not modules then modules={} end modules ['lxml-tab']={
version=1.001,
@@ -11373,7 +11405,7 @@ local function add_empty(spacing,namespace,tag)
tg=tag,
at=at,
dt={},
- ni=nt,
+ ni=nil,
__p__=top
}
dt[nt]=t
@@ -11395,7 +11427,7 @@ local function add_begin(spacing,namespace,tag)
tg=tag,
at=at,
dt={},
- ni=nt,
+ ni=nil,
__p__=stack[level]
}
setmetatable(top,mt)
@@ -11422,7 +11454,6 @@ local function add_end(spacing,namespace,tag)
end
dt=top.dt
nt=#dt+1
- toclose.ni=nt
dt[nt]=toclose
if toclose.at.xmlns then
remove(xmlns)
@@ -11472,7 +11503,7 @@ local function add_special(what,spacing,text)
special=true,
ns="",
tg=what,
- ni=nt,
+ ni=nil,
dt={ text },
}
end
@@ -12589,7 +12620,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["lxml-lpt"] = package.loaded["lxml-lpt"] or true
--- original size: 54930, stripped down to: 33354
+-- original size: 54921, stripped down to: 33410
if not modules then modules={} end modules ['lxml-lpt']={
version=1.001,
@@ -12680,6 +12711,7 @@ apply_axis['child']=function(list)
if dk.tg then
c=c+1
collected[c]=dk
+ dk.ni=k
en=en+1
dk.ei=en
end
@@ -12698,6 +12730,7 @@ local function collect(list,collected,c)
if dk.tg then
c=c+1
collected[c]=dk
+ dk.ni=k
en=en+1
dk.ei=en
c=collect(dk,collected,c)
@@ -12723,6 +12756,7 @@ local function collect(list,collected,c)
if dk.tg then
c=c+1
collected[c]=dk
+ dk.ni=k
en=en+1
dk.ei=en
c=collect(dk,collected,c)
@@ -19624,7 +19658,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-lib"] = package.loaded["util-lib"] or true
--- original size: 13648, stripped down to: 7455
+-- original size: 13748, stripped down to: 7544
if not modules then modules={} end modules ['util-lib']={
version=1.001,
@@ -19841,15 +19875,20 @@ if FFISUPPORTED and ffi and ffi.load then
local trace_ffilib=false
local savedffiload=ffi.load
trackers.register("resolvers.ffilib",function(v) trace_ffilib=v end)
+ local function locateindeed(name)
+ local message,library=pcall(savedffiload,removesuffix(name))
+ if type(library)=="userdata" then
+ return library
+ else
+ return false
+ end
+ end
function ffilib(required,version)
- return locate(required,version,trace_ffilib,report_ffilib,function(name)
- local message,library=pcall(savedffiload,removesuffix(name))
- if type(library)=="userdata" then
- return message,library
- else
- return message,false
- end
- end)
+ if version=="system" then
+ return locateindeed(name)
+ else
+ return locate(required,version,trace_ffilib,report_ffilib,locateindeed)
+ end
end
function ffi.load(name)
local library=ffilib(name)
@@ -20204,8 +20243,8 @@ end -- of closure
-- used libraries : l-lua.lua l-sandbox.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 855737
--- stripped bytes : 310443
+-- original bytes : 860167
+-- stripped bytes : 313517
-- end library merge