From fb43532b6f9ce833b23619edd9bc81a7a3f16212 Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 4 Aug 2012 16:40:19 +0300 Subject: beta 2012.08.04 14:00 --- scripts/context/lua/mtx-fcd.lua | 2 +- scripts/context/lua/mtx-server.lua | 4 +- scripts/context/lua/mtx-watch.lua | 11 ----- scripts/context/lua/mtxrun.lua | 84 ++++++++++++++++++++++++++++++++-- scripts/context/stubs/mswin/mtxrun.lua | 84 ++++++++++++++++++++++++++++++++-- scripts/context/stubs/unix/mtxrun | 84 ++++++++++++++++++++++++++++++++-- 6 files changed, 240 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-fcd.lua b/scripts/context/lua/mtx-fcd.lua index d96d0bad3..d7e1d17a7 100644 --- a/scripts/context/lua/mtx-fcd.lua +++ b/scripts/context/lua/mtx-fcd.lua @@ -297,7 +297,7 @@ local function globdirs(path,dirs) for name in lfs.dir(path) do if not find(name,"%.$") then local fullname = path .. "/" .. name - if lfs.isdir(fullname) then + if lfs.isdir(fullname) and not find(fullname,"/%.") then dirs[#dirs+1] = fullname globdirs(fullname,dirs) end diff --git a/scripts/context/lua/mtx-server.lua b/scripts/context/lua/mtx-server.lua index 068d51111..1a688fb5d 100644 --- a/scripts/context/lua/mtx-server.lua +++ b/scripts/context/lua/mtx-server.lua @@ -30,7 +30,7 @@ dofile(resolvers.findfile("l-url.lua","tex")) dofile(resolvers.findfile("luat-soc.lua","tex")) local socket = socket or require("socket") -local http = socket or require("socket.http") +local http = socket or require("socket.http") -- not needed local format = string.format -- The following two lists are taken from webrick (ruby) and @@ -322,7 +322,7 @@ function scripts.webserver.run(configuration) fullurl = socket.url.unescape(fullurl) local hashed = url.hashed(fullurl) local query = url.query(hashed.query) - local filename = hashed.path + local filename = hashed.path -- hm, not query? -- table.print(hashed) if filename then filename = socket.url.unescape(filename) diff --git a/scripts/context/lua/mtx-watch.lua b/scripts/context/lua/mtx-watch.lua index 36a3176c4..31ed95f7b 100644 --- a/scripts/context/lua/mtx-watch.lua +++ b/scripts/context/lua/mtx-watch.lua @@ -227,17 +227,6 @@ function scripts.watch.watch() end end local n, start = 0, time() ---~ local function wait() ---~ io.flush() ---~ if not done then ---~ n = n + 1 ---~ if n >= 10 then ---~ report("run time: %i seconds, memory usage: %0.3g MB", difftime(time(),start), (status.luastate_bytes/1024)/1000) ---~ n = 0 ---~ end ---~ os.sleep(delay) ---~ end ---~ end local wtime = 0 local function wait() io.flush() diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 62293e867..b4df0521b 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -3053,6 +3053,7 @@ local drive = C(R("az","AZ")) * P(":") local path = C(((1-slash)^0 * slash)^0) local suffix = period * C(P(1-period)^0 * P(-1)) local base = C((1-suffix)^0) +local rest = C(P(1)^0) drive = drive + Cc("") path = path + Cc("") @@ -3061,7 +3062,8 @@ suffix = suffix + Cc("") local pattern_a = drive * path * base * suffix local pattern_b = path * base * suffix -local pattern_c = C(drive * path) * C(base * suffix) +local pattern_c = C(drive * path) * C(base * suffix) -- trick: two extra captures +local pattern_d = path * rest function file.splitname(str,splitdrive) if splitdrive then @@ -3071,6 +3073,10 @@ function file.splitname(str,splitdrive) end end +function file.splitbase(str) + return lpegmatch(pattern_d,str) -- returns path, base+suffix +end + function file.nametotable(str,splitdrive) -- returns table local path, drive, subpath, name, base, suffix = lpegmatch(pattern_c,str) if splitdrive then @@ -3092,6 +3098,8 @@ function file.nametotable(str,splitdrive) -- returns table end end +-- print(file.splitbase("a/b/c.txt")) + -- function test(t) for k, v in next, t do print(v, "=>", file.splitname(v)) end end -- -- test { "c:", "c:/aa", "c:/aa/bb", "c:/aa/bb/cc", "c:/aa/bb/cc.dd", "c:/aa/bb/cc.dd.ee" } @@ -4591,11 +4599,10 @@ local concat = table.concat local type, next = type, next utilities = utilities or {} -utilities.merger = utilities.merger or { } -- maybe mergers +local merger = utilities.merger or { } +utilities.merger = merger utilities.report = logs and logs.reporter("system") or print -local merger = utilities.merger - merger.strip_comment = true local m_begin_merge = "begin library merge" @@ -5297,7 +5304,7 @@ end -- of closure do -- create closure to overcome 200 locals limit -if not modules then modules = { } end modules ['util.deb'] = { +if not modules then modules = { } end modules ['util-deb'] = { version = 1.001, comment = "companion to luat-lib.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -15803,6 +15810,71 @@ function environment.run_format(name,data,more) end +end -- of closure + +do -- create closure to overcome 200 locals limit + +if not modules then modules = { } end modules ['util-tpl'] = { + 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" +} + +-- experimental code + +-- maybe make %% scanning optional +-- maybe use $[ and ]$ or {{ }} + +utilities.templates = utilities.templates or { } +local templates = utilities.templates + +local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) +local report_template = logs.reporter("template") + +local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match + +local function replacekey(k,t) + local v = t[k] + if not v then + if trace_template then + report_template("unknown key %q",k) + end + return "" + else + if trace_template then + report_template("setting key %q to value %q",k,v) + end + return v + end +end + +----- leftmarker = P("") / "" + +local escape = P("%%") / "%%" +local leftmarker = P("%") / "" +local rightmarker = P("%") / "" + +local key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local any = P(1) +local replacer = Cs((escape + key + any)^0) + +function templates.replace(str,mapping) + return mapping and lpegmatch(replacer,str,1,mapping) or str +end + +function templates.load(filename,mapping) + local data = io.loaddata(filename) or "" + if mapping and next(mapping) then + return templates.replace(data,mapping) + else + return data + end +end + + end -- of closure -- end library merge @@ -15871,6 +15943,8 @@ own.libs = { -- order can be made better 'luat-sta.lua', 'luat-fmt.lua', + + 'util-tpl.lua', } -- We need this hack till luatex is fixed. diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 62293e867..b4df0521b 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -3053,6 +3053,7 @@ local drive = C(R("az","AZ")) * P(":") local path = C(((1-slash)^0 * slash)^0) local suffix = period * C(P(1-period)^0 * P(-1)) local base = C((1-suffix)^0) +local rest = C(P(1)^0) drive = drive + Cc("") path = path + Cc("") @@ -3061,7 +3062,8 @@ suffix = suffix + Cc("") local pattern_a = drive * path * base * suffix local pattern_b = path * base * suffix -local pattern_c = C(drive * path) * C(base * suffix) +local pattern_c = C(drive * path) * C(base * suffix) -- trick: two extra captures +local pattern_d = path * rest function file.splitname(str,splitdrive) if splitdrive then @@ -3071,6 +3073,10 @@ function file.splitname(str,splitdrive) end end +function file.splitbase(str) + return lpegmatch(pattern_d,str) -- returns path, base+suffix +end + function file.nametotable(str,splitdrive) -- returns table local path, drive, subpath, name, base, suffix = lpegmatch(pattern_c,str) if splitdrive then @@ -3092,6 +3098,8 @@ function file.nametotable(str,splitdrive) -- returns table end end +-- print(file.splitbase("a/b/c.txt")) + -- function test(t) for k, v in next, t do print(v, "=>", file.splitname(v)) end end -- -- test { "c:", "c:/aa", "c:/aa/bb", "c:/aa/bb/cc", "c:/aa/bb/cc.dd", "c:/aa/bb/cc.dd.ee" } @@ -4591,11 +4599,10 @@ local concat = table.concat local type, next = type, next utilities = utilities or {} -utilities.merger = utilities.merger or { } -- maybe mergers +local merger = utilities.merger or { } +utilities.merger = merger utilities.report = logs and logs.reporter("system") or print -local merger = utilities.merger - merger.strip_comment = true local m_begin_merge = "begin library merge" @@ -5297,7 +5304,7 @@ end -- of closure do -- create closure to overcome 200 locals limit -if not modules then modules = { } end modules ['util.deb'] = { +if not modules then modules = { } end modules ['util-deb'] = { version = 1.001, comment = "companion to luat-lib.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -15803,6 +15810,71 @@ function environment.run_format(name,data,more) end +end -- of closure + +do -- create closure to overcome 200 locals limit + +if not modules then modules = { } end modules ['util-tpl'] = { + 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" +} + +-- experimental code + +-- maybe make %% scanning optional +-- maybe use $[ and ]$ or {{ }} + +utilities.templates = utilities.templates or { } +local templates = utilities.templates + +local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) +local report_template = logs.reporter("template") + +local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match + +local function replacekey(k,t) + local v = t[k] + if not v then + if trace_template then + report_template("unknown key %q",k) + end + return "" + else + if trace_template then + report_template("setting key %q to value %q",k,v) + end + return v + end +end + +----- leftmarker = P("") / "" + +local escape = P("%%") / "%%" +local leftmarker = P("%") / "" +local rightmarker = P("%") / "" + +local key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local any = P(1) +local replacer = Cs((escape + key + any)^0) + +function templates.replace(str,mapping) + return mapping and lpegmatch(replacer,str,1,mapping) or str +end + +function templates.load(filename,mapping) + local data = io.loaddata(filename) or "" + if mapping and next(mapping) then + return templates.replace(data,mapping) + else + return data + end +end + + end -- of closure -- end library merge @@ -15871,6 +15943,8 @@ own.libs = { -- order can be made better 'luat-sta.lua', 'luat-fmt.lua', + + 'util-tpl.lua', } -- We need this hack till luatex is fixed. diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 62293e867..b4df0521b 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -3053,6 +3053,7 @@ local drive = C(R("az","AZ")) * P(":") local path = C(((1-slash)^0 * slash)^0) local suffix = period * C(P(1-period)^0 * P(-1)) local base = C((1-suffix)^0) +local rest = C(P(1)^0) drive = drive + Cc("") path = path + Cc("") @@ -3061,7 +3062,8 @@ suffix = suffix + Cc("") local pattern_a = drive * path * base * suffix local pattern_b = path * base * suffix -local pattern_c = C(drive * path) * C(base * suffix) +local pattern_c = C(drive * path) * C(base * suffix) -- trick: two extra captures +local pattern_d = path * rest function file.splitname(str,splitdrive) if splitdrive then @@ -3071,6 +3073,10 @@ function file.splitname(str,splitdrive) end end +function file.splitbase(str) + return lpegmatch(pattern_d,str) -- returns path, base+suffix +end + function file.nametotable(str,splitdrive) -- returns table local path, drive, subpath, name, base, suffix = lpegmatch(pattern_c,str) if splitdrive then @@ -3092,6 +3098,8 @@ function file.nametotable(str,splitdrive) -- returns table end end +-- print(file.splitbase("a/b/c.txt")) + -- function test(t) for k, v in next, t do print(v, "=>", file.splitname(v)) end end -- -- test { "c:", "c:/aa", "c:/aa/bb", "c:/aa/bb/cc", "c:/aa/bb/cc.dd", "c:/aa/bb/cc.dd.ee" } @@ -4591,11 +4599,10 @@ local concat = table.concat local type, next = type, next utilities = utilities or {} -utilities.merger = utilities.merger or { } -- maybe mergers +local merger = utilities.merger or { } +utilities.merger = merger utilities.report = logs and logs.reporter("system") or print -local merger = utilities.merger - merger.strip_comment = true local m_begin_merge = "begin library merge" @@ -5297,7 +5304,7 @@ end -- of closure do -- create closure to overcome 200 locals limit -if not modules then modules = { } end modules ['util.deb'] = { +if not modules then modules = { } end modules ['util-deb'] = { version = 1.001, comment = "companion to luat-lib.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -15803,6 +15810,71 @@ function environment.run_format(name,data,more) end +end -- of closure + +do -- create closure to overcome 200 locals limit + +if not modules then modules = { } end modules ['util-tpl'] = { + 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" +} + +-- experimental code + +-- maybe make %% scanning optional +-- maybe use $[ and ]$ or {{ }} + +utilities.templates = utilities.templates or { } +local templates = utilities.templates + +local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) +local report_template = logs.reporter("template") + +local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match + +local function replacekey(k,t) + local v = t[k] + if not v then + if trace_template then + report_template("unknown key %q",k) + end + return "" + else + if trace_template then + report_template("setting key %q to value %q",k,v) + end + return v + end +end + +----- leftmarker = P("") / "" + +local escape = P("%%") / "%%" +local leftmarker = P("%") / "" +local rightmarker = P("%") / "" + +local key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local any = P(1) +local replacer = Cs((escape + key + any)^0) + +function templates.replace(str,mapping) + return mapping and lpegmatch(replacer,str,1,mapping) or str +end + +function templates.load(filename,mapping) + local data = io.loaddata(filename) or "" + if mapping and next(mapping) then + return templates.replace(data,mapping) + else + return data + end +end + + end -- of closure -- end library merge @@ -15871,6 +15943,8 @@ own.libs = { -- order can be made better 'luat-sta.lua', 'luat-fmt.lua', + + 'util-tpl.lua', } -- We need this hack till luatex is fixed. -- cgit v1.2.3