grph-fil.lua /size: 3753 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
grph-fil
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to grph-fig.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
type
=
type
10 11
local
trace_run
=
false
trackers
.
register
(
"
graphic.runfile
"
,
function
(
v
)
trace_run
=
v
end
)
12
local
report_run
=
logs
.
reporter
(
"
graphics
"
,
"
run
"
)
13 14
local
isfile
=
lfs
.
isfile
15
local
replacesuffix
=
file
.
replacesuffix
16
local
addsuffix
=
file
.
addsuffix
17
local
checksum
=
file
.
checksum
18 19
-- Historically running files is part of graphics processing, so this is why it
20
-- sits here but is part of the job namespace.
21 22
local
allocate
=
utilities
.
storage
.
allocate
23 24
local
collected
=
allocate
(
)
25
local
tobesaved
=
allocate
(
)
26 27
local
jobfiles
=
{
28
collected
=
collected
,
29
tobesaved
=
tobesaved
,
30
forcerun
=
false
,
-- maybe a directive some day
31
}
32 33
job
.
files
=
jobfiles
34 35
local
inputsuffix
=
"
tex
"
36
local
resultsuffix
=
"
pdf
"
37 38
local
function
initializer
(
)
39
tobesaved
=
jobfiles
.
tobesaved
40
collected
=
jobfiles
.
collected
41
end
42 43
job
.
register
(
'
job.files.collected
'
,
tobesaved
,
initializer
)
44 45
local
runner
=
sandbox
.
registerrunner
{
46
name
=
"
hashed context run
"
,
47
program
=
"
context
"
,
48
template
=
[[
%options% %filename%
]]
,
49
checkers
=
{
50
options
=
"
string
"
,
51
filename
=
"
readable
"
,
52
}
53
}
54 55
function
jobfiles
.
run
(
name
,
action
)
56
local
usedname
=
addsuffix
(
name
,
inputsuffix
)
-- we assume tex if not set
57
local
oldchecksum
=
collected
[
usedname
]
58
local
newchecksum
=
checksum
(
usedname
)
59
local
resultfile
=
replacesuffix
(
usedname
,
resultsuffix
)
60
local
tobedone
=
false
61
if
jobfiles
.
forcerun
then
62
tobedone
=
true
63
if
trace_run
then
64
report_run
(
"
processing file, changes in %a, %s
"
,
name
,
"
processing forced
"
)
65
end
66
end
67
if
not
tobedone
and
not
oldchecksum
then
68
tobedone
=
true
69
if
trace_run
then
70
report_run
(
"
processing file, changes in %a, %s
"
,
name
,
"
no checksum yet
"
)
71
end
72
end
73
if
not
tobedone
and
oldchecksum
~
=
newchecksum
then
74
tobedone
=
true
75
if
trace_run
then
76
report_run
(
"
processing file, changes in %a, %s
"
,
name
,
"
checksum mismatch
"
)
77
end
78
end
79
if
not
tobedone
and
not
isfile
(
resultfile
)
then
80
tobedone
=
true
81
if
trace_run
then
82
report_run
(
"
processing file, changes in %a, %s
"
,
name
,
"
no result file
"
)
83
end
84
end
85
if
tobedone
then
86
local
ta
=
type
(
action
)
87
if
ta
=
=
"
function
"
then
88
action
(
name
)
89
elseif
ta
=
=
"
string
"
and
action
~
=
"
"
then
90
-- can be anything but we assume it gets checked by the sandbox
91
os
.
execute
(
action
)
92
elseif
ta
=
=
"
table
"
then
93
runner
(
action
)
94
else
95
report_run
(
"
processing file, no action given for processing %a
"
,
name
)
96
end
97
elseif
trace_run
then
98
report_run
(
"
processing file, no changes in %a, not processed
"
,
name
)
99
end
100
tobesaved
[
name
]
=
newchecksum
101
end
102 103
--
104 105
local
done
=
{
}
106 107
function
jobfiles
.
context
(
name
,
options
)
108
if
type
(
name
)
=
=
"
table
"
then
109
local
result
=
{
}
110
for
i
=
1
,
#
name
do
111
result
[
#
result
+
1
]
=
jobfiles
.
context
(
name
[
i
]
,
options
)
112
end
113
return
result
114
else
115
local
result
=
replacesuffix
(
name
,
resultsuffix
)
116
if
not
done
[
result
]
then
117
jobfiles
.
run
(
name
,
{
options
=
options
,
filename
=
name
}
)
118
done
[
result
]
=
true
119
end
120
return
result
121
end
122
end
123 124
interfaces
.
implement
{
125
name
=
"
runcontextjob
"
,
126
arguments
=
"
2 strings
"
,
127
actions
=
{
jobfiles
.
context
,
context
}
128
}
129