summaryrefslogtreecommitdiff
path: root/scripts/context/stubs/unix/luatools
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2009-11-19 23:11:00 +0100
committerHans Hagen <pragma@wxs.nl>2009-11-19 23:11:00 +0100
commitdcdaf3c02b6c05569af874841585ebe31561285f (patch)
treeb0a48a603b2533baf7e96ed2df1a622fa438e99f /scripts/context/stubs/unix/luatools
parentb309379ef546b7fa819f493fa3cb1dc559d4c3b8 (diff)
downloadcontext-dcdaf3c02b6c05569af874841585ebe31561285f.tar.gz
beta 2009.11.19 23:11
Diffstat (limited to 'scripts/context/stubs/unix/luatools')
-rwxr-xr-xscripts/context/stubs/unix/luatools97
1 files changed, 80 insertions, 17 deletions
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)