From 5dd5aa0744705fbac6f0093f5092108d8ddaf7bb Mon Sep 17 00:00:00 2001 From: Manuel Pégourié-Gonnard Date: Tue, 15 Jul 2008 23:56:31 +0000 Subject: Reworking the -s option to display only files whose extension is in ext_list. git-svn-id: svn://tug.org/texlive/trunk@9590 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf/scripts/texlive/texdoc.tlu | 66 ++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'Master/texmf') diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu index d3cf9bbcdad..4055d25d384 100755 --- a/Master/texmf/scripts/texlive/texdoc.tlu +++ b/Master/texmf/scripts/texlive/texdoc.tlu @@ -113,9 +113,8 @@ function deluaficate(oldpat) return newpat end --deluaficate -docdirs = {} -docfiles = {} function pattern_search (pattern) + docdirs, docfiles = {}, {} -- should not be local (used in recurse_tree) pattern = deluaficate(pattern) -- populate docdirs and doclines list for database in get_lsr_files() do @@ -131,7 +130,9 @@ function pattern_search (pattern) -- the next file lines are in docdir "this_dir" is_docline = true -- save it in the docdirs table - table.insert(docdirs,this_dir) + if string.match(this_dir, pattern) then + table.insert(docdirs,this_dir) + end else is_docline = false end -- docdir @@ -140,41 +141,52 @@ function pattern_search (pattern) -- now we have only file lines left, are they a docline? elseif is_docline then local fullpath = this_dir .. line - -- print(fullpath) - table.insert(docfiles,fullpath) + if string.match(fullpath, pattern) then + if lfs.isfile(fullpath) then -- cannot know form ls-R + table.insert(docfiles,fullpath) + end + end end -- line starting with ./ end -- for line end -- for database for no_lsr_dir in list_iter(no_lsr_doctrees) do - recurse_tree(no_lsr_dir) + recurse_tree(no_lsr_dir, pattern) end -- - print("Directories that match:") + print("\tDirectories that match:") for dir in list_iter(docdirs) do - if string.match(dir,pattern) then - print (dir) - end - end -- for dir - print() - print("Files that match:") - for file in list_iter(docfiles) do - if string.match(file,pattern) then - print (file) + print (dir) + end + print("\tFiles that match:") + for _, ext in ipairs (config.ext_list) do + if ext == '' then + ext_pattern = '/[^.]*$' + elseif ext == '*' then + ext_pattern = '' + else + ext_pattern = '%.'..ext..'$' end - end -- for file + for file in list_iter(docfiles) do + if string.match (file, ext_pattern) then print (file) end + end + end end -- function pattern_search() -function recurse_tree (path) +function recurse_tree (path, pattern) for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local f = path..'/'..file local attr = lfs.attributes (f) if attr then -- else stale symlink if attr.mode == "directory" then - table.insert(docdirs,f) - recurse_tree (f) + if string.match (f, pattern) then + table.insert(docdirs,f) + end + recurse_tree (f, pattern) else - table.insert(docfiles,f) + if string.match (f, pattern) then + table.insert(docfiles,f) + end end end end @@ -533,11 +545,13 @@ setup_config_from_env () setup_config_from_files () setup_config_from_defaults () --- we want an empty string for ext at the beginning, so that it works --- to specify the complete filename. Doesn't matter when there's one --- more empty string, but we can easily avoid two in a row -if not (config.ext_list[1] == '') then - table.insert(config.ext_list,1,'') +-- 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 +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 -- cgit v1.2.3