summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-01 22:57:25 +0000
committerKarl Berry <karl@freefriends.org>2014-01-01 22:57:25 +0000
commit55573131324ca3ede6a08c8aaa010937f4ae0883 (patch)
tree1f713272f8e367d1e33f545f922ee131349314f7
parent0479a789f43c32b8fbc9d74bb82c615932a3c5b1 (diff)
lualibs (1jan14)
git-svn-id: svn://tug.org/texlive/trunk@32539 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/luatex/lualibs/NEWS7
-rw-r--r--Master/texmf-dist/doc/luatex/lualibs/README1
-rw-r--r--Master/texmf-dist/doc/luatex/lualibs/lualibs.pdfbin79751 -> 79978 bytes
-rw-r--r--Master/texmf-dist/source/luatex/lualibs/Makefile6
-rw-r--r--Master/texmf-dist/source/luatex/lualibs/lualibs.dtx40
-rw-r--r--Master/texmf-dist/source/luatex/lualibs/test-lualibs.lua1
-rw-r--r--Master/texmf-dist/source/luatex/lualibs/whatsnew.lua1
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua449
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua5
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-boolean.lua4
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-dir.lua36
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua221
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua4
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua54
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-io.lua2
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua27
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-os.lua122
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-package.lua26
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua30
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua5
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua389
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-url.lua16
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-env.lua5
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua56
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-sto.lua58
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua117
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua53
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua16
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs.lua24
29 files changed, 1394 insertions, 381 deletions
diff --git a/Master/texmf-dist/doc/luatex/lualibs/NEWS b/Master/texmf-dist/doc/luatex/lualibs/NEWS
index 1d8a93e9525..315fb040268 100644
--- a/Master/texmf-dist/doc/luatex/lualibs/NEWS
+++ b/Master/texmf-dist/doc/luatex/lualibs/NEWS
@@ -1,4 +1,11 @@
History of the lualibs package
+2013/31/03 v2.1a/
+ * sync with Context beta as of 2013-12-30
+
+2013/11/03 v2.1/
+ * sync with Context beta as of 2013-11-01
+ * add l-gzip
+
2013/07/23 v2.0c/
* sync with Context beta as of 2013-07-14
diff --git a/Master/texmf-dist/doc/luatex/lualibs/README b/Master/texmf-dist/doc/luatex/lualibs/README
index 4f50cbf16bc..c37b671a3e6 100644
--- a/Master/texmf-dist/doc/luatex/lualibs/README
+++ b/Master/texmf-dist/doc/luatex/lualibs/README
@@ -41,6 +41,7 @@ Source files:
lualibs-compat.lua tex/luatex/lualibs/lualibs-compat.lua
lualibs-dir.lua tex/luatex/lualibs/lualibs-dir.lua
lualibs-file.lua tex/luatex/lualibs/lualibs-file.lua
+ lualibs-gzip.lua tex/luatex/lualibs/lualibs-gzip.lua
lualibs-function.lua tex/luatex/lualibs/lualibs-function.lua
lualibs-io.lua tex/luatex/lualibs/lualibs-io.lua
lualibs-lpeg.lua tex/luatex/lualibs/lualibs-lpeg.lua
diff --git a/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf b/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf
index 86f9cf4222e..3c724bebd9e 100644
--- a/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf
+++ b/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/luatex/lualibs/Makefile b/Master/texmf-dist/source/luatex/lualibs/Makefile
index 556e56f1399..a50c63d48b8 100644
--- a/Master/texmf-dist/source/luatex/lualibs/Makefile
+++ b/Master/texmf-dist/source/luatex/lualibs/Makefile
@@ -70,7 +70,10 @@ $(UNPACKED): lualibs.dtx
$(DO_TEX)
define make-ctandir
-@rm -r $(DISTDIR)
+@if [ -d $(DISTDIR) ] ; \
+ then \
+ rm -r $(DISTDIR) ; \
+ fi
@mkdir $(DISTDIR) && cp $(ALL_FILES) $(DISTDIR)
endef
@@ -112,5 +115,6 @@ clean:
mrproper: clean
@$(RM) -- $(GENERATED) $(ZIPS)
+ @$(RM) -r $(DISTDIR)
merge: $(MERGED)
diff --git a/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx b/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx
index 629856432a0..43e567a8bfb 100644
--- a/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx
+++ b/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx
@@ -34,7 +34,7 @@
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
-\Msg{* Package: lualibs 2013/07/23 v2.0c Lua additional functions.}
+\Msg{* Package: lualibs 2013/11/03 v2.1 Lua additional functions.}
\Msg{************************************************************************}
\keepsilent
@@ -101,7 +101,7 @@ and the derived file lualibs.lua.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{lualibs.drv}
- [2013/07/23 v2.0c Lua Libraries.]
+ [2013/11/03 v2.1 Lua Libraries.]
\documentclass{ltxdoc}
\usepackage{fancyvrb,xspace}
\usepackage[x11names]{xcolor}
@@ -202,7 +202,7 @@ and the derived file lualibs.lua.
% \GetFileInfo{lualibs.drv}
%
% \title{The \identifier{lualibs} package}
-% \date{2013/07/23 v2.0c}
+% \date{2013/11/03 v2.1}
% \author{Élie Roux · \email{elie.roux@telecom-bretagne.eu}\\
% Philipp Gesang · \email{philipp.gesang@alumni.uni-heidelberg.de}}
%
@@ -315,6 +315,7 @@ and the derived file lualibs.lua.
% lualibs-io.lua & l-io.lua & reading and writing files \\
% lualibs-os.lua & l-os.lua & platform specific code \\
% lualibs-file.lua & l-file.lua & filesystem operations \\
+% lualibs-gzip.lua & l-gzip.lua & wrapper for \identifier{lgzip} \\
% lualibs-md5.lua & l-md5.lua & checksum functions \\
% lualibs-dir.lua & l-dir.lua & directory handling \\
% lualibs-unicode.lua & l-unicode.lua & utf and unicode \\
@@ -417,8 +418,8 @@ lualibs = lualibs or { }
lualibs.module_info = {
name = "lualibs",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua standard libraries.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
@@ -445,9 +446,23 @@ lualibs.module_info = {
config = config or { }
config.lualibs = config.lualibs or { }
-lualibs.prefer_merged = config.lualibs.prefer_merged or true
-lualibs.load_extended = config.lualibs.load_extended or true
-config.lualibs.verbose = config.lualibs.verbose or false
+if config.lualibs.prefer_merged ~= nil then
+ lualibs.prefer_merged = config.lualibs.prefer_merged
+else
+ lualibs.prefer_merged = true
+end
+
+if config.lualibs.load_extended ~= nil then
+ lualibs.load_extended = config.lualibs.load_extended
+else
+ lualibs.load_extended = true
+end
+
+if config.lualibs.verbose ~= nil then
+ config.lualibs.verbose = config.lualibs.verbose
+else
+ config.lualibs.verbose = false
+end
% \end{macrocode}
% The lualibs may be loaded in scripts.
@@ -558,8 +573,8 @@ local loadmodule = lualibs.loadmodule
local lualibs_basic_module = {
name = "lualibs-basic",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua libraries -- basic collection.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
@@ -597,6 +612,7 @@ if loaded == false then
loadmodule("lualibs-io.lua")
loadmodule("lualibs-os.lua")
loadmodule("lualibs-file.lua")
+ loadmodule("lualibs-gzip.lua")
loadmodule("lualibs-md5.lua")
loadmodule("lualibs-dir.lua")
loadmodule("lualibs-unicode.lua")
@@ -639,8 +655,8 @@ lualibs = lualibs or { }
local lualibs_extended_module = {
name = "lualibs-extended",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua libraries -- extended collection.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
diff --git a/Master/texmf-dist/source/luatex/lualibs/test-lualibs.lua b/Master/texmf-dist/source/luatex/lualibs/test-lualibs.lua
index 55cecfb0b0b..c592c6e58a9 100644
--- a/Master/texmf-dist/source/luatex/lualibs/test-lualibs.lua
+++ b/Master/texmf-dist/source/luatex/lualibs/test-lualibs.lua
@@ -3,6 +3,7 @@
local luafiles = {
"lualibs-boolean.lua", "lualibs-compat.lua",
"lualibs-dir.lua", "lualibs-file.lua",
+ "lualibs-gzip.lua",
"lualibs-function.lua", "lualibs-io.lua",
"lualibs-lpeg.lua", "lualibs-lua.lua",
"lualibs-math.lua", "lualibs-md5.lua",
diff --git a/Master/texmf-dist/source/luatex/lualibs/whatsnew.lua b/Master/texmf-dist/source/luatex/lualibs/whatsnew.lua
index 30cf83782eb..0c0ca9bd44d 100644
--- a/Master/texmf-dist/source/luatex/lualibs/whatsnew.lua
+++ b/Master/texmf-dist/source/luatex/lualibs/whatsnew.lua
@@ -46,6 +46,7 @@ local filenames = {
"dir",
"file",
"function",
+ "gzip",
"io",
"lpeg",
"lua",
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
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua
index 07719b20b4e..3715a4249c2 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua
@@ -26,8 +26,8 @@ local loadmodule = lualibs.loadmodule
local lualibs_basic_module = {
name = "lualibs-basic",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua libraries -- basic collection.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
@@ -58,6 +58,7 @@ if loaded == false then
loadmodule("lualibs-io.lua")
loadmodule("lualibs-os.lua")
loadmodule("lualibs-file.lua")
+ loadmodule("lualibs-gzip.lua")
loadmodule("lualibs-md5.lua")
loadmodule("lualibs-dir.lua")
loadmodule("lualibs-unicode.lua")
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-boolean.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-boolean.lua
index f087f1a4ce2..8d11080e7fc 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-boolean.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-boolean.lua
@@ -59,9 +59,9 @@ 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
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-dir.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-dir.lua
index e47de603126..40081cc3bbc 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-dir.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-dir.lua
@@ -26,6 +26,8 @@ local isfile = lfs.isfile
local currentdir = lfs.currentdir
local chdir = lfs.chdir
+local onwindows = os.type == "windows" or find(os.getenv("PATH"),";")
+
-- in case we load outside luatex
if not isdir then
@@ -136,11 +138,33 @@ 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 -- we could sanitize here
+
+-- pattern = Ct {
+-- [1] = (C(P(".") + S("/\\")^1) + C(R("az","AZ") * P(":") * S("/\\")^0) + Cc("./")) * V(2) * V(3),
+-- [2] = C(((1-S("*?/\\"))^0 * S("/\\"))^0),
+-- [3] = C(P(1)^0)
+-- }
+
+ 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 -- assume unix
+
+ 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("**") / ".*" +
@@ -257,8 +281,6 @@ end
local make_indeed = true -- false
-local onwindows = os.type == "windows" or find(os.getenv("PATH"),";")
-
if onwindows then
function dir.mkdirs(...)
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua
index 8c9e4c3a126..d0adc397fcb 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua
@@ -1,6 +1,6 @@
-- merged file : lualibs-extended-merged.lua
-- parent file : lualibs-extended.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
@@ -147,6 +147,31 @@ function number.signed(i)
return "-",-i
end
end
+local zero=P("0")^1/""
+local plus=P("+")/""
+local minus=P("-")
+local separator=S(".")
+local digit=R("09")
+local trailing=zero^1*#S("eE")
+local exponent=(S("eE")*(plus+Cs((minus*zero^0*P(-1))/"")+minus)*zero^0*(P(-1)*Cc("0")+P(1)^1))
+local pattern_a=Cs(minus^0*digit^1*(separator/""*trailing+separator*(trailing+digit)^0)*exponent)
+local pattern_b=Cs((exponent+P(1))^0)
+function number.sparseexponent(f,n)
+ if not n then
+ n=f
+ f="%e"
+ end
+ local tn=type(n)
+ if tn=="string" then
+ local m=tonumber(n)
+ if m then
+ return lpegmatch((f=="%e" or f=="%E") and pattern_a or pattern_b,format(f,m))
+ end
+ elseif tn=="number" then
+ return lpegmatch((f=="%e" or f=="%E") and pattern_a or pattern_b,format(f,n))
+ end
+ return tostring(n)
+end
local preamble=[[
local type = type
local tostring = tostring
@@ -164,6 +189,8 @@ local tracedchar = string.tracedchar
local autosingle = string.autosingle
local autodouble = string.autodouble
local sequenced = table.sequenced
+local formattednumber = number.formatted
+local sparseexponent = number.sparseexponent
]]
local template=[[
%s
@@ -236,6 +263,14 @@ local format_E=function(f)
n=n+1
return format("format('%%%sE',a%s)",f,n)
end
+local format_j=function(f)
+ n=n+1
+ return format("sparseexponent('%%%se',a%s)",f,n)
+end
+local format_J=function(f)
+ n=n+1
+ return format("sparseexponent('%%%sE',a%s)",f,n)
+end
local format_x=function(f)
n=n+1
return format("format('%%%sx',a%s)",f,n)
@@ -360,6 +395,43 @@ end
local format_W=function(f)
return format("nspaces[%s]",tonumber(f) or 0)
end
+local digit=patterns.digit
+local period=patterns.period
+local three=digit*digit*digit
+local splitter=Cs (
+ (((1-(three^1*period))^1+C(three))*(Carg(1)*three)^1+C((1-period)^1))*(P(1)/""*Carg(2))*C(2)
+)
+patterns.formattednumber=splitter
+function number.formatted(n,sep1,sep2)
+ local s=type(s)=="string" and n or format("%0.2f",n)
+ if sep1==true then
+ return lpegmatch(splitter,s,1,".",",")
+ elseif sep1=="." then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ",")
+ elseif sep1=="," then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ".")
+ else
+ return lpegmatch(splitter,s,1,sep1 or ",",sep2 or ".")
+ end
+end
+local format_m=function(f)
+ n=n+1
+ if not f or f=="" then
+ f=","
+ end
+ return format([[formattednumber(a%s,%q,".")]],n,f)
+end
+local format_M=function(f)
+ n=n+1
+ if not f or f=="" then
+ f="."
+ end
+ return format([[formattednumber(a%s,%q,",")]],n,f)
+end
+local format_z=function(f)
+ n=n+(tonumber(f) or 1)
+ return "''"
+end
local format_rest=function(s)
return format("%q",s)
end
@@ -393,11 +465,13 @@ local builder=Cs { "start",
+V("c")+V("C")+V("S")
+V("Q")
+V("N")
-+V("r")+V("h")+V("H")+V("u")+V("U")+V("p")+V("b")+V("t")+V("T")+V("l")+V("L")+V("I")+V("h")
-+V("w")
++V("r")+V("h")+V("H")+V("u")+V("U")+V("p")+V("b")+V("t")+V("T")+V("l")+V("L")+V("I")+V("w")
+V("W")
+V("a")
-+V("A")
++V("A")
++V("j")+V("J")
++V("m")+V("M")
++V("z")
+V("*")
)+V("*")
)*(P(-1)+Carg(1))
@@ -433,6 +507,11 @@ local builder=Cs { "start",
["I"]=(prefix_any*P("I"))/format_I,
["w"]=(prefix_any*P("w"))/format_w,
["W"]=(prefix_any*P("W"))/format_W,
+ ["j"]=(prefix_any*P("j"))/format_j,
+ ["J"]=(prefix_any*P("J"))/format_J,
+ ["m"]=(prefix_tab*P("m"))/format_m,
+ ["M"]=(prefix_tab*P("M"))/format_M,
+ ["z"]=(prefix_any*P("z"))/format_z,
["a"]=(prefix_any*P("a"))/format_a,
["A"]=(prefix_any*P("A"))/format_A,
["*"]=Cs(((1-P("%"))^1+P("%%")/"%%")^1)/format_rest,
@@ -503,13 +582,14 @@ if not modules then modules={} end modules ['util-tab']={
utilities=utilities or {}
utilities.tables=utilities.tables or {}
local tables=utilities.tables
-local format,gmatch,gsub=string.format,string.gmatch,string.gsub
+local format,gmatch,gsub,sub=string.format,string.gmatch,string.gsub,string.sub
local concat,insert,remove=table.concat,table.insert,table.remove
local setmetatable,getmetatable,tonumber,tostring=setmetatable,getmetatable,tonumber,tostring
local type,next,rawset,tonumber,tostring,load,select=type,next,rawset,tonumber,tostring,load,select
local lpegmatch,P,Cs,Cc=lpeg.match,lpeg.P,lpeg.Cs,lpeg.Cc
local sortedkeys,sortedpairs=table.sortedkeys,table.sortedpairs
local formatters=string.formatters
+local utftoeight=utf.toeight
local splitter=lpeg.tsplitat(".")
function tables.definetable(target,nofirst,nolast)
local composed,shortcut,t=nil,nil,{}
@@ -717,10 +797,14 @@ local f_hashed_string=formatters["[%q]=%q,"]
local f_hashed_number=formatters["[%q]=%s,"]
local f_hashed_boolean=formatters["[%q]=%l,"]
local f_hashed_table=formatters["[%q]="]
-local f_indexed_string=formatters["%q,"]
-local f_indexed_number=formatters["%s,"]
-local f_indexed_boolean=formatters["%l,"]
-function table.fastserialize(t,prefix)
+local f_indexed_string=formatters["[%s]=%q,"]
+local f_indexed_number=formatters["[%s]=%s,"]
+local f_indexed_boolean=formatters["[%s]=%l,"]
+local f_indexed_table=formatters["[%s]="]
+local f_ordered_string=formatters["%q,"]
+local f_ordered_number=formatters["%s,"]
+local f_ordered_boolean=formatters["%l,"]
+function table.fastserialize(t,prefix)
local r={ prefix or "return" }
local m=1
local function fastserialize(t,outer)
@@ -728,21 +812,37 @@ function table.fastserialize(t,prefix)
m=m+1
r[m]="{"
if n>0 then
- for i=1,n do
+ for i=0,n do
local v=t[i]
local tv=type(v)
if tv=="string" then
- m=m+1 r[m]=f_indexed_string(v)
+ m=m+1 r[m]=f_ordered_string(v)
elseif tv=="number" then
- m=m+1 r[m]=f_indexed_number(v)
+ m=m+1 r[m]=f_ordered_number(v)
elseif tv=="table" then
fastserialize(v)
elseif tv=="boolean" then
- m=m+1 r[m]=f_indexed_boolean(v)
+ m=m+1 r[m]=f_ordered_boolean(v)
end
end
- else
- for k,v in next,t do
+ end
+ for k,v in next,t do
+ local tk=type(k)
+ if tk=="number" then
+ if k>n or k<0 then
+ local tv=type(v)
+ if tv=="string" then
+ m=m+1 r[m]=f_indexed_string(k,v)
+ elseif tv=="number" then
+ m=m+1 r[m]=f_indexed_number(k,v)
+ elseif tv=="table" then
+ m=m+1 r[m]=f_indexed_table(k)
+ fastserialize(v)
+ elseif tv=="boolean" then
+ m=m+1 r[m]=f_indexed_boolean(k,v)
+ end
+ end
+ else
local tv=type(v)
if tv=="string" then
m=m+1 r[m]=f_hashed_string(k,v)
@@ -784,6 +884,7 @@ function table.load(filename,loader)
if filename then
local t=(loader or io.loaddata)(filename)
if t and t~="" then
+ local t=utftoeight(t)
t=load(t)
if type(t)=="function" then
t=t()
@@ -893,7 +994,7 @@ local f_table_direct=formatters["{"]
local f_table_entry=formatters["[%q]={"]
local f_table_finish=formatters["}"]
local spaces=utilities.strings.newrepeater(" ")
-local serialize=table.serialize
+local serialize=table.serialize
function table.serialize(root,name,specification)
if type(specification)=="table" then
return serialize(root,name,specification)
@@ -1144,56 +1245,47 @@ end
local function f_empty () return "" end
local function f_self (t,k) t[k]=k return k end
local function f_table (t,k) local v={} t[k]=v return v end
+local function f_number(t,k) t[k]=0 return 0 end
local function f_ignore() end
-local t_empty={ __index=f_empty }
-local t_self={ __index=f_self }
-local t_table={ __index=f_table }
-local t_ignore={ __newindex=f_ignore }
+local f_index={
+ ["empty"]=f_empty,
+ ["self"]=f_self,
+ ["table"]=f_table,
+ ["number"]=f_number,
+}
+local t_index={
+ ["empty"]={ __index=f_empty },
+ ["self"]={ __index=f_self },
+ ["table"]={ __index=f_table },
+ ["number"]={ __index=f_number },
+}
function table.setmetatableindex(t,f)
if type(t)~="table" then
f,t=t,{}
end
local m=getmetatable(t)
if m then
- if f=="empty" then
- m.__index=f_empty
- elseif f=="key" then
- m.__index=f_self
- elseif f=="table" then
- m.__index=f_table
- else
- m.__index=f
- end
+ m.__index=f_index[f] or f
else
- if f=="empty" then
- setmetatable(t,t_empty)
- elseif f=="key" then
- setmetatable(t,t_self)
- elseif f=="table" then
- setmetatable(t,t_table)
- else
- setmetatable(t,{ __index=f })
- end
+ setmetatable(t,t_index[f] or { __index=f })
end
return t
end
+local f_index={
+ ["ignore"]=f_ignore,
+}
+local t_index={
+ ["ignore"]={ __newindex=f_ignore },
+}
function table.setmetatablenewindex(t,f)
if type(t)~="table" then
f,t=t,{}
end
local m=getmetatable(t)
if m then
- if f=="ignore" then
- m.__newindex=f_ignore
- else
- m.__newindex=f
- end
+ m.__newindex=f_index[f] or f
else
- if f=="ignore" then
- setmetatable(t,t_ignore)
- else
- setmetatable(t,{ __newindex=f })
- end
+ setmetatable(t,t_index[f] or { __newindex=f })
end
return t
end
@@ -1379,6 +1471,25 @@ function parsers.settings_to_array(str,strict)
return lpegmatch(pattern,str)
end
end
+local separator=space^0*comma*space^0
+local value=P(lbrace*C((nobrace+nestedbraces)^0)*rbrace)+C((nestedbraces+(1-(space^0*(comma+P(-1)))))^0)
+local withvalue=Carg(1)*value/function(f,s) return f(s) end
+local pattern_a=spaces*Ct(value*(separator*value)^0)
+local pattern_b=spaces*withvalue*(separator*withvalue)^0
+function parsers.stripped_settings_to_array(str)
+ if not str or str=="" then
+ return {}
+ else
+ return lpegmatch(pattern_a,str)
+ end
+end
+function parsers.process_stripped_settings(str,action)
+ if not str or str=="" then
+ return {}
+ else
+ return lpegmatch(pattern_b,str,1,action)
+ end
+end
local function set(t,v)
t[#t+1]=v
end
@@ -1443,6 +1554,12 @@ function parsers.simple_hash_to_string(h,separator)
end
return concat(t,separator or ",")
end
+local str=C((1-whitespace-equal)^1)
+local setting=Cf(Carg(1)*(whitespace^0*Cg(str*whitespace^0*(equal*whitespace^0*str+Cc(""))))^1,rawset)
+local splitter=setting^1
+function utilities.parsers.options_to_hash(str,target)
+ return str and lpegmatch(splitter,str,1,target or {}) or {}
+end
local value=P(lbrace*C((nobrace+nestedbraces)^0)*rbrace)+C(digit^1*lparent*(noparent+nestedparents)^1*rparent)+C((nestedbraces+(1-comma))^1)
local pattern_a=spaces*Ct(value*(separator*value)^0)
local function repeater(n,str)
@@ -1655,7 +1772,7 @@ end
local function fetch(t,name)
return t[name] or {}
end
-function process(result,more)
+local function process(result,more)
for k,v in next,more do
result[k]=v
end
@@ -2382,8 +2499,8 @@ local templates=utilities.templates
local trace_template=false trackers.register("templates.trace",function(v) trace_template=v end)
local report_template=logs.reporter("template")
local tostring=tostring
-local format,sub=string.format,string.sub
-local P,C,Cs,Carg,lpegmatch,lpegpatterns=lpeg.P,lpeg.C,lpeg.Cs,lpeg.Carg,lpeg.match,lpeg.patterns
+local format,sub,byte=string.format,string.sub,string.byte
+local P,C,R,Cs,Cc,Carg,lpegmatch,lpegpatterns=lpeg.P,lpeg.C,lpeg.R,lpeg.Cs,lpeg.Cc,lpeg.Carg,lpeg.match,lpeg.patterns
local replacer
local function replacekey(k,t,how,recursive)
local v=t[k]
@@ -2413,6 +2530,7 @@ local sqlescape=lpeg.replacer {
local sqlquoted=lpeg.Cs(lpeg.Cc("'")*sqlescape*lpeg.Cc("'"))
lpegpatterns.sqlescape=sqlescape
lpegpatterns.sqlquoted=sqlquoted
+local luaescape=lpegpatterns.luaescape
local escapers={
lua=function(s)
return lpegmatch(luaescape,s)
@@ -2753,6 +2871,7 @@ local luaengines=allocate {
environment.validengines=validengines
environment.basicengines=basicengines
if not arg then
+ environment.used_as_library=true
elseif luaengines[file.removesuffix(arg[-1])] then
elseif validengines[file.removesuffix(arg[0])] then
if arg[1]=="--luaonly" then
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua
index be659e162e0..ca51b400a4e 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua
@@ -27,8 +27,8 @@ lualibs = lualibs or { }
local lualibs_extended_module = {
name = "lualibs-extended",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua libraries -- extended collection.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua
new file mode 100644
index 00000000000..5100e47222c
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua
@@ -0,0 +1,54 @@
+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
+
+ -- no fallback yet
+
+ return
+
+end
+
+local suffix, suffixes = file.suffix, file.suffixes
+
+function gzip.load(filename)
+ local f = io.open(filename,"rb")
+ if not f then
+ -- invalid file
+ 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
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-io.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-io.lua
index e3a443be8c0..52f166af9aa 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-io.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-io.lua
@@ -60,7 +60,7 @@ io.readall = readall
function io.loaddata(filename,textmode) -- return nil if empty
local f = io.open(filename,(textmode and 'r') or 'rb')
if f then
--- local data = f:read('*all')
+ -- local data = f:read('*all')
local data = readall(f)
f:close()
if #data > 0 then
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua
index b33df96b7d9..399b3ad6501 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua
@@ -82,7 +82,6 @@ setinspector(function(v) if lpegtype(v) then lpegprint(v) return true end end)
lpeg.patterns = lpeg.patterns or { } -- so that we can share
local patterns = lpeg.patterns
-
local anything = P(1)
local endofstring = P(-1)
local alwaysmatched = P(true)
@@ -109,29 +108,42 @@ 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') -- 00 00 FE FF
+local utfbom_32_le = P('\255\254\000\000') -- FF FE 00 00
+local utfbom_16_be = P('\254\255') -- FE FF
+local utfbom_16_le = P('\255\254') -- FF FE
+local utfbom_8 = P('\239\187\191') -- EF BB BF
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") -- assume utf8
+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
@@ -454,6 +466,9 @@ function lpeg.replacer(one,two,makefunction,isutf) -- in principle we should sor
end
end
+-- local pattern1 = P(1-P(pattern))^0 * P(pattern) : test for not nil
+-- local pattern2 = (P(pattern) * Cc(true) + P(1))^0 : test for true (could be faster, but not much)
+
function lpeg.finder(lst,makefunction) -- beware: slower than find with 'patternless finds'
local pattern
if type(lst) == "table" then
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-os.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-os.lua
index a4c0ac82085..bfafa4f95db 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-os.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-os.lua
@@ -127,7 +127,13 @@ 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
@@ -191,9 +197,8 @@ end
-- no need for function anymore as we have more clever code and helpers now
-- this metatable trickery might as well disappear
-os.resolvers = os.resolvers or { } -- will become private
-
-local resolvers = os.resolvers
+local resolvers = os.resolvers or { }
+os.resolvers = resolvers
setmetatable(os, { __index = function(t,k)
local r = resolvers[k]
@@ -216,6 +221,8 @@ local function guess()
return os.resultof("echo $HOSTTYPE") or ""
end
+-- os.bits = 32 | 64
+
if platform ~= "" then
os.platform = platform
@@ -224,10 +231,14 @@ elseif os.type == "windows" then
-- we could set the variable directly, no function needed here
- function os.resolvers.platform(t,k)
+ -- PROCESSOR_ARCHITECTURE : binary platform
+ -- PROCESSOR_ARCHITEW6432 : OS platform
+
+ function resolvers.platform(t,k)
local platform, architecture = "", os.getenv("PROCESSOR_ARCHITECTURE") or ""
if find(architecture,"AMD64") then
- platform = "mswin-64"
+ -- platform = "mswin-64"
+ platform = "win64"
else
platform = "mswin"
end
@@ -238,7 +249,7 @@ elseif os.type == "windows" then
elseif name == "linux" then
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
-- we sometimes have HOSTTYPE set so let's check that first
local platform, architecture = "", os.getenv("HOSTTYPE") or os.resultof("uname -m") or ""
if find(architecture,"x86_64") then
@@ -265,7 +276,7 @@ elseif name == "macosx" then
therefore not permitted to run the 64 bit kernel.
]]--
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
-- local platform, architecture = "", os.getenv("HOSTTYPE") or ""
-- if architecture == "" then
-- architecture = os.resultof("echo $HOSTTYPE") or ""
@@ -288,7 +299,7 @@ elseif name == "macosx" then
elseif name == "sunos" then
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
local platform, architecture = "", os.resultof("uname -m") or ""
if find(architecture,"sparc") then
platform = "solaris-sparc"
@@ -302,7 +313,7 @@ elseif name == "sunos" then
elseif name == "freebsd" then
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
local platform, architecture = "", os.resultof("uname -m") or ""
if find(architecture,"amd64") then
platform = "freebsd-amd64"
@@ -316,7 +327,7 @@ elseif name == "freebsd" then
elseif name == "kfreebsd" then
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
-- we sometimes have HOSTTYPE set so let's check that first
local platform, architecture = "", os.getenv("HOSTTYPE") or os.resultof("uname -m") or ""
if find(architecture,"x86_64") then
@@ -335,7 +346,7 @@ else
-- os.setenv("MTX_PLATFORM",platform)
-- os.platform = platform
- function os.resolvers.platform(t,k)
+ function resolvers.platform(t,k)
local platform = "linux"
os.setenv("MTX_PLATFORM",platform)
os.platform = platform
@@ -344,6 +355,12 @@ else
end
+function resolvers.bits(t,k)
+ local bits = find(os.platform,"64") and 64 or 32
+ os.bits = bits
+ return bits
+end
+
-- beware, we set the randomseed
-- from wikipedia: Version 4 UUIDs use a scheme relying only on random numbers. This algorithm sets the
@@ -382,31 +399,43 @@ 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
-- valid time
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
-- valid time
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)
@@ -474,3 +503,60 @@ end
-- print(os.which("inkscape"))
-- print(os.which("gs.exe"))
-- print(os.which("ps2pdf"))
+
+-- These are moved from core-con.lua (as I needed them elsewhere).
+
+local function isleapyear(year)
+ return (year % 400 == 0) or ((year % 100 ~= 0) and (year % 4 == 0))
+end
+
+os.isleapyear = isleapyear
+
+-- nicer:
+--
+-- local days = {
+-- [false] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+-- [true] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+-- }
+--
+-- local function nofdays(year,month)
+-- return days[isleapyear(year)][month]
+-- return month == 2 and isleapyear(year) and 29 or days[month]
+-- end
+--
+-- more efficient:
+
+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)
+ -- we assume that all three values are set
+ -- year is always ok, even if lua has a 1970 time limit
+ 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
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-package.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-package.lua
index 579fd3941c6..075fcde25ae 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-package.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-package.lua
@@ -17,7 +17,7 @@ if not modules then modules = { } end modules ['l-package'] = {
-- -- local mysql = require("luasql.mysql")
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
@@ -68,6 +68,7 @@ local helpers = package.helpers or {
sequence = {
"already loaded",
"preload table",
+ "qualified path", -- beware, lua itself doesn't handle qualified paths (prepends ./)
"lua extra list",
"lib extra list",
"path specification",
@@ -243,6 +244,23 @@ 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
@@ -251,8 +269,12 @@ 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")
+ return loadedbypath(addsuffix(lualibfile(name),"lua"),name,getextraluapaths(),false,"lua")
end
methods["lib extra list"] = function(name)
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
index 11cb66bef1e..f361f3d20c4 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
@@ -129,10 +129,13 @@ local function sortedhash(t,cmp)
s = sortedkeys(t) -- the robust one
end
local n = 0
+ local m = #s
local function kv(s)
- n = n + 1
- local k = s[n]
- return k, t[k]
+ if n < m then
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
end
return kv, s
else
@@ -1054,3 +1057,24 @@ function table.sorted(t,...)
sort(t,...)
return t -- still sorts in-place
end
+
+--
+
+function table.values(t,s) -- optional sort flag
+ if t then
+ local values, keys, v = { }, { }, 0
+ for key, value in next, t do
+ if not keys[value] then
+ v = v + 1
+ values[v] = value
+ keys[k] = key
+ end
+ end
+ if s then
+ sort(values)
+ end
+ return values
+ else
+ return { }
+ end
+end
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
index 79cbdba3f2a..802f2e6672e 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
@@ -122,6 +122,9 @@ function statistics.show()
if statistics.enable then
-- this code will move
local register = statistics.register
+ register("used platform", function()
+ return format("%s, type: %s, binary subtree: %s",os.platform or "unknown",os.type or "unknown", environment.texos or "unknown")
+ end)
register("luatex banner", function()
return lower(status.banner)
end)
@@ -179,7 +182,7 @@ function statistics.timed(action)
starttiming("run")
action()
stoptiming("run")
- report("total runtime: %s",elapsedtime("run"))
+ report("total runtime: %s seconds",elapsedtime("run"))
end
-- goodie
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua
index 813ffd54b79..6601a4c62f7 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua
@@ -9,7 +9,6 @@ if not modules then modules = { } end modules ['l-unicode'] = {
-- this module will be reorganized
-- todo: utf.sub replacement (used in syst-aux)
-
-- we put these in the utf namespace:
utf = utf or (unicode and unicode.utf8) or { }
@@ -25,7 +24,7 @@ utf.values = utf.values or string.utfvalues
-- string.bytepairs
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
@@ -38,13 +37,14 @@ local replacer = lpeg.replacer
local utfvalues = utf.values
local utfgmatch = utf.gmatch -- not always present
-local p_utftype = patterns.utftype
-local p_utfoffset = patterns.utfoffset
-local p_utf8char = patterns.utf8char
-local p_utf8byte = patterns.utf8byte
-local p_utfbom = patterns.utfbom
-local p_newline = patterns.newline
-local p_whitespace = patterns.whitespace
+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
+local p_utfbom = patterns.utfbom
+local p_newline = patterns.newline
+local p_whitespace = patterns.whitespace
if not unicode then
@@ -621,116 +621,273 @@ function utf.magic(f) -- not used
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 = { } -- we reuse 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 -- the 0x10000 smells wrong
- 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)
+
+-- we have three possibilities:
+
+-- bytepairs: 0.048
+-- gmatch : 0.069
+-- lpeg : 0.089 (match time captures)
+
+if bytepairs then
+
+ -- with a little bit more code we could include the linesplitter
+
+ utf16_to_utf8_be = function(t)
+ if type(t) == "string" then
+ t = lpegmatch(utf_16_be_linesplitter,t)
+ end
+ local result = { } -- we reuse 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 -- the 0x10000 smells wrong
+ 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) -- we reused tmp, hence t
end
- t[i] = concat(result,"",1,r) -- we reused tmp, hence t
+ 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 = { } -- we reuse 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 -- the 0x10000 smells wrong
+ 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) -- we reused tmp, hence t
+ end
+ return t
end
- local result = { } -- we reuse 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 -- the 0x10000 smells wrong
- 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 = { } -- we reuse 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) -- we reused tmp, hence t
+ return t
end
- return t
-end
-local function utf32_to_utf8_be(t)
- if type(t) == "string" then
- t = lpegmatch(utflinesplitter,t)
- end
- local result = { } -- we reuse 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 = { } -- we reuse 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 = { } -- we reuse result
+ for i=1,#t do
+ local r, more = 0, 0
+ for left, right in gmatch(t[i],"(.)(.)") do
+ if left == "\000" then -- experiment
+ 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 -- the 0x10000 smells wrong
+ 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) -- we reused tmp, hence t
+ end
+ return t
end
- local result = { } -- we reuse 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 = { } -- we reuse 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 -- the 0x10000 smells wrong
+ 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) -- we reused tmp, hence t
end
- t[i] = concat(result,"",1,r)
+ return t
end
- return t
+
+ utf32_to_utf8_le = function() return { } end -- never used anyway
+ utf32_to_utf8_be = function() return { } end -- never used anyway
+
+ -- the next one is slighty slower
+
+ -- local result, lines, r, more = { }, { }, 0, 0
+ --
+ -- local simple = Cmt(
+ -- C(1) * C(1), function(str,p,left,right)
+ -- local now = 256*byte(left) + byte(right)
+ -- if more > 0 then
+ -- now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong
+ -- 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
+ -- return p
+ -- end
+ -- )
+ --
+ -- local complex = Cmt(
+ -- C(1) * C(1), function(str,p,left,right)
+ -- local now = 256*byte(left) + byte(right)
+ -- if more > 0 then
+ -- now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong
+ -- 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
+ -- return p
+ -- end
+ -- )
+ --
+ -- local lineend = Cmt (
+ -- patterns.utf_16_be_nl, function(str,p)
+ -- lines[#lines+1] = concat(result,"",1,r)
+ -- r, more = 0, 0
+ -- return p
+ -- end
+ -- )
+ --
+ -- local be_1 = patterns.utfbom_16_be^-1 * (simple + complex)^0
+ -- local be_2 = patterns.utfbom_16_be^-1 * (lineend + simple + complex)^0
+ --
+ -- utf16_to_utf8_be = function(t)
+ -- if type(t) == "string" then
+ -- local s = t
+ -- lines, r, more = { }, 0, 0
+ -- lpegmatch(be_2,s)
+ -- if r > 0 then
+ -- lines[#lines+1] = concat(result,"",1,r)
+ -- end
+ -- result = { }
+ -- return lines
+ -- else
+ -- for i=1,#t do
+ -- r, more = 0, 0
+ -- lpegmatch(be_1,t[i])
+ -- t[i] = concat(result,"",1,r)
+ -- end
+ -- result = { }
+ -- return t
+ -- end
+ -- 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
@@ -777,14 +934,30 @@ end
local _, l_remap = utf.remapper(little)
local _, b_remap = utf.remapper(big)
-function utf.utf8_to_utf16(str,littleendian)
- if littleendian then
- return char(255,254) .. lpegmatch(l_remap,str)
+function utf.utf8_to_utf16_be(str,nobom)
+ if nobom then
+ return lpegmatch(b_remap,str)
else
return char(254,255) .. lpegmatch(b_remap,str)
end
end
+function utf.utf8_to_utf16_le(str,nobom)
+ if nobom then
+ return lpegmatch(l_remap,str)
+ else
+ return char(255,254) .. lpegmatch(l_remap,str)
+ end
+end
+
+function utf.utf8_to_utf16(str,littleendian,nobom)
+ if littleendian then
+ return utf.utf8_to_utf16_le(str,nobom)
+ else
+ return utf.utf8_to_utf16_be(str,nobom)
+ end
+end
+
-- function utf.tocodes(str,separator) -- can be sped up with an lpeg
-- local t, n = { }, 0
-- for u in utfvalues(str) do
@@ -811,6 +984,22 @@ 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 / ""
@@ -940,3 +1129,13 @@ if not utf.values then
string.utfvalues = utf.values
end
+
+function utf.chrlen(u) -- u is number
+ return
+ (u < 0x80 and 1) or
+ (u < 0xE0 and 2) or
+ (u < 0xF0 and 3) or
+ (u < 0xF8 and 4) or
+ (u < 0xFC and 5) or
+ (u < 0xFE and 6) or 0
+end
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-url.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-url.lua
index 4624a05070d..7b7910fa731 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-url.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-url.lua
@@ -79,12 +79,18 @@ setmetatable(escapes, { __index = function(t,k)
return v
end })
-local escaper = Cs((R("09","AZ","az")^1 + P(" ")/"%%20" + S("-./_")^1 + P(1) / escapes)^0) -- space happens most
-local unescaper = Cs((escapedchar + 1)^0)
+local escaper = Cs((R("09","AZ","az")^1 + P(" ")/"%%20" + S("-./_")^1 + P(1) / escapes)^0) -- space happens most
+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.urlunescaped = escapedchar
+lpegpatterns.urlescaper = escaper
+lpegpatterns.urlunescaper = unescaper
+lpegpatterns.urlgetcleaner = getcleaner
+
+function url.unescapeget(str)
+ return lpegmatch(getcleaner,str)
+end
-- todo: reconsider Ct as we can as well have five return values (saves a table)
-- so we can have two parsers, one with and one without
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-env.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-env.lua
index f4f3ef69f2f..0a708ea4397 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-env.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-env.lua
@@ -42,7 +42,7 @@ local basicengines = allocate {
-- ["texluajit.exe"] = "luajittex",
}
-local luaengines=allocate {
+local luaengines = allocate {
["lua"] = true,
["luajit"] = true,
}
@@ -57,6 +57,7 @@ environment.basicengines = basicengines
-- instead we could set ranges
if not arg then
+ environment.used_as_library = true
-- used as library
elseif luaengines[file.removesuffix(arg[-1])] then
-- arg[-1] = arg[0]
@@ -65,6 +66,8 @@ elseif luaengines[file.removesuffix(arg[-1])] then
-- arg[k-1] = arg[k]
-- end
-- remove(arg) -- last
+--
+-- environment.used_as_library = true
elseif validengines[file.removesuffix(arg[0])] then
if arg[1] == "--luaonly" then
arg[-1] = arg[0]
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
index 7fe1e703b7b..e5b35a72720 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
@@ -40,8 +40,8 @@ local newline = lpegpatterns.newline
local anything = lpegpatterns.anything
local endofstring = lpegpatterns.endofstring
-local nobrace = 1 - ( lbrace + rbrace )
-local noparent = 1 - ( lparent + rparent)
+local nobrace = 1 - (lbrace + rbrace )
+local noparent = 1 - (lparent + rparent)
-- we could use a Cf Cg construct
@@ -184,11 +184,45 @@ function parsers.settings_to_array(str,strict)
else
return { str }
end
- else
+ elseif find(str,",") then
return lpegmatch(pattern,str)
+ else
+ return { str }
+ end
+end
+
+-- this one also strips end spaces before separators
+--
+-- "{123} , 456 " -> "123" "456"
+
+local separator = space^0 * comma * space^0
+local value = P(lbrace * C((nobrace + nestedbraces)^0) * rbrace)
+ + C((nestedbraces + (1-(space^0*(comma+P(-1)))))^0)
+local withvalue = Carg(1) * value / function(f,s) return f(s) end
+local pattern_a = spaces * Ct(value*(separator*value)^0)
+local pattern_b = spaces * withvalue * (separator*withvalue)^0
+
+function parsers.stripped_settings_to_array(str)
+ if not str or str == "" then
+ return { }
+ else
+ return lpegmatch(pattern_a,str)
end
end
+function parsers.process_stripped_settings(str,action)
+ if not str or str == "" then
+ return { }
+ else
+ return lpegmatch(pattern_b,str,1,action)
+ end
+end
+
+-- parsers.process_stripped_settings("{123} , 456 ",function(s) print("["..s.."]") end)
+-- parsers.process_stripped_settings("123 , 456 ",function(s) print("["..s.."]") end)
+
+--
+
local function set(t,v)
t[#t+1] = v
end
@@ -261,6 +295,16 @@ function parsers.simple_hash_to_string(h, separator)
return concat(t,separator or ",")
end
+-- for mtx-context etc: aaaa bbbb cccc=dddd eeee=ffff
+
+local str = C((1-whitespace-equal)^1)
+local setting = Cf( Carg(1) * (whitespace^0 * Cg(str * whitespace^0 * (equal * whitespace^0 * str + Cc(""))))^1,rawset)
+local splitter = setting^1
+
+function utilities.parsers.options_to_hash(str,target)
+ return str and lpegmatch(splitter,str,1,target or { }) or { }
+end
+
-- for chem (currently one level)
local value = P(lbrace * C((nobrace + nestedbraces)^0) * rbrace)
@@ -441,8 +485,8 @@ function parsers.rfc4180splitter(specification)
* Cs((dquotechar + (1 - quotechar))^0)
* quotechar
local non_escaped = C((1 - quotechar - newline - separator)^1)
- local field = escaped + non_escaped
- local record = Ct((field * separator^-1)^1)
+ local field = escaped + non_escaped + Cc("")
+ local record = Ct(field * (separator * field)^1)
local headerline = record * Cp()
local wholeblob = Ct((newline^-1 * record)^0)
return function(data,getheader)
@@ -569,7 +613,7 @@ local function fetch(t,name)
return t[name] or { }
end
-function process(result,more)
+local function process(result,more)
for k, v in next, more do
result[k] = v
end
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-sto.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-sto.lua
index 191d6cd73b2..8aafca425b8 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-sto.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-sto.lua
@@ -103,12 +103,22 @@ end
local function f_empty () return "" end -- t,k
local function f_self (t,k) t[k] = k return k end
local function f_table (t,k) local v = { } t[k] = v return v end
+local function f_number(t,k) t[k] = 0 return 0 end -- t,k,v
local function f_ignore() end -- t,k,v
-local t_empty = { __index = f_empty }
-local t_self = { __index = f_self }
-local t_table = { __index = f_table }
-local t_ignore = { __newindex = f_ignore }
+local f_index = {
+ ["empty"] = f_empty,
+ ["self"] = f_self,
+ ["table"] = f_table,
+ ["number"] = f_number,
+}
+
+local t_index = {
+ ["empty"] = { __index = f_empty },
+ ["self"] = { __index = f_self },
+ ["table"] = { __index = f_table },
+ ["number"] = { __index = f_number },
+}
function table.setmetatableindex(t,f)
if type(t) ~= "table" then
@@ -116,46 +126,30 @@ function table.setmetatableindex(t,f)
end
local m = getmetatable(t)
if m then
- if f == "empty" then
- m.__index = f_empty
- elseif f == "key" then
- m.__index = f_self
- elseif f == "table" then
- m.__index = f_table
- else
- m.__index = f
- end
+ m.__index = f_index[f] or f
else
- if f == "empty" then
- setmetatable(t, t_empty)
- elseif f == "key" then
- setmetatable(t, t_self)
- elseif f == "table" then
- setmetatable(t, t_table)
- else
- setmetatable(t,{ __index = f })
- end
+ setmetatable(t,t_index[f] or { __index = f })
end
return t
end
+local f_index = {
+ ["ignore"] = f_ignore,
+}
+
+local t_index = {
+ ["ignore"] = { __newindex = f_ignore },
+}
+
function table.setmetatablenewindex(t,f)
if type(t) ~= "table" then
f, t = t, { }
end
local m = getmetatable(t)
if m then
- if f == "ignore" then
- m.__newindex = f_ignore
- else
- m.__newindex = f
- end
+ m.__newindex = f_index[f] or f
else
- if f == "ignore" then
- setmetatable(t, t_ignore)
- else
- setmetatable(t,{ __newindex = f })
- end
+ setmetatable(t,t_index[f] or { __newindex = f })
end
return t
end
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua
index 13e1e092241..af8b1651e9a 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua
@@ -264,6 +264,33 @@ function number.signed(i)
end
end
+local zero = P("0")^1 / ""
+local plus = P("+") / ""
+local minus = P("-")
+local separator = S(".")
+local digit = R("09")
+local trailing = zero^1 * #S("eE")
+local exponent = (S("eE") * (plus + Cs((minus * zero^0 * P(-1))/"") + minus) * zero^0 * (P(-1) * Cc("0") + P(1)^1))
+local pattern_a = Cs(minus^0 * digit^1 * (separator/"" * trailing + separator * (trailing + digit)^0) * exponent)
+local pattern_b = Cs((exponent + P(1))^0)
+
+function number.sparseexponent(f,n)
+ if not n then
+ n = f
+ f = "%e"
+ end
+ local tn = type(n)
+ if tn == "string" then -- cast to number
+ local m = tonumber(n)
+ if m then
+ return lpegmatch((f == "%e" or f == "%E") and pattern_a or pattern_b,format(f,m))
+ end
+ elseif tn == "number" then
+ return lpegmatch((f == "%e" or f == "%E") and pattern_a or pattern_b,format(f,n))
+ end
+ return tostring(n)
+end
+
local preamble = [[
local type = type
local tostring = tostring
@@ -281,6 +308,8 @@ local tracedchar = string.tracedchar
local autosingle = string.autosingle
local autodouble = string.autodouble
local sequenced = table.sequenced
+local formattednumber = number.formatted
+local sparseexponent = number.sparseexponent
]]
local template = [[
@@ -375,6 +404,16 @@ local format_E = function(f)
return format("format('%%%sE',a%s)",f,n)
end
+local format_j = function(f)
+ n = n + 1
+ return format("sparseexponent('%%%se',a%s)",f,n)
+end
+
+local format_J = function(f)
+ n = n + 1
+ return format("sparseexponent('%%%sE',a%s)",f,n)
+end
+
local format_x = function(f)
n = n + 1
return format("format('%%%sx',a%s)",f,n)
@@ -520,6 +559,68 @@ local format_W = function(f) -- handy when doing depth related indent
return format("nspaces[%s]",tonumber(f) or 0)
end
+-- maybe to util-num
+
+local digit = patterns.digit
+local period = patterns.period
+local three = digit * digit * digit
+
+local splitter = Cs (
+ (((1 - (three^1 * period))^1 + C(three)) * (Carg(1) * three)^1 + C((1-period)^1))
+ * (P(1)/"" * Carg(2)) * C(2)
+)
+
+patterns.formattednumber = splitter
+
+function number.formatted(n,sep1,sep2)
+ local s = type(s) == "string" and n or format("%0.2f",n)
+ if sep1 == true then
+ return lpegmatch(splitter,s,1,".",",")
+ elseif sep1 == "." then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ",")
+ elseif sep1 == "," then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ".")
+ else
+ return lpegmatch(splitter,s,1,sep1 or ",",sep2 or ".")
+ end
+end
+
+-- print(number.formatted(1))
+-- print(number.formatted(12))
+-- print(number.formatted(123))
+-- print(number.formatted(1234))
+-- print(number.formatted(12345))
+-- print(number.formatted(123456))
+-- print(number.formatted(1234567))
+-- print(number.formatted(12345678))
+-- print(number.formatted(12345678,true))
+-- print(number.formatted(1234.56,"!","?"))
+
+local format_m = function(f)
+ n = n + 1
+ if not f or f == "" then
+ f = ","
+ end
+ return format([[formattednumber(a%s,%q,".")]],n,f)
+end
+
+local format_M = function(f)
+ n = n + 1
+ if not f or f == "" then
+ f = "."
+ end
+ return format([[formattednumber(a%s,%q,",")]],n,f)
+end
+
+--
+
+local format_z = function(f)
+ n = n + (tonumber(f) or 1)
+ return "''" -- okay, not that efficient to append '' but a special case anyway
+end
+
+--
+
local format_rest = function(s)
return format("%q",s) -- catches " and \n and such
end
@@ -546,6 +647,8 @@ local format_extension = function(extensions,f,name)
end
end
+-- aA b cC d eE f gG hH iI jJ lL mM N o p qQ r sS tT uU wW xX z
+
local builder = Cs { "start",
start = (
(
@@ -569,11 +672,13 @@ local builder = Cs { "start",
+ V("t") + V("T")
+ V("l") + V("L")
+ V("I")
- + V("h") -- new
+ V("w") -- new
+ V("W") -- new
+ V("a") -- new
+ V("A") -- new
+ + V("j") + V("J") -- stripped e E
+ + V("m") + V("M") -- new
+ + V("z") -- new
--
+ V("*") -- ignores probably messed up %
)
@@ -617,6 +722,14 @@ local builder = Cs { "start",
["w"] = (prefix_any * P("w")) / format_w, -- %w => n spaces (optional prefix is added)
["W"] = (prefix_any * P("W")) / format_W, -- %W => mandate prefix, no specifier
--
+ ["j"] = (prefix_any * P("j")) / format_j, -- %j => %e (float) stripped exponent (irrational)
+ ["J"] = (prefix_any * P("J")) / format_J, -- %J => %E (float) stripped exponent (irrational)
+ --
+ ["m"] = (prefix_tab * P("m")) / format_m, -- %m => xxx.xxx.xxx,xx (optional prefix instead of .)
+ ["M"] = (prefix_tab * P("M")) / format_M, -- %M => xxx,xxx,xxx.xx (optional prefix instead of ,)
+ --
+ ["z"] = (prefix_any * P("z")) / format_z, -- %M => xxx,xxx,xxx.xx (optional prefix instead of ,)
+ --
["a"] = (prefix_any * P("a")) / format_a, -- %a => '...' (forces tostring)
["A"] = (prefix_any * P("A")) / format_A, -- %A => "..." (forces tostring)
--
@@ -647,7 +760,7 @@ local function make(t,str)
p = lpegmatch(builder,str,1,"..",t._extensions_) -- after this we know n
if n > 0 then
p = format(template,preamble,t._preamble_,arguments[n],p)
--- print("builder>",p)
+-- print("builder>",p)
f = loadstripped(p)()
else
f = function() return str end
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua
index f18c719e420..ae44269bbd3 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua
@@ -10,13 +10,14 @@ utilities = utilities or {}
utilities.tables = utilities.tables or { }
local tables = utilities.tables
-local format, gmatch, gsub = string.format, string.gmatch, string.gsub
+local format, gmatch, gsub, sub = string.format, string.gmatch, string.gsub, string.sub
local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
local type, next, rawset, tonumber, tostring, load, select = type, next, rawset, tonumber, tostring, load, select
local lpegmatch, P, Cs, Cc = lpeg.match, lpeg.P, lpeg.Cs, lpeg.Cc
local sortedkeys, sortedpairs = table.sortedkeys, table.sortedpairs
local formatters = string.formatters
+local utftoeight = utf.toeight
local splitter = lpeg.tsplitat(".")
@@ -300,11 +301,20 @@ local f_hashed_number = formatters["[%q]=%s,"]
local f_hashed_boolean = formatters["[%q]=%l,"]
local f_hashed_table = formatters["[%q]="]
-local f_indexed_string = formatters["%q,"]
-local f_indexed_number = formatters["%s,"]
-local f_indexed_boolean = formatters["%l,"]
+local f_indexed_string = formatters["[%s]=%q,"]
+local f_indexed_number = formatters["[%s]=%s,"]
+local f_indexed_boolean = formatters["[%s]=%l,"]
+local f_indexed_table = formatters["[%s]="]
-function table.fastserialize(t,prefix) -- so prefix should contain the = | not sorted
+local f_ordered_string = formatters["%q,"]
+local f_ordered_number = formatters["%s,"]
+local f_ordered_boolean = formatters["%l,"]
+
+function table.fastserialize(t,prefix)
+
+ -- prefix should contain the =
+ -- not sorted
+ -- only number and string indices (currently)
local r = { prefix or "return" }
local m = 1
@@ -314,21 +324,37 @@ function table.fastserialize(t,prefix) -- so prefix should contain the = | not s
m = m + 1
r[m] = "{"
if n > 0 then
- for i=1,n do
+ for i=0,n do
local v = t[i]
local tv = type(v)
if tv == "string" then
- m = m + 1 r[m] = f_indexed_string(v)
+ m = m + 1 r[m] = f_ordered_string(v)
elseif tv == "number" then
- m = m + 1 r[m] = f_indexed_number(v)
+ m = m + 1 r[m] = f_ordered_number(v)
elseif tv == "table" then
fastserialize(v)
elseif tv == "boolean" then
- m = m + 1 r[m] = f_indexed_boolean(v)
+ m = m + 1 r[m] = f_ordered_boolean(v)
end
end
- else
- for k, v in next, t do
+ end
+ for k, v in next, t do
+ local tk = type(k)
+ if tk == "number" then
+ if k > n or k < 0 then
+ local tv = type(v)
+ if tv == "string" then
+ m = m + 1 r[m] = f_indexed_string(k,v)
+ elseif tv == "number" then
+ m = m + 1 r[m] = f_indexed_number(k,v)
+ elseif tv == "table" then
+ m = m + 1 r[m] = f_indexed_table(k)
+ fastserialize(v)
+ elseif tv == "boolean" then
+ m = m + 1 r[m] = f_indexed_boolean(k,v)
+ end
+ end
+ else
local tv = type(v)
if tv == "string" then
m = m + 1 r[m] = f_hashed_string(k,v)
@@ -375,6 +401,7 @@ function table.load(filename,loader)
if filename then
local t = (loader or io.loaddata)(filename)
if t and t ~= "" then
+ local t = utftoeight(t)
t = load(t)
if type(t) == "function" then
t = t()
@@ -518,6 +545,10 @@ local spaces = utilities.strings.newrepeater(" ")
local serialize = table.serialize -- the extensive one, the one we started with
+-- there is still room for optimization: index run, key run, but i need to check with the
+-- latest lua for the value of #n (with holes) .. anyway for tracing purposes we want
+-- indices / keys being sorted, so it will never be real fast
+
function table.serialize(root,name,specification)
if type(specification) == "table" then
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua
index e0c405a42de..67d05822116 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua
@@ -17,8 +17,8 @@ local trace_template = false trackers.register("templates.trace",function(v) t
local report_template = logs.reporter("template")
local tostring = tostring
-local format, sub = string.format, string.sub
-local P, C, Cs, Carg, lpegmatch, lpegpatterns = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match, lpeg.patterns
+local format, sub, byte = string.format, string.sub, string.byte
+local P, C, R, Cs, Cc, Carg, lpegmatch, lpegpatterns = lpeg.P, lpeg.C, lpeg.R, lpeg.Cs, lpeg.Cc, lpeg.Carg, lpeg.match, lpeg.patterns
-- todo: make installable template.new
@@ -71,7 +71,7 @@ lpegpatterns.sqlquoted = sqlquoted
-- }
--
-- slightly faster:
---
+
-- local luaescape = Cs ((
-- P('"' ) / [[\"]] +
-- P('\\') / [[\\]] +
@@ -81,11 +81,11 @@ lpegpatterns.sqlquoted = sqlquoted
-- P(1)
-- )^0)
--- local xmlescape = lpegpatterns.xmlescape
--- local texescape = lpegpatterns.texescape
--- local luaescape = lpegpatterns.luaescape
--- local sqlquoted = lpegpatterns.sqlquoted
--- local luaquoted = lpegpatterns.luaquoted
+----- xmlescape = lpegpatterns.xmlescape
+----- texescape = lpegpatterns.texescape
+local luaescape = lpegpatterns.luaescape
+----- sqlquoted = lpegpatterns.sqlquoted
+----- luaquoted = lpegpatterns.luaquoted
local escapers = {
lua = function(s)
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua
index 9240f1b1c79..150333f68b2 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua
@@ -22,8 +22,8 @@ lualibs = lualibs or { }
lualibs.module_info = {
name = "lualibs",
- version = 2.00,
- date = "2013/07/23",
+ version = 2.10,
+ date = "2013/11/03",
description = "ConTeXt Lua standard libraries.",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
copyright = "PRAGMA ADE / ConTeXt Development Team",
@@ -34,9 +34,23 @@ lualibs.module_info = {
config = config or { }
config.lualibs = config.lualibs or { }
-lualibs.prefer_merged = config.lualibs.prefer_merged or true
-lualibs.load_extended = config.lualibs.load_extended or true
-config.lualibs.verbose = config.lualibs.verbose or false
+if config.lualibs.prefer_merged ~= nil then
+ lualibs.prefer_merged = config.lualibs.prefer_merged
+else
+ lualibs.prefer_merged = true
+end
+
+if config.lualibs.load_extended ~= nil then
+ lualibs.load_extended = config.lualibs.load_extended
+else
+ lualibs.load_extended = true
+end
+
+if config.lualibs.verbose ~= nil then
+ config.lualibs.verbose = config.lualibs.verbose
+else
+ config.lualibs.verbose = false
+end
local dofile = dofile