diff options
Diffstat (limited to 'scripts/context/lua/mtxrun.lua')
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 254 |
1 files changed, 145 insertions, 109 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 9b0b1c346..9b47c6805 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1036,7 +1036,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 40146, stripped down to: 21485 +-- original size: 38434, stripped down to: 20344 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -1464,64 +1464,6 @@ function lpeg.counter(pattern,action) return function(str) n=0;lpegmatch(pattern,str);return n end end end -utf=utf or {} -local utfcharacters=utf and utf.characters or string.utfcharacters -local utfgmatch=utf and utf.gmatch -local utfchar=utf and utf.char -lpeg.UP=lpeg.P -if utfcharacters then - function lpeg.US(str) - local p=P(false) - for uc in utfcharacters(str) do - p=p+P(uc) - end - return p - end -elseif utfgmatch then - function lpeg.US(str) - local p=P(false) - for uc in utfgmatch(str,".") do - p=p+P(uc) - end - return p - end -else - function lpeg.US(str) - local p=P(false) - local f=function(uc) - p=p+P(uc) - end - lpegmatch((utf8char/f)^0,str) - return p - end -end -local range=utf8byte*utf8byte+Cc(false) -function lpeg.UR(str,more) - local first,last - if type(str)=="number" then - first=str - last=more or first - else - first,last=lpegmatch(range,str) - if not last then - return P(str) - end - end - if first==last then - return P(str) - elseif utfchar and (last-first<8) then - local p=P(false) - for i=first,last do - p=p+P(utfchar(i)) - end - return p - else - local f=function(b) - return b>=first and b<=last - end - return utf8byte/f - end -end function lpeg.is_lpeg(p) return p and lpegtype(p)=="pattern" end @@ -3666,7 +3608,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-os"] = package.loaded["l-os"] or true --- original size: 17018, stripped down to: 9696 +-- original size: 19347, stripped down to: 11016 if not modules then modules={} end modules ['l-os']={ version=1.001, @@ -3681,6 +3623,61 @@ local find,format,gsub,upper,gmatch=string.find,string.format,string.gsub,string local concat=table.concat local random,ceil,randomseed=math.random,math.ceil,math.randomseed local rawget,rawset,type,getmetatable,setmetatable,tonumber,tostring=rawget,rawset,type,getmetatable,setmetatable,tonumber,tostring +do + local selfdir=os.selfdir + if selfdir=="" then + selfdir=nil + end + if not selfdir then + if arg then + for i=1,#arg do + local a=arg[i] + if find(a,"^%-%-[c:]*texmfbinpath=") then + selfdir=gsub(a,"^.-=","") + break + end + end + end + if not selfdir then + selfdir=os.selfbin or "luatex" + if find(selfdir,"[/\\]") then + selfdir=gsub(selfdir,"[/\\][^/\\]*$","") + elseif os.getenv then + local path=os.getenv("PATH") + local name=gsub(selfdir,"^.*[/\\][^/\\]","") + local patt="[^:]+" + if os.type=="windows" then + patt="[^;]+" + name=name..".exe" + end + local isfile + if lfs then + local attributes=lfs.attributes + isfile=function(name) + local a=attributes(name,"mode") + return a=="file" or a=="link" or nil + end + else + local open=io.open + isfile=function(name) + local f=open(name) + if f then + f:close() + return true + end + end + end + for p in gmatch(path,patt) do + if isfile(p.."/"..name) then + selfdir=p + break + end + end + end + end + os.selfdir=selfdir or "." + end +end math.initialseed=tonumber(string.sub(string.reverse(tostring(ceil(socket and socket.gettime()*10000 or time()))),1,6)) randomseed(math.initialseed) if not os.__getenv__ then @@ -5480,7 +5477,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-unicode"] = package.loaded["l-unicode"] or true --- original size: 40179, stripped down to: 17768 +-- original size: 41047, stripped down to: 18594 if not modules then modules={} end modules ['l-unicode']={ version=1.001, @@ -5491,8 +5488,13 @@ if not modules then modules={} end modules ['l-unicode']={ } utf=utf or {} unicode=nil -utf.characters=utf.characters or string.utfcharacters -utf.values=utf.values or string.utfvalues +if not string.utfcharacters then + local gmatch=string.gmatch + function string.characters(str) + return gmatch(str,".[\128-\191]*") + end +end +utf.characters=string.utfcharacters local type=type local char,byte,format,sub,gmatch=string.char,string.byte,string.format,string.sub,string.gmatch local concat=table.concat @@ -5503,12 +5505,11 @@ local tabletopattern=lpeg.utfchartabletopattern local bytepairs=string.bytepairs local finder=lpeg.finder local replacer=lpeg.replacer -local utfvalues=utf.values -local utfgmatch=utf.gmatch local p_utftype=patterns.utftype local p_utfstricttype=patterns.utfstricttype local p_utfoffset=patterns.utfoffset -local p_utf8char=patterns.utf8character +local p_utf8character=patterns.utf8character +local p_utf8char=patterns.utf8char local p_utf8byte=patterns.utf8byte local p_utfbom=patterns.utfbom local p_newline=patterns.newline @@ -5577,9 +5578,8 @@ end if not utf.byte then utf.byte=string.utfvalue or (utf8 and utf8.codepoint) if not utf.byte then - local utf8byte=patterns.utf8byte function utf.byte(c) - return lpegmatch(utf8byte,c) + return lpegmatch(p_utf8byte,c) end end end @@ -5680,10 +5680,10 @@ if not utf.sub then return true end end - local pattern_zero=Cmt(p_utf8char,slide_zero)^0 - local pattern_one=Cmt(p_utf8char,slide_one )^0 - local pattern_two=Cmt(p_utf8char,slide_two )^0 - local pattern_first=C(patterns.utf8character) + local pattern_zero=Cmt(p_utf8character,slide_zero)^0 + local pattern_one=Cmt(p_utf8character,slide_one )^0 + local pattern_two=Cmt(p_utf8character,slide_two )^0 + local pattern_first=C(p_utf8character) function utf.sub(str,start,stop) if not start then return str @@ -5758,15 +5758,15 @@ function utf.remapper(mapping,option,action) return "" else if not pattern then - pattern=Cs((tabletopattern(mapping)/action+p_utf8char)^0) + pattern=Cs((tabletopattern(mapping)/action+p_utf8character)^0) end return lpegmatch(pattern,str) end end elseif option=="pattern" then - return Cs((tabletopattern(mapping)/action+p_utf8char)^0) + return Cs((tabletopattern(mapping)/action+p_utf8character)^0) else - local pattern=Cs((tabletopattern(mapping)/action+p_utf8char)^0) + local pattern=Cs((tabletopattern(mapping)/action+p_utf8character)^0) return function(str) if not str or str=="" then return "" @@ -5777,9 +5777,9 @@ function utf.remapper(mapping,option,action) end elseif variant=="function" then if option=="pattern" then - return Cs((p_utf8char/mapping+p_utf8char)^0) + return Cs((p_utf8character/mapping+p_utf8character)^0) else - local pattern=Cs((p_utf8char/mapping+p_utf8char)^0) + local pattern=Cs((p_utf8character/mapping+p_utf8character)^0) return function(str) if not str or str=="" then return "" @@ -5815,9 +5815,9 @@ function utf.subtituter(t) end end local utflinesplitter=p_utfbom^-1*lpeg.tsplitat(p_newline) -local utfcharsplitter_ows=p_utfbom^-1*Ct(C(p_utf8char)^0) -local utfcharsplitter_iws=p_utfbom^-1*Ct((p_whitespace^1+C(p_utf8char))^0) -local utfcharsplitter_raw=Ct(C(p_utf8char)^0) +local utfcharsplitter_ows=p_utfbom^-1*Ct(C(p_utf8character)^0) +local utfcharsplitter_iws=p_utfbom^-1*Ct((p_whitespace^1+C(p_utf8character))^0) +local utfcharsplitter_raw=Ct(C(p_utf8character)^0) patterns.utflinesplitter=utflinesplitter function utf.splitlines(str) return lpegmatch(utflinesplitter,str or "") @@ -5854,7 +5854,7 @@ local more=0 local p_utf16_to_utf8_be=C(1)*C(1)/function(left,right) local now=256*byte(left)+byte(right) if more>0 then - now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 + now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 more=0 return utfchar(now) elseif now>=0xD800 and now<=0xDBFF then @@ -5867,7 +5867,7 @@ end local p_utf16_to_utf8_le=C(1)*C(1)/function(right,left) local now=256*byte(left)+byte(right) if more>0 then - now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 + now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 more=0 return utfchar(now) elseif now>=0xD800 and now<=0xDBFF then @@ -6064,20 +6064,8 @@ function utf.toeight(str) return str end end -local p_nany=p_utf8char/"" -if utfgmatch then - function utf.count(str,what) - if type(what)=="string" then - local n=0 - for _ in utfgmatch(str,what) do - n=n+1 - end - return n - else - return #lpegmatch(Cs((P(what)/" "+p_nany)^0),str) - end - end -else +do + local p_nany=p_utf8character/"" local cache={} function utf.count(str,what) if type(what)=="string" then @@ -6092,17 +6080,11 @@ else end end end -if not utf.characters then - function utf.characters(str) - return gmatch(str,".[\128-\191]*") - end - string.utfcharacters=utf.characters -end -if not utf.values then +if not string.utfvalues then local find=string.find local dummy=function() end - function utf.values(str) + function string.utfvalues(str) local n=#str if n==0 then return dummy @@ -6119,8 +6101,8 @@ if not utf.values then end end end - string.utfvalues=utf.values end +utf.values=string.utfvalues function utf.chrlen(u) return (u<0x80 and 1) or @@ -6168,6 +6150,60 @@ function string.utfpadd(s,n) end return s end +do + local utfcharacters=utf.characters or string.utfcharacters + local utfchar=utf.char or string.utfcharacter + lpeg.UP=P + if utfcharacters then + function lpeg.US(str) + local p=P(false) + for uc in utfcharacters(str) do + p=p+P(uc) + end + return p + end + else + function lpeg.US(str) + local p=P(false) + local f=function(uc) + p=p+P(uc) + end + lpegmatch((p_utf8char/f)^0,str) + return p + end + end + local range=p_utf8byte*p_utf8byte+Cc(false) + function lpeg.UR(str,more) + local first,last + if type(str)=="number" then + first=str + last=more or first + else + first,last=lpegmatch(range,str) + if not last then + return P(str) + end + end + if first==last then + return P(str) + end + if not utfchar then + utfchar=utf.char + end + if utfchar and (last-first<8) then + local p=P(false) + for i=first,last do + p=p+P(utfchar(i)) + end + return p + else + local f=function(b) + return b>=first and b<=last + end + return p_utf8byte/f + end + end +end end -- of closure @@ -12485,7 +12521,7 @@ do -- create closure to overcome 200 locals limit package.loaded["trac-log"] = package.loaded["trac-log"] or true --- original size: 32613, stripped down to: 22577 +-- original size: 32608, stripped down to: 22574 if not modules then modules={} end modules ['trac-log']={ version=1.001, @@ -13260,7 +13296,7 @@ if utilities then end if tex and tex.error then function logs.texerrormessage(...) - tex.error(format(...),{}) + tex.error(format(...)) end else function logs.texerrormessage(...) @@ -24707,8 +24743,8 @@ end -- of closure -- used libraries : 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 -- skipped libraries : - --- original bytes : 986308 --- stripped bytes : 348445 +-- original bytes : 987788 +-- stripped bytes : 348923 -- end library merge |