summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-28 20:06:04 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-28 20:06:04 +0000
commit7f4ebcfb84d0a56c24cb3032f8759fddfd4c3b7a (patch)
tree8da8ff8090e6b5433eb483b2210d8e4f26dd7f3c
parent5c3879fd68d93ad4dfee849f4d4a5c4964397389 (diff)
Do not use lfs.isfile() in read_lsr(), too slow. Get rid of the dirs another
way. Fixed bugs in path construction. Added '' in ext_list by default. git-svn-id: svn://tug.org/texlive/trunk@9847 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-xMaster/texmf/scripts/texlive/texdoc.tlu53
1 files changed, 32 insertions, 21 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu
index 51483361090..4c09d307cdf 100755
--- a/Master/texmf/scripts/texlive/texdoc.tlu
+++ b/Master/texmf/scripts/texlive/texdoc.tlu
@@ -121,10 +121,10 @@ function is_good_ext (ext)
end
-- include a file in the lists if it should be
-function process_file (file, pathfile, code, pattern, sure_isfile)
+function process_file (file, pathfile, code, pattern)
local base, ext = string.match(file, '^(.*)%.(.*)$')
if string.find(pathfile, pattern, 1, no_regex) and is_good_ext (ext)
- and (sure_isfile or lfs.isfile (pathfile)) then
+ then
if base == pattern then
table.insert(exact_docfiles, code..':'..pathfile)
else
@@ -163,24 +163,35 @@ function lsr_root (path)
end
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
+end
+
-- scan a ls-R file
function scan_lsr (code, shift, pattern)
local isdoc = false
local current_dir
+ local l = #shift
local lsr = assert(io.open('ls-R', 'r'))
+ local _ = lsr:read('*line') -- throw away first line (comment)
+ local maybe_dir = true -- next line may be a directory
while true do
local line = lsr:read('*line')
+ while line == '' do line, maybe_dir = lsr:read('*line'), true end
if line == nil then break end -- EOF
- local dir_line = string.match (line, '^%./(.*):$')
+ local dir_line = maybe_dir and string.match (line, '^%./(.*):$')
if dir_line then
- if string.find (dir_line, '^'..shift) then
+ maybe_dir = false -- next line may not be a dir
+ if string.sub (dir_line, 1, l) == shift then
isdoc = true
- current_dir = dir_line
+ current_dir = string.sub (dir_line, l+1)
+ is_dir[code..':'..current_dir] = true
elseif isdoc then
break -- we're exiting the ./doc (or shift) dir, so it's over
end
elseif isdoc then
- process_file (line, current_dir..'/'..line, code, pattern, false)
+ process_file (line, merge_path(current_dir, line), code, pattern)
end
end
lsr:close()
@@ -190,6 +201,7 @@ end
function populate_docfiles (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)
@@ -202,6 +214,8 @@ function populate_docfiles (pattern)
end
end
assert(lfs.chdir(curr_dir))
+ exact_docfiles = rmdirs (exact_docfiles)
+ rel_docfiles = rmdirs (rel_docfiles)
end
-- END kpse-like
@@ -223,6 +237,14 @@ function real_path (fake)
return texdocs[code]..'/'..file
end
+-- remove directories from the files list
+function rmdirs (files)
+ local res = {}
+ for f in list (files) do
+ if not is_dir[f] then table.insert(res, f) end
+ end
+ return res
+end
-- functions to set config values and aliases
---------------------------------------------
@@ -464,7 +486,7 @@ function setup_config_from_defaults()
if support_zipped then
set_config_element('ext_list',
'pdf,pdf.gz,pdf.bz2, html,html.gz,html.bz2, txt,txt.gz,txt.bz2,'..
- 'dvi,dvi.gz,dvi.bz2, ps,ps.gz,ps.bz2')
+ 'dvi,dvi.gz,dvi.bz2, ps,ps.gz,ps.bz2, ,gz,bz2')
set_config_list {
unzip_gz = 'gzip -d -c ',
unzip_bz2 = 'bzip -d -c ',
@@ -472,7 +494,7 @@ function setup_config_from_defaults()
rm_dir = 'rmdir'
}
else
- set_config_element('ext_list', 'pdf, html, txt, dvi, ps')
+ set_config_element('ext_list', 'pdf, html, txt, dvi, ps, ')
end
end
@@ -484,7 +506,7 @@ end
-- may uncompress if support_zipped is set (giving the complete filename on the
-- command line is unsupported for compressed files by the way)
function how_to_view (filename)
- filename = real_path(filename)
+ filename = real_path(filename) -- TODO: if not filename then ...
if support_zipped then
ext = string.match(filename,'.*%.(.*)$')
zipext = string.match(ext,'^.*%.(.*)')
@@ -598,7 +620,7 @@ function ext_pos (ext)
end
-- display a table, sorted, numbered with given offset (0 by default),
--- with real pat
+-- with real path
function display_table (t, offset)
offset = offset or 0
table.sort(t, file_order)
@@ -693,17 +715,6 @@ enable_alias = (config.enable_alias == 'true')
verbose = (config.verbose == 'true')
interactive = (config.interactive == 'true')
--- we want an empty string for ext at the beginning, so that it works to specify
--- the complete filename (at least in list or view mode). Doesn't matter when
--- there's one more empty string, but we can easily avoid two in a row
--- TODO: should be dealt with another way
-if (config.mode == 'view' or config.mode == 'list') then
- if not (config.ext_list[1] == '') then
- table.insert(config.ext_list,1,'')
- end
-end
-
-
-- the main loop over the args
------------------------------