From 1e74733e95e8a624a8d6ed637087aa25480b61df Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 27 Nov 2010 14:40:13 +0200 Subject: beta 2010.11.27 13:21 --- tex/context/base/buff-ini.lua | 52 +++- tex/context/base/buff-ini.mkiv | 10 +- tex/context/base/buff-ver.mkiv | 2 +- tex/context/base/cont-new.tex | 2 +- tex/context/base/context.tex | 2 +- tex/context/base/data-met.lua | 2 +- tex/context/base/data-out.lua | 2 +- tex/context/base/data-tex.lua | 393 +++++++++++++++++----------- tex/context/base/data-zip.lua | 4 +- tex/context/base/mult-cld.lua | 30 ++- tex/context/base/strc-blk.lua | 8 +- tex/context/base/strc-blk.mkiv | 13 +- tex/context/base/trac-log.lua | 1 + tex/generic/context/luatex-fonts-merged.lua | 2 +- 14 files changed, 329 insertions(+), 194 deletions(-) (limited to 'tex') diff --git a/tex/context/base/buff-ini.lua b/tex/context/base/buff-ini.lua index 9caa673dc..9d4562e18 100644 --- a/tex/context/base/buff-ini.lua +++ b/tex/context/base/buff-ini.lua @@ -22,12 +22,12 @@ local huge = math.huge local byte, sub, find, char, gsub, rep, lower, format, gmatch, match, count = string.byte, string.sub, string.find, string.char, string.gsub, string.rep, string.lower, string.format, string.gmatch, string.match, string.count local splitlines, escapedpattern = string.splitlines, string.escapedpattern local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues -local ctxcatcodes = tex.ctxcatcodes local variables = interfaces.variables local lpegmatch = lpeg.match local settings_to_array = utilities.parsers.settings_to_array local allocate = utilities.storage.allocate local tabtospace = utilities.strings.tabtospace +local texsprint, texprint, ctxcatcodes = tex.sprint, tex.print, tex.ctxcatcodes buffers = { data = allocate(), @@ -218,18 +218,18 @@ function buffers.typebuffer(settings) -- todo: settings.nature = "display" end end -function buffers.processbuffer(settings) -- overlaps too much with the previous - local name = settings.name -- maybe use processor instead of visualizer +function buffers.processbuffer(settings) -- nearly the same + local name = settings.name local lines = name and data[name] if lines then + -- dodo: process only and feedback if type(lines) == "string" then lines = splitlines(lines) data[name] = lines end local content, m = filter(lines,settings) if content and content ~= "" then ---~ print("!!!!!!!!!!!!!!!!!!!") - flush(content,"process",settings) + flush(content,"direct",settings) end end end @@ -314,13 +314,14 @@ local printer = (lpeg.patterns.textline/texprint)^0 -- not the right one, we can function buffers.get(name) local b = data[name] if b then - if type(b) == "table" then - for i=1,#b do - texprint(b[i]) - end - else - lpegmatch(printer,b) - end + context.viafile(b) +--~ if type(b) == "table" then +--~ for i=1,#b do +--~ texprint(b[i]) +--~ end +--~ else +--~ lpegmatch(printer,b) +--~ end end end @@ -348,6 +349,33 @@ function buffers.evaluate(name) end end +-- maybe we should keep buffers unsplit and only split when needed +-- or better: we need a tex.sprint that splits on newlines (\r \n or +-- \r\n) + +local function n_content(s) + flush(contentcatcodes,s) +end + +local function n_endofline() + texsprint(" ") +end + +local function n_emptyline() + texprint("") +end + +local function n_simpleline() + texprint("") +end + +function buffers.mkvi(name,raw) + local lines = content(name) + lines = resolvers.macros.preprocessed(lines) + -- context.printlines(lines,raw) + context.viafile(lines) +end + function buffers.collect(names,separator) -- no print -- maybe we should always store a buffer as table so -- that we can pass it directly diff --git a/tex/context/base/buff-ini.mkiv b/tex/context/base/buff-ini.mkiv index f195cd8cf..403bbf55f 100644 --- a/tex/context/base/buff-ini.mkiv +++ b/tex/context/base/buff-ini.mkiv @@ -186,10 +186,12 @@ % % \ctxluabuffer[what] \ctxluabuffer -\def\ctxluabuffer - {\dosingleempty\doctxluabuffer} +\def\ctxluabuffer {\dosingleempty\doctxluabuffer} +\def\mkvibuffer {\dosingleempty\domkvibuffer} +\def\mkvibufferraw{\dosingleempty\domkvibufferraw} -\def\doctxluabuffer[#1]% - {\ctxlua{buffers.evaluate("#1")}} +\def\doctxluabuffer [#1]{\ctxlua{buffers.evaluate("#1")}} +\def\domkvibuffer [#1]{\ctxlua{buffers.mkvi("#1")}} +%def\domkvibufferraw[#1]{\ctxlua{buffers.mkvi("#1",true)}} \protect \endinput diff --git a/tex/context/base/buff-ver.mkiv b/tex/context/base/buff-ver.mkiv index 4a226885e..6dd540385 100644 --- a/tex/context/base/buff-ver.mkiv +++ b/tex/context/base/buff-ver.mkiv @@ -765,7 +765,7 @@ strip = "\typingparameter\c!strip", tab = "\typingparameter\c!tab", visualizer = "\typingparameter\c!option", - nature = "process", + nature = "direct", }}} % line numbering, keep broken lines together diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index e8b89219b..35a71c5f1 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.11.26 22:49} +\newcontextversion{2010.11.27 13:21} %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 06c589c92..58b05c300 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.11.26 22:49} +\edef\contextversion{2010.11.27 13:21} %D For those who want to use this: diff --git a/tex/context/base/data-met.lua b/tex/context/base/data-met.lua index c9c3cde5e..908dbf199 100644 --- a/tex/context/base/data-met.lua +++ b/tex/context/base/data-met.lua @@ -42,7 +42,7 @@ function resolvers.methodhandler(what, filename, filetype) -- ... if trace_locating then report_resolvers("using special handler for '%s' -> '%s' -> '%s'",specification.original,what,table.sequenced(specification)) end - return resolver[scheme](filename,filetype) + return resolver[scheme](filename,filetype,specification) -- todo: query else if trace_locating then report_resolvers("no handler for '%s' -> '%s' -> '%s'",specification.original,what,table.sequenced(specification)) diff --git a/tex/context/base/data-out.lua b/tex/context/base/data-out.lua index 94c12bd8c..598f857f8 100644 --- a/tex/context/base/data-out.lua +++ b/tex/context/base/data-out.lua @@ -6,5 +6,5 @@ if not modules then modules = { } end modules ['data-out'] = { license = "see context related readme files" } --- not used yet +resolvers.savers = utilities.storage.allocate { } diff --git a/tex/context/base/data-tex.lua b/tex/context/base/data-tex.lua index 3c42882fd..393c787d6 100644 --- a/tex/context/base/data-tex.lua +++ b/tex/context/base/data-tex.lua @@ -17,147 +17,10 @@ local report_resolvers = logs.new("resolvers") local resolvers = resolvers -local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders +local finders, openers, loaders, savers = resolvers.finders, resolvers.openers, resolvers.loaders, resolvers.savers local checkgarbage = utilities.garbagecollector and utilities.garbagecollector.check -function finders.generic(tag,filename,filetype) - local foundname = resolvers.findfile(filename,filetype) - if foundname and foundname ~= "" then - if trace_locating then - report_resolvers("%s finder: file '%s' found",tag,filename) - end - return foundname - else - if trace_locating then - report_resolvers("%s finder: unknown file '%s'",tag,filename) - end - return unpack(finders.notfound) - end -end - --- -- keep this one as reference as it's the first version --- --- resolvers.filters = resolvers.filters or { } --- --- local input_translator, utf_translator, user_translator = nil, nil, nil --- --- function resolvers.filters.install(name,func) --- if name == "input" then input_translator = func --- elseif name == "utf" then utf_translator = func --- elseif name == "user" then user_translator = func end --- end --- --- function openers.textopener(filename,file_handle,tag) --- local u = unicode.utftype(file_handle) --- local t = { } --- if u > 0 then --- if trace_locating then --- report_resolvers("%s opener, file '%s' opened using method '%s'",tag,filename,unicode.utfname[u]) --- end --- local l --- local data = file_handle:read("*a") --- if u > 2 then --- l = unicode.utf32_to_utf8(data,u==4) --- elseif u > 1 then --- l = unicode.utf16_to_utf8(data,u==2) --- else --- l = string.splitlines(data) --- end --- file_handle:close() --- t = { --- utftype = u, -- may go away --- lines = l, --- current = 0, -- line number, not really needed --- handle = nil, --- noflines = #l, --- close = function() --- if trace_locating then --- report_resolvers("%s closer, file '%s' closed",tag,filename) --- end --- logs.show_close(filename) --- t = nil --- end, --- reader = function(self) --- self = self or t --- local current, lines = self.current, self.lines --- if current >= #lines then --- return nil --- else --- current = current + 1 --- self.current = current --- local line = lines[current] --- if not line then --- return nil --- elseif line == "" then --- return "" --- else --- if input_translator then --- line = input_translator(line) --- end --- if utf_translator then --- line = utf_translator(line) --- end --- if user_translator then --- line = user_translator(line) --- end --- return line --- end --- end --- end --- } --- else --- if trace_locating then --- report_resolvers("%s opener, file '%s' opened",tag,filename) --- end --- -- todo: file;name -> freeze / eerste regel scannen -> freeze --- --~ local data = lpegmatch(getlines,file_handle:read("*a")) --- --~ local n = 0 --- t = { --- reader = function() -- self --- local line = file_handle:read() --- --~ n = n + 1 --- --~ local line = data[n] --- --~ print(line) --- if not line then --- return nil --- elseif line == "" then --- return "" --- else --- if input_translator then --- line = input_translator(line) --- end --- if utf_translator then --- line = utf_translator(line) --- end --- if user_translator then --- line = user_translator(line) --- end --- return line --- end --- end, --- close = function() --- if trace_locating then --- report_resolvers("%s closer, file '%s' closed",tag,filename) --- end --- logs.show_close(filename) --- file_handle:close() --- t = nil --- collectgarbage("step") -- saves some memory, maybe checkgarbage but no # --- end, --- handle = function() --- return file_handle --- end, --- noflines = function() --- t.noflines = io.noflines(file_handle) --- return t.noflines --- end --- } --- end --- return t --- end - - -- the main text reader -- local sequencers = utilities.sequencers @@ -186,26 +49,40 @@ sequencers.appendgroup(textfileactions,"user") sequencers.appendgroup(textlineactions,"system") sequencers.appendgroup(textlineactions,"user") -function openers.textopener(filename,file_handle,tag) - if trace_locating then - report_resolvers("%s opener, file '%s' opened using method '%s'",tag,filename,unicode.utfname[u]) - end +function openers.textopener(tag,filename,file_handle) if textfileactions.dirty then fileprocessor = sequencers.compile(textfileactions) end - local lines = io.loaddata(filename) - local kind = unicode.filetype(lines) - if kind == "utf-16-be" then - lines = unicode.utf16_to_utf8_be(lines) - elseif kind == "utf-16-le" then - lines = unicode.utf16_to_utf8_le(lines) - elseif kind == "utf-32-be" then - lines = unicode.utf32_to_utf8_be(lines) - elseif kind == "utf-32-le" then - lines = unicode.utf32_to_utf8_le(lines) - else -- utf8 or unknown - lines = fileprocessor(lines,filename) or lines - lines = string.splitlines(lines) + local lines + if not file_handle then + lines = io.loaddata(filename) + elseif type(file_handle) == "string" then + lines = file_handle + elseif type(file_handle) == "table" then + lines = file_handle + elseif file_handle then + lines = file_handle:read("*a") + file_handle:close() + end + if type(lines) == "string" then + local kind = unicode.filetype(lines) + if trace_locating then + report_resolvers("%s opener, file '%s' opened using method '%s'",tag,filename,kind) + end + if kind == "utf-16-be" then + lines = unicode.utf16_to_utf8_be(lines) + elseif kind == "utf-16-le" then + lines = unicode.utf16_to_utf8_le(lines) + elseif kind == "utf-32-be" then + lines = unicode.utf32_to_utf8_be(lines) + elseif kind == "utf-32-le" then + lines = unicode.utf32_to_utf8_le(lines) + else -- utf8 or unknown + lines = fileprocessor(lines,filename) or lines + lines = string.splitlines(lines) + end + elseif trace_locating then + report_resolvers("%s opener, file '%s' opened",tag,filename) end local t = { lines = lines, @@ -244,7 +121,88 @@ function openers.textopener(filename,file_handle,tag) return t end --- -- -- +local data, n, template = { }, 0, "virtual://virtualfile:%s" + +-- todo: report statistics + +function savers.virtual(content) + n = n + 1 + local filename = format(template,n) + if trace_locating then + report_resolvers("%s finder: virtual file '%s' saved",tag,filename) + end + data[filename] = content + return filename +end + +function finders.virtual(filename,filetype,specification) + local path = specification and specification.path + local name = path ~= "" and path or filename + local d = data[name] + if d then + if trace_locating then + report_resolvers("virtual finder: file '%s' found",filename) + end + return filename + else + if trace_locating then + report_resolvers("virtual finder: unknown file '%s'",filename) + end + return unpack(finders.notfound) + end +end + +function openers.virtual(filename,filetype,specification) -- duplicate ... todo: specification + local path = specification and specification.path + local name = path ~= "" and path or filename + local d = data[name] + if d then + if trace_locating then + report_resolvers("virtual opener, file '%s' opened",filename) + end + data[filename] = nil + return openers.textopener("virtual",filename,d) + else + if trace_locating then + report_resolvers("virtual opener, file '%s' not found",filename) + end + return unpack(openers.notfound) + end +end + +function loaders.virtual(filename,filetype,specification) + local path = specification and specification.path + local name = path ~= "" and path or filename + local d = data[name] + if d then + if trace_locating then + report_resolvers("virtual loader, file '%s' loaded",filename) + end + data[filename] = nil + return true, d, #d + end + if trace_locating then + report_resolvers("virtual loader, file '%s' not loaded",filename) + end + return unpack(loaders.notfound) +end + +-- could be a finder (beware: the generic finders take a tag!) + +function finders.generic(tag,filename,filetype) + local foundname = resolvers.findfile(filename,filetype) + if foundname and foundname ~= "" then + if trace_locating then + report_resolvers("%s finder: file '%s' found",tag,filename) + end + return foundname + else + if trace_locating then + report_resolvers("%s finder: unknown file '%s'",tag,filename) + end + return unpack(finders.notfound) + end +end function openers.generic(tag,filename) if filename and filename ~= "" then @@ -254,7 +212,7 @@ function openers.generic(tag,filename) if trace_locating then report_resolvers("%s opener, file '%s' opened",tag,filename) end - return openers.textopener(filename,f,tag) + return openers.textopener(tag,filename,f) end end if trace_locating then @@ -323,3 +281,124 @@ function resolvers.loadtexfile(filename, filetype) end resolvers.texdatablob = resolvers.loadtexfile + +-- -- keep this one as reference as it's the first version +-- +-- resolvers.filters = resolvers.filters or { } +-- +-- local input_translator, utf_translator, user_translator = nil, nil, nil +-- +-- function resolvers.filters.install(name,func) +-- if name == "input" then input_translator = func +-- elseif name == "utf" then utf_translator = func +-- elseif name == "user" then user_translator = func end +-- end +-- +-- function openers.textopener(tag,filename,file_handle) +-- local u = unicode.utftype(file_handle) +-- local t = { } +-- if u > 0 then +-- if trace_locating then +-- report_resolvers("%s opener, file '%s' opened using method '%s'",tag,filename,unicode.utfname[u]) +-- end +-- local l +-- local data = file_handle:read("*a") +-- if u > 2 then +-- l = unicode.utf32_to_utf8(data,u==4) +-- elseif u > 1 then +-- l = unicode.utf16_to_utf8(data,u==2) +-- else +-- l = string.splitlines(data) +-- end +-- file_handle:close() +-- t = { +-- utftype = u, -- may go away +-- lines = l, +-- current = 0, -- line number, not really needed +-- handle = nil, +-- noflines = #l, +-- close = function() +-- if trace_locating then +-- report_resolvers("%s closer, file '%s' closed",tag,filename) +-- end +-- logs.show_close(filename) +-- t = nil +-- end, +-- reader = function(self) +-- self = self or t +-- local current, lines = self.current, self.lines +-- if current >= #lines then +-- return nil +-- else +-- current = current + 1 +-- self.current = current +-- local line = lines[current] +-- if not line then +-- return nil +-- elseif line == "" then +-- return "" +-- else +-- if input_translator then +-- line = input_translator(line) +-- end +-- if utf_translator then +-- line = utf_translator(line) +-- end +-- if user_translator then +-- line = user_translator(line) +-- end +-- return line +-- end +-- end +-- end +-- } +-- else +-- if trace_locating then +-- report_resolvers("%s opener, file '%s' opened",tag,filename) +-- end +-- -- todo: file;name -> freeze / eerste regel scannen -> freeze +-- --~ local data = lpegmatch(getlines,file_handle:read("*a")) +-- --~ local n = 0 +-- t = { +-- reader = function() -- self +-- local line = file_handle:read() +-- --~ n = n + 1 +-- --~ local line = data[n] +-- --~ print(line) +-- if not line then +-- return nil +-- elseif line == "" then +-- return "" +-- else +-- if input_translator then +-- line = input_translator(line) +-- end +-- if utf_translator then +-- line = utf_translator(line) +-- end +-- if user_translator then +-- line = user_translator(line) +-- end +-- return line +-- end +-- end, +-- close = function() +-- if trace_locating then +-- report_resolvers("%s closer, file '%s' closed",tag,filename) +-- end +-- logs.show_close(filename) +-- file_handle:close() +-- t = nil +-- collectgarbage("step") -- saves some memory, maybe checkgarbage but no # +-- end, +-- handle = function() +-- return file_handle +-- end, +-- noflines = function() +-- t.noflines = io.noflines(file_handle) +-- return t.noflines +-- end +-- } +-- end +-- return t +-- end diff --git a/tex/context/base/data-zip.lua b/tex/context/base/data-zip.lua index 784ecb6b7..10c1b74f0 100644 --- a/tex/context/base/data-zip.lua +++ b/tex/context/base/data-zip.lua @@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['data-zip'] = { license = "see context related readme files" } +-- to be redone using the more recent schemes mechanism + local format, find, match = string.format, string.find, string.match local unpack = unpack or table.unpack @@ -141,7 +143,7 @@ function openers.zip(specification) if trace_locating then report_resolvers("zip opener, file '%s' found",q.name) end - return openers.textopener(specification,dfile,'zip') + return openers.textopener('zip',specification,dfile) elseif trace_locating then report_resolvers("zip opener, file '%s' not found",q.name) end diff --git a/tex/context/base/mult-cld.lua b/tex/context/base/mult-cld.lua index 1154eefe3..32436c5a5 100644 --- a/tex/context/base/mult-cld.lua +++ b/tex/context/base/mult-cld.lua @@ -161,9 +161,37 @@ end local flushlines = lpeg.texlinesplitter(n_content,n_endofline,n_emptyline,n_simpleline) -context.__flushlines = flushlines -- maybe context.helpers.flushtexlines +context.__flushlines = flushlines -- maybe context.helpers.flushtexlines context.__flush = flush +local printlines_ctx = ( + (newline) / function() texprint("") end + + (1-newline)^1 / function(s) texprint(ctxcatcodes,s) end * newline^-1 +)^0 + +local printlines_raw = ( + (newline) / function() texprint("") end + + (1-newline)^1 / function(s) texprint(s) end * newline^-1 +)^0 + +function context.printlines(str,raw) + if raw then + lpegmatch(printlines_raw,str) + else + lpegmatch(printlines_ctx,str) + end +end + +-- -- -- + +local savedata = resolvers.savers.virtual + +function context.viafile(data) + -- this is the only way to deal with nested buffers + -- and other catcode sensitive data + context.input(savedata(data)) +end + -- -- -- local function writer(parent,command,first,...) diff --git a/tex/context/base/strc-blk.lua b/tex/context/base/strc-blk.lua index d02fdeb7b..a52fb737a 100644 --- a/tex/context/base/strc-blk.lua +++ b/tex/context/base/strc-blk.lua @@ -43,13 +43,7 @@ function blocks.print(name,data,hide) else context.dostartnormalblock(name) end - if type(data) == "table" then - for i=1,#data do - context(data[i]) - end - else - lpegmatch(printer,data) - end + context.viafile(data) if hide then context.dostophiddenblock() else diff --git a/tex/context/base/strc-blk.mkiv b/tex/context/base/strc-blk.mkiv index 1f8bbd212..f625fa448 100644 --- a/tex/context/base/strc-blk.mkiv +++ b/tex/context/base/strc-blk.mkiv @@ -23,7 +23,7 @@ % check functionality % alternative files (needs further integration elsewhere) -\def\blockparameter#1#2{\ifcsname\??tb#1#2\endcsname\csname\??tb#1#2\endcsname\fi} +\def\namedblockparameter#1#2{\ifcsname\??tb#1#2\endcsname\csname\??tb#1#2\endcsname\fi} \unexpanded\def\setupblockparameters{\dodoubleargument \dosetupblock} % fast one (for compatibility) \unexpanded\def\setupblock {\dodoubleargumentwithset\dosetupblock} % handles set @@ -42,12 +42,13 @@ \c!style=, \c!file=]% todo \ctxlua{structures.blocks.define("#1")}% - \setvalue{\e!begin#1}{\dodoubleempty\dobeginofblock[#1]}% + \setuvalue{\e!begin#1}{\dodoubleempty\dobeginofblock[#1]}% \letvalue{\e!end#1}\relax} \long\def\dobeginofblock[#1][#2]% {\normalexpanded{\noexpand\dodowithbuffer{@block@}{\e!begin#1}{\e!end#1}} - {}{\ctxlua{structures.blocks.save("#1","#2","@block@")}}}% before after + {}% before + {\ctxlua{structures.blocks.save("#1","#2","@block@")}}}% after \def\dostarthiddenblock {\startnointerference @@ -69,15 +70,15 @@ \edef\currentblock{#1}% \doblocksetups\currentblock \let\doblocksetups\gobbleoneargument - \blockparameter\currentblock\c!before + \namedblockparameter\currentblock\c!before \dosetfontattribute{\??tb\currentblock}\c!style \dosetcolorattribute{\??tb\currentblock}\c!color - \blockparameter\currentblock\c!inner + \namedblockparameter\currentblock\c!inner \ignorespaces} \def\dostopnormalblock {\removeunwantedspaces - \blockparameter\currentblock\c!after + \namedblockparameter\currentblock\c!after \par % todo: alternative = text, paragraph \egroup} diff --git a/tex/context/base/trac-log.lua b/tex/context/base/trac-log.lua index 768f61821..4a77087f5 100644 --- a/tex/context/base/trac-log.lua +++ b/tex/context/base/trac-log.lua @@ -92,6 +92,7 @@ end local texlog = { } logs.tex = texlog setmetatable(texlog, { __index = noplog }) function texlog.report(a,b,c,...) +--~ print(a,b,c,...) if c then write_nl(format("%-16s> %s\n",a,format(b,c,...))) elseif b then diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 7685bb12c..ee0f0dd84 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 : 11/26/10 22:49:55 +-- merge date : 11/27/10 13:21:07 do -- begin closure to overcome local limits and interference -- cgit v1.2.3