1if not modules then modules = { } end modules ['mlib-run'] = {
2 version = 1.001,
3 comment = "companion to mlib-ctx.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 concat = table.concat
10local mplib = mplib
11
12local report_logger = logs.reporter("metapost log")
13local report_error = logs.reporter("metapost error")
14
15local l, nl, dl = { }, 0, false
16local t, nt, dt = { }, 0, false
17local e, ne, de = { }, 0, false
18
19mplib.realtimelogging = false
20
21local function logger(target,str)
22 if target == 1 then
23
24 elseif target == 2 or target == 3 then
25
26 if str == "\n" then
27 mplib.realtimelogging = true
28 if nl > 0 then
29 report_logger(concat(l,"",1,nl))
30 nl, dl = 0, false
31 elseif not dl then
32 report_logger("")
33 dl = true
34 end
35 else
36 nl = nl + 1
37 l[nl] = str
38 end
39 elseif target == 4 then
40 report_error(str)
41 end
42end
43
44local finders = { }
45mplib.finders = finders
46
47local new_instance = mplib.new
48
49local function validftype(ftype)
50 if ftype == "mp" then
51 return "mp"
52 else
53 return nil
54 end
55end
56
57local remapped = {
58
59
60 ["hatching.mp"] = "mp-remapped-hatching.mp",
61 ["boxes.mp"] = "mp-remapped-boxes.mp",
62 ["hatching"] = "mp-remapped-hatching.mp",
63 ["boxes"] = "mp-remapped-boxes.mp",
64}
65
66finders.file = function(specification,name,mode,ftype)
67 local usedname = remapped[name] or name
68 return resolvers.findfile(usedname,validftype(ftype))
69end
70
71local function i_finder(name,mode,ftype)
72 local specification = url.hashed(name)
73 local finder = finders[specification.scheme] or finders.file
74 local found = finder(specification,name,mode,validftype(ftype))
75 return found
76end
77
78local function o_finder(name,mode,ftype)
79 return name
80end
81
82o_finder = sandbox.register(o_finder,sandbox.filehandlerone,"mplib output finder")
83
84local function finder(name,mode,ftype)
85 return (mode == "w" and o_finder or i_finder)(name,mode,validftype(ftype))
86end
87
88function mplib.new(specification)
89 specification.find_file = finder
90 specification.run_logger = logger
91 return new_instance(specification)
92end
93
94mplib.finder = finder
95
96 |