summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua449
1 files changed, 341 insertions, 108 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
index ec738c2918f..d83c9035b68 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
@@ -1,6 +1,6 @@
-- merged file : lualibs-basic-merged.lua
-- parent file : lualibs-basic.lua
--- merge date : Wed Jul 24 11:48:34 2013
+-- merge date : Wed Nov 6 19:11:53 2013
do -- begin closure to overcome local limits and interference
@@ -95,7 +95,7 @@ if not modules then modules={} end modules ['l-package']={
license="see context related readme files"
}
local type=type
-local gsub,format=string.gsub,string.format
+local gsub,format,find=string.gsub,string.format,string.find
local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match
local package=package
local searchers=package.searchers or package.loaders
@@ -125,6 +125,7 @@ local helpers=package.helpers or {
sequence={
"already loaded",
"preload table",
+ "qualified path",
"lua extra list",
"lib extra list",
"path specification",
@@ -270,12 +271,30 @@ local function loadedbypath(name,rawname,paths,islib,what)
end
end
helpers.loadedbypath=loadedbypath
+local function loadedbyname(name,rawname)
+ if find(name,"^/") or find(name,"^[a-zA-Z]:/") then
+ local trace=helpers.trace
+ if trace then
+ helpers.report("qualified name, identifying '%s'",what,name)
+ end
+ if isreadable(name) then
+ if trace then
+ helpers.report("qualified name, '%s' found",what,name)
+ end
+ return loadfile(name)
+ end
+ end
+end
+helpers.loadedbyname=loadedbyname
methods["already loaded"]=function(name)
return package.loaded[name]
end
methods["preload table"]=function(name)
return builtin["preload table"](name)
end
+methods["qualified path"]=function(name)
+ return loadedbyname(addsuffix(lualibfile(name),"lua"),name)
+end
methods["lua extra list"]=function(name)
return loadedbypath(addsuffix(lualibfile(name),"lua" ),name,getextraluapaths(),false,"lua")
end
@@ -393,21 +412,30 @@ local dquote=P('"')
local space=P(" ")
local period=P(".")
local comma=P(",")
-local utfbom_32_be=P('\000\000\254\255')
-local utfbom_32_le=P('\255\254\000\000')
-local utfbom_16_be=P('\255\254')
-local utfbom_16_le=P('\254\255')
-local utfbom_8=P('\239\187\191')
+local utfbom_32_be=P('\000\000\254\255')
+local utfbom_32_le=P('\255\254\000\000')
+local utfbom_16_be=P('\254\255')
+local utfbom_16_le=P('\255\254')
+local utfbom_8=P('\239\187\191')
local utfbom=utfbom_32_be+utfbom_32_le+utfbom_16_be+utfbom_16_le+utfbom_8
local utftype=utfbom_32_be*Cc("utf-32-be")+utfbom_32_le*Cc("utf-32-le")+utfbom_16_be*Cc("utf-16-be")+utfbom_16_le*Cc("utf-16-le")+utfbom_8*Cc("utf-8")+alwaysmatched*Cc("utf-8")
+local utfstricttype=utfbom_32_be*Cc("utf-32-be")+utfbom_32_le*Cc("utf-32-le")+utfbom_16_be*Cc("utf-16-be")+utfbom_16_le*Cc("utf-16-le")+utfbom_8*Cc("utf-8")
local utfoffset=utfbom_32_be*Cc(4)+utfbom_32_le*Cc(4)+utfbom_16_be*Cc(2)+utfbom_16_le*Cc(2)+utfbom_8*Cc(3)+Cc(0)
local utf8next=R("\128\191")
+patterns.utfbom_32_be=utfbom_32_be
+patterns.utfbom_32_le=utfbom_32_le
+patterns.utfbom_16_be=utfbom_16_be
+patterns.utfbom_16_le=utfbom_16_le
+patterns.utfbom_8=utfbom_8
+patterns.utf_16_be_nl=P("\000\r\000\n")+P("\000\r")+P("\000\n")
+patterns.utf_16_le_nl=P("\r\000\n\000")+P("\r\000")+P("\n\000")
patterns.utf8one=R("\000\127")
patterns.utf8two=R("\194\223")*utf8next
patterns.utf8three=R("\224\239")*utf8next*utf8next
patterns.utf8four=R("\240\244")*utf8next*utf8next*utf8next
patterns.utfbom=utfbom
patterns.utftype=utftype
+patterns.utfstricttype=utfstricttype
patterns.utfoffset=utfoffset
local utf8char=patterns.utf8one+patterns.utf8two+patterns.utf8three+patterns.utf8four
local validutf8char=utf8char^0*endofstring*Cc(true)+Cc(false)
@@ -1984,9 +2012,9 @@ function string.booleanstring(str)
end
function string.is_boolean(str,default)
if type(str)=="string" then
- if str=="true" or str=="yes" or str=="on" or str=="t" then
+ if str=="true" or str=="yes" or str=="on" or str=="t" or str=="1" then
return true
- elseif str=="false" or str=="no" or str=="off" or str=="f" then
+ elseif str=="false" or str=="no" or str=="off" or str=="f" or str=="0" then
return false
end
end
@@ -2560,7 +2588,13 @@ function os.exec (...) ioflush() return exec (...) end
function io.popen (...) ioflush() return iopopen(...) end
function os.resultof(command)
local handle=io.popen(command,"r")
- return handle and handle:read("*all") or ""
+ if handle then
+ local result=handle:read("*all") or ""
+ handle:close()
+ return result
+ else
+ return ""
+ end
end
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
@@ -2731,26 +2765,38 @@ function os.timezone(delta)
end
local timeformat=format("%%s%s",os.timezone(true))
local dateformat="!%Y-%m-%d %H:%M:%S"
+local lasttime=nil
+local lastdate=nil
function os.fulltime(t,default)
- t=tonumber(t) or 0
+ t=t and tonumber(t) or 0
if t>0 then
elseif default then
return default
else
- t=nil
+ t=time()
+ end
+ if t~=lasttime then
+ lasttime=t
+ lastdate=format(timeformat,date(dateformat))
end
- return format(timeformat,date(dateformat,t))
+ return lastdate
end
local dateformat="%Y-%m-%d %H:%M:%S"
+local lasttime=nil
+local lastdate=nil
function os.localtime(t,default)
- t=tonumber(t) or 0
+ t=t and tonumber(t) or 0
if t>0 then
elseif default then
return default
else
- t=nil
+ t=time()
end
- return date(dateformat,t)
+ if t~=lasttime then
+ lasttime=t
+ lastdate=date(dateformat,t)
+ end
+ return lastdate
end
function os.converttime(t,default)
local t=tonumber(t)
@@ -2800,6 +2846,38 @@ if not os.sleep then
socket.sleep(n)
end
end
+local function isleapyear(year)
+ return (year%400==0) or ((year%100~=0) and (year%4==0))
+end
+os.isleapyear=isleapyear
+local days={ 31,28,31,30,31,30,31,31,30,31,30,31 }
+local function nofdays(year,month)
+ if not month then
+ return isleapyear(year) and 365 or 364
+ else
+ return month==2 and isleapyear(year) and 29 or days[month]
+ end
+end
+os.nofdays=nofdays
+function os.weekday(day,month,year)
+ return date("%w",time { year=year,month=month,day=day })+1
+end
+function os.validdate(year,month,day)
+ if month<1 then
+ month=1
+ elseif month>12 then
+ month=12
+ end
+ if day<1 then
+ day=1
+ else
+ local max=nofdays(year,month)
+ if day>max then
+ day=max
+ end
+ end
+ return year,month,day
+end
end -- closure
@@ -3191,6 +3269,55 @@ end -- closure
do -- begin closure to overcome local limits and interference
+if not modules then modules={} end modules ['l-gzip']={
+ version=1.001,
+ author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright="PRAGMA ADE / ConTeXt Development Team",
+ license="see context related readme files"
+}
+if not gzip then
+ return
+end
+local suffix,suffixes=file.suffix,file.suffixes
+function gzip.load(filename)
+ local f=io.open(filename,"rb")
+ if not f then
+ elseif suffix(filename)=="gz" then
+ f:close()
+ local g=gzip.open(filename,"rb")
+ if g then
+ local str=g:read("*all")
+ g:close()
+ return str
+ end
+ else
+ local str=f:read("*all")
+ f:close()
+ return str
+ end
+end
+function gzip.save(filename,data)
+ if suffix(filename)~="gz" then
+ filename=filename..".gz"
+ end
+ local f=io.open(filename,"wb")
+ if f then
+ local s=zlib.compress(data or "",9,nil,15+16)
+ f:write(s)
+ f:close()
+ return #s
+ end
+end
+function gzip.suffix(filename)
+ local suffix,extra=suffixes(filename)
+ local gzipped=extra=="gz"
+ return suffix,gzipped
+end
+
+end -- closure
+
+do -- begin closure to overcome local limits and interference
+
if not modules then modules={} end modules ['l-md5']={
version=1.001,
author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -3289,6 +3416,7 @@ local isdir=lfs.isdir
local isfile=lfs.isfile
local currentdir=lfs.currentdir
local chdir=lfs.chdir
+local onwindows=os.type=="windows" or find(os.getenv("PATH"),";")
if not isdir then
function isdir(name)
local a=attributes(name)
@@ -3360,11 +3488,21 @@ local function collectpattern(path,patt,recurse,result)
return result
end
dir.collectpattern=collectpattern
-local pattern=Ct {
- [1]=(C(P(".")+P("/")^1)+C(R("az","AZ")*P(":")*P("/")^0)+Cc("./"))*V(2)*V(3),
- [2]=C(((1-S("*?/"))^0*P("/"))^0),
- [3]=C(P(1)^0)
-}
+local separator
+if onwindows then
+ local slash=S("/\\")/"/"
+ pattern=Ct {
+ [1]=(Cs(P(".")+slash^1)+Cs(R("az","AZ")*P(":")*slash^0)+Cc("./"))*V(2)*V(3),
+ [2]=Cs(((1-S("*?/\\"))^0*slash)^0),
+ [3]=Cs(P(1)^0)
+ }
+else
+ pattern=Ct {
+ [1]=(C(P(".")+P("/")^1)+Cc("./"))*V(2)*V(3),
+ [2]=C(((1-S("*?/"))^0*P("/"))^0),
+ [3]=C(P(1)^0)
+ }
+end
local filter=Cs ((
P("**")/".*"+P("*")/"[^/]*"+P("?")/"[^/]"+P(".")/"%%."+P("+")/"%%+"+P("-")/"%%-"+P(1)
)^0 )
@@ -3448,7 +3586,6 @@ function dir.ls(pattern)
return concat(glob(pattern),"\n")
end
local make_indeed=true
-local onwindows=os.type=="windows" or find(os.getenv("PATH"),";")
if onwindows then
function dir.mkdirs(...)
local str,pth="",""
@@ -3631,7 +3768,7 @@ utf=utf or (unicode and unicode.utf8) or {}
utf.characters=utf.characters or string.utfcharacters
utf.values=utf.values or string.utfvalues
local type=type
-local char,byte,format,sub=string.char,string.byte,string.format,string.sub
+local char,byte,format,sub,gmatch=string.char,string.byte,string.format,string.sub,string.gmatch
local concat=table.concat
local P,C,R,Cs,Ct,Cmt,Cc,Carg,Cp=lpeg.P,lpeg.C,lpeg.R,lpeg.Cs,lpeg.Ct,lpeg.Cmt,lpeg.Cc,lpeg.Carg,lpeg.Cp
local lpegmatch,patterns=lpeg.match,lpeg.patterns
@@ -3641,6 +3778,7 @@ 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.utf8char
local p_utf8byte=patterns.utf8byte
@@ -3897,112 +4035,181 @@ function utf.magic(f)
end
return lpegmatch(p_utftype,str)
end
-local function utf16_to_utf8_be(t)
- if type(t)=="string" then
- t=lpegmatch(utflinesplitter,t)
- end
- local result={}
- for i=1,#t do
- local r,more=0,0
- for left,right in bytepairs(t[i]) do
- if right then
- local now=256*left+right
- if more>0 then
- now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
- more=0
- r=r+1
- result[r]=utfchar(now)
- elseif now>=0xD800 and now<=0xDBFF then
- more=now
- else
- r=r+1
- result[r]=utfchar(now)
+local utf16_to_utf8_be,utf16_to_utf8_le
+local utf32_to_utf8_be,utf32_to_utf8_le
+local utf_16_be_linesplitter=patterns.utfbom_16_be^-1*lpeg.tsplitat(patterns.utf_16_be_nl)
+local utf_16_le_linesplitter=patterns.utfbom_16_le^-1*lpeg.tsplitat(patterns.utf_16_le_nl)
+if bytepairs then
+ utf16_to_utf8_be=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utf_16_be_linesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,0
+ for left,right in bytepairs(t[i]) do
+ if right then
+ local now=256*left+right
+ if more>0 then
+ now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
+ more=0
+ r=r+1
+ result[r]=utfchar(now)
+ elseif now>=0xD800 and now<=0xDBFF then
+ more=now
+ else
+ r=r+1
+ result[r]=utfchar(now)
+ end
end
end
+ t[i]=concat(result,"",1,r)
end
- t[i]=concat(result,"",1,r)
+ return t
end
- return t
-end
-local function utf16_to_utf8_le(t)
- if type(t)=="string" then
- t=lpegmatch(utflinesplitter,t)
+ utf16_to_utf8_le=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utf_16_le_linesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,0
+ for left,right in bytepairs(t[i]) do
+ if right then
+ local now=256*right+left
+ if more>0 then
+ now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
+ more=0
+ r=r+1
+ result[r]=utfchar(now)
+ elseif now>=0xD800 and now<=0xDBFF then
+ more=now
+ else
+ r=r+1
+ result[r]=utfchar(now)
+ end
+ end
+ end
+ t[i]=concat(result,"",1,r)
+ end
+ return t
end
- local result={}
- for i=1,#t do
- local r,more=0,0
- for left,right in bytepairs(t[i]) do
- if right then
- local now=256*right+left
- if more>0 then
- now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
- more=0
- r=r+1
- result[r]=utfchar(now)
- elseif now>=0xD800 and now<=0xDBFF then
- more=now
+ utf32_to_utf8_be=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utflinesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,-1
+ for a,b in bytepairs(t[i]) do
+ if a and b then
+ if more<0 then
+ more=256*256*256*a+256*256*b
+ else
+ r=r+1
+ result[t]=utfchar(more+256*a+b)
+ more=-1
+ end
else
- r=r+1
- result[r]=utfchar(now)
+ break
end
end
+ t[i]=concat(result,"",1,r)
end
- t[i]=concat(result,"",1,r)
- end
- return t
-end
-local function utf32_to_utf8_be(t)
- if type(t)=="string" then
- t=lpegmatch(utflinesplitter,t)
+ return t
end
- local result={}
- for i=1,#t do
- local r,more=0,-1
- for a,b in bytepairs(t[i]) do
- if a and b then
- if more<0 then
- more=256*256*256*a+256*256*b
+ utf32_to_utf8_le=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utflinesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,-1
+ for a,b in bytepairs(t[i]) do
+ if a and b then
+ if more<0 then
+ more=256*b+a
+ else
+ r=r+1
+ result[t]=utfchar(more+256*256*256*b+256*256*a)
+ more=-1
+ end
else
- r=r+1
- result[t]=utfchar(more+256*a+b)
- more=-1
+ break
end
- else
- break
end
+ t[i]=concat(result,"",1,r)
end
- t[i]=concat(result,"",1,r)
+ return t
end
- return t
-end
-local function utf32_to_utf8_le(t)
- if type(t)=="string" then
- t=lpegmatch(utflinesplitter,t)
+else
+ utf16_to_utf8_be=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utf_16_be_linesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,0
+ for left,right in gmatch(t[i],"(.)(.)") do
+ if left=="\000" then
+ r=r+1
+ result[r]=utfchar(byte(right))
+ elseif right then
+ local now=256*byte(left)+byte(right)
+ if more>0 then
+ now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
+ more=0
+ r=r+1
+ result[r]=utfchar(now)
+ elseif now>=0xD800 and now<=0xDBFF then
+ more=now
+ else
+ r=r+1
+ result[r]=utfchar(now)
+ end
+ end
+ end
+ t[i]=concat(result,"",1,r)
+ end
+ return t
end
- local result={}
- for i=1,#t do
- local r,more=0,-1
- for a,b in bytepairs(t[i]) do
- if a and b then
- if more<0 then
- more=256*b+a
- else
+ utf16_to_utf8_le=function(t)
+ if type(t)=="string" then
+ t=lpegmatch(utf_16_le_linesplitter,t)
+ end
+ local result={}
+ for i=1,#t do
+ local r,more=0,0
+ for left,right in gmatch(t[i],"(.)(.)") do
+ if right=="\000" then
r=r+1
- result[t]=utfchar(more+256*256*256*b+256*256*a)
- more=-1
+ result[r]=utfchar(byte(left))
+ elseif right then
+ local now=256*byte(right)+byte(left)
+ if more>0 then
+ now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
+ more=0
+ r=r+1
+ result[r]=utfchar(now)
+ elseif now>=0xD800 and now<=0xDBFF then
+ more=now
+ else
+ r=r+1
+ result[r]=utfchar(now)
+ end
end
- else
- break
end
+ t[i]=concat(result,"",1,r)
end
- t[i]=concat(result,"",1,r)
+ return t
end
- return t
+ utf32_to_utf8_le=function() return {} end
+ utf32_to_utf8_be=function() return {} end
end
-utf.utf32_to_utf8_be=utf32_to_utf8_be
-utf.utf32_to_utf8_le=utf32_to_utf8_le
-utf.utf16_to_utf8_be=utf16_to_utf8_be
utf.utf16_to_utf8_le=utf16_to_utf8_le
+utf.utf16_to_utf8_be=utf16_to_utf8_be
+utf.utf32_to_utf8_le=utf32_to_utf8_le
+utf.utf32_to_utf8_be=utf32_to_utf8_be
function utf.utf8_to_utf8(t)
return type(t)=="string" and lpegmatch(utflinesplitter,t) or t
end
@@ -4034,11 +4241,17 @@ local function big(c)
end
local _,l_remap=utf.remapper(little)
local _,b_remap=utf.remapper(big)
+function utf.utf8_to_utf16_be(str)
+ return char(254,255)..lpegmatch(b_remap,str)
+end
+function utf.utf8_to_utf16_le(str)
+ return char(255,254)..lpegmatch(l_remap,str)
+end
function utf.utf8_to_utf16(str,littleendian)
if littleendian then
- return char(255,254)..lpegmatch(l_remap,str)
+ return utf.utf8_to_utf16_le(str)
else
- return char(254,255)..lpegmatch(b_remap,str)
+ return utf.utf8_to_utf16_be(str)
end
end
local pattern=Cs (
@@ -4053,6 +4266,21 @@ end
function utf.xstring(s)
return format("0x%05X",type(s)=="number" and s or utfbyte(s))
end
+function utf.toeight(str)
+ if not str then
+ return nil
+ end
+ local utftype=lpegmatch(p_utfstricttype,str)
+ if utftype=="utf-8" then
+ return sub(str,4)
+ elseif utftype=="utf-16-le" then
+ return utf16_to_utf8_le(str)
+ elseif utftype=="utf-16-be" then
+ return utf16_to_utf8_ne(str)
+ else
+ return str
+ end
+end
local p_nany=p_utf8char/""
if utfgmatch then
function utf.count(str,what)
@@ -4164,9 +4392,14 @@ setmetatable(escapes,{ __index=function(t,k)
end })
local escaper=Cs((R("09","AZ","az")^1+P(" ")/"%%20"+S("-./_")^1+P(1)/escapes)^0)
local unescaper=Cs((escapedchar+1)^0)
+local getcleaner=Cs((P("+++")/"%%2B"+P("+")/"%%20"+P(1))^1)
lpegpatterns.urlunescaped=escapedchar
lpegpatterns.urlescaper=escaper
lpegpatterns.urlunescaper=unescaper
+lpegpatterns.urlgetcleaner=getcleaner
+function url.unescapeget(str)
+ return lpegmatch(getcleaner,str)
+end
local function split(str)
return (type(str)=="string" and lpegmatch(parser,str)) or str
end