diff options
author | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2008-06-20 15:03:58 +0000 |
---|---|---|
committer | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2008-06-20 15:03:58 +0000 |
commit | ee8e3e5961e4fe75e1a13e4ed623d18b479d39ab (patch) | |
tree | 82cf1ff29c4658f62015480ea9532f42b4ab1428 | |
parent | c220877b86c3a931d991d4597b7fe6d1e1d51035 (diff) |
apologize if no doc was found
git-svn-id: svn://tug.org/texlive/trunk@8884 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-x | Master/texmf/scripts/texlive/texdoc.tlu | 230 |
1 files changed, 121 insertions, 109 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu index 2110f937944..59c4a38b82a 100755 --- a/Master/texmf/scripts/texlive/texdoc.tlu +++ b/Master/texmf/scripts/texlive/texdoc.tlu @@ -19,17 +19,21 @@ Public domain.]] ]] progname = 'texdoc'; -version = '0.3'; -usage = ' Usage: ' .. progname ..' [-h|--help] name\ - -h|--help\t\t Show this help\ - -V|--version\t\t Print the version of the program\ - -v|--verbose\t\t Show the command being used to display the documentation\ - -l|--list\t\t List matching files, do not start a viewer.\ - -s|--search\t\t search for name as a pattern'; +version = '0.31'; +usage_msg = [[ +Usage: texdoc -h, --help | -v, --version | [option] name + -h|--help Show this help. + -V|--version Print the version of the program. + -v|--verbose Show the command being used to display the documentation. + -l|--list List matching files, do not start a viewer. + -s|--search Search for name as a pattern.]] +notfound_msg = [[ +Sorry, I'm not smart enough to find documentation for PKGNAME. Please see +http://tug.org/pkginfo/PKGNAME for information about the package.]] if not arg[1] then - print (usage); + print (usage_msg); return end @@ -38,7 +42,7 @@ verbose = false; while table.maxn(arg) > 0 and string.match(arg[1],'^%-') do curr_arg = table.remove(arg,1) if string.match (curr_arg,'-h') or string.match (curr_arg,'--help') then - print (usage); + print (usage_msg); os.exit(0); elseif string.match (curr_arg,'-V') or string.match (curr_arg,'--version') then print (progname .. ' version: ' .. version ); @@ -69,9 +73,9 @@ function list_iter (t) local i = 0 local n = table.getn(t) return function () - i = i + 1 - if i <= n then return t[i] end - end + i = i + 1 + if i <= n then return t[i] end + end end @@ -86,11 +90,11 @@ function get_lsr_files () tree_root = string.gsub(path,'doc$','') tree_root = string.gsub(tree_root,'^!!','') if lfs.isfile(tree_root .. "ls-R") then - table.insert(lsr_files,tree_root .. "ls-R") + table.insert(lsr_files,tree_root .. "ls-R") else - if not string.match(path,'^%.$') and lfs.isdir(path) then - table.insert(no_lsr_doctrees,path) - end + if not string.match(path,'^%.$') and lfs.isdir(path) then + table.insert(no_lsr_doctrees,path) + end end -- does lsRfile exist? end -- for path local i = 0 @@ -99,10 +103,10 @@ function get_lsr_files () -- don't know how to get the output of "find" without resorting to -- temporary files, anyway, I don't care. return function () - i = i +1 - if i <= n then return lsr_files[i] end - end - + i = i +1 + if i <= n then return lsr_files[i] end + end + end -- get_lsr_files() function deluaficate(oldpat) @@ -123,26 +127,26 @@ function pattern_search (pattern) is_docline = false local this_dir -- changed to each individual docdir for line in io.lines(database) do - if string.match(line,'^./') then - -- a directory - this_dir = string.gsub(line,'^./',texmf_tree) - this_dir = string.gsub(this_dir,':$','/') - if string.match(line,'^./doc') then - -- the next file lines are in docdir "this_dir" - is_docline = true - -- save it in the docdirs table - table.insert(docdirs,this_dir) - else - is_docline = false - end -- docdir - elseif string.match(line,'^%s*$') then - -- empty line, do nothing - -- 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) - end -- line starting with ./ + if string.match(line,'^./') then + -- a directory + this_dir = string.gsub(line,'^./',texmf_tree) + this_dir = string.gsub(this_dir,':$','/') + if string.match(line,'^./doc') then + -- the next file lines are in docdir "this_dir" + is_docline = true + -- save it in the docdirs table + table.insert(docdirs,this_dir) + else + is_docline = false + end -- docdir + elseif string.match(line,'^%s*$') then + -- empty line, do nothing + -- 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) + end -- line starting with ./ end -- for line end -- for database for no_lsr_dir in list_iter(no_lsr_doctrees) do @@ -152,14 +156,14 @@ function pattern_search (pattern) print("Directories that match:") for dir in list_iter(docdirs) do if string.match(dir,pattern) then - print (dir) + 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 (file) end end -- for file @@ -170,13 +174,13 @@ function recurse_tree (path) 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) - else - table.insert(docfiles,f) - end + if attr then -- else stale symlink + if attr.mode == "directory" then + table.insert(docdirs,f) + recurse_tree (f) + else + table.insert(docfiles,f) + end end end end @@ -289,69 +293,77 @@ if not extlist[1] == '' then insert(extlist,1,'') end - for docname in list_iter (arg) do - if string.match(mode,'search') then - pattern_search(docname); - elseif string.match(mode,'view') or string.match(mode,'list') then - for ext in list_iter(extlist) do - filename = kpse.find_file(docname .. ext , "TeX system documentation") + local docfound = false + if string.match(mode,'search') then + docfound = true + pattern_search(docname); + elseif string.match(mode,'view') or string.match(mode,'list') then + for ext in list_iter(extlist) do + filename = kpse.find_file(docname .. ext, + "TeX system documentation") + if filename then + docfound = true + if string.match (mode, 'list') then + print(filename); + else + -- mode is view, is unzipping needed? + zipext = string.match(ext,'%..*%.(.*)'); + if zipext then + unzip_command = texdoc_unzip[zipext]; + viewext = string.match(ext,'%.(.*)%..*$'); + basebame_pattern = '.*/(.*%.' .. viewext .. ')'; + basename = string.match(filename,basebame_pattern); - if filename then - if string.match (mode, 'list') then - print(filename); - else - -- mode is view, is unzipping needed? - zipext = string.match(ext,'%..*%.(.*)'); - if zipext then - unzip_command = texdoc_unzip[zipext]; - viewext = string.match(ext,'%.(.*)%..*$'); - basebame_pattern = '.*/(.*%.' .. viewext .. ')'; - basename = string.match(filename,basebame_pattern); + -- uncompress only once per file, in case it is given + -- more than once (dvi besides ps or so) + -- TODO: to be done - -- uncompress only once per file, in case it is given more - -- than once (dvi besides ps or so) - -- TODO: to be done + tmpdir = os.tmpdir("/tmp/texdoc.XXXXXX"); - tmpdir = os.tmpdir("/tmp/texdoc.XXXXXX"); - - unzip_commandline = unzip_command .. filename .. " > " .. tmpdir .. "/" .. basename; - if os.execute(unzip_commandline) then - filename = tmpdir .. "/" .. basename; - else - print("Error executing \n" .. unzip_commandline); - end - viewer_replacement = filename .. ';' .. rmfile_command .. filename .. ';' .. rmdir_command .. tmpdir; - else - if ext == '' then - -- fallback if complete filename has been specified - ext = string.match(filename,'.*(%..*)$') - if not ext then - -- still no extension for filenames like README - ext = 'txt'; - end - end - viewer_replacement = filename; - viewext = string.match(ext,'%.(.*)$'); - if not viewext or not texdoc_viewer[viewext] then - -- complete filename specified, unknown extension, use "txt" - viewext = 'txt' - end - end -- zipped or not - view_command = string.gsub(texdoc_viewer[viewext],'%%s',viewer_replacement) - if verbose then - print(view_command); - end - view_result = os.execute(view_command); - if view_result then - do break end; - else - print("Error executing \n" .. view_command); - end - end -- list or view - end -- found a filename with that extension or not? - end -- for ext - end -- if construct "case mode in" -end -- for docname + unzip_commandline = unzip_command .. filename .. " > " .. tmpdir .. "/" .. basename; + if os.execute(unzip_commandline) then + filename = tmpdir .. "/" .. basename; + else + print("Error executing \n" .. unzip_commandline); + end + viewer_replacement = filename .. ';' .. rmfile_command .. filename .. ';' .. rmdir_command .. tmpdir; + else + if ext == '' then + -- fallback if complete filename has been specified + ext = string.match(filename,'.*(%..*)$') + if not ext then + -- still no extension for filenames like README + ext = 'txt'; + end + end + viewer_replacement = filename; + viewext = string.match(ext,'%.(.*)$'); + if not viewext or not texdoc_viewer[viewext] then + -- complete filename specified, unknown extension, use "txt" + viewext = 'txt' + end + end -- zipped or not + view_command = string.gsub(texdoc_viewer[viewext],'%%s',viewer_replacement) + if verbose then + print(view_command); + end + view_result = os.execute(view_command); + if view_result then + do break end; + else + print("Error executing \n" .. view_command); + end + end -- list or view + end -- found a filename with that extension or not? + end -- for ext + end -- if construct "case mode in" + if not docfound then -- apologize if we didn't suceed + msg = string.gsub(notfound_msg, 'PKGNAME', docname) + print (msg) -- to get rid of gsub's 2nd value + end +end -- for docname in arg -- cleanup_tmpdir(); + +-- vim: sw=4 ts=8 expandtab: |