Debian Codegraph @

texk/web2c/etexdir/etex.ch

raw
1 % This is etex.ch, a
2 % WEB change file containing code for various features extending TeX;
3 % to be applied to tex.web in order to define the
4 % e-TeX program.
5
6 % e-TeX is copyright (C) 1999-2012 by P. Breitenlohner (1994,98 by the NTS
7 % team); all rights are reserved. Copying of this file is authorized only if
8 % (1) you are P. Breitenlohner, or if (2) you make absolutely no changes to
9 % your copy. (Programs such as TIE allow the application of several change
10 % files to tex.web; the master files tex.web and etex.ch should stay intact.)
11
12 % See etex_gen.tex for hints on how to install this program.
13 % And see etripman.tex for details about how to validate it.
14
15 % The TeX program is copyright (C) 1982 by D. E. Knuth.
16 % TeX is a trademark of the American Mathematical Society.
17 % e-TeX and NTS are trademarks of the NTS group.
18
19 % All line numbers refer to tex.web 3.141592653 as of January 29, 2021.
20
21 @x [0.0] l.1 - this is e-TeX
22 % This program is copyright (C) 1982 by D. E. Knuth; all rights are reserved.
23 % Unlimited copying and redistribution of this file are permitted as long
24 % as this file is not modified. Modifications are permitted, but only if
25 % the resulting file is not named tex.web. (The WEB system provides
26 % for alterations via an auxiliary file; the master file should stay intact.)
27 % See Appendix H of the WEB manual for hints on how to install this program.
28 % And see Appendix A of the TRIP manual for details about how to validate it.
29
30 % TeX is a trademark of the American Mathematical Society.
31 % METAFONT is a trademark of Addison-Wesley Publishing Company.
32 @y
33 % e-TeX is copyright (C) 1999-2012 by P. Breitenlohner (1994,98 by the NTS
34 % team); all rights are reserved. Copying of this file is authorized only if
35 % (1) you are P. Breitenlohner, or if (2) you make absolutely no changes to
36 % your copy. (Programs such as TIE allow the application of several change
37 % files to tex.web; the master files tex.web and etex.ch should stay intact.)
38
39 % See etex_gen.tex for hints on how to install this program.
40 % And see etripman.tex for details about how to validate it.
41
42 % e-TeX and NTS are trademarks of the NTS group.
43 % TeX is a trademark of the American Mathematical Society.
44 % METAFONT is a trademark of Addison-Wesley Publishing Company.
45
46 % This program is directly derived from Donald E. Knuth's TeX;
47 % the change history which follows and the reward offered for finders of
48 % bugs refer specifically to TeX; they should not be taken as referring
49 % to e-TeX, although the change history is relevant in that it
50 % demonstrates the evolutionary path followed. This program is not TeX;
51 % that name is reserved strictly for the program which is the creation
52 % and sole responsibility of Professor Knuth.
53 @z
54 %---------------------------------------
55 @x [0.0] l.54 - e-TeX history
56 % Although considerable effort has been expended to make the TeX program
57 % correct and reliable, no warranty is implied; the author disclaims any
58 % obligation or liability for damages, including but not limited to
59 % special, indirect, or consequential damages arising out of or in
60 % connection with the use or performance of this software. This work has
61 % been a ``labor of love'' and the author hopes that users enjoy it.
62 @y
63 % A preliminary version of TeX--XeT was released in April 1992.
64 % TeX--XeT version 1.0 was released in June 1992,
65 % version 1.1 prevented arith overflow in glue computation (Oct 1992).
66 % A preliminary e-TeX version 0.95 was operational in March 1994.
67 % Version 1.0beta was released in May 1995.
68 % Version 1.01beta fixed bugs in just_copy and every_eof (December 1995).
69 % Version 1.02beta allowed 256 mark classes (March 1996).
70 % Version 1.1 changed \group{type,level} -> \currentgroup{type,level},
71 % first public release (October 1996).
72 % Version 2.0 development was started in March 1997;
73 % fixed a ligature-\beginR bug in January 1998;
74 % was released in March 1998.
75 % Version 2.1 fixed a \marks bug (when min_halfword<>0) (January 1999).
76 % Version 2.2 development was started in Feb 2003; released in Oct 2004.
77 % fixed a bug in sparse array handling (0=>null), Jun 2002;
78 % fixed a bug in \lastnodetype (cur_val=>cur_val_level)
79 % reported by Hartmut Henkel <hartmut_henkel@@gmx.de>,
80 % fix by Fabrice Popineau <Fabrice.Popineau@@supelec.fr>,
81 % Jan 2004;
82 % another bug in sparse array handling (cur_ptr=>cur_chr)
83 % reported by Taco Hoekwater <taco@@elvenkind.com>, Jul 2004;
84 % fixed a sparse array reference count bug (\let,\futurelet),
85 % fix by Bernd Raichle <berd@@dante.de>, Aug 2004;
86 % reorganized handling of banner, additional token list and
87 % integer parameters, and similar in order to reduce the
88 % interference between eTeX, pdfTeX, and web2c change files.
89 % adapted to tex.web 3.141592, revised glue rounding for mixed
90 % direction typesetting;
91 % fixed a bug in the revised glue rounding code, detected by
92 % Tigran Aivazian <tigran@@aivazian.fsnet.co.uk>, Oct 2004.
93 % Version 2.3 development was started in Feb 2008; released in Apr 2011.
94 % fixed a bug in hyph_code handling (\savinghyphcodes)
95 % reported by Vladimir Volovich <vvv@@vsu.ru>, Feb 2008.
96 % fixed the error messages for improper use of \protected,
97 % reported by Heiko Oberdiek
98 % <heiko.oberdiek@@googlemail.com>, May 2010.
99 % some rearrangements to reduce interferences between
100 % e-TeX and pTeX, in part suggested by Hironori Kitagawa
101 % <h_kitagawa2001@@yahoo.co.jp>, Mar 2011.
102 % Version 2.4 fixed an uninitialized line number bug, released in May 2012.
103 % Version 2.5 development was started in Aug 2012; released in Feb 2013.
104 % better tracing of font definitions, reported by
105 % Bruno Le Floch <blflatex@@gmail.com>, Jul 2012.
106 % Version 2.6 development was started in Mar 2013; released in ??? 201?.
107 % enable hyphenation of text between \beginL and \endL or
108 % between \beginR and \endR, problem reported by
109 % Vafa Khalighi <vafalgk@@gmail.com>, Nov 2013.
110 % better handling of right-to-left text -- to be done.
111
112 % Although considerable effort has been expended to make the e-TeX program
113 % correct and reliable, no warranty is implied; the author disclaims any
114 % obligation or liability for damages, including but not limited to
115 % special, indirect, or consequential damages arising out of or in
116 % connection with the use or performance of this software. This work has
117 % been a ``labor of love'' and the author hopes that users enjoy it.
118 @z
119 %---------------------------------------
120 @x [0.0] l.66 - e-TeX logo, TeXXeT
121 \let\mc=\ninerm % medium caps for names like SAIL
122 @y
123 \let\mc=\ninerm % medium caps for names like SAIL
124 \def\eTeX{$\varepsilon$-\TeX}
125 \font\revrm=xbmc10 % for right-to-left text
126 % to generate xbmc10 (i.e., reflected cmbx10) use a file
127 % xbmc10.mf containing:
128 %+++++++++++++++++++++++++++++++++++++++++++++++++
129 % if unknown cmbase: input cmbase fi
130 % extra_endchar := extra_endchar &
131 % "currentpicture:=currentpicture " &
132 % "reflectedabout((.5[l,r],0),(.5[l,r],1));";
133 % input cmbx10
134 %+++++++++++++++++++++++++++++++++++++++++++++++++
135 \ifx\beginL\undefined % this is TeX
136 \def\XeT{X\kern-.125em\lower.5ex\hbox{E}\kern-.1667emT}
137 \def\TeXeT{\TeX-\hbox{\revrm \XeT}} % for TeX-XeT
138 \def\TeXXeT{\TeX-\hbox{\revrm -\XeT}} % for TeX--XeT
139 \else
140 \ifx\eTeXversion\undefined % this is \TeXeT
141 \def\TeXeT{\TeX-{\revrm\beginR\TeX\endR}} % for TeX-XeT
142 \def\TeXXeT{\TeX-{\revrm\beginR\TeX-\endR}} % for TeX--XeT
143 \else % this is \eTeX
144 \def\TeXeT{\TeX-{\TeXXeTstate=1\revrm\beginR\TeX\endR}} % for TeX-XeT
145 \def\TeXXeT{\TeX-{\TeXXeTstate=1\revrm\beginR\TeX-\endR}} % for TeX--XeT
146 \fi
147 \fi
148 @z
149 %---------------------------------------
150 @x [0.0] l.69 - bug fix (print only changed modules)
151 \def\pct!{{\char`\%}} % percent sign in ordinary text
152 @y
153 \def\pct!{{\char`\%}} % percent sign in ordinary text
154 \def\grp{\.{\char'173...\char'175}}
155 @z
156 %---------------------------------------
157 @x [0.0] l.85 - e-TeX basic
158 \def\title{\TeX82}
159 @y
160 \def\title{\eTeX}
161 % system dependent redefinitions of \title should come later
162 % and should use:
163 % \toks0=\expandafter{\title}
164 % \edef\title{...\the\toks0...}
165 \let\maybe=\iffalse % print only changed modules
166 @z
167 %---------------------------------------
168 @x [1.1] l.96 - this is e-TeX
169 This is \TeX, a document compiler intended to produce typesetting of high
170 @y
171 This is \eTeX, a program derived from and extending the capabilities of
172 \TeX, a document compiler intended to produce typesetting of high
173 @z
174 %---------------------------------------
175 @x [1.2] l.185 - e-TeX basic
176 If this program is changed, the resulting system should not be called
177 @y
178 This program contains code for various features extending \TeX,
179 therefore this program is called `\eTeX' and not
180 @z
181 %---------------------------------------
182 @x [1.2] l.191 - e-TeX basic
183 November 1984].
184 @y
185 November 1984].
186
187 A similar test suite called the ``\.{e-TRIP} test'' is available for
188 helping to determine whether a particular implementation deserves to be
189 known as `\eTeX'.
190 @z
191 %---------------------------------------
192 @x [1.2] l.193 - e-TeX basic
193 @d banner=='This is TeX, Version 3.141592653' {printed when \TeX\ starts}
194 @y
195 @d eTeX_version=2 { \.{\\eTeXversion} }
196 @d eTeX_revision==".6" { \.{\\eTeXrevision} }
197 @d eTeX_version_string=='-2.6' {current \eTeX\ version}
198 @#
199 @d eTeX_banner=='This is e-TeX, Version 3.141592653',eTeX_version_string
200 {printed when \eTeX\ starts}
201 @#
202 @d TeX_banner=='This is TeX, Version 3.141592653' {printed when \TeX\ starts}
203 @#
204 @d banner==eTeX_banner
205 @#
206 @d TEX==ETEX {change program name into |ETEX|}
207 @#
208 @d TeXXeT_code=0 {the \TeXXeT\ feature is optional}
209 @#
210 @d eTeX_states=1 {number of \eTeX\ state variables in |eqtb|}
211 @z
212 %---------------------------------------
213 @x [1.3] l.212 - e-TeX basic
214 scalar types; there are no `\&{var}' parameters, except in the case of files;
215 @y
216 scalar types; there are no `\&{var}' parameters, except in the case of files
217 --- \eTeX, however, does use `\&{var}' parameters for the |reverse| function;
218 @z
219 %---------------------------------------
220 @x [1.15] l.507 - e-TeX basic
221 @d not_found=45 {go here when you've found nothing}
222 @y
223 @d not_found=45 {go here when you've found nothing}
224 @d not_found1=46 {like |not_found|, when there's more than one}
225 @d not_found2=47 {like |not_found|, when there's more than two}
226 @d not_found3=48 {like |not_found|, when there's more than three}
227 @d not_found4=49 {like |not_found|, when there's more than four}
228 @z
229 %---------------------------------------
230 @x [10.135] l.2901 - e-TeX TeXXeT
231 |fil|, |fill|, or |filll|). The |subtype| field is not used.
232 @y
233 |fil|, |fill|, or |filll|). The |subtype| field is not used in \TeX.
234 In \eTeX\ the |subtype| field records the box direction mode |box_lr|.
235 @z
236 %---------------------------------------
237 @x [10.141] l.2986 - e-TeX marks
238 This field occupies a full word instead of a halfword, because
239 there's nothing to put in the other halfword; it is easier in \PASCAL\ to
240 use the full word than to risk leaving garbage in the unused half.
241 @y
242 In addition there is a |mark_class| field that contains the mark class.
243 @z
244 %---------------------------------------
245 @x [10.141] l.2992 - e-TeX marks
246 @d mark_ptr(#)==mem[#+1].int {head of the token list for a mark}
247 @y
248 @d mark_ptr(#)==link(#+1) {head of the token list for a mark}
249 @d mark_class(#)==info(#+1) {the mark class}
250 @z
251 %---------------------------------------
252 @x [10.142] l.3001 - e-TeX marks
253 @d adjust_ptr==mark_ptr {vertical list to be moved out of horizontal list}
254 @y
255 @d adjust_ptr(#)==mem[#+1].int
256 {vertical list to be moved out of horizontal list}
257 @z
258 %---------------------------------------
259 @x [10.147] l.3090 - e-TeX TeXXeT
260 the amount of surrounding space inserted by \.{\\mathsurround}.
261 @y
262 the amount of surrounding space inserted by \.{\\mathsurround}.
263
264 In addition a |math_node| with |subtype>after| and |width=0| will be
265 (ab)used to record a regular |math_node| reinserted after being
266 discarded at a line break or one of the text direction primitives (
267 \.{\\beginL}, \.{\\endL}, \.{\\beginR}, and \.{\\endR} ).
268 @z
269 %---------------------------------------
270 @x [10.147] l.3094 - e-TeX TeXXeT
271 @d after=1 {|subtype| for math node that winds up a formula}
272 @y
273 @d after=1 {|subtype| for math node that winds up a formula}
274 @#
275 @d M_code=2
276 @d begin_M_code=M_code+before {|subtype| for \.{\\beginM} node}
277 @d end_M_code=M_code+after {|subtype| for \.{\\endM} node}
278 @d L_code=4
279 @d begin_L_code=L_code+begin_M_code {|subtype| for \.{\\beginL} node}
280 @d end_L_code=L_code+end_M_code {|subtype| for \.{\\endL} node}
281 @d R_code=L_code+L_code
282 @d begin_R_code=R_code+begin_M_code {|subtype| for \.{\\beginR} node}
283 @d end_R_code=R_code+end_M_code {|subtype| for \.{\\endR} node}
284 @#
285 @d end_LR(#)==odd(subtype(#))
286 @d end_LR_type(#)==(L_code*(subtype(#) div L_code)+end_M_code)
287 @d begin_LR_type(#)==(#-after+before)
288 @z
289 %---------------------------------------
290 @x [12.175] l.3567 - e-TeX TeXXeT
291 math_node: print_char("$");
292 @y
293 math_node: if subtype(p)>=L_code then print("[]")
294 else print_char("$");
295 @z
296 %---------------------------------------
297 @x [12.184] l.3734 - e-TeX TeXXeT
298 begin print(", shifted "); print_scaled(shift_amount(p));
299 end;
300 @y
301 begin print(", shifted "); print_scaled(shift_amount(p));
302 end;
303 if eTeX_ex then @<Display if this box is never to be reversed@>;
304 @z
305 %---------------------------------------
306 @x [12.192] l.3832 - e-TeX TeXXeT
307 begin print_esc("math");
308 @y
309 if subtype(p)>after then
310 begin if end_LR(p) then print_esc("end")
311 else print_esc("begin");
312 if subtype(p)>R_code then print_char("R")
313 else if subtype(p)>L_code then print_char("L")
314 else print_char("M");
315 end else
316 begin print_esc("math");
317 @z
318 %---------------------------------------
319 @x [12.196] l.3865 - e-TeX marks
320 begin print_esc("mark"); print_mark(mark_ptr(p));
321 @y
322 begin print_esc("mark");
323 if mark_class(p)<>0 then
324 begin print_char("s"); print_int(mark_class(p));
325 end;
326 print_mark(mark_ptr(p));
327 @z
328 %---------------------------------------
329 @x [15.208] l.4102 - e-TeX saved_items
330 @d un_vbox=24 {unglue a box ( \.{\\unvbox}, \.{\\unvcopy} )}
331 @y
332 @d un_vbox=24 {unglue a box ( \.{\\unvbox}, \.{\\unvcopy} )}
333 {( or \.{\\pagediscards}, \.{\\splitdiscards} )}
334 @z
335 %---------------------------------------
336 @x [15.208] l.4112 - e-TeX TeXXeT
337 @d valign=33 {vertical table alignment ( \.{\\valign} )}
338 @y
339 @d valign=33 {vertical table alignment ( \.{\\valign} )}
340 {or text direction directives ( \.{\\beginL}, etc.~)}
341 @z
342 %---------------------------------------
343 @x [15.208] l.4128 - e-TeX middle
344 @d left_right=49 {variable delimiter ( \.{\\left}, \.{\\right} )}
345 @y
346 @d left_right=49 {variable delimiter ( \.{\\left}, \.{\\right} )}
347 {( or \.{\\middle} )}
348 @z
349 %---------------------------------------
350 @x [15.209] l.4172 - e-TeX basic
351 \.{\\insertpenalties} )}
352 @y
353 \.{\\insertpenalties} )}
354 {( or \.{\\interactionmode} )}
355 @z
356 %---------------------------------------
357 @x [15.209] l.4174 - e-TeX penalties
358 @d set_shape=84 {specify fancy paragraph shape ( \.{\\parshape} )}
359 @y
360 @d set_shape=84 {specify fancy paragraph shape ( \.{\\parshape} )}
361 {(or \.{\\interlinepenalties}, etc.~)}
362 @z
363 %---------------------------------------
364 @x [15.209] l.4184 - e-TeX protected
365 @d prefix=93 {qualify a definition ( \.{\\global}, \.{\\long}, \.{\\outer} )}
366 @y
367 @d prefix=93 {qualify a definition ( \.{\\global}, \.{\\long}, \.{\\outer} )}
368 {( or \.{\\protected} )}
369 @z
370 %---------------------------------------
371 @x [15.209] l.4187 - e-TeX read_line
372 @d read_to_cs=96 {read into a control sequence ( \.{\\read} )}
373 @y
374 @d read_to_cs=96 {read into a control sequence ( \.{\\read} )}
375 {( or \.{\\readline} )}
376 @z
377 %---------------------------------------
378 @x [15.210] l.4202 - e-TeX scan_tokens
379 @d input=max_command+4 {input a source file ( \.{\\input}, \.{\\endinput} )}
380 @y
381 @d input=max_command+4 {input a source file ( \.{\\input}, \.{\\endinput} )}
382 {( or \.{\\scantokens} )}
383 @z
384 %---------------------------------------
385 @x [15.210] l.4207 - e-TeX unexpanded
386 @d the=max_command+9 {expand an internal quantity ( \.{\\the} )}
387 @y
388 @d the=max_command+9 {expand an internal quantity ( \.{\\the} )}
389 {( or \.{\\unexpanded}, \.{\\detokenize} )}
390 @z
391 %---------------------------------------
392 @x [16.212] l.4310 - e-TeX basic
393 user's output routine.
394 @y
395 user's output routine.
396
397 A seventh quantity, |eTeX_aux|, is used by the extended features \eTeX.
398 In vertical modes it is known as |LR_save| and holds the LR stack when a
399 paragraph is interrupted by a displayed formula. In display math mode
400 it is known as |LR_box| and holds a pointer to a prototype box for the
401 display. In math mode it is known as |delim_ptr| and points to the most
402 recent |left_noad| or |middle_noad| of a |math_left_group|.
403 @z
404 %---------------------------------------
405 @x [16.212] l.4325 - e-TeX basic
406 @!head_field,@!tail_field: pointer;
407 @y
408 @!head_field,@!tail_field: pointer;
409 @!eTeX_aux_field: pointer;
410 @z
411 %---------------------------------------
412 @x [16.213] l.4332 - e-TeX basic
413 @d tail==cur_list.tail_field {final node on current list}
414 @y
415 @d tail==cur_list.tail_field {final node on current list}
416 @d eTeX_aux==cur_list.eTeX_aux_field {auxiliary data for \eTeX}
417 @d LR_save==eTeX_aux {LR stack when a paragraph is interrupted}
418 @d LR_box==eTeX_aux {prototype box for display}
419 @d delim_ptr==eTeX_aux {most recent left or right noad of a math left group}
420 @z
421 %---------------------------------------
422 @x [16.215] l.4363 - e-TeX basic
423 mode:=vmode; head:=contrib_head; tail:=contrib_head;
424 @y
425 mode:=vmode; head:=contrib_head; tail:=contrib_head;
426 eTeX_aux:=null;
427 @z
428 %---------------------------------------
429 @x [16.216] l.4379 - push_nest - e-TeX basic
430 incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line;
431 @y
432 incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line;
433 eTeX_aux:=null;
434 @z
435 %---------------------------------------
436 @x [17.230] l.4742 - e-TeX basic, every_eof
437 @d toks_base=local_base+10 {table of 256 token list registers}
438 @y
439 @d tex_toks=local_base+10 {end of \TeX's token list parameters}
440 @#
441 @d etex_toks_base=tex_toks {base for \eTeX's token list parameters}
442 @d every_eof_loc=etex_toks_base {points to token list for \.{\\everyeof}}
443 @d etex_toks=etex_toks_base+1 {end of \eTeX's token list parameters}
444 @#
445 @d toks_base=etex_toks {table of 256 token list registers}
446 @z
447 %---------------------------------------
448 @x [17.230] l.4743 - e-TeX basic, penalties
449 @d box_base=toks_base+256 {table of 256 box registers}
450 @y
451 @#
452 @d etex_pen_base=toks_base+256 {start of table of \eTeX's penalties}
453 @d inter_line_penalties_loc=etex_pen_base {additional penalties between lines}
454 @d club_penalties_loc=etex_pen_base+1 {penalties for creating club lines}
455 @d widow_penalties_loc=etex_pen_base+2 {penalties for creating widow lines}
456 @d display_widow_penalties_loc=etex_pen_base+3 {ditto, just before a display}
457 @d etex_pens=etex_pen_base+4 {end of table of \eTeX's penalties}
458 @#
459 @d box_base=etex_pens {table of 256 box registers}
460 @z
461 %---------------------------------------
462 @x [17.231] l.4808 - e-TeX basic
463 othercases print_esc("errhelp")
464 @y
465 @/@<Cases of |assign_toks| for |print_cmd_chr|@>@/
466 othercases print_esc("errhelp")
467 @z
468 %---------------------------------------
469 @x [17.232] l.4826 - e-TeX penalties
470 eq_level(par_shape_loc):=level_one;@/
471 @y
472 eq_level(par_shape_loc):=level_one;@/
473 for k:=etex_pen_base to etex_pens-1 do
474 eqtb[k]:=eqtb[par_shape_loc];
475 @z
476 %---------------------------------------
477 @x [17.233] l.4854 - e-TeX penalties
478 if n=par_shape_loc then
479 begin print_esc("parshape"); print_char("=");
480 if par_shape_ptr=null then print_char("0")
481 @y
482 if (n=par_shape_loc) or ((n>=etex_pen_base) and (n<etex_pens)) then
483 begin print_cmd_chr(set_shape,n); print_char("=");
484 if equiv(n)=null then print_char("0")
485 else if n>par_shape_loc then
486 begin print_int(penalty(equiv(n))); print_char(" ");
487 print_int(penalty(equiv(n)+1));
488 if penalty(equiv(n))>1 then print_esc("ETC.");
489 end
490 @z
491 %---------------------------------------
492 @x [17.236] l.4975 - e-TeX basic
493 @d int_pars=55 {total number of integer parameters}
494 @y
495 @d tex_int_pars=55 {total number of \TeX's integer parameters}
496 @#
497 @d etex_int_base=tex_int_pars {base for \eTeX's integer parameters}
498 @d tracing_assigns_code=etex_int_base {show assignments}
499 @d tracing_groups_code=etex_int_base+1 {show save/restore groups}
500 @d tracing_ifs_code=etex_int_base+2 {show conditionals}
501 @d tracing_scan_tokens_code=etex_int_base+3 {show pseudo file open and close}
502 @d tracing_nesting_code=etex_int_base+4 {show incomplete groups and ifs within files}
503 @d pre_display_direction_code=etex_int_base+5 {text direction preceding a display}
504 @d last_line_fit_code=etex_int_base+6 {adjustment for last line of paragraph}
505 @d saving_vdiscards_code=etex_int_base+7 {save items discarded from vlists}
506 @d saving_hyph_codes_code=etex_int_base+8 {save hyphenation codes for languages}
507 @d eTeX_state_code=etex_int_base+9 {\eTeX\ state variables}
508 @d etex_int_pars=eTeX_state_code+eTeX_states {total number of \eTeX's integer parameters}
509 @#
510 @d int_pars=etex_int_pars {total number of integer parameters}
511 @z
512 %---------------------------------------
513 @x [17.236] l.5037 - e-TeX basic
514 @d error_context_lines==int_par(error_context_lines_code)
515 @y
516 @d error_context_lines==int_par(error_context_lines_code)
517 @#
518 @d tracing_assigns==int_par(tracing_assigns_code)
519 @d tracing_groups==int_par(tracing_groups_code)
520 @d tracing_ifs==int_par(tracing_ifs_code)
521 @d tracing_scan_tokens==int_par(tracing_scan_tokens_code)
522 @d tracing_nesting==int_par(tracing_nesting_code)
523 @d pre_display_direction==int_par(pre_display_direction_code)
524 @d last_line_fit==int_par(last_line_fit_code)
525 @d saving_vdiscards==int_par(saving_vdiscards_code)
526 @d saving_hyph_codes==int_par(saving_hyph_codes_code)
527 @z
528 %---------------------------------------
529 @x [17.237] l.5102 - print_param - e-TeX basic
530 othercases print("[unknown integer parameter!]")
531 @y
532 @/@<Cases for |print_param|@>@/
533 othercases print("[unknown integer parameter!]")
534 @z
535 %---------------------------------------
536 @x [18.264] l.5639 - primitive - e-TeX basic
537 @!j:small_number; {index into |buffer|}
538 @y
539 @!j:0..buf_size; {index into |buffer|}
540 @z
541 %---------------------------------------
542 @x [18.264] l.5643 - primitive - e-TeX basic
543 {we will move |s| into the (empty) |buffer|}
544 for j:=0 to l-1 do buffer[j]:=so(str_pool[k+j]);
545 cur_val:=id_lookup(0,l); {|no_new_control_sequence| is |false|}
546 @y
547 {we will move |s| into the (possibly non-empty) |buffer|}
548 if first+l>buf_size+1 then
549 overflow("buffer size",buf_size);
550 @:TeX capacity exceeded buffer size}{\quad buffer size@>
551 for j:=0 to l-1 do buffer[first+j]:=so(str_pool[k+j]);
552 cur_val:=id_lookup(first,l); {|no_new_control_sequence| is |false|}
553 @z
554 %---------------------------------------
555 @x [18.265] l.5718 - e-TeX penalties
556 primitive("parshape",set_shape,0);@/
557 @y
558 primitive("parshape",set_shape,par_shape_loc);@/
559 @z
560 %---------------------------------------
561 @x [18.265] l.5735 - e-TeX sparse arrays
562 primitive("toks",toks_register,0);@/
563 @y
564 primitive("toks",toks_register,mem_bot);@/
565 @z
566 %---------------------------------------
567 @x [18.266] l.5768 - e-TeX cond
568 expand_after: print_esc("expandafter");
569 @y
570 expand_after: if chr_code=0 then print_esc("expandafter")
571 @<Cases of |expandafter| for |print_cmd_chr|@>;
572 @z
573 %---------------------------------------
574 @x [18.266] l.5774 - e-TeX marks
575 mark: print_esc("mark");
576 @y
577 mark: begin print_esc("mark");
578 if chr_code>0 then print_char("s");
579 end;
580 @z
581 %---------------------------------------
582 @x [18.266] l.5785 - e-TeX read_line
583 read_to_cs: print_esc("read");
584 @y
585 read_to_cs: if chr_code=0 then print_esc("read")
586 @<Cases of |read| for |print_cmd_chr|@>;
587 @z
588 %---------------------------------------
589 @x [18.266] l.5789 - e-TeX penalties
590 set_shape: print_esc("parshape");
591 @y
592 set_shape: case chr_code of
593 par_shape_loc: print_esc("parshape");
594 @<Cases of |set_shape| for |print_cmd_chr|@>@;@/
595 end; {there are no other cases}
596 @z
597 %---------------------------------------
598 @x [18.266] l.5790 - e-TeX unexpanded
599 the: print_esc("the");
600 @y
601 the: if chr_code=0 then print_esc("the")
602 @<Cases of |the| for |print_cmd_chr|@>;
603 @z
604 %---------------------------------------
605 @x [18.266] l.5791 - e-TeX sparse arrays
606 toks_register: print_esc("toks");
607 @y
608 toks_register: @<Cases of |toks_register| for |print_cmd_chr|@>;
609 @z
610 %---------------------------------------
611 @x [18.266] l.5793 - e-TeX TeXXeT
612 valign: print_esc("valign");
613 @y
614 valign: if chr_code=0 then print_esc("valign")@/
615 @<Cases of |valign| for |print_cmd_chr|@>;
616 @z
617 %---------------------------------------
618 @x [19.268] l.5827 - e-TeX sparse arrays
619 interpreted in one of four ways:
620 @y
621 interpreted in one of five ways:
622 @z
623 %---------------------------------------
624 @x [19.268] l.5847 - e-TeX tracing
625 the entries for that group.
626 @y
627 the entries for that group.
628 Furthermore, in extended \eTeX\ mode, |save_stack[p-1]| contains the
629 source line number at which the current level of grouping was entered.
630
631 \yskip\hang 5) If |save_type(p)=restore_sa|, then |sa_chain| points to a
632 chain of sparse array entries to be restored at the end of the current
633 group. Furthermore |save_index(p)| and |save_level(p)| should replace
634 the values of |sa_chain| and |sa_level| respectively.
635 @z
636 %---------------------------------------
637 @x [19.268] l.5857 - e-TeX basic
638 @d level_boundary=3 {|save_type| corresponding to beginning of group}
639 @y
640 @d level_boundary=3 {|save_type| corresponding to beginning of group}
641 @d restore_sa=4 {|save_type| when sparse array entries should be restored}
642
643 @p@t\4@>@<Declare \eTeX\ procedures for tracing and input@>
644 @z
645 %---------------------------------------
646 @x [19.273] l.5915 - e-TeX tracing
647 @ The following macro is used to test if there is room for up to six more
648 @y
649 @ The following macro is used to test if there is room for up to seven more
650 @z
651 %---------------------------------------
652 @x [19.273] l.5921 - check_full_save_stack - e-TeX tracing
653 if max_save_stack>save_size-6 then overflow("save size",save_size);
654 @y
655 if max_save_stack>save_size-7 then overflow("save size",save_size);
656 @z
657 %---------------------------------------
658 @x [19.274] l.5943 - new_save_level - e-TeX tracing
659 begin check_full_save_stack;
660 @y
661 begin check_full_save_stack;
662 if eTeX_ex then
663 begin saved(0):=line; incr(save_ptr);
664 end;
665 @z
666 %---------------------------------------
667 @x [19.274] l.5950 - new_save_level - e-TeX tracing
668 cur_boundary:=save_ptr; incr(cur_level); incr(save_ptr); cur_group:=c;
669 @y
670 cur_boundary:=save_ptr; cur_group:=c;
671 @!stat if tracing_groups>0 then group_trace(false);@+tats@;@/
672 incr(cur_level); incr(save_ptr);
673 @z
674 %---------------------------------------
675 @x [19.275] l.5968 - eq_destroy - e-TeX sparse arrays
676 othercases do_nothing
677 @y
678 @/@<Cases for |eq_destroy|@>@/
679 othercases do_nothing
680 @z
681 %---------------------------------------
682 @x [19.277] l.5990 - e-TeX tracing
683 the call, since |eq_save| makes the necessary test.
684 @y
685 the call, since |eq_save| makes the necessary test.
686
687 @d assign_trace(#)==@!stat if tracing_assigns>0 then restore_trace(#);
688 tats
689 @z
690 %---------------------------------------
691 @x [19.277] l.5994 - eq_define - e-TeX tracing
692 begin if eq_level(p)=cur_level then eq_destroy(eqtb[p])
693 @y
694 label exit;
695 begin if eTeX_ex and(eq_type(p)=t)and(equiv(p)=e) then
696 begin assign_trace(p,"reassigning")@;@/
697 eq_destroy(eqtb[p]); return;
698 end;
699 assign_trace(p,"changing")@;@/
700 if eq_level(p)=cur_level then eq_destroy(eqtb[p])
701 @z
702 %---------------------------------------
703 @x [19.277] l.5997 - eq_define - e-TeX tracing
704 end;
705 @y
706 assign_trace(p,"into")@;@/
707 exit:end;
708 @z
709 %---------------------------------------
710 @x [19.278] l.6004 - eq_word_define - e-TeX tracing
711 begin if xeq_level[p]<>cur_level then
712 @y
713 label exit;
714 begin if eTeX_ex and(eqtb[p].int=w) then
715 begin assign_trace(p,"reassigning")@;@/
716 return;
717 end;
718 assign_trace(p,"changing")@;@/
719 if xeq_level[p]<>cur_level then
720 @z
721 %---------------------------------------
722 @x [19.278] l.6008 - eq_word_define - e-TeX tracing
723 end;
724 @y
725 assign_trace(p,"into")@;@/
726 exit:end;
727 @z
728 %---------------------------------------
729 @x [19.279] l.6017 - geq_define - e-TeX tracing
730 begin eq_destroy(eqtb[p]);
731 eq_level(p):=level_one; eq_type(p):=t; equiv(p):=e;
732 @y
733 begin assign_trace(p,"globally changing")@;@/
734 begin eq_destroy(eqtb[p]);
735 eq_level(p):=level_one; eq_type(p):=t; equiv(p):=e;
736 end;
737 assign_trace(p,"into")@;@/
738 @z
739 %---------------------------------------
740 @x [19.279] l.6022 - geq_word_define - e-TeX tracing
741 begin eqtb[p].int:=w; xeq_level[p]:=level_one;
742 @y
743 begin assign_trace(p,"globally changing")@;@/
744 begin eqtb[p].int:=w; xeq_level[p]:=level_one;
745 end;
746 assign_trace(p,"into")@;@/
747 @z
748 %---------------------------------------
749 @x [19.281] l.6039 - e-TeX tracing
750 @p@t\4@>@<Declare the procedure called |restore_trace|@>@;@/
751 @y
752 @p
753 @z
754 %---------------------------------------
755 @x [19.281] l.6046 - unsave - e-TeX optimized \aftergroup
756 begin if cur_level>level_one then
757 @y
758 @!a:boolean; {have we already processed an \.{\\aftergroup} ?}
759 begin a:=false;
760 if cur_level>level_one then
761 @z
762 %---------------------------------------
763 @x [19.282] l.6060 - e-TeX sparse arrays
764 else begin if save_type(save_ptr)=restore_old_value then
765 @y
766 else if save_type(save_ptr)=restore_sa then
767 begin sa_restore; sa_chain:=p; sa_level:=save_level(save_ptr);
768 end
769 else begin if save_type(save_ptr)=restore_old_value then
770 @z
771 %---------------------------------------
772 @x [19.282] l.6068 - e-TeX tracing
773 done: cur_group:=save_level(save_ptr); cur_boundary:=save_index(save_ptr)
774 @y
775 done: @!stat if tracing_groups>0 then group_trace(true);@+tats@;@/
776 if grp_stack[in_open]=cur_boundary then group_warning;
777 {groups possibly not properly nested with files}
778 cur_group:=save_level(save_ptr); cur_boundary:=save_index(save_ptr);
779 if eTeX_ex then decr(save_ptr)
780 @z
781 %---------------------------------------
782 @x [19.284] l.6094 - e-TeX tracing
783 @ @<Declare the procedure called |restore_trace|@>=
784 @y
785 @ @<Declare \eTeX\ procedures for tr...@>=
786 @z
787 %---------------------------------------
788 @x [20.289] l.6182 - e-TeX protected
789 @d end_match_token=@'7000 {$2^8\cdot|end_match|$}
790 @y
791 @d end_match_token=@'7000 {$2^8\cdot|end_match|$}
792 @d protected_token=@'7001 {$2^8\cdot|end_match|+1$}
793 @z
794 %---------------------------------------
795 @x [20.294] l.6307 - e-TeX protected
796 end_match: print("->");
797 @y
798 end_match: if c=0 then print("->");
799 @z
800 %---------------------------------------
801 @x [20.296] l.6328 - print_meaning - e-TeX marks
802 else if cur_cmd=top_bot_mark then
803 @y
804 else if (cur_cmd=top_bot_mark)and(cur_chr<marks_code) then
805 @z
806 %---------------------------------------
807 @x [21.298] l.6402 - print_cmd_chr - e-TeX protected
808 procedure print_cmd_chr(@!cmd:quarterword;@!chr_code:halfword);
809 @y
810 procedure print_cmd_chr(@!cmd:quarterword;@!chr_code:halfword);
811 var n:integer; {temp variable}
812 @z
813 %---------------------------------------
814 @x [21.299] l.6421 - show_cur_cmd_chr - e-TeX tracing
815 @p procedure show_cur_cmd_chr;
816 @y
817 @p procedure show_cur_cmd_chr;
818 var n:integer; {level of \.{\\if...\\fi} nesting}
819 @!l:integer; {line where \.{\\if} started}
820 @!p:pointer;
821 @z
822 %---------------------------------------
823 @x [21.299] l.6426 - show_cur_cmd_chr - e-TeX tracing
824 print_cmd_chr(cur_cmd,cur_chr); print_char("}");
825 @y
826 print_cmd_chr(cur_cmd,cur_chr);
827 if tracing_ifs>0 then
828 if cur_cmd>=if_test then if cur_cmd<=fi_or_else then
829 begin print(": ");
830 if cur_cmd=fi_or_else then
831 begin print_cmd_chr(if_test,cur_if); print_char(" ");
832 n:=0; l:=if_line;
833 end
834 else begin n:=1; l:=line;
835 end;
836 p:=cond_ptr;
837 while p<>null do
838 begin incr(n); p:=link(p);
839 end;
840 print("(level "); print_int(n); print_char(")"); print_if_line(l);
841 end;
842 print_char("}");
843 @z
844 %---------------------------------------
845 @x [22.303] l.6502 - show_context - e-TeX scan_tokens
846 the terminal, under control of the procedure |read_toks|.)
847 @y
848 the terminal, under control of the procedure |read_toks|.)
849 Finally |18<=name<=19| indicates that we are reading a pseudo file
850 created by the \.{\\scantokens} command.
851 @z
852 %---------------------------------------
853 @x [22.307] l.6699 - e-TeX basic, every_eof
854 only if |token_type>=macro|.
855 @^reference counts@>
856 @y
857 only if |token_type>=macro|.
858 @^reference counts@>
859
860 Since \eTeX's additional token list parameters precede |toks_base|, the
861 corresponding token types must precede |write_text|.
862 @z
863 %---------------------------------------
864 @x [22.307] l.6720 - e-TeX basic
865 @d write_text=15 {|token_type| code for \.{\\write}}
866 @y
867 @#
868 @d eTeX_text_offset=output_routine_loc-output_text
869 @d every_eof_text=every_eof_loc-eTeX_text_offset
870 {|token_type| code for \.{\\everyeof}}
871 @#
872 @d write_text=toks_base-eTeX_text_offset {|token_type| code for \.{\\write}}
873 @z
874 %---------------------------------------
875 @x [22.311] l.6776 - show_context - e-TeX scan_tokens
876 if (name>17) or (base_ptr=0) then bottom_line:=true;
877 @y
878 if (name>19) or (base_ptr=0) then bottom_line:=true;
879 @z
880 %---------------------------------------
881 @x [22.313] l.6821 - e-TeX scan_tokens
882 else begin print_nl("l."); print_int(line);
883 @y
884 else begin print_nl("l.");
885 if index=in_open then print_int(line)
886 else print_int(line_stack[index+1]); {input from a pseudo file}
887 @z
888 %---------------------------------------
889 @x [22.314] l.6843 - e-TeX basic
890 write_text: print_nl("<write> ");
891 @y
892 every_eof_text: print_nl("<everyeof> ");
893 write_text: print_nl("<write> ");
894 @z
895 %---------------------------------------
896 @x [23.326] l.7036 - e-TeX optimized \aftergroup
897 begin t:=cur_tok; cur_tok:=p; back_input; cur_tok:=t;
898 @y
899 begin t:=cur_tok; cur_tok:=p;
900 if a then
901 begin p:=get_avail; info(p):=cur_tok; link(p):=loc; loc:=p; start:=p;
902 if cur_tok<right_brace_limit then
903 if cur_tok<left_brace_limit then decr(align_state)
904 else incr(align_state);
905 end
906 else begin back_input; a:=eTeX_ex;
907 end;
908 cur_tok:=t;
909 @z
910 %---------------------------------------
911 @x [23.328] l.7064 - begin_file_reading - e-TeX every_eof, tracing_nesting
912 incr(in_open); push_input; index:=in_open;
913 @y
914 incr(in_open); push_input; index:=in_open;
915 eof_seen[index]:=false;
916 grp_stack[index]:=cur_boundary; if_stack[index]:=cond_ptr;
917 @z
918 %---------------------------------------
919 @x [23.329] l.7074 - end_file_reading - e-TeX scan_tokens
920 if name>17 then a_close(cur_file); {forget it}
921 @y
922 if (name=18)or(name=19) then pseudo_close else
923 if name>17 then a_close(cur_file); {forget it}
924 @z
925 %---------------------------------------
926 @x [23.331] l.7093 - e-TeX tracing_nesting
927 in_open:=0; open_parens:=0; max_buf_stack:=0;
928 @y
929 in_open:=0; open_parens:=0; max_buf_stack:=0;
930 grp_stack[0]:=0; if_stack[0]:=null;
931 @z
932 %---------------------------------------
933 @x [24.362] l.7566 - e-TeX scan_tokens, every_eof
934 if not force_eof then
935 @y
936 if not force_eof then
937 if name<=19 then
938 begin if pseudo_input then {not end of file}
939 firm_up_the_line {this sets |limit|}
940 else if (every_eof<>null)and not eof_seen[index] then
941 begin limit:=first-1; eof_seen[index]:=true; {fake one empty line}
942 begin_token_list(every_eof,every_eof_text); goto restart;
943 end
944 else force_eof:=true;
945 end
946 else
947 @z
948 %---------------------------------------
949 @x [24.362] l.7569 - e-TeX every_eof
950 else force_eof:=true;
951 @y
952 else if (every_eof<>null)and not eof_seen[index] then
953 begin limit:=first-1; eof_seen[index]:=true; {fake one empty line}
954 begin_token_list(every_eof,every_eof_text); goto restart;
955 end
956 else force_eof:=true;
957 @z
958 %---------------------------------------
959 @x [24.362] l.7572 - e-TeX scan_tokens
960 begin print_char(")"); decr(open_parens);
961 update_terminal; {show user that file has been read}
962 @y
963 begin if tracing_nesting>0 then
964 if (grp_stack[in_open]<>cur_boundary)or@|
965 (if_stack[in_open]<>cond_ptr) then file_warning;
966 {give warning for some unfinished groups and/or conditionals}
967 if name>=19 then
968 begin print_char(")"); decr(open_parens);
969 update_terminal; {show user that file has been read}
970 end;
971 @z
972 %---------------------------------------
973 @x [25.366] l.7656 - e-TeX basic
974 @t\4@>@<Declare the procedure called |insert_relax|@>@;@/
975 @y
976 @t\4@>@<Declare the procedure called |insert_relax|@>@;@/
977 @t\4@>@<Declare \eTeX\ procedures for expanding@>@;@/
978 @z
979 %---------------------------------------
980 @x [25.366] l.7663 - expand - e-TeX cond
981 procedure expand;
982 @y
983 procedure expand;
984 label reswitch;
985 @z
986 %---------------------------------------
987 @x [25.366] l.7674 - expand - e-TeX cond
988 if cur_cmd<call then @<Expand a nonmacro@>
989 @y
990 reswitch:
991 if cur_cmd<call then @<Expand a nonmacro@>
992 @z
993 %---------------------------------------
994 @x [25.367] l.7685 - e-TeX cond
995 expand_after:@<Expand the token after the next token@>;
996 @y
997 expand_after:if cur_chr=0 then @<Expand the token after the next token@>
998 else @<Negate a boolean conditional and |goto reswitch|@>;
999 @z
1000 %---------------------------------------
1001 @x [25.377] l.7805 - e-TeX scan_tokens
1002 input: if chr_code=0 then print_esc("input")@+else print_esc("endinput");
1003 @y
1004 input: if chr_code=0 then print_esc("input")
1005 @/@<Cases of |input| for |print_cmd_chr|@>@/
1006 else print_esc("endinput");
1007 @z
1008 %---------------------------------------
1009 @x [25.378] l.7808 - e-TeX scan_tokens
1010 if cur_chr>0 then force_eof:=true
1011 @y
1012 if cur_chr=1 then force_eof:=true
1013 @/@<Cases for |input|@>@/
1014 @z
1015 %---------------------------------------
1016 @x [25.382] l.7864 - e-TeX marks
1017 @d top_mark_code=0 {the mark in effect at the previous page break}
1018 @y
1019 @d marks_code==5 {add this for \.{\\topmarks} etc.}
1020 @#
1021 @d top_mark_code=0 {the mark in effect at the previous page break}
1022 @z
1023 %---------------------------------------
1024 @x [25.385] l.7896 - e-TeX marks
1025 top_bot_mark: case chr_code of
1026 @y
1027 top_bot_mark: begin case (chr_code mod marks_code) of
1028 @z
1029 %---------------------------------------
1030 @x [25.385] l.7902 - e-TeX marks
1031 endcases;
1032 @y
1033 endcases;
1034 if chr_code>=marks_code then print_char("s");
1035 end;
1036 @z
1037 %---------------------------------------
1038 @x [25.386] l.7908 - e-TeX marks
1039 begin if cur_mark[cur_chr]<>null then
1040 begin_token_list(cur_mark[cur_chr],mark_text);
1041 @y
1042 begin t:=cur_chr mod marks_code;
1043 if cur_chr>=marks_code then scan_register_num@+else cur_val:=0;
1044 if cur_val=0 then cur_ptr:=cur_mark[t]
1045 else @<Compute the mark pointer for mark type |t| and class |cur_val|@>;
1046 if cur_ptr<>null then begin_token_list(cur_ptr,mark_text);
1047 @z
1048 %---------------------------------------
1049 @x [25.389] l.7971 - macro_call - e-TeX protected
1050 if info(r)<>end_match_token then
1051 @y
1052 if info(r)=protected_token then r:=link(r);
1053 if info(r)<>end_match_token then
1054 @z
1055 %---------------------------------------
1056 @x [26.409] l.8283 - e-TeX basic
1057 @t\4\4@>@<Declare procedures that scan font-related stuff@>
1058 @y
1059 @t\4\4@>@<Declare \eTeX\ procedures for scanning@>@;
1060 @t\4\4@>@<Declare procedures that scan font-related stuff@>
1061 @z
1062 %---------------------------------------
1063 @x [26.411] l.8327 - e-TeX sparse arrays
1064 |glue_val|, or |mu_val|.
1065 @y
1066 |glue_val|, or |mu_val| more than |mem_bot| (dynamic variable-size nodes
1067 cannot have these values)
1068 @z
1069 %---------------------------------------
1070 @x [26.411] l.8330 - e-TeX sparse arrays
1071 primitive("count",register,int_val);
1072 @!@:count_}{\.{\\count} primitive@>
1073 primitive("dimen",register,dimen_val);
1074 @!@:dimen_}{\.{\\dimen} primitive@>
1075 primitive("skip",register,glue_val);
1076 @!@:skip_}{\.{\\skip} primitive@>
1077 primitive("muskip",register,mu_val);
1078 @y
1079 primitive("count",register,mem_bot+int_val);
1080 @!@:count_}{\.{\\count} primitive@>
1081 primitive("dimen",register,mem_bot+dimen_val);
1082 @!@:dimen_}{\.{\\dimen} primitive@>
1083 primitive("skip",register,mem_bot+glue_val);
1084 @!@:skip_}{\.{\\skip} primitive@>
1085 primitive("muskip",register,mem_bot+mu_val);
1086 @z
1087 %---------------------------------------
1088 @x [26.412] l.8340 - e-TeX sparse arrays
1089 register: if chr_code=int_val then print_esc("count")
1090 else if chr_code=dimen_val then print_esc("dimen")
1091 else if chr_code=glue_val then print_esc("skip")
1092 else print_esc("muskip");
1093 @y
1094 register: @<Cases of |register| for |print_cmd_chr|@>;
1095 @z
1096 %---------------------------------------
1097 @x [26.413] l.8356 - scan_something_internal - e-TeX basic
1098 var m:halfword; {|chr_code| part of the operand token}
1099 @y
1100 label exit;
1101 var m:halfword; {|chr_code| part of the operand token}
1102 @!q,@!r:pointer; {general purpose indices}
1103 @!tx:pointer; {effective tail node}
1104 @!i:four_quarters; {character info}
1105 @z
1106 %---------------------------------------
1107 @x [26.413] l.8382 - scan_something_internal - e-TeX basic
1108 end;
1109 @y
1110 exit:end;
1111 @z
1112 %---------------------------------------
1113 @x [26.415] l.8403 - e-TeX sparse arrays
1114 begin scan_eight_bit_int; m:=toks_base+cur_val;
1115 end;
1116 scanned_result(equiv(m))(tok_val);
1117 @y
1118 if m=mem_bot then
1119 begin scan_register_num;
1120 if cur_val<256 then cur_val:=equiv(toks_base+cur_val)
1121 else begin find_sa_element(tok_val,cur_val,false);
1122 if cur_ptr=null then cur_val:=null
1123 else cur_val:=sa_ptr(cur_ptr);
1124 end;
1125 end
1126 else cur_val:=sa_ptr(m)
1127 else cur_val:=equiv(m);
1128 cur_val_level:=tok_val;
1129 @z
1130 %---------------------------------------
1131 @x [26.416] l.8418 - e-TeX basic
1132 |glue_val|, |input_line_no_code|, or |badness_code|.
1133 @y
1134 |glue_val|, |input_line_no_code|, or |badness_code|.
1135 \eTeX\ inserts |last_node_type_code| after |glue_val| and adds
1136 the codes for its extensions: |eTeX_version_code|, \dots\ .
1137 @z
1138 %---------------------------------------
1139 @x [26.416] l.8420 - e-TeX basic
1140 @d input_line_no_code=glue_val+1 {code for \.{\\inputlineno}}
1141 @d badness_code=glue_val+2 {code for \.{\\badness}}
1142 @y
1143 @d last_node_type_code=glue_val+1 {code for \.{\\lastnodetype}}
1144 @d input_line_no_code=glue_val+2 {code for \.{\\inputlineno}}
1145 @d badness_code=input_line_no_code+1 {code for \.{\\badness}}
1146 @#
1147 @d eTeX_int=badness_code+1 {first of \eTeX\ codes for integers}
1148 @d eTeX_dim=eTeX_int+8 {first of \eTeX\ codes for dimensions}
1149 @d eTeX_glue=eTeX_dim+9 {first of \eTeX\ codes for glue}
1150 @d eTeX_mu=eTeX_glue+1 {first of \eTeX\ codes for muglue}
1151 @d eTeX_expr=eTeX_mu+1 {first of \eTeX\ codes for expressions}
1152 @z
1153 %---------------------------------------
1154 @x [26.417] l.8453 - e-TeX interaction_mode
1155 @+else print_esc("insertpenalties");
1156 @y
1157 @/@<Cases of |set_page_int| for |print_cmd_chr|@>@/
1158 @+else print_esc("insertpenalties");
1159 @z
1160 %---------------------------------------
1161 @x [26.417] l.8462 - e-TeX basic
1162 othercases print_esc("badness")
1163 @y
1164 @/@<Cases of |last_item| for |print_cmd_chr|@>@/
1165 othercases print_esc("badness")
1166 @z
1167 %---------------------------------------
1168 @x [26.419] l.8482 - e-TeX interaction_mode
1169 begin if m=0 then cur_val:=dead_cycles@+else cur_val:=insert_penalties;
1170 @y
1171 begin if m=0 then cur_val:=dead_cycles
1172 @/@<Cases for `Fetch the |dead_cycles| or the |insert_penalties|'@>@/
1173 else cur_val:=insert_penalties;
1174 @z
1175 %---------------------------------------
1176 @x [26.420] l.8487 - e-TeX sparse arrays
1177 begin scan_eight_bit_int;
1178 if box(cur_val)=null then cur_val:=0 @+else cur_val:=mem[box(cur_val)+m].sc;
1179 @y
1180 begin scan_register_num; fetch_box(q);
1181 if q=null then cur_val:=0 @+else cur_val:=mem[q+m].sc;
1182 @z
1183 %---------------------------------------
1184 @x [26.423] l.8512 - e-TeX penalties
1185 begin if par_shape_ptr=null then cur_val:=0
1186 @y
1187 begin if m>par_shape_loc then @<Fetch a penalties array element@>
1188 else if par_shape_ptr=null then cur_val:=0
1189 @z
1190 %---------------------------------------
1191 @x [26.424] l.8517 - e-TeX \lastnodetype
1192 @ Here is where \.{\\lastpenalty}, \.{\\lastkern}, and \.{\\lastskip} are
1193 @y
1194 @ Here is where \.{\\lastpenalty}, \.{\\lastkern}, \.{\\lastskip}, and
1195 \.{\\lastnodetype} are
1196 @z
1197 %---------------------------------------
1198 @x [26.424] l.8521 - e-TeX TeXXeT
1199 legal in similar contexts.
1200 @y
1201 legal in similar contexts.
1202
1203 The macro |find_effective_tail_eTeX| sets |tx| to the last non-\.{\\endM}
1204 node of the current list.
1205 @z
1206 %---------------------------------------
1207 @x [26.424] l.8523 - e-TeX TeXXeT
1208 @<Fetch an item in the current node...@>=
1209 @y
1210 @d find_effective_tail_eTeX==
1211 tx:=tail;
1212 if not is_char_node(tx) then
1213 if (type(tx)=math_node)and(subtype(tx)=end_M_code) then
1214 begin r:=head;
1215 repeat q:=r; r:=link(q);
1216 until r=tx;
1217 tx:=q;
1218 end
1219 @#
1220 @d find_effective_tail==find_effective_tail_eTeX
1221
1222 @<Fetch an item in the current node...@>=
1223 @z
1224 %---------------------------------------
1225 @x [26.424] l.8524 - e-TeX basic
1226 if cur_chr>glue_val then
1227 @y
1228 if m>=input_line_no_code then
1229 @z
1230 %---------------------------------------
1231 @x [26.424] l.8525 - e-TeX basic
1232 begin if cur_chr=input_line_no_code then cur_val:=line
1233 else cur_val:=last_badness; {|cur_chr=badness_code|}
1234 @y
1235 if m>=eTeX_glue then @<Process an expression and |return|@>@;
1236 else if m>=eTeX_dim then
1237 begin case m of
1238 @/@<Cases for fetching a dimension value@>@/
1239 end; {there are no other cases}
1240 cur_val_level:=dimen_val;
1241 end
1242 else begin case m of
1243 input_line_no_code: cur_val:=line;
1244 badness_code: cur_val:=last_badness;
1245 @/@<Cases for fetching an integer value@>@/
1246 end; {there are no other cases}
1247 @z
1248 %---------------------------------------
1249 @x [26.424] l.8530 - e-TeX last_node_type
1250 cur_val_level:=cur_chr;
1251 if not is_char_node(tail)and(mode<>0) then
1252 case cur_chr of
1253 int_val: if type(tail)=penalty_node then cur_val:=penalty(tail);
1254 dimen_val: if type(tail)=kern_node then cur_val:=width(tail);
1255 glue_val: if type(tail)=glue_node then
1256 begin cur_val:=glue_ptr(tail);
1257 if subtype(tail)=mu_glue then cur_val_level:=mu_val;
1258 end;
1259 end {there are no other cases}
1260 else if (mode=vmode)and(tail=head) then
1261 @y
1262 find_effective_tail;
1263 if cur_chr=last_node_type_code then
1264 begin cur_val_level:=int_val;
1265 if (tx=head)or(mode=0) then cur_val:=-1;
1266 end
1267 else cur_val_level:=cur_chr;
1268 if not is_char_node(tx)and(mode<>0) then
1269 case cur_chr of
1270 int_val: if type(tx)=penalty_node then cur_val:=penalty(tx);
1271 dimen_val: if type(tx)=kern_node then cur_val:=width(tx);
1272 glue_val: if type(tx)=glue_node then
1273 begin cur_val:=glue_ptr(tx);
1274 if subtype(tx)=mu_glue then cur_val_level:=mu_val;
1275 end;
1276 last_node_type_code: if type(tx)<=unset_node then cur_val:=type(tx)+1
1277 else cur_val:=unset_node+2;
1278 end {there are no other cases}
1279 else if (mode=vmode)and(tx=head) then
1280 @z
1281 %---------------------------------------
1282 @x [26.424] l.8544 - e-TeX last_node_type
1283 glue_val: if last_glue<>max_halfword then cur_val:=last_glue;
1284 @y
1285 glue_val: if last_glue<>max_halfword then cur_val:=last_glue;
1286 last_node_type_code: cur_val:=last_node_type;
1287 @z
1288 %---------------------------------------
1289 @x [26.427] l.8560 - e-TeX sparse arrays
1290 begin scan_eight_bit_int;
1291 case m of
1292 @y
1293 begin if (m<mem_bot)or(m>lo_mem_stat_max) then
1294 begin cur_val_level:=sa_type(m);
1295 if cur_val_level<glue_val then cur_val:=sa_int(m)
1296 else cur_val:=sa_ptr(m);
1297 end
1298 else begin scan_register_num; cur_val_level:=m-mem_bot;
1299 if cur_val>255 then
1300 begin find_sa_element(cur_val_level,cur_val,false);
1301 if cur_ptr=null then
1302 if cur_val_level<glue_val then cur_val:=0
1303 else cur_val:=zero_glue
1304 else if cur_val_level<glue_val then cur_val:=sa_int(cur_ptr)
1305 else cur_val:=sa_ptr(cur_ptr);
1306 end
1307 else
1308 case cur_val_level of
1309 @z
1310 %---------------------------------------
1311 @x [26.427] l.8567 - e-TeX sparse arrays
1312 cur_val_level:=m;
1313 @y
1314 end;
1315 @z
1316 %---------------------------------------
1317 @x [26.461] l.9095 - e-TeX expr
1318 exit:end;
1319 @y
1320 exit:end;
1321 @#
1322 @<Declare procedures needed for expressions@>@;
1323 @z
1324 %---------------------------------------
1325 @x [27.464] l.9154 - e-TeX basic
1326 @p function str_toks(@!b:pool_pointer):pointer;
1327 @y
1328 @p @t\4@>@<Declare \eTeX\ procedures for token lists@>@;@/
1329 function str_toks(@!b:pool_pointer):pointer;
1330 @z
1331 %---------------------------------------
1332 @x [27.465] l.9179 - the_toks - e-TeX unexpanded
1333 @p function the_toks:pointer;
1334 @y
1335 @p function the_toks:pointer;
1336 label exit;
1337 @z
1338 %---------------------------------------
1339 @x [27.465] l.9183 - the_toks - e-TeX unexpanded
1340 begin get_x_token; scan_something_internal(tok_val,false);
1341 @y
1342 @!c:small_number; {value of |cur_chr|}
1343 begin @<Handle \.{\\unexpanded} or \.{\\detokenize} and |return|@>;@/
1344 get_x_token; scan_something_internal(tok_val,false);
1345 @z
1346 %---------------------------------------
1347 @x [27.465] l.9197 - the_toks - e-TeX unexpanded
1348 end;
1349 @y
1350 exit:end;
1351 @z
1352 %---------------------------------------
1353 @x [27.468] l.9220 - e-TeX basic
1354 @d number_code=0 {command code for \.{\\number}}
1355 @y
1356 \eTeX\ adds \.{\\eTeXrevision} such that |job_name_code| remains last.
1357
1358 @d number_code=0 {command code for \.{\\number}}
1359 @z
1360 %---------------------------------------
1361 @x [27.468] l.9225 - e-TeX basic
1362 @d job_name_code=5 {command code for \.{\\jobname}}
1363 @y
1364 @d etex_convert_base=5 {base for \eTeX's command codes}
1365 @d eTeX_revision_code=etex_convert_base {command code for \.{\\eTeXrevision}}
1366 @d etex_convert_codes=etex_convert_base+1 {end of \eTeX's command codes}
1367 @d job_name_code=etex_convert_codes {command code for \.{\\jobname}}
1368 @z
1369 %---------------------------------------
1370 @x [27.469] l.9248 - e-TeX basic
1371 othercases print_esc("jobname")
1372 @y
1373 eTeX_revision_code: print_esc("eTeXrevision");
1374 othercases print_esc("jobname")
1375 @z
1376 %---------------------------------------
1377 @x [27.471] l.9273 - e-TeX basic
1378 job_name_code: if job_name=0 then open_log_file;
1379 @y
1380 eTeX_revision_code: do_nothing;
1381 job_name_code: if job_name=0 then open_log_file;
1382 @z
1383 %---------------------------------------
1384 @x [27.472] l.9289 - e-TeX basic
1385 job_name_code: print(job_name);
1386 @y
1387 eTeX_revision_code: print(eTeX_revision);
1388 job_name_code: print(job_name);
1389 @z
1390 %---------------------------------------
1391 @x [27.478] l.9400 - e-TeX protected
1392 if cur_cmd<=max_command then goto done2;
1393 @y
1394 if cur_cmd>=call then
1395 if info(link(cur_chr))=protected_token then
1396 begin cur_cmd:=relax; cur_chr:=no_expand_flag;
1397 end;
1398 if cur_cmd<=max_command then goto done2;
1399 @z
1400 %---------------------------------------
1401 @x [27.482] l.9448 - read_toks - e-TeX read_line
1402 @p procedure read_toks(@!n:integer;@!r:pointer);
1403 @y
1404 @p procedure read_toks(@!n:integer;@!r:pointer;@!j:halfword);
1405 @z
1406 %---------------------------------------
1407 @x [27.483] l.9474 - e-TeX read_line
1408 loop@+ begin get_token;
1409 @y
1410 @<Handle \.{\\readline} and |goto done|@>;@/
1411 loop@+ begin get_token;
1412 @z
1413 %---------------------------------------
1414 @x [28.487] l.9526 - e-TeX cond
1415 @d if_char_code=0 { `\.{\\if}' }
1416 @y
1417 @d unless_code=32 {amount added for `\.{\\unless}' prefix}
1418 @#
1419 @d if_char_code=0 { `\.{\\if}' }
1420 @z
1421 %---------------------------------------
1422 @x [28.488] l.9581 - e-TeX cond
1423 if_test: case chr_code of
1424 @y
1425 if_test: begin if chr_code>=unless_code then print_esc("unless");
1426 case chr_code mod unless_code of
1427 @z
1428 %---------------------------------------
1429 @x [28.488] l.9598 - e-TeX cond
1430 othercases print_esc("if")
1431 endcases;
1432 @y
1433 @/@<Cases of |if_test| for |print_cmd_chr|@>@/
1434 othercases print_esc("if")
1435 endcases;
1436 end;
1437 @z
1438 %---------------------------------------
1439 @x [28.494] l.9672 - pass_text - e-TeX tracing
1440 done: scanner_status:=save_scanner_status;
1441 @y
1442 done: scanner_status:=save_scanner_status;
1443 if tracing_ifs>0 then show_cur_cmd_chr;
1444 @z
1445 %---------------------------------------
1446 @x [28.496] l.9688 - e-TeX tracing_nesting
1447 begin p:=cond_ptr; if_line:=if_line_field(p);
1448 @y
1449 begin if if_stack[in_open]=cond_ptr then if_warning;
1450 {conditionals possibly not properly nested with files}
1451 p:=cond_ptr; if_line:=if_line_field(p);
1452 @z
1453 %---------------------------------------
1454 @x [28.498] l.9725 - conditional - e-TeX cond
1455 begin @<Push the condition stack@>;@+save_cond_ptr:=cond_ptr;this_if:=cur_chr;@/
1456 @<Either process \.{\\ifcase} or set |b| to the value of a boolean condition@>;
1457 @y
1458 @!is_unless:boolean; {was this if preceded by `\.{\\unless}' ?}
1459 begin if tracing_ifs>0 then if tracing_commands<=1 then show_cur_cmd_chr;
1460 @<Push the condition stack@>;@+save_cond_ptr:=cond_ptr;
1461 is_unless:=(cur_chr>=unless_code); this_if:=cur_chr mod unless_code;@/
1462 @<Either process \.{\\ifcase} or set |b| to the value of a boolean condition@>;
1463 if is_unless then b:=not b;
1464 @z
1465 %---------------------------------------
1466 @x [28.501] l.9768 - e-TeX cond
1467 if_false_code: b:=false;
1468 @y
1469 if_false_code: b:=false;
1470 @/@<Cases for |conditional|@>@/
1471 @z
1472 %---------------------------------------
1473 @x [28.505] l.9807 - e-TeX sparse arrays
1474 begin scan_eight_bit_int; p:=box(cur_val);
1475 @y
1476 begin scan_register_num; fetch_box(p);
1477 @z
1478 %---------------------------------------
1479 @x [28.510] l.9897 - e-TeX cond
1480 if cur_chr>if_limit then
1481 @y
1482 begin if tracing_ifs>0 then if tracing_commands<=1 then show_cur_cmd_chr;
1483 if cur_chr>if_limit then
1484 @z
1485 %---------------------------------------
1486 @x [28.510] l.9908 - e-TeX cond
1487 end
1488 @y
1489 end;
1490 end
1491 @z
1492 %---------------------------------------
1493 @x [29.536] l.10362 - e-TeX basic
1494 print_two(sys_time div 60); print_char(":"); print_two(sys_time mod 60);
1495 @y
1496 print_two(sys_time div 60); print_char(":"); print_two(sys_time mod 60);
1497 if eTeX_ex then
1498 begin; wlog_cr; wlog('entering extended mode');
1499 end;
1500 @z
1501 %---------------------------------------
1502 @x [30.581] l.11299 - char_warning - e-TeX tracing
1503 begin if tracing_lost_chars>0 then
1504 @y
1505 var old_setting: integer; {saved value of |tracing_online|}
1506 begin if tracing_lost_chars>0 then
1507 begin old_setting:=tracing_online;
1508 if eTeX_ex and(tracing_lost_chars>1) then tracing_online:=1;
1509 @z
1510 %---------------------------------------
1511 @x [30.581] l.11306 - char_warning - e-TeX tracing
1512 end;
1513 @y
1514 tracing_online:=old_setting;
1515 end;
1516 end;
1517 @z
1518 %---------------------------------------
1519 @x [32.616] l.12274 - e-TeX TeXXeT
1520 this is essentially the depth of |push| commands in the \.{DVI} output.
1521 @y
1522 this is essentially the depth of |push| commands in the \.{DVI} output.
1523
1524 For mixed direction text (\TeXXeT) the current text direction is called
1525 |cur_dir|. As the box being shipped out will never be used again and
1526 soon be recycled, we can simply reverse any R-text (i.e., right-to-left)
1527 segments of hlist nodes as well as complete hlist nodes embedded in such
1528 segments. Moreover this can be done iteratively rather than recursively.
1529 There are, however, two complications related to leaders that require
1530 some additional bookkeeping: (1)~One and the same hlist node might be
1531 used more than once (but never inside both L- and R-text); and
1532 (2)~leader boxes inside hlists must be aligned with respect to the left
1533 edge of the original hlist.
1534
1535 A math node is changed into a kern node whenever the text direction
1536 remains the same, it is replaced by an |edge_node| if the text direction
1537 changes; the subtype of an an |hlist_node| inside R-text is changed to
1538 |reversed| once its hlist has been reversed.
1539 @!@^data structure assumptions@>
1540 @z
1541 %---------------------------------------
1542 @x [32.616] l.12276 - e-TeX TeXXeT
1543 @d synch_h==if cur_h<>dvi_h then
1544 @y
1545 @d reversed=1 {subtype for an |hlist_node| whose hlist has been reversed}
1546 @d dlist=2 {subtype for an |hlist_node| from display math mode}
1547 @d box_lr(#) == (qo(subtype(#))) {direction mode of a box}
1548 @d set_box_lr(#) == subtype(#):=set_box_lr_end
1549 @d set_box_lr_end(#) == qi(#)
1550 @#
1551 @d left_to_right=0
1552 @d right_to_left=1
1553 @d reflected==1-cur_dir {the opposite of |cur_dir|}
1554 @#
1555 @d synch_h==if cur_h<>dvi_h then
1556 @z
1557 %---------------------------------------
1558 @x [32.619] l.12344 - hlist_out - e-TeX TeXXeT
1559 @!edge:scaled; {left edge of sub-box, or right edge of leader space}
1560 @y
1561 @!edge:scaled; {right edge of sub-box or leader space}
1562 @!prev_p:pointer; {one step behind |p|}
1563 @z
1564 %---------------------------------------
1565 @x [32.619] l.12354 - hlist_out - e-TeX TeXXeT
1566 save_loc:=dvi_offset+dvi_ptr; base_line:=cur_v; left_edge:=cur_h;
1567 @y
1568 save_loc:=dvi_offset+dvi_ptr; base_line:=cur_v;
1569 prev_p:=this_box+list_offset;
1570 @<Initialize |hlist_out| for mixed direction typesetting@>;
1571 left_edge:=cur_h;
1572 @z
1573 %---------------------------------------
1574 @x [32.619] l.12357 - hlist_out - e-TeX TeXXeT
1575 prune_movements(save_loc);
1576 @y
1577 @<Finish |hlist_out| for mixed direction typesetting@>;
1578 prune_movements(save_loc);
1579 @z
1580 %---------------------------------------
1581 @x [32.620] l.12376 - e-TeX TeXXeT
1582 p:=link(p);
1583 @y
1584 prev_p:=link(prev_p); {N.B.: not |prev_p:=p|, |p| might be |lig_trick|}
1585 p:=link(p);
1586 @z
1587 %---------------------------------------
1588 @x [32.622] l.12401 - e-TeX TeXXeT
1589 kern_node,math_node:cur_h:=cur_h+width(p);
1590 @y
1591 kern_node:cur_h:=cur_h+width(p);
1592 math_node: @<Handle a math node in |hlist_out|@>;
1593 @z
1594 %---------------------------------------
1595 @x [32.622] l.12403 - e-TeX TeXXeT
1596 othercases do_nothing
1597 @y
1598 @/@<Cases of |hlist_out| that arise in mixed direction text only@>@;
1599 othercases do_nothing
1600 @z
1601 %---------------------------------------
1602 @x [32.622] l.12408 - e-TeX TeXXeT
1603 next_p:p:=link(p);
1604 @y
1605 next_p:prev_p:=p; p:=link(p);
1606 @z
1607 %---------------------------------------
1608 @x [32.623] l.12415 - e-TeX TeXXeT
1609 temp_ptr:=p; edge:=cur_h;
1610 @y
1611 temp_ptr:=p; edge:=cur_h+width(p);
1612 if cur_dir=right_to_left then cur_h:=edge;
1613 @z
1614 %---------------------------------------
1615 @x [32.623] l.12418 - e-TeX TeXXeT
1616 cur_h:=edge+width(p); cur_v:=base_line;
1617 @y
1618 cur_h:=edge; cur_v:=base_line;
1619 @z
1620 %---------------------------------------
1621 @x [32.625] l.12436 - e-TeX TeXXeT
1622 glue_temp:=-billion
1623
1624 @<Move right or output leaders@>=
1625 begin g:=glue_ptr(p); rule_wd:=width(g)-cur_g;
1626 @y
1627 glue_temp:=-billion
1628 @#
1629 @d round_glue==g:=glue_ptr(p); rule_wd:=width(g)-cur_g;
1630 @z
1631 %---------------------------------------
1632 @x [32.625] l.12455 - e-TeX TeXXeT
1633 rule_wd:=rule_wd+cur_g;
1634 @y
1635 rule_wd:=rule_wd+cur_g
1636
1637 @<Move right or output leaders@>=
1638 begin round_glue;
1639 if eTeX_ex then @<Handle a glue node for mixed direction typesetting@>;
1640 @z
1641 %---------------------------------------
1642 @x [32.626] l.12471 - e-TeX TeXXeT
1643 edge:=cur_h+rule_wd; lx:=0;
1644 @y
1645 if cur_dir=right_to_left then cur_h:=cur_h-10;
1646 edge:=cur_h+rule_wd; lx:=0;
1647 @z
1648 %---------------------------------------
1649 @x [32.626] l.12477 - e-TeX TeXXeT
1650 cur_h:=edge-10; goto next_p;
1651 @y
1652 if cur_dir=right_to_left then cur_h:=edge
1653 else cur_h:=edge-10;
1654 goto next_p;
1655 @z
1656 %---------------------------------------
1657 @x [32.628] l.12516 - e-TeX TeXXeT
1658 synch_h; save_h:=dvi_h; temp_ptr:=leader_box;
1659 @y
1660 synch_h; save_h:=dvi_h; temp_ptr:=leader_box;
1661 if cur_dir=right_to_left then cur_h:=cur_h+leader_wd;
1662 @z
1663 %---------------------------------------
1664 @x [32.632] l.12590 - e-TeX TeXXeT
1665 cur_h:=left_edge+shift_amount(p); {shift the box right}
1666 @y
1667 if cur_dir=right_to_left then cur_h:=left_edge-shift_amount(p)
1668 else cur_h:=left_edge+shift_amount(p); {shift the box right}
1669 @z
1670 %---------------------------------------
1671 @x [32.633] l.12602 - e-TeX TeXXeT
1672 begin synch_h; synch_v;
1673 dvi_out(put_rule); dvi_four(rule_ht); dvi_four(rule_wd);
1674 @y
1675 begin if cur_dir=right_to_left then cur_h:=cur_h-rule_wd;
1676 synch_h; synch_v;
1677 dvi_out(put_rule); dvi_four(rule_ht); dvi_four(rule_wd);
1678 cur_h:=left_edge;
1679 @z
1680 %---------------------------------------
1681 @x [32.637] l.12668 - e-TeX TeXXeT
1682 begin cur_h:=left_edge+shift_amount(leader_box); synch_h; save_h:=dvi_h;@/
1683 @y
1684 begin if cur_dir=right_to_left then
1685 cur_h:=left_edge-shift_amount(leader_box)
1686 else cur_h:=left_edge+shift_amount(leader_box);
1687 synch_h; save_h:=dvi_h;@/
1688 @z
1689 %---------------------------------------
1690 @x [32.638] l.12705 - ship_out - e-TeX TeXXeT
1691 @<Ship box |p| out@>;
1692 @y
1693 @<Ship box |p| out@>;
1694 if eTeX_ex then @<Check for LR anomalies at the end of |ship_out|@>;
1695 @z
1696 %---------------------------------------
1697 @x [33.649] l.12926 - hpack - e-TeX TeXXeT
1698 h:=0; @<Clear dimensions to zero@>;
1699 @y
1700 h:=0; @<Clear dimensions to zero@>;
1701 if TeXXeT_en then @<Initialize the LR stack@>;
1702 @z
1703 %---------------------------------------
1704 @x [33.649] l.12936 - hpack - e-TeX TeXXeT
1705 exit: hpack:=r;
1706 @y
1707 exit: if TeXXeT_en then @<Check for LR anomalies at the end of |hpack|@>;
1708 hpack:=r;
1709 @z
1710 %---------------------------------------
1711 @x [33.651] l.12960 - e-TeX TeXXeT
1712 kern_node,math_node: x:=x+width(p);
1713 @y
1714 kern_node: x:=x+width(p);
1715 math_node: begin x:=x+width(p);
1716 if TeXXeT_en then @<Adjust \(t)the LR stack for the |hpack| routine@>;
1717 end;
1718 @z
1719 %---------------------------------------
1720 @x [34.687] l.13531 - e-TeX middle
1721 \TeX's \.{\\left} and \.{\\right}. The |nucleus| of such noads is
1722 @y
1723 \TeX's \.{\\left} and \.{\\right} as well as \eTeX's \.{\\middle}.
1724 The |nucleus| of such noads is
1725 @z
1726 %---------------------------------------
1727 @x [34.687] l.13548 - e-TeX middle
1728 @d delimiter==nucleus {|delimiter| field in left and right noads}
1729 @y
1730 @d delimiter==nucleus {|delimiter| field in left and right noads}
1731 @d middle_noad==1 {|subtype| of right noad representing \.{\\middle}}
1732 @z
1733 %---------------------------------------
1734 @x [34.696] l.13721 - e-TeX middle
1735 right_noad: begin print_esc("right"); print_delimiter(delimiter(p));
1736 end;
1737 end;
1738 if subtype(p)<>normal then
1739 if subtype(p)=limits then print_esc("limits")
1740 else print_esc("nolimits");
1741 if type(p)<left_noad then print_subsidiary_data(nucleus(p),".");
1742 @y
1743 right_noad: begin if subtype(p)=normal then print_esc("right")
1744 else print_esc("middle");
1745 print_delimiter(delimiter(p));
1746 end;
1747 end;
1748 if type(p)<left_noad then
1749 begin if subtype(p)<>normal then
1750 if subtype(p)=limits then print_esc("limits")
1751 else print_esc("nolimits");
1752 print_subsidiary_data(nucleus(p),".");
1753 end;
1754 @z
1755 %---------------------------------------
1756 @x [36.727] l.14319 - e-TeX middle
1757 done_with_noad: r:=q; r_type:=type(r);
1758 @y
1759 done_with_noad: r:=q; r_type:=type(r);
1760 if r_type=right_noad then
1761 begin r_type:=left_noad; cur_style:=style; @<Set up the values...@>;
1762 end;
1763 @z
1764 %---------------------------------------
1765 @x [36.760] l.14980 - e-TeX middle
1766 r_type:=t;
1767 @y
1768 if type(q)=right_noad then t:=open_noad;
1769 r_type:=t;
1770 @z
1771 %---------------------------------------
1772 @x [36.762] l.15020 - make_left_right - e-TeX middle
1773 begin if style<script_style then cur_size:=text_size
1774 else cur_size:=16*((style-text_style) div 2);
1775 @y
1776 begin cur_style:=style; @<Set up the values...@>;
1777 @z
1778 %---------------------------------------
1779 @x [37.785] l.15512 - align_peek - e-TeX protected
1780 begin restart: align_state:=1000000; @<Get the next non-blank non-call token@>;
1781 @y
1782 begin restart: align_state:=1000000;
1783 repeat get_x_or_protected;
1784 until cur_cmd<>spacer;
1785 @z
1786 %---------------------------------------
1787 @x [37.791] l.15623 - fin_col - e-TeX protected
1788 align_state:=1000000; @<Get the next non-blank non-call token@>;
1789 @y
1790 align_state:=1000000;
1791 repeat get_x_or_protected;
1792 until cur_cmd<>spacer;
1793 @z
1794 %---------------------------------------
1795 @x [37.807] l.15886 - e-TeX TeXXeT
1796 begin type(q):=hlist_node; width(q):=width(p);
1797 @y
1798 begin type(q):=hlist_node; width(q):=width(p);
1799 if nest[nest_ptr-1].mode_field=mmode then set_box_lr(q)(dlist); {for |ship_out|}
1800 @z
1801 %---------------------------------------
1802 @x [37.808] l.15904 - e-TeX TeXXeT
1803 n:=span_count(r); t:=width(s); w:=t; u:=hold_head;
1804 @y
1805 n:=span_count(r); t:=width(s); w:=t; u:=hold_head;
1806 set_box_lr(r)(0); {for |ship_out|}
1807 @z
1808 %---------------------------------------
1809 @x [38.814] l.16027 - e-TeX penalties
1810 There is one explicit parameter: |final_widow_penalty| is the amount of
1811 additional penalty to be inserted before the final line of the paragraph.
1812 @y
1813 There is one explicit parameter: |d| is true for partial paragraphs
1814 preceding display math mode; in this case the amount of additional
1815 penalty inserted before the final line is |display_widow_penalty|
1816 instead of |widow_penalty|.
1817 @z
1818 %---------------------------------------
1819 @x [38.815] l.16054 - line_break - e-TeX penalties
1820 procedure line_break(@!final_widow_penalty:integer);
1821 @y
1822 procedure line_break(@!d:boolean);
1823 @z
1824 %---------------------------------------
1825 @x [38.815] l.16064 - e-TeX basic
1826 end;
1827 @y
1828 end;
1829 @#
1830 @t\4@>@<Declare \eTeX\ procedures for use by |main_control|@>
1831 @z
1832 %---------------------------------------
1833 @x [38.816] l.16084 - e-TeX last_line_fit
1834 link(tail):=new_param_glue(par_fill_skip_code);
1835 @y
1836 link(tail):=new_param_glue(par_fill_skip_code);
1837 last_line_fill:=link(tail);
1838 @z
1839 %---------------------------------------
1840 @x [38.819] l.16149 - e-TeX last_line_fit
1841 @d active_node_size=3 {number of words in active nodes}
1842 @y
1843 @d active_node_size_normal=3 {number of words in normal active nodes}
1844 @z
1845 %---------------------------------------
1846 @x [38.827] l.16314 - e-TeX last_line_fit
1847 background[6]:=shrink(q)+shrink(r);
1848 @y
1849 background[6]:=shrink(q)+shrink(r);
1850 @<Check for special treatment of last line of paragraph@>;
1851 @z
1852 %---------------------------------------
1853 @x [38.829] l.16365 - try_break - e-TeX last_line_fit
1854 label exit,done,done1,continue,deactivate;
1855 @y
1856 label exit,done,done1,continue,deactivate,found,not_found;
1857 @z
1858 %---------------------------------------
1859 @x [38.845] l.16657 - e-TeX last_line_fit
1860 total_demerits(q):=minimal_demerits[fit_class];
1861 @y
1862 total_demerits(q):=minimal_demerits[fit_class];
1863 if do_last_line_fit then
1864 @<Store \(a)additional data in the new active node@>;
1865 @z
1866 %---------------------------------------
1867 @x [38.846] l.16670 - e-TeX last_line_fit
1868 print(" t="); print_int(total_demerits(q));
1869 @y
1870 print(" t="); print_int(total_demerits(q));
1871 if do_last_line_fit then @<Print additional data in the new active node@>;
1872 @z
1873 %---------------------------------------
1874 @x [38.851] l.16769 - e-TeX last_line_fit
1875 if (b>inf_bad)or(pi=eject_penalty) then
1876 @y
1877 if do_last_line_fit then @<Adjust \(t)the additional data for last line@>;
1878 found:
1879 if (b>inf_bad)or(pi=eject_penalty) then
1880 @z
1881 %---------------------------------------
1882 @x [38.852] l.16793 - e-TeX last_line_fit
1883 begin b:=0; fit_class:=decent_fit; {infinite stretch}
1884 @y
1885 begin if do_last_line_fit then
1886 begin if cur_p=null then {the last line of a paragraph}
1887 @<Perform computations for last line and |goto found|@>;
1888 shortfall:=0;
1889 end;
1890 b:=0; fit_class:=decent_fit; {infinite stretch}
1891 @z
1892 %---------------------------------------
1893 @x [38.855] l.16850 - e-TeX last_line_fit
1894 best_place[fit_class]:=break_node(r); best_pl_line[fit_class]:=l;
1895 @y
1896 best_place[fit_class]:=break_node(r); best_pl_line[fit_class]:=l;
1897 if do_last_line_fit then
1898 @<Store \(a)additional data for this feasible break@>;
1899 @z
1900 %---------------------------------------
1901 @x [39.863] l.17023 - e-TeX last_line_fit
1902 end;@+tats@/
1903 @y
1904 end;@+tats@/
1905 if do_last_line_fit then @<Adjust \(t)the final line of the paragraph@>;
1906 @z
1907 %---------------------------------------
1908 @x [39.864] l.17034 - e-TeX last_line_fit
1909 line_number(q):=prev_graf+1; total_demerits(q):=0; link(active):=q;
1910 @y
1911 line_number(q):=prev_graf+1; total_demerits(q):=0; link(active):=q;
1912 if do_last_line_fit then
1913 @<Initialize additional fields of the first active node@>;
1914 @z
1915 %---------------------------------------
1916 @x [39.866] l.17084 - e-TeX TeXXeT
1917 math_node: begin auto_breaking:=(subtype(cur_p)=after); kern_break;
1918 @y
1919 math_node: begin if subtype(cur_p)<L_code then auto_breaking:=odd(subtype(cur_p));
1920 kern_break;
1921 @z
1922 %---------------------------------------
1923 @x [39.876] l.17246 - e-TeX penalties
1924 post_line_break(final_widow_penalty)
1925 @y
1926 post_line_break(d)
1927 @z
1928 %---------------------------------------
1929 @x [39.877] l.17260 - post_line_break - e-TeX penalties
1930 procedure post_line_break(@!final_widow_penalty:integer);
1931 @y
1932 procedure post_line_break(@!d:boolean);
1933 @z
1934 %---------------------------------------
1935 @x [39.877] l.17270 - post_line_break - e-TeX TeXXeT
1936 begin @<Reverse the links of the relevant passive nodes, setting |cur_p| to the
1937 @y
1938 @!LR_ptr:pointer; {stack of LR codes}
1939 begin LR_ptr:=LR_save;
1940 @<Reverse the links of the relevant passive nodes, setting |cur_p| to the
1941 @z
1942 %---------------------------------------
1943 @x [39.877] l.17283 - post_line_break - e-TeX TeXXeT
1944 prev_graf:=best_line-1;
1945 @y
1946 prev_graf:=best_line-1;
1947 LR_save:=LR_ptr;
1948 @z
1949 %---------------------------------------
1950 @x [39.879] l.17313 - e-TeX TeXXeT
1951 r:=q; {now |type(q)=glue_node|, |kern_node|, |math_node|, or |penalty_node|}
1952 @y
1953 r:=q; {now |type(q)=glue_node|, |kern_node|, |math_node|, or |penalty_node|}
1954 if type(q)=math_node then if TeXXeT_en then
1955 @<Adjust \(t)the LR stack for the |post_line_break| routine@>;
1956 @z
1957 %---------------------------------------
1958 @x [39.880] l.17330 - e-TeX TeXXeT
1959 @<Modify the end of the line to reflect the nature of the break and to include
1960 \.{\\rightskip}; also set the proper value of |disc_break|@>;
1961 @y
1962 if TeXXeT_en then
1963 @<Insert LR nodes at the beginning of the current line and adjust
1964 the LR stack based on LR nodes in this line@>;
1965 @<Modify the end of the line to reflect the nature of the break and to include
1966 \.{\\rightskip}; also set the proper value of |disc_break|@>;
1967 if TeXXeT_en then @<Insert LR nodes at the end of the current line@>;
1968 @z
1969 %---------------------------------------
1970 @x [39.881] l.17353 - e-TeX TeXXeT
1971 else if (type(q)=math_node)or(type(q)=kern_node) then width(q):=0;
1972 @y
1973 else if type(q)=kern_node then width(q):=0
1974 else if type(q)=math_node then
1975 begin width(q):=0;
1976 if TeXXeT_en then @<Adjust \(t)the LR stack for the |p...@>;
1977 end;
1978 @z
1979 %---------------------------------------
1980 @x [39.890] l.17447 - e-TeX penalties
1981 begin pen:=inter_line_penalty;
1982 if cur_line=prev_graf+1 then pen:=pen+club_penalty;
1983 if cur_line+2=best_line then pen:=pen+final_widow_penalty;
1984 @y
1985 begin q:=inter_line_penalties_ptr;
1986 if q<>null then
1987 begin r:=cur_line;
1988 if r>penalty(q) then r:=penalty(q);
1989 pen:=penalty(q+r);
1990 end
1991 else pen:=inter_line_penalty;
1992 q:=club_penalties_ptr;
1993 if q<>null then
1994 begin r:=cur_line-prev_graf;
1995 if r>penalty(q) then r:=penalty(q);
1996 pen:=pen+penalty(q+r);
1997 end
1998 else if cur_line=prev_graf+1 then pen:=pen+club_penalty;
1999 if d then q:=display_widow_penalties_ptr
2000 else q:=widow_penalties_ptr;
2001 if q<>null then
2002 begin r:=best_line-cur_line-1;
2003 if r>penalty(q) then r:=penalty(q);
2004 pen:=pen+penalty(q+r);
2005 end
2006 else if cur_line+2=best_line then
2007 if d then pen:=pen+display_widow_penalty
2008 else pen:=pen+widow_penalty;
2009 @z
2010 %---------------------------------------
2011 @x [40.891] l.17475 - e-TeX TeXXeT
2012 implicit kern nodes, and $p_m$ is a glue or penalty or insertion or adjust
2013 @y
2014 implicit kern or text direction nodes, and $p_m$ is a glue or penalty or
2015 insertion or adjust
2016 @z
2017 %---------------------------------------
2018 @x [40.891] l.17514 - e-TeX hyph_codes
2019 cur_lang:=init_cur_lang; l_hyf:=init_l_hyf; r_hyf:=init_r_hyf;
2020 @y
2021 cur_lang:=init_cur_lang; l_hyf:=init_l_hyf; r_hyf:=init_r_hyf;
2022 set_hyph_index;
2023 @z
2024 %---------------------------------------
2025 @x [40.896] l.17578 - e-TeX TeXXeT
2026 else if (type(s)=kern_node)and(subtype(s)=normal) then goto continue
2027 @y
2028 else if (type(s)=kern_node)and(subtype(s)=normal) then goto continue
2029 else if (type(s)=math_node)and(subtype(s)>=L_code) then goto continue
2030 @z
2031 %---------------------------------------
2032 @x [40.896] l.17584 - e-TeX hyph_codes
2033 if lc_code(c)<>0 then
2034 if (lc_code(c)=c)or(uc_hyph>0) then goto done2
2035 @y
2036 set_lc_code(c);
2037 if hc[0]<>0 then
2038 if (hc[0]=c)or(uc_hyph>0) then goto done2
2039 @z
2040 %---------------------------------------
2041 @x [40.897] l.17601 - e-TeX hyph_codes
2042 if lc_code(c)=0 then goto done3;
2043 if hn=63 then goto done3;
2044 hb:=s; incr(hn); hu[hn]:=c; hc[hn]:=lc_code(c); hyf_bchar:=non_char;
2045 @y
2046 set_lc_code(c);
2047 if hc[0]=0 then goto done3;
2048 if hn=63 then goto done3;
2049 hb:=s; incr(hn); hu[hn]:=c; hc[hn]:=hc[0]; hyf_bchar:=non_char;
2050 @z
2051 %---------------------------------------
2052 @x [40.898] l.17627 - e-TeX hyph_codes
2053 if lc_code(c)=0 then goto done3;
2054 if j=63 then goto done3;
2055 incr(j); hu[j]:=c; hc[j]:=lc_code(c);@/
2056 @y
2057 set_lc_code(c);
2058 if hc[0]=0 then goto done3;
2059 if j=63 then goto done3;
2060 incr(j); hu[j]:=c; hc[j]:=hc[0];@/
2061 @z
2062 %---------------------------------------
2063 @x [40.899] l.17644 - e-TeX TeXXeT
2064 othercases goto done1
2065 @y
2066 math_node: if subtype(s)>=L_code then goto done4@+else goto done1;
2067 othercases goto done1
2068 @z
2069 %---------------------------------------
2070 @x [42.934] l.18266 - new_hyph_exceptions - e-TeX hyph_codes
2071 label reswitch, exit, found, not_found;
2072 @y
2073 label reswitch, exit, found, not_found, not_found1;
2074 @z
2075 %---------------------------------------
2076 @x [42.934] l.18276 - new_hyph_exceptions - e-TeX hyph_codes
2077 set_cur_lang;
2078 @y
2079 set_cur_lang;
2080 @!init if trie_not_ready then
2081 begin hyph_index:=0; goto not_found1;
2082 end;
2083 tini@/
2084 set_hyph_index;
2085 not_found1:
2086 @z
2087 %---------------------------------------
2088 @x [42.937] l.18308 - e-TeX hyph_codes
2089 else begin if lc_code(cur_chr)=0 then
2090 @y
2091 else begin set_lc_code(cur_chr);
2092 if hc[0]=0 then
2093 @z
2094 %---------------------------------------
2095 @x [42.937] l.18316 - e-TeX hyph_codes
2096 begin incr(n); hc[n]:=lc_code(cur_chr);
2097 @y
2098 begin incr(n); hc[n]:=hc[0];
2099 @z
2100 %---------------------------------------
2101 @x [43.952] l.18604 - e-TeX hyph_codes
2102 trie_root:=compress_trie(trie_root); {identify equivalent subtries}
2103 @y
2104 hyph_root:=compress_trie(hyph_root);
2105 trie_root:=compress_trie(trie_root); {identify equivalent subtries}
2106 @z
2107 %---------------------------------------
2108 @x [43.958] l.18692 - e-TeX hyph_codes
2109 if trie_root=0 then {no patterns were given}
2110 @y
2111 if trie_max=0 then {no patterns were given}
2112 @z
2113 %---------------------------------------
2114 @x [43.958] l.18696 - e-TeX hyph_codes
2115 else begin trie_fix(trie_root); {this fixes the non-holes in |trie|}
2116 @y
2117 else begin if hyph_root>0 then trie_fix(hyph_root);
2118 if trie_root>0 then trie_fix(trie_root); {this fixes the non-holes in |trie|}
2119 @z
2120 %---------------------------------------
2121 @x [43.960] l.18739 - new_patterns - e-TeX hyph_codes
2122 brace@>;
2123 @y
2124 brace@>;
2125 if saving_hyph_codes>0 then
2126 @<Store hyphenation codes for current language@>;
2127 @z
2128 %---------------------------------------
2129 @x [43.966] l.18846 - init_trie - e-TeX hyph_codes
2130 @<Move the data into |trie|@>;
2131 @y
2132 if hyph_root<>0 then @<Pack all stored |hyph_codes|@>;
2133 @<Move the data into |trie|@>;
2134 @z
2135 %---------------------------------------
2136 @x [44.968] l.18862 - e-TeX saved_items
2137 whenever this is possible without backspacing.
2138 @y
2139 whenever this is possible without backspacing.
2140
2141 When the second argument |s| is |false| the deleted nodes are destroyed,
2142 otherwise they are collected in a list starting at |split_disc|.
2143 @z
2144 %---------------------------------------
2145 @x [44.968] l.18869 - prune_page_top - e-TeX saved_items
2146 @p function prune_page_top(@!p:pointer):pointer; {adjust top after page break}
2147 var prev_p:pointer; {lags one step behind |p|}
2148 @!q:pointer; {temporary variable for list manipulation}
2149 @y
2150 @p function prune_page_top(@!p:pointer;@!s:boolean):pointer;
2151 {adjust top after page break}
2152 var prev_p:pointer; {lags one step behind |p|}
2153 @!q,@!r:pointer; {temporary variables for list manipulation}
2154 @z
2155 %---------------------------------------
2156 @x [44.968] l.18880 - prune_page_top - e-TeX saved_items
2157 link(prev_p):=p; flush_node_list(q);
2158 @y
2159 link(prev_p):=p;
2160 if s then
2161 begin if split_disc=null then split_disc:=q@+else link(r):=q;
2162 r:=q;
2163 end
2164 else flush_node_list(q);
2165 @z
2166 %---------------------------------------
2167 @x [44.977] l.19047 - vsplit - e-TeX marks, sparse arrays
2168 @p function vsplit(@!n:eight_bits; @!h:scaled):pointer;
2169 @y
2170 @p @t\4@>@<Declare the function called |do_marks|@>@;
2171 function vsplit(@!n:halfword; @!h:scaled):pointer;
2172 @z
2173 %---------------------------------------
2174 @x [44.977] l.19053 - vsplit - e-TeX sparse arrays
2175 begin v:=box(n);
2176 @y
2177 begin cur_val:=n; fetch_box(v);
2178 @z
2179 %---------------------------------------
2180 @x [44.977] l.19054 - vsplit - e-TeX marks, saved_items
2181 if split_first_mark<>null then
2182 @y
2183 flush_node_list(split_disc); split_disc:=null;
2184 if sa_mark<>null then
2185 if do_marks(vsplit_init,0,sa_mark) then sa_mark:=null;
2186 if split_first_mark<>null then
2187 @z
2188 %---------------------------------------
2189 @x [44.977] l.19062 - vsplit - e-TeX saved_items
2190 q:=prune_page_top(q); p:=list_ptr(v); free_node(v,box_node_size);
2191 @y
2192 q:=prune_page_top(q,saving_vdiscards>0);
2193 p:=list_ptr(v); free_node(v,box_node_size);
2194 @z
2195 %---------------------------------------
2196 @x [44.977] l.19063 - vsplit - e-TeX sparse arrays
2197 if q=null then box(n):=null {the |eq_level| of the box stays the same}
2198 else box(n):=vpack(q,natural);
2199 @y
2200 if q<>null then q:=vpack(q,natural);
2201 change_box(q); {the |eq_level| of the box stays the same}
2202 @z
2203 %---------------------------------------
2204 @x [44.979] l.19088 - e-TeX marks
2205 if split_first_mark=null then
2206 @y
2207 if mark_class(p)<>0 then @<Update the current marks for |vsplit|@>
2208 else if split_first_mark=null then
2209 @z
2210 %---------------------------------------
2211 @x [45.982] l.19222 - e-TeX last_node_type
2212 The variables |last_penalty| and |last_kern| are similar. And
2213 @y
2214 The variables |last_penalty|, |last_kern|, and |last_node_type|
2215 are similar. And
2216 @z
2217 %---------------------------------------
2218 @x [45.982] l.19235 - e-TeX last_node_type
2219 @!last_kern:scaled; {used to implement \.{\\lastkern}}
2220 @y
2221 @!last_kern:scaled; {used to implement \.{\\lastkern}}
2222 @!last_node_type:integer; {used to implement \.{\\lastnodetype}}
2223 @z
2224 %---------------------------------------
2225 @x [45.991] l.19375 - e-TeX last_node_type
2226 last_glue:=max_halfword; last_penalty:=0; last_kern:=0;
2227 @y
2228 last_glue:=max_halfword; last_penalty:=0; last_kern:=0;
2229 last_node_type:=-1;
2230 @z
2231 %---------------------------------------
2232 @x [45.996] l.19442 - e-TeX last_node_type
2233 last_penalty:=0; last_kern:=0;
2234 @y
2235 last_penalty:=0; last_kern:=0;
2236 last_node_type:=type(p)+1;
2237 @z
2238 %---------------------------------------
2239 @x [45.999] l.19479 - e-TeX saved_items
2240 link(contrib_head):=link(p); link(p):=null; flush_node_list(p)
2241 @y
2242 link(contrib_head):=link(p); link(p):=null;
2243 if saving_vdiscards>0 then
2244 begin if page_disc=null then page_disc:=p@+else link(tail_page_disc):=p;
2245 tail_page_disc:=p;
2246 end
2247 else flush_node_list(p)
2248 @z
2249 %---------------------------------------
2250 @x [45.1012] l.19719 - fire_up - e-TeX marks
2251 if bot_mark<>null then
2252 @y
2253 if sa_mark<>null then
2254 if do_marks(fire_up_init,0,sa_mark) then sa_mark:=null;
2255 if bot_mark<>null then
2256 @z
2257 %---------------------------------------
2258 @x [45.1012] l.19727 - fire_up - e-TeX marks
2259 if (top_mark<>null)and(first_mark=null) then
2260 @y
2261 if sa_mark<>null then
2262 if do_marks(fire_up_done,0,sa_mark) then sa_mark:=null;
2263 if (top_mark<>null)and(first_mark=null) then
2264 @z
2265 %---------------------------------------
2266 @x [45.1014] l.19764 - e-TeX marks
2267 else if type(p)=mark_node then @<Update the values of
2268 @y
2269 else if type(p)=mark_node then
2270 if mark_class(p)<>0 then @<Update the current marks for |fire_up|@>
2271 else @<Update the values of
2272 @z
2273 %---------------------------------------
2274 @x [45.1021] l.19876 - e-TeX saved_items
2275 ins_ptr(p):=prune_page_top(broken_ptr(r));
2276 @y
2277 ins_ptr(p):=prune_page_top(broken_ptr(r),false);
2278 @z
2279 %---------------------------------------
2280 @x [45.1023] l.19912 - e-TeX saved_items
2281 ship_out(box(255)); box(255):=null;
2282 @y
2283 flush_node_list(page_disc); page_disc:=null;
2284 ship_out(box(255)); box(255):=null;
2285 @z
2286 %---------------------------------------
2287 @x [45.1026] l.19954 - e-TeX saved_items
2288 pop_nest; build_page;
2289 @y
2290 flush_node_list(page_disc); page_disc:=null;
2291 pop_nest; build_page;
2292 @z
2293 %---------------------------------------
2294 @x [47.1070] l.20760 - normal_paragraph - e-TeX penalties
2295 if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
2296 @y
2297 if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
2298 if inter_line_penalties_ptr<>null then
2299 eq_define(inter_line_penalties_loc,shape_ref,null);
2300 @z
2301 %---------------------------------------
2302 @x [47.1071] l.20781 - e-TeX sparse arrays
2303 |box_flag+255| represent `\.{\\setbox0}' through `\.{\\setbox255}';
2304 codes |box_flag+256| through |box_flag+511| represent `\.{\\global\\setbox0}'
2305 through `\.{\\global\\setbox255}';
2306 code |box_flag+512| represents `\.{\\shipout}'; and codes |box_flag+513|
2307 through |box_flag+515| represent `\.{\\leaders}', `\.{\\cleaders}',
2308 @y
2309 |global_box_flag-1| represent `\.{\\setbox0}' through `\.{\\setbox32767}';
2310 codes |global_box_flag| through |ship_out_flag-1| represent
2311 `\.{\\global\\setbox0}' through `\.{\\global\\setbox32767}';
2312 code |ship_out_flag| represents `\.{\\shipout}'; and codes |leader_flag|
2313 through |leader_flag+2| represent `\.{\\leaders}', `\.{\\cleaders}',
2314 @z
2315 %---------------------------------------
2316 @x [47.1071] l.20795 - e-TeX sparse arrays
2317 @d ship_out_flag==box_flag+512 {context code for `\.{\\shipout}'}
2318 @d leader_flag==box_flag+513 {context code for `\.{\\leaders}'}
2319 @y
2320 @d global_box_flag==@'10000100000 {context code for `\.{\\global\\setbox0}'}
2321 @d ship_out_flag==@'10000200000 {context code for `\.{\\shipout}'}
2322 @d leader_flag==@'10000200001 {context code for `\.{\\leaders}'}
2323 @z
2324 %---------------------------------------
2325 @x [47.1075] l.20878 - box_end - e-TeX sparse arrays
2326 var p:pointer; {|ord_noad| for new box in math mode}
2327 @y
2328 var p:pointer; {|ord_noad| for new box in math mode}
2329 @!a:small_number; {global prefix}
2330 @z
2331 %---------------------------------------
2332 @x [47.1077] l.20916 - e-TeX sparse arrays
2333 if box_context<box_flag+256 then
2334 eq_define(box_base-box_flag+box_context,box_ref,cur_box)
2335 else geq_define(box_base-box_flag-256+box_context,box_ref,cur_box)
2336 @y
2337 begin if box_context<global_box_flag then
2338 begin cur_val:=box_context-box_flag; a:=0;
2339 end
2340 else begin cur_val:=box_context-global_box_flag; a:=4;
2341 end;
2342 if cur_val<256 then define(box_base+cur_val,box_ref,cur_box)
2343 else sa_def_box;
2344 end
2345 @z
2346 %---------------------------------------
2347 @x [47.1079] l.20945 - begin_box - e-TeX TeXXeT
2348 @!m:quarterword; {the length of a replacement list}
2349 @y
2350 @!r:pointer; {running behind |p|}
2351 @!fm:boolean; {a final \.{\\beginM} \.{\\endM} node pair?}
2352 @!tx:pointer; {effective tail node}
2353 @!m:quarterword; {the length of a replacement list}
2354 @z
2355 %---------------------------------------
2356 @x [47.1079] l.20947 - begin_box - e-TeX sparse arrays
2357 @!n:eight_bits; {a box number}
2358 begin case cur_chr of
2359 box_code: begin scan_eight_bit_int; cur_box:=box(cur_val);
2360 box(cur_val):=null; {the box becomes void, at the same level}
2361 end;
2362 copy_code: begin scan_eight_bit_int; cur_box:=copy_node_list(box(cur_val));
2363 @y
2364 @!n:halfword; {a box number}
2365 begin case cur_chr of
2366 box_code: begin scan_register_num; fetch_box(cur_box);
2367 change_box(null); {the box becomes void, at the same level}
2368 end;
2369 copy_code: begin scan_register_num; fetch_box(q); cur_box:=copy_node_list(q);
2370 @z
2371 %---------------------------------------
2372 @x [47.1080] l.20965 - e-TeX TeXXeT
2373 @<If the current list ends with a box node, delete it...@>=
2374 @y
2375 @d fetch_effective_tail_eTeX(#)== {extract |tx|,
2376 drop \.{\\beginM} \.{\\endM} pair}
2377 q:=head; p:=null;
2378 repeat r:=p; p:=q; fm:=false;
2379 if not is_char_node(q) then
2380 if type(q)=disc_node then
2381 begin for m:=1 to replace_count(q) do p:=link(p);
2382 if p=tx then #;
2383 end
2384 else if (type(q)=math_node)and(subtype(q)=begin_M_code) then fm:=true;
2385 q:=link(p);
2386 until q=tx; {found |r|$\to$|p|$\to$|q=tx|}
2387 q:=link(tx); link(p):=q; link(tx):=null;
2388 if q=null then if fm then confusion("tail1")
2389 @:this can't happen tail1}{\quad tail1@>
2390 else tail:=p
2391 else if fm then {|r|$\to$|p=begin_M|$\to$|q=end_M|}
2392 begin tail:=r; link(r):=null; flush_node_list(p);@+end
2393 @#
2394 @d check_effective_tail(#)==find_effective_tail_eTeX
2395 @d fetch_effective_tail==fetch_effective_tail_eTeX
2396
2397 @<If the current list ends with a box node, delete it...@>=
2398 @z
2399 %---------------------------------------
2400 @x [47.1080] l.20975 - e-TeX TeXXeT
2401 else begin if not is_char_node(tail) then
2402 if (type(tail)=hlist_node)or(type(tail)=vlist_node) then
2403 @<Remove the last box, unless it's part of a discretionary@>;
2404 end;
2405 @y
2406 else begin check_effective_tail(goto done);
2407 if not is_char_node(tx) then
2408 if (type(tx)=hlist_node)or(type(tx)=vlist_node) then
2409 @<Remove the last box, unless it's part of a discretionary@>;
2410 done:end;
2411 @z
2412 %---------------------------------------
2413 @x [47.1081] l.20982 - e-TeX TeXXeT
2414 begin q:=head;
2415 repeat p:=q;
2416 if not is_char_node(q) then if type(q)=disc_node then
2417 begin for m:=1 to replace_count(q) do p:=link(p);
2418 if p=tail then goto done;
2419 end;
2420 q:=link(p);
2421 until q=tail;
2422 cur_box:=tail; shift_amount(cur_box):=0;
2423 tail:=p; link(p):=null;
2424 done:end
2425 @y
2426 begin fetch_effective_tail(goto done);
2427 cur_box:=tx; shift_amount(cur_box):=0;
2428 end
2429 @z
2430 %---------------------------------------
2431 @x [47.1082] l.20997 - e-TeX sparse arrays
2432 begin scan_eight_bit_int; n:=cur_val;
2433 @y
2434 begin scan_register_num; n:=cur_val;
2435 @z
2436 %---------------------------------------
2437 @x [47.1096] l.21181 - e-TeX penalties, TeXXeT
2438 else line_break(widow_penalty);
2439 @y
2440 else line_break(false);
2441 if LR_save<>null then
2442 begin flush_list(LR_save); LR_save:=null;
2443 end;
2444 @z
2445 %---------------------------------------
2446 @x [47.1101] l.21237 - make_mark - e-TeX marks
2447 begin p:=scan_toks(false,true); p:=get_node(small_node_size);
2448 @y
2449 @!c:halfword; {the mark class}
2450 begin if cur_chr=0 then c:=0
2451 else begin scan_register_num; c:=cur_val;
2452 end;
2453 p:=scan_toks(false,true); p:=get_node(small_node_size);
2454 mark_class(p):=c;
2455 @z
2456 %---------------------------------------
2457 @x [47.1105] l.21271 - delete_last - e-TeX TeXXeT
2458 @!m:quarterword; {the length of a replacement list}
2459 @y
2460 @!r:pointer; {running behind |p|}
2461 @!fm:boolean; {a final \.{\\beginM} \.{\\endM} node pair?}
2462 @!tx:pointer; {effective tail node}
2463 @!m:quarterword; {the length of a replacement list}
2464 @z
2465 %---------------------------------------
2466 @x [47.1105] l.21275 - delete_last - e-TeX TeXXeT
2467 else begin if not is_char_node(tail) then if type(tail)=cur_chr then
2468 begin q:=head;
2469 repeat p:=q;
2470 if not is_char_node(q) then if type(q)=disc_node then
2471 begin for m:=1 to replace_count(q) do p:=link(p);
2472 if p=tail then return;
2473 end;
2474 q:=link(p);
2475 until q=tail;
2476 link(p):=null; flush_node_list(tail); tail:=p;
2477 @y
2478 else begin check_effective_tail(return);
2479 if not is_char_node(tx) then if type(tx)=cur_chr then
2480 begin fetch_effective_tail(return);
2481 flush_node_list(tx);
2482 @z
2483 %---------------------------------------
2484 @x [47.1108] l.21324 - e-TeX saved_items
2485 un_vbox: if chr_code=copy_code then print_esc("unvcopy")
2486 @y
2487 un_vbox: if chr_code=copy_code then print_esc("unvcopy")
2488 @<Cases of |un_vbox| for |print_cmd_chr|@>@/
2489 @z
2490 %---------------------------------------
2491 @x [47.1110] l.21334 - unpackage - e-TeX saved_items
2492 label exit;
2493 @y
2494 label done, exit;
2495 @z
2496 %---------------------------------------
2497 @x [47.1110] l.21337 - unpackage - e-TeX saved_items, sparse arrays
2498 begin c:=cur_chr; scan_eight_bit_int; p:=box(cur_val);
2499 @y
2500 begin if cur_chr>copy_code then @<Handle saved items and |goto done|@>;
2501 c:=cur_chr; scan_register_num; fetch_box(p);
2502 @z
2503 %---------------------------------------
2504 @x [47.1110] l.21349 - unpackage - e-TeX sparse arrays
2505 else begin link(tail):=list_ptr(p); box(cur_val):=null;
2506 @y
2507 else begin link(tail):=list_ptr(p); change_box(null);
2508 @z
2509 %---------------------------------------
2510 @x [47.1110] l.21352 - unpackage - e-TeX saved_items
2511 while link(tail)<>null do tail:=link(tail);
2512 @y
2513 done:
2514 while link(tail)<>null do tail:=link(tail);
2515 @z
2516 %---------------------------------------
2517 @x [47.1130] l.21624 - e-TeX TeXXeT
2518 vmode+halign,hmode+valign:init_align;
2519 @y
2520 vmode+halign:init_align;
2521 hmode+valign:@<Cases of |main_control| for |hmode+valign|@>@; init_align;
2522 @z
2523 %---------------------------------------
2524 @x [48.1138] l.21703 - init_math - e-TeX TeXXeT
2525 procedure init_math;
2526 label reswitch,found,not_found,done;
2527 var w:scaled; {new or partial |pre_display_size|}
2528 @y
2529 @t\4@>@<Declare subprocedures for |init_math|@>@;
2530 procedure init_math;
2531 label reswitch,found,not_found,done;
2532 var w:scaled; {new or partial |pre_display_size|}
2533 @!j:pointer; {prototype box for display}
2534 @!x:integer; {new |pre_display_direction|}
2535 @z
2536 %---------------------------------------
2537 @x [48.1145] l.21761 - e-TeX TeXXeT, penalties
2538 begin if head=tail then {`\.{\\noindent\$\$}' or `\.{\$\${ }\$\$}'}
2539 begin pop_nest; w:=-max_dimen;
2540 end
2541 else begin line_break(display_widow_penalty);@/
2542 @y
2543 begin j:=null; w:=-max_dimen;
2544 if head=tail then {`\.{\\noindent\$\$}' or `\.{\$\${ }\$\$}'}
2545 @<Prepare for display after an empty paragraph@>
2546 else begin line_break(true);@/
2547 @z
2548 %---------------------------------------
2549 @x [48.1145] l.21774 - e-TeX TeXXeT
2550 eq_word_define(dimen_base+pre_display_size_code,w);
2551 @y
2552 eq_word_define(dimen_base+pre_display_size_code,w);
2553 LR_box:=j;
2554 if eTeX_ex then eq_word_define(int_base+pre_display_direction_code,x);
2555 @z
2556 %---------------------------------------
2557 @x [48.1146] l.21782 - e-TeX TeXXeT
2558 v:=shift_amount(just_box)+2*quad(cur_font); w:=-max_dimen;
2559 p:=list_ptr(just_box);
2560 @y
2561 @<Prepare for display after a non-empty paragraph@>;
2562 @z
2563 %---------------------------------------
2564 @x [48.1146] l.21797 - e-TeX TeXXeT
2565 done:
2566 @y
2567 done:
2568 @<Finish the natural width computation@>
2569 @z
2570 %---------------------------------------
2571 @x [48.1147] l.21808 - e-TeX TeXXeT
2572 kern_node,math_node: d:=width(p);
2573 @y
2574 kern_node: d:=width(p);
2575 @t\4@>@<Cases of `Let |d| be the natural width' that need special treatment@>@;
2576 @z
2577 %---------------------------------------
2578 @x [48.1185] l.22317 - e-TeX middle
2579 if type(q)<>left_noad then confusion("right");
2580 @:this can't happen right}{\quad right@>
2581 info(numerator(incompleat_noad)):=link(q);
2582 link(q):=incompleat_noad; link(incompleat_noad):=p;
2583 @y
2584 if (type(q)<>left_noad)or(delim_ptr=null) then confusion("right");
2585 @:this can't happen right}{\quad right@>
2586 info(numerator(incompleat_noad)):=link(delim_ptr);
2587 link(delim_ptr):=incompleat_noad; link(incompleat_noad):=p;
2588 @z
2589 %---------------------------------------
2590 @x [48.1189] l.22362 - e-TeX middle
2591 else print_esc("right");
2592 @y
2593 @/@<Cases of |left_right| for |print_cmd_chr|@>@/
2594 else print_esc("right");
2595 @z
2596 %---------------------------------------
2597 @x [48.1191] l.22371 - math_left_right - e-TeX middle
2598 begin t:=cur_chr;
2599 if (t=right_noad)and(cur_group<>math_left_group) then
2600 @y
2601 @!q:pointer; {resulting mlist}
2602 begin t:=cur_chr;
2603 if (t<>left_noad)and(cur_group<>math_left_group) then
2604 @z
2605 %---------------------------------------
2606 @x [48.1191] l.22376 - math_left_right - e-TeX middle
2607 if t=left_noad then
2608 begin push_math(math_left_group); link(head):=p; tail:=p;
2609 end
2610 else begin p:=fin_mlist(p); unsave; {end of |math_left_group|}
2611 @y
2612 if t=middle_noad then
2613 begin type(p):=right_noad; subtype(p):=middle_noad;
2614 end;
2615 if t=left_noad then q:=p
2616 else begin q:=fin_mlist(p); unsave; {end of |math_left_group|}
2617 end;
2618 if t<>right_noad then
2619 begin push_math(math_left_group); link(head):=q; tail:=p;
2620 delim_ptr:=p;
2621 end
2622 else begin
2623 @z
2624 %---------------------------------------
2625 @x [48.1191] l.22382 - math_left_right - e-TeX middle
2626 info(nucleus(tail)):=p;
2627 @y
2628 info(nucleus(tail)):=q;
2629 @z
2630 %---------------------------------------
2631 @x [48.1192] l.22390 - e-TeX middle
2632 print_err("Extra "); print_esc("right");
2633 @.Extra \\right.@>
2634 help1("I'm ignoring a \right that had no matching \left.");
2635 @y
2636 print_err("Extra ");
2637 if t=middle_noad then
2638 begin print_esc("middle");
2639 @.Extra \\middle.@>
2640 help1("I'm ignoring a \middle that had no matching \left.");
2641 end
2642 else begin print_esc("right");
2643 @.Extra \\right.@>
2644 help1("I'm ignoring a \right that had no matching \left.");
2645 end;
2646 @z
2647 %---------------------------------------
2648 @x [48.1194] l.22405 - after_math - e-TeX TeXXeT
2649 procedure after_math;
2650 @y
2651 @t\4@>@<Declare subprocedures for |after_math|@>@;
2652 procedure after_math;
2653 @z
2654 %---------------------------------------
2655 @x [48.1194] l.22412 - after_math - e-TeX TeXXeT
2656 begin danger:=false;
2657 @y
2658 begin danger:=false;
2659 @<Retrieve the prototype box@>;
2660 @z
2661 %---------------------------------------
2662 @x [48.1194] l.22419 - after_math - e-TeX TeXXeT
2663 mlist_to_hlist; a:=hpack(link(temp_head),natural);
2664 @y
2665 mlist_to_hlist; a:=hpack(link(temp_head),natural);
2666 set_box_lr(a)(dlist);
2667 @z
2668 %---------------------------------------
2669 @x [48.1194] l.22422 - after_math - e-TeX TeXXeT
2670 danger:=false;
2671 @y
2672 danger:=false;
2673 @<Retrieve the prototype box@>;
2674 @z
2675 %---------------------------------------
2676 @x [48.1199] l.22509 - e-TeX TeXXeT
2677 w:=width(b); z:=display_width; s:=display_indent;
2678 @y
2679 w:=width(b); z:=display_width; s:=display_indent;
2680 if pre_display_direction<0 then s:=-s-z;
2681 @z
2682 %---------------------------------------
2683 @x [48.1199] l.22524 - e-TeX TeXXeT
2684 resume_after_display
2685 @y
2686 @<Flush the prototype box@>;
2687 resume_after_display
2688 @z
2689 %---------------------------------------
2690 @x [48.1202] l.22566 - e-TeX TeXXeT
2691 d:=half(z-w);
2692 @y
2693 set_box_lr(b)(dlist);
2694 d:=half(z-w);
2695 @z
2696 %---------------------------------------
2697 @x [48.1203] l.22587 - e-TeX TeXXeT
2698 begin shift_amount(a):=s; append_to_vlist(a);
2699 @y
2700 begin app_display(j,a,0);
2701 @z
2702 %---------------------------------------
2703 @x [48.1204] l.22602 - e-TeX TeXXeT
2704 shift_amount(b):=s+d; append_to_vlist(b)
2705 @y
2706 app_display(j,b,d)
2707 @z
2708 %---------------------------------------
2709 @x [48.1205] l.22607 - e-TeX TeXXeT
2710 shift_amount(a):=s+z-width(a);
2711 append_to_vlist(a);
2712 @y
2713 app_display(j,a,z-width(a));
2714 @z
2715 %---------------------------------------
2716 @x [48.1206] l.22626 - e-TeX TeXXeT
2717 pop_nest;
2718 @y
2719 flush_node_list(LR_box);
2720 pop_nest;
2721 @z
2722 %---------------------------------------
2723 @x [49.1208] l.22651 - e-TeX protected
2724 control sequence can be defined to be `\.{\\long}' or `\.{\\outer}', and
2725 it might or might not be expanded. The prefixes `\.{\\global}', `\.{\\long}',
2726 @y
2727 control sequence can be defined to be `\.{\\long}', `\.{\\protected}',
2728 or `\.{\\outer}', and it might or might not be expanded. The prefixes
2729 `\.{\\global}', `\.{\\long}', `\.{\\protected}',
2730 @z
2731 %---------------------------------------
2732 @x [49.1209] l.22677 - e-TeX protected
2733 else print_esc("global");
2734 @y
2735 @/@<Cases of |prefix| for |print_cmd_chr|@>@/
2736 else print_esc("global");
2737 @z
2738 %---------------------------------------
2739 @x [49.1211] l.22739 - prefixed_command - e-TeX tracing
2740 @<Discard erroneous prefixes and |return|@>;
2741 @y
2742 @<Discard erroneous prefixes and |return|@>;
2743 if tracing_commands>2 then if eTeX_ex then show_cur_cmd_chr;
2744 @z
2745 %---------------------------------------
2746 @x [49.1212] l.22755 - e-TeX protected
2747 help1("I'll pretend you didn't say \long or \outer or \global.");
2748 @y
2749 help1("I'll pretend you didn't say \long or \outer or \global.");
2750 if eTeX_ex then help_line[0]:=@|
2751 "I'll pretend you didn't say \long or \outer or \global or \protected.";
2752 @z
2753 %---------------------------------------
2754 @x [49.1213] l.22760 - e-TeX protected
2755 if (cur_cmd<>def)and(a mod 4<>0) then
2756 begin print_err("You can't use `"); print_esc("long"); print("' or `");
2757 print_esc("outer"); print("' with `");
2758 @y
2759 if a>=8 then
2760 begin j:=protected_token; a:=a-8;
2761 end
2762 else j:=0;
2763 if (cur_cmd<>def)and((a mod 4<>0)or(j<>0)) then
2764 begin print_err("You can't use `"); print_esc("long"); print("' or `");
2765 print_esc("outer");
2766 help1("I'll pretend you didn't say \long or \outer here.");
2767 if eTeX_ex then
2768 begin help_line[0]:=@|
2769 "I'll pretend you didn't say \long or \outer or \protected here.";
2770 print("' or `"); print_esc("protected");
2771 end;
2772 print("' with `");
2773 @z
2774 %---------------------------------------
2775 @x [49.1213] l.22765 - e-TeX protected
2776 help1("I'll pretend you didn't say \long or \outer here.");
2777 @y
2778 @z
2779 %---------------------------------------
2780 @x [49.1218] l.22824 - e-TeX protected
2781 q:=scan_toks(true,e); define(p,call+(a mod 4),def_ref);
2782 @y
2783 q:=scan_toks(true,e);
2784 if j<>0 then
2785 begin q:=get_avail; info(q):=j; link(q):=link(def_ref);
2786 link(def_ref):=q;
2787 end;
2788 define(p,call+(a mod 4),def_ref);
2789 @z
2790 %---------------------------------------
2791 @x [49.1221] l.22852 - e-TeX sparse arrays
2792 if cur_cmd>=call then add_token_ref(cur_chr);
2793 @y
2794 if cur_cmd>=call then add_token_ref(cur_chr)
2795 else if (cur_cmd=register)or(cur_cmd=toks_register) then
2796 if (cur_chr<mem_bot)or(cur_chr>lo_mem_stat_max) then
2797 add_sa_ref(cur_chr);
2798 @z
2799 %---------------------------------------
2800 @x [49.1224] l.22915 - e-TeX sparse arrays
2801 othercases begin scan_eight_bit_int;
2802 @y
2803 othercases begin scan_register_num;
2804 if cur_val>255 then
2805 begin j:=n-count_def_code; {|int_val..box_val|}
2806 if j>mu_val then j:=tok_val; {|int_val..mu_val| or |tok_val|}
2807 find_sa_element(j,cur_val,true); add_sa_ref(cur_ptr);
2808 if j=tok_val then j:=toks_register@+else j:=register;
2809 define(p,j,cur_ptr);
2810 end
2811 else
2812 @z
2813 %---------------------------------------
2814 @x [49.1225] l.22928 - e-TeX read_line
2815 read_to_cs: begin scan_int; n:=cur_val;
2816 @y
2817 read_to_cs: begin j:=cur_chr; scan_int; n:=cur_val;
2818 @z
2819 %---------------------------------------
2820 @x [49.1225] l.22937 - e-TeX read_line
2821 p:=cur_cs; read_toks(n,p); define(p,call,cur_val);
2822 @y
2823 p:=cur_cs; read_toks(n,p,j); define(p,call,cur_val);
2824 @z
2825 %---------------------------------------
2826 @x [49.1226] l.22946 - e-TeX sparse arrays
2827 if cur_cmd=toks_register then
2828 begin scan_eight_bit_int; p:=toks_base+cur_val;
2829 end
2830 else p:=cur_chr; {|p=every_par_loc| or |output_routine_loc| or \dots}
2831 @y
2832 e:=false; {just in case, will be set |true| for sparse array elements}
2833 if cur_cmd=toks_register then
2834 if cur_chr=mem_bot then
2835 begin scan_register_num;
2836 if cur_val>255 then
2837 begin find_sa_element(tok_val,cur_val,true);
2838 cur_chr:=cur_ptr; e:=true;
2839 end
2840 else cur_chr:=toks_base+cur_val;
2841 end
2842 else e:=true;
2843 p:=cur_chr; {|p=every_par_loc| or |output_routine_loc| or \dots}
2844 @z
2845 %---------------------------------------
2846 @x [49.1226] l.22956 - e-TeX sparse arrays
2847 begin define(p,undefined_cs,null); free_avail(def_ref);
2848 end
2849 else begin if p=output_routine_loc then {enclose in curlies}
2850 @y
2851 begin sa_define(p,null)(p,undefined_cs,null); free_avail(def_ref);
2852 end
2853 else begin if (p=output_routine_loc)and not e then {enclose in curlies}
2854 @z
2855 %---------------------------------------
2856 @x [49.1226] l.22964 - e-TeX sparse arrays
2857 define(p,call,def_ref);
2858 @y
2859 sa_define(p,def_ref)(p,call,def_ref);
2860 @z
2861 %---------------------------------------
2862 @x [49.1227] l.22969 - e-TeX sparse arrays
2863 begin if cur_cmd=toks_register then
2864 begin scan_eight_bit_int; cur_cmd:=assign_toks; cur_chr:=toks_base+cur_val;
2865 end;
2866 if cur_cmd=assign_toks then
2867 begin q:=equiv(cur_chr);
2868 if q=null then define(p,undefined_cs,null)
2869 else begin add_token_ref(q); define(p,call,q);
2870 end;
2871 goto done;
2872 end;
2873 end
2874 @y
2875 if (cur_cmd=toks_register)or(cur_cmd=assign_toks) then
2876 begin if cur_cmd=toks_register then
2877 if cur_chr=mem_bot then
2878 begin scan_register_num;
2879 if cur_val<256 then q:=equiv(toks_base+cur_val)
2880 else begin find_sa_element(tok_val,cur_val,false);
2881 if cur_ptr=null then q:=null
2882 else q:=sa_ptr(cur_ptr);
2883 end;
2884 end
2885 else q:=sa_ptr(cur_chr)
2886 else q:=equiv(cur_chr);
2887 if q=null then sa_define(p,null)(p,undefined_cs,null)
2888 else begin add_token_ref(q); sa_define(p,q)(p,call,q);
2889 end;
2890 goto done;
2891 end
2892 @z
2893 %---------------------------------------
2894 @x [49.1236] l.23085 - do_register_command - e-TeX sparse arrays
2895 begin q:=cur_cmd;
2896 @y
2897 @!e:boolean; {does |l| refer to a sparse array element?}
2898 @!w:integer; {integer or dimen value of |l|}
2899 begin q:=cur_cmd;
2900 e:=false; {just in case, will be set |true| for sparse array elements}
2901 @z
2902 %---------------------------------------
2903 @x [49.1236] l.23102 - do_register_command - e-TeX sparse arrays
2904 if p<glue_val then word_define(l,cur_val)
2905 else begin trap_zero_glue; define(l,glue_ref,cur_val);
2906 @y
2907 if p<glue_val then sa_word_define(l,cur_val)
2908 else begin trap_zero_glue; sa_define(l,cur_val)(l,glue_ref,cur_val);
2909 @z
2910 %---------------------------------------
2911 @x [49.1237] l.23124 - e-TeX sparse arrays
2912 p:=cur_chr; scan_eight_bit_int;
2913 @y
2914 if (cur_chr<mem_bot)or(cur_chr>lo_mem_stat_max) then
2915 begin l:=cur_chr; p:=sa_type(l); e:=true;
2916 end
2917 else begin p:=cur_chr-mem_bot; scan_register_num;
2918 if cur_val>255 then
2919 begin find_sa_element(p,cur_val,true); l:=cur_ptr; e:=true;
2920 end
2921 else
2922 @z
2923 %---------------------------------------
2924 @x [49.1237] l.23131 - e-TeX sparse arrays
2925 end;
2926 found:
2927 @y
2928 end;
2929 end;
2930 found: if p<glue_val then@+if e then w:=sa_int(l)@+else w:=eqtb[l].int
2931 else if e then s:=sa_ptr(l)@+else s:=equiv(l)
2932 @z
2933 %---------------------------------------
2934 @x [49.1238] l.23137 - e-TeX sparse arrays
2935 if q=advance then cur_val:=cur_val+eqtb[l].int;
2936 @y
2937 if q=advance then cur_val:=cur_val+w;
2938 @z
2939 %---------------------------------------
2940 @x [49.1239] l.23144 - e-TeX sparse arrays
2941 begin q:=new_spec(cur_val); r:=equiv(l);
2942 @y
2943 begin q:=new_spec(cur_val); r:=s;
2944 @z
2945 %---------------------------------------
2946 @x [49.1240] l.23164 - e-TeX sparse arrays
2947 if p=int_val then cur_val:=mult_integers(eqtb[l].int,cur_val)
2948 else cur_val:=nx_plus_y(eqtb[l].int,cur_val,0)
2949 else cur_val:=x_over_n(eqtb[l].int,cur_val)
2950 else begin s:=equiv(l); r:=new_spec(s);
2951 @y
2952 if p=int_val then cur_val:=mult_integers(w,cur_val)
2953 else cur_val:=nx_plus_y(w,cur_val,0)
2954 else cur_val:=x_over_n(w,cur_val)
2955 else begin r:=new_spec(s);
2956 @z
2957 %---------------------------------------
2958 @x [49.1241] l.23186 - e-TeX sparse arrays
2959 set_box: begin scan_eight_bit_int;
2960 if global then n:=256+cur_val@+else n:=cur_val;
2961 scan_optional_equals;
2962 if set_box_allowed then scan_box(box_flag+n)
2963 @y
2964 set_box: begin scan_register_num;
2965 if global then n:=global_box_flag+cur_val@+else n:=box_flag+cur_val;
2966 scan_optional_equals;
2967 if set_box_allowed then scan_box(n)
2968 @z
2969 %---------------------------------------
2970 @x [49.1246] l.23257 - alter_integer - e-TeX interaction_mode
2971 var c:0..1; {0 for \.{\\deadcycles}, 1 for \.{\\insertpenalties}}
2972 begin c:=cur_chr; scan_optional_equals; scan_int;
2973 if c=0 then dead_cycles:=cur_val
2974 @y
2975 var c:small_number;
2976 {0 for \.{\\deadcycles}, 1 for \.{\\insertpenalties}, etc.}
2977 begin c:=cur_chr; scan_optional_equals; scan_int;
2978 if c=0 then dead_cycles:=cur_val
2979 @/@<Cases for |alter_integer|@>@/
2980 @z
2981 %---------------------------------------
2982 @x [49.1247] l.23266 - alter_box_dimen - e-TeX sparse arrays
2983 @!b:eight_bits; {box number}
2984 begin c:=cur_chr; scan_eight_bit_int; b:=cur_val; scan_optional_equals;
2985 scan_normal_dimen;
2986 if box(b)<>null then mem[box(b)+c].sc:=cur_val;
2987 @y
2988 @!b:pointer; {box register}
2989 begin c:=cur_chr; scan_register_num; fetch_box(b); scan_optional_equals;
2990 scan_normal_dimen;
2991 if b<>null then mem[b+c].sc:=cur_val;
2992 @z
2993 %---------------------------------------
2994 @x [49.1248] l.23275 - e-TeX penalties
2995 set_shape: begin scan_optional_equals; scan_int; n:=cur_val;
2996 if n<=0 then p:=null
2997 @y
2998 set_shape: begin q:=cur_chr; scan_optional_equals; scan_int; n:=cur_val;
2999 if n<=0 then p:=null
3000 else if q>par_shape_loc then
3001 begin n:=(cur_val div 2)+1; p:=get_node(2*n+1); info(p):=n;
3002 n:=cur_val; mem[p+1].int:=n; {number of penalties}
3003 for j:=p+2 to p+n+1 do
3004 begin scan_int; mem[j].int:=cur_val; {penalty values}
3005 end;
3006 if not odd(n) then mem[p+n+2].int:=0; {unused}
3007 end
3008 @z
3009 %---------------------------------------
3010 @x [49.1248] l.23285 - e-TeX penalties
3011 define(par_shape_loc,shape_ref,p);
3012 @y
3013 define(q,shape_ref,p);
3014 @z
3015 %---------------------------------------
3016 @x [49.1257] l.23372 - new_font - e-TeX tracing
3017 common_ending: equiv(u):=f; eqtb[font_id_base+f]:=eqtb[u]; font_id_text(f):=t;
3018 @y
3019 common_ending: define(u,set_font,f); eqtb[font_id_base+f]:=eqtb[u]; font_id_text(f):=t;
3020 @z
3021 %---------------------------------------
3022 @x [49.1292] l.23659 - e-TeX show_groups
3023 show_lists_code:print_esc("showlists");
3024 @y
3025 show_lists_code:print_esc("showlists");
3026 @<Cases of |xray| for |print_cmd_chr|@>@;@/
3027 @z
3028 %---------------------------------------
3029 @x [49.1293] l.23666 - show_whatever - e-TeX show_ifs
3030 var p:pointer; {tail of a token list to show}
3031 @y
3032 var p:pointer; {tail of a token list to show}
3033 @!t:small_number; {type of conditional being shown}
3034 @!m:normal..or_code; {upper bound on |fi_or_else| codes}
3035 @!l:integer; {line where that conditional began}
3036 @!n:integer; {level of \.{\\if...\\fi} nesting}
3037 @z
3038 %---------------------------------------
3039 @x [49.1293] l.23672 - show_whatever - e-TeX show_groups
3040 othercases @<Show the current value of some parameter or register,
3041 @y
3042 @<Cases for |show_whatever|@>@;@/
3043 othercases @<Show the current value of some parameter or register,
3044 @z
3045 %---------------------------------------
3046 @x [49.1295] l.23707 - e-TeX protected
3047 call: print("macro");
3048 long_call: print_esc("long macro");
3049 outer_call: print_esc("outer macro");
3050 long_outer_call: begin print_esc("long"); print_esc("outer macro");
3051 @y
3052 call,long_call,outer_call,long_outer_call: begin n:=cmd-call;
3053 if info(link(chr_code))=protected_token then n:=n+4;
3054 if odd(n div 4) then print_esc("protected");
3055 if odd(n) then print_esc("long");
3056 if odd(n div 2) then print_esc("outer");
3057 if n>0 then print_char(" ");
3058 print("macro");
3059 @z
3060 %---------------------------------------
3061 @x [49.1296] l.23715 - e-TeX sparse arrays
3062 begin scan_eight_bit_int; begin_diagnostic;
3063 print_nl("> \box"); print_int(cur_val); print_char("=");
3064 if box(cur_val)=null then print("void")
3065 else show_box(box(cur_val));
3066 @y
3067 begin scan_register_num; fetch_box(p); begin_diagnostic;
3068 print_nl("> \box"); print_int(cur_val); print_char("=");
3069 if p=null then print("void")@+else show_box(p);
3070 @z
3071 %---------------------------------------
3072 @x [50.1307] l.23859 - e-TeX basic
3073 dump_int(@$);@/
3074 @y
3075 dump_int(@$);@/
3076 @<Dump the \eTeX\ state@>@/
3077 @z
3078 %---------------------------------------
3079 @x [50.1308] l.23874 - e-TeX basic
3080 if x<>@$ then goto bad_fmt; {check that strings are the same}
3081 @y
3082 if x<>@$ then goto bad_fmt; {check that strings are the same}
3083 @/@<Undump the \eTeX\ state@>@/
3084 @z
3085 %---------------------------------------
3086 @x [50.1311] l.23928 - e-TeX sparse arrays
3087 dump_int(lo_mem_max); dump_int(rover);
3088 @y
3089 dump_int(lo_mem_max); dump_int(rover);
3090 if eTeX_ex then for k:=int_val to tok_val do dump_int(sa_root[k]);
3091 @z
3092 %---------------------------------------
3093 @x [50.1312] l.23951 - e-TeX sparse arrays
3094 undump(lo_mem_stat_max+1)(lo_mem_max)(rover);
3095 @y
3096 undump(lo_mem_stat_max+1)(lo_mem_max)(rover);
3097 if eTeX_ex then for k:=int_val to tok_val do
3098 undump(null)(lo_mem_max)(sa_root[k]);
3099 @z
3100 %---------------------------------------
3101 @x [50.1324] l.24145 - e-TeX hyph_codes
3102 dump_int(trie_max);
3103 @y
3104 dump_int(trie_max);
3105 dump_int(hyph_start);
3106 @z
3107 %---------------------------------------
3108 @x [50.1325] l.24173 - e-TeX hyph_codes
3109 undump_size(0)(trie_size)('trie size')(j); @+init trie_max:=j;@+tini
3110 @y
3111 undump_size(0)(trie_size)('trie size')(j); @+init trie_max:=j;@+tini
3112 undump(0)(j)(hyph_start);
3113 @z
3114 %---------------------------------------
3115 @x [51.1335] l.24393 - final_cleanup - tracing
3116 print_int(cur_level-level_one); print_char(")");
3117 @y
3118 print_int(cur_level-level_one); print_char(")");
3119 if eTeX_ex then show_save_groups;
3120 @z
3121 %---------------------------------------
3122 @x [51.1335] l.24416 - final_cleanup - e-TeX marks, saved_items
3123 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
3124 @y
3125 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
3126 if sa_mark<>null then
3127 if do_marks(destroy_marks,0,sa_mark) then sa_mark:=null;
3128 for c:=last_box_code to vsplit_code do flush_node_list(disc_ptr[c]);
3129 @z
3130 %---------------------------------------
3131 @x [51.1336] l.24426 - init_prim - e-TeX basic
3132 begin no_new_control_sequence:=false;
3133 @y
3134 begin no_new_control_sequence:=false;
3135 first:=0;
3136 @z
3137 %---------------------------------------
3138 @x [51.1337] l.24441 - e-TeX basic
3139 if (format_ident=0)or(buffer[loc]="&") then
3140 @y
3141 @<Enable \eTeX, if requested@>@;@/
3142 if (format_ident=0)or(buffer[loc]="&") then
3143 @z
3144 %---------------------------------------
3145 @x [51.1337] l.24449 - e-TeX basic
3146 end;
3147 @y
3148 end;
3149 if eTeX_ex then wterm_ln('entering extended mode');
3150 @z
3151 %---------------------------------------
3152 @x [53.1362] l.24791 - adv_past - e-TeX hyph_codes
3153 begin cur_lang:=what_lang(#); l_hyf:=what_lhm(#); r_hyf:=what_rhm(#);@+end
3154 @y
3155 begin cur_lang:=what_lang(#); l_hyf:=what_lhm(#); r_hyf:=what_rhm(#);
3156 set_hyph_index;
3157 end
3158 @z
3159 %---------------------------------------
3160 @x [54.1379] l.24985 - e-TeX additions
3161 @* \[54] System-dependent changes.
3162 @y
3163 @* \[53a] The extended features of \eTeX.
3164 The program has two modes of operation: (1)~In \TeX\ compatibility mode
3165 it fully deserves the name \TeX\ and there are neither extended features
3166 nor additional primitive commands. There are, however, a few
3167 modifications that would be legitimate in any implementation of \TeX\
3168 such as, e.g., preventing inadequate results of the glue to \.{DVI}
3169 unit conversion during |ship_out|. (2)~In extended mode there are
3170 additional primitive commands and the extended features of \eTeX\ are
3171 available.
3172
3173 The distinction between these two modes of operation initially takes
3174 place when a `virgin' \.{eINITEX} starts without reading a format file.
3175 Later on the values of all \eTeX\ state variables are inherited when
3176 \.{eVIRTEX} (or \.{eINITEX}) reads a format file.
3177
3178 The code below is designed to work for cases where `$|init|\ldots|tini|$'
3179 is a run-time switch.
3180
3181 @<Enable \eTeX, if requested@>=
3182 @!init if (buffer[loc]="*")and(format_ident=" (INITEX)") then
3183 begin no_new_control_sequence:=false;
3184 @<Generate all \eTeX\ primitives@>@;
3185 incr(loc); eTeX_mode:=1; {enter extended mode}
3186 @<Initialize variables for \eTeX\ extended mode@>@;
3187 end;
3188 tini@;@/
3189 if not no_new_control_sequence then {just entered extended mode ?}
3190 no_new_control_sequence:=true@+else
3191
3192 @ The \eTeX\ features available in extended mode are grouped into two
3193 categories: (1)~Some of them are permanently enabled and have no
3194 semantic effect as long as none of the additional primitives are
3195 executed. (2)~The remaining \eTeX\ features are optional and can be
3196 individually enabled and disabled. For each optional feature there is
3197 an \eTeX\ state variable named \.{\\...state}; the feature is enabled,
3198 resp.\ disabled by assigning a positive, resp.\ non-positive value to
3199 that integer.
3200
3201 @d eTeX_state_base=int_base+eTeX_state_code
3202 @d eTeX_state(#)==eqtb[eTeX_state_base+#].int {an \eTeX\ state variable}
3203 @#
3204 @d eTeX_version_code=eTeX_int {code for \.{\\eTeXversion}}
3205
3206 @<Generate all \eTeX...@>=
3207 primitive("lastnodetype",last_item,last_node_type_code);
3208 @!@:last_node_type_}{\.{\\lastnodetype} primitive@>
3209 primitive("eTeXversion",last_item,eTeX_version_code);
3210 @!@:eTeX_version_}{\.{\\eTeXversion} primitive@>
3211 primitive("eTeXrevision",convert,eTeX_revision_code);@/
3212 @!@:eTeX_revision_}{\.{\\eTeXrevision} primitive@>
3213
3214 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3215 last_node_type_code: print_esc("lastnodetype");
3216 eTeX_version_code: print_esc("eTeXversion");
3217
3218 @ @<Cases for fetching an integer value@>=
3219 eTeX_version_code: cur_val:=eTeX_version;
3220
3221 @ @d eTeX_ex==(eTeX_mode=1) {is this extended mode?}
3222
3223 @<Glob...@>=
3224 @!eTeX_mode: 0..1; {identifies compatibility and extended mode}
3225
3226 @ @<Initialize table entries...@>=
3227 eTeX_mode:=0; {initially we are in compatibility mode}
3228 @<Initialize variables for \eTeX\ compatibility mode@>@;
3229
3230 @ @<Dump the \eTeX\ state@>=
3231 dump_int(eTeX_mode);
3232 for j:=0 to eTeX_states-1 do eTeX_state(j):=0; {disable all enhancements}
3233
3234 @ @<Undump the \eTeX\ state@>=
3235 undump(0)(1)(eTeX_mode);
3236 if eTeX_ex then
3237 begin @<Initialize variables for \eTeX\ extended mode@>@;
3238 end
3239 else begin @<Initialize variables for \eTeX\ compatibility mode@>@;
3240 end;
3241
3242 @ The |eTeX_enabled| function simply returns its first argument as
3243 result. This argument is |true| if an optional \eTeX\ feature is
3244 currently enabled; otherwise, if the argument is |false|, the function
3245 gives an error message.
3246
3247 @<Declare \eTeX\ procedures for use...@>=
3248 function eTeX_enabled(@!b:boolean;@!j:quarterword;@!k:halfword):boolean;
3249 begin if not b then
3250 begin print_err("Improper "); print_cmd_chr(j,k);
3251 help1("Sorry, this optional e-TeX feature has been disabled."); error;
3252 end;
3253 eTeX_enabled:=b;
3254 end;
3255
3256 @ First we implement the additional \eTeX\ parameters in the table of
3257 equivalents.
3258
3259 @<Generate all \eTeX...@>=
3260 primitive("everyeof",assign_toks,every_eof_loc);
3261 @!@:every_eof_}{\.{\\everyeof} primitive@>
3262 primitive("tracingassigns",assign_int,int_base+tracing_assigns_code);@/
3263 @!@:tracing_assigns_}{\.{\\tracingassigns} primitive@>
3264 primitive("tracinggroups",assign_int,int_base+tracing_groups_code);@/
3265 @!@:tracing_groups_}{\.{\\tracinggroups} primitive@>
3266 primitive("tracingifs",assign_int,int_base+tracing_ifs_code);@/
3267 @!@:tracing_ifs_}{\.{\\tracingifs} primitive@>
3268 primitive("tracingscantokens",assign_int,int_base+tracing_scan_tokens_code);@/
3269 @!@:tracing_scan_tokens_}{\.{\\tracingscantokens} primitive@>
3270 primitive("tracingnesting",assign_int,int_base+tracing_nesting_code);@/
3271 @!@:tracing_nesting_}{\.{\\tracingnesting} primitive@>
3272 primitive("predisplaydirection",
3273 assign_int,int_base+pre_display_direction_code);@/
3274 @!@:pre_display_direction_}{\.{\\predisplaydirection} primitive@>
3275 primitive("lastlinefit",assign_int,int_base+last_line_fit_code);@/
3276 @!@:last_line_fit_}{\.{\\lastlinefit} primitive@>
3277 primitive("savingvdiscards",assign_int,int_base+saving_vdiscards_code);@/
3278 @!@:saving_vdiscards_}{\.{\\savingvdiscards} primitive@>
3279 primitive("savinghyphcodes",assign_int,int_base+saving_hyph_codes_code);@/
3280 @!@:saving_hyph_codes_}{\.{\\savinghyphcodes} primitive@>
3281
3282 @ @d every_eof==equiv(every_eof_loc)
3283
3284 @<Cases of |assign_toks| for |print_cmd_chr|@>=
3285 every_eof_loc: print_esc("everyeof");
3286
3287 @ @<Cases for |print_param|@>=
3288 tracing_assigns_code:print_esc("tracingassigns");
3289 tracing_groups_code:print_esc("tracinggroups");
3290 tracing_ifs_code:print_esc("tracingifs");
3291 tracing_scan_tokens_code:print_esc("tracingscantokens");
3292 tracing_nesting_code:print_esc("tracingnesting");
3293 pre_display_direction_code:print_esc("predisplaydirection");
3294 last_line_fit_code:print_esc("lastlinefit");
3295 saving_vdiscards_code:print_esc("savingvdiscards");
3296 saving_hyph_codes_code:print_esc("savinghyphcodes");
3297
3298 @ In order to handle \.{\\everyeof} we need an array |eof_seen| of
3299 boolean variables.
3300
3301 @<Glob...@>=
3302 @!eof_seen : array[1..max_in_open] of boolean; {has eof been seen?}
3303
3304 @ The |print_group| procedure prints the current level of grouping and
3305 the name corresponding to |cur_group|.
3306
3307 @<Declare \eTeX\ procedures for tr...@>=
3308 procedure print_group(@!e:boolean);
3309 label exit;
3310 begin case cur_group of
3311 bottom_level: begin print("bottom level"); return;
3312 end;
3313 simple_group,semi_simple_group:
3314 begin if cur_group=semi_simple_group then print("semi ");
3315 print("simple");
3316 end;
3317 hbox_group,adjusted_hbox_group:
3318 begin if cur_group=adjusted_hbox_group then print("adjusted ");
3319 print("hbox");
3320 end;
3321 vbox_group: print("vbox");
3322 vtop_group: print("vtop");
3323 align_group,no_align_group:
3324 begin if cur_group=no_align_group then print("no ");
3325 print("align");
3326 end;
3327 output_group: print("output");
3328 disc_group: print("disc");
3329 insert_group: print("insert");
3330 vcenter_group: print("vcenter");
3331 math_group,math_choice_group,math_shift_group,math_left_group:
3332 begin print("math");
3333 if cur_group=math_choice_group then print(" choice")
3334 else if cur_group=math_shift_group then print(" shift")
3335 else if cur_group=math_left_group then print(" left");
3336 end;
3337 end; {there are no other cases}
3338 print(" group (level "); print_int(qo(cur_level)); print_char(")");
3339 if saved(-1)<>0 then
3340 begin if e then print(" entered at line ") else print(" at line ");
3341 print_int(saved(-1));
3342 end;
3343 exit:end;
3344
3345 @ The |group_trace| procedure is called when a new level of grouping
3346 begins (|e=false|) or ends (|e=true|) with |saved(-1)| containing the
3347 line number.
3348
3349 @<Declare \eTeX\ procedures for tr...@>=
3350 @!stat procedure group_trace(@!e:boolean);
3351 begin begin_diagnostic; print_char("{");
3352 if e then print("leaving ") else print("entering ");
3353 print_group(e); print_char("}"); end_diagnostic(false);
3354 end;
3355 tats
3356
3357 @ The \.{\\currentgrouplevel} and \.{\\currentgrouptype} commands return
3358 the current level of grouping and the type of the current group
3359 respectively.
3360
3361 @d current_group_level_code=eTeX_int+1 {code for \.{\\currentgrouplevel}}
3362 @d current_group_type_code=eTeX_int+2 {code for \.{\\currentgrouptype}}
3363
3364 @<Generate all \eTeX...@>=
3365 primitive("currentgrouplevel",last_item,current_group_level_code);
3366 @!@:current_group_level_}{\.{\\currentgrouplevel} primitive@>
3367 primitive("currentgrouptype",last_item,current_group_type_code);
3368 @!@:current_group_type_}{\.{\\currentgrouptype} primitive@>
3369
3370 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3371 current_group_level_code: print_esc("currentgrouplevel");
3372 current_group_type_code: print_esc("currentgrouptype");
3373
3374 @ @<Cases for fetching an integer value@>=
3375 current_group_level_code: cur_val:=cur_level-level_one;
3376 current_group_type_code: cur_val:=cur_group;
3377
3378 @ The \.{\\currentiflevel}, \.{\\currentiftype}, and
3379 \.{\\currentifbranch} commands return the current level of conditionals
3380 and the type and branch of the current conditional.
3381
3382 @d current_if_level_code=eTeX_int+3 {code for \.{\\currentiflevel}}
3383 @d current_if_type_code=eTeX_int+4 {code for \.{\\currentiftype}}
3384 @d current_if_branch_code=eTeX_int+5 {code for \.{\\currentifbranch}}
3385
3386 @<Generate all \eTeX...@>=
3387 primitive("currentiflevel",last_item,current_if_level_code);
3388 @!@:current_if_level_}{\.{\\currentiflevel} primitive@>
3389 primitive("currentiftype",last_item,current_if_type_code);
3390 @!@:current_if_type_}{\.{\\currentiftype} primitive@>
3391 primitive("currentifbranch",last_item,current_if_branch_code);
3392 @!@:current_if_branch_}{\.{\\currentifbranch} primitive@>
3393
3394 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3395 current_if_level_code: print_esc("currentiflevel");
3396 current_if_type_code: print_esc("currentiftype");
3397 current_if_branch_code: print_esc("currentifbranch");
3398
3399 @ @<Cases for fetching an integer value@>=
3400 current_if_level_code: begin q:=cond_ptr; cur_val:=0;
3401 while q<>null do
3402 begin incr(cur_val); q:=link(q);
3403 end;
3404 end;
3405 current_if_type_code: if cond_ptr=null then cur_val:=0
3406 else if cur_if<unless_code then cur_val:=cur_if+1
3407 else cur_val:=-(cur_if-unless_code+1);
3408 current_if_branch_code:
3409 if (if_limit=or_code)or(if_limit=else_code) then cur_val:=1
3410 else if if_limit=fi_code then cur_val:=-1
3411 else cur_val:=0;
3412
3413 @ The \.{\\fontcharwd}, \.{\\fontcharht}, \.{\\fontchardp}, and
3414 \.{\\fontcharic} commands return information about a character in a
3415 font.
3416
3417 @d font_char_wd_code=eTeX_dim {code for \.{\\fontcharwd}}
3418 @d font_char_ht_code=eTeX_dim+1 {code for \.{\\fontcharht}}
3419 @d font_char_dp_code=eTeX_dim+2 {code for \.{\\fontchardp}}
3420 @d font_char_ic_code=eTeX_dim+3 {code for \.{\\fontcharic}}
3421
3422 @<Generate all \eTeX...@>=
3423 primitive("fontcharwd",last_item,font_char_wd_code);
3424 @!@:font_char_wd_}{\.{\\fontcharwd} primitive@>
3425 primitive("fontcharht",last_item,font_char_ht_code);
3426 @!@:font_char_ht_}{\.{\\fontcharht} primitive@>
3427 primitive("fontchardp",last_item,font_char_dp_code);
3428 @!@:font_char_dp_}{\.{\\fontchardp} primitive@>
3429 primitive("fontcharic",last_item,font_char_ic_code);
3430 @!@:font_char_ic_}{\.{\\fontcharic} primitive@>
3431
3432 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3433 font_char_wd_code: print_esc("fontcharwd");
3434 font_char_ht_code: print_esc("fontcharht");
3435 font_char_dp_code: print_esc("fontchardp");
3436 font_char_ic_code: print_esc("fontcharic");
3437
3438 @ @<Cases for fetching a dimension value@>=
3439 font_char_wd_code,
3440 font_char_ht_code,
3441 font_char_dp_code,
3442 font_char_ic_code: begin scan_font_ident; q:=cur_val; scan_char_num;
3443 if (font_bc[q]<=cur_val)and(font_ec[q]>=cur_val) then
3444 begin i:=char_info(q)(qi(cur_val));
3445 case m of
3446 font_char_wd_code: cur_val:=char_width(q)(i);
3447 font_char_ht_code: cur_val:=char_height(q)(height_depth(i));
3448 font_char_dp_code: cur_val:=char_depth(q)(height_depth(i));
3449 font_char_ic_code: cur_val:=char_italic(q)(i);
3450 end; {there are no other cases}
3451 end
3452 else cur_val:=0;
3453 end;
3454
3455 @ The \.{\\parshapedimen}, \.{\\parshapeindent}, and \.{\\parshapelength}
3456 commands return the indent and length parameters of the current
3457 \.{\\parshape} specification.
3458
3459 @d par_shape_length_code=eTeX_dim+4 {code for \.{\\parshapelength}}
3460 @d par_shape_indent_code=eTeX_dim+5 {code for \.{\\parshapeindent}}
3461 @d par_shape_dimen_code=eTeX_dim+6 {code for \.{\\parshapedimen}}
3462
3463 @<Generate all \eTeX...@>=
3464 primitive("parshapelength",last_item,par_shape_length_code);
3465 @!@:par_shape_length_}{\.{\\parshapelength} primitive@>
3466 primitive("parshapeindent",last_item,par_shape_indent_code);
3467 @!@:par_shape_indent_}{\.{\\parshapeindent} primitive@>
3468 primitive("parshapedimen",last_item,par_shape_dimen_code);
3469 @!@:par_shape_dimen_}{\.{\\parshapedimen} primitive@>
3470
3471 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3472 par_shape_length_code: print_esc("parshapelength");
3473 par_shape_indent_code: print_esc("parshapeindent");
3474 par_shape_dimen_code: print_esc("parshapedimen");
3475
3476 @ @<Cases for fetching a dimension value@>=
3477 par_shape_length_code,
3478 par_shape_indent_code,
3479 par_shape_dimen_code: begin q:=cur_chr-par_shape_length_code; scan_int;
3480 if (par_shape_ptr=null)or(cur_val<=0) then cur_val:=0
3481 else begin if q=2 then
3482 begin q:=cur_val mod 2; cur_val:=(cur_val+q)div 2;
3483 end;
3484 if cur_val>info(par_shape_ptr) then cur_val:=info(par_shape_ptr);
3485 cur_val:=mem[par_shape_ptr+2*cur_val-q].sc;
3486 end;
3487 cur_val_level:=dimen_val;
3488 end;
3489
3490 @ The \.{\\showgroups} command displays all currently active grouping
3491 levels.
3492
3493 @d show_groups=4 { \.{\\showgroups} }
3494
3495 @<Generate all \eTeX...@>=
3496 primitive("showgroups",xray,show_groups);
3497 @!@:show_groups_}{\.{\\showgroups} primitive@>
3498
3499 @ @<Cases of |xray| for |print_cmd_chr|@>=
3500 show_groups:print_esc("showgroups");
3501
3502 @ @<Cases for |show_whatever|@>=
3503 show_groups: begin begin_diagnostic; show_save_groups;
3504 end;
3505
3506 @ @<Types...@>=
3507 @!save_pointer=0..save_size; {index into |save_stack|}
3508
3509 @ The modifications of \TeX\ required for the display produced by the
3510 |show_save_groups| procedure were first discussed by Donald~E. Knuth in
3511 {\sl TUGboat\/} {\bf 11}, 165--170 and 499--511, 1990.
3512 @^Knuth, Donald Ervin@>
3513
3514 In order to understand a group type we also have to know its mode.
3515 Since unrestricted horizontal modes are not associated with grouping,
3516 they are skipped when traversing the semantic nest.
3517
3518 @<Declare \eTeX\ procedures for use...@>=
3519 procedure show_save_groups;
3520 label found1,found2,found,done;
3521 var p:0..nest_size; {index into |nest|}
3522 @!m:-mmode..mmode; {mode}
3523 @!v:save_pointer; {saved value of |save_ptr|}
3524 @!l:quarterword; {saved value of |cur_level|}
3525 @!c:group_code; {saved value of |cur_group|}
3526 @!a:-1..1; {to keep track of alignments}
3527 @!i:integer;
3528 @!j:quarterword;
3529 @!s:str_number;
3530 begin p:=nest_ptr; nest[p]:=cur_list; {put the top level into the array}
3531 v:=save_ptr; l:=cur_level; c:=cur_group;
3532 save_ptr:=cur_boundary; decr(cur_level);@/
3533 a:=1;
3534 print_nl(""); print_ln;
3535 loop@+begin print_nl("### "); print_group(true);
3536 if cur_group=bottom_level then goto done;
3537 repeat m:=nest[p].mode_field;
3538 if p>0 then decr(p) else m:=vmode;
3539 until m<>hmode;
3540 print(" (");
3541 case cur_group of
3542 simple_group: begin incr(p); goto found2;
3543 end;
3544 hbox_group,adjusted_hbox_group: s:="hbox";
3545 vbox_group: s:="vbox";
3546 vtop_group: s:="vtop";
3547 align_group: if a=0 then
3548 begin if m=-vmode then s:="halign" else s:="valign";
3549 a:=1; goto found1;
3550 end
3551 else begin if a=1 then print("align entry") else print_esc("cr");
3552 if p>=a then p:=p-a;
3553 a:=0; goto found;
3554 end;
3555 no_align_group:
3556 begin incr(p); a:=-1; print_esc("noalign"); goto found2;
3557 end;
3558 output_group:
3559 begin print_esc("output"); goto found;
3560 end;
3561 math_group: goto found2;
3562 disc_group,math_choice_group:
3563 begin if cur_group=disc_group then print_esc("discretionary")
3564 else print_esc("mathchoice");
3565 for i:=1 to 3 do if i<=saved(-2) then print("{}");
3566 goto found2;
3567 end;
3568 insert_group:
3569 begin if saved(-2)=255 then print_esc("vadjust")
3570 else begin print_esc("insert"); print_int(saved(-2));
3571 end;
3572 goto found2;
3573 end;
3574 vcenter_group: begin s:="vcenter"; goto found1;
3575 end;
3576 semi_simple_group: begin incr(p); print_esc("begingroup"); goto found;
3577 end;
3578 math_shift_group:
3579 begin if m=mmode then print_char("$")
3580 else if nest[p].mode_field=mmode then
3581 begin print_cmd_chr(eq_no,saved(-2)); goto found;
3582 end;
3583 print_char("$"); goto found;
3584 end;
3585 math_left_group:
3586 begin if type(nest[p+1].eTeX_aux_field)=left_noad then print_esc("left")
3587 else print_esc("middle");
3588 goto found;
3589 end;
3590 end; {there are no other cases}
3591 @<Show the box context@>;
3592 found1: print_esc(s); @<Show the box packaging info@>;
3593 found2: print_char("{");
3594 found: print_char(")"); decr(cur_level);
3595 cur_group:=save_level(save_ptr); save_ptr:=save_index(save_ptr)
3596 end;
3597 done: save_ptr:=v; cur_level:=l; cur_group:=c;
3598 end;
3599
3600 @ @<Show the box packaging info@>=
3601 if saved(-2)<>0 then
3602 begin print_char(" ");
3603 if saved(-3)=exactly then print("to") else print("spread");
3604 print_scaled(saved(-2)); print("pt");
3605 end
3606
3607 @ @<Show the box context@>=
3608 i:=saved(-4);
3609 if i<>0 then
3610 if i<box_flag then
3611 begin if abs(nest[p].mode_field)=vmode then j:=hmove else j:=vmove;
3612 if i>0 then print_cmd_chr(j,0) else print_cmd_chr(j,1);
3613 print_scaled(abs(i)); print("pt");
3614 end
3615 else if i<ship_out_flag then
3616 begin if i>=global_box_flag then
3617 begin print_esc("global"); i:=i-(global_box_flag-box_flag);
3618 end;
3619 print_esc("setbox"); print_int(i-box_flag); print_char("=");
3620 end
3621 else print_cmd_chr(leader_ship,i-(leader_flag-a_leaders))
3622
3623 @ The |scan_general_text| procedure is much like |scan_toks(false,false)|,
3624 but will be invoked via |expand|, i.e., recursively.
3625 @^recursion@>
3626
3627 @<Declare \eTeX\ procedures for sc...@>=
3628 procedure@?scan_general_text; forward;@t\2@>
3629
3630 @ The token list (balanced text) created by |scan_general_text| begins
3631 at |link(temp_head)| and ends at |cur_val|. (If |cur_val=temp_head|,
3632 the list is empty.)
3633
3634 @<Declare \eTeX\ procedures for tok...@>=
3635 procedure scan_general_text;
3636 label found;
3637 var s:normal..absorbing; {to save |scanner_status|}
3638 @!w:pointer; {to save |warning_index|}
3639 @!d:pointer; {to save |def_ref|}
3640 @!p:pointer; {tail of the token list being built}
3641 @!q:pointer; {new node being added to the token list via |store_new_token|}
3642 @!unbalance:halfword; {number of unmatched left braces}
3643 begin s:=scanner_status; w:=warning_index; d:=def_ref;
3644 scanner_status:=absorbing; warning_index:=cur_cs;
3645 def_ref:=get_avail; token_ref_count(def_ref):=null; p:=def_ref;
3646 scan_left_brace; {remove the compulsory left brace}
3647 unbalance:=1;
3648 loop@+ begin get_token;
3649 if cur_tok<right_brace_limit then
3650 if cur_cmd<right_brace then incr(unbalance)
3651 else begin decr(unbalance);
3652 if unbalance=0 then goto found;
3653 end;
3654 store_new_token(cur_tok);
3655 end;
3656 found: q:=link(def_ref); free_avail(def_ref); {discard reference count}
3657 if q=null then cur_val:=temp_head @+ else cur_val:=p;
3658 link(temp_head):=q;
3659 scanner_status:=s; warning_index:=w; def_ref:=d;
3660 end;
3661
3662 @ The \.{\\showtokens} command displays a token list.
3663
3664 @d show_tokens=5 { \.{\\showtokens} , must be odd! }
3665
3666 @<Generate all \eTeX...@>=
3667 primitive("showtokens",xray,show_tokens);
3668 @!@:show_tokens_}{\.{\\showtokens} primitive@>
3669
3670 @ @<Cases of |xray| for |print_cmd_chr|@>=
3671 show_tokens:print_esc("showtokens");
3672
3673 @ The \.{\\unexpanded} primitive prevents expansion of tokens much as
3674 the result from \.{\\the} applied to a token variable. The
3675 \.{\\detokenize} primitive converts a token list into a list of
3676 character tokens much as if the token list were written to a file. We
3677 use the fact that the command modifiers for \.{\\unexpanded} and
3678 \.{\\detokenize} are odd whereas those for \.{\\the} and \.{\\showthe}
3679 are even.
3680
3681 @<Generate all \eTeX...@>=
3682 primitive("unexpanded",the,1);@/
3683 @!@:unexpanded_}{\.{\\unexpanded} primitive@>
3684 primitive("detokenize",the,show_tokens);@/
3685 @!@:detokenize_}{\.{\\detokenize} primitive@>
3686
3687 @ @<Cases of |the| for |print_cmd_chr|@>=
3688 else if chr_code=1 then print_esc("unexpanded")
3689 else print_esc("detokenize")
3690
3691 @ @<Handle \.{\\unexpanded} or \.{\\detokenize} and |return|@>=
3692 if odd(cur_chr) then
3693 begin c:=cur_chr; scan_general_text;
3694 if c=1 then the_toks:=cur_val
3695 else begin old_setting:=selector; selector:=new_string; b:=pool_ptr;
3696 p:=get_avail; link(p):=link(temp_head);
3697 token_show(p); flush_list(p);
3698 selector:=old_setting; the_toks:=str_toks(b);
3699 end;
3700 return;
3701 end
3702
3703 @ The \.{\\showifs} command displays all currently active conditionals.
3704
3705 @d show_ifs=6 { \.{\\showifs} }
3706
3707 @<Generate all \eTeX...@>=
3708 primitive("showifs",xray,show_ifs);
3709 @!@:show_ifs_}{\.{\\showifs} primitive@>
3710
3711 @ @<Cases of |xray| for |print_cmd_chr|@>=
3712 show_ifs:print_esc("showifs");
3713
3714 @
3715 @d print_if_line(#)==if #<>0 then
3716 begin print(" entered on line "); print_int(#);
3717 end
3718
3719 @<Cases for |show_whatever|@>=
3720 show_ifs: begin begin_diagnostic; print_nl(""); print_ln;
3721 if cond_ptr=null then
3722 begin print_nl("### "); print("no active conditionals");
3723 end
3724 else begin p:=cond_ptr; n:=0;
3725 repeat incr(n); p:=link(p);@+until p=null;
3726 p:=cond_ptr; t:=cur_if; l:=if_line; m:=if_limit;
3727 repeat print_nl("### level "); print_int(n); print(": ");
3728 print_cmd_chr(if_test,t);
3729 if m=fi_code then print_esc("else");
3730 print_if_line(l);
3731 decr(n); t:=subtype(p); l:=if_line_field(p); m:=type(p); p:=link(p);
3732 until p=null;
3733 end;
3734 end;
3735
3736 @ The \.{\\interactionmode} primitive allows to query and set the
3737 interaction mode.
3738
3739 @<Generate all \eTeX...@>=
3740 primitive("interactionmode",set_page_int,2);
3741 @!@:interaction_mode_}{\.{\\interactionmode} primitive@>
3742
3743 @ @<Cases of |set_page_int| for |print_cmd_chr|@>=
3744 else if chr_code=2 then print_esc("interactionmode")
3745
3746 @ @<Cases for `Fetch the |dead_cycles| or the |insert_penalties|'@>=
3747 else if m=2 then cur_val:=interaction
3748
3749 @ @<Declare \eTeX\ procedures for use...@>=
3750 procedure@?new_interaction; forward;@t\2@>
3751
3752 @ @<Cases for |alter_integer|@>=
3753 else if c=2 then
3754 begin if (cur_val<batch_mode)or(cur_val>error_stop_mode) then
3755 begin print_err("Bad interaction mode");
3756 @.Bad interaction mode@>
3757 help2("Modes are 0=batch, 1=nonstop, 2=scroll, and")@/
3758 ("3=errorstop. Proceed, and I'll ignore this case.");
3759 int_error(cur_val);
3760 end
3761 else begin cur_chr:=cur_val; new_interaction;
3762 end;
3763 end
3764
3765 @ The |middle| feature of \eTeX\ allows one ore several \.{\\middle}
3766 delimiters to appear between \.{\\left} and \.{\\right}.
3767
3768 @<Generate all \eTeX...@>=
3769 primitive("middle",left_right,middle_noad);
3770 @!@:middle_}{\.{\\middle} primitive@>
3771
3772 @ @<Cases of |left_right| for |print_cmd_chr|@>=
3773 else if chr_code=middle_noad then print_esc("middle")
3774
3775 @ In constructions such as
3776 $$\vbox{\halign{\.{#}\hfil\cr
3777 {}\\hbox to \\hsize\{\cr
3778 \hskip 25pt \\hskip 0pt plus 0.0001fil\cr
3779 \hskip 25pt ...\cr
3780 \hskip 25pt \\hfil\\penalty-200\\hfilneg\cr
3781 \hskip 25pt ...\}\cr}}$$
3782 the stretch components of \.{\\hfil} and \.{\\hfilneg} compensate; they may,
3783 however, get modified in order to prevent arithmetic overflow during
3784 |hlist_out| when each of them is multiplied by a large |glue_set| value.
3785
3786 Since this ``glue rounding'' depends on state variables |cur_g| and
3787 |cur_glue| and \TeXXeT\ is supposed to emulate the behaviour of \TeXeT\
3788 (plus a suitable postprocessor) as close as possible the glue rounding
3789 cannot be postponed until (segments of) an hlist has been reversed.
3790
3791 The code below is invoked after the effective width, |rule_wd|, of a glue
3792 node has been computed. The glue node is either converted into a kern node
3793 or, for leaders, the glue specification is replaced by an equivalent rigid
3794 one; the subtype of the glue node remains unchanged.
3795
3796 @<Handle a glue node for mixed...@>=
3797 if (((g_sign=stretching) and (stretch_order(g)=g_order)) or
3798 ((g_sign=shrinking) and (shrink_order(g)=g_order))) then
3799 begin fast_delete_glue_ref(g);
3800 if subtype(p)<a_leaders then
3801 begin type(p):=kern_node; width(p):=rule_wd;
3802 end
3803 else begin g:=get_node(glue_spec_size);@/
3804 stretch_order(g):=filll+1; shrink_order(g):=filll+1; {will never match}
3805 width(g):=rule_wd; stretch(g):=0; shrink(g):=0; glue_ptr(p):=g;
3806 end;
3807 end
3808
3809 @ The optional |TeXXeT| feature of \eTeX\ contains the code for mixed
3810 left-to-right and right-to-left typesetting. This code is inspired by
3811 but different from \TeXeT\ as presented by Donald~E. Knuth and Pierre
3812 MacKay in {\sl TUGboat\/} {\bf 8}, 14--25, 1987.
3813 @^Knuth, Donald Ervin@>
3814 @^MacKay, Pierre@>
3815
3816 In order to avoid confusion with \TeXeT\ the present implementation of
3817 mixed direction typesetting is called \TeXXeT. It differs from \TeXeT\
3818 in several important aspects: (1)~Right-to-left text is reversed
3819 explicitly by the |ship_out| routine and is written to a normal \.{DVI}
3820 file without any |begin_reflect| or |end_reflect| commands; (2)~a
3821 |math_node| is (ab)used instead of a |whatsit_node| to record the
3822 \.{\\beginL}, \.{\\endL}, \.{\\beginR}, and \.{\\endR} text direction
3823 primitives in order to keep the influence on the line breaking algorithm
3824 for pure left-to-right text as small as possible; (3)~right-to-left text
3825 interrupted by a displayed equation is automatically resumed after that
3826 equation; and (4)~the |valign| command code with a non-zero command
3827 modifier is (ab)used for the text direction primitives.
3828
3829 Nevertheless there is a subtle difference between \TeX\ and \TeXXeT\
3830 that may influence the line breaking algorithm for pure left-to-right
3831 text. When a paragraph containing math mode material is broken into
3832 lines \TeX\ may generate lines where math mode material is not enclosed
3833 by properly nested \.{\\mathon} and \.{\\mathoff} nodes. Unboxing such
3834 lines as part of a new paragraph may have the effect that hyphenation is
3835 attempted for `words' originating from math mode or that hyphenation is
3836 inhibited for words originating from horizontal mode.
3837
3838 In \TeXXeT\ additional \.{\\beginM}, resp.\ \.{\\endM} math nodes are
3839 supplied at the start, resp.\ end of lines such that math mode material
3840 inside a horizontal list always starts with either \.{\\mathon} or
3841 \.{\\beginM} and ends with \.{\\mathoff} or \.{\\endM}. These
3842 additional nodes are transparent to operations such as \.{\\unskip},
3843 \.{\\lastpenalty}, or \.{\\lastbox} but they do have the effect that
3844 hyphenation is never attempted for `words' originating from math mode
3845 and is never inhibited for words originating from horizontal mode.
3846
3847 @d TeXXeT_state==eTeX_state(TeXXeT_code)
3848 @d TeXXeT_en==(TeXXeT_state>0) {is \TeXXeT\ enabled?}
3849
3850 @<Cases for |print_param|@>=
3851 eTeX_state_code+TeXXeT_code:print_esc("TeXXeTstate");
3852
3853 @ @<Generate all \eTeX...@>=
3854 primitive("TeXXeTstate",assign_int,eTeX_state_base+TeXXeT_code);
3855 @!@:TeXXeT_state_}{\.{\\TeXXeT_state} primitive@>
3856 primitive("beginL",valign,begin_L_code);
3857 @!@:beginL_}{\.{\\beginL} primitive@>
3858 primitive("endL",valign,end_L_code);
3859 @!@:endL_}{\.{\\endL} primitive@>
3860 primitive("beginR",valign,begin_R_code);
3861 @!@:beginR_}{\.{\\beginR} primitive@>
3862 primitive("endR",valign,end_R_code);
3863 @!@:endR_}{\.{\\endR} primitive@>
3864
3865 @ @<Cases of |valign| for |print_cmd_chr|@>=
3866 else case chr_code of
3867 begin_L_code: print_esc("beginL");
3868 end_L_code: print_esc("endL");
3869 begin_R_code: print_esc("beginR");
3870 othercases print_esc("endR")
3871 endcases
3872
3873 @ @<Cases of |main_control| for |hmode+valign|@>=
3874 if cur_chr>0 then
3875 begin if eTeX_enabled(TeXXeT_en,cur_cmd,cur_chr) then
3876 @.Improper \\beginL@>
3877 @.Improper \\endL@>
3878 @.Improper \\beginR@>
3879 @.Improper \\endR@>
3880 tail_append(new_math(0,cur_chr));
3881 end
3882 else
3883
3884 @ An hbox with subtype dlist will never be reversed, even when embedded
3885 in right-to-left text.
3886
3887 @<Display if this box is never to be reversed@>=
3888 if (type(p)=hlist_node)and(box_lr(p)=dlist) then print(", display")
3889
3890 @ A number of routines are based on a stack of one-word nodes whose
3891 |info| fields contain |end_M_code|, |end_L_code|, or |end_R_code|. The
3892 top of the stack is pointed to by |LR_ptr|.
3893
3894 When the stack manipulation macros of this section are used below,
3895 variable |LR_ptr| might be the global variable declared here for |hpack|
3896 and |ship_out|, or might be local to |post_line_break|.
3897
3898 @d put_LR(#)==begin temp_ptr:=get_avail; info(temp_ptr):=#;
3899 link(temp_ptr):=LR_ptr; LR_ptr:=temp_ptr;
3900 end
3901 @#
3902 @d push_LR(#)==put_LR(end_LR_type(#))
3903 @#
3904 @d pop_LR==begin temp_ptr:=LR_ptr; LR_ptr:=link(temp_ptr);
3905 free_avail(temp_ptr);
3906 end
3907
3908 @<Glob...@>=
3909 @!LR_ptr:pointer; {stack of LR codes for |hpack|, |ship_out|, and |init_math|}
3910 @!LR_problems:integer; {counts missing begins and ends}
3911 @!cur_dir:small_number; {current text direction}
3912
3913 @ @<Set init...@>=
3914 LR_ptr:=null; LR_problems:=0; cur_dir:=left_to_right;
3915
3916 @ @<Insert LR nodes at the beg...@>=
3917 begin q:=link(temp_head);
3918 if LR_ptr<>null then
3919 begin temp_ptr:=LR_ptr; r:=q;
3920 repeat s:=new_math(0,begin_LR_type(info(temp_ptr))); link(s):=r; r:=s;
3921 temp_ptr:=link(temp_ptr);
3922 until temp_ptr=null;
3923 link(temp_head):=r;
3924 end;
3925 while q<>cur_break(cur_p) do
3926 begin if not is_char_node(q) then
3927 if type(q)=math_node then @<Adjust \(t)the LR stack for the |p...@>;
3928 q:=link(q);
3929 end;
3930 end
3931
3932 @ @<Adjust \(t)the LR stack for the |p...@>=
3933 if end_LR(q) then
3934 begin if LR_ptr<>null then if info(LR_ptr)=end_LR_type(q) then pop_LR;
3935 end
3936 else push_LR(q)
3937
3938 @ We use the fact that |q| now points to the node with \.{\\rightskip} glue.
3939
3940 @<Insert LR nodes at the end...@>=
3941 if LR_ptr<>null then
3942 begin s:=temp_head; r:=link(s);
3943 while r<>q do
3944 begin s:=r; r:=link(s);
3945 end;
3946 r:=LR_ptr;
3947 while r<>null do
3948 begin temp_ptr:=new_math(0,info(r));
3949 link(s):=temp_ptr; s:=temp_ptr; r:=link(r);
3950 end;
3951 link(s):=q;
3952 end
3953
3954 @ @<Initialize the LR stack@>=
3955 put_LR(before) {this will never match}
3956
3957 @ @<Adjust \(t)the LR stack for the |hp...@>=
3958 if end_LR(p) then
3959 if info(LR_ptr)=end_LR_type(p) then pop_LR
3960 else begin incr(LR_problems); type(p):=kern_node; subtype(p):=explicit;
3961 end
3962 else push_LR(p)
3963
3964 @ @<Check for LR anomalies at the end of |hp...@>=
3965 begin if info(LR_ptr)<>before then
3966 begin while link(q)<>null do q:=link(q);
3967 repeat temp_ptr:=q; q:=new_math(0,info(LR_ptr)); link(temp_ptr):=q;
3968 LR_problems:=LR_problems+10000; pop_LR;
3969 until info(LR_ptr)=before;
3970 end;
3971 if LR_problems>0 then
3972 begin @<Report LR problems@>; goto common_ending;
3973 end;
3974 pop_LR;
3975 if LR_ptr<>null then confusion("LR1");
3976 @:this can't happen LR1}{\quad LR1@>
3977 end
3978
3979 @ @<Report LR problems@>=
3980 begin print_ln; print_nl("\endL or \endR problem (");@/
3981 print_int(LR_problems div 10000); print(" missing, ");@/
3982 print_int(LR_problems mod 10000); print(" extra");@/
3983 LR_problems:=0;
3984 end
3985
3986 @ @<Initialize |hlist_out| for mixed...@>=
3987 if eTeX_ex then
3988 begin @<Initialize the LR stack@>;
3989 if box_lr(this_box)=dlist then
3990 if cur_dir=right_to_left then
3991 begin cur_dir:=left_to_right; cur_h:=cur_h-width(this_box);
3992 end
3993 else set_box_lr(this_box)(0);
3994 if (cur_dir=right_to_left)and(box_lr(this_box)<>reversed) then
3995 @<Reverse the complete hlist and set the subtype to |reversed|@>;
3996 end
3997
3998 @ @<Finish |hlist_out| for mixed...@>=
3999 if eTeX_ex then
4000 begin @<Check for LR anomalies at the end of |hlist_out|@>;
4001 if box_lr(this_box)=dlist then cur_dir:=right_to_left;
4002 end
4003
4004 @ @<Handle a math node in |hlist_out|@>=
4005 begin if eTeX_ex then
4006 @<Adjust \(t)the LR stack for the |hlist_out| routine; if necessary
4007 reverse an hlist segment and |goto reswitch|@>;
4008 cur_h:=cur_h+width(p);
4009 end
4010
4011 @ Breaking a paragraph into lines while \TeXXeT\ is disabled may result
4012 in lines whith unpaired math nodes. Such hlists are silently accepted
4013 in the absence of text direction directives.
4014
4015 @d LR_dir(#)==(subtype(#) div R_code) {text direction of a `math node'}
4016
4017 @<Adjust \(t)the LR stack for the |hl...@>=
4018 begin if end_LR(p) then
4019 if info(LR_ptr)=end_LR_type(p) then pop_LR
4020 else begin if subtype(p)>L_code then incr(LR_problems);
4021 end
4022 else begin push_LR(p);
4023 if LR_dir(p)<>cur_dir then
4024 @<Reverse an hlist segment and |goto reswitch|@>;
4025 end;
4026 type(p):=kern_node;
4027 end
4028
4029 @ @<Check for LR anomalies at the end of |hl...@>=
4030 begin while info(LR_ptr)<>before do
4031 begin if info(LR_ptr)>L_code then LR_problems:=LR_problems+10000;
4032 pop_LR;
4033 end;
4034 pop_LR;
4035 end
4036
4037 @ @d edge_node=style_node {a |style_node| does not occur in hlists}
4038 @d edge_node_size=style_node_size {number of words in an edge node}
4039 @d edge_dist(#)==depth(#) {new |left_edge| position relative to |cur_h|
4040 (after |width| has been taken into account)}
4041
4042 @<Declare procedures needed in |hlist_out|, |vlist_out|@>=
4043 function new_edge(@!s:small_number;@!w:scaled):pointer;
4044 {create an edge node}
4045 var p:pointer; {the new node}
4046 begin p:=get_node(edge_node_size); type(p):=edge_node; subtype(p):=s;
4047 width(p):=w; edge_dist(p):=0; {the |edge_dist| field will be set later}
4048 new_edge:=p;
4049 end;
4050
4051 @ @<Cases of |hlist_out| that arise...@>=
4052 edge_node: begin cur_h:=cur_h+width(p);
4053 left_edge:=cur_h+edge_dist(p); cur_dir:=subtype(p);
4054 end;
4055
4056 @ We detach the hlist, start a new one consisting of just one kern node,
4057 append the reversed list, and set the width of the kern node.
4058
4059 @<Reverse the complete hlist...@>=
4060 begin save_h:=cur_h; temp_ptr:=p; p:=new_kern(0); link(prev_p):=p;
4061 cur_h:=0; link(p):=reverse(this_box,null,cur_g,cur_glue); width(p):=-cur_h;
4062 cur_h:=save_h; set_box_lr(this_box)(reversed);
4063 end
4064
4065 @ We detach the remainder of the hlist, replace the math node by
4066 an edge node, and append the reversed hlist segment to it; the tail of
4067 the reversed segment is another edge node and the remainder of the
4068 original list is attached to it.
4069
4070 @<Reverse an hlist segment...@>=
4071 begin save_h:=cur_h; temp_ptr:=link(p); rule_wd:=width(p);
4072 free_node(p,small_node_size);
4073 cur_dir:=reflected; p:=new_edge(cur_dir,rule_wd); link(prev_p):=p;
4074 cur_h:=cur_h-left_edge+rule_wd;
4075 link(p):=reverse(this_box,new_edge(reflected,0),cur_g,cur_glue);
4076 edge_dist(p):=cur_h; cur_dir:=reflected; cur_h:=save_h;
4077 goto reswitch;
4078 end
4079
4080 @ OLD VERSION.
4081 The |reverse| function defined here is responsible to reverse the
4082 nodes of an hlist (segment). The first parameter |this_box| is the enclosing
4083 hlist node, the second parameter |t| is to become the tail of the reversed
4084 list, and the global variable |temp_ptr| is the head of the list to be
4085 reversed. Finally |cur_g| and |cur_glue| are the current glue rounding state
4086 variables, to be updated by this function. We remove nodes from the original
4087 list and add them to the head of the new one.
4088
4089 @<Declare procedures needed in |hlist_out|, |vlist_out|@>=
4090 function reverse(@!this_box,@!t:pointer; var cur_g:scaled;
4091 var cur_glue:real):pointer;
4092 label reswitch,next_p,done;
4093 var l:pointer; {the new list}
4094 @!p:pointer; {the current node}
4095 @!q:pointer; {the next node}
4096 @!g_order: glue_ord; {applicable order of infinity for glue}
4097 @!g_sign: normal..shrinking; {selects type of glue}
4098 @!glue_temp:real; {glue value before rounding}
4099 @!m,@!n:halfword; {count of unmatched math nodes}
4100 begin g_order:=glue_order(this_box); g_sign:=glue_sign(this_box);
4101 l:=t; p:=temp_ptr; m:=min_halfword; n:=min_halfword;
4102 loop@+ begin while p<>null do
4103 @<Move node |p| to the new list and go to the next node;
4104 or |goto done| if the end of the reflected segment has been reached@>;
4105 if (t=null)and(m=min_halfword)and(n=min_halfword) then goto done;
4106 p:=new_math(0,info(LR_ptr)); LR_problems:=LR_problems+10000;
4107 {manufacture one missing math node}
4108 end;
4109 done:reverse:=l;
4110 end;
4111
4112 @ NEW VERSION.
4113 The |reverse| function defined here is responsible to reverse (parts of)
4114 the nodes of an hlist. The first parameter |this_box| is the enclosing
4115 hlist node, the second parameter |t| is to become the tail of the reversed
4116 list, and the global variable |temp_ptr| is the head of the list to be
4117 reversed. Finally |cur_g| and |cur_glue| are the current glue rounding
4118 state variables, to be updated by this function.
4119
4120 @<Declare procedures needed in |hlist_out|, |vlist_out|@>=
4121 @{
4122 @t\4@>@<Declare subprocedures for |reverse|@>@;
4123 function reverse(@!this_box,@!t:pointer; var cur_g:scaled;
4124 var cur_glue:real):pointer;
4125 label reswitch,next_p,done;
4126 var l:pointer; {the new list}
4127 @!p:pointer; {the current node}
4128 @!q:pointer; {the next node}
4129 @!g_order: glue_ord; {applicable order of infinity for glue}
4130 @!g_sign: normal..shrinking; {selects type of glue}
4131 @!glue_temp:real; {glue value before rounding}
4132 @!m,@!n:halfword; {count of unmatched math nodes}
4133 begin g_order:=glue_order(this_box); g_sign:=glue_sign(this_box);
4134 @<Build a list of segments and determine their widths@>;
4135 l:=t; p:=temp_ptr; m:=min_halfword; n:=min_halfword;
4136 loop@+ begin while p<>null do
4137 @<Move node |p| to the new list and go to the next node;
4138 or |goto done| if the end of the reflected segment has been reached@>;
4139 if (t=null)and(m=min_halfword)and(n=min_halfword) then goto done;
4140 p:=new_math(0,info(LR_ptr)); LR_problems:=LR_problems+10000;
4141 {manufacture one missing math node}
4142 end;
4143 done:reverse:=l;
4144 end;
4145 @}
4146
4147 @ We cannot simply remove nodes from the original list and add them to the
4148 head of the new one; this might reverse the order of whatsit nodes such
4149 that, e.g., a |write_node| for a stream appears before the |open_node|
4150 and\slash or after the |close_node| for that stream.
4151
4152 All whatsit nodes as well as hlist and vlist nodes containing such nodes
4153 must not be permuted. A sequence of hlist and vlist nodes not containing
4154 whatsit nodes as well as char, ligature, rule, kern, and glue nodes together
4155 with math nodes not changing the text direction can be explicitly reversed.
4156 Embedded sections of left-to-right text are treated as a unit and all
4157 remaining nodes are irrelevant and can be ignored.
4158
4159 In a first step we determine the width of various segments of the hlist to
4160 be reversed: (1)~embedded left-to-right text, (2)~sequences of permutable or
4161 irrelevant nodes, (3)~sequences of whatsit or irrelevant nodes, and
4162 (4)~individual hlist and vlist nodes containing whatsit nodes.
4163
4164 @d segment_node=style_node
4165 @d segment_node_size=style_node_size {number of words in a segment node}
4166 @d segment_first(#)==info(#+2) {first node of the segment}
4167 @d segment_last(#)==link(#+2) {last node of the segment}
4168
4169 @<Declare subprocedures for |reverse|@>=
4170 function new_segment(@!s:small_number;@!f:pointer):pointer;
4171 {create a segment node}
4172 var p:pointer; {the new node}
4173 begin p:=get_node(segment_node_size); type(p):=segment_node; subtype(p):=s;
4174 width(p):=0; {the |width| field will be set later}
4175 segment_first(p):=f; segment_last(p):=f;
4176 new_segment:=p;
4177 end;
4178
4179 @ @<Build a list of segments and determine their widths@>=
4180 begin
4181 end
4182
4183 @ Here is a recursive subroutine that determines if the hlist or vlist
4184 node~|p| contains whatsit nodes.
4185
4186 @<Declare subprocedures for |reverse|@>=
4187 function has_whatsit(@!p:pointer):boolean;
4188 label exit;
4189 begin p:=list_ptr(p); has_whatsit:=true;
4190 while p<>null do
4191 begin if not is_char_node(p) then
4192 case type(p) of
4193 hlist_node, vlist_node: if has_whatsit(p) then goto exit;
4194 whatsit_node: goto exit;
4195 othercases do_nothing
4196 endcases;@/
4197 p:=link(p);
4198 end;
4199 has_whatsit:=false;
4200 exit: end;
4201
4202 @ @<Move node |p| to the new list...@>=
4203 reswitch: if is_char_node(p) then
4204 repeat f:=font(p); c:=character(p);
4205 cur_h:=cur_h+char_width(f)(char_info(f)(c));
4206 q:=link(p); link(p):=l; l:=p; p:=q;
4207 until not is_char_node(p)
4208 else @<Move the non-|char_node| |p| to the new list@>
4209
4210 @ @<Move the non-|char_node| |p| to the new list@>=
4211 begin q:=link(p);
4212 case type(p) of
4213 hlist_node,vlist_node,rule_node,kern_node: rule_wd:=width(p);
4214 @t\4@>@<Cases of |reverse| that need special treatment@>@;
4215 edge_node: confusion("LR2");
4216 @:this can't happen LR2}{\quad LR2@>
4217 othercases goto next_p
4218 endcases;@/
4219 cur_h:=cur_h+rule_wd;
4220 next_p: link(p):=l;
4221 if type(p)=kern_node then if (rule_wd=0)or(l=null) then
4222 begin free_node(p,small_node_size); p:=l;
4223 end;
4224 l:=p; p:=q;
4225 end
4226
4227 @ Here we compute the effective width of a glue node as in |hlist_out|.
4228
4229 @<Cases of |reverse|...@>=
4230 glue_node: begin round_glue;
4231 @<Handle a glue node for mixed...@>;
4232 end;
4233
4234 @ A ligature node is replaced by a char node.
4235
4236 @<Cases of |reverse|...@>=
4237 ligature_node: begin flush_node_list(lig_ptr(p));
4238 temp_ptr:=p; p:=get_avail; mem[p]:=mem[lig_char(temp_ptr)]; link(p):=q;
4239 free_node(temp_ptr,small_node_size); goto reswitch;
4240 end;
4241
4242 @ Math nodes in an inner reflected segment are modified, those at the
4243 outer level are changed into kern nodes.
4244
4245 @<Cases of |reverse|...@>=
4246 math_node: begin rule_wd:=width(p);
4247 if end_LR(p) then
4248 if info(LR_ptr)<>end_LR_type(p) then
4249 begin type(p):=kern_node; incr(LR_problems);
4250 end
4251 else begin pop_LR;
4252 if n>min_halfword then
4253 begin decr(n); decr(subtype(p)); {change |after| into |before|}
4254 end
4255 else begin type(p):=kern_node;
4256 if m>min_halfword then decr(m)
4257 else @<Finish the reversed hlist segment and |goto done|@>;
4258 end;
4259 end
4260 else begin push_LR(p);
4261 if (n>min_halfword)or(LR_dir(p)<>cur_dir) then
4262 begin incr(n); incr(subtype(p)); {change |before| into |after|}
4263 end
4264 else begin type(p):=kern_node; incr(m);
4265 end;
4266 end;
4267 end;
4268
4269 @ Finally we have found the end of the hlist segment to be reversed; the
4270 final math node is released and the remaining list attached to the
4271 edge node terminating the reversed segment.
4272
4273 @<Finish the reversed...@>=
4274 begin free_node(p,small_node_size);
4275 link(t):=q; width(t):=rule_wd; edge_dist(t):=-cur_h-rule_wd; goto done;
4276 end
4277
4278 @ @<Check for LR anomalies at the end of |s...@>=
4279 begin if LR_problems>0 then
4280 begin @<Report LR problems@>; print_char(")"); print_ln;
4281 end;
4282 if (LR_ptr<>null)or(cur_dir<>left_to_right) then confusion("LR3");
4283 @:this can't happen LR3}{\quad LR3@>
4284 end
4285
4286 @ Some special actions are required for displayed equation in paragraphs
4287 with mixed direction texts. First of all we have to set the text
4288 direction preceding the display.
4289
4290 @<Set the value of |x| to the text direction before the display@>=
4291 if LR_save=null then x:=0
4292 else if info(LR_save)>=R_code then x:=-1@+else x:=1
4293
4294 @ @<Prepare for display after an empty...@>=
4295 begin pop_nest; @<Set the value of |x|...@>;
4296 end
4297
4298 @ When calculating the natural width, |w|, of the final line preceding
4299 the display, we may have to copy all or part of its hlist. We copy,
4300 however, only those parts of the original list that are relevant for the
4301 computation of |pre_display_size|.
4302 @^data structure assumptions@>
4303
4304 @<Declare subprocedures for |init_math|@>=
4305 procedure just_copy(@!p,@!h,@!t:pointer);
4306 label found,not_found;
4307 var @!r:pointer; {current node being fabricated for new list}
4308 @!words:0..5; {number of words remaining to be copied}
4309 begin while p<>null do
4310 begin words:=1; {this setting occurs in more branches than any other}
4311 if is_char_node(p) then r:=get_avail
4312 else case type(p) of
4313 hlist_node,vlist_node: begin r:=get_node(box_node_size);
4314 mem[r+6]:=mem[p+6]; mem[r+5]:=mem[p+5]; {copy the last two words}
4315 words:=5; list_ptr(r):=null; {this affects |mem[r+5]|}
4316 end;
4317 rule_node: begin r:=get_node(rule_node_size); words:=rule_node_size;
4318 end;
4319 ligature_node: begin r:=get_avail; {only |font| and |character| are needed}
4320 mem[r]:=mem[lig_char(p)]; goto found;
4321 end;
4322 kern_node,math_node: begin r:=get_node(small_node_size);
4323 words:=small_node_size;
4324 end;
4325 glue_node: begin r:=get_node(small_node_size); add_glue_ref(glue_ptr(p));
4326 glue_ptr(r):=glue_ptr(p); leader_ptr(r):=null;
4327 end;
4328 whatsit_node:@<Make a partial copy of the whatsit...@>;
4329 othercases goto not_found
4330 endcases;
4331 while words>0 do
4332 begin decr(words); mem[r+words]:=mem[p+words];
4333 end;
4334 found: link(h):=r; h:=r;
4335 not_found: p:=link(p);
4336 end;
4337 link(h):=t;
4338 end;
4339
4340 @ When the final line ends with R-text, the value |w| refers to the line
4341 reflected with respect to the left edge of the enclosing vertical list.
4342
4343 @<Prepare for display after a non-empty...@>=
4344 if eTeX_ex then @<Let |j| be the prototype box for the display@>;
4345 v:=shift_amount(just_box);
4346 @<Set the value of |x|...@>;
4347 if x>=0 then
4348 begin p:=list_ptr(just_box); link(temp_head):=null;
4349 end
4350 else begin v:=-v-width(just_box);
4351 p:=new_math(0,begin_L_code); link(temp_head):=p;
4352 just_copy(list_ptr(just_box),p,new_math(0,end_L_code));
4353 cur_dir:=right_to_left;
4354 end;
4355 v:=v+2*quad(cur_font);
4356 if TeXXeT_en then @<Initialize the LR stack@>
4357
4358 @ @<Finish the natural width computation@>=
4359 if TeXXeT_en then
4360 begin while LR_ptr<>null do pop_LR;
4361 if LR_problems<>0 then
4362 begin w:=max_dimen; LR_problems:=0;
4363 end;
4364 end;
4365 cur_dir:=left_to_right; flush_node_list(link(temp_head))
4366
4367 @ In the presence of text direction directives we assume that any LR
4368 problems have been fixed by the |hpack| routine. If the final line
4369 contains, however, text direction directives while \TeXXeT\ is disabled,
4370 then we set |w:=max_dimen|.
4371
4372 @<Cases of `Let |d| be the natural...@>=
4373 math_node: begin d:=width(p);
4374 if TeXXeT_en then @<Adjust \(t)the LR stack for the |init_math| routine@>
4375 else if subtype(p)>=L_code then
4376 begin w:=max_dimen; goto done;
4377 end;
4378 end;
4379 edge_node: begin d:=width(p); cur_dir:=subtype(p);
4380 end;
4381
4382 @ @<Adjust \(t)the LR stack for the |i...@>=
4383 if end_LR(p) then
4384 begin if info(LR_ptr)=end_LR_type(p) then pop_LR
4385 else if subtype(p)>L_code then
4386 begin w:=max_dimen; goto done;
4387 end
4388 end
4389 else begin push_LR(p);
4390 if LR_dir(p)<>cur_dir then
4391 begin just_reverse(p); p:=temp_head;
4392 end;
4393 end
4394
4395 @ @<Declare subprocedures for |init_math|@>=
4396 procedure just_reverse(@!p:pointer);
4397 label found,done;
4398 var l:pointer; {the new list}
4399 @!t:pointer; {tail of reversed segment}
4400 @!q:pointer; {the next node}
4401 @!m,@!n:halfword; {count of unmatched math nodes}
4402 begin m:=min_halfword; n:=min_halfword;
4403 if link(temp_head)=null then
4404 begin just_copy(link(p),temp_head,null); q:=link(temp_head);
4405 end
4406 else begin q:=link(p); link(p):=null; flush_node_list(link(temp_head));
4407 end;
4408 t:=new_edge(cur_dir,0); l:=t; cur_dir:=reflected;
4409 while q<>null do
4410 if is_char_node(q) then
4411 repeat p:=q; q:=link(p); link(p):=l; l:=p;
4412 until not is_char_node(q)
4413 else begin p:=q; q:=link(p);
4414 if type(p)=math_node then
4415 @<Adjust \(t)the LR stack for the |just_reverse| routine@>;
4416 link(p):=l; l:=p;
4417 end;
4418 goto done;
4419 found:width(t):=width(p); link(t):=q; free_node(p,small_node_size);
4420 done:link(temp_head):=l;
4421 end;
4422
4423 @ @<Adjust \(t)the LR stack for the |j...@>=
4424 if end_LR(p) then
4425 if info(LR_ptr)<>end_LR_type(p) then
4426 begin type(p):=kern_node; incr(LR_problems);
4427 end
4428 else begin pop_LR;
4429 if n>min_halfword then
4430 begin decr(n); decr(subtype(p)); {change |after| into |before|}
4431 end
4432 else begin if m>min_halfword then decr(m)@+else goto found;
4433 type(p):=kern_node;
4434 end;
4435 end
4436 else begin push_LR(p);
4437 if (n>min_halfword)or(LR_dir(p)<>cur_dir) then
4438 begin incr(n); incr(subtype(p)); {change |before| into |after|}
4439 end
4440 else begin type(p):=kern_node; incr(m);
4441 end;
4442 end
4443
4444 @ The prototype box is an hlist node with the width, glue set, and shift
4445 amount of |just_box|, i.e., the last line preceding the display. Its
4446 hlist reflects the current \.{\\leftskip} and \.{\\rightskip}.
4447
4448 @<Let |j| be the prototype box for the display@>=
4449 begin if right_skip=zero_glue then j:=new_kern(0)
4450 else j:=new_param_glue(right_skip_code);
4451 if left_skip=zero_glue then p:=new_kern(0)
4452 else p:=new_param_glue(left_skip_code);
4453 link(p):=j; j:=new_null_box; width(j):=width(just_box);
4454 shift_amount(j):=shift_amount(just_box); list_ptr(j):=p;
4455 glue_order(j):=glue_order(just_box); glue_sign(j):=glue_sign(just_box);
4456 glue_set(j):=glue_set(just_box);
4457 end
4458
4459 @ At the end of a displayed equation we retrieve the prototype box.
4460
4461 @<Local variables for finishing...@>=
4462 @!j:pointer; {prototype box}
4463
4464 @ @<Retrieve the prototype box@>=
4465 if mode=mmode then j:=LR_box
4466
4467 @ @<Flush the prototype box@>=
4468 flush_node_list(j)
4469
4470 @ The |app_display| procedure used to append the displayed equation
4471 and\slash or equation number to the current vertical list has three
4472 parameters: the prototype box, the hbox to be appended, and the
4473 displacement of the hbox in the display line.
4474
4475 @<Declare subprocedures for |after_math|@>=
4476 procedure app_display(@!j,@!b:pointer;@!d:scaled);
4477 var z:scaled; {width of the line}
4478 @!s:scaled; {move the line right this much}
4479 @!e:scaled; {distance from right edge of box to end of line}
4480 @!x:integer; {|pre_display_direction|}
4481 @!p,@!q,@!r,@!t,@!u:pointer; {for list manipulation}
4482 begin s:=display_indent; x:=pre_display_direction;
4483 if x=0 then shift_amount(b):=s+d
4484 else begin z:=display_width; p:=b;
4485 @<Set up the hlist for the display line@>;
4486 @<Package the display line@>;
4487 end;
4488 append_to_vlist(b);
4489 end;
4490
4491 @ Here we construct the hlist for the display, starting with node |p|
4492 and ending with node |q|. We also set |d| and |e| to the amount of
4493 kerning to be added before and after the hlist (adjusted for the
4494 prototype box).
4495
4496 @<Set up the hlist for the display line@>=
4497 if x>0 then e:=z-d-width(p)
4498 else begin e:=d; d:=z-e-width(p);
4499 end;
4500 if j<>null then
4501 begin b:=copy_node_list(j); height(b):=height(p); depth(b):=depth(p);
4502 s:=s-shift_amount(b); d:=d+s; e:=e+width(b)-z-s;
4503 end;
4504 if box_lr(p)=dlist then q:=p {display or equation number}
4505 else begin {display and equation number}
4506 r:=list_ptr(p); free_node(p,box_node_size);
4507 if r=null then confusion("LR4");
4508 if x>0 then
4509 begin p:=r;
4510 repeat q:=r; r:=link(r); {find tail of list}
4511 until r=null;
4512 end
4513 else begin p:=null; q:=r;
4514 repeat t:=link(r); link(r):=p; p:=r; r:=t; {reverse list}
4515 until r=null;
4516 end;
4517 end
4518
4519 @ In the presence of a prototype box we use its shift amount and width
4520 to adjust the values of kerning and add these values to the glue nodes
4521 inserted to cancel the \.{\\leftskip} and \.{\\rightskip}. If there is
4522 no prototype box (because the display is preceded by an empty
4523 paragraph), or if the skip parameters are zero, we just add kerns.
4524
4525 The |cancel_glue| macro creates and links a glue node that is, together
4526 with another glue node, equivalent to a given amount of kerning. We can
4527 use |j| as temporary pointer, since all we need is |j<>null|.
4528
4529 @d cancel_glue(#)==j:=new_skip_param(#); cancel_glue_cont
4530 @d cancel_glue_cont(#)==link(#):=j; cancel_glue_cont_cont
4531 @d cancel_glue_cont_cont(#)==link(j):=#; cancel_glue_end
4532 @d cancel_glue_end(#)==j:=glue_ptr(#); cancel_glue_end_end
4533 @d cancel_glue_end_end(#)==
4534 stretch_order(temp_ptr):=stretch_order(j);
4535 shrink_order(temp_ptr):=shrink_order(j); width(temp_ptr):=#-width(j);
4536 stretch(temp_ptr):=-stretch(j); shrink(temp_ptr):=-shrink(j)
4537
4538 @<Package the display line@>=
4539 if j=null then
4540 begin r:=new_kern(0); t:=new_kern(0); {the widths will be set later}
4541 end
4542 else begin r:=list_ptr(b); t:=link(r);
4543 end;
4544 u:=new_math(0,end_M_code);
4545 if type(t)=glue_node then {|t| is \.{\\rightskip} glue}
4546 begin cancel_glue(right_skip_code)(q)(u)(t)(e); link(u):=t;
4547 end
4548 else begin width(t):=e; link(t):=u; link(q):=t;
4549 end;
4550 u:=new_math(0,begin_M_code);
4551 if type(r)=glue_node then {|r| is \.{\\leftskip} glue}
4552 begin cancel_glue(left_skip_code)(u)(p)(r)(d); link(r):=u;
4553 end
4554 else begin width(r):=d; link(r):=p; link(u):=r;
4555 if j=null then
4556 begin b:=hpack(u,natural); shift_amount(b):=s;
4557 end
4558 else list_ptr(b):=u;
4559 end
4560
4561 @ The |scan_tokens| feature of \eTeX\ defines the \.{\\scantokens}
4562 primitive.
4563
4564 @<Generate all \eTeX...@>=
4565 primitive("scantokens",input,2);
4566 @!@:scan_tokens_}{\.{\\scantokens} primitive@>
4567
4568 @ @<Cases of |input| for |print_cmd_chr|@>=
4569 else if chr_code=2 then print_esc("scantokens")
4570
4571 @ @<Cases for |input|@>=
4572 else if cur_chr=2 then pseudo_start
4573
4574 @ The global variable |pseudo_files| is used to maintain a stack of
4575 pseudo files. The |info| field of each pseudo file points to a linked
4576 list of variable size nodes representing lines not yet processed: the
4577 |info| field of the first word contains the size of this node, all the
4578 following words contain ASCII codes.
4579
4580 @<Glob...@>=
4581 @!pseudo_files:pointer; {stack of pseudo files}
4582
4583 @ @<Set init...@>=
4584 pseudo_files:=null;
4585
4586 @ The |pseudo_start| procedure initiates reading from a pseudo file.
4587
4588 @<Declare \eTeX\ procedures for ex...@>=
4589 procedure@?pseudo_start; forward;@t\2@>
4590
4591 @ @<Declare \eTeX\ procedures for tok...@>=
4592 procedure pseudo_start;
4593 var old_setting:0..max_selector; {holds |selector| setting}
4594 @!s:str_number; {string to be converted into a pseudo file}
4595 @!l,@!m:pool_pointer; {indices into |str_pool|}
4596 @!p,@!q,@!r:pointer; {for list construction}
4597 @!w: four_quarters; {four ASCII codes}
4598 @!nl,@!sz:integer;
4599 begin scan_general_text;
4600 old_setting:=selector; selector:=new_string;
4601 token_show(temp_head); selector:=old_setting;
4602 flush_list(link(temp_head));
4603 str_room(1); s:=make_string;
4604 @<Convert string |s| into a new pseudo file@>;
4605 flush_string;
4606 @<Initiate input from new pseudo file@>;
4607 end;
4608
4609 @ @<Convert string |s| into a new pseudo file@>=
4610 str_pool[pool_ptr]:=si(" "); l:=str_start[s];
4611 nl:=si(new_line_char);
4612 p:=get_avail; q:=p;
4613 while l<pool_ptr do
4614 begin m:=l;
4615 while (l<pool_ptr)and(str_pool[l]<>nl) do incr(l);
4616 sz:=(l-m+7)div 4;
4617 if sz=1 then sz:=2;
4618 r:=get_node(sz); link(q):=r; q:=r; info(q):=hi(sz);
4619 while sz>2 do
4620 begin decr(sz); incr(r);
4621 w.b0:=qi(so(str_pool[m])); w.b1:=qi(so(str_pool[m+1]));
4622 w.b2:=qi(so(str_pool[m+2])); w.b3:=qi(so(str_pool[m+3]));
4623 mem[r].qqqq:=w; m:=m+4;
4624 end;
4625 w.b0:=qi(" "); w.b1:=qi(" "); w.b2:=qi(" "); w.b3:=qi(" ");
4626 if l>m then
4627 begin w.b0:=qi(so(str_pool[m]));
4628 if l>m+1 then
4629 begin w.b1:=qi(so(str_pool[m+1]));
4630 if l>m+2 then
4631 begin w.b2:=qi(so(str_pool[m+2]));
4632 if l>m+3 then w.b3:=qi(so(str_pool[m+3]));
4633 end;
4634 end;
4635 end;
4636 mem[r+1].qqqq:=w;
4637 if str_pool[l]=nl then incr(l);
4638 end;
4639 info(p):=link(p); link(p):=pseudo_files; pseudo_files:=p
4640
4641 @ @<Initiate input from new pseudo file@>=
4642 begin_file_reading; {set up |cur_file| and new level of input}
4643 line:=0; limit:=start; loc:=limit+1; {force line read}
4644 if tracing_scan_tokens>0 then
4645 begin if term_offset>max_print_line-3 then print_ln
4646 else if (term_offset>0)or(file_offset>0) then print_char(" ");
4647 name:=19; print("( "); incr(open_parens); update_terminal;
4648 end
4649 else name:=18
4650
4651 @ Here we read a line from the current pseudo file into |buffer|.
4652
4653 @<Declare \eTeX\ procedures for tr...@>=
4654 function pseudo_input: boolean; {inputs the next line or returns |false|}
4655 var p:pointer; {current line from pseudo file}
4656 @!sz:integer; {size of node |p|}
4657 @!w:four_quarters; {four ASCII codes}
4658 @!r:pointer; {loop index}
4659 begin last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
4660 p:=info(pseudo_files);
4661 if p=null then pseudo_input:=false
4662 else begin info(pseudo_files):=link(p); sz:=ho(info(p));
4663 if 4*sz-3>=buf_size-last then
4664 @<Report overflow of the input buffer, and abort@>;
4665 last:=first;
4666 for r:=p+1 to p+sz-1 do
4667 begin w:=mem[r].qqqq;
4668 buffer[last]:=w.b0; buffer[last+1]:=w.b1;
4669 buffer[last+2]:=w.b2; buffer[last+3]:=w.b3;
4670 last:=last+4;
4671 end;
4672 if last>=max_buf_stack then max_buf_stack:=last+1;
4673 while (last>first)and(buffer[last-1]=" ") do decr(last);
4674 free_node(p,sz);
4675 pseudo_input:=true;
4676 end;
4677 end;
4678
4679 @ When we are done with a pseudo file we `close' it.
4680
4681 @<Declare \eTeX\ procedures for tr...@>=
4682 procedure pseudo_close; {close the top level pseudo file}
4683 var p,@!q: pointer;
4684 begin p:=link(pseudo_files); q:=info(pseudo_files);
4685 free_avail(pseudo_files); pseudo_files:=p;
4686 while q<>null do
4687 begin p:=q; q:=link(p); free_node(p,ho(info(p)));
4688 end;
4689 end;
4690
4691 @ @<Dump the \eTeX\ state@>=
4692 while pseudo_files<>null do pseudo_close; {flush pseudo files}
4693
4694 @ @<Generate all \eTeX...@>=
4695 primitive("readline",read_to_cs,1);@/
4696 @!@:read_line_}{\.{\\readline} primitive@>
4697
4698 @ @<Cases of |read| for |print_cmd_chr|@>=
4699 else print_esc("readline")
4700
4701 @ @<Handle \.{\\readline} and |goto done|@>=
4702 if j=1 then
4703 begin while loc<=limit do {current line not yet finished}
4704 begin cur_chr:=buffer[loc]; incr(loc);
4705 if cur_chr=" " then cur_tok:=space_token
4706 @+else cur_tok:=cur_chr+other_token;
4707 store_new_token(cur_tok);
4708 end;
4709 goto done;
4710 end
4711
4712 @ Here we define the additional conditionals of \eTeX\ as well as the
4713 \.{\\unless} prefix.
4714
4715 @d if_def_code=17 { `\.{\\ifdefined}' }
4716 @d if_cs_code=18 { `\.{\\ifcsname}' }
4717 @d if_font_char_code=19 { `\.{\\iffontchar}' }
4718
4719 @<Generate all \eTeX...@>=
4720 primitive("unless",expand_after,1);@/
4721 @!@:unless_}{\.{\\unless} primitive@>
4722 primitive("ifdefined",if_test,if_def_code);
4723 @!@:if_defined_}{\.{\\ifdefined} primitive@>
4724 primitive("ifcsname",if_test,if_cs_code);
4725 @!@:if_cs_name_}{\.{\\ifcsname} primitive@>
4726 primitive("iffontchar",if_test,if_font_char_code);
4727 @!@:if_font_char_}{\.{\\iffontchar} primitive@>
4728
4729 @ @<Cases of |expandafter| for |print_cmd_chr|@>=
4730 else print_esc("unless")
4731
4732 @ @<Cases of |if_test| for |print_cmd_chr|@>=
4733 if_def_code:print_esc("ifdefined");
4734 if_cs_code:print_esc("ifcsname");
4735 if_font_char_code:print_esc("iffontchar");
4736
4737 @ The result of a boolean condition is reversed when the conditional is
4738 preceded by \.{\\unless}.
4739
4740 @<Negate a boolean conditional and |goto reswitch|@>=
4741 begin get_token;
4742 if (cur_cmd=if_test)and(cur_chr<>if_case_code) then
4743 begin cur_chr:=cur_chr+unless_code; goto reswitch;
4744 end;
4745 print_err("You can't use `"); print_esc("unless"); print("' before `");
4746 @.You can't use \\unless...@>
4747 print_cmd_chr(cur_cmd,cur_chr); print_char("'");
4748 help1("Continue, and I'll forget that it ever happened.");
4749 back_error;
4750 end
4751
4752 @ The conditional \.{\\ifdefined} tests if a control sequence is
4753 defined.
4754
4755 We need to reset |scanner_status|, since \.{\\outer} control sequences
4756 are allowed, but we might be scanning a macro definition or preamble.
4757
4758 @<Cases for |conditional|@>=
4759 if_def_code:begin save_scanner_status:=scanner_status;
4760 scanner_status:=normal;
4761 get_next; b:=(cur_cmd<>undefined_cs);
4762 scanner_status:=save_scanner_status;
4763 end;
4764
4765 @ The conditional \.{\\ifcsname} is equivalent to \.{\{\\expandafter}
4766 \.{\}\\expandafter} \.{\\ifdefined} \.{\\csname}, except that no new
4767 control sequence will be entered into the hash table (once all tokens
4768 preceding the mandatory \.{\\endcsname} have been expanded).
4769
4770 @<Cases for |conditional|@>=
4771 if_cs_code:begin n:=get_avail; p:=n; {head of the list of characters}
4772 repeat get_x_token;
4773 if cur_cs=0 then store_new_token(cur_tok);
4774 until cur_cs<>0;
4775 if cur_cmd<>end_cs_name then @<Complain about missing \.{\\endcsname}@>;
4776 @<Look up the characters of list |n| in the hash table, and set |cur_cs|@>;
4777 flush_list(n);
4778 b:=(eq_type(cur_cs)<>undefined_cs);
4779 end;
4780
4781 @ @<Look up the characters of list |n| in the hash table...@>=
4782 m:=first; p:=link(n);
4783 while p<>null do
4784 begin if m>=max_buf_stack then
4785 begin max_buf_stack:=m+1;
4786 if max_buf_stack=buf_size then
4787 overflow("buffer size",buf_size);
4788 @:TeX capacity exceeded buffer size}{\quad buffer size@>
4789 end;
4790 buffer[m]:=info(p) mod @'400; incr(m); p:=link(p);
4791 end;
4792 if m>first+1 then
4793 cur_cs:=id_lookup(first,m-first) {|no_new_control_sequence| is |true|}
4794 else if m=first then cur_cs:=null_cs {the list is empty}
4795 else cur_cs:=single_base+buffer[first] {the list has length one}
4796
4797 @ The conditional \.{\\iffontchar} tests the existence of a character in
4798 a font.
4799
4800 @<Cases for |conditional|@>=
4801 if_font_char_code:begin scan_font_ident; n:=cur_val; scan_char_num;
4802 if (font_bc[n]<=cur_val)and(font_ec[n]>=cur_val) then
4803 b:=char_exists(char_info(n)(qi(cur_val)))
4804 else b:=false;
4805 end;
4806
4807 @ The |protected| feature of \eTeX\ defines the \.{\\protected} prefix
4808 command for macro definitions. Such macros are protected against
4809 expansions when lists of expanded tokens are built, e.g., for \.{\\edef}
4810 or during \.{\\write}.
4811
4812 @<Generate all \eTeX...@>=
4813 primitive("protected",prefix,8);
4814 @!@:protected_}{\.{\\protected} primitive@>
4815
4816 @ @<Cases of |prefix| for |print_cmd_chr|@>=
4817 else if chr_code=8 then print_esc("protected")
4818
4819 @ The |get_x_or_protected| procedure is like |get_x_token| except that
4820 protected macros are not expanded.
4821
4822 @<Declare \eTeX\ procedures for sc...@>=
4823 procedure get_x_or_protected; {sets |cur_cmd|, |cur_chr|, |cur_tok|,
4824 and expands non-protected macros}
4825 label exit;
4826 begin loop@+begin get_token;
4827 if cur_cmd<=max_command then return;
4828 if (cur_cmd>=call)and(cur_cmd<end_template) then
4829 if info(link(cur_chr))=protected_token then return;
4830 expand;
4831 end;
4832 exit:end;
4833
4834 @ A group entered (or a conditional started) in one file may end in a
4835 different file. Such slight anomalies, although perfectly legitimate,
4836 may cause errors that are difficult to locate. In order to be able to
4837 give a warning message when such anomalies occur, \eTeX\ uses the
4838 |grp_stack| and |if_stack| arrays to record the initial |cur_boundary|
4839 and |cond_ptr| values for each input file.
4840
4841 @<Glob...@>=
4842 @!grp_stack : array[0..max_in_open] of save_pointer; {initial |cur_boundary|}
4843 @!if_stack : array[0..max_in_open] of pointer; {initial |cond_ptr|}
4844
4845 @ When a group ends that was apparently entered in a different input
4846 file, the |group_warning| procedure is invoked in order to update the
4847 |grp_stack|. If moreover \.{\\tracingnesting} is positive we want to
4848 give a warning message. The situation is, however, somewhat complicated
4849 by two facts: (1)~There may be |grp_stack| elements without a
4850 corresponding \.{\\input} file or \.{\\scantokens} pseudo file (e.g.,
4851 error insertions from the terminal); and (2)~the relevant information is
4852 recorded in the |name_field| of the |input_stack| only loosely
4853 synchronized with the |in_open| variable indexing |grp_stack|.
4854
4855 @<Declare \eTeX\ procedures for tr...@>=
4856 procedure group_warning;
4857 var i:0..max_in_open; {index into |grp_stack|}
4858 @!w:boolean; {do we need a warning?}
4859 begin base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input;
4860 {store current state}
4861 i:=in_open; w:=false;
4862 while (grp_stack[i]=cur_boundary)and(i>0) do
4863 begin @<Set variable |w| to indicate if this case should be reported@>;
4864 grp_stack[i]:=save_index(save_ptr); decr(i);
4865 end;
4866 if w then
4867 begin print_nl("Warning: end of "); print_group(true);
4868 @.Warning: end of...@>
4869 print(" of a different file"); print_ln;
4870 if tracing_nesting>1 then show_context;
4871 if history=spotless then history:=warning_issued;
4872 end;
4873 end;
4874
4875 @ This code scans the input stack in order to determine the type of the
4876 current input file.
4877
4878 @<Set variable |w| to...@>=
4879 if tracing_nesting>0 then
4880 begin while (input_stack[base_ptr].state_field=token_list)or@|
4881 (input_stack[base_ptr].index_field>i) do decr(base_ptr);
4882 if input_stack[base_ptr].name_field>17 then w:=true;
4883 end
4884
4885 @ When a conditional ends that was apparently started in a different
4886 input file, the |if_warning| procedure is invoked in order to update the
4887 |if_stack|. If moreover \.{\\tracingnesting} is positive we want to
4888 give a warning message (with the same complications as above).
4889
4890 @<Declare \eTeX\ procedures for tr...@>=
4891 procedure if_warning;
4892 var i:0..max_in_open; {index into |if_stack|}
4893 @!w:boolean; {do we need a warning?}
4894 begin base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input;
4895 {store current state}
4896 i:=in_open; w:=false;
4897 while if_stack[i]=cond_ptr do
4898 begin @<Set variable |w| to...@>;
4899 if_stack[i]:=link(cond_ptr); decr(i);
4900 end;
4901 if w then
4902 begin print_nl("Warning: end of "); print_cmd_chr(if_test,cur_if);
4903 @.Warning: end of...@>
4904 print_if_line(if_line); print(" of a different file"); print_ln;
4905 if tracing_nesting>1 then show_context;
4906 if history=spotless then history:=warning_issued;
4907 end;
4908 end;
4909
4910 @ Conversely, the |file_warning| procedure is invoked when a file ends
4911 and some groups entered or conditionals started while reading from that
4912 file are still incomplete.
4913
4914 @<Declare \eTeX\ procedures for tr...@>=
4915 procedure file_warning;
4916 var p:pointer; {saved value of |save_ptr| or |cond_ptr|}
4917 @!l:quarterword; {saved value of |cur_level| or |if_limit|}
4918 @!c:quarterword; {saved value of |cur_group| or |cur_if|}
4919 @!i:integer; {saved value of |if_line|}
4920 begin p:=save_ptr; l:=cur_level; c:=cur_group; save_ptr:=cur_boundary;
4921 while grp_stack[in_open]<>save_ptr do
4922 begin decr(cur_level);
4923 print_nl("Warning: end of file when ");
4924 @.Warning: end of file when...@>
4925 print_group(true); print(" is incomplete");@/
4926 cur_group:=save_level(save_ptr); save_ptr:=save_index(save_ptr)
4927 end;
4928 save_ptr:=p; cur_level:=l; cur_group:=c; {restore old values}
4929 p:=cond_ptr; l:=if_limit; c:=cur_if; i:=if_line;
4930 while if_stack[in_open]<>cond_ptr do
4931 begin print_nl("Warning: end of file when ");
4932 @.Warning: end of file when...@>
4933 print_cmd_chr(if_test,cur_if);
4934 if if_limit=fi_code then print_esc("else");
4935 print_if_line(if_line); print(" is incomplete");@/
4936 if_line:=if_line_field(cond_ptr); cur_if:=subtype(cond_ptr);
4937 if_limit:=type(cond_ptr); cond_ptr:=link(cond_ptr);
4938 end;
4939 cond_ptr:=p; if_limit:=l; cur_if:=c; if_line:=i; {restore old values}
4940 print_ln;
4941 if tracing_nesting>1 then show_context;
4942 if history=spotless then history:=warning_issued;
4943 end;
4944
4945 @ Here are the additional \eTeX\ primitives for expressions.
4946
4947 @<Generate all \eTeX...@>=
4948 primitive("numexpr",last_item,eTeX_expr-int_val+int_val);
4949 @!@:num_expr_}{\.{\\numexpr} primitive@>
4950 primitive("dimexpr",last_item,eTeX_expr-int_val+dimen_val);
4951 @!@:dim_expr_}{\.{\\dimexpr} primitive@>
4952 primitive("glueexpr",last_item,eTeX_expr-int_val+glue_val);
4953 @!@:glue_expr_}{\.{\\glueexpr} primitive@>
4954 primitive("muexpr",last_item,eTeX_expr-int_val+mu_val);
4955 @!@:mu_expr_}{\.{\\muexpr} primitive@>
4956
4957 @ @<Cases of |last_item| for |print_cmd_chr|@>=
4958 eTeX_expr-int_val+int_val: print_esc("numexpr");
4959 eTeX_expr-int_val+dimen_val: print_esc("dimexpr");
4960 eTeX_expr-int_val+glue_val: print_esc("glueexpr");
4961 eTeX_expr-int_val+mu_val: print_esc("muexpr");
4962
4963 @ This code for reducing |cur_val_level| and\slash or negating the
4964 result is similar to the one for all the other cases of
4965 |scan_something_internal|, with the difference that |scan_expr| has
4966 already increased the reference count of a glue specification.
4967
4968 @<Process an expression and |return|@>=
4969 begin if m<eTeX_mu then
4970 begin case m of
4971 @/@<Cases for fetching a glue value@>@/
4972 end; {there are no other cases}
4973 cur_val_level:=glue_val;
4974 end
4975 else if m<eTeX_expr then
4976 begin case m of
4977 @/@<Cases for fetching a mu value@>@/
4978 end; {there are no other cases}
4979 cur_val_level:=mu_val;
4980 end
4981 else begin cur_val_level:=m-eTeX_expr+int_val; scan_expr;
4982 end;
4983 while cur_val_level>level do
4984 begin if cur_val_level=glue_val then
4985 begin m:=cur_val; cur_val:=width(m); delete_glue_ref(m);
4986 end
4987 else if cur_val_level=mu_val then mu_error;
4988 decr(cur_val_level);
4989 end;
4990 if negative then
4991 if cur_val_level>=glue_val then
4992 begin m:=cur_val; cur_val:=new_spec(m); delete_glue_ref(m);
4993 @<Negate all three glue components of |cur_val|@>;
4994 end
4995 else negate(cur_val);
4996 return;
4997 end
4998
4999 @ @<Declare \eTeX\ procedures for sc...@>=
5000 procedure@?scan_expr; forward;@t\2@>
5001
5002 @ The |scan_expr| procedure scans and evaluates an expression.
5003
5004 @<Declare procedures needed for expressions@>=
5005 @t\4@>@<Declare subprocedures for |scan_expr|@>
5006 procedure scan_expr; {scans and evaluates an expression}
5007 label restart, continue, found;
5008 var a,@!b:boolean; {saved values of |arith_error|}
5009 @!l:small_number; {type of expression}
5010 @!r:small_number; {state of expression so far}
5011 @!s:small_number; {state of term so far}
5012 @!o:small_number; {next operation or type of next factor}
5013 @!e:integer; {expression so far}
5014 @!t:integer; {term so far}
5015 @!f:integer; {current factor}
5016 @!n:integer; {numerator of combined multiplication and division}
5017 @!p:pointer; {top of expression stack}
5018 @!q:pointer; {for stack manipulations}
5019 begin l:=cur_val_level; a:=arith_error; b:=false; p:=null;
5020 incr(expand_depth_count);
5021 if expand_depth_count>=expand_depth then overflow("expansion depth",expand_depth);
5022 @<Scan and evaluate an expression |e| of type |l|@>;
5023 decr(expand_depth_count);
5024 if b then
5025 begin print_err("Arithmetic overflow");
5026 @.Arithmetic overflow@>
5027 help2("I can't evaluate this expression,")@/
5028 ("since the result is out of range.");
5029 error;
5030 if l>=glue_val then
5031 begin delete_glue_ref(e); e:=zero_glue; add_glue_ref(e);
5032 end
5033 else e:=0;
5034 end;
5035 arith_error:=a; cur_val:=e; cur_val_level:=l;
5036 end;
5037
5038 @ Evaluating an expression is a recursive process: When the left
5039 parenthesis of a subexpression is scanned we descend to the next level
5040 of recursion; the previous level is resumed with the matching right
5041 parenthesis.
5042
5043 @d expr_none=0 {\.( seen, or \.( $\langle\it expr\rangle$ \.) seen}
5044 @d expr_add=1 {\.( $\langle\it expr\rangle$ \.+ seen}
5045 @d expr_sub=2 {\.( $\langle\it expr\rangle$ \.- seen}
5046 @d expr_mult=3 {$\langle\it term\rangle$ \.* seen}
5047 @d expr_div=4 {$\langle\it term\rangle$ \./ seen}
5048 @d expr_scale=5 {$\langle\it term\rangle$ \.*
5049 $\langle\it factor\rangle$ \./ seen}
5050
5051 @<Scan and eval...@>=
5052 restart: r:=expr_none; e:=0; s:=expr_none; t:=0; n:=0;
5053 continue: if s=expr_none then o:=l@+else o:=int_val;
5054 @<Scan a factor |f| of type |o| or start a subexpression@>;
5055 found: @<Scan the next operator and set |o|@>;
5056 arith_error:=b;
5057 @<Make sure that |f| is in the proper range@>;
5058 case s of @<Cases for evaluation of the current term@>@;
5059 end; {there are no other cases}
5060 if o>expr_sub then s:=o@+else @<Evaluate the current expression@>;
5061 b:=arith_error;
5062 if o<>expr_none then goto continue;
5063 if p<>null then @<Pop the expression stack and |goto found|@>
5064
5065 @ @<Scan the next op...@>=
5066 @<Get the next non-blank non-call token@>;
5067 if cur_tok=other_token+"+" then o:=expr_add
5068 else if cur_tok=other_token+"-" then o:=expr_sub
5069 else if cur_tok=other_token+"*" then o:=expr_mult
5070 else if cur_tok=other_token+"/" then o:=expr_div
5071 else begin o:=expr_none;
5072 if p=null then
5073 begin if cur_cmd<>relax then back_input;
5074 end
5075 else if cur_tok<>other_token+")" then
5076 begin print_err("Missing ) inserted for expression");
5077 @.Missing ) inserted@>
5078 help1("I was expecting to see `+', `-', `*', `/', or `)'. Didn't.");
5079 back_error;
5080 end;
5081 end
5082
5083 @ @<Scan a factor...@>=
5084 @<Get the next non-blank non-call token@>;
5085 if cur_tok=other_token+"(" then
5086 @<Push the expression stack and |goto restart|@>;
5087 back_input;
5088 if o=int_val then scan_int
5089 else if o=dimen_val then scan_normal_dimen
5090 else if o=glue_val then scan_normal_glue
5091 else scan_mu_glue;
5092 f:=cur_val
5093
5094 @ @<Declare \eTeX\ procedures for sc...@>=
5095 procedure@?scan_normal_glue; forward;@t\2@>@/
5096 procedure@?scan_mu_glue; forward;@t\2@>
5097
5098 @ Here we declare two trivial procedures in order to avoid mutually
5099 recursive procedures with parameters.
5100
5101 @<Declare procedures needed for expressions@>=
5102 procedure scan_normal_glue;
5103 begin scan_glue(glue_val);
5104 end;
5105 @#
5106 procedure scan_mu_glue;
5107 begin scan_glue(mu_val);
5108 end;
5109
5110 @ Parenthesized subexpressions can be inside expressions, and this
5111 nesting has a stack. Seven local variables represent the top of the
5112 expression stack: |p| points to pushed-down entries, if any; |l|
5113 specifies the type of expression currently being evaluated; |e| is the
5114 expression so far and |r| is the state of its evaluation; |t| is the
5115 term so far and |s| is the state of its evaluation; finally |n| is the
5116 numerator for a combined multiplication and division, if any.
5117
5118 @d expr_node_size=4 {number of words in stack entry for subexpressions}
5119 @d expr_e_field(#)==mem[#+1].int {saved expression so far}
5120 @d expr_t_field(#)==mem[#+2].int {saved term so far}
5121 @d expr_n_field(#)==mem[#+3].int {saved numerator}
5122
5123 @<Push the expression...@>=
5124 begin q:=get_node(expr_node_size); link(q):=p; type(q):=l;
5125 subtype(q):=4*s+r;
5126 expr_e_field(q):=e; expr_t_field(q):=t; expr_n_field(q):=n;
5127 p:=q; l:=o; goto restart;
5128 end
5129
5130 @ @<Pop the expression...@>=
5131 begin f:=e; q:=p;
5132 e:=expr_e_field(q); t:=expr_t_field(q); n:=expr_n_field(q);
5133 s:=subtype(q) div 4; r:=subtype(q) mod 4;
5134 l:=type(q); p:=link(q); free_node(q,expr_node_size);
5135 goto found;
5136 end
5137
5138 @ We want to make sure that each term and (intermediate) result is in
5139 the proper range. Integer values must not exceed |infinity|
5140 ($2^{31}-1$) in absolute value, dimensions must not exceed |max_dimen|
5141 ($2^{30}-1$). We avoid the absolute value of an integer, because this
5142 might fail for the value $-2^{31}$ using 32-bit arithmetic.
5143
5144 @d num_error(#)== {clear a number or dimension and set |arith_error|}
5145 begin arith_error:=true; #:=0;
5146 end
5147 @d glue_error(#)== {clear a glue spec and set |arith_error|}
5148 begin arith_error:=true; delete_glue_ref(#); #:=new_spec(zero_glue);
5149 end
5150
5151 @<Make sure that |f|...@>=
5152 if (l=int_val)or(s>expr_sub) then
5153 begin if (f>infinity)or(f<-infinity) then num_error(f);
5154 end
5155 else if l=dimen_val then
5156 begin if abs(f)>max_dimen then num_error(f);
5157 end
5158 else begin if (abs(width(f))>max_dimen)or@|
5159 (abs(stretch(f))>max_dimen)or@|
5160 (abs(shrink(f))>max_dimen) then glue_error(f);
5161 end
5162
5163 @ Applying the factor |f| to the partial term |t| (with the operator
5164 |s|) is delayed until the next operator |o| has been scanned. Here we
5165 handle the first factor of a partial term. A glue spec has to be copied
5166 unless the next operator is a right parenthesis; this allows us later on
5167 to simply modify the glue components.
5168
5169 @d normalize_glue(#)==
5170 if stretch(#)=0 then stretch_order(#):=normal;
5171 if shrink(#)=0 then shrink_order(#):=normal
5172
5173 @<Cases for evaluation of the current term@>=
5174 expr_none: if (l>=glue_val)and(o<>expr_none) then
5175 begin t:=new_spec(f); delete_glue_ref(f); normalize_glue(t);
5176 end
5177 else t:=f;
5178
5179 @ When a term |t| has been completed it is copied to, added to, or
5180 subtracted from the expression |e|.
5181
5182 @d expr_add_sub(#)==add_or_sub(#,r=expr_sub)
5183 @d expr_a(#)==expr_add_sub(#,max_dimen)
5184
5185 @<Evaluate the current expression@>=
5186 begin s:=expr_none;
5187 if r=expr_none then e:=t
5188 else if l=int_val then e:=expr_add_sub(e,t,infinity)
5189 else if l=dimen_val then e:=expr_a(e,t)
5190 else @<Compute the sum or difference of two glue specs@>;
5191 r:=o;
5192 end
5193
5194 @ The function |add_or_sub(x,y,max_answer,negative)| computes the sum
5195 (for |negative=false|) or difference (for |negative=true|) of |x| and
5196 |y|, provided the absolute value of the result does not exceed
5197 |max_answer|.
5198
5199 @<Declare subprocedures for |scan_expr|@>=
5200 function add_or_sub(@!x,@!y,@!max_answer:integer;@!negative:boolean):integer;
5201 var a:integer; {the answer}
5202 begin if negative then negate(y);
5203 if x>=0 then
5204 if y<=max_answer-x then a:=x+y@+else num_error(a)
5205 else if y>=-max_answer-x then a:=x+y@+else num_error(a);
5206 add_or_sub:=a;
5207 end;
5208
5209 @ We know that |stretch_order(e)>normal| implies |stretch(e)<>0| and
5210 |shrink_order(e)>normal| implies |shrink(e)<>0|.
5211
5212 @<Compute the sum or diff...@>=
5213 begin width(e):=expr_a(width(e),width(t));
5214 if stretch_order(e)=stretch_order(t) then
5215 stretch(e):=expr_a(stretch(e),stretch(t))
5216 else if (stretch_order(e)<stretch_order(t))and(stretch(t)<>0) then
5217 begin stretch(e):=stretch(t); stretch_order(e):=stretch_order(t);
5218 end;
5219 if shrink_order(e)=shrink_order(t) then
5220 shrink(e):=expr_a(shrink(e),shrink(t))
5221 else if (shrink_order(e)<shrink_order(t))and(shrink(t)<>0) then
5222 begin shrink(e):=shrink(t); shrink_order(e):=shrink_order(t);
5223 end;
5224 delete_glue_ref(t); normalize_glue(e);
5225 end
5226
5227 @ If a multiplication is followed by a division, the two operations are
5228 combined into a `scaling' operation. Otherwise the term |t| is
5229 multiplied by the factor |f|.
5230
5231 @d expr_m(#)==#:=nx_plus_y(#,f,0)
5232
5233 @<Cases for evaluation of the current term@>=
5234 expr_mult: if o=expr_div then
5235 begin n:=f; o:=expr_scale;
5236 end
5237 else if l=int_val then t:=mult_integers(t,f)
5238 else if l=dimen_val then expr_m(t)
5239 else begin expr_m(width(t)); expr_m(stretch(t)); expr_m(shrink(t));
5240 end;
5241
5242 @ Here we divide the term |t| by the factor |f|.
5243
5244 @d expr_d(#)==#:=quotient(#,f)
5245
5246 @<Cases for evaluation of the current term@>=
5247 expr_div: if l<glue_val then expr_d(t)
5248 else begin expr_d(width(t)); expr_d(stretch(t)); expr_d(shrink(t));
5249 end;
5250
5251 @ The function |quotient(n,d)| computes the rounded quotient
5252 $q=\lfloor n/d+{1\over2}\rfloor$, when $n$ and $d$ are positive.
5253
5254 @<Declare subprocedures for |scan_expr|@>=
5255 function quotient(@!n,@!d:integer):integer;
5256 var negative:boolean; {should the answer be negated?}
5257 @!a:integer; {the answer}
5258 begin if d=0 then num_error(a)
5259 else begin if d>0 then negative:=false
5260 else begin negate(d); negative:=true;
5261 end;
5262 if n<0 then
5263 begin negate(n); negative:=not negative;
5264 end;
5265 a:=n div d; n:=n-a*d; d:=n-d; {avoid certain compiler optimizations!}
5266 if d+n>=0 then incr(a);
5267 if negative then negate(a);
5268 end;
5269 quotient:=a;
5270 end;
5271
5272 @ Here the term |t| is multiplied by the quotient $n/f$.
5273
5274 @d expr_s(#)==#:=fract(#,n,f,max_dimen)
5275
5276 @<Cases for evaluation of the current term@>=
5277 expr_scale: if l=int_val then t:=fract(t,n,f,infinity)
5278 else if l=dimen_val then expr_s(t)
5279 else begin expr_s(width(t)); expr_s(stretch(t)); expr_s(shrink(t));
5280 end;
5281
5282 @ Finally, the function |fract(x,n,d,max_answer)| computes the integer
5283 $q=\lfloor xn/d+{1\over2}\rfloor$, when $x$, $n$, and $d$ are positive
5284 and the result does not exceed |max_answer|. We can't use floating
5285 point arithmetic since the routine must produce identical results in all
5286 cases; and it would be too dangerous to multiply by~|n| and then divide
5287 by~|d|, in separate operations, since overflow might well occur. Hence
5288 this subroutine simulates double precision arithmetic, somewhat
5289 analogous to \MF's |make_fraction| and |take_fraction| routines.
5290
5291 @d too_big=88 {go here when the result is too big}
5292
5293 @<Declare subprocedures for |scan_expr|@>=
5294 function fract(@!x,@!n,@!d,@!max_answer:integer):integer;
5295 label found, found1, too_big, done;
5296 var negative:boolean; {should the answer be negated?}
5297 @!a:integer; {the answer}
5298 @!f:integer; {a proper fraction}
5299 @!h:integer; {smallest integer such that |2*h>=d|}
5300 @!r:integer; {intermediate remainder}
5301 @!t:integer; {temp variable}
5302 begin if d=0 then goto too_big;
5303 a:=0;
5304 if d>0 then negative:=false
5305 else begin negate(d); negative:=true;
5306 end;
5307 if x<0 then
5308 begin negate(x); negative:=not negative;
5309 end
5310 else if x=0 then goto done;
5311 if n<0 then
5312 begin negate(n); negative:=not negative;
5313 end;
5314 t:=n div d;
5315 if t>max_answer div x then goto too_big;
5316 a:=t*x; n:=n-t*d;
5317 if n=0 then goto found;
5318 t:=x div d;
5319 if t>(max_answer-a) div n then goto too_big;
5320 a:=a+t*n; x:=x-t*d;
5321 if x=0 then goto found;
5322 if x<n then
5323 begin t:=x; x:=n; n:=t;
5324 end; {now |0<n<=x<d|}
5325 @<Compute \(f)$f=\lfloor xn/d+{1\over2}\rfloor$@>@;
5326 if f>(max_answer-a) then goto too_big;
5327 a:=a+f;
5328 found: if negative then negate(a);
5329 goto done;
5330 too_big: num_error(a);
5331 done: fract:=a;
5332 end;
5333
5334 @ The loop here preserves the following invariant relations
5335 between |f|, |x|, |n|, and~|r|:
5336 (i)~$f+\lfloor(xn+(r+d))/d\rfloor=\lfloor x_0n_0/d+{1\over2}\rfloor$;
5337 (ii)~|-d<=r<0<n<=x<d|, where $x_0$, $n_0$ are the original values of~$x$
5338 and $n$.
5339
5340 Notice that the computation specifies |(x-d)+x| instead of |(x+x)-d|,
5341 because the latter could overflow.
5342
5343 @<Compute \(f)$f=\lfloor xn/d+{1\over2}\rfloor$@>=
5344 f:=0; r:=(d div 2)-d; h:=-r;
5345 loop@+begin if odd(n) then
5346 begin r:=r+x;
5347 if r>=0 then
5348 begin r:=r-d; incr(f);
5349 end;
5350 end;
5351 n:=n div 2;
5352 if n=0 then goto found1;
5353 if x<h then x:=x+x
5354 else begin t:=x-d; x:=t+x; f:=f+n;
5355 if x<n then
5356 begin if x=0 then goto found1;
5357 t:=x; x:=n; n:=t;
5358 end;
5359 end;
5360 end;
5361 found1:
5362
5363 @ The \.{\\gluestretch}, \.{\\glueshrink}, \.{\\gluestretchorder}, and
5364 \.{\\glueshrinkorder} commands return the stretch and shrink components
5365 and their orders of ``infinity'' of a glue specification.
5366
5367 @d glue_stretch_order_code=eTeX_int+6 {code for \.{\\gluestretchorder}}
5368 @d glue_shrink_order_code=eTeX_int+7 {code for \.{\\glueshrinkorder}}
5369 @d glue_stretch_code=eTeX_dim+7 {code for \.{\\gluestretch}}
5370 @d glue_shrink_code=eTeX_dim+8 {code for \.{\\glueshrink}}
5371
5372 @<Generate all \eTeX...@>=
5373 primitive("gluestretchorder",last_item,glue_stretch_order_code);
5374 @!@:glue_stretch_order_}{\.{\\gluestretchorder} primitive@>
5375 primitive("glueshrinkorder",last_item,glue_shrink_order_code);
5376 @!@:glue_shrink_order_}{\.{\\glueshrinkorder} primitive@>
5377 primitive("gluestretch",last_item,glue_stretch_code);
5378 @!@:glue_stretch_}{\.{\\gluestretch} primitive@>
5379 primitive("glueshrink",last_item,glue_shrink_code);
5380 @!@:glue_shrink_}{\.{\\glueshrink} primitive@>
5381
5382 @ @<Cases of |last_item| for |print_cmd_chr|@>=
5383 glue_stretch_order_code: print_esc("gluestretchorder");
5384 glue_shrink_order_code: print_esc("glueshrinkorder");
5385 glue_stretch_code: print_esc("gluestretch");
5386 glue_shrink_code: print_esc("glueshrink");
5387
5388 @ @<Cases for fetching an integer value@>=
5389 glue_stretch_order_code, glue_shrink_order_code:
5390 begin scan_normal_glue; q:=cur_val;
5391 if m=glue_stretch_order_code then cur_val:=stretch_order(q)
5392 else cur_val:=shrink_order(q);
5393 delete_glue_ref(q);
5394 end;
5395
5396 @ @<Cases for fetching a dimension value@>=
5397 glue_stretch_code, glue_shrink_code:
5398 begin scan_normal_glue; q:=cur_val;
5399 if m=glue_stretch_code then cur_val:=stretch(q)
5400 else cur_val:=shrink(q);
5401 delete_glue_ref(q);
5402 end;
5403
5404 @ The \.{\\mutoglue} and \.{\\gluetomu} commands convert ``math'' glue
5405 into normal glue and vice versa; they allow to manipulate math glue with
5406 \.{\\gluestretch} etc.
5407
5408 @d mu_to_glue_code=eTeX_glue {code for \.{\\mutoglue}}
5409 @d glue_to_mu_code=eTeX_mu {code for \.{\\gluetomu}}
5410
5411 @<Generate all \eTeX...@>=
5412 primitive("mutoglue",last_item,mu_to_glue_code);
5413 @!@:mu_to_glue_}{\.{\\mutoglue} primitive@>
5414 primitive("gluetomu",last_item,glue_to_mu_code);
5415 @!@:glue_to_mu_}{\.{\\gluetomu} primitive@>
5416
5417 @ @<Cases of |last_item| for |print_cmd_chr|@>=
5418 mu_to_glue_code: print_esc("mutoglue");
5419 glue_to_mu_code: print_esc("gluetomu");
5420
5421 @ @<Cases for fetching a glue value@>=
5422 mu_to_glue_code: scan_mu_glue;
5423
5424 @ @<Cases for fetching a mu value@>=
5425 glue_to_mu_code: scan_normal_glue;
5426
5427 @ \eTeX\ (in extended mode) supports 32768 (i.e., $2^{15}$) count,
5428 dimen, skip, muskip, box, and token registers. As in \TeX\ the first
5429 256 registers of each kind are realized as arrays in the table of
5430 equivalents; the additional registers are realized as tree structures
5431 built from variable-size nodes with individual registers existing only
5432 when needed. Default values are used for nonexistent registers: zero
5433 for count and dimen values, |zero_glue| for glue (skip and muskip)
5434 values, void for boxes, and |null| for token lists (and current marks
5435 discussed below).
5436
5437 Similarly there are 32768 mark classes; the command \.{\\marks}|n|
5438 creates a mark node for a given mark class |0<=n<=32767| (where
5439 \.{\\marks0} is synonymous to \.{\\mark}). The page builder (actually
5440 the |fire_up| routine) and the |vsplit| routine maintain the current
5441 values of |top_mark|, |first_mark|, |bot_mark|, |split_first_mark|, and
5442 |split_bot_mark| for each mark class. They are accessed as
5443 \.{\\topmarks}|n| etc., and \.{\\topmarks0} is again synonymous to
5444 \.{\\topmark}. As in \TeX\ the five current marks for mark class zero
5445 are realized as |cur_mark| array. The additional current marks are
5446 again realized as tree structure with individual mark classes existing
5447 only when needed.
5448
5449 @<Generate all \eTeX...@>=
5450 primitive("marks",mark,marks_code);
5451 @!@:marks_}{\.{\\marks} primitive@>
5452 primitive("topmarks",top_bot_mark,top_mark_code+marks_code);
5453 @!@:top_marks_}{\.{\\topmarks} primitive@>
5454 primitive("firstmarks",top_bot_mark,first_mark_code+marks_code);
5455 @!@:first_marks_}{\.{\\firstmarks} primitive@>
5456 primitive("botmarks",top_bot_mark,bot_mark_code+marks_code);
5457 @!@:bot_marks_}{\.{\\botmarks} primitive@>
5458 primitive("splitfirstmarks",top_bot_mark,split_first_mark_code+marks_code);
5459 @!@:split_first_marks_}{\.{\\splitfirstmarks} primitive@>
5460 primitive("splitbotmarks",top_bot_mark,split_bot_mark_code+marks_code);
5461 @!@:split_bot_marks_}{\.{\\splitbotmarks} primitive@>
5462
5463 @ The |scan_register_num| procedure scans a register number that must
5464 not exceed 255 in compatibility mode resp.\ 32767 in extended mode.
5465
5466 @<Declare \eTeX\ procedures for ex...@>=
5467 procedure@?scan_register_num; forward;@t\2@>
5468
5469 @ @<Declare procedures that scan restricted classes of integers@>=
5470 procedure scan_register_num;
5471 begin scan_int;
5472 if (cur_val<0)or(cur_val>max_reg_num) then
5473 begin print_err("Bad register code");
5474 @.Bad register code@>
5475 help2(max_reg_help_line)("I changed this one to zero.");
5476 int_error(cur_val); cur_val:=0;
5477 end;
5478 end;
5479
5480 @ @<Initialize variables for \eTeX\ comp...@>=
5481 max_reg_num:=255;
5482 max_reg_help_line:="A register number must be between 0 and 255.";
5483
5484 @ @<Initialize variables for \eTeX\ ext...@>=
5485 max_reg_num:=32767;
5486 max_reg_help_line:="A register number must be between 0 and 32767.";
5487
5488 @ @<Glob...@>=
5489 @!max_reg_num: halfword; {largest allowed register number}
5490 @!max_reg_help_line: str_number; {first line of help message}
5491
5492 @ There are seven almost identical doubly linked trees, one for the
5493 sparse array of the up to 32512 additional registers of each kind and
5494 one for the sparse array of the up to 32767 additional mark classes.
5495 The root of each such tree, if it exists, is an index node containing 16
5496 pointers to subtrees for 4096 consecutive array elements. Similar index
5497 nodes are the starting points for all nonempty subtrees for 4096, 256,
5498 and 16 consecutive array elements. These four levels of index nodes are
5499 followed by a fifth level with nodes for the individual array elements.
5500
5501 Each index node is nine words long. The pointers to the 16 possible
5502 subtrees or are kept in the |info| and |link| fields of the last eight
5503 words. (It would be both elegant and efficient to declare them as
5504 array, unfortunately \PASCAL\ doesn't allow this.)
5505
5506 The fields in the first word of each index node and in the nodes for the
5507 array elements are closely related. The |link| field points to the next
5508 lower index node and the |sa_index| field contains four bits (one
5509 hexadecimal digit) of the register number or mark class. For the lowest
5510 index node the |link| field is |null| and the |sa_index| field indicates
5511 the type of quantity (|int_val|, |dimen_val|, |glue_val|, |mu_val|,
5512 |box_val|, |tok_val|, or |mark_val|). The |sa_used| field in the index
5513 nodes counts how many of the 16 pointers are non-null.
5514
5515 The |sa_index| field in the nodes for array elements contains the four
5516 bits plus 16 times the type. Therefore such a node represents a count
5517 or dimen register if and only if |sa_index<dimen_val_limit|; it
5518 represents a skip or muskip register if and only if
5519 |dimen_val_limit<=sa_index<mu_val_limit|; it represents a box register
5520 if and only if |mu_val_limit<=sa_index<box_val_limit|; it represents a
5521 token list register if and only if
5522 |box_val_limit<=sa_index<tok_val_limit|; finally it represents a mark
5523 class if and only if |tok_val_limit<=sa_index|.
5524
5525 The |new_index| procedure creates an index node (returned in |cur_ptr|)
5526 having given contents of the |sa_index| and |link| fields.
5527
5528 @d box_val==4 {the additional box registers}
5529 @d mark_val=6 {the additional mark classes}
5530 @#
5531 @d dimen_val_limit=@"20 {$2^4\cdot(|dimen_val|+1)$}
5532 @d mu_val_limit=@"40 {$2^4\cdot(|mu_val|+1)$}
5533 @d box_val_limit=@"50 {$2^4\cdot(|box_val|+1)$}
5534 @d tok_val_limit=@"60 {$2^4\cdot(|tok_val|+1)$}
5535 @#
5536 @d index_node_size=9 {size of an index node}
5537 @d sa_index==type {a four-bit address or a type or both}
5538 @d sa_used==subtype {count of non-null pointers}
5539
5540 @<Declare \eTeX\ procedures for ex...@>=
5541 procedure new_index(@!i:quarterword; @!q:pointer);
5542 var k:small_number; {loop index}
5543 begin cur_ptr:=get_node(index_node_size); sa_index(cur_ptr):=i;
5544 sa_used(cur_ptr):=0; link(cur_ptr):=q;
5545 for k:=1 to index_node_size-1 do {clear all 16 pointers}
5546 mem[cur_ptr+k]:=sa_null;
5547 end;
5548
5549 @ The roots of the seven trees for the additional registers and mark
5550 classes are kept in the |sa_root| array. The first six locations must
5551 be dumped and undumped; the last one is also known as |sa_mark|.
5552
5553 @d sa_mark==sa_root[mark_val] {root for mark classes}
5554
5555 @<Glob...@>=
5556 @!sa_root:array[int_val..mark_val] of pointer; {roots of sparse arrays}
5557 @!cur_ptr:pointer; {value returned by |new_index| and |find_sa_element|}
5558 @!sa_null:memory_word; {two |null| pointers}
5559
5560 @ @<Set init...@>=
5561 sa_mark:=null; sa_null.hh.lh:=null; sa_null.hh.rh:=null;
5562
5563 @ @<Initialize table...@>=
5564 for i:=int_val to tok_val do sa_root[i]:=null;
5565
5566 @ Given a type |t| and a sixteen-bit number |n|, the |find_sa_element|
5567 procedure returns (in |cur_ptr|) a pointer to the node for the
5568 corresponding array element, or |null| when no such element exists. The
5569 third parameter |w| is set |true| if the element must exist, e.g.,
5570 because it is about to be modified. The procedure has two main
5571 branches: one follows the existing tree structure, the other (only used
5572 when |w| is |true|) creates the missing nodes.
5573
5574 We use macros to extract the four-bit pieces from a sixteen-bit register
5575 number or mark class and to fetch or store one of the 16 pointers from
5576 an index node.
5577
5578 @d if_cur_ptr_is_null_then_return_or_goto(#)== {some tree element is missing}
5579 begin if cur_ptr=null then
5580 if w then goto #@+else return;
5581 end
5582 @#
5583 @d hex_dig1(#)==# div 4096 {the fourth lowest hexadecimal digit}
5584 @d hex_dig2(#)==(# div 256) mod 16 {the third lowest hexadecimal digit}
5585 @d hex_dig3(#)==(# div 16) mod 16 {the second lowest hexadecimal digit}
5586 @d hex_dig4(#)==# mod 16 {the lowest hexadecimal digit}
5587 @#
5588 @d get_sa_ptr==if odd(i) then cur_ptr:=link(q+(i div 2)+1)
5589 else cur_ptr:=info(q+(i div 2)+1)
5590 {set |cur_ptr| to the pointer indexed by |i| from index node |q|}
5591 @d put_sa_ptr(#)==if odd(i) then link(q+(i div 2)+1):=#
5592 else info(q+(i div 2)+1):=#
5593 {store the pointer indexed by |i| in index node |q|}
5594 @d add_sa_ptr==begin put_sa_ptr(cur_ptr); incr(sa_used(q));
5595 end {add |cur_ptr| as the pointer indexed by |i| in index node |q|}
5596 @d delete_sa_ptr==begin put_sa_ptr(null); decr(sa_used(q));
5597 end {delete the pointer indexed by |i| in index node |q|}
5598
5599 @<Declare \eTeX\ procedures for ex...@>=
5600 procedure find_sa_element(@!t:small_number;@!n:halfword;@!w:boolean);
5601 {sets |cur_val| to sparse array element location or |null|}
5602 label not_found,not_found1,not_found2,not_found3,not_found4,exit;
5603 var q:pointer; {for list manipulations}
5604 @!i:small_number; {a four bit index}
5605 begin cur_ptr:=sa_root[t];
5606 if_cur_ptr_is_null_then_return_or_goto(not_found);@/
5607 q:=cur_ptr; i:=hex_dig1(n); get_sa_ptr;
5608 if_cur_ptr_is_null_then_return_or_goto(not_found1);@/
5609 q:=cur_ptr; i:=hex_dig2(n); get_sa_ptr;
5610 if_cur_ptr_is_null_then_return_or_goto(not_found2);@/
5611 q:=cur_ptr; i:=hex_dig3(n); get_sa_ptr;
5612 if_cur_ptr_is_null_then_return_or_goto(not_found3);@/
5613 q:=cur_ptr; i:=hex_dig4(n); get_sa_ptr;
5614 if (cur_ptr=null)and w then goto not_found4;
5615 return;
5616 not_found: new_index(t,null); {create first level index node}
5617 sa_root[t]:=cur_ptr; q:=cur_ptr; i:=hex_dig1(n);
5618 not_found1: new_index(i,q); {create second level index node}
5619 add_sa_ptr; q:=cur_ptr; i:=hex_dig2(n);
5620 not_found2: new_index(i,q); {create third level index node}
5621 add_sa_ptr; q:=cur_ptr; i:=hex_dig3(n);
5622 not_found3: new_index(i,q); {create fourth level index node}
5623 add_sa_ptr; q:=cur_ptr; i:=hex_dig4(n);
5624 not_found4: @<Create a new array element of type |t| with index |i|@>;
5625 link(cur_ptr):=q; add_sa_ptr;
5626 exit:end;
5627
5628 @ The array elements for registers are subject to grouping and have an
5629 |sa_lev| field (quite analogous to |eq_level|) instead of |sa_used|.
5630 Since saved values as well as shorthand definitions (created by e.g.,
5631 \.{\\countdef}) refer to the location of the respective array element,
5632 we need a reference count that is kept in the |sa_ref| field. An array
5633 element can be deleted (together with all references to it) when its
5634 |sa_ref| value is |null| and its value is the default value.
5635 @^reference counts@>
5636
5637 Skip, muskip, box, and token registers use two word nodes, their values
5638 are stored in the |sa_ptr| field.
5639 Count and dimen registers use three word nodes, their
5640 values are stored in the |sa_int| resp.\ |sa_dim| field in the third
5641 word; the |sa_ptr| field is used under the name |sa_num| to store
5642 the register number. Mark classes use four word nodes. The last three
5643 words contain the five types of current marks
5644
5645 @d sa_lev==sa_used {grouping level for the current value}
5646 @d pointer_node_size=2 {size of an element with a pointer value}
5647 @d sa_type(#)==(sa_index(#) div 16) {type part of combined type/index}
5648 @d sa_ref(#)==info(#+1) {reference count of a sparse array element}
5649 @d sa_ptr(#)==link(#+1) {a pointer value}
5650 @#
5651 @d word_node_size=3 {size of an element with a word value}
5652 @d sa_num==sa_ptr {the register number}
5653 @d sa_int(#)==mem[#+2].int {an integer}
5654 @d sa_dim(#)==mem[#+2].sc {a dimension (a somewhat esotheric distinction)}
5655 @#
5656 @d mark_class_node_size=4 {size of an element for a mark class}
5657 @#
5658 @d fetch_box(#)== {fetch |box(cur_val)|}
5659 if cur_val<256 then #:=box(cur_val)
5660 else begin find_sa_element(box_val,cur_val,false);
5661 if cur_ptr=null then #:=null@+else #:=sa_ptr(cur_ptr);
5662 end
5663
5664 @<Create a new array element...@>=
5665 if t=mark_val then {a mark class}
5666 begin cur_ptr:=get_node(mark_class_node_size);
5667 mem[cur_ptr+1]:=sa_null; mem[cur_ptr+2]:=sa_null; mem[cur_ptr+3]:=sa_null;
5668 end
5669 else begin if t<=dimen_val then {a count or dimen register}
5670 begin cur_ptr:=get_node(word_node_size); sa_int(cur_ptr):=0;
5671 sa_num(cur_ptr):=n;
5672 end
5673 else begin cur_ptr:=get_node(pointer_node_size);
5674 if t<=mu_val then {a skip or muskip register}
5675 begin sa_ptr(cur_ptr):=zero_glue; add_glue_ref(zero_glue);
5676 end
5677 else sa_ptr(cur_ptr):=null; {a box or token list register}
5678 end;
5679 sa_ref(cur_ptr):=null; {all registers have a reference count}
5680 end;
5681 sa_index(cur_ptr):=16*t+i; sa_lev(cur_ptr):=level_one
5682
5683 @ The |delete_sa_ref| procedure is called when a pointer to an array
5684 element representing a register is being removed; this means that the
5685 reference count should be decreased by one. If the reduced reference
5686 count is |null| and the register has been (globally) assigned its
5687 default value the array element should disappear, possibly together with
5688 some index nodes. This procedure will never be used for mark class
5689 nodes.
5690 @^reference counts@>
5691
5692 @d add_sa_ref(#)==incr(sa_ref(#)) {increase reference count}
5693 @#
5694 @d change_box(#)== {change |box(cur_val)|, the |eq_level| stays the same}
5695 if cur_val<256 then box(cur_val):=#@+else set_sa_box(#)
5696 @#
5697 @d set_sa_box(#)==begin find_sa_element(box_val,cur_val,false);
5698 if cur_ptr<>null then
5699 begin sa_ptr(cur_ptr):=#; add_sa_ref(cur_ptr); delete_sa_ref(cur_ptr);
5700 end;
5701 end
5702
5703 @<Declare \eTeX\ procedures for tr...@>=
5704 procedure delete_sa_ref(@!q:pointer); {reduce reference count}
5705 label exit;
5706 var p:pointer; {for list manipulations}
5707 @!i:small_number; {a four bit index}
5708 @!s:small_number; {size of a node}
5709 begin decr(sa_ref(q));
5710 if sa_ref(q)<>null then return;
5711 if sa_index(q)<dimen_val_limit then
5712 if sa_int(q)=0 then s:=word_node_size
5713 else return
5714 else begin if sa_index(q)<mu_val_limit then
5715 if sa_ptr(q)=zero_glue then delete_glue_ref(zero_glue)
5716 else return
5717 else if sa_ptr(q)<>null then return;
5718 s:=pointer_node_size;
5719 end;
5720 repeat i:=hex_dig4(sa_index(q)); p:=q; q:=link(p); free_node(p,s);
5721 if q=null then {the whole tree has been freed}
5722 begin sa_root[i]:=null; return;
5723 end;
5724 delete_sa_ptr; s:=index_node_size; {node |q| is an index node}
5725 until sa_used(q)>0;
5726 exit:end;
5727
5728 @ The |print_sa_num| procedure prints the register number corresponding
5729 to an array element.
5730
5731 @<Basic print...@>=
5732 procedure print_sa_num(@!q:pointer); {print register number}
5733 var @!n:halfword; {the register number}
5734 begin if sa_index(q)<dimen_val_limit then n:=sa_num(q) {the easy case}
5735 else begin n:=hex_dig4(sa_index(q)); q:=link(q); n:=n+16*sa_index(q);
5736 q:=link(q); n:=n+256*(sa_index(q)+16*sa_index(link(q)));
5737 end;
5738 print_int(n);
5739 end;
5740
5741 @ Here is a procedure that displays the contents of an array element
5742 symbolically. It is used under similar circumstances as is
5743 |restore_trace| (together with |show_eqtb|) for the quantities kept in
5744 the |eqtb| array.
5745
5746 @<Declare \eTeX\ procedures for tr...@>=
5747 @!stat procedure show_sa(@!p:pointer;@!s:str_number);
5748 var t:small_number; {the type of element}
5749 begin begin_diagnostic; print_char("{"); print(s); print_char(" ");
5750 if p=null then print_char("?") {this can't happen}
5751 else begin t:=sa_type(p);
5752 if t<box_val then print_cmd_chr(register,p)
5753 else if t=box_val then
5754 begin print_esc("box"); print_sa_num(p);
5755 end
5756 else if t=tok_val then print_cmd_chr(toks_register,p)
5757 else print_char("?"); {this can't happen either}
5758 print_char("=");
5759 if t=int_val then print_int(sa_int(p))
5760 else if t=dimen_val then
5761 begin print_scaled(sa_dim(p)); print("pt");
5762 end
5763 else begin p:=sa_ptr(p);
5764 if t=glue_val then print_spec(p,"pt")
5765 else if t=mu_val then print_spec(p,"mu")
5766 else if t=box_val then
5767 if p=null then print("void")
5768 else begin depth_threshold:=0; breadth_max:=1; show_node_list(p);
5769 end
5770 else if t=tok_val then
5771 begin if p<>null then show_token_list(link(p),null,32);
5772 end
5773 else print_char("?"); {this can't happen either}
5774 end;
5775 end;
5776 print_char("}"); end_diagnostic(false);
5777 end;
5778 tats
5779
5780 @ Here we compute the pointer to the current mark of type |t| and mark
5781 class |cur_val|.
5782
5783 @<Compute the mark pointer...@>=
5784 begin find_sa_element(mark_val,cur_val,false);
5785 if cur_ptr<>null then
5786 if odd(t) then cur_ptr:=link(cur_ptr+(t div 2)+1)
5787 else cur_ptr:=info(cur_ptr+(t div 2)+1);
5788 end
5789
5790 @ The current marks for all mark classes are maintained by the |vsplit|
5791 and |fire_up| routines and are finally destroyed (for \.{INITEX} only)
5792 @.INITEX@>
5793 by the |final_cleanup| routine. Apart from updating the current marks
5794 when mark nodes are encountered, these routines perform certain actions
5795 on all existing mark classes. The recursive |do_marks| procedure walks
5796 through the whole tree or a subtree of existing mark class nodes and
5797 preforms certain actions indicted by its first parameter |a|, the action
5798 code. The second parameter |l| indicates the level of recursion (at
5799 most four); the third parameter points to a nonempty tree or subtree.
5800 The result is |true| if the complete tree or subtree has been deleted.
5801
5802 @d vsplit_init==0 {action code for |vsplit| initialization}
5803 @d fire_up_init==1 {action code for |fire_up| initialization}
5804 @d fire_up_done==2 {action code for |fire_up| completion}
5805 @d destroy_marks==3 {action code for |final_cleanup|}
5806 @#
5807 @d sa_top_mark(#)==info(#+1) {\.{\\topmarks}|n|}
5808 @d sa_first_mark(#)==link(#+1) {\.{\\firstmarks}|n|}
5809 @d sa_bot_mark(#)==info(#+2) {\.{\\botmarks}|n|}
5810 @d sa_split_first_mark(#)==link(#+2) {\.{\\splitfirstmarks}|n|}
5811 @d sa_split_bot_mark(#)==info(#+3) {\.{\\splitbotmarks}|n|}
5812
5813 @<Declare the function called |do_marks|@>=
5814 function do_marks(@!a,@!l:small_number;@!q:pointer):boolean;
5815 var i:small_number; {a four bit index}
5816 begin if l<4 then {|q| is an index node}
5817 begin for i:=0 to 15 do
5818 begin get_sa_ptr;
5819 if cur_ptr<>null then if do_marks(a,l+1,cur_ptr) then delete_sa_ptr;
5820 end;
5821 if sa_used(q)=0 then
5822 begin free_node(q,index_node_size); q:=null;
5823 end;
5824 end
5825 else {|q| is the node for a mark class}
5826 begin case a of
5827 @<Cases for |do_marks|@>@;
5828 end; {there are no other cases}
5829 if sa_bot_mark(q)=null then if sa_split_bot_mark(q)=null then
5830 begin free_node(q,mark_class_node_size); q:=null;
5831 end;
5832 end;
5833 do_marks:=(q=null);
5834 end;
5835
5836 @ At the start of the |vsplit| routine the existing |split_fist_mark|
5837 and |split_bot_mark| are discarded.
5838
5839 @<Cases for |do_marks|@>=
5840 vsplit_init: if sa_split_first_mark(q)<>null then
5841 begin delete_token_ref(sa_split_first_mark(q)); sa_split_first_mark(q):=null;
5842 delete_token_ref(sa_split_bot_mark(q)); sa_split_bot_mark(q):=null;
5843 end;
5844
5845 @ We use again the fact that |split_first_mark=null| if and only if
5846 |split_bot_mark=null|.
5847
5848 @<Update the current marks for |vsplit|@>=
5849 begin find_sa_element(mark_val,mark_class(p),true);
5850 if sa_split_first_mark(cur_ptr)=null then
5851 begin sa_split_first_mark(cur_ptr):=mark_ptr(p);
5852 add_token_ref(mark_ptr(p));
5853 end
5854 else delete_token_ref(sa_split_bot_mark(cur_ptr));
5855 sa_split_bot_mark(cur_ptr):=mark_ptr(p);
5856 add_token_ref(mark_ptr(p));
5857 end
5858
5859 @ At the start of the |fire_up| routine the old |top_mark| and
5860 |first_mark| are discarded, whereas the old |bot_mark| becomes the new
5861 |top_mark|. An empty new |top_mark| token list is, however, discarded
5862 as well in order that mark class nodes can eventually be released. We
5863 use again the fact that |bot_mark<>null| implies |first_mark<>null|; it
5864 also knows that |bot_mark=null| implies |top_mark=first_mark=null|.
5865
5866 @<Cases for |do_marks|@>=
5867 fire_up_init: if sa_bot_mark(q)<>null then
5868 begin if sa_top_mark(q)<>null then delete_token_ref(sa_top_mark(q));
5869 delete_token_ref(sa_first_mark(q)); sa_first_mark(q):=null;
5870 if link(sa_bot_mark(q))=null then {an empty token list}
5871 begin delete_token_ref(sa_bot_mark(q)); sa_bot_mark(q):=null;
5872 end
5873 else add_token_ref(sa_bot_mark(q));
5874 sa_top_mark(q):=sa_bot_mark(q);
5875 end;
5876
5877 @ @<Cases for |do_marks|@>=
5878 fire_up_done: if (sa_top_mark(q)<>null)and(sa_first_mark(q)=null) then
5879 begin sa_first_mark(q):=sa_top_mark(q); add_token_ref(sa_top_mark(q));
5880 end;
5881
5882 @ @<Update the current marks for |fire_up|@>=
5883 begin find_sa_element(mark_val,mark_class(p),true);
5884 if sa_first_mark(cur_ptr)=null then
5885 begin sa_first_mark(cur_ptr):=mark_ptr(p);
5886 add_token_ref(mark_ptr(p));
5887 end;
5888 if sa_bot_mark(cur_ptr)<>null then delete_token_ref(sa_bot_mark(cur_ptr));
5889 sa_bot_mark(cur_ptr):=mark_ptr(p); add_token_ref(mark_ptr(p));
5890 end
5891
5892 @ Here we use the fact that the five current mark pointers in a mark
5893 class node occupy the same locations as the the first five pointers of
5894 an index node. For systems using a run-time switch to distinguish
5895 between \.{VIRTEX} and \.{INITEX}, the codewords `$|init|\ldots|tini|$'
5896 surrounding the following piece of code should be removed.
5897 @.INITEX@>
5898 @^system dependencies@>
5899
5900 @<Cases for |do_marks|@>=
5901 @!init destroy_marks: for i:=top_mark_code to split_bot_mark_code do
5902 begin get_sa_ptr;
5903 if cur_ptr<>null then
5904 begin delete_token_ref(cur_ptr); put_sa_ptr(null);
5905 end;
5906 end;
5907 tini
5908
5909 @ The command code |register| is used for `\.{\\count}', `\.{\\dimen}',
5910 etc., as well as for references to sparse array elements defined by
5911 `\.{\\countdef}', etc.
5912
5913 @<Cases of |register| for |print_cmd_chr|@>=
5914 begin if (chr_code<mem_bot)or(chr_code>lo_mem_stat_max) then
5915 cmd:=sa_type(chr_code)
5916 else begin cmd:=chr_code-mem_bot; chr_code:=null;
5917 end;
5918 if cmd=int_val then print_esc("count")
5919 else if cmd=dimen_val then print_esc("dimen")
5920 else if cmd=glue_val then print_esc("skip")
5921 else print_esc("muskip");
5922 if chr_code<>null then print_sa_num(chr_code);
5923 end
5924
5925 @ Similarly the command code |toks_register| is used for `\.{\\toks}' as
5926 well as for references to sparse array elements defined by
5927 `\.{\\toksdef}'.
5928
5929 @<Cases of |toks_register| for |print_cmd_chr|@>=
5930 begin print_esc("toks");
5931 if chr_code<>mem_bot then print_sa_num(chr_code);
5932 end
5933
5934 @ When a shorthand definition for an element of one of the sparse arrays
5935 is destroyed, we must reduce the reference count.
5936
5937 @<Cases for |eq_destroy|@>=
5938 toks_register,register:
5939 if (equiv_field(w)<mem_bot)or(equiv_field(w)>lo_mem_stat_max) then
5940 delete_sa_ref(equiv_field(w));
5941
5942 @ The task to maintain (change, save, and restore) register values is
5943 essentially the same when the register is realized as sparse array
5944 element or entry in |eqtb|. The global variable |sa_chain| is the head
5945 of a linked list of entries saved at the topmost level |sa_level|; the
5946 lists for lowel levels are kept in special save stack entries.
5947
5948 @<Glob...@>=
5949 @!sa_chain: pointer; {chain of saved sparse array entries}
5950 @!sa_level: quarterword; {group level for |sa_chain|}
5951
5952 @ @<Set init...@>=
5953 sa_chain:=null; sa_level:=level_zero;
5954
5955 @ The individual saved items are kept in pointer or word nodes similar
5956 to those used for the array elements: a word node with value zero is,
5957 however, saved as pointer node with the otherwise impossible |sa_index|
5958 value |tok_val_limit|.
5959
5960 @d sa_loc==sa_ref {location of saved item}
5961
5962 @<Declare \eTeX\ procedures for tr...@>=
5963 procedure sa_save(@!p:pointer); {saves value of |p|}
5964 var q:pointer; {the new save node}
5965 @!i:quarterword; {index field of node}
5966 begin if cur_level<>sa_level then
5967 begin check_full_save_stack; save_type(save_ptr):=restore_sa;
5968 save_level(save_ptr):=sa_level; save_index(save_ptr):=sa_chain;
5969 incr(save_ptr); sa_chain:=null; sa_level:=cur_level;
5970 end;
5971 i:=sa_index(p);
5972 if i<dimen_val_limit then
5973 begin if sa_int(p)=0 then
5974 begin q:=get_node(pointer_node_size); i:=tok_val_limit;
5975 end
5976 else begin q:=get_node(word_node_size); sa_int(q):=sa_int(p);
5977 end;
5978 sa_ptr(q):=null;
5979 end
5980 else begin q:=get_node(pointer_node_size); sa_ptr(q):=sa_ptr(p);
5981 end;
5982 sa_loc(q):=p; sa_index(q):=i; sa_lev(q):=sa_lev(p);
5983 link(q):=sa_chain; sa_chain:=q; add_sa_ref(p);
5984 end;
5985
5986 @ @<Declare \eTeX\ procedures for tr...@>=
5987 procedure sa_destroy(@!p:pointer); {destroy value of |p|}
5988 begin if sa_index(p)<mu_val_limit then delete_glue_ref(sa_ptr(p))
5989 else if sa_ptr(p)<>null then
5990 if sa_index(p)<box_val_limit then flush_node_list(sa_ptr(p))
5991 else delete_token_ref(sa_ptr(p));
5992 end;
5993
5994 @ The procedure |sa_def| assigns a new value to sparse array elements,
5995 and saves the former value if appropriate. This procedure is used only
5996 for skip, muskip, box, and token list registers. The counterpart of
5997 |sa_def| for count and dimen registers is called |sa_w_def|.
5998
5999 @d sa_define(#)==if e then
6000 if global then gsa_def(#)@+else sa_def(#)
6001 else define
6002 @#
6003 @d sa_def_box== {assign |cur_box| to |box(cur_val)|}
6004 begin find_sa_element(box_val,cur_val,true);
6005 if global then gsa_def(cur_ptr,cur_box)@+else sa_def(cur_ptr,cur_box);
6006 end
6007 @#
6008 @d sa_word_define(#)==if e then
6009 if global then gsa_w_def(#)@+else sa_w_def(#)
6010 else word_define(#)
6011
6012 @<Declare \eTeX\ procedures for tr...@>=
6013 procedure sa_def(@!p:pointer;@!e:halfword);
6014 {new data for sparse array elements}
6015 begin add_sa_ref(p);
6016 if sa_ptr(p)=e then
6017 begin @!stat if tracing_assigns>0 then show_sa(p,"reassigning");@+tats@;@/
6018 sa_destroy(p);
6019 end
6020 else begin @!stat if tracing_assigns>0 then show_sa(p,"changing");@+tats@;@/
6021 if sa_lev(p)=cur_level then sa_destroy(p)@+else sa_save(p);
6022 sa_lev(p):=cur_level; sa_ptr(p):=e;
6023 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
6024 end;
6025 delete_sa_ref(p);
6026 end;
6027 @#
6028 procedure sa_w_def(@!p:pointer;@!w:integer);
6029 begin add_sa_ref(p);
6030 if sa_int(p)=w then
6031 begin @!stat if tracing_assigns>0 then show_sa(p,"reassigning");@+tats@;@/
6032 end
6033 else begin @!stat if tracing_assigns>0 then show_sa(p,"changing");@+tats@;@/
6034 if sa_lev(p)<>cur_level then sa_save(p);
6035 sa_lev(p):=cur_level; sa_int(p):=w;
6036 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
6037 end;
6038 delete_sa_ref(p);
6039 end;
6040
6041 @ The |sa_def| and |sa_w_def| routines take care of local definitions.
6042 @^global definitions@>
6043 Global definitions are done in almost the same way, but there is no need
6044 to save old values, and the new value is associated with |level_one|.
6045
6046 @<Declare \eTeX\ procedures for tr...@>=
6047 procedure gsa_def(@!p:pointer;@!e:halfword); {global |sa_def|}
6048 begin add_sa_ref(p);
6049 @!stat if tracing_assigns>0 then show_sa(p,"globally changing");@+tats@;@/
6050 sa_destroy(p); sa_lev(p):=level_one; sa_ptr(p):=e;
6051 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
6052 delete_sa_ref(p);
6053 end;
6054 @#
6055 procedure gsa_w_def(@!p:pointer;@!w:integer); {global |sa_w_def|}
6056 begin add_sa_ref(p);
6057 @!stat if tracing_assigns>0 then show_sa(p,"globally changing");@+tats@;@/
6058 sa_lev(p):=level_one; sa_int(p):=w;
6059 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
6060 delete_sa_ref(p);
6061 end;
6062
6063 @ The |sa_restore| procedure restores the sparse array entries pointed
6064 at by |sa_chain|
6065
6066 @<Declare \eTeX\ procedures for tr...@>=
6067 procedure sa_restore;
6068 var p:pointer; {sparse array element}
6069 begin repeat p:=sa_loc(sa_chain);
6070 if sa_lev(p)=level_one then
6071 begin if sa_index(p)>=dimen_val_limit then sa_destroy(sa_chain);
6072 @!stat if tracing_restores>0 then show_sa(p,"retaining");@+tats@;@/
6073 end
6074 else begin if sa_index(p)<dimen_val_limit then
6075 if sa_index(sa_chain)<dimen_val_limit then sa_int(p):=sa_int(sa_chain)
6076 else sa_int(p):=0
6077 else begin sa_destroy(p); sa_ptr(p):=sa_ptr(sa_chain);
6078 end;
6079 sa_lev(p):=sa_lev(sa_chain);
6080 @!stat if tracing_restores>0 then show_sa(p,"restoring");@+tats@;@/
6081 end;
6082 delete_sa_ref(p);
6083 p:=sa_chain; sa_chain:=link(p);
6084 if sa_index(p)<dimen_val_limit then free_node(p,word_node_size)
6085 else free_node(p,pointer_node_size);
6086 until sa_chain=null;
6087 end;
6088
6089 @ When the value of |last_line_fit| is positive, the last line of a
6090 (partial) paragraph is treated in a special way and we need additional
6091 fields in the active nodes.
6092
6093 @d active_node_size_extended=5 {number of words in extended active nodes}
6094 @d active_short(#)==mem[#+3].sc {|shortfall| of this line}
6095 @d active_glue(#)==mem[#+4].sc {corresponding glue stretch or shrink}
6096
6097 @<Glob...@>=
6098 @!last_line_fill:pointer; {the |par_fill_skip| glue node of the new paragraph}
6099 @!do_last_line_fit:boolean; {special algorithm for last line of paragraph?}
6100 @!active_node_size:small_number; {number of words in active nodes}
6101 @!fill_width:array[0..2] of scaled; {infinite stretch components of
6102 |par_fill_skip|}
6103 @!best_pl_short:array[very_loose_fit..tight_fit] of scaled; {|shortfall|
6104 corresponding to |minimal_demerits|}
6105 @!best_pl_glue:array[very_loose_fit..tight_fit] of scaled; {corresponding
6106 glue stretch or shrink}
6107
6108 @ The new algorithm for the last line requires that the stretchability of
6109 |par_fill_skip| is infinite and the stretchability of |left_skip| plus
6110 |right_skip| is finite.
6111
6112 @<Check for special...@>=
6113 do_last_line_fit:=false; active_node_size:=active_node_size_normal;
6114 {just in case}
6115 if last_line_fit>0 then
6116 begin q:=glue_ptr(last_line_fill);
6117 if (stretch(q)>0)and(stretch_order(q)>normal) then
6118 if (background[3]=0)and(background[4]=0)and(background[5]=0) then
6119 begin do_last_line_fit:=true;
6120 active_node_size:=active_node_size_extended;
6121 fill_width[0]:=0; fill_width[1]:=0; fill_width[2]:=0;
6122 fill_width[stretch_order(q)-1]:=stretch(q);
6123 end;
6124 end
6125
6126 @ @<Other local variables for |try_break|@>=
6127 @!g:scaled; {glue stretch or shrink of test line, adjustment for last line}
6128
6129 @ Here we initialize the additional fields of the first active node
6130 representing the beginning of the paragraph.
6131
6132 @<Initialize additional fields of the first active node@>=
6133 begin active_short(q):=0; active_glue(q):=0;
6134 end
6135
6136 @ Here we compute the adjustment |g| and badness |b| for a line from |r|
6137 to the end of the paragraph. When any of the criteria for adjustment is
6138 violated we fall through to the normal algorithm.
6139
6140 The last line must be too short, and have infinite stretch entirely due
6141 to |par_fill_skip|.
6142
6143 @<Perform computations for last line and |goto found|@>=
6144 begin if (active_short(r)=0)or(active_glue(r)<=0) then goto not_found;
6145 {previous line was neither stretched nor shrunk, or was infinitely bad}
6146 if (cur_active_width[3]<>fill_width[0])or@|
6147 (cur_active_width[4]<>fill_width[1])or@|
6148 (cur_active_width[5]<>fill_width[2]) then goto not_found;
6149 {infinite stretch of this line not entirely due to |par_fill_skip|}
6150 if active_short(r)>0 then g:=cur_active_width[2]
6151 else g:=cur_active_width[6];
6152 if g<=0 then goto not_found; {no finite stretch resp.\ no shrink}
6153 arith_error:=false; g:=fract(g,active_short(r),active_glue(r),max_dimen);
6154 if last_line_fit<1000 then g:=fract(g,last_line_fit,1000,max_dimen);
6155 if arith_error then
6156 if active_short(r)>0 then g:=max_dimen@+else g:=-max_dimen;
6157 if g>0 then
6158 @<Set the value of |b| to the badness of the last line for stretching,
6159 compute the corresponding |fit_class|, and |goto found|@>
6160 else if g<0 then
6161 @<Set the value of |b| to the badness of the last line for shrinking,
6162 compute the corresponding |fit_class|, and |goto found|@>;
6163 not_found:end
6164
6165 @ These badness computations are rather similar to those of the standard
6166 algorithm, with the adjustment amount |g| replacing the |shortfall|.
6167
6168 @<Set the value of |b| to the badness of the last line for str...@>=
6169 begin if g>shortfall then g:=shortfall;
6170 if g>7230584 then if cur_active_width[2]<1663497 then
6171 begin b:=inf_bad; fit_class:=very_loose_fit; goto found;
6172 end;
6173 b:=badness(g,cur_active_width[2]);
6174 if b>12 then
6175 if b>99 then fit_class:=very_loose_fit
6176 else fit_class:=loose_fit
6177 else fit_class:=decent_fit;
6178 goto found;
6179 end
6180
6181 @ @<Set the value of |b| to the badness of the last line for shr...@>=
6182 begin if -g>cur_active_width[6] then g:=-cur_active_width[6];
6183 b:=badness(-g,cur_active_width[6]);
6184 if b>12 then fit_class:=tight_fit@+else fit_class:=decent_fit;
6185 goto found;
6186 end
6187
6188 @ Vanishing values of |shortfall| and |g| indicate that the last line is
6189 not adjusted.
6190
6191 @<Adjust \(t)the additional data for last line@>=
6192 begin if cur_p=null then shortfall:=0;
6193 if shortfall>0 then g:=cur_active_width[2]
6194 else if shortfall<0 then g:=cur_active_width[6]
6195 else g:=0;
6196 end
6197
6198 @ For each feasible break we record the shortfall and glue stretch or
6199 shrink (or adjustment).
6200
6201 @<Store \(a)additional data for this feasible break@>=
6202 begin best_pl_short[fit_class]:=shortfall; best_pl_glue[fit_class]:=g;
6203 end
6204
6205 @ Here we save these data in the active node representing a potential
6206 line break.
6207
6208 @<Store \(a)additional data in the new active node@>=
6209 begin active_short(q):=best_pl_short[fit_class];
6210 active_glue(q):=best_pl_glue[fit_class];
6211 end
6212
6213 @ @<Print additional data in the new active node@>=
6214 begin print(" s="); print_scaled(active_short(q));
6215 if cur_p=null then print(" a=")@+else print(" g=");
6216 print_scaled(active_glue(q));
6217 end
6218
6219 @ Here we either reset |do_last_line_fit| or adjust the |par_fill_skip|
6220 glue.
6221
6222 @<Adjust \(t)the final line of the paragraph@>=
6223 if active_short(best_bet)=0 then do_last_line_fit:=false
6224 else begin q:=new_spec(glue_ptr(last_line_fill));
6225 delete_glue_ref(glue_ptr(last_line_fill));
6226 width(q):=width(q)+active_short(best_bet)-active_glue(best_bet);
6227 stretch(q):=0; glue_ptr(last_line_fill):=q;
6228 end
6229
6230 @ When reading \.{\\patterns} while \.{\\savinghyphcodes} is positive
6231 the current |lc_code| values are stored together with the hyphenation
6232 patterns for the current language. They will later be used instead of
6233 the |lc_code| values for hyphenation purposes.
6234
6235 The |lc_code| values are stored in the linked trie analogous to patterns
6236 $p_1$ of length~1, with |hyph_root=trie_r[0]| replacing |trie_root| and
6237 |lc_code(p_1)| replacing the |trie_op| code. This allows to compress
6238 and pack them together with the patterns with minimal changes to the
6239 existing code.
6240
6241 @d hyph_root==trie_r[0] {root of the linked trie for |hyph_codes|}
6242
6243 @<Initialize table entries...@>=
6244 hyph_root:=0; hyph_start:=0;
6245
6246 @ @<Store hyphenation codes for current language@>=
6247 begin c:=cur_lang; first_child:=false; p:=0;
6248 repeat q:=p; p:=trie_r[q];
6249 until (p=0)or(c<=so(trie_c[p]));
6250 if (p=0)or(c<so(trie_c[p])) then
6251 @<Insert a new trie node between |q| and |p|, and
6252 make |p| point to it@>;
6253 q:=p; {now node |q| represents |cur_lang|}
6254 @<Store all current |lc_code| values@>;
6255 end
6256
6257 @ We store all nonzero |lc_code| values, overwriting any previously
6258 stored values (and possibly wasting a few trie nodes that were used
6259 previously and are not needed now). We always store at least one
6260 |lc_code| value such that |hyph_index| (defined below) will not be zero.
6261
6262 @<Store all current |lc_code| values@>=
6263 p:=trie_l[q]; first_child:=true;
6264 for c:=0 to 255 do
6265 if (lc_code(c)>0)or((c=255)and first_child) then
6266 begin if p=0 then
6267 @<Insert a new trie node between |q| and |p|, and
6268 make |p| point to it@>
6269 else trie_c[p]:=si(c);
6270 trie_o[p]:=qi(lc_code(c));
6271 q:=p; p:=trie_r[q]; first_child:=false;
6272 end;
6273 if first_child then trie_l[q]:=0@+else trie_r[q]:=0
6274
6275 @ We must avoid to ``take'' location~1, in order to distinguish between
6276 |lc_code| values and patterns.
6277
6278 @<Pack all stored |hyph_codes|@>=
6279 begin if trie_root=0 then for p:=0 to 255 do trie_min[p]:=p+2;
6280 first_fit(hyph_root); trie_pack(hyph_root);
6281 hyph_start:=trie_ref[hyph_root];
6282 end
6283
6284 @ The global variable |hyph_index| will point to the hyphenation codes
6285 for the current language.
6286
6287 @d set_hyph_index== {set |hyph_index| for current language}
6288 if trie_char(hyph_start+cur_lang)<>qi(cur_lang)
6289 then hyph_index:=0 {no hyphenation codes for |cur_lang|}
6290 else hyph_index:=trie_link(hyph_start+cur_lang)
6291 @#
6292 @d set_lc_code(#)== {set |hc[0]| to hyphenation or lc code for |#|}
6293 if hyph_index=0 then hc[0]:=lc_code(#)
6294 else if trie_char(hyph_index+#)<>qi(#) then hc[0]:=0
6295 else hc[0]:=qo(trie_op(hyph_index+#))
6296
6297 @<Glob...@>=
6298 @!hyph_start:trie_pointer; {root of the packed trie for |hyph_codes|}
6299 @!hyph_index:trie_pointer; {pointer to hyphenation codes for |cur_lang|}
6300
6301 @ When |saving_vdiscards| is positive then the glue, kern, and penalty
6302 nodes removed by the page builder or by \.{\\vsplit} from the top of a
6303 vertical list are saved in special lists instead of being discarded.
6304
6305 @d tail_page_disc==disc_ptr[copy_code] {last item removed by page builder}
6306 @d page_disc==disc_ptr[last_box_code] {first item removed by page builder}
6307 @d split_disc==disc_ptr[vsplit_code] {first item removed by \.{\\vsplit}}
6308
6309 @<Glob...@>=
6310 @!disc_ptr:array[copy_code..vsplit_code] of pointer; {list pointers}
6311
6312 @ @<Set init...@>=
6313 page_disc:=null; split_disc:=null;
6314
6315 @ The \.{\\pagediscards} and \.{\\splitdiscards} commands share the
6316 command code |un_vbox| with \.{\\unvbox} and \.{\\unvcopy}, they are
6317 distinguished by their |chr_code| values |last_box_code| and
6318 |vsplit_code|. These |chr_code| values are larger than |box_code| and
6319 |copy_code|.
6320
6321 @<Generate all \eTeX...@>=
6322 primitive("pagediscards",un_vbox,last_box_code);@/
6323 @!@:page_discards_}{\.{\\pagediscards} primitive@>
6324 primitive("splitdiscards",un_vbox,vsplit_code);@/
6325 @!@:split_discards_}{\.{\\splitdiscards} primitive@>
6326
6327 @ @<Cases of |un_vbox| for |print_cmd_chr|@>=
6328 else if chr_code=last_box_code then print_esc("pagediscards")
6329 else if chr_code=vsplit_code then print_esc("splitdiscards")
6330
6331 @ @<Handle saved items and |goto done|@>=
6332 begin link(tail):=disc_ptr[cur_chr]; disc_ptr[cur_chr]:=null;
6333 goto done;
6334 end
6335
6336 @ The \.{\\interlinepenalties}, \.{\\clubpenalties}, \.{\\widowpenalties},
6337 and \.{\\displaywidowpenalties} commands allow to define arrays of
6338 penalty values to be used instead of the corresponding single values.
6339
6340 @d inter_line_penalties_ptr==equiv(inter_line_penalties_loc)
6341 @d club_penalties_ptr==equiv(club_penalties_loc)
6342 @d widow_penalties_ptr==equiv(widow_penalties_loc)
6343 @d display_widow_penalties_ptr==equiv(display_widow_penalties_loc)
6344
6345 @<Generate all \eTeX...@>=
6346 primitive("interlinepenalties",set_shape,inter_line_penalties_loc);@/
6347 @!@:inter_line_penalties_}{\.{\\interlinepenalties} primitive@>
6348 primitive("clubpenalties",set_shape,club_penalties_loc);@/
6349 @!@:club_penalties_}{\.{\\clubpenalties} primitive@>
6350 primitive("widowpenalties",set_shape,widow_penalties_loc);@/
6351 @!@:widow_penalties_}{\.{\\widowpenalties} primitive@>
6352 primitive("displaywidowpenalties",set_shape,display_widow_penalties_loc);@/
6353 @!@:display_widow_penalties_}{\.{\\displaywidowpenalties} primitive@>
6354
6355 @ @<Cases of |set_shape| for |print_cmd_chr|@>=
6356 inter_line_penalties_loc: print_esc("interlinepenalties");
6357 club_penalties_loc: print_esc("clubpenalties");
6358 widow_penalties_loc: print_esc("widowpenalties");
6359 display_widow_penalties_loc: print_esc("displaywidowpenalties");
6360
6361 @ @<Fetch a penalties array element@>=
6362 begin scan_int;
6363 if (equiv(m)=null)or(cur_val<0) then cur_val:=0
6364 else begin if cur_val>penalty(equiv(m)) then cur_val:=penalty(equiv(m));
6365 cur_val:=penalty(equiv(m)+cur_val);
6366 end;
6367 end
6368
6369 @* \[54] System-dependent changes.
6370 @z
6371 %---------------------------------------