[tex-live] texdoc in luatex
Frank Küster
frank at kuesterei.ch
Mon Jun 25 19:08:39 CEST 2007
Frank Küster <frank at kuesterei.ch> wrote:
> The current state is attached, the -l and -h options already work.
Attached is version 0.1. It can be used to list and view files (and it
has a '-v|--version' option, but the regex search is not implemented.
Regards, Frank
--
Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)
-------------- next part --------------
#!/usr/bin/luatexlua
--[[ Written in lua by Frank Küster (2007) based on the shell script by
Thomas Esser, David Aspinall, and Simon Wilkinson.
Public domain.]]
progname = 'texdoc';
version = '0.1';
usage = ' Usage: ' .. progname ..' [-h|--help] name\
-h|--help\t\t Show this help\
-v|--version\t\t Print the version of the program\
-l|--list\t\t List matching files, do not start a viewer.';
if not arg[1] then
print (usage);
return
end
if string.match (arg[1],'^-') then
if string.match (arg[1],'-h') or string.match (arg[1],'--help') then
print (usage);
os.exit(0);
elseif string.match (arg[1],'-v') or string.match (arg[1],'--version') then
print (progname .. ' version: ' .. version );
os.exit(0);
elseif string.match (arg[1],'-l') or string.match (arg[1],'--list' ) then
mode = 'list';
iter_arg_start = 1;
end
else
mode = 'view';
iter_arg_start = 0;
end
--[[ function definitions ]]
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
end
function list_iter_arg (t,start)
local i = start
local n = table.getn(t)
return function ()
i = i + 1
if i <= n then return t[i] end
end
end
local tmpdir;
function cleanup_tmpdir ()
local is_successful
local error_string
if needs_cleanup then
is_successful,error_string = lfs.rmdir (tmpdir);
if is_successful then
print ("removing worked");
else
print ("removing failed");
print (error_string);
end
end
end
--[[ initialize kpathsea ]]
kpse.set_program_name("texdoc")
-- [[ initialize some variables ]]
verbose = false;
nodoc_pattern = [=[\.tfm|\.afm|\.enc|\.pfb|\.pfa|\.pfm|\.vf|\.fd|\.ttf|\.htf|\.mf|\.otf|\.[[:digit:]]*pk]=];
extlist = {'.dvi', '.dvi.gz', '.dvi.bz2', '.pdf', '.pdf.gz', '.pdf.bz2', '.ps', '.ps.gz', '.ps.bz2', '.txt', '.txt.gz', '.txt.bz2', '.html'};
texdoc_unzip = { gz = "gzip -d -c ", bz2 = "bzip2 -d -c "};
texdoc_viewer = {
dvi = '(xdvi %s ) &',
html = '(see %s) &',
pdf = '(see %s) &'
};
rmfile_command = 'rm -f ';
rmdir_command = 'rmdir ';
found = false;
-- needs_cleanup = false;
for docname in list_iter_arg (arg,iter_arg_start) do
for ext in list_iter(extlist) do
filename = kpse.find_file(docname .. ext , "TeX system documentation")
if filename then
found = "true"
if string.match (mode, 'list') then
print(filename);
else
-- mode should be view
dirname = string.match(filename,'.*/');
-- 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
-- TODO: to be done
tmpdir = os.tmpname();
is_ok_tmpdir,error_string = lfs.mkdir(tmpdir)
if is_ok_tmpdir then
-- needs_cleanup = true;
else
print(error_string);
os.exit(1);
end
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
viewer_replacement = filename;
viewext = string.match(ext,'%.(.*)$');
end
view_command = string.gsub(texdoc_viewer[viewext],'%%s',viewer_replacement)
view_result = os.execute(view_command);
if view_result then
do break end;
else
print("Error executing \n" .. view_command);
end
end
end
end
end
-- cleanup_tmpdir();
More information about the tex-live
mailing list