summaryrefslogtreecommitdiff
path: root/Master/texmf/scripts/texdoc/main.tlu
blob: 9fc20ae11825150ddcbbf8e4c9396925cf03ca0a (plain)
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
-- texdoc's main()
--[[ 
Copyright 2008, 2009 Manuel Pégourié-Gonnard
Distributed under the terms of the GNU GPL version 3 or later.
See texdoc.tlu for details.
--]]

-- Load a private environment for this submodule (see texdoc.tlu).
local L = {}
load_env(L, {
    'os', 'arg', 'print',
    'setup_config_and_alias', 'init_databases', 'print_usage',
    'get_doclist', 'deliver_results', 'aliased_names',
    'config', 'view_file',
})

-- get started
setup_config_and_alias(arg)
init_databases()

-- make sure we actually have argument(s)
if not arg[1] then
    print_usage()
    os.exit(C.exit_usage)
end

-- special case for just view
if config.just_view then
    local ok = view_file(arg[1])
    os.exit(ok and C.exit_ok or C.exit_error)
end

-- main loop
local docname
for _, docname in ipairs(arg) do
    -- do we have more then one argument?
    local multiarg = not not arg[2]
    -- get results
    local doclist = get_doclist(docname)
    -- deliver results to the user
    deliver_results(docname, doclist, multiarg)
end