1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/usr/bin/env texlua
--[[
Copyright 2008, 2009 Manuel Pégourié-Gonnard.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
Previous work in the public domain:
- Contributions from Reinhard Kotucha (2008).
- First texlua versions by Frank Küster (2007).
- Original shell script by Thomas Esser, David Aspinall, and Simon Wilkinson.
--]]
---------------------- functions handling submodules -----------------------
-- texdoc is divided in submodules (files).
-- Most submodules use a private environment: that is, the functions and
-- variables defined in a file won't be globally visible, unless explicitly
-- exported at the end of the file.
-- Also, symbols from the global environment (hence from other submodules)
-- aren't imported in the local environment, except if explicitly requested and
-- a few default symbols.
-- load a local environment, importing symbols from (this function's) _G
-- usage: local L = {} load_env(L, {'a', 'b'})
function load_env(l, symbols)
local default = {
'export_symbols',
'string', 'table', 'pairs', 'ipairs', 'tonumber', 'tostring', 'next',
'assert', 'error', 'err_print', 'deb_print',
'C',
}
for _, symb in ipairs(default) do
l[symb] = _G[symb]
end
local _, symb
for _, symb in ipairs(symbols) do
assert(_G[symb] ~= nil,
'Internal error: trying to import undefined symbol '..symb..'.')
l[symb] = _G[symb]
end
setfenv(2, l)
end
-- export symbols from a local environment to (this fonction's) _G
function export_symbols(l, symbols)
local _, symb
for _, symb in ipairs(symbols) do
assert(l[symb] ~= nil,
'Internal error: trying to export undefined symbol '..symb..'.')
assert(_G[symb] == nil,
'Internal error: trying to export existing symbol '..symb..'.')
_G[symb] = l[symb]
end
end
-- execute a submodule of texdoc
function texdoc_do(name)
local f = kpse.find_file(name..'.tlu', 'texmfscripts')
assert(f, 'Internal error: unable to find texdoc module '..name..'.')
dofile(f)
end
------------------------ initilisation & main code -------------------------
-- initialize kpathsea
kpse.set_program_name(arg[-1], 'texdoc')
-- declare global variables;
-- they will be made read-only as soon as they are set
C = {} -- constants
config = {} -- configuration settings
-- actually load the submodules now
texdoc_do('constants')
texdoc_do('functions')
texdoc_do('alias')
texdoc_do('score')
texdoc_do('config')
texdoc_do('search')
texdoc_do('view')
-- execute main()
texdoc_do('main')
-- the end
os.exit(C.exit_ok)
|