Debian Codegraph @

texk/web2c/alephdir/eobase.ch

raw
1 % vim: ft=change
2 % TODO: sparse arrays
3 % This is the first of the set of
4 % WEB change file containing code for various features extending Omega;
5 % these files define the Aleph program, and are designed to be applied
6 % to omega.web compiled without XML support.
7 % This change-file is heavily based on etex.ch,
8 % defining version 2.1 of e-TeX.
9
10 % ATTENTION: The software is currently in pre-alpha stage.
11
12 % The TeX program is copyright (C) 1982 by D. E. Knuth.
13 % TeX is a trademark of the American Mathematical Society.
14 % e-TeX and NTS are trademarks of the NTS group.
15
16 % All line numbers refer to TEX.WEB 3.14159 as of March 21, 1995.
17 % TODO: double line number reference, having them for both TEX.WEB
18 % and (X)OMEGA.WEB
19
20 @x limbo l.1 - this is Aleph
21 % (C) 1994--2000 by John Plaice and Yannis Haralambous.
22 @y
23 % (C) 2002--2004 by Giuseppe Bilotta and the Aleph task force;
24 % all rights are reserved.
25 %
26 % Aleph is directly derived from e-TeX, an extension of
27 % Donald E. Knuth's TeX developed by Peter Breitenlohner and
28 % the NTS team, and Omega, another extension of TeX, developed by
29 % John Plaice and Yannis Haralambous.
30
31 % Aleph is designed in the form of a set of WEB changefiles
32 % to be applied to Omega
33 % compiled without XML support. The changefiles are heavily based
34 % on the e-TeX 2.1 changefiles.
35
36 % Omega is copyright (C) 1994--2000 by John Plaice and Yannis Haralambous.
37 @z
38 %---------------------------------------
39 @x limbo l.1 - this is e-TeX
40 %
41 % This program is copyright (C) 1982 by D. E. Knuth; all rights are reserved.
42 % Unlimited copying and redistribution of this file are permitted as long
43 % as this file is not modified. Modifications are permitted, but only if
44 % the resulting file is not named tex.web. (The WEB system provides
45 % for alterations via an auxiliary file; the master file should stay intact.)
46 % See Appendix H of the WEB manual for hints on how to install this program.
47 % And see Appendix A of the TRIP manual for details about how to validate it.
48
49 % TeX is a trademark of the American Mathematical Society.
50 % METAFONT is a trademark of Addison-Wesley Publishing Company.
51 @y
52 % e-TeX is copyright (C) 1999-2012 by P. Breitenlohner (1994,98 by the NTS
53 % team); all rights are reserved.
54
55 % e-TeX and NTS are trademarks of the NTS group.
56 % TeX is a trademark of the American Mathematical Society.
57 % METAFONT is a trademark of Addison-Wesley Publishing Company.
58
59 % e-TeX is directly derived from Donald E. Knuth's TeX;
60 % the change history which follows and the reward offered for finders of
61 % bugs refer specifically to TeX; they should not be taken as referring
62 % to e-TeX, although the change history is relevant in that it
63 % demonstrates the evolutionary path followed. This program is not TeX;
64 % that name is reserved strictly for the program which is the creation
65 % and sole responsibility of Professor Knuth.
66 @z
67 %---------------------------------------
68 @x limbo l.50 - e-TeX history
69 % Although considerable effort has been expended to make the TeX program
70 % correct and reliable, no warranty is implied; the author disclaims any
71 % obligation or liability for damages, including but not limited to
72 % special, indirect, or consequential damages arising out of or in
73 % connection with the use or performance of this software. This work has
74 % been a ``labor of love'' and the author hopes that users enjoy it.
75 @y
76 % A preliminary version of TeX--XeT was released in April 1992.
77 % TeX--XeT version 1.0 was released in June 1992,
78 % version 1.1 prevented arith overflow in glue computation (Oct 1992).
79 % A preliminary e-TeX version 0.95 was operational in March 1994.
80 % Version 1.0beta was released in May 1995.
81 % Version 1.01beta fixed bugs in just_copy and every_eof (December 1995).
82 % Version 1.02beta allowed 256 mark classes (March 1996).
83 % Version 1.1 changed \group{type,level} -> \currentgroup{type,level},
84 % first public release (October 1996).
85 % Version 2.0 development was started in March 1997;
86 % fixed a ligature-\beginR bug in January 1998;
87 % was released in March 1998.
88 % Version 2.1 fixed a marks bug (when min_halfword<>0) (January 1999).
89
90 % Aleph includes all the e-TeX extensions, except for TeX--XeT and
91 % some optimizations.
92
93 % Release Candidate 0 was released in Janurary 2003.
94 % Release Candidate 1 was released in June 2003.
95 % fixed Omega overfull box bug
96 % Release Candidate 2 has to be released
97 % fixed Omega overfull rule bug
98 % fixed Omega leader tripping bug
99 % reorganized source code
100
101 % Although considerable effort has been expended to make the Aleph program
102 % correct and reliable, no warranty is implied; the authors disclaim any
103 % obligation or liability for damages, including but not limited to
104 % special, indirect, or consequential damages arising out of or in
105 % connection with the use or performance of this software. This work has
106 % been a ``labor of love'' and the authors hope that users enjoy it.
107 @z
108 %---------------------------------------
109 @x limbo l.61 - e-TeX logo, TeXXeT
110 \let\mc=\ninerm % medium caps for names like SAIL
111 @y
112 \let\mc=\ninerm % medium caps for names like SAIL
113 \def\eTeX{$\varepsilon$-\TeX}
114 \def\Aleph{$\aleph$}
115 % \font\revrm=xbmc10 % for right-to-left text
116 % % to generate xbmc10 (i.e., reflected cmbx10) use a file
117 % % xbmc10.mf containing:
118 % %+++++++++++++++++++++++++++++++++++++++++++++++++
119 % % if unknown cmbase: input cmbase fi
120 % % extra_endchar := extra_endchar &
121 % % "currentpicture:=currentpicture " &
122 % % "reflectedabout((.5[l,r],0),(.5[l,r],1));";
123 % % input cmbx10
124 % %+++++++++++++++++++++++++++++++++++++++++++++++++
125 % \ifx\beginL\undefined % this is TeX
126 \def\XeT{X\kern-.125em\lower.5ex\hbox{E}\kern-.1667emT}
127 \def\TeXeT{\TeX-\hbox{\revrm \XeT}} % for TeX-XeT
128 \def\TeXXeT{\TeX-\hbox{\revrm -\XeT}} % for TeX--XeT
129 % \else
130 % \ifx\eTeXversion\undefined % this is \TeXeT
131 % \def\TeXeT{\TeX-{\revrm\beginR\TeX\endR}} % for TeX-XeT
132 % \def\TeXXeT{\TeX-{\revrm\beginR\TeX-\endR}} % for TeX--XeT
133 % \else % this is \eTeX
134 % \def\TeXeT{\TeX-{\TeXXeTstate=1\revrm\beginR\TeX\endR}} % for TeX-XeT
135 % \def\TeXXeT{\TeX-{\TeXXeTstate=1\revrm\beginR\TeX-\endR}} % for TeX--XeT
136 % \fi
137 % \fi
138 @z
139 %---------------------------------------
140 @x limbo l.64 - bug fix (print only changed modules)
141 \def\pct!{{\char`\%}} % percent sign in ordinary text
142 @y
143 \def\pct!{{\char`\%}} % percent sign in ordinary text
144 \def\grp{\.{\char'173...\char'175}}
145 @z
146 %---------------------------------------
147 @x limbo l.80 - e-TeX basic
148 \def\title{$\Omega$ (OMEGA)}
149 @y
150 \def\title{\Aleph\ (ALEPH)}
151 % system dependent redefinitions of \title should come later
152 % and should use:
153 % \toks0=\expandafter{\title}
154 % \edef\title{...\the\toks0...}
155 \let\maybe=\iffalse % print only changed modules
156 \let\maybe=\iftrue % print everything
157 @z
158 %---------------------------------------
159 @x [1] m.1 l.91 - this is e-TeX
160 This is $\Omega$, a document compiler intended to simplify high-quality
161 @y
162 This is \Aleph, an extension of $\Omega$. $\Omega$ is a document compiler
163 intended to simplify high-quality
164 @z
165 %---------------------------------------
166 @x [1] m.2 l.179 - e-TeX basic
167 If this program is changed, the resulting system should not be called
168 @y
169 This program contains code from both the $\Omega$ (developed by
170 John Plaice and Yannis Haralambous) and \eTeX\
171 (developed by Peter Breitenlohner and the NTS team) extensions
172 to \TeX, therefore this program is called `\Aleph' and not
173 @z
174 %---------------------------------------
175 @x [1] m.2 l.185 - e-TeX basic
176 November 1984].
177 @y
178 November 1984].
179
180 A similar test suite called the ``\.{e-BUMP} test'' is (or will be made)
181 available for helping to determine whether a particular implementation deserves
182 to be known as `\Aleph'.
183 @z
184 %---------------------------------------
185 @x [1] m.2 l.187 - e-TeX basic
186 @d banner=='This is Omega, Version 3.141592653--1.15' {printed when \TeX\ starts}
187 @y
188 @d banner=='This is Aleph, Version 3.141592653--1.15--2.1' {printed when \TeX\ starts}
189 @#
190 @d eTeX_version_string=='3.141592653--1.15--2.1' {current \eTeX\ version}
191 @d eTeX_version=2 { \.{\\eTeXversion} }
192 @d eTeX_revision==".1" { \.{\\eTeXrevision} }
193 @#
194 @d eTeX_banner=='This is Aleph, Version ',eTeX_version_string
195 {printed when \eTeX\ starts}
196 @#
197 @d OMEGA==ALEPH {change program name into |ALEPH|}
198 @#
199 @d eTeX_states=1 {number of \eTeX\ state variables in |eqtb|}
200 @z
201 %---------------------------------------
202 @x [1] m.15 l.493 - e-TeX basic
203 @d not_found=45 {go here when you've found nothing}
204 @y
205 @d not_found=45 {go here when you've found nothing}
206 @d not_found1=46 {like |not_found|, when there's more than one}
207 @d not_found2=47 {like |not_found|, when there's more than two}
208 @d not_found3=48 {like |not_found|, when there's more than three}
209 @d not_found4=49 {like |not_found|, when there's more than four}
210 @z
211 %---------------------------------------
212 @x [5] m.61 l.1556 - e-TeX basic
213 wterm(banner);
214 @y
215 wterm(eTeX_banner);
216 @z
217 %---------------------------------------
218 @x [10] m.141 l.2965 - e-TeX marks
219 This field occupies a full word instead of a halfword, because
220 there's nothing to put in the other halfword; it is easier in \PASCAL\ to
221 use the full word than to risk leaving garbage in the unused half.
222 @y
223 In addition there is a |mark_class| field that contains the mark class.
224 @z
225 %---------------------------------------
226 @x [10] m.141 l.2971 - e-TeX marks
227 @d mark_ptr(#)==mem[#+1].int {head of the token list for a mark}
228 @y
229 @d mark_ptr(#)==link(#+1) {head of the token list for a mark}
230 @d mark_class(#)==info(#+1) {the mark class}
231 @z
232 %---------------------------------------
233 @x [10] m.142 l.2980 - e-TeX marks
234 @d adjust_ptr==mark_ptr {vertical list to be moved out of horizontal list}
235 @y
236 @d adjust_ptr(#)==mem[#+1].int
237 {vertical list to be moved out of horizontal list}
238 @z
239 %---------------------------------------
240 @x [12] m.196 l.3844 - e-TeX marks
241 begin print_esc("mark"); print_mark(mark_ptr(p));
242 @y
243 begin print_esc("mark");
244 if mark_class(p)<>0 then
245 begin print_char("s"); print_int(mark_class(p));
246 end;
247 print_mark(mark_ptr(p));
248 @z
249 %---------------------------------------
250 @x [15] m.208 l.4081 - e-TeX saved_items
251 @d un_vbox=24 {unglue a box ( \.{\\unvbox}, \.{\\unvcopy} )}
252 @y
253 @d un_vbox=24 {unglue a box ( \.{\\unvbox}, \.{\\unvcopy} )}
254 {( or \.{\\pagediscards}, \.{\\splitdiscards} )}
255 @z
256 %---------------------------------------
257 @x [15] m.208 l.4107 - e-TeX middle
258 @d left_right=49 {variable delimiter ( \.{\\left}, \.{\\right} )}
259 @y
260 @d left_right=49 {variable delimiter ( \.{\\left}, \.{\\right} )}
261 {( or \.{\\middle} )}
262 @z
263 %---------------------------------------
264 @x [15] m.209 l.4151 - e-TeX basic
265 \.{\\insertpenalties} )}
266 @y
267 \.{\\insertpenalties} )}
268 {( or \.{\\interactionmode} )}
269 @z
270 %---------------------------------------
271 @x [15] m.209 l.4153 - e-TeX penalties
272 @d set_shape=set_box_dimen+1
273 {specify fancy paragraph shape ( \.{\\parshape} )}
274 @y
275 @d set_shape=set_box_dimen+1
276 {specify fancy paragraph shape ( \.{\\parshape} )}
277 {(or \.{\\interlinepenalties}, etc.~)}
278 @z
279 %---------------------------------------
280 @x [15] m.209 l.4163 - e-TeX protected
281 @d prefix=divide+1
282 {qualify a definition ( \.{\\global}, \.{\\long}, \.{\\outer} )}
283 @y
284 @d prefix=divide+1
285 {qualify a definition ( \.{\\global}, \.{\\long}, \.{\\outer} )}
286 {( or \.{\\protected} )}
287 @z
288 %---------------------------------------
289 @x [15] m.209 l.4166 - e-TeX read_line
290 @d read_to_cs=shorthand_def+1
291 {read into a control sequence ( \.{\\read} )}
292 @y
293 @d read_to_cs=shorthand_def+1
294 {read into a control sequence ( \.{\\read} )}
295 {( or \.{\\readline} )}
296 @z
297 %---------------------------------------
298 @x [15] m.210 l.4181 - e-TeX scan_tokens
299 @d input=max_command+4 {input a source file ( \.{\\input}, \.{\\endinput} )}
300 @y
301 @d input=max_command+4 {input a source file ( \.{\\input}, \.{\\endinput} )}
302 {( or \.{\\scantokens} )}
303 @z
304 %---------------------------------------
305 @x [15] m.210 l.4186 - e-TeX unexpanded
306 @d the=max_command+9 {expand an internal quantity ( \.{\\the} )}
307 @y
308 @d the=max_command+9 {expand an internal quantity ( \.{\\the} )}
309 {( or \.{\\unexpanded}, \.{\\detokenize} )}
310 @z
311 %---------------------------------------
312 @x [16] m.212 l.4289 - e-TeX basic
313 user's output routine.
314 @y
315 user's output routine.
316
317 A seventh quantity, |eTeX_aux|, is used by the extended features \eTeX.
318 In vertical modes it is known as |LR_save| and holds the LR stack when a
319 paragraph is interrupted by a displayed formula. In display math mode
320 it is known as |LR_box| and holds a pointer to a prototype box for the
321 display. In math mode it is known as |delim_ptr| and points to the most
322 recent |left_noad| or |middle_noad| of a |math_left_group|.
323
324 In \Aleph it is only used in this last sense.
325 @z
326 %---------------------------------------
327 @x [16] m.212 l.4304 - e-TeX basic
328 @!head_field,@!tail_field: pointer;
329 @y
330 @!head_field,@!tail_field: pointer;
331 @!eTeX_aux_field: pointer;
332 @z
333 %---------------------------------------
334 @x [16] m.213 l.4311 - e-TeX basic
335 @d tail==cur_list.tail_field {final node on current list}
336 @y
337 @d tail==cur_list.tail_field {final node on current list}
338 @d eTeX_aux==cur_list.eTeX_aux_field {auxiliary data for \eTeX}
339 @d delim_ptr==eTeX_aux {most recent left or right noad of a math left group}
340 @z
341 %---------------------------------------
342 @x [16] m.215 l.4342 - e-TeX basic
343 mode:=vmode; head:=contrib_head; tail:=contrib_head;
344 @y
345 mode:=vmode; head:=contrib_head; tail:=contrib_head;
346 eTeX_aux:=null;
347 @z
348 %---------------------------------------
349 @x [16] m.216 l.4358 push_nest - e-TeX basic
350 incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line;
351 @y
352 incr(nest_ptr); head:=get_avail; tail:=head; prev_graf:=0; mode_line:=line;
353 eTeX_aux:=null;
354 @z
355 %---------------------------------------
356 @x [17] m.230 l.4712 - e-TeX basic, penalties
357 @d output_routine_loc=local_base+1 {points to token list for \.{\\output}}
358 @d every_par_loc=local_base+2 {points to token list for \.{\\everypar}}
359 @d every_math_loc=local_base+3 {points to token list for \.{\\everymath}}
360 @d every_display_loc=local_base+4 {points to token list for \.{\\everydisplay}}
361 @d every_hbox_loc=local_base+5 {points to token list for \.{\\everyhbox}}
362 @d every_vbox_loc=local_base+6 {points to token list for \.{\\everyvbox}}
363 @d every_job_loc=local_base+7 {points to token list for \.{\\everyjob}}
364 @d every_cr_loc=local_base+8 {points to token list for \.{\\everycr}}
365 @d err_help_loc=local_base+9 {points to token list for \.{\\errhelp}}
366 @d ocp_trace_level_base=local_base+10
367 @y
368 @d inter_line_penalties_loc=local_base+1 {additional penalties between lines}
369 @d club_penalties_loc=local_base+2 {penalties for creating club lines}
370 @d widow_penalties_loc=local_base+3 {penalties for creating widow lines}
371 @d display_widow_penalties_loc=local_base+4 {ditto, just before a display}
372 @d token_base=local_base+5 {table of token list parameters}
373 @d output_routine_loc=token_base {points to token list for \.{\\output}}
374 @d every_par_loc=token_base+1 {points to token list for \.{\\everypar}}
375 @d every_math_loc=token_base+2 {points to token list for \.{\\everymath}}
376 @d every_display_loc=token_base+3 {points to token list for \.{\\everydisplay}}
377 @d every_hbox_loc=token_base+4 {points to token list for \.{\\everyhbox}}
378 @d every_vbox_loc=token_base+5 {points to token list for \.{\\everyvbox}}
379 @d every_job_loc=token_base+6 {points to token list for \.{\\everyjob}}
380 @d every_cr_loc=token_base+7 {points to token list for \.{\\everycr}}
381 @d every_eof_loc=token_base+8 {points to token list for \.{\\everyeof}}
382 @d err_help_loc=token_base+9 {points to token list for \.{\\errhelp}}
383 @d ocp_trace_level_base=token_base+10
384 @z
385 %---------------------------------------
386 @x [17] m.231 l.4787 - e-TeX basic
387 othercases print_esc("errhelp")
388 @y
389 @/@<Cases of |assign_toks| for |print_cmd_chr|@>@/
390 othercases print_esc("errhelp")
391 @z
392 %---------------------------------------
393 @x [17] m.233 l.4833 - e-TeX penalties
394 if n=par_shape_loc then
395 begin print_esc("parshape"); print_char("=");
396 if par_shape_ptr=null then print_char("0")
397 else print_int(info(par_shape_ptr));
398 @y
399 if n<token_base then
400 begin print_cmd_chr(set_shape,n); print_char("=");
401 if equiv(n)=null then print_char("0")
402 else if n>par_shape_loc then
403 begin print_int(penalty(equiv(n))); print_char(" ");
404 print_int(penalty(equiv(n)+1));
405 if penalty(equiv(n))>1 then print_esc("ETC.");
406 end
407 else print_int(info(par_shape_ptr));
408 @z
409 %---------------------------------------
410 % FIXME: in this section and in the next
411 % we should remove pre_display_direction[_code]
412 % stuff, both here and down below
413 @x [17] m.236 l.4955 - e-TeX basic
414 @d dir_base=int_base+int_pars
415 @y
416 @d tracing_assigns_code=int_pars {show assignments}
417 @d tracing_groups_code=int_pars+1 {show save/restore groups}
418 @d tracing_ifs_code=int_pars+2 {show conditionals}
419 @d tracing_scan_tokens_code=int_pars+3 {show pseudo file open and close}
420 @d tracing_nesting_code=int_pars+4
421 {show incomplete groups and ifs within files}
422 @d pre_display_direction_code=int_pars+5 {text direction preceding a display}
423 @d last_line_fit_code=int_pars+6 {adjustment for last line of paragraph}
424 @d saving_vdiscards_code=int_pars+7 {save items discarded from vlists}
425 @d saving_hyph_codes_code=int_pars+8 {save hyphenation codes for languages}
426 @d eTeX_state_code=int_pars+9 {\eTeX\ state variables}
427 @d dir_base=int_base+eTeX_state_code+eTeX_states
428 @z
429 %---------------------------------------
430 @x [17] m.236 l.5016 - e-TeX basic
431 @d error_context_lines==int_par(error_context_lines_code)
432 @y
433 @d error_context_lines==int_par(error_context_lines_code)
434 @d tracing_assigns==int_par(tracing_assigns_code)
435 @d tracing_groups==int_par(tracing_groups_code)
436 @d tracing_ifs==int_par(tracing_ifs_code)
437 @d tracing_scan_tokens==int_par(tracing_scan_tokens_code)
438 @d tracing_nesting==int_par(tracing_nesting_code)
439 @d pre_display_direction==int_par(pre_display_direction_code)
440 @d last_line_fit==int_par(last_line_fit_code)
441 @d saving_vdiscards==int_par(saving_vdiscards_code)
442 @d saving_hyph_codes==int_par(saving_hyph_codes_code)
443 @z
444 %---------------------------------------
445 @x [17] m.237 l.5081 print_param - e-TeX basic
446 othercases print("[unknown integer parameter!]")
447 @y
448 @/@<Cases for |print_param|@>@/
449 othercases print("[unknown integer parameter!]")
450 @z
451 %---------------------------------------
452 % FIXED(?): moved to init_eqtb_entry in
453 % omega.web at l.5813
454 @x [17] m.232 l.4805 - e-TeX penalties
455 { Region 4 }
456 else if (p>=par_shape_loc) and
457 (p<=toks_base+biggest_reg) then begin
458 equiv_field(mw):=null;
459 eq_type_field(mw):=undefined_cs;
460 eq_level_field(mw):=level_zero;
461 end
462 @y
463 { Region 4 }
464 else if (p>=par_shape_loc) and
465 (p< token_base) then begin
466 equiv_field(mw):=null;
467 eq_type_field(mw):=shape_ref;
468 eq_level_field(mw):=level_one;
469 end
470 else if (p>=token_base) and
471 (p<=toks_base+biggest_reg) then begin
472 equiv_field(mw):=null;
473 eq_type_field(mw):=undefined_cs;
474 eq_level_field(mw):=level_zero;
475 end
476 @z
477 %---------------------------------------
478 @x [18] m.264 l.5612 primitive - e-TeX basic
479 @!j:small_number; {index into |buffer|}
480 @y
481 @!j:0..buf_size; {index into |buffer|}
482 @z
483 %---------------------------------------
484 @x [18] m.264 l.5616 primitive - e-TeX basic
485 {we will move |s| into the (empty) |buffer|}
486 for j:=0 to l-1 do buffer[j]:=so(str_pool[k+j]);
487 cur_val:=id_lookup(0,l); {|no_new_control_sequence| is |false|}
488 @y
489 {we will move |s| into the (possibly non-empty) |buffer|}
490 if first+l>buf_size+1 then
491 overflow("buffer size",buf_size);
492 @:TeX capacity exceeded buffer size}{\quad buffer size@>
493 for j:=0 to l-1 do buffer[first+j]:=so(str_pool[k+j]);
494 cur_val:=id_lookup(first,l); {|no_new_control_sequence| is |false|}
495 @z
496 %---------------------------------------
497 @x [18] m.265 l.5691 - e-TeX penalties
498 primitive("parshape",set_shape,0);@/
499 @y
500 primitive("parshape",set_shape,par_shape_loc);@/
501 @z
502 %---------------------------------------
503 @x [18] m.265 l.5708 - e-TeX sparse arrays
504 primitive("toks",toks_register,0);@/
505 @y
506 primitive("toks",toks_register,mem_bot);@/
507 @z
508 %---------------------------------------
509 @x [18] m.266 l.5741 - e-TeX cond
510 expand_after: print_esc("expandafter");
511 @y
512 expand_after: if chr_code=0 then print_esc("expandafter")
513 @<Cases of |expandafter| for |print_cmd_chr|@>;
514 @z
515 %---------------------------------------
516 @x [18] m.266 l.5747 - e-TeX marks
517 mark: print_esc("mark");
518 @y
519 mark: begin print_esc("mark");
520 if chr_code>0 then print_char("s");
521 end;
522 @z
523 %---------------------------------------
524 @x [18] m.266 l.5758 - e-TeX read_line
525 read_to_cs: print_esc("read");
526 @y
527 read_to_cs: if chr_code=0 then print_esc("read")
528 @<Cases of |read| for |print_cmd_chr|@>;
529 @z
530 %---------------------------------------
531 @x [18] m.266 l.5762 - e-TeX penalties
532 set_shape: print_esc("parshape");
533 @y
534 set_shape: case chr_code of
535 par_shape_loc: print_esc("parshape");
536 @<Cases of |set_shape| for |print_cmd_chr|@>@;@/
537 end; {there are no other cases}
538 @z
539 %---------------------------------------
540 @x [18] m.266 l.5763 - e-TeX unexpanded
541 the: print_esc("the");
542 @y
543 the: if chr_code=0 then print_esc("the")
544 @<Cases of |the| for |print_cmd_chr|@>;
545 @z
546 %---------------------------------------
547 @x [18] m.266 l.5764 - e-TeX sparse arrays
548 toks_register: print_esc("toks");
549 @y
550 toks_register: @<Cases of |toks_register| for |print_cmd_chr|@>;
551 @z
552 %---------------------------------------
553 @x [19] m.268 l.5800 - e-TeX sparse arrays
554 interpreted in one of four ways:
555 @y
556 interpreted in one of five ways:
557 @z
558 %---------------------------------------
559 @x [19] m.268 l.5820 - e-TeX tracing
560 the entries for that group.
561 @y
562 the entries for that group.
563 Furthermore, in extended \eTeX\ mode, |save_stack[p-1]| contains the
564 source line number at which the current level of grouping was entered.
565
566 \yskip\hang 5) If |save_type(p)=restore_sa|, then |sa_chain| points to a
567 chain of sparse array entries to be restored at the end of the current
568 group. Furthermore |save_index(p)| and |save_level(p)| should replace
569 the values of |sa_chain| and |sa_level| respectively.
570 @z
571 %---------------------------------------
572 % FIXME restore_sa safe? (sparse arrays)
573 @x [19] m.268 l.5830 - e-TeX basic
574 @d level_boundary=3 {|save_type| corresponding to beginning of group}
575 @y
576 @d level_boundary=3 {|save_type| corresponding to beginning of group}
577 @d restore_sa=4 {|save_type| when sparse array entries should be restored}
578
579 @p@t\4@>@<Declare \eTeX\ procedures for tracing and input@>
580 @z
581 %---------------------------------------
582 @x [19] m.273 l.5888 - e-TeX tracing
583 @ The following macro is used to test if there is room for up to six more
584 @y
585 @ The following macro is used to test if there is room for up to seven more
586 @z
587 %---------------------------------------
588 @x [19] m.273 l.5894 check_full_save_stack - e-TeX tracing
589 if max_save_stack>save_size-6 then overflow("save size",save_size);
590 @y
591 if max_save_stack>save_size-7 then overflow("save size",save_size);
592 @z
593 %---------------------------------------
594 @x [19] m.274 l.5916 new_save_level - e-TeX tracing
595 begin check_full_save_stack;
596 @y
597 begin check_full_save_stack;
598 if eTeX_ex then
599 begin saved(0):=line; incr(save_ptr);
600 end;
601 @z
602 %---------------------------------------
603 @x [19] m.274 l.5923 new_save_level - e-TeX tracing
604 cur_boundary:=save_ptr; incr(cur_level); incr(save_ptr); cur_group:=c;
605 @y
606 cur_boundary:=save_ptr; cur_group:=c;
607 @!stat if tracing_groups>0 then group_trace(false);@+tats@;@/
608 incr(cur_level); incr(save_ptr);
609 @z
610 %---------------------------------------
611 @x [19] m.275 l.5941 eq_destroy - e-TeX sparse arrays
612 othercases do_nothing
613 @y
614 @/@<Cases for |eq_destroy|@>@/
615 othercases do_nothing
616 @z
617 %---------------------------------------
618 @x [19] m.277 l.5963 - e-TeX tracing
619 the call, since |eq_save| makes the necessary test.
620 @y
621 the call, since |eq_save| makes the necessary test.
622
623 @d assign_trace(#)==@!stat if tracing_assigns>0 then restore_trace(#);
624 tats
625 @z
626 %---------------------------------------
627 @x [19] m.277 l.5967 eq_define - e-TeX tracing
628 begin if eq_level(p)=cur_level then eq_destroy(new_eqtb(p))
629 @y
630 label exit;
631 begin if eTeX_ex and(eq_type(p)=t)and(equiv(p)=e) then
632 begin assign_trace(p,"reassigning")@;@/
633 eq_destroy(new_eqtb(p)); return;
634 end;
635 assign_trace(p,"changing")@;@/
636 if eq_level(p)=cur_level then eq_destroy(new_eqtb(p))
637 @z
638 %---------------------------------------
639 @x [19] m.277 l.5970 eq_define - e-TeX tracing
640 end;
641 @y
642 assign_trace(p,"into")@;@/
643 exit:end;
644 @z
645 %---------------------------------------
646 @x [19] m.278 l.5977 eq_word_define - e-TeX tracing
647 begin if xeq_level(p)<>cur_level then
648 @y
649 label exit;
650 begin if eTeX_ex and(eqtb[p].int=w) then
651 begin assign_trace(p,"reassigning")@;@/
652 return;
653 end;
654 assign_trace(p,"changing")@;@/
655 if xeq_level(p)<>cur_level then
656 @z
657 %---------------------------------------
658 @x [19] m.278 l.5981 eq_word_define - e-TeX tracing
659 end;
660 @y
661 assign_trace(p,"into")@;@/
662 exit:end;
663 @z
664 %---------------------------------------
665 @x [19] m.279 l.5990 geq_define - e-TeX tracing
666 begin eq_destroy(new_eqtb(p));
667 set_eq_level(p,level_one); set_eq_type(p,t); set_equiv(p,e);
668 @y
669 begin assign_trace(p,"globally changing")@;@/
670 begin eq_destroy(new_eqtb(p));
671 set_eq_level(p,level_one); set_eq_type(p,t); set_equiv(p,e);
672 end;
673 assign_trace(p,"into")@;@/
674 @z
675 %---------------------------------------
676 @x [19] m.279 l.5995 geq_word_define - e-TeX tracing
677 begin set_new_eqtb_int(p,w); set_xeq_level(p,level_one);
678 @y
679 begin assign_trace(p,"globally changing")@;@/
680 begin set_new_eqtb_int(p,w); set_xeq_level(p,level_one);
681 end;
682 assign_trace(p,"into")@;@/
683 @z
684 %---------------------------------------
685 @x [19] m.281 l.6012 - e-TeX tracing
686 @p@t\4@>@<Declare the procedure called |restore_trace|@>@;@/
687 @y
688 @p
689 @z
690 %---------------------------------------
691 @x [19] m.281 l.6019 unsave - e-TeX optimized \aftergroup
692 begin if cur_level>level_one then
693 @y
694 @!a:boolean; {have we already processed an \.{\\aftergroup} ?}
695 begin a:=false;
696 if cur_level>level_one then
697 @z
698 %---------------------------------------
699 % FIXME restore_sa usage
700 @x [19] m.282 l.6033 - e-TeX sparse arrays
701 else begin if save_type(save_ptr)=restore_old_value then
702 @y
703 else if save_type(save_ptr)=restore_sa then
704 begin sa_restore; sa_chain:=p; sa_level:=save_level(save_ptr);
705 end
706 else begin if save_type(save_ptr)=restore_old_value then
707 @z
708 %---------------------------------------
709 @x [19] m.282 l.6041 - e-TeX tracing
710 done: cur_group:=save_level(save_ptr); cur_boundary:=save_index(save_ptr)
711 @y
712 done: @!stat if tracing_groups>0 then group_trace(true);@+tats@;@/
713 if grp_stack[in_open]=cur_boundary then group_warning;
714 {groups possibly not properly nested with files}
715 cur_group:=save_level(save_ptr); cur_boundary:=save_index(save_ptr);
716 if eTeX_ex then decr(save_ptr)
717 @z
718 %---------------------------------------
719 @x [19] m.284 l.6067 - e-TeX tracing
720 @ @<Declare the procedure called |restore_trace|@>=
721 @y
722 @ @<Declare \eTeX\ procedures for tr...@>=
723 @z
724 %---------------------------------------
725 @x [20] m.289 l.6155 - e-TeX protected
726 @d end_match_token=@"E0000 {$2^16\cdot|end_match|$}
727 @y
728 @d end_match_token=@"E0000 {$2^16\cdot|end_match|$}
729 @d protected_token=@"E0001 {$2^16\cdot|end_match|+1$}
730 @z
731 %---------------------------------------
732 @x [20] m.294 l.6280 - e-TeX protected
733 end_match: print("->");
734 @y
735 end_match: if c=0 then print("->");
736 @z
737 %---------------------------------------
738 @x [20] m.296 l.6301 print_meaning - e-TeX marks
739 else if cur_cmd=top_bot_mark then
740 @y
741 else if (cur_cmd=top_bot_mark)and(cur_chr<marks_code) then
742 @z
743 %---------------------------------------
744 @x [21] m.298 l.6375 print_cmd_chr - e-TeX protected
745 procedure print_cmd_chr(@!cmd:quarterword;@!chr_code:halfword);
746 @y
747 procedure print_cmd_chr(@!cmd:quarterword;@!chr_code:halfword);
748 var n:integer; {temp variable}
749 @z
750 %---------------------------------------
751 @x [21] m.299 l.6394 show_cur_cmd_chr - e-TeX tracing
752 @p procedure show_cur_cmd_chr;
753 @y
754 @p procedure show_cur_cmd_chr;
755 var n:integer; {level of \.{\\if...\\fi} nesting}
756 @!l:integer; {line where \.{\\if} started}
757 @!p:pointer;
758 @z
759 %---------------------------------------
760 @x [21] m.299 l.6399 show_cur_cmd_chr - e-TeX tracing
761 print_cmd_chr(cur_cmd,cur_chr); print_char("}");
762 @y
763 print_cmd_chr(cur_cmd,cur_chr);
764 if tracing_ifs>0 then
765 if cur_cmd>=if_test then if cur_cmd<=fi_or_else then
766 begin print(": ");
767 if cur_cmd=fi_or_else then
768 begin print_cmd_chr(if_test,cur_if); print_char(" ");
769 n:=0; l:=if_line;
770 end
771 else begin n:=1; l:=line;
772 end;
773 p:=cond_ptr;
774 while p<>null do
775 begin incr(n); p:=link(p);
776 end;
777 print("(level "); print_int(n); print_char(")"); print_if_line(l);
778 end;
779 print_char("}");
780 @z
781 %---------------------------------------
782 % FIXME: What about \write18 compatibility?
783 @x [22] m.303 l.6475 show_context - e-TeX scan_tokens
784 the terminal, under control of the procedure |read_toks|.)
785 @y
786 the terminal, under control of the procedure |read_toks|.)
787 Finally |18<=name<=19| indicates that we are reading a pseudo file
788 created by the \.{\\scantokens} command.
789 @z
790 %---------------------------------------
791 @x [22] m.307 l.6692 - e-TeX basic
792 @d mark_text=14 {|token_type| code for \.{\\topmark}, etc.}
793 @d write_text=15 {|token_type| code for \.{\\write}}
794 @y
795 @d every_eof_text=14 {|token_type| code for \.{\\everyeof}}
796 @d mark_text=15 {|token_type| code for \.{\\topmark}, etc.}
797 @d write_text=16 {|token_type| code for \.{\\write}}
798 @z
799 %---------------------------------------
800 @x [22] m.311 l.6749 show_context - e-TeX scan_tokens
801 if (name>17) or (base_ptr=0) then bottom_line:=true;
802 @y
803 if (name>19) or (base_ptr=0) then bottom_line:=true;
804 @z
805 %---------------------------------------
806 @x [22] m.313 l.6794 - e-TeX scan_tokens
807 else begin print_nl("l."); print_int(line);
808 @y
809 else begin print_nl("l.");
810 if index=in_open then print_int(line)
811 else print_int(line_stack[index+1]); {input from a pseudo file}
812 @z
813 %---------------------------------------
814 @x [22] m.314 l.6814 - e-TeX basic
815 every_cr_text: print_nl("<everycr> ");
816 @y
817 every_cr_text: print_nl("<everycr> ");
818 every_eof_text: print_nl("<everyeof> ");
819 @z
820 %---------------------------------------
821 @x [23] m.326 l.7009 - e-TeX optimized \aftergroup
822 begin t:=cur_tok; cur_tok:=p; back_input; cur_tok:=t;
823 @y
824 begin t:=cur_tok; cur_tok:=p;
825 if a then
826 begin p:=get_avail; info(p):=cur_tok; link(p):=loc; loc:=p; start:=p;
827 if cur_tok<right_brace_limit then
828 if cur_tok<left_brace_limit then decr(align_state)
829 else incr(align_state);
830 end
831 else begin back_input; a:=eTeX_ex;
832 end;
833 cur_tok:=t;
834 @z
835 %---------------------------------------
836 @x [23] m.328 l.7037 begin_file_reading - e-TeX every_eof, tracing_nesting
837 incr(in_open); push_input; index:=in_open;
838 @y
839 incr(in_open); push_input; index:=in_open;
840 eof_seen[index]:=false;
841 grp_stack[index]:=cur_boundary; if_stack[index]:=cond_ptr;
842 @z
843 %---------------------------------------
844 % FIXME: What about \write18 compatibility?
845 @x [23] m.329 l.7047 end_file_reading - e-TeX scan_tokens
846 if name>17 then a_close(cur_file); {forget it}
847 @y
848 if (name=18)or(name=19) then pseudo_close else
849 if name>17 then a_close(cur_file); {forget it}
850 @z
851 %---------------------------------------
852 @x [23] m.331 l.7066 - e-TeX tracing_nesting
853 in_open:=0; open_parens:=0; max_buf_stack:=0;
854 @y
855 in_open:=0; open_parens:=0; max_buf_stack:=0;
856 grp_stack[0]:=0; if_stack[0]:=null;
857 @z
858 %---------------------------------------
859 @x [24] m.362 l.7538 - e-TeX scan_tokens, every_eof
860 if not force_eof then
861 @y
862 if not force_eof then
863 if name<=19 then
864 begin if pseudo_input then {not end of file}
865 firm_up_the_line {this sets |limit|}
866 else if (every_eof<>null)and not eof_seen[index] then
867 begin limit:=first-1; eof_seen[index]:=true; {fake one empty line}
868 begin_token_list(every_eof,every_eof_text); goto restart;
869 end
870 else force_eof:=true;
871 end
872 else
873 @z
874 %---------------------------------------
875 @x [24] m.362 l.7541 - e-TeX every_eof
876 else force_eof:=true;
877 @y
878 else if (every_eof<>null)and not eof_seen[index] then
879 begin limit:=first-1; eof_seen[index]:=true; {fake one empty line}
880 begin_token_list(every_eof,every_eof_text); goto restart;
881 end
882 else force_eof:=true;
883 @z
884 %---------------------------------------
885 @x [24] m.362 l.7544 - e-TeX scan_tokens
886 begin print_char(")"); decr(open_parens);
887 update_terminal; {show user that file has been read}
888 @y
889 begin if tracing_nesting>0 then
890 if (grp_stack[in_open]<>cur_boundary)or@|
891 (if_stack[in_open]<>cond_ptr) then file_warning;
892 {give warning for some unfinished groups and/or conditionals}
893 if name>=19 then
894 begin print_char(")"); decr(open_parens);
895 update_terminal; {show user that file has been read}
896 end;
897 @z
898 %---------------------------------------
899 @x [25] m.366 l.7630 - e-TeX basic
900 @t\4@>@<Declare the procedure called |insert_relax|@>@;@/
901 @y
902 @t\4@>@<Declare the procedure called |insert_relax|@>@;@/
903 @t\4@>@<Declare \eTeX\ procedures for expanding@>@;@/
904 @z
905 %---------------------------------------
906 @x [25] m.366 l.7637 expand - e-TeX cond
907 procedure expand;
908 @y
909 procedure expand;
910 label reswitch;
911 @z
912 %---------------------------------------
913 @x [25] m.366 l.7648 expand - e-TeX cond
914 if cur_cmd<call then @<Expand a nonmacro@>
915 @y
916 reswitch:
917 if cur_cmd<call then @<Expand a nonmacro@>
918 @z
919 %---------------------------------------
920 @x [25] m.367 l.7659 - e-TeX cond
921 expand_after:@<Expand the token after the next token@>;
922 @y
923 expand_after:if cur_chr=0 then @<Expand the token after the next token@>
924 else @<Negate a boolean conditional and |goto reswitch|@>;
925 @z
926 %---------------------------------------
927 @x [25] m.377 l.7779 - e-TeX scan_tokens
928 input: if chr_code=0 then print_esc("input")@+else print_esc("endinput");
929 @y
930 input: if chr_code=0 then print_esc("input")
931 @/@<Cases of |input| for |print_cmd_chr|@>@/
932 else print_esc("endinput");
933 @z
934 %---------------------------------------
935 @x [25] m.378 l.7782 - e-TeX scan_tokens
936 if cur_chr>0 then force_eof:=true
937 @y
938 if cur_chr=1 then force_eof:=true
939 @/@<Cases for |input|@>@/
940 @z
941 %---------------------------------------
942 @x [25] m.382 l.7838 - e-TeX marks
943 @d top_mark_code=0 {the mark in effect at the previous page break}
944 @y
945 @d marks_code==5 {add this for \.{\\topmarks} etc.}
946 @#
947 @d top_mark_code=0 {the mark in effect at the previous page break}
948 @z
949 %---------------------------------------
950 @x [25] m.385 l.7870 - e-TeX marks
951 top_bot_mark: case chr_code of
952 @y
953 top_bot_mark: begin case (chr_code mod marks_code) of
954 @z
955 %---------------------------------------
956 @x [25] m.385 l.7876 - e-TeX marks
957 endcases;
958 @y
959 endcases;
960 if chr_code>=marks_code then print_char("s");
961 end;
962 @z
963 %---------------------------------------
964 @x [25] m.386 l.7882 - e-TeX marks
965 begin if cur_mark[cur_chr]<>null then
966 begin_token_list(cur_mark[cur_chr],mark_text);
967 @y
968 begin t:=cur_chr mod marks_code;
969 if cur_chr>=marks_code then scan_register_num@+else cur_val:=0;
970 if cur_val=0 then cur_ptr:=cur_mark[t]
971 else @<Compute the mark pointer for mark type |t| and class |cur_val|@>;
972 if cur_ptr<>null then begin_token_list(cur_ptr,mark_text);
973 @z
974 %---------------------------------------
975 @x [25] m.389 l.7945 macro_call - e-TeX protected
976 if info(r)<>end_match_token then
977 @y
978 if info(r)=protected_token then r:=link(r);
979 if info(r)<>end_match_token then
980 @z
981 %---------------------------------------
982 @x [26] m.409 l.8255 - e-TeX basic
983 @t\4\4@>@<Declare procedures that scan font-related stuff@>
984 @y
985 @t\4\4@>@<Declare \eTeX\ procedures for scanning@>@;
986 @t\4\4@>@<Declare procedures that scan font-related stuff@>
987 @z
988 %---------------------------------------
989 @x [26] m.411 l.8299 - e-TeX sparse arrays
990 |glue_val|, or |mu_val|.
991 @y
992 |glue_val|, or |mu_val| more than |mem_bot| (dynamic variable-size nodes
993 cannot have these values)
994 @z
995 %---------------------------------------
996 @x [26] m.411 l.8302 - e-TeX sparse arrays
997 primitive("count",register,int_val);
998 @!@:count_}{\.{\\count} primitive@>
999 primitive("dimen",register,dimen_val);
1000 @!@:dimen_}{\.{\\dimen} primitive@>
1001 primitive("skip",register,glue_val);
1002 @!@:skip_}{\.{\\skip} primitive@>
1003 primitive("muskip",register,mu_val);
1004 @y
1005 primitive("count",register,mem_bot+int_val);
1006 @!@:count_}{\.{\\count} primitive@>
1007 primitive("dimen",register,mem_bot+dimen_val);
1008 @!@:dimen_}{\.{\\dimen} primitive@>
1009 primitive("skip",register,mem_bot+glue_val);
1010 @!@:skip_}{\.{\\skip} primitive@>
1011 primitive("muskip",register,mem_bot+mu_val);
1012 @z
1013 %---------------------------------------
1014 @x [26] m.412 l.8312 - e-TeX sparse arrays
1015 register: if chr_code=int_val then print_esc("count")
1016 else if chr_code=dimen_val then print_esc("dimen")
1017 else if chr_code=glue_val then print_esc("skip")
1018 else print_esc("muskip");
1019 @y
1020 register: @<Cases of |register| for |print_cmd_chr|@>;
1021 @z
1022 %---------------------------------------
1023 @x [26] m.413 l.8328 scan_something_internal - e-TeX basic
1024 var m:halfword; {|chr_code| part of the operand token}
1025 @y
1026 label exit;
1027 var m:halfword; {|chr_code| part of the operand token}
1028 @!q:halfword; {general purpose index}
1029 @!i:four_quarters; {character info}
1030 @z
1031 %---------------------------------------
1032 @x [26] m.413 l.8354 scan_something_internal - e-TeX basic
1033 end;
1034 @y
1035 exit:end;
1036 @z
1037 %---------------------------------------
1038 @x [26] m.415 l.8375 - e-TeX sparse arrays
1039 begin scan_eight_bit_int; m:=toks_base+cur_val;
1040 end;
1041 scanned_result(equiv(m))(tok_val);
1042 @y
1043 if m=mem_bot then
1044 begin scan_register_num;
1045 if cur_val<256 then cur_val:=equiv(toks_base+cur_val)
1046 else begin find_sa_element(tok_val,cur_val,false);
1047 if cur_ptr=null then cur_val:=null
1048 else cur_val:=sa_ptr(cur_ptr);
1049 end;
1050 end
1051 else cur_val:=sa_ptr(m)
1052 else cur_val:=equiv(m);
1053 cur_val_level:=tok_val;
1054 @z
1055 %---------------------------------------
1056 @x [26] m.416 l.8390 - e-TeX basic
1057 |glue_val|, |input_line_no_code|, or |badness_code|.
1058
1059 @d input_line_no_code=glue_val+1 {code for \.{\\inputlineno}}
1060 @d badness_code=glue_val+2 {code for \.{\\badness}}
1061 @y
1062 |glue_val|, |last_node_type_code|, |input_line_no_code|, |badness_code|,
1063 |eTeX_version_code|, or one of the other codes for \eTeX\ extensions.
1064
1065 @d last_node_type_code=glue_val+1 {code for \.{\\lastnodetype}}
1066 @d input_line_no_code=glue_val+2 {code for \.{\\inputlineno}}
1067 @d badness_code=glue_val+3 {code for \.{\\badness}}
1068 @d eTeX_int=glue_val+4 {first of \eTeX\ codes for integers}
1069 @d eTeX_dim=eTeX_int+8 {first of \eTeX\ codes for dimensions}
1070 @d eTeX_glue=eTeX_dim+9 {first of \eTeX\ codes for glue}
1071 @d eTeX_mu=eTeX_glue+1 {first of \eTeX\ codes for muglue}
1072 @d eTeX_expr=eTeX_mu+1 {first of \eTeX\ codes for expressions}
1073 @z
1074 %---------------------------------------
1075 @x [26] m.417 l.8425 - e-TeX interaction_mode
1076 @+else print_esc("insertpenalties");
1077 @y
1078 @/@<Cases of |set_page_int| for |print_cmd_chr|@>@/
1079 @+else print_esc("insertpenalties");
1080 @z
1081 %---------------------------------------
1082 @x [26] m.417 l.8434 - e-TeX basic
1083 othercases print_esc("badness")
1084 @y
1085 @/@<Cases of |last_item| for |print_cmd_chr|@>@/
1086 othercases print_esc("badness")
1087 @z
1088 %---------------------------------------
1089 @x [26] m.419 l.8457 - e-TeX interaction_mode
1090 begin if m=0 then cur_val:=dead_cycles@+else cur_val:=insert_penalties;
1091 @y
1092 begin if m=0 then cur_val:=dead_cycles
1093 @/@<Cases for `Fetch the |dead_cycles| or the |insert_penalties|'@>@/
1094 else cur_val:=insert_penalties;
1095 @z
1096 %---------------------------------------
1097 @x [26] m.420 l.8462 - e-TeX sparse arrays
1098 begin
1099 scan_eight_bit_int;
1100 if box(cur_val)=null then cur_val:=0 @+else
1101 cur_val:=mem[box(cur_val)+m].sc;
1102 @y
1103 begin
1104 scan_register_num;
1105 fetch_box(q);
1106 if q=null then cur_val:=0 @+else
1107 cur_val:=mem[q+m].sc;
1108 @z
1109 %---------------------------------------
1110 @x [26] m.423 l.8487 - e-TeX penalties
1111 begin if par_shape_ptr=null then cur_val:=0
1112 @y
1113 begin if m>par_shape_loc then @<Fetch a penalties array element@>
1114 else if par_shape_ptr=null then cur_val:=0
1115 @z
1116 %---------------------------------------
1117 @x [26] m.424 l.8499 - e-TeX basic
1118 if cur_chr>glue_val then
1119 begin if cur_chr=input_line_no_code then cur_val:=line
1120 else cur_val:=last_badness; {|cur_chr=badness_code|}
1121 @y
1122 if m>last_node_type_code then
1123 if m>=eTeX_glue then @<Process an expression and |return|@>@;
1124 else if m>=eTeX_dim then
1125 begin case m of
1126 @/@<Cases for fetching a dimension value@>@/
1127 end; {there are no other cases}
1128 cur_val_level:=dimen_val;
1129 end
1130 else begin case m of
1131 input_line_no_code: cur_val:=line;
1132 badness_code: cur_val:=last_badness;
1133 @/@<Cases for fetching an integer value@>@/
1134 end; {there are no other cases}
1135 @z
1136 %---------------------------------------
1137 @x [26] m.424 l.8505 - e-TeX last_node_type
1138 cur_val_level:=cur_chr;
1139 @y
1140 if cur_chr=last_node_type_code then
1141 begin cur_val:=int_val;
1142 if (tail=head)or(mode=0) then cur_val:=-1;
1143 end
1144 else cur_val_level:=cur_chr;
1145 @z
1146 %---------------------------------------
1147 @x [26] m.424 l.8513 - e-TeX last_node_type
1148 end;
1149 @y
1150 end;
1151 last_node_type_code:
1152 if (type(tail)<>math_node)or(subtype(tail)<>end_M_code) then
1153 if type(tail)<=unset_node then cur_val:=type(tail)+1
1154 else cur_val:=unset_node+2;
1155 @z
1156 %---------------------------------------
1157 @x [26] m.424 l.8519 - e-TeX last_node_type
1158 glue_val: if last_glue<>max_halfword then cur_val:=last_glue;
1159 @y
1160 glue_val: if last_glue<>max_halfword then cur_val:=last_glue;
1161 last_node_type_code: cur_val:=last_node_type;
1162 @z
1163 %---------------------------------------
1164 % FIXME might need work
1165 @x [26] m.427 l.8535 - e-TeX sparse arrays
1166 begin scan_eight_bit_int;
1167 case m of
1168 @y
1169 begin if (m<mem_bot)or(m>lo_mem_stat_max) then
1170 begin cur_val_level:=sa_type(m);
1171 if cur_val_level<glue_val then cur_val:=sa_int(m)
1172 else cur_val:=sa_ptr(m);
1173 end
1174 else begin scan_register_num; cur_val_level:=m-mem_bot;
1175 if cur_val>255 then
1176 begin find_sa_element(cur_val_level,cur_val,false);
1177 if cur_ptr=null then
1178 if cur_val_level<glue_val then cur_val:=0
1179 else cur_val:=zero_glue
1180 else if cur_val_level<glue_val then cur_val:=sa_int(cur_ptr)
1181 else cur_val:=sa_ptr(cur_ptr);
1182 end
1183 else
1184 case cur_val_level of
1185 @z
1186 %---------------------------------------
1187 @x [26] m.427 l.8542 - e-TeX sparse arrays
1188 cur_val_level:=m;
1189 @y
1190 end;
1191 @z
1192 %---------------------------------------
1193 @x [26] m.461 l.9070 - e-TeX expr
1194 exit:end;
1195 @y
1196 exit:end;
1197 @#
1198 @<Declare procedures needed for expressions@>@;
1199 @z
1200 %---------------------------------------
1201 @x [27] m.464 l.9129 - e-TeX basic
1202 @p function str_toks(@!b:pool_pointer):pointer;
1203 @y
1204 @p @t\4@>@<Declare \eTeX\ procedures for token lists@>@;@/
1205 function str_toks(@!b:pool_pointer):pointer;
1206 @z
1207 %---------------------------------------
1208 @x [27] m.465 l.9154 the_toks - e-TeX unexpanded
1209 @p function the_toks:pointer;
1210 @y
1211 @p function the_toks:pointer;
1212 label exit;
1213 @z
1214 %---------------------------------------
1215 @x [27] m.465 l.9158 the_toks - e-TeX unexpanded
1216 begin get_x_token; scan_something_internal(tok_val,false);
1217 @y
1218 @!c:small_number; {value of |cur_chr|}
1219 begin @<Handle \.{\\unexpanded} or \.{\\detokenize} and |return|@>;@/
1220 get_x_token; scan_something_internal(tok_val,false);
1221 @z
1222 %---------------------------------------
1223 @x [27] m.465 l.9172 the_toks - e-TeX unexpanded
1224 end;
1225 @y
1226 exit:end;
1227 @z
1228 %---------------------------------------
1229 @x [27] m.469 l.9223 - e-TeX basic
1230 othercases print_esc("jobname")
1231 @y
1232 @/@<Cases of |convert| for |print_cmd_chr|@>@/
1233 othercases print_esc("jobname")
1234 @z
1235 %---------------------------------------
1236 @x [27] m.470 l.9232 conv_toks - e-TeX basic
1237 @!c:number_code..job_name_code; {desired type of conversion}
1238 @y
1239 @!c:small_number; {desired type of conversion}
1240 @z
1241 %---------------------------------------
1242 @x [27] m.471 l.9249 - e-TeX basic
1243 end {there are no other cases}
1244 @y
1245 @/@<Cases of `Scan the argument for command |c|'@>@/
1246 end {there are no other cases}
1247 @z
1248 %---------------------------------------
1249 @x [27] m.472 l.9265 - e-TeX basic
1250 end {there are no other cases}
1251 @y
1252 @/@<Cases of `Print the result of command |c|'@>@/
1253 end {there are no other cases}
1254 @z
1255 %---------------------------------------
1256 @x [27] m.478 l.9374 - e-TeX protected
1257 if cur_cmd<=max_command then goto done2;
1258 @y
1259 if cur_cmd>=call then
1260 if info(link(cur_chr))=protected_token then
1261 begin cur_cmd:=relax; cur_chr:=no_expand_flag;
1262 end;
1263 if cur_cmd<=max_command then goto done2;
1264 @z
1265 %---------------------------------------
1266 @x [27] m.482 l.9422 read_toks - e-TeX read_line
1267 @p procedure read_toks(@!n:integer;@!r:pointer);
1268 @y
1269 @p procedure read_toks(@!n:integer;@!r:pointer;@!j:halfword);
1270 @z
1271 %---------------------------------------
1272 @x [27] m.483 l.9448 - e-TeX read_line
1273 loop@+ begin get_token;
1274 @y
1275 @<Handle \.{\\readline} and |goto done|@>;@/
1276 loop@+ begin get_token;
1277 @z
1278 %---------------------------------------
1279 @x [28] m.487 l.9500 - e-TeX cond
1280 @d if_char_code=0 { `\.{\\if}' }
1281 @y
1282 @d unless_code=32 {amount added for `\.{\\unless}' prefix}
1283 @#
1284 @d if_char_code=0 { `\.{\\if}' }
1285 @z
1286 %---------------------------------------
1287 @x [28] m.488 l.9555 - e-TeX cond
1288 if_test: case chr_code of
1289 @y
1290 if_test: begin if chr_code>=unless_code then print_esc("unless");
1291 case chr_code mod unless_code of
1292 @z
1293 %---------------------------------------
1294 @x [28] m.488 l.9572 - e-TeX cond
1295 othercases print_esc("if")
1296 endcases;
1297 @y
1298 @/@<Cases of |if_test| for |print_cmd_chr|@>@/
1299 othercases print_esc("if")
1300 endcases;
1301 end;
1302 @z
1303 %---------------------------------------
1304 @x [28] m.494 l.9646 pass_text - e-TeX tracing
1305 done: scanner_status:=save_scanner_status;
1306 @y
1307 done: scanner_status:=save_scanner_status;
1308 if tracing_ifs>0 then show_cur_cmd_chr;
1309 @z
1310 %---------------------------------------
1311 @x [28] m.496 l.9662 - e-TeX tracing_nesting
1312 begin p:=cond_ptr; if_line:=if_line_field(p);
1313 @y
1314 begin if if_stack[in_open]=cond_ptr then if_warning;
1315 {conditionals possibly not properly nested with files}
1316 p:=cond_ptr; if_line:=if_line_field(p);
1317 @z
1318 %---------------------------------------
1319 @x [28] m.498 l.9699 conditional - e-TeX cond
1320 begin @<Push the condition stack@>;@+save_cond_ptr:=cond_ptr;this_if:=cur_chr;@/
1321 @<Either process \.{\\ifcase} or set |b| to the value of a boolean condition@>;
1322 @y
1323 @!is_unless:boolean; {was this if preceded by `\.{\\unless}' ?}
1324 begin if tracing_ifs>0 then if tracing_commands<=1 then show_cur_cmd_chr;
1325 @<Push the condition stack@>;@+save_cond_ptr:=cond_ptr;
1326 is_unless:=(cur_chr>=unless_code); this_if:=cur_chr mod unless_code;@/
1327 @<Either process \.{\\ifcase} or set |b| to the value of a boolean condition@>;
1328 if is_unless then b:=not b;
1329 @z
1330 %---------------------------------------
1331 @x [28] m.501 l.9742 - e-TeX cond
1332 if_false_code: b:=false;
1333 @y
1334 if_false_code: b:=false;
1335 @/@<Cases for |conditional|@>@/
1336 @z
1337 %---------------------------------------
1338 @x [28] m.505 l.9781 - e-TeX sparse arrays
1339 begin scan_eight_bit_int; p:=box(cur_val);
1340 @y
1341 begin scan_register_num; fetch_box(p);
1342 @z
1343 %---------------------------------------
1344 @x [28] m.510 l.9871 - e-TeX cond
1345 if cur_chr>if_limit then
1346 @y
1347 begin if tracing_ifs>0 then if tracing_commands<=1 then show_cur_cmd_chr;
1348 if cur_chr>if_limit then
1349 @z
1350 %---------------------------------------
1351 @x [28] m.510 l.9882 - e-TeX cond
1352 end
1353 @y
1354 end;
1355 end
1356 @z
1357 %---------------------------------------
1358 @x [29] m.536 l.10324 - e-TeX basic
1359 begin wlog(banner);
1360 @y
1361 begin wlog(eTeX_banner);
1362 @z
1363 %---------------------------------------
1364 @x [29] m.536 l.10331 - e-TeX basic
1365 end
1366 @y
1367 if eTeX_ex then
1368 begin; wlog_cr; wlog('entering extended mode');
1369 end;
1370 end
1371 @z
1372 %---------------------------------------
1373 @x [30] m.581 l.11263 char_warning - e-TeX tracing
1374 begin if tracing_lost_chars>0 then
1375 @y
1376 var old_setting: integer; {saved value of |tracing_online|}
1377 begin if tracing_lost_chars>0 then
1378 begin old_setting:=tracing_online;
1379 if eTeX_ex and(tracing_lost_chars>1) then tracing_online:=1;
1380 @z
1381 %---------------------------------------
1382 @x [30] m.581 l.11270 char_warning - e-TeX tracing
1383 end;
1384 @y
1385 tracing_online:=old_setting;
1386 end;
1387 end;
1388 @z
1389 %---------------------------------------
1390 @x [34] m.687 l.13480 - e-TeX middle
1391 \TeX's \.{\\left} and \.{\\right}. The |nucleus| of such noads is
1392 @y
1393 \TeX's \.{\\left} and \.{\\right} as well as \eTeX's \.{\\middle}.
1394 The |nucleus| of such noads is
1395 @z
1396 %---------------------------------------
1397 @x [34] m.687 l.13497 - e-TeX middle
1398 @d delimiter==nucleus {|delimiter| field in left and right noads}
1399 @y
1400 @d delimiter==nucleus {|delimiter| field in left and right noads}
1401 @d middle_noad==1 {|subtype| of right noad representing \.{\\middle}}
1402 @z
1403 %---------------------------------------
1404 @x [34] m.696 l.13670 - e-TeX middle
1405 right_noad: begin print_esc("right"); print_delimiter(delimiter(p));
1406 end;
1407 end;
1408 if subtype(p)<>normal then
1409 if subtype(p)=limits then print_esc("limits")
1410 else print_esc("nolimits");
1411 if type(p)<left_noad then print_subsidiary_data(nucleus(p),".");
1412 @y
1413 right_noad: begin if subtype(p)=normal then print_esc("right")
1414 else print_esc("middle");
1415 print_delimiter(nucleus(p));
1416 end;
1417 end;
1418 if type(p)<left_noad then
1419 begin if subtype(p)<>normal then
1420 if subtype(p)=limits then print_esc("limits")
1421 else print_esc("nolimits");
1422 print_subsidiary_data(nucleus(p),".");
1423 end;
1424 @z
1425 %---------------------------------------
1426 @x [36] m.727 l.14268 - e-TeX middle
1427 done_with_noad: r:=q; r_type:=type(r);
1428 @y
1429 done_with_noad: r:=q; r_type:=type(r);
1430 if r_type=right_noad then
1431 begin r_type:=left_noad; cur_style:=style; @<Set up the values...@>;
1432 end;
1433 @z
1434 %---------------------------------------
1435 @x [36] m.760 l.14929 - e-TeX middle
1436 r_type:=t;
1437 @y
1438 if type(q)=right_noad then t:=open_noad;
1439 r_type:=t;
1440 @z
1441 %---------------------------------------
1442 @x [36] m.762 l.14970 make_left_right - e-TeX middle
1443 begin if style<script_style then cur_size:=text_size
1444 else cur_size:=script_size*((style-text_style) div 2);
1445 @y
1446 begin cur_style:=style; @<Set up the values...@>;
1447 @z
1448 %---------------------------------------
1449 @x [37] m.785 l.15461 align_peek - e-TeX protected
1450 begin restart: align_state:=1000000; @<Get the next non-blank non-call token@>;
1451 @y
1452 begin restart: align_state:=1000000;
1453 repeat get_x_or_protected;
1454 until cur_cmd<>spacer;
1455 @z
1456 %---------------------------------------
1457 @x [37] m.791 l.15572 fin_col - e-TeX protected
1458 align_state:=1000000; @<Get the next non-blank non-call token@>;
1459 @y
1460 align_state:=1000000;
1461 repeat get_x_or_protected;
1462 until cur_cmd<>spacer;
1463 @z
1464 %---------------------------------------
1465 @x [38] m.814 l.15975 - e-TeX penalties
1466 There is one explicit parameter: |final_widow_penalty| is the amount of
1467 additional penalty to be inserted before the final line of the paragraph.
1468 @y
1469 There is one explicit parameter: |d| is true for partial paragraphs
1470 preceding display math mode; in this case the amount of additional
1471 penalty inserted before the final line is |display_widow_penalty|
1472 instead of |widow_penalty|.
1473 @z
1474 %---------------------------------------
1475 @x [38] m.815 l.16002 line_break - e-TeX penalties
1476 procedure line_break(@!final_widow_penalty:integer);
1477 @y
1478 procedure line_break(@!d:boolean);
1479 @z
1480 %---------------------------------------
1481 @x [38] m.815 l.16012 - e-TeX basic
1482 end;
1483 @y
1484 end;
1485 @#
1486 @t\4@>@<Declare \eTeX\ procedures for use by |main_control|@>
1487 @z
1488 %---------------------------------------
1489 @x [38] m.816 l.16032 - e-TeX last_line_fit
1490 final_par_glue:=new_param_glue(par_fill_skip_code);
1491 link(tail):=final_par_glue;
1492 @y
1493 final_par_glue:=new_param_glue(par_fill_skip_code);
1494 link(tail):=final_par_glue;
1495 last_line_fill:=link(tail);
1496 @z
1497 %---------------------------------------
1498 @x [38] m.819 l.16097 - e-TeX last_line_fit
1499 @d active_node_size=3 {number of words in active nodes}
1500 @y
1501 @d active_node_size_normal=3 {number of words in normal active nodes}
1502 @z
1503 %---------------------------------------
1504 % FIXME might need fixes; TeX has 6 backgrounds
1505 % Omega has 7. Why the difference?
1506 @x [38] m.827 l.16260 - e-TeX last_line_fit
1507 background[7]:=shrink(q)+shrink(r);
1508 @y
1509 background[7]:=shrink(q)+shrink(r);
1510 @<Check for special treatment of last line of paragraph@>;
1511 @z
1512 %---------------------------------------
1513 @x [38] m.829 l.16311 try_break - e-TeX last_line_fit
1514 label exit,done,done1,continue,deactivate;
1515 @y
1516 label exit,done,done1,continue,deactivate,found,not_found;
1517 @z
1518 %---------------------------------------
1519 @x [38] m.845 l.16603 - e-TeX last_line_fit
1520 total_demerits(q):=minimal_demerits[fit_class];
1521 @y
1522 total_demerits(q):=minimal_demerits[fit_class];
1523 if do_last_line_fit then
1524 @<Store \(a)additional data in the new active node@>;
1525 @z
1526 %---------------------------------------
1527 @x [38] m.846 l.16616 - e-TeX last_line_fit
1528 print(" t="); print_int(total_demerits(q));
1529 @y
1530 print(" t="); print_int(total_demerits(q));
1531 if do_last_line_fit then @<Print additional data in the new active node@>;
1532 @z
1533 %---------------------------------------
1534 @x [38] m.851 l.16715 - e-TeX last_line_fit
1535 if (b>inf_bad)or(pi=eject_penalty) then
1536 @y
1537 if do_last_line_fit then @<Adjust \(t)the additional data for last line@>;
1538 found:
1539 if (b>inf_bad)or(pi=eject_penalty) then
1540 @z
1541 %---------------------------------------
1542 @x [38] m.852 l.16739 - e-TeX last_line_fit
1543 begin b:=0; fit_class:=decent_fit; {infinite stretch}
1544 @y
1545 begin if do_last_line_fit then
1546 begin if cur_p=null then {the last line of a paragraph}
1547 @<Perform computations for last line and |goto found|@>;
1548 shortfall:=0;
1549 end;
1550 b:=0; fit_class:=decent_fit; {infinite stretch}
1551 @z
1552 %---------------------------------------
1553 @x [38] m.855 l.16796 - e-TeX last_line_fit
1554 best_place[fit_class]:=break_node(r); best_pl_line[fit_class]:=l;
1555 @y
1556 best_place[fit_class]:=break_node(r); best_pl_line[fit_class]:=l;
1557 if do_last_line_fit then
1558 @<Store \(a)additional data for this feasible break@>;
1559 @z
1560 %---------------------------------------
1561 @x [39] m.863 l.16969 - e-TeX last_line_fit
1562 end;@+tats@/
1563 @y
1564 end;@+tats@/
1565 if do_last_line_fit then @<Adjust \(t)the final line of the paragraph@>;
1566 @z
1567 %---------------------------------------
1568 @x [39] m.864 l.16980 - e-TeX last_line_fit
1569 line_number(q):=prev_graf+1; total_demerits(q):=0; link(active):=q;
1570 @y
1571 line_number(q):=prev_graf+1; total_demerits(q):=0; link(active):=q;
1572 if do_last_line_fit then
1573 @<Initialize additional fields of the first active node@>;
1574 @z
1575 %---------------------------------------
1576 @x [39] m.876 l.17192 - e-TeX penalties
1577 post_line_break(final_widow_penalty)
1578 @y
1579 post_line_break(d)
1580 @z
1581 %---------------------------------------
1582 @x [39] m.877 l.17206 post_line_break - e-TeX penalties
1583 procedure post_line_break(@!final_widow_penalty:integer);
1584 @y
1585 procedure post_line_break(@!d:boolean);
1586 @z
1587 %---------------------------------------
1588 % FIXME possible conflict
1589 @x [39] m.890 l.17395 - e-TeX penalties
1590 if passive_pen_inter(cur_p)<>0 then
1591 pen:=passive_pen_inter(cur_p)
1592 else pen:=inter_line_penalty;
1593 if cur_line=prev_graf+1 then pen:=pen+club_penalty;
1594 if cur_line+2=best_line then pen:=pen+final_widow_penalty;
1595 @y
1596 q:=inter_line_penalties_ptr;
1597 if q<>null then
1598 begin r:=cur_line;
1599 if r>penalty(q) then r:=penalty(q);
1600 pen:=penalty(q+r);
1601 end
1602 else begin
1603 if passive_pen_inter(cur_p)<>0 then
1604 pen:=passive_pen_inter(cur_p)
1605 else pen:=inter_line_penalty;
1606 end;
1607 q:=club_penalties_ptr;
1608 if q<>null then
1609 begin r:=cur_line-prev_graf;
1610 if r>penalty(q) then r:=penalty(q);
1611 pen:=pen+penalty(q+r);
1612 end
1613 else if cur_line=prev_graf+1 then pen:=pen+club_penalty;
1614 if d then q:=display_widow_penalties_ptr
1615 else q:=widow_penalties_ptr;
1616 if q<>null then
1617 begin r:=best_line-cur_line-1;
1618 if r>penalty(q) then r:=penalty(q);
1619 pen:=pen+penalty(q+r);
1620 end
1621 else if cur_line+2=best_line then
1622 if d then pen:=pen+display_widow_penalty
1623 else pen:=pen+widow_penalty;
1624 @z
1625 %---------------------------------------
1626 @x [40] m.891 l.17460 - e-TeX hyph_codes
1627 cur_lang:=init_cur_lang; l_hyf:=init_l_hyf; r_hyf:=init_r_hyf;
1628 @y
1629 cur_lang:=init_cur_lang; l_hyf:=init_l_hyf; r_hyf:=init_r_hyf;
1630 set_hyph_index;
1631 @z
1632 %---------------------------------------
1633 @x [40] m.896 l.17529 - e-TeX hyph_codes
1634 if lc_code(c)<>0 then
1635 if (lc_code(c)=c)or(uc_hyph>0) then goto done2
1636 @y
1637 set_lc_code(c);
1638 if hc[0]<>0 then
1639 if (hc[0]=c)or(uc_hyph>0) then goto done2
1640 @z
1641 %---------------------------------------
1642 @x [40] m.897 l.17546 - e-TeX hyph_codes
1643 if lc_code(c)=0 then goto done3;
1644 if lc_code(c)>max_hyph_char then goto done3;
1645 if hn=63 then goto done3;
1646 hb:=s; incr(hn); hu[hn]:=c; hc[hn]:=lc_code(c); hyf_bchar:=non_char;
1647 @y
1648 set_lc_code(c);
1649 if hc[0]=0 then goto done3;
1650 if lc_code(c)>max_hyph_char then goto done3;
1651 if hn=63 then goto done3;
1652 hb:=s; incr(hn); hu[hn]:=c; hc[hn]:=hc[0]; hyf_bchar:=non_char;
1653 @z
1654 %---------------------------------------
1655 @x [40] m.898 l.17572 - e-TeX hyph_codes
1656 if lc_code(c)=0 then goto done3;
1657 if lc_code(c)>max_hyph_char then goto done3;
1658 if j=63 then goto done3;
1659 incr(j); hu[j]:=c; hc[j]:=lc_code(c);@/
1660 @y
1661 set_lc_code(c);
1662 if hc[0]=0 then goto done3;
1663 if lc_code(c)>max_hyph_char then goto done3;
1664 if j=63 then goto done3;
1665 incr(j); hu[j]:=c; hc[j]:=hc[0];@/
1666 @z
1667 %---------------------------------------
1668 @x [42] m.934 l.18211 new_hyph_exceptions - e-TeX hyph_codes
1669 label reswitch, exit, found, not_found;
1670 @y
1671 label reswitch, exit, found, not_found, not_found1;
1672 @z
1673 %---------------------------------------
1674 @x [42] m.934 l.18221 new_hyph_exceptions - e-TeX hyph_codes
1675 set_cur_lang;
1676 @y
1677 set_cur_lang;
1678 @!init if trie_not_ready then
1679 begin hyph_index:=0; goto not_found1;
1680 end;
1681 tini@/
1682 set_hyph_index;
1683 not_found1:
1684 @z
1685 %---------------------------------------
1686 @x [42] m.937 l.18253 - e-TeX hyph_codes
1687 else begin if lc_code(cur_chr)=0 then
1688 @y
1689 else begin set_lc_code(cur_chr);
1690 if hc[0]=0 then
1691 @z
1692 %---------------------------------------
1693 @x [42] m.937 l.18261 - e-TeX hyph_codes
1694 begin incr(n); hc[n]:=lc_code(cur_chr);
1695 @y
1696 begin incr(n); hc[n]:=hc[0];
1697 @z
1698 %---------------------------------------
1699 @x [43] m.952 l.18549 - e-TeX hyph_codes
1700 trie_root:=compress_trie(trie_root); {identify equivalent subtries}
1701 @y
1702 hyph_root:=compress_trie(hyph_root);
1703 trie_root:=compress_trie(trie_root); {identify equivalent subtries}
1704 @z
1705 %---------------------------------------
1706 @x [43] m.958 l.18637 - e-TeX hyph_codes
1707 if trie_root=0 then {no patterns were given}
1708 @y
1709 if trie_max=0 then {no patterns were given}
1710 @z
1711 %---------------------------------------
1712 @x [43] m.958 l.18641 - e-TeX hyph_codes
1713 else begin trie_fix(trie_root); {this fixes the non-holes in |trie|}
1714 @y
1715 else begin if hyph_root>0 then trie_fix(hyph_root);
1716 if trie_root>0 then trie_fix(trie_root); {this fixes the non-holes in |trie|}
1717 @z
1718 %---------------------------------------
1719 @x [43] m.960 l.18684 new_patterns - e-TeX hyph_codes
1720 brace@>;
1721 @y
1722 brace@>;
1723 if saving_hyph_codes>0 then
1724 @<Store hyphenation codes for current language@>;
1725 @z
1726 %---------------------------------------
1727 @x [43] m.966 l.18791 init_trie - e-TeX hyph_codes
1728 @<Move the data into |trie|@>;
1729 @y
1730 if hyph_root<>0 then @<Pack all stored |hyph_codes|@>;
1731 @<Move the data into |trie|@>;
1732 @z
1733 %---------------------------------------
1734 @x [44] m.968 l.18807 - e-TeX saved_items
1735 whenever this is possible without backspacing.
1736 @y
1737 whenever this is possible without backspacing.
1738
1739 When the second argument |s| is |false| the deleted nodes are destroyed,
1740 otherwise they are collected in a list starting at |split_disc|.
1741 @z
1742 %---------------------------------------
1743 @x [44] m.968 l.18814 prune_page_top - e-TeX saved_items
1744 @p function prune_page_top(@!p:pointer):pointer; {adjust top after page break}
1745 var prev_p:pointer; {lags one step behind |p|}
1746 @!q:pointer; {temporary variable for list manipulation}
1747 @y
1748 @p function prune_page_top(@!p:pointer;@!s:boolean):pointer;
1749 {adjust top after page break}
1750 var prev_p:pointer; {lags one step behind |p|}
1751 @!q,@!r:pointer; {temporary variables for list manipulation}
1752 @z
1753 %---------------------------------------
1754 @x [44] m.968 l.18825 prune_page_top - e-TeX saved_items
1755 link(prev_p):=p; flush_node_list(q);
1756 @y
1757 link(prev_p):=p;
1758 if s then
1759 begin if split_disc=null then split_disc:=q@+else link(r):=q;
1760 r:=q;
1761 end
1762 else flush_node_list(q);
1763 @z
1764 %---------------------------------------
1765 @x [44] m.977 l.18992 vsplit - e-TeX marks, sparse arrays
1766 @p function vsplit(@!n:eight_bits; @!h:scaled):pointer;
1767 @y
1768 @p @t\4@>@<Declare the function called |do_marks|@>@;
1769 function vsplit(@!n:halfword; @!h:scaled):pointer;
1770 @z
1771 %---------------------------------------
1772 % FIXME incompatible?
1773 @x [44] m.977 l.18998 vsplit - e-TeX sparse arrays
1774 begin v:=box(n); vdir:=box_dir(v);
1775 @y
1776 begin cur_val:=n; fetch_box(v); vdir:=box_dir(v);
1777 @z
1778 %---------------------------------------
1779 % FIXME: how to detach this from sparse arrays?
1780 @x [44] m.977 l.18999 vsplit - e-TeX marks, saved_items
1781 if split_first_mark<>null then
1782 @y
1783 flush_node_list(split_disc); split_disc:=null;
1784 if sa_mark<>null then
1785 if do_marks(vsplit_init,0,sa_mark) then sa_mark:=null;
1786 if split_first_mark<>null then
1787 @z
1788 %---------------------------------------
1789 @x [44] m.977 l.19007 vsplit - e-TeX saved_items
1790 q:=prune_page_top(q); p:=list_ptr(v); free_node(v,box_node_size);
1791 @y
1792 q:=prune_page_top(q,saving_vdiscards>0);
1793 p:=list_ptr(v); free_node(v,box_node_size);
1794 @z
1795 %---------------------------------------
1796 % FIXME might be incompatible?
1797 @x [44] m.977 l.19008 vsplit - e-TeX sparse arrays
1798 if q=null then set_equiv(box_base+n,null)
1799 {the |eq_level| of the box stays the same}
1800 else set_equiv(box_base+n,vpack(q,natural));
1801 @y
1802 if q<>null then q:=vpack(q,natural);
1803 change_box(q); {the |eq_level| of the box stays the same}
1804 @z
1805 %---------------------------------------
1806 @x [44] m.979 l.19033 - e-TeX marks
1807 if split_first_mark=null then
1808 @y
1809 if mark_class(p)<>0 then @<Update the current marks for |vsplit|@>
1810 else if split_first_mark=null then
1811 @z
1812 %---------------------------------------
1813 @x [45] m.982 l.19167 - e-TeX last_node_type
1814 The variables |last_penalty| and |last_kern| are similar. And
1815 @y
1816 The variables |last_penalty|, |last_kern|, and |last_node_type|
1817 are similar. And
1818 @z
1819 %---------------------------------------
1820 @x [45] m.982 l.19180 - e-TeX last_node_type
1821 @!last_kern:scaled; {used to implement \.{\\lastkern}}
1822 @y
1823 @!last_kern:scaled; {used to implement \.{\\lastkern}}
1824 @!last_node_type:integer; {used to implement \.{\\lastnodetype}}
1825 @z
1826 %---------------------------------------
1827 @x [45] m.991 l.19317 - e-TeX last_node_type
1828 last_glue:=max_halfword; last_penalty:=0; last_kern:=0;
1829 @y
1830 last_glue:=max_halfword; last_penalty:=0; last_kern:=0;
1831 last_node_type:=-1;
1832 @z
1833 %---------------------------------------
1834 @x [45] m.996 l.19384 - e-TeX last_node_type
1835 last_penalty:=0; last_kern:=0;
1836 @y
1837 last_penalty:=0; last_kern:=0;
1838 last_node_type:=type(p)+1;
1839 @z
1840 %---------------------------------------
1841 @x [45] m.999 l.19421 - e-TeX saved_items
1842 link(contrib_head):=link(p); link(p):=null; flush_node_list(p)
1843 @y
1844 link(contrib_head):=link(p); link(p):=null;
1845 if saving_vdiscards>0 then
1846 begin if page_disc=null then page_disc:=p@+else link(tail_page_disc):=p;
1847 tail_page_disc:=p;
1848 end
1849 else flush_node_list(p)
1850 @z
1851 %---------------------------------------
1852 % FIXME: sparse arrays?
1853 @x [45] m.1012 l.19661 fire_up - e-TeX marks
1854 if bot_mark<>null then
1855 @y
1856 if sa_mark<>null then
1857 if do_marks(fire_up_init,0,sa_mark) then sa_mark:=null;
1858 if bot_mark<>null then
1859 @z
1860 %---------------------------------------
1861 @x [45] m.1012 l.19669 fire_up - e-TeX marks
1862 if (top_mark<>null)and(first_mark=null) then
1863 @y
1864 if sa_mark<>null then
1865 if do_marks(fire_up_done,0,sa_mark) then sa_mark:=null;
1866 if (top_mark<>null)and(first_mark=null) then
1867 @z
1868 %---------------------------------------
1869 @x [45] m.1014 l.19706 - e-TeX marks
1870 else if type(p)=mark_node then @<Update the values of
1871 @y
1872 else if type(p)=mark_node then
1873 if mark_class(p)<>0 then @<Update the current marks for |fire_up|@>
1874 else @<Update the values of
1875 @z
1876 %---------------------------------------
1877 @x [45] m.1021 l.19818 - e-TeX saved_items
1878 ins_ptr(p):=prune_page_top(broken_ptr(r));
1879 @y
1880 ins_ptr(p):=prune_page_top(broken_ptr(r),false);
1881 @z
1882 %---------------------------------------
1883 @x [45] m.1023 l.19854 - e-TeX saved_items
1884 ship_out(box(255)); set_equiv(box_base+255,null);
1885 @y
1886 flush_node_list(page_disc); page_disc:=null;
1887 ship_out(box(255)); set_equiv(box_base+255,null);
1888 @z
1889 %---------------------------------------
1890 @x [45] m.1026 l.19896 - e-TeX saved_items
1891 pop_nest; build_page;
1892 @y
1893 flush_node_list(page_disc); page_disc:=null;
1894 pop_nest; build_page;
1895 @z
1896 %---------------------------------------
1897 @x [47] m.1070 l.20697 normal_paragraph - e-TeX penalties
1898 if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
1899 @y
1900 if par_shape_ptr<>null then eq_define(par_shape_loc,shape_ref,null);
1901 if inter_line_penalties_ptr<>null then
1902 eq_define(inter_line_penalties_loc,shape_ref,null);
1903 @z
1904 %---------------------------------------
1905 @x [47] m.1071 l.20732 - e-TeX sparse arrays
1906 @d ship_out_flag==box_flag+(number_regs+number_regs)
1907 {context code for `\.{\\shipout}'}
1908 @y
1909 @d global_box_flag==box_flag+(number_regs+number_regs) {context code for `\.{\\global\\setbox0}'}
1910 @d ship_out_flag==global_box_flag+1 {context code for `\.{\\shipout}'}
1911 @z
1912 %---------------------------------------
1913 @x [47] m.1075 l.20815 box_end - e-TeX sparse arrays
1914 var p:pointer; {|ord_noad| for new box in math mode}
1915 @y
1916 var p:pointer; {|ord_noad| for new box in math mode}
1917 @!a:small_number; {global prefix}
1918 @z
1919 %---------------------------------------
1920 % FIXME: might not work this way
1921 @x [47] m.1077 l.20853 - e-TeX sparse arrays
1922 if box_context<box_flag+number_regs then
1923 eq_define(box_base-box_flag+box_context,box_ref,cur_box)
1924 else geq_define(box_base-box_flag-number_regs+box_context,box_ref,cur_box)
1925 @y
1926 begin if box_context<global_box_flag then
1927 begin cur_val:=box_context-box_flag; a:=0;
1928 end
1929 else begin cur_val:=box_context-global_box_flag; a:=4;
1930 end;
1931 if cur_val<256 then define(box_base+cur_val,box_ref,cur_box)
1932 else sa_def_box;
1933 end
1934 @z
1935 %---------------------------------------
1936 @x [47] m.1079 l.20885 begin_box - e-TeX sparse arrays
1937 @!n:eight_bits; {a box number}
1938 begin case cur_chr of
1939 box_code: begin scan_eight_bit_int; cur_box:=box(cur_val);
1940 set_equiv(box_base+cur_val,null);
1941 {the box becomes void, at the same level}
1942 end;
1943 copy_code: begin scan_eight_bit_int; cur_box:=copy_node_list(box(cur_val));
1944 @y
1945 @!n:halfword; {a box number}
1946 begin case cur_chr of
1947 box_code: begin scan_register_num; fetch_box(cur_box);
1948 set_equiv(box_base+cur_val,null);
1949 {the box becomes void, at the same level}
1950 end;
1951 copy_code: begin scan_register_num; fetch_box(q); cur_box:=copy_node_list(q);
1952 @z
1953 %---------------------------------------
1954 @x [47] m.1082 l.20935 - e-TeX sparse arrays
1955 begin scan_eight_bit_int; n:=cur_val;
1956 @y
1957 begin scan_register_num; n:=cur_val;
1958 @z
1959 %---------------------------------------
1960 @x [47] m.1101 l.21175 make_mark - e-TeX marks
1961 begin p:=scan_toks(false,true); p:=get_node(small_node_size);
1962 @y
1963 @!c:halfword; {the mark class}
1964 begin if cur_chr=0 then c:=0
1965 else begin scan_register_num; c:=cur_val;
1966 end;
1967 p:=scan_toks(false,true); p:=get_node(small_node_size);
1968 mark_class(p):=c;
1969 @z
1970 %---------------------------------------
1971 @x [47] m.1108 l.21262 - e-TeX saved_items
1972 un_vbox: if chr_code=copy_code then print_esc("unvcopy")
1973 @y
1974 un_vbox: if chr_code=copy_code then print_esc("unvcopy")
1975 @<Cases of |un_vbox| for |print_cmd_chr|@>@/
1976 @z
1977 %---------------------------------------
1978 @x [47] m.1110 l.21272 unpackage - e-TeX saved_items
1979 label exit;
1980 @y
1981 label done, exit;
1982 @z
1983 %---------------------------------------
1984 @x [47] m.1110 l.21275 unpackage - e-TeX saved_items, sparse arrays
1985 begin c:=cur_chr; scan_eight_bit_int; p:=box(cur_val);
1986 @y
1987 begin if cur_chr>copy_code then @<Handle saved items and |goto done|@>;
1988 c:=cur_chr; scan_register_num; fetch_box(p);
1989 @z
1990 %---------------------------------------
1991 % FIXME: might be incompatible
1992 @x [47] m.1110 l.21287 unpackage - e-TeX sparse arrays
1993 else begin link(tail):=list_ptr(p);
1994 set_equiv(box_base+cur_val,null);
1995 @y
1996 else begin link(tail):=list_ptr(p);
1997 change_box(null);
1998 @z
1999 %---------------------------------------
2000 @x [47] m.1110 l.21290 unpackage - e-TeX saved_items
2001 while link(tail)<>null do tail:=link(tail);
2002 @y
2003 done:
2004 while link(tail)<>null do tail:=link(tail);
2005 @z
2006 %---------------------------------------
2007 @x [48] m.1185 l.22243 - e-TeX middle
2008 if type(q)<>left_noad then confusion("right");
2009 @:this can't happen right}{\quad right@>
2010 info(numerator(incompleat_noad)):=link(q);
2011 link(q):=incompleat_noad; link(incompleat_noad):=p;
2012 @y
2013 if (type(q)<>left_noad)or(delim_ptr=null) then confusion("right");
2014 @:this can't happen right}{\quad right@>
2015 info(numerator(incompleat_noad)):=link(delim_ptr);
2016 link(delim_ptr):=incompleat_noad; link(incompleat_noad):=p;
2017 @z
2018 %---------------------------------------
2019 @x [48] m.1189 l.22288 - e-TeX middle
2020 else print_esc("right");
2021 @y
2022 @/@<Cases of |left_right| for |print_cmd_chr|@>@/
2023 else print_esc("right");
2024 @z
2025 %---------------------------------------
2026 @x [48] m.1191 l.22297 math_left_right - e-TeX middle
2027 begin t:=cur_chr;
2028 if (t=right_noad)and(cur_group<>math_left_group) then
2029 @y
2030 @!q:pointer; {resulting mlist}
2031 begin t:=cur_chr;
2032 if (t<>left_noad)and(cur_group<>math_left_group) then
2033 @z
2034 %---------------------------------------
2035 % FIXME: might be incompatible?
2036 @x [48] m.1191 l.22302 math_left_right - e-TeX middle
2037 if t=left_noad then
2038 begin push_math(math_left_group); link(head):=p; tail:=p;
2039 end
2040 else begin p:=fin_mlist(p);
2041 @<DIR: |unsave| math@>; {end of |math_left_group|}
2042 @y
2043 if t=middle_noad then
2044 begin type(p):=right_noad; subtype(p):=middle_noad;
2045 end;
2046 if t=left_noad then q:=p
2047 else begin q:=fin_mlist(p);
2048 @<DIR: |unsave| math@>; {end of |math_left_group|}
2049 end;
2050 if t<>right_noad then
2051 begin push_math(math_left_group); link(head):=q; tail:=p;
2052 delim_ptr:=p;
2053 end
2054 else begin
2055 @z
2056 %---------------------------------------
2057 @x [48] m.1191 l.22308 math_left_right - e-TeX middle
2058 info(nucleus(tail)):=p;
2059 @y
2060 info(nucleus(tail)):=q;
2061 @z
2062 %---------------------------------------
2063 @x [48] m.1192 l.22316 - e-TeX middle
2064 print_err("Extra "); print_esc("right");
2065 @.Extra \\right.@>
2066 help1("I'm ignoring a \right that had no matching \left.");
2067 @y
2068 print_err("Extra ");
2069 if t=middle_noad then
2070 begin print_esc("middle");
2071 @.Extra \\middle.@>
2072 help1("I'm ignoring a \middle that had no matching \left.");
2073 end
2074 else begin print_esc("right");
2075 @.Extra \\right.@>
2076 help1("I'm ignoring a \right that had no matching \left.");
2077 end;
2078 @z
2079 %---------------------------------------
2080 @x [49] m.1208 l.22577 - e-TeX protected
2081 control sequence can be defined to be `\.{\\long}' or `\.{\\outer}', and
2082 it might or might not be expanded. The prefixes `\.{\\global}', `\.{\\long}',
2083 @y
2084 control sequence can be defined to be `\.{\\long}', `\.{\\protected}',
2085 or `\.{\\outer}', and it might or might not be expanded. The prefixes
2086 `\.{\\global}', `\.{\\long}', `\.{\\protected}',
2087 @z
2088 %---------------------------------------
2089 @x [49] m.1209 l.22603 - e-TeX protected
2090 else print_esc("global");
2091 @y
2092 @/@<Cases of |prefix| for |print_cmd_chr|@>@/
2093 else print_esc("global");
2094 @z
2095 %---------------------------------------
2096 @x [49] m.1211 l.22665 prefixed_command - e-TeX tracing
2097 @<Discard erroneous prefixes and |return|@>;
2098 @y
2099 @<Discard erroneous prefixes and |return|@>;
2100 if tracing_commands>2 then if eTeX_ex then show_cur_cmd_chr;
2101 @z
2102 %---------------------------------------
2103 @x [49] m.1212 l.22730 - e-TeX protected
2104 help1("I'll pretend you didn't say \long or \outer or \global.");
2105 @y
2106 help1("I'll pretend you didn't say \long or \outer or \global.");
2107 if eTeX_ex then help_line[0]:=@|
2108 "I'll pretend you didn't say \long or \outer or \global or \protected.";
2109 @z
2110 %---------------------------------------
2111 @x [49] m.1213 l.22686 - e-TeX protected
2112 if (cur_cmd<>def)and(a mod 4<>0) then
2113 begin print_err("You can't use `"); print_esc("long"); print("' or `");
2114 print_esc("outer"); print("' with `");
2115 @y
2116 if a>=8 then
2117 begin j:=protected_token; a:=a-8;
2118 end
2119 else j:=0;
2120 if (cur_cmd<>def)and((a mod 4<>0)or(j<>0)) then
2121 begin print_err("You can't use `"); print_esc("long"); print("' or `");
2122 print_esc("outer");
2123 help1("I'll pretend you didn't say \long or \outer here.");
2124 if eTeX_ex then
2125 begin help_line[0]:=@|
2126 "I'll pretend you didn't say \long or \outer or \protected here.";
2127 print("' or `"); print_esc("protected");
2128 end;
2129 print("' with `");
2130 @z
2131 %---------------------------------------
2132 @x [49] m.1213 l.22691 - e-TeX protected
2133 help1("I'll pretend you didn't say \long or \outer here.");
2134 @y
2135 @z
2136 %---------------------------------------
2137 @x [49] m.1218 l.22749 - e-TeX protected
2138 q:=scan_toks(true,e); define(p,call+(a mod 4),def_ref);
2139 @y
2140 q:=scan_toks(true,e);
2141 if j<>0 then
2142 begin q:=get_avail; info(q):=j; link(q):=link(def_ref);
2143 link(def_ref):=q;
2144 end;
2145 define(p,call+(a mod 4),def_ref);
2146 @z
2147 %---------------------------------------
2148 @x [49] m.1224 l.22840 - e-TeX sparse arrays
2149 othercases begin scan_eight_bit_int;
2150 @y
2151 othercases begin scan_register_num;
2152 if cur_val>255 then
2153 begin j:=n-count_def_code; {|int_val..box_val|}
2154 if j>mu_val then j:=tok_val; {|int_val..mu_val| or |tok_val|}
2155 find_sa_element(j,cur_val,true); add_sa_ref(cur_ptr);
2156 if j=tok_val then j:=toks_register@+else j:=register;
2157 define(p,j,cur_ptr);
2158 end
2159 else
2160 @z
2161 %---------------------------------------
2162 @x [49] m.1225 l.22853 - e-TeX read_line
2163 read_to_cs: begin scan_int; n:=cur_val;
2164 @y
2165 read_to_cs: begin j:=cur_chr; scan_int; n:=cur_val;
2166 @z
2167 %---------------------------------------
2168 @x [49] m.1225 l.22861 - e-TeX read_line
2169 p:=cur_cs; read_toks(n,p); define(p,call,cur_val);
2170 @y
2171 p:=cur_cs; read_toks(n,p,j); define(p,call,cur_val);
2172 @z
2173 %---------------------------------------
2174 @x [49] m.1226 l.22870 - e-TeX sparse arrays
2175 if cur_cmd=toks_register then
2176 begin scan_eight_bit_int; p:=toks_base+cur_val;
2177 end
2178 else p:=cur_chr; {|p=every_par_loc| or |output_routine_loc| or \dots}
2179 @y
2180 e:=false; {just in case, will be set |true| for sparse array elements}
2181 if cur_cmd=toks_register then
2182 if cur_chr=mem_bot then
2183 begin scan_register_num;
2184 if cur_val>255 then
2185 begin find_sa_element(tok_val,cur_val,true);
2186 cur_chr:=cur_ptr; e:=true;
2187 end
2188 else cur_chr:=toks_base+cur_val;
2189 end
2190 else e:=true;
2191 p:=cur_chr; {|p=every_par_loc| or |output_routine_loc| or \dots}
2192 @z
2193 %---------------------------------------
2194 @x [49] m.1226 l.22880 - e-TeX sparse arrays
2195 begin define(p,undefined_cs,null); free_avail(def_ref);
2196 end
2197 else begin if p=output_routine_loc then {enclose in curlies}
2198 @y
2199 begin sa_define(p,null)(p,undefined_cs,null); free_avail(def_ref);
2200 end
2201 else begin if (p=output_routine_loc)and not e then {enclose in curlies}
2202 @z
2203 %---------------------------------------
2204 @x [49] m.1226 l.22888 - e-TeX sparse arrays
2205 define(p,call,def_ref);
2206 @y
2207 sa_define(p,def_ref)(p,call,def_ref);
2208 @z
2209 %---------------------------------------
2210 @x [49] m.1227 l.22893 - e-TeX sparse arrays
2211 begin if cur_cmd=toks_register then
2212 begin scan_eight_bit_int; cur_cmd:=assign_toks; cur_chr:=toks_base+cur_val;
2213 end;
2214 if cur_cmd=assign_toks then
2215 begin q:=equiv(cur_chr);
2216 if q=null then define(p,undefined_cs,null)
2217 else begin add_token_ref(q); define(p,call,q);
2218 end;
2219 goto done;
2220 end;
2221 end
2222 @y
2223 if (cur_cmd=toks_register)or(cur_cmd=assign_toks) then
2224 begin if cur_cmd=toks_register then
2225 if cur_chr=mem_bot then
2226 begin scan_register_num;
2227 if cur_val<256 then q:=equiv(toks_base+cur_val)
2228 else begin find_sa_element(tok_val,cur_val,false);
2229 if cur_ptr=null then q:=null
2230 else q:=sa_ptr(cur_ptr);
2231 end;
2232 end
2233 else q:=sa_ptr(cur_ptr)
2234 else q:=equiv(cur_chr);
2235 if q=null then sa_define(p,null)(p,undefined_cs,null)
2236 else begin add_token_ref(q); sa_define(p,q)(p,call,q);
2237 end;
2238 goto done;
2239 end
2240 @z
2241 %---------------------------------------
2242 @x [49] m.1236 l.23009 do_register_command - e-TeX sparse arrays
2243 begin q:=cur_cmd;
2244 @y
2245 @!e:boolean; {does |l| refer to a sparse array element?}
2246 @!w:integer; {integer or dimen value of |l|}
2247 begin q:=cur_cmd;
2248 e:=false; {just in case, will be set |true| for sparse array elements}
2249 @z
2250 %---------------------------------------
2251 @x [49] m.1236 l.23024 do_register_command - e-TeX sparse arrays
2252 if p<glue_val then word_define(l,cur_val)
2253 else begin trap_zero_glue; define(l,glue_ref,cur_val);
2254 @y
2255 if p<glue_val then sa_word_define(l,cur_val)
2256 else begin trap_zero_glue; sa_define(l,cur_val)(l,glue_ref,cur_val);
2257 @z
2258 %---------------------------------------
2259 @x [49] m.1237 l.23046 - e-TeX sparse arrays
2260 p:=cur_chr; scan_eight_bit_int;
2261 @y
2262 if (cur_chr<mem_bot)or(cur_chr>lo_mem_stat_max) then
2263 begin l:=cur_chr; p:=sa_type(l); e:=true;
2264 end
2265 else begin p:=cur_chr-mem_bot; scan_register_num;
2266 if cur_val>255 then
2267 begin find_sa_element(p,cur_val,true); l:=cur_ptr; e:=true;
2268 end
2269 else
2270 @z
2271 %---------------------------------------
2272 @x [49] m.1237 l.23053 - e-TeX sparse arrays
2273 end;
2274 found:
2275 @y
2276 end;
2277 end;
2278 found: if p<glue_val then@+if e then w:=sa_int(l)@+else w:=new_eqtb_int(l);
2279 else if e then s:=sa_ptr(l)@+else s:=equiv(l)
2280 @z
2281 %---------------------------------------
2282 @x [49] m.1238 l.23059 - e-TeX sparse arrays
2283 if q=advance then cur_val:=cur_val+new_eqtb_int(l);
2284 @y
2285 if q=advance then cur_val:=cur_val+w;
2286 @z
2287 %---------------------------------------
2288 @x [49] m.1239 l.23066 - e-TeX sparse arrays
2289 begin q:=new_spec(cur_val); r:=equiv(l);
2290 @y
2291 begin q:=new_spec(cur_val); r:=s;
2292 @z
2293 %---------------------------------------
2294 @x [49] m.1240 l.23086 - e-TeX sparse arrays
2295 if p=int_val then cur_val:=mult_integers(new_eqtb_int(l),cur_val)
2296 else cur_val:=nx_plus_y(new_eqtb_int(l),cur_val,0)
2297 else cur_val:=x_over_n(new_eqtb_int(l),cur_val)
2298 else begin s:=equiv(l); r:=new_spec(s);
2299 @y
2300 if p=int_val then cur_val:=mult_integers(w,cur_val)
2301 else cur_val:=nx_plus_y(w,cur_val,0)
2302 else cur_val:=x_over_n(w,cur_val)
2303 else begin r:=new_spec(s);
2304 @z
2305 %---------------------------------------
2306 @x [49] m.1241 l.23108 - e-TeX sparse arrays
2307 set_box: begin scan_eight_bit_int;
2308 if global then n:=number_regs+cur_val@+else n:=cur_val;
2309 scan_optional_equals;
2310 if set_box_allowed then scan_box(box_flag+n)
2311 @y
2312 set_box: begin scan_register_num;
2313 if global then n:=global_box_flag+cur_val@+else n:=box_flag+cur_val;
2314 scan_optional_equals;
2315 if set_box_allowed then scan_box(n)
2316 @z
2317 %---------------------------------------
2318 @x [49] m.1246 l.23179 alter_integer - e-TeX interaction_mode
2319 var c:0..1; {0 for \.{\\deadcycles}, 1 for \.{\\insertpenalties}}
2320 begin c:=cur_chr; scan_optional_equals; scan_int;
2321 if c=0 then dead_cycles:=cur_val
2322 @y
2323 var c:small_number;
2324 {0 for \.{\\deadcycles}, 1 for \.{\\insertpenalties}, etc.}
2325 begin c:=cur_chr; scan_optional_equals; scan_int;
2326 if c=0 then dead_cycles:=cur_val
2327 @/@<Cases for |alter_integer|@>@/
2328 @z
2329 %---------------------------------------
2330 @x [49] m.1247 l.23188 alter_box_dimen - e-TeX sparse arrays
2331 @!b:eight_bits; {box number}
2332 begin c:=cur_chr; scan_eight_bit_int; b:=cur_val; scan_optional_equals;
2333 scan_normal_dimen;
2334 if box(b)<>null then mem[box(b)+c].sc:=cur_val;
2335 @y
2336 @!b:pointer; {box register}
2337 begin c:=cur_chr; scan_register_num; fetch_box(b); scan_optional_equals;
2338 scan_normal_dimen;
2339 if b<>null then mem[b+c].sc:=cur_val;
2340 @z
2341 %---------------------------------------
2342 @x [49] m.1248 l.23197 - e-TeX penalties
2343 set_shape: begin scan_optional_equals; scan_int; n:=cur_val;
2344 if n<=0 then p:=null
2345 @y
2346 set_shape: begin q:=cur_chr; scan_optional_equals; scan_int; n:=cur_val;
2347 if n<=0 then p:=null
2348 else if q>par_shape_loc then
2349 begin n:=(cur_val div 2)+1; p:=get_node(2*n+1); info(p):=n;
2350 n:=cur_val; mem[p+1].int:=n; {number of penalties}
2351 for j:=p+2 to p+n+1 do
2352 begin scan_int; mem[j].int:=cur_val; {penalty values}
2353 end;
2354 if not odd(n) then mem[p+n+2].int:=0; {unused}
2355 end
2356 @z
2357 %---------------------------------------
2358 @x [49] m.1248 l.23207 - e-TeX penalties
2359 define(par_shape_loc,shape_ref,p);
2360 @y
2361 define(q,shape_ref,p);
2362 @z
2363 %---------------------------------------
2364 @x [49] m.1292 l.23581 - e-TeX show_groups
2365 show_lists_code:print_esc("showlists");
2366 @y
2367 show_lists_code:print_esc("showlists");
2368 @<Cases of |xray| for |print_cmd_chr|@>@;@/
2369 @z
2370 %---------------------------------------
2371 @x [49] m.1293 l.23588 show_whatever - e-TeX show_ifs
2372 var p:pointer; {tail of a token list to show}
2373 @y
2374 var p:pointer; {tail of a token list to show}
2375 @!t:small_number; {type of conditional being shown}
2376 @!m:normal..or_code; {upper bound on |fi_or_else| codes}
2377 @!l:integer; {line where that conditional began}
2378 @!n:integer; {level of \.{\\if...\\fi} nesting}
2379 @z
2380 %---------------------------------------
2381 @x [49] m.1293 l.23594 show_whatever - e-TeX show_groups
2382 othercases @<Show the current value of some parameter or register,
2383 @y
2384 @<Cases for |show_whatever|@>@;@/
2385 othercases @<Show the current value of some parameter or register,
2386 @z
2387 %---------------------------------------
2388 @x [49] m.1295 l.23629 - e-TeX protected
2389 call: print("macro");
2390 long_call: print_esc("long macro");
2391 outer_call: print_esc("outer macro");
2392 long_outer_call: begin print_esc("long"); print_esc("outer macro");
2393 @y
2394 call,long_call,outer_call,long_outer_call: begin n:=cmd-call;
2395 if info(link(chr_code))=protected_token then n:=n+4;
2396 if odd(n div 4) then print_esc("protected");
2397 if odd(n) then print_esc("long");
2398 if odd(n div 2) then print_esc("outer");
2399 if n>0 then print_char(" ");
2400 print("macro");
2401 @z
2402 %---------------------------------------
2403 @x [49] m.1296 l.23637 - e-TeX sparse arrays
2404 begin scan_eight_bit_int; begin_diagnostic;
2405 print_nl("> \box"); print_int(cur_val); print_char("=");
2406 if box(cur_val)=null then print("void")
2407 else show_box(box(cur_val));
2408 @y
2409 begin scan_register_num; fetch_box(p); begin_diagnostic;
2410 print_nl("> \box"); print_int(cur_val); print_char("=");
2411 if p=null then print("void")@+else show_box(p);
2412 @z
2413 %---------------------------------------
2414 @x [50] m.1307 l.23779 - e-TeX basic
2415 dump_int(@$);@/
2416 @y
2417 dump_int(@$);@/
2418 @<Dump the \eTeX\ state@>@/
2419 @z
2420 %---------------------------------------
2421 @x [50] m.1308 l.23794 - e-TeX basic
2422 if x<>@$ then goto bad_fmt; {check that strings are the same}
2423 @y
2424 if x<>@$ then goto bad_fmt; {check that strings are the same}
2425 @/@<Undump the \eTeX\ state@>@/
2426 @z
2427 %---------------------------------------
2428 @x [50] m.1311 l.23848 - e-TeX sparse arrays
2429 dump_int(lo_mem_max); dump_int(rover);
2430 @y
2431 dump_int(lo_mem_max); dump_int(rover);
2432 if eTeX_ex then for k:=int_val to tok_val do dump_int(sa_root[k]);
2433 @z
2434 %---------------------------------------
2435 @x [50] m.1312 l.23871 - e-TeX sparse arrays
2436 undump(lo_mem_stat_max+1)(lo_mem_max)(rover);
2437 @y
2438 undump(lo_mem_stat_max+1)(lo_mem_max)(rover);
2439 if eTeX_ex then for k:=int_val to tok_val do
2440 undump(null)(lo_mem_max)(sa_root[k]);
2441 @z
2442 %---------------------------------------
2443 @x [50] m.1324 l.24065 - e-TeX hyph_codes
2444 dump_int(trie_max);
2445 @y
2446 dump_int(trie_max);
2447 dump_int(hyph_start);
2448 @z
2449 %---------------------------------------
2450 @x [50] m.1325 l.24093 - e-TeX hyph_codes
2451 undump_size(0)(trie_size)('trie size')(j); @+init trie_max:=j;@+tini
2452 @y
2453 undump_size(0)(trie_size)('trie size')(j); @+init trie_max:=j;@+tini
2454 undump(0)(j)(hyph_start);
2455 @z
2456 %---------------------------------------
2457 @x [51] m.1335 l.24313 final_cleanup - tracing
2458 print_int(cur_level-level_one); print_char(")");
2459 @y
2460 print_int(cur_level-level_one); print_char(")");
2461 if eTeX_ex then show_save_groups;
2462 @z
2463 %---------------------------------------
2464 @x [51] m.1335 l.24336 final_cleanup - e-TeX marks, saved_items
2465 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
2466 @y
2467 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
2468 if sa_mark<>null then
2469 if do_marks(destroy_marks,0,sa_mark) then sa_mark:=null;
2470 for c:=last_box_code to vsplit_code do flush_node_list(disc_ptr[c]);
2471 @z
2472 %---------------------------------------
2473 @x [51] m.1336 l.24345 ] m.1336 l.24340 init_prim - e-TeX basic
2474 begin no_new_control_sequence:=false;
2475 @y
2476 begin no_new_control_sequence:=false;
2477 first:=0;
2478 @z
2479 %---------------------------------------
2480 @x [51] m.1337 l.24360 - e-TeX basic
2481 if (format_ident=0)or(buffer[loc]="&") then
2482 @y
2483 @<Enable \eTeX, if requested@>@;@/
2484 if (format_ident=0)or(buffer[loc]="&") then
2485 @z
2486 %---------------------------------------
2487 @x [51] m.1337 l.24368 - e-TeX basic
2488 end;
2489 @y
2490 end;
2491 if eTeX_ex then wterm_ln('entering extended mode');
2492 @z
2493 %---------------------------------------
2494 @x [53] m.1363 l.24715 - e-TeX hyph_codes
2495 adv_past(s)
2496 @y
2497 if subtype(s)=language_node then
2498 begin cur_lang:=what_lang(s); l_hyf:=what_lhm(s); r_hyf:=what_rhm(s);
2499 set_hyph_index;
2500 end
2501 @z
2502 %---------------------------------------
2503 @x [54] m.1379 l.24903 - e-TeX additions
2504 @* \[54] System-dependent changes.
2505 @y
2506 @* \[53a] The extended features of \eTeX.
2507 The program has two modes of operation: (1)~In \TeX\ compatibility mode
2508 it fully deserves the name \TeX\ and there are neither extended features
2509 nor additional primitive commands. There are, however, a few
2510 modifications that would be legitimate in any implementation of \TeX\
2511 such as, e.g., preventing inadequate results of the glue to \.{DVI}
2512 unit conversion during |ship_out|. (2)~In extended mode there are
2513 additional primitive commands and the extended features of \eTeX\ are
2514 available.
2515
2516 The distinction between these two modes of operation initially takes
2517 place when a `virgin' \.{eINITEX} starts without reading a format file.
2518 Later on the values of all \eTeX\ state variables are inherited when
2519 \.{eVIRTEX} (or \.{eINITEX}) reads a format file.
2520
2521 The code below is designed to work for cases where `$|init|\ldots|tini|$'
2522 is a run-time switch.
2523
2524 @<Enable \eTeX, if requested@>=
2525 @!init if (buffer[loc]="*")and(format_ident=" (INITEX)") then
2526 begin no_new_control_sequence:=false;
2527 @<Generate all \eTeX\ primitives@>@;
2528 incr(loc); eTeX_mode:=1; {enter extended mode}
2529 @<Initialize variables for \eTeX\ extended mode@>@;
2530 end;
2531 tini@;@/
2532 if not no_new_control_sequence then {just entered extended mode ?}
2533 no_new_control_sequence:=true@+else
2534
2535 @ The \eTeX\ features available in extended mode are grouped into two
2536 categories: (1)~Some of them are permanently enabled and have no
2537 semantic effect as long as none of the additional primitives are
2538 executed. (2)~The remaining \eTeX\ features are optional and can be
2539 individually enabled and disabled. For each optional feature there is
2540 an \eTeX\ state variable named \.{\\...state}; the feature is enabled,
2541 resp.\ disabled by assigning a positive, resp.\ non-positive value to
2542 that integer.
2543
2544 @d eTeX_state_base=int_base+eTeX_state_code
2545 @d eTeX_state(#)==eqtb[eTeX_state_base+#].int {an \eTeX\ state variable}
2546 @#
2547 @d eTeX_version_code=eTeX_int {code for \.{\\eTeXversion}}
2548 @d eTeX_revision_code=6 {command code for \.{\\eTeXrevision}}
2549
2550 @<Generate all \eTeX...@>=
2551 primitive("lastnodetype",last_item,last_node_type_code);
2552 @!@:last_node_type_}{\.{\\lastnodetype} primitive@>
2553 primitive("eTeXversion",last_item,eTeX_version_code);
2554 @!@:eTeX_version_}{\.{\\eTeXversion} primitive@>
2555 primitive("eTeXrevision",convert,eTeX_revision_code);@/
2556 @!@:eTeX_revision_}{\.{\\eTeXrevision} primitive@>
2557
2558 @ @<Cases of |last_item| for |print_cmd_chr|@>=
2559 last_node_type_code: print_esc("lastnodetype");
2560 eTeX_version_code: print_esc("eTeXversion");
2561
2562 @ @<Cases for fetching an integer value@>=
2563 eTeX_version_code: cur_val:=eTeX_version;
2564
2565 @ @<Cases of |convert| for |print_cmd_chr|@>=
2566 eTeX_revision_code: print_esc("eTeXrevision");
2567
2568 @ @<Cases of `Scan the argument for command |c|'@>=
2569 eTeX_revision_code: do_nothing;
2570
2571 @ @<Cases of `Print the result of command |c|'@>=
2572 eTeX_revision_code: print(eTeX_revision);
2573
2574 @ @d eTeX_ex==(eTeX_mode=1) {is this extended mode?}
2575
2576 @<Glob...@>=
2577 @!eTeX_mode: 0..1; {identifies compatibility and extended mode}
2578
2579 @ @<Initialize table entries...@>=
2580 eTeX_mode:=0; {initially we are in compatibility mode}
2581 @<Initialize variables for \eTeX\ compatibility mode@>@;
2582
2583 @ @<Dump the \eTeX\ state@>=
2584 dump_int(eTeX_mode);
2585 for j:=0 to eTeX_states-1 do eTeX_state(j):=0; {disable all enhancements}
2586
2587 @ @<Undump the \eTeX\ state@>=
2588 undump(0)(1)(eTeX_mode);
2589 if eTeX_ex then
2590 begin @<Initialize variables for \eTeX\ extended mode@>@;
2591 end
2592 else begin @<Initialize variables for \eTeX\ compatibility mode@>@;
2593 end;
2594
2595 @ The |eTeX_enabled| function simply returns its first argument as
2596 result. This argument is |true| if an optional \eTeX\ feature is
2597 currently enabled; otherwise, if the argument is |false|, the function
2598 gives an error message.
2599
2600 @<Declare \eTeX\ procedures for use...@>=
2601 function eTeX_enabled(@!b:boolean;@!j:quarterword;@!k:halfword):boolean;
2602 begin if not b then
2603 begin print_err("Improper "); print_cmd_chr(j,k);
2604 help1("Sorry, this optional e-TeX feature has been disabled."); error;
2605 end;
2606 eTeX_enabled:=b;
2607 end;
2608
2609 @ First we implement the additional \eTeX\ parameters in the table of
2610 equivalents.
2611
2612 @<Generate all \eTeX...@>=
2613 primitive("everyeof",assign_toks,every_eof_loc);
2614 @!@:every_eof_}{\.{\\everyeof} primitive@>
2615 primitive("tracingassigns",assign_int,int_base+tracing_assigns_code);@/
2616 @!@:tracing_assigns_}{\.{\\tracingassigns} primitive@>
2617 primitive("tracinggroups",assign_int,int_base+tracing_groups_code);@/
2618 @!@:tracing_groups_}{\.{\\tracinggroups} primitive@>
2619 primitive("tracingifs",assign_int,int_base+tracing_ifs_code);@/
2620 @!@:tracing_ifs_}{\.{\\tracingifs} primitive@>
2621 primitive("tracingscantokens",assign_int,int_base+tracing_scan_tokens_code);@/
2622 @!@:tracing_scan_tokens_}{\.{\\tracingscantokens} primitive@>
2623 primitive("tracingnesting",assign_int,int_base+tracing_nesting_code);@/
2624 @!@:tracing_nesting_}{\.{\\tracingnesting} primitive@>
2625 { FIXME: the next two should be commented }
2626 primitive("predisplaydirection",
2627 assign_int,int_base+pre_display_direction_code);@/
2628 @!@:pre_display_direction_}{\.{\\predisplaydirection} primitive@>
2629 primitive("lastlinefit",assign_int,int_base+last_line_fit_code);@/
2630 @!@:last_line_fit_}{\.{\\lastlinefit} primitive@>
2631 primitive("savingvdiscards",assign_int,int_base+saving_vdiscards_code);@/
2632 @!@:saving_vdiscards_}{\.{\\savingvdiscards} primitive@>
2633 primitive("savinghyphcodes",assign_int,int_base+saving_hyph_codes_code);@/
2634 @!@:saving_hyph_codes_}{\.{\\savinghyphcodes} primitive@>
2635
2636 @ @d every_eof==equiv(every_eof_loc)
2637
2638 @<Cases of |assign_toks| for |print_cmd_chr|@>=
2639 every_eof_loc: print_esc("everyeof");
2640
2641 @ @<Cases for |print_param|@>=
2642 tracing_assigns_code:print_esc("tracingassigns");
2643 tracing_groups_code:print_esc("tracinggroups");
2644 tracing_ifs_code:print_esc("tracingifs");
2645 tracing_scan_tokens_code:print_esc("tracingscantokens");
2646 tracing_nesting_code:print_esc("tracingnesting");
2647 { FIXME: the next one should be commented }
2648 pre_display_direction_code:print_esc("predisplaydirection");
2649 last_line_fit_code:print_esc("lastlinefit");
2650 saving_vdiscards_code:print_esc("savingvdiscards");
2651 saving_hyph_codes_code:print_esc("savinghyphcodes");
2652
2653 @ In order to handle \.{\\everyeof} we need an array |eof_seen| of
2654 boolean variables.
2655
2656 @<Glob...@>=
2657 @!eof_seen : array[1..max_in_open] of boolean; {has eof been seen?}
2658
2659 @ The |print_group| procedure prints the current level of grouping and
2660 the name corresponding to |cur_group|.
2661
2662 @<Declare \eTeX\ procedures for tr...@>=
2663 procedure print_group(@!e:boolean);
2664 label exit;
2665 begin case cur_group of
2666 bottom_level: begin print("bottom level"); return;
2667 end;
2668 simple_group,semi_simple_group:
2669 begin if cur_group=semi_simple_group then print("semi ");
2670 print("simple");
2671 end;
2672 hbox_group,adjusted_hbox_group:
2673 begin if cur_group=adjusted_hbox_group then print("adjusted ");
2674 print("hbox");
2675 end;
2676 vbox_group: print("vbox");
2677 vtop_group: print("vtop");
2678 align_group,no_align_group:
2679 begin if cur_group=no_align_group then print("no ");
2680 print("align");
2681 end;
2682 output_group: print("output");
2683 disc_group: print("disc");
2684 insert_group: print("insert");
2685 vcenter_group: print("vcenter");
2686 math_group,math_choice_group,math_shift_group,math_left_group:
2687 begin print("math");
2688 if cur_group=math_choice_group then print(" choice")
2689 else if cur_group=math_shift_group then print(" shift")
2690 else if cur_group=math_left_group then print(" left");
2691 end;
2692 end; {there are no other cases}
2693 print(" group (level "); print_int(qo(cur_level)); print_char(")");
2694 if saved(-1)<>0 then
2695 begin if e then print(" entered at line ") else print(" at line ");
2696 print_int(saved(-1));
2697 end;
2698 exit:end;
2699
2700 @ The |group_trace| procedure is called when a new level of grouping
2701 begins (|e=false|) or ends (|e=true|) with |saved(-1)| containing the
2702 line number.
2703
2704 @<Declare \eTeX\ procedures for tr...@>=
2705 @!stat procedure group_trace(@!e:boolean);
2706 begin begin_diagnostic; print_char("{");
2707 if e then print("leaving ") else print("entering ");
2708 print_group(e); print_char("}"); end_diagnostic(false);
2709 end;
2710 tats
2711
2712 @ The \.{\\currentgrouplevel} and \.{\\currentgrouptype} commands return
2713 the current level of grouping and the type of the current group
2714 respectively.
2715
2716 @d current_group_level_code=eTeX_int+1 {code for \.{\\currentgrouplevel}}
2717 @d current_group_type_code=eTeX_int+2 {code for \.{\\currentgrouptype}}
2718
2719 @<Generate all \eTeX...@>=
2720 primitive("currentgrouplevel",last_item,current_group_level_code);
2721 @!@:current_group_level_}{\.{\\currentgrouplevel} primitive@>
2722 primitive("currentgrouptype",last_item,current_group_type_code);
2723 @!@:current_group_type_}{\.{\\currentgrouptype} primitive@>
2724
2725 @ @<Cases of |last_item| for |print_cmd_chr|@>=
2726 current_group_level_code: print_esc("currentgrouplevel");
2727 current_group_type_code: print_esc("currentgrouptype");
2728
2729 @ @<Cases for fetching an integer value@>=
2730 current_group_level_code: cur_val:=cur_level-level_one;
2731 current_group_type_code: cur_val:=cur_group;
2732
2733 @ The \.{\\currentiflevel}, \.{\\currentiftype}, and
2734 \.{\\currentifbranch} commands return the current level of conditionals
2735 and the type and branch of the current conditional.
2736
2737 @d current_if_level_code=eTeX_int+3 {code for \.{\\currentiflevel}}
2738 @d current_if_type_code=eTeX_int+4 {code for \.{\\currentiftype}}
2739 @d current_if_branch_code=eTeX_int+5 {code for \.{\\currentifbranch}}
2740
2741 @<Generate all \eTeX...@>=
2742 primitive("currentiflevel",last_item,current_if_level_code);
2743 @!@:current_if_level_}{\.{\\currentiflevel} primitive@>
2744 primitive("currentiftype",last_item,current_if_type_code);
2745 @!@:current_if_type_}{\.{\\currentiftype} primitive@>
2746 primitive("currentifbranch",last_item,current_if_branch_code);
2747 @!@:current_if_branch_}{\.{\\currentifbranch} primitive@>
2748
2749 @ @<Cases of |last_item| for |print_cmd_chr|@>=
2750 current_if_level_code: print_esc("currentiflevel");
2751 current_if_type_code: print_esc("currentiftype");
2752 current_if_branch_code: print_esc("currentifbranch");
2753
2754 @ @<Cases for fetching an integer value@>=
2755 current_if_level_code: begin q:=cond_ptr; cur_val:=0;
2756 while q<>null do
2757 begin incr(cur_val); q:=link(q);
2758 end;
2759 end;
2760 current_if_type_code: if cond_ptr=null then cur_val:=0
2761 else if cur_if<unless_code then cur_val:=cur_if+1
2762 else cur_val:=-(cur_if-unless_code+1);
2763 current_if_branch_code:
2764 if (if_limit=or_code)or(if_limit=else_code) then cur_val:=1
2765 else if if_limit=fi_code then cur_val:=-1
2766 else cur_val:=0;
2767
2768 @ The \.{\\fontcharwd}, \.{\\fontcharht}, \.{\\fontchardp}, and
2769 \.{\\fontcharic} commands return information about a character in a
2770 font.
2771
2772 @d font_char_wd_code=eTeX_dim {code for \.{\\fontcharwd}}
2773 @d font_char_ht_code=eTeX_dim+1 {code for \.{\\fontcharht}}
2774 @d font_char_dp_code=eTeX_dim+2 {code for \.{\\fontchardp}}
2775 @d font_char_ic_code=eTeX_dim+3 {code for \.{\\fontcharic}}
2776
2777 @<Generate all \eTeX...@>=
2778 primitive("fontcharwd",last_item,font_char_wd_code);
2779 @!@:font_char_wd_}{\.{\\fontcharwd} primitive@>
2780 primitive("fontcharht",last_item,font_char_ht_code);
2781 @!@:font_char_ht_}{\.{\\fontcharht} primitive@>
2782 primitive("fontchardp",last_item,font_char_dp_code);
2783 @!@:font_char_dp_}{\.{\\fontchardp} primitive@>
2784 primitive("fontcharic",last_item,font_char_ic_code);
2785 @!@:font_char_ic_}{\.{\\fontcharic} primitive@>
2786
2787 @ @<Cases of |last_item| for |print_cmd_chr|@>=
2788 font_char_wd_code: print_esc("fontcharwd");
2789 font_char_ht_code: print_esc("fontcharht");
2790 font_char_dp_code: print_esc("fontchardp");
2791 font_char_ic_code: print_esc("fontcharic");
2792
2793 @ @<Cases for fetching a dimension value@>=
2794 font_char_wd_code,
2795 font_char_ht_code,
2796 font_char_dp_code,
2797 font_char_ic_code: begin scan_font_ident; q:=cur_val; scan_char_num;
2798 if (font_bc(q)<=cur_val)and(font_ec(q)>=cur_val) then
2799 begin i:=char_info(q)(qi(cur_val));
2800 case m of
2801 font_char_wd_code: cur_val:=char_width(q)(i);
2802 font_char_ht_code: cur_val:=char_height(q)(height_depth(i));
2803 font_char_dp_code: cur_val:=char_depth(q)(height_depth(i));
2804 font_char_ic_code: cur_val:=char_italic(q)(i);
2805 end; {there are no other cases}
2806 end
2807 else cur_val:=0;
2808 end;
2809
2810 @ The \.{\\parshapedimen}, \.{\\parshapeindent}, and \.{\\parshapelength}
2811 commands return the indent and length parameters of the current
2812 \.{\\parshape} specification.
2813
2814 @d par_shape_length_code=eTeX_dim+4 {code for \.{\\parshapelength}}
2815 @d par_shape_indent_code=eTeX_dim+5 {code for \.{\\parshapeindent}}
2816 @d par_shape_dimen_code=eTeX_dim+6 {code for \.{\\parshapedimen}}
2817
2818 @<Generate all \eTeX...@>=
2819 primitive("parshapelength",last_item,par_shape_length_code);
2820 @!@:par_shape_length_}{\.{\\parshapelength} primitive@>
2821 primitive("parshapeindent",last_item,par_shape_indent_code);
2822 @!@:par_shape_indent_}{\.{\\parshapeindent} primitive@>
2823 primitive("parshapedimen",last_item,par_shape_dimen_code);
2824 @!@:par_shape_dimen_}{\.{\\parshapedimen} primitive@>
2825
2826 @ @<Cases of |last_item| for |print_cmd_chr|@>=
2827 par_shape_length_code: print_esc("parshapelength");
2828 par_shape_indent_code: print_esc("parshapeindent");
2829 par_shape_dimen_code: print_esc("parshapedimen");
2830
2831 @ @<Cases for fetching a dimension value@>=
2832 par_shape_length_code,
2833 par_shape_indent_code,
2834 par_shape_dimen_code: begin q:=cur_chr-par_shape_length_code; scan_int;
2835 if (par_shape_ptr=null)or(cur_val<=0) then cur_val:=0
2836 else begin if q=2 then
2837 begin q:=cur_val mod 2; cur_val:=(cur_val+q)div 2;
2838 end;
2839 if cur_val>info(par_shape_ptr) then cur_val:=info(par_shape_ptr);
2840 cur_val:=mem[par_shape_ptr+2*cur_val-q].sc;
2841 end;
2842 cur_val_level:=dimen_val;
2843 end;
2844
2845 @ The \.{\\showgroups} command displays all currently active grouping
2846 levels.
2847
2848 @d show_groups=4 { \.{\\showgroups} }
2849
2850 @<Generate all \eTeX...@>=
2851 primitive("showgroups",xray,show_groups);
2852 @!@:show_groups_}{\.{\\showgroups} primitive@>
2853
2854 @ @<Cases of |xray| for |print_cmd_chr|@>=
2855 show_groups:print_esc("showgroups");
2856
2857 @ @<Cases for |show_whatever|@>=
2858 show_groups: begin begin_diagnostic; show_save_groups;
2859 end;
2860
2861 @ @<Types...@>=
2862 @!save_pointer=0..save_size; {index into |save_stack|}
2863
2864 @ The modifications of \TeX\ required for the display produced by the
2865 |show_save_groups| procedure were first discussed by Donald~E. Knuth in
2866 {\sl TUGboat\/} {\bf 11}, 165--170 and 499--511, 1990.
2867 @^Knuth, Donald Ervin@>
2868
2869 In order to understand a group type we also have to know its mode.
2870 Since unrestricted horizontal modes are not associated with grouping,
2871 they are skipped when traversing the semantic nest.
2872
2873 @<Declare \eTeX\ procedures for use...@>=
2874 procedure show_save_groups;
2875 label found1,found2,found,done;
2876 var p:0..nest_size; {index into |nest|}
2877 @!m:-mmode..mmode; {mode}
2878 @!v:save_pointer; {saved value of |save_ptr|}
2879 @!l:quarterword; {saved value of |cur_level|}
2880 @!c:group_code; {saved value of |cur_group|}
2881 @!a:-1..1; {to keep track of alignments}
2882 @!i:integer;
2883 @!j:quarterword;
2884 @!s:str_number;
2885 begin p:=nest_ptr; nest[p]:=cur_list; {put the top level into the array}
2886 v:=save_ptr; l:=cur_level; c:=cur_group;
2887 save_ptr:=cur_boundary; decr(cur_level);@/
2888 a:=1;
2889 print_nl(""); print_ln;
2890 loop@+begin print_nl("### "); print_group(true);
2891 if cur_group=bottom_level then goto done;
2892 repeat m:=nest[p].mode_field;
2893 if p>0 then decr(p) else m:=vmode;
2894 until m<>hmode;
2895 print(" (");
2896 case cur_group of
2897 simple_group: begin incr(p); goto found2;
2898 end;
2899 hbox_group,adjusted_hbox_group: s:="hbox";
2900 vbox_group: s:="vbox";
2901 vtop_group: s:="vtop";
2902 align_group: if a=0 then
2903 begin if m=-vmode then s:="halign" else s:="valign";
2904 a:=1; goto found1;
2905 end
2906 else begin if a=1 then print("align entry") else print_esc("cr");
2907 if p>=a then p:=p-a;
2908 a:=0; goto found;
2909 end;
2910 no_align_group:
2911 begin incr(p); a:=-1; print_esc("noalign"); goto found2;
2912 end;
2913 output_group:
2914 begin print_esc("output"); goto found;
2915 end;
2916 math_group: goto found2;
2917 disc_group,math_choice_group:
2918 begin if cur_group=disc_group then print_esc("discretionary")
2919 else print_esc("mathchoice");
2920 for i:=1 to 3 do if i<=saved(-2) then print("{}");
2921 goto found2;
2922 end;
2923 insert_group:
2924 begin if saved(-2)=255 then print_esc("vadjust")
2925 else begin print_esc("insert"); print_int(saved(-2));
2926 end;
2927 goto found2;
2928 end;
2929 vcenter_group: begin s:="vcenter"; goto found1;
2930 end;
2931 semi_simple_group: begin incr(p); print_esc("begingroup"); goto found;
2932 end;
2933 math_shift_group:
2934 begin if m=mmode then print_char("$")
2935 else if nest[p].mode_field=mmode then
2936 begin print_cmd_chr(eq_no,saved(-2)); goto found;
2937 end;
2938 print_char("$"); goto found;
2939 end;
2940 math_left_group:
2941 begin if type(nest[p+1].eTeX_aux_field)=left_noad then print_esc("left")
2942 else print_esc("middle");
2943 goto found;
2944 end;
2945 end; {there are no other cases}
2946 @<Show the box context@>;
2947 found1: print_esc(s); @<Show the box packaging info@>;
2948 found2: print_char("{");
2949 found: print_char(")"); decr(cur_level);
2950 cur_group:=save_level(save_ptr); save_ptr:=save_index(save_ptr)
2951 end;
2952 done: save_ptr:=v; cur_level:=l; cur_group:=c;
2953 end;
2954
2955 @ @<Show the box packaging info@>=
2956 if saved(-2)<>0 then
2957 begin print_char(" ");
2958 if saved(-3)=exactly then print("to") else print("spread");
2959 print_scaled(saved(-2)); print("pt");
2960 end
2961
2962 @ @<Show the box context@>=
2963 i:=saved(-4);
2964 if i<>0 then
2965 if i<box_flag then
2966 begin if abs(nest[p].mode_field)=vmode then j:=hmove else j:=vmove;
2967 if i>0 then print_cmd_chr(j,0) else print_cmd_chr(j,1);
2968 print_scaled(abs(i)); print("pt");
2969 end
2970 else if i<ship_out_flag then
2971 begin if i>=global_box_flag then
2972 begin print_esc("global"); i:=i-(global_box_flag-box_flag);
2973 end;
2974 print_esc("setbox"); print_int(i-box_flag); print_char("=");
2975 end
2976 else print_cmd_chr(leader_ship,i-(leader_flag-a_leaders))
2977
2978 @ The |scan_general_text| procedure is much like |scan_toks(false,false)|,
2979 but will be invoked via |expand|, i.e., recursively.
2980 @^recursion@>
2981
2982 @<Declare \eTeX\ procedures for sc...@>=
2983 procedure@?scan_general_text; forward;@t\2@>
2984
2985 @ The token list (balanced text) created by |scan_general_text| begins
2986 at |link(temp_head)| and ends at |cur_val|. (If |cur_val=temp_head|,
2987 the list is empty.)
2988
2989 @<Declare \eTeX\ procedures for tok...@>=
2990 procedure scan_general_text;
2991 label found;
2992 var s:normal..absorbing; {to save |scanner_status|}
2993 @!w:pointer; {to save |warning_index|}
2994 @!d:pointer; {to save |def_ref|}
2995 @!p:pointer; {tail of the token list being built}
2996 @!q:pointer; {new node being added to the token list via |store_new_token|}
2997 @!unbalance:halfword; {number of unmatched left braces}
2998 begin s:=scanner_status; w:=warning_index; d:=def_ref;
2999 scanner_status:=absorbing; warning_index:=cur_cs;
3000 def_ref:=get_avail; token_ref_count(def_ref):=null; p:=def_ref;
3001 scan_left_brace; {remove the compulsory left brace}
3002 unbalance:=1;
3003 loop@+ begin get_token;
3004 if cur_tok<right_brace_limit then
3005 if cur_cmd<right_brace then incr(unbalance)
3006 else begin decr(unbalance);
3007 if unbalance=0 then goto found;
3008 end;
3009 store_new_token(cur_tok);
3010 end;
3011 found: q:=link(def_ref); free_avail(def_ref); {discard reference count}
3012 if q=null then cur_val:=temp_head @+ else cur_val:=p;
3013 link(temp_head):=q;
3014 scanner_status:=s; warning_index:=w; def_ref:=d;
3015 end;
3016
3017 @ The \.{\\showtokens} command displays a token list.
3018
3019 @d show_tokens=5 { \.{\\showtokens} , must be odd! }
3020
3021 @<Generate all \eTeX...@>=
3022 primitive("showtokens",xray,show_tokens);
3023 @!@:show_tokens_}{\.{\\showtokens} primitive@>
3024
3025 @ @<Cases of |xray| for |print_cmd_chr|@>=
3026 show_tokens:print_esc("showtokens");
3027
3028 @ The \.{\\unexpanded} primitive prevents expansion of tokens much as
3029 the result from \.{\\the} applied to a token variable. The
3030 \.{\\detokenize} primitive converts a token list into a list of
3031 character tokens much as if the token list were written to a file. We
3032 use the fact that the command modifiers for \.{\\unexpanded} and
3033 \.{\\detokenize} are odd whereas those for \.{\\the} and \.{\\showthe}
3034 are even.
3035
3036 @<Generate all \eTeX...@>=
3037 primitive("unexpanded",the,1);@/
3038 @!@:unexpanded_}{\.{\\unexpanded} primitive@>
3039 primitive("detokenize",the,show_tokens);@/
3040 @!@:detokenize_}{\.{\\detokenize} primitive@>
3041
3042 @ @<Cases of |the| for |print_cmd_chr|@>=
3043 else if chr_code=1 then print_esc("unexpanded")
3044 else print_esc("detokenize")
3045
3046 @ @<Handle \.{\\unexpanded} or \.{\\detokenize} and |return|@>=
3047 if odd(cur_chr) then
3048 begin c:=cur_chr; scan_general_text;
3049 if c=1 then the_toks:=cur_val
3050 else begin old_setting:=selector; selector:=new_string; b:=pool_ptr;
3051 p:=get_avail; link(p):=link(temp_head);
3052 token_show(p); flush_list(p);
3053 selector:=old_setting; the_toks:=str_toks(b);
3054 end;
3055 return;
3056 end
3057
3058 @ The \.{\\showifs} command displays all currently active conditionals.
3059
3060 @d show_ifs=6 { \.{\\showifs} }
3061
3062 @<Generate all \eTeX...@>=
3063 primitive("showifs",xray,show_ifs);
3064 @!@:show_ifs_}{\.{\\showifs} primitive@>
3065
3066 @ @<Cases of |xray| for |print_cmd_chr|@>=
3067 show_ifs:print_esc("showifs");
3068
3069 @
3070 @d print_if_line(#)==if #<>0 then
3071 begin print(" entered on line "); print_int(#);
3072 end
3073
3074 @<Cases for |show_whatever|@>=
3075 show_ifs: begin begin_diagnostic; print_nl(""); print_ln;
3076 if cond_ptr=null then
3077 begin print_nl("### "); print("no active conditionals");
3078 end
3079 else begin p:=cond_ptr; n:=0;
3080 repeat incr(n); p:=link(p);@+until p=null;
3081 p:=cond_ptr; t:=cur_if; l:=if_line; m:=if_limit;
3082 repeat print_nl("### level "); print_int(n); print(": ");
3083 print_cmd_chr(if_test,t);
3084 if m=fi_code then print_esc("else");
3085 print_if_line(l);
3086 decr(n); t:=subtype(p); l:=if_line_field(p); m:=type(p); p:=link(p);
3087 until p=null;
3088 end;
3089 end;
3090
3091 @ The \.{\\interactionmode} primitive allows to query and set the
3092 interaction mode.
3093
3094 @<Generate all \eTeX...@>=
3095 primitive("interactionmode",set_page_int,2);
3096 @!@:interaction_mode_}{\.{\\interactionmode} primitive@>
3097
3098 @ @<Cases of |set_page_int| for |print_cmd_chr|@>=
3099 else if chr_code=2 then print_esc("interactionmode")
3100
3101 @ @<Cases for `Fetch the |dead_cycles| or the |insert_penalties|'@>=
3102 else if m=2 then cur_val:=interaction
3103
3104 @ @<Declare \eTeX\ procedures for use...@>=
3105 procedure@?new_interaction; forward;@t\2@>
3106
3107 @ @<Cases for |alter_integer|@>=
3108 else if c=2 then
3109 begin if (cur_val<batch_mode)or(cur_val>error_stop_mode) then
3110 begin print_err("Bad interaction mode");
3111 @.Bad interaction mode@>
3112 help2("Modes are 0=batch, 1=nonstop, 2=scroll, and")@/
3113 ("3=errorstop. Proceed, and I'll ignore this case.");
3114 int_error(cur_val);
3115 end
3116 else begin cur_chr:=cur_val; new_interaction;
3117 end;
3118 end
3119
3120 @ The |middle| feature of \eTeX\ allows one ore several \.{\\middle}
3121 delimiters to appear between \.{\\left} and \.{\\right}.
3122
3123 @<Generate all \eTeX...@>=
3124 primitive("middle",left_right,middle_noad);
3125 @!@:middle_}{\.{\\middle} primitive@>
3126
3127 @ @<Cases of |left_right| for |print_cmd_chr|@>=
3128 else if chr_code=middle_noad then print_esc("middle")
3129
3130 @ The |scan_tokens| feature of \eTeX\ defines the \.{\\scantokens}
3131 primitive.
3132
3133 @<Generate all \eTeX...@>=
3134 primitive("scantokens",input,2);
3135 @!@:scan_tokens_}{\.{\\scantokens} primitive@>
3136
3137 @ @<Cases of |input| for |print_cmd_chr|@>=
3138 else if chr_code=2 then print_esc("scantokens")
3139
3140 @ @<Cases for |input|@>=
3141 else if cur_chr=2 then pseudo_start
3142
3143 @ The global variable |pseudo_files| is used to maintain a stack of
3144 pseudo files. The |info| field of each pseudo file points to a linked
3145 list of variable size nodes representing lines not yet processed: the
3146 |info| field of the first word contains the size of this node, all the
3147 following words contain ASCII codes.
3148
3149 @<Glob...@>=
3150 @!pseudo_files:pointer; {stack of pseudo files}
3151
3152 @ @<Set init...@>=
3153 pseudo_files:=null;
3154
3155 @ The |pseudo_start| procedure initiates reading from a pseudo file.
3156
3157 @<Declare \eTeX\ procedures for ex...@>=
3158 procedure@?pseudo_start; forward;@t\2@>
3159
3160 @ @<Declare \eTeX\ procedures for tok...@>=
3161 procedure pseudo_start;
3162 var old_setting:0..max_selector; {holds |selector| setting}
3163 @!s:str_number; {string to be converted into a pseudo file}
3164 @!l,@!m:pool_pointer; {indices into |str_pool|}
3165 @!p,@!q,@!r:pointer; {for list construction}
3166 @!w: four_quarters; {four ASCII codes}
3167 @!nl,@!sz:integer;
3168 begin scan_general_text;
3169 old_setting:=selector; selector:=new_string;
3170 token_show(temp_head); selector:=old_setting;
3171 flush_list(link(temp_head));
3172 str_room(1); s:=make_string;
3173 @<Convert string |s| into a new pseudo file@>;
3174 flush_string;
3175 @<Initiate input from new pseudo file@>;
3176 end;
3177
3178 @ @<Convert string |s| into a new pseudo file@>=
3179 str_pool[pool_ptr]:=si(" "); l:=str_start(s);
3180 nl:=si(new_line_char);
3181 p:=get_avail; q:=p;
3182 while l<pool_ptr do
3183 begin m:=l;
3184 while (l<pool_ptr)and(str_pool[l]<>nl) do incr(l);
3185 sz:=(l-m+7)div 4;
3186 if sz=1 then sz:=2;
3187 r:=get_node(sz); link(q):=r; q:=r; info(q):=hi(sz);
3188 while sz>2 do
3189 begin decr(sz); incr(r);
3190 w.b0:=qi(so(str_pool[m])); w.b1:=qi(so(str_pool[m+1]));
3191 w.b2:=qi(so(str_pool[m+2])); w.b3:=qi(so(str_pool[m+3]));
3192 mem[r].qqqq:=w; m:=m+4;
3193 end;
3194 w.b0:=qi(" "); w.b1:=qi(" "); w.b2:=qi(" "); w.b3:=qi(" ");
3195 if l>m then
3196 begin w.b0:=qi(so(str_pool[m]));
3197 if l>m+1 then
3198 begin w.b1:=qi(so(str_pool[m+1]));
3199 if l>m+2 then
3200 begin w.b2:=qi(so(str_pool[m+2]));
3201 if l>m+3 then w.b3:=qi(so(str_pool[m+3]));
3202 end;
3203 end;
3204 end;
3205 mem[r+1].qqqq:=w;
3206 if str_pool[l]=nl then incr(l);
3207 end;
3208 info(p):=link(p); link(p):=pseudo_files; pseudo_files:=p
3209
3210 @ @<Initiate input from new pseudo file@>=
3211 begin_file_reading; {set up |cur_file| and new level of input}
3212 line:=0; limit:=start; loc:=limit+1; {force line read}
3213 if tracing_scan_tokens>0 then
3214 begin if term_offset>max_print_line-3 then print_ln
3215 else if (term_offset>0)or(file_offset>0) then print_char(" ");
3216 name:=19; print("( "); incr(open_parens); update_terminal;
3217 end
3218 else name:=18
3219
3220 @ Here we read a line from the current pseudo file into |buffer|.
3221
3222 @<Declare \eTeX\ procedures for tr...@>=
3223 function pseudo_input: boolean; {inputs the next line or returns |false|}
3224 var p:pointer; {current line from pseudo file}
3225 @!sz:integer; {size of node |p|}
3226 @!w:four_quarters; {four ASCII codes}
3227 @!r:pointer; {loop index}
3228 begin last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
3229 p:=info(pseudo_files);
3230 if p=null then pseudo_input:=false
3231 else begin info(pseudo_files):=link(p); sz:=ho(info(p));
3232 if 4*sz-3>=buf_size-last then
3233 @<Report overflow of the input buffer, and abort@>;
3234 last:=first;
3235 for r:=p+1 to p+sz-1 do
3236 begin w:=mem[r].qqqq;
3237 buffer[last]:=w.b0; buffer[last+1]:=w.b1;
3238 buffer[last+2]:=w.b2; buffer[last+3]:=w.b3;
3239 last:=last+4;
3240 end;
3241 if last>=max_buf_stack then max_buf_stack:=last+1;
3242 while (last>first)and(buffer[last-1]=" ") do decr(last);
3243 free_node(p,sz);
3244 pseudo_input:=true;
3245 end;
3246 end;
3247
3248 @ When we are done with a pseudo file we `close' it.
3249
3250 @<Declare \eTeX\ procedures for tr...@>=
3251 procedure pseudo_close; {close the top level pseudo file}
3252 var p,@!q: pointer;
3253 begin p:=link(pseudo_files); q:=info(pseudo_files);
3254 free_avail(pseudo_files); pseudo_files:=p;
3255 while q<>null do
3256 begin p:=q; q:=link(p); free_node(p,ho(info(p)));
3257 end;
3258 end;
3259
3260 @ @<Dump the \eTeX\ state@>=
3261 while pseudo_files<>null do pseudo_close; {flush pseudo files}
3262
3263 @ @<Generate all \eTeX...@>=
3264 primitive("readline",read_to_cs,1);@/
3265 @!@:read_line_}{\.{\\readline} primitive@>
3266
3267 @ @<Cases of |read| for |print_cmd_chr|@>=
3268 else print_esc("readline")
3269
3270 @ @<Handle \.{\\readline} and |goto done|@>=
3271 if j=1 then
3272 begin while loc<=limit do {current line not yet finished}
3273 begin cur_chr:=buffer[loc]; incr(loc);
3274 if cur_chr=" " then cur_tok:=space_token
3275 @+else cur_tok:=cur_chr+other_token;
3276 store_new_token(cur_tok);
3277 end;
3278 goto done;
3279 end
3280
3281 @ Here we define the additional conditionals of \eTeX\ as well as the
3282 \.{\\unless} prefix.
3283
3284 @d if_def_code=17 { `\.{\\ifdefined}' }
3285 @d if_cs_code=18 { `\.{\\ifcsname}' }
3286 @d if_font_char_code=19 { `\.{\\iffontchar}' }
3287
3288 @<Generate all \eTeX...@>=
3289 primitive("unless",expand_after,1);@/
3290 @!@:unless_}{\.{\\unless} primitive@>
3291 primitive("ifdefined",if_test,if_def_code);
3292 @!@:if_defined_}{\.{\\ifdefined} primitive@>
3293 primitive("ifcsname",if_test,if_cs_code);
3294 @!@:if_cs_name_}{\.{\\ifcsname} primitive@>
3295 primitive("iffontchar",if_test,if_font_char_code);
3296 @!@:if_font_char_}{\.{\\iffontchar} primitive@>
3297
3298 @ @<Cases of |expandafter| for |print_cmd_chr|@>=
3299 else print_esc("unless")
3300
3301 @ @<Cases of |if_test| for |print_cmd_chr|@>=
3302 if_def_code:print_esc("ifdefined");
3303 if_cs_code:print_esc("ifcsname");
3304 if_font_char_code:print_esc("iffontchar");
3305
3306 @ The result of a boolean condition is reversed when the conditional is
3307 preceded by \.{\\unless}.
3308
3309 @<Negate a boolean conditional and |goto reswitch|@>=
3310 begin get_token;
3311 if (cur_cmd=if_test)and(cur_chr<>if_case_code) then
3312 begin cur_chr:=cur_chr+unless_code; goto reswitch;
3313 end;
3314 print_err("You can't use `"); print_esc("unless"); print("' before `");
3315 @.You can't use \\unless...@>
3316 print_cmd_chr(cur_cmd,cur_chr); print_char("'");
3317 help1("Continue, and I'll forget that it ever happened.");
3318 back_error;
3319 end
3320
3321 @ The conditional \.{\\ifdefined} tests if a control sequence is
3322 defined.
3323
3324 We need to reset |scanner_status|, since \.{\\outer} control sequences
3325 are allowed, but we might be scanning a macro definition or preamble.
3326
3327 @<Cases for |conditional|@>=
3328 if_def_code:begin save_scanner_status:=scanner_status;
3329 scanner_status:=normal;
3330 get_next; b:=(cur_cmd<>undefined_cs);
3331 scanner_status:=save_scanner_status;
3332 end;
3333
3334 @ The conditional \.{\\ifcsname} is equivalent to \.{\{\\expandafter}
3335 \.{\}\\expandafter} \.{\\ifdefined} \.{\\csname}, except that no new
3336 control sequence will be entered into the hash table (once all tokens
3337 preceding the mandatory \.{\\endcsname} have been expanded).
3338
3339 @<Cases for |conditional|@>=
3340 if_cs_code:begin n:=get_avail; p:=n; {head of the list of characters}
3341 repeat get_x_token;
3342 if cur_cs=0 then store_new_token(cur_tok);
3343 until cur_cs<>0;
3344 if cur_cmd<>end_cs_name then @<Complain about missing \.{\\endcsname}@>;
3345 @<Look up the characters of list |n| in the hash table, and set |cur_cs|@>;
3346 flush_list(n);
3347 b:=(eq_type(cur_cs)<>undefined_cs);
3348 end;
3349
3350 @ @<Look up the characters of list |n| in the hash table...@>=
3351 m:=first; p:=link(n);
3352 while p<>null do
3353 begin if m>=max_buf_stack then
3354 begin max_buf_stack:=m+1;
3355 if max_buf_stack=buf_size then
3356 overflow("buffer size",buf_size);
3357 @:TeX capacity exceeded buffer size}{\quad buffer size@>
3358 end;
3359 buffer[m]:=info(p) mod @'400; incr(m); p:=link(p);
3360 end;
3361 if m>first+1 then
3362 cur_cs:=id_lookup(first,m-first) {|no_new_control_sequence| is |true|}
3363 else if m=first then cur_cs:=null_cs {the list is empty}
3364 else cur_cs:=single_base+buffer[first] {the list has length one}
3365
3366 @ The conditional \.{\\iffontchar} tests the existence of a character in
3367 a font.
3368
3369 @<Cases for |conditional|@>=
3370 if_font_char_code:begin scan_font_ident; n:=cur_val; scan_char_num;
3371 if (font_bc(n)<=cur_val)and(font_ec(n)>=cur_val) then
3372 b:=char_exists(char_info(n)(qi(cur_val)))
3373 else b:=false;
3374 end;
3375
3376 @ The |protected| feature of \eTeX\ defines the \.{\\protected} prefix
3377 command for macro definitions. Such macros are protected against
3378 expansions when lists of expanded tokens are built, e.g., for \.{\\edef}
3379 or during \.{\\write}.
3380
3381 @<Generate all \eTeX...@>=
3382 primitive("protected",prefix,8);
3383 @!@:protected_}{\.{\\protected} primitive@>
3384
3385 @ @<Cases of |prefix| for |print_cmd_chr|@>=
3386 else if chr_code=8 then print_esc("protected")
3387
3388 @ The |get_x_or_protected| procedure is like |get_x_token| except that
3389 protected macros are not expanded.
3390
3391 @<Declare \eTeX\ procedures for sc...@>=
3392 procedure get_x_or_protected; {sets |cur_cmd|, |cur_chr|, |cur_tok|,
3393 and expands non-protected macros}
3394 label exit;
3395 begin loop@+begin get_token;
3396 if cur_cmd<=max_command then return;
3397 if (cur_cmd>=call)and(cur_cmd<end_template) then
3398 if info(link(cur_chr))=protected_token then return;
3399 expand;
3400 end;
3401 exit:end;
3402
3403 @ A group entered (or a conditional started) in one file may end in a
3404 different file. Such slight anomalies, although perfectly legitimate,
3405 may cause errors that are difficult to locate. In order to be able to
3406 give a warning message when such anomalies occur, \eTeX\ uses the
3407 |grp_stack| and |if_stack| arrays to record the initial |cur_boundary|
3408 and |cond_ptr| values for each input file.
3409
3410 @<Glob...@>=
3411 @!grp_stack : array[0..max_in_open] of save_pointer; {initial |cur_boundary|}
3412 @!if_stack : array[0..max_in_open] of pointer; {initial |cond_ptr|}
3413
3414 @ When a group ends that was apparently entered in a different input
3415 file, the |group_warning| procedure is invoked in order to update the
3416 |grp_stack|. If moreover \.{\\tracingnesting} is positive we want to
3417 give a warning message. The situation is, however, somewhat complicated
3418 by two facts: (1)~There may be |grp_stack| elements without a
3419 corresponding \.{\\input} file or \.{\\scantokens} pseudo file (e.g.,
3420 error insertions from the terminal); and (2)~the relevant information is
3421 recorded in the |name_field| of the |input_stack| only loosely
3422 synchronized with the |in_open| variable indexing |grp_stack|.
3423
3424 @<Declare \eTeX\ procedures for tr...@>=
3425 procedure group_warning;
3426 var i:0..max_in_open; {index into |grp_stack|}
3427 @!w:boolean; {do we need a warning?}
3428 begin base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input;
3429 {store current state}
3430 i:=in_open; w:=false;
3431 while (grp_stack[i]=cur_boundary)and(i>0) do
3432 begin @<Set variable |w| to indicate if this case should be reported@>;
3433 grp_stack[i]:=save_index(save_ptr); decr(i);
3434 end;
3435 if w then
3436 begin print_nl("Warning: end of "); print_group(true);
3437 @.Warning: end of...@>
3438 print(" of a different file"); print_ln;
3439 if tracing_nesting>1 then show_context;
3440 if history=spotless then history:=warning_issued;
3441 end;
3442 end;
3443
3444 @ This code scans the input stack in order to determine the type of the
3445 current input file.
3446
3447 @<Set variable |w| to...@>=
3448 if tracing_nesting>0 then
3449 begin while (input_stack[base_ptr].state_field=token_list)or@|
3450 (input_stack[base_ptr].index_field>i) do decr(base_ptr);
3451 if input_stack[base_ptr].name_field>17 then w:=true;
3452 end
3453
3454 @ When a conditional ends that was apparently started in a different
3455 input file, the |if_warning| procedure is invoked in order to update the
3456 |if_stack|. If moreover \.{\\tracingnesting} is positive we want to
3457 give a warning message (with the same complications as above).
3458
3459 @<Declare \eTeX\ procedures for tr...@>=
3460 procedure if_warning;
3461 var i:0..max_in_open; {index into |if_stack|}
3462 @!w:boolean; {do we need a warning?}
3463 begin base_ptr:=input_ptr; input_stack[base_ptr]:=cur_input;
3464 {store current state}
3465 i:=in_open; w:=false;
3466 while if_stack[i]=cond_ptr do
3467 begin @<Set variable |w| to...@>;
3468 if_stack[i]:=link(cond_ptr); decr(i);
3469 end;
3470 if w then
3471 begin print_nl("Warning: end of "); print_cmd_chr(if_test,cur_if);
3472 @.Warning: end of...@>
3473 print_if_line(if_line); print(" of a different file"); print_ln;
3474 if tracing_nesting>1 then show_context;
3475 if history=spotless then history:=warning_issued;
3476 end;
3477 end;
3478
3479 @ Conversely, the |file_warning| procedure is invoked when a file ends
3480 and some groups entered or conditionals started while reading from that
3481 file are still incomplete.
3482
3483 @<Declare \eTeX\ procedures for tr...@>=
3484 procedure file_warning;
3485 var p:pointer; {saved value of |save_ptr| or |cond_ptr|}
3486 @!l:quarterword; {saved value of |cur_level| or |if_limit|}
3487 @!c:quarterword; {saved value of |cur_group| or |cur_if|}
3488 @!i:integer; {saved value of |if_line|}
3489 begin p:=save_ptr; l:=cur_level; c:=cur_group; save_ptr:=cur_boundary;
3490 while grp_stack[in_open]<>save_ptr do
3491 begin decr(cur_level);
3492 print_nl("Warning: end of file when ");
3493 @.Warning: end of file when...@>
3494 print_group(true); print(" is incomplete");@/
3495 cur_group:=save_level(save_ptr); save_ptr:=save_index(save_ptr)
3496 end;
3497 save_ptr:=p; cur_level:=l; cur_group:=c; {restore old values}
3498 p:=cond_ptr; l:=if_limit; c:=cur_if; i:=if_line;
3499 while if_stack[in_open]<>cond_ptr do
3500 begin print_nl("Warning: end of file when ");
3501 @.Warning: end of file when...@>
3502 print_cmd_chr(if_test,cur_if);
3503 if if_limit=fi_code then print_esc("else");
3504 print_if_line(if_line); print(" is incomplete");@/
3505 if_line:=if_line_field(cond_ptr); cur_if:=subtype(cond_ptr);
3506 if_limit:=type(cond_ptr); cond_ptr:=link(cond_ptr);
3507 end;
3508 cond_ptr:=p; if_limit:=l; cur_if:=c; if_line:=i; {restore old values}
3509 print_ln;
3510 if tracing_nesting>1 then show_context;
3511 if history=spotless then history:=warning_issued;
3512 end;
3513
3514 @ Here are the additional \eTeX\ primitives for expressions.
3515
3516 @<Generate all \eTeX...@>=
3517 primitive("numexpr",last_item,eTeX_expr-int_val+int_val);
3518 @!@:num_expr_}{\.{\\numexpr} primitive@>
3519 primitive("dimexpr",last_item,eTeX_expr-int_val+dimen_val);
3520 @!@:dim_expr_}{\.{\\dimexpr} primitive@>
3521 primitive("glueexpr",last_item,eTeX_expr-int_val+glue_val);
3522 @!@:glue_expr_}{\.{\\glueexpr} primitive@>
3523 primitive("muexpr",last_item,eTeX_expr-int_val+mu_val);
3524 @!@:mu_expr_}{\.{\\muexpr} primitive@>
3525
3526 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3527 eTeX_expr-int_val+int_val: print_esc("numexpr");
3528 eTeX_expr-int_val+dimen_val: print_esc("dimexpr");
3529 eTeX_expr-int_val+glue_val: print_esc("glueexpr");
3530 eTeX_expr-int_val+mu_val: print_esc("muexpr");
3531
3532 @ This code for reducing |cur_val_level| and\slash or negating the
3533 result is similar to the one for all the other cases of
3534 |scan_something_internal|, with the difference that |scan_expr| has
3535 already increased the reference count of a glue specification.
3536
3537 @<Process an expression and |return|@>=
3538 begin if m<eTeX_mu then
3539 begin case m of
3540 @/@<Cases for fetching a glue value@>@/
3541 end; {there are no other cases}
3542 cur_val_level:=glue_val;
3543 end
3544 else if m<eTeX_expr then
3545 begin case m of
3546 @/@<Cases for fetching a mu value@>@/
3547 end; {there are no other cases}
3548 cur_val_level:=mu_val;
3549 end
3550 else begin cur_val_level:=m-eTeX_expr+int_val; scan_expr;
3551 end;
3552 while cur_val_level>level do
3553 begin if cur_val_level=glue_val then
3554 begin m:=cur_val; cur_val:=width(m); delete_glue_ref(m);
3555 end
3556 else if cur_val_level=mu_val then mu_error;
3557 decr(cur_val_level);
3558 end;
3559 if negative then
3560 if cur_val_level>=glue_val then
3561 begin m:=cur_val; cur_val:=new_spec(m); delete_glue_ref(m);
3562 @<Negate all three glue components of |cur_val|@>;
3563 end
3564 else negate(cur_val);
3565 return;
3566 end
3567
3568 @ @<Declare \eTeX\ procedures for sc...@>=
3569 procedure@?scan_expr; forward;@t\2@>
3570
3571 @ The |scan_expr| procedure scans and evaluates an expression.
3572
3573 @<Declare procedures needed for expressions@>=
3574 @t\4@>@<Declare subprocedures for |scan_expr|@>
3575 procedure scan_expr; {scans and evaluates an expression}
3576 label restart, continue, found;
3577 var a,@!b:boolean; {saved values of |arith_error|}
3578 @!l:small_number; {type of expression}
3579 @!r:small_number; {state of expression so far}
3580 @!s:small_number; {state of term so far}
3581 @!o:small_number; {next operation or type of next factor}
3582 @!e:integer; {expression so far}
3583 @!t:integer; {term so far}
3584 @!f:integer; {current factor}
3585 @!n:integer; {numerator of combined multiplication and division}
3586 @!p:pointer; {top of expression stack}
3587 @!q:pointer; {for stack manipulations}
3588 begin l:=cur_val_level; a:=arith_error; b:=false; p:=null;
3589 incr(expand_depth_count);
3590 if expand_depth_count>=expand_depth then overflow("expansion depth",expand_depth);
3591 @<Scan and evaluate an expression |e| of type |l|@>;
3592 decr(expand_depth_count);
3593 if b then
3594 begin print_err("Arithmetic overflow");
3595 @.Arithmetic overflow@>
3596 help2("I can't evaluate this expression,")@/
3597 ("since the result is out of range.");
3598 error;
3599 if l>=glue_val then
3600 begin delete_glue_ref(e); e:=zero_glue; add_glue_ref(e);
3601 end
3602 else e:=0;
3603 end;
3604 arith_error:=a; cur_val:=e; cur_val_level:=l;
3605 end;
3606
3607 @ Evaluating an expression is a recursive process: When the left
3608 parenthesis of a subexpression is scanned we descend to the next level
3609 of recursion; the previous level is resumed with the matching right
3610 parenthesis.
3611
3612 @d expr_none=0 {\.( seen, or \.( $\langle\it expr\rangle$ \.) seen}
3613 @d expr_add=1 {\.( $\langle\it expr\rangle$ \.+ seen}
3614 @d expr_sub=2 {\.( $\langle\it expr\rangle$ \.- seen}
3615 @d expr_mult=3 {$\langle\it term\rangle$ \.* seen}
3616 @d expr_div=4 {$\langle\it term\rangle$ \./ seen}
3617 @d expr_scale=5 {$\langle\it term\rangle$ \.*
3618 $\langle\it factor\rangle$ \./ seen}
3619
3620 @<Scan and eval...@>=
3621 restart: r:=expr_none; e:=0; s:=expr_none; t:=0; n:=0;
3622 continue: if s=expr_none then o:=l@+else o:=int_val;
3623 @<Scan a factor |f| of type |o| or start a subexpression@>;
3624 found: @<Scan the next operator and set |o|@>;
3625 arith_error:=b;
3626 @<Make sure that |f| is in the proper range@>;
3627 case s of @<Cases for evaluation of the current term@>@;
3628 end; {there are no other cases}
3629 if o>expr_sub then s:=o@+else @<Evaluate the current expression@>;
3630 b:=arith_error;
3631 if o<>expr_none then goto continue;
3632 if p<>null then @<Pop the expression stack and |goto found|@>
3633
3634 @ @<Scan the next op...@>=
3635 @<Get the next non-blank non-call token@>;
3636 if cur_tok=other_token+"+" then o:=expr_add
3637 else if cur_tok=other_token+"-" then o:=expr_sub
3638 else if cur_tok=other_token+"*" then o:=expr_mult
3639 else if cur_tok=other_token+"/" then o:=expr_div
3640 else begin o:=expr_none;
3641 if p=null then
3642 begin if cur_cmd<>relax then back_input;
3643 end
3644 else if cur_tok<>other_token+")" then
3645 begin print_err("Missing ) inserted for expression");
3646 @.Missing ) inserted@>
3647 help1("I was expecting to see `+', `-', `*', `/', or `)'. Didn't.");
3648 back_error;
3649 end;
3650 end
3651
3652 @ @<Scan a factor...@>=
3653 @<Get the next non-blank non-call token@>;
3654 if cur_tok=other_token+"(" then
3655 @<Push the expression stack and |goto restart|@>;
3656 back_input;
3657 if o=int_val then scan_int
3658 else if o=dimen_val then scan_normal_dimen
3659 else if o=glue_val then scan_normal_glue
3660 else scan_mu_glue;
3661 f:=cur_val
3662
3663 @ @<Declare \eTeX\ procedures for sc...@>=
3664 procedure@?scan_normal_glue; forward;@t\2@>@/
3665 procedure@?scan_mu_glue; forward;@t\2@>
3666
3667 @ Here we declare two trivial procedures in order to avoid mutually
3668 recursive procedures with parameters.
3669
3670 @<Declare procedures needed for expressions@>=
3671 procedure scan_normal_glue;
3672 begin scan_glue(glue_val);
3673 end;
3674 @#
3675 procedure scan_mu_glue;
3676 begin scan_glue(mu_val);
3677 end;
3678
3679 @ Parenthesized subexpressions can be inside expressions, and this
3680 nesting has a stack. Seven local variables represent the top of the
3681 expression stack: |p| points to pushed-down entries, if any; |l|
3682 specifies the type of expression currently being evaluated; |e| is the
3683 expression so far and |r| is the state of its evaluation; |t| is the
3684 term so far and |s| is the state of its evaluation; finally |n| is the
3685 numerator for a combined multiplication and division, if any.
3686
3687 @d expr_node_size=4 {number of words in stack entry for subexpressions}
3688 @d expr_e_field(#)==mem[#+1].int {saved expression so far}
3689 @d expr_t_field(#)==mem[#+2].int {saved term so far}
3690 @d expr_n_field(#)==mem[#+3].int {saved numerator}
3691
3692 @<Push the expression...@>=
3693 begin q:=get_node(expr_node_size); link(q):=p; type(q):=l;
3694 subtype(q):=4*s+r;
3695 expr_e_field(q):=e; expr_t_field(q):=t; expr_n_field(q):=n;
3696 p:=q; l:=o; goto restart;
3697 end
3698
3699 @ @<Pop the expression...@>=
3700 begin f:=e; q:=p;
3701 e:=expr_e_field(q); t:=expr_t_field(q); n:=expr_n_field(q);
3702 s:=subtype(q) div 4; r:=subtype(q) mod 4;
3703 l:=type(q); p:=link(q); free_node(q,expr_node_size);
3704 goto found;
3705 end
3706
3707 @ We want to make sure that each term and (intermediate) result is in
3708 the proper range. Integer values must not exceed |infinity|
3709 ($2^{31}-1$) in absolute value, dimensions must not exceed |max_dimen|
3710 ($2^{30}-1$). We avoid the absolute value of an integer, because this
3711 might fail for the value $-2^{31}$ using 32-bit arithmetic.
3712
3713 @d num_error(#)== {clear a number or dimension and set |arith_error|}
3714 begin arith_error:=true; #:=0;
3715 end
3716 @d glue_error(#)== {clear a glue spec and set |arith_error|}
3717 begin arith_error:=true; delete_glue_ref(#); #:=new_spec(zero_glue);
3718 end
3719
3720 @<Make sure that |f|...@>=
3721 if (l=int_val)or(s>expr_sub) then
3722 begin if (f>infinity)or(f<-infinity) then num_error(f);
3723 end
3724 else if l=dimen_val then
3725 begin if abs(f)>max_dimen then num_error(f);
3726 end
3727 else begin if (abs(width(f))>max_dimen)or@|
3728 (abs(stretch(f))>max_dimen)or@|
3729 (abs(shrink(f))>max_dimen) then glue_error(f);
3730 end
3731
3732 @ Applying the factor |f| to the partial term |t| (with the operator
3733 |s|) is delayed until the next operator |o| has been scanned. Here we
3734 handle the first factor of a partial term. A glue spec has to be copied
3735 unless the next operator is a right parenthesis; this allows us later on
3736 to simply modify the glue components.
3737
3738 @d normalize_glue(#)==
3739 if stretch(#)=0 then stretch_order(#):=normal;
3740 if shrink(#)=0 then shrink_order(#):=normal
3741
3742 @<Cases for evaluation of the current term@>=
3743 expr_none: if (l>=glue_val)and(o<>expr_none) then
3744 begin t:=new_spec(f); delete_glue_ref(f); normalize_glue(t);
3745 end
3746 else t:=f;
3747
3748 @ When a term |t| has been completed it is copied to, added to, or
3749 subtracted from the expression |e|.
3750
3751 @d expr_add_sub(#)==add_or_sub(#,r=expr_sub)
3752 @d expr_a(#)==expr_add_sub(#,max_dimen)
3753
3754 @<Evaluate the current expression@>=
3755 begin s:=expr_none;
3756 if r=expr_none then e:=t
3757 else if l=int_val then e:=expr_add_sub(e,t,infinity)
3758 else if l=dimen_val then e:=expr_a(e,t)
3759 else @<Compute the sum or difference of two glue specs@>;
3760 r:=o;
3761 end
3762
3763 @ The function |add_or_sub(x,y,max_answer,negative)| computes the sum
3764 (for |negative=false|) or difference (for |negative=true|) of |x| and
3765 |y|, provided the absolute value of the result does not exceed
3766 |max_answer|.
3767
3768 @<Declare subprocedures for |scan_expr|@>=
3769 function add_or_sub(@!x,@!y,@!max_answer:integer;@!negative:boolean):integer;
3770 var a:integer; {the answer}
3771 begin if negative then negate(y);
3772 if x>=0 then
3773 if y<=max_answer-x then a:=x+y@+else num_error(a)
3774 else if y>=-max_answer-x then a:=x+y@+else num_error(a);
3775 add_or_sub:=a;
3776 end;
3777
3778 @ We know that |stretch_order(e)>normal| implies |stretch(e)<>0| and
3779 |shrink_order(e)>normal| implies |shrink(e)<>0|.
3780
3781 @<Compute the sum or diff...@>=
3782 begin width(e):=expr_a(width(e),width(t));
3783 if stretch_order(e)=stretch_order(t) then
3784 stretch(e):=expr_a(stretch(e),stretch(t))
3785 else if (stretch_order(e)<stretch_order(t))and(stretch(t)<>0) then
3786 begin stretch(e):=stretch(t); stretch_order(e):=stretch_order(t);
3787 end;
3788 if shrink_order(e)=shrink_order(t) then
3789 shrink(e):=expr_a(shrink(e),shrink(t))
3790 else if (shrink_order(e)<shrink_order(t))and(shrink(t)<>0) then
3791 begin shrink(e):=shrink(t); shrink_order(e):=shrink_order(t);
3792 end;
3793 delete_glue_ref(t); normalize_glue(e);
3794 end
3795
3796 @ If a multiplication is followed by a division, the two operations are
3797 combined into a `scaling' operation. Otherwise the term |t| is
3798 multiplied by the factor |f|.
3799
3800 @d expr_m(#)==#:=nx_plus_y(#,f,0)
3801
3802 @<Cases for evaluation of the current term@>=
3803 expr_mult: if o=expr_div then
3804 begin n:=f; o:=expr_scale;
3805 end
3806 else if l=int_val then t:=mult_integers(t,f)
3807 else if l=dimen_val then expr_m(t)
3808 else begin expr_m(width(t)); expr_m(stretch(t)); expr_m(shrink(t));
3809 end;
3810
3811 @ Here we divide the term |t| by the factor |f|.
3812
3813 @d expr_d(#)==#:=quotient(#,f)
3814
3815 @<Cases for evaluation of the current term@>=
3816 expr_div: if l<glue_val then expr_d(t)
3817 else begin expr_d(width(t)); expr_d(stretch(t)); expr_d(shrink(t));
3818 end;
3819
3820 @ The function |quotient(n,d)| computes the rounded quotient
3821 $q=\lfloor n/d+{1\over2}\rfloor$, when $n$ and $d$ are positive.
3822
3823 @<Declare subprocedures for |scan_expr|@>=
3824 function quotient(@!n,@!d:integer):integer;
3825 var negative:boolean; {should the answer be negated?}
3826 @!a:integer; {the answer}
3827 begin if d=0 then num_error(a)
3828 else begin if d>0 then negative:=false
3829 else begin negate(d); negative:=true;
3830 end;
3831 if n<0 then
3832 begin negate(n); negative:=not negative;
3833 end;
3834 a:=n div d; n:=n-a*d; d:=n-d; {avoid certain compiler optimizations!}
3835 if d+n>=0 then incr(a);
3836 if negative then negate(a);
3837 end;
3838 quotient:=a;
3839 end;
3840
3841 @ Here the term |t| is multiplied by the quotient $n/f$.
3842
3843 @d expr_s(#)==#:=fract(#,n,f,max_dimen)
3844
3845 @<Cases for evaluation of the current term@>=
3846 expr_scale: if l=int_val then t:=fract(t,n,f,infinity)
3847 else if l=dimen_val then expr_s(t)
3848 else begin expr_s(width(t)); expr_s(stretch(t)); expr_s(shrink(t));
3849 end;
3850
3851 @ Finally, the function |fract(x,n,d,max_answer)| computes the integer
3852 $q=\lfloor xn/d+{1\over2}\rfloor$, when $x$, $n$, and $d$ are positive
3853 and the result does not exceed |max_answer|. We can't use floating
3854 point arithmetic since the routine must produce identical results in all
3855 cases; and it would be too dangerous to multiply by~|n| and then divide
3856 by~|d|, in separate operations, since overflow might well occur. Hence
3857 this subroutine simulates double precision arithmetic, somewhat
3858 analogous to \MF's |make_fraction| and |take_fraction| routines.
3859
3860 @d too_big=88 {go here when the result is too big}
3861
3862 @<Declare subprocedures for |scan_expr|@>=
3863 function fract(@!x,@!n,@!d,@!max_answer:integer):integer;
3864 label found, found1, too_big, done;
3865 var negative:boolean; {should the answer be negated?}
3866 @!a:integer; {the answer}
3867 @!f:integer; {a proper fraction}
3868 @!h:integer; {smallest integer such that |2*h>=d|}
3869 @!r:integer; {intermediate remainder}
3870 @!t:integer; {temp variable}
3871 begin if d=0 then goto too_big;
3872 a:=0;
3873 if d>0 then negative:=false
3874 else begin negate(d); negative:=true;
3875 end;
3876 if x<0 then
3877 begin negate(x); negative:=not negative;
3878 end
3879 else if x=0 then goto done;
3880 if n<0 then
3881 begin negate(n); negative:=not negative;
3882 end;
3883 t:=n div d;
3884 if t>max_answer div x then goto too_big;
3885 a:=t*x; n:=n-t*d;
3886 if n=0 then goto found;
3887 t:=x div d;
3888 if t>(max_answer-a) div n then goto too_big;
3889 a:=a+t*n; x:=x-t*d;
3890 if x=0 then goto found;
3891 if x<n then
3892 begin t:=x; x:=n; n:=t;
3893 end; {now |0<n<=x<d|}
3894 @<Compute \(f)$f=\lfloor xn/d+{1\over2}\rfloor$@>@;
3895 if f>(max_answer-a) then goto too_big;
3896 a:=a+f;
3897 found: if negative then negate(a);
3898 goto done;
3899 too_big: num_error(a);
3900 done: fract:=a;
3901 end;
3902
3903 @ The loop here preserves the following invariant relations
3904 between |f|, |x|, |n|, and~|r|:
3905 (i)~$f+\lfloor(xn+(r+d))/d\rfloor=\lfloor x_0n_0/d+{1\over2}\rfloor$;
3906 (ii)~|-d<=r<0<n<=x<d|, where $x_0$, $n_0$ are the original values of~$x$
3907 and $n$.
3908
3909 Notice that the computation specifies |(x-d)+x| instead of |(x+x)-d|,
3910 because the latter could overflow.
3911
3912 @<Compute \(f)$f=\lfloor xn/d+{1\over2}\rfloor$@>=
3913 f:=0; r:=(d div 2)-d; h:=-r;
3914 loop@+begin if odd(n) then
3915 begin r:=r+x;
3916 if r>=0 then
3917 begin r:=r-d; incr(f);
3918 end;
3919 end;
3920 n:=n div 2;
3921 if n=0 then goto found1;
3922 if x<h then x:=x+x
3923 else begin t:=x-d; x:=t+x; f:=f+n;
3924 if x<n then
3925 begin if x=0 then goto found1;
3926 t:=x; x:=n; n:=t;
3927 end;
3928 end;
3929 end;
3930 found1:
3931
3932 @ The \.{\\gluestretch}, \.{\\glueshrink}, \.{\\gluestretchorder}, and
3933 \.{\\glueshrinkorder} commands return the stretch and shrink components
3934 and their orders of ``infinity'' of a glue specification.
3935
3936 @d glue_stretch_order_code=eTeX_int+6 {code for \.{\\gluestretchorder}}
3937 @d glue_shrink_order_code=eTeX_int+7 {code for \.{\\glueshrinkorder}}
3938 @d glue_stretch_code=eTeX_dim+7 {code for \.{\\gluestretch}}
3939 @d glue_shrink_code=eTeX_dim+8 {code for \.{\\glueshrink}}
3940
3941 @<Generate all \eTeX...@>=
3942 primitive("gluestretchorder",last_item,glue_stretch_order_code);
3943 @!@:glue_stretch_order_}{\.{\\gluestretchorder} primitive@>
3944 primitive("glueshrinkorder",last_item,glue_shrink_order_code);
3945 @!@:glue_shrink_order_}{\.{\\glueshrinkorder} primitive@>
3946 primitive("gluestretch",last_item,glue_stretch_code);
3947 @!@:glue_stretch_}{\.{\\gluestretch} primitive@>
3948 primitive("glueshrink",last_item,glue_shrink_code);
3949 @!@:glue_shrink_}{\.{\\glueshrink} primitive@>
3950
3951 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3952 glue_stretch_order_code: print_esc("gluestretchorder");
3953 glue_shrink_order_code: print_esc("glueshrinkorder");
3954 glue_stretch_code: print_esc("gluestretch");
3955 glue_shrink_code: print_esc("glueshrink");
3956
3957 @ @<Cases for fetching an integer value@>=
3958 glue_stretch_order_code, glue_shrink_order_code:
3959 begin scan_normal_glue; q:=cur_val;
3960 if m=glue_stretch_order_code then cur_val:=stretch_order(q)
3961 else cur_val:=shrink_order(q);
3962 delete_glue_ref(q);
3963 end;
3964
3965 @ @<Cases for fetching a dimension value@>=
3966 glue_stretch_code, glue_shrink_code:
3967 begin scan_normal_glue; q:=cur_val;
3968 if m=glue_stretch_code then cur_val:=stretch(q)
3969 else cur_val:=shrink(q);
3970 delete_glue_ref(q);
3971 end;
3972
3973 @ The \.{\\mutoglue} and \.{\\gluetomu} commands convert ``math'' glue
3974 into normal glue and vice versa; they allow to manipulate math glue with
3975 \.{\\gluestretch} etc.
3976
3977 @d mu_to_glue_code=eTeX_glue {code for \.{\\mutoglue}}
3978 @d glue_to_mu_code=eTeX_mu {code for \.{\\gluetomu}}
3979
3980 @<Generate all \eTeX...@>=
3981 primitive("mutoglue",last_item,mu_to_glue_code);
3982 @!@:mu_to_glue_}{\.{\\mutoglue} primitive@>
3983 primitive("gluetomu",last_item,glue_to_mu_code);
3984 @!@:glue_to_mu_}{\.{\\gluetomu} primitive@>
3985
3986 @ @<Cases of |last_item| for |print_cmd_chr|@>=
3987 mu_to_glue_code: print_esc("mutoglue");
3988 glue_to_mu_code: print_esc("gluetomu");
3989
3990 @ @<Cases for fetching a glue value@>=
3991 mu_to_glue_code: scan_mu_glue;
3992
3993 @ @<Cases for fetching a mu value@>=
3994 glue_to_mu_code: scan_normal_glue;
3995
3996 { FIXME: next chapter is about sparse arrays; how does it cope with Omega? }
3997
3998 @ \eTeX\ (in extended mode) supports 32768 (i.e., $2^{15}$) count,
3999 dimen, skip, muskip, box, and token registers. As in \TeX\ the first
4000 256 registers of each kind are realized as arrays in the table of
4001 equivalents; the additional registers are realized as tree structures
4002 built from variable-size nodes with individual registers existing only
4003 when needed. Default values are used for nonexistent registers: zero
4004 for count and dimen values, |zero_glue| for glue (skip and muskip)
4005 values, void for boxes, and |null| for token lists (and current marks
4006 discussed below).
4007
4008 Similarly there are 32768 mark classes; the command \.{\\marks}|n|
4009 creates a mark node for a given mark class |0<=n<=32767| (where
4010 \.{\\marks0} is synonymous to \.{\\mark}). The page builder (actually
4011 the |fire_up| routine) and the |vsplit| routine maintain the current
4012 values of |top_mark|, |first_mark|, |bot_mark|, |split_first_mark|, and
4013 |split_bot_mark| for each mark class. They are accessed as
4014 \.{\\topmarks}|n| etc., and \.{\\topmarks0} is again synonymous to
4015 \.{\\topmark}. As in \TeX\ the five current marks for mark class zero
4016 are realized as |cur_mark| array. The additional current marks are
4017 again realized as tree structure with individual mark classes existing
4018 only when needed.
4019
4020 @<Generate all \eTeX...@>=
4021 primitive("marks",mark,marks_code);
4022 @!@:marks_}{\.{\\marks} primitive@>
4023 primitive("topmarks",top_bot_mark,top_mark_code+marks_code);
4024 @!@:top_marks_}{\.{\\topmarks} primitive@>
4025 primitive("firstmarks",top_bot_mark,first_mark_code+marks_code);
4026 @!@:first_marks_}{\.{\\firstmarks} primitive@>
4027 primitive("botmarks",top_bot_mark,bot_mark_code+marks_code);
4028 @!@:bot_marks_}{\.{\\botmarks} primitive@>
4029 primitive("splitfirstmarks",top_bot_mark,split_first_mark_code+marks_code);
4030 @!@:split_first_marks_}{\.{\\splitfirstmarks} primitive@>
4031 primitive("splitbotmarks",top_bot_mark,split_bot_mark_code+marks_code);
4032 @!@:split_bot_marks_}{\.{\\splitbotmarks} primitive@>
4033
4034 @ The |scan_register_num| procedure scans a register number that must
4035 not exceed 255 in compatibility mode resp.\ 32767 in extended mode.
4036
4037 @<Declare \eTeX\ procedures for ex...@>=
4038 procedure@?scan_register_num; forward;@t\2@>
4039
4040 @ @<Declare procedures that scan restricted classes of integers@>=
4041 procedure scan_register_num;
4042 begin scan_int;
4043 if (cur_val<0)or(cur_val>max_reg_num) then
4044 begin print_err("Bad register code");
4045 @.Bad register code@>
4046 help2(max_reg_help_line)("I changed this one to zero.");
4047 int_error(cur_val); cur_val:=0;
4048 end;
4049 end;
4050
4051 @ @<Initialize variables for \eTeX\ comp...@>=
4052 max_reg_num:=255;
4053 max_reg_help_line:="A register number must be between 0 and 255.";
4054
4055 @ @<Initialize variables for \eTeX\ ext...@>=
4056 max_reg_num:=32767;
4057 max_reg_help_line:="A register number must be between 0 and 32767.";
4058
4059 @ @<Glob...@>=
4060 @!max_reg_num: halfword; {largest allowed register number}
4061 @!max_reg_help_line: str_number; {first line of help message}
4062
4063 @ There are seven almost identical doubly linked trees, one for the
4064 sparse array of the up to 32512 additional registers of each kind and
4065 one for the sparse array of the up to 32767 additional mark classes.
4066 The root of each such tree, if it exists, is an index node containing 16
4067 pointers to subtrees for 4096 consecutive array elements. Similar index
4068 nodes are the starting points for all nonempty subtrees for 4096, 256,
4069 and 16 consecutive array elements. These four levels of index nodes are
4070 followed by a fifth level with nodes for the individual array elements.
4071
4072 Each index node is nine words long. The pointers to the 16 possible
4073 subtrees or are kept in the |info| and |link| fields of the last eight
4074 words. (It would be both elegant and efficient to declare them as
4075 array, unfortunately \PASCAL\ doesn't allow this.)
4076
4077 The fields in the first word of each index node and in the nodes for the
4078 array elements are closely related. The |link| field points to the next
4079 lower index node and the |sa_index| field contains four bits (one
4080 hexadecimal digit) of the register number or mark class. For the lowest
4081 index node the |link| field is |null| and the |sa_index| field indicates
4082 the type of quantity (|int_avl|, |dimen_val|, |glue_val|, |mu_val|,
4083 |box_val|, |tok_val|, or |mark_val|). The |sa_used| field in the index
4084 nodes counts how many of the 16 pointers are non-null.
4085
4086 The |sa_index| field in the nodes for array elements contains the four
4087 bits plus 16 times the type. Therefore such a node represents a count
4088 or dimen register if and only if |sa_index<dimen_val_limit|; it
4089 represents a skip or muskip register if and only if
4090 |dimen_val_limit<=sa_index<mu_val_limit|; it represents a box register
4091 if and only if |mu_val_limit<=sa_index<box_val_limit|; it represents a
4092 token list register if and only if
4093 |box_val_limit<=sa_index<tok_val_limit|; finally it represents a mark
4094 class if and only if |tok_val_limit<=sa_index|.
4095
4096 The |new_index| procedure creates an index node (returned in |cur_ptr|)
4097 having given contents of the |sa_index| and |link| fields.
4098
4099 @d box_val==4 {the additional box registers}
4100 @d mark_val=6 {the additional mark classes}
4101 @#
4102 @d dimen_val_limit=@"20 {$2^4\cdot(|dimen_val|+1)$}
4103 @d mu_val_limit=@"40 {$2^4\cdot(|mu_val|+1)$}
4104 @d box_val_limit=@"50 {$2^4\cdot(|box_val|+1)$}
4105 @d tok_val_limit=@"60 {$2^4\cdot(|tok_val|+1)$}
4106 @#
4107 @d index_node_size=9 {size of an index node}
4108 @d sa_index==type {a four-bit address or a type or both}
4109 @d sa_used==subtype {count of non-null pointers}
4110
4111 @<Declare \eTeX\ procedures for ex...@>=
4112 procedure new_index(@!i:quarterword; @!q:pointer);
4113 var k:small_number; {loop index}
4114 begin cur_ptr:=get_node(index_node_size); sa_index(cur_ptr):=i;
4115 sa_used(cur_ptr):=0; link(cur_ptr):=q;
4116 for k:=1 to index_node_size-1 do {clear all 16 pointers}
4117 mem[cur_ptr+k]:=sa_null;
4118 end;
4119
4120 @ The roots of the seven trees for the additional registers and mark
4121 classes are kept in the |sa_root| array. The first six locations must
4122 be dumped and undumped; the last one is also known as |sa_mark|.
4123
4124 @d sa_mark==sa_root[mark_val] {root for mark classes}
4125
4126 @<Glob...@>=
4127 @!sa_root:array[int_val..mark_val] of pointer; {roots of sparse arrays}
4128 @!cur_ptr:pointer; {value returned by |new_index| and |find_sa_element|}
4129 @!sa_null:memory_word; {two |null| pointers}
4130
4131 @ @<Set init...@>=
4132 sa_mark:=null; sa_null.hh.lh:=null; sa_null.hh.rh:=null;
4133
4134 @ @<Initialize table...@>=
4135 for i:=int_val to tok_val do sa_root[i]:=null;
4136
4137 @ Given a type |t| and a sixteen-bit number |n|, the |find_sa_element|
4138 procedure returns (in |cur_ptr|) a pointer to the node for the
4139 corresponding array element, or |null| when no such element exists. The
4140 third parameter |w| is set |true| if the element must exist, e.g.,
4141 because it is about to be modified. The procedure has two main
4142 branches: one follows the existing tree structure, the other (only used
4143 when |w| is |true|) creates the missing nodes.
4144
4145 We use macros to extract the four-bit pieces from a sixteen-bit register
4146 number or mark class and to fetch or store one of the 16 pointers from
4147 an index node.
4148
4149 @d if_cur_ptr_is_null_then_return_or_goto(#)== {some tree element is missing}
4150 begin if cur_ptr=null then
4151 if w then goto #@+else return;
4152 end
4153 @#
4154 @d hex_dig1(#)==# div 4096 {the fourth lowest hexadecimal digit}
4155 @d hex_dig2(#)==(# div 256) mod 16 {the third lowest hexadecimal digit}
4156 @d hex_dig3(#)==(# div 16) mod 16 {the second lowest hexadecimal digit}
4157 @d hex_dig4(#)==# mod 16 {the lowest hexadecimal digit}
4158 @#
4159 @d get_sa_ptr==if odd(i) then cur_ptr:=link(q+(i div 2)+1)
4160 else cur_ptr:=info(q+(i div 2)+1)
4161 {set |cur_ptr| to the pointer indexed by |i| from index node |q|}
4162 @d put_sa_ptr(#)==if odd(i) then link(q+(i div 2)+1):=#
4163 else info(q+(i div 2)+1):=#
4164 {store the pointer indexed by |i| in index node |q|}
4165 @d add_sa_ptr==begin put_sa_ptr(cur_ptr); incr(sa_used(q));
4166 end {add |cur_ptr| as the pointer indexed by |i| in index node |q|}
4167 @d delete_sa_ptr==begin put_sa_ptr(null); decr(sa_used(q));
4168 end {delete the pointer indexed by |i| in index node |q|}
4169
4170 @<Declare \eTeX\ procedures for ex...@>=
4171 procedure find_sa_element(@!t:small_number;@!n:halfword;@!w:boolean);
4172 {sets |cur_val| to sparse array element location or |null|}
4173 label not_found,not_found1,not_found2,not_found3,not_found4,exit;
4174 var q:pointer; {for list manipulations}
4175 @!i:small_number; {a four bit index}
4176 begin cur_ptr:=sa_root[t];
4177 if_cur_ptr_is_null_then_return_or_goto(not_found);@/
4178 q:=cur_ptr; i:=hex_dig1(n); get_sa_ptr;
4179 if_cur_ptr_is_null_then_return_or_goto(not_found1);@/
4180 q:=cur_ptr; i:=hex_dig2(n); get_sa_ptr;
4181 if_cur_ptr_is_null_then_return_or_goto(not_found2);@/
4182 q:=cur_ptr; i:=hex_dig3(n); get_sa_ptr;
4183 if_cur_ptr_is_null_then_return_or_goto(not_found3);@/
4184 q:=cur_ptr; i:=hex_dig4(n); get_sa_ptr;
4185 if (cur_ptr=null)and w then goto not_found4;
4186 return;
4187 not_found: new_index(t,null); {create first level index node}
4188 sa_root[t]:=cur_ptr; q:=cur_ptr; i:=hex_dig1(n);
4189 not_found1: new_index(i,q); {create second level index node}
4190 add_sa_ptr; q:=cur_ptr; i:=hex_dig2(n);
4191 not_found2: new_index(i,q); {create third level index node}
4192 add_sa_ptr; q:=cur_ptr; i:=hex_dig3(n);
4193 not_found3: new_index(i,q); {create fourth level index node}
4194 add_sa_ptr; q:=cur_ptr; i:=hex_dig4(n);
4195 not_found4: @<Create a new array element of type |t| with index |i|@>;
4196 link(cur_ptr):=q; add_sa_ptr;
4197 exit:end;
4198
4199 @ The array elements for registers are subject to grouping and have an
4200 |sa_lev| field (quite analogous to |eq_level|) instead of |sa_used|.
4201 Since saved values as well as shorthand definitions (created by e.g.,
4202 \.{\\countdef}) refer to the location of the respective array element,
4203 we need a reference count that is kept in the |sa_ref| field. An array
4204 element can be deleted (together with all references to it) when its
4205 |sa_ref| value is |null| and its value is the default value.
4206 @^reference counts@>
4207
4208 Skip, muskip, box, and token registers use two word nodes, their values
4209 are stored in the |sa_ptr| field.
4210 Count and dimen registers use three word nodes, their
4211 values are stored in the |sa_int| resp.\ |sa_dim| field in the third
4212 word; the |sa_ptr| field is used under the name |sa_num| to store
4213 the register number. Mark classes use four word nodes. The last three
4214 words contain the five types of current marks
4215
4216 @d sa_lev==sa_used {grouping level for the current value}
4217 @d pointer_node_size=2 {size of an element with a pointer value}
4218 @d sa_type(#)==(sa_index(#) div 16) {type part of combined type/index}
4219 @d sa_ref(#)==info(#+1) {reference count of a sparse array element}
4220 @d sa_ptr(#)==link(#+1) {a pointer value}
4221 @#
4222 @d word_node_size=3 {size of an element with a word value}
4223 @d sa_num==sa_ptr {the register number}
4224 @d sa_int(#)==mem[#+2].int {an integer}
4225 @d sa_dim(#)==mem[#+2].sc {a dimension (a somewhat esotheric distinction)}
4226 @#
4227 @d mark_class_node_size=4 {size of an element for a mark class}
4228 @#
4229 @d fetch_box(#)== {fetch |box(cur_val)|}
4230 if cur_val<256 then #:=box(cur_val)
4231 else begin find_sa_element(box_val,cur_val,false);
4232 if cur_ptr=null then #:=null@+else #:=sa_ptr(cur_ptr);
4233 end
4234
4235 @<Create a new array element...@>=
4236 if t=mark_val then {a mark class}
4237 begin cur_ptr:=get_node(mark_class_node_size);
4238 mem[cur_ptr+1]:=sa_null; mem[cur_ptr+2]:=sa_null; mem[cur_ptr+3]:=sa_null;
4239 end
4240 else begin if t<=dimen_val then {a count or dimen register}
4241 begin cur_ptr:=get_node(word_node_size); sa_int(cur_ptr):=0;
4242 sa_num(cur_ptr):=n;
4243 end
4244 else begin cur_ptr:=get_node(pointer_node_size);
4245 if t<=mu_val then {a skip or muskip register}
4246 begin sa_ptr(cur_ptr):=zero_glue; add_glue_ref(zero_glue);
4247 end
4248 else sa_ptr(cur_ptr):=null; {a box or token list register}
4249 end;
4250 sa_ref(cur_ptr):=null; {all registers have a reference count}
4251 end;
4252 sa_index(cur_ptr):=16*t+i; sa_lev(cur_ptr):=level_one
4253
4254 @ The |delete_sa_ref| procedure is called when a pointer to an array
4255 element representing a register is being removed; this means that the
4256 reference count should be decreased by one. If the reduced reference
4257 count is |null| and the register has been (globally) assigned its
4258 default value the array element should disappear, possibly together with
4259 some index nodes. This procedure will never be used for mark class
4260 nodes.
4261 @^reference counts@>
4262
4263 @d add_sa_ref(#)==incr(sa_ref(#)) {increase reference count}
4264 @#
4265 @d change_box(#)== {change |box(cur_val)|, the |eq_level| stays the same}
4266 if cur_val<256 then set_equiv(box_base+cur_val,#)@+else set_sa_box(#)
4267 @#
4268
4269 { FIXME: needs debugging (sparse arrays) }
4270 @d set_sa_box(#)==begin find_sa_element(box_val,cur_val,false);
4271 if cur_ptr<>0 then
4272 begin
4273 set_equiv(sa_ptr(cur_ptr),#);
4274 add_sa_ref(cur_ptr);
4275 delete_sa_ref(cur_ptr);
4276 end;
4277 end
4278
4279 @<Declare \eTeX\ procedures for tr...@>=
4280 procedure delete_sa_ref(@!q:pointer); {reduce reference count}
4281 label exit;
4282 var p:pointer; {for list manipulations}
4283 @!i:small_number; {a four bit index}
4284 @!s:small_number; {size of a node}
4285 begin decr(sa_ref(q));
4286 if sa_ref(q)<>null then return;
4287 if sa_index(q)<dimen_val_limit then
4288 if sa_int(q)=0 then s:=word_node_size
4289 else return
4290 else begin if sa_index(q)<mu_val_limit then
4291 if sa_ptr(q)=zero_glue then delete_glue_ref(zero_glue)
4292 else return
4293 else if sa_ptr(q)<>null then return;
4294 s:=pointer_node_size;
4295 end;
4296 repeat i:=hex_dig4(sa_index(q)); p:=q; q:=link(p); free_node(p,s);
4297 if q=null then {the whole tree has been freed}
4298 begin sa_root[i]:=null; return;
4299 end;
4300 delete_sa_ptr; s:=index_node_size; {node |q| is an index node}
4301 until sa_used(q)>0;
4302 exit:end;
4303
4304 @ The |print_sa_num| procedure prints the register number corresponding
4305 to an array element.
4306
4307 @<Basic print...@>=
4308 procedure print_sa_num(@!q:pointer); {print register number}
4309 var @!n:halfword; {the register number}
4310 begin if sa_index(q)<dimen_val_limit then n:=sa_num(q) {the easy case}
4311 else begin n:=hex_dig4(sa_index(q)); q:=link(q); n:=n+16*sa_index(q);
4312 q:=link(q); n:=n+256*(sa_index(q)+16*sa_index(link(q)));
4313 end;
4314 print_int(n);
4315 end;
4316
4317 @ Here is a procedure that displays the contents of an array element
4318 symbolically. It is used under similar circumstances as is
4319 |restore_trace| (together with |show_eqtb|) for the quantities kept in
4320 the |eqtb| array.
4321
4322 @<Declare \eTeX\ procedures for tr...@>=
4323 @!stat procedure show_sa(@!p:pointer;@!s:str_number);
4324 var t:small_number; {the type of element}
4325 begin begin_diagnostic; print_char("{"); print(s); print_char(" ");
4326 if p=null then print_char("?") {this can't happen}
4327 else begin t:=sa_type(p);
4328 if t<box_val then print_cmd_chr(register,p)
4329 else if t=box_val then
4330 begin print_esc("box"); print_sa_num(p);
4331 end
4332 else if t=tok_val then print_cmd_chr(toks_register,p)
4333 else print_char("?"); {this can't happen either}
4334 print_char("=");
4335 if t=int_val then print_int(sa_int(p))
4336 else if t=dimen_val then
4337 begin print_scaled(sa_dim(p)); print("pt");
4338 end
4339 else begin p:=sa_ptr(p);
4340 if t=glue_val then print_spec(p,"pt")
4341 else if t=mu_val then print_spec(p,"mu")
4342 else if t=box_val then
4343 if p=null then print("void")
4344 else begin depth_threshold:=0; breadth_max:=1; show_node_list(p);
4345 end
4346 else if t=tok_val then
4347 begin if p<>null then show_token_list(link(p),null,32);
4348 end
4349 else print_char("?"); {this can't happen either}
4350 end;
4351 end;
4352 print_char("}"); end_diagnostic(false);
4353 end;
4354 tats
4355
4356 @ Here we compute the pointer to the current mark of type |t| and mark
4357 class |cur_val|.
4358
4359 @<Compute the mark pointer...@>=
4360 begin find_sa_element(mark_val,cur_val,false);
4361 if cur_ptr<>null then
4362 if odd(t) then cur_ptr:=link(cur_ptr+(t div 2)+1)
4363 else cur_ptr:=info(cur_ptr+(t div 2)+1);
4364 end
4365
4366 @ The current marks for all mark classes are maintained by the |vsplit|
4367 and |fire_up| routines and are finally destroyed (for \.{INITEX} only)
4368 @.INITEX@>
4369 by the |final_cleanup| routine. Apart from updating the current marks
4370 when mark nodes are encountered, these routines perform certain actions
4371 on all existing mark classes. The recursive |do_marks| procedure walks
4372 through the whole tree or a subtree of existing mark class nodes and
4373 preforms certain actions indicted by its first parameter |a|, the action
4374 code. The second parameter |l| indicates the level of recursion (at
4375 most four); the third parameter points to a nonempty tree or subtree.
4376 The result is |true| if the complete tree or subtree has been deleted.
4377
4378 @d vsplit_init==0 {action code for |vsplit| initialization}
4379 @d fire_up_init==1 {action code for |fire_up| initialization}
4380 @d fire_up_done==2 {action code for |fire_up| completion}
4381 @d destroy_marks==3 {action code for |final_cleanup|}
4382 @#
4383 @d sa_top_mark(#)==info(#+1) {\.{\\topmarks}|n|}
4384 @d sa_first_mark(#)==link(#+1) {\.{\\firstmarks}|n|}
4385 @d sa_bot_mark(#)==info(#+2) {\.{\\botmarks}|n|}
4386 @d sa_split_first_mark(#)==link(#+2) {\.{\\splitfirstmarks}|n|}
4387 @d sa_split_bot_mark(#)==info(#+3) {\.{\\splitbotmarks}|n|}
4388
4389 @<Declare the function called |do_marks|@>=
4390 function do_marks(@!a,@!l:small_number;@!q:pointer):boolean;
4391 var i:small_number; {a four bit index}
4392 begin if l<4 then {|q| is an index node}
4393 begin for i:=0 to 15 do
4394 begin get_sa_ptr;
4395 if cur_ptr<>null then if do_marks(a,l+1,cur_ptr) then delete_sa_ptr;
4396 end;
4397 if sa_used(q)=0 then
4398 begin free_node(q,index_node_size); q:=null;
4399 end;
4400 end
4401 else {|q| is the node for a mark class}
4402 begin case a of
4403 @<Cases for |do_marks|@>@;
4404 end; {there are no other cases}
4405 if sa_bot_mark(q)=null then if sa_split_bot_mark(q)=null then
4406 begin free_node(q,mark_class_node_size); q:=null;
4407 end;
4408 end;
4409 do_marks:=(q=null);
4410 end;
4411
4412 @ At the start of the |vsplit| routine the existing |split_fist_mark|
4413 and |split_bot_mark| are discarded.
4414
4415 @<Cases for |do_marks|@>=
4416 vsplit_init: if sa_split_first_mark(q)<>null then
4417 begin delete_token_ref(sa_split_first_mark(q)); sa_split_first_mark(q):=null;
4418 delete_token_ref(sa_split_bot_mark(q)); sa_split_bot_mark(q):=null;
4419 end;
4420
4421 @ We use again the fact that |split_first_mark=null| if and only if
4422 |split_bot_mark=null|.
4423
4424 @<Update the current marks for |vsplit|@>=
4425 begin find_sa_element(mark_val,mark_class(p),true);
4426 if sa_split_first_mark(cur_ptr)=null then
4427 begin sa_split_first_mark(cur_ptr):=mark_ptr(p);
4428 add_token_ref(mark_ptr(p));
4429 end
4430 else delete_token_ref(sa_split_bot_mark(cur_ptr));
4431 sa_split_bot_mark(cur_ptr):=mark_ptr(p);
4432 add_token_ref(mark_ptr(p));
4433 end
4434
4435 @ At the start of the |fire_up| routine the old |top_mark| and
4436 |first_mark| are discarded, whereas the old |bot_mark| becomes the new
4437 |top_mark|. An empty new |top_mark| token list is, however, discarded
4438 as well in order that mark class nodes can eventually be released. We
4439 use again the fact that |bot_mark<>null| implies |first_mark<>null|; it
4440 also knows that |bot_mark=null| implies |top_mark=first_mark=null|.
4441
4442 @<Cases for |do_marks|@>=
4443 fire_up_init: if sa_bot_mark(q)<>null then
4444 begin if sa_top_mark(q)<>null then delete_token_ref(sa_top_mark(q));
4445 delete_token_ref(sa_first_mark(q)); sa_first_mark(q):=null;
4446 if link(sa_bot_mark(q))=null then {an empty token list}
4447 begin delete_token_ref(sa_bot_mark(q)); sa_bot_mark(q):=null;
4448 end
4449 else add_token_ref(sa_bot_mark(q));
4450 sa_top_mark(q):=sa_bot_mark(q);
4451 end;
4452
4453 @ @<Cases for |do_marks|@>=
4454 fire_up_done: if (sa_top_mark(q)<>null)and(sa_first_mark(q)=null) then
4455 begin sa_first_mark(q):=sa_top_mark(q); add_token_ref(sa_top_mark(q));
4456 end;
4457
4458 @ @<Update the current marks for |fire_up|@>=
4459 begin find_sa_element(mark_val,mark_class(p),true);
4460 if sa_first_mark(cur_ptr)=null then
4461 begin sa_first_mark(cur_ptr):=mark_ptr(p);
4462 add_token_ref(mark_ptr(p));
4463 end;
4464 if sa_bot_mark(cur_ptr)<>null then delete_token_ref(sa_bot_mark(cur_ptr));
4465 sa_bot_mark(cur_ptr):=mark_ptr(p); add_token_ref(mark_ptr(p));
4466 end
4467
4468 @ Here we use the fact that the five current mark pointers in a mark
4469 class node occupy the same locations as the first five pointers of
4470 an index node. For systems using a run-time switch to distinguish
4471 between \.{VIRTEX} and \.{INITEX}, the codewords `$|init|\ldots|tini|$'
4472 surrounding the following piece of code should be removed.
4473 @.INITEX@>
4474 @^system dependencies@>
4475
4476 @<Cases for |do_marks|@>=
4477 @!init destroy_marks: for i:=top_mark_code to split_bot_mark_code do
4478 begin get_sa_ptr;
4479 if cur_ptr<>null then
4480 begin delete_token_ref(cur_ptr); put_sa_ptr(null);
4481 end;
4482 end;
4483 tini
4484
4485 @ The command code |register| is used for `\.{\\count}', `\.{\\dimen}',
4486 etc., as well as for references to sparse array elements defined by
4487 `\.{\\countdef}', etc.
4488
4489 @<Cases of |register| for |print_cmd_chr|@>=
4490 begin if (chr_code<mem_bot)or(chr_code>lo_mem_stat_max) then
4491 cmd:=sa_type(chr_code)
4492 else begin cmd:=chr_code-mem_bot; chr_code:=null;
4493 end;
4494 if cmd=int_val then print_esc("count")
4495 else if cmd=dimen_val then print_esc("dimen")
4496 else if cmd=glue_val then print_esc("skip")
4497 else print_esc("muskip");
4498 if chr_code<>null then print_sa_num(chr_code);
4499 end
4500
4501 @ Similarly the command code |toks_register| is used for `\.{\\toks}' as
4502 well as for references to sparse array elements defined by
4503 `\.{\\toksdef}'.
4504
4505 @<Cases of |toks_register| for |print_cmd_chr|@>=
4506 begin print_esc("toks");
4507 if chr_code<>mem_bot then print_sa_num(chr_code);
4508 end
4509
4510 @ When a shorthand definition for an element of one of the sparse arrays
4511 is destroyed, we must reduce the reference count.
4512
4513 @<Cases for |eq_destroy|@>=
4514 toks_register,register:
4515 if (equiv_field(w)<mem_bot)or(equiv_field(w)>lo_mem_stat_max) then
4516 delete_sa_ref(equiv_field(w));
4517
4518 @ The task to maintain (change, save, and restore) register values is
4519 essentially the same when the register is realized as sparse array
4520 element or entry in |eqtb|. The global variable |sa_chain| is the head
4521 of a linked list of entries saved at the topmost level |sa_level|; the
4522 lists for lowel levels are kept in special save stack entries.
4523
4524 @<Glob...@>=
4525 @!sa_chain: pointer; {chain of saved sparse array entries}
4526 @!sa_level: quarterword; {group level for |sa_chain|}
4527
4528 @ @<Set init...@>=
4529 sa_chain:=null; sa_level:=level_zero;
4530
4531 @ The individual saved items are kept in pointer or word nodes similar
4532 to those used for the array elements: a word node with value zero is,
4533 however, saved as pointer node with the otherwise impossible |sa_index|
4534 value |tok_val_limit|.
4535
4536 @d sa_loc==sa_ref {location of saved item}
4537
4538 @<Declare \eTeX\ procedures for tr...@>=
4539 procedure sa_save(@!p:pointer); {saves value of |p|}
4540 var q:pointer; {the new save node}
4541 @!i:quarterword; {index field of node}
4542 begin if cur_level<>sa_level then
4543 begin check_full_save_stack; save_type(save_ptr):=restore_sa;
4544 save_level(save_ptr):=sa_level; save_index(save_ptr):=sa_chain;
4545 incr(save_ptr); sa_chain:=null; sa_level:=cur_level;
4546 end;
4547 i:=sa_index(p);
4548 if i<dimen_val_limit then
4549 begin if sa_int(p)=0 then
4550 begin q:=get_node(pointer_node_size); i:=tok_val_limit;
4551 end
4552 else begin q:=get_node(word_node_size); sa_int(q):=sa_int(p);
4553 end;
4554 sa_ptr(q):=null;
4555 end
4556 else begin q:=get_node(pointer_node_size); sa_ptr(q):=sa_ptr(p);
4557 end;
4558 sa_loc(q):=p; sa_index(q):=i; sa_lev(q):=sa_lev(p);
4559 link(q):=sa_chain; sa_chain:=q; add_sa_ref(p);
4560 end;
4561
4562 @ @<Declare \eTeX\ procedures for tr...@>=
4563 procedure sa_destroy(@!p:pointer); {destroy value of |p|}
4564 begin if sa_index(p)<mu_val_limit then delete_glue_ref(sa_ptr(p))
4565 else if sa_ptr(p)<>null then
4566 if sa_index(p)<box_val_limit then flush_node_list(sa_ptr(p))
4567 else delete_token_ref(sa_ptr(p));
4568 end;
4569
4570 @ The procedure |sa_def| assigns a new value to sparse array elements,
4571 and saves the former value if appropriate. This procedure is used only
4572 for skip, muskip, box, and token list registers. The counterpart of
4573 |sa_def| for count and dimen registers is called |sa_w_def|.
4574
4575 @d sa_define(#)==if e then
4576 if global then gsa_def(#)@+else sa_def(#)
4577 else define
4578 @#
4579 @d sa_def_box== {assign |cur_box| to |box(cur_val)|}
4580 begin find_sa_element(box_val,cur_val,true);
4581 if global then gsa_def(cur_ptr,cur_box)@+else sa_def(cur_ptr,cur_box);
4582 end
4583 @#
4584 @d sa_word_define(#)==if e then
4585 if global then gsa_w_def(#)@+else sa_w_def(#)
4586 else word_define(#)
4587
4588 @<Declare \eTeX\ procedures for tr...@>=
4589 procedure sa_def(@!p:pointer;@!e:halfword);
4590 {new data for sparse array elements}
4591 begin add_sa_ref(p);
4592 if sa_ptr(p)=e then
4593 begin @!stat if tracing_assigns>0 then show_sa(p,"reassigning");@+tats@;@/
4594 sa_destroy(p);
4595 end
4596 else begin @!stat if tracing_assigns>0 then show_sa(p,"changing");@+tats@;@/
4597 if sa_lev(p)=cur_level then sa_destroy(p)@+else sa_save(p);
4598 sa_lev(p):=cur_level; sa_ptr(p):=e;
4599 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
4600 end;
4601 delete_sa_ref(p);
4602 end;
4603 @#
4604 procedure sa_w_def(@!p:pointer;@!w:integer);
4605 begin add_sa_ref(p);
4606 if sa_int(p)=w then
4607 begin @!stat if tracing_assigns>0 then show_sa(p,"reassigning");@+tats@;@/
4608 end
4609 else begin @!stat if tracing_assigns>0 then show_sa(p,"changing");@+tats@;@/
4610 if sa_lev(p)<>cur_level then sa_save(p);
4611 sa_lev(p):=cur_level; sa_int(p):=w;
4612 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
4613 end;
4614 delete_sa_ref(p);
4615 end;
4616
4617 @ The |sa_def| and |sa_w_def| routines take care of local definitions.
4618 @^global definitions@>
4619 Global definitions are done in almost the same way, but there is no need
4620 to save old values, and the new value is associated with |level_one|.
4621
4622 @<Declare \eTeX\ procedures for tr...@>=
4623 procedure gsa_def(@!p:pointer;@!e:halfword); {global |sa_def|}
4624 begin add_sa_ref(p);
4625 @!stat if tracing_assigns>0 then show_sa(p,"globally changing");@+tats@;@/
4626 sa_destroy(p); sa_lev(p):=level_one; sa_ptr(p):=e;
4627 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
4628 delete_sa_ref(p);
4629 end;
4630 @#
4631 procedure gsa_w_def(@!p:pointer;@!w:integer); {global |sa_w_def|}
4632 begin add_sa_ref(p);
4633 @!stat if tracing_assigns>0 then show_sa(p,"globally changing");@+tats@;@/
4634 sa_lev(p):=level_one; sa_int(p):=w;
4635 @!stat if tracing_assigns>0 then show_sa(p,"into");@+tats@;@/
4636 delete_sa_ref(p);
4637 end;
4638
4639 @ The |sa_restore| procedure restores the sparse array entries pointed
4640 at by |sa_chain|
4641
4642 @<Declare \eTeX\ procedures for tr...@>=
4643 procedure sa_restore;
4644 var p:pointer; {sparse array element}
4645 begin repeat p:=sa_loc(sa_chain);
4646 if sa_lev(p)=level_one then
4647 begin if sa_index(p)>=dimen_val_limit then sa_destroy(sa_chain);
4648 @!stat if tracing_restores>0 then show_sa(p,"retaining");@+tats@;@/
4649 end
4650 else begin if sa_index(p)<dimen_val_limit then
4651 if sa_index(sa_chain)<dimen_val_limit then sa_int(p):=sa_int(sa_chain)
4652 else sa_int(p):=0
4653 else begin sa_destroy(p); sa_ptr(p):=sa_ptr(sa_chain);
4654 end;
4655 sa_lev(p):=sa_lev(sa_chain);
4656 @!stat if tracing_restores>0 then show_sa(p,"restoring");@+tats@;@/
4657 end;
4658 delete_sa_ref(p);
4659 p:=sa_chain; sa_chain:=link(p);
4660 if sa_index(p)<dimen_val_limit then free_node(p,word_node_size)
4661 else free_node(p,pointer_node_size);
4662 until sa_chain=null;
4663 end;
4664
4665 {FIXME: |last_line_fit| might be incompatible with Omega}
4666
4667 @ When the value of |last_line_fit| is positive, the last line of a
4668 (partial) paragraph is treated in a special way and we need additional
4669 fields in the active nodes.
4670
4671 @d active_node_size_extended=5 {number of words in extended active nodes}
4672 @d active_short(#)==mem[#+3].sc {|shortfall| of this line}
4673 @d active_glue(#)==mem[#+4].sc {corresponding glue stretch or shrink}
4674
4675 @<Glob...@>=
4676 @!last_line_fill:pointer; {the |par_fill_skip| glue node of the new paragraph}
4677 @!do_last_line_fit:boolean; {special algorithm for last line of paragraph?}
4678 @!active_node_size:small_number; {number of words in active nodes}
4679 @!fill_width:array[0..2] of scaled; {infinite stretch components of
4680 |par_fill_skip|}
4681 @!best_pl_short:array[very_loose_fit..tight_fit] of scaled; {|shortfall|
4682 corresponding to |minimal_demerits|}
4683 @!best_pl_glue:array[very_loose_fit..tight_fit] of scaled; {corresponding
4684 glue stretch or shrink}
4685
4686 @ The new algorithm for the last line requires that the stretchability
4687 |par_fill_skip| is infinite and the stretchability of |left_skip| plus
4688 |right_skip| is finite.
4689
4690 @<Check for special...@>=
4691 do_last_line_fit:=false; active_node_size:=active_node_size_normal;
4692 {just in case}
4693 if last_line_fit>0 then
4694 begin q:=glue_ptr(last_line_fill);
4695 if (stretch(q)>0)and(stretch_order(q)>normal) then
4696 if (background[3]=0)and(background[4]=0)and(background[5]=0) then
4697 begin do_last_line_fit:=true;
4698 active_node_size:=active_node_size_extended;
4699 fill_width[0]:=0; fill_width[1]:=0; fill_width[2]:=0;
4700 fill_width[stretch_order(q)-1]:=stretch(q);
4701 end;
4702 end
4703
4704 @ @<Other local variables for |try_break|@>=
4705 @!g:scaled; {glue stretch or shrink of test line, adjustment for last line}
4706
4707 @ Here we initialize the additional fields of the first active node
4708 representing the beginning of the paragraph.
4709
4710 @<Initialize additional fields of the first active node@>=
4711 begin active_short(q):=0; active_glue(q):=0;
4712 end
4713
4714 @ Here we compute the adjustment |g| and badness |b| for a line from |r|
4715 to the end of the paragraph. When any of the criteria for adjustment is
4716 violated we fall through to the normal algorithm.
4717
4718 The last line must be too short, and have infinite stretch entirely due
4719 to |par_fill_skip|.
4720
4721 @<Perform computations for last line and |goto found|@>=
4722 begin if (active_short(r)=0)or(active_glue(r)<=0) then goto not_found;
4723 {previous line was neither stretched nor shrunk, or was infinitely bad}
4724 if (cur_active_width[3]<>fill_width[0])or@|
4725 (cur_active_width[4]<>fill_width[1])or@|
4726 (cur_active_width[5]<>fill_width[2]) then goto not_found;
4727 {infinite stretch of this line not entirely due to |par_fill_skip|}
4728 if active_short(r)>0 then g:=cur_active_width[2]
4729 else g:=cur_active_width[6];
4730 if g<=0 then goto not_found; {no finite stretch resp.\ no shrink}
4731 arith_error:=false; g:=fract(g,active_short(r),active_glue(r),max_dimen);
4732 if last_line_fit<1000 then g:=fract(g,last_line_fit,1000,max_dimen);
4733 if arith_error then
4734 if active_short(r)>0 then g:=max_dimen@+else g:=-max_dimen;
4735 if g>0 then
4736 @<Set the value of |b| to the badness of the last line for stretching,
4737 compute the corresponding |fit_class, and |goto found||@>
4738 else if g<0 then
4739 @<Set the value of |b| to the badness of the last line for shrinking,
4740 compute the corresponding |fit_class, and |goto found||@>;
4741 not_found:end
4742
4743 @ These badness computations are rather similar to those of the standard
4744 algorithm, with the adjustment amount |g| replacing the |shortfall|.
4745
4746 @<Set the value of |b| to the badness of the last line for str...@>=
4747 begin if g>shortfall then g:=shortfall;
4748 if g>7230584 then if cur_active_width[2]<1663497 then
4749 begin b:=inf_bad; fit_class:=very_loose_fit; goto found;
4750 end;
4751 b:=badness(g,cur_active_width[2]);
4752 if b>12 then
4753 if b>99 then fit_class:=very_loose_fit
4754 else fit_class:=loose_fit
4755 else fit_class:=decent_fit;
4756 goto found;
4757 end
4758
4759 @ @<Set the value of |b| to the badness of the last line for shr...@>=
4760 begin if -g>cur_active_width[6] then g:=-cur_active_width[6];
4761 b:=badness(-g,cur_active_width[6]);
4762 if b>12 then fit_class:=tight_fit@+else fit_class:=decent_fit;
4763 goto found;
4764 end
4765
4766 @ Vanishing values of |shortfall| and |g| indicate that the last line is
4767 not adjusted.
4768
4769 @<Adjust \(t)the additional data for last line@>=
4770 begin if cur_p=null then shortfall:=0;
4771 if shortfall>0 then g:=cur_active_width[2]
4772 else if shortfall<0 then g:=cur_active_width[6]
4773 else g:=0;
4774 end
4775
4776 @ For each feasible break we record the shortfall and glue stretch or
4777 shrink (or adjustment).
4778
4779 @<Store \(a)additional data for this feasible break@>=
4780 begin best_pl_short[fit_class]:=shortfall; best_pl_glue[fit_class]:=g;
4781 end
4782
4783 @ Here we save these data in the active node representing a potential
4784 line break.
4785
4786 @<Store \(a)additional data in the new active node@>=
4787 begin active_short(q):=best_pl_short[fit_class];
4788 active_glue(q):=best_pl_glue[fit_class];
4789 end
4790
4791 @ @<Print additional data in the new active node@>=
4792 begin print(" s="); print_scaled(active_short(q));
4793 if cur_p=null then print(" a=")@+else print(" g=");
4794 print_scaled(active_glue(q));
4795 end
4796
4797 @ Here we either reset |do_last_line_fit| or adjust the |par_fill_skip|
4798 glue.
4799
4800 @<Adjust \(t)the final line of the paragraph@>=
4801 if active_short(best_bet)=0 then do_last_line_fit:=false
4802 else begin q:=new_spec(glue_ptr(last_line_fill));
4803 delete_glue_ref(glue_ptr(last_line_fill));
4804 width(q):=width(q)+active_short(best_bet)-active_glue(best_bet);
4805 stretch(q):=0; glue_ptr(last_line_fill):=q;
4806 end
4807
4808 @ When reading \.{\\patterns} while \.{\\savinghyphcodes} is positive
4809 the current |lc_code| values are stored together with the hyphenation
4810 patterns for the current language. They will later be used instead of
4811 the |lc_code| values for hyphenation purposes.
4812
4813 The |lc_code| values are stored in the linked trie analogous to patterns
4814 $p_1$ of length~1, with |hyph_root=trie_r[0]| replacing |trie_root| and
4815 |lc_code(p_1)| replacing the |trie_op| code. This allows to compress
4816 and pack them together with the patterns with minimal changes to the
4817 existing code.
4818
4819 @d hyph_root==trie_r[0] {root of the linked trie for |hyph_codes|}
4820
4821 @<Initialize table entries...@>=
4822 hyph_root:=0; hyph_start:=0;
4823
4824 @ @<Store hyphenation codes for current language@>=
4825 begin c:=cur_lang; first_child:=false; p:=0;
4826 repeat q:=p; p:=trie_r[q];
4827 until (p=0)or(c<=so(trie_c[p]));
4828 if (p=0)or(c<so(trie_c[p])) then
4829 @<Insert a new trie node between |q| and |p|, and
4830 make |p| point to it@>;
4831 q:=p; {now node |q| represents |cur_lang|}
4832 @<Store all current |lc_code| values@>;
4833 end
4834
4835 @ We store all nonzero |lc_code| values, overwriting any previously
4836 stored values (and possibly wasting a few trie nodes that were used
4837 previously and are not needed now). We always store at least one
4838 |lc_code| value such that |hyph_index| (defined below) will not be zero.
4839
4840 @<Store all current |lc_code| values@>=
4841 p:=trie_l[q]; first_child:=true;
4842 for c:=0 to 255 do
4843 if (lc_code(c)>0)or((c=255)and first_child) then
4844 begin if p=0 then
4845 @<Insert a new trie node between |q| and |p|, and
4846 make |p| point to it@>
4847 else trie_c[p]:=si(c);
4848 trie_o[p]:=qi(lc_code(c));
4849 q:=p; p:=trie_r[q]; first_child:=false;
4850 end;
4851 if first_child then trie_l[q]:=0@+else trie_r[q]:=0
4852
4853 @ We must avoid to ``take'' location~1, in order to distinguish between
4854 |lc_code| values and patterns.
4855
4856 @<Pack all stored |hyph_codes|@>=
4857 begin if trie_root=0 then for p:=0 to 255 do trie_min[p]:=p+2;
4858 first_fit(hyph_root); trie_pack(hyph_root);
4859 hyph_start:=trie_ref[hyph_root];
4860 end
4861
4862 @ The global variable |hyph_index| will point to the hyphenation codes
4863 for the current language.
4864
4865 @d set_hyph_index== {set |hyph_index| for current language}
4866 if trie_char(hyph_start+cur_lang)<>qi(cur_lang)
4867 then hyph_index:=0 {no hyphenation codes for |cur_lang|}
4868 else hyph_index:=trie_link(hyph_start+cur_lang)
4869 @#
4870 @d set_lc_code(#)== {set |hc[0]| to hyphenation or lc code for |#|}
4871 if hyph_index=0 then hc[0]:=lc_code(#)
4872 else if trie_char(hyph_index+#)<>qi(#) then hc[0]:=0
4873 else hc[0]:=qo(trie_op(hyph_index+#))
4874
4875 @<Glob...@>=
4876 @!hyph_start:trie_pointer; {root of the packed trie for |hyph_codes|}
4877 @!hyph_index:trie_pointer; {pointer to hyphenation codes for |cur_lang|}
4878
4879 @ When |saving_vdiscards| is positive then the glue, kern, and penalty
4880 nodes removed by the page builder or by \.{\\vsplit} from the top of a
4881 vertical list are saved in special lists instead of being discarded.
4882
4883 @d tail_page_disc==disc_ptr[copy_code] {last item removed by page builder}
4884 @d page_disc==disc_ptr[last_box_code] {first item removed by page builder}
4885 @d split_disc==disc_ptr[vsplit_code] {first item removed by \.{\\vsplit}}
4886
4887 @<Glob...@>=
4888 @!disc_ptr:array[copy_code..vsplit_code] of pointer; {list pointers}
4889
4890 @ @<Set init...@>=
4891 page_disc:=null; split_disc:=null;
4892
4893 @ The \.{\\pagediscards} and \.{\\splitdiscards} commands share the
4894 command code |un_vbox| with \.{\\unvbox} and \.{\\unvcopy}, they are
4895 distinguished by their |chr_code| values |last_box_code| and
4896 |vsplit_code|. These |chr_code| values are larger than |box_code| and
4897 |copy_code|.
4898
4899 @<Generate all \eTeX...@>=
4900 primitive("pagediscards",un_vbox,last_box_code);@/
4901 @!@:page_discards_}{\.{\\pagediscards} primitive@>
4902 primitive("splitdiscards",un_vbox,vsplit_code);@/
4903 @!@:split_discards_}{\.{\\splitdiscards} primitive@>
4904
4905 @ @<Cases of |un_vbox| for |print_cmd_chr|@>=
4906 else if chr_code=last_box_code then print_esc("pagediscards")
4907 else if chr_code=vsplit_code then print_esc("splitdiscards")
4908
4909 @ @<Handle saved items and |goto done|@>=
4910 begin link(tail):=disc_ptr[cur_chr]; disc_ptr[cur_chr]:=null;
4911 goto done;
4912 end
4913
4914 @ The \.{\\interlinepenalties}, \.{\\clubpenalties}, \.{\\widowpenalties},
4915 and \.{\\displaywidowpenalties} commands allow to define arrays of
4916 penalty values to be used instead of the corresponding single values.
4917
4918 @d inter_line_penalties_ptr==equiv(inter_line_penalties_loc)
4919 @d club_penalties_ptr==equiv(club_penalties_loc)
4920 @d widow_penalties_ptr==equiv(widow_penalties_loc)
4921 @d display_widow_penalties_ptr==equiv(display_widow_penalties_loc)
4922
4923 @<Generate all \eTeX...@>=
4924 primitive("interlinepenalties",set_shape,inter_line_penalties_loc);@/
4925 @!@:inter_line_penalties_}{\.{\\interlinepenalties} primitive@>
4926 primitive("clubpenalties",set_shape,club_penalties_loc);@/
4927 @!@:club_penalties_}{\.{\\clubpenalties} primitive@>
4928 primitive("widowpenalties",set_shape,widow_penalties_loc);@/
4929 @!@:widow_penalties_}{\.{\\widowpenalties} primitive@>
4930 primitive("displaywidowpenalties",set_shape,display_widow_penalties_loc);@/
4931 @!@:display_widow_penalties_}{\.{\\displaywidowpenalties} primitive@>
4932
4933 @ @<Cases of |set_shape| for |print_cmd_chr|@>=
4934 inter_line_penalties_loc: print_esc("interlinepenalties");
4935 club_penalties_loc: print_esc("clubpenalties");
4936 widow_penalties_loc: print_esc("widowpenalties");
4937 display_widow_penalties_loc: print_esc("displaywidowpenalties");
4938
4939 @ @<Fetch a penalties array element@>=
4940 begin scan_int;
4941 if (equiv(m)=null)or(cur_val<0) then cur_val:=0
4942 else begin if cur_val>penalty(equiv(m)) then cur_val:=penalty(equiv(m));
4943 cur_val:=penalty(equiv(m)+cur_val);
4944 end;
4945 end
4946
4947 @* \[54] System-dependent changes.
4948 @z
4949 %---------------------------------------