diff options
Diffstat (limited to 'tex/context/base/l-file.lua')
-rw-r--r-- | tex/context/base/l-file.lua | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua index a28991339..37de64ba1 100644 --- a/tex/context/base/l-file.lua +++ b/tex/context/base/l-file.lua @@ -33,12 +33,8 @@ function file.dirname(name,default) return match(name,"^(.+)[/\\].-$") or (default or "") end ---~ function file.basename(name) ---~ return match(name,"^.+[/\\](.-)$") or name ---~ end - function file.basename(name) - return match(name,"^.*[/\\](.-)$") or name + return match(name,"^.+[/\\](.-)$") or name end function file.nameonly(name) @@ -84,39 +80,27 @@ end file.is_readable = file.isreadable file.is_writable = file.iswritable -local checkedsplit = string.checkedsplit +-- todo: lpeg -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) +--~ 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 +--~ end +--~ return t +--~ end + +local checkedsplit = string.checkedsplit 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 checkedsplit(str,separator or io.pathseparator) 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 |