diff options
author | Marius <mariausol@gmail.com> | 2011-04-22 19:40:44 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2011-04-22 19:40:44 +0300 |
commit | 6f891b8572f03990803f9cb1ceb5870fcbe4d240 (patch) | |
tree | 419dc45860d70876c4a7e590eae9fc38cfcde8a0 | |
parent | 48aee08be6614bf30710ae7c42248f64d55f8f22 (diff) | |
download | context-6f891b8572f03990803f9cb1ceb5870fcbe4d240.tar.gz |
beta 2011.04.22 18:17
23 files changed, 610 insertions, 179 deletions
diff --git a/scripts/context/lua/mtx-colors.lua b/scripts/context/lua/mtx-colors.lua index ee825a42c..2a51d5099 100644 --- a/scripts/context/lua/mtx-colors.lua +++ b/scripts/context/lua/mtx-colors.lua @@ -17,7 +17,7 @@ mtxrun --script color --table somename ]] local application = logs.application { - name = "mtx-cache", + name = "mtx-colors", banner = "ConTeXt Color Management 0.10", helpinfo = helpinfo, } diff --git a/scripts/context/lua/mtx-flac.lua b/scripts/context/lua/mtx-flac.lua new file mode 100644 index 000000000..dc7f89218 --- /dev/null +++ b/scripts/context/lua/mtx-flac.lua @@ -0,0 +1,216 @@ +if not modules then modules = { } end modules ['mtx-flac'] = { + version = 1.001, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- Written with Within Temptation's "The Unforgiven" in loopmode on +-- the speakers. The following code is also used for my occasional music +-- repository cleanup session using the code below. + +-- this can become l-flac.lua + +local sub, match, byte, lower = string.sub, string.match, string.byte, string.lower +local readstring, readnumber = io.readstring, io.readnumber +local concat = table.concat +local tonumber = tonumber +local tobitstring = number.tobitstring + +flac = flac or { } + +flac.report = string.format + +local splitter = lpeg.splitat("=") +local readers = { } + +readers[0] = function(f,size,target) -- not yet ok + local info = { } + target.info = info + info.minimum_block_size = readnumber(f,-2) + info.maximum_block_size = readnumber(f,-2) + info.minimum_frame_size = readnumber(f,-3) + info.maximum_frame_size = readnumber(f,-3) + local buffer = { } + for i=1,8 do + buffer[i] = tobitstring(readnumber(f,1)) + end + local bytes = concat(buffer) + info.sample_rate_in_hz = tonumber(sub(bytes, 1,20),2) -- 20 + info.number_of_channels = tonumber(sub(bytes,21,23),2) -- 3 + info.bits_per_sample = tonumber(sub(bytes,24,28),2) -- 5 + info.samples_in_stream = tonumber(sub(bytes,29,64),2) -- 36 + info.md5_signature = readstring(f,16) -- 128 +end + +readers[4] = function(f,size,target,banner) + local tags = { } + target.tags = tags + target.vendor = readstring(f,readnumber(f,-4)) + for i=1,readnumber(f,-4) do + local key, value = lpeg.match(splitter,readstring(f,readnumber(f,-4))) + tags[lower(key)] = value + end +end + +readers.default = function(f,size,target) + f:seek("cur",size) +end + +function flac.getmetadata(filename) + local f = io.open(filename, "rb") + if f then + local banner = readstring(f,4) + if banner == "fLaC" then + local data = { + banner = banner, + filename = filename, + filesize = lfs.attributes(filename,"size"), + } + while true do + local flag = readnumber(f,1) + local size = readnumber(f,3) + local last = flag > 127 + if last then + flag = flag - 128 + end + local reader = readers[flag] or readers.default + reader(f,size,data,banner) + if last then + return data + end + end + else + flac.report("no flac file: %s (%s)",filename,banner) + end + f:close() + else + flac.report("no file: %s",filename) + end +end + +function flac.savecollection(pattern,filename) + pattern = (pattern ~= "" and pattern) or "**/*.flac" + filename = (filename ~= "" and filename) or "music-collection.xml" + flac.report("identifying files using pattern %q" ,pattern) + local files = dir.glob(pattern) + flac.report("%s files found, analyzing files",#files) + local music = { } + for i=1,#files do + local data = flac.getmetadata(files[i]) + if data then + local tags = data.tags + local info = data.info + local artist = tags.artist + local album = tags.album + local albums = music[artist] + if not albums then + albums = { } + music[artist] = albums + end + local albumx = albums[album] + if not albumx then + albumx = { + year = tags.date, + tracks = { }, + } + albums[album] = albumx + end + albumx.tracks[tonumber(tags.tracknumber) or 0] = { + title = tags.title, + length = math.round((info.samples_in_stream/info.sample_rate_in_hz)), + } + end + end + -- inspect(music) + local nofartists, nofalbums, noftracks, noferrors = 0, 0, 0, 0 + local f = io.open(filename,"wb") + if f then + f:write("<?xml version='1.0' standalone='yes'?>\n\n") + f:write("<collection>\n") + for artist, albums in table.sortedpairs(music) do + nofartists = nofartists + 1 + f:write("\t<artist>\n") + f:write("\t\t<name>" .. artist .. "</name>\n") + f:write("\t\t\t<albums>\n") + for album, data in table.sortedpairs(albums) do + nofalbums = nofalbums + 1 + f:write("\t\t\t\t<album year='" .. (data.year or 0) .. "'>\n") + f:write("\t\t\t\t\t<name>" .. album .. "</name>\n") + f:write("\t\t\t\t\t<tracks>\n") + local tracks = data.tracks + for i=1,#tracks do + local track = tracks[i] + if track then + noftracks = noftracks + 1 + f:write("\t\t\t\t\t\t<track length='" .. track.length .. "'>" .. track.title .. "</track>\n") + else + noferrors = noferrors + 1 + flac.report("error in album: %q of artist",album,artist) + f:write("\t\t\t\t\t\t<error track='" .. i .. "'/>\n") + end + end + f:write("\t\t\t\t\t</tracks>\n") + f:write("\t\t\t\t</album>\n") + end + f:write("\t\t\t</albums>\n") + f:write("\t\t</artist>\n") + end + f:write("</collection>\n") + end + f:close() + flac.report("%s tracks of %s albums of %s artists saved in %q (%s errors)",noftracks,nofalbums,nofartists,filename,noferrors) +end + +-- + +local helpinfo = [[ +--collect collect albums in xml file + +example: + +mtxrun --collect somename.flac +mtxrun --collect --pattern="m:/music/**") +]] + +local application = logs.application { + name = "mtx-flac", + banner = "ConTeXt Flac Helpers 0.10", + helpinfo = helpinfo, +} + +flac.report = application.report + +-- script code + +scripts = scripts or { } +scripts.flac = scripts.flac or { } + +function scripts.flac.collect() + local files = environment.files + local pattern = environment.arguments.pattern + if #files > 0 then + for i=1,#files do + local filename = files[1] + if file.suffix(filename) == "flac" then + flac.savecollection(filename,file.replacesuffix(filename,"xml")) + elseif lfs.isdir(filename) then + local pattern = filename .. "/**.flac" + flac.savecollection(pattern,file.addsuffix(file.basename(filename),"xml")) + else + flac.savecollection(file.replacesuffix(filename,"flac"),file.replacesuffix(filename,"xml")) + end + end + elseif pattern then + flac.savecollection(file.addsuffix(pattern,"flac"),"music-collection.xml") + else + flac.report("no file(s) or pattern given" ) + end +end + +if environment.argument("collect") then + scripts.flac.collect() +else + application.help() +end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 2f81b4629..f399b90a4 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1683,8 +1683,6 @@ local nextchar = { function io.characters(f,n) if f then return nextchar[n or 1], f - else - return nil, nil end end @@ -1693,40 +1691,42 @@ local nextbyte = { local a, b, c, d = f:read(1,1,1,1) if d then return byte(a), byte(b), byte(c), byte(d) - else - return nil, nil, nil, nil + end + end, + [3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(a), byte(b), byte(c) end end, [2] = function(f) local a, b = f:read(1,1) if b then return byte(a), byte(b) - else - return nil, nil end end, [1] = function (f) local a = f:read(1) if a then return byte(a) - else - return nil end end, [-2] = function (f) local a, b = f:read(1,1) if b then return byte(b), byte(a) - else - return nil, nil + end + end, + [-3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(c), byte(b), byte(a) end end, [-4] = function(f) local a, b, c, d = f:read(1,1,1,1) if d then return byte(d), byte(c), byte(b), byte(a) - else - return nil, nil, nil, nil end end } @@ -1782,10 +1782,13 @@ local function readnumber(f,n,m) return byte(f:read(1)) elseif n == 2 then local a, b = byte(f:read(2),1,2) - return 256*a + b + return 256 * a + b + elseif n == 3 then + local a, b, c = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == 4 then local a, b, c, d = byte(f:read(4),1,4) - return 256*256*256 * a + 256*256 * b + 256*c + d + return 256*256*256 * a + 256*256 * b + 256 * c + d elseif n == 8 then local a, b = readnumber(f,4), readnumber(f,4) return 256 * a + b @@ -1795,9 +1798,22 @@ local function readnumber(f,n,m) elseif n == -2 then local b, a = byte(f:read(2),1,2) return 256*a + b + elseif n == -3 then + local c, b, a = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == -4 then local d, c, b, a = byte(f:read(4),1,4) return 256*256*256 * a + 256*256 * b + 256*c + d + elseif n == -8 then + local h, g, f, e, d, c, b, a = byte(f:read(8),1,8) + return 256*256*256*256*256*256*256 * a + + 256*256*256*256*256*256 * b + + 256*256*256*256*256 * c + + 256*256*256*256 * d + + 256*256*256 * e + + 256*256 * f + + 256 * g + + h else return 0 end @@ -1830,7 +1846,7 @@ if not modules then modules = { } end modules ['l-number'] = { -- this module will be replaced when we have the bit library local tostring = tostring -local format, floor, insert, match = string.format, math.floor, string.match +local format, floor, match, rep = string.format, math.floor, string.match, string.rep local concat, insert = table.concat, table.insert local lpegmatch = lpeg.match @@ -1900,27 +1916,37 @@ function number.clearbit(x, p) end -function number.tobitstring(n) +function number.tobitstring(n,m) if n == 0 then - return "00000000" + if m then + rep("00000000",m) + else + return "00000000" + end else - tc = 0 - t = {} + local t = { } while n > 0 do - table.insert(t,1,n % 2 > 0 and 1 or 0) - n = math.floor(n/2) - tc = tc + 1 - end - while tc % 8 > 0 do - table.insert(t,1,0) - tc = tc + 1 - end - n = table.concat(t) - return n + insert(t,1,n % 2 > 0 and 1 or 0) + n = floor(n/2) + end + local nn = 8 - #t % 8 + if nn > 0 and nn < 8 then + for i=1,nn do + insert(t,1,0) + end + end + if m then + m = m * 8 - #t + if m > 0 then + insert(t,1,rep("0",m)) + end + end + return concat(t) end end + end -- of closure do -- create closure to overcome 200 locals limit @@ -8638,6 +8664,15 @@ function xml.collected(root,pattern,reverse) -- e return wrap(function() end) end +-- handy + +function xml.inspect(collection,pattern) + pattern = pattern or "." + for e in xml.collected(collection,pattern or ".") do + report_lpath("pattern %q\n\n%s\n",pattern,xml.tostring(e)) + end +end + end -- of closure diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 2f81b4629..f399b90a4 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1683,8 +1683,6 @@ local nextchar = { function io.characters(f,n) if f then return nextchar[n or 1], f - else - return nil, nil end end @@ -1693,40 +1691,42 @@ local nextbyte = { local a, b, c, d = f:read(1,1,1,1) if d then return byte(a), byte(b), byte(c), byte(d) - else - return nil, nil, nil, nil + end + end, + [3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(a), byte(b), byte(c) end end, [2] = function(f) local a, b = f:read(1,1) if b then return byte(a), byte(b) - else - return nil, nil end end, [1] = function (f) local a = f:read(1) if a then return byte(a) - else - return nil end end, [-2] = function (f) local a, b = f:read(1,1) if b then return byte(b), byte(a) - else - return nil, nil + end + end, + [-3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(c), byte(b), byte(a) end end, [-4] = function(f) local a, b, c, d = f:read(1,1,1,1) if d then return byte(d), byte(c), byte(b), byte(a) - else - return nil, nil, nil, nil end end } @@ -1782,10 +1782,13 @@ local function readnumber(f,n,m) return byte(f:read(1)) elseif n == 2 then local a, b = byte(f:read(2),1,2) - return 256*a + b + return 256 * a + b + elseif n == 3 then + local a, b, c = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == 4 then local a, b, c, d = byte(f:read(4),1,4) - return 256*256*256 * a + 256*256 * b + 256*c + d + return 256*256*256 * a + 256*256 * b + 256 * c + d elseif n == 8 then local a, b = readnumber(f,4), readnumber(f,4) return 256 * a + b @@ -1795,9 +1798,22 @@ local function readnumber(f,n,m) elseif n == -2 then local b, a = byte(f:read(2),1,2) return 256*a + b + elseif n == -3 then + local c, b, a = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == -4 then local d, c, b, a = byte(f:read(4),1,4) return 256*256*256 * a + 256*256 * b + 256*c + d + elseif n == -8 then + local h, g, f, e, d, c, b, a = byte(f:read(8),1,8) + return 256*256*256*256*256*256*256 * a + + 256*256*256*256*256*256 * b + + 256*256*256*256*256 * c + + 256*256*256*256 * d + + 256*256*256 * e + + 256*256 * f + + 256 * g + + h else return 0 end @@ -1830,7 +1846,7 @@ if not modules then modules = { } end modules ['l-number'] = { -- this module will be replaced when we have the bit library local tostring = tostring -local format, floor, insert, match = string.format, math.floor, string.match +local format, floor, match, rep = string.format, math.floor, string.match, string.rep local concat, insert = table.concat, table.insert local lpegmatch = lpeg.match @@ -1900,27 +1916,37 @@ function number.clearbit(x, p) end -function number.tobitstring(n) +function number.tobitstring(n,m) if n == 0 then - return "00000000" + if m then + rep("00000000",m) + else + return "00000000" + end else - tc = 0 - t = {} + local t = { } while n > 0 do - table.insert(t,1,n % 2 > 0 and 1 or 0) - n = math.floor(n/2) - tc = tc + 1 - end - while tc % 8 > 0 do - table.insert(t,1,0) - tc = tc + 1 - end - n = table.concat(t) - return n + insert(t,1,n % 2 > 0 and 1 or 0) + n = floor(n/2) + end + local nn = 8 - #t % 8 + if nn > 0 and nn < 8 then + for i=1,nn do + insert(t,1,0) + end + end + if m then + m = m * 8 - #t + if m > 0 then + insert(t,1,rep("0",m)) + end + end + return concat(t) end end + end -- of closure do -- create closure to overcome 200 locals limit @@ -8638,6 +8664,15 @@ function xml.collected(root,pattern,reverse) -- e return wrap(function() end) end +-- handy + +function xml.inspect(collection,pattern) + pattern = pattern or "." + for e in xml.collected(collection,pattern or ".") do + report_lpath("pattern %q\n\n%s\n",pattern,xml.tostring(e)) + end +end + end -- of closure diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 2f81b4629..f399b90a4 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1683,8 +1683,6 @@ local nextchar = { function io.characters(f,n) if f then return nextchar[n or 1], f - else - return nil, nil end end @@ -1693,40 +1691,42 @@ local nextbyte = { local a, b, c, d = f:read(1,1,1,1) if d then return byte(a), byte(b), byte(c), byte(d) - else - return nil, nil, nil, nil + end + end, + [3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(a), byte(b), byte(c) end end, [2] = function(f) local a, b = f:read(1,1) if b then return byte(a), byte(b) - else - return nil, nil end end, [1] = function (f) local a = f:read(1) if a then return byte(a) - else - return nil end end, [-2] = function (f) local a, b = f:read(1,1) if b then return byte(b), byte(a) - else - return nil, nil + end + end, + [-3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(c), byte(b), byte(a) end end, [-4] = function(f) local a, b, c, d = f:read(1,1,1,1) if d then return byte(d), byte(c), byte(b), byte(a) - else - return nil, nil, nil, nil end end } @@ -1782,10 +1782,13 @@ local function readnumber(f,n,m) return byte(f:read(1)) elseif n == 2 then local a, b = byte(f:read(2),1,2) - return 256*a + b + return 256 * a + b + elseif n == 3 then + local a, b, c = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == 4 then local a, b, c, d = byte(f:read(4),1,4) - return 256*256*256 * a + 256*256 * b + 256*c + d + return 256*256*256 * a + 256*256 * b + 256 * c + d elseif n == 8 then local a, b = readnumber(f,4), readnumber(f,4) return 256 * a + b @@ -1795,9 +1798,22 @@ local function readnumber(f,n,m) elseif n == -2 then local b, a = byte(f:read(2),1,2) return 256*a + b + elseif n == -3 then + local c, b, a = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == -4 then local d, c, b, a = byte(f:read(4),1,4) return 256*256*256 * a + 256*256 * b + 256*c + d + elseif n == -8 then + local h, g, f, e, d, c, b, a = byte(f:read(8),1,8) + return 256*256*256*256*256*256*256 * a + + 256*256*256*256*256*256 * b + + 256*256*256*256*256 * c + + 256*256*256*256 * d + + 256*256*256 * e + + 256*256 * f + + 256 * g + + h else return 0 end @@ -1830,7 +1846,7 @@ if not modules then modules = { } end modules ['l-number'] = { -- this module will be replaced when we have the bit library local tostring = tostring -local format, floor, insert, match = string.format, math.floor, string.match +local format, floor, match, rep = string.format, math.floor, string.match, string.rep local concat, insert = table.concat, table.insert local lpegmatch = lpeg.match @@ -1900,27 +1916,37 @@ function number.clearbit(x, p) end -function number.tobitstring(n) +function number.tobitstring(n,m) if n == 0 then - return "00000000" + if m then + rep("00000000",m) + else + return "00000000" + end else - tc = 0 - t = {} + local t = { } while n > 0 do - table.insert(t,1,n % 2 > 0 and 1 or 0) - n = math.floor(n/2) - tc = tc + 1 - end - while tc % 8 > 0 do - table.insert(t,1,0) - tc = tc + 1 - end - n = table.concat(t) - return n + insert(t,1,n % 2 > 0 and 1 or 0) + n = floor(n/2) + end + local nn = 8 - #t % 8 + if nn > 0 and nn < 8 then + for i=1,nn do + insert(t,1,0) + end + end + if m then + m = m * 8 - #t + if m > 0 then + insert(t,1,rep("0",m)) + end + end + return concat(t) end end + end -- of closure do -- create closure to overcome 200 locals limit @@ -8638,6 +8664,15 @@ function xml.collected(root,pattern,reverse) -- e return wrap(function() end) end +-- handy + +function xml.inspect(collection,pattern) + pattern = pattern or "." + for e in xml.collected(collection,pattern or ".") do + report_lpath("pattern %q\n\n%s\n",pattern,xml.tostring(e)) + end +end + end -- of closure diff --git a/tex/context/base/cldf-ini.mkiv b/tex/context/base/cldf-ini.mkiv index 5f7e31ae7..8aef17f93 100644 --- a/tex/context/base/cldf-ini.mkiv +++ b/tex/context/base/cldf-ini.mkiv @@ -15,6 +15,20 @@ \registerctxluafile{cldf-ini}{1.001} +%D With each new update of \MKIV\ we can join Within Temptation in +%D singing: +%D +%D \startbuffer +%D \startluacode +%D context("I go faster%s",string.rep(" and faster",6)) +%D \stopluacode +%D +%D \cldcontext{"I go faster\letterpercent s", +%D string.rep(" and faster",6)} +%D \stopbuffer +%D +%D \typebuffer \getbuffer + \def\cldf#1{\directlua\zerocount{_cldf_(#1)}} % global (functions) \def\cldn#1{\directlua\zerocount{_cldn_(#1)}} % global (nodes) diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 5075f36f5..f18aa4a2c 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.04.20 16:23} +\newcontextversion{2011.04.22 18:17} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 3c4f74b42..cd2518e64 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.04.20 16:23} +\newcontextversion{2011.04.22 18:17} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index e34e83e42..9b252fc19 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.04.20 16:23} +\edef\contextversion{2011.04.22 18:17} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index c210f5667..9b783a093 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.04.20 16:23} +\edef\contextversion{2011.04.22 18:17} %D For those who want to use this: diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index 486300bc1..7d7b1253b 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -6,7 +6,8 @@ if not modules then modules = { } end modules ['font-ctx'] = { license = "see context related readme files" } --- split in definition and specifiers (as these need to come before goodies) +-- At some point I will clean up the code here so that at the tex end +-- the table interface is used. local texcount, texsetcount = tex.count, tex.setcount local format, gmatch, match, find, lower, gsub, byte = string.format, string.gmatch, string.match, string.find, string.lower, string.gsub, string.byte diff --git a/tex/context/base/l-io.lua b/tex/context/base/l-io.lua index 290dcec42..a740996c6 100644 --- a/tex/context/base/l-io.lua +++ b/tex/context/base/l-io.lua @@ -106,8 +106,6 @@ local nextchar = { function io.characters(f,n) if f then return nextchar[n or 1], f - else - return nil, nil end end @@ -116,40 +114,42 @@ local nextbyte = { local a, b, c, d = f:read(1,1,1,1) if d then return byte(a), byte(b), byte(c), byte(d) - else - return nil, nil, nil, nil + end + end, + [3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(a), byte(b), byte(c) end end, [2] = function(f) local a, b = f:read(1,1) if b then return byte(a), byte(b) - else - return nil, nil end end, [1] = function (f) local a = f:read(1) if a then return byte(a) - else - return nil end end, [-2] = function (f) local a, b = f:read(1,1) if b then return byte(b), byte(a) - else - return nil, nil + end + end, + [-3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(c), byte(b), byte(a) end end, [-4] = function(f) local a, b, c, d = f:read(1,1,1,1) if d then return byte(d), byte(c), byte(b), byte(a) - else - return nil, nil, nil, nil end end } @@ -205,10 +205,13 @@ local function readnumber(f,n,m) return byte(f:read(1)) elseif n == 2 then local a, b = byte(f:read(2),1,2) - return 256*a + b + return 256 * a + b + elseif n == 3 then + local a, b, c = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == 4 then local a, b, c, d = byte(f:read(4),1,4) - return 256*256*256 * a + 256*256 * b + 256*c + d + return 256*256*256 * a + 256*256 * b + 256 * c + d elseif n == 8 then local a, b = readnumber(f,4), readnumber(f,4) return 256 * a + b @@ -218,9 +221,22 @@ local function readnumber(f,n,m) elseif n == -2 then local b, a = byte(f:read(2),1,2) return 256*a + b + elseif n == -3 then + local c, b, a = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == -4 then local d, c, b, a = byte(f:read(4),1,4) return 256*256*256 * a + 256*256 * b + 256*c + d + elseif n == -8 then + local h, g, f, e, d, c, b, a = byte(f:read(8),1,8) + return 256*256*256*256*256*256*256 * a + + 256*256*256*256*256*256 * b + + 256*256*256*256*256 * c + + 256*256*256*256 * d + + 256*256*256 * e + + 256*256 * f + + 256 * g + + h else return 0 end diff --git a/tex/context/base/l-number.lua b/tex/context/base/l-number.lua index 9e99667cd..b1ffb9ca9 100644 --- a/tex/context/base/l-number.lua +++ b/tex/context/base/l-number.lua @@ -9,7 +9,7 @@ if not modules then modules = { } end modules ['l-number'] = { -- this module will be replaced when we have the bit library local tostring = tostring -local format, floor, insert, match = string.format, math.floor, string.match +local format, floor, match, rep = string.format, math.floor, string.match, string.rep local concat, insert = table.concat, table.insert local lpegmatch = lpeg.match @@ -92,22 +92,39 @@ end --~ end --~ end -function number.tobitstring(n) +function number.tobitstring(n,m) if n == 0 then - return "00000000" + if m then + rep("00000000",m) + else + return "00000000" + end else - tc = 0 - t = {} + local t = { } while n > 0 do - table.insert(t,1,n % 2 > 0 and 1 or 0) - n = math.floor(n/2) - tc = tc + 1 - end - while tc % 8 > 0 do - table.insert(t,1,0) - tc = tc + 1 + insert(t,1,n % 2 > 0 and 1 or 0) + n = floor(n/2) + end + local nn = 8 - #t % 8 + if nn > 0 and nn < 8 then + for i=1,nn do + insert(t,1,0) + end end - n = table.concat(t) - return n + if m then + m = m * 8 - #t + if m > 0 then + insert(t,1,rep("0",m)) + end + end + return concat(t) end end + +--~ print(number.tobitstring(8)) +--~ print(number.tobitstring(14)) +--~ print(number.tobitstring(66)) +--~ print(number.tobitstring(0x00)) +--~ print(number.tobitstring(0xFF)) +--~ print(number.tobitstring(46260767936,8)) +--~ print(#number.tobitstring(46260767936,6)) diff --git a/tex/context/base/lang-lab.mkiv b/tex/context/base/lang-lab.mkiv index d7a705627..025958ade 100644 --- a/tex/context/base/lang-lab.mkiv +++ b/tex/context/base/lang-lab.mkiv @@ -77,24 +77,44 @@ \expandafter\noexpand\csname #1texts\endcsname \expandafter\noexpand\csname #1text\endcsname}} +\let\currentlabelcategory\empty + \def\dododefinelabelclass#1#2#3#4#5#6#7#8#9% {\setuvalue{setup#1text}{\protecttextprefixes#2\def\currenttextprefixclass{#1}\dodoubleempty\dosetupsometextprefix}% \setuvalue{preset#1text}{\protecttextprefixes1\def\currenttextprefixclass{#1}\dodoubleempty\dosetupsometextprefix}% \def#4{\reallanguagetag{\defaultlanguage\currentmainlanguage}}% \ifnum#2=\plustwo \def#3{#5#4}% +% \def#5##1##2% ##1=language +% {\ifcsname\??ml:#1:##1:##2\endcsname +% \csname\??ml:#1:##1:##2\endcsname +% \else\ifcsname\??la#4\s!default\endcsname +% \expandafter#5\csname\??la#4\s!default\endcsname{##2}% +% \else\ifcsname\??ml:#1:##2\endcsname +% \csname\??ml:#1:##2\endcsname +% \else\ifcsname\??ml:#1:\s!en:##2\endcsname +% \csname\??ml:#1:\s!en:##2\endcsname +% \else +% ##2% +% \fi\fi\fi\fi}% \def#5##1##2% ##1=language - {\ifcsname\??ml:#1:##1:##2\endcsname + {\ifcsname\??ml:\currentlabelcategory#1:##1:##2\endcsname + \csname\??ml:\currentlabelcategory#1:##1:##2\endcsname + \else\ifcsname\??ml:#1:##1:##2\endcsname \csname\??ml:#1:##1:##2\endcsname \else\ifcsname\??la#4\s!default\endcsname \expandafter#5\csname\??la#4\s!default\endcsname{##2}% + \else\ifcsname\??ml:\currentlabelcategory#1:##2\endcsname + \csname\??ml:\currentlabelcategory#1:##2\endcsname \else\ifcsname\??ml:#1:##2\endcsname \csname\??ml:#1:##2\endcsname + \else\ifcsname\??ml:\currentlabelcategory#1:\s!en:##2\endcsname + \csname\??ml:\currentlabelcategory#1:\s!en:##2\endcsname \else\ifcsname\??ml:#1:\s!en:##2\endcsname \csname\??ml:#1:\s!en:##2\endcsname \else ##2% - \fi\fi\fi\fi}% + \fi\fi\fi\fi\fi\fi\fi}% \let#6\gobbleoneargument \let#7\gobbleoneargument \let#8\gobbletwoarguments diff --git a/tex/context/base/lpdf-fld.lua b/tex/context/base/lpdf-fld.lua index ec09a00ee..9445333d7 100644 --- a/tex/context/base/lpdf-fld.lua +++ b/tex/context/base/lpdf-fld.lua @@ -249,9 +249,10 @@ local function fieldsurrounding(specification) end local tag = fontstyle .. fontalternative fontsize = todimen(fontsize) - fontsize = (fontsize and (bpfactor * fontsize)) or 12 + fontsize = fontsize and (bpfactor * fontsize) or 12 fontraise = 0.1 * fontsize -- todo: figure out what the natural one is and compensate for strutdp local fontcode = format("%0.4f Tf %0.4f Ts",fontsize,fontraise) + -- we could test for colorvalue being 1 (black) and omit it then local colorcode = lpdf.color(3,colorvalue) -- we force an rgb color space if trace_fields then report_fields("fontcode : %s %s @ %s => %s => %s",fontstyle,fontalternative,fontsize,tag,fontcode) @@ -426,7 +427,7 @@ local function fieldrendering(specification) local bvalue = tonumber(specification.backgroundcolorvalue) local fvalue = tonumber(specification.framecolorvalue) local svalue = specification.fontsymbol - if bvalue or fvalue or svalue then + if bvalue or fvalue or (svalue and svalue ~= "") then return pdfdictionary { BG = bvalue and pdfarray { lpdf.colorvalues(3,bvalue) } or nil, BC = fvalue and pdfarray { lpdf.colorvalues(3,fvalue) } or nil, diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index db8958c14..aa0b0a22e 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -1327,3 +1327,12 @@ function xml.collected(root,pattern,reverse) -- e end return wrap(function() end) end + +-- handy + +function xml.inspect(collection,pattern) + pattern = pattern or "." + for e in xml.collected(collection,pattern or ".") do + report_lpath("pattern %q\n\n%s\n",pattern,xml.tostring(e)) + end +end diff --git a/tex/context/base/page-lay.mkiv b/tex/context/base/page-lay.mkiv index 55608d590..4fa00ab90 100644 --- a/tex/context/base/page-lay.mkiv +++ b/tex/context/base/page-lay.mkiv @@ -316,7 +316,8 @@ {\doifelsenothing{#2} {\expanded{\dodosetuppapersize [\executeifdefined{\??pp:1:#1}{#1}]% - [\executeifdefined{\??pp:2:#1}{\v!default}]}} +% [\executeifdefined{\??pp:2:#1}{\v!default}]}} + [\executeifdefined{\??pp:2:#1}{#1}]}} {\doifassignmentelse{#2} {\getparameters[\??pp\executeifdefined{\??pp:1:#1}{#1}][#2]} {\expanded{\dodosetuppapersize @@ -1425,15 +1426,15 @@ %D paper size with the typeset paper size. This setting should %D come after the first layout specification (already done). -\definepapersize - [\v!default] - [ \c!width=\paperwidth, - \c!height=\paperheight] +% \definepapersize +% [\v!default] +% [ \c!width=\paperwidth, +% \c!height=\paperheight] -\definepapersize - [samesized] - [ \c!width=\paperwidth, - \c!height=\paperheight] +% \definepapersize +% [samesized] +% [ \c!width=\paperwidth, +% \c!height=\paperheight] \definepapersize [oversized] diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 7a6da08e2..03ad47eb3 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 2bd85687e..554a3d15f 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/strc-lst.lua b/tex/context/base/strc-lst.lua index 6a7a7d8c7..086f42c93 100644 --- a/tex/context/base/strc-lst.lua +++ b/tex/context/base/strc-lst.lua @@ -489,6 +489,14 @@ function lists.location(n) texsprint(l.references.internal or n) end +function lists.label(n) + local l = lists.result[n] + local t = l.titledata + if t then + texsprint(t.label) + end +end + function lists.sectionnumber(name,n,spec) local data = lists.result[n] local sectiondata = sections.collected[data.references.section] diff --git a/tex/context/base/strc-lst.mkiv b/tex/context/base/strc-lst.mkiv index c764b889b..26e2392bd 100644 --- a/tex/context/base/strc-lst.mkiv +++ b/tex/context/base/strc-lst.mkiv @@ -550,28 +550,34 @@ \endgroup} \def\listsymbol@default - {% prefix = no, none, yes - \strut - \doif{\listparameter\c!label}\v!yes{\leftlabeltext\currentlist}% we can use the new command that does left and right - \listparameter\c!starter - \currentlistnumber - \listparameter\c!stopper - \doif{\listparameter\c!label}\v!yes{\rightlabeltext\currentlist}} - -\def\listsymbol@default - {% todo: - % prefix=no (first gone)|none (all gone)|yes - % number=no|yes - \strut - \doifelse{\listparameter\c!label}\v!yes - {\leftlabeltext\currentlist - \listparameter\c!starter - \currentlistnumber - \listparameter\c!stopper - \rightlabeltext\currentlist} - {\listparameter\c!starter - \currentlistnumber - \listparameter\c!stopper}} + {\strut + \begingroup + \edef\currentlistlabel{\listparameter\c!label}% + \ifx\currentlistlabel\empty % default + \listparameter\c!starter + \currentlistnumber + \listparameter\c!stopper + \else\ifx\currentlistlabel\v!no % also default + \listparameter\c!starter + \currentlistnumber + \listparameter\c!stopper + \else\ifx\currentlistlabel\v!none % real minimal (as suggested by WS) + \currentlistnumber + \else\ifx\currentlistlabel\v!yes % auto (use value stored in tuc file) + \edef\currentlistlabel{\ctxlua{structures.lists.label(\currentlistindex)}}% + \leftlabeltext\currentlistlabel + \listparameter\c!starter + \currentlistnumber + \listparameter\c!stopper + \rightlabeltext\currentlistlabel + \else % use whatever is set + \leftlabeltext\currentlistlabel + \listparameter\c!starter + \currentlistnumber + \listparameter\c!stopper + \rightlabeltext\currentlistlabel + \fi\fi\fi\fi + \endgroup} \def\listsymbol@unknown {\listparameter\c!symbol} diff --git a/tex/context/base/strc-sec.mkiv b/tex/context/base/strc-sec.mkiv index 350d971a2..6cb6f84c1 100644 --- a/tex/context/base/strc-sec.mkiv +++ b/tex/context/base/strc-sec.mkiv @@ -54,15 +54,15 @@ % interface -\def\structureheadparameter #1{\csname\dostructureheadparameter{\??nh\currentstructurehead}#1\endcsname} -\def\structureheadparameterhash #1{\dostructureheadparameterhash {\??nh\currentstructurehead}#1} -\def\namedstructureheadparameter#1#2{\csname\dostructureheadparameter{\??nh#1}#2\endcsname} +\def\structureheadparameter #1{\csname\dostructureheadparameter{\??nh\currentstructurehead}{#1}\endcsname} +\def\structureheadparameterhash #1{\dostructureheadparameterhash {\??nh\currentstructurehead}{#1}} +\def\namedstructureheadparameter#1#2{\csname\dostructureheadparameter{\??nh#1}{#2}\endcsname} -\def\dostructureheadparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dostructureheadparentparameter \csname#1\s!parent\endcsname#2\fi} -\def\dostructureheadparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\dostructureheadparentparameterhash\csname#1\s!parent\endcsname#2\fi} +\def\dostructureheadparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dostructureheadparentparameter \csname#1\s!parent\endcsname{#2}\fi} +\def\dostructureheadparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\dostructureheadparentparameterhash\csname#1\s!parent\endcsname{#2}\fi} -\def\dostructureheadparentparameter #1#2{\ifx#1\relax\s!empty\else\dostructureheadparameter #1#2\fi} -\def\dostructureheadparentparameterhash#1#2{\ifx#1\relax \else\dostructureheadparameterhash#1#2\fi} +\def\dostructureheadparentparameter #1#2{\ifx#1\relax\s!empty\else\dostructureheadparameter #1{#2}\fi} +\def\dostructureheadparentparameterhash#1#2{\ifx#1\relax \else\dostructureheadparameterhash#1{#2}\fi} \def\structureheadparameterstrict#1{\csname\ifcsname\??nh\currentstructurehead#1\endcsname\??nh\currentstructurehead#1\else\s!empty\fi\endcsname} @@ -481,7 +481,8 @@ \def\doregisterstructurehead#1#2#3% name data userdata {\structurecomponent - [\c!label={\structureheadparameter\c!label}, % why { } + %[\c!label={\structureheadparameter\c!label}, % why { } + [\c!label={\structureheadparameter{\currentstructureblock\c!label}}, \c!incrementnumber=\ifconditional\structureheaddoincrement\v!yes\else\v!no\fi, % not that needed \c!saveinlist=\ifconditional\structureheadtolist\v!yes\else\v!no\fi, \c!level=\currentstructureheadlevel, diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 01e745f62..e2c86f1ac 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 04/20/11 16:23:12 +-- merge date : 04/22/11 18:17:39 do -- begin closure to overcome local limits and interference @@ -2243,8 +2243,6 @@ local nextchar = { function io.characters(f,n) if f then return nextchar[n or 1], f - else - return nil, nil end end @@ -2253,40 +2251,42 @@ local nextbyte = { local a, b, c, d = f:read(1,1,1,1) if d then return byte(a), byte(b), byte(c), byte(d) - else - return nil, nil, nil, nil + end + end, + [3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(a), byte(b), byte(c) end end, [2] = function(f) local a, b = f:read(1,1) if b then return byte(a), byte(b) - else - return nil, nil end end, [1] = function (f) local a = f:read(1) if a then return byte(a) - else - return nil end end, [-2] = function (f) local a, b = f:read(1,1) if b then return byte(b), byte(a) - else - return nil, nil + end + end, + [-3] = function(f) + local a, b, c = f:read(1,1,1) + if b then + return byte(c), byte(b), byte(a) end end, [-4] = function(f) local a, b, c, d = f:read(1,1,1,1) if d then return byte(d), byte(c), byte(b), byte(a) - else - return nil, nil, nil, nil end end } @@ -2342,10 +2342,13 @@ local function readnumber(f,n,m) return byte(f:read(1)) elseif n == 2 then local a, b = byte(f:read(2),1,2) - return 256*a + b + return 256 * a + b + elseif n == 3 then + local a, b, c = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == 4 then local a, b, c, d = byte(f:read(4),1,4) - return 256*256*256 * a + 256*256 * b + 256*c + d + return 256*256*256 * a + 256*256 * b + 256 * c + d elseif n == 8 then local a, b = readnumber(f,4), readnumber(f,4) return 256 * a + b @@ -2355,9 +2358,22 @@ local function readnumber(f,n,m) elseif n == -2 then local b, a = byte(f:read(2),1,2) return 256*a + b + elseif n == -3 then + local c, b, a = byte(f:read(3),1,3) + return 256*256 * a + 256 * b + c elseif n == -4 then local d, c, b, a = byte(f:read(4),1,4) return 256*256*256 * a + 256*256 * b + 256*c + d + elseif n == -8 then + local h, g, f, e, d, c, b, a = byte(f:read(8),1,8) + return 256*256*256*256*256*256*256 * a + + 256*256*256*256*256*256 * b + + 256*256*256*256*256 * c + + 256*256*256*256 * d + + 256*256*256 * e + + 256*256 * f + + 256 * g + + h else return 0 end |