diff options
Diffstat (limited to 'support/texdoc/script/texdoclib-util.tlu')
-rw-r--r-- | support/texdoc/script/texdoclib-util.tlu | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/support/texdoc/script/texdoclib-util.tlu b/support/texdoc/script/texdoclib-util.tlu index 81627c823e..db043b150e 100644 --- a/support/texdoc/script/texdoclib-util.tlu +++ b/support/texdoc/script/texdoclib-util.tlu @@ -4,8 +4,8 @@ -- dependencies local texdoc = { - const = require('texdoclib-const'), - config = require('texdoclib-config'), + const = require 'texdoclib-const', + config = require 'texdoclib-config', } -- shortcuts @@ -103,18 +103,42 @@ end end -- end scope of active_debugs --- if file is base .. '.' .. zip with zip in zipext_list, return: base, zip --- otherwise, return: file, nil -function M.parse_zip(file) +-- if filename is base .. '.' .. zip with zip in zipext_list, return: base, zip +-- otherwise, return: filename, nil +function M.parse_zip(filename) local zip for _, zip in ipairs(texdoc.config.get_value('zipext_list')) do local l = #zip + 1 - if string.sub(file, -l, -1) == '.' .. zip then - return string.sub(file, 1, -l - 1), zip + if string.sub(filename, -l, -1) == '.' .. zip then + return string.sub(filename, 1, -l - 1), zip end end + return filename, nil +end - return file, nil +-- take a known extension according to ext_list +function M.get_ext(filename) + filename = M.parse_zip(filename) + + for _, e in ipairs(texdoc.config.get_value('ext_list')) do + if e == '*' then + local dot = filename:find('.', 1, true) + if not dot then + return '' + else + return filename:sub(-dot + 1) + end + elseif (e == '') then + if not filename:find('.', 1, true) then + return '' + end + else + local dot_e = '.' .. e + if filename:sub(-#dot_e) == dot_e then + return dot_e:sub(2) + end + end + end end -- print a usage message |