summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-09 21:09:51 +0000
committerKarl Berry <karl@freefriends.org>2018-04-09 21:09:51 +0000
commit4d2d4764dde3caf40817a1ef84719e1319b10d2f (patch)
tree096967b6679e1e110b75e42e1747936323508fc4 /Master/texmf-dist/scripts/make4ht/make4ht-config.lua
parent1e0147a88c7bc3a3e2986968f697ef5fbcef2bcb (diff)
make4ht (9apr18)
git-svn-id: svn://tug.org/texlive/trunk@47398 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/make4ht-config.lua')
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht-config.lua92
1 files changed, 92 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht-config.lua b/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
new file mode 100755
index 00000000000..bd83632a574
--- /dev/null
+++ b/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
@@ -0,0 +1,92 @@
+local m = {}
+
+local mkutils = require "mkutils"
+
+local file_exists = mkutils.file_exists
+-- function file_exists(name)
+-- local f=io.open(name,"r")
+-- if f~=nil then io.close(f) return true else return false end
+-- end
+
+
+local make_name = function(name)
+ return table.concat(name, "/")
+ -- return name:gsub("//","/")
+end
+
+-- find the config file in XDG_CONFIG_HOME or in the HOME directry
+-- the XDG tree is looked up first, the $HOME is used only when it cannot be
+-- find in the former
+local xdg_config = function(filename, xdg_config_name)
+ local dotfilename = "." .. filename
+ local xdg_config_name = xdg_config_name or "config.lua"
+ local xdg = os.getenv("XDG_CONFIG_HOME") or ((os.getenv("HOME") or "") .. "/.config")
+ local home = os.getenv("HOME")
+ if xdg then
+ -- filename like ~/.config/make4ht/config.lua
+ local fn = make_name{ xdg ,filename , xdg_config_name }
+ if file_exists(fn) then
+ return fn
+ end
+ end
+ if home then
+ -- ~/.make4ht
+ local fn = make_name{ home, dotfilename }
+ if file_exists(fn) then
+ return fn
+ end
+ end
+end
+
+local find_config = function(filename)
+ local filename = "." .. filename
+ local current = lfs.currentdir()
+ local path = {}
+ current:gsub("([^/]+)", function(s) table.insert(path,s) end)
+ local begin = os.type == "windows" and "" or "/"
+ for i = #path, 1, -1 do
+ local fn =begin .. table.concat(path,"/") .. "/".. filename
+ -- print("testing",fn)
+ if file_exists(fn) then return fn end
+ table.remove(path)
+ end
+ return false
+end
+
+local function load_config(filename, default)
+ local default = default or {}
+ default.table = table
+ default.string = string
+ default.io = io
+ default.os = os
+ default.math = math
+ default.print = print
+ default.ipairs = ipairs
+ default.pairs = pairs
+ local f = io.open(filename, "r")
+ local contents = f:read("*all")
+ f:close()
+ load(contents,"sandbox config","bt", default)()
+ return default
+end
+
+--[[
+local function load_config(filename, default)
+ local default = default or {}
+ if ~file_exists(filename) then
+ return nil, "Cannot load config file "..filename
+ end
+ local section = "default"
+ local file = io.open(filename, "r")
+ if ~file then return nil, "Error opening config file"..filename end
+ for line in file:lines() do
+ local ts = line:match("")
+ end
+ file:close()
+end
+--]]
+
+m.find_config = find_config
+m.find_xdg_config = xdg_config
+m.load_config = load_config
+return m