summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua86
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua86
-rwxr-xr-xscripts/context/stubs/unix/mtxrun86
3 files changed, 252 insertions, 6 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index af31ba8f8..3a1972640 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -3290,6 +3290,15 @@ function file.collapsepath(str,anchor)
end
end
+-- local function test(str)
+-- print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
+-- end
+-- test("a/b.c/d") test("b.c/d") test("b.c/..")
+-- test("/") test("c:/..") test("sys://..")
+-- test("") test("./") test(".") test("..") test("./..") test("../..")
+-- 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/../..")
function file.robustname(str,strict)
str = gsub(str,"[^%a%d%/%-%.\\]+","-")
@@ -3300,6 +3309,20 @@ function file.robustname(str,strict)
end
end
+-- local pattern_a = lpeg.replacer(1-R("az","09","AZ","--",".."))
+-- local pattern_a = Cs((R("az","09","AZ","--","..") + P(1)/"-")^1)
+-- local whatever = P("-")^0 / ""
+-- local pattern_b = Cs(whatever * (1 - whatever * -1)^1)
+
+-- function file.robustname(str,strict)
+-- str = lpegmatch(pattern_a,str) or str
+-- if strict then
+-- return lpegmatch(pattern_b,str) or str -- two step is cleaner (less backtracking)
+-- else
+-- return str
+-- end
+-- end
+
file.readdata = io.loaddata
file.savedata = io.savedata
@@ -3309,23 +3332,82 @@ end
-- lpeg variants, slightly faster, not always
+-- local period = P(".")
+-- local slashes = S("\\/")
+-- local noperiod = 1-period
+-- local noslashes = 1-slashes
+-- local name = noperiod^1
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * C(noperiod^1) * -1
+-- function file.suffixonly(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+-- function file.removesuffix(name)
+-- return lpegmatch(pattern,name)
+-- end
+-- local pattern = (noslashes^0 * slashes)^1 * C(noslashes^1) * -1
+-- function file.basename(name)
+-- return lpegmatch(pattern,name) or name
+-- end
+-- local pattern = Cs ((1 - slashes * noslashes^1 * -1)^1)
+-- function file.dirname(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
+-- function file.addsuffix(name, suffix)
+-- local p = lpegmatch(pattern,name)
+-- if p then
+-- return name
+-- else
+-- return name .. "." .. suffix
+-- end
+-- end
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = Cs((1-suffix)^1)
+-- function file.replacesuffix(name,suffix)
+-- if suffix and suffix ~= "" then
+-- return lpegmatch(pattern,name) .. "." .. suffix
+-- else
+-- return name
+-- end
+-- end
+-- local path = noslashes^0 * slashes^1
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = path^0 * Cs((1-suffix)^1) * suffix^0
+-- function file.nameonly(name)
+-- return lpegmatch(pattern,name) or name
+-- end
-
-
+-- local test = file.suffixonly
+-- local test = file.basename
+-- local test = file.dirname
+-- local test = file.addsuffix
+-- local test = file.replacesuffix
+-- local test = file.nameonly
+
+-- print(1,test("./a/b/c/abd.def.xxx","!!!"))
+-- print(2,test("./../b/c/abd.def.xxx","!!!"))
+-- print(3,test("a/b/c/abd.def.xxx","!!!"))
+-- print(4,test("a/b/c/def.xxx","!!!"))
+-- print(5,test("a/b/c/def","!!!"))
+-- print(6,test("def","!!!"))
+-- print(7,test("def.xxx","!!!"))
+
+-- local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
-- also rewrite previous
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index af31ba8f8..3a1972640 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -3290,6 +3290,15 @@ function file.collapsepath(str,anchor)
end
end
+-- local function test(str)
+-- print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
+-- end
+-- test("a/b.c/d") test("b.c/d") test("b.c/..")
+-- test("/") test("c:/..") test("sys://..")
+-- test("") test("./") test(".") test("..") test("./..") test("../..")
+-- 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/../..")
function file.robustname(str,strict)
str = gsub(str,"[^%a%d%/%-%.\\]+","-")
@@ -3300,6 +3309,20 @@ function file.robustname(str,strict)
end
end
+-- local pattern_a = lpeg.replacer(1-R("az","09","AZ","--",".."))
+-- local pattern_a = Cs((R("az","09","AZ","--","..") + P(1)/"-")^1)
+-- local whatever = P("-")^0 / ""
+-- local pattern_b = Cs(whatever * (1 - whatever * -1)^1)
+
+-- function file.robustname(str,strict)
+-- str = lpegmatch(pattern_a,str) or str
+-- if strict then
+-- return lpegmatch(pattern_b,str) or str -- two step is cleaner (less backtracking)
+-- else
+-- return str
+-- end
+-- end
+
file.readdata = io.loaddata
file.savedata = io.savedata
@@ -3309,23 +3332,82 @@ end
-- lpeg variants, slightly faster, not always
+-- local period = P(".")
+-- local slashes = S("\\/")
+-- local noperiod = 1-period
+-- local noslashes = 1-slashes
+-- local name = noperiod^1
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * C(noperiod^1) * -1
+-- function file.suffixonly(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+-- function file.removesuffix(name)
+-- return lpegmatch(pattern,name)
+-- end
+-- local pattern = (noslashes^0 * slashes)^1 * C(noslashes^1) * -1
+-- function file.basename(name)
+-- return lpegmatch(pattern,name) or name
+-- end
+-- local pattern = Cs ((1 - slashes * noslashes^1 * -1)^1)
+-- function file.dirname(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
+-- function file.addsuffix(name, suffix)
+-- local p = lpegmatch(pattern,name)
+-- if p then
+-- return name
+-- else
+-- return name .. "." .. suffix
+-- end
+-- end
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = Cs((1-suffix)^1)
+-- function file.replacesuffix(name,suffix)
+-- if suffix and suffix ~= "" then
+-- return lpegmatch(pattern,name) .. "." .. suffix
+-- else
+-- return name
+-- end
+-- end
+-- local path = noslashes^0 * slashes^1
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = path^0 * Cs((1-suffix)^1) * suffix^0
+-- function file.nameonly(name)
+-- return lpegmatch(pattern,name) or name
+-- end
-
-
+-- local test = file.suffixonly
+-- local test = file.basename
+-- local test = file.dirname
+-- local test = file.addsuffix
+-- local test = file.replacesuffix
+-- local test = file.nameonly
+
+-- print(1,test("./a/b/c/abd.def.xxx","!!!"))
+-- print(2,test("./../b/c/abd.def.xxx","!!!"))
+-- print(3,test("a/b/c/abd.def.xxx","!!!"))
+-- print(4,test("a/b/c/def.xxx","!!!"))
+-- print(5,test("a/b/c/def","!!!"))
+-- print(6,test("def","!!!"))
+-- print(7,test("def.xxx","!!!"))
+
+-- local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
-- also rewrite previous
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index af31ba8f8..3a1972640 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -3290,6 +3290,15 @@ function file.collapsepath(str,anchor)
end
end
+-- local function test(str)
+-- print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
+-- end
+-- test("a/b.c/d") test("b.c/d") test("b.c/..")
+-- test("/") test("c:/..") test("sys://..")
+-- test("") test("./") test(".") test("..") test("./..") test("../..")
+-- 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/../..")
function file.robustname(str,strict)
str = gsub(str,"[^%a%d%/%-%.\\]+","-")
@@ -3300,6 +3309,20 @@ function file.robustname(str,strict)
end
end
+-- local pattern_a = lpeg.replacer(1-R("az","09","AZ","--",".."))
+-- local pattern_a = Cs((R("az","09","AZ","--","..") + P(1)/"-")^1)
+-- local whatever = P("-")^0 / ""
+-- local pattern_b = Cs(whatever * (1 - whatever * -1)^1)
+
+-- function file.robustname(str,strict)
+-- str = lpegmatch(pattern_a,str) or str
+-- if strict then
+-- return lpegmatch(pattern_b,str) or str -- two step is cleaner (less backtracking)
+-- else
+-- return str
+-- end
+-- end
+
file.readdata = io.loaddata
file.savedata = io.savedata
@@ -3309,23 +3332,82 @@ end
-- lpeg variants, slightly faster, not always
+-- local period = P(".")
+-- local slashes = S("\\/")
+-- local noperiod = 1-period
+-- local noslashes = 1-slashes
+-- local name = noperiod^1
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * C(noperiod^1) * -1
+-- function file.suffixonly(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+-- function file.removesuffix(name)
+-- return lpegmatch(pattern,name)
+-- end
+-- local pattern = (noslashes^0 * slashes)^1 * C(noslashes^1) * -1
+-- function file.basename(name)
+-- return lpegmatch(pattern,name) or name
+-- end
+-- local pattern = Cs ((1 - slashes * noslashes^1 * -1)^1)
+-- function file.dirname(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
+-- function file.addsuffix(name, suffix)
+-- local p = lpegmatch(pattern,name)
+-- if p then
+-- return name
+-- else
+-- return name .. "." .. suffix
+-- end
+-- end
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = Cs((1-suffix)^1)
+-- function file.replacesuffix(name,suffix)
+-- if suffix and suffix ~= "" then
+-- return lpegmatch(pattern,name) .. "." .. suffix
+-- else
+-- return name
+-- end
+-- end
+-- local path = noslashes^0 * slashes^1
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = path^0 * Cs((1-suffix)^1) * suffix^0
+-- function file.nameonly(name)
+-- return lpegmatch(pattern,name) or name
+-- end
-
-
+-- local test = file.suffixonly
+-- local test = file.basename
+-- local test = file.dirname
+-- local test = file.addsuffix
+-- local test = file.replacesuffix
+-- local test = file.nameonly
+
+-- print(1,test("./a/b/c/abd.def.xxx","!!!"))
+-- print(2,test("./../b/c/abd.def.xxx","!!!"))
+-- print(3,test("a/b/c/abd.def.xxx","!!!"))
+-- print(4,test("a/b/c/def.xxx","!!!"))
+-- print(5,test("a/b/c/def","!!!"))
+-- print(6,test("def","!!!"))
+-- print(7,test("def.xxx","!!!"))
+
+-- local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
-- also rewrite previous