Debian Codegraph @

texmf-dist/tex/plain/pdftoolbox/pdfData/ptb-arrays.tex

raw
1 \input ptb-utils
2 \_checkloaded{arrays}
3 \input pdfData/ptb-stack
4
5 \def\createarray#1{%
6 \_xp\currdef\csname arr@#1\endcsname{}%
7 \_xp\currdef\csname arr@#1@len\endcsname{0}%
8 }
9
10 \def\arrayexists#1{%
11 \ifcsname arr@#1\endcsname%
12 \let\@return@value=\True%
13 \else%
14 \let\@return@value=\False%
15 \fi%
16 }
17
18 \def\ensurearray#1{%
19 \unless\ifcsname arr@#1\endcsname%
20 \createarray{#1}%
21 \fi%
22 }
23
24 \def\localizearray#1{%
25 \_xp\localize\csname arr@#1\endcsname%
26 \_xp\localize\csname arr@#1@len\endcsname%
27 }
28
29 \long\def\appendarray#1#2{%
30 \def\_uregA{\_xp\currdef\csname arr@#1\endcsname}%
31 \_xp\_xp\_xp\_uregA\_xp\_xp\_xp{\csname arr@#1\endcsname\_arr_index{#2}}%
32 \_xp\curredef\csname arr@#1@len\endcsname{\the\numexpr\csname arr@#1@len\endcsname+1\relax}%
33 }
34
35 \long\def\prependarray#1#2{%
36 \def\_uregA{\_xp\currdef\csname arr@#1\endcsname}%
37 \def\_uregB{\_arr_index{#2}}%
38 \_xp\_xp\_xp\_xp\_xp\_xp\_xp\_uregA\_xp\_xp\_xp\_xp\_xp\_xp\_xp{\_xp\_xp\_xp\_uregB\csname arr@#1\endcsname}%
39 \_xp\curredef\csname arr@#1@len\endcsname{\the\numexpr\csname arr@#1@len\endcsname+1\relax}%
40 }
41
42 \long\def\appendarraymany#1#2{%
43 \map{\appendarray{#1}}{#2}%
44 }
45
46 \long\def\_appendarrayvalue#1#2#3{\appendarray{#1}{{#3}{#2}}}
47 \long\def\appendarraymanyvalued#1#2#3{\map{\_appendarrayvalue{#1}{#2}}{#3}}
48
49 \def\arraylen#1{%
50 \csname arr@#1@len\endcsname%
51 }
52
53 \def\getarraylen#1#2{%
54 \_xp\let\_xp#2\csname arr@#1@len\endcsname%
55 }
56
57 \def\executearray#1{\csname arr@#1\endcsname}
58
59 \def\arraymap#1#2{%
60 \def\_mac_arr_cnt{0}%
61 \beginscope%
62 \localize\_arr_index%
63 \long\def\_arr_index##1{%
64 \beginscope%
65 \localize\_mac_arr_cnt%
66 #2{##1}{\_mac_arr_cnt}%
67 \edef\_mac_arr_cnt{\the\numexpr\_mac_arr_cnt+1\relax}%
68 \endscope%
69 }%
70 \csname arr@#1\endcsname%
71 \endscope%
72 }
73
74 \newcount\_arr_cnt
75 \newcount\_arr_cntB
76 \def\indexarray#1#2#3{%
77 \let#3=\_nul%
78 \long\def\_arr_index##1{%
79 \ifnum\_arr_cnt=#2 %
80 \def#3{##1}
81 \fi%
82 \advance\_arr_cnt by 1 %
83 }
84 \csname arr@#1\endcsname%
85 }
86
87 \def\removearray#1#2#3{%
88 \_arr_cnt=0 %
89 \let#3=\_nul%
90 \_xp\let\_xp\_regA\csname arr@#1\endcsname%
91 \createarray{#1}%
92 \def\_arr_index##1{%
93 \ifnum\_arr_cnt=#2 %
94 \def#3{##1}%
95 \else%
96 \appendarray{#1}{##1}%
97 \fi
98 \advance\_arr_cnt by 1 %
99 }%
100 \_regA%
101 }
102
103 \def\removeitemarray#1#2{%
104 \def\_temp{#2}%
105 \_xp\let\_xp\_regA\csname arr@#1\endcsname%
106 \createarray{#1}%
107 \def\_arr_index##1{%
108 \def\_tempA{##1}%
109 \unless\ifx\_temp\_tempA%
110 \appendarray{#1}{##1}%
111 \fi%
112 }%
113 \_regA%
114 }
115
116 \long\def\__printarray#1#2#3{%
117 #1{#2}%
118 \unless\ifnum\_arr_cnt=\_temp%
119 ,
120 \fi%
121 }
122
123 \def\_printarray#1[#2]{%
124 \getarraylen{#1}\_temp%
125 \edef\_temp{\the\numexpr \_temp-1\relax}%
126 \arraymap{#1}{\__printarray{#2}}%
127 }
128
129 \def\printarray#1{\_ifnextchar[ {\_printarray{#1}}{\_printarray{#1}[\relax]}}
130
131 \def\copyarray#1#2{%
132 \def\_temp{\csname arr@#2\endcsname}%
133 \_xp\_xp\_xp\_xp\_xp\_xp\_xp\let\_xp\_temp\csname arr@#1\endcsname%
134 \def\_temp{\csname arr@#2@len\endcsname}%
135 \_xp\_xp\_xp\_xp\_xp\_xp\_xp\let\_xp\_temp\csname arr@#1@len\endcsname%
136 }
137
138 \def\_concatenatearray#1#2#3#4#5{%
139 \_xp\currdef\csname arr@#5\endcsname{#1#2}%
140 \_xp\curredef\csname arr@#5@len\endcsname{\the\numexpr\csname arr@#3@len\endcsname + \csname arr@#4@len\endcsname\relax}%
141 }
142
143 \def\concatenatearrays#1#2#3{%
144 \def\_temp{\csname arr@#1\endcsname}%
145 \_xp\_xp\_xp\_concatenatearray\_xp\_xp\_xp{\_xp\_temp\_xp}\_xp{\csname arr@#2\endcsname}{#1}{#2}{#3}%
146 }
147
148 \def\createmarray#1{\_xp\currdef\csname marr@#1@len\endcsname{0}}
149
150 \def\localizemarray#1{%
151 \_xp\localize\csname marr@#1@len\endcsname%
152 \_arr_cnt=0 %
153 \loop\ifnum\_arr_cnt < \csname marr@#1@len\endcsname %
154 \_xp\localize\csname marr@#1@idx@\the\_arr_cnt\endcsname%
155 \advance\_arr_cnt by 1 %
156 \repeat%
157 }
158
159 \def\appendmarray#1#2{%
160 \_xp\currdef\csname marr@#1@idx@\csname marr@#1@len\endcsname\endcsname{#2}%
161 \_xp\curredef\csname marr@#1@len\endcsname{\the\numexpr\csname marr@#1@len\endcsname + 1\relax}%
162 }
163
164 \def\_rappendmarray#1#2{\appendmarray{#2}{#1}}
165 \def\_rappendarray#1#2{\appendarray{#2}{#1}}
166
167 \def\printmarray#1{%
168 \_arr_cnt=0 %
169 \loop\ifnum\_arr_cnt < \csname marr@#1@len\endcsname %
170 (\csname marr@#1@idx@\the\_arr_cnt\endcsname)%
171 \advance\_arr_cnt by 1 %
172 \ifnum\_arr_cnt < \csname marr@#1@len\endcsname %
173 , %
174 \fi%
175 \repeat%
176 }
177
178 \def\convertarray#1#2{%
179 \createmarray{#2}%
180 \_xp\curredef\csname marr@#2@len\endcsname{\csname arr@#1@len\endcsname}%
181 \_arr_cnt=0 %
182 \def\_arr_index##1{%
183 \_xp\currdef\csname marr@#2@idx@\the\_arr_cnt\endcsname{##1}%
184 \advance\_arr_cnt by 1 %
185 }%
186 \csname arr@#1\endcsname%
187 }
188
189 \def\convertmarray#1#2{%
190 \createarray{#2}%
191 %\_xp\edef\csname arr@#2@len\endcsname{\csname marr@#1@len\endcsname}%
192 \_arr_cnt=0 %
193 \loop\ifnum\_arr_cnt < \csname marr@#1@len\endcsname %
194 \_xp\_rappendarray\_xp{\csname marr@#1@idx@\the\_arr_cnt\endcsname}{#2}%
195 \advance\_arr_cnt by 1 %
196 \repeat%
197 }
198
199 \def\copymarray#1#2{%
200 \createmarray{#2}%
201 \_arr_cnt=0 %
202 \loop\ifnum\_arr_cnt < \csname marr@#1@len\endcsname %
203 \_xp\_xp\_xp\_rappendmarray\_xp\_xp\_xp{\csname marr@#1@idx@\the\_arr_cnt\endcsname}{#2}%
204 \advance\_arr_cnt by 1 %
205 \repeat%
206 }
207
208 % #1: name of array
209 % #2: text to initialize array to
210 % #3: macro for creating array
211 % #4: macro for appending to array
212 \def\_init_array#1#2#3#4{%
213 #3{#1}%
214 \commap{#4{#1}}{#2}%
215 }
216
217 \def\initarray#1#2{%
218 \_init_array{#1}{#2}\createarray\appendarray%
219 }
220
221 \def\initmarray#1#2{%
222 \_init_array{#1}{#2}\createmarray\appendmarray%
223 }
224
225 \def\findarray#1#2{%
226 \def\_regA{#2}%
227 \let\@return@value=\False%
228 \def\_arr_index##1{%
229 \def\_regB{##1}%
230 \ifx\_regA\_regB%
231 \let\@return@value=\True%
232 \fi%
233 }%
234 \csname arr@#1\endcsname%
235 }
236
237 \def\uniqueappendarray#1#2{%
238 \findarray{#1}{#2}%
239 \ifx\@return@value\False%
240 \appendarray{#1}{#2}%
241 \fi%
242 }
243
244 \def\findmarray#1#2#3{%
245 \def\_regA{#2}
246 \let\@return@value=\False%
247 \_arr_cnt=0 %
248 \loop\ifnum\_arr_cnt < \csname arr@#1@len\endcsname %
249 \ifx\_regA\csname arr@#1@idx@\the\_arr_cnt\endcsname%
250 \let\@return@value=\True%
251 \_xp\let\_xp#3\csname arr@#1@idx@\the\_arr_cnt\endcsname%
252 \fi%
253 \advance\_arr_cnt by 1 %
254 \repeat%
255 }
256