data-use.lua /size: 5790 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
data-use
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to luat-lib.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
format
=
string
.
format
10 11
local
trace_locating
=
false
trackers
.
register
(
"
resolvers.locating
"
,
function
(
v
)
trace_locating
=
v
end
)
12 13
local
report_mounts
=
logs
.
reporter
(
"
resolvers
"
,
"
mounts
"
)
14 15
local
resolvers
=
resolvers
16
local
findfile
=
resolvers
.
findfile
17 18
-- -- This should mount a zip file so that we can run from zip files but I never went
19
-- -- on with it. It's really old code, from right when we started with luatex and
20
-- -- mkiv. Nowadays I'd use a lua specification file instead of a line based url.tmi,
21
-- -- file so just to be modern I patched it but it's untested. This is a normally a
22
-- -- startup-only feature.
23
--
24
-- do
25
--
26
-- local mounted = { }
27
--
28
-- function resolvers.automount(usecache)
29
-- local mountpaths = resolvers.cleanpathlist(resolvers.expansion('TEXMFMOUNT'))
30
-- if (not mountpaths or #mountpaths == 0) and usecache then
31
-- mountpaths = caches.getreadablepaths("mount")
32
-- end
33
-- if mountpaths and #mountpaths > 0 then
34
-- resolvers.starttiming()
35
-- for k=1,#mountpaths do
36
-- local root = mountpaths[k]
37
-- local list = table.load("automount.lua")
38
-- if list then
39
-- local archives = list.archives
40
-- if archives then
41
-- for i=1,#archives do
42
-- local archive = archives[i]
43
-- local already = false
44
-- for i=1,#mounted do
45
-- if archive == mounted[i] then
46
-- already = true
47
-- break
48
-- end
49
-- end
50
-- if not already then
51
-- mounted[#mounted+1] = archive
52
-- resolvers.usezipfile(archive)
53
-- end
54
-- end
55
-- end
56
-- end
57
-- end
58
-- resolvers.stoptiming()
59
-- end
60
-- end
61
--
62
-- end
63 64
-- status info
65 66
statistics
.
register
(
"
used config file
"
,
function
(
)
return
caches
.
configfiles
(
)
end
)
67
statistics
.
register
(
"
used cache path
"
,
function
(
)
return
caches
.
usedpaths
(
)
end
)
68 69
-- experiment (code will move)
70 71
function
statistics
.
savefmtstatus
(
texname
,
formatbanner
,
sourcefile
,
kind
,
banner
)
-- texname == formatname
72
local
enginebanner
=
status
.
banner
73
if
formatbanner
and
enginebanner
and
sourcefile
then
74
local
luvname
=
file
.
replacesuffix
(
texname
,
"
luv
"
)
-- utilities.lua.suffixes.luv
75
local
luvdata
=
{
76
enginebanner
=
enginebanner
,
77
formatbanner
=
formatbanner
,
78
sourcehash
=
md5
.
hex
(
io
.
loaddata
(
findfile
(
sourcefile
)
)
or
"
unknown
"
)
,
79
sourcefile
=
sourcefile
,
80
luaversion
=
LUAVERSION
,
81
formatid
=
LUATEXFORMATID
,
82
functionality
=
LUATEXFUNCTIONALITY
,
83
}
84
io
.
savedata
(
luvname
,
table
.
serialize
(
luvdata
,
true
)
)
85
lua
.
registerfinalizer
(
function
(
)
86
if
jit
then
87
logs
.
report
(
"
format banner
"
,
"
%s lua: %s jit
"
,
banner
,
LUAVERSION
)
88
else
89
logs
.
report
(
"
format banner
"
,
"
%s lua: %s
"
,
banner
,
LUAVERSION
)
90
end
91
logs
.
newline
(
)
92
end
)
93
end
94
end
95 96
-- todo: check this at startup and return (say) 999 as signal that the run
97
-- was aborted due to a wrong format in which case mtx-context can trigger
98
-- a remake
99 100
function
statistics
.
checkfmtstatus
(
texname
)
101
local
enginebanner
=
status
.
banner
102
if
enginebanner
and
texname
then
103
local
luvname
=
file
.
replacesuffix
(
texname
,
"
luv
"
)
-- utilities.lua.suffixes.luv
104
if
lfs
.
isfile
(
luvname
)
then
105
local
luv
=
dofile
(
luvname
)
106
if
luv
and
luv
.
sourcefile
then
107
local
sourcehash
=
md5
.
hex
(
io
.
loaddata
(
findfile
(
luv
.
sourcefile
)
)
or
"
unknown
"
)
108
local
luvbanner
=
luv
.
enginebanner
or
"
?
"
109
if
luvbanner
~
=
enginebanner
then
110
return
format
(
"
engine mismatch (luv: %s <> bin: %s)
"
,
luvbanner
,
enginebanner
)
111
end
112
local
luvhash
=
luv
.
sourcehash
or
"
?
"
113
if
luvhash
~
=
sourcehash
then
114
return
format
(
"
source mismatch (luv: %s <> bin: %s)
"
,
luvhash
,
sourcehash
)
115
end
116
local
luvluaversion
=
luv
.
luaversion
or
0
117
local
engluaversion
=
LUAVERSION
or
0
118
if
luvluaversion
~
=
engluaversion
then
119
return
format
(
"
lua mismatch (luv: %s <> bin: %s)
"
,
luvluaversion
,
engluaversion
)
120
end
121
local
luvfunctionality
=
luv
.
functionality
or
0
122
local
engfunctionality
=
status
.
development_id
or
0
123
if
luvfunctionality
~
=
engfunctionality
then
124
return
format
(
"
functionality mismatch (luv: %s <> bin: %s)
"
,
luvfunctionality
,
engfunctionality
)
125
end
126
local
luvformatid
=
luv
.
formatid
or
0
127
local
engformatid
=
status
.
format_id
or
0
128
if
luvformatid
~
=
engformatid
then
129
return
format
(
"
formatid mismatch (luv: %s <> bin: %s)
"
,
luvformatid
,
engformatid
)
130
end
131
else
132
return
"
invalid status file
"
133
end
134
else
135
return
"
missing status file
"
136
end
137
end
138
return
true
139
end
140