trac-tex.lua /size: 2849 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
trac-tex
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to trac-deb.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
texhashtokens
=
tex
.
hashtokens
10 11
local
trackers
=
trackers
12
local
token
=
token
13
local
saved
=
{
}
14
local
create
=
token
.
create
15
local
undefined
=
create
(
"
undefined
"
)
.
command
16 17
function
trackers
.
savehash
(
)
18
saved
=
texhashtokens
(
)
19
return
saved
20
end
21 22
function
trackers
.
dumphashtofile
(
filename
,
delta
)
23
local
list
=
{
}
24
local
hash
=
texhashtokens
(
)
25
local
create
=
token
.
create
26
for
i
=
1
,
#
hash
do
27
local
name
=
hash
[
i
]
28
if
not
delta
or
not
saved
[
name
]
then
29
local
token
=
create
(
name
)
30
if
token
.
command
~
=
undefined
then
31
local
category
=
token
.
cmdname
32
local
dk
=
list
[
category
]
33
if
not
dk
then
34
dk
=
{
35
names
=
{
}
,
36
found
=
0
,
37
-- code = token[1],
38
}
39
list
[
category
]
=
dk
40
end
41
if
token
.
protected
then
42
if
token
.
expandable
then
43
dk
.
names
[
name
]
=
"
ep
"
44
else
45
dk
.
names
[
name
]
=
"
-p
"
46
end
47
else
48
if
token
.
expandable
then
49
dk
.
names
[
name
]
=
"
ep
"
50
else
51
dk
.
names
[
name
]
=
"
--
"
52
end
53
end
54
dk
.
found
=
dk
.
found
+
1
55
end
56
end
57
end
58
table
.
save
(
filename
or
tex
.
jobname
.
.
"
-hash.log
"
,
list
)
59
end
60 61
local
delta
=
nil
62 63
local
function
dump_hash
(
wanteddelta
)
64
if
delta
=
=
nil
then
65
saved
=
saved
or
trackers
.
savehash
(
)
66
luatex
.
registerstopactions
(
1
,
function
(
)
dump_hash
(
nil
,
wanteddelta
)
end
)
-- at front
67
end
68
delta
=
wanteddelta
69
end
70 71
directives
.
register
(
"
system.dumphash
"
,
function
(
)
dump_hash
(
false
)
end
)
72
directives
.
register
(
"
system.dumpdelta
"
,
function
(
)
dump_hash
(
true
)
end
)
73 74
local
function
saveusedfilesintrees
(
format
)
75
local
data
=
{
76
jobname
=
environment
.
jobname
or
"
?
"
,
77
version
=
environment
.
version
or
"
?
"
,
78
kind
=
environment
.
kind
or
"
?
"
,
79
files
=
resolvers
.
foundintrees
(
)
80
}
81
local
filename
=
file
.
replacesuffix
(
environment
.
jobname
or
"
context-job
"
,
'
jlg
'
)
82
if
format
=
=
"
lua
"
then
83
io
.
savedata
(
filename
,
table
.
serialize
(
data
,
true
)
)
84
else
85
io
.
savedata
(
filename
,
table
.
toxml
(
data
,
"
job
"
)
)
86
end
87
end
88 89
directives
.
register
(
"
system.dumpfiles
"
,
function
(
v
)
90
luatex
.
registerstopactions
(
function
(
)
saveusedfilesintrees
(
v
)
end
)
91
end
)
92 93