summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-08-04 16:40:19 +0300
committerMarius <mariausol@gmail.com>2012-08-04 16:40:19 +0300
commitfb43532b6f9ce833b23619edd9bc81a7a3f16212 (patch)
treed49c0ad79dc0d7244efdc603773184f660f2b767 /scripts
parent2f920851e38f427bbafbf0ef895d43a0db48611f (diff)
downloadcontext-fb43532b6f9ce833b23619edd9bc81a7a3f16212.tar.gz
beta 2012.08.04 14:00
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-fcd.lua2
-rw-r--r--scripts/context/lua/mtx-server.lua4
-rw-r--r--scripts/context/lua/mtx-watch.lua11
-rw-r--r--scripts/context/lua/mtxrun.lua84
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua84
-rw-r--r--scripts/context/stubs/unix/mtxrun84
6 files changed, 240 insertions, 29 deletions
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",
@@ -15804,6 +15811,71 @@ 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("<!-- ") / ""
+----- rightmarker = 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
own = { } -- not local, might change
@@ -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",
@@ -15804,6 +15811,71 @@ 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("<!-- ") / ""
+----- rightmarker = 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
own = { } -- not local, might change
@@ -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",
@@ -15804,6 +15811,71 @@ 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("<!-- ") / ""
+----- rightmarker = 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
own = { } -- not local, might change
@@ -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.