summaryrefslogtreecommitdiff
path: root/Master/bin
diff options
context:
space:
mode:
Diffstat (limited to 'Master/bin')
-rwxr-xr-xMaster/bin/win32/luatools.lua54
-rwxr-xr-xMaster/bin/win32/mtxrun.lua54
2 files changed, 84 insertions, 24 deletions
diff --git a/Master/bin/win32/luatools.lua b/Master/bin/win32/luatools.lua
index 581ba70c86a..ac1e38f4c6d 100755
--- a/Master/bin/win32/luatools.lua
+++ b/Master/bin/win32/luatools.lua
@@ -2214,22 +2214,52 @@ end
-- we can hash them weakly
+
+local insert = table.insert
+
function file.collapse_path(str)
+ if str == "" or str =="." then
+ return "."
+ elseif find(str,"^%.%.") then
+ return str
+ elseif not find(str,"%.") then
+ return str
+ end
+ str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified
str = gsub(str,"\\","/")
- if find(str,"/") then
- str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified
- str = gsub(str,"/%./","/")
- local n, m = 1, 1
- while n > 0 or m > 0 do
- str, n = gsub(str,"[^/%.]+/%.%.$","")
- str, m = gsub(str,"[^/%.]+/%.%./","")
+ local oldelements = checkedsplit(str,"/")
+ local newelements = { }
+ local i = #oldelements
+ while i > 0 do
+ local element = oldelements[i]
+ if element == '.' then
+ -- do nothing
+ elseif element == '..' then
+ local n = i -1
+ while n > 0 do
+ local element = oldelements[n]
+ if element ~= '..' and element ~= '.' then
+ oldelements[n] = '.'
+ break
+ else
+ n = n - 1
+ end
+ end
+ if n<1 then
+ insert(newelements,1,'..')
+ end
+ elseif element ~= "" then
+ insert(newelements,1,element)
end
- str = gsub(str,"([^/])/$","%1")
- -- str = gsub(str,"^%./","") -- ./xx in qualified
- str = gsub(str,"/%.$","")
+ i = i - 1
+ end
+ if #newelements == 0 then
+ return "."
+ elseif find(str,"^/") then
+ return "/" .. concat(newelements,'/')
+ else
+ return concat(newelements, '/')
end
- if str == "" then str = "." end
- return str
end
--~ print(file.collapse_path("/a"))
diff --git a/Master/bin/win32/mtxrun.lua b/Master/bin/win32/mtxrun.lua
index d6b2d13a71a..574335c58d5 100755
--- a/Master/bin/win32/mtxrun.lua
+++ b/Master/bin/win32/mtxrun.lua
@@ -2223,22 +2223,52 @@ end
-- we can hash them weakly
+
+local insert = table.insert
+
function file.collapse_path(str)
+ if str == "" or str =="." then
+ return "."
+ elseif find(str,"^%.%.") then
+ return str
+ elseif not find(str,"%.") then
+ return str
+ end
+ str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified
str = gsub(str,"\\","/")
- if find(str,"/") then
- str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified
- str = gsub(str,"/%./","/")
- local n, m = 1, 1
- while n > 0 or m > 0 do
- str, n = gsub(str,"[^/%.]+/%.%.$","")
- str, m = gsub(str,"[^/%.]+/%.%./","")
+ local oldelements = checkedsplit(str,"/")
+ local newelements = { }
+ local i = #oldelements
+ while i > 0 do
+ local element = oldelements[i]
+ if element == '.' then
+ -- do nothing
+ elseif element == '..' then
+ local n = i -1
+ while n > 0 do
+ local element = oldelements[n]
+ if element ~= '..' and element ~= '.' then
+ oldelements[n] = '.'
+ break
+ else
+ n = n - 1
+ end
+ end
+ if n<1 then
+ insert(newelements,1,'..')
+ end
+ elseif element ~= "" then
+ insert(newelements,1,element)
end
- str = gsub(str,"([^/])/$","%1")
- -- str = gsub(str,"^%./","") -- ./xx in qualified
- str = gsub(str,"/%.$","")
+ i = i - 1
+ end
+ if #newelements == 0 then
+ return "."
+ elseif find(str,"^/") then
+ return "/" .. concat(newelements,'/')
+ else
+ return concat(newelements, '/')
end
- if str == "" then str = "." end
- return str
end
--~ print(file.collapse_path("/a"))