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
57finders.file = function(specification,name,mode,ftype)
58 return resolvers.findfile(name,validftype(ftype))
59end
60
61local function i_finder(name,mode,ftype)
62 local specification = url.hashed(name)
63 local finder = finders[specification.scheme] or finders.file
64 local found = finder(specification,name,mode,validftype(ftype))
65 return found
66end
67
68local function o_finder(name,mode,ftype)
69 return name
70end
71
72o_finder = sandbox.register(o_finder,sandbox.filehandlerone,"mplib output finder")
73
74local function finder(name,mode,ftype)
75 return (mode == "w" and o_finder or i_finder)(name,mode,validftype(ftype))
76end
77
78function mplib.new(specification)
79 specification.find_file = finder
80 specification.run_logger = logger
81 return new_instance(specification)
82end
83
84mplib.finder = finder
85
86 |