summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/texdoc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-03-03 21:09:20 +0000
committerKarl Berry <karl@freefriends.org>2022-03-03 21:09:20 +0000
commitc568ce9e272d7341e2c05d8a8c204c21486b83f7 (patch)
tree5e84088225a26e5b6c0cb6d4ae808a530002925f /Master/texmf-dist/scripts/texdoc
parent9150bf479bb504503a94eb23384ee565d29613a1 (diff)
texdoc (3mar22)
git-svn-id: svn://tug.org/texlive/trunk@62379 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/texdoc')
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-cli.tlu4
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-config.tlu8
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-const.tlu33
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-score.tlu107
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-search.tlu56
-rwxr-xr-xMaster/texmf-dist/scripts/texdoc/texdoclib-util.tlu40
-rw-r--r--Master/texmf-dist/scripts/texdoc/texdoclib.tlu2
7 files changed, 173 insertions, 77 deletions
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu
index 95a43b7ddd9..5818af7f184 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu
@@ -1,4 +1,4 @@
--- texdoclib-cli.tlu: command line interfaces for texdoc
+-- texdoclib-cli.tlu: command-line interfaces for texdoc
--
-- The TeX Live Team, GPLv3, see texdoclib.tlu for details
@@ -200,7 +200,7 @@ end
-------------------------- the main function --------------------------
function M.exec()
- -- parsing command line options
+ -- parsing command-line options
local ok, action, cl_config = parse_options()
if not ok then
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-config.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-config.tlu
index 2fc0c99cdf0..3f2dddb34a9 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-config.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib-config.tlu
@@ -50,7 +50,7 @@ function M.get_value(key) return config[key] end
local function context_to_string(context)
if not context then return '(no context)' end
if context.src == 'cl' then
- return 'from command line option "' .. context.name .. '"'
+ return 'from command-line option "' .. context.name .. '"'
elseif context.src == 'env' then
return 'from environment variable "' .. context.name .. '"'
elseif context.src == 'loc' then
@@ -169,9 +169,9 @@ local function set_config_list(conf, context)
end
end
------------------------- config from command line ------------------------
+------------------------ config from command-line ------------------------
--- set config from the command line
+-- set config from the command-line
-- Note: Make sure to set a default value in setup_config_from_defaults()
-- if relevant.
local function setup_config_from_cl(cl_config)
@@ -450,7 +450,7 @@ function M.get_default_viewers()
-- Use 'start' to get file associations.
-- We need to quote the filenames, but the first quoted argument
-- is considered as the title by start, so we provide a dummy title.
- -- Also, since the command line parser removes quotes if there
+ -- Also, since the command-line parser removes quotes if there
-- is no space inside, the dummy title must contain spaces.
viewer_dvi = 'start "texdoc dvi viewer"',
viewer_html = 'start "texdoc html viewer"',
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-const.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-const.tlu
index 7da64d394bb..d6def02f747 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-const.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib-const.tlu
@@ -22,8 +22,8 @@ end
-- progname and version
fullname = kpse.find_file('texdoc/texdoclib', 'lua')
progname = 'Texdoc'
-version = '3.3.1'
-release_date = '2021-05-20'
+version = '3.4'
+release_date = '2022-03-03'
-- make sure to update setup_config_from_cl() accordingly
-- and set a default value in setup_config_from_defaults() if relevant
@@ -64,7 +64,7 @@ Repository: <https://github.com/TeX-Live/texdoc>
Please email bugs to <texdoc@tug.org>.]]
copyright_msg = [[
-Copyright 2008-2021 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team.
+Copyright 2008-2022 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.]]
@@ -104,7 +104,7 @@ notfound_msg_ph = 'PKGNAME'
-- exit codes
exit_ok = 0
-exit_error = 1 -- apparently hard-coded in Lua
+exit_error = 1 -- apparently hard-coded in Lua
exit_usage = 2
exit_notfound = 3
@@ -129,14 +129,35 @@ known_debugs = {
}
-- various cache or non-cache files
-cache_name = 'texdoc/cache-tlpdb.lua' -- relative to TEXMFVAR
+cache_name = 'texdoc/cache-tlpdb.lua' -- relative to TEXMFVAR
data_tlpdb_name = 'texdoc/Data.tlpdb.lua'
-place_holder = '%%s' -- used for viewer commands
+place_holder = '%%s' -- used for viewer commands
-- kpse path separator
kpse_sep = (os.type == 'windows') and ';' or ':'
+-- language codes
+-- Note: corrected with `find $TEXMFDIST/doc/ | awk 'match(
+-- $0, /(.*)-(\w{2}).pdf/, a){print a[2]}'`
+lang_codes = {
+ cn = 'zh', -- Chinese (alias)
+ cz = 'cz', -- Chech/Slovak
+ de = 'de', -- German
+ ee = 'et', -- Estonian
+ en = 'en', -- English
+ es = 'es', -- Spanish
+ fr = 'fr', -- French
+ it = 'it', -- Italian
+ ja = 'ja', -- Japanese
+ nl = 'nl', -- Dutch
+ pl = 'pl', -- Polish
+ ro = 'ro', -- Romanian
+ ru = 'ru', -- Russian
+ sr = 'sr', -- Serbian
+ zh = 'zh', -- Chinese
+}
+
-- END constants
-- get our previous environment back
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-score.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-score.tlu
index 01c3818e375..5aca28ef73b 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-score.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib-score.tlu
@@ -5,6 +5,7 @@
-- dependencies
local md5 = require 'md5'
local texdoc = {
+ const = require 'texdoclib-const',
util = require 'texdoclib-util',
config = require 'texdoclib-config',
}
@@ -49,6 +50,26 @@ end
---------------------------- score computation -----------------------------
+-- parse filename into <base>, <lang>, <ext>
+local function parse(filename)
+ local base, lang, ext
+ ext = texdoc.util.get_ext(filename)
+ if ext ~= nil and ext ~= '' then
+ base = filename:sub(1, -#ext - 2)
+ else
+ base = filename
+ end
+
+ for lc, _ in pairs(texdoc.const.lang_codes) do
+ local hyph_lc = '-' .. lc
+ if base:sub(-#hyph_lc) == hyph_lc then
+ return base:sub(1, -#hyph_lc - 1), lc, ext
+ end
+ end
+
+ return base, lang, ext
+end
+
-- says if pat is a "subword" of str
local function is_subword(str, pat)
local function is_delim(str, i)
@@ -72,8 +93,8 @@ local function has_bad_basename(file)
return false
end
--- compute a heuristic score -10 <= s < 10
-local function heuristic_score(file, pat, dbg_score)
+-- compute a pattern score -10 <= s < 10
+local function pattern_score(name, pat, dbg_score)
dbg_score('Start heuristic scoring with pattern: ' .. pat)
-- score management
@@ -84,42 +105,40 @@ local function heuristic_score(file, pat, dbg_score)
dbg_score('New heuristic score: %.1f. Reason: %s', s, reason)
end
end
- local slash = not not string.find(pat, '/', 1, true)
-- look for exact or subword match
- if M.is_exact_locale(file, pat) then
- upscore(5, 'exact match with correct locale')
- elseif M.is_exact(file, pat) then
+ if M.is_exact(name, pat) then
upscore(4, 'exact match')
- elseif is_subword(file, pat) then
+ elseif is_subword(name, pat) then
upscore(1, 'subword match')
end
-- try derivatives unless pat contains a slash
+ local slash = not not string.find(pat, '/', 1, true)
if not slash then
for _, suffix in ipairs(texdoc.config.get_value('suffix_list')) do
local deriv = pat .. suffix
- if M.is_exact(file, deriv) then
+ if M.is_exact(name, deriv) then
upscore(4.5, 'exact match for derived pattern: ' .. deriv)
- elseif is_subword(file, deriv) then
+ elseif is_subword(name, deriv) then
upscore(3.5, 'subword match for derived pattern: ' .. deriv)
end
end
end
-- if extension is bad, score becomes an epsilon
- local ext = texdoc.config.get_value('ext_list')[M.ext_pos(file)]
+ local ext = texdoc.config.get_value('ext_list')[M.ext_pos(name)]
if ext and texdoc.config.get_value('badext_list_inv')[ext] and score > 0 then
upscore(0.1, 'bad extension', true)
end
-- if basename is bad, score becomes an epsilon
- if has_bad_basename(file) and score > 0 then
+ if has_bad_basename(name) and score > 0 then
upscore(0.1, 'bad basename', true)
end
-- bonus for being in the right directory
- if string.find('/' .. file, '/' .. pat .. '/', 1, true) and not slash then
+ if string.find('/' .. name, '/' .. pat .. '/', 1, true) and not slash then
upscore(score + 1.5, 'directory bonus')
end
@@ -146,12 +165,18 @@ local function set_score(df, original_kw)
-- get score from patterns
local score = -10
+ local is_alias = false
for _, pat in ipairs(df.matches) do
local s = -10
local p = string.lower(pat.name)
if pat.original then -- non-alias
- s = df.tree > -1 and heuristic_score(name, p, dbg_score) or 1
+ if df.tree > -1 then
+ s = pattern_score(name, p, dbg_score)
+ else
+ s = 1
+ end
elseif M.is_exact(name, p) then -- alias
+ is_alias = true
local bonus, note = 0, ''
if pat.locale then
bonus, note = 5, ', (language-based)'
@@ -185,6 +210,22 @@ local function set_score(df, original_kw)
end
end
+ -- bonus for locale
+ if not is_alias then
+ local config_lang = texdoc.config.get_value('lang')
+ local file_lang = df.lang
+
+ if not file_lang then
+ _, file_lang, _ = parse(name)
+ file_lang = texdoc.const.lang_codes[file_lang]
+ end
+
+ if config_lang == file_lang then
+ score = score + 1
+ dbg_score('Locale match bonus: +1.0')
+ end
+ end
+
-- adjust from keyword-specific tables
if df.tree > -1 and spec_adjscore[original_kw] then
for pat, val in pairs(spec_adjscore[original_kw]) do
@@ -218,33 +259,29 @@ local function set_list_scores(list, original_kw)
end
end
--- says if file is an exact match for pat
-function M.is_exact(file, pat)
- file = texdoc.util.parse_zip(file)
- local slashes = string.gsub(pat, '[^/]+', '[^/]+')
- basename = string.match(file, slashes .. '$')
- if not basename then return nil end
- if basename == pat then return true end
- for _, ext in ipairs(texdoc.config.get_value('ext_list')) do
- if ext ~= '' and ext ~= '*' and basename == pat .. '.' .. ext then
- return true
- end
+-- says if filename is an exact match for pat
+function M.is_exact(filename, pattern)
+ local f_base, f_lang, f_ext = parse(filename)
+ local p_base, p_lang, p_ext = parse(pattern)
+
+ -- if the pattern contains lang, check if identical
+ if p_lang ~= nil and f_lang ~= p_lang then
+ return false
end
- return false
-end
--- says if file is an exact match for pat and the current locale
-function M.is_exact_locale(file, pat)
- if string.match(pat, '%-%l%l%l?$') then
- -- don't match if the pattern appears to include a language code
+ -- if the pattern contains ext, check if identical
+ if p_ext ~= nil and p_ext ~= '' and f_ext ~= p_ext then
return false
end
- local lang = texdoc.config.get_value('lang')
- if lang then
- return M.is_exact(file, pat .. '-' .. lang)
- or M.is_exact(file, lang .. '-' .. pat)
+
+ -- finally check the bases
+ if (f_base == p_base
+ or (f_base:sub(-#p_base) == p_base
+ and f_base:sub(-#p_base - 1, -#p_base - 1) == '/')) then
+ return true
+ else
+ return false
end
- return false
end
-- compare two docfile's: (see texdoclib-search.tlu for structure)
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-search.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-search.tlu
index af04a2a3eec..b560626b439 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-search.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib-search.tlu
@@ -39,22 +39,9 @@ end
-- (or known basename according to basename_list)
local function check_ext(file)
file = file:lower()
- -- remove zipext if applicable
- file = texdoc.util.parse_zip(file)
- -- then do the normal thing
- for _, e in ipairs(texdoc.config.get_value('ext_list')) do
- if e == '*' then
- return true
- elseif (e == '') then
- if not file:find('.', 1, true) then
- return true
- end
- else
- local dot_e = '.' .. e
- if file:sub(-#dot_e) == dot_e then
- return true
- end
- end
+ -- has a known extention?
+ if texdoc.util.get_ext(file) ~= nil then
+ return true
end
-- is the basename good?
for _, b in ipairs(texdoc.config.get_value('basename_list')) do
@@ -443,6 +430,33 @@ end
-- tlpdb means TeX Live Package DataBase and tlp means TeX Live Package
+-- return an iterator that ouputs the keys in order
+local function opairs(t)
+ local tkeys = {}
+
+ -- use the counter len to avoid the cost of table.insert and to save the
+ -- length of tkeys for later use in the iterator
+ local len = 0
+ for k, _ in pairs(t) do
+ len = len + 1
+ tkeys[len] = k
+ end
+
+ table.sort(tkeys)
+
+ local i = 0
+ local function iterator()
+ i = i + 1
+ if i > len then
+ return nil
+ else
+ return tkeys[i], t[tkeys[i]]
+ end
+ end
+
+ return iterator
+end
+
-- return true if cache exists and is newer than original, false otherwise
local function good_cache(cache, ori)
local cache_date = lfs.attributes(cache, 'modification')
@@ -556,25 +570,25 @@ print_out_tlpinfo = function(filename)
-- s_meta
printf('local s_meta = {\n')
- for k, v in pairs(s_meta) do
+ for k, v in opairs(s_meta) do
printf(' [%q] = {', k)
- for i, j in pairs(v) do printf('[%q] = %q, ', i, j) end
+ for i, j in opairs(v) do printf('[%q] = %q, ', i, j) end
printf('},\n')
end
printf('}\n')
-- tlp_from_runfile
printf('local tlp_from_runfile = {\n')
- for k, v in pairs(tlp_from_runfile) do
+ for k, v in opairs(tlp_from_runfile) do
printf(' [%q] = {', k)
- for f in pairs(v) do printf('[%q]=true,', f) end
+ for f in opairs(v) do printf('[%q]=true,', f) end
printf('},\n')
end
printf('}\n')
-- tlp_doclist
printf('local tlp_doclist = {\n')
- for k, v in pairs(tlp_doclist) do
+ for k, v in opairs(tlp_doclist) do
printf(' [%q] = {\n', k)
for _, f in ipairs(v) do printf(' %q,\n', f) end
printf(' },\n')
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-util.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-util.tlu
index 81627c823e6..db043b150ee 100755
--- a/Master/texmf-dist/scripts/texdoc/texdoclib-util.tlu
+++ b/Master/texmf-dist/scripts/texdoc/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
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib.tlu
index f7d4f06055e..3c0f66c1d28 100644
--- a/Master/texmf-dist/scripts/texdoc/texdoclib.tlu
+++ b/Master/texmf-dist/scripts/texdoc/texdoclib.tlu
@@ -1,7 +1,7 @@
-- texdoclib.tlu: the texdoc library
--[[
-Copyright 2008-2021 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team.
+Copyright 2008-2022 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software