diff options
32 files changed, 545 insertions, 353 deletions
diff --git a/doc/context/documents/general/manuals/luatex.pdf b/doc/context/documents/general/manuals/luatex.pdf Binary files differindex c7a492ea8..d4ddd2996 100644 --- a/doc/context/documents/general/manuals/luatex.pdf +++ b/doc/context/documents/general/manuals/luatex.pdf diff --git a/doc/context/documents/general/manuals/math-mkiv.pdf b/doc/context/documents/general/manuals/math-mkiv.pdf Binary files differindex 5b6a5441e..6a120e30a 100644 --- a/doc/context/documents/general/manuals/math-mkiv.pdf +++ b/doc/context/documents/general/manuals/math-mkiv.pdf diff --git a/doc/context/documents/general/manuals/sql-mkiv.pdf b/doc/context/documents/general/manuals/sql-mkiv.pdf Binary files differindex 8d3588615..94a99d0ce 100644 --- a/doc/context/documents/general/manuals/sql-mkiv.pdf +++ b/doc/context/documents/general/manuals/sql-mkiv.pdf diff --git a/doc/context/sources/general/manuals/luatex/luatex-nodes.tex b/doc/context/sources/general/manuals/luatex/luatex-nodes.tex index 821942a9a..fd0b47c72 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-nodes.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-nodes.tex @@ -1218,7 +1218,7 @@ The second return value is the badness of the generated box. See the description of \type {node.hpack()} for a few memory allocation caveats. -\subsubsection{\type {node.dimensions}} +\subsubsection{\type {node.dimensions}, \type {node.rangedimensions}} \startfunctioncall <number> w, <number> h, <number> d = @@ -1271,7 +1271,17 @@ example in code like this, which prints the width of the space in between the You need to keep in mind that this is one of the few places in \TEX\ where floats are used, which means that you can get small differences in rounding when you -compare the width repported by \type {hpack} with \type {dimensions}. +compare the width reported by \type {hpack} with \type {dimensions}. + +The second alternative saves a few lookups and can be more convenient in some +cases: + +\startfunctioncall +<number> w, <number> h, <number> d = + node.rangedimensions(<node> parent, <node> first) +<number> w, <number> h, <number> d = + node.rangedimensions(<node> parent, <node> first, <node> last) +\stopfunctioncall \subsubsection{\type {node.mlist_to_hlist}} @@ -1828,6 +1838,7 @@ this: \NC \type {count} \NC \yes \NC \yes \NC \NR \NC \type {current_attr} \NC \yes \NC \yes \NC \NR \NC \type {dimensions} \NC \yes \NC \yes \NC \NR +\NC \type {rangedimensions} \NC \yes \NC \yes \NC \NR %NC \type {do_ligature_n} \NC \yes \NC \yes \NC \NR % was never documented and experimental \NC \type {effective_glue} \NC \yes \NC \yes \NC \NR \NC \type {end_of_math} \NC \yes \NC \yes \NC \NR diff --git a/doc/context/sources/general/manuals/luatex/luatex.tex b/doc/context/sources/general/manuals/luatex/luatex.tex index 7fd436666..75e63c9bb 100644 --- a/doc/context/sources/general/manuals/luatex/luatex.tex +++ b/doc/context/sources/general/manuals/luatex/luatex.tex @@ -12,7 +12,7 @@ \dontcomplain \startdocument - [version=0.98.2, + [version=0.98.4, status=pre-release] \component luatex-titlepage diff --git a/doc/context/sources/general/manuals/sql/sql-mkiv.tex b/doc/context/sources/general/manuals/sql/sql-mkiv.tex index 1b05c8738..95af57e11 100644 --- a/doc/context/sources/general/manuals/sql/sql-mkiv.tex +++ b/doc/context/sources/general/manuals/sql/sql-mkiv.tex @@ -487,6 +487,94 @@ context --extra=sql-tables --help \stopsection +\startsection[title=Example] + +The distribution has a few examples, for instance a logger. The following code shows +a bit of this (we assume that the swiglib sqlite module is present): + +\startbuffer +require("util-sql") +utilities.sql.setmethod("sqlite") +require("util-sql-loggers") + +local loggers = utilities.sql.loggers + +local presets = { + -- method = "sqlite", + database = "loggertest", + datatable = "loggers", + id = "loggers", +} + +os.remove("loggertest.db") -- start fresh + +local db = loggers.createdb(presets) + +loggers.save(db, { -- variant 1: data subtable + type = "error", + action = "process", + data = { filename = "test-1", message = "whatever a" } +} ) + +loggers.save(db, { -- variant 2: flat table + type = "warning", + action = "process", + filename = "test-2", + message = "whatever b" +} ) + + +local result = loggers.collect(db, { + start = { + day = 1, + month = 1, + year = 2016, + }, + stop = { + day = 31, + month = 12, + year = 2116, + }, + limit = 1000000, + -- type = "error", + action = "process" +}) + +context.starttabulate { "||||||" } +for i=1,#result do + local r = result[i] + context.NC() context(r.time) + context.NC() context(r.type) + context.NC() context(r.action) + if r.data then + context.NC() context(r.data.filename) + context.NC() context(r.data.message) + else + context.NC() + context.NC() + end + context.NC() context.NR() +end +context.stoptabulate() + +-- local result = loggers.cleanup(db, { +-- before = { +-- day = 1, +-- month = 1, +-- year = 2117, +-- }, +-- }) +\stopbuffer + +\typebuffer + +In this example we typeset the (small) table): + +\ctxluabuffer + + +\stopsection + \startsection[title=Colofon] \starttabulate[|B|p|] diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index baed742e9..f5bd13761 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -9178,7 +9178,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lua"] = package.loaded["util-lua"] or true --- original size: 5393, stripped down to: 3611 +-- original size: 5574, stripped down to: 3816 if not modules then modules={} end modules ['util-lua']={ version=1.001, @@ -9300,6 +9300,17 @@ function luautilities.loadstripped(...) return load(dump(l,true)) end end +local finalizers={} +setmetatable(finalizers,{ + __gc=function(t) + for i=1,#t do + pcall(t[i]) + end + end +} ) +function luautilities.registerfinalizer(f) + finalizers[#finalizers+1]=f +end end -- of closure @@ -18837,8 +18848,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 801851 --- stripped bytes : 291622 +-- original bytes : 802032 +-- stripped bytes : 291598 -- end library merge diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index baed742e9..f5bd13761 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -9178,7 +9178,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lua"] = package.loaded["util-lua"] or true --- original size: 5393, stripped down to: 3611 +-- original size: 5574, stripped down to: 3816 if not modules then modules={} end modules ['util-lua']={ version=1.001, @@ -9300,6 +9300,17 @@ function luautilities.loadstripped(...) return load(dump(l,true)) end end +local finalizers={} +setmetatable(finalizers,{ + __gc=function(t) + for i=1,#t do + pcall(t[i]) + end + end +} ) +function luautilities.registerfinalizer(f) + finalizers[#finalizers+1]=f +end end -- of closure @@ -18837,8 +18848,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 801851 --- stripped bytes : 291622 +-- original bytes : 802032 +-- stripped bytes : 291598 -- end library merge diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index baed742e9..f5bd13761 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -9178,7 +9178,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lua"] = package.loaded["util-lua"] or true --- original size: 5393, stripped down to: 3611 +-- original size: 5574, stripped down to: 3816 if not modules then modules={} end modules ['util-lua']={ version=1.001, @@ -9300,6 +9300,17 @@ function luautilities.loadstripped(...) return load(dump(l,true)) end end +local finalizers={} +setmetatable(finalizers,{ + __gc=function(t) + for i=1,#t do + pcall(t[i]) + end + end +} ) +function luautilities.registerfinalizer(f) + finalizers[#finalizers+1]=f +end end -- of closure @@ -18837,8 +18848,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 801851 --- stripped bytes : 291622 +-- original bytes : 802032 +-- stripped bytes : 291598 -- end library merge diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua index baed742e9..f5bd13761 100644 --- a/scripts/context/stubs/win64/mtxrun.lua +++ b/scripts/context/stubs/win64/mtxrun.lua @@ -9178,7 +9178,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lua"] = package.loaded["util-lua"] or true --- original size: 5393, stripped down to: 3611 +-- original size: 5574, stripped down to: 3816 if not modules then modules={} end modules ['util-lua']={ version=1.001, @@ -9300,6 +9300,17 @@ function luautilities.loadstripped(...) return load(dump(l,true)) end end +local finalizers={} +setmetatable(finalizers,{ + __gc=function(t) + for i=1,#t do + pcall(t[i]) + end + end +} ) +function luautilities.registerfinalizer(f) + finalizers[#finalizers+1]=f +end end -- of closure @@ -18837,8 +18848,8 @@ end -- of closure -- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 801851 --- stripped bytes : 291622 +-- original bytes : 802032 +-- stripped bytes : 291598 -- end library merge diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 488b0a574..1e57311f4 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index ffeb9087c..f619cbcc4 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2016.09.01 21:11} +\newcontextversion{2016.09.04 13:46} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index d13f28bd4..37dc55cc6 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -39,7 +39,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2016.09.01 21:11} +\edef\contextversion{2016.09.04 13:46} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/mkiv/math-ali.mkiv b/tex/context/base/mkiv/math-ali.mkiv index 404fddcc6..2456efd22 100644 --- a/tex/context/base/mkiv/math-ali.mkiv +++ b/tex/context/base/mkiv/math-ali.mkiv @@ -83,37 +83,6 @@ % use zeroskipplusfill -% \def\math_prepare_r_eqalign_no -% {\t_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% -% \t_math_align_b{\aligntab\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% -% \ifnum\mathraggedstatus=\plusone -% \t_math_align_c{\hfil\aligntab\span\math_text_in_eqalign{\alignmark\alignmark}\tabskip\zeropoint}% -% \else\ifnum\mathraggedstatus=\plusthree -% \t_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill\aligntab\span\math_text_in_eqalign{\alignmark\alignmark}\tabskip\zeropoint}% -% \else -% \t_math_align_c{\hfil\tabskip\centering\aligntab\llap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\zeropoint}% -% \fi\fi -% \global\mathnumberstatus\zerocount -% \math_build_eqalign -% \the\mathdisplayaligntweaks -% \tabskip\centering} - -% \def\math_prepare_l_eqalign_no % \checkeddisplaymath -% {\t_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% -% \t_math_align_b{\aligntab\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% -% % problem: number is handled after rest and so ends up in the margin -% \ifnum\mathraggedstatus=\plusone -% \t_math_align_c{\hfil\aligntab\kern-\displaywidth\rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% -% \else\ifnum\mathraggedstatus=\plusthree -% \t_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill\aligntab\kern-\displaywidth\span\math_rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% -% \else -% \t_math_align_c{\hfil\tabskip\centering\aligntab\kern-\displaywidth\rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% -% \fi\fi -% \global\mathnumberstatus\zerocount -% \math_build_eqalign -% \the\mathdisplayaligntweaks -% \tabskip\centering} - \def\math_prepare_r_eqalign_no {\t_math_align_a {\strut @@ -156,11 +125,9 @@ \tabskip\centering \aligntab \span - % \rlap{\math_text_in_eqalign{\alignmark\alignmark}}% - \math_text_in_eqalign{\alignmark\alignmark}% + \llap{\math_text_in_eqalign{\alignmark\alignmark}}% \tabskip\zeropoint}% \fi\fi - \global\mathnumberstatus\zerocount \math_build_eqalign \the\mathdisplayaligntweaks \tabskip\centering} @@ -213,7 +180,6 @@ \rlap{\math_text_in_eqalign{\alignmark\alignmark}}% \tabskip\displaywidth}% \fi\fi - \global\mathnumberstatus\zerocount \math_build_eqalign \the\mathdisplayaligntweaks \tabskip\centering} @@ -235,15 +201,15 @@ \def\math_both_eqalign_no_aligned#1% {\ifmmode - \the\mathdisplayaligntweaks - \global\mathnumberstatus\plusone - \ifcase\mathraggedstatus + \the\mathdisplayaligntweaks + \global\mathnumberstatus\plusone + \ifcase\mathraggedstatus \def\math_finish_eqalign_no{\crcr\egroup}% - \else + \else % we're in a mathbox \vcenter\bgroup \def\math_finish_eqalign_no{\crcr\egroup\egroup}% - \fi + \fi \fi #1% \math_halign_checked\expandafter\bgroup\the\scratchtoks\crcr} @@ -275,27 +241,6 @@ \newtoks \everymathalignment -% \def\math_alignment_NC_first -% {\glet\math_alignment_NC\math_alignment_NC_rest} -% -% \def\math_alignment_NR -% {\aligntab -% \dostoptagged % finish cell -% \dodoubleempty\math_alignment_NR_indeed} % use xx from tabulate -% -% \def\math_alignment_NR_indeed[#1][#2]% -% {\strc_formulas_place_number_nested{#1}{#2}% to be tagged (better an attribute) -% \crcr -% \dostoptagged % finish row -% \noalign{\glet\math_alignment_NC\math_alignment_NC_first}} % noalign used for change state, conditional does not work here - -% \def\math_alignment_NC_first#1\NR -% {\glet\math_alignment_NC\math_alignment_NC_rest -% \dotripleempty\math_alignment_NC_first_indeed[{#1}]} - -% \def\math_alignment_NC_first_indeed[#1][#2][#3]% -% {\strc_formulas_place_number_nested{#2}{#3}\aligntab#1\NR} - \def\math_alignment_NC_first#1\NR {\glet\math_alignment_NC\math_alignment_NC_rest \scratchtoks{\math_number_left_of_eqalign\aligntab#1\NR}% @@ -355,7 +300,7 @@ \the\everymathalignment \c_math_eqalign_column\zerocount \processcommacommand - [\mathalignmentparameter\c!align] + [\mathalignmentparameter\c!align]% {\advance\c_math_eqalign_column\plusone\math_eqalign_set_column}% takes argument \global\c_math_eqalign_column\plusone \dostarttagged\t!math\empty diff --git a/tex/context/base/mkiv/math-ini.mkiv b/tex/context/base/mkiv/math-ini.mkiv index ca309df3d..38bff5afe 100644 --- a/tex/context/base/mkiv/math-ini.mkiv +++ b/tex/context/base/mkiv/math-ini.mkiv @@ -2201,10 +2201,6 @@ \newtoks\mathdisplayaligntweaks -\appendtoks - \resetdisplaymatheq % moved to here -\to \mathdisplayaligntweaks - % this can become an option: \unexpanded\def\math_display_align_hack % I don't like the global, maybe we should push and pop diff --git a/tex/context/base/mkiv/mlib-pps.lua b/tex/context/base/mkiv/mlib-pps.lua index 0c0cc6637..b6d22f1be 100644 --- a/tex/context/base/mkiv/mlib-pps.lua +++ b/tex/context/base/mkiv/mlib-pps.lua @@ -25,7 +25,7 @@ local setmacro = interfaces.setmacro local texsetbox = tex.setbox local textakebox = tex.takebox local copy_list = node.copy_list -local free_list = node.flush_list +local flush_list = node.flush_list local setmetatableindex = table.setmetatableindex local sortedhash = table.sortedhash @@ -259,7 +259,7 @@ end local function stopjob() if top then for n, tn in next, top.textexts do - free_list(tn) + flush_list(tn) if trace_textexts then report_textexts("freeing text %s",n) end diff --git a/tex/context/base/mkiv/node-met.lua b/tex/context/base/mkiv/node-met.lua index 1dee3a9f5..efd748b12 100644 --- a/tex/context/base/mkiv/node-met.lua +++ b/tex/context/base/mkiv/node-met.lua @@ -76,6 +76,7 @@ nodes.copy_node = node.copy nodes.copy_list = node.copy_list nodes.delete = node.delete nodes.dimensions = node.dimensions +nodes.rangedimensions = node.rangedimensions nodes.end_of_math = node.end_of_math nodes.flush = node.flush_node nodes.flush_node = node.flush_node @@ -128,6 +129,23 @@ if LUATEXVERSION < 0.97 then end +if not node.rangedimensions then -- LUATEXVERSION < 0.99 + + local dimensions = node.dimensions + local getfield = node.getfield + local findtail = node.find_tail + + function node.rangedimensions(parent,first,last) + return dimensions( + getfield(parent,"glue_set"), getfield(parent,"glue_sign"), getfield(parent,"glue_order"), + first, last or find_tail(first), getfield(parent,"dir") + ) + end + + nodes.rangedimensions = node.rangedimensions + +end + nodes.effective_glue = node.effective_glue nodes.getglue = node.getglue nodes.setglue = node.setglue diff --git a/tex/context/base/mkiv/node-nut.lua b/tex/context/base/mkiv/node-nut.lua index c2c74308d..e158b9325 100644 --- a/tex/context/base/mkiv/node-nut.lua +++ b/tex/context/base/mkiv/node-nut.lua @@ -164,6 +164,7 @@ nuts.copy_node = direct.copy nuts.copy_list = direct.copy_list nuts.delete = direct.delete nuts.dimensions = direct.dimensions +nuts.rangedimensions = direct.rangedimensions nuts.end_of_math = direct.end_of_math nuts.flush = direct.flush_node nuts.flush_node = direct.flush_node @@ -225,6 +226,23 @@ if LUATEXVERSION < 0.97 then end +if not direct.rangedimensions then -- LUATEXVERSION < 0.99 + + local dimensions = direct.dimensions + local getfield = direct.getfield + local findtail = direct.find_tail + + function direct.rangedimensions(parent,first,last) + return dimensions( + getfield(parent,"glue_set"), getfield(parent,"glue_sign"), getfield(parent,"glue_order"), + first, last or find_tail(first), getfield(parent,"dir") + ) + end + + nuts.rangedimensions = direct.rangedimensions + +end + local getglue = direct.getglue local setglue = direct.setglue local is_zero_glue = direct.is_zero_glue diff --git a/tex/context/base/mkiv/node-ref.lua b/tex/context/base/mkiv/node-ref.lua index 7bdd5b8d8..d709eb811 100644 --- a/tex/context/base/mkiv/node-ref.lua +++ b/tex/context/base/mkiv/node-ref.lua @@ -20,82 +20,83 @@ local concat = table.concat local attributes, nodes, node = attributes, nodes, node -local allocate = utilities.storage.allocate, utilities.storage.mark -local mark = utilities.storage.allocate, utilities.storage.mark - -local nodeinjections = backends.nodeinjections -local codeinjections = backends.codeinjections - -local cleanupreferences = false -local cleanupdestinations = true - -local transparencies = attributes.transparencies -local colors = attributes.colors -local references = structures.references -local tasks = nodes.tasks - -local trace_references = false trackers.register("nodes.references", function(v) trace_references = v end) -local trace_destinations = false trackers.register("nodes.destinations", function(v) trace_destinations = v end) -local trace_areas = false trackers.register("nodes.areas", function(v) trace_areas = v end) -local show_references = false trackers.register("nodes.references.show", function(v) show_references = tonumber(v) or (v and 2.25 or false) end) -local show_destinations = false trackers.register("nodes.destinations.show", function(v) show_destinations = tonumber(v) or (v and 2.00 or false) end) - -local report_reference = logs.reporter("backend","references") -local report_destination = logs.reporter("backend","destinations") -local report_area = logs.reporter("backend","areas") - -local nuts = nodes.nuts -local nodepool = nuts.pool - -local tonode = nuts.tonode -local tonut = nuts.tonut - -local getfield = nuts.getfield -local setfield = nuts.setfield -local setlink = nuts.setlink -local setnext = nuts.setnext -local setprev = nuts.setprev -local getnext = nuts.getnext -local getprev = nuts.getprev -local getid = nuts.getid -local getlist = nuts.getlist -local setlist = nuts.setlist -local getattr = nuts.getattr -local setattr = nuts.setattr -local getsubtype = nuts.getsubtype - -local hpack_list = nuts.hpack -local vpack_list = nuts.vpack -local list_dimensions = nuts.dimensions -local traverse = nuts.traverse -local find_node_tail = nuts.tail - -local nodecodes = nodes.nodecodes -local skipcodes = nodes.skipcodes -local listcodes = nodes.listcodes - -local hlist_code = nodecodes.hlist -local vlist_code = nodecodes.vlist -local glue_code = nodecodes.glue -local glyph_code = nodecodes.glyph -local rule_code = nodecodes.rule -local dir_code = nodecodes.dir -local localpar_code = nodecodes.localpar - -local leftskip_code = skipcodes.leftskip -local rightskip_code = skipcodes.rightskip -local parfillskip_code = skipcodes.parfillskip - -local line_code = listcodes.line - -local new_rule = nodepool.rule -local new_kern = nodepool.kern - -local flush_node = nuts.flush - -local tosequence = nodes.tosequence - -local implement = interfaces.implement +local allocate = utilities.storage.allocate, utilities.storage.mark +local mark = utilities.storage.allocate, utilities.storage.mark + +local nodeinjections = backends.nodeinjections +local codeinjections = backends.codeinjections + +local cleanupreferences = false +local cleanupdestinations = true + +local transparencies = attributes.transparencies +local colors = attributes.colors +local references = structures.references +local tasks = nodes.tasks + +local trace_references = false trackers.register("nodes.references", function(v) trace_references = v end) +local trace_destinations = false trackers.register("nodes.destinations", function(v) trace_destinations = v end) +local trace_areas = false trackers.register("nodes.areas", function(v) trace_areas = v end) +local show_references = false trackers.register("nodes.references.show", function(v) show_references = tonumber(v) or (v and 2.25 or false) end) +local show_destinations = false trackers.register("nodes.destinations.show", function(v) show_destinations = tonumber(v) or (v and 2.00 or false) end) + +local report_reference = logs.reporter("backend","references") +local report_destination = logs.reporter("backend","destinations") +local report_area = logs.reporter("backend","areas") + +local nuts = nodes.nuts +local nodepool = nuts.pool + +local tonode = nuts.tonode +local tonut = nuts.tonut + +local getfield = nuts.getfield +local setfield = nuts.setfield +local setlink = nuts.setlink +local setnext = nuts.setnext +local setprev = nuts.setprev +local getnext = nuts.getnext +local getprev = nuts.getprev +local getid = nuts.getid +local getlist = nuts.getlist +local setlist = nuts.setlist +local getattr = nuts.getattr +local setattr = nuts.setattr +local getsubtype = nuts.getsubtype + +local hpack_list = nuts.hpack +local vpack_list = nuts.vpack +local list_dimensions = nuts.dimensions +local list_rangedimensions = nuts.rangedimensions +local traverse = nuts.traverse +local find_node_tail = nuts.tail + +local nodecodes = nodes.nodecodes +local skipcodes = nodes.skipcodes +local listcodes = nodes.listcodes + +local hlist_code = nodecodes.hlist +local vlist_code = nodecodes.vlist +local glue_code = nodecodes.glue +local glyph_code = nodecodes.glyph +local rule_code = nodecodes.rule +local dir_code = nodecodes.dir +local localpar_code = nodecodes.localpar + +local leftskip_code = skipcodes.leftskip +local rightskip_code = skipcodes.rightskip +local parfillskip_code = skipcodes.parfillskip + +local line_code = listcodes.line + +local new_rule = nodepool.rule +local new_kern = nodepool.kern + +local flush_node = nuts.flush + +local tosequence = nodes.tosequence + +local implement = interfaces.implement -- Normally a (destination) area is a box or a simple stretch if nodes but when it is -- a paragraph we have a problem: we cannot calculate the height well. This happens @@ -104,7 +105,7 @@ local implement = interfaces.implement local function hlist_dimensions(start,stop,parent) local last = stop and getnext(stop) if parent then - return list_dimensions(getfield(parent,"glue_set"),getfield(parent,"glue_sign"),getfield(parent,"glue_order"),start,last) + return list_rangedimensions(parent,start,last) else return list_dimensions(start,last) end diff --git a/tex/context/base/mkiv/node-rul.lua b/tex/context/base/mkiv/node-rul.lua index b3caa5ccd..219aa5e26 100644 --- a/tex/context/base/mkiv/node-rul.lua +++ b/tex/context/base/mkiv/node-rul.lua @@ -37,6 +37,7 @@ local getfont = nuts.getfont local getsubtype = nuts.getsubtype local getlist = nuts.getlist local setlist = nuts.setlist +local flushlist = nuts.flush_list local nodecodes = nodes.nodecodes local tasks = nodes.tasks @@ -107,7 +108,7 @@ local a_colormodel = attributes.private('colormodel') local insert_node_before = nuts.insert_before local insert_node_after = nuts.insert_after -local list_dimensions = nuts.dimensions +local list_dimensions = nuts.rangedimensions local hpack_nodes = nuts.hpack local striprange = nodes.striprange @@ -357,8 +358,9 @@ local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but a if not f then return head end - local w, ht, dp = list_dimensions(getfield(parent,"glue_set"),getfield(parent,"glue_sign"),getfield(parent,"glue_order"),f,getnext(l)) + local w, ht, dp = list_dimensions(parent,f,getnext(l)) local method = d.method + local empty = d.empty == v_yes local offset = d.offset local continue = d.continue local dy = d.dy @@ -402,14 +404,22 @@ local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but a if layer then setattr(r,a_viewerlayer,layer) end - local k = new_kern(-w) - if foreground then - insert_node_after(head,l,k) - insert_node_after(head,k,r) - l = r - else + if empty then head = insert_node_before(head,f,r) - insert_node_after(head,r,k) + setlink(r,getnext(l)) + setprev(f) + setnext(l) + flushlist(f) + else + local k = new_kern(-w) + if foreground then + insert_node_after(head,l,k) + insert_node_after(head,k,r) + l = r + else + head = insert_node_before(head,f,r) + insert_node_after(head,r,k) + end end if trace_ruled then report_ruled("level %a, width %p, height %p, depth %p, nodes %a, text %a", @@ -489,7 +499,7 @@ local function flush_shifted(head,first,last,data,level,parent,strip) -- not tha local next = getnext(last) setprev(first) setnext(last) - local width, height, depth = list_dimensions(getfield(parent,"glue_set"),getfield(parent,"glue_sign"),getfield(parent,"glue_order"),first,next) + local width, height, depth = list_dimensions(parent,first,next) local list = hpack_nodes(first,width,"exactly") if first == head then head = list @@ -541,13 +551,14 @@ implement { { "order" }, { "method", "integer" }, { "offset", "number" }, - { "rulethickness", "string" }, + { "rulethickness" }, { "dy", "number" }, { "max", "number" }, { "ma", "integer" }, { "ca", "integer" }, { "ta", "integer" }, - { "mp", "string" }, + { "mp" }, + { "empty" }, } } } diff --git a/tex/context/base/mkiv/node-rul.mkiv b/tex/context/base/mkiv/node-rul.mkiv index 0be4a0f4b..91b013937 100644 --- a/tex/context/base/mkiv/node-rul.mkiv +++ b/tex/context/base/mkiv/node-rul.mkiv @@ -124,6 +124,7 @@ ta \thetransparencyattribute\p_node_rules_color offset \barparameter\c!offset\space % number dy \barparameter\c!dy\space % number + empty {\barparameter\c!empty}% \relax}} \unexpanded\def\node_rules_redefine#1% @@ -182,6 +183,7 @@ \setupbars [\c!method=0, % new: 0=center nested, 1=stack nested \c!continue=\v!no, + \c!empty=, % new: yes = hide text \c!offset=0, % upwards, replaces: topoffset bottomoffset \c!dy=0, \c!max=3, diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex 5be73cee9..ad2f3bea9 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex a39c6a930..273acc006 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/strc-mat.mkiv b/tex/context/base/mkiv/strc-mat.mkiv index b0e37f987..fba6b5ee2 100644 --- a/tex/context/base/mkiv/strc-mat.mkiv +++ b/tex/context/base/mkiv/strc-mat.mkiv @@ -226,7 +226,6 @@ \to \everyresetformulas \newconditional\c_strc_formulas_handle_number -\newconditional\c_strc_formulas_increment \newconditional\c_strc_formulas_inside_place \newconditional\c_strc_formulas_inside_place_sub \newconditional\c_strc_formulas_inside_formulas @@ -489,9 +488,6 @@ \let\math_native_leqno\leqno \let\math_native_reqno\reqno -\unexpanded\def\resetdisplaymatheq - {\let\strc_formulas_place_number\relax} - \unexpanded\def\normaleqno#1{\writestatus\m!system{no native (l)eqno equation number support}} \let\normalleqno\normaleqno @@ -741,7 +737,7 @@ \d_strc_formulas_display_skip_left \leftskip \d_strc_formulas_display_skip_right \rightskip \d_strc_formulas_display_width \formulaparameter\c!width\relax - \d_strc_formulas_display_margin_left \formulaparameter\c!leftmargin \relax + \d_strc_formulas_display_margin_left \formulaparameter\c!leftmargin\relax \d_strc_formulas_display_margin_right\formulaparameter\c!rightmargin\relax \edef\p_option{\formulaparameter\c!option}% \ifsecondargument @@ -817,65 +813,6 @@ %D \startformula x \stopformula % now has \noindent (in mkii we messed with baselineskip) %D \stoptyping -% \unexpanded\def\startdisplaymath -% {\bgroup -% \par -% \informulatrue -% \beforedisplayspace -% \par -% \ifvmode -% \prevdepth-\maxdimen % texbook pagina 79-80 -% \fi -% \noindent % else funny hlist with funny baselineskip -% $$% \Ucheckedstartdisplaymath -% \setdisplaydimensions -% \startinnermath} -% -% \unexpanded\def\stopdisplaymath -% {\stopinnermath -% $$% \Ucheckedstopdisplaymath -% \par -% \afterdisplayspace -% \par -% \egroup} -% -% \unexpanded\def\startdisplaymath -% {\bgroup -% \par -% \informulatrue -% \beforedisplayspace -% \par -% \ifvmode -% \ifcase\c_strc_formulas_space_model -% % nothing -% \or -% % nothing yet -% \or -% \prevdepth-\maxdimen % texbook pagina 79-80 -% \fi -% \fi -% \noindent % else funny hlist with funny baselineskip -% \Ucheckedstartdisplaymath -% \setdisplaydimensions -% \startinnermath} -% -% \unexpanded\def\stopdisplaymath -% {\stopinnermath -% \Ucheckedstopdisplaymath -% \par -% \ifvmode -% \ifcase\c_strc_formulas_space_model -% % nothing -% \or -% \prevdepth .5\strutdp -% \or -% \prevdepth\lineheight -% \fi -% \fi -% \afterdisplayspace -% \par -% \egroup} - \unexpanded\def\startdisplaymath {\bgroup \informulatrue @@ -1043,17 +980,14 @@ \unexpanded\def\strc_formulas_number_again[#1]% {\def\currentformulareference{#1}% - \glet\strc_formulas_place_number\relax \strc_formulas_place_number_in_box} \unexpanded\def\placeformula {\global\settrue\c_strc_formulas_inside_place - \settrue\c_strc_formulas_increment \dosingleempty\strc_formulas_place} \unexpanded\def\placesubformula {\global\settrue\c_strc_formulas_inside_place_sub - \setfalse\c_strc_formulas_increment \dosingleempty\strc_formulas_place} \unexpanded\def\strc_formulas_place[#1]% @@ -1139,21 +1073,21 @@ \def\strc_formulas_place_number_nested_indeed#1#2% {\def\currentnestedformulareference{#1}% \def\currentnestedformulasuffix{#2}% - \glet\strc_formulas_place_number\relax \strc_formulas_check_reference\c_strc_formulas_nested_number_mode\currentnestedformulareference \ifcase\c_strc_formulas_nested_number_mode % nothing \or + \glet\strc_formulas_place_number\relax \expandafter\strc_formulas_number % hm, looks ahead for [] \or % nothing \or + \glet\strc_formulas_place_number\relax \expandafter\strc_formulas_number % hm, looks ahead for [] \fi} \def\strc_formulas_place_number_indeed - {\glet\strc_formulas_place_number\relax - \strc_formulas_place_number_in_box} + {\strc_formulas_place_number_in_box} \def\strc_formulas_place_number_in_box {\dostarttagged\t!formulacaption\empty diff --git a/tex/context/base/mkiv/util-lua.lua b/tex/context/base/mkiv/util-lua.lua index d4020a1e9..b3346006c 100644 --- a/tex/context/base/mkiv/util-lua.lua +++ b/tex/context/base/mkiv/util-lua.lua @@ -159,14 +159,20 @@ end -- -- print(luautilities.datatype(lpeg.P("oeps"))) --- local finalizers = { } --- --- function luautilities.registerfinalizer(f) --- finalizers[#finalizers+1] = f --- end --- --- function luautilities.finalize() --- for i=1,#finalizers do --- pcall(finalizers[i]) --- end --- end +-- These finalizers will only be invoked when we have a proper lua_close +-- call (which is not happening in luatex tex node yes) or finish with an +-- os.exit(n,true). + +local finalizers = { } + +setmetatable(finalizers, { + __gc = function(t) + for i=1,#t do + pcall(t[i]) -- let's not crash + end + end +} ) + +function luautilities.registerfinalizer(f) + finalizers[#finalizers+1] = f +end diff --git a/tex/context/base/mkiv/util-sql-imp-client.lua b/tex/context/base/mkiv/util-sql-imp-client.lua index 50b1e9dff..55c944ebb 100644 --- a/tex/context/base/mkiv/util-sql-imp-client.lua +++ b/tex/context/base/mkiv/util-sql-imp-client.lua @@ -26,6 +26,8 @@ local serialize = sql.serialize local deserialize = sql.deserialize local getserver = sql.getserver +local osclock = os.gettimeofday + -- Experiments with an p/action demonstrated that there is not much gain. We could do a runtime -- capture but creating all the small tables is not faster and it doesn't work well anyway. @@ -172,7 +174,7 @@ local function datafetched(specification) local t = osclock() report_state("command: %s",command) local okay = os.execute(command) - report_state("fetchtime: %.3f sec",osclock()-t) -- not okay under linux + report_state("fetchtime: %.3f sec, return code: %i",osclock()-t,okay) -- not okay under linux return okay == 0 else return os.execute(command) == 0 diff --git a/tex/context/base/mkiv/util-sql-imp-sqlite.lua b/tex/context/base/mkiv/util-sql-imp-sqlite.lua index 390e3aa29..bb789f648 100644 --- a/tex/context/base/mkiv/util-sql-imp-sqlite.lua +++ b/tex/context/base/mkiv/util-sql-imp-sqlite.lua @@ -6,18 +6,21 @@ if not modules then modules = { } end modules ['util-sql-imp-sqlite'] = { license = "see context related readme files" } --- todo: make a converter +local next = next -require("util-sql") +local sql = require("util-sql") +----- sql = utilities.sql +local sqlite = require("swiglib.sqlite.core") +local swighelpers = require("swiglib.helpers.core") + +-- sql.sqlite = sqlite -- maybe in the module itself -local rawset, setmetatable = rawset, setmetatable -local P, S, V, C, Cs, Ct, Cc, Cg, Cf, patterns, lpegmatch = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.Cc, lpeg.Cg, lpeg.Cf, lpeg.patterns, lpeg.match +-- inspect(table.sortedkeys(sqlite)) local trace_sql = false trackers.register("sql.trace", function(v) trace_sql = v end) local trace_queries = false trackers.register("sql.queries",function(v) trace_queries = v end) local report_state = logs.reporter("sql","sqlite") -local sql = utilities.sql local helpers = sql.helpers local methods = sql.methods local validspecification = helpers.validspecification @@ -28,32 +31,21 @@ local serialize = sql.serialize local deserialize = sql.deserialize local getserver = sql.getserver -local sqlite = require("swiglib.sqlite.core") -local swighelpers = require("swiglib.helpers.core") - - --- we can have a cache - --- local preamble = t_preamble[getserver()] or t_preamble.mysql --- if preamble then --- preamble = replacetemplate(preamble,specification.variables,'sql') --- query = preamble .. "\n" .. query --- end - --- print(sqlite.sqlite3_errmsg(dbh)) +local setmetatable = setmetatable +local formatters = string.formatters -local get_list_item = sqlite.char_p_array_getitem -local is_okay = sqlite.SQLITE_OK -local execute_query = sqlite.sqlite3_exec_lua_callback -local error_message = sqlite.sqlite3_errmsg +local get_list_item = sqlite.char_p_array_getitem +local is_okay = sqlite.SQLITE_OK +local execute_query = sqlite.sqlite3_exec_lua_callback +local error_message = sqlite.sqlite3_errmsg -local new_db = sqlite.new_sqlite3_p_array -local open_db = sqlite.sqlite3_open -local get_db = sqlite.sqlite3_p_array_getitem -local close_db = sqlite.sqlite3_close -local dispose_db = sqlite.delete_sqlite3_p_array +local new_db = sqlite.new_sqlite3_p_array +local open_db = sqlite.sqlite3_open +local get_db = sqlite.sqlite3_p_array_getitem +local close_db = sqlite.sqlite3_close +local dispose_db = sqlite.delete_sqlite3_p_array -local cache = { } +local cache = { } setmetatable(cache, { __gc = function(t) @@ -67,6 +59,21 @@ setmetatable(cache, { end }) +-- synchronous journal_mode locking_mode 1000 logger inserts +-- +-- normal normal normal 6.8 +-- off off normal 0.1 +-- normal off normal 2.1 +-- normal persist normal 5.8 +-- normal truncate normal 4.2 +-- normal truncate exclusive 4.1 + +local f_preamble = formatters[ [[ +ATTACH `%s` AS `%s` ; +PRAGMA `%s`.synchronous = normal ; +PRAGMA journal_mode = truncate ; +]] ] + local function execute(specification) if trace_sql then report_state("executing sqlite") @@ -84,62 +91,88 @@ local function execute(specification) report_state("no database specified") return end - base = file.addsuffix(base,"db") - local result = { } - local keys = { } - local id = specification.id - local db = nil - local dbh = nil - local okay = false + local filename = file.addsuffix(base,"db") + local result = { } + local keys = { } + local id = specification.id + local db = nil + local dbh = nil + local okay = false + local preamble = nil if id then local session = cache[id] if session then dbh = session.dbh okay = is_okay else - db = new_db(1) - okay = open_db(base,db) - dbh = get_db(db,0) + db = new_db(1) + okay = open_db(filename,db) + dbh = get_db(db,0) + preamble = f_preamble(filename,base,base) if okay ~= is_okay then report_state("no session database specified") else cache[id] = { - name = base, + name = filename, db = db, dbh = dbh, } end end else - db = new_db(1) - okay = open_db(base,db) - dbh = get_db(db,0) + db = new_db(1) + okay = open_db(filename,db) + dbh = get_db(db,0) + preamble = f_preamble(filename,base,base) end if okay ~= is_okay then report_state("no database opened") else - local keysdone = false - local nofresults = 0 - local callback = function(data,nofcolumns,values,fields) - nofresults = nofresults + 1 - local r = { } - for i=0,nofcolumns-1 do - local field = get_list_item(fields,i) - local value = get_list_item(values,i) - r[field] = value - if not keysdone then - keys[i+1] = field + local converter = specification.converter + local keysdone = false + local nofrows = 0 + local callback = nil + if preamble then + query = preamble .. query -- only needed in open + end + if converter then + converter = converter.sqlite + callback = function(data,nofcolumns,values,fields) + local column = { } + for i=0,nofcolumns-1 do + column[i+1] = get_list_item(values,i) + end + nofrows = nofrows + 1 + result[nofrows] = converter(column) + return is_okay + end + -- + -- callback = converter.sqlite + else + callback = function(data,nofcolumns,values,fields) + local column = { } + for i=0,nofcolumns-1 do + local field + if keysdone then + field = keys[i+1] + else + field = get_list_item(fields,i) + keys[i+1] = field + end + column[field] = get_list_item(values,i) end + nofrows = nofrows + 1 + keysdone = true + result[nofrows] = column + return is_okay end - keysdone = true - result[nofresults] = r - return is_okay end local okay = execute_query(dbh,query,callback,nil,nil) if okay ~= is_okay then - report_state(error_message(dbh)) + report_state("error: %s",error_message(dbh)) + -- elseif converter then + -- result = converter.sqlite(result) end - end if not id then close_db(dbh) @@ -158,20 +191,45 @@ local booleanstring = string.booleanstring %s -return function(data) - local target = %s -- data or { } - for i=1,#data do - local cells = data[i] - target[%s] = { - %s - } - end - return target +return function(cells) + -- %s (not needed) + -- %s (not needed) + return { + %s + } end ]] local celltemplate = "cells[%s]" +-- todo: how to deal with result ... pass via temp global .. bah .. or +-- also pass the execute here ... not now +-- +-- local wraptemplate = [[ +-- local converters = utilities.sql.converters +-- local deserialize = utilities.sql.deserialize +-- +-- local tostring = tostring +-- local tonumber = tonumber +-- local booleanstring = string.booleanstring +-- +-- local get_list_item = utilities.sql.sqlite.char_p_array_getitem +-- local is_okay = utilities.sql.sqlite.SQLITE_OK +-- +-- %s +-- +-- return function(data,nofcolumns,values,fields) +-- -- no %s (data) needed +-- -- no %s (i) needed +-- local cells = { } +-- for i=0,nofcolumns-1 do +-- cells[i+1] = get_list_item(values,i) +-- end +-- result[#result+1] = { %s } +-- return is_okay +-- end +-- ]] + methods.sqlite = { execute = execute, usesfiles = false, diff --git a/tex/context/base/mkiv/util-sql-loggers.lua b/tex/context/base/mkiv/util-sql-loggers.lua index ceb1ff75c..4473f8971 100644 --- a/tex/context/base/mkiv/util-sql-loggers.lua +++ b/tex/context/base/mkiv/util-sql-loggers.lua @@ -65,12 +65,21 @@ local template = [[ DEFAULT CHARSET = utf8 ; ]] +local sqlite_template = [[ + CREATE TABLE IF NOT EXISTS %basename% ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `time` INTEGER NOT NULL, + `type` INTEGER NOT NULL, + `action` TEXT NOT NULL, + `data` TEXT + ) ; +]] + function loggers.createdb(presets,datatable) local db = checkeddb(presets,datatable) - db.execute { - template = template, + template = db.usedmethod == "sqlite" and sqlite_template or template, variables = { basename = db.basename, }, @@ -115,7 +124,11 @@ local template =[[ ) ; ]] -function loggers.save(db,data) -- beware, we pass type and action in the data (saves a table) +-- beware, when we either pass a dat afield explicitly or we're using +-- a flat table and then nill type and action in the data (which +-- saves a table) + +function loggers.save(db,data) if data then @@ -123,8 +136,16 @@ function loggers.save(db,data) -- beware, we pass type and action in the data (s local kind = totype[data.type] local action = data.action or "unknown" - data.type = nil - data.action = nil + local extra = data.data + + if extra then + -- we have a dedicated data table + data = extra + else + -- we have a flat table + data.type = nil + data.action = nil + end db.execute { template = template, @@ -141,28 +162,49 @@ function loggers.save(db,data) -- beware, we pass type and action in the data (s end --- local template =[[ --- REMOVE FROM --- %basename% --- WHERE --- `token` = '%token%' ; --- ]] --- --- function loggers.remove(db,token) --- --- db.execute { --- template = template, --- variables = { --- basename = db.basename, --- token = token, --- }, --- } --- --- if trace_sql then --- report("removed: %s",token) --- end --- --- end +local template =[[ + DELETE FROM %basename% %WHERE% ; +]] + +function loggers.cleanup(db,specification) + + specification = specification or { } + + local today = os.date("*t") + local before = specification.before or today + local where = { } + + if type(before) == "number" then + before = os.date(before) + end + + before = os.time { + day = before.day or today.day, + month = before.month or today.month, + year = before.year or today.year, + hour = before.hour or 0, + minute = before.minute or 0, + second = before.second or 0, + isdst = true, + } + + where[#where+1] = format("`time` < %s",before) + + db.execute { + template = template, + variables = { + basename = db.basename, + WHERE = format("WHERE\n%s",concat(where," AND ")), + }, + } + + if db.usedmethod == "sqlite" then + db.execute { + template = "VACUUM ;", + } + end + +end local template_nop =[[ SELECT diff --git a/tex/context/base/mkiv/util-sql.lua b/tex/context/base/mkiv/util-sql.lua index 023c7809a..a0578f086 100644 --- a/tex/context/base/mkiv/util-sql.lua +++ b/tex/context/base/mkiv/util-sql.lua @@ -311,15 +311,30 @@ sql.setserver("mysql") -- helper: +local sqlmethods = sql.methods + function sql.usedatabase(presets,datatable) local name = datatable or presets.datatable if name then - local method = presets.method and sql.methods[presets.method] or sql.methods.client + local usedmethod = presets.method + local method = usedmethod and sqlmethods[usedmethod] + if not method then + usedmethod = currentmethod + method = usedmethod and sqlmethods[usedmethod] + end + if not method then + usedmethod = sql.methods.client + method = usedmethod and sqlmethods[usedmethod] + end local base = presets.database or "test" local basename = format("`%s`.`%s`",base,name) local execute = nil local m_execute = method.execute - if method.usesfiles then + if not m_execute then + execute = function() + report_state("no valid execute handler") + end + elseif method.usesfiles then local queryfile = presets.queryfile or format("%s-temp.sql",name) local resultfile = presets.resultfile or format("%s-temp.dat",name) execute = function(specification) -- variables template @@ -347,6 +362,7 @@ function sql.usedatabase(presets,datatable) end end return { + usedmethod = usedmethod, presets = preset, base = base, name = name, diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex 301acb985..acd42b3c6 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex ebaef2f9b..f5d105ac8 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index a442ceab4..ef3528c76 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 09/01/16 21:11:58 +-- merge date : 09/04/16 13:46:35 do -- begin closure to overcome local limits and interference |