| 1 |
#!/usr/bin/env texlua |
| 2 |
|
| 3 |
-- texdoc.tlu: the main program of texdoc |
| 4 |
-- |
| 5 |
-- The TeX Live Team, GPLv3, see texdoclib.tlu for details |
| 6 |
|
| 7 |
-- Note: we keep this file small as much as possible so that make it easier |
| 8 |
-- to install a new version of texdoc in TEXMFHOME. |
| 9 |
|
| 10 |
local lfs = require 'lfs' |
| 11 |
local kpse = require 'kpse' |
| 12 |
|
| 13 |
-- setup kpse library |
| 14 |
kpse.set_program_name(arg[-1], 'texdoc') |
| 15 |
|
| 16 |
-- get realpath of this file |
| 17 |
local function realpath(p) |
| 18 |
if os.type == 'unix' then |
| 19 |
local e = os.execute('which realpath >/dev/null 2>&1') |
| 20 |
if e == 0 then |
| 21 |
local h = io.popen(string.format("realpath '%s'", p)) |
| 22 |
local r = h:read('*a') |
| 23 |
h:close() |
| 24 |
return r:gsub('\n$', '') |
| 25 |
end |
| 26 |
end |
| 27 |
return '' |
| 28 |
end |
| 29 |
local file = realpath(arg[0]) |
| 30 |
|
| 31 |
-- if the file is not in TEXMFMAIN, set temporal TEXMFAUXTREES and TEXMFDIST |
| 32 |
local texmf = file:match('^(.*/texmf[^/]*)/scripts/texdoc/texdoc.tlu$') |
| 33 |
if texmf ~= nil then |
| 34 |
if texmf ~= kpse.var_value('TEXMFMAIN') then |
| 35 |
io.stderr:write('Info: ' .. |
| 36 |
'Running Texdoc not installed in the current TEXMFMAIN.\n') |
| 37 |
os.setenv('TEXMFAUXTREES', texmf .. ',') |
| 38 |
os.setenv('TEXMFDIST', ',') |
| 39 |
end |
| 40 |
end |
| 41 |
|
| 42 |
-- load the library and execute |
| 43 |
local texdoc = require 'texdoclib' |
| 44 |
assert(texdoc.cli, 'Internal error: Texdoc is not installed properly.') |
| 45 |
texdoc.cli.exec() |
| 46 |
|
| 47 |
-- vim: ft=lua: |