1if not modules then modules = { } end modules ['mtxlibs'] = {
2 version = 1.001,
3 comment = "a reasonable subset of mtxrun preloaded libraries",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
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
52xpcall(function() local _, t = require("lpeg") if t then lpeg = t end return end,function() end)
53xpcall(function() local _, t = require("md5") if t then md5 = t end return end,function() end)
54xpcall(function() local _, t = require("lfs") if t then lfs = t end return end,function() end)
55xpcall(function() local _, t = require("slunicode") if t then unicode = t end return end,function() end)
56
57
58
59
60
61local gsub, gmatch, match, find = string.gsub, string.gmatch, string.match, string.find
62local concat = table.concat
63
64local ownname = arg and arg[0] or 'mtxlibs.lua'
65local ownpath = gsub(match(ownname,"^(.+)[\\/].-$") or ".","\\","/")
66local owntree = ownpath
67
68local ownlibs = {
69
70 "l-bit32.lua",
71 "l-lua.lua",
72 "l-macro.lua",
73 "l-sandbox.lua",
74 "l-package.lua",
75 "l-lpeg.lua",
76 "l-function.lua",
77 "l-string.lua",
78 "l-table.lua",
79 "l-io.lua",
80 "l-number.lua",
81 "l-set.lua",
82 "l-os.lua",
83 "l-file.lua",
84
85 "l-md5.lua",
86 "l-sha.lua",
87 "l-url.lua",
88 "l-dir.lua",
89 "l-boolean.lua",
90 "l-unicode.lua",
91 "l-math.lua",
92
93 "util-str.lua",
94 "util-tab.lua",
95 "util-fil.lua",
96 "util-sac.lua",
97 "util-sto.lua",
98
99 "util-prs.lua",
100
101
102
103 "util-soc-imp-reset",
104 "util-soc-imp-socket",
105 "util-soc-imp-copas",
106 "util-soc-imp-ltn12",
107
108 "util-soc-imp-mime",
109 "util-soc-imp-url",
110 "util-soc-imp-headers",
111 "util-soc-imp-tp",
112 "util-soc-imp-http",
113 "util-soc-imp-ftp",
114 "util-soc-imp-smtp",
115
116 "trac-set.lua",
117 "trac-log.lua",
118
119 "trac-inf.lua",
120
121 "util-mrg.lua",
122 "util-tpl.lua",
123 "util-sbx.lua",
124
125 "util-env.lua",
126
127
128 "lxml-tab.lua",
129 "lxml-lpt.lua",
130 "lxml-mis.lua",
131 "lxml-aux.lua",
132 "lxml-xml.lua",
133
134 "trac-xml.lua",
135}
136
137package.path = "t:/sources/?.lua;t:/sources/?;" .. package.path
138
139local ownlist = {
140 '.',
141 ownpath ,
142 ownpath .. "/../sources",
143
144 owntree .. "/../../texmf-local/tex/context/base/mkiv",
145 owntree .. "/../../texmf-context/tex/context/base/mkiv",
146 owntree .. "/../../texmf/tex/context/base/mkiv",
147 owntree .. "/../../../texmf-local/tex/context/base/mkiv",
148 owntree .. "/../../../texmf-context/tex/context/base/mkiv",
149 owntree .. "/../../../texmf/tex/context/base/mkiv",
150
151 owntree .. "/../../texmf-local/tex/context/base",
152 owntree .. "/../../texmf-context/tex/context/base",
153 owntree .. "/../../texmf/tex/context/base",
154 owntree .. "/../../../texmf-local/tex/context/base",
155 owntree .. "/../../../texmf-context/tex/context/base",
156 owntree .. "/../../../texmf/tex/context/base",
157}
158
159if ownpath == "." then table.remove(ownlist,1) end
160
161own = {
162 name = ownname,
163 path = ownpath,
164 tree = owntree,
165 list = ownlist,
166 libs = ownlibs,
167}
168
169local function locate_libs()
170 local name = ownlibs[1]
171 local done = false
172 for i=1,#ownlist do
173 local path = ownlist[i]
174 local filename = path .. "/" .. name
175 local f = io.open(filename)
176 if f then
177 f:close()
178 package.path = package.path .. ";" .. path .. "/?.lua"
179 done = path
180 break
181 end
182 end
183 locate_libs = function() return done end
184 return done
185end
186
187local function load_libs()
188 local found = locate_libs()
189 if found then
190 for i=1,#ownlibs do
191 local basename = ownlibs[i]
192 local filename = found .. "/" .. basename
193 local codeblob = loadfile(filename)
194 if codeblob then
195 package.preload[basename] = codeblob() or true
196 end
197 end
198 end
199end
200
201if not unicode then
202 load_libs()
203end
204
205local merger = utilities and utilities.merger
206
207if not merger then
208 return
209end
210
211local arguments = environment.arguments
212local files = environment.files
213
214local ownname = file.basename(environment.ownname)
215
216local helpinfo = [[
217usage: mtxlibs [options]
218
219--selfmerge
220--selfmerge targetfile extralibs
221--selfclean
222
223and in a lua file:
224
225require("mtxlibs")
226]]
227
228local application = logs.application {
229 name = "mtxlibs",
230 banner = "ConTeXt Basic Lua Libraries 1.00",
231 helpinfo = helpinfo,
232}
233
234local report = application.report
235
236if ownname == "mtxrun" or ownname == "mtxrun.lua" then
237
238 ownname = "mtxlibs.lua"
239elseif ownname == "mtxlibs" or ownname == "mtxlibs.lua" then
240
241 ownname = "mtxlibs.lua"
242else
243 report("usage : lua mtxlibs.lua ...")
244 report(" : mtxrun --script mtxlibs.lua ...")
245 return
246end
247
248if arguments.selfmerge then
249
250 report("merging libraries")
251 local found = locate_libs()
252 if found then
253 local target = files[1]
254 if target == ownname then
255 report("target cannot be this file")
256 return
257 elseif target then
258 report("target: %s",target)
259 for i=1,#files do
260 ownlibs[#ownlibs+1] = file.addsuffix(files[i],"lua")
261 end
262 end
263 merger.selfmerge(ownname,ownlibs,{ found },target)
264 report("done")
265 else
266 report("no libraries found")
267 end
268
269elseif arguments.selfclean then
270
271 report("cleaning libraries")
272 merger.selfclean(ownname)
273 report("done")
274
275else
276
277 application.help()
278
279end
280 |