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 --- scripts/context/lua/luatools.lua | 97 ++++++++++++++++++++++++++------ scripts/context/lua/mtx-fonts.lua | 61 +++++++++++++------- scripts/context/lua/mtx-texworks.lua | 4 +- scripts/context/lua/mtxrun.lua | 97 ++++++++++++++++++++++++++------ scripts/context/stubs/mswin/luatools.lua | 97 ++++++++++++++++++++++++++------ scripts/context/stubs/mswin/mtxrun.lua | 97 ++++++++++++++++++++++++++------ scripts/context/stubs/unix/luatools | 97 ++++++++++++++++++++++++++------ scripts/context/stubs/unix/mtxrun | 97 ++++++++++++++++++++++++++------ 8 files changed, 524 insertions(+), 123 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua index abd80b8b4..a96474620 100644 --- a/scripts/context/lua/luatools.lua +++ b/scripts/context/lua/luatools.lua @@ -379,7 +379,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) @@ -403,6 +403,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 @@ -1911,20 +1924,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 @@ -4846,6 +4878,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 @@ -4856,10 +4893,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 @@ -5302,13 +5335,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/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua index 67c48d0a8..4d3e52382 100644 --- a/scripts/context/lua/mtx-fonts.lua +++ b/scripts/context/lua/mtx-fonts.lua @@ -15,14 +15,10 @@ dofile(resolvers.find_file("font-mis.lua","tex")) scripts = scripts or { } scripts.fonts = scripts.fonts or { } -function scripts.fonts.reload(verbose) - fonts.names.load(true,verbose) -end - -function scripts.fonts.names(name) +function fonts.names.simple() local simpleversion = 1.001 local simplelist = { "ttf", "otf", "ttc", "dfont" } - name = name or "luatex-fonts-names.lua" + local name = "luatex-fonts-names.lua" fonts.names.filters.list = simplelist fonts.names.version = simpleversion -- this number is the same as in font-dum.lua logs.report("fontnames","generating font database for 'luatex-fonts' version %s",fonts.names.version) @@ -53,6 +49,14 @@ function scripts.fonts.names(name) end end +function scripts.fonts.reload() + if environment.argument("simple") then + fonts.names.simple() + else + fonts.names.load(true) + end +end + local function showfeatures(tag,specification) logs.simple("mapping : %s",tag) logs.simple("fontname: %s",specification.fontname) @@ -213,6 +217,18 @@ function scripts.fonts.list() else logs.report("fontnames","not supported: --list --spec ",name) end + elseif environment.argument("file") then + if pattern then + --~ mtxrun --script font --list --file --pattern=*somename* + list_specifications(fonts.names.collectfiles(make_pattern(pattern),reload,all)) + elseif filter then + logs.report("fontnames","not supported: --list --spec",name) + elseif given then + --~ mtxrun --script font --list --file somename + list_specifications(fonts.names.collectfiles(given,reload,all)) + else + logs.report("fontnames","not supported: --list --file ",name) + end elseif pattern then --~ mtxrun --script font --list --pattern=*somename* list_matches(fonts.names.list(make_pattern(pattern),reload,all)) @@ -268,21 +284,22 @@ end logs.extendbanner("Font Tools 0.21",true) messages.help = [[ ---reload generate new font database --save save open type font in raw table ---names generate 'luatex-fonts-names.lua' (not for context!) ---list list installed fonts (show info) ---name filter by name ---spec filter by spec +--reload generate new font database +--reload --simple generate 'luatex-fonts-names.lua' (not for context!) + +--list --name list installed fonts, filter by name [--pattern] +--list --spec list installed fonts, filter by spec [--filter] +--list --file list installed fonts, filter by file [--pattern] --pattern=str filter files using pattern --filter=list key-value pairs ---all provide alternatives +--all show all found instances --info give more details --track=list enable trackers -examples: +examples of searches: mtxrun --script font --list somename (== --pattern=*somename*) @@ -294,20 +311,26 @@ mtxrun --script font --list --spec somename-bold-italic mtxrun --script font --list --spec --pattern=*somename* mtxrun --script font --list --spec --filter="fontname=somename" mtxrun --script font --list --spec --filter="familyname=somename,weight=bold,style=italic,width=condensed" + +mtxrun --script font --list --file somename +mtxrun --script font --list --file --pattern=*somename* ]] local track = environment.argument("track") if track then trackers.enable(track) end -if environment.argument("reload") then - scripts.fonts.reload(true) -elseif environment.argument("names") then - scripts.fonts.names() +if environment.argument("names") then + environment.setargument("reload",true) + environment.setargument("simple",true) +end + +if environment.argument("list") then + scripts.fonts.list() +elseif environment.argument("reload") then + scripts.fonts.reload() elseif environment.argument("save") then scripts.fonts.save() -elseif environment.argument("list") then - scripts.fonts.list() else logs.help(messages.help) end diff --git a/scripts/context/lua/mtx-texworks.lua b/scripts/context/lua/mtx-texworks.lua index f525d5336..77d257480 100644 --- a/scripts/context/lua/mtx-texworks.lua +++ b/scripts/context/lua/mtx-texworks.lua @@ -20,11 +20,11 @@ local texworkspaths = { } local texworkssignal = "texworks-context.rme" -local texworkininame = "TeXworks.ini" +local texworkininame = "texworks.ini" function scripts.texworks.start(indeed) local is_mswin = os.platform == "windows" - local workname = (is_mswin and "texworks.exe") or "TeXworks" + local workname = (is_mswin and "texworks.exe") or "texworks" local fullname = nil local binpaths = file.split_path(os.getenv("PATH")) or file.split_path(os.getenv("path")) local datapath = resolvers.find_file(texworkssignal,"other text files") or "" diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 0d3f08025..4ed4dbdd1 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -388,7 +388,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) @@ -412,6 +412,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 @@ -1920,20 +1933,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 @@ -7574,6 +7606,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 @@ -7584,10 +7621,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 @@ -8030,13 +8063,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/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua index abd80b8b4..a96474620 100644 --- a/scripts/context/stubs/mswin/luatools.lua +++ b/scripts/context/stubs/mswin/luatools.lua @@ -379,7 +379,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) @@ -403,6 +403,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 @@ -1911,20 +1924,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 @@ -4846,6 +4878,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 @@ -4856,10 +4893,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 @@ -5302,13 +5335,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/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 0d3f08025..4ed4dbdd1 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -388,7 +388,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) @@ -412,6 +412,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 @@ -1920,20 +1933,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 @@ -7574,6 +7606,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 @@ -7584,10 +7621,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 @@ -8030,13 +8063,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/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools index abd80b8b4..a96474620 100755 --- a/scripts/context/stubs/unix/luatools +++ b/scripts/context/stubs/unix/luatools @@ -379,7 +379,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) @@ -403,6 +403,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 @@ -1911,20 +1924,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 @@ -4846,6 +4878,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 @@ -4856,10 +4893,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 @@ -5302,13 +5335,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/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 0d3f08025..4ed4dbdd1 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -388,7 +388,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) @@ -412,6 +412,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 @@ -1920,20 +1933,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 @@ -7574,6 +7606,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 @@ -7584,10 +7621,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 @@ -8030,13 +8063,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) -- cgit v1.2.3