From dcdaf3c02b6c05569af874841585ebe31561285f Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 19 Nov 2009 23:11:00 +0100 Subject: beta 2009.11.19 23:11 --- tex/context/base/cont-new.tex | 2 +- tex/context/base/context.tex | 2 +- tex/context/base/data-lua.lua | 1 + tex/context/base/data-res.lua | 43 +++++++++-- tex/context/base/font-dum.lua | 2 +- tex/context/base/font-ini.mkiv | 4 +- tex/context/base/font-syn.lua | 32 +++++++- tex/context/base/grph-inc.lua | 9 +-- tex/context/base/grph-inc.mkiv | 2 + tex/context/base/l-file.lua | 41 ++++++++--- tex/context/base/l-lpeg.lua | 15 +++- tex/context/base/math-vfu.lua | 110 ++++++++++++++-------------- tex/context/base/spec-fdf.mkii | 3 + tex/context/base/strc-syn.lua | 2 +- tex/context/base/strc-syn.mkiv | 6 +- tex/generic/context/luatex-fonts-merged.lua | 58 +++++++++++---- 16 files changed, 226 insertions(+), 106 deletions(-) (limited to 'tex') diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index b6b633877..df7e636ce 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2009.11.18 21:51} +\newcontextversion{2009.11.19 23:11} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex index 76233c43d..4df95ab04 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2009.11.18 21:51} +\edef\contextversion{2009.11.19 23:11} %D For those who want to use this: diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua index 26e6c830d..d7f6fdcf5 100644 --- a/tex/context/base/data-lua.lua +++ b/tex/context/base/data-lua.lua @@ -18,6 +18,7 @@ local libformats = { 'luatexlibs', 'tex', 'texmfscripts', 'othertextfiles' } local libpaths = file.split_path(package.path) package.loaders[2] = function(name) -- was [#package.loaders+1] +--~ package.loaders[#package.loaders+1] = function(name) -- was for i=1,#libformats do local format = libformats[i] local resolved = resolvers.find_file(name,format) or "" diff --git a/tex/context/base/data-res.lua b/tex/context/base/data-res.lua index 9964af421..a2bace306 100644 --- a/tex/context/base/data-res.lua +++ b/tex/context/base/data-res.lua @@ -416,6 +416,11 @@ local function splitpathexpr(str, t, validate) return t end +local function validate(s) + s = collapse_path(s) + return s ~= "" and not find(s,dummy_path_expr) and s +end + local function expanded_path_from_list(pathlist) -- maybe not a list, just a path -- a previous version fed back into pathlist local newlist, ok = { }, false @@ -426,10 +431,6 @@ local function expanded_path_from_list(pathlist) -- maybe not a list, just a pat end end if ok then - local function validate(s) - s = collapse_path(s) - return s ~= "" and not find(s,dummy_path_expr) and s - end for k=1,#pathlist do splitpathexpr(pathlist[k],newlist,validate) end @@ -872,13 +873,43 @@ function resolvers.joinconfig() end end end -function resolvers.split_path(str) + +local winpath = lpeg.P("!!")^-1 * (lpeg.R("AZ","az") * lpeg.P(":") * lpeg.P("/")) +local separator = lpeg.P(":") + lpeg.P(";") +local rest = (1-separator)^1 +local somepath = winpath * rest + rest +local splitter = lpeg.Ct(lpeg.C(somepath) * (separator^1 + lpeg.C(somepath))^0) + +local function split_kpse_path(str) + str = gsub(str,"\\","/") + return splitter:match(str) or { } +end + +local cache = { } -- we assume stable strings + +function resolvers.split_path(str) -- overkill but i need to check this module anyway if type(str) == 'table' then return str else - return file.split_path(str) + local s = cache[str] + if s then + return s -- happens seldom + else + s = { } + end + local t = { } + splitpathexpr(str,t) + for _, p in ipairs(t) do + for _, pp in ipairs(split_kpse_path(p)) do + s[#s+1] = pp + end + end + cache[str] = s + return s + --~ return file.split_path(str) end end + function resolvers.join_path(str) if type(str) == 'table' then return file.join_path(str) diff --git a/tex/context/base/font-dum.lua b/tex/context/base/font-dum.lua index d6fee5598..e13f8a255 100644 --- a/tex/context/base/font-dum.lua +++ b/tex/context/base/font-dum.lua @@ -70,7 +70,7 @@ function fonts.names.resolve(name,sub) end if type(data) == "table" and data.version == fonts.names.version then local condensed = string.gsub(string.lower(name),"[^%a%d]","") - local found = data.mapping and data.mapping[condensed] + local found = data.mappings and data.mappings[condensed] if found then local fontname, filename, subfont = found[1], found[2], found[3] if subfont then diff --git a/tex/context/base/font-ini.mkiv b/tex/context/base/font-ini.mkiv index e36485319..eca6e5679 100644 --- a/tex/context/base/font-ini.mkiv +++ b/tex/context/base/font-ini.mkiv @@ -4014,9 +4014,9 @@ %D %D \starttyping %D \def\TestLookup#1% -%D {pattern: #1, found: \dolookupnoffound +%D {\dolookupfontbyspec{#1} +%D pattern: #1, found: \dolookupnoffound %D \blank -%D \dolookupfontbyspec{#1} %D \dorecurse {\dolookupnoffound} {% %D \recurselevel:~\dolookupgetkeyofindex{fontname}{\recurselevel}\quad %D }% diff --git a/tex/context/base/font-syn.lua b/tex/context/base/font-syn.lua index 0b74cc73c..ec700f9de 100644 --- a/tex/context/base/font-syn.lua +++ b/tex/context/base/font-syn.lua @@ -33,7 +33,7 @@ fonts.names.data = fonts.names.data or { } local names = fonts.names local filters = fonts.names.filters -names.version = 1.100 +names.version = 1.101 names.basename = "names" names.saved = false names.loaded = false @@ -48,6 +48,8 @@ names.cache = containers.define("fonts","data",names.version,true) local P, C, Cc, Cs, Carg = lpeg.P, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Carg +-- what to do with 'thin' + local weights = Cs ( -- not extra P("demibold") + P("semibold") @@ -289,7 +291,8 @@ local function walk_tree(pathlist,suffix,identify) local pattern = path .. "**." .. suffix -- ** forces recurse logs.report("fontnames", "globbing path %s",pattern) local t = dir.glob(pattern) - for _, completename in pairs(t) do -- ipairs + sort(t,sorter) + for _, completename in ipairs(t) do -- ipairs identify(completename,file.basename(completename),suffix,completename) end end @@ -355,6 +358,9 @@ local function check_name(data,result,filename,suffix,subfont) weight = weight, style = style, width = width, + minsize = result.design_range_bottom or 0, + maxsize = result.design_range_top or 0, + designsize = result.design_size or 0, } local family = families[familyname] if not family then @@ -418,6 +424,7 @@ local function collecthashes() local specifications = data.specifications local nofmappings, noffallbacks = 0, 0 if specifications then + -- maybe multiple passes for index=1,#specifications do local s = specifications[index] local format, fullname, fontname, familyname, weight, subfamily = s.format, s.fullname, s.fontname, s.familyname, s.weight, s.subfamily @@ -440,7 +447,7 @@ local function collecthashes() ff[extraname], noffallbacks = index, noffallbacks + 1 end end - if familyname and subfamily then + if familyname then if not mf[familyname] and not ff[familyname] then ff[familyname], noffallbacks = index, noffallbacks + 1 end @@ -717,7 +724,7 @@ local function list_them(mapping,sorted,pattern,t,all) else for k=1,#sorted do local v = sorted[k] - if find(v,pattern) then + if not t[v] and find(v,pattern) then t[v] = mapping[v] if not all then return @@ -1152,6 +1159,23 @@ function names.resolvespec(askedname,sub) end end +function names.collectfiles(askedname,reload) -- no all + if askedname and askedname ~= "" and names.enabled then + askedname = lower(askedname) -- or cleanname + names.load(reload) + local list = { } + local basename = file.basename + local specifications = names.data.specifications + for i=1,#specifications do + local s = specifications[i] + if find(lower(basename(s.filename)),askedname) then + list[#list+1] = s + end + end + return list + end +end + --[[ldx--

Fallbacks, not permanent but a transition thing.

--ldx]]-- diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua index 44447a7ad..ff8a78f0f 100644 --- a/tex/context/base/grph-inc.lua +++ b/tex/context/base/grph-inc.lua @@ -293,7 +293,6 @@ do end -- maybe move texsprint to tex function figures.get(category,tag,default) ---~ print(table.serialize(figuredata)) local value = figuredata[category] value = value and value[tag] if not value or value == "" or value == true then @@ -597,14 +596,14 @@ function figures.done(data) return data end -function figures.dummy(data) -- fails +function figures.dummy(data) --~ data = data or figures.current() --~ local dr, du, ds = data.request, data.used, data.status --~ local r = node.new("rule") --~ r.width = du.width or figures.defaultwidth --~ r.height = du.height or figures.defaultheight --~ r.depth = du.depth or figures.defaultdepth ---~ tex.box[figures.boxnumber] = node.write(r) +--~ tex.box[figures.boxnumber] = node.hpack(node.write(r)) texsprint(ctxcatcodes,"\\emptyfoundexternalfigure") end @@ -669,10 +668,6 @@ function figures.includers.generic(data) local n = figures.boxnumber tex.box[n] = node.hpack(img.node(figure)) -- tex.box[n] = img.node(figure) -- img.write(figure) -- assigning img.node directly no longer valid ---~ local inode = img.node(figure) ---~ print(table.serialize(nodes.totable(inode))) ---~ tex.box[n] = inode ---~ print(table.serialize(nodes.totable(tex.box[n]))) tex.wd[n], tex.ht[n], tex.dp[n] = figure.width, figure.height, 0 -- new, hm, tricky, we need to do that in tex (yet) ds.objectnumber = figure.objnum texsprint(ctxcatcodes,"\\relocateexternalfigure") diff --git a/tex/context/base/grph-inc.mkiv b/tex/context/base/grph-inc.mkiv index c07e0d108..d18c72e06 100644 --- a/tex/context/base/grph-inc.mkiv +++ b/tex/context/base/grph-inc.mkiv @@ -246,7 +246,9 @@ \ifconditional\testexternalfigureonly \ifcase\figurestatus \else \ctxlua{figures.check()}% + \ctxlua{figures.dummy()}% \ctxlua{figures.scale()}% + \ctxlua{figures.done()}% \fi \signalexternalfigure \else diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua index 955b6cc36..a28991339 100644 --- a/tex/context/base/l-file.lua +++ b/tex/context/base/l-file.lua @@ -84,20 +84,39 @@ end file.is_readable = file.isreadable file.is_writable = file.iswritable --- todo: lpeg - -function file.split_path(str) - local t = { } - str = gsub(str,"\\", "/") - str = gsub(str,"(%a):([;/])", "%1\001%2") - for name in gmatch(str,"([^;:]+)") do - if name ~= "" then - t[#t+1] = gsub(name,"\001",":") - end +local checkedsplit = string.checkedsplit + +local winpath = (lpeg.R("AZ","az") * lpeg.P(":") * lpeg.P("/")) +local separator = lpeg.P(":") + lpeg.P(";") +local rest = (1-separator)^1 +local somepath = winpath * rest + rest +local splitter = lpeg.Ct(lpeg.C(somepath) * (separator^1 + lpeg.C(somepath))^0) + +function file.split_path(str,separator) + str = gsub(str,"\\","/") + if separator then + return checkedsplit(str,separator) or { } + else + return splitter:match(str) or { } end - return t end +-- special one for private usage + +--~ local winpath = lpeg.P("!!")^-1 * winpath +--~ local splitter= lpeg.Ct(lpeg.C(somepath) * (separator^1 + lpeg.C(somepath))^0) + +--~ function file.split_kpse_path(str) +--~ str = gsub(str,"\\","/") +--~ return splitter:match(str) or { } +--~ end + +-- str = [[/opt/texlive/2009/bin/i386-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mine/bin:/home/mine/.local/bin]] +-- +-- str = os.getenv("PATH") -- +-- str = [[/opt/texlive/2009/bin/i386-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mine/bin:/home/mine/.local/bin]] +-- str = [[c:/oeps:whatever]] + function file.join_path(tab) return concat(tab,io.pathseparator) -- can have trailing // end diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua index b2a646fcb..1318746c4 100644 --- a/tex/context/base/l-lpeg.lua +++ b/tex/context/base/l-lpeg.lua @@ -77,7 +77,7 @@ local function splitat(separator,single) separator = P(separator) if single then local other, any = C((1 - separator)^0), P(1) - splitter = other * (separator * C(any^0) + "") + splitter = other * (separator * C(any^0) + "") -- ? splitters_s[separator] = splitter else local other = C((1 - separator)^0) @@ -101,6 +101,19 @@ function string:split(separator) return c:match(self) end +local cache = { } + +function string:checkedsplit(separator) + local c = cache[separator] + if not c then + separator = P(separator) + local other = C((1 - separator)^1) + c = Ct(other * (separator^1 + other)^1) + cache[separator] = c + end + return c:match(self) +end + --~ function lpeg.L(list,pp) --~ local p = pp --~ for l=1,#list do diff --git a/tex/context/base/math-vfu.lua b/tex/context/base/math-vfu.lua index 1a8979160..e67e50457 100644 --- a/tex/context/base/math-vfu.lua +++ b/tex/context/base/math-vfu.lua @@ -764,73 +764,73 @@ fonts.enc.math["tex-mi"] = { fonts.enc.math["tex-it"] = { --- [0x00041] = 0x41, -- A +-- [0x1D434] = 0x41, -- A [0x1D6E2] = 0x41, -- Alpha --- [0x00042] = 0x42, -- B +-- [0x1D435] = 0x42, -- B [0x1D6E3] = 0x42, -- Beta --- [0x00043] = 0x43, -- C --- [0x00044] = 0x44, -- D --- [0x00045] = 0x45, -- E +-- [0x1D436] = 0x43, -- C +-- [0x1D437] = 0x44, -- D +-- [0x1D438] = 0x45, -- E [0x1D6E6] = 0x45, -- Epsilon --- [0x00046] = 0x46, -- F --- [0x00047] = 0x47, -- G --- [0x00048] = 0x48, -- H +-- [0x1D439] = 0x46, -- F +-- [0x1D43A] = 0x47, -- G +-- [0x1D43B] = 0x48, -- H [0x1D6E8] = 0x48, -- Eta --- [0x00049] = 0x49, -- I +-- [0x1D43C] = 0x49, -- I [0x1D6EA] = 0x49, -- Iota --- [0x0004A] = 0x4A, -- J --- [0x0004B] = 0x4B, -- K +-- [0x1D43D] = 0x4A, -- J +-- [0x1D43E] = 0x4B, -- K [0x1D6EB] = 0x4B, -- Kappa --- [0x0004C] = 0x4C, -- L --- [0x0004D] = 0x4D, -- M +-- [0x1D43F] = 0x4C, -- L +-- [0x1D440] = 0x4D, -- M [0x1D6ED] = 0x4D, -- Mu --- [0x0004E] = 0x4E, -- N +-- [0x1D441] = 0x4E, -- N [0x1D6EE] = 0x4E, -- Nu --- [0x0004F] = 0x4F, -- O +-- [0x1D442] = 0x4F, -- O [0x1D6F0] = 0x4F, -- Omicron --- [0x00050] = 0x50, -- P +-- [0x1D443] = 0x50, -- P [0x1D6F2] = 0x50, -- Rho --- [0x00051] = 0x51, -- Q --- [0x00052] = 0x52, -- R --- [0x00053] = 0x53, -- S --- [0x00054] = 0x54, -- T +-- [0x1D444] = 0x51, -- Q +-- [0x1D445] = 0x52, -- R +-- [0x1D446] = 0x53, -- S +-- [0x1D447] = 0x54, -- T [0x1D6F5] = 0x54, -- Tau --- [0x00055] = 0x55, -- U --- [0x00056] = 0x56, -- V --- [0x00057] = 0x57, -- W --- [0x00058] = 0x58, -- X +-- [0x1D448] = 0x55, -- U +-- [0x1D449] = 0x56, -- V +-- [0x1D44A] = 0x57, -- W +-- [0x1D44B] = 0x58, -- X [0x1D6F8] = 0x58, -- Chi --- [0x00059] = 0x59, -- Y --- [0x0005A] = 0x5A, -- Z - [0x1D6E7] = 0x5A, -- Zeta --- [0x00061] = 0x61, -- a --- [0x00062] = 0x62, -- b --- [0x00063] = 0x63, -- c --- [0x00064] = 0x64, -- d --- [0x00065] = 0x65, -- e --- [0x00066] = 0x66, -- f --- [0x00067] = 0x67, -- g --- [0x00068] = 0x68, -- h - [0x0210E] = 0x68, -- plank constant --- [0x00069] = 0x69, -- i --- [0x0006A] = 0x6A, -- j --- [0x0006B] = 0x6B, -- k --- [0x0006C] = 0x6C, -- l --- [0x0006D] = 0x6D, -- m --- [0x0006E] = 0x6E, -- n --- [0x0006F] = 0x6F, -- o +-- [0x1D44C] = 0x59, -- Y +-- [0x1D44D] = 0x5A, -- Z +-- +-- [0x1D44E] = 0x61, -- a +-- [0x1D44F] = 0x62, -- b +-- [0x1D450] = 0x63, -- c +-- [0x1D451] = 0x64, -- d +-- [0x1D452] = 0x65, -- e +-- [0x1D453] = 0x66, -- f +-- [0x1D454] = 0x67, -- g +-- [0x1D455] = 0x68, -- h + [0x0210E] = 0x68, -- Planck constant (h) +-- [0x1D456] = 0x69, -- i +-- [0x1D457] = 0x6A, -- j +-- [0x1D458] = 0x6B, -- k +-- [0x1D459] = 0x6C, -- l +-- [0x1D45A] = 0x6D, -- m +-- [0x1D45B] = 0x6E, -- n +-- [0x1D45C] = 0x6F, -- o [0x1D70A] = 0x6F, -- omicron --- [0x00070] = 0x70, -- p --- [0x00071] = 0x71, -- q --- [0x00072] = 0x72, -- r --- [0x00073] = 0x73, -- s --- [0x00074] = 0x74, -- t --- [0x00075] = 0x75, -- u --- [0x00076] = 0x76, -- v --- [0x00077] = 0x77, -- w --- [0x00078] = 0x78, -- x --- [0x00079] = 0x79, -- y --- [0x0007A] = 0x7A, -- z +-- [0x1D45D] = 0x70, -- p +-- [0x1D45E] = 0x71, -- q +-- [0x1D45F] = 0x72, -- r +-- [0x1D460] = 0x73, -- s +-- [0x1D461] = 0x74, -- t +-- [0x1D462] = 0x75, -- u +-- [0x1D463] = 0x76, -- v +-- [0x1D464] = 0x77, -- w +-- [0x1D465] = 0x78, -- x +-- [0x1D466] = 0x79, -- y +-- [0x1D467] = 0x7A, -- z } fonts.enc.math["tex-ss"] = { } @@ -1548,7 +1548,7 @@ mathematics.make_font ( "px-math", { { name = "texgyrepagella-regular.otf", features = "virtualmath", main = true }, { name = "rpxr.tfm", vector = "tex-mr" } , { name = "rpxmi.tfm", vector = "tex-mi", skewchar=0x7F }, - { name = "pxmi1.tfm", vector = "tex-it", skewchar=0x7F }, + { name = "rpxpplri.tfm", vector = "tex-it", skewchar=0x7F }, { name = "pxsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } , { name = "pxex.tfm", vector = "tex-ex", extension = true } , { name = "pxsya.tfm", vector = "tex-ma" }, diff --git a/tex/context/base/spec-fdf.mkii b/tex/context/base/spec-fdf.mkii index 509ea0596..f160be874 100644 --- a/tex/context/base/spec-fdf.mkii +++ b/tex/context/base/spec-fdf.mkii @@ -3275,6 +3275,9 @@ \doifobjectreferencefoundelse{FDF}{docuextgstates} {\doPDFgetobjectreference{FDF}{docuextgstates}\PDFobjectreference \xdef\collectedPDFresources{\collectedPDFresources/ExtGState \PDFobjectreference}}\donothing + \doifobjectreferencefoundelse{FDF}{docupatterns} + {\doPDFgetobjectreference{FDF}{docupatterns}\PDFobjectreference + \xdef\collectedPDFresources{\collectedPDFresources/Pattern \PDFobjectreference}}\donothing \doifobjectreferencefoundelse{FDF}{colorspaces} {\doPDFgetobjectreference{FDF}{colorspaces}\PDFobjectreference \xdef\collectedPDFresources{\collectedPDFresources/ColorSpace \PDFobjectreference}}\donothing diff --git a/tex/context/base/strc-syn.lua b/tex/context/base/strc-syn.lua index b410b4243..110ae7720 100644 --- a/tex/context/base/strc-syn.lua +++ b/tex/context/base/strc-syn.lua @@ -157,7 +157,7 @@ function joblists.flush(data,options) -- maybe pass the settings differently --~ texsprint(ctxcatcodes,format("\\start%ssection{%s}",kind,sublist.tag)) for d=1,#data do local entry = data[d].definition - texsprint(ctxcatcodes,format("\\%sentry{%s}{%s}{%s}",kind,d,entry.tag,entry.synonym)) + texsprint(ctxcatcodes,format("\\%sentry{%s}{%s}{%s}{%s}",kind,d,entry.tag,entry.synonym,entry.meaning or "")) end --~ texsprint(ctxcatcodes,format("\\stop%ssection",kind)) end diff --git a/tex/context/base/strc-syn.mkiv b/tex/context/base/strc-syn.mkiv index 7b3271591..17ae7934a 100644 --- a/tex/context/base/strc-syn.mkiv +++ b/tex/context/base/strc-syn.mkiv @@ -217,10 +217,10 @@ \let\startsynonymsection\gobbleoneargument \let\stopsynonymsection \relax -\unexpanded\def\synonymentry#1#2#3% +\unexpanded\def\synonymentry#1#2#3#4% % {\syndef{\dosetsynonymattributes\c!textstyle\c!textcolor#2}#3\par} % {\startsyndef{#2}#3\stopsyndef} - {\syndef{#2}#3\par} + {\syndef{#3}#4\par} \let\currentsorting\empty @@ -359,7 +359,7 @@ \let\startsortingsection\gobbleoneargument \let\stopsortingsection \relax -\def\sortingentry#1#2#3% +\def\sortingentry#1#2#3#4% #4 is meaning but empty here {\doifelsenothing{\sortingparameter\c!command} {\begingroup\dosetsortingattributes\c!style\c!color#3\endgroup\par} % todo {\sortingparameter\c!command{#1}{#2}{#3}}} diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 82fe96610..c550519be 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts.lua --- merge date : 11/18/09 21:55:28 +-- merge date : 11/19/09 23:18:54 do -- begin closure to overcome local limits and interference @@ -345,7 +345,7 @@ local function splitat(separator,single) separator = P(separator) if single then local other, any = C((1 - separator)^0), P(1) - splitter = other * (separator * C(any^0) + "") + splitter = other * (separator * C(any^0) + "") -- ? splitters_s[separator] = splitter else local other = C((1 - separator)^0) @@ -369,6 +369,19 @@ function string:split(separator) return c:match(self) end +local cache = { } + +function string:checkedsplit(separator) + local c = cache[separator] + if not c then + separator = P(separator) + local other = C((1 - separator)^1) + c = Ct(other * (separator^1 + other)^1) + cache[separator] = c + end + return c:match(self) +end + --~ function lpeg.L(list,pp) --~ local p = pp --~ for l=1,#list do @@ -1475,20 +1488,39 @@ end file.is_readable = file.isreadable file.is_writable = file.iswritable --- todo: lpeg +local checkedsplit = string.checkedsplit -function file.split_path(str) - local t = { } - str = gsub(str,"\\", "/") - str = gsub(str,"(%a):([;/])", "%1\001%2") - for name in gmatch(str,"([^;:]+)") do - if name ~= "" then - t[#t+1] = gsub(name,"\001",":") - end +local winpath = (lpeg.R("AZ","az") * lpeg.P(":") * lpeg.P("/")) +local separator = lpeg.P(":") + lpeg.P(";") +local rest = (1-separator)^1 +local somepath = winpath * rest + rest +local splitter = lpeg.Ct(lpeg.C(somepath) * (separator^1 + lpeg.C(somepath))^0) + +function file.split_path(str,separator) + str = gsub(str,"\\","/") + if separator then + return checkedsplit(str,separator) or { } + else + return splitter:match(str) or { } end - return t end +-- special one for private usage + +--~ local winpath = lpeg.P("!!")^-1 * winpath +--~ local splitter= lpeg.Ct(lpeg.C(somepath) * (separator^1 + lpeg.C(somepath))^0) + +--~ function file.split_kpse_path(str) +--~ str = gsub(str,"\\","/") +--~ return splitter:match(str) or { } +--~ end + +-- str = [[/opt/texlive/2009/bin/i386-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mine/bin:/home/mine/.local/bin]] +-- +-- str = os.getenv("PATH") -- +-- str = [[/opt/texlive/2009/bin/i386-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mine/bin:/home/mine/.local/bin]] +-- str = [[c:/oeps:whatever]] + function file.join_path(tab) return concat(tab,io.pathseparator) -- can have trailing // end @@ -11642,7 +11674,7 @@ function fonts.names.resolve(name,sub) end if type(data) == "table" and data.version == fonts.names.version then local condensed = string.gsub(string.lower(name),"[^%a%d]","") - local found = data.mapping and data.mapping[condensed] + local found = data.mappings and data.mappings[condensed] if found then local fontname, filename, subfont = found[1], found[2], found[3] if subfont then -- cgit v1.2.3