summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/core-uti.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/core-uti.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/core-uti.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/core-uti.lua99
1 files changed, 56 insertions, 43 deletions
diff --git a/Master/texmf-dist/tex/context/base/core-uti.lua b/Master/texmf-dist/tex/context/base/core-uti.lua
index 1657a75e26d..96ccdca4809 100644
--- a/Master/texmf-dist/tex/context/base/core-uti.lua
+++ b/Master/texmf-dist/tex/context/base/core-uti.lua
@@ -20,21 +20,23 @@ saves much runtime but at the cost of more memory usage.</p>
local format, match = string.format, string.match
local next, type, tostring = next, type, tostring
local concat = table.concat
+local texcount = tex.count
-local definetable = utilities.tables.definetable
-local accesstable = utilities.tables.accesstable
-local migratetable = utilities.tables.migratetable
-local serialize = table.serialize
-local packers = utilities.packers
-local allocate = utilities.storage.allocate
-local mark = utilities.storage.mark
+local definetable = utilities.tables.definetable
+local accesstable = utilities.tables.accesstable
+local migratetable = utilities.tables.migratetable
+local serialize = table.serialize
+local packers = utilities.packers
+local allocate = utilities.storage.allocate
+local mark = utilities.storage.mark
-local report_jobcontrol = logs.reporter("jobcontrol")
+local report_passes = logs.reporter("job","passes")
-job = job or { }
-local job = job
+job = job or { }
+local job = job
-job.version = 1.19
+job.version = 1.22 -- make sure we don't have old lua 5.1 hash leftovers
+job.packversion = 1.02 -- make sure we don't have old lua 5.1 hash leftovers
-- some day we will implement loading of other jobs and then we need
-- job.jobs
@@ -47,11 +49,11 @@ directly access the variable using a <l n='lua'/> call.</p>
local savelist, comment = { }, { }
-function job.comment(str)
- comment[#comment+1] = str
+function job.comment(key,value)
+ comment[key] = value
end
-job.comment(format("version: %1.2f",job.version))
+job.comment("version",job.version)
local enabled = true
@@ -131,9 +133,10 @@ local packlist = {
-- "references", -- we need to rename of them as only one packs (not structures.lists.references)
}
-local jobpacker = packers.new(packlist,1.01)
+local jobpacker = packers.new(packlist,job.packversion) -- jump number when changs in hash
job.pack = true
+-- job.pack = false
directives.register("job.pack",function(v) pack = v end)
@@ -143,12 +146,8 @@ function job.save(filename) -- we could return a table but it can get pretty lar
statistics.starttiming(_save_)
local f = io.open(filename,'w')
if f then
- for c=1,#comment do
- f:write("-- ",comment[c],"\n")
- end
- f:write("\n")
- f:write("local utilitydata = { }\n")
- f:write("\n")
+ f:write("local utilitydata = { }\n\n")
+ f:write(serialize(comment,"utilitydata.comment",true,true),"\n\n")
for l=1,#savelist do
local list = savelist[l]
local target = format("utilitydata.%s",list[1])
@@ -160,30 +159,35 @@ function job.save(filename) -- we could return a table but it can get pretty lar
if job.pack then
packers.pack(data,jobpacker,true)
end
- f:write(definetable(target),"\n")
- f:write(serialize(data,target,true,true),"\n")
+ local definer, name = definetable(target,true,true) -- no first and no last
+ f:write(definer,"\n\n",serialize(data,name,true,true),"\n\n")
end
if job.pack then
packers.strip(jobpacker)
- f:write(serialize(jobpacker,"utilitydata.job.packed",true,true),"\n")
+ f:write(serialize(jobpacker,"utilitydata.job.packed",true,true),"\n\n")
end
- f:write("\n")
- f:write("return utilitydata\n")
- f:write("\n")
+ f:write("return utilitydata")
f:close()
end
statistics.stoptiming(_save_)
end
local function load(filename)
- local data = io.loaddata(filename)
- if data and data ~= "" then
- local version = tonumber(match(data,"^-- version: ([%d%.]+)"))
- if version ~= job.version then
- report_jobcontrol("version mismatch with jobfile: %s <> %s", version or "?", job.version)
+ if lfs.isfile(filename) then
+ local okay, data = pcall(dofile,filename)
+ if okay and type(data) == "table" then
+ local jobversion = job.version
+ local datacomment = data.comment
+ local dataversion = datacomment and datacomment.version or "?"
+ if dataversion ~= jobversion then
+ report_passes("version mismatch: %s <> %s",dataversion,jobversion)
+ else
+ return data
+ end
else
- local data = loadstring(data)
- return data and data()
+ os.remove(filename) -- probably a bad file
+ report_passes("removing stale job data file %a, restart job",filename)
+ os.exit(true) -- trigger second run
end
end
end
@@ -198,10 +202,14 @@ function job.load(filename)
local target = list[1]
local initializer = list[3]
local result = accesstable(target,utilitydata)
- packers.unpack(result,jobpacker,true)
- migratetable(target,mark(result))
- if type(initializer) == "function" then
- initializer(result)
+ local done = packers.unpack(result,jobpacker,true)
+ if done then
+ migratetable(target,mark(result))
+ if type(initializer) == "function" then
+ initializer(result)
+ end
+ else
+ report_passes("pack version mismatch")
end
end
end
@@ -219,8 +227,10 @@ function job.loadother(filename)
local list = savelist[l]
local target = list[1]
local result = accesstable(target,utilitydata)
- packers.unpack(result,jobpacker,true)
- migratetable(target,result,unpacked)
+ local done = packers.unpack(result,jobpacker,true)
+ if done then
+ migratetable(target,result,unpacked)
+ end
end
unpacked.job.packed = nil -- nicer in inspecting
return unpacked
@@ -252,7 +262,7 @@ end)
statistics.register("callbacks", function()
local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
- local pages = tex.count['realpageno'] - 1
+ local pages = texcount['realpageno'] - 1
if pages > 1 then
return format("direct: %s, indirect: %s, total: %s (%i per page)", total-indirect, indirect, total, total/pages)
else
@@ -268,8 +278,11 @@ end)
function statistics.formatruntime(runtime)
if not environment.initex then -- else error when testing as not counters yet
- local shipped = tex.count['nofshipouts']
- local pages = tex.count['realpageno'] - 1
+ local shipped = texcount['nofshipouts']
+ local pages = texcount['realpageno']
+ if pages > shipped then
+ pages = shipped
+ end
if shipped > 0 or pages > 0 then
local persecond = shipped / runtime
if pages == 0 then pages = shipped end