summaryrefslogtreecommitdiff
path: root/Master/texmf/scripts/texdoc
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-05-18 20:21:44 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-05-18 20:21:44 +0000
commite71eaa026ac3384e0e25e3cae94a54be4fe69223 (patch)
tree44eaf7ef2af6da9e2d4f4599e391a29bf66f0c4e /Master/texmf/scripts/texdoc
parent0d6f6d802fc805abf007cdde14f242de7450c587 (diff)
texdoc 0.80
git-svn-id: svn://tug.org/texlive/trunk@22522 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf/scripts/texdoc')
-rw-r--r--Master/texmf/scripts/texdoc/alias.tlu34
-rw-r--r--Master/texmf/scripts/texdoc/config.tlu16
-rw-r--r--Master/texmf/scripts/texdoc/constants.tlu3
-rw-r--r--Master/texmf/scripts/texdoc/score.tlu38
-rw-r--r--Master/texmf/scripts/texdoc/search.tlu3
-rw-r--r--Master/texmf/scripts/texdoc/view.tlu3
6 files changed, 83 insertions, 14 deletions
diff --git a/Master/texmf/scripts/texdoc/alias.tlu b/Master/texmf/scripts/texdoc/alias.tlu
index f364fa90f76..a99a8b51058 100644
--- a/Master/texmf/scripts/texdoc/alias.tlu
+++ b/Master/texmf/scripts/texdoc/alias.tlu
@@ -13,14 +13,20 @@ load_env(L, {
--[[ structure of the alias table
-alias = { name1 = aliasentry1, ... }
+alias = {
+ name1 = { <true or nill> stop, <aliasentry> aliasentry1, ... },
+ ...
+}
+stop == true means further alias directives should be ignored
aliasentry = {
- name = <string> pattern to be matched,
- score = <number or nil> associated score (may be nil),
- original = <true or nil> is this the original keyword?,
+ name = <string> pattern to be matched,
+ score = <number or nil> associated score,
+ original = <true or nil> is this the original keyword?,
+ locale = <true or nil> is this entry found via config.lang?
}
score == nil means to use the default score (defined in score.tlu)
+
--]]
-- alias is local to this file
@@ -57,12 +63,28 @@ end
-- get patterns for a name
function get_patterns(name, no_alias)
local n = string.lower(name)
+ -- get normal aliases
+ local res
if config.mode ~= 'regex' and config.alias_switch
and not no_alias and alias[n] then
- return alias[n]
+ res = alias[n]
else
- return { make_alias(name, false) }
+ res = { make_alias(name, false) }
+ end
+ -- check for language-specific aliases
+ local lang = config.lang and alias[n .. '-' .. config.lang]
+ if lang then
+ for _, entry in ipairs(lang) do
+ if not entry.original then
+ table.insert(res, {
+ name = entry.name,
+ score = entry.score,
+ locale = true,
+ })
+ end
+ end
end
+ return res
end
-- interpret a confline as an alias setting or return false
diff --git a/Master/texmf/scripts/texdoc/config.tlu b/Master/texmf/scripts/texdoc/config.tlu
index a83b7855308..fd37ba66be7 100644
--- a/Master/texmf/scripts/texdoc/config.tlu
+++ b/Master/texmf/scripts/texdoc/config.tlu
@@ -122,6 +122,8 @@ function context_to_string(context)
return 'from command line option "'..context.name..'"'
elseif context.src == 'env' then
return 'from environment variable "'..context.name..'"'
+ elseif context.src == 'loc' then
+ return 'from operating system locale'
elseif context.src == 'file' then
return 'in file "'..context.file..'" on line '..context.line
elseif context.src == 'def' then
@@ -373,6 +375,19 @@ end
end -- scope of config_files
+---------------------- config from locale settings -------------------------
+
+function setup_config_from_locale()
+ local current = os.setlocale(nil, "all")
+ os.setlocale("", "all")
+ local native = os.setlocale(nil, "time")
+ os.setlocale(current, "all")
+ local lang = string.match(native, "^[a-z][a-z]")
+ if lang then
+ set_config_element("lang", lang, {src="loc"})
+ end
+end
+
---------------------- options from built-in defaults ----------------------
-- for default viewer on general Unix, we have a list; the following two
@@ -551,6 +566,7 @@ function setup_config_and_alias(arg)
setup_config_from_cl(arg)
setup_config_from_env()
setup_config_from_files()
+ setup_config_from_locale()
setup_config_from_defaults()
-- regex mode is deprecated
if config.mode == 'regex' then
diff --git a/Master/texmf/scripts/texdoc/constants.tlu b/Master/texmf/scripts/texdoc/constants.tlu
index 9e2b5ff4e55..a8c107034cc 100644
--- a/Master/texmf/scripts/texdoc/constants.tlu
+++ b/Master/texmf/scripts/texdoc/constants.tlu
@@ -15,7 +15,7 @@ load_env(L, {
-- progname and version
fullname = arg[0]
progname = 'texdoc'
-version = '0.72'
+version = '0.80'
-- make sure to update setup_config_from_cl() accordingly
-- and set a default value in setup_config_from_defaults() if relevant
@@ -76,6 +76,7 @@ known_options = {
'unzip_.*',
'zipext_list',
'max_lines',
+ 'lang',
}
error_msg = [[
diff --git a/Master/texmf/scripts/texdoc/score.tlu b/Master/texmf/scripts/texdoc/score.tlu
index b655f62e57f..75022e41288 100644
--- a/Master/texmf/scripts/texdoc/score.tlu
+++ b/Master/texmf/scripts/texdoc/score.tlu
@@ -61,6 +61,7 @@ function set_score(df, original_kw)
if config.mode == 'regex' then df.score = 0 return end
-- scoring is case-insenstitive (patterns are already lowercased)
local name = string.lower(df.shortname)
+ deb_print('score', '----------')
deb_print('score', 'Start scoring '..df.realpath)
deb_print('score', 'Name used: '..name)
-- get score from patterns
@@ -71,16 +72,26 @@ function set_score(df, original_kw)
if pat.original then
s = df.tree > -1 and heuristic_score(name, p) or 1
elseif is_exact(name, p) then
- s = pat.score or 10 -- default alias score
+ local bonus, msg = 0, ''
+ if pat.locale then
+ bonus, msg = 5, ', (language-based)'
+ end
+ s = (pat.score or 10) + bonus -- default alias score is 10
deb_print('score', string.format(
- "Matching alias '%s', score: %g", pat.name, s))
+ "Matching alias '%s', score: %g%s", pat.name, s, msg))
end
if s > score then score = s end
end
deb_print('score', 'Max pattern score: '..tostring(score))
-- get score from tlp associations
- if score == -10 and df.tlptodoc then score = -2 end
- if score == -10 and df.runtodoc then score = -6 end
+ if score == -10 and df.tlptodoc then
+ score = -2
+ deb_print('score', 'New score: -2 from package name association')
+ end
+ if score == -10 and df.runtodoc then
+ score = -6
+ deb_print('score', 'New score: -6 from sty/cls association')
+ end
-- bonus for metadata
if df.details then
if string.find(string.lower(df.details), 'readme') then
@@ -88,6 +99,7 @@ function set_score(df, original_kw)
else
score = score + 2.5
end
+ deb_print('score', string.format('New score: %g from metadata', score))
end
-- adjust from keyword-specific tables
if df.tree > -1 and spec_adjscore[original_kw] then
@@ -127,7 +139,9 @@ function heuristic_score(file, pat)
end
local slash = not not string.find(pat, '/', 1, true)
-- look for exact or subword match
- if is_exact(file, pat) then
+ if is_exact_locale(file, pat) then
+ upscore(5, 'exact match with correct locale')
+ elseif is_exact(file, pat) then
upscore(4, 'exact match')
elseif is_subword(file, pat) then
upscore(1, 'subword match')
@@ -176,6 +190,20 @@ function is_exact(file, pat)
return false
end
+-- says if file is an exact match for pat and the current locale
+function 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
+ return false
+ end
+ local lang = config.lang
+ if lang then
+ return is_exact(file, pat .. '-' .. lang)
+ or is_exact(file, lang .. '-' .. pat)
+ end
+ return false
+end
+
-- say if pat is a "subword" of str
function is_subword(str, pat)
local i, j = string.find(str, pat, 1, true)
diff --git a/Master/texmf/scripts/texdoc/search.tlu b/Master/texmf/scripts/texdoc/search.tlu
index 4e19513d1ca..11203fd97c5 100644
--- a/Master/texmf/scripts/texdoc/search.tlu
+++ b/Master/texmf/scripts/texdoc/search.tlu
@@ -480,7 +480,8 @@ function get_tlpinfo_from_tlpdb(filename)
else
local file = string.match(line, '^ ([^ ]*)')
local meta = string.match(line, '^ [^ ]* (.+)')
- if check_ext(file) then
+ local basename = string.match(file, '([^/]*)$')
+ if check_ext(basename) then
-- we've got a docfile here, add it
table.insert(tlp_doclist[curr_tlp], file)
if meta then
diff --git a/Master/texmf/scripts/texdoc/view.tlu b/Master/texmf/scripts/texdoc/view.tlu
index e2676ba367b..218cbfff6bf 100644
--- a/Master/texmf/scripts/texdoc/view.tlu
+++ b/Master/texmf/scripts/texdoc/view.tlu
@@ -62,10 +62,11 @@ function view_file (filename)
viewer_replacement = '"'..w32_path(filename)..'"'
end
-- files without extension are assumed to be text
- local viewext = string.match(filename,'.*%.([^/]*)$') or 'txt'
+ local viewext = filename:match('.*%.([^/]*)$'):lower() or 'txt'
-- special case : sty files use txt viewer
if viewext == 'sty' then viewext = 'txt' end
-- FIXME: hardcoding such cases this way is not very clean
+ if viewext == 'texlive' then viewext = 'txt' end
if viewext == 'htm' then viewext = 'html' end
if not config['viewer_'..viewext] then
err_print('warning',