core-dat.mkiv /size: 4366 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=core-dat,
3%D        version=20122.04.17, % replaces core-two from 1997.03.31,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=Multipass Datasets,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Core Macros / Multipass Datasets}
15
16%D \starttyping
17%D \definedataset[test-1]
18%D \definedataset[test-2][delay=yes]
19%D
20%D \startlines
21%D set 1: \setdataset[test-1][whatever=this-or-that-1]
22%D set 2: \setdataset[test-2][whatever=this-or-that-2]
23%D set 3: \setdataset[test-2][whatever=this-or-that-3]
24%D \stoplines
25%D
26%D \startlines
27%D get 1: \datasetvariable{test-1}{1}{whatever} / \datasetvariable{test-1}{1}{realpage}
28%D get 2: \datasetvariable{test-2}{1}{whatever} / \datasetvariable{test-2}{1}{realpage}
29%D get 3: \datasetvariable{test-2}{2}{whatever} / \datasetvariable{test-2}{2}{realpage}
30%D \stoplines
31%D \stoptyping
32
33\unprotect
34
35\registerctxluafile{core-dat}{}
36
37\installcorenamespace{dataset}
38
39\installcommandhandler \??dataset {dataset} \??dataset
40
41\unexpanded\def\setdataset
42  {\dotripleempty\syst_datasets_set}
43
44\def\syst_datasets_set
45  {\ifthirdargument
46     \expandafter\syst_datasets_set_named
47   \else
48     \expandafter\syst_datasets_set_indexed
49   \fi}
50
51\def\syst_datasets_set_named[#1][#2][#3]%
52  {\begingroup
53   \edef\currentdataset{#1}%
54   \clf_setdataset
55      name  {\currentdataset}%
56      tag   {#2}%
57      delay {\datasetparameter\c!delay}%
58      data  {#3}%
59   \relax
60   \endgroup}
61
62\def\syst_datasets_set_indexed[#1][#2][#3]%
63  {\begingroup
64   \edef\currentdataset{#1}%
65   \clf_setdataset
66      name  {\currentdataset}%
67      delay {\datasetparameter\c!delay}%
68      data  {#2}%
69   \relax
70   \endgroup}
71
72\def\datasetvariable#1#2#3%
73  {\clf_datasetvariable{#1}{#2}{#3}}
74
75\installcorenamespace{pagestate}
76\installcorenamespace{pagestatecounter}
77
78\installcommandhandler \??pagestate {pagestate} \??pagestate
79
80% \def\syst_pagestates_allocate
81%   {\expandafter\newcount\csname\??pagestatecounter\currentpagestate\endcsname
82%    \expandafter\let\expandafter\c_syst_pagestate\csname\??pagestatecounter\currentpagestate\endcsname}
83
84\def\syst_pagestates_allocate
85  {\expandafter\newcount\csname\??pagestatecounter\currentpagestate\endcsname}
86
87\appendtoks
88    \syst_pagestates_allocate
89\to \everydefinepagestate
90
91\setuppagestate
92  [\c!delay=\v!yes]
93
94\unexpanded\def\setpagestate
95  {\dodoubleempty\syst_pagestates_set}
96
97% \def\syst_pagestates_set[#1][#2]%
98%   {\begingroup
99%    \edef\currentpagestate{#1}%
100%    \ifcsname\??pagestatecounter\currentpagestate\endcsname
101%      \let\c_syst_pagestate\lastnamedcs
102%    \else
103%      \syst_pagestates_allocate
104%    \fi
105%    \global\advance\c_syst_pagestate\plusone
106%    \scratchcounter\lastnamedcs
107%    \clf_setpagestate
108%       name  {\currentpagestate}%
109%       tag   {\ifsecondargument#2\else\number\c_syst_pagestate\fi}%
110%       delay {\pagestateparameter\c!delay}%
111%    \relax
112%    \endgroup}
113
114\def\syst_pagestates_set[#1][#2]%
115  {\begingroup
116   \edef\currentpagestate{#1}%
117   \ifcsname\??pagestatecounter\currentpagestate\endcsname
118     \scratchcounter\lastnamedcs
119     \advance\scratchcounter\plusone
120   \else
121     \scratchcounter\plusone
122     \syst_pagestates_allocate
123   \fi
124   \global\csname\??pagestatecounter\currentpagestate\endcsname\scratchcounter
125   \clf_setpagestate
126      name  {\currentpagestate}%
127      tag   {\ifsecondargument#2\else\number\scratchcounter\fi}%
128      delay {\pagestateparameter\c!delay}%
129   \relax
130   \endgroup}
131
132\unexpanded\def\autosetpagestate#1%
133  {\secondargumentfalse\syst_pagestates_set[#1]}
134
135\def\autopagestatenumber#1{\begincsname\??pagestatecounter#1\endcsname}
136
137\def\pagestaterealpage     #1#2{\clf_pagestaterealpage     {#1}{#2}}
138\def\setpagestaterealpageno#1#2{\clf_setpagestaterealpageno{#1}{#2}}
139\def\pagestaterealpageorder#1#2{\clf_pagestaterealpageorder{#1}#2\relax}
140
141\def\autopagestaterealpage     #1{\clf_pagestaterealpage     {#1}{\number\autopagestatenumber{#1}}}
142\def\setautopagestaterealpageno#1{\clf_setpagestaterealpageno{#1}{\number\autopagestatenumber{#1}}}
143\def\autopagestaterealpageorder#1{\clf_pagestaterealpageorder{#1}\numexpr\autopagestatenumber{#1}\relax}
144
145\protect
146