summaryrefslogtreecommitdiff
path: root/luaotfload-fonts.lua
diff options
context:
space:
mode:
authoreroux <elie.roux@telecom-bretagne.eu>2010-02-26 10:12:19 +0100
committereroux <elie.roux@telecom-bretagne.eu>2010-02-26 10:14:29 +0100
commite927dc3d77cd4317cefb07a6831abe1654734e42 (patch)
treee87f25f9de13d371cb56b8c83ad78a7846ebb67b /luaotfload-fonts.lua
parentb8795802b43e389edf8d99294258c2d56bd83af2 (diff)
downloadluaotfload-e927dc3d77cd4317cefb07a6831abe1654734e42.tar.gz
A safer path normalization
Diffstat (limited to 'luaotfload-fonts.lua')
-rw-r--r--luaotfload-fonts.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/luaotfload-fonts.lua b/luaotfload-fonts.lua
index 36aa1a4..8e4b81b 100644
--- a/luaotfload-fonts.lua
+++ b/luaotfload-fonts.lua
@@ -181,14 +181,18 @@ else
end
log(2, "Detecting system: %s", system)
--- path must be normalized under cygwin
+-- path normalization:
+-- - a\b\c -> a/b/c
+-- - a/../b -> b
+-- - /cygdrive/a/b -> a:/b
local function path_normalize(path)
+ if system ~= 'unix' then
+ path = path:gsub('\\', '/')
+ path = path:lower()
+ end
+ path = file.collapse_path(path)
if system == "cygwin" then
- local res = string.lower(io.popen(string.format("cygpath.exe --mixed %s", path)):read("*all"))
- -- a very strange thing: spaces are replaced by \n and there is a trailing \n at the end
- res = res:gsub("\n$", '')
- res = res:gsub("\n", ' ')
- return res
+ path = path:gsub('^/cygdrive/(%a)/', '%1:/')
end
return path
end
@@ -223,6 +227,7 @@ local function scan_dir(dirname, names, recursive, texmf, scanned_fonts)
end
log(2, "%d fonts found in '%s'", nbfound, dirname)
for _,fnt in ipairs(list) do
+ fnt = path_normalize(fnt)
if not scanned_fonts[fnt] then
load_font(fnt, names, texmf)
scanned_fonts[fnt] = true
@@ -308,6 +313,7 @@ local function generate()
version = luaotfload.fonts.version,
}
local savepath = luaotfload.fonts.directory
+ savepath = path_normalize(savepath)
if not lfs.isdir(savepath) then
log(1, "Creating directory %s", savepath)
lfs.mkdir(savepath)
@@ -316,7 +322,7 @@ local function generate()
os.exit(1)
end
end
- savepath = savepath .. luaotfload.fonts.basename
+ savepath = savepath .. '/' .. luaotfload.fonts.basename
local fh = io.open(savepath, 'wb')
if not fh then
texio.write_nl(string.format("Error: cannot write file '%s', exiting.\n", savepath))
@@ -336,3 +342,6 @@ end
luaotfload.fonts.scan = scan_dir
luaotfload.fonts.generate = generate
+if arg[0] == "luaotfload-fonts.lua" then
+ generate()
+end