summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/texdoc/main.tlu
blob: 0058a55da8fcb9e442e24602f7f8c1afe8452558 (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
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
-- $Id: main.tlu 24 2017-11-18 23:00:18Z karl $
-- main.tlu: default command-line interface of texdoc
--
-- Manuel Pégourié-Gonnard, GPLv3, see texdoclib.tlu for details

-- load texdoclib (kpse initialized by the wrapper)
local texdoc = require('texdoc.texdoclib')

-- exit codes
local exit_ok = 0
local exit_error = 1 -- apparently hard-coded in Lua
local exit_usage = 2

-- action command-line options
local action_help = [[
  -h, --help            Print this help message.
  -V, --version         Print the version number.
  -f, --files           Print the list of configuration files used.
  --just-view FILE      Display FILE, given with full path (no searching).]]

-- get configuration and parse command line
local action = texdoc.setup_config_and_alias(arg)
if not action then
    os.exit(exit_usage)
end

-- handle action options
if action == 'help' then
    texdoc.print_usage(action_help)
    os.exit(exit_ok)
elseif action == 'version' then
    print(texdoc.const.progname .. ' ' .. texdoc.const.version)
    print('\n' .. texdoc.const.copyright_msg)
    os.exit(exit_ok)
elseif action == 'files' then
    print(texdoc.const.fullname .. ' ' .. texdoc.const.version)
    texdoc.show_config_files(print, true)
    os.exit(exit_ok)
elseif action == 'view' then
    if not arg[1] then
        texdoc.err_print('error', "missing file operand to --just-view")
        texdoc.err_print('error', texdoc.const.error_msg)
        os.exit(exit_usage)
    end
    local ok = texdoc.view_file(arg[1])
    os.exit(ok and exit_ok or exit_error)
end

-- make sure we actually have argument(s)
if not arg[1] then
    texdoc.err_print('error', "no action specified")
    texdoc.err_print('error', texdoc.const.error_msg)
    os.exit(exit_usage)
end

-- initialise databases
texdoc.init_databases()

-- 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 = texdoc.get_doclist(docname)
    -- deliver results to the user
    texdoc.deliver_results(docname, doclist, multiarg)
end

-- the end
os.exit(exit_ok)