diff options
Diffstat (limited to 'Master/texmf-dist/scripts/texdoc/texdoclib.tlu')
-rw-r--r-- | Master/texmf-dist/scripts/texdoc/texdoclib.tlu | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib.tlu new file mode 100644 index 00000000000..ccaad778d93 --- /dev/null +++ b/Master/texmf-dist/scripts/texdoc/texdoclib.tlu @@ -0,0 +1,91 @@ +-- texdoclib.tlu: the texdoc library + +--[[ +Copyright 2008, 2009, 2010, 2011 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 for submodules ------------------------ + +-- texdoc is divided in submodules (files). Each module is loaded in a private +-- copy of a shared environment, and can export symbols to this environments +-- by returning a table to be merge with this environment. + +-- return a simple (not deep) copy of a table +local function simple_copy(t) + local c = {} + for sym, val in pairs(t) do + c[sym] = val + end + return c +end + +-- initialise the shared environment with a copy of the global environment +local prv_env = simple_copy(_G) +setfenv(1, prv_env) + +-- import symbols from a table to the share environment +local function import_symbols(symbols, name) + for sym, val in pairs(symbols) do + assert(val ~= nil, + 'Internal error: '..name..'exporting undefined symbol '..sym..'.') + assert(prv_env[sym] == nil, + 'Internal error: '..name..'exporting existing symbol '..sym..'.') + prv_env[sym] = val + end +end + +-- load a submodule of texdoc +local function texdoc_do(name) + local pathname = kpse.find_file('texdoc/'..name, 'lua') + assert(pathname, 'Internal error: missing submodule: '..name) + local submod = assert(loadfile (pathname)) + setfenv(submod, simple_copy(prv_env)) + local symbols = submod() + if symbols then import_symbols(symbols, name) end +end + +------------------------ initilisation & main code ------------------------- + +-- pre-declare variables in the shared environment +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') + +return { + setup_config_and_alias = setup_config_and_alias, + read_config_file = read_config_file, + init_databases = init_databases, + print_usage = print_usage, + get_doclist = get_doclist, + deliver_results = deliver_results, + aliased_names = aliased_names, + show_config_files = show_config_files, + config = config, + view_file = view_file, + const = C, +} |