core-dat.mkiv /size: 3667 b    last modification: 2020-07-01 14:35
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
\appendtoks
85
\syst_pagestates_allocate
86
\to
\everydefinepagestate
87 88
\setuppagestate
89
[
\c!delay
=
\v!yes
]
90 91
\unexpanded
\def
\setpagestate
92
{
\dodoubleempty
\syst_pagestates_set
}
93 94
\def
\syst_pagestates_set
[#
1
][#
2
]
%
95
{
\begingroup
96
\edef
\currentpagestate
{
#
1
}
%
97
\ifcsname
\??pagestatecounter
\currentpagestate
\endcsname
98
\let
\c_syst_pagestate
\lastnamedcs
99
\else
100
\syst_pagestates_allocate
101
\fi
102
\global\advance
\c_syst_pagestate
\plusone
103
\scratchcounter
\lastnamedcs
104
\clf_setpagestate
105
name
{
\currentpagestate
}
%
106
tag
{
\ifsecondargument
#
2
\else\number
\c_syst_pagestate
\fi
}
%
107
delay
{
\pagestateparameter
\c!delay
}
%
108
\relax
109
\endgroup
}
110 111
\unexpanded
\def
\autosetpagestate
#
1
%
112
{
\secondargumentfalse
\syst_pagestates_set
[#
1
]
}
113 114
\def
\autopagestatenumber
#
1
{
\begincsname
\??pagestatecounter
#
1
\endcsname
}
115 116
\def
\pagestaterealpage
#
1
#
2
{
\clf_pagestaterealpage
{
#
1
}{
#
2
}}
117
\def
\setpagestaterealpageno
#
1
#
2
{
\clf_setpagestaterealpageno
{
#
1
}{
#
2
}}
118
\def
\pagestaterealpageorder
#
1
#
2
{
\clf_pagestaterealpageorder
{
#
1
}
#
2
\relax
}
119 120
\def
\autopagestaterealpage
#
1
{
\clf_pagestaterealpage
{
#
1
}{
\number
\autopagestatenumber
{
#
1
}}}
121
\def
\setautopagestaterealpageno
#
1
{
\clf_setpagestaterealpageno
{
#
1
}{
\number
\autopagestatenumber
{
#
1
}}}
122
\def
\autopagestaterealpageorder
#
1
{
\clf_pagestaterealpageorder
{
#
1
}
\numexpr
\autopagestatenumber
{
#
1
}
\relax
}
123 124
\protect
125