luat-fio.lua /size: 6293 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['luat-fio'] = {
2    version   = 1.001,
3    comment   = "companion to luat-lib.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
9local format = string.format
10local concat = table.concat
11
12texconfig.kpse_init      = false
13texconfig.shell_escape   = 't'
14texconfig.max_print_line = 100000
15texconfig.max_in_open    = 1000
16
17if not resolvers.initialized() then
18
19    resolvers.reset()
20
21    -- we now load the file database as we might need files other than
22    -- tex and lua file on the given path
23
24 -- trackers.enable("resolvers.*")
25    resolvers.load()
26 -- trackers.disable("resolvers.*")
27
28    local findbinfile, loadbinfile = resolvers.findbinfile, resolvers.loadbinfile
29    local findtexfile, opentexfile = resolvers.findtexfile, resolvers.opentexfile
30
31    if callback then
32
33        local register  = callbacks.register
34
35        local addsuffix = file.addsuffix
36        local join      = file.join
37
38        local function findpk(font,dpi)
39            local dpi  = dpi or 600 -- could take from resolution
40            -- <font>.pk
41            local name = addsuffix(font,"pk")
42            -- <dpi>/name.pk
43            local temp = join(dpi,name)
44            local okay = findbinfile(temp,"pk")
45         -- print(temp,okay)
46            if okay and okay ~= "" then
47                return okay
48            end
49            -- <dpi>.dpi/name.pk
50            local temp = join(dpi..".dpi",name)
51            local okay = findbinfile(temp,"pk")
52         -- print(temp,okay)
53            if okay and okay ~= "" then
54                return okay
55            end
56            -- <font>.<dpi>pk
57            local name = addsuffix(font,dpi.."pk")
58            -- name.<dpi>pk
59            local temp = name
60            local okay = findbinfile(temp,"pk")
61         -- print(temp,okay)
62            if okay and okay ~= "" then
63                return okay
64            end
65            -- <dpi>.dpi/name.<dpi>pk
66            local temp = join(dpi..".dpi",name)
67            local okay = findbinfile(temp,"pk")
68         -- print(temp,okay)
69            return okay or ""
70        end
71
72        resolvers.findpk = findpk
73
74     -- register('process_jobname'     , function(name) return name end, true)
75
76        register('find_read_file'      , function(id,name) return findtexfile(name)       end, true)
77        register('open_read_file'      , function(   name) return opentexfile(name)       end, true)
78
79        register('find_data_file'      , function(name) return findbinfile(name,"tex")    end, true)
80        register('open_data_file'      , function(name) return opentexfile(name)          end, true)
81
82        register('find_enc_file'       , function(name) return findbinfile(name,"enc")    end, true)
83        register('find_font_file'      , function(name) return findbinfile(name,"tfm")    end, true)
84     -- register('find_format_file'    , function(name) return findbinfile(name,"fmt")    end, true)
85        register('find_image_file'     , function(name) return findbinfile(name,"tex")    end, true)
86        register('find_map_file'       , function(name) return findbinfile(name,"map")    end, true)
87        register('find_opentype_file'  , function(name) return findbinfile(name,"otf")    end, true)
88        register('find_output_file'    , function(name) return name                       end, true)
89        register('find_pk_file'        , findpk, true)
90     -- register('find_sfd_file'       , function(name) return findbinfile(name,"sfd")    end, true)
91        register('find_truetype_file'  , function(name) return findbinfile(name,"ttf")    end, true)
92        register('find_type1_file'     , function(name) return findbinfile(name,"pfb")    end, true)
93        register('find_vf_file'        , function(name) return findbinfile(name,"vf")     end, true)
94        register('find_cidmap_file'    , function(name) return findbinfile(name,"cidmap") end, true)
95
96        register('read_data_file'      , function(file) return loadbinfile(file,"tex")    end, true)
97        register('read_enc_file'       , function(file) return loadbinfile(file,"enc")    end, true)
98        register('read_font_file'      , function(file) return loadbinfile(file,"tfm")    end, true)
99     -- format
100     -- image
101        register('read_map_file'       , function(file) return loadbinfile(file,"map")    end, true)
102     -- output
103        register('read_pk_file'        , function(file) return loadbinfile(file,"pk")     end, true) -- 600dpi/manfnt.720pk
104     -- register('read_sfd_file'       , function(file) return loadbinfile(file,"sfd")    end, true)
105        register('read_vf_file'        , function(file) return loadbinfile(file,"vf" )    end, true)
106
107     -- register('find_font_file'      , function(name) return findbinfile(name,"ofm")    end, true)
108     -- register('find_vf_file'        , function(name) return findbinfile(name,"ovf")    end, true)
109
110     -- register('read_font_file'      , function(file) return loadbinfile(file,"ofm")    end, true)
111     -- register('read_vf_file'        , function(file) return loadbinfile(file,"ovf")    end, true)
112
113     -- register('read_opentype_file'  , function(file) return loadbinfile(file,"otf")    end, true)
114     -- register('read_truetype_file'  , function(file) return loadbinfile(file,"ttf")    end, true)
115     -- register('read_type1_file'     , function(file) return loadbinfile(file,"pfb")    end, true)
116     -- register('read_cidmap_file'    , function(file) return loadbinfile(file,"cidmap") end, true)
117
118        register('find_write_file'     , function(id,name) return name end, true)
119
120        register('find_log_file'       , function(name)    return name end, true)
121        register('find_format_file'    , function(name)    return name end, true)
122
123    end
124
125end
126
127statistics.register("resource resolver", function()
128    local scandata = resolvers.scandata()
129    return format("loadtime %s seconds, %s scans with scantime %s seconds, %s shared scans, %s found files, scanned paths: %s",
130        resolvers.loadtime(),
131        scandata.n,
132        scandata.time,
133        scandata.shared,
134        #resolvers.foundintrees(),
135        #scandata.paths > 0 and concat(scandata.paths," ") or "<none>"
136    )
137end)
138