diff options
author | Marius <mariausol@gmail.com> | 2010-09-15 09:21:49 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2010-09-15 09:21:49 +0300 |
commit | 3baed6092e175a237fb3f11144b5abf990c80759 (patch) | |
tree | 704ba449a1cce3d75514d9431bf64322601adea1 /tex/context/base | |
parent | 37b0c79d3951304959d24218874992d125bf9854 (diff) | |
download | context-3baed6092e175a237fb3f11144b5abf990c80759.tar.gz |
beta 2010.09.14 23:27
Diffstat (limited to 'tex/context/base')
-rw-r--r-- | tex/context/base/cont-new.tex | 2 | ||||
-rw-r--r-- | tex/context/base/context.tex | 2 | ||||
-rw-r--r-- | tex/context/base/font-agl.lua | 1 | ||||
-rw-r--r-- | tex/context/base/font-dum.lua | 4 | ||||
-rw-r--r-- | tex/context/base/font-map.lua | 2 | ||||
-rw-r--r-- | tex/context/base/font-otf.lua | 4 | ||||
-rw-r--r-- | tex/context/base/luat-dum.lua | 7 | ||||
-rw-r--r-- | tex/context/base/luat-sta.lua | 14 | ||||
-rw-r--r-- | tex/context/base/m-database.lua | 89 | ||||
-rw-r--r-- | tex/context/base/m-database.mkii (renamed from tex/context/base/m-database.tex) | 0 | ||||
-rw-r--r-- | tex/context/base/m-database.mkiv | 207 | ||||
-rw-r--r-- | tex/context/base/node-dum.lua | 50 | ||||
-rw-r--r-- | tex/context/base/trac-set.lua | 3 |
13 files changed, 347 insertions, 38 deletions
diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index 6558c664b..50bdd2dce 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2010.09.14 10:28} +\newcontextversion{2010.09.14 23:27} %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.tex b/tex/context/base/context.tex index 887804b75..3e4cd9d8f 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2010.09.14 10:28} +\edef\contextversion{2010.09.14 23:27} %D For those who want to use this: diff --git a/tex/context/base/font-agl.lua b/tex/context/base/font-agl.lua index 729863618..820600acc 100644 --- a/tex/context/base/font-agl.lua +++ b/tex/context/base/font-agl.lua @@ -8,6 +8,7 @@ if not modules then modules = { } end modules ['font-map'] = { local allocate = utilities.storage.allocate +fonts.enc = fonts.enc or { } local enc = fonts.enc local agl = { } enc.agl = agl diff --git a/tex/context/base/font-dum.lua b/tex/context/base/font-dum.lua index 00663daf4..6e07a53ec 100644 --- a/tex/context/base/font-dum.lua +++ b/tex/context/base/font-dum.lua @@ -25,7 +25,7 @@ fonts.tfm.readers.afm = nil fonts.definers = fonts.definers or { } fonts.definers.specifiers = fonts.definers.specifiers or { } -fonts.definers.specifiers.specifiers.colonizedpreference = "name" -- is "file" in context +fonts.definers.specifiers.colonizedpreference = "name" -- is "file" in context function fonts.definers.getspecification(str) return "", str, "", ":", str @@ -262,7 +262,7 @@ end -- needed (different in context) -function otf.scriptandlanguage(tfmdata) +function fonts.otf.scriptandlanguage(tfmdata) return tfmdata.script, tfmdata.language end diff --git a/tex/context/base/font-map.lua b/tex/context/base/font-map.lua index 128e80eb9..5e7135013 100644 --- a/tex/context/base/font-map.lua +++ b/tex/context/base/font-map.lua @@ -165,7 +165,7 @@ fonts.map.addtounicode = function(data,filename) cidcodes = usedmap.unicodes end uparser = makenameparser() - local aglmap = fonts.enc.agl and fonts.enc.unicodes -- to name + local aglmap = fonts.enc and fonts.enc.agl -- to name for index, glyph in next, data.glyphs do local name, unic = glyph.name, glyph.unicode or -1 -- play safe if unic == -1 or unic >= private or (unic >= 0xE000 and unic <= 0xF8FF) or unic == 0xFFFE or unic == 0xFFFF then diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua index dec564993..be05b8271 100644 --- a/tex/context/base/font-otf.lua +++ b/tex/context/base/font-otf.lua @@ -442,7 +442,9 @@ function otf.load(filename,format,sub,featurefile) collectgarbage("collect") end stoptiming(data) - report_otf("preprocessing and caching took %s seconds",elapsedtime(data)) + if elapsedtime then -- not in generic + report_otf("preprocessing and caching took %s seconds",elapsedtime(data)) + end data = containers.read(otf.cache, hash) -- this frees the old table and load the sparse one if cleanup > 1 then collectgarbage("collect") diff --git a/tex/context/base/luat-dum.lua b/tex/context/base/luat-dum.lua index be886692a..bb3454fa3 100644 --- a/tex/context/base/luat-dum.lua +++ b/tex/context/base/luat-dum.lua @@ -12,6 +12,7 @@ statistics = { register = dummyfunction, starttiming = dummyfunction, stoptiming = dummyfunction, + elapsedtime = nil, } directives = { register = dummyfunction, @@ -41,8 +42,10 @@ callbacks = { register = function(n,f) return callback.register(n,f) end, } utilities = { - allocate = function(t) return t end, - mark = function(t) return t end, + storage = { + allocate = function(t) return t or { } end, + mark = function(t) return t or { } end, + }, } -- we need to cheat a bit here diff --git a/tex/context/base/luat-sta.lua b/tex/context/base/luat-sta.lua index 7e87b90fb..8b58774d3 100644 --- a/tex/context/base/luat-sta.lua +++ b/tex/context/base/luat-sta.lua @@ -60,8 +60,10 @@ local function set_by_tag(tag,key,value,default,persistent) end dkey, hkey = post, key end - if type(value) == nil then - value = value or default + if value == nil then + value = default + elseif value == false then + -- special case elseif persistent then value = value or d[dkey] or default else @@ -84,13 +86,17 @@ local function get_by_tag(tag,key,default) if d then for k in gmatch(key,"[^%.]+") do local dk = d[k] - if dk then + if dk ~= nil then d = dk else return default end end - return d or default + if d == false then + return false + else + return d or default + end end end end diff --git a/tex/context/base/m-database.lua b/tex/context/base/m-database.lua new file mode 100644 index 000000000..8d0d1e1e0 --- /dev/null +++ b/tex/context/base/m-database.lua @@ -0,0 +1,89 @@ +if not modules then modules = { } end modules ['m-database'] = { + version = 1.001, + comment = "companion to m-database.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local sub, gmatch = string.sub, string.gmatch +local lpegpatterns, lpegmatch, lpegsplitat = lpeg.patterns, lpeg.match, lpeg.splitat +local lpegP, lpegC, lpegS, lpegCt = lpeg.P, lpeg.C, lpeg.S, lpeg.Ct +local sprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes + +buffers.database = buffers.database or { } + +local separators = { -- not interfaced + tab = lpegpatterns.tab, + comma = lpegpatterns.comma, + space = lpegpatterns.space, + spaces = lpegpatterns.space^1, +} + +function buffers.database.process(settings) + -- table.print(settings) + local data + if settings.type == "file" then + local filename = resolvers.finders.any(settings.database) + data = filename ~= "" and io.loaddata(filename) + data = data and string.splitlines(data) + else + data = buffers.raw(settings.database) + end + if data and #data > 0 then + local separatorchar, quotechar, commentchar = settings.separator, settings.quotechar, settings.commentchar + local before, after = settings.before or "", settings.after or "" + local first, last = settings.first or "", settings.last or "" + local left, right = settings.left or "", settings.right or "" + local command = settings.command + separatorchar = (not separatorchar and ",") or separators[separatorchar] or separatorchar + local separator = type(separatorchar) == "string" and lpegS(separatorchar) or separatorchar + local whatever = lpegC((1 - separator)^0) + if quotechar and quotechar ~= "" then + local quotedata = nil + for chr in gmatch(quotechar,".") do + local quotechar = lpegP(chr) + local quoteword = quotechar * lpeg.C((1 - quotechar)^0) * quotechar + if quotedata then + quotedata = quotedata + quoteword + else + quotedata = quoteword + end + end + whatever = quotedata + whatever + end + local checker = commentchar ~= "" and lpeg.S(commentchar) + local splitter = lpegCt(whatever * (separator * whatever)^0) + local found = false + for i=1,#data do + local line = data[i] + if line ~= "" and (not checker or not lpegmatch(checker,line)) then + local list = lpegmatch(splitter,line) + if found then + sprint(ctxcatcodes,first) + else + local setups = settings.setups or "" + if setups == "" then + sprint(ctxcatcodes,"\\begingroup",before,first) + else + sprint(ctxcatcodes,"\\begingroup\\setups[",setups,"]",before,first) + end + found = true + end + for j=1,#list do + if command == "" then + sprint(ctxcatcodes,left,list[j],right) + else + sprint(ctxcatcodes,left,command,"{",list[j],"}",right) + end + end + sprint(ctxcatcodes,last) + end + end + if found then + sprint(ctxcatcodes,after,"\\endgroup") + end + else + -- message + end +end diff --git a/tex/context/base/m-database.tex b/tex/context/base/m-database.mkii index 3bb050f14..3bb050f14 100644 --- a/tex/context/base/m-database.tex +++ b/tex/context/base/m-database.mkii diff --git a/tex/context/base/m-database.mkiv b/tex/context/base/m-database.mkiv new file mode 100644 index 000000000..21be4365a --- /dev/null +++ b/tex/context/base/m-database.mkiv @@ -0,0 +1,207 @@ +%D \module +%D [ file=m-database, +%D version=2010.08.04, +%D title=\CONTEXT\ Modules, +%D subtitle=Database Thingies, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright=PRAGMA +%D ] + +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D For Mojca. + +\registerctxluafile{m-database}{1.001} + +\unprotect + +\ifdefined \installparameterhandler \else \input mult-aux.mkiv \fi + +\def\c!first {first} +\def\c!last {last} +\def\c!quotechar {quotechar} +\def\c!commentchar {commentchar} + +\def\????db{@@@@db} + +\installparameterhandler \????db {database} +\installcommandhandler \????db {database} \????db % #3 == defaultroot +\installattributehandler \????db {database} + +\appendtoks + \getparameters + [\????db\currentdatabase] + [\c!separator={,}, + \c!quotechar=, + \c!commentchar=, + \c!setups=, + \c!before=, + \c!after=, + \c!first=, + \c!last=, + \c!left=, + \c!right=, + \c!command=]% +\to \everypresetdatabase + +% \let\currentdatabase\empty \the\everypresetdatabase % or just: + +\setupdatabase + [\c!separator={,}] + +\def\doprocessdatabase#1#2#3% + {\edef\currentdatabasetype{#1}% + \edef\currentdatabase {#2}% + \edef\currentdatabasename{#3}% + \ifx\currentdatabasename\empty + \let\currentdatabasename\currentdatabase + \let\currentdatabase\empty + \fi + \ctxlua{buffers.database.process { + name = "\currentdatabase", + type = "\currentdatabasetype", + database = "\currentdatabasename", + separator = \!!bs\databaseparameter\c!separator \!!es, + quotechar = \!!bs\databaseparameter\c!quotechar \!!es, + commentchar = \!!bs\databaseparameter\c!commentchar\!!es, + setups = \!!bs\databaseparameter\c!setups \!!es, + before = \!!bs\databaseparameter\c!before \!!es, + after = \!!bs\databaseparameter\c!after \!!es, + first = \!!bs\databaseparameter\c!first \!!es, + last = \!!bs\databaseparameter\c!last \!!es, + left = \!!bs\databaseparameter\c!left \!!es, + right = \!!bs\databaseparameter\c!right \!!es, + command = \!!bs\databaseparameter\c!command \!!es, + }}} + +\unexpanded\def\processdatabasebuffer{\dodoubleempty\doprocessdatabasebuffer} +\unexpanded\def\processdatabasefile {\dodoubleempty\doprocessdatabasefile } + +\def\doprocessdatabasebuffer[#1][#2]{\doprocessdatabase{buffer}{#1}{#2}} +\def\doprocessdatabasefile [#1][#2]{\doprocessdatabase{file} {#1}{#2}} + +% for old times sake: + +\def\defineseparatedlist {\dodoubleempty\dodefineseparatedlist } +\def\processseparatedfile{\dodoubleempty\doprocessseparatedfile} + +\def\dodefineseparatedlist[#1][#2]% + {\definedatabase[#1][#2]% + \setuvalue{\e!start#1}{\dostartbuffer[#1][\e!start#1][\e!stop#1]}% + \setuvalue{\e!stop#1}{\processdatabasebuffer[#1][#1]}} + +\def\processseparatedfile[#1][#2]% + {\processdatabasefile[#1][#2]} + +\protect + +\doifnotmode{demo}{\endinput} + +\starttext + +% m-database.txt +% +% 1,2,3,4,5 +% 6,7,8,"9,x",0 +% A,B,C,D +% E,,F +% G + +\definedatabase[test] + +\setupdatabase + [test] + [separator={,}, + quotechar={"}, + before={<}, + after={>}, + first={\endgraf[}, + last={]\endgraf}, + left={ (}, + right={) }, + command=\ruledhbox] + +\startbuffer[testbuffer] +1,2,3,4,5 +6,7,8,"9,x",0 +A,B,C,D +E,,F +G +\stopbuffer + +\processdatabasebuffer[test][testbuffer] + +\processdatabasefile[test][m-database.txt] + +\defineseparatedlist + [CSV] + [separator={,}, + before=\bTABLE,after=\eTABLE, + first=\bTR,last=\eTR, + left=\bTD,right=\eTD] + +% \startseparatedlist[CSV] +% a,b,c +% d,e,f +% \stopseparatedlist + +\startCSV +a,b,c +d,e,f +\stopCSV + +\defineseparatedlist + [CSV] + [separator={,+},quotechar={"'},commentchar=\letterhash, + before={\starttabulate[|l|l|l|]},after=\stoptabulate, + first=\NC,last=\NR, + left=,right=\NC] + +\startCSV +#a,b,"c,d" +a,b,"c,d" +a,'b,c',d +"a,b"+c+d +\stopCSV + +\defineseparatedlist + [CSV] + [separator=space, + first=\NC,last=\NR, + left=,right=\NC, + before={\starttabulate[|l|l|l|]},after=\stoptabulate] + +\startCSV +a b c +d e f +\stopCSV + +\startsetups csv:unix + \catcode`\#=\commentcatcode +\stopsetups + +\defineseparatedlist + [CSV] + [setups=csv:unix, + separator={,}, + first=\NC,last=\NR, + left=,right=\NC, + before={\starttabulate[|l|l|l|]},after=\stoptabulate] + +\processseparatedfile[CSV][m-database.txt] + +\defineseparatedlist[CSV] + [separator=comma, + before=\bTABLE, after=\eTABLE, + first=\bTR, last=\eTR, + left=\bTD, right=\eTD] + +\startCSV +a,b,c,č +d,e,f,š +\stopCSV + +\stoptext diff --git a/tex/context/base/node-dum.lua b/tex/context/base/node-dum.lua index 7a454c8c9..b04204740 100644 --- a/tex/context/base/node-dum.lua +++ b/tex/context/base/node-dum.lua @@ -58,40 +58,38 @@ end nodes.handlers.protectglyphs = node.protect_glyphs nodes.handlers.unprotectglyphs = node.unprotect_glyphs -nodes.characters = { - handler = function (head) - local usedfonts, done, prevfont = { }, false, nil - for n in traverse_id(glyph_code,head) do - local font = n.font - if font ~= prevfont then - prevfont = font - local used = usedfonts[font] - if not used then - local tfmdata = fontdata[font] - if tfmdata then - local shared = tfmdata.shared -- we need to check shared, only when same features - if shared then - local processors = shared.processes - if processors and #processors > 0 then - usedfonts[font] = processors - done = true - end +function nodes.handlers.characters(head) + local usedfonts, done, prevfont = { }, false, nil + for n in traverse_id(glyph_code,head) do + local font = n.font + if font ~= prevfont then + prevfont = font + local used = usedfonts[font] + if not used then + local tfmdata = fontdata[font] + if tfmdata then + local shared = tfmdata.shared -- we need to check shared, only when same features + if shared then + local processors = shared.processes + if processors and #processors > 0 then + usedfonts[font] = processors + done = true end end end end end - if done then - for font, processors in next, usedfonts do - for i=1,#processors do - local h, d = processors[i](head,font,0) - head, done = h or head, done or d - end + end + if done then + for font, processors in next, usedfonts do + for i=1,#processors do + local h, d = processors[i](head,font,0) + head, done = h or head, done or d end end - return head, true end -} + return head, true +end -- helper diff --git a/tex/context/base/trac-set.lua b/tex/context/base/trac-set.lua index 3b99b489c..b14c6112e 100644 --- a/tex/context/base/trac-set.lua +++ b/tex/context/base/trac-set.lua @@ -74,6 +74,9 @@ local function set(t,what,newvalue) if type(what) == "string" then what = settings_to_hash(what) -- inefficient but ok end + if type(what) ~= "table" then + return + end for w, value in next, what do if value == "" then value = newvalue |