From 15c9a0a54f08ffc9fb72d6d878db4602ac6e1ca2 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sat, 23 Mar 2019 23:12:42 +0100 Subject: 2019-03-21 21:47:00 --- scripts/context/lua/mtx-bibtex.lua | 2 +- scripts/context/lua/mtx-context.lua | 14 +- scripts/context/lua/mtx-dvi.lua | 4 +- scripts/context/lua/mtx-fcd.lua | 2 +- scripts/context/lua/mtx-fonts.lua | 2 +- scripts/context/lua/mtx-grep.lua | 2 +- scripts/context/lua/mtx-install.lua | 204 ++++++-- scripts/context/lua/mtx-tools.lua | 5 +- scripts/context/lua/mtxrun.lua | 821 ++++++++++++++++++++++++++++----- scripts/context/stubs/mswin/mtxrun.lua | 821 ++++++++++++++++++++++++++++----- scripts/context/stubs/unix/mtxrun | 821 ++++++++++++++++++++++++++++----- scripts/context/stubs/win64/mtxrun.lua | 821 ++++++++++++++++++++++++++++----- 12 files changed, 3037 insertions(+), 482 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-bibtex.lua b/scripts/context/lua/mtx-bibtex.lua index 92036e3a5..d30cc2f6a 100644 --- a/scripts/context/lua/mtx-bibtex.lua +++ b/scripts/context/lua/mtx-bibtex.lua @@ -127,7 +127,7 @@ function scripts.bibtex.search(files,pattern,list) utilities.formatters.formatcolumns(result) logs.newline() for i=1,#result do - texio.write_nl(result[i]) + logs.writer(result[i]) end logs.newline() else diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 0288d686c..49d40dda8 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -159,7 +159,7 @@ local formatofinterface = { local defaultformats = { "cont-en", - "cont-nl", + -- "cont-nl", } -- purging files (we should have an mkii and mkiv variants) @@ -537,7 +537,7 @@ end local function luatex_command(l_flags,c_flags,filename,engine) return format('%s %s %s "%s"', - engine or "luatex", + engine or (status and status.luatex_engine) or "luatex", flags_to_string(l_flags), flags_to_string(c_flags,true), filename @@ -872,10 +872,12 @@ function scripts.context.run(ctxdata,filename) -- report("run %s: %s",currentrun,command) print("") -- cleaner, else continuation on same line - local returncode, errorstring = os.spawn(command) +-- local returncode, errorstring = os.spawn(command) + local returncode = os.execute(command) -- todo: remake format when no proper format is found if not returncode then - report("fatal error: no return code, message: %s",errorstring or "?") +-- report("fatal error: no return code, message: %s",errorstring or "?") + report("fatal error: no return code") if resultname then result_save_error(oldbase,newbase) end @@ -1192,7 +1194,7 @@ function scripts.context.make(name) scripts.context.generate() end local list = (name and { name }) or (environment.filenames[1] and environment.filenames) or defaultformats - local engine = getargument("engine") or "luatex" + local engine = getargument("engine") or (status and status.luatex_engine) or "luatex" if getargument("jit") then engine = "luajittex" end @@ -1201,7 +1203,7 @@ function scripts.context.make(name) name = formatofinterface[name] or name or "" if name == "" then -- nothing - elseif engine == "luatex" or engine == "luajittex" then + elseif engine == "luametatex" or engine == "luatex" or engine == "luajittex" then make_mkiv_format(name,engine) elseif engine == "pdftex" or engine == "xetex" then make_mkii_format(name,engine) diff --git a/scripts/context/lua/mtx-dvi.lua b/scripts/context/lua/mtx-dvi.lua index 57f146ee6..901b9561f 100644 --- a/scripts/context/lua/mtx-dvi.lua +++ b/scripts/context/lua/mtx-dvi.lua @@ -83,7 +83,7 @@ local f_postamble_end = formatters["postamble end offset=%s version=%s"] local f_define_font = formatters["define font k=%i checksum=%i scale=%p designsize=%p area=%s name=%s"] local currentdepth = 0 -local usedprinter = texio and texio.write_ln or print +local usedprinter = (logs and logs.writer) or (texio and texio.write_nl) or print local handler = { } for i=0,255 do handler[i] = false end @@ -379,7 +379,7 @@ function scripts.dvi.list(filename,printer) local position = 0 f:seek("set",position) local format = formatters["%0" .. #tostring(filesize) .. "i : %s"] - local flush = printer or (texio and texio.write_ln) or print + local flush = printer or usedprinter usedprinter = function(str) flush(format(position,str)) position = f:seek() diff --git a/scripts/context/lua/mtx-fcd.lua b/scripts/context/lua/mtx-fcd.lua index 76087cc37..87b06dff0 100644 --- a/scripts/context/lua/mtx-fcd.lua +++ b/scripts/context/lua/mtx-fcd.lua @@ -66,7 +66,7 @@ local application = logs.application { } local report = application.report -local writeln = print -- texio.write_nl +local writeln = (logs and logs.writer) or (texio and texio.write_nl) or print local find, char, byte, lower, gsub, format = string.find, string.char, string.byte, string.lower, string.gsub, string.format diff --git a/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua index 5fab67082..2e50543c3 100644 --- a/scripts/context/lua/mtx-fonts.lua +++ b/scripts/context/lua/mtx-fonts.lua @@ -14,7 +14,7 @@ local suffix, addsuffix, removesuffix, replacesuffix = file.suffix, file.addsuff local nameonly, basename, joinpath, collapsepath = file.nameonly, file.basename, file.join, file.collapsepath local lower = string.lower local concat = table.concat -local write_nl = texio.write_nl +local write_nl = (logs and logs.writer) or (texio and texio.write_nl) or print local otlversion = 3.106 diff --git a/scripts/context/lua/mtx-grep.lua b/scripts/context/lua/mtx-grep.lua index 0c4364630..9a4237737 100644 --- a/scripts/context/lua/mtx-grep.lua +++ b/scripts/context/lua/mtx-grep.lua @@ -69,7 +69,7 @@ local crlf = cr * lf local newline = crlf + cr + lf local content = lpeg.C((1-newline)^0) * newline + lpeg.C(lpeg.P(1)^1) -local write_nl = texio.write_nl +local write_nl = (logs and logs.writer) or (texio and texio.write_nl) or print -- local pattern = "LIJST[@TYPE='BULLET']/LIJSTITEM[contains(text(),'Kern')]" diff --git a/scripts/context/lua/mtx-install.lua b/scripts/context/lua/mtx-install.lua index 46580bb20..275102e37 100644 --- a/scripts/context/lua/mtx-install.lua +++ b/scripts/context/lua/mtx-install.lua @@ -36,8 +36,8 @@ local helpinfo = [[ local gsub, find, escapedpattern = string.gsub, string.find, string.escapedpattern local round = math.round local savetable, loadtable, sortedhash = table.save, table.load, table.sortedhash -local joinfile, filesize, dirname, addsuffix = file.join, file.size, file.dirname, file.addsuffix -local isdir, isfile, walkdir = lfs.isdir, lfs.isfile, lfs.dir +local copyfile, joinfile, filesize, dirname, addsuffix, basename = file.copy, file.join, file.size, file.dirname, file.addsuffix, file.basename +local isdir, isfile, walkdir, pushdir, popdir, currentdir = lfs.isdir, lfs.isfile, lfs.dir, lfs.chdir, dir.push, dir.pop, currentdir local mkdirs, globdir = dir.mkdirs, dir.glob local osremove, osexecute, ostype = os.remove, os.execute, os.type local savedata = io.savedata @@ -223,9 +223,9 @@ function install.update() mkdirs(tree) end - local function update(url,tree) + local function update(url,what,zipfile,skiplist) - tree = joinfile("tex",tree) + local tree = joinfile("tex",what) local ok = validdir(tree) if not validdir(tree) then @@ -252,24 +252,69 @@ function install.update() local total = 0 local done = 0 + local count = 0 if not old then - report("installing %s, %i files",tree,#new) + if zipfile then + zipfile = addsuffix(what,"zip") + end + if zipfile then + local zipurl = url .. "/" .. zipfile + report("fetching %a",zipurl) + local zipdata = fetch(zipurl) + if zipdata then + io.savedata(zipfile,zipdata) + else + zipfile = false + end + end + + if type(zipfile) == "string" and isfile(zipfile) then + + -- todo: pcall - for i=1,#new do + report("unzipping %a",zipfile) + + local specification = { + zipname = zipfile, + path = ".", + -- verbose = true, + verbose = "steps", + } + + if utilities.zipfiles.unzipdir(specification) then + osremove(zipfile) + goto done + else + osremove(zipfile) + end + + end + + count = #new + + report("installing %s, %i files",tree,count) + + for i=1,count do total = total + new[i][2] end - for i=1,#new do + for i=1,count do local entry = new[i] local name = entry[1] local size = entry[2] local target = joinfile(tree,name) done = done + size - download("new",url,target,total,done) + if not skiplist or not skiplist[basename(name)] then + download("new",url,target,total,done) + else + report("skipping %s",target) + end end + ::done:: + else report("updating %s, %i files",tree,#new) @@ -279,24 +324,30 @@ function install.update() local todo = { } for newname, newhash in sortedhash(hnew) do - local target = joinfile(tree,newname) - local oldhash = hold[newname] - local action = nil - if not oldhash then - action = "added" - elseif oldhash[3] ~= newhash[3] then - action = "changed" - elseif not ispresent(joinfile(tree,newname)) then - action = "missing" - end - if action then - local size = newhash[2] - total = total + size - todo[#todo+1] = { action, target, size } + local target = joinfile(tree,newname) + if not skiplist or not skiplist[basename(newname)] then + local oldhash = hold[newname] + local action = nil + if not oldhash then + action = "added" + elseif oldhash[3] ~= newhash[3] then + action = "changed" + elseif not ispresent(joinfile(tree,newname)) then + action = "missing" + end + if action then + local size = newhash[2] + total = total + size + todo[#todo+1] = { action, target, size } + end + else + report("skipping %s",target) end end - for i=1,#todo do + count = #todo + + for i=1,count do local entry = todo[i] download(entry[1],url,entry[2],total,done) done = done + entry[3] @@ -314,6 +365,8 @@ function install.update() savetable(lua,new) + return { tree, count, done } + end local targetroot = dir.current() @@ -355,9 +408,17 @@ function install.update() report("platform : %s",osplatform) report("system : %s",ostype) - update(url,"texmf") - update(url,"texmf-context") - update(url,texmfplatform) + local status = { } + local skiplist = { + ["mtxrun"] = true, + ["context"] = true, + ["mtxrun.exe"] = true, + ["context.exe"] = true, + } + + status[#status+1] = update(url,"texmf",true) + status[#status+1] = update(url,"texmf-context",true) + status[#status+1] = update(url,texmfplatform,false,skiplist) prepare("texmf-cache") prepare("texmf-project") @@ -367,36 +428,83 @@ function install.update() local binpath = joinfile(targetroot,"tex",texmfplatform,"bin") - if ostype == "unix" then - osexecute(formatters["chmod +x %s/*"](binpath)) + local luametatex = "luametatex" + local mtxrun = "mtxrun" + local context = "context" + + if ostype == "windows" then + luametatex = addsuffix(luametatex,"exe") + mtxrun = addsuffix(mtxrun,"exe") + context = addsuffix(context,"exe") end - local mtxrun = joinfile(binpath,"mtxrun") - local context = joinfile(binpath,"context") + local luametatexbin = joinfile(binpath,luametatex) + local mtxrunbin = joinfile(binpath,mtxrun) + local contextbin = joinfile(binpath,context) - if ostype == "windows" then - addsuffix(mtxrun,"exe") - addsuffix(context,"exe") + local cdir = currentdir() + local pdir = pushdir(binpath) + + report("current : %S",cdir) + report("target : %S",pdir) + + if pdir ~= cdir then + + report("removing : %s",mtxrun) + report("removing : %s",context) + + osremove(mtxrun) + osremove(context) + + if isfile(luametatex) then + lfs.symlink(luametatex,mtxrun) + lfs.symlink(luametatex,context) + end + + if isfile(mtxrun) then + report("linked : %s",mtxrun) + else + copyfile(luametatex,mtxrun) + report("copied : %s",mtxrun) + end + if isfile(context) then + report("linked : %s",context) + else + copyfile(luametatex,context) + report("copied : %s",context) + end + + end + + popdir() + + if lfs.setexecutable(luametatexbin) then + report("xbit set : %s",luametatexbin) + else + -- report("xbit bad : %s",luametatexbin) + end + if lfs.setexecutable(mtxrunbin) then + report("xbit set : %s",mtxrunbin) + else + -- report("xbit bad : %s",mtxrunbin) + end + if lfs.setexecutable(contextbin) then + report("xbit set : %s",contextbin) + else + -- report("xbit bad : %s",contextbin) end - run("%s --generate",mtxrun) - run("%s --make en", context) - run("%s --make nl", context) - - -- local mtxrun = joinfile(binpath,"mtxrunjit") - -- local context = joinfile(binpath,"contextjit") - -- - -- if ostype == "windows" then - -- addsuffix(mtxrun,"exe") - -- addsuffix(context,"exe") - -- end - -- - -- run("%s --generate",mtxrun) - -- run("%s --make en", context) - -- run("%s --make nl", context) + run("%s --generate",mtxrunbin) + run("%s --make en", contextbin) -- in calling script: update mtxrun.exe and mtxrun.lua + report("") + for i=1,#status do + report("%-20s : %4i files with %9i bytes installed",unpack(status[i])) + end + report("") + report("update, done") end diff --git a/scripts/context/lua/mtx-tools.lua b/scripts/context/lua/mtx-tools.lua index 146c46f36..be2177111 100644 --- a/scripts/context/lua/mtx-tools.lua +++ b/scripts/context/lua/mtx-tools.lua @@ -53,7 +53,8 @@ local application = logs.application { helpinfo = helpinfo, } -local report = application.report +local report = application.report +local writeln = (logs and logs.writer) or (texio and texio.write_nl) or print scripts = scripts or { } scripts.tools = scripts.tools or { } @@ -189,7 +190,7 @@ function scripts.tools.dirtoxml() result = table.concat(result,"\n") if not outputfile or outputfile == "" then - texio.write_nl(result) + writeln(result) else io.savedata(outputfile,result) end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 15606e1e1..98fe7f752 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -194,7 +194,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 6281, stripped down to: 2863 +-- original size: 6330, stripped down to: 2831 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -312,7 +312,6 @@ elseif not ffi.number then ffi.number=tonumber end if LUAVERSION>5.3 then - collectgarbage("generational") end @@ -3766,7 +3765,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19347, stripped down to: 10258 +-- original size: 18916, stripped down to: 10126 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3933,16 +3932,6 @@ local launchers={ function os.launch(str) execute(format(launchers[os.name] or launchers.unix,str)) end -if not os.times then - function os.times() - return { - utime=os.gettimeofday(), - stime=0, - cutime=0, - cstime=0, - } - end -end local gettimeofday=os.gettimeofday or os.clock os.gettimeofday=gettimeofday local startuptime=gettimeofday() @@ -4218,7 +4207,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-file"] = package.loaded["l-file"] or true --- original size: 21804, stripped down to: 9980 +-- original size: 21984, stripped down to: 10148 if not modules then modules={} end modules ['l-file']={ version=1.001, @@ -4398,40 +4387,45 @@ local reslasher=lpeg.replacer(P("\\"),"/") function file.reslash(str) return str and lpegmatch(reslasher,str) end -function file.is_writable(name) - if not name then - elseif lfs.isdir(name) then - name=name.."/m_t_x_t_e_s_t.tmp" - local f=io.open(name,"wb") - if f then - f:close() - os.remove(name) - return true - end - elseif lfs.isfile(name) then - local f=io.open(name,"ab") - if f then - f:close() - return true - end - else - local f=io.open(name,"ab") - if f then - f:close() - os.remove(name) - return true +if lfs.isreadablefile and lfs.iswritablefile then + file.is_readable=lfs.isreadablefile + file.is_writable=lfs.iswritablefile +else + function file.is_writable(name) + if not name then + elseif lfs.isdir(name) then + name=name.."/m_t_x_t_e_s_t.tmp" + local f=io.open(name,"wb") + if f then + f:close() + os.remove(name) + return true + end + elseif lfs.isfile(name) then + local f=io.open(name,"ab") + if f then + f:close() + return true + end + else + local f=io.open(name,"ab") + if f then + f:close() + os.remove(name) + return true + end end - end - return false -end -local readable=P("r")*Cc(true) -function file.is_readable(name) - if name then - local a=attributes(name) - return a and lpegmatch(readable,a.permissions) or false - else return false end + local readable=P("r")*Cc(true) + function file.is_readable(name) + if name then + local a=attributes(name) + return a and lpegmatch(readable,a.permissions) or false + else + return false + end + end end file.isreadable=file.is_readable file.iswritable=file.is_writable @@ -5062,7 +5056,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-dir"] = package.loaded["l-dir"] or true --- original size: 18002, stripped down to: 10681 +-- original size: 18253, stripped down to: 10816 if not modules then modules={} end modules ['l-dir']={ version=1.001, @@ -5127,13 +5121,15 @@ local function glob_pattern_function(path,patt,recurse,action) end local dirs local nofdirs=0 - for name in walkdir(usedpath) do + for name,mode,size,time in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then - action(full) + action(full,size,time) end elseif recurse and mode=="directory" then if dirs then @@ -5169,10 +5165,12 @@ local function glob_pattern_table(path,patt,recurse,result) local dirs local nofdirs=0 local noffiles=#result - for name,a in walkdir(usedpath) do + for name,mode in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then noffiles=noffiles+1 @@ -5223,7 +5221,7 @@ local function collectpattern(path,patt,recurse,result) if not find(path,"/$") then path=path..'/' end - for name in scanner,first do + for name in scanner,first do if name=="." then elseif name==".." then else @@ -5314,10 +5312,12 @@ local function globfiles(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if recurse then globfiles(path.."/"..name,recurse,func,files) @@ -5340,10 +5340,12 @@ local function globdirs(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if not func or func(name) then noffiles=noffiles+1 @@ -5524,8 +5526,7 @@ local stack={} function dir.push(newdir) local curdir=currentdir() insert(stack,curdir) - if newdir and newdir~="" then - chdir(newdir) + if newdir and newdir~="" and chdir(newdir) then return newdir else return curdir @@ -6466,7 +6467,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 43538, stripped down to: 21641 +-- original size: 43488, stripped down to: 21595 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6482,7 +6483,6 @@ local format,gsub,rep,sub,find=string.format,string.gsub,string.rep,string.sub,s local load,dump=load,string.dump local tonumber,type,tostring,next,setmetatable=tonumber,type,tostring,next,setmetatable local unpack,concat=table.unpack,table.concat -local unpack,concat=table.unpack,table.concat local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc local patterns,lpegmatch=lpeg.patterns,lpeg.match local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len @@ -7307,7 +7307,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-tab"] = package.loaded["util-tab"] or true --- original size: 28810, stripped down to: 16134 +-- original size: 28866, stripped down to: 16134 if not modules then modules={} end modules ['util-tab']={ version=1.001, @@ -7971,7 +7971,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 8607, stripped down to: 6727 +-- original size: 11530, stripped down to: 9007 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8180,6 +8180,32 @@ if bit32 then local b=char(n%256) f:write(b,a) end + function files.writecardinal4(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(a,b,c,d) + end else local floor=math.floor function files.writecardinal2(f,n) @@ -8188,16 +8214,32 @@ else local b=char(n%256) f:write(b,a) end -end -function files.writecardinal4(f,n) - local a=char(n%256) - n=rshift(n,8) - local b=char(n%256) - n=rshift(n,8) - local c=char(n%256) - n=rshift(n,8) - local d=char(n%256) - f:write(d,c,b,a) + function files.writecardinal4(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(a,b,c,d) + end end function files.writestring(f,s) f:write(char(byte(s,1,#s))) @@ -8210,10 +8252,18 @@ if fio and fio.readcardinal1 then files.readcardinal2=fio.readcardinal2 files.readcardinal3=fio.readcardinal3 files.readcardinal4=fio.readcardinal4 + files.readcardinal1le=fio.readcardinal1le or files.readcardinal1le + files.readcardinal2le=fio.readcardinal2le or files.readcardinal2le + files.readcardinal3le=fio.readcardinal3le or files.readcardinal3le + files.readcardinal4le=fio.readcardinal4le or files.readcardinal4le files.readinteger1=fio.readinteger1 files.readinteger2=fio.readinteger2 files.readinteger3=fio.readinteger3 files.readinteger4=fio.readinteger4 + files.readinteger1le=fio.readinteger1le or files.readinteger1le + files.readinteger2le=fio.readinteger2le or files.readinteger2le + files.readinteger3le=fio.readinteger3le or files.readinteger3le + files.readinteger4le=fio.readinteger4le or files.readinteger4le files.readfixed2=fio.readfixed2 files.readfixed4=fio.readfixed4 files.read2dot14=fio.read2dot14 @@ -8234,6 +8284,24 @@ if fio and fio.readcardinal1 then skipposition(f,4*(n or 1)) end end +if fio and fio.writecardinal1 then + files.writecardinal1=fio.writecardinal1 + files.writecardinal2=fio.writecardinal2 + files.writecardinal3=fio.writecardinal3 + files.writecardinal4=fio.writecardinal4 + files.writecardinal1le=fio.writecardinal1le + files.writecardinal2le=fio.writecardinal2le + files.writecardinal3le=fio.writecardinal3le + files.writecardinal4le=fio.writecardinal4le + files.writeinteger1=fio.writeinteger1 or fio.writecardinal1 + files.writeinteger2=fio.writeinteger2 or fio.writecardinal2 + files.writeinteger3=fio.writeinteger3 or fio.writecardinal3 + files.writeinteger4=fio.writeinteger4 or fio.writecardinal4 + files.writeinteger1le=files.writeinteger1le or fio.writecardinal1le + files.writeinteger2le=files.writeinteger2le or fio.writecardinal2le + files.writeinteger3le=files.writeinteger3le or fio.writecardinal3le + files.writeinteger4le=files.writeinteger4le or fio.writecardinal4le +end if fio and fio.readcardinaltable then files.readcardinaltable=fio.readcardinaltable files.readintegertable=fio.readintegertable @@ -8271,7 +8339,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 11065, stripped down to: 8209 +-- original size: 11332, stripped down to: 8420 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8296,6 +8364,11 @@ function streams.openstring(f,zerobased) return { f,1,#f,zerobased or false } end end +function streams.getstring(f) + if f then + return f[1] + end +end function streams.close() end function streams.size(f) @@ -8386,7 +8459,7 @@ function streams.readcardinal2(f) local a,b=byte(f[1],i,j) return 0x100*a+b end -function streams.readcardinal2LE(f) +function streams.readcardinal2le(f) local i=f[2] local j=i+1 f[2]=j+1 @@ -8458,6 +8531,13 @@ function streams.readcardinal4(f) local a,b,c,d=byte(f[1],i,j) return 0x1000000*a+0x10000*b+0x100*c+d end +function streams.readcardinal4le(f) + local i=f[2] + local j=i+3 + f[2]=j+1 + local d,c,b,a=byte(f[1],i,j) + return 0x1000000*a+0x10000*b+0x100*c+d +end function streams.readinteger4(f) local i=f[2] local j=i+3 @@ -9545,13 +9625,13 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-socket"] = package.loaded["util-soc-imp-socket"] or true --- original size: 4870, stripped down to: 3527 +-- original size: 4905, stripped down to: 3562 local type,tostring,setmetatable=type,tostring,setmetatable local min=math.min local format=string.format -local socket=require("socket.core") +local socket=socket or package.loaded.socket or require("socket.core") local connect=socket.connect local tcp4=socket.tcp4 local tcp6=socket.tcp6 @@ -10734,12 +10814,12 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-mime"] = package.loaded["util-soc-imp-mime"] or true --- original size: 2328, stripped down to: 1874 +-- original size: 2373, stripped down to: 1931 local type,tostring=type,tostring -local mime=require("mime.core") -local ltn12=ltn12 or require("ltn12") +local mime=mime or package.loaded.mime or require("mime.core") +local ltn12=ltn12 or package.loaded.ltn12 or require("ltn12") local filtercycle=ltn12.filter.cycle local function report(fmt,first,...) if logs then @@ -12691,7 +12771,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 32608, stripped down to: 20925 +-- original size: 32618, stripped down to: 20935 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -12736,7 +12816,7 @@ local function ignore() end setmetatableindex(logs,function(t,k) t[k]=ignore;return ignore end) local report,subreport,status,settarget,setformats,settranslations local direct,subdirect,writer,pushtarget,poptarget,setlogfile,settimedlog,setprocessor,setformatters,newline -if runningtex then +if runningtex and texio then if texio.setescape then texio.setescape(0) end @@ -15609,6 +15689,468 @@ environment.filenames=setmetatable({},{ } ) +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["util-zip"] = package.loaded["util-zip"] or true + +-- original size: 18645, stripped down to: 11291 + +if not modules then modules={} end modules ['util-zip']={ + version=1.001, + author="Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright="PRAGMA ADE / ConTeXt Development Team", + license="see context related readme files" +} +local type,tostring,tonumber=type,tostring,tonumber +local sort=table.sort +local find,format,sub,gsub=string.find,string.format,string.sub,string.gsub +local osdate,ostime=os.date,os.time +local ioopen=io.open +local loaddata,savedata=io.loaddata,io.savedata +local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +local files=utilities.files +local openfile=files.open +local closefile=files.close +local readstring=files.readstring +local readcardinal2=files.readcardinal2le +local readcardinal4=files.readcardinal4le +local setposition=files.setposition +local getposition=files.getposition +local band=bit32.band +local rshift=bit32.rshift +local lshift=bit32.lshift +local decompress,calculatecrc +if flate then + decompress=flate.flate_decompress + calculatecrc=flate.update_crc32 +else + local zlibdecompress=zlib.decompress + local zlibchecksum=zlib.crc32 + decompress=function(source,targetsize) + local target=zlibdecompress(source,-15) + if target then + return target + else + return false,1 + end + end + calculatecrc=function(buffer,initial) + return zlibchecksum(initial or 0,buffer) + end +end +local zipfiles={} +utilities.zipfiles=zipfiles +local openzipfile,closezipfile,unzipfile,foundzipfile,getziphash,getziplist do + function openzipfile(name) + return { + name=name, + handle=openfile(name,0), + } + end + local function collect(z) + if not z.list then + local list={} + local hash={} + local position=0 + local index=0 + local handle=z.handle + while true do + setposition(handle,position) + local signature=readstring(handle,4) + if signature=="PK\3\4" then + local version=readcardinal2(handle) + local flag=readcardinal2(handle) + local method=readcardinal2(handle) + local filetime=readcardinal2(handle) + local filedate=readcardinal2(handle) + local crc32=readcardinal4(handle) + local compressed=readcardinal4(handle) + local uncompressed=readcardinal4(handle) + local namelength=readcardinal2(handle) + local extralength=readcardinal2(handle) + local filename=readstring(handle,namelength) + local descriptor=band(flag,8)~=0 + local encrypted=band(flag,1)~=0 + local acceptable=method==0 or method==8 + local skipped=0 + local size=0 + if encrypted then + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + skipbytes(8) + skipped=skipped+8 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + size=readcardinal4(handle) + skipbytes(size) + skipped=skipped+size+4 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + end + position=position+30+namelength+extralength+skipped + if descriptor then + setposition(handle,position+compressed) + crc32=readcardinal4(handle) + compressed=readcardinal4(handle) + uncompressed=readcardinal4(handle) + end + if acceptable then + index=index+1 + local data={ + filename=filename, + index=index, + position=position, + method=method, + compressed=compressed, + uncompressed=uncompressed, + crc32=crc32, + encrypted=encrypted, + } + hash[filename]=data + list[index]=data + else + end + position=position+compressed + else + break + end + z.list=list + z.hash=hash + end + end + end + function getziplist(z) + local list=z.list + if not list then + collect(z) + end + return z.list + end + function getziphash(z) + local hash=z.hash + if not hash then + collect(z) + end + return z.hash + end + function foundzipfile(z,name) + return getziphash(z)[name] + end + function closezipfile(z) + local f=z.handle + if f then + closefile(f) + z.handle=nil + end + end + function unzipfile(z,filename,check) + local hash=z.hash + if not hash then + hash=zipfiles.hash(z) + end + local data=hash[filename] + if not data then + end + if data then + local handle=z.handle + local position=data.position + local compressed=data.compressed + if compressed>0 then + setposition(handle,position) + local result=readstring(handle,compressed) + if data.method==8 then + result=decompress(result,data.uncompressed) + end + if check and data.crc32~=calculatecrc(result) then + print("checksum mismatch") + return "" + end + return result + else + return "" + end + end + end + zipfiles.open=openzipfile + zipfiles.close=closezipfile + zipfiles.unzip=unzipfile + zipfiles.hash=getziphash + zipfiles.list=getziplist + zipfiles.found=foundzipfile +end +if flate then do + local writecardinal1=files.writebyte + local writecardinal2=files.writecardinal2le + local writecardinal4=files.writecardinal4le + local logwriter=logs.writer + local globpattern=dir.globpattern + local compress=flate.flate_compress + local checksum=flate.update_crc32 + local function fromdostime(dostime,dosdate) + return ostime { + year=rshift(dosdate,9)+1980, + month=band(rshift(dosdate,5),0x0F), + day=band((dosdate ),0x1F), + hour=band(rshift(dostime,11) ), + min=band(rshift(dostime,5),0x3F), + sec=band((dostime ),0x1F), + } + end + local function todostime(time) + local t=osdate("*t",time) + return + lshift(t.year-1980,9)+lshift(t.month,5)+t.day, + lshift(t.hour,11)+lshift(t.min,5)+rshift(t.sec,1) + end + local function openzip(filename,level,comment,verbose) + local f=ioopen(filename,"wb") + if f then + return { + filename=filename, + handle=f, + list={}, + level=tonumber(level) or 3, + comment=tostring(comment), + verbose=verbose, + uncompressed=0, + compressed=0, + } + end + end + local function writezip(z,name,data,level,time) + local f=z.handle + local list=z.list + local level=tonumber(level) or z.level or 3 + local method=8 + local zipped=compress(data,level) + local checksum=checksum(data) + local verbose=z.verbose + if not zipped then + method=0 + zipped=data + end + local start=f:seek() + local compressed=#zipped + local uncompressed=#data + z.compressed=z.compressed+compressed + z.uncompressed=z.uncompressed+uncompressed + if verbose then + local pct=100*compressed/uncompressed + if pct>=100 then + logwriter(format("%10i %s",uncompressed,name)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,name)) + end + end + f:write("\x50\x4b\x03\x04") + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,method) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + f:write(name) + f:write(zipped) + list[#list+1]={ #zipped,#data,name,checksum,start,time or 0 } + end + local function closezip(z) + local f=z.handle + local list=z.list + local comment=z.comment + local verbose=z.verbose + local count=#list + local start=f:seek() + for i=1,count do + local l=list[i] + local compressed=l[1] + local uncompressed=l[2] + local name=l[3] + local checksum=l[4] + local start=l[5] + local time=l[6] + local date,time=todostime(time) + f:write('\x50\x4b\x01\x02') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,8) + writecardinal2(f,time) + writecardinal2(f,date) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,0) + writecardinal4(f,start) + f:write(name) + end + local stop=f:seek() + local size=stop-start + f:write('\x50\x4b\x05\x06') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,count) + writecardinal2(f,count) + writecardinal4(f,size) + writecardinal4(f,start) + if type(comment)=="string" and comment~="" then + writecardinal2(f,#comment) + f:write(comment) + else + writecardinal2(f,0) + end + if verbose then + local compressed=z.compressed + local uncompressed=z.uncompressed + local filename=z.filename + local pct=100*compressed/uncompressed + logwriter("") + if pct>=100 then + logwriter(format("%10i %s",uncompressed,filename)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,filename)) + end + end + f:close() + end + local function zipdir(zipname,path,level,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + level=zipname.level + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + if not isdir(path) then + return + end + path=gsub(path,"\\+","/") + path=gsub(path,"/+","/") + local list={} + local count=0 + globpattern(path,"",true,function(name,size,time) + count=count+1 + list[count]={ name,time } + end) + sort(list,function(a,b) + return a[1]=step then + done=0 + logwriter(format("%4i files of %4i done, %10i bytes",i,count,total)) + end + elseif verbose then + logwriter(n) + end + savedata(p,d) + end + end + if verbose=="steps" then + logwriter(format("%4i files of %4i done, %10i bytes",count,count,total)) + end + closezipfile(z) + return true + else + closezipfile(z) + end + end + end + zipfiles.zipdir=zipdir + zipfiles.unzipdir=unzipdir +end end +if flate then + local streams=utilities.streams + local openfile=streams.open + local closestream=streams.close + local setposition=streams.setposition + local getsize=streams.size + local readcardinal4=streams.readcardinal4le + local getstring=streams.getstring + local decompress=flate.gz_decompress + function zipfiles.gunzipfile(filename) + local strm=openfile(filename) + if strm then + setposition(strm,getsize(strm)-4+1) + local size=readcardinal4(strm) + local data=decompress(getstring(strm),size) + closestream(strm) + return data + end + end +elseif gzip then + local openfile=gzip.open + function zipfiles.gunzipfile(filename) + local g=openfile(filename,"rb") + if g then + local d=g:read("*a") + d:close() + return d + end + end +end + + end -- of closure do -- create closure to overcome 200 locals limit @@ -20103,7 +20645,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-exp"] = package.loaded["data-exp"] or true --- original size: 18105, stripped down to: 10389 +-- original size: 18154, stripped down to: 10416 if not modules then modules={} end modules ['data-exp']={ version=1.001, @@ -20310,9 +20852,11 @@ local function scan(files,remap,spec,path,n,m,r,onlyone,tolerant) local pattern=tolerant and lessweird or weird local filelist={} local noffiles=0 - for name in directory(full) do + for name,mode in directory(full) do if not lpegmatch(pattern,name) then - local mode=attributes(full..name,"mode") + if not mode then + mode=attributes(full..name,"mode") + end if mode=="file" then n=n+1 noffiles=noffiles+1 @@ -20793,7 +21337,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-tmp"] = package.loaded["data-tmp"] or true --- original size: 16116, stripped down to: 10782 +-- original size: 16284, stripped down to: 10938 if not modules then modules={} end modules ['data-tmp']={ version=1.100, @@ -20833,6 +21377,7 @@ caches.force=true caches.ask=false caches.relocate=false caches.defaults={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" } +directives.register("system.caches.fast",function(v) caches.fast=true end) local writable,readables,usedreadables=nil,{},{} local function identify() local texmfcaches=resolvers.cleanpathlist("TEXMFCACHE") @@ -21066,7 +21611,9 @@ local saveoptions={ compact=true } function caches.savedata(filepath,filename,data,raw) local tmaname,tmcname=caches.setluanames(filepath,filename) data.cache_uuid=os.uuid() - if caches.direct then + if caches.fast then + file.savedata(tmaname,table.fastserialize(data,true)) + elseif caches.direct then file.savedata(tmaname,table.serialize(data,true,saveoptions)) else table.tofile(tmaname,data,true,saveoptions) @@ -23400,7 +23947,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 8700, stripped down to: 6313 +-- original size: 10263, stripped down to: 7556 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -23419,6 +23966,65 @@ local archives=zip.archives or {} zip.archives=archives local registeredfiles=zip.registeredfiles or {} zip.registeredfiles=registeredfiles +local zipfiles=utilities.zipfiles +local openzip,closezip,validfile,wholefile,filehandle,traversezip +if zipfiles then + local ipairs=ipairs + openzip=zipfiles.open + closezip=zipfiles.close + validfile=zipfiles.found + wholefile=zipfiles.unzip + traversezip=function(zfile) + return ipairs(zipfiles.list(zfile)) + end + local streams=utilities.streams + local openstream=streams.open + local readstring=streams.readstring + local streamsize=streams.size + local metatable={ + close=streams.close, + read=function(stream,n) + readstring(stream,n=="*a" and streamsize(stream) or n) + end + } + filehandle=function(zfile,queryname) + local data=wholefile(zfile,queryname) + if data then + local stream=openstream(data) + if stream then + return setmetatableindex(stream,metatable) + end + end + end +else + openzip=zip.open + closezip=zip.close + validfile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + dfile:close() + return true + end + return false + end + traversezip=function(zfile) + return z:files() + end + wholefile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + local s=dfile:read("*all") + dfile:close() + return s + end + end + filehandle=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + return dfile + end + end +end local function validzip(str) if not find(str,"^zip://") then return "zip:///"..str @@ -23433,7 +24039,7 @@ function zip.openarchive(name) local arch=archives[name] if not arch then local full=resolvers.findfile(name) or "" - arch=full~="" and zip.open(full) or false + arch=full~="" and openzip(full) or false archives[name]=arch end return arch @@ -23441,7 +24047,7 @@ function zip.openarchive(name) end function zip.closearchive(name) if not name or (name=="" and archives[name]) then - zip.close(archives[name]) + closezip(archives[name]) archives[name]=nil end end @@ -23482,9 +24088,7 @@ function resolvers.finders.zip(specification) if trace_locating then report_zip("finder: archive %a found",archive) end - local dfile=zfile:open(queryname) - if dfile then - dfile:close() + if validfile(zfile,queryname) then if trace_locating then report_zip("finder: file %a found",queryname) end @@ -23514,12 +24118,12 @@ function resolvers.openers.zip(specification) if trace_locating then report_zip("opener; archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local handle=filehandle(zfile,queryname) + if handle then if trace_locating then report_zip("opener: file %a found",queryname) end - return resolvers.openers.helpers.textopener('zip',original,dfile) + return resolvers.openers.helpers.textopener('zip',original,handle) elseif trace_locating then report_zip("opener: file %a not found",queryname) end @@ -23545,15 +24149,13 @@ function resolvers.loaders.zip(specification) if trace_locating then report_zip("loader: archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local data=wholefile(zfile,queryname) + if data then logs.show_load(original) if trace_locating then report_zip("loader; file %a loaded",original) end - local s=dfile:read("*all") - dfile:close() - return true,s,#s + return true,data,#data elseif trace_locating then report_zip("loader: file %a not found",queryname) end @@ -23600,7 +24202,7 @@ function resolvers.registerzipfile(z,tree) if trace_locating then report_zip("registering: using filter %a",filter) end - for i in z:files() do + for i in traversezip(z) do local filename=i.filename local path,name=match(filename,filter) if not path then @@ -24734,7 +25336,7 @@ do -- create closure to overcome 200 locals limit package.loaded["luat-fmt"] = package.loaded["luat-fmt"] or true --- original size: 9418, stripped down to: 7087 +-- original size: 9637, stripped down to: 7253 if not modules then modules={} end modules ['luat-fmt']={ version=1.001, @@ -24804,6 +25406,13 @@ local runners={ checkers=checkers, reporter=report_format, }, + luametatex=sandbox.registerrunner { + name="make luametatex format", + program="luametatex", + template=template, + checkers=checkers, + reporter=report_format, + }, luajittex=sandbox.registerrunner { name="make luajittex format", program="luajittex", @@ -24971,10 +25580,10 @@ end end -- of closure --- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 +-- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 util-zip.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 : 995501 --- stripped bytes : 395318 +-- original bytes : 1019480 +-- stripped bytes : 403728 -- end library merge @@ -25055,6 +25664,8 @@ local ownlibs = { -- order can be made better 'util-env.lua', 'luat-env.lua', -- can come before inf (as in mkiv) + 'util-zip.lua', + 'lxml-tab.lua', 'lxml-lpt.lua', -- 'lxml-ent.lua', diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 15606e1e1..98fe7f752 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -194,7 +194,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 6281, stripped down to: 2863 +-- original size: 6330, stripped down to: 2831 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -312,7 +312,6 @@ elseif not ffi.number then ffi.number=tonumber end if LUAVERSION>5.3 then - collectgarbage("generational") end @@ -3766,7 +3765,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19347, stripped down to: 10258 +-- original size: 18916, stripped down to: 10126 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3933,16 +3932,6 @@ local launchers={ function os.launch(str) execute(format(launchers[os.name] or launchers.unix,str)) end -if not os.times then - function os.times() - return { - utime=os.gettimeofday(), - stime=0, - cutime=0, - cstime=0, - } - end -end local gettimeofday=os.gettimeofday or os.clock os.gettimeofday=gettimeofday local startuptime=gettimeofday() @@ -4218,7 +4207,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-file"] = package.loaded["l-file"] or true --- original size: 21804, stripped down to: 9980 +-- original size: 21984, stripped down to: 10148 if not modules then modules={} end modules ['l-file']={ version=1.001, @@ -4398,40 +4387,45 @@ local reslasher=lpeg.replacer(P("\\"),"/") function file.reslash(str) return str and lpegmatch(reslasher,str) end -function file.is_writable(name) - if not name then - elseif lfs.isdir(name) then - name=name.."/m_t_x_t_e_s_t.tmp" - local f=io.open(name,"wb") - if f then - f:close() - os.remove(name) - return true - end - elseif lfs.isfile(name) then - local f=io.open(name,"ab") - if f then - f:close() - return true - end - else - local f=io.open(name,"ab") - if f then - f:close() - os.remove(name) - return true +if lfs.isreadablefile and lfs.iswritablefile then + file.is_readable=lfs.isreadablefile + file.is_writable=lfs.iswritablefile +else + function file.is_writable(name) + if not name then + elseif lfs.isdir(name) then + name=name.."/m_t_x_t_e_s_t.tmp" + local f=io.open(name,"wb") + if f then + f:close() + os.remove(name) + return true + end + elseif lfs.isfile(name) then + local f=io.open(name,"ab") + if f then + f:close() + return true + end + else + local f=io.open(name,"ab") + if f then + f:close() + os.remove(name) + return true + end end - end - return false -end -local readable=P("r")*Cc(true) -function file.is_readable(name) - if name then - local a=attributes(name) - return a and lpegmatch(readable,a.permissions) or false - else return false end + local readable=P("r")*Cc(true) + function file.is_readable(name) + if name then + local a=attributes(name) + return a and lpegmatch(readable,a.permissions) or false + else + return false + end + end end file.isreadable=file.is_readable file.iswritable=file.is_writable @@ -5062,7 +5056,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-dir"] = package.loaded["l-dir"] or true --- original size: 18002, stripped down to: 10681 +-- original size: 18253, stripped down to: 10816 if not modules then modules={} end modules ['l-dir']={ version=1.001, @@ -5127,13 +5121,15 @@ local function glob_pattern_function(path,patt,recurse,action) end local dirs local nofdirs=0 - for name in walkdir(usedpath) do + for name,mode,size,time in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then - action(full) + action(full,size,time) end elseif recurse and mode=="directory" then if dirs then @@ -5169,10 +5165,12 @@ local function glob_pattern_table(path,patt,recurse,result) local dirs local nofdirs=0 local noffiles=#result - for name,a in walkdir(usedpath) do + for name,mode in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then noffiles=noffiles+1 @@ -5223,7 +5221,7 @@ local function collectpattern(path,patt,recurse,result) if not find(path,"/$") then path=path..'/' end - for name in scanner,first do + for name in scanner,first do if name=="." then elseif name==".." then else @@ -5314,10 +5312,12 @@ local function globfiles(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if recurse then globfiles(path.."/"..name,recurse,func,files) @@ -5340,10 +5340,12 @@ local function globdirs(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if not func or func(name) then noffiles=noffiles+1 @@ -5524,8 +5526,7 @@ local stack={} function dir.push(newdir) local curdir=currentdir() insert(stack,curdir) - if newdir and newdir~="" then - chdir(newdir) + if newdir and newdir~="" and chdir(newdir) then return newdir else return curdir @@ -6466,7 +6467,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 43538, stripped down to: 21641 +-- original size: 43488, stripped down to: 21595 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6482,7 +6483,6 @@ local format,gsub,rep,sub,find=string.format,string.gsub,string.rep,string.sub,s local load,dump=load,string.dump local tonumber,type,tostring,next,setmetatable=tonumber,type,tostring,next,setmetatable local unpack,concat=table.unpack,table.concat -local unpack,concat=table.unpack,table.concat local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc local patterns,lpegmatch=lpeg.patterns,lpeg.match local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len @@ -7307,7 +7307,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-tab"] = package.loaded["util-tab"] or true --- original size: 28810, stripped down to: 16134 +-- original size: 28866, stripped down to: 16134 if not modules then modules={} end modules ['util-tab']={ version=1.001, @@ -7971,7 +7971,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 8607, stripped down to: 6727 +-- original size: 11530, stripped down to: 9007 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8180,6 +8180,32 @@ if bit32 then local b=char(n%256) f:write(b,a) end + function files.writecardinal4(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(a,b,c,d) + end else local floor=math.floor function files.writecardinal2(f,n) @@ -8188,16 +8214,32 @@ else local b=char(n%256) f:write(b,a) end -end -function files.writecardinal4(f,n) - local a=char(n%256) - n=rshift(n,8) - local b=char(n%256) - n=rshift(n,8) - local c=char(n%256) - n=rshift(n,8) - local d=char(n%256) - f:write(d,c,b,a) + function files.writecardinal4(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(a,b,c,d) + end end function files.writestring(f,s) f:write(char(byte(s,1,#s))) @@ -8210,10 +8252,18 @@ if fio and fio.readcardinal1 then files.readcardinal2=fio.readcardinal2 files.readcardinal3=fio.readcardinal3 files.readcardinal4=fio.readcardinal4 + files.readcardinal1le=fio.readcardinal1le or files.readcardinal1le + files.readcardinal2le=fio.readcardinal2le or files.readcardinal2le + files.readcardinal3le=fio.readcardinal3le or files.readcardinal3le + files.readcardinal4le=fio.readcardinal4le or files.readcardinal4le files.readinteger1=fio.readinteger1 files.readinteger2=fio.readinteger2 files.readinteger3=fio.readinteger3 files.readinteger4=fio.readinteger4 + files.readinteger1le=fio.readinteger1le or files.readinteger1le + files.readinteger2le=fio.readinteger2le or files.readinteger2le + files.readinteger3le=fio.readinteger3le or files.readinteger3le + files.readinteger4le=fio.readinteger4le or files.readinteger4le files.readfixed2=fio.readfixed2 files.readfixed4=fio.readfixed4 files.read2dot14=fio.read2dot14 @@ -8234,6 +8284,24 @@ if fio and fio.readcardinal1 then skipposition(f,4*(n or 1)) end end +if fio and fio.writecardinal1 then + files.writecardinal1=fio.writecardinal1 + files.writecardinal2=fio.writecardinal2 + files.writecardinal3=fio.writecardinal3 + files.writecardinal4=fio.writecardinal4 + files.writecardinal1le=fio.writecardinal1le + files.writecardinal2le=fio.writecardinal2le + files.writecardinal3le=fio.writecardinal3le + files.writecardinal4le=fio.writecardinal4le + files.writeinteger1=fio.writeinteger1 or fio.writecardinal1 + files.writeinteger2=fio.writeinteger2 or fio.writecardinal2 + files.writeinteger3=fio.writeinteger3 or fio.writecardinal3 + files.writeinteger4=fio.writeinteger4 or fio.writecardinal4 + files.writeinteger1le=files.writeinteger1le or fio.writecardinal1le + files.writeinteger2le=files.writeinteger2le or fio.writecardinal2le + files.writeinteger3le=files.writeinteger3le or fio.writecardinal3le + files.writeinteger4le=files.writeinteger4le or fio.writecardinal4le +end if fio and fio.readcardinaltable then files.readcardinaltable=fio.readcardinaltable files.readintegertable=fio.readintegertable @@ -8271,7 +8339,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 11065, stripped down to: 8209 +-- original size: 11332, stripped down to: 8420 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8296,6 +8364,11 @@ function streams.openstring(f,zerobased) return { f,1,#f,zerobased or false } end end +function streams.getstring(f) + if f then + return f[1] + end +end function streams.close() end function streams.size(f) @@ -8386,7 +8459,7 @@ function streams.readcardinal2(f) local a,b=byte(f[1],i,j) return 0x100*a+b end -function streams.readcardinal2LE(f) +function streams.readcardinal2le(f) local i=f[2] local j=i+1 f[2]=j+1 @@ -8458,6 +8531,13 @@ function streams.readcardinal4(f) local a,b,c,d=byte(f[1],i,j) return 0x1000000*a+0x10000*b+0x100*c+d end +function streams.readcardinal4le(f) + local i=f[2] + local j=i+3 + f[2]=j+1 + local d,c,b,a=byte(f[1],i,j) + return 0x1000000*a+0x10000*b+0x100*c+d +end function streams.readinteger4(f) local i=f[2] local j=i+3 @@ -9545,13 +9625,13 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-socket"] = package.loaded["util-soc-imp-socket"] or true --- original size: 4870, stripped down to: 3527 +-- original size: 4905, stripped down to: 3562 local type,tostring,setmetatable=type,tostring,setmetatable local min=math.min local format=string.format -local socket=require("socket.core") +local socket=socket or package.loaded.socket or require("socket.core") local connect=socket.connect local tcp4=socket.tcp4 local tcp6=socket.tcp6 @@ -10734,12 +10814,12 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-mime"] = package.loaded["util-soc-imp-mime"] or true --- original size: 2328, stripped down to: 1874 +-- original size: 2373, stripped down to: 1931 local type,tostring=type,tostring -local mime=require("mime.core") -local ltn12=ltn12 or require("ltn12") +local mime=mime or package.loaded.mime or require("mime.core") +local ltn12=ltn12 or package.loaded.ltn12 or require("ltn12") local filtercycle=ltn12.filter.cycle local function report(fmt,first,...) if logs then @@ -12691,7 +12771,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 32608, stripped down to: 20925 +-- original size: 32618, stripped down to: 20935 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -12736,7 +12816,7 @@ local function ignore() end setmetatableindex(logs,function(t,k) t[k]=ignore;return ignore end) local report,subreport,status,settarget,setformats,settranslations local direct,subdirect,writer,pushtarget,poptarget,setlogfile,settimedlog,setprocessor,setformatters,newline -if runningtex then +if runningtex and texio then if texio.setescape then texio.setescape(0) end @@ -15609,6 +15689,468 @@ environment.filenames=setmetatable({},{ } ) +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["util-zip"] = package.loaded["util-zip"] or true + +-- original size: 18645, stripped down to: 11291 + +if not modules then modules={} end modules ['util-zip']={ + version=1.001, + author="Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright="PRAGMA ADE / ConTeXt Development Team", + license="see context related readme files" +} +local type,tostring,tonumber=type,tostring,tonumber +local sort=table.sort +local find,format,sub,gsub=string.find,string.format,string.sub,string.gsub +local osdate,ostime=os.date,os.time +local ioopen=io.open +local loaddata,savedata=io.loaddata,io.savedata +local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +local files=utilities.files +local openfile=files.open +local closefile=files.close +local readstring=files.readstring +local readcardinal2=files.readcardinal2le +local readcardinal4=files.readcardinal4le +local setposition=files.setposition +local getposition=files.getposition +local band=bit32.band +local rshift=bit32.rshift +local lshift=bit32.lshift +local decompress,calculatecrc +if flate then + decompress=flate.flate_decompress + calculatecrc=flate.update_crc32 +else + local zlibdecompress=zlib.decompress + local zlibchecksum=zlib.crc32 + decompress=function(source,targetsize) + local target=zlibdecompress(source,-15) + if target then + return target + else + return false,1 + end + end + calculatecrc=function(buffer,initial) + return zlibchecksum(initial or 0,buffer) + end +end +local zipfiles={} +utilities.zipfiles=zipfiles +local openzipfile,closezipfile,unzipfile,foundzipfile,getziphash,getziplist do + function openzipfile(name) + return { + name=name, + handle=openfile(name,0), + } + end + local function collect(z) + if not z.list then + local list={} + local hash={} + local position=0 + local index=0 + local handle=z.handle + while true do + setposition(handle,position) + local signature=readstring(handle,4) + if signature=="PK\3\4" then + local version=readcardinal2(handle) + local flag=readcardinal2(handle) + local method=readcardinal2(handle) + local filetime=readcardinal2(handle) + local filedate=readcardinal2(handle) + local crc32=readcardinal4(handle) + local compressed=readcardinal4(handle) + local uncompressed=readcardinal4(handle) + local namelength=readcardinal2(handle) + local extralength=readcardinal2(handle) + local filename=readstring(handle,namelength) + local descriptor=band(flag,8)~=0 + local encrypted=band(flag,1)~=0 + local acceptable=method==0 or method==8 + local skipped=0 + local size=0 + if encrypted then + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + skipbytes(8) + skipped=skipped+8 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + size=readcardinal4(handle) + skipbytes(size) + skipped=skipped+size+4 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + end + position=position+30+namelength+extralength+skipped + if descriptor then + setposition(handle,position+compressed) + crc32=readcardinal4(handle) + compressed=readcardinal4(handle) + uncompressed=readcardinal4(handle) + end + if acceptable then + index=index+1 + local data={ + filename=filename, + index=index, + position=position, + method=method, + compressed=compressed, + uncompressed=uncompressed, + crc32=crc32, + encrypted=encrypted, + } + hash[filename]=data + list[index]=data + else + end + position=position+compressed + else + break + end + z.list=list + z.hash=hash + end + end + end + function getziplist(z) + local list=z.list + if not list then + collect(z) + end + return z.list + end + function getziphash(z) + local hash=z.hash + if not hash then + collect(z) + end + return z.hash + end + function foundzipfile(z,name) + return getziphash(z)[name] + end + function closezipfile(z) + local f=z.handle + if f then + closefile(f) + z.handle=nil + end + end + function unzipfile(z,filename,check) + local hash=z.hash + if not hash then + hash=zipfiles.hash(z) + end + local data=hash[filename] + if not data then + end + if data then + local handle=z.handle + local position=data.position + local compressed=data.compressed + if compressed>0 then + setposition(handle,position) + local result=readstring(handle,compressed) + if data.method==8 then + result=decompress(result,data.uncompressed) + end + if check and data.crc32~=calculatecrc(result) then + print("checksum mismatch") + return "" + end + return result + else + return "" + end + end + end + zipfiles.open=openzipfile + zipfiles.close=closezipfile + zipfiles.unzip=unzipfile + zipfiles.hash=getziphash + zipfiles.list=getziplist + zipfiles.found=foundzipfile +end +if flate then do + local writecardinal1=files.writebyte + local writecardinal2=files.writecardinal2le + local writecardinal4=files.writecardinal4le + local logwriter=logs.writer + local globpattern=dir.globpattern + local compress=flate.flate_compress + local checksum=flate.update_crc32 + local function fromdostime(dostime,dosdate) + return ostime { + year=rshift(dosdate,9)+1980, + month=band(rshift(dosdate,5),0x0F), + day=band((dosdate ),0x1F), + hour=band(rshift(dostime,11) ), + min=band(rshift(dostime,5),0x3F), + sec=band((dostime ),0x1F), + } + end + local function todostime(time) + local t=osdate("*t",time) + return + lshift(t.year-1980,9)+lshift(t.month,5)+t.day, + lshift(t.hour,11)+lshift(t.min,5)+rshift(t.sec,1) + end + local function openzip(filename,level,comment,verbose) + local f=ioopen(filename,"wb") + if f then + return { + filename=filename, + handle=f, + list={}, + level=tonumber(level) or 3, + comment=tostring(comment), + verbose=verbose, + uncompressed=0, + compressed=0, + } + end + end + local function writezip(z,name,data,level,time) + local f=z.handle + local list=z.list + local level=tonumber(level) or z.level or 3 + local method=8 + local zipped=compress(data,level) + local checksum=checksum(data) + local verbose=z.verbose + if not zipped then + method=0 + zipped=data + end + local start=f:seek() + local compressed=#zipped + local uncompressed=#data + z.compressed=z.compressed+compressed + z.uncompressed=z.uncompressed+uncompressed + if verbose then + local pct=100*compressed/uncompressed + if pct>=100 then + logwriter(format("%10i %s",uncompressed,name)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,name)) + end + end + f:write("\x50\x4b\x03\x04") + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,method) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + f:write(name) + f:write(zipped) + list[#list+1]={ #zipped,#data,name,checksum,start,time or 0 } + end + local function closezip(z) + local f=z.handle + local list=z.list + local comment=z.comment + local verbose=z.verbose + local count=#list + local start=f:seek() + for i=1,count do + local l=list[i] + local compressed=l[1] + local uncompressed=l[2] + local name=l[3] + local checksum=l[4] + local start=l[5] + local time=l[6] + local date,time=todostime(time) + f:write('\x50\x4b\x01\x02') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,8) + writecardinal2(f,time) + writecardinal2(f,date) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,0) + writecardinal4(f,start) + f:write(name) + end + local stop=f:seek() + local size=stop-start + f:write('\x50\x4b\x05\x06') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,count) + writecardinal2(f,count) + writecardinal4(f,size) + writecardinal4(f,start) + if type(comment)=="string" and comment~="" then + writecardinal2(f,#comment) + f:write(comment) + else + writecardinal2(f,0) + end + if verbose then + local compressed=z.compressed + local uncompressed=z.uncompressed + local filename=z.filename + local pct=100*compressed/uncompressed + logwriter("") + if pct>=100 then + logwriter(format("%10i %s",uncompressed,filename)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,filename)) + end + end + f:close() + end + local function zipdir(zipname,path,level,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + level=zipname.level + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + if not isdir(path) then + return + end + path=gsub(path,"\\+","/") + path=gsub(path,"/+","/") + local list={} + local count=0 + globpattern(path,"",true,function(name,size,time) + count=count+1 + list[count]={ name,time } + end) + sort(list,function(a,b) + return a[1]=step then + done=0 + logwriter(format("%4i files of %4i done, %10i bytes",i,count,total)) + end + elseif verbose then + logwriter(n) + end + savedata(p,d) + end + end + if verbose=="steps" then + logwriter(format("%4i files of %4i done, %10i bytes",count,count,total)) + end + closezipfile(z) + return true + else + closezipfile(z) + end + end + end + zipfiles.zipdir=zipdir + zipfiles.unzipdir=unzipdir +end end +if flate then + local streams=utilities.streams + local openfile=streams.open + local closestream=streams.close + local setposition=streams.setposition + local getsize=streams.size + local readcardinal4=streams.readcardinal4le + local getstring=streams.getstring + local decompress=flate.gz_decompress + function zipfiles.gunzipfile(filename) + local strm=openfile(filename) + if strm then + setposition(strm,getsize(strm)-4+1) + local size=readcardinal4(strm) + local data=decompress(getstring(strm),size) + closestream(strm) + return data + end + end +elseif gzip then + local openfile=gzip.open + function zipfiles.gunzipfile(filename) + local g=openfile(filename,"rb") + if g then + local d=g:read("*a") + d:close() + return d + end + end +end + + end -- of closure do -- create closure to overcome 200 locals limit @@ -20103,7 +20645,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-exp"] = package.loaded["data-exp"] or true --- original size: 18105, stripped down to: 10389 +-- original size: 18154, stripped down to: 10416 if not modules then modules={} end modules ['data-exp']={ version=1.001, @@ -20310,9 +20852,11 @@ local function scan(files,remap,spec,path,n,m,r,onlyone,tolerant) local pattern=tolerant and lessweird or weird local filelist={} local noffiles=0 - for name in directory(full) do + for name,mode in directory(full) do if not lpegmatch(pattern,name) then - local mode=attributes(full..name,"mode") + if not mode then + mode=attributes(full..name,"mode") + end if mode=="file" then n=n+1 noffiles=noffiles+1 @@ -20793,7 +21337,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-tmp"] = package.loaded["data-tmp"] or true --- original size: 16116, stripped down to: 10782 +-- original size: 16284, stripped down to: 10938 if not modules then modules={} end modules ['data-tmp']={ version=1.100, @@ -20833,6 +21377,7 @@ caches.force=true caches.ask=false caches.relocate=false caches.defaults={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" } +directives.register("system.caches.fast",function(v) caches.fast=true end) local writable,readables,usedreadables=nil,{},{} local function identify() local texmfcaches=resolvers.cleanpathlist("TEXMFCACHE") @@ -21066,7 +21611,9 @@ local saveoptions={ compact=true } function caches.savedata(filepath,filename,data,raw) local tmaname,tmcname=caches.setluanames(filepath,filename) data.cache_uuid=os.uuid() - if caches.direct then + if caches.fast then + file.savedata(tmaname,table.fastserialize(data,true)) + elseif caches.direct then file.savedata(tmaname,table.serialize(data,true,saveoptions)) else table.tofile(tmaname,data,true,saveoptions) @@ -23400,7 +23947,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 8700, stripped down to: 6313 +-- original size: 10263, stripped down to: 7556 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -23419,6 +23966,65 @@ local archives=zip.archives or {} zip.archives=archives local registeredfiles=zip.registeredfiles or {} zip.registeredfiles=registeredfiles +local zipfiles=utilities.zipfiles +local openzip,closezip,validfile,wholefile,filehandle,traversezip +if zipfiles then + local ipairs=ipairs + openzip=zipfiles.open + closezip=zipfiles.close + validfile=zipfiles.found + wholefile=zipfiles.unzip + traversezip=function(zfile) + return ipairs(zipfiles.list(zfile)) + end + local streams=utilities.streams + local openstream=streams.open + local readstring=streams.readstring + local streamsize=streams.size + local metatable={ + close=streams.close, + read=function(stream,n) + readstring(stream,n=="*a" and streamsize(stream) or n) + end + } + filehandle=function(zfile,queryname) + local data=wholefile(zfile,queryname) + if data then + local stream=openstream(data) + if stream then + return setmetatableindex(stream,metatable) + end + end + end +else + openzip=zip.open + closezip=zip.close + validfile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + dfile:close() + return true + end + return false + end + traversezip=function(zfile) + return z:files() + end + wholefile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + local s=dfile:read("*all") + dfile:close() + return s + end + end + filehandle=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + return dfile + end + end +end local function validzip(str) if not find(str,"^zip://") then return "zip:///"..str @@ -23433,7 +24039,7 @@ function zip.openarchive(name) local arch=archives[name] if not arch then local full=resolvers.findfile(name) or "" - arch=full~="" and zip.open(full) or false + arch=full~="" and openzip(full) or false archives[name]=arch end return arch @@ -23441,7 +24047,7 @@ function zip.openarchive(name) end function zip.closearchive(name) if not name or (name=="" and archives[name]) then - zip.close(archives[name]) + closezip(archives[name]) archives[name]=nil end end @@ -23482,9 +24088,7 @@ function resolvers.finders.zip(specification) if trace_locating then report_zip("finder: archive %a found",archive) end - local dfile=zfile:open(queryname) - if dfile then - dfile:close() + if validfile(zfile,queryname) then if trace_locating then report_zip("finder: file %a found",queryname) end @@ -23514,12 +24118,12 @@ function resolvers.openers.zip(specification) if trace_locating then report_zip("opener; archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local handle=filehandle(zfile,queryname) + if handle then if trace_locating then report_zip("opener: file %a found",queryname) end - return resolvers.openers.helpers.textopener('zip',original,dfile) + return resolvers.openers.helpers.textopener('zip',original,handle) elseif trace_locating then report_zip("opener: file %a not found",queryname) end @@ -23545,15 +24149,13 @@ function resolvers.loaders.zip(specification) if trace_locating then report_zip("loader: archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local data=wholefile(zfile,queryname) + if data then logs.show_load(original) if trace_locating then report_zip("loader; file %a loaded",original) end - local s=dfile:read("*all") - dfile:close() - return true,s,#s + return true,data,#data elseif trace_locating then report_zip("loader: file %a not found",queryname) end @@ -23600,7 +24202,7 @@ function resolvers.registerzipfile(z,tree) if trace_locating then report_zip("registering: using filter %a",filter) end - for i in z:files() do + for i in traversezip(z) do local filename=i.filename local path,name=match(filename,filter) if not path then @@ -24734,7 +25336,7 @@ do -- create closure to overcome 200 locals limit package.loaded["luat-fmt"] = package.loaded["luat-fmt"] or true --- original size: 9418, stripped down to: 7087 +-- original size: 9637, stripped down to: 7253 if not modules then modules={} end modules ['luat-fmt']={ version=1.001, @@ -24804,6 +25406,13 @@ local runners={ checkers=checkers, reporter=report_format, }, + luametatex=sandbox.registerrunner { + name="make luametatex format", + program="luametatex", + template=template, + checkers=checkers, + reporter=report_format, + }, luajittex=sandbox.registerrunner { name="make luajittex format", program="luajittex", @@ -24971,10 +25580,10 @@ end end -- of closure --- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 +-- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 util-zip.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 : 995501 --- stripped bytes : 395318 +-- original bytes : 1019480 +-- stripped bytes : 403728 -- end library merge @@ -25055,6 +25664,8 @@ local ownlibs = { -- order can be made better 'util-env.lua', 'luat-env.lua', -- can come before inf (as in mkiv) + 'util-zip.lua', + 'lxml-tab.lua', 'lxml-lpt.lua', -- 'lxml-ent.lua', diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 15606e1e1..98fe7f752 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -194,7 +194,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 6281, stripped down to: 2863 +-- original size: 6330, stripped down to: 2831 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -312,7 +312,6 @@ elseif not ffi.number then ffi.number=tonumber end if LUAVERSION>5.3 then - collectgarbage("generational") end @@ -3766,7 +3765,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19347, stripped down to: 10258 +-- original size: 18916, stripped down to: 10126 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3933,16 +3932,6 @@ local launchers={ function os.launch(str) execute(format(launchers[os.name] or launchers.unix,str)) end -if not os.times then - function os.times() - return { - utime=os.gettimeofday(), - stime=0, - cutime=0, - cstime=0, - } - end -end local gettimeofday=os.gettimeofday or os.clock os.gettimeofday=gettimeofday local startuptime=gettimeofday() @@ -4218,7 +4207,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-file"] = package.loaded["l-file"] or true --- original size: 21804, stripped down to: 9980 +-- original size: 21984, stripped down to: 10148 if not modules then modules={} end modules ['l-file']={ version=1.001, @@ -4398,40 +4387,45 @@ local reslasher=lpeg.replacer(P("\\"),"/") function file.reslash(str) return str and lpegmatch(reslasher,str) end -function file.is_writable(name) - if not name then - elseif lfs.isdir(name) then - name=name.."/m_t_x_t_e_s_t.tmp" - local f=io.open(name,"wb") - if f then - f:close() - os.remove(name) - return true - end - elseif lfs.isfile(name) then - local f=io.open(name,"ab") - if f then - f:close() - return true - end - else - local f=io.open(name,"ab") - if f then - f:close() - os.remove(name) - return true +if lfs.isreadablefile and lfs.iswritablefile then + file.is_readable=lfs.isreadablefile + file.is_writable=lfs.iswritablefile +else + function file.is_writable(name) + if not name then + elseif lfs.isdir(name) then + name=name.."/m_t_x_t_e_s_t.tmp" + local f=io.open(name,"wb") + if f then + f:close() + os.remove(name) + return true + end + elseif lfs.isfile(name) then + local f=io.open(name,"ab") + if f then + f:close() + return true + end + else + local f=io.open(name,"ab") + if f then + f:close() + os.remove(name) + return true + end end - end - return false -end -local readable=P("r")*Cc(true) -function file.is_readable(name) - if name then - local a=attributes(name) - return a and lpegmatch(readable,a.permissions) or false - else return false end + local readable=P("r")*Cc(true) + function file.is_readable(name) + if name then + local a=attributes(name) + return a and lpegmatch(readable,a.permissions) or false + else + return false + end + end end file.isreadable=file.is_readable file.iswritable=file.is_writable @@ -5062,7 +5056,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-dir"] = package.loaded["l-dir"] or true --- original size: 18002, stripped down to: 10681 +-- original size: 18253, stripped down to: 10816 if not modules then modules={} end modules ['l-dir']={ version=1.001, @@ -5127,13 +5121,15 @@ local function glob_pattern_function(path,patt,recurse,action) end local dirs local nofdirs=0 - for name in walkdir(usedpath) do + for name,mode,size,time in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then - action(full) + action(full,size,time) end elseif recurse and mode=="directory" then if dirs then @@ -5169,10 +5165,12 @@ local function glob_pattern_table(path,patt,recurse,result) local dirs local nofdirs=0 local noffiles=#result - for name,a in walkdir(usedpath) do + for name,mode in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then noffiles=noffiles+1 @@ -5223,7 +5221,7 @@ local function collectpattern(path,patt,recurse,result) if not find(path,"/$") then path=path..'/' end - for name in scanner,first do + for name in scanner,first do if name=="." then elseif name==".." then else @@ -5314,10 +5312,12 @@ local function globfiles(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if recurse then globfiles(path.."/"..name,recurse,func,files) @@ -5340,10 +5340,12 @@ local function globdirs(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if not func or func(name) then noffiles=noffiles+1 @@ -5524,8 +5526,7 @@ local stack={} function dir.push(newdir) local curdir=currentdir() insert(stack,curdir) - if newdir and newdir~="" then - chdir(newdir) + if newdir and newdir~="" and chdir(newdir) then return newdir else return curdir @@ -6466,7 +6467,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 43538, stripped down to: 21641 +-- original size: 43488, stripped down to: 21595 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6482,7 +6483,6 @@ local format,gsub,rep,sub,find=string.format,string.gsub,string.rep,string.sub,s local load,dump=load,string.dump local tonumber,type,tostring,next,setmetatable=tonumber,type,tostring,next,setmetatable local unpack,concat=table.unpack,table.concat -local unpack,concat=table.unpack,table.concat local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc local patterns,lpegmatch=lpeg.patterns,lpeg.match local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len @@ -7307,7 +7307,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-tab"] = package.loaded["util-tab"] or true --- original size: 28810, stripped down to: 16134 +-- original size: 28866, stripped down to: 16134 if not modules then modules={} end modules ['util-tab']={ version=1.001, @@ -7971,7 +7971,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 8607, stripped down to: 6727 +-- original size: 11530, stripped down to: 9007 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8180,6 +8180,32 @@ if bit32 then local b=char(n%256) f:write(b,a) end + function files.writecardinal4(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(a,b,c,d) + end else local floor=math.floor function files.writecardinal2(f,n) @@ -8188,16 +8214,32 @@ else local b=char(n%256) f:write(b,a) end -end -function files.writecardinal4(f,n) - local a=char(n%256) - n=rshift(n,8) - local b=char(n%256) - n=rshift(n,8) - local c=char(n%256) - n=rshift(n,8) - local d=char(n%256) - f:write(d,c,b,a) + function files.writecardinal4(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(a,b,c,d) + end end function files.writestring(f,s) f:write(char(byte(s,1,#s))) @@ -8210,10 +8252,18 @@ if fio and fio.readcardinal1 then files.readcardinal2=fio.readcardinal2 files.readcardinal3=fio.readcardinal3 files.readcardinal4=fio.readcardinal4 + files.readcardinal1le=fio.readcardinal1le or files.readcardinal1le + files.readcardinal2le=fio.readcardinal2le or files.readcardinal2le + files.readcardinal3le=fio.readcardinal3le or files.readcardinal3le + files.readcardinal4le=fio.readcardinal4le or files.readcardinal4le files.readinteger1=fio.readinteger1 files.readinteger2=fio.readinteger2 files.readinteger3=fio.readinteger3 files.readinteger4=fio.readinteger4 + files.readinteger1le=fio.readinteger1le or files.readinteger1le + files.readinteger2le=fio.readinteger2le or files.readinteger2le + files.readinteger3le=fio.readinteger3le or files.readinteger3le + files.readinteger4le=fio.readinteger4le or files.readinteger4le files.readfixed2=fio.readfixed2 files.readfixed4=fio.readfixed4 files.read2dot14=fio.read2dot14 @@ -8234,6 +8284,24 @@ if fio and fio.readcardinal1 then skipposition(f,4*(n or 1)) end end +if fio and fio.writecardinal1 then + files.writecardinal1=fio.writecardinal1 + files.writecardinal2=fio.writecardinal2 + files.writecardinal3=fio.writecardinal3 + files.writecardinal4=fio.writecardinal4 + files.writecardinal1le=fio.writecardinal1le + files.writecardinal2le=fio.writecardinal2le + files.writecardinal3le=fio.writecardinal3le + files.writecardinal4le=fio.writecardinal4le + files.writeinteger1=fio.writeinteger1 or fio.writecardinal1 + files.writeinteger2=fio.writeinteger2 or fio.writecardinal2 + files.writeinteger3=fio.writeinteger3 or fio.writecardinal3 + files.writeinteger4=fio.writeinteger4 or fio.writecardinal4 + files.writeinteger1le=files.writeinteger1le or fio.writecardinal1le + files.writeinteger2le=files.writeinteger2le or fio.writecardinal2le + files.writeinteger3le=files.writeinteger3le or fio.writecardinal3le + files.writeinteger4le=files.writeinteger4le or fio.writecardinal4le +end if fio and fio.readcardinaltable then files.readcardinaltable=fio.readcardinaltable files.readintegertable=fio.readintegertable @@ -8271,7 +8339,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 11065, stripped down to: 8209 +-- original size: 11332, stripped down to: 8420 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8296,6 +8364,11 @@ function streams.openstring(f,zerobased) return { f,1,#f,zerobased or false } end end +function streams.getstring(f) + if f then + return f[1] + end +end function streams.close() end function streams.size(f) @@ -8386,7 +8459,7 @@ function streams.readcardinal2(f) local a,b=byte(f[1],i,j) return 0x100*a+b end -function streams.readcardinal2LE(f) +function streams.readcardinal2le(f) local i=f[2] local j=i+1 f[2]=j+1 @@ -8458,6 +8531,13 @@ function streams.readcardinal4(f) local a,b,c,d=byte(f[1],i,j) return 0x1000000*a+0x10000*b+0x100*c+d end +function streams.readcardinal4le(f) + local i=f[2] + local j=i+3 + f[2]=j+1 + local d,c,b,a=byte(f[1],i,j) + return 0x1000000*a+0x10000*b+0x100*c+d +end function streams.readinteger4(f) local i=f[2] local j=i+3 @@ -9545,13 +9625,13 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-socket"] = package.loaded["util-soc-imp-socket"] or true --- original size: 4870, stripped down to: 3527 +-- original size: 4905, stripped down to: 3562 local type,tostring,setmetatable=type,tostring,setmetatable local min=math.min local format=string.format -local socket=require("socket.core") +local socket=socket or package.loaded.socket or require("socket.core") local connect=socket.connect local tcp4=socket.tcp4 local tcp6=socket.tcp6 @@ -10734,12 +10814,12 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-mime"] = package.loaded["util-soc-imp-mime"] or true --- original size: 2328, stripped down to: 1874 +-- original size: 2373, stripped down to: 1931 local type,tostring=type,tostring -local mime=require("mime.core") -local ltn12=ltn12 or require("ltn12") +local mime=mime or package.loaded.mime or require("mime.core") +local ltn12=ltn12 or package.loaded.ltn12 or require("ltn12") local filtercycle=ltn12.filter.cycle local function report(fmt,first,...) if logs then @@ -12691,7 +12771,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 32608, stripped down to: 20925 +-- original size: 32618, stripped down to: 20935 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -12736,7 +12816,7 @@ local function ignore() end setmetatableindex(logs,function(t,k) t[k]=ignore;return ignore end) local report,subreport,status,settarget,setformats,settranslations local direct,subdirect,writer,pushtarget,poptarget,setlogfile,settimedlog,setprocessor,setformatters,newline -if runningtex then +if runningtex and texio then if texio.setescape then texio.setescape(0) end @@ -15609,6 +15689,468 @@ environment.filenames=setmetatable({},{ } ) +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["util-zip"] = package.loaded["util-zip"] or true + +-- original size: 18645, stripped down to: 11291 + +if not modules then modules={} end modules ['util-zip']={ + version=1.001, + author="Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright="PRAGMA ADE / ConTeXt Development Team", + license="see context related readme files" +} +local type,tostring,tonumber=type,tostring,tonumber +local sort=table.sort +local find,format,sub,gsub=string.find,string.format,string.sub,string.gsub +local osdate,ostime=os.date,os.time +local ioopen=io.open +local loaddata,savedata=io.loaddata,io.savedata +local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +local files=utilities.files +local openfile=files.open +local closefile=files.close +local readstring=files.readstring +local readcardinal2=files.readcardinal2le +local readcardinal4=files.readcardinal4le +local setposition=files.setposition +local getposition=files.getposition +local band=bit32.band +local rshift=bit32.rshift +local lshift=bit32.lshift +local decompress,calculatecrc +if flate then + decompress=flate.flate_decompress + calculatecrc=flate.update_crc32 +else + local zlibdecompress=zlib.decompress + local zlibchecksum=zlib.crc32 + decompress=function(source,targetsize) + local target=zlibdecompress(source,-15) + if target then + return target + else + return false,1 + end + end + calculatecrc=function(buffer,initial) + return zlibchecksum(initial or 0,buffer) + end +end +local zipfiles={} +utilities.zipfiles=zipfiles +local openzipfile,closezipfile,unzipfile,foundzipfile,getziphash,getziplist do + function openzipfile(name) + return { + name=name, + handle=openfile(name,0), + } + end + local function collect(z) + if not z.list then + local list={} + local hash={} + local position=0 + local index=0 + local handle=z.handle + while true do + setposition(handle,position) + local signature=readstring(handle,4) + if signature=="PK\3\4" then + local version=readcardinal2(handle) + local flag=readcardinal2(handle) + local method=readcardinal2(handle) + local filetime=readcardinal2(handle) + local filedate=readcardinal2(handle) + local crc32=readcardinal4(handle) + local compressed=readcardinal4(handle) + local uncompressed=readcardinal4(handle) + local namelength=readcardinal2(handle) + local extralength=readcardinal2(handle) + local filename=readstring(handle,namelength) + local descriptor=band(flag,8)~=0 + local encrypted=band(flag,1)~=0 + local acceptable=method==0 or method==8 + local skipped=0 + local size=0 + if encrypted then + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + skipbytes(8) + skipped=skipped+8 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + size=readcardinal4(handle) + skipbytes(size) + skipped=skipped+size+4 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + end + position=position+30+namelength+extralength+skipped + if descriptor then + setposition(handle,position+compressed) + crc32=readcardinal4(handle) + compressed=readcardinal4(handle) + uncompressed=readcardinal4(handle) + end + if acceptable then + index=index+1 + local data={ + filename=filename, + index=index, + position=position, + method=method, + compressed=compressed, + uncompressed=uncompressed, + crc32=crc32, + encrypted=encrypted, + } + hash[filename]=data + list[index]=data + else + end + position=position+compressed + else + break + end + z.list=list + z.hash=hash + end + end + end + function getziplist(z) + local list=z.list + if not list then + collect(z) + end + return z.list + end + function getziphash(z) + local hash=z.hash + if not hash then + collect(z) + end + return z.hash + end + function foundzipfile(z,name) + return getziphash(z)[name] + end + function closezipfile(z) + local f=z.handle + if f then + closefile(f) + z.handle=nil + end + end + function unzipfile(z,filename,check) + local hash=z.hash + if not hash then + hash=zipfiles.hash(z) + end + local data=hash[filename] + if not data then + end + if data then + local handle=z.handle + local position=data.position + local compressed=data.compressed + if compressed>0 then + setposition(handle,position) + local result=readstring(handle,compressed) + if data.method==8 then + result=decompress(result,data.uncompressed) + end + if check and data.crc32~=calculatecrc(result) then + print("checksum mismatch") + return "" + end + return result + else + return "" + end + end + end + zipfiles.open=openzipfile + zipfiles.close=closezipfile + zipfiles.unzip=unzipfile + zipfiles.hash=getziphash + zipfiles.list=getziplist + zipfiles.found=foundzipfile +end +if flate then do + local writecardinal1=files.writebyte + local writecardinal2=files.writecardinal2le + local writecardinal4=files.writecardinal4le + local logwriter=logs.writer + local globpattern=dir.globpattern + local compress=flate.flate_compress + local checksum=flate.update_crc32 + local function fromdostime(dostime,dosdate) + return ostime { + year=rshift(dosdate,9)+1980, + month=band(rshift(dosdate,5),0x0F), + day=band((dosdate ),0x1F), + hour=band(rshift(dostime,11) ), + min=band(rshift(dostime,5),0x3F), + sec=band((dostime ),0x1F), + } + end + local function todostime(time) + local t=osdate("*t",time) + return + lshift(t.year-1980,9)+lshift(t.month,5)+t.day, + lshift(t.hour,11)+lshift(t.min,5)+rshift(t.sec,1) + end + local function openzip(filename,level,comment,verbose) + local f=ioopen(filename,"wb") + if f then + return { + filename=filename, + handle=f, + list={}, + level=tonumber(level) or 3, + comment=tostring(comment), + verbose=verbose, + uncompressed=0, + compressed=0, + } + end + end + local function writezip(z,name,data,level,time) + local f=z.handle + local list=z.list + local level=tonumber(level) or z.level or 3 + local method=8 + local zipped=compress(data,level) + local checksum=checksum(data) + local verbose=z.verbose + if not zipped then + method=0 + zipped=data + end + local start=f:seek() + local compressed=#zipped + local uncompressed=#data + z.compressed=z.compressed+compressed + z.uncompressed=z.uncompressed+uncompressed + if verbose then + local pct=100*compressed/uncompressed + if pct>=100 then + logwriter(format("%10i %s",uncompressed,name)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,name)) + end + end + f:write("\x50\x4b\x03\x04") + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,method) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + f:write(name) + f:write(zipped) + list[#list+1]={ #zipped,#data,name,checksum,start,time or 0 } + end + local function closezip(z) + local f=z.handle + local list=z.list + local comment=z.comment + local verbose=z.verbose + local count=#list + local start=f:seek() + for i=1,count do + local l=list[i] + local compressed=l[1] + local uncompressed=l[2] + local name=l[3] + local checksum=l[4] + local start=l[5] + local time=l[6] + local date,time=todostime(time) + f:write('\x50\x4b\x01\x02') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,8) + writecardinal2(f,time) + writecardinal2(f,date) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,0) + writecardinal4(f,start) + f:write(name) + end + local stop=f:seek() + local size=stop-start + f:write('\x50\x4b\x05\x06') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,count) + writecardinal2(f,count) + writecardinal4(f,size) + writecardinal4(f,start) + if type(comment)=="string" and comment~="" then + writecardinal2(f,#comment) + f:write(comment) + else + writecardinal2(f,0) + end + if verbose then + local compressed=z.compressed + local uncompressed=z.uncompressed + local filename=z.filename + local pct=100*compressed/uncompressed + logwriter("") + if pct>=100 then + logwriter(format("%10i %s",uncompressed,filename)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,filename)) + end + end + f:close() + end + local function zipdir(zipname,path,level,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + level=zipname.level + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + if not isdir(path) then + return + end + path=gsub(path,"\\+","/") + path=gsub(path,"/+","/") + local list={} + local count=0 + globpattern(path,"",true,function(name,size,time) + count=count+1 + list[count]={ name,time } + end) + sort(list,function(a,b) + return a[1]=step then + done=0 + logwriter(format("%4i files of %4i done, %10i bytes",i,count,total)) + end + elseif verbose then + logwriter(n) + end + savedata(p,d) + end + end + if verbose=="steps" then + logwriter(format("%4i files of %4i done, %10i bytes",count,count,total)) + end + closezipfile(z) + return true + else + closezipfile(z) + end + end + end + zipfiles.zipdir=zipdir + zipfiles.unzipdir=unzipdir +end end +if flate then + local streams=utilities.streams + local openfile=streams.open + local closestream=streams.close + local setposition=streams.setposition + local getsize=streams.size + local readcardinal4=streams.readcardinal4le + local getstring=streams.getstring + local decompress=flate.gz_decompress + function zipfiles.gunzipfile(filename) + local strm=openfile(filename) + if strm then + setposition(strm,getsize(strm)-4+1) + local size=readcardinal4(strm) + local data=decompress(getstring(strm),size) + closestream(strm) + return data + end + end +elseif gzip then + local openfile=gzip.open + function zipfiles.gunzipfile(filename) + local g=openfile(filename,"rb") + if g then + local d=g:read("*a") + d:close() + return d + end + end +end + + end -- of closure do -- create closure to overcome 200 locals limit @@ -20103,7 +20645,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-exp"] = package.loaded["data-exp"] or true --- original size: 18105, stripped down to: 10389 +-- original size: 18154, stripped down to: 10416 if not modules then modules={} end modules ['data-exp']={ version=1.001, @@ -20310,9 +20852,11 @@ local function scan(files,remap,spec,path,n,m,r,onlyone,tolerant) local pattern=tolerant and lessweird or weird local filelist={} local noffiles=0 - for name in directory(full) do + for name,mode in directory(full) do if not lpegmatch(pattern,name) then - local mode=attributes(full..name,"mode") + if not mode then + mode=attributes(full..name,"mode") + end if mode=="file" then n=n+1 noffiles=noffiles+1 @@ -20793,7 +21337,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-tmp"] = package.loaded["data-tmp"] or true --- original size: 16116, stripped down to: 10782 +-- original size: 16284, stripped down to: 10938 if not modules then modules={} end modules ['data-tmp']={ version=1.100, @@ -20833,6 +21377,7 @@ caches.force=true caches.ask=false caches.relocate=false caches.defaults={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" } +directives.register("system.caches.fast",function(v) caches.fast=true end) local writable,readables,usedreadables=nil,{},{} local function identify() local texmfcaches=resolvers.cleanpathlist("TEXMFCACHE") @@ -21066,7 +21611,9 @@ local saveoptions={ compact=true } function caches.savedata(filepath,filename,data,raw) local tmaname,tmcname=caches.setluanames(filepath,filename) data.cache_uuid=os.uuid() - if caches.direct then + if caches.fast then + file.savedata(tmaname,table.fastserialize(data,true)) + elseif caches.direct then file.savedata(tmaname,table.serialize(data,true,saveoptions)) else table.tofile(tmaname,data,true,saveoptions) @@ -23400,7 +23947,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 8700, stripped down to: 6313 +-- original size: 10263, stripped down to: 7556 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -23419,6 +23966,65 @@ local archives=zip.archives or {} zip.archives=archives local registeredfiles=zip.registeredfiles or {} zip.registeredfiles=registeredfiles +local zipfiles=utilities.zipfiles +local openzip,closezip,validfile,wholefile,filehandle,traversezip +if zipfiles then + local ipairs=ipairs + openzip=zipfiles.open + closezip=zipfiles.close + validfile=zipfiles.found + wholefile=zipfiles.unzip + traversezip=function(zfile) + return ipairs(zipfiles.list(zfile)) + end + local streams=utilities.streams + local openstream=streams.open + local readstring=streams.readstring + local streamsize=streams.size + local metatable={ + close=streams.close, + read=function(stream,n) + readstring(stream,n=="*a" and streamsize(stream) or n) + end + } + filehandle=function(zfile,queryname) + local data=wholefile(zfile,queryname) + if data then + local stream=openstream(data) + if stream then + return setmetatableindex(stream,metatable) + end + end + end +else + openzip=zip.open + closezip=zip.close + validfile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + dfile:close() + return true + end + return false + end + traversezip=function(zfile) + return z:files() + end + wholefile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + local s=dfile:read("*all") + dfile:close() + return s + end + end + filehandle=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + return dfile + end + end +end local function validzip(str) if not find(str,"^zip://") then return "zip:///"..str @@ -23433,7 +24039,7 @@ function zip.openarchive(name) local arch=archives[name] if not arch then local full=resolvers.findfile(name) or "" - arch=full~="" and zip.open(full) or false + arch=full~="" and openzip(full) or false archives[name]=arch end return arch @@ -23441,7 +24047,7 @@ function zip.openarchive(name) end function zip.closearchive(name) if not name or (name=="" and archives[name]) then - zip.close(archives[name]) + closezip(archives[name]) archives[name]=nil end end @@ -23482,9 +24088,7 @@ function resolvers.finders.zip(specification) if trace_locating then report_zip("finder: archive %a found",archive) end - local dfile=zfile:open(queryname) - if dfile then - dfile:close() + if validfile(zfile,queryname) then if trace_locating then report_zip("finder: file %a found",queryname) end @@ -23514,12 +24118,12 @@ function resolvers.openers.zip(specification) if trace_locating then report_zip("opener; archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local handle=filehandle(zfile,queryname) + if handle then if trace_locating then report_zip("opener: file %a found",queryname) end - return resolvers.openers.helpers.textopener('zip',original,dfile) + return resolvers.openers.helpers.textopener('zip',original,handle) elseif trace_locating then report_zip("opener: file %a not found",queryname) end @@ -23545,15 +24149,13 @@ function resolvers.loaders.zip(specification) if trace_locating then report_zip("loader: archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local data=wholefile(zfile,queryname) + if data then logs.show_load(original) if trace_locating then report_zip("loader; file %a loaded",original) end - local s=dfile:read("*all") - dfile:close() - return true,s,#s + return true,data,#data elseif trace_locating then report_zip("loader: file %a not found",queryname) end @@ -23600,7 +24202,7 @@ function resolvers.registerzipfile(z,tree) if trace_locating then report_zip("registering: using filter %a",filter) end - for i in z:files() do + for i in traversezip(z) do local filename=i.filename local path,name=match(filename,filter) if not path then @@ -24734,7 +25336,7 @@ do -- create closure to overcome 200 locals limit package.loaded["luat-fmt"] = package.loaded["luat-fmt"] or true --- original size: 9418, stripped down to: 7087 +-- original size: 9637, stripped down to: 7253 if not modules then modules={} end modules ['luat-fmt']={ version=1.001, @@ -24804,6 +25406,13 @@ local runners={ checkers=checkers, reporter=report_format, }, + luametatex=sandbox.registerrunner { + name="make luametatex format", + program="luametatex", + template=template, + checkers=checkers, + reporter=report_format, + }, luajittex=sandbox.registerrunner { name="make luajittex format", program="luajittex", @@ -24971,10 +25580,10 @@ end end -- of closure --- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 +-- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 util-zip.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 : 995501 --- stripped bytes : 395318 +-- original bytes : 1019480 +-- stripped bytes : 403728 -- end library merge @@ -25055,6 +25664,8 @@ local ownlibs = { -- order can be made better 'util-env.lua', 'luat-env.lua', -- can come before inf (as in mkiv) + 'util-zip.lua', + 'lxml-tab.lua', 'lxml-lpt.lua', -- 'lxml-ent.lua', diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua index 15606e1e1..98fe7f752 100644 --- a/scripts/context/stubs/win64/mtxrun.lua +++ b/scripts/context/stubs/win64/mtxrun.lua @@ -194,7 +194,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 6281, stripped down to: 2863 +-- original size: 6330, stripped down to: 2831 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -312,7 +312,6 @@ elseif not ffi.number then ffi.number=tonumber end if LUAVERSION>5.3 then - collectgarbage("generational") end @@ -3766,7 +3765,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19347, stripped down to: 10258 +-- original size: 18916, stripped down to: 10126 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3933,16 +3932,6 @@ local launchers={ function os.launch(str) execute(format(launchers[os.name] or launchers.unix,str)) end -if not os.times then - function os.times() - return { - utime=os.gettimeofday(), - stime=0, - cutime=0, - cstime=0, - } - end -end local gettimeofday=os.gettimeofday or os.clock os.gettimeofday=gettimeofday local startuptime=gettimeofday() @@ -4218,7 +4207,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-file"] = package.loaded["l-file"] or true --- original size: 21804, stripped down to: 9980 +-- original size: 21984, stripped down to: 10148 if not modules then modules={} end modules ['l-file']={ version=1.001, @@ -4398,40 +4387,45 @@ local reslasher=lpeg.replacer(P("\\"),"/") function file.reslash(str) return str and lpegmatch(reslasher,str) end -function file.is_writable(name) - if not name then - elseif lfs.isdir(name) then - name=name.."/m_t_x_t_e_s_t.tmp" - local f=io.open(name,"wb") - if f then - f:close() - os.remove(name) - return true - end - elseif lfs.isfile(name) then - local f=io.open(name,"ab") - if f then - f:close() - return true - end - else - local f=io.open(name,"ab") - if f then - f:close() - os.remove(name) - return true +if lfs.isreadablefile and lfs.iswritablefile then + file.is_readable=lfs.isreadablefile + file.is_writable=lfs.iswritablefile +else + function file.is_writable(name) + if not name then + elseif lfs.isdir(name) then + name=name.."/m_t_x_t_e_s_t.tmp" + local f=io.open(name,"wb") + if f then + f:close() + os.remove(name) + return true + end + elseif lfs.isfile(name) then + local f=io.open(name,"ab") + if f then + f:close() + return true + end + else + local f=io.open(name,"ab") + if f then + f:close() + os.remove(name) + return true + end end - end - return false -end -local readable=P("r")*Cc(true) -function file.is_readable(name) - if name then - local a=attributes(name) - return a and lpegmatch(readable,a.permissions) or false - else return false end + local readable=P("r")*Cc(true) + function file.is_readable(name) + if name then + local a=attributes(name) + return a and lpegmatch(readable,a.permissions) or false + else + return false + end + end end file.isreadable=file.is_readable file.iswritable=file.is_writable @@ -5062,7 +5056,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-dir"] = package.loaded["l-dir"] or true --- original size: 18002, stripped down to: 10681 +-- original size: 18253, stripped down to: 10816 if not modules then modules={} end modules ['l-dir']={ version=1.001, @@ -5127,13 +5121,15 @@ local function glob_pattern_function(path,patt,recurse,action) end local dirs local nofdirs=0 - for name in walkdir(usedpath) do + for name,mode,size,time in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then - action(full) + action(full,size,time) end elseif recurse and mode=="directory" then if dirs then @@ -5169,10 +5165,12 @@ local function glob_pattern_table(path,patt,recurse,result) local dirs local nofdirs=0 local noffiles=#result - for name,a in walkdir(usedpath) do + for name,mode in walkdir(usedpath) do if name~="." and name~=".." then local full=path..name - local mode=attributes(full,'mode') + if mode==nil then + mode=attributes(full,'mode') + end if mode=='file' then if not patt or find(full,patt) then noffiles=noffiles+1 @@ -5223,7 +5221,7 @@ local function collectpattern(path,patt,recurse,result) if not find(path,"/$") then path=path..'/' end - for name in scanner,first do + for name in scanner,first do if name=="." then elseif name==".." then else @@ -5314,10 +5312,12 @@ local function globfiles(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if recurse then globfiles(path.."/"..name,recurse,func,files) @@ -5340,10 +5340,12 @@ local function globdirs(path,recurse,func,files) end files=files or {} local noffiles=#files - for name in walkdir(path) do + for name,mode in walkdir(path) do if find(name,"^%.") then else - local mode=attributes(name,'mode') + if mode==nil then + mode=attributes(name,'mode') + end if mode=="directory" then if not func or func(name) then noffiles=noffiles+1 @@ -5524,8 +5526,7 @@ local stack={} function dir.push(newdir) local curdir=currentdir() insert(stack,curdir) - if newdir and newdir~="" then - chdir(newdir) + if newdir and newdir~="" and chdir(newdir) then return newdir else return curdir @@ -6466,7 +6467,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 43538, stripped down to: 21641 +-- original size: 43488, stripped down to: 21595 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6482,7 +6483,6 @@ local format,gsub,rep,sub,find=string.format,string.gsub,string.rep,string.sub,s local load,dump=load,string.dump local tonumber,type,tostring,next,setmetatable=tonumber,type,tostring,next,setmetatable local unpack,concat=table.unpack,table.concat -local unpack,concat=table.unpack,table.concat local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc local patterns,lpegmatch=lpeg.patterns,lpeg.match local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len @@ -7307,7 +7307,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-tab"] = package.loaded["util-tab"] or true --- original size: 28810, stripped down to: 16134 +-- original size: 28866, stripped down to: 16134 if not modules then modules={} end modules ['util-tab']={ version=1.001, @@ -7971,7 +7971,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 8607, stripped down to: 6727 +-- original size: 11530, stripped down to: 9007 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8180,6 +8180,32 @@ if bit32 then local b=char(n%256) f:write(b,a) end + function files.writecardinal4(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + n=rshift(n,8) + local c=char(n%256) + n=rshift(n,8) + local d=char(n%256) + f:write(a,b,c,d) + end else local floor=math.floor function files.writecardinal2(f,n) @@ -8188,16 +8214,32 @@ else local b=char(n%256) f:write(b,a) end -end -function files.writecardinal4(f,n) - local a=char(n%256) - n=rshift(n,8) - local b=char(n%256) - n=rshift(n,8) - local c=char(n%256) - n=rshift(n,8) - local d=char(n%256) - f:write(d,c,b,a) + function files.writecardinal4(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(d,c,b,a) + end + function files.writecardinal2le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + f:write(a,b) + end + function files.writecardinal4le(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + n=floor(n/256) + local c=char(n%256) + n=floor(n/256) + local d=char(n%256) + f:write(a,b,c,d) + end end function files.writestring(f,s) f:write(char(byte(s,1,#s))) @@ -8210,10 +8252,18 @@ if fio and fio.readcardinal1 then files.readcardinal2=fio.readcardinal2 files.readcardinal3=fio.readcardinal3 files.readcardinal4=fio.readcardinal4 + files.readcardinal1le=fio.readcardinal1le or files.readcardinal1le + files.readcardinal2le=fio.readcardinal2le or files.readcardinal2le + files.readcardinal3le=fio.readcardinal3le or files.readcardinal3le + files.readcardinal4le=fio.readcardinal4le or files.readcardinal4le files.readinteger1=fio.readinteger1 files.readinteger2=fio.readinteger2 files.readinteger3=fio.readinteger3 files.readinteger4=fio.readinteger4 + files.readinteger1le=fio.readinteger1le or files.readinteger1le + files.readinteger2le=fio.readinteger2le or files.readinteger2le + files.readinteger3le=fio.readinteger3le or files.readinteger3le + files.readinteger4le=fio.readinteger4le or files.readinteger4le files.readfixed2=fio.readfixed2 files.readfixed4=fio.readfixed4 files.read2dot14=fio.read2dot14 @@ -8234,6 +8284,24 @@ if fio and fio.readcardinal1 then skipposition(f,4*(n or 1)) end end +if fio and fio.writecardinal1 then + files.writecardinal1=fio.writecardinal1 + files.writecardinal2=fio.writecardinal2 + files.writecardinal3=fio.writecardinal3 + files.writecardinal4=fio.writecardinal4 + files.writecardinal1le=fio.writecardinal1le + files.writecardinal2le=fio.writecardinal2le + files.writecardinal3le=fio.writecardinal3le + files.writecardinal4le=fio.writecardinal4le + files.writeinteger1=fio.writeinteger1 or fio.writecardinal1 + files.writeinteger2=fio.writeinteger2 or fio.writecardinal2 + files.writeinteger3=fio.writeinteger3 or fio.writecardinal3 + files.writeinteger4=fio.writeinteger4 or fio.writecardinal4 + files.writeinteger1le=files.writeinteger1le or fio.writecardinal1le + files.writeinteger2le=files.writeinteger2le or fio.writecardinal2le + files.writeinteger3le=files.writeinteger3le or fio.writecardinal3le + files.writeinteger4le=files.writeinteger4le or fio.writecardinal4le +end if fio and fio.readcardinaltable then files.readcardinaltable=fio.readcardinaltable files.readintegertable=fio.readintegertable @@ -8271,7 +8339,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 11065, stripped down to: 8209 +-- original size: 11332, stripped down to: 8420 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8296,6 +8364,11 @@ function streams.openstring(f,zerobased) return { f,1,#f,zerobased or false } end end +function streams.getstring(f) + if f then + return f[1] + end +end function streams.close() end function streams.size(f) @@ -8386,7 +8459,7 @@ function streams.readcardinal2(f) local a,b=byte(f[1],i,j) return 0x100*a+b end -function streams.readcardinal2LE(f) +function streams.readcardinal2le(f) local i=f[2] local j=i+1 f[2]=j+1 @@ -8458,6 +8531,13 @@ function streams.readcardinal4(f) local a,b,c,d=byte(f[1],i,j) return 0x1000000*a+0x10000*b+0x100*c+d end +function streams.readcardinal4le(f) + local i=f[2] + local j=i+3 + f[2]=j+1 + local d,c,b,a=byte(f[1],i,j) + return 0x1000000*a+0x10000*b+0x100*c+d +end function streams.readinteger4(f) local i=f[2] local j=i+3 @@ -9545,13 +9625,13 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-socket"] = package.loaded["util-soc-imp-socket"] or true --- original size: 4870, stripped down to: 3527 +-- original size: 4905, stripped down to: 3562 local type,tostring,setmetatable=type,tostring,setmetatable local min=math.min local format=string.format -local socket=require("socket.core") +local socket=socket or package.loaded.socket or require("socket.core") local connect=socket.connect local tcp4=socket.tcp4 local tcp6=socket.tcp6 @@ -10734,12 +10814,12 @@ do -- create closure to overcome 200 locals limit package.loaded["util-soc-imp-mime"] = package.loaded["util-soc-imp-mime"] or true --- original size: 2328, stripped down to: 1874 +-- original size: 2373, stripped down to: 1931 local type,tostring=type,tostring -local mime=require("mime.core") -local ltn12=ltn12 or require("ltn12") +local mime=mime or package.loaded.mime or require("mime.core") +local ltn12=ltn12 or package.loaded.ltn12 or require("ltn12") local filtercycle=ltn12.filter.cycle local function report(fmt,first,...) if logs then @@ -12691,7 +12771,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 32608, stripped down to: 20925 +-- original size: 32618, stripped down to: 20935 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -12736,7 +12816,7 @@ local function ignore() end setmetatableindex(logs,function(t,k) t[k]=ignore;return ignore end) local report,subreport,status,settarget,setformats,settranslations local direct,subdirect,writer,pushtarget,poptarget,setlogfile,settimedlog,setprocessor,setformatters,newline -if runningtex then +if runningtex and texio then if texio.setescape then texio.setescape(0) end @@ -15609,6 +15689,468 @@ environment.filenames=setmetatable({},{ } ) +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["util-zip"] = package.loaded["util-zip"] or true + +-- original size: 18645, stripped down to: 11291 + +if not modules then modules={} end modules ['util-zip']={ + version=1.001, + author="Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright="PRAGMA ADE / ConTeXt Development Team", + license="see context related readme files" +} +local type,tostring,tonumber=type,tostring,tonumber +local sort=table.sort +local find,format,sub,gsub=string.find,string.format,string.sub,string.gsub +local osdate,ostime=os.date,os.time +local ioopen=io.open +local loaddata,savedata=io.loaddata,io.savedata +local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +local files=utilities.files +local openfile=files.open +local closefile=files.close +local readstring=files.readstring +local readcardinal2=files.readcardinal2le +local readcardinal4=files.readcardinal4le +local setposition=files.setposition +local getposition=files.getposition +local band=bit32.band +local rshift=bit32.rshift +local lshift=bit32.lshift +local decompress,calculatecrc +if flate then + decompress=flate.flate_decompress + calculatecrc=flate.update_crc32 +else + local zlibdecompress=zlib.decompress + local zlibchecksum=zlib.crc32 + decompress=function(source,targetsize) + local target=zlibdecompress(source,-15) + if target then + return target + else + return false,1 + end + end + calculatecrc=function(buffer,initial) + return zlibchecksum(initial or 0,buffer) + end +end +local zipfiles={} +utilities.zipfiles=zipfiles +local openzipfile,closezipfile,unzipfile,foundzipfile,getziphash,getziplist do + function openzipfile(name) + return { + name=name, + handle=openfile(name,0), + } + end + local function collect(z) + if not z.list then + local list={} + local hash={} + local position=0 + local index=0 + local handle=z.handle + while true do + setposition(handle,position) + local signature=readstring(handle,4) + if signature=="PK\3\4" then + local version=readcardinal2(handle) + local flag=readcardinal2(handle) + local method=readcardinal2(handle) + local filetime=readcardinal2(handle) + local filedate=readcardinal2(handle) + local crc32=readcardinal4(handle) + local compressed=readcardinal4(handle) + local uncompressed=readcardinal4(handle) + local namelength=readcardinal2(handle) + local extralength=readcardinal2(handle) + local filename=readstring(handle,namelength) + local descriptor=band(flag,8)~=0 + local encrypted=band(flag,1)~=0 + local acceptable=method==0 or method==8 + local skipped=0 + local size=0 + if encrypted then + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + skipbytes(8) + skipped=skipped+8 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + size=readcardinal4(handle) + skipbytes(size) + skipped=skipped+size+4 + size=readcardinal2(handle) + skipbytes(size) + skipped=skipped+size+2 + end + position=position+30+namelength+extralength+skipped + if descriptor then + setposition(handle,position+compressed) + crc32=readcardinal4(handle) + compressed=readcardinal4(handle) + uncompressed=readcardinal4(handle) + end + if acceptable then + index=index+1 + local data={ + filename=filename, + index=index, + position=position, + method=method, + compressed=compressed, + uncompressed=uncompressed, + crc32=crc32, + encrypted=encrypted, + } + hash[filename]=data + list[index]=data + else + end + position=position+compressed + else + break + end + z.list=list + z.hash=hash + end + end + end + function getziplist(z) + local list=z.list + if not list then + collect(z) + end + return z.list + end + function getziphash(z) + local hash=z.hash + if not hash then + collect(z) + end + return z.hash + end + function foundzipfile(z,name) + return getziphash(z)[name] + end + function closezipfile(z) + local f=z.handle + if f then + closefile(f) + z.handle=nil + end + end + function unzipfile(z,filename,check) + local hash=z.hash + if not hash then + hash=zipfiles.hash(z) + end + local data=hash[filename] + if not data then + end + if data then + local handle=z.handle + local position=data.position + local compressed=data.compressed + if compressed>0 then + setposition(handle,position) + local result=readstring(handle,compressed) + if data.method==8 then + result=decompress(result,data.uncompressed) + end + if check and data.crc32~=calculatecrc(result) then + print("checksum mismatch") + return "" + end + return result + else + return "" + end + end + end + zipfiles.open=openzipfile + zipfiles.close=closezipfile + zipfiles.unzip=unzipfile + zipfiles.hash=getziphash + zipfiles.list=getziplist + zipfiles.found=foundzipfile +end +if flate then do + local writecardinal1=files.writebyte + local writecardinal2=files.writecardinal2le + local writecardinal4=files.writecardinal4le + local logwriter=logs.writer + local globpattern=dir.globpattern + local compress=flate.flate_compress + local checksum=flate.update_crc32 + local function fromdostime(dostime,dosdate) + return ostime { + year=rshift(dosdate,9)+1980, + month=band(rshift(dosdate,5),0x0F), + day=band((dosdate ),0x1F), + hour=band(rshift(dostime,11) ), + min=band(rshift(dostime,5),0x3F), + sec=band((dostime ),0x1F), + } + end + local function todostime(time) + local t=osdate("*t",time) + return + lshift(t.year-1980,9)+lshift(t.month,5)+t.day, + lshift(t.hour,11)+lshift(t.min,5)+rshift(t.sec,1) + end + local function openzip(filename,level,comment,verbose) + local f=ioopen(filename,"wb") + if f then + return { + filename=filename, + handle=f, + list={}, + level=tonumber(level) or 3, + comment=tostring(comment), + verbose=verbose, + uncompressed=0, + compressed=0, + } + end + end + local function writezip(z,name,data,level,time) + local f=z.handle + local list=z.list + local level=tonumber(level) or z.level or 3 + local method=8 + local zipped=compress(data,level) + local checksum=checksum(data) + local verbose=z.verbose + if not zipped then + method=0 + zipped=data + end + local start=f:seek() + local compressed=#zipped + local uncompressed=#data + z.compressed=z.compressed+compressed + z.uncompressed=z.uncompressed+uncompressed + if verbose then + local pct=100*compressed/uncompressed + if pct>=100 then + logwriter(format("%10i %s",uncompressed,name)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,name)) + end + end + f:write("\x50\x4b\x03\x04") + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,method) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + f:write(name) + f:write(zipped) + list[#list+1]={ #zipped,#data,name,checksum,start,time or 0 } + end + local function closezip(z) + local f=z.handle + local list=z.list + local comment=z.comment + local verbose=z.verbose + local count=#list + local start=f:seek() + for i=1,count do + local l=list[i] + local compressed=l[1] + local uncompressed=l[2] + local name=l[3] + local checksum=l[4] + local start=l[5] + local time=l[6] + local date,time=todostime(time) + f:write('\x50\x4b\x01\x02') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,8) + writecardinal2(f,time) + writecardinal2(f,date) + writecardinal4(f,checksum) + writecardinal4(f,compressed) + writecardinal4(f,uncompressed) + writecardinal2(f,#name) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal4(f,0) + writecardinal4(f,start) + f:write(name) + end + local stop=f:seek() + local size=stop-start + f:write('\x50\x4b\x05\x06') + writecardinal2(f,0) + writecardinal2(f,0) + writecardinal2(f,count) + writecardinal2(f,count) + writecardinal4(f,size) + writecardinal4(f,start) + if type(comment)=="string" and comment~="" then + writecardinal2(f,#comment) + f:write(comment) + else + writecardinal2(f,0) + end + if verbose then + local compressed=z.compressed + local uncompressed=z.uncompressed + local filename=z.filename + local pct=100*compressed/uncompressed + logwriter("") + if pct>=100 then + logwriter(format("%10i %s",uncompressed,filename)) + else + logwriter(format("%10i %02.1f %s",uncompressed,pct,filename)) + end + end + f:close() + end + local function zipdir(zipname,path,level,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + level=zipname.level + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + if not isdir(path) then + return + end + path=gsub(path,"\\+","/") + path=gsub(path,"/+","/") + local list={} + local count=0 + globpattern(path,"",true,function(name,size,time) + count=count+1 + list[count]={ name,time } + end) + sort(list,function(a,b) + return a[1]=step then + done=0 + logwriter(format("%4i files of %4i done, %10i bytes",i,count,total)) + end + elseif verbose then + logwriter(n) + end + savedata(p,d) + end + end + if verbose=="steps" then + logwriter(format("%4i files of %4i done, %10i bytes",count,count,total)) + end + closezipfile(z) + return true + else + closezipfile(z) + end + end + end + zipfiles.zipdir=zipdir + zipfiles.unzipdir=unzipdir +end end +if flate then + local streams=utilities.streams + local openfile=streams.open + local closestream=streams.close + local setposition=streams.setposition + local getsize=streams.size + local readcardinal4=streams.readcardinal4le + local getstring=streams.getstring + local decompress=flate.gz_decompress + function zipfiles.gunzipfile(filename) + local strm=openfile(filename) + if strm then + setposition(strm,getsize(strm)-4+1) + local size=readcardinal4(strm) + local data=decompress(getstring(strm),size) + closestream(strm) + return data + end + end +elseif gzip then + local openfile=gzip.open + function zipfiles.gunzipfile(filename) + local g=openfile(filename,"rb") + if g then + local d=g:read("*a") + d:close() + return d + end + end +end + + end -- of closure do -- create closure to overcome 200 locals limit @@ -20103,7 +20645,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-exp"] = package.loaded["data-exp"] or true --- original size: 18105, stripped down to: 10389 +-- original size: 18154, stripped down to: 10416 if not modules then modules={} end modules ['data-exp']={ version=1.001, @@ -20310,9 +20852,11 @@ local function scan(files,remap,spec,path,n,m,r,onlyone,tolerant) local pattern=tolerant and lessweird or weird local filelist={} local noffiles=0 - for name in directory(full) do + for name,mode in directory(full) do if not lpegmatch(pattern,name) then - local mode=attributes(full..name,"mode") + if not mode then + mode=attributes(full..name,"mode") + end if mode=="file" then n=n+1 noffiles=noffiles+1 @@ -20793,7 +21337,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-tmp"] = package.loaded["data-tmp"] or true --- original size: 16116, stripped down to: 10782 +-- original size: 16284, stripped down to: 10938 if not modules then modules={} end modules ['data-tmp']={ version=1.100, @@ -20833,6 +21377,7 @@ caches.force=true caches.ask=false caches.relocate=false caches.defaults={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" } +directives.register("system.caches.fast",function(v) caches.fast=true end) local writable,readables,usedreadables=nil,{},{} local function identify() local texmfcaches=resolvers.cleanpathlist("TEXMFCACHE") @@ -21066,7 +21611,9 @@ local saveoptions={ compact=true } function caches.savedata(filepath,filename,data,raw) local tmaname,tmcname=caches.setluanames(filepath,filename) data.cache_uuid=os.uuid() - if caches.direct then + if caches.fast then + file.savedata(tmaname,table.fastserialize(data,true)) + elseif caches.direct then file.savedata(tmaname,table.serialize(data,true,saveoptions)) else table.tofile(tmaname,data,true,saveoptions) @@ -23400,7 +23947,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 8700, stripped down to: 6313 +-- original size: 10263, stripped down to: 7556 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -23419,6 +23966,65 @@ local archives=zip.archives or {} zip.archives=archives local registeredfiles=zip.registeredfiles or {} zip.registeredfiles=registeredfiles +local zipfiles=utilities.zipfiles +local openzip,closezip,validfile,wholefile,filehandle,traversezip +if zipfiles then + local ipairs=ipairs + openzip=zipfiles.open + closezip=zipfiles.close + validfile=zipfiles.found + wholefile=zipfiles.unzip + traversezip=function(zfile) + return ipairs(zipfiles.list(zfile)) + end + local streams=utilities.streams + local openstream=streams.open + local readstring=streams.readstring + local streamsize=streams.size + local metatable={ + close=streams.close, + read=function(stream,n) + readstring(stream,n=="*a" and streamsize(stream) or n) + end + } + filehandle=function(zfile,queryname) + local data=wholefile(zfile,queryname) + if data then + local stream=openstream(data) + if stream then + return setmetatableindex(stream,metatable) + end + end + end +else + openzip=zip.open + closezip=zip.close + validfile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + dfile:close() + return true + end + return false + end + traversezip=function(zfile) + return z:files() + end + wholefile=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + local s=dfile:read("*all") + dfile:close() + return s + end + end + filehandle=function(zfile,queryname) + local dfile=zfile:open(queryname) + if dfile then + return dfile + end + end +end local function validzip(str) if not find(str,"^zip://") then return "zip:///"..str @@ -23433,7 +24039,7 @@ function zip.openarchive(name) local arch=archives[name] if not arch then local full=resolvers.findfile(name) or "" - arch=full~="" and zip.open(full) or false + arch=full~="" and openzip(full) or false archives[name]=arch end return arch @@ -23441,7 +24047,7 @@ function zip.openarchive(name) end function zip.closearchive(name) if not name or (name=="" and archives[name]) then - zip.close(archives[name]) + closezip(archives[name]) archives[name]=nil end end @@ -23482,9 +24088,7 @@ function resolvers.finders.zip(specification) if trace_locating then report_zip("finder: archive %a found",archive) end - local dfile=zfile:open(queryname) - if dfile then - dfile:close() + if validfile(zfile,queryname) then if trace_locating then report_zip("finder: file %a found",queryname) end @@ -23514,12 +24118,12 @@ function resolvers.openers.zip(specification) if trace_locating then report_zip("opener; archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local handle=filehandle(zfile,queryname) + if handle then if trace_locating then report_zip("opener: file %a found",queryname) end - return resolvers.openers.helpers.textopener('zip',original,dfile) + return resolvers.openers.helpers.textopener('zip',original,handle) elseif trace_locating then report_zip("opener: file %a not found",queryname) end @@ -23545,15 +24149,13 @@ function resolvers.loaders.zip(specification) if trace_locating then report_zip("loader: archive %a opened",archive) end - local dfile=zfile:open(queryname) - if dfile then + local data=wholefile(zfile,queryname) + if data then logs.show_load(original) if trace_locating then report_zip("loader; file %a loaded",original) end - local s=dfile:read("*all") - dfile:close() - return true,s,#s + return true,data,#data elseif trace_locating then report_zip("loader: file %a not found",queryname) end @@ -23600,7 +24202,7 @@ function resolvers.registerzipfile(z,tree) if trace_locating then report_zip("registering: using filter %a",filter) end - for i in z:files() do + for i in traversezip(z) do local filename=i.filename local path,name=match(filename,filter) if not path then @@ -24734,7 +25336,7 @@ do -- create closure to overcome 200 locals limit package.loaded["luat-fmt"] = package.loaded["luat-fmt"] or true --- original size: 9418, stripped down to: 7087 +-- original size: 9637, stripped down to: 7253 if not modules then modules={} end modules ['luat-fmt']={ version=1.001, @@ -24804,6 +25406,13 @@ local runners={ checkers=checkers, reporter=report_format, }, + luametatex=sandbox.registerrunner { + name="make luametatex format", + program="luametatex", + template=template, + checkers=checkers, + reporter=report_format, + }, luajittex=sandbox.registerrunner { name="make luajittex format", program="luajittex", @@ -24971,10 +25580,10 @@ end end -- of closure --- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 +-- used libraries : l-bit32.lua l-lua.lua l-macro.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-sha.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 util-soc-imp-reset.lua util-soc-imp-socket.lua util-soc-imp-copas.lua util-soc-imp-ltn12.lua util-soc-imp-mime.lua util-soc-imp-url.lua util-soc-imp-headers.lua util-soc-imp-tp.lua util-soc-imp-http.lua util-soc-imp-ftp.lua util-soc-imp-smtp.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 util-zip.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 : 995501 --- stripped bytes : 395318 +-- original bytes : 1019480 +-- stripped bytes : 403728 -- end library merge @@ -25055,6 +25664,8 @@ local ownlibs = { -- order can be made better 'util-env.lua', 'luat-env.lua', -- can come before inf (as in mkiv) + 'util-zip.lua', + 'lxml-tab.lua', 'lxml-lpt.lua', -- 'lxml-ent.lua', -- cgit v1.2.3