Skip to content

Commit d4ed4e6

Browse files
committed
add new debug category "docfile"
1 parent 61ddf2d commit d4ed4e6

4 files changed

+80
-20
lines changed

script/texdoclib-alias.tlu

+6-7
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ end
4646

4747
-- add an alias value for a key
4848
local function add_alias(key, value, score)
49-
local k = string.lower(key)
49+
local k = key:lower()
5050
alias[k] = alias[k] or {make_alias(key, false)}
5151
if alias[k].stop then return end
5252
table.insert(alias[k], make_alias(value, score))
5353
end
5454

5555
-- prevent a key from being further aliased
5656
local function stop_alias(key)
57-
local k = string.lower(key)
57+
local k = key:lower()
5858
alias[k] = alias[k] or {}
5959
alias[k].stop = true
6060
end
6161

6262
-- get patterns for a name
6363
function M.get_patterns(name, no_alias)
64-
local n = string.lower(name)
64+
local n = name:lower()
6565

6666
-- get normal aliases
6767
local res
@@ -92,21 +92,20 @@ end
9292
-- interpret a confline as an alias setting or return false
9393
function M.confline_to_alias(line)
9494
-- alias directive without score
95-
local key, val = string.match(line, '^alias%s+([%w%p]+)%s*=%s*(.+)')
95+
local key, val = line:match('^alias%s+([%w%p]+)%s*=%s*(.+)')
9696
if key and val then
9797
add_alias(key, val)
9898
return true
9999
end
100100
-- alias directive with score
101-
local score, key, val = string.match(line,
102-
'^alias%(([%d+-.]+)%)%s+([%w%p]+)%s*=%s*(.+)')
101+
local score, key, val = line:match('^alias%(([%d+-.]+)%)%s+([%w%p]+)%s*=%s*(.+)')
103102
if score then score = tonumber(score) end
104103
if key and val and score then
105104
add_alias(key, val, score)
106105
return true
107106
end
108107
-- stopalias directive
109-
local key = string.match(line, '^stopalias%s+(.+)')
108+
local key = line:match('^stopalias%s+(.+)')
110109
if key then
111110
stop_alias(key)
112111
return true

script/texdoclib-const.tlu

+3
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,13 @@ min_verbosity = '0' -- (nothing at all)
355355
max_verbosity = '3'
356356
def_verbosity = '2'
357357

358+
-- debug categories
359+
-- the listed categories in the values are automatically activated
358360
known_debugs = {
359361
config = {'files'},
360362
files = {},
361363
search = {},
364+
docfile = {'search'},
362365
score = {},
363366
texdocs = {},
364367
tlpdb = {},

script/texdoclib-score.tlu

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ end
150150
-- set the score of a docfile
151151
local function set_score(df, original_kw)
152152
-- scoring is case-insensitive (patterns are already lowercased)
153-
local name = string.lower(df.normname)
154-
local df_id = string.sub(md5.sumhexa(name), 1, 7)
153+
local name = df.normname:lower()
154+
local df_hash = md5.sumhexa(name):sub(1, 7) -- we use normname hash for cross-platform consistency
155155

156156
-- special debugging function
157157
local function dbg_score(msg, ...)
158158
-- add the hash id prefix to make the outputs grep-friendly
159-
local msg = string.format('(%s) ', df_id) .. msg
159+
local msg = string.format('(%s) ', df_hash) .. msg
160160
texdoc.util.dbg_print('score', msg, ...)
161161
end
162162

script/texdoclib-search.tlu

+68-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-- dependencies
88
local kpse = require 'kpse'
99
local lfs = require 'lfs'
10+
local md5 = require 'md5'
1011
local texdoc = {
1112
const = require 'texdoclib-const',
1213
util = require 'texdoclib-util',
@@ -75,15 +76,61 @@ function Doclist:new()
7576
return dl
7677
end
7778

79+
-- show debug information of docfile
80+
local function dbg_print_docfile(df, df_hash)
81+
local function dbg_df_item(item)
82+
if not df[item] then return end
83+
84+
local cur_pattern, value
85+
if item == 'matches' then
86+
if #df[item] == 0 then return end
87+
for i, v in ipairs(df[item]) do
88+
-- judge alias or not
89+
if v.original then
90+
cur_pattern = v.name
91+
else
92+
cur_pattern = v.name .. ' (alias)'
93+
end
94+
95+
if i == 1 then
96+
value = cur_pattern
97+
else
98+
value = value .. ', ' .. cur_pattern
99+
end
100+
end
101+
else
102+
value = df[item]
103+
end
104+
105+
local msg = string.format('(%s) %s: %s', df_hash, item, value)
106+
dbg_print('docfile', msg)
107+
end
108+
109+
-- mandatory info
110+
dbg_df_item('name')
111+
dbg_df_item('tree')
112+
dbg_df_item('source')
113+
114+
-- support info
115+
dbg_df_item('matches')
116+
dbg_df_item('runtodoc')
117+
dbg_df_item('tlptodoc')
118+
119+
-- other details
120+
dbg_df_item('details')
121+
dbg_df_item('lang')
122+
end
123+
78124
-- add a docfile to a list
79125
function Doclist:add(df)
80126
-- if no realpath information, unable to add
81127
-- (useful if vanilla == false)
82128
if not df.realpath then return end
129+
local df_hash = md5.sumhexa(df.normname:lower()):sub(1, 7) -- same as debug-score
83130

84131
-- check the existence of the file
85132
if not lfs.isfile(df.realpath) then
86-
dbg_print('search', 'File %s not found. Skipping.', df.realpath)
133+
dbg_print('search', '(%d) File %s not found. Skipping.', df_hash, df.realpath)
87134
return
88135
end
89136

@@ -92,7 +139,8 @@ function Doclist:add(df)
92139
if index then
93140
self[index]:mergein(df)
94141
else
95-
dbg_print('search', 'File %s found.', df.realpath)
142+
dbg_print('search', '(%s) File %s found.', df_hash, df.realpath)
143+
dbg_print_docfile(df, df_hash)
96144

97145
local newindex = #self + 1
98146
self[newindex] = df
@@ -110,10 +158,13 @@ docfile = {
110158
-- name and tree are mandatory
111159
name = filename (used for scoring only)
112160
tree = code of the tree, see below
161+
source = where the docfile found (sty, tlpdb, or texdocs)
162+
113163
-- at least one of the following fields should exist
114-
matches = {pattern1, pattern2, ...} or {}
115-
runtodoc = true if there is a runfile -> docfile association
116-
tlptodoc = true if there is a tlp name -> docfile association
164+
matches = {pattern1, pattern2, ...} or {} (for sty and texdocs)
165+
runtodoc = true if there is a runfile -> docfile association (for tlpdb)
166+
tlptodoc = true if there is a tlp name -> docfile association (for tlpdb)
167+
117168
-- those are virtual members, see below
118169
realpath = full path
119170
normname = nomrmalised (path removed up to the 'doc' component)
@@ -122,12 +173,14 @@ docfile = {
122173
details = details tag from the catalogue metadata
123174
quality = 'good', 'bad', or 'killed' depending on score
124175
ext_pos = position of the extension in ext_list
176+
125177
-- set for elements of a list as a side effect of sort_doclist()
126178
score = score
127179
}
128-
if tree > 1, this is the index of the tree in TEXDOCS
180+
181+
if tree > 0, this is the index of the tree in TEXDOCS
129182
if tree = 0, then name is relative to TLROOT
130-
tree = - 1 if and only if file is a sty file. Here name is absolute.
183+
tree = -1 if and only if file is a sty file. Here name is absolute.
131184
--]]
132185

133186
-- Docfile objects inherit members from Docfile
@@ -233,7 +286,7 @@ end
233286
local function matches(pattern, file)
234287
if pattern.original then
235288
return file:lower():find(pattern.name:lower(), 1, true)
236-
else
289+
else -- alias
237290
return texdoc.score.is_exact(file, pattern.name)
238291
end
239292
end
@@ -263,7 +316,10 @@ end
263316
local function scan_db(patlist, code, lsr_db)
264317
for file, basename in pairs(lsr_db) do
265318
local df = process_file(patlist, basename, file, code)
266-
if df then s_doclist:add(df) end
319+
if df then
320+
df.source = 'texdocs'
321+
s_doclist:add(df)
322+
end
267323
end
268324
end
269325

@@ -420,6 +476,7 @@ local function get_doclist_sty(patlist)
420476
local df = Docfile:new({
421477
name = file,
422478
tree = -1,
479+
source = 'sty',
423480
pattern = pat,
424481
})
425482
s_doclist:add(df)
@@ -625,6 +682,7 @@ get_doclist_tlpdb = function(pattern)
625682
s_doclist:add(Docfile:new{
626683
name = file,
627684
tree = 0,
685+
source = 'tlpdb',
628686
runtodoc = true,
629687
})
630688
end
@@ -636,6 +694,7 @@ get_doclist_tlpdb = function(pattern)
636694
s_doclist:add(Docfile:new{
637695
name = file,
638696
tree = 0,
697+
source = 'tlpdb',
639698
tlptodoc = true,
640699
})
641700
end
@@ -761,7 +820,6 @@ function M.get_doclist(pattern, no_alias)
761820

762821
-- get results; _texdocs search comes after _tlpdb search so that
763822
-- files found by both will have the priority of the _texdocs tree.
764-
-- (https://puszcza.gnu.org.ua/bugs/?369)
765823
get_doclist_sty(sty)
766824
get_doclist_tlpdb(pattern)
767825
get_doclist_texdocs(normal)

0 commit comments

Comments
 (0)