diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-03-23 23:12:42 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-03-23 23:12:42 +0100 |
commit | 15c9a0a54f08ffc9fb72d6d878db4602ac6e1ca2 (patch) | |
tree | 19f4f5a061de3fe14f8e990437c69f740026e9a1 | |
parent | b958bba841f9907582f3c5fa4b6162353636fc8f (diff) | |
download | context-15c9a0a54f08ffc9fb72d6d878db4602ac6e1ca2.tar.gz |
2019-03-21 21:47:00current
91 files changed, 4013 insertions, 944 deletions
diff --git a/doc/context/documents/general/qrcs/setup-cs.pdf b/doc/context/documents/general/qrcs/setup-cs.pdf Binary files differindex 0a02331c2..3d1e4f5de 100644 --- a/doc/context/documents/general/qrcs/setup-cs.pdf +++ b/doc/context/documents/general/qrcs/setup-cs.pdf diff --git a/doc/context/documents/general/qrcs/setup-de.pdf b/doc/context/documents/general/qrcs/setup-de.pdf Binary files differindex fdc000a1f..df9f4f122 100644 --- a/doc/context/documents/general/qrcs/setup-de.pdf +++ b/doc/context/documents/general/qrcs/setup-de.pdf diff --git a/doc/context/documents/general/qrcs/setup-en.pdf b/doc/context/documents/general/qrcs/setup-en.pdf Binary files differindex 147d7755b..c4450ad71 100644 --- a/doc/context/documents/general/qrcs/setup-en.pdf +++ b/doc/context/documents/general/qrcs/setup-en.pdf diff --git a/doc/context/documents/general/qrcs/setup-fr.pdf b/doc/context/documents/general/qrcs/setup-fr.pdf Binary files differindex f835d6ade..6b5603f4f 100644 --- a/doc/context/documents/general/qrcs/setup-fr.pdf +++ b/doc/context/documents/general/qrcs/setup-fr.pdf diff --git a/doc/context/documents/general/qrcs/setup-it.pdf b/doc/context/documents/general/qrcs/setup-it.pdf Binary files differindex 88576c838..86359572b 100644 --- a/doc/context/documents/general/qrcs/setup-it.pdf +++ b/doc/context/documents/general/qrcs/setup-it.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf Binary files differindex 535c6d157..3883ae49e 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-de.pdf b/doc/context/documents/general/qrcs/setup-mapping-de.pdf Binary files differindex ad1893c29..58e98cfe2 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-de.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-de.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-en.pdf b/doc/context/documents/general/qrcs/setup-mapping-en.pdf Binary files differindex 30f757833..5fee547d2 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-en.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-en.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf Binary files differindex 39a3f6cb8..1b8d7be73 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-it.pdf b/doc/context/documents/general/qrcs/setup-mapping-it.pdf Binary files differindex 7b0254841..5714fef31 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-it.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-it.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf Binary files differindex 2290d98cf..4d776ed86 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf Binary files differindex d10ea0b9a..f387f4c06 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf diff --git a/doc/context/documents/general/qrcs/setup-nl.pdf b/doc/context/documents/general/qrcs/setup-nl.pdf Binary files differindex d482570f1..d25676688 100644 --- a/doc/context/documents/general/qrcs/setup-nl.pdf +++ b/doc/context/documents/general/qrcs/setup-nl.pdf diff --git a/doc/context/documents/general/qrcs/setup-ro.pdf b/doc/context/documents/general/qrcs/setup-ro.pdf Binary files differindex b30441453..5d0e026e6 100644 --- a/doc/context/documents/general/qrcs/setup-ro.pdf +++ b/doc/context/documents/general/qrcs/setup-ro.pdf diff --git a/doc/context/sources/general/manuals/luatex/luatex-nodes.tex b/doc/context/sources/general/manuals/luatex/luatex-nodes.tex index 34a2aebe8..21e8a2808 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-nodes.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-nodes.tex @@ -2305,8 +2305,8 @@ consistency. You can of course always define additional accessors using \type \def\supported#1#2#3% {\NC \type{#1} - \NC \ifx#2\yes\libidx{node} {#1}\fi #2 - \NC \ifx#3\yes\libidx{node.direct}{#1}\fi #3 \NC + \NC \ifx#2\yes\lix{node} {#1}\fi #2 + \NC \ifx#3\yes\lix{node.direct}{#1}\fi #3 \NC \NR} \starttabulate[|l|c|c|] diff --git a/doc/context/sources/general/manuals/luatex/luatex-style.tex b/doc/context/sources/general/manuals/luatex/luatex-style.tex index 708f83ed6..aa0a7edc3 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-style.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-style.tex @@ -436,6 +436,7 @@ \unexpanded\def\lib #1{\doifmode{*bodypart}{\expanded{\libraryindex{\currentlibraryindex+#1}}\type{\currentlibraryindex.#1}}} \unexpanded\def\libindex#1{\doifmode{*bodypart}{\expanded{\libraryindex{\currentlibraryindex+#1}}}} \unexpanded\def\libidx#1#2{\doifmode{*bodypart}{\expanded{\libraryindex{#1+#2}}\type{#1.#2}}} +\unexpanded\def\lix #1#2{\doifmode{*bodypart}{\expanded{\libraryindex{#1+#2}}}} % \setstructurepageregister[][keys:1=,entries:1=] diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 131796757..f39010e00 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -16,7 +16,7 @@ if known context_mlib : endinput ; fi ; boolean context_mlib ; context_mlib := true ; -numeric LUATEXFUNCTIONALITY ; LUATEXFUNCTIONALITY := runscript("mp.print(LUATEXFUNCTIONALITY)") ; +% numeric LUATEXFUNCTIONALITY ; LUATEXFUNCTIONALITY := runscript("mp.print(LUATEXFUNCTIONALITY or (status and status.development_id) or 6346)") ; %D Objects: 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 @@ -15613,6 +15693,468 @@ 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]<b[1] + end) + local zipf=openzip(zipname,level,comment,verbose) + if zipf then + local p=#path+2 + for i=1,count do + local li=list[i] + local name=li[1] + local time=li[2] + local data=loaddata(name) + local name=sub(name,p,#name) + writezip(zipf,name,data,level,time,verbose) + end + closezip(zipf) + end + end + local function unzipdir(zipname,path,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + local z=openzipfile(zipname) + if z then + local list=getziplist(z) + if list then + local total=0 + local count=#list + local step=number.idiv(count,10) + local done=0 + for i=1,count do + local l=list[i] + local n=l.filename + local d=unzipfile(z,n) + local p=filejoin(path,n) + if mkdirs(dirname(p)) then + if verbose=="steps" then + total=total+#d + done=done+1 + if done>=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 + package.loaded["lxml-tab"] = package.loaded["lxml-tab"] or true -- original size: 60383, stripped down to: 35698 @@ -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 @@ -15613,6 +15693,468 @@ 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]<b[1] + end) + local zipf=openzip(zipname,level,comment,verbose) + if zipf then + local p=#path+2 + for i=1,count do + local li=list[i] + local name=li[1] + local time=li[2] + local data=loaddata(name) + local name=sub(name,p,#name) + writezip(zipf,name,data,level,time,verbose) + end + closezip(zipf) + end + end + local function unzipdir(zipname,path,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + local z=openzipfile(zipname) + if z then + local list=getziplist(z) + if list then + local total=0 + local count=#list + local step=number.idiv(count,10) + local done=0 + for i=1,count do + local l=list[i] + local n=l.filename + local d=unzipfile(z,n) + local p=filejoin(path,n) + if mkdirs(dirname(p)) then + if verbose=="steps" then + total=total+#d + done=done+1 + if done>=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 + package.loaded["lxml-tab"] = package.loaded["lxml-tab"] or true -- original size: 60383, stripped down to: 35698 @@ -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 @@ -15613,6 +15693,468 @@ 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]<b[1] + end) + local zipf=openzip(zipname,level,comment,verbose) + if zipf then + local p=#path+2 + for i=1,count do + local li=list[i] + local name=li[1] + local time=li[2] + local data=loaddata(name) + local name=sub(name,p,#name) + writezip(zipf,name,data,level,time,verbose) + end + closezip(zipf) + end + end + local function unzipdir(zipname,path,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + local z=openzipfile(zipname) + if z then + local list=getziplist(z) + if list then + local total=0 + local count=#list + local step=number.idiv(count,10) + local done=0 + for i=1,count do + local l=list[i] + local n=l.filename + local d=unzipfile(z,n) + local p=filejoin(path,n) + if mkdirs(dirname(p)) then + if verbose=="steps" then + total=total+#d + done=done+1 + if done>=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 + package.loaded["lxml-tab"] = package.loaded["lxml-tab"] or true -- original size: 60383, stripped down to: 35698 @@ -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 @@ -15613,6 +15693,468 @@ 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]<b[1] + end) + local zipf=openzip(zipname,level,comment,verbose) + if zipf then + local p=#path+2 + for i=1,count do + local li=list[i] + local name=li[1] + local time=li[2] + local data=loaddata(name) + local name=sub(name,p,#name) + writezip(zipf,name,data,level,time,verbose) + end + closezip(zipf) + end + end + local function unzipdir(zipname,path,verbose) + if type(zipname)=="table" then + verbose=zipname.verbose + path=zipname.path + zipname=zipname.zipname + end + if not zipname or zipname=="" then + return + end + if not path or path=="" then + path="." + end + local z=openzipfile(zipname) + if z then + local list=getziplist(z) + if list then + local total=0 + local count=#list + local step=number.idiv(count,10) + local done=0 + for i=1,count do + local l=list[i] + local n=l.filename + local d=unzipfile(z,n) + local p=filejoin(path,n) + if mkdirs(dirname(p)) then + if verbose=="steps" then + total=total+#d + done=done+1 + if done>=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 + package.loaded["lxml-tab"] = package.loaded["lxml-tab"] or true -- original size: 60383, stripped down to: 35698 @@ -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/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index faa50ce78..a1981921b 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.03.05 15:40} +\newcontextversion{2019.03.21 21:39} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index c0e856845..a6f8647ee 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2019.03.05 15:40} +\edef\contextversion{2019.03.21 21:39} %D For those who want to use this: diff --git a/tex/context/base/mkiv/char-ini.mkiv b/tex/context/base/mkiv/char-ini.mkiv index 0519aaf91..5979b8685 100644 --- a/tex/context/base/mkiv/char-ini.mkiv +++ b/tex/context/base/mkiv/char-ini.mkiv @@ -57,14 +57,34 @@ \unexpanded\def\checkedtextchar#1% #2% {\clf_doifelsecharinfont\numexpr#1\relax{\char#1}} % {#2} +% \unexpanded\def\textormathchar#1% +% {\relax\ifmmode +% \char#1\relax +% \else\iffontchar\font#1\relax +% \char#1\relax +% \else +% \normalstartimath\char#1\normalstopimath +% \fi\fi} + +\newconditional\prefermathovertextchar + \unexpanded\def\textormathchar#1% - {\relax\ifmmode - \char#1\relax - \else\iffontchar\font#1\relax - \char#1\relax + {\begingroup + \scratchcounter#1\relax + \ifmmode + \char\scratchcounter \else - \normalstartimath\char#1\normalstopimath - \fi\fi} + \ifconditional\prefermathovertextchar + % dirty trick .. maybe let this adapt to bf too ? + \setfontid\fontid\textfont\c_font_fam_mr + \fi + \iffontchar\font\scratchcounter + \char\scratchcounter + \else + \normalstartimath\char\scratchcounter\normalstopimath + \fi + \fi + \endgroup} \unexpanded\def\textormathchars#1% {{\font_text_or_mathchars#1\relax}} diff --git a/tex/context/base/mkiv/cldf-ini.lua b/tex/context/base/mkiv/cldf-ini.lua index ccbbb2454..15ebc9d95 100644 --- a/tex/context/base/mkiv/cldf-ini.lua +++ b/tex/context/base/mkiv/cldf-ini.lua @@ -793,7 +793,7 @@ local function writer(parent,command,...) -- already optimized before call tj = storefunction(tj) if tokenflushmode then if newtoken then - flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_code),"]") + flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_token_code),"]") else flush(currentcatcodes,"[",t_cldl_luafunction,tj,"]") end @@ -811,7 +811,7 @@ local function writer(parent,command,...) -- already optimized before call tj = storefunction(tj) if tokenflushmode then if newtoken then - flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_code),j == tn and "]" or ",") + flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_token_code),j == tn and "]" or ",") else flush(currentcatcodes,"[",t_cldl_luafunction,tj,j == tn and "]" or ",") end diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 913fa747f..f75814652 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.03.05 15:40} +\newcontextversion{2019.03.21 21:39} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 81558c98a..4059a2975 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.03.05 15:40} +\edef\contextversion{2019.03.21 21:39} \edef\contextkind {beta} %D Kind of special: diff --git a/tex/context/base/mkiv/data-exp.lua b/tex/context/base/mkiv/data-exp.lua index 76fd3c7b0..ce7f95222 100644 --- a/tex/context/base/mkiv/data-exp.lua +++ b/tex/context/base/mkiv/data-exp.lua @@ -344,9 +344,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 diff --git a/tex/context/base/mkiv/data-tmp.lua b/tex/context/base/mkiv/data-tmp.lua index 948827161..d25a6b2f9 100644 --- a/tex/context/base/mkiv/data-tmp.lua +++ b/tex/context/base/mkiv/data-tmp.lua @@ -68,6 +68,8 @@ 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, { }, { } -- we could use a metatable for writable and readable but not yet @@ -364,7 +366,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) diff --git a/tex/context/base/mkiv/data-zip.lua b/tex/context/base/mkiv/data-zip.lua index 6f20b4a9d..388ae0c10 100644 --- a/tex/context/base/mkiv/data-zip.lua +++ b/tex/context/base/mkiv/data-zip.lua @@ -37,6 +37,81 @@ 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) -- todo: use url splitter if not find(str,"^zip://") then return "zip:///" .. str @@ -52,7 +127,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 @@ -61,7 +136,7 @@ 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 @@ -106,9 +181,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 @@ -139,12 +212,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 @@ -171,15 +244,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 @@ -231,7 +302,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 diff --git a/tex/context/base/mkiv/font-lib.mkvi b/tex/context/base/mkiv/font-lib.mkvi index 3cff81751..081ae0f38 100644 --- a/tex/context/base/mkiv/font-lib.mkvi +++ b/tex/context/base/mkiv/font-lib.mkvi @@ -50,6 +50,7 @@ \registerctxluafile{font-otc}{} \registerctxluafile{font-oth}{} \registerctxluafile{font-osd}{} +% \doifelsefileexists{font-osm.lua}{\registerctxluafile{font-osm}{}}{} \registerctxluafile{font-ocl}{} % we use otf code for type one diff --git a/tex/context/base/mkiv/font-one.lua b/tex/context/base/mkiv/font-one.lua index 18ba51185..9b296cac5 100644 --- a/tex/context/base/mkiv/font-one.lua +++ b/tex/context/base/mkiv/font-one.lua @@ -761,7 +761,7 @@ local function check_afm(specification,fullname) if foundname == "" then foundname = fonts.names.getfilename(fullname,"afm") or "" end - if foundname == "" and afm.autoprefixed then + if fullname and foundname == "" and afm.autoprefixed then local encoding, shortname = match(fullname,"^(.-)%-(.*)$") -- context: encoding-name.* if encoding and shortname and fonts.encodings.known[encoding] then shortname = findbinfile(shortname,'afm') or "" -- just to be sure diff --git a/tex/context/base/mkiv/font-osd.lua b/tex/context/base/mkiv/font-osd.lua index 32d791b48..f51ae7bf7 100644 --- a/tex/context/base/mkiv/font-osd.lua +++ b/tex/context/base/mkiv/font-osd.lua @@ -615,6 +615,8 @@ local function initializedevanagi(tfmdata) end end -- + -- needs checking: this might be needed per instance ? + -- if script == "deva" then sharedfeatures["dv04"] = true -- dv04_remove_joiners elseif script == "dev2" then @@ -689,7 +691,7 @@ local function initialize_one(font,attr) -- we need a proper hook into the datas if not devanagaridata then - devanagaridata = { + devanagaridata = { reph = false, vattu = false, blwfcache = { }, @@ -1329,7 +1331,7 @@ end function handlers.devanagari_remove_joiners(head,start,kind,lookupname,replacement) local stop = getnext(start) - local font = getfont(start) + local font = getfont(start) -- hm local last = start while stop do local char = ischar(stop,font) diff --git a/tex/context/base/mkiv/font-syn.lua b/tex/context/base/mkiv/font-syn.lua index dfe32b57b..18c25fbfd 100644 --- a/tex/context/base/mkiv/font-syn.lua +++ b/tex/context/base/mkiv/font-syn.lua @@ -515,15 +515,20 @@ local function cleanname(name) end local function cleanfilename(fullname,defaultsuffix) - local path, name, suffix = splitname(fullname) - name = gsub(lower(name),"[^%a%d]","") - if suffix and suffix ~= "" then - return name .. ".".. suffix - elseif defaultsuffix and defaultsuffix ~= "" then - return name .. ".".. defaultsuffix - else - return name + if fullname then + local path, name, suffix = splitname(fullname) + if name then + name = gsub(lower(name),"[^%a%d]","") + if suffix and suffix ~= "" then + return name .. ".".. suffix + elseif defaultsuffix and defaultsuffix ~= "" then + return name .. ".".. defaultsuffix + else + return name + end + end end + return "badfontname" end local sorter = function(a,b) diff --git a/tex/context/base/mkiv/grph-inc.lua b/tex/context/base/mkiv/grph-inc.lua index f66f8249a..0856e0de9 100644 --- a/tex/context/base/mkiv/grph-inc.lua +++ b/tex/context/base/mkiv/grph-inc.lua @@ -1611,15 +1611,15 @@ function includers.generic(data) ds.pageindex = nofimages local image = wrapimage(figure) local pager = new_latelua { action = updatepage, n = nofimages } - image.next = pager - pager.prev = image - local box = hpack(image) - -- indexed[figure.index] = figure - box.width = figure.width - box.height = figure.height - box.depth = 0 + image.next = pager + pager.prev = image + local box = hpack(image) + box.width = figure.width + box.height = figure.height + box.depth = 0 texsetbox(nr,box) ds.objectnumber = figure.objnum + -- indexed[figure.index] = figure ctx_relocateexternalfigure() end return data diff --git a/tex/context/base/mkiv/l-dir.lua b/tex/context/base/mkiv/l-dir.lua index b0b2c5283..325039cb1 100644 --- a/tex/context/base/mkiv/l-dir.lua +++ b/tex/context/base/mkiv/l-dir.lua @@ -91,13 +91,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 @@ -134,10 +136,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 @@ -193,7 +197,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 -- cna be optimized if name == "." then -- skip elseif name == ".." then @@ -321,11 +325,13 @@ local function globfiles(path,recurse,func,files) -- func == pattern or function end files = files or { } local noffiles = #files - for name in walkdir(path) do + for name, mode in walkdir(path) do if find(name,"^%.") then --- skip 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) @@ -350,11 +356,13 @@ local function globdirs(path,recurse,func,files) -- func == pattern or function end files = files or { } local noffiles = #files - for name in walkdir(path) do + for name, mode in walkdir(path) do if find(name,"^%.") then --- skip 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 @@ -597,8 +605,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 diff --git a/tex/context/base/mkiv/l-file.lua b/tex/context/base/mkiv/l-file.lua index 46b6847d3..1b039a438 100644 --- a/tex/context/base/mkiv/l-file.lua +++ b/tex/context/base/mkiv/l-file.lua @@ -73,13 +73,9 @@ local P, R, S, C, Cs, Cp, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg -- better this way: ------ tricky = S("/\\") * P(-1) local attributes = lfs.attributes function lfs.isdir(name) - -- if not lpegmatch(tricky,name) then - -- name = name .. "/." - -- end return attributes(name,"mode") == "directory" end @@ -336,43 +332,52 @@ end -- But after some testing Taco and I came up with the more robust -- variant: -function file.is_writable(name) - if not name then - -- error - 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 + -- error + 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 + return false end - return false -end -local readable = P("r") * Cc(true) + 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 + 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 -- depricated diff --git a/tex/context/base/mkiv/l-lua.lua b/tex/context/base/mkiv/l-lua.lua index d8989364e..5570e83dc 100644 --- a/tex/context/base/mkiv/l-lua.lua +++ b/tex/context/base/mkiv/l-lua.lua @@ -250,5 +250,6 @@ end -- if not loaded["socket.url"] then loaded["socket.url"] = socket.url end if LUAVERSION > 5.3 then - collectgarbage("generational") + -- collectgarbage("collect") + -- collectgarbage("generational") -- crashes on unix end diff --git a/tex/context/base/mkiv/l-os.lua b/tex/context/base/mkiv/l-os.lua index cf469f79d..15408565c 100644 --- a/tex/context/base/mkiv/l-os.lua +++ b/tex/context/base/mkiv/l-os.lua @@ -230,22 +230,6 @@ function os.launch(str) execute(format(launchers[os.name] or launchers.unix,str)) end -if not os.times then -- ? - -- utime = user time - -- stime = system time - -- cutime = children user time - -- cstime = children system time - function os.times() - return { - utime = os.gettimeofday(), -- user - stime = 0, -- system - cutime = 0, -- children user - cstime = 0, -- children system - } - end -end - - local gettimeofday = os.gettimeofday or os.clock os.gettimeofday = gettimeofday diff --git a/tex/context/base/mkiv/lang-dis.lua b/tex/context/base/mkiv/lang-dis.lua index 5603d1193..90e84f65d 100644 --- a/tex/context/base/mkiv/lang-dis.lua +++ b/tex/context/base/mkiv/lang-dis.lua @@ -180,7 +180,6 @@ end -- experiment: for now not in not in export mode! local flatten = languages.flatten -local getlist = nodes.getlist nodes.handlers.flattenline = flatten diff --git a/tex/context/base/mkiv/lpdf-col.lua b/tex/context/base/mkiv/lpdf-col.lua index b697dc481..9ba64abba 100644 --- a/tex/context/base/mkiv/lpdf-col.lua +++ b/tex/context/base/mkiv/lpdf-col.lua @@ -429,7 +429,8 @@ function codeinjections.setfigurecolorspace(data,figure) local ref = indexcolorref(color) if ref then figure.colorspace = ref - data.used.color = color + data.used.color = color + data.used.colorref = ref end end end diff --git a/tex/context/base/mkiv/lpdf-pde.lua b/tex/context/base/mkiv/lpdf-pde.lua index 9d14f8f5e..c1680137d 100644 --- a/tex/context/base/mkiv/lpdf-pde.lua +++ b/tex/context/base/mkiv/lpdf-pde.lua @@ -1003,7 +1003,15 @@ if img then do return openpdf(str,userpassword,ownerpassword,true) end - local function querypdf(pdfdoc,pagenumber) + local sizes = { + crop = "CropBox", + media = "MediaBox", + bleed = "BleedBox", + art = "ArtBox", + trim = "TrimBox", + } + + local function querypdf(pdfdoc,pagenumber,size) if pdfdoc then if not pagenumber then pagenumber = 1 @@ -1011,9 +1019,9 @@ if img then do local root = pdfdoc.Catalog local page = pdfdoc.pages[pagenumber] if page then - -- todo + local sizetag = sizes[size or "crop"] or sizes.cro local mediabox = page.MediaBox or { 0, 0, 0, 0 } - local cropbox = page.CropBox or mediabox + local cropbox = page[sizetag] or mediabox return { filename = pdfdoc.filename, pagenumber = pagenumber, diff --git a/tex/context/base/mkiv/luat-fmt.lua b/tex/context/base/mkiv/luat-fmt.lua index 1c9222d95..586c5948e 100644 --- a/tex/context/base/mkiv/luat-fmt.lua +++ b/tex/context/base/mkiv/luat-fmt.lua @@ -79,6 +79,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", diff --git a/tex/context/base/mkiv/luat-lib.mkiv b/tex/context/base/mkiv/luat-lib.mkiv index d5f6099ca..666032369 100644 --- a/tex/context/base/mkiv/luat-lib.mkiv +++ b/tex/context/base/mkiv/luat-lib.mkiv @@ -54,6 +54,10 @@ %registerctxluafile{util-soc-imp-ftp} {} %registerctxluafile{util-soc-imp-smtp} {} +\ifcase\contextlmtxmode\else + \registerctxluafile{util-zip}{} +\fi + \registerctxluafile{data-ini}{} \registerctxluafile{data-exp}{} \registerctxluafile{data-env}{} diff --git a/tex/context/base/mkiv/luat-run.lua b/tex/context/base/mkiv/luat-run.lua index 98f981777..00cc65075 100644 --- a/tex/context/base/mkiv/luat-run.lua +++ b/tex/context/base/mkiv/luat-run.lua @@ -64,8 +64,9 @@ local function stop_run() end end if quit then - if status.setexitcode then - status.setexitcode(1) + local setexitcode = lua.setexitcode or status.setexitcode + if setexitcode then + setexitcode(1) if type(quit) == "table" then logs.newline() report_tex("quitting due to: %, t",quit) diff --git a/tex/context/base/mkiv/mlib-run.lua b/tex/context/base/mkiv/mlib-run.lua index 670c0e16b..09872ef0f 100644 --- a/tex/context/base/mkiv/mlib-run.lua +++ b/tex/context/base/mkiv/mlib-run.lua @@ -348,6 +348,13 @@ function metapost.pushformat(specification,f,m) -- was: instance, name, method return mpx end + +-- luatex.wrapup(function() +-- for k, mpx in next, mpxformats do +-- mpx:finish() +-- end +-- end) + function metapost.popformat() nofformats = nofformats - 1 end diff --git a/tex/context/base/mkiv/mtx-context-listing.tex b/tex/context/base/mkiv/mtx-context-listing.tex index 1053e80b9..285113850 100644 --- a/tex/context/base/mkiv/mtx-context-listing.tex +++ b/tex/context/base/mkiv/mtx-context-listing.tex @@ -116,10 +116,10 @@ -- forced end context.page() - context.setupfootertexts( -- return true: we need to keep this entry - { function() context.detokenize(pattern and filename or file.basename(filename)) return true end }, - { function() context.pagenumber() return true end } - ) +-- context.setupfootertexts( -- return true: we need to keep this entry +-- { function() context.detokenize(pattern and filename or file.basename(filename)) return true end }, +-- { function() context.pagenumber() return true end } +-- ) if scite then context.scitefile { filename } -- here { } elseif pretty then diff --git a/tex/context/base/mkiv/node-met.lua b/tex/context/base/mkiv/node-met.lua index f5db4babd..574c71f60 100644 --- a/tex/context/base/mkiv/node-met.lua +++ b/tex/context/base/mkiv/node-met.lua @@ -136,103 +136,82 @@ nodes.is_zero_glue = node.is_zero_glue nodes.tonode = function(n) return n end nodes.tonut = function(n) return n end -local n_getid = node.getid -local n_getlist = node.getlist -local n_getnext = node.getnext -local n_getprev = node.getprev -local n_getchar = node.getchar -local n_getfont = node.getfont -local n_getsubtype = node.getsubtype -local n_getfield = node.getfield -local n_getattr = node.get_attribute -local n_getdisc = node.getdisc -local n_getleader = node.getleader - -local n_setfield = node.setfield -local n_setattr = n_setfield - -local n_setnext = node.setnext or -- always - function(c,n) - n_setfield(c,"next",n) - end -local n_setprev = node.setprev or -- always - function(c,p) - n_setfield(c,"prev",p) - end -local n_setlist = node.setlist or -- always - function(c,l) - n_setfield(c,"list",l) - end -local n_setlink = node.setlink or -- always - function(...) - -- not that fast but not used often anyway - local h = nil - for i=1,select("#",...) do - local n = select(i,...) - if not n then - -- go on - elseif h then - n_setfield(h,"next",n) - n_setfield(n,"prev",h) - else - h = n - end +-- These are never used in \CONTEXT, only as a gimmick in node operators +-- so we keep them around. + +local n_getfield = node.getfield +local n_getattr = node.get_attribute + +local n_setfield = node.setfield +local n_setattr = n_setfield + +nodes.getfield = n_getfield +nodes.setfield = n_setfield +nodes.getattr = n_getattr +nodes.setattr = n_setattr +nodes.takeattr = nodes.unset_attribute + +local function n_getid (n) return n_getfield(n,"id") end +local function n_getsubtype(n) return n_getfield(n,"subtype") end + +nodes.getid = n_getid +nodes.getsubtype = n_getsubtype + +local function n_getchar(n) return n_getfield(n,"char") end +local function n_setchar(n,c) return n_setfield(n,"char",c) end +local function n_getfont(n) return n_getfield(n,"font") end +local function n_setfont(n,f) return n_setfield(n,"font",f) end + +nodes.getchar = n_getchar +nodes.setchar = n_setchar +nodes.getfont = n_getfont +nodes.setfont = n_setfont + +local function n_getlist (n) return n_getfield(n,"list") end +local function n_setlist (n,l) return n_setfield(n,"list",l) end +local function n_getleader(n) return n_getfield(n,"leader") end +local function n_setleader(n,l) return n_setfield(n,"leader",l) end + +nodes.getlist = n_getlist +nodes.setlist = n_setlist +nodes.getleader = n_getleader +nodes.setleader = n_setleader + +local function n_getnext(n) return n_getfield(n,"next") end +local function n_setnext(n,nn) return n_setfield(n,"next",nn) end +local function n_getprev(n) return n_getfield(n,"prev") end +local function n_setprev(n,pp) return n_setfield(n,"prev",pp) end +local function n_getboth(n) return n_getfield(n,"prev"), n_getfield(n,"next") end +local function n_setboth(n,pp,nn) return n_setfield(n,"prev",pp), n_setfield(n,"next",nn) end + +nodes.getnext = n_getnext +nodes.setnext = n_setnext +nodes.getprev = n_getprev +nodes.setprev = n_setprev +nodes.getboth = n_getboth +nodes.setboth = n_setboth + +local function n_setlink(...) + -- not that fast but not used often anyway + local h = nil + for i=1,select("#",...) do + local n = select(i,...) + if not n then + -- go on + elseif h then + n_setfield(h,"next",n) + n_setfield(n,"prev",h) + else + h = n end - return h - end -local n_setboth = node.setboth or -- always - function(c,p,n) - n_setfield(c,"prev",p) - n_setfield(c,"next",n) - end - -nodes.setnext = n_setnext -nodes.setprev = n_setprev -nodes.setlink = n_setlink -nodes.setboth = n_setboth -nodes.setlist = n_setlist - -nodes.getfield = n_getfield -nodes.setfield = n_setfield -nodes.getattr = n_getattr -nodes.setattr = n_setattr -nodes.takeattr = nodes.unset_attribute - -nodes.getnext = n_getnext -nodes.getprev = n_getprev -nodes.getid = n_getid -nodes.getchar = n_getchar -nodes.getfont = n_getfont -nodes.getsubtype = n_getsubtype -nodes.getlist = n_getlist -nodes.getleader = n_getleader -nodes.getdisc = n_getdisc - -if not node.getwhd then - function node.getwhd(n) - return n_getfield(n,"width"), n_getfield(n,"height"), n_getfield(n,"depth") end + return h end -if not node.setwhd then - function node.setwhd(n,w,h,d) - n_setfield(n,"width",w or 0) - n_setfield(n,"height",h or 0) - n_setfield(n,"depth",d or 0) - end -end - -nodes.getwhd = node.getwhd -nodes.setwhd = node.setwhd - -nodes.is_char = node.is_char -nodes.ischar = node.is_char - -nodes.is_glyph = node.is_glyph -nodes.isglyph = node.is_glyph +nodes.setlink = n_setlink -nodes.getbox = node.getbox or tex.getbox -nodes.setbox = node.setbox or tex.setbox +nodes.getbox = node.getbox or tex.getbox +nodes.setbox = node.setbox or tex.setbox local n_flush_node = nodes.flush local n_copy_node = nodes.copy diff --git a/tex/context/base/mkiv/node-pro.lua b/tex/context/base/mkiv/node-pro.lua index b6b130588..606d5b8d7 100644 --- a/tex/context/base/mkiv/node-pro.lua +++ b/tex/context/base/mkiv/node-pro.lua @@ -14,6 +14,7 @@ local report_nodes = logs.reporter("nodes","processors") local nodes = nodes local tasks = nodes.tasks local nuts = nodes.nuts +local tonut = nodes.tonut nodes.processors = nodes.processors or { } local processors = nodes.processors @@ -25,7 +26,6 @@ local actions = tasks.actions("processors") do - local tonut = nuts.tonut local isglyph = nuts.isglyph local getnext = nuts.getnext @@ -178,9 +178,9 @@ do local texnest = tex.nest - local getlist = nodes.getlist - local setlist = nodes.setlist - local getsubtype = nodes.getsubtype + local getlist = nuts.getlist + local setlist = nuts.setlist + local getsubtype = nuts.getsubtype local linelist_code = nodes.listcodes.line @@ -191,12 +191,15 @@ do local whatever = texnest[texnest.ptr] if whatever then local line = whatever.tail - if line and getsubtype(line) == linelist_code then - local head = getlist(line) - if head then - local result = actions(head,groupcode,line) - if result and result ~= head then - setlist(line,result) + if line then + line = tonut(line) + if getsubtype(line) == linelist_code then + local head = getlist(line) + if head then + local result = actions(head,groupcode,line) + if result and result ~= head then + setlist(line,result) + end end end end diff --git a/tex/context/base/mkiv/node-tsk.lua b/tex/context/base/mkiv/node-tsk.lua index 0378c14c6..ca7c7fee4 100644 --- a/tex/context/base/mkiv/node-tsk.lua +++ b/tex/context/base/mkiv/node-tsk.lua @@ -627,12 +627,11 @@ local tonode = nodes.nuts.tonode %localize% -return function(head,groupcode,line) - local nuthead = tonut(head) - local nutline = tonut(line) +-- we operate exclusively on nuts +return function(nuthead,groupcode,nutline) %actions% - return tonode(nuthead) + return nuthead end ]], diff --git a/tex/context/base/mkiv/publ-imp-apa.mkvi b/tex/context/base/mkiv/publ-imp-apa.mkvi index 160cc4522..36e4882d2 100644 --- a/tex/context/base/mkiv/publ-imp-apa.mkvi +++ b/tex/context/base/mkiv/publ-imp-apa.mkvi @@ -696,6 +696,30 @@ apa:Advanced={Publicación en línea avanzada}, apa:Retrieved={Obtenido de}] % {Disponible desde}] + +\setupbtxlabeltext + [sv] + [apa:number={nr.}, + apa:edition={Utgåva}, + apa:Editor=Redaktör, + apa:Editors=Redaktörer, + apa:Volume=Band, + apa:Volumes=Band, + apa:nd={u.å.}, % utan årtal + apa:supplement=Bilaga, % Supplement + apa:MotionPicture=Spelfilm, % ? + apa:Writer={Manusförfattare}, % Assuming for a movie + apa:Writers={Manusförfattare}, % + apa:Producer=Producent, % Assuming for a movie + apa:Producers=Producenter, % + apa:Director={Regissör}, % Assuming for a movie + apa:Directors={Regissörer}, % + apa:Recordedby={Inspelad av}, % Assuming for a movie + apa:Author={Författare}, + apa:Translator={Översättare}, + apa:Advanced={Avancerad onlinepublikation}, % ? + apa:Retrieved={Hämtad från}] + % cite setups % The following differs from the default returning n.d. if year is empty diff --git a/tex/context/base/mkiv/publ-imp-aps.mkvi b/tex/context/base/mkiv/publ-imp-aps.mkvi index 4180b6491..4e12fbfc7 100644 --- a/tex/context/base/mkiv/publ-imp-aps.mkvi +++ b/tex/context/base/mkiv/publ-imp-aps.mkvi @@ -514,6 +514,20 @@ aps:tobe={que se publicará}, aps:unpublished={inédito}] +\setupbtxlabeltext + [sv] + [aps:number={nr.}, + aps:edition={Utgåva}, + aps:Editor=Redaktör, + aps:Editors=Redaktörer, + aps:Volume=Band, + aps:Volumes=Band, + aps:supplement=Bilaga, + aps:inpress={under tryckning}, + aps:tobe={att publiceras}, + aps:unpublished={opublicerat}] + + % cite setups \startsetups btx:aps:nd diff --git a/tex/context/base/mkiv/publ-imp-commands.mkvi b/tex/context/base/mkiv/publ-imp-commands.mkvi index 14e2dbae1..281b8324a 100644 --- a/tex/context/base/mkiv/publ-imp-commands.mkvi +++ b/tex/context/base/mkiv/publ-imp-commands.mkvi @@ -10,6 +10,6 @@ \definebtxcommand\acro #1{\dontleavehmode{\smallcaps#1}} \let\<< -\let\<> +\let\>> \protect \endinput diff --git a/tex/context/base/mkiv/publ-imp-default.mkvi b/tex/context/base/mkiv/publ-imp-default.mkvi index 22638c900..fef993fe0 100644 --- a/tex/context/base/mkiv/publ-imp-default.mkvi +++ b/tex/context/base/mkiv/publ-imp-default.mkvi @@ -342,24 +342,36 @@ [it] [\s!default:and=e, \s!default:number={nº}, - \s!default:edition={ed.}, % edizione + \s!default:edition={ed.}, % edizione \s!default:Editor={A cura di}, \s!default:Editors={A cura di}, - \s!default:Volume={Vol.}, % Volume - \s!default:Volumes={Vol.}, % Volumi + \s!default:Volume={Vol.}, % Volume + \s!default:Volumes={Vol.}, % Volumi \s!default:others={et al.}] \setupbtxlabeltext [es] [\s!default:and=y, \s!default:number={nº}, - \s!default:edition={ed.}, % edición - \s!default:Editor=Editor, % Ed./Eds. + \s!default:edition={ed.}, % edición + \s!default:Editor=Editor, % Ed./Eds. \s!default:Editors=Editores, \s!default:Volume={Vol.}, % Volumen \s!default:Volumes={Vols.}, % Volúmenes \s!default:others={et al.}] +\setupbtxlabeltext + [sv] + [\s!default:and=och, + \s!default:number={nr.}, + \s!default:edition={Utgåva}, + \s!default:Editor=Redaktör, + \s!default:Editors=Redaktörer, + \s!default:Volume=Band, + \s!default:Volumes=Band, + \s!default:others={et al.}] + + % First some helpers: \starttexdefinition btx:default:composed-title diff --git a/tex/context/base/mkiv/spac-hor.mkiv b/tex/context/base/mkiv/spac-hor.mkiv index 32b7f06fb..24c7c7893 100644 --- a/tex/context/base/mkiv/spac-hor.mkiv +++ b/tex/context/base/mkiv/spac-hor.mkiv @@ -717,7 +717,7 @@ \global\s_spac_narrower_left \zeropoint \global\s_spac_narrower_right \zeropoint \global\s_spac_narrower_middle\zeropoint - \edef\askednarrower{#1} + \edef\askednarrower{#1}% \ifx\askednarrower\v!reverse \ifconditional\s_spac_narrower_last_swap \leftskip \s_spac_narrower_right_last diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex d0d2324d8..211e6773f 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex a0d9f04f4..a9c4cb673 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/symb-ini.mkiv b/tex/context/base/mkiv/symb-ini.mkiv index abf857675..428fcd381 100644 --- a/tex/context/base/mkiv/symb-ini.mkiv +++ b/tex/context/base/mkiv/symb-ini.mkiv @@ -44,9 +44,23 @@ %D \stoptyping \installcorenamespace{symbol} +\installcorenamespace{symbols} \installcorenamespace{symbolset} \installcorenamespace{symboldefault} +%D For now we only have one option. + +\installparameterhandler\??symbols {symbols} +\installsetuphandler \??symbols {symbols} + +\appendtoks + \doifelse{\symbolsparameter\c!stylealternative}\v!math + \settrue\setfalse\prefermathovertextchar +\to \everysetupsymbols + +\setupsymbols + [\c!stylealternative=\v!text] + \let\currentsymbol \empty \let\currentsymbolset\empty diff --git a/tex/context/base/mkiv/trac-log.lua b/tex/context/base/mkiv/trac-log.lua index 206af5668..e76c9f684 100644 --- a/tex/context/base/mkiv/trac-log.lua +++ b/tex/context/base/mkiv/trac-log.lua @@ -114,7 +114,7 @@ local direct, subdirect, writer, pushtarget, poptarget, setlogfile, settimedlog, -- we don't want this overhead for single messages (not that there are that -- many; we could have a special weak table) -if runningtex then +if runningtex and texio then if texio.setescape then texio.setescape(0) -- or (false) diff --git a/tex/context/base/mkiv/typo-mar.lua b/tex/context/base/mkiv/typo-mar.lua index f8665e0b0..ce8375eea 100644 --- a/tex/context/base/mkiv/typo-mar.lua +++ b/tex/context/base/mkiv/typo-mar.lua @@ -204,7 +204,6 @@ end function margins.save(t) setmetatable(t,defaults) local content = takebox(t.number) - setprop(content,"specialcontent","margindata") local location = t.location local category = t.category local inline = t.inline @@ -220,6 +219,7 @@ function margins.save(t) report_margindata("ignoring empty margin data %a",location or "unknown") return end + setprop(content,"specialcontent","margindata") local store if inline then store = inlinestore diff --git a/tex/context/base/mkiv/util-fil.lua b/tex/context/base/mkiv/util-fil.lua index 9f96a01b9..79af27743 100644 --- a/tex/context/base/mkiv/util-fil.lua +++ b/tex/context/base/mkiv/util-fil.lua @@ -14,10 +14,14 @@ local char = string.char -- flac files). In Lua 5.3 we can probably do this better. Some code will move -- here. +-- We could comment those that are in fio and sio. + utilities = utilities or { } local files = { } utilities.files = files +-- we could have a gc method that closes but files auto close anyway + local zerobased = { } function files.open(filename,zb) @@ -249,7 +253,7 @@ end if bit32 then - local rshift = bit32.rshift + local rshift = bit32.rshift function files.writecardinal2(f,n) local a = char(n % 256) @@ -258,6 +262,35 @@ if bit32 then 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 @@ -269,17 +302,35 @@ else f:write(b,a) end -end + 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 -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.writestring(f,s) @@ -292,30 +343,42 @@ end if fio and fio.readcardinal1 then - files.readcardinal1 = fio.readcardinal1 - files.readcardinal2 = fio.readcardinal2 - files.readcardinal3 = fio.readcardinal3 - files.readcardinal4 = fio.readcardinal4 - files.readinteger1 = fio.readinteger1 - files.readinteger2 = fio.readinteger2 - files.readinteger3 = fio.readinteger3 - files.readinteger4 = fio.readinteger4 - files.readfixed2 = fio.readfixed2 - files.readfixed4 = fio.readfixed4 - files.read2dot14 = fio.read2dot14 - files.setposition = fio.setposition - files.getposition = fio.getposition - - files.readbyte = files.readcardinal1 - files.readsignedbyte = files.readinteger1 - files.readcardinal = files.readcardinal1 - files.readinteger = files.readinteger1 - - local skipposition = fio.skipposition - files.skipposition = skipposition - - files.readbytes = fio.readbytes - files.readbytetable = fio.readbytetable + files.readcardinal1 = fio.readcardinal1 + 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 + files.setposition = fio.setposition + files.getposition = fio.getposition + + files.readbyte = files.readcardinal1 + files.readsignedbyte = files.readinteger1 + files.readcardinal = files.readcardinal1 + files.readinteger = files.readinteger1 + + local skipposition = fio.skipposition + files.skipposition = skipposition + + files.readbytes = fio.readbytes + files.readbytetable = fio.readbytetable function files.skipshort(f,n) skipposition(f,2*(n or 1)) @@ -327,6 +390,30 @@ if fio and fio.readcardinal1 then 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 diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua index dc8ba72f1..976989a77 100644 --- a/tex/context/base/mkiv/util-sac.lua +++ b/tex/context/base/mkiv/util-sac.lua @@ -29,6 +29,12 @@ function streams.openstring(f,zerobased) end end +function streams.getstring(f) + if f then + return f[1] + end +end + function streams.close() -- dummy end @@ -137,7 +143,7 @@ function streams.readcardinal2(f) 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 @@ -217,6 +223,14 @@ function streams.readcardinal4(f) 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 diff --git a/tex/context/base/mkiv/util-soc-imp-mime.lua b/tex/context/base/mkiv/util-soc-imp-mime.lua index 4b5d2baff..7a5cef27b 100644 --- a/tex/context/base/mkiv/util-soc-imp-mime.lua +++ b/tex/context/base/mkiv/util-soc-imp-mime.lua @@ -3,8 +3,8 @@ 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 diff --git a/tex/context/base/mkiv/util-soc-imp-socket.lua b/tex/context/base/mkiv/util-soc-imp-socket.lua index 3da155749..d1486f8f8 100644 --- a/tex/context/base/mkiv/util-soc-imp-socket.lua +++ b/tex/context/base/mkiv/util-soc-imp-socket.lua @@ -5,7 +5,7 @@ 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 diff --git a/tex/context/base/mkiv/util-str.lua b/tex/context/base/mkiv/util-str.lua index 5f175e227..a04b20835 100644 --- a/tex/context/base/mkiv/util-str.lua +++ b/tex/context/base/mkiv/util-str.lua @@ -14,7 +14,6 @@ local format, gsub, rep, sub, find = string.format, string.gsub, string.rep, str 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 diff --git a/tex/context/base/mkiv/util-tab.lua b/tex/context/base/mkiv/util-tab.lua index be5f1318c..2f425cca3 100644 --- a/tex/context/base/mkiv/util-tab.lua +++ b/tex/context/base/mkiv/util-tab.lua @@ -311,7 +311,8 @@ function tables.encapsulate(core,capsule,protect) end end --- best keep [%q] keys (as we have some in older applications i.e. saving user data +-- best keep [%q] keys (as we have some in older applications i.e. saving user data (otherwise +-- we also need to check for reserved words) local f_hashed_string = formatters["[%q]=%q,"] local f_hashed_number = formatters["[%q]=%s,"] diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex 147d7755b..c4450ad71 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex b48a519ae..8bc3240c4 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/context/modules/mkiv/m-chart.lua b/tex/context/modules/mkiv/m-chart.lua index cde563fb3..7973640a7 100644 --- a/tex/context/modules/mkiv/m-chart.lua +++ b/tex/context/modules/mkiv/m-chart.lua @@ -864,8 +864,8 @@ local function getchart(settings,forced_x,forced_y,forced_nx,forced_ny) for i=1,#data do local cell = data[i] if not autofocus or autofocus[cell.name] then -- offsets probably interfere with autofocus - local x = cell.x - local y = cell.y + local x = cell.realx -- was bug: .x + local y = cell.realy -- was bug: .y if minx == 0 or x < minx then minx = x end if miny == 0 or y < miny then miny = y end if minx == 0 or x > maxx then maxx = x end diff --git a/tex/context/sample/third/aristotle-grc.tex b/tex/context/sample/third/aristotle-grc.tex new file mode 100644 index 000000000..85d774f23 --- /dev/null +++ b/tex/context/sample/third/aristotle-grc.tex @@ -0,0 +1,13 @@ +\startlanguage[grc] +Λόγος δέ ἐστι φωνὴ σημαντική, ἧς τῶν μερῶν τι σημαντικόν ἐστι +κεχωρισμένον, ὡς φάσις ἀλλ᾽ οὐχ ὡς κατάφασις. λέγω δέ, οἷον ἄνθρωπος +σημαίνει τι, ἀλλ᾽ οὐχ ὅτι ἔστιν ἢ οὐκ ἔστιν (ἀλλ᾽ ἔσται κατάφασις ἢ +ἀπόφασις ἐάν τι προστεθῇ)· ἀλλ᾽ οὐχ ἡ τοῦ ἀνθρώπου συλλαβὴ μία· οὐδὲ +γὰρ ἐν τῷ μῦς τὸ υς σημαντικόν, ἀλλὰ φωνή ἐστι νῦν μόνον. ἐν δὲ τοῖς +διπλοῖς σημαίνει μέν, ἀλλ᾽ οὐ καθ᾽ αὑτό, ὥσπερ εἴρηται. ἔστι δὲ λόγος +ἅπας μὲν σημαντικός, οὐχ ὡς ὄργανον δέ, ἀλλ᾽ ὥσπερ εἴρηται κατὰ +συνθήκην· ἀποφαντικὸς δὲ οὐ πᾶς, ἀλλ᾽ ἐν ᾧ τὸ ἀληθεύειν ἢ ψεύδεσθαι +ὑπάρχει· οὐκ ἐν ἅπασι δὲ ὑπάρχει, οἷον ἡ εὐχὴ λόγος μέν, ἀλλ᾽ οὔτ᾽ +ἀληθὴς οὔτε ψευδής. οἱ μὲν οὖν ἄλλοι ἀφείσθωσαν, —ῥητορικῆς γὰρ ἢ +ποιητικῆς οἰκειοτέρα ἡ σκέψις,— ὁ δὲ ἀποφαντικὸς τῆς νῦν θεωρίας. +\stoplanguage diff --git a/tex/context/sample/third/capek-cz.tex b/tex/context/sample/third/capek-cz.tex new file mode 100644 index 000000000..8083d7152 --- /dev/null +++ b/tex/context/sample/third/capek-cz.tex @@ -0,0 +1,13 @@ +Tak vám jednou byl jeden chudý pán neboli člověk, on se vlastně jmenoval +František Král, ale tak mu říkali jenom tehdy, když ho sebral strážník a +dovedl ho na komisařství pro potulku, kde ho zapsali do takové tlusté knihy +a nechali ho přespat na pryčně a ráno ho zase poslali dál; na policii mu +tedy říkali František Král, ale ostatní lidé ho jmenovali všelijak jinak: +ten vandrák, ten šupák, ten tulák, ten pobuda, ten lajdák, ten otrapa, ten +hadrník, ten trhan, ten obejda, ten lenoch, ten chudák, ten jindyvyjduum, +ten člověk, ten kdovíkdo, ten poběhlík, ten krajánek, ten štvanec, ten +vošlapa, ten revertent, ten vagabund, ten darmošlap, ten budižkničemu, ten +hlad, ten hunt, ten holota a ještě mnoho jiných jmen mu dávali; kdyby každé +to názvisko platilo aspoň korunu, mohl by si za ně koupit žluté boty a možná +že i klobouk, ale takhle si za to nekoupil nic a měl jenom to, co mu lidé +dali. diff --git a/tex/context/sample/third/capek-vlnka-cz.tex b/tex/context/sample/third/capek-vlnka-cz.tex new file mode 100644 index 000000000..9fede2334 --- /dev/null +++ b/tex/context/sample/third/capek-vlnka-cz.tex @@ -0,0 +1,13 @@ +Tak vám jednou byl jeden chudý pán neboli člověk, on se vlastně jmenoval +František Král, ale tak mu říkali jenom tehdy, když ho sebral strážník +a~dovedl ho na komisařství pro potulku, kde ho zapsali do takové tlusté knihy +a~nechali ho přespat na pryčně a~ráno ho zase poslali dál; na policii mu +tedy říkali František Král, ale ostatní lidé ho jmenovali všelijak jinak: +ten vandrák, ten šupák, ten tulák, ten pobuda, ten lajdák, ten otrapa, ten +hadrník, ten trhan, ten obejda, ten lenoch, ten chudák, ten jindyvyjduum, +ten člověk, ten kdovíkdo, ten poběhlík, ten krajánek, ten štvanec, ten +vošlapa, ten revertent, ten vagabund, ten darmošlap, ten budižkničemu, ten +hlad, ten hunt, ten holota a~ještě mnoho jiných jmen mu dávali; kdyby každé +to názvisko platilo aspoň korunu, mohl by si za ně koupit žluté boty a~možná +že i~klobouk, ale takhle si za to nekoupil nic a~měl jenom to, co mu lidé +dali. diff --git a/tex/context/sample/third/dequincey.tex b/tex/context/sample/third/dequincey.tex new file mode 100644 index 000000000..a1070b562 --- /dev/null +++ b/tex/context/sample/third/dequincey.tex @@ -0,0 +1,5 @@ +For if once a man indulges himself in murder, very soon he comes to +think little of robbing; and from robbing he comes next to drinking and +Sabbath--breaking, and from that to incivility and procrastination. +Once begin upon this downward path, you never know where you are to +stop. diff --git a/tex/context/sample/third/dyrynk-cz.tex b/tex/context/sample/third/dyrynk-cz.tex new file mode 100644 index 000000000..e12a228b9 --- /dev/null +++ b/tex/context/sample/third/dyrynk-cz.tex @@ -0,0 +1,22 @@ +Čeho jsem si zvlášť všímal při prohlížení knih, je typografické jejich +zhotovení, technické provedení knihtiskařem, které po mém soudu je základem +dobré knižní úpravy. A tu nelze upřít, že řemeslná stránka je dosud stránkou +slabou většiny našich knih. Často až překvapí rozpor mezi péčí, kterou +věnoval umělec výzdobě knihy, a ledabylostí, s jakou ji tiskárna zhotovila. +Bývá to podivná harmonie: výzdoba umělecká a sazba i tisk jako denních +novin. Nejsou to malé závody, jichž výrobkům lze vytknouti tuto řemeslnou +chybu, i přední veliké tiskárny zhotovují takto >>krásné<< knihy. Stačí +prohlédnouti si podrobněji reprodukce v tomto díle, abychom se přesvědčili, +že to tvrzení není přehnané. + +Přece však lze pozorovati potěšitelný obrat k lepšímu: některé české +knihtiskárny se chlubí už správně vysazenými a dobře vytištěnými knihami. +Sice dosud jest málo impressí, které takto jeví úctu a vážnost k svému +černému umění, obracejíce knihtisk k jeho staré lásce, knize, a věnujíce +její vkusné úpravě čas, píči a píli; na prstech jedné ruky by je spočetl. +Nepochybuji však, že jich přibude, vždyť ničím nemůže se knihtiskárna +lépe doporučiti než svojí firmou na dokonale, krásně upravené knize, která +je rozkoší oku a potěšením duši, a ještě po letech a desetiletích, kdy +dávno upadnou v zapomnění drobné akcidence, zůstane v knihovnách jako svědek +odborné vyspělosti knihtiskárny, schopnosti jejích pracovníků +a prozíravosti i vkusu principála nebo řiditele závodu. diff --git a/tex/context/sample/third/dyrynk-vlnka-cz.tex b/tex/context/sample/third/dyrynk-vlnka-cz.tex new file mode 100644 index 000000000..1d4df1e49 --- /dev/null +++ b/tex/context/sample/third/dyrynk-vlnka-cz.tex @@ -0,0 +1,23 @@ + +Čeho jsem si zvlášť všímal při prohlížení knih, je typografické jejich +zhotovení, technické provedení knihtiskařem, které po mém soudu je základem +dobré knižní úpravy. A~tu nelze upřít, že řemeslná stránka je dosud stránkou +slabou většiny našich knih. Často až překvapí rozpor mezi péčí, kterou +věnoval umělec výzdobě knihy, a~ledabylostí, s~jakou ji tiskárna zhotovila. +Bývá to podivná harmonie: výzdoba umělecká a~sazba i~tisk jako denních +novin. Nejsou to malé závody, jichž výrobkům lze vytknouti tuto řemeslnou +chybu, i~přední veliké tiskárny zhotovují takto >>krásné<< knihy. Stačí +prohlédnouti si podrobněji reprodukce v~tomto díle, abychom se přesvědčili, +že to tvrzení není přehnané. + +Přece však lze pozorovati potěšitelný obrat k~lepšímu: některé české +knihtiskárny se chlubí už správně vysazenými a~dobře vytištěnými knihami. +Sice dosud jest málo impressí, které takto jeví úctu a~vážnost k~svému +černému umění, obracejíce knihtisk k~jeho staré lásce, knize, a~věnujíce +její vkusné úpravě čas, píči a~píli; na prstech jedné ruky by je spočetl. +Nepochybuji však, že jich přibude, vždyť ničím nemůže se knihtiskárna +lépe doporučiti než svojí firmou na dokonale, krásně upravené knize, která +je rozkoší oku a~potěšením duši, a~ještě po letech a~desetiletích, kdy +dávno upadnou v~zapomnění drobné akcidence, zůstane v~knihovnách jako svědek +odborné vyspělosti knihtiskárny, schopnosti jejích pracovníků +a~prozíravosti i~vkusu principála nebo řiditele závodu. diff --git a/tex/context/sample/third/kollar-cz.tex b/tex/context/sample/third/kollar-cz.tex new file mode 100644 index 000000000..5a4f63695 --- /dev/null +++ b/tex/context/sample/third/kollar-cz.tex @@ -0,0 +1,31 @@ + +Aj zde leží zem ta před okem mým slzy ronícím, +někdy kolébka, nyní národu mého rakev. +Stoj noho! posvátná místa jsou, kamkoli kráčíš, +k obloze, Tatry synu, vznes se vyvýše pohled, +neb raději k velikému prichyl tomu tam se dubisku, +jenž vzdoruje zhoubným až dosaváde časům. +Však času ten horší je člověk, jenž berlu železnou +v těchto krajích na tvou, Slavie, šíji chopil. +Horší, nežli divé války, hromu, ohně divější, +zaslepenec na své když zlobu plémě kydá. +Ó věkové dávní, jako noc vůkol mne ležící, +ó krajino, všeliké slávy i hanby obraz! +Od Labe zrádného k rovinám až Visly nevěrné, +od Dunaje k hltným Baltu celého pěnám: +Krásnohlasy zmužilých Slavjanů kde se někdy ozýval, +aj oněmělť už, byv k ourazu zášti, jazyk. +A kdo se loupeže té, volající vzhůru, dopustil? +Kdo zhanobil v jednom národu lidstvo celé? +Zardi se závistná Teutonie, sousedo Slávy, +tvé vin těchto počet spáchaly někdy ruky! +Neb krve nikde tolik nevylil černidla že žádný +nepřítel, co vylil k záhubě Slávy Němec. +Sám svobody kdo hoden, svobodu zná vážiti každou, +ten kdo do pout jímá otroky, sám je otrok. +Nechť ruky, nechť by jazyk v okovy své vázal otrocké, +jedno to, neb nezná šetřiti práva jiných. +Ten, kdo trůny bořil, lidskou krev darmo vyléval, +po světě nešťastnou války pochodni nosil: +ten porobu slušnou, buď Goth, buď Skytha zasloužil, +ne kdo divé chválil příkladem ordě pokoj. diff --git a/tex/context/sample/third/kollar-vlnka-cz.tex b/tex/context/sample/third/kollar-vlnka-cz.tex new file mode 100644 index 000000000..01e815e74 --- /dev/null +++ b/tex/context/sample/third/kollar-vlnka-cz.tex @@ -0,0 +1,30 @@ +Aj zde leží zem ta před okem mým slzy ronícím, +někdy kolébka, nyní národu mého rakev. +Stoj noho! posvátná místa jsou, kamkoli kráčíš, +k~obloze, Tatry synu, vznes se vyvýše pohled, +neb raději k~velikému prichyl tomu tam se dubisku, +jenž vzdoruje zhoubným až dosaváde časům. +Však času ten horší je člověk, jenž berlu železnou +v~těchto krajích na tvou, Slavie, šíji chopil. +Horší, nežli divé války, hromu, ohně divější, +zaslepenec na své když zlobu plémě kydá. +Ó věkové dávní, jako noc vůkol mne ležící, +ó krajino, všeliké slávy i~hanby obraz! +Od Labe zrádného k~rovinám až Visly nevěrné, +od Dunaje k~hltným Baltu celého pěnám: +Krásnohlasy zmužilých Slavjanů kde se někdy ozýval, +aj oněmělť už, byv k~ourazu zášti, jazyk. +A~kdo se loupeže té, volající vzhůru, dopustil? +Kdo zhanobil v~jednom národu lidstvo celé? +Zardi se závistná Teutonie, sousedo Slávy, +tvé vin těchto počet spáchaly někdy ruky! +Neb krve nikde tolik nevylil černidla že žádný +nepřítel, co vylil k~záhubě Slávy Němec. +Sám svobody kdo hoden, svobodu zná vážiti každou, +ten kdo do pout jímá otroky, sám je otrok. +Nechť ruky, nechť by jazyk v~okovy své vázal otrocké, +jedno to, neb nezná šetřiti práva jiných. +Ten, kdo trůny bořil, lidskou krev darmo vyléval, +po světě nešťastnou války pochodni nosil: +ten porobu slušnou, buď Goth, buď Skytha zasloužil, +ne kdo divé chválil příkladem ordě pokoj. diff --git a/tex/context/sample/third/komensky-cz.tex b/tex/context/sample/third/komensky-cz.tex new file mode 100644 index 000000000..f25bb47d9 --- /dev/null +++ b/tex/context/sample/third/komensky-cz.tex @@ -0,0 +1,33 @@ +Nejkrásnějším dílem Božím je svět, všeliké neviditelné Božské věcí viditelné +ukazující. Nejkrásnější je ale naše duše, jíž je dáno, myšlením zobrazovat +ve svém nitru svět i věci veškery. Nejkrásnější je řeč, jejíž pomocí +vmalováváme všeliké obrazy své duše v duši druhého. Nejkrásnější je písmo, +jímž zachycujeme a natrvalo upevňujeme řeč, samu o sobě prchavou a +pomíjející, a jímž jako bychom ji zadržovali, aby trvala. Nejkrásnější jsou +knihy, písmem ladně sestavené, jimiž zpodobenou moudrost posíláme lidem, +místně či časově vzdáleným, ba dokonce i pozdnímu potomstvu. Nejkrásnějším +darem Božím je vynález tiskových liter, jimž se knihy nesmírně rychle +rozmnožují. + +Sazeč, maje před sebou kasu, naplněnou kovovými literkami, uloženými v +přihrádkách, dívá se do rukopisu, postaveného na vidlici tak, aby pohodlně +viděl, v levé ruce sázítko, pravou rukou vybírá (z přihrádek) literky a +skládá je do sázítka v slova: když naplní sloupec, přenáší je na desku. +Jakmile pak je naplněn počet sloupců pro jednu stranu archu, rozdělí je +příložkami, ováže je a stáhne železnými rámy, aby se nerozpadly; a tím se +podle svého mínění sví povinnosti zhostil. + +A tak tito všichni pracujíce vzájemně vykonávající jakoby hračkou +podivuhodné dílo, lidem kdysi nepochopitelné, jen když mají všichni to, čeho +je přitom potření, jednak odborné znalosti zbystřené praxí, jednak vytrvalou +pozornost a píli. Znalosti: poněvadž třebaže je tiskařství řemeslem, je +nejsubtilnějším uměním, skládajícím se z přečetných maličkostí, na něž nutno +dávat dobrý pozor. Pozornost a píli: poněvadž zde, kde se stýká tolik +maličkostí, velmi snadno se něco přihodí, co by dílo rušilo, kdyby se +nebdělo. + +Tolik ve všeobecnosti o tom, jak se tisknou knihy vůbec. Jestliže by se +naskytla otázka, jak vznikají knihy dobré, bude třeba říci, že je žádoucí za +prvé rozumně sepsaný rukopis, hodný světla a nikoli tmy; na druhém místě +elegantní typy; na třetím čistý papír; na čtvrtém pak pozorná práce, aby vše +až do poslední čárky bylo zřetelné, rozlišené a správné. diff --git a/tex/context/sample/third/komensky-vlnka-cz.tex b/tex/context/sample/third/komensky-vlnka-cz.tex new file mode 100644 index 000000000..17a2ab3f7 --- /dev/null +++ b/tex/context/sample/third/komensky-vlnka-cz.tex @@ -0,0 +1,33 @@ +Nejkrásnějším dílem Božím je svět, všeliké neviditelné Božské věcí viditelné +ukazující. Nejkrásnější je ale naše duše, jíž je dáno, myšlením zobrazovat +ve svém nitru svět i~věci veškery. Nejkrásnější je řeč, jejíž pomocí +vmalováváme všeliké obrazy své duše v~duši druhého. Nejkrásnější je písmo, +jímž zachycujeme a~natrvalo upevňujeme řeč, samu o~sobě prchavou +a~pomíjející, a~jímž jako bychom ji zadržovali, aby trvala. Nejkrásnější jsou +knihy, písmem ladně sestavené, jimiž zpodobenou moudrost posíláme lidem, +místně či časově vzdáleným, ba dokonce i~pozdnímu potomstvu. Nejkrásnějším +darem Božím je vynález tiskových liter, jimž se knihy nesmírně rychle +rozmnožují. + +Sazeč, maje před sebou kasu, naplněnou kovovými literkami, uloženými +v~přihrádkách, dívá se do rukopisu, postaveného na vidlici tak, aby pohodlně +viděl, v~levé ruce sázítko, pravou rukou vybírá (z~přihrádek) literky +a~skládá je do sázítka v~slova: když naplní sloupec, přenáší je na desku. +Jakmile pak je naplněn počet sloupců pro jednu stranu archu, rozdělí je +příložkami, ováže je a~stáhne železnými rámy, aby se nerozpadly; a~tím se +podle svého mínění sví povinnosti zhostil. + +A~tak tito všichni pracujíce vzájemně vykonávající jakoby hračkou +podivuhodné dílo, lidem kdysi nepochopitelné, jen když mají všichni to, čeho +je přitom potřebí, jednak odborné znalosti zbystřené praxí, jednak vytrvalou +pozornost a~píli. Znalosti: poněvadž třebaže je tiskařství řemeslem, je +nejsubtilnějším uměním, skládajícím se z~přečetných maličkostí, na něž nutno +dávat dobrý pozor. Pozornost a~píli: poněvadž zde, kde se stýká tolik +maličkostí, velmi snadno se něco přihodí, co by dílo rušilo, kdyby se +nebdělo. + +Tolik ve všeobecnosti o~tom, jak se tisknou knihy vůbec. Jestliže by se +naskytla otázka, jak vznikají knihy dobré, bude třeba říci, že je žádoucí za +prvé rozumně sepsaný rukopis, hodný světla a~nikoli tmy; na druhém místě +elegantní typy; na třetím čistý papír; na čtvrtém pak pozorná práce, aby vše +až do poslední čárky bylo zřetelné, rozlišené a~správné. diff --git a/tex/context/sample/third/krdel-sk.tex b/tex/context/sample/third/krdel-sk.tex new file mode 100644 index 000000000..2f2395427 --- /dev/null +++ b/tex/context/sample/third/krdel-sk.tex @@ -0,0 +1,7 @@ + +KŔDEĽ ŠŤASTNÝCH ĎATĽOV UČÍ PRI ÚSTÍ VÁHU MĹKVÉHO KOŇA OBHRÝZAŤ KÔRU A ŽRAŤ ČERSTVÉ MÄSO. + +Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso. + +0123456789 :;!?()[]\{\} -/--/--- ÖÜŮŘ öüůř + diff --git a/tex/context/sample/third/kun-cz.tex b/tex/context/sample/third/kun-cz.tex new file mode 100644 index 000000000..ee1471c1b --- /dev/null +++ b/tex/context/sample/third/kun-cz.tex @@ -0,0 +1,7 @@ + +ŽLUŤOUČKÝ KŮŇ ÚPĚL ĎÁBELSKÉ ÓDY, + +žluťoučký kůň úpěl ďábelské ódy. + +0123456789 :;!?()[]\{\} -/--/--- ŕĺľäöü ŔĹĽÄÖÜ + diff --git a/tex/generic/context/luatex/luatex-basics-nod.lua b/tex/generic/context/luatex/luatex-basics-nod.lua index e22f170ef..879da4bc7 100644 --- a/tex/generic/context/luatex/luatex-basics-nod.lua +++ b/tex/generic/context/luatex/luatex-basics-nod.lua @@ -70,81 +70,77 @@ nodes.nodecodes = nodecodes nodes.glyphcodes = glyphcodes nodes.disccodes = disccodes -local flush_node = node.flush_node -local remove_node = node.remove -local traverse_id = node.traverse_id - nodes.handlers.protectglyphs = node.protect_glyphs -- beware: nodes! nodes.handlers.unprotectglyphs = node.unprotect_glyphs -- beware: nodes! -function nodes.remove(head, current, free_too) - local t = current - head, current = remove_node(head,current) - if t then - if free_too then - flush_node(t) - t = nil - else - t.next, t.prev = nil, nil - end - end - return head, current, t -end - -function nodes.delete(head,current) - return nodes.remove(head,current,true) -end - -local getfield = node.getfield -local setfield = node.setfield - -nodes.getfield = getfield -nodes.setfield = setfield - -nodes.getattr = getfield -nodes.setattr = setfield - --- being lazy ... just copy a bunch ... not all needed in generic but we assume --- nodes to be kind of private anyway - -nodes.tostring = node.tostring or tostring -nodes.copy = node.copy -nodes.copy_node = node.copy -nodes.copy_list = node.copy_list -nodes.delete = node.delete -nodes.dimensions = node.dimensions -nodes.end_of_math = node.end_of_math -nodes.flush_list = node.flush_list -nodes.flush_node = node.flush_node -nodes.flush = node.flush_node -nodes.free = node.free -nodes.insert_after = node.insert_after -nodes.insert_before = node.insert_before -nodes.hpack = node.hpack -nodes.new = node.new -nodes.tail = node.tail -nodes.traverse = node.traverse -nodes.traverse_id = node.traverse_id -nodes.slide = node.slide -nodes.vpack = node.vpack - -nodes.first_glyph = node.first_glyph -nodes.has_glyph = node.has_glyph or node.first_glyph - -nodes.current_attr = node.current_attr -nodes.has_field = node.has_field -nodes.last_node = node.last_node -nodes.usedlist = node.usedlist -nodes.protrusion_skippable = node.protrusion_skippable -nodes.write = node.write - -nodes.has_attribute = node.has_attribute -nodes.set_attribute = node.set_attribute -nodes.unset_attribute = node.unset_attribute - -nodes.protect_glyphs = node.protect_glyphs -nodes.unprotect_glyphs = node.unprotect_glyphs -nodes.mlist_to_hlist = node.mlist_to_hlist +-- These are now gone in generic as they are context specific. + +-- local flush_node = node.flush_node +-- local remove_node = node.remove +-- local traverse_id = node.traverse_id +-- +-- function nodes.remove(head, current, free_too) +-- local t = current +-- head, current = remove_node(head,current) +-- if t then +-- if free_too then +-- flush_node(t) +-- t = nil +-- else +-- t.next, t.prev = nil, nil +-- end +-- end +-- return head, current, t +-- end +-- +-- function nodes.delete(head,current) +-- return nodes.remove(head,current,true) +-- end + +----- getfield = node.getfield +----- setfield = node.setfield + +-----.getfield = getfield +-----.setfield = setfield +-----.getattr = getfield +-----.setattr = setfield + +-----.tostring = node.tostring or tostring +-----.copy = node.copy +-----.copy_node = node.copy +-----.copy_list = node.copy_list +-----.delete = node.delete +-----.dimensions = node.dimensions +-----.end_of_math = node.end_of_math +-----.flush_list = node.flush_list +-----.flush_node = node.flush_node +-----.flush = node.flush_node +-----.free = node.free +-----.insert_after = node.insert_after +-----.insert_before = node.insert_before +-----.hpack = node.hpack +-----.new = node.new +-----.tail = node.tail +-----.traverse = node.traverse +-----.traverse_id = node.traverse_id +-----.slide = node.slide +-----.vpack = node.vpack + +-----.first_glyph = node.first_glyph +-----.has_glyph = node.has_glyph or node.first_glyph +-----.current_attr = node.current_attr +-----.has_field = node.has_field +-----.usedlist = node.usedlist +-----.protrusion_skippable = node.protrusion_skippable +-----.write = node.write + +-----.has_attribute = node.has_attribute +-----.set_attribute = node.set_attribute +-----.unset_attribute = node.unset_attribute + +-----.protect_glyphs = node.protect_glyphs +-----.unprotect_glyphs = node.unprotect_glyphs +-----.mlist_to_hlist = node.mlist_to_hlist -- in generic code, at least for some time, we stay nodes, while in context -- we can go nuts (e.g. experimental); this split permits us us keep code diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 6fab6ea69..766b869fe 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 03/05/19 15:40:37 +-- merge date : 03/21/19 21:39:34 do -- begin closure to overcome local limits and interference @@ -120,7 +120,6 @@ elseif not ffi.number then ffi.number=tonumber end if LUAVERSION>5.3 then - collectgarbage("generational") end end -- closure @@ -2677,40 +2676,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 @@ -3070,7 +3074,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 @@ -4099,6 +4102,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) @@ -4107,16 +4136,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))) @@ -4129,10 +4174,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 @@ -4153,6 +4206,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 @@ -4737,67 +4808,8 @@ end nodes.nodecodes=nodecodes nodes.glyphcodes=glyphcodes nodes.disccodes=disccodes -local flush_node=node.flush_node -local remove_node=node.remove -local traverse_id=node.traverse_id nodes.handlers.protectglyphs=node.protect_glyphs -nodes.handlers.unprotectglyphs=node.unprotect_glyphs -function nodes.remove(head,current,free_too) - local t=current - head,current=remove_node(head,current) - if t then - if free_too then - flush_node(t) - t=nil - else - t.next,t.prev=nil,nil - end - end - return head,current,t -end -function nodes.delete(head,current) - return nodes.remove(head,current,true) -end -local getfield=node.getfield -local setfield=node.setfield -nodes.getfield=getfield -nodes.setfield=setfield -nodes.getattr=getfield -nodes.setattr=setfield -nodes.tostring=node.tostring or tostring -nodes.copy=node.copy -nodes.copy_node=node.copy -nodes.copy_list=node.copy_list -nodes.delete=node.delete -nodes.dimensions=node.dimensions -nodes.end_of_math=node.end_of_math -nodes.flush_list=node.flush_list -nodes.flush_node=node.flush_node -nodes.flush=node.flush_node -nodes.free=node.free -nodes.insert_after=node.insert_after -nodes.insert_before=node.insert_before -nodes.hpack=node.hpack -nodes.new=node.new -nodes.tail=node.tail -nodes.traverse=node.traverse -nodes.traverse_id=node.traverse_id -nodes.slide=node.slide -nodes.vpack=node.vpack -nodes.first_glyph=node.first_glyph -nodes.has_glyph=node.has_glyph or node.first_glyph -nodes.current_attr=node.current_attr -nodes.has_field=node.has_field -nodes.last_node=node.last_node -nodes.usedlist=node.usedlist -nodes.protrusion_skippable=node.protrusion_skippable -nodes.write=node.write -nodes.has_attribute=node.has_attribute -nodes.set_attribute=node.set_attribute -nodes.unset_attribute=node.unset_attribute -nodes.protect_glyphs=node.protect_glyphs -nodes.unprotect_glyphs=node.unprotect_glyphs -nodes.mlist_to_hlist=node.mlist_to_hlist +nodes.handlers.unprotectglyphs=node.unprotect_glyphs local direct=node.direct local nuts={} nodes.nuts=nuts @@ -30089,7 +30101,7 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start) end function handlers.devanagari_remove_joiners(head,start,kind,lookupname,replacement) local stop=getnext(start) - local font=getfont(start) + local font=getfont(start) local last=start while stop do local char=ischar(stop,font) @@ -33242,7 +33254,7 @@ local function check_afm(specification,fullname) if foundname=="" then foundname=fonts.names.getfilename(fullname,"afm") or "" end - if foundname=="" and afm.autoprefixed then + if fullname and foundname=="" and afm.autoprefixed then local encoding,shortname=match(fullname,"^(.-)%-(.*)$") if encoding and shortname and fonts.encodings.known[encoding] then shortname=findbinfile(shortname,'afm') or "" |