summaryrefslogtreecommitdiff
path: root/tex/context/base/l-file.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-04-16 20:20:28 +0300
committerMarius <mariausol@gmail.com>2013-04-16 20:20:28 +0300
commit2bce12e0c387ba3a0e084bf0c44c23af1f93642e (patch)
treefcf93a966bbc848411295c490198b61ac17849be /tex/context/base/l-file.lua
parent7d59d03f80badf3733d3230b9976b66c19e92919 (diff)
downloadcontext-2bce12e0c387ba3a0e084bf0c44c23af1f93642e.tar.gz
beta 2013.04.16 18:49
Diffstat (limited to 'tex/context/base/l-file.lua')
-rw-r--r--tex/context/base/l-file.lua18
1 files changed, 12 insertions, 6 deletions
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua
index af86f9397..29416caf0 100644
--- a/tex/context/base/l-file.lua
+++ b/tex/context/base/l-file.lua
@@ -62,7 +62,7 @@ elseif not lfs.isfile then
end
local insert, concat = table.insert, table.concat
-local match = string.match
+local match, find = string.match, string.find
local lpegmatch = lpeg.match
local getcurrentdir, attributes = lfs.currentdir, lfs.attributes
local checkedsplit = string.checkedsplit
@@ -410,11 +410,11 @@ local untouched = periods + (1-period)^1 * P(-1)
local splitstarter = (Cs(drivespec * (bwslash/"/" + fwslash)^0) + Cc(false)) * Ct(lpeg.splitat(S("/\\")^1))
local absolute = fwslash
-function file.collapsepath(str,anchor)
+function file.collapsepath(str,anchor) -- anchor: false|nil, true, "."
if not str then
return
end
- if anchor and not lpegmatch(anchors,str) then
+ if anchor == true and not lpegmatch(anchors,str) then
str = getcurrentdir() .. "/" .. str
end
if str == "" or str =="." then
@@ -455,12 +455,17 @@ function file.collapsepath(str,anchor)
elseif lpegmatch(absolute,str) then
return "/" .. concat(newelements,'/')
else
- return concat(newelements, '/')
+ newelements = concat(newelements, '/')
+ if anchor == "." and find(str,"^%./") then
+ return "./" .. newelements
+ else
+ return newelements
+ end
end
end
--- local function test(str)
--- print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
+-- local function test(str,...)
+-- print(string.format("%-20s %-15s %-30s %-20s",str,file.collapsepath(str),file.collapsepath(str,true),file.collapsepath(str,".")))
-- end
-- test("a/b.c/d") test("b.c/d") test("b.c/..")
-- test("/") test("c:/..") test("sys://..")
@@ -468,6 +473,7 @@ end
-- test("a") test("./a") test("/a") test("a/../..")
-- test("a/./b/..") test("a/aa/../b/bb") test("a/.././././b/..") test("a/./././b/..")
-- test("a/b/c/../..") test("./a/b/c/../..") test("a/b/c/../..")
+-- test("./a")
local validchars = R("az","09","AZ","--","..")
local pattern_a = lpeg.replacer(1-validchars)