summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-metatex.lua
blob: 4453e2ccb474ce364d8cdfbdd501bf0fb033dbbf (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
63
64
65
66
67
68
69
if not modules then modules = { } end modules ['mtx-metatex'] = {
    version   = 1.001,
    comment   = "companion to mtxrun.lua",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- future versions will deal with specific variants of metatex

scripts         = scripts         or { }
scripts.metatex = scripts.metatex or { }

-- metatex

function scripts.metatex.make()
    local command = "luatools --make --compile metatex"
    logs.simple("running command: %s",command)
    os.spawn(command)
end

--~ function scripts.metatex.run()
--~     local name = environment.files[1] or ""
--~     if name ~= "" then
--~         local command = "luatools --fmt=metatex " .. name
--~         logs.simple("running command: %s",command)
--~         os.spawn(command)
--~     end
--~ end

function scripts.metatex.run(ctxdata,filename)
    local filename = environment.files[1] or ""
    if filename ~= "" then
        local formatfile, scriptfile = resolvers.locate_format("metatex")
        if formatfile and scriptfile then
            local command = string.format("luatex --fmt=%s --lua=%s  %s",
                string.quote(formatfile), string.quote(scriptfile), string.quote(filename))
            logs.simple("running command: %s",command)
            os.spawn(command)
        elseif formatname then
            logs.simple("error, no format found with name: %s",formatname)
        else
            logs.simple("error, no format found (provide formatname or interface)")
        end
    end
end

function scripts.metatex.timed(action)
    statistics.timed(action)
end

logs.extendbanner("MetaTeX Process Management 0.10",true)

messages.help = [[
--run                 process (one or more) files (default action)
--make                create metatex format(s)
]]

if environment.argument("run") then
    scripts.metatex.timed(scripts.metatex.run)
elseif environment.argument("make") then
    scripts.metatex.timed(scripts.metatex.make)
elseif environment.argument("help") then
    logs.help(messages.help,false)
elseif environment.files[1] then
    scripts.metatex.timed(scripts.metatex.run)
else
    logs.help(messages.help,false)
end