summaryrefslogtreecommitdiff
path: root/tex/context/base/grph-fil.lua
blob: 4bd1e7d0f6c4584d70f344b08aa922c5c76f16a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
if not modules then modules = { } end modules ['grph-fil'] = {
    version   = 1.001,
    comment   = "companion to grph-fig.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local format, concat = string.format, table.concat

local trace_run = false  trackers.register("files.run",function(v) trace_run = v end)

local allocate, mark = utilities.storage.allocate, utilities.storage.mark

local collected, tobesaved = allocate(), allocate()

local jobfiles = {
    collected = collected,
    tobesaved = tobesaved,
}

job.files = jobfiles

local function initializer()
    tobesaved = mark(jobfiles.tobesaved)
    collected = mark(jobfiles.collected)
end

job.register('job.files.collected', tobesaved, initializer)

jobfiles.forcerun = false

function jobfiles.run(name,command)
    local oldchecksum = collected[name]
    local newchecksum = file.checksum(name)
    if jobfiles.forcerun or not oldchecksum or oldchecksum ~= newchecksum then
        if trace_run then
            commands.writestatus("processing","changes in '%s', processing forced",name)
        end
        if command and command ~= "" then
            os.execute(command)
        else
            commands.writestatus("processing","no command given for processing '%s'",name)
        end
    elseif trace_run then
        commands.writestatus("processing","no changes in '%s', not processed",name)
    end
    tobesaved[name] = newchecksum
end

function jobfiles.context(name,options)
    if type(name) == "table" then
        local result = { }
        for i=1,#name do
            result[#result+1] = jobfiles.context(name[i],options)
        end
        return result
    else
        jobfiles.run(name,"context ".. (options or "") .. " " .. name)
        return file.replacesuffix(name,"pdf")
    end
end