7
7
-- dependencies
8
8
local kpse = require ' kpse'
9
9
local lfs = require ' lfs'
10
+ local md5 = require ' md5'
10
11
local texdoc = {
11
12
const = require ' texdoclib-const' ,
12
13
util = require ' texdoclib-util' ,
@@ -75,15 +76,61 @@ function Doclist:new()
75
76
return dl
76
77
end
77
78
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
+
78
124
-- add a docfile to a list
79
125
function Doclist :add (df )
80
126
-- if no realpath information, unable to add
81
127
-- (useful if vanilla == false)
82
128
if not df .realpath then return end
129
+ local df_hash = md5 .sumhexa (df .normname :lower ()):sub (1 , 7 ) -- same as debug-score
83
130
84
131
-- check the existence of the file
85
132
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 )
87
134
return
88
135
end
89
136
@@ -92,7 +139,8 @@ function Doclist:add(df)
92
139
if index then
93
140
self [index ]:mergein (df )
94
141
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 )
96
144
97
145
local newindex = # self + 1
98
146
self [newindex ] = df
@@ -110,10 +158,13 @@ docfile = {
110
158
-- name and tree are mandatory
111
159
name = filename (used for scoring only)
112
160
tree = code of the tree, see below
161
+ source = where the docfile found (sty, tlpdb, or texdocs)
162
+
113
163
-- 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
+
117
168
-- those are virtual members, see below
118
169
realpath = full path
119
170
normname = nomrmalised (path removed up to the 'doc' component)
@@ -122,12 +173,14 @@ docfile = {
122
173
details = details tag from the catalogue metadata
123
174
quality = 'good', 'bad', or 'killed' depending on score
124
175
ext_pos = position of the extension in ext_list
176
+
125
177
-- set for elements of a list as a side effect of sort_doclist()
126
178
score = score
127
179
}
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
129
182
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.
131
184
--]]
132
185
133
186
-- Docfile objects inherit members from Docfile
233
286
local function matches (pattern , file )
234
287
if pattern .original then
235
288
return file :lower ():find (pattern .name :lower (), 1 , true )
236
- else
289
+ else -- alias
237
290
return texdoc .score .is_exact (file , pattern .name )
238
291
end
239
292
end
263
316
local function scan_db (patlist , code , lsr_db )
264
317
for file , basename in pairs (lsr_db ) do
265
318
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
267
323
end
268
324
end
269
325
@@ -420,6 +476,7 @@ local function get_doclist_sty(patlist)
420
476
local df = Docfile :new ({
421
477
name = file ,
422
478
tree = - 1 ,
479
+ source = ' sty' ,
423
480
pattern = pat ,
424
481
})
425
482
s_doclist :add (df )
@@ -625,6 +682,7 @@ get_doclist_tlpdb = function(pattern)
625
682
s_doclist :add (Docfile :new {
626
683
name = file ,
627
684
tree = 0 ,
685
+ source = ' tlpdb' ,
628
686
runtodoc = true ,
629
687
})
630
688
end
@@ -636,6 +694,7 @@ get_doclist_tlpdb = function(pattern)
636
694
s_doclist :add (Docfile :new {
637
695
name = file ,
638
696
tree = 0 ,
697
+ source = ' tlpdb' ,
639
698
tlptodoc = true ,
640
699
})
641
700
end
@@ -761,7 +820,6 @@ function M.get_doclist(pattern, no_alias)
761
820
762
821
-- get results; _texdocs search comes after _tlpdb search so that
763
822
-- files found by both will have the priority of the _texdocs tree.
764
- -- (https://puszcza.gnu.org.ua/bugs/?369)
765
823
get_doclist_sty (sty )
766
824
get_doclist_tlpdb (pattern )
767
825
get_doclist_texdocs (normal )
0 commit comments