summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/core-dat.mkiv
blob: 41a84c3e61a6598048660201b3223cb145c542b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
%D \module
%D   [       file=core-dat,
%D        version=20122.04.17, % replaces core-two from 1997.03.31,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Multipass Datasets,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Core Macros / Multipass Datasets}

%D \starttyping
%D \definedataset[test-1]
%D \definedataset[test-2][delay=yes]
%D
%D \startlines
%D set 1: \setdataset[test-1][whatever=this-or-that-1]
%D set 2: \setdataset[test-2][whatever=this-or-that-2]
%D set 3: \setdataset[test-2][whatever=this-or-that-3]
%D \stoplines
%D
%D \startlines
%D get 1: \datasetvariable{test-1}{1}{whatever} / \datasetvariable{test-1}{1}{realpage}
%D get 2: \datasetvariable{test-2}{1}{whatever} / \datasetvariable{test-2}{1}{realpage}
%D get 3: \datasetvariable{test-2}{2}{whatever} / \datasetvariable{test-2}{2}{realpage}
%D \stoplines
%D \stoptyping

\unprotect

\registerctxluafile{core-dat}{}

\installcorenamespace{dataset}

\installcommandhandler \??dataset {dataset} \??dataset

\unexpanded\def\setdataset
  {\dotripleempty\syst_datasets_set}

\def\syst_datasets_set
  {\ifthirdargument
     \expandafter\syst_datasets_set_named
   \else
     \expandafter\syst_datasets_set_indexed
   \fi}

\def\syst_datasets_set_named[#1][#2][#3]%
  {\begingroup
   \edef\currentdataset{#1}%
   \clf_setdataset
      name  {\currentdataset}%
      tag   {#2}%
      delay {\datasetparameter\c!delay}%
      data  {#3}%
   \relax
   \endgroup}

\def\syst_datasets_set_indexed[#1][#2][#3]%
  {\begingroup
   \edef\currentdataset{#1}%
   \clf_setdataset
      name  {\currentdataset}%
      delay {\datasetparameter\c!delay}%
      data  {#2}%
   \relax
   \endgroup}

\def\datasetvariable#1#2#3%
  {\clf_datasetvariable{#1}{#2}{#3}}

\installcorenamespace{pagestate}
\installcorenamespace{pagestatecounter}

\installcommandhandler \??pagestate {pagestate} \??pagestate

% \def\syst_pagestates_allocate
%   {\expandafter\newcount\csname\??pagestatecounter\currentpagestate\endcsname
%    \expandafter\let\expandafter\c_syst_pagestate\csname\??pagestatecounter\currentpagestate\endcsname}

\def\syst_pagestates_allocate
  {\expandafter\newcount\csname\??pagestatecounter\currentpagestate\endcsname}

\appendtoks
    \syst_pagestates_allocate
\to \everydefinepagestate

\setuppagestate
  [\c!delay=\v!yes]

\unexpanded\def\setpagestate
  {\dodoubleempty\syst_pagestates_set}

% \def\syst_pagestates_set[#1][#2]%
%   {\begingroup
%    \edef\currentpagestate{#1}%
%    \ifcsname\??pagestatecounter\currentpagestate\endcsname
%      \let\c_syst_pagestate\lastnamedcs
%    \else
%      \syst_pagestates_allocate
%    \fi
%    \global\advance\c_syst_pagestate\plusone
%    \scratchcounter\lastnamedcs
%    \clf_setpagestate
%       name  {\currentpagestate}%
%       tag   {\ifsecondargument#2\else\number\c_syst_pagestate\fi}%
%       delay {\pagestateparameter\c!delay}%
%    \relax
%    \endgroup}

\def\syst_pagestates_set[#1][#2]%
  {\begingroup
   \edef\currentpagestate{#1}%
   \ifcsname\??pagestatecounter\currentpagestate\endcsname
     \scratchcounter\lastnamedcs
     \advance\scratchcounter\plusone
   \else
     \scratchcounter\plusone
     \syst_pagestates_allocate
   \fi
   \global\csname\??pagestatecounter\currentpagestate\endcsname\scratchcounter
   \clf_setpagestate
      name  {\currentpagestate}%
      tag   {\ifsecondargument#2\else\number\scratchcounter\fi}%
      delay {\pagestateparameter\c!delay}%
   \relax
   \endgroup}

\unexpanded\def\autosetpagestate#1%
  {\secondargumentfalse\syst_pagestates_set[#1]}

\def\autopagestatenumber#1{\begincsname\??pagestatecounter#1\endcsname}

\def\pagestaterealpage     #1#2{\clf_pagestaterealpage     {#1}{#2}}
\def\setpagestaterealpageno#1#2{\clf_setpagestaterealpageno{#1}{#2}}
\def\pagestaterealpageorder#1#2{\clf_pagestaterealpageorder{#1}#2\relax}

\def\autopagestaterealpage     #1{\clf_pagestaterealpage     {#1}{\number\autopagestatenumber{#1}}}
\def\setautopagestaterealpageno#1{\clf_setpagestaterealpageno{#1}{\number\autopagestatenumber{#1}}}
\def\autopagestaterealpageorder#1{\clf_pagestaterealpageorder{#1}\numexpr\autopagestatenumber{#1}\relax}

\protect