summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/page-ini.lua
blob: 1aeae8f09a0c347c6a5d7080175385a5f8893e11 (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
if not modules then modules = { } end modules ['page-ini'] = {
    version   = 1.001,
    comment   = "companion to page-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local tonumber, rawget = tonumber, rawget
local gmatch = string.gmatch

local texgetcount  = tex.getcount

local ctx_testcase = commands.testcase

local data = table.setmetatableindex("table")
local last = 0

interfaces.implement {
    name      = "markpage",
    arguments = { "string", "string" },
    actions   = function(name,list)
        local realpage = texgetcount("realpageno")
        if list and list ~= "" then
            for sign, page in gmatch(list,"([%+%-])(%d+)") do
                page = tonumber(page)
                if page then
                    if sign == "+" then
                        page = realpage + page
                    end
                    data[page][name] = true
                end
            end
        else
            data[realpage][name] = true
        end
    end
}

interfaces.implement {
    name      = "doifelsemarkedpage",
    arguments = "string",
    actions   = function(name)
        local realpage = texgetcount("realpageno")
        for i=last,realpage-1 do
            data[i] = nil
        end
        local pagedata = rawget(data,realpage)
        ctx_testcase(pagedata and pagedata[name])
    end
}