summaryrefslogtreecommitdiff
path: root/Master/texmf/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf/scripts')
-rwxr-xr-xMaster/texmf/scripts/texdoc/texdoc.tlu150
1 files changed, 85 insertions, 65 deletions
diff --git a/Master/texmf/scripts/texdoc/texdoc.tlu b/Master/texmf/scripts/texdoc/texdoc.tlu
index 2f5969af8ed..f0252dbf40f 100755
--- a/Master/texmf/scripts/texdoc/texdoc.tlu
+++ b/Master/texmf/scripts/texdoc/texdoc.tlu
@@ -29,9 +29,9 @@ Previous work in the public domain:
-- progname and version
progname = 'texdoc'
-version = '0.42'
+version = '0.43'
if string.sub(version, -1) == '+' then
- local svnrev = string.match('$Rev: 44 $', '%$Rev:%s*(%d*)%s*%$');
+ local svnrev = string.match('$Rev: 61 $', '%$Rev:%s*(%d*)%s*%$');
version = version..' svn r'..svnrev
end
@@ -74,6 +74,10 @@ known_options = {
'ext_list',
'verbosity_level',
'lastfile_switch',
+ 'rm_dir',
+ 'rm_file',
+ 'unzip_bz2',
+ 'unzip_gz',
}
err_priority = {
@@ -137,36 +141,76 @@ end
------------------ exploring trees (kpse-style functions) ------------------
-- global variables:
--- texdocs: a Lua table version of $TEXDOCS
--- do_recurse: do_recurse[i] = 1 iff texdocs[i] ends with // in $TEXDOCS
--- must_have_lsr: must_have_lsr[i] = 1 iff texdocs[i] starts with !! in $TEXDOCS
-- exact_docfiles: list of "exact matches"
-- rel_docfiles: list of "non-exact matches"
--- set texdocs, do_recurse and must_have_lsr lists from kpse's $TEXDOCS
+do -- begin scope of doc_roots, a lua version of kpse's TEXDOCS
+local doc_roots
+
+-- structure of the doc_roots variable:
+-- doc_roots[i] = {
+-- path = <path>,
+-- index_mandatory = <does path begin with !! in TEXDOCS?>
+-- recursion_allowed = <does path ends with // in TEXDOCS?>,
+-- }
+
+-- set the doc_roots list from kpse's $TEXDOCS
function get_texdocs ()
+ doc_roots = {}
local sep = (os.type == 'windows') and ';' or ':'
- texdocs = kpse.expand_var ("$TEXDOCS")
+ local kpse_texdocs = kpse.expand_var("$TEXDOCS")
-- expand the path and turn it into a lua list
- texdocs = string.explode (kpse.expand_braces (texdocs), sep)
- do_recurse, must_have_lsr = {}, {} -- global
+ local raw_doc_roots = string.explode(kpse.expand_braces(kpse_texdocs), sep)
err_print('Search paths:', 'debug3')
- for i, dir in ipairs (texdocs) do
+ for i, dir in ipairs(raw_doc_roots) do
+ doc_roots[i] = {}
local n
dir, n = string.gsub (dir, '//$', '')
- do_recurse[i] = (n == 1)
- texdocs[i], n = string.gsub (dir, '^!!', '')
- must_have_lsr[i] = (n == 1)
- err_print(string.format('%s (do_recurse=%s, must_have_lsr=%s)',
- texdocs[i],
- do_recurse[i] and 'true' or 'false',
- must_have_lsr[i] and 'true' or 'false'), 'debug3')
+ doc_roots[i].recursion_allowed = (n == 1)
+ doc_roots[i].path, n = string.gsub (dir, '^!!', '')
+ doc_roots[i].index_mandatory = (n == 1)
+ err_print(string.format('%s (index_mandatory=%s, recursion_allowed=%s)',
+ doc_roots[i].path,
+ doc_roots[i].index_mandatory and 'true' or 'false',
+ doc_roots[i].recursion_allowed and 'true' or 'false'),
+ 'debug3')
end
end
--- once get_texdocs() is done, roots are represented by their index in texdocs
--- usefull to avoid fake matches and also for the sort routine
--- the next two functions do the conversions
+-- once get_texdocs() is done, roots are represented by their index in doc_roots
+-- this is usefull to avoid fake matches and also for the sort routine
+-- conversions are done by real_path() below and code_path() later
+
+-- decode a path as given in *_docfiles into a real path
+function real_path(fake)
+ local code, file = string.match(fake, '^(.-):(.*)$')
+ code = tonumber(code)
+ return win32_hook(doc_roots[code].path..'/'..file)
+end
+
+-- find docfiles "matching" pattern
+function populate_docfiles (pattern)
+ pattern = normalize_pattern(pattern)
+ rel_docfiles, exact_docfiles = {}, {} -- global
+ is_dir = {} -- global; is_dir[path] = true iff path is a dir, see scan_lsr
+ local curr_dir = lfs.currentdir()
+ for code, doc_root in ipairs (doc_roots) do
+ root, shift = lsr_root (doc_root.path)
+ if root and shift and doc_root.recursion_allowed then
+ assert(lfs.chdir(root))
+ scan_lsr(code, shift, pattern)
+ elseif (not doc_root.index_mandatory)
+ and lfs.isdir(doc_root.path) then
+ assert(lfs.chdir(doc_root.path))
+ scan_tree(code, '.', pattern, doc_root.recursion_allowed)
+ end
+ end
+ assert(lfs.chdir(curr_dir))
+ exact_docfiles = rmdirs (exact_docfiles)
+ rel_docfiles = rmdirs (rel_docfiles)
+end
+
+end -- scope of doc_roots
-- encode the base path on two digits and concatenate with filename
function code_path (code, file)
@@ -174,13 +218,6 @@ function code_path (code, file)
return padding..code..':'..file
end
--- decode a path as given in *_docfiles into a real path
-function real_path (fake)
- local code, file = string.match (fake, '^(.-):(.*)$')
- code = tonumber (code)
- return win32_hook (texdocs[code]..'/'..file)
-end
-
-- merge two components of a path, taking care of empty components
function merge_path (a, b)
return ((a == '') or (b == '')) and a..b or a..'/'..b
@@ -254,28 +291,6 @@ function rmdirs (files)
return res
end
--- find docfiles "matching" pattern
-function populate_docfiles (pattern)
- pattern = normalize_pattern(pattern)
- if not texdocs then get_texdocs() end
- rel_docfiles, exact_docfiles = {}, {} -- global
- is_dir = {} -- global; is_dir[path] = true iff path is a dir, see scan_lsr
- local curr_dir = lfs.currentdir()
- for code, docdir in ipairs (texdocs) do
- root, shift = lsr_root (docdir)
- if root and shift and do_recurse[code] then
- assert(lfs.chdir(root))
- scan_lsr(code, shift, pattern)
- elseif (not must_have_lsr[code]) and lfs.isdir(docdir) then
- assert(lfs.chdir(docdir))
- scan_tree(code, '.', pattern, do_recurse[code])
- end
- end
- assert(lfs.chdir(curr_dir))
- exact_docfiles = rmdirs (exact_docfiles)
- rel_docfiles = rmdirs (rel_docfiles)
-end
-
-- like populate_docfiles, but rel replaces exact if exact is empty
function mixed_populate_docfiles (pattern)
populate_docfiles (pattern)
@@ -405,7 +420,7 @@ end
-- a helper function for warning messages in the above
function config_warn (key, value, context)
local begin = value and 'Illegal value "'..value..'" for option "'..key..'"'
- or 'Unkown option "'..key..'"'
+ or 'Unknown option "'..key..'"'
local ending = '. Skipping.'
err_print (begin..'\n '..context_to_string(context)..ending, 'warning')
end
@@ -744,18 +759,19 @@ end
--------------------------------- viewing ----------------------------------
--- prepare for viewing: set viewer_replacement and viewer_ext
--- may uncompress if support_zipped is set (giving the complete filename on the
--- command line is unsupported for compressed files by the way)
+-- prepare for viewing: returns <viewer command> and <viewer replacement>
+-- <viewer replacement> is either:
+-- 1. the filename, quoted with "
+-- 2. the filename, quoted with " followed by some rm commands
+-- The second case happens when the doc was zipped. In the case, this function
+-- unzips it in a tempdir so that the viewer command can use the unzipped file.
function how_to_view (filename)
filename = real_path(filename) -- TODO: if not filename then ...
if support_zipped then
- ext = string.match(filename,'.*%.(.*)$')
- zipext = string.match(ext,'^.*%.(.*)')
- if zipext then
+ viewext,zipext = string.match(filename, '.*%.([^.]*)%.([^.]*)$')
+ if viewext and zipext then
unzip_command = config['unzip_'..zipext]
- viewext = string.match(ext,'^(.*)%..*$')
- basename_pattern = '.*/(.*%.' .. viewext .. ')'
+ local basename_pattern = '.*/(.*%.' .. viewext .. ')'
basename = string.match(filename,basename_pattern)
tmpdir = os.tmpdir("/tmp/texdoc.XXXXXX")
unzip_commandline = unzip_command .. filename .. " > "
@@ -765,11 +781,14 @@ function how_to_view (filename)
else
print("Error executing \n" .. unzip_commandline)
end
- viewer_replacement = filename .. ';' .. config.rm_file
- .. filename .. ';' .. config.rm_dir .. tmpdir
+ viewer_replacement = '"' .. filename .. '"; '
+ .. config.rm_file .. ' ' .. filename .. '; '
+ .. config.rm_dir .. ' ' .. tmpdir
end
- else
- viewer_replacement = filename
+ end
+ -- if viewext wasn't set zipped way, then try the normal way
+ if not viewext then
+ viewer_replacement = '"' .. filename .. '"'
-- files without extension are assumed to be text
viewext = string.match(filename,'.*%.(.*)$') or 'txt'
if not config['viewer_'..viewext] then
@@ -793,9 +812,9 @@ function try_viewing (view_command, viewer_replacement)
else
if string.match (view_command, place_holder) then
view_command = string.gsub(
- view_command, place_holder, '"'..viewer_replacement..'"')
+ view_command, place_holder, viewer_replacement)
else
- view_command = view_command..' "'..viewer_replacement..'"'
+ view_command = view_command..' '..viewer_replacement
end
err_print(view_command, 'debug1')
view_result = os.execute(view_command)
@@ -905,8 +924,9 @@ setup_config_from_env ()
setup_config_from_files ()
setup_config_from_defaults ()
--- now that verbosity_level is known...
+-- now that config.verbosity_level is known...
show_config_files(function(s) err_print(s, 'debug1') end)
+get_texdocs()
------------------------ looping over the arguments ------------------------