summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/luat-fio.lmt
blob: 4ce981c48b73151eb59b1bec7db2d6cd8195225d (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
if not modules then modules = { } end modules ['luat-fio'] = {
    version   = 1.001,
    comment   = "companion to luat-lib.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

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

texconfig.kpse_init      = false  -- can go away
texconfig.shell_escape   = 't'    -- can go away
texconfig.max_print_line = 100000 -- can go away
texconfig.max_in_open    = 1000   -- can go away

if not resolvers.initialized() then

    resolvers.reset()

    -- we now load the file database as we might need files other than
    -- tex and lua file on the given path

    resolvers.load()

    if callback then

        local findbinfile = resolvers.findbinfile
        local loadbinfile = resolvers.loadbinfile
        local findtexfile = resolvers.findtexfile
        local opentexfile = resolvers.opentexfile
        local register    = callbacks.register

        local ioflush     = io.flush
        local ioread      = io.read
        local writenl     = texio.write_nl

        local function terminal()
            writenl("\ntex console > ")
            ioflush()
            local line = ioread()
            writenl("")
            ioflush()
            return line
        end

        local function find_data_file(name, index)
            if index == 0 then
                return "terminal"
            else
                return findbinfile(name,"tex")
            end
        end

        local function open_data_file(name, index)
            if index == 0 and name == "terminal" then
                return {
                    reader   = terminal,
                    noflines = 1,
                    filename = name,
                }
            else
                return opentexfile(name)
            end
        end

        local function find_any_file(name)
            return name
        end

        register('find_data_file'  , find_data_file, true)
        register('open_data_file'  , open_data_file, true)
        register('find_log_file'   , find_any_file,  true)
        register('find_format_file', find_any_file,  true)

    end

end

statistics.register("resource resolver", function()
    local scandata = resolvers.scandata()
    return format("loadtime %s seconds, %s scans with scantime %s seconds, %s shared scans, %s found files, scanned paths: %s",
        resolvers.loadtime(),
        scandata.n,
        scandata.time,
        scandata.shared,
        #resolvers.foundintrees(),
        #scandata.paths > 0 and concat(scandata.paths," ") or "<none>"
    )
end)