summaryrefslogtreecommitdiff
path: root/tex/context/base/core-two.mkii
blob: a14586dc48e5964d2e46280a4ee6847e51b55868 (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
%D \module
%D   [       file=core-two, % moved from core-uti
%D        version=1997.03.31,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Two Pass Data,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

%D We save two pass information in the utility file.

\addutilityreset{twopassentries}

\def\immediatesavetwopassdata   #1#2#3{\immediatewriteutilitycommand{\twopassentry{#1}{#2}{#3}}}
\def\savetwopassdata            #1#2#3{\writeutilitycommand{\twopassentry{#1}{#2}{#3}}}
\def\lazysavetwopassdata        #1#2#3{\expanded{\writeutilitycommand{\noexpand\twopassentry{#1}{#2}{#3}}}} % expanded !
\def\savetaggedtwopassdata    #1#2#3#4{\immediatewriteutilitycommand{\twopassentry{#1}{#2}{#3::#4}}}
\def\lazysavetaggedtwopassdata#1#2#3#4{\expanded{\writeutilitycommand{\noexpand\twopassentry{#1}{#2}{#3::#4}}}} % expanded !

\def\resettwopassentries
  {\let\twopassentry\gobblethreearguments}

\def\settwopassentries
  {\def\twopassentry##1{\executeifdefined{@@##1\s!pass}\gobbletwoarguments}}

\resettwopassentries

\def\appendtwopasselement#1#2#3% can sometimes become a large list
  {%\debuggerinfo{\m!systems}{twopass data #1 - #2 = #3}%
   \expandafter\xdef\csname#1:\s!list\endcsname
     {\@EA\ifx\csname#1:\s!list\endcsname\empty \else
        \csname#1:\s!list\endcsname,\fi#3}}

\def\dodefinetwopasslist#1%
  {\doifundefined{#1:\s!list}
     {%\debuggerinfo\m!systems{defining twopass class #1}%
      \doglobal\addutilityreset{#1\s!pass}%
      \setgvalue{\s!set  #1\s!pass}{\dosettwopasslist  {#1}}%
      \setgvalue{\s!reset#1\s!pass}{\doresettwopasslist{#1}}%
      \getvalue {\s!reset#1\s!pass}}}

\def\definetwopasslist#1%
  {\expanded{\dodefinetwopasslist{#1}}%
   \doglobal\addtocommalist{#1}\alltwopasslists}

\def\dosettwopasslist#1%
  {\letgvalue{\s!set#1\s!pass}\gobbletwoarguments
   \setgvalue{@@#1\s!pass}{\appendtwopasselement{#1}}}

\def\doresettwopasslist#1%
  {\letgvalue{@@#1\s!pass}\gobbletwoarguments}

\def\doloadtwopassdata#1%
  {\doifundefined{#1:\s!list}
     {\startnointerference
      \letgvalueempty{#1:\s!list}%
      \protectlabels
      \doutilities{twopassentries,#1\s!pass}\jobname\empty\relax\relax
      \stopnointerference}}

\def\loadtwopassdata
  {\ifx\alltwopasslists\empty\else
     \processcommacommand[\alltwopasslists]\doloadtwopassdata
     \globallet\alltwopasslists\empty
   \fi}

\def\dogettwopassdata[#1,#2]#3#4%
  {\edef\twopassdata{#1}%
   \ifx\twopassdata\empty
     \twopassdatafoundfalse
     \let\twopassdata\empty
   \else
     \twopassdatafoundtrue
     \ifcase#4\or\setxvalue{#3:\s!list}{#2}\fi
   \fi}

\def\gettwopassdata#1%
  {\loadtwopassdata \@EAEAEA\dogettwopassdata\@EA\@EA\@EA[\csname#1:\s!list\endcsname,]{#1}\plusone}

\def\checktwopassdata#1%
  {\loadtwopassdata \@EAEAEA\dogettwopassdata\@EA\@EA\@EA[\csname#1:\s!list\endcsname,]{#1}\zerocount}

\def\findtwopassdata#1#2%
  {\loadtwopassdata \expanded{\dofindtwopassdata{#1}{#2}}}

\def\dofindtwopassdata#1#2%
  {\def\dodofindtwopassdata[##1,##2#2::##3,##4]{\edef\twopassdata{##3}}%
   \@EAEAEA\dodofindtwopassdata\@EA\@EA\@EA[\@EA\@EA\@EA,\csname#1:\s!list\endcsname,#2,#2::,]%
   \ifx\twopassdata\empty
     \twopassdatafoundfalse
   \else
     \twopassdatafoundtrue
   \fi}

\let\getfirsttwopassdata\checktwopassdata

\def\getlasttwopassdata#1%
  {\loadtwopassdata
   \scratchcounter\zerocount
   \@EAEAEA\rawprocesscommalist\@EA\@EA\@EA[\csname#1:\s!list\endcsname]\dogetlasttwopassdata
   \edef\noftwopassitems{\the\scratchcounter}%
   \iftwopassdatafound\else
     \let\twopassdata\empty
   \fi}

\def\dogetlasttwopassdata#1%
  {\edef\nexttwopassdata{#1}%
   \ifx\nexttwopassdata\empty \else
     \let\twopassdata\nexttwopassdata
     \advance\scratchcounter \plusone
     \twopassdatafoundtrue
   \fi}

\def\getfromtwopassdata#1#2%
  {\loadtwopassdata
   \@EAEAEA\getfromcommalist\@EA\@EA\@EA[\csname#1:\s!list\endcsname][#2]%
   \ifx\commalistelement\empty
     \twopassdatafoundfalse
     \let\twopassdata\empty
   \else
     \twopassdatafoundtrue
     \let\twopassdata\commalistelement
   \fi}

\def\gettwopassdatalist#1%
  {\loadtwopassdata
   \letcscsname\twopassdatalist\csname#1:\s!list\endcsname
   \ifx\twopassdatalist\relax\let\twopassdatalist\empty\fi}

\def\gettwopassdatalist
  {\getnamedtwopassdatalist\twopassdatalist}

\def\doifelseintwopassdata#1#2% tag dat
  {\gettwopassdatalist{#1}%
   \expanded{\doifinsetelse{#2}{\twopassdatalist}}}

\protect \endinput