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
97
98
99
100
|
-- General use functions for texdoc
--[[
Copyright 2008, 2009 Manuel Pégourié-Gonnard
Distributed under the terms of the GNU GPL version 3 or later.
See texdoc.tlu for details.
--]]
local L = {}
load_env(L, {
'export_symbols',
'string', 'io', 'os',
'pairs', 'ipairs',
'C',
'config',
})
-- change '/' to '\' on windows
if os.type == "windows" then
function win32_hook (path)
local res = string.gsub (path, '/', '\\')
return res -- get rid of gsub's 2nd return value
end
else
function win32_hook (path)
return path
end
end
-- generic error display function (see the error_priority constant)
function err_print (lvl, msg)
-- be careful: maybe config.verbosity_level is not set yet
local verbosity_level = config.verbosity_level or 2
if C.err_priority[lvl] <= verbosity_level then
io.stderr:write ("texdoc "..lvl..": "..msg.."\n")
end
end
do --scope of active_debugs
local active_debugs
-- generic debug function
function deb_print(cat, msg)
-- make sure active_debugs is set
if not active_debugs then set_active_debugs() end
-- print message it belongs to an active category
if active_debugs and active_debugs[cat] or cat == 'XXX' then
io.stderr:write ("texdoc debug-"..cat..": "..msg.."\n")
end
end
-- set active_debugs
function set_active_debugs()
if not config.debug_list then return end
active_debugs = {}
-- all debug options imply version info
if config.debug_list[1] then
active_debugs.version = true
else
return
end
-- if 'all' is the first keyword, just activate all categories
if config.debug_list[1] == 'all' then
for deb in pairs(C.known_debugs) do
active_debugs[deb] = true end
return
end
-- activate options from the list
for _, deb in ipairs(config.debug_list) do
local deps = C.known_debugs[deb]
if deps then
active_debugs[deb] = true
for _, d in ipairs(deps) do active_debugs[d] = true end
else
err_print('warning', "Unknown debug category '"..deb.."'.")
end
end
end
end -- scope of active_debugs
-- if file is base..'.'..zip with zip in zipext_list, return: base, zip
-- otherwise, return: file, nil
function parse_zip(file)
local zip
for _, zip in ipairs(config.zipext_list) do
local l = #zip + 1
if string.sub(file, -l, -1) == '.'..zip then
return string.sub(file, 1, -l - 1), zip
end
end
return file, nil
end
-- finally export a few symbols
export_symbols(L, {
'err_print',
'deb_print',
'win32_hook',
'parse_zip',
})
|