diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtx-ctan.lua | 319 | ||||
-rw-r--r-- | scripts/context/lua/mtx-interface.lua | 138 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 256 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 256 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 256 | ||||
-rw-r--r-- | scripts/context/stubs/win64/mtxrun.lua | 256 |
6 files changed, 1035 insertions, 446 deletions
diff --git a/scripts/context/lua/mtx-ctan.lua b/scripts/context/lua/mtx-ctan.lua new file mode 100644 index 000000000..798a2da02 --- /dev/null +++ b/scripts/context/lua/mtx-ctan.lua @@ -0,0 +1,319 @@ +if not modules then modules = { } end modules ['mtx-ctan'] = { + version = 1.00, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- This is just an experiment. Some day I want to be able to install fonts this way +-- but maybe fetching tex live packages is also an option (I need to check if there +-- is an api for that ... in wintertime). Normally fonts come from the web but I had +-- to fetch newcm from ctan, so ... +-- +-- mtxrun --script ctan --packages --pattern=computermodern + +-- http://www.ctan.org/json/2.0/packages +-- http://www.ctan.org/json/2.0/pkg/name +-- http://www.ctan.org/json/2.0/topics : key details +-- http://www.ctan.org/json/2.0/topic/name : key details +-- http://www.ctan.org/json/2.0/topic/name?ref=true : key details packages + +local lower, find, gsub = string.lower, string.find, string.gsub +local write_nl = (logs and logs.writer) or (texio and texio.write_nl) or print +local xmlconvert, xmltext, xmlattr, xmlcollected = xml.convert, xml.text, xml.attribute, xml.collected + +local helpinfo = [[ +<?xml version="1.0"?> +<application> + <metadata> + <entry name="name">mtx-ctan</entry> + <entry name="detail">Dealing with CTAN</entry> + <entry name="version">1.00</entry> + </metadata> + <flags> + <category name="basic"> + <subcategory> + <flag name="packages"><short>list available packages</short></flag> + <flag name="topics"><short>list available topics</short></flag> + <flag name="detail"><short>show details about package</short></flag> + <flag name="pattern" value="string"><short>use this pattern, otherwise first argument</short></flag> + </subcategory> + </category> + </flags> +</application> +]] + +local application = logs.application { + name = "mtx-ctan", + banner = "Dealing with CTAN", + helpinfo = helpinfo, +} + +local report = application.report + +scripts = scripts or { } +scripts.ctan = scripts.ctan or { } + +local okay, json = pcall(require,"util-jsn") +local okay, curl = pcall(require,"libs-imp-curl") + pcall(require,"char-ini") + +local jsontolua = json and json.tolua +local shaped = characters and characters.shaped or lower + +-- local ignore = { +-- "latex", +-- "plain", +-- "xetex", +-- } + +-- what is the url to fetch a zip + +-- We cannot use the socket library because we don't compile that massive amount of +-- ssl code into lua(meta)tex. aybe some day one fo these small embedded libraries +-- makes sense but there are so many changes in all that security stuff that it +-- defeats long term stability of the ecosystem anyway ... just like some of my old +-- devices suddenly are no longer accessible with modern browsers I expect it to +-- happen everywhere. I'm not sure why ctan can't support http because I see no +-- added value in the 's' here. + +local ctanurl = "https://www.ctan.org/" .. (json and "json" or "xml") .. "/2.0/" + +local fetched = curl and + + function(str) + local data, message = curl.fetch { + url = ctanurl .. str, + sslverifyhost = false, + sslverifypeer = false, + } + if not data then + report("some error: %s",message) + end + return data + end + +or + + function(str) + -- So, no redirect to http, which means that we cannot use the built in socket + -- library. What if the client is happy with http? + local data = os.resultof("curl -sS " .. ctanurl .. str) + -- print(data) + return data + end + +-- for j=1,#ignore do +-- if find(str,ignore[j]) then +-- return false +-- end +-- end + +local function strfound(pattern,str) + if not pattern then + return true + else + local str = lower(shaped(str)) + if find(str,pattern) then + return true + else + str = gsub(str,"[^a-zA-Z0-9]","") + if find(str,pattern) then + return true + else + return false + end + end + end +end + +local function showresult(found) + if #found > 2 then + utilities.formatters.formatcolumns(found) + report("") + for k=1,#found do + report(found[k]) + end + report("") + end +end + +local function checkedpattern(pattern) + if pattern then + return lower(shaped(pattern)) + end +end + +local validdata = json and + + function(data) + if data then + data = jsontolua(data) + if type(data) == "table" then + return data + else + report("unable to handle this json data") + end + else + report("unable to fetch packages") + end + end + +or + + function(data) + if data then + data = xmlconvert(data) + if data.error then + report("unable to handle this json data") + else + return data + end + else + report("unable to fetch packages") + end + end + +scripts.ctan.details = json and + + function(name) + if name then + local data = validdata(fetched("pkg/" .. name)) + if data then + report("") + -- report("key : %s",data.key or "-") + report("name : %s",data.name or "-") + report("caption : %s",data.caption or "-") + report("path : %s",data.ctan.path or "-") + report("") + end + end + end + +or + + function (name) + if name then + local data = validdata(fetched("pkg/" .. name)) + report("") + -- report("key : %s",data.key or "-") + report("name : %s",xmltext(data,"/entry/name")) + report("caption : %s",xmltext(data,"/entry/caption")) + report("path : %s",xmlattr(data,"/entry/ctan","path")) + report("") + end + end + +scripts.ctan.packages = json and + + function(pattern) + local data = validdata(fetched("packages")) + if data then + local found = { + { "key", "name", "caption" }, + { "", "", "" }, + } + pattern = checkedpattern(pattern) + for i=1,#data do + local entry = data[i] + if strfound(pattern,entry.caption) then + found[#found+1] = { entry.key, entry.name, entry.caption } + end + end + showresult(found) + end + end + +or + + function(pattern) + local data = validdata(fetched("packages")) + if data then + local found = { + { "key", "name", "caption" }, + { "", "", "" }, + } + pattern = checkedpattern(pattern) + for c in xmlcollected(data,"/packages/package") do + local at = c.at + if strfound(pattern,at.caption) then + found[#found+1] = { at.key, at.name, at.caption } + end + end + showresult(found) + end + end + +scripts.ctan.topics = json and + + function (pattern) + local data = validdata(fetched("topics")) + if data then + local found = { + { "key", "details" }, + { "", "" }, + } + pattern = checkedpattern(pattern) + for i=1,#data do + local entry = data[i] + if strfound(pattern,entry.details) then + found[#found+1] = { entry.key or entry.name, entry.details } -- inconsistency between json and xml + end + end + showresult(found) + end + end + +or + + function(pattern) + local data = validdata(fetched("topics")) + if data then + local found = { + { "name", "details" }, + { "", "" }, + } + pattern = checkedpattern(pattern) + for c in xmlcollected(data,"/topics/topic") do + local at = c.at + if strfound(pattern,at.caption) then + found[#found+1] = { at.key or at.name, at.details } -- inconsistency between json and xml + end + end + showresult(found) + end + end + +local function whatever() + report("") + report("using %s interface", json and "json" or "xml") + report("using curl %s", curl and "library" or "binary") + report("") +end + +if environment.argument("packages") then + whatever() + scripts.ctan.packages(environment.argument("pattern") or environment.files[1]) +elseif environment.argument("topics") then + whatever() + scripts.ctan.topics(environment.argument("pattern") or environment.files[1]) +elseif environment.argument("details") then + whatever() + scripts.ctan.details(environment.files[1]) +elseif environment.argument("exporthelp") then + application.export(environment.argument("exporthelp"),environment.files[1]) +else + application.help() +end + +-- scripts.ctan.packages(environment.argument("pattern") or environment.files[1]) +-- scripts.ctan.packages("font") +-- scripts.ctan.details("tex") +-- scripts.ctan.details("ipaex") + +-- scripts.ctan.packages("Półtawskiego") +-- scripts.ctan.packages("Poltawskiego") + +-- scripts.ctan.topics("font") +-- scripts.ctan.topics() diff --git a/scripts/context/lua/mtx-interface.lua b/scripts/context/lua/mtx-interface.lua index a335560fa..ec2da63cc 100644 --- a/scripts/context/lua/mtx-interface.lua +++ b/scripts/context/lua/mtx-interface.lua @@ -7,9 +7,9 @@ if not modules then modules = { } end modules ['mtx-cache'] = { } local concat, sort, insert = table.concat, table.sort, table.insert -local gsub, format, gmatch, find = string.gsub, string.format, string.gmatch, string.find +local gsub, format, gmatch, find, upper = string.gsub, string.format, string.gmatch, string.find, string.upper local utfchar, utfgsub = utf.char, utf.gsub -local sortedkeys = table.sortedkeys +local sortedkeys, sortedhash, serialize = table.sortedkeys, table.sortedhash, table.serialize local helpinfo = [[ <?xml version="1.0"?> @@ -32,6 +32,7 @@ local helpinfo = [[ <flag name="bbedit"><short>generate bbedit interface files</short></flag> <flag name="jedit"><short>generate jedit interface files</short></flag> <flag name="textpad"><short>generate textpad interface files</short></flag> + <flag name="vim"><short>generate vim interface files</short></flag> <flag name="text"><short>create text files for commands and environments</short></flag> <flag name="raw"><short>report commands to the console</short></flag> <flag name="check"><short>generate check file</short></flag> @@ -71,19 +72,19 @@ local messageinterfaces = { 'en','cs','de','it','nl','ro','fr','pe','no' } local function collect(filename,class,data) if data then - local result = { } - for name, list in table.sortedhash(data) do - result[#result+1] = format("keywordclass.%s.%s=\\\n",class,name) + local result, r = { }, 0 + for name, list in sortedhash(data) do + r = r + 1 ; result[r] = format("keywordclass.%s.%s=\\\n",class,name) for i=1,#list do if i%5 == 0 then - result[#result+1] = "\\\n" + r = r + 1 ; result[r] = "\\\n" end - result[#result+1] = format("%s ",list[i]) + r = r + 1 ; result[r] = format("%s ",list[i]) end - result[#result+1] = "\n\n" + r = r + 1 ; result[r] = "\n\n" end io.savedata(file.addsuffix(filename,"properties"),concat(result)) - io.savedata(file.addsuffix(filename,"lua"), table.serialize(data,true)) + io.savedata(file.addsuffix(filename,"lua"),serialize(data,true)) else os.remove(filename) end @@ -127,18 +128,18 @@ function flushers.jedit(collected) for interface, whatever in next, collected do local commands = whatever.commands local environments = whatever.environments - local result = { } - result[#result+1] = "<?xml version='1.0'?>" - result[#result+1] = "<!DOCTYPE MODE SYSTEM 'xmode.dtd'>\n" - result[#result+1] = "<MODE>" - result[#result+1] = "\t<RULES>" - result[#result+1] = "\t\t<KEYWORDS>" + local result, r = { }, 0 + r = r + 1 ; result[r] = "<?xml version='1.0'?>" + r = r + 1 ; result[r] = "<!DOCTYPE MODE SYSTEM 'xmode.dtd'>\n" + r = r + 1 ; result[r] = "<MODE>" + r = r + 1 ; result[r] = "\t<RULES>" + r = r + 1 ; result[r] = "\t\t<KEYWORDS>" for i=1,#commands do - result[#result+1] = format("\t\t\t<KEYWORD2>%s</KEYWORD2>",commands[i]) + r = r + 1 ; result[r] = format("\t\t\t<KEYWORD2>%s</KEYWORD2>",commands[i]) end - result[#result+1] = "\t\t</KEYWORDS>" - result[#result+1] = "\t</RULES>" - result[#result+1] = "</MODE>" + r = r + 1 ; result[r] = "\t\t</KEYWORDS>" + r = r + 1 ; result[r] = "\t</RULES>" + r = r + 1 ; result[r] = "</MODE>" io.savedata(format("context-jedit-%s.xml",interface), concat(result),"\n") end end @@ -147,18 +148,100 @@ function flushers.bbedit(collected) for interface, whatever in next, collected do local commands = whatever.commands local environments = whatever.environments - local result = {} - result[#result+1] = "<?xml version='1.0'?>" - result[#result+1] = "<key>BBLMKeywordList</key>" - result[#result+1] = "<array>" + local result, r = { }, 0 + r = r + 1 ; result[r] = "<?xml version='1.0'?>" + r = r + 1 ; result[r] = "<key>BBLMKeywordList</key>" + r = r + 1 ; result[r] = "<array>" for i=1,#commands do - result[#result+1] = format("\t<string>\\%s</string>",commands[i]) + r = r + 1 ; result[r] = format("\t<string>\\%s</string>",commands[i]) end - result[#result+1] = "</array>" + r = r + 1 ; result[r] = "</array>" io.savedata(format("context-bbedit-%s.xml",interface), concat(result),"\n") end end +-- The Vim export is maintained by Nicola Vitacolonna: + +local function vimcollect(filename,class,data) + if data then + local result, r = { }, 0 + local endline = " contained\n" + if find(class,"^meta") then + endline = "\n" + end + r = r + 1 ; result[r] = "vim9script\n\n" + r = r + 1 ; result[r] = "# Vim syntax file\n" + r = r + 1 ; result[r] = "# Language: ConTeXt\n" + r = r + 1 ; result[r] = format("# Automatically generated by mtx-interface (%s)\n\n", os.date()) + local n = 5 -- number of keywords per row + for name, list in sortedhash(data) do + local i = 1 + while i <= #list do + r = r + 1 ; result[r] = format("syn keyword %s%s", class, (gsub(name,"^%l",upper))) -- upper is fragile + local j = 0 +-- while i+j <= #list and j < n do +-- if list[i+j] == "transparent" then -- this is a Vim keyword +-- r = r + 1 ; result[r] = format(" %s[]",list[i+j]) +-- else +-- r = r + 1 ; result[r] = format(" %s",list[i+j]) +-- end +-- j = j + 1 +-- end + while j < n do + local lij = list[i + j] + if not lij then + break + elseif lij == "transparent" then -- this is a Vim keyword + r = r + 1 ; result[r] = format(" %s[]",lij) + else + r = r + 1 ; result[r] = format(" %s",lij) + end + j = j + 1 + end + r = r + 1 ; result[r] = endline + i = i + n + end + end + io.savedata(file.addsuffix(filename,"vim"),concat(result)) + else + os.remove(filename) + end +end + +function flushers.vim(collected) + local data = { } + -- for interface, whatever in next, collected do + -- data[interface] = whatever.commands + -- end + local function add(target,origin,field) + if origin then + local list = origin[field] + if list then + for i=1,#list do + target[list[i]] = true + end + end + end + end + -- + for interface, whatever in next, collected do + local combined = { } + add(combined,whatever,"commands") + add(combined,whatever,"environments") + if interface == "common" then + add(combined,whatever,"textnames") + add(combined,whatever,"mathnames") + end + data[interface] = sortedkeys(combined) + end + -- + vimcollect("context-data-interfaces", "context", data) + -- vimcollect("context-data-metapost", "metapost", dofile(resolvers.findfile("mult-mps.lua"))) + vimcollect("context-data-metafun", "metafun", dofile(resolvers.findfile("mult-fun.lua"))) + vimcollect("context-data-context", "context", dofile(resolvers.findfile("mult-low.lua"))) + vimcollect("context-data-tex", "tex", dofile(resolvers.findfile("mult-prm.lua"))) +end + function flushers.raw(collected) for interface, whatever in next, collected do local commands = whatever.commands @@ -749,7 +832,7 @@ elseif ea("bidi") then scripts.interface.bidi() elseif ea("check") then scripts.interface.check() -elseif ea("scite") or ea("bbedit") or ea("jedit") or ea("textpad") or ea("text") or ea("raw") then +elseif ea("scite") or ea("bbedit") or ea("jedit") or ea("textpad") or ea("vim") or ea("text") or ea("raw") then if ea("scite") then scripts.interface.editor("scite") end @@ -762,6 +845,9 @@ elseif ea("scite") or ea("bbedit") or ea("jedit") or ea("textpad") or ea("text") if ea("textpad") then scripts.interface.editor("textpad",true, { "en" }) end + if ea("vim") then + scripts.interface.editor("vim",true, { "en" }) + end if ea("text") then scripts.interface.editor("text") end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index c32050c3f..90674eacc 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1201,7 +1201,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 38735, stripped down to: 19489 +-- original size: 38747, stripped down to: 19489 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -3837,7 +3837,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19410, stripped down to: 10420 +-- original size: 19423, stripped down to: 10421 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3969,7 +3969,7 @@ end local execute=os.execute local iopopen=io.popen local function resultof(command) - local handle=iopopen(command,"r") + local handle=iopopen(command,"rb") if handle then local result=handle:read("*all") or "" handle:close() @@ -4714,7 +4714,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-gzip"] = package.loaded["l-gzip"] or true --- original size: 5115, stripped down to: 1699 +-- original size: 268, stripped down to: 216 if not modules then modules={} end modules ['l-gzip']={ version=1.001, @@ -4722,76 +4722,6 @@ if not modules then modules={} end modules ['l-gzip']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -gzip=gzip or {} -if not zlib then - zlib=xzip -elseif not xzip then - xzip=zlib -end -if zlib then - local suffix=file.suffix - local suffixes=file.suffixes - local find=string.find - local openfile=io.open - local gzipwindow=15+16 - local gziplevel=3 - local identifier="^\x1F\x8B\x08" - local compress=zlib.compress - local decompress=zlib.decompress - function gzip.load(filename) - local f=openfile(filename,"rb") - if not f then - else - local data=f:read("*all") - f:close() - if data and data~="" then - if suffix(filename)=="gz" then - data=decompress(data,gzipwindow) - end - return data - end - end - end - function gzip.save(filename,data,level) - if suffix(filename)~="gz" then - filename=filename..".gz" - end - local f=openfile(filename,"wb") - if f then - data=compress(data or "",level or gziplevel,nil,gzipwindow) - f:write(data) - f:close() - return #data - end - end - function gzip.suffix(filename) - local suffix,extra=suffixes(filename) - local gzipped=extra=="gz" - return suffix,gzipped - end - function gzip.compressed(s) - return s and find(s,identifier) - end - function gzip.compress(s,level) - if s and not find(s,identifier) then - if not level then - level=gziplevel - elseif level<=0 then - return s - elseif level>9 then - level=9 - end - return compress(s,level or gziplevel,nil,gzipwindow) or s - end - end - function gzip.decompress(s) - if s and find(s,identifier) then - return decompress(s,gzipwindow) - else - return s - end - end -end end -- of closure @@ -8285,7 +8215,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 11552, stripped down to: 9023 +-- original size: 11474, stripped down to: 8973 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8452,20 +8382,20 @@ function files.readinteger4le(f) end end function files.readfixed2(f) - local a,b=byte(f:read(2),1,2) - if a>=0x80 then - tonumber((a-0x100).."."..b) - else - tonumber((a ).."."..b) + local n1,n2=byte(f:read(2),1,2) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function files.readfixed4(f) local a,b,c,d=byte(f:read(4),1,4) - if a>=0x80 then - tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) - else - tonumber((0x100*a+b ).."."..(0x100*c+d)) + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -8654,7 +8584,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 12970, stripped down to: 9525 +-- original size: 12905, stripped down to: 9439 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8881,23 +8811,23 @@ function streams.readfixed2(f) local i=f[2] local j=i+1 f[2]=j+1 - local a,b=byte(f[1],i,j) - if a>=0x80 then - return tonumber((a-0x100).."."..b) or 0 - else - return tonumber((a ).."."..b) or 0 + local n1,n2=byte(f[1],i,j) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function streams.readfixed4(f) local i=f[2] local j=i+3 f[2]=j+1 local a,b,c,d=byte(f[1],i,j) - if a>=0x80 then - return tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) or 0 - else - return tonumber((0x100*a+b ).."."..(0x100*c+d)) or 0 + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -9095,10 +9025,10 @@ do function io.newreader(str,method) local f,m if method=="string" then - f=openstring(str) + f=openstring(str,true) m=streams elseif method=="stream" then - f=openstream(str) + f=openstream(str,true) m=streams else f=openfile(str,"rb") @@ -15774,7 +15704,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-zip"] = package.loaded["util-zip"] or true --- original size: 19324, stripped down to: 10821 +-- original size: 23162, stripped down to: 13844 if not modules then modules={} end modules ['util-zip']={ version=1.001, @@ -15789,6 +15719,12 @@ local osdate,ostime,osclock=os.date,os.time,os.clock local ioopen=io.open local loaddata,savedata=io.loaddata,io.savedata local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +gzip=gzip or {} +if not zlib then + zlib=xzip +elseif not xzip then + xzip=zlib +end local files=utilities.files local openfile=files.open local closefile=files.close @@ -16195,6 +16131,116 @@ if xzip then zipfiles.zipdir=zipdir zipfiles.unzipdir=unzipdir end +if not gzip.compress then + local suffix=file.suffix + local suffixes=file.suffixes + local find=string.find + local concat=table.concat + local openfile=io.open + local gzipwindow=-15 + local gziplevel=3 + local identifier="\x1F\x8B" + local pattern="^\x1F\x8B\x08" + local compress=zlib.compress + local decompress=zlib.decompress + local crc32=zlib.crc32 + local streams=utilities.streams + local openstream=streams.openstring + local closestream=streams.close + local getposition=streams.getposition + local readbyte=streams.readbyte + local readcardinal4=streams.readcardinal4le + local readcardinal2=streams.readcardinal2le + local readstring=streams.readstring + local readcstring=streams.readcstring + local skipbytes=streams.skip + local tocardinal1=streams.tocardinal1 + local tocardinal4=streams.tocardinal4le + local function getdecompressed(str) + local s=openstream(str) + local identifier=readstring(s,2) + local method=readbyte(s,1) + local flags=readbyte(s,1) + local timestamp=readcardinal4(s) + local compression=readbyte(s,1) + local operating=readbyte(s,1) + local isjusttext=(flags & 0x01~=0) and true or false + local extrasize=(flags & 0x04~=0) and readcardinal2(s) or 0 + local filename=(flags & 0x08~=0) and readcstring(s) or "" + local comment=(flags & 0x10~=0) and readcstring(s) or "" + local checksum=(flags & 0x02~=0) and readcardinal2(s) or 0 + local compressed=readstring(s,#str) + local data=decompress(compressed,gzipwindow) + return data + end + local function putcompressed(str,level,originalname) + return concat { + identifier, + tocardinal1(0x08), + tocardinal1(0x08), + tocardinal4(os.time()), + tocardinal1(0x02), + tocardinal1(0xFF), + (originalname or "unknownname").."\0", + compress(str,level,nil,gzipwindow), + tocardinal4(crc32(str)), + tocardinal4(#str), + } + end + function gzip.load(filename) + local f=openfile(filename,"rb") + if not f then + else + local data=f:read("*all") + f:close() + if data and data~="" then + if suffix(filename)=="gz" then + data=getdecompressed(data) + end + return data + end + end + end + function gzip.save(filename,data,level,originalname) + if suffix(filename)~="gz" then + filename=filename..".gz" + end + local f=openfile(filename,"wb") + if f then + data=putcompressed(data or "",level or gziplevel,originalname) + f:write(data) + f:close() + return #data + end + end + function gzip.suffix(filename) + local suffix,extra=suffixes(filename) + local gzipped=extra=="gz" + return suffix,gzipped + end + function gzip.compressed(s) + return s and find(s,identifier) + end + function gzip.compress(s,level) + if s and not find(s,identifier) then + if not level then + level=gziplevel + elseif level<=0 then + return s + elseif level>9 then + level=9 + end + return putcompressed(s,level or gziplevel) or s + end + end + function gzip.decompress(s) + if s and find(s,identifier) then + return getdecompressed(s) + else + return s + end + end +end zipfiles.gunzipfile=gzip.load @@ -24134,7 +24180,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-use"] = package.loaded["data-use"] or true --- original size: 5785, stripped down to: 2905 +-- original size: 5806, stripped down to: 2925 if not modules then modules={} end modules ['data-use']={ version=1.001, @@ -24164,14 +24210,14 @@ function statistics.savefmtstatus(texname,formatbanner,sourcefile,banner) functionality=LUATEXFUNCTIONALITY, } io.savedata(luvname,table.serialize(luvdata,true)) - lua.registerfinalizer(function() + lua.registerinitexfinalizer(function() if jit then logs.report("format banner","%s lua: %s jit",banner,LUAVERSION) else logs.report("format banner","%s lua: %s",banner,LUAVERSION) end logs.newline() - end) + end,"show banner") end end function statistics.checkfmtstatus(texname) @@ -24222,7 +24268,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 10725, stripped down to: 7949 +-- original size: 10805, stripped down to: 7951 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -24265,10 +24311,10 @@ if zipfiles then local openstream=streams.open local readstring=streams.readstring local streamsize=streams.size - local metatable={ + local metatable={ close=streams.close, read=function(stream,n) - readstring(stream,n=="*a" and streamsize(stream) or n) + readstring(stream,n=="*a" and streamsize(stream) or n) end } filehandle=function(zfile,queryname) @@ -25850,8 +25896,8 @@ 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 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 libs-ini.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 1025323 --- stripped bytes : 404592 +-- original bytes : 1024297 +-- stripped bytes : 402139 -- end library merge diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index c32050c3f..90674eacc 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1201,7 +1201,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 38735, stripped down to: 19489 +-- original size: 38747, stripped down to: 19489 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -3837,7 +3837,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19410, stripped down to: 10420 +-- original size: 19423, stripped down to: 10421 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3969,7 +3969,7 @@ end local execute=os.execute local iopopen=io.popen local function resultof(command) - local handle=iopopen(command,"r") + local handle=iopopen(command,"rb") if handle then local result=handle:read("*all") or "" handle:close() @@ -4714,7 +4714,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-gzip"] = package.loaded["l-gzip"] or true --- original size: 5115, stripped down to: 1699 +-- original size: 268, stripped down to: 216 if not modules then modules={} end modules ['l-gzip']={ version=1.001, @@ -4722,76 +4722,6 @@ if not modules then modules={} end modules ['l-gzip']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -gzip=gzip or {} -if not zlib then - zlib=xzip -elseif not xzip then - xzip=zlib -end -if zlib then - local suffix=file.suffix - local suffixes=file.suffixes - local find=string.find - local openfile=io.open - local gzipwindow=15+16 - local gziplevel=3 - local identifier="^\x1F\x8B\x08" - local compress=zlib.compress - local decompress=zlib.decompress - function gzip.load(filename) - local f=openfile(filename,"rb") - if not f then - else - local data=f:read("*all") - f:close() - if data and data~="" then - if suffix(filename)=="gz" then - data=decompress(data,gzipwindow) - end - return data - end - end - end - function gzip.save(filename,data,level) - if suffix(filename)~="gz" then - filename=filename..".gz" - end - local f=openfile(filename,"wb") - if f then - data=compress(data or "",level or gziplevel,nil,gzipwindow) - f:write(data) - f:close() - return #data - end - end - function gzip.suffix(filename) - local suffix,extra=suffixes(filename) - local gzipped=extra=="gz" - return suffix,gzipped - end - function gzip.compressed(s) - return s and find(s,identifier) - end - function gzip.compress(s,level) - if s and not find(s,identifier) then - if not level then - level=gziplevel - elseif level<=0 then - return s - elseif level>9 then - level=9 - end - return compress(s,level or gziplevel,nil,gzipwindow) or s - end - end - function gzip.decompress(s) - if s and find(s,identifier) then - return decompress(s,gzipwindow) - else - return s - end - end -end end -- of closure @@ -8285,7 +8215,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 11552, stripped down to: 9023 +-- original size: 11474, stripped down to: 8973 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8452,20 +8382,20 @@ function files.readinteger4le(f) end end function files.readfixed2(f) - local a,b=byte(f:read(2),1,2) - if a>=0x80 then - tonumber((a-0x100).."."..b) - else - tonumber((a ).."."..b) + local n1,n2=byte(f:read(2),1,2) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function files.readfixed4(f) local a,b,c,d=byte(f:read(4),1,4) - if a>=0x80 then - tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) - else - tonumber((0x100*a+b ).."."..(0x100*c+d)) + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -8654,7 +8584,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 12970, stripped down to: 9525 +-- original size: 12905, stripped down to: 9439 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8881,23 +8811,23 @@ function streams.readfixed2(f) local i=f[2] local j=i+1 f[2]=j+1 - local a,b=byte(f[1],i,j) - if a>=0x80 then - return tonumber((a-0x100).."."..b) or 0 - else - return tonumber((a ).."."..b) or 0 + local n1,n2=byte(f[1],i,j) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function streams.readfixed4(f) local i=f[2] local j=i+3 f[2]=j+1 local a,b,c,d=byte(f[1],i,j) - if a>=0x80 then - return tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) or 0 - else - return tonumber((0x100*a+b ).."."..(0x100*c+d)) or 0 + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -9095,10 +9025,10 @@ do function io.newreader(str,method) local f,m if method=="string" then - f=openstring(str) + f=openstring(str,true) m=streams elseif method=="stream" then - f=openstream(str) + f=openstream(str,true) m=streams else f=openfile(str,"rb") @@ -15774,7 +15704,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-zip"] = package.loaded["util-zip"] or true --- original size: 19324, stripped down to: 10821 +-- original size: 23162, stripped down to: 13844 if not modules then modules={} end modules ['util-zip']={ version=1.001, @@ -15789,6 +15719,12 @@ local osdate,ostime,osclock=os.date,os.time,os.clock local ioopen=io.open local loaddata,savedata=io.loaddata,io.savedata local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +gzip=gzip or {} +if not zlib then + zlib=xzip +elseif not xzip then + xzip=zlib +end local files=utilities.files local openfile=files.open local closefile=files.close @@ -16195,6 +16131,116 @@ if xzip then zipfiles.zipdir=zipdir zipfiles.unzipdir=unzipdir end +if not gzip.compress then + local suffix=file.suffix + local suffixes=file.suffixes + local find=string.find + local concat=table.concat + local openfile=io.open + local gzipwindow=-15 + local gziplevel=3 + local identifier="\x1F\x8B" + local pattern="^\x1F\x8B\x08" + local compress=zlib.compress + local decompress=zlib.decompress + local crc32=zlib.crc32 + local streams=utilities.streams + local openstream=streams.openstring + local closestream=streams.close + local getposition=streams.getposition + local readbyte=streams.readbyte + local readcardinal4=streams.readcardinal4le + local readcardinal2=streams.readcardinal2le + local readstring=streams.readstring + local readcstring=streams.readcstring + local skipbytes=streams.skip + local tocardinal1=streams.tocardinal1 + local tocardinal4=streams.tocardinal4le + local function getdecompressed(str) + local s=openstream(str) + local identifier=readstring(s,2) + local method=readbyte(s,1) + local flags=readbyte(s,1) + local timestamp=readcardinal4(s) + local compression=readbyte(s,1) + local operating=readbyte(s,1) + local isjusttext=(flags & 0x01~=0) and true or false + local extrasize=(flags & 0x04~=0) and readcardinal2(s) or 0 + local filename=(flags & 0x08~=0) and readcstring(s) or "" + local comment=(flags & 0x10~=0) and readcstring(s) or "" + local checksum=(flags & 0x02~=0) and readcardinal2(s) or 0 + local compressed=readstring(s,#str) + local data=decompress(compressed,gzipwindow) + return data + end + local function putcompressed(str,level,originalname) + return concat { + identifier, + tocardinal1(0x08), + tocardinal1(0x08), + tocardinal4(os.time()), + tocardinal1(0x02), + tocardinal1(0xFF), + (originalname or "unknownname").."\0", + compress(str,level,nil,gzipwindow), + tocardinal4(crc32(str)), + tocardinal4(#str), + } + end + function gzip.load(filename) + local f=openfile(filename,"rb") + if not f then + else + local data=f:read("*all") + f:close() + if data and data~="" then + if suffix(filename)=="gz" then + data=getdecompressed(data) + end + return data + end + end + end + function gzip.save(filename,data,level,originalname) + if suffix(filename)~="gz" then + filename=filename..".gz" + end + local f=openfile(filename,"wb") + if f then + data=putcompressed(data or "",level or gziplevel,originalname) + f:write(data) + f:close() + return #data + end + end + function gzip.suffix(filename) + local suffix,extra=suffixes(filename) + local gzipped=extra=="gz" + return suffix,gzipped + end + function gzip.compressed(s) + return s and find(s,identifier) + end + function gzip.compress(s,level) + if s and not find(s,identifier) then + if not level then + level=gziplevel + elseif level<=0 then + return s + elseif level>9 then + level=9 + end + return putcompressed(s,level or gziplevel) or s + end + end + function gzip.decompress(s) + if s and find(s,identifier) then + return getdecompressed(s) + else + return s + end + end +end zipfiles.gunzipfile=gzip.load @@ -24134,7 +24180,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-use"] = package.loaded["data-use"] or true --- original size: 5785, stripped down to: 2905 +-- original size: 5806, stripped down to: 2925 if not modules then modules={} end modules ['data-use']={ version=1.001, @@ -24164,14 +24210,14 @@ function statistics.savefmtstatus(texname,formatbanner,sourcefile,banner) functionality=LUATEXFUNCTIONALITY, } io.savedata(luvname,table.serialize(luvdata,true)) - lua.registerfinalizer(function() + lua.registerinitexfinalizer(function() if jit then logs.report("format banner","%s lua: %s jit",banner,LUAVERSION) else logs.report("format banner","%s lua: %s",banner,LUAVERSION) end logs.newline() - end) + end,"show banner") end end function statistics.checkfmtstatus(texname) @@ -24222,7 +24268,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 10725, stripped down to: 7949 +-- original size: 10805, stripped down to: 7951 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -24265,10 +24311,10 @@ if zipfiles then local openstream=streams.open local readstring=streams.readstring local streamsize=streams.size - local metatable={ + local metatable={ close=streams.close, read=function(stream,n) - readstring(stream,n=="*a" and streamsize(stream) or n) + readstring(stream,n=="*a" and streamsize(stream) or n) end } filehandle=function(zfile,queryname) @@ -25850,8 +25896,8 @@ 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 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 libs-ini.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 1025323 --- stripped bytes : 404592 +-- original bytes : 1024297 +-- stripped bytes : 402139 -- end library merge diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index c32050c3f..90674eacc 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1201,7 +1201,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 38735, stripped down to: 19489 +-- original size: 38747, stripped down to: 19489 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -3837,7 +3837,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19410, stripped down to: 10420 +-- original size: 19423, stripped down to: 10421 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3969,7 +3969,7 @@ end local execute=os.execute local iopopen=io.popen local function resultof(command) - local handle=iopopen(command,"r") + local handle=iopopen(command,"rb") if handle then local result=handle:read("*all") or "" handle:close() @@ -4714,7 +4714,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-gzip"] = package.loaded["l-gzip"] or true --- original size: 5115, stripped down to: 1699 +-- original size: 268, stripped down to: 216 if not modules then modules={} end modules ['l-gzip']={ version=1.001, @@ -4722,76 +4722,6 @@ if not modules then modules={} end modules ['l-gzip']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -gzip=gzip or {} -if not zlib then - zlib=xzip -elseif not xzip then - xzip=zlib -end -if zlib then - local suffix=file.suffix - local suffixes=file.suffixes - local find=string.find - local openfile=io.open - local gzipwindow=15+16 - local gziplevel=3 - local identifier="^\x1F\x8B\x08" - local compress=zlib.compress - local decompress=zlib.decompress - function gzip.load(filename) - local f=openfile(filename,"rb") - if not f then - else - local data=f:read("*all") - f:close() - if data and data~="" then - if suffix(filename)=="gz" then - data=decompress(data,gzipwindow) - end - return data - end - end - end - function gzip.save(filename,data,level) - if suffix(filename)~="gz" then - filename=filename..".gz" - end - local f=openfile(filename,"wb") - if f then - data=compress(data or "",level or gziplevel,nil,gzipwindow) - f:write(data) - f:close() - return #data - end - end - function gzip.suffix(filename) - local suffix,extra=suffixes(filename) - local gzipped=extra=="gz" - return suffix,gzipped - end - function gzip.compressed(s) - return s and find(s,identifier) - end - function gzip.compress(s,level) - if s and not find(s,identifier) then - if not level then - level=gziplevel - elseif level<=0 then - return s - elseif level>9 then - level=9 - end - return compress(s,level or gziplevel,nil,gzipwindow) or s - end - end - function gzip.decompress(s) - if s and find(s,identifier) then - return decompress(s,gzipwindow) - else - return s - end - end -end end -- of closure @@ -8285,7 +8215,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 11552, stripped down to: 9023 +-- original size: 11474, stripped down to: 8973 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8452,20 +8382,20 @@ function files.readinteger4le(f) end end function files.readfixed2(f) - local a,b=byte(f:read(2),1,2) - if a>=0x80 then - tonumber((a-0x100).."."..b) - else - tonumber((a ).."."..b) + local n1,n2=byte(f:read(2),1,2) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function files.readfixed4(f) local a,b,c,d=byte(f:read(4),1,4) - if a>=0x80 then - tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) - else - tonumber((0x100*a+b ).."."..(0x100*c+d)) + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -8654,7 +8584,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 12970, stripped down to: 9525 +-- original size: 12905, stripped down to: 9439 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8881,23 +8811,23 @@ function streams.readfixed2(f) local i=f[2] local j=i+1 f[2]=j+1 - local a,b=byte(f[1],i,j) - if a>=0x80 then - return tonumber((a-0x100).."."..b) or 0 - else - return tonumber((a ).."."..b) or 0 + local n1,n2=byte(f[1],i,j) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function streams.readfixed4(f) local i=f[2] local j=i+3 f[2]=j+1 local a,b,c,d=byte(f[1],i,j) - if a>=0x80 then - return tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) or 0 - else - return tonumber((0x100*a+b ).."."..(0x100*c+d)) or 0 + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -9095,10 +9025,10 @@ do function io.newreader(str,method) local f,m if method=="string" then - f=openstring(str) + f=openstring(str,true) m=streams elseif method=="stream" then - f=openstream(str) + f=openstream(str,true) m=streams else f=openfile(str,"rb") @@ -15774,7 +15704,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-zip"] = package.loaded["util-zip"] or true --- original size: 19324, stripped down to: 10821 +-- original size: 23162, stripped down to: 13844 if not modules then modules={} end modules ['util-zip']={ version=1.001, @@ -15789,6 +15719,12 @@ local osdate,ostime,osclock=os.date,os.time,os.clock local ioopen=io.open local loaddata,savedata=io.loaddata,io.savedata local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +gzip=gzip or {} +if not zlib then + zlib=xzip +elseif not xzip then + xzip=zlib +end local files=utilities.files local openfile=files.open local closefile=files.close @@ -16195,6 +16131,116 @@ if xzip then zipfiles.zipdir=zipdir zipfiles.unzipdir=unzipdir end +if not gzip.compress then + local suffix=file.suffix + local suffixes=file.suffixes + local find=string.find + local concat=table.concat + local openfile=io.open + local gzipwindow=-15 + local gziplevel=3 + local identifier="\x1F\x8B" + local pattern="^\x1F\x8B\x08" + local compress=zlib.compress + local decompress=zlib.decompress + local crc32=zlib.crc32 + local streams=utilities.streams + local openstream=streams.openstring + local closestream=streams.close + local getposition=streams.getposition + local readbyte=streams.readbyte + local readcardinal4=streams.readcardinal4le + local readcardinal2=streams.readcardinal2le + local readstring=streams.readstring + local readcstring=streams.readcstring + local skipbytes=streams.skip + local tocardinal1=streams.tocardinal1 + local tocardinal4=streams.tocardinal4le + local function getdecompressed(str) + local s=openstream(str) + local identifier=readstring(s,2) + local method=readbyte(s,1) + local flags=readbyte(s,1) + local timestamp=readcardinal4(s) + local compression=readbyte(s,1) + local operating=readbyte(s,1) + local isjusttext=(flags & 0x01~=0) and true or false + local extrasize=(flags & 0x04~=0) and readcardinal2(s) or 0 + local filename=(flags & 0x08~=0) and readcstring(s) or "" + local comment=(flags & 0x10~=0) and readcstring(s) or "" + local checksum=(flags & 0x02~=0) and readcardinal2(s) or 0 + local compressed=readstring(s,#str) + local data=decompress(compressed,gzipwindow) + return data + end + local function putcompressed(str,level,originalname) + return concat { + identifier, + tocardinal1(0x08), + tocardinal1(0x08), + tocardinal4(os.time()), + tocardinal1(0x02), + tocardinal1(0xFF), + (originalname or "unknownname").."\0", + compress(str,level,nil,gzipwindow), + tocardinal4(crc32(str)), + tocardinal4(#str), + } + end + function gzip.load(filename) + local f=openfile(filename,"rb") + if not f then + else + local data=f:read("*all") + f:close() + if data and data~="" then + if suffix(filename)=="gz" then + data=getdecompressed(data) + end + return data + end + end + end + function gzip.save(filename,data,level,originalname) + if suffix(filename)~="gz" then + filename=filename..".gz" + end + local f=openfile(filename,"wb") + if f then + data=putcompressed(data or "",level or gziplevel,originalname) + f:write(data) + f:close() + return #data + end + end + function gzip.suffix(filename) + local suffix,extra=suffixes(filename) + local gzipped=extra=="gz" + return suffix,gzipped + end + function gzip.compressed(s) + return s and find(s,identifier) + end + function gzip.compress(s,level) + if s and not find(s,identifier) then + if not level then + level=gziplevel + elseif level<=0 then + return s + elseif level>9 then + level=9 + end + return putcompressed(s,level or gziplevel) or s + end + end + function gzip.decompress(s) + if s and find(s,identifier) then + return getdecompressed(s) + else + return s + end + end +end zipfiles.gunzipfile=gzip.load @@ -24134,7 +24180,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-use"] = package.loaded["data-use"] or true --- original size: 5785, stripped down to: 2905 +-- original size: 5806, stripped down to: 2925 if not modules then modules={} end modules ['data-use']={ version=1.001, @@ -24164,14 +24210,14 @@ function statistics.savefmtstatus(texname,formatbanner,sourcefile,banner) functionality=LUATEXFUNCTIONALITY, } io.savedata(luvname,table.serialize(luvdata,true)) - lua.registerfinalizer(function() + lua.registerinitexfinalizer(function() if jit then logs.report("format banner","%s lua: %s jit",banner,LUAVERSION) else logs.report("format banner","%s lua: %s",banner,LUAVERSION) end logs.newline() - end) + end,"show banner") end end function statistics.checkfmtstatus(texname) @@ -24222,7 +24268,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 10725, stripped down to: 7949 +-- original size: 10805, stripped down to: 7951 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -24265,10 +24311,10 @@ if zipfiles then local openstream=streams.open local readstring=streams.readstring local streamsize=streams.size - local metatable={ + local metatable={ close=streams.close, read=function(stream,n) - readstring(stream,n=="*a" and streamsize(stream) or n) + readstring(stream,n=="*a" and streamsize(stream) or n) end } filehandle=function(zfile,queryname) @@ -25850,8 +25896,8 @@ 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 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 libs-ini.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 1025323 --- stripped bytes : 404592 +-- original bytes : 1024297 +-- stripped bytes : 402139 -- end library merge diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua index c32050c3f..90674eacc 100644 --- a/scripts/context/stubs/win64/mtxrun.lua +++ b/scripts/context/stubs/win64/mtxrun.lua @@ -1201,7 +1201,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 38735, stripped down to: 19489 +-- original size: 38747, stripped down to: 19489 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -3837,7 +3837,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 19410, stripped down to: 10420 +-- original size: 19423, stripped down to: 10421 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3969,7 +3969,7 @@ end local execute=os.execute local iopopen=io.popen local function resultof(command) - local handle=iopopen(command,"r") + local handle=iopopen(command,"rb") if handle then local result=handle:read("*all") or "" handle:close() @@ -4714,7 +4714,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-gzip"] = package.loaded["l-gzip"] or true --- original size: 5115, stripped down to: 1699 +-- original size: 268, stripped down to: 216 if not modules then modules={} end modules ['l-gzip']={ version=1.001, @@ -4722,76 +4722,6 @@ if not modules then modules={} end modules ['l-gzip']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -gzip=gzip or {} -if not zlib then - zlib=xzip -elseif not xzip then - xzip=zlib -end -if zlib then - local suffix=file.suffix - local suffixes=file.suffixes - local find=string.find - local openfile=io.open - local gzipwindow=15+16 - local gziplevel=3 - local identifier="^\x1F\x8B\x08" - local compress=zlib.compress - local decompress=zlib.decompress - function gzip.load(filename) - local f=openfile(filename,"rb") - if not f then - else - local data=f:read("*all") - f:close() - if data and data~="" then - if suffix(filename)=="gz" then - data=decompress(data,gzipwindow) - end - return data - end - end - end - function gzip.save(filename,data,level) - if suffix(filename)~="gz" then - filename=filename..".gz" - end - local f=openfile(filename,"wb") - if f then - data=compress(data or "",level or gziplevel,nil,gzipwindow) - f:write(data) - f:close() - return #data - end - end - function gzip.suffix(filename) - local suffix,extra=suffixes(filename) - local gzipped=extra=="gz" - return suffix,gzipped - end - function gzip.compressed(s) - return s and find(s,identifier) - end - function gzip.compress(s,level) - if s and not find(s,identifier) then - if not level then - level=gziplevel - elseif level<=0 then - return s - elseif level>9 then - level=9 - end - return compress(s,level or gziplevel,nil,gzipwindow) or s - end - end - function gzip.decompress(s) - if s and find(s,identifier) then - return decompress(s,gzipwindow) - else - return s - end - end -end end -- of closure @@ -8285,7 +8215,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-fil"] = package.loaded["util-fil"] or true --- original size: 11552, stripped down to: 9023 +-- original size: 11474, stripped down to: 8973 if not modules then modules={} end modules ['util-fil']={ version=1.001, @@ -8452,20 +8382,20 @@ function files.readinteger4le(f) end end function files.readfixed2(f) - local a,b=byte(f:read(2),1,2) - if a>=0x80 then - tonumber((a-0x100).."."..b) - else - tonumber((a ).."."..b) + local n1,n2=byte(f:read(2),1,2) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function files.readfixed4(f) local a,b,c,d=byte(f:read(4),1,4) - if a>=0x80 then - tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) - else - tonumber((0x100*a+b ).."."..(0x100*c+d)) + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -8654,7 +8584,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-sac"] = package.loaded["util-sac"] or true --- original size: 12970, stripped down to: 9525 +-- original size: 12905, stripped down to: 9439 if not modules then modules={} end modules ['util-sac']={ version=1.001, @@ -8881,23 +8811,23 @@ function streams.readfixed2(f) local i=f[2] local j=i+1 f[2]=j+1 - local a,b=byte(f[1],i,j) - if a>=0x80 then - return tonumber((a-0x100).."."..b) or 0 - else - return tonumber((a ).."."..b) or 0 + local n1,n2=byte(f[1],i,j) + if n1>=0x80 then + n1=n1-0x100 end + return n1+n2/0xFF end function streams.readfixed4(f) local i=f[2] local j=i+3 f[2]=j+1 local a,b,c,d=byte(f[1],i,j) - if a>=0x80 then - return tonumber((0x100*a+b-0x10000).."."..(0x100*c+d)) or 0 - else - return tonumber((0x100*a+b ).."."..(0x100*c+d)) or 0 + local n1=0x100*a+b + local n2=0x100*c+d + if n1>=0x8000 then + n1=n1-0x10000 end + return n1+n2/0xFFFF end if bit32 then local extract=bit32.extract @@ -9095,10 +9025,10 @@ do function io.newreader(str,method) local f,m if method=="string" then - f=openstring(str) + f=openstring(str,true) m=streams elseif method=="stream" then - f=openstream(str) + f=openstream(str,true) m=streams else f=openfile(str,"rb") @@ -15774,7 +15704,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-zip"] = package.loaded["util-zip"] or true --- original size: 19324, stripped down to: 10821 +-- original size: 23162, stripped down to: 13844 if not modules then modules={} end modules ['util-zip']={ version=1.001, @@ -15789,6 +15719,12 @@ local osdate,ostime,osclock=os.date,os.time,os.clock local ioopen=io.open local loaddata,savedata=io.loaddata,io.savedata local filejoin,isdir,dirname,mkdirs=file.join,lfs.isdir,file.dirname,dir.mkdirs +gzip=gzip or {} +if not zlib then + zlib=xzip +elseif not xzip then + xzip=zlib +end local files=utilities.files local openfile=files.open local closefile=files.close @@ -16195,6 +16131,116 @@ if xzip then zipfiles.zipdir=zipdir zipfiles.unzipdir=unzipdir end +if not gzip.compress then + local suffix=file.suffix + local suffixes=file.suffixes + local find=string.find + local concat=table.concat + local openfile=io.open + local gzipwindow=-15 + local gziplevel=3 + local identifier="\x1F\x8B" + local pattern="^\x1F\x8B\x08" + local compress=zlib.compress + local decompress=zlib.decompress + local crc32=zlib.crc32 + local streams=utilities.streams + local openstream=streams.openstring + local closestream=streams.close + local getposition=streams.getposition + local readbyte=streams.readbyte + local readcardinal4=streams.readcardinal4le + local readcardinal2=streams.readcardinal2le + local readstring=streams.readstring + local readcstring=streams.readcstring + local skipbytes=streams.skip + local tocardinal1=streams.tocardinal1 + local tocardinal4=streams.tocardinal4le + local function getdecompressed(str) + local s=openstream(str) + local identifier=readstring(s,2) + local method=readbyte(s,1) + local flags=readbyte(s,1) + local timestamp=readcardinal4(s) + local compression=readbyte(s,1) + local operating=readbyte(s,1) + local isjusttext=(flags & 0x01~=0) and true or false + local extrasize=(flags & 0x04~=0) and readcardinal2(s) or 0 + local filename=(flags & 0x08~=0) and readcstring(s) or "" + local comment=(flags & 0x10~=0) and readcstring(s) or "" + local checksum=(flags & 0x02~=0) and readcardinal2(s) or 0 + local compressed=readstring(s,#str) + local data=decompress(compressed,gzipwindow) + return data + end + local function putcompressed(str,level,originalname) + return concat { + identifier, + tocardinal1(0x08), + tocardinal1(0x08), + tocardinal4(os.time()), + tocardinal1(0x02), + tocardinal1(0xFF), + (originalname or "unknownname").."\0", + compress(str,level,nil,gzipwindow), + tocardinal4(crc32(str)), + tocardinal4(#str), + } + end + function gzip.load(filename) + local f=openfile(filename,"rb") + if not f then + else + local data=f:read("*all") + f:close() + if data and data~="" then + if suffix(filename)=="gz" then + data=getdecompressed(data) + end + return data + end + end + end + function gzip.save(filename,data,level,originalname) + if suffix(filename)~="gz" then + filename=filename..".gz" + end + local f=openfile(filename,"wb") + if f then + data=putcompressed(data or "",level or gziplevel,originalname) + f:write(data) + f:close() + return #data + end + end + function gzip.suffix(filename) + local suffix,extra=suffixes(filename) + local gzipped=extra=="gz" + return suffix,gzipped + end + function gzip.compressed(s) + return s and find(s,identifier) + end + function gzip.compress(s,level) + if s and not find(s,identifier) then + if not level then + level=gziplevel + elseif level<=0 then + return s + elseif level>9 then + level=9 + end + return putcompressed(s,level or gziplevel) or s + end + end + function gzip.decompress(s) + if s and find(s,identifier) then + return getdecompressed(s) + else + return s + end + end +end zipfiles.gunzipfile=gzip.load @@ -24134,7 +24180,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-use"] = package.loaded["data-use"] or true --- original size: 5785, stripped down to: 2905 +-- original size: 5806, stripped down to: 2925 if not modules then modules={} end modules ['data-use']={ version=1.001, @@ -24164,14 +24210,14 @@ function statistics.savefmtstatus(texname,formatbanner,sourcefile,banner) functionality=LUATEXFUNCTIONALITY, } io.savedata(luvname,table.serialize(luvdata,true)) - lua.registerfinalizer(function() + lua.registerinitexfinalizer(function() if jit then logs.report("format banner","%s lua: %s jit",banner,LUAVERSION) else logs.report("format banner","%s lua: %s",banner,LUAVERSION) end logs.newline() - end) + end,"show banner") end end function statistics.checkfmtstatus(texname) @@ -24222,7 +24268,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-zip"] = package.loaded["data-zip"] or true --- original size: 10725, stripped down to: 7949 +-- original size: 10805, stripped down to: 7951 if not modules then modules={} end modules ['data-zip']={ version=1.001, @@ -24265,10 +24311,10 @@ if zipfiles then local openstream=streams.open local readstring=streams.readstring local streamsize=streams.size - local metatable={ + local metatable={ close=streams.close, read=function(stream,n) - readstring(stream,n=="*a" and streamsize(stream) or n) + readstring(stream,n=="*a" and streamsize(stream) or n) end } filehandle=function(zfile,queryname) @@ -25850,8 +25896,8 @@ 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 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 libs-ini.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 1025323 --- stripped bytes : 404592 +-- original bytes : 1024297 +-- stripped bytes : 402139 -- end library merge |