Debian Codegraph @

texk/web2c/luatexdir/tex/texnodes.c

raw
1 /*
2
3 Copyright 2006-2010 Taco Hoekwater <[email protected]>
4
5 This file is part of LuaTeX.
6
7 LuaTeX is free software; you can redistribute it and/or modify it under the terms
8 of the GNU General Public License as published by the Free Software Foundation;
9 either version 2 of the License, or (at your option) any later version.
10
11 LuaTeX is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 LuaTeX; if not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20 #include "ptexlib.h"
21 #include "lua/luatex-api.h"
22
23 /*tex
24
25 This module started out using NDEBUG to trigger checking invalid node usage,
26 something that is needed because users can mess up nodes in Lua. At some
27 point that code was always enabled so it is now always on but still can be
28 recognized as additional code. And as the performance hit is close to zero so
29 disabling makes no sense, not even to make it configureable. There is a
30 little more memory used but that is neglectable compared to other memory
31 usage.
32
33 */
34
35 #define MAX_CHAIN_SIZE 13 /* why not a bit larger */
36
37 memory_word *volatile varmem = NULL;
38
39 char *varmem_sizes = NULL;
40
41 halfword var_mem_max = 0;
42 halfword rover = 0;
43
44 halfword free_chain[MAX_CHAIN_SIZE] = { null };
45
46 static int my_prealloc = 0;
47
48 /*tex Used in font and lang: */
49
50 int fix_node_lists = 1;
51
52 /*tex Defined below. */
53
54 halfword slow_get_node(int s);
55
56 #define fake_node 100
57 #define fake_node_size 2
58 #define fake_node_name "fake"
59
60 #define variable_node_size 2
61
62 /*tex
63
64 The following definitions are used for keys at the \LUA\ end and
65 provide an efficient way to share hashed strings.
66
67 */
68
69 # define init_node_key(target,n,key) \
70 target[n].lua = luaS_##key##_index; \
71 target[n].name = luaS_##key##_ptr;
72
73 # define init_field_key(target,n,key) \
74 target[n].lua = luaS_##key##_index; \
75 target[n].name = luaS_##key##_ptr;
76
77 # define init_field_nop(target,n) \
78 target[n].lua = 0; \
79 target[n].name = NULL;
80
81 /*tex The fields of nodes. */
82
83 field_info node_fields_accent[10];
84 field_info node_fields_adjust[3];
85 field_info node_fields_attribute[3];
86 field_info node_fields_attribute_list[1];
87 field_info node_fields_boundary[3];
88 field_info node_fields_choice[6];
89 field_info node_fields_delim[6];
90 field_info node_fields_dir[4];
91 field_info node_fields_disc[6];
92 field_info node_fields_fence[8];
93 field_info node_fields_fraction[10];
94 field_info node_fields_glue[8];
95 field_info node_fields_glue_spec[6];
96 field_info node_fields_glyph[16];
97 field_info node_fields_insert[7];
98 field_info node_fields_inserting[9];
99 field_info node_fields_kern[4];
100 field_info node_fields_list[11];
101 field_info node_fields_local_par[9];
102 field_info node_fields_margin_kern[4];
103 field_info node_fields_mark[4];
104 field_info node_fields_math[8];
105 field_info node_fields_math_char[4];
106 field_info node_fields_math_text_char[4];
107 field_info node_fields_noad[5];
108 field_info node_fields_penalty[3];
109 field_info node_fields_radical[9];
110 field_info node_fields_rule[9];
111 field_info node_fields_splitup[6];
112 field_info node_fields_style[3];
113 field_info node_fields_sub_box[3];
114 field_info node_fields_sub_mlist[3];
115 field_info node_fields_unset[12];
116
117 /*tex The fields of whatsit nodes. */
118
119 field_info node_fields_whatsit_close[3];
120 field_info node_fields_whatsit_late_lua[6];
121 field_info node_fields_whatsit_open[6];
122 field_info node_fields_whatsit_save_pos[2];
123 field_info node_fields_whatsit_special[3];
124 field_info node_fields_whatsit_user_defined[5];
125 field_info node_fields_whatsit_write[4];
126
127 field_info node_fields_whatsit_pdf_action[8];
128 field_info node_fields_whatsit_pdf_annot[7];
129 field_info node_fields_whatsit_pdf_colorstack[5];
130 field_info node_fields_whatsit_pdf_dest[10];
131 field_info node_fields_whatsit_pdf_end_link[2];
132 field_info node_fields_whatsit_pdf_end_thread[2];
133 field_info node_fields_whatsit_pdf_literal[4];
134 field_info node_fields_whatsit_pdf_refobj[3];
135 field_info node_fields_whatsit_pdf_restore[2];
136 field_info node_fields_whatsit_pdf_link_state[3];
137 field_info node_fields_whatsit_pdf_save[2];
138 field_info node_fields_whatsit_pdf_setmatrix[3];
139 field_info node_fields_whatsit_pdf_start_link[8];
140 field_info node_fields_whatsit_pdf_start_thread[8];
141 field_info node_fields_whatsit_pdf_thread[8];
142
143
144 /*tex The values of fields. */
145
146 subtype_info node_values_dir[] = {
147 { 0, NULL, 0 },
148 { 1, NULL, 0 },
149 { 2, NULL, 0 },
150 { 3, NULL, 0 },
151 { -1, NULL, 0 },
152 };
153
154 subtype_info node_values_pdf_destination[] = {
155 { 0, NULL, 0 },
156 { 1, NULL, 0 },
157 { 2, NULL, 0 },
158 { 3, NULL, 0 },
159 { 4, NULL, 0 },
160 { 5, NULL, 0 },
161 { 6, NULL, 0 },
162 { 7, NULL, 0 },
163 { -1, NULL, 0 },
164 };
165
166 subtype_info node_values_pdf_action[] = {
167 { 0, NULL, 0 },
168 { 1, NULL, 0 },
169 { 2, NULL, 0 },
170 { 3, NULL, 0 },
171 { -1, NULL, 0 },
172 };
173
174 subtype_info node_values_pdf_window[] = {
175 { 0, NULL, 0 },
176 { 1, NULL, 0 },
177 { 2, NULL, 0 },
178 { -1, NULL, 0 },
179 };
180
181 subtype_info node_values_color_stack[] = {
182 { 0, NULL, 0 },
183 { 1, NULL, 0 },
184 { 2, NULL, 0 },
185 { 3, NULL, 0 },
186 { -1, NULL, 0 },
187 };
188
189 subtype_info node_values_fill[] = {
190 { normal, NULL, 0 },
191 { sfi, NULL, 0 },
192 { fil, NULL, 0 },
193 { fill, NULL, 0 },
194 { filll, NULL, 0 },
195 { -1, NULL, 0 },
196 };
197
198 subtype_info node_values_pdf_literal[] = {
199 { set_origin, NULL, 0 },
200 { direct_page, NULL, 0 },
201 { direct_always, NULL, 0 },
202 { direct_raw, NULL, 0 },
203 { direct_text, NULL, 0 },
204 { direct_font, NULL, 0 },
205 { scan_special, NULL, 0 },
206 { -1, NULL, 0 },
207 };
208
209 subtype_info other_values_page_states[] = {
210 { 0, NULL, 0 },
211 { 1, NULL, 0 },
212 { 2, NULL, 0 },
213 { -1, NULL, 0 },
214 };
215
216 /*tex The subtypes of nodes (most have one). */
217
218 subtype_info node_subtypes_dir[] = {
219 { normal_dir, NULL, 0 },
220 { cancel_dir, NULL, 0 },
221 { -1, NULL, 0 },
222 };
223
224 subtype_info node_subtypes_glue[] = {
225 { user_skip_glue, NULL, 0 },
226 { line_skip_glue, NULL, 0 },
227 { baseline_skip_glue, NULL, 0 },
228 { par_skip_glue, NULL, 0 },
229 { above_display_skip_glue, NULL, 0 },
230 { below_display_skip_glue, NULL, 0 },
231 { above_display_short_skip_glue, NULL, 0 },
232 { below_display_short_skip_glue, NULL, 0 },
233 { left_skip_glue, NULL, 0 },
234 { right_skip_glue, NULL, 0 },
235 { top_skip_glue, NULL, 0 },
236 { split_top_skip_glue, NULL, 0 },
237 { tab_skip_glue, NULL, 0 },
238 { space_skip_glue, NULL, 0 },
239 { xspace_skip_glue, NULL, 0 },
240 { par_fill_skip_glue, NULL, 0 },
241 { math_skip_glue, NULL, 0 },
242 { thin_mu_skip_glue, NULL, 0 },
243 { med_mu_skip_glue, NULL, 0 },
244 { thick_mu_skip_glue, NULL, 0 },
245 /* math */
246 { cond_math_glue, NULL, 0 },
247 { mu_glue, NULL, 0 },
248 /* leaders */
249 { a_leaders, NULL, 0 },
250 { c_leaders, NULL, 0 },
251 { x_leaders, NULL, 0 },
252 { g_leaders, NULL, 0 },
253 { -1, NULL, 0 },
254 };
255
256 /*tex
257
258 Math glue and leaders have special numbers. At some point we might decide to
259 move them down so best don't use hard coded numbers!
260
261 */
262
263 subtype_info node_subtypes_mathglue[] = { /* 98+ */
264 { cond_math_glue, NULL, 0 },
265 { mu_glue, NULL, 0 },
266 { -1, NULL, 0 },
267 };
268
269 subtype_info node_subtypes_leader[] = { /* 100+ */
270 { a_leaders, NULL, 0 },
271 { c_leaders, NULL, 0 },
272 { x_leaders, NULL, 0 },
273 { g_leaders, NULL, 0 },
274 { -1, NULL, 0 },
275 };
276
277 subtype_info node_subtypes_boundary[] = {
278 { cancel_boundary, NULL, 0 },
279 { user_boundary, NULL, 0 },
280 { protrusion_boundary, NULL, 0 },
281 { word_boundary, NULL, 0 },
282 { -1, NULL, 0 },
283 };
284
285 subtype_info node_subtypes_penalty[] = {
286 { user_penalty, NULL, 0 },
287 { linebreak_penalty, NULL, 0 },
288 { line_penalty, NULL, 0 },
289 { word_penalty, NULL, 0 },
290 { final_penalty, NULL, 0 },
291 { noad_penalty, NULL, 0 },
292 { before_display_penalty, NULL, 0 },
293 { after_display_penalty, NULL, 0 },
294 { equation_number_penalty, NULL, 0 },
295 { -1, NULL, 0 },
296 };
297
298 subtype_info node_subtypes_kern[] = {
299 { font_kern, NULL, 0 },
300 { explicit_kern, NULL, 0 },
301 { accent_kern, NULL, 0 },
302 { italic_kern, NULL, 0 },
303 { -1, NULL, 0 },
304 };
305
306 subtype_info node_subtypes_rule[] = {
307 { normal_rule, NULL, 0 },
308 { box_rule, NULL, 0 },
309 { image_rule, NULL, 0 },
310 { empty_rule, NULL, 0 },
311 { user_rule, NULL, 0 },
312 { math_over_rule, NULL, 0 },
313 { math_under_rule, NULL, 0 },
314 { math_fraction_rule, NULL, 0 },
315 { math_radical_rule, NULL, 0 },
316 { outline_rule, NULL, 0 },
317 { -1, NULL, 0 },
318 };
319
320 subtype_info node_subtypes_glyph[] = {
321 { glyph_unset, NULL, 0 },
322 { glyph_character, NULL, 0 },
323 { glyph_ligature, NULL, 0 },
324 { glyph_ghost, NULL, 0 },
325 { glyph_left, NULL, 0 },
326 { glyph_right, NULL, 0 },
327 { -1, NULL, 0 },
328 };
329
330 subtype_info node_subtypes_disc[] = {
331 { discretionary_disc, NULL, 0 },
332 { explicit_disc, NULL, 0 },
333 { automatic_disc, NULL, 0 },
334 { syllable_disc, NULL, 0 },
335 { init_disc, NULL, 0 },
336 { select_disc, NULL, 0 },
337 { -1, NULL, 0 },
338 };
339
340 subtype_info node_subtypes_marginkern[] = {
341 { left_side, NULL, 0 },
342 { right_side, NULL, 0 },
343 { -1, NULL, 0 },
344 };
345
346 subtype_info node_subtypes_list[] = {
347 { unknown_list, NULL, 0 },
348 { line_list, NULL, 0 },
349 { hbox_list, NULL, 0 },
350 { indent_list, NULL, 0 },
351 { align_row_list, NULL, 0 },
352 { align_cell_list, NULL, 0 },
353 { equation_list, NULL, 0 },
354 { equation_number_list, NULL, 0 },
355 { math_list_list, NULL, 0 },
356 { math_char_list, NULL, 0 },
357 { math_h_extensible_list, NULL, 0 },
358 { math_v_extensible_list, NULL, 0 },
359 { math_h_delimiter_list, NULL, 0 },
360 { math_v_delimiter_list, NULL, 0 },
361 { math_over_delimiter_list, NULL, 0 },
362 { math_under_delimiter_list, NULL, 0 },
363 { math_numerator_list, NULL, 0 },
364 { math_denominator_list, NULL, 0 },
365 { math_limits_list, NULL, 0 },
366 { math_fraction_list, NULL, 0 },
367 { math_nucleus_list, NULL, 0 },
368 { math_sup_list, NULL, 0 },
369 { math_sub_list, NULL, 0 },
370 { math_degree_list, NULL, 0 },
371 { math_scripts_list, NULL, 0 },
372 { math_over_list, NULL, 0 },
373 { math_under_list, NULL, 0 },
374 { math_accent_list, NULL, 0 },
375 { math_radical_list, NULL, 0 },
376 { -1, NULL, 0 },
377 };
378
379 subtype_info node_subtypes_adjust[] = {
380 { 0, NULL, 0 },
381 { 1, NULL, 0 },
382 { -1, NULL, 0 },
383 };
384
385 subtype_info node_subtypes_math[] = {
386 { before, NULL, 0 },
387 { after, NULL, 0 },
388 { -1, NULL, 0 },
389 };
390
391 subtype_info node_subtypes_noad[] = {
392 { ord_noad_type, NULL, 0 },
393 { op_noad_type_normal, NULL, 0 },
394 { op_noad_type_limits, NULL, 0 },
395 { op_noad_type_no_limits, NULL, 0 },
396 { bin_noad_type, NULL, 0 },
397 { rel_noad_type, NULL, 0 },
398 { open_noad_type, NULL, 0 },
399 { close_noad_type, NULL, 0 },
400 { punct_noad_type, NULL, 0 },
401 { inner_noad_type, NULL, 0 },
402 { under_noad_type, NULL, 0 },
403 { over_noad_type, NULL, 0 },
404 { vcenter_noad_type, NULL, 0 },
405 { -1, NULL, 0 },
406 };
407
408 subtype_info node_subtypes_radical[] = {
409 { radical_noad_type, NULL, 0 },
410 { uradical_noad_type, NULL, 0 },
411 { uroot_noad_type, NULL, 0 },
412 { uunderdelimiter_noad_type, NULL, 0 },
413 { uoverdelimiter_noad_type, NULL, 0 },
414 { udelimiterunder_noad_type, NULL, 0 },
415 { udelimiterover_noad_type, NULL, 0 },
416 { -1, NULL, 0 },
417 };
418
419 subtype_info node_subtypes_accent[] = {
420 { bothflexible_accent, NULL, 0 },
421 { fixedtop_accent, NULL, 0 },
422 { fixedbottom_accent, NULL, 0 },
423 { fixedboth_accent, NULL, 0 },
424 { -1, NULL, 0 },
425 };
426
427 subtype_info node_subtypes_fence[] = {
428 { unset_noad_side, NULL, 0 },
429 { left_noad_side, NULL, 0 },
430 { middle_noad_side, NULL, 0 },
431 { right_noad_side, NULL, 0 },
432 { no_noad_side, NULL, 0 },
433 { -1, NULL, 0 },
434 };
435
436 /*tes This brings all together */
437
438 node_info node_data[] = {
439 { hlist_node, box_node_size, node_subtypes_list, node_fields_list, NULL, 1, 0 },
440 { vlist_node, box_node_size, node_subtypes_list, node_fields_list, NULL, 2, 0 },
441 { rule_node, rule_node_size, node_subtypes_rule, node_fields_rule, NULL, 3, 0 },
442 { ins_node, ins_node_size, NULL, node_fields_insert, NULL, 4, 0 },
443 { mark_node, mark_node_size, NULL, node_fields_mark, NULL, 5, 0 },
444 { adjust_node, adjust_node_size, node_subtypes_adjust, node_fields_adjust, NULL, 6, 0 },
445 { boundary_node, boundary_node_size, node_subtypes_boundary, node_fields_boundary, NULL, -1, 0 },
446 { disc_node, disc_node_size, node_subtypes_disc, node_fields_disc, NULL, 8, 0 },
447 { whatsit_node, -1, NULL, NULL, NULL, 9, 0 },
448 { local_par_node, local_par_size, NULL, node_fields_local_par, NULL, -1, 0 },
449 { dir_node, dir_node_size, node_subtypes_dir, node_fields_dir, NULL, -1, 0 },
450 { math_node, math_node_size, node_subtypes_math, node_fields_math, NULL, 10, 0 },
451 { glue_node, glue_node_size, node_subtypes_glue, node_fields_glue, NULL, 11, 0 },
452 { kern_node, kern_node_size, node_subtypes_kern, node_fields_kern, NULL, 12, 0 },
453 { penalty_node, penalty_node_size, node_subtypes_penalty, node_fields_penalty, NULL, 13, 0 },
454 { unset_node, box_node_size, NULL, node_fields_unset, NULL, 14, 0 },
455 { style_node, style_node_size, NULL, node_fields_style, NULL, 15, 0 },
456 { choice_node, style_node_size, NULL, node_fields_choice, NULL, 15, 0 },
457 { simple_noad, noad_size, node_subtypes_noad, node_fields_noad, NULL, 15, 0 },
458 { radical_noad, radical_noad_size, node_subtypes_radical, node_fields_radical, NULL, 15, 0 },
459 { fraction_noad, fraction_noad_size, NULL, node_fields_fraction, NULL, 15, 0 },
460 { accent_noad, accent_noad_size, node_subtypes_accent, node_fields_accent, NULL, 15, 0 },
461 { fence_noad, fence_noad_size, node_subtypes_fence, node_fields_fence, NULL, 15, 0 },
462 { math_char_node, math_kernel_node_size, NULL, node_fields_math_char, NULL, 15, 0 },
463 { sub_box_node, math_kernel_node_size, NULL, node_fields_sub_box, NULL, 15, 0 },
464 { sub_mlist_node, math_kernel_node_size, NULL, node_fields_sub_mlist, NULL, 15, 0 },
465 { math_text_char_node, math_kernel_node_size, NULL, node_fields_math_text_char, NULL, 15, 0 },
466 { delim_node, math_shield_node_size, NULL, node_fields_delim, NULL, 15, 0 },
467 { margin_kern_node, margin_kern_node_size, node_subtypes_marginkern, node_fields_margin_kern, NULL, -1, 0 },
468 { glyph_node, glyph_node_size, node_subtypes_glyph, node_fields_glyph, NULL, 0, 0 },
469 { align_record_node, box_node_size, NULL, NULL, NULL, -1, 0 },
470 { pseudo_file_node, pseudo_file_node_size, NULL, NULL, NULL, -1, 0 },
471 { pseudo_line_node, variable_node_size, NULL, NULL, NULL, -1, 0 },
472 { inserting_node, page_ins_node_size, NULL, node_fields_inserting, NULL, -1, 0 },
473 { split_up_node, page_ins_node_size, NULL, node_fields_splitup, NULL, -1, 0 },
474 { expr_node, expr_node_size, NULL, NULL, NULL, -1, 0 },
475 { nesting_node, nesting_node_size, NULL, NULL, NULL, -1, 0 },
476 { span_node, span_node_size, NULL, NULL, NULL, -1, 0 },
477 { attribute_node, attribute_node_size, NULL, node_fields_attribute, NULL, -1, 0 },
478 { glue_spec_node, glue_spec_size, NULL, node_fields_glue_spec, NULL, -1, 0 },
479 { attribute_list_node, attribute_node_size, NULL, node_fields_attribute_list, NULL, -1, 0 },
480 { temp_node, temp_node_size, NULL, NULL, NULL, -1, 0 },
481 { align_stack_node, align_stack_node_size, NULL, NULL, NULL, -1, 0 },
482 { movement_node, movement_node_size, NULL, NULL, NULL, -1, 0 },
483 { if_node, if_node_size, NULL, NULL, NULL, -1, 0 },
484 { unhyphenated_node, active_node_size, NULL, NULL, NULL, -1, 0 },
485 { hyphenated_node, active_node_size, NULL, NULL, NULL, -1, 0 },
486 { delta_node, delta_node_size, NULL, NULL, NULL, -1, 0 },
487 { passive_node, passive_node_size, NULL, NULL, NULL, -1, 0 },
488 { shape_node, variable_node_size, NULL, NULL, NULL, -1, 0 },
489 { -1, -1, NULL, NULL, NULL, -1, 0 }
490 };
491
492 void l_set_node_data(void) {
493 init_node_key(node_data, hlist_node, hlist)
494 init_node_key(node_data, vlist_node, vlist)
495 init_node_key(node_data, rule_node, rule)
496 init_node_key(node_data, ins_node, ins)
497 init_node_key(node_data, mark_node, mark)
498 init_node_key(node_data, adjust_node, adjust)
499 init_node_key(node_data, boundary_node, boundary)
500 init_node_key(node_data, disc_node, disc)
501 init_node_key(node_data, whatsit_node, whatsit)
502 init_node_key(node_data, local_par_node, local_par)
503 init_node_key(node_data, dir_node, dir)
504 init_node_key(node_data, math_node, math)
505 init_node_key(node_data, glue_node, glue)
506 init_node_key(node_data, kern_node, kern)
507 init_node_key(node_data, penalty_node, penalty)
508 init_node_key(node_data, unset_node, unset)
509 init_node_key(node_data, style_node, style)
510 init_node_key(node_data, choice_node, choice)
511 init_node_key(node_data, simple_noad, noad)
512 init_node_key(node_data, radical_noad, radical)
513 init_node_key(node_data, fraction_noad, fraction)
514 init_node_key(node_data, accent_noad, accent)
515 init_node_key(node_data, fence_noad, fence)
516 init_node_key(node_data, math_char_node, math_char)
517 init_node_key(node_data, sub_box_node, sub_box)
518 init_node_key(node_data, sub_mlist_node, sub_mlist)
519 init_node_key(node_data, math_text_char_node, math_text_char)
520 init_node_key(node_data, delim_node, delim)
521 init_node_key(node_data, margin_kern_node, margin_kern)
522 init_node_key(node_data, glyph_node, glyph)
523 init_node_key(node_data, align_record_node, align_record)
524 init_node_key(node_data, pseudo_file_node, pseudo_file)
525 init_node_key(node_data, pseudo_line_node, pseudo_line)
526 init_node_key(node_data, inserting_node, page_insert)
527 init_node_key(node_data, split_up_node, split_insert)
528 init_node_key(node_data, expr_node, expr_stack)
529 init_node_key(node_data, nesting_node, nested_list)
530 init_node_key(node_data, span_node, span)
531 init_node_key(node_data, attribute_node, attribute)
532 init_node_key(node_data, glue_spec_node, glue_spec)
533 init_node_key(node_data, attribute_list_node, attribute_list)
534 init_node_key(node_data, temp_node, temp)
535 init_node_key(node_data, align_stack_node, align_stack)
536 init_node_key(node_data, movement_node, movement_stack)
537 init_node_key(node_data, if_node, if_stack)
538 init_node_key(node_data, unhyphenated_node, unhyphenated)
539 init_node_key(node_data, hyphenated_node, hyphenated)
540 init_node_key(node_data, delta_node, delta)
541 init_node_key(node_data, passive_node, passive)
542 init_node_key(node_data, shape_node, shape)
543
544 init_node_key(node_subtypes_dir, normal_dir, normal)
545 init_node_key(node_subtypes_dir, cancel_dir, cancel)
546
547 init_node_key(node_subtypes_glue, user_skip_glue, userskip)
548 init_node_key(node_subtypes_glue, line_skip_glue, lineskip)
549 init_node_key(node_subtypes_glue, baseline_skip_glue, baselineskip)
550 init_node_key(node_subtypes_glue, par_skip_glue, parskip)
551 init_node_key(node_subtypes_glue, above_display_skip_glue, abovedisplayskip)
552 init_node_key(node_subtypes_glue, below_display_skip_glue, belowdisplayskip)
553 init_node_key(node_subtypes_glue, above_display_short_skip_glue, abovedisplayshortskip)
554 init_node_key(node_subtypes_glue, below_display_short_skip_glue, belowdisplayshortskip)
555 init_node_key(node_subtypes_glue, left_skip_glue, leftskip)
556 init_node_key(node_subtypes_glue, right_skip_glue, rightskip)
557 init_node_key(node_subtypes_glue, top_skip_glue, topskip)
558 init_node_key(node_subtypes_glue, split_top_skip_glue, splittopskip)
559 init_node_key(node_subtypes_glue, tab_skip_glue, tabskip)
560 init_node_key(node_subtypes_glue, space_skip_glue, spaceskip)
561 init_node_key(node_subtypes_glue, xspace_skip_glue, xspaceskip)
562 init_node_key(node_subtypes_glue, par_fill_skip_glue, parfillskip)
563 init_node_key(node_subtypes_glue, math_skip_glue, mathskip)
564 init_node_key(node_subtypes_glue, thin_mu_skip_glue, thinmuskip)
565 init_node_key(node_subtypes_glue, med_mu_skip_glue, medmuskip)
566 init_node_key(node_subtypes_glue, thick_mu_skip_glue, thickmuskip)
567 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 1, conditionalmathskip)
568 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 2, muglue)
569 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 3, leaders)
570 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 4, cleaders)
571 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 5, xleaders)
572 init_node_key(node_subtypes_glue, thick_mu_skip_glue + 6, gleaders)
573
574 init_node_key(node_subtypes_mathglue, 0, conditionalmathskip)
575 init_node_key(node_subtypes_mathglue, 1, muglue)
576
577 init_node_key(node_subtypes_leader, 0, leaders)
578 init_node_key(node_subtypes_leader, 1, cleaders)
579 init_node_key(node_subtypes_leader, 2, xleaders)
580 init_node_key(node_subtypes_leader, 3, gleaders)
581
582 init_node_key(node_subtypes_boundary, cancel_boundary, cancel)
583 init_node_key(node_subtypes_boundary, user_boundary, user)
584 init_node_key(node_subtypes_boundary, protrusion_boundary, protrusion)
585 init_node_key(node_subtypes_boundary, word_boundary, word)
586
587 init_node_key(node_subtypes_penalty, user_penalty, userpenalty)
588 init_node_key(node_subtypes_penalty, linebreak_penalty, linebreakpenalty)
589 init_node_key(node_subtypes_penalty, line_penalty, linepenalty)
590 init_node_key(node_subtypes_penalty, word_penalty, wordpenalty)
591 init_node_key(node_subtypes_penalty, final_penalty, finalpenalty)
592 init_node_key(node_subtypes_penalty, noad_penalty, noadpenalty)
593 init_node_key(node_subtypes_penalty, before_display_penalty, beforedisplaypenalty)
594 init_node_key(node_subtypes_penalty, after_display_penalty, afterdisplaypenalty)
595 init_node_key(node_subtypes_penalty, equation_number_penalty, equationnumberpenalty)
596
597 init_node_key(node_subtypes_kern, font_kern, fontkern)
598 init_node_key(node_subtypes_kern, explicit_kern, userkern)
599 init_node_key(node_subtypes_kern, accent_kern, accentkern)
600 init_node_key(node_subtypes_kern, italic_kern, italiccorrection)
601
602 init_node_key(node_subtypes_rule, normal_rule, normal)
603 init_node_key(node_subtypes_rule, box_rule, box)
604 init_node_key(node_subtypes_rule, image_rule, image)
605 init_node_key(node_subtypes_rule, empty_rule, empty)
606 init_node_key(node_subtypes_rule, user_rule, user)
607 init_node_key(node_subtypes_rule, math_over_rule, over)
608 init_node_key(node_subtypes_rule, math_under_rule, under)
609 init_node_key(node_subtypes_rule, math_fraction_rule, fraction)
610 init_node_key(node_subtypes_rule, math_radical_rule, radical)
611 init_node_key(node_subtypes_rule, outline_rule, outline)
612
613 init_node_key(node_subtypes_glyph, 0, unset)
614 init_node_key(node_subtypes_glyph, 1, character)
615 init_node_key(node_subtypes_glyph, 2, ligature)
616 init_node_key(node_subtypes_glyph, 3, ghost)
617 init_node_key(node_subtypes_glyph, 4, left)
618 init_node_key(node_subtypes_glyph, 5, right)
619
620 init_node_key(node_subtypes_disc, discretionary_disc, discretionary)
621 init_node_key(node_subtypes_disc, explicit_disc, explicit)
622 init_node_key(node_subtypes_disc, automatic_disc, automatic)
623 init_node_key(node_subtypes_disc, syllable_disc, regular)
624 init_node_key(node_subtypes_disc, init_disc, first)
625 init_node_key(node_subtypes_disc, select_disc, second)
626
627 init_node_key(node_subtypes_fence, unset_noad_side, unset)
628 init_node_key(node_subtypes_fence, left_noad_side, left)
629 init_node_key(node_subtypes_fence, middle_noad_side, middle)
630 init_node_key(node_subtypes_fence, right_noad_side, right)
631 init_node_key(node_subtypes_fence, no_noad_side, no)
632
633 init_node_key(node_subtypes_list, unknown_list, unknown)
634 init_node_key(node_subtypes_list, line_list, line)
635 init_node_key(node_subtypes_list, hbox_list, box)
636 init_node_key(node_subtypes_list, indent_list, indent)
637 init_node_key(node_subtypes_list, align_row_list, alignment)
638 init_node_key(node_subtypes_list, align_cell_list, cell)
639 init_node_key(node_subtypes_list, equation_list, equation)
640 init_node_key(node_subtypes_list, equation_number_list, equationnumber)
641 init_node_key(node_subtypes_list, math_list_list, math)
642 init_node_key(node_subtypes_list, math_char_list, mathchar)
643 init_node_key(node_subtypes_list, math_h_extensible_list, hextensible)
644 init_node_key(node_subtypes_list, math_v_extensible_list, vextensible)
645 init_node_key(node_subtypes_list, math_h_delimiter_list, hdelimiter)
646 init_node_key(node_subtypes_list, math_v_delimiter_list, vdelimiter)
647 init_node_key(node_subtypes_list, math_over_delimiter_list, overdelimiter)
648 init_node_key(node_subtypes_list, math_under_delimiter_list, underdelimiter)
649 init_node_key(node_subtypes_list, math_numerator_list, numerator)
650 init_node_key(node_subtypes_list, math_denominator_list, denominator)
651 init_node_key(node_subtypes_list, math_limits_list, limits)
652 init_node_key(node_subtypes_list, math_fraction_list, fraction)
653 init_node_key(node_subtypes_list, math_nucleus_list, nucleus)
654 init_node_key(node_subtypes_list, math_sup_list, sup)
655 init_node_key(node_subtypes_list, math_sub_list, sub)
656 init_node_key(node_subtypes_list, math_degree_list, degree)
657 init_node_key(node_subtypes_list, math_scripts_list, scripts)
658 init_node_key(node_subtypes_list, math_over_list, over)
659 init_node_key(node_subtypes_list, math_under_list, under)
660 init_node_key(node_subtypes_list, math_accent_list, accent)
661 init_node_key(node_subtypes_list, math_radical_list, radical)
662
663 init_node_key(node_subtypes_math, before, beginmath)
664 init_node_key(node_subtypes_math, after, endmath)
665
666 init_node_key(node_subtypes_marginkern, left_side, left)
667 init_node_key(node_subtypes_marginkern, right_side, right)
668
669 init_node_key(node_subtypes_adjust, 0, normal)
670 init_node_key(node_subtypes_adjust, 1, pre)
671
672 init_node_key(node_subtypes_noad, ord_noad_type, ord)
673 init_node_key(node_subtypes_noad, op_noad_type_normal, opdisplaylimits)
674 init_node_key(node_subtypes_noad, op_noad_type_limits, oplimits)
675 init_node_key(node_subtypes_noad, op_noad_type_no_limits, opnolimits)
676 init_node_key(node_subtypes_noad, bin_noad_type, bin)
677 init_node_key(node_subtypes_noad, rel_noad_type, rel)
678 init_node_key(node_subtypes_noad, open_noad_type, open)
679 init_node_key(node_subtypes_noad, close_noad_type, close)
680 init_node_key(node_subtypes_noad, punct_noad_type, punct)
681 init_node_key(node_subtypes_noad, inner_noad_type, inner)
682 init_node_key(node_subtypes_noad, under_noad_type, under)
683 init_node_key(node_subtypes_noad, over_noad_type, over)
684 init_node_key(node_subtypes_noad, vcenter_noad_type, vcenter)
685
686 init_node_key(node_subtypes_radical, radical_noad_type, radical)
687 init_node_key(node_subtypes_radical, uradical_noad_type, uradical)
688 init_node_key(node_subtypes_radical, uroot_noad_type, uroot)
689 init_node_key(node_subtypes_radical, uunderdelimiter_noad_type, uunderdelimiter)
690 init_node_key(node_subtypes_radical, uoverdelimiter_noad_type, uoverdelimiter)
691 init_node_key(node_subtypes_radical, udelimiterunder_noad_type, udelimiterunder)
692 init_node_key(node_subtypes_radical, udelimiterover_noad_type, udelimiterover)
693
694 init_node_key(node_subtypes_accent, bothflexible_accent, bothflexible)
695 init_node_key(node_subtypes_accent, fixedtop_accent, fixedtop)
696 init_node_key(node_subtypes_accent, fixedbottom_accent, fixedbottom)
697 init_node_key(node_subtypes_accent, fixedboth_accent, fixedboth)
698
699 init_node_key(node_values_fill, normal, normal)
700 init_node_key(node_values_fill, sfi, fi)
701 init_node_key(node_values_fill, fil, fil)
702 init_node_key(node_values_fill, fill, fill)
703 init_node_key(node_values_fill, filll, filll)
704
705 init_node_key(node_values_dir, 0, TLT)
706 init_node_key(node_values_dir, 1, TRT)
707 init_node_key(node_values_dir, 2, LTL)
708 init_node_key(node_values_dir, 3, RTT)
709
710 init_node_key(other_values_page_states, 0, empty)
711 init_node_key(other_values_page_states, 1, box_there)
712 init_node_key(other_values_page_states, 2, inserts_only)
713
714 init_field_key(node_fields_accent, 0, attr);
715 init_field_key(node_fields_accent, 1, nucleus);
716 init_field_key(node_fields_accent, 2, sub);
717 init_field_key(node_fields_accent, 3, sup);
718 init_field_key(node_fields_accent, 4, accent);
719 init_field_key(node_fields_accent, 5, bot_accent);
720 init_field_key(node_fields_accent, 6, top_accent);
721 init_field_key(node_fields_accent, 7, overlay_accent);
722 init_field_key(node_fields_accent, 8, fraction);
723 init_field_nop(node_fields_accent, 9);
724
725 init_field_key(node_fields_adjust, 0, attr);
726 init_field_key(node_fields_adjust, 1, head);
727 init_field_nop(node_fields_adjust, 2);
728
729 init_field_key(node_fields_attribute, 0, number);
730 init_field_key(node_fields_attribute, 1, value);
731 init_field_nop(node_fields_attribute, 2);
732
733 init_field_nop(node_fields_attribute_list,0);
734
735 init_field_key(node_fields_boundary, 0, attr);
736 init_field_key(node_fields_boundary, 1, value);
737 init_field_nop(node_fields_boundary, 2);
738
739 init_field_key(node_fields_choice, 0, attr);
740 init_field_key(node_fields_choice, 1, display);
741 init_field_key(node_fields_choice, 2, text);
742 init_field_key(node_fields_choice, 3, script);
743 init_field_key(node_fields_choice, 4, scriptscript);
744 init_field_nop(node_fields_choice, 5);
745
746 init_field_key(node_fields_delim, 0, attr);
747 init_field_key(node_fields_delim, 1, small_fam);
748 init_field_key(node_fields_delim, 2, small_char);
749 init_field_key(node_fields_delim, 3, large_fam);
750 init_field_key(node_fields_delim, 4, large_char);
751 init_field_nop(node_fields_delim, 5);
752
753 init_field_key(node_fields_dir, 0, attr);
754 init_field_key(node_fields_dir, 1, dir);
755 init_field_key(node_fields_dir, 2, level);
756 init_field_nop(node_fields_dir, 3);
757
758 init_field_key(node_fields_disc, 0, attr);
759 init_field_key(node_fields_disc, 1, pre);
760 init_field_key(node_fields_disc, 2, post);
761 init_field_key(node_fields_disc, 3, replace);
762 init_field_key(node_fields_disc, 4, penalty);
763 init_field_nop(node_fields_disc, 5);
764
765 init_field_key(node_fields_fence, 0, attr);
766 init_field_key(node_fields_fence, 1, delim);
767 init_field_key(node_fields_fence, 2, italic);
768 init_field_key(node_fields_fence, 3, height);
769 init_field_key(node_fields_fence, 4, depth);
770 init_field_key(node_fields_fence, 5, options);
771 init_field_key(node_fields_fence, 6, class);
772 init_field_nop(node_fields_fence, 7);
773
774 init_field_key(node_fields_fraction, 0, attr);
775 init_field_key(node_fields_fraction, 1, width);
776 init_field_key(node_fields_fraction, 2, num);
777 init_field_key(node_fields_fraction, 3, denom);
778 init_field_key(node_fields_fraction, 4, left);
779 init_field_key(node_fields_fraction, 5, right);
780 init_field_key(node_fields_fraction, 6, middle);
781 init_field_key(node_fields_fraction, 7, fam);
782 init_field_key(node_fields_fraction, 8, options);
783 init_field_nop(node_fields_fraction, 9);
784
785 init_field_key(node_fields_glue, 0, attr);
786 init_field_key(node_fields_glue, 1, leader);
787 init_field_key(node_fields_glue, 2, width);
788 init_field_key(node_fields_glue, 3, stretch);
789 init_field_key(node_fields_glue, 4, shrink);
790 init_field_key(node_fields_glue, 5, stretch_order);
791 init_field_key(node_fields_glue, 6, shrink_order);
792 init_field_nop(node_fields_glue, 7);
793
794 init_field_key(node_fields_glue_spec, 0, width);
795 init_field_key(node_fields_glue_spec, 1, stretch);
796 init_field_key(node_fields_glue_spec, 2, shrink);
797 init_field_key(node_fields_glue_spec, 3, stretch_order);
798 init_field_key(node_fields_glue_spec, 4, shrink_order);
799 init_field_nop(node_fields_glue_spec, 5);
800
801 init_field_key(node_fields_glyph, 0, attr);
802 init_field_key(node_fields_glyph, 1, char);
803 init_field_key(node_fields_glyph, 2, font);
804 init_field_key(node_fields_glyph, 3, lang);
805 init_field_key(node_fields_glyph, 4, left);
806 init_field_key(node_fields_glyph, 5, right);
807 init_field_key(node_fields_glyph, 6, uchyph);
808 init_field_key(node_fields_glyph, 7, components);
809 init_field_key(node_fields_glyph, 8, xoffset);
810 init_field_key(node_fields_glyph, 9, yoffset);
811 init_field_key(node_fields_glyph, 10, width);
812 init_field_key(node_fields_glyph, 11, height);
813 init_field_key(node_fields_glyph, 12, depth);
814 init_field_key(node_fields_glyph, 13, expansion_factor);
815 init_field_key(node_fields_glyph, 14, data);
816 init_field_nop(node_fields_glyph, 15);
817
818 init_field_key(node_fields_insert, 0, attr);
819 init_field_key(node_fields_insert, 1, cost);
820 init_field_key(node_fields_insert, 2, depth);
821 init_field_key(node_fields_insert, 3, height);
822 init_field_key(node_fields_insert, 4, spec);
823 init_field_key(node_fields_insert, 5, head);
824 init_field_nop(node_fields_insert, 6);
825
826 init_field_key(node_fields_inserting, 0, height);
827 init_field_key(node_fields_inserting, 1, last_ins_ptr);
828 init_field_key(node_fields_inserting, 2, best_ins_ptr);
829 init_field_key(node_fields_inserting, 3, width);
830 init_field_key(node_fields_inserting, 4, stretch);
831 init_field_key(node_fields_inserting, 5, shrink);
832 init_field_key(node_fields_inserting, 6, stretch_order);
833 init_field_key(node_fields_inserting, 7, shrink_order);
834 init_field_nop(node_fields_inserting, 8);
835
836 init_field_key(node_fields_kern, 0, attr);
837 init_field_key(node_fields_kern, 1, kern);
838 init_field_key(node_fields_kern, 2, expansion_factor);
839 init_field_nop(node_fields_kern, 3);
840
841 init_field_key(node_fields_list, 0, attr);
842 init_field_key(node_fields_list, 1, width);
843 init_field_key(node_fields_list, 2, depth);
844 init_field_key(node_fields_list, 3, height);
845 init_field_key(node_fields_list, 4, dir);
846 init_field_key(node_fields_list, 5, shift);
847 init_field_key(node_fields_list, 6, glue_order);
848 init_field_key(node_fields_list, 7, glue_sign);
849 init_field_key(node_fields_list, 8, glue_set);
850 init_field_key(node_fields_list, 9, head);
851 init_field_nop(node_fields_list, 10);
852
853 init_field_key(node_fields_local_par, 0, attr);
854 init_field_key(node_fields_local_par, 1, pen_inter);
855 init_field_key(node_fields_local_par, 2, pen_broken);
856 init_field_key(node_fields_local_par, 3, dir);
857 init_field_key(node_fields_local_par, 4, box_left);
858 init_field_key(node_fields_local_par, 5, box_left_width);
859 init_field_key(node_fields_local_par, 6, box_right);
860 init_field_key(node_fields_local_par, 7, box_right_width);
861 init_field_nop(node_fields_local_par, 8);
862
863 init_field_key(node_fields_margin_kern, 0, attr);
864 init_field_key(node_fields_margin_kern, 1, width);
865 init_field_key(node_fields_margin_kern, 2, glyph);
866 init_field_nop(node_fields_margin_kern, 3);
867
868 init_field_key(node_fields_mark, 0, attr);
869 init_field_key(node_fields_mark, 1, class);
870 init_field_key(node_fields_mark, 2, mark);
871 init_field_nop(node_fields_mark, 3);
872
873 init_field_key(node_fields_math, 0, attr);
874 init_field_key(node_fields_math, 1, surround);
875 init_field_key(node_fields_math, 2, width);
876 init_field_key(node_fields_math, 3, stretch);
877 init_field_key(node_fields_math, 4, shrink);
878 init_field_key(node_fields_math, 5, stretch_order);
879 init_field_key(node_fields_math, 6, shrink_order);
880 init_field_nop(node_fields_math, 7);
881
882 init_field_key(node_fields_math_char, 0, attr);
883 init_field_key(node_fields_math_char, 1, fam);
884 init_field_key(node_fields_math_char, 2, char);
885 init_field_nop(node_fields_math_char, 3);
886
887 init_field_key(node_fields_math_text_char, 0, attr);
888 init_field_key(node_fields_math_text_char, 1, fam);
889 init_field_key(node_fields_math_text_char, 2, char);
890 init_field_nop(node_fields_math_text_char, 3);
891
892 init_field_key(node_fields_noad, 0, attr);
893 init_field_key(node_fields_noad, 1, nucleus);
894 init_field_key(node_fields_noad, 2, sub);
895 init_field_key(node_fields_noad, 3, sup);
896 init_field_nop(node_fields_noad, 4);
897
898 init_field_key(node_fields_penalty, 0, attr);
899 init_field_key(node_fields_penalty, 1, penalty);
900 init_field_nop(node_fields_penalty, 2);
901
902 init_field_key(node_fields_radical, 0, attr);
903 init_field_key(node_fields_radical, 1, nucleus);
904 init_field_key(node_fields_radical, 2, sub);
905 init_field_key(node_fields_radical, 3, sup);
906 init_field_key(node_fields_radical, 4, left);
907 init_field_key(node_fields_radical, 5, degree);
908 init_field_key(node_fields_radical, 6, width);
909 init_field_key(node_fields_radical, 7, options);
910 init_field_nop(node_fields_radical, 8);
911
912 init_field_key(node_fields_rule, 0, attr);
913 init_field_key(node_fields_rule, 1, width);
914 init_field_key(node_fields_rule, 2, depth);
915 init_field_key(node_fields_rule, 3, height);
916 init_field_key(node_fields_rule, 4, dir);
917 init_field_key(node_fields_rule, 5, index);
918 init_field_key(node_fields_rule, 6, left);
919 init_field_key(node_fields_rule, 7, right);
920 init_field_nop(node_fields_rule, 8);
921
922 init_field_key(node_fields_splitup, 0, height);
923 init_field_key(node_fields_splitup, 1, last_ins_ptr);
924 init_field_key(node_fields_splitup, 2, best_ins_ptr);
925 init_field_key(node_fields_splitup, 3, broken_ptr);
926 init_field_key(node_fields_splitup, 4, broken_ins);
927 init_field_nop(node_fields_splitup, 5);
928
929 init_field_key(node_fields_style, 0, attr);
930 init_field_key(node_fields_style, 1, style);
931 init_field_nop(node_fields_style, 2);
932
933 init_field_key(node_fields_sub_box, 0, attr);
934 init_field_key(node_fields_sub_box, 1, head);
935 init_field_nop(node_fields_sub_box, 2);
936
937 init_field_key(node_fields_sub_mlist, 0, attr);
938 init_field_key(node_fields_sub_mlist, 1, head);
939 init_field_nop(node_fields_sub_mlist, 2);
940
941 init_field_key(node_fields_unset, 0, attr);
942 init_field_key(node_fields_unset, 1, width);
943 init_field_key(node_fields_unset, 2, depth);
944 init_field_key(node_fields_unset, 3, height);
945 init_field_key(node_fields_unset, 4, dir);
946 init_field_key(node_fields_unset, 5, shrink);
947 init_field_key(node_fields_unset, 6, glue_order);
948 init_field_key(node_fields_unset, 7, glue_sign);
949 init_field_key(node_fields_unset, 8, stretch);
950 init_field_key(node_fields_unset, 9, span);
951 init_field_key(node_fields_unset, 10, head);
952 init_field_nop(node_fields_unset, 11);
953
954 }
955
956 node_info whatsit_node_data[] = {
957
958 /*tex These are always there. The fake nodes are historical. */
959
960 { open_node, open_node_size, NULL, node_fields_whatsit_open, NULL, -1, 0 },
961 { write_node, write_node_size, NULL, node_fields_whatsit_write, NULL, -1, 0 },
962 { close_node, close_node_size, NULL, node_fields_whatsit_close, NULL, -1, 0 },
963 { special_node, special_node_size, NULL, node_fields_whatsit_special, NULL, -1, 0 },
964 { late_special_node, special_node_size, NULL, node_fields_whatsit_special, NULL, -1, 0 },
965 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
966 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
967 { save_pos_node, save_pos_node_size, NULL, node_fields_whatsit_save_pos, NULL, -1, 0 },
968 { late_lua_node, late_lua_node_size, NULL, node_fields_whatsit_late_lua, NULL, -1, 0 },
969 { user_defined_node, user_defined_node_size, NULL, node_fields_whatsit_user_defined, NULL, -1, 0 },
970 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
971 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
972 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
973 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
974 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
975 { fake_node, fake_node_size, NULL, NULL, NULL, -1, 0 },
976
977 /*tex Here starts the \DVI\ backend section, todo: a separate list. */
978
979 /*tex {\em There is nothing here.} */
980
981 /*tex Here starts the \PDF\ backend section, todo: a separate list. */
982
983 { pdf_literal_node, literal_node_size, NULL, node_fields_whatsit_pdf_literal, NULL, -1, 0 },
984 { pdf_late_literal_node, literal_node_size, NULL, node_fields_whatsit_pdf_literal, NULL, -1, 0 },
985 { pdf_refobj_node, pdf_refobj_node_size, NULL, node_fields_whatsit_pdf_refobj, NULL, -1, 0 },
986 { pdf_annot_node, pdf_annot_node_size, NULL, node_fields_whatsit_pdf_annot, NULL, -1, 0 },
987 { pdf_start_link_node, pdf_annot_node_size, NULL, node_fields_whatsit_pdf_start_link, NULL, -1, 0 },
988 { pdf_end_link_node, pdf_end_link_node_size, NULL, node_fields_whatsit_pdf_end_link, NULL, -1, 0 },
989 { pdf_dest_node, pdf_dest_node_size, NULL, node_fields_whatsit_pdf_dest, NULL, -1, 0 },
990 { pdf_action_node, pdf_action_size, NULL, node_fields_whatsit_pdf_action, NULL, -1, 0 },
991 { pdf_thread_node, pdf_thread_node_size, NULL, node_fields_whatsit_pdf_thread, NULL, -1, 0 },
992 { pdf_start_thread_node, pdf_thread_node_size, NULL, node_fields_whatsit_pdf_start_thread, NULL, -1, 0 },
993 { pdf_end_thread_node, pdf_end_thread_node_size, NULL, node_fields_whatsit_pdf_end_thread, NULL, -1, 0 },
994 { pdf_thread_data_node, pdf_thread_node_size, NULL, NULL, NULL, -1, 0 },
995 { pdf_link_data_node, pdf_annot_node_size, NULL, NULL, NULL, -1, 0 },
996 { pdf_colorstack_node, pdf_colorstack_node_size, NULL, node_fields_whatsit_pdf_colorstack, NULL, -1, 0 },
997 { pdf_setmatrix_node, pdf_setmatrix_node_size, NULL, node_fields_whatsit_pdf_setmatrix, NULL, -1, 0 },
998 { pdf_save_node, pdf_save_node_size, NULL, node_fields_whatsit_pdf_save, NULL, -1, 0 },
999 { pdf_restore_node, pdf_restore_node_size, NULL, node_fields_whatsit_pdf_restore, NULL, -1, 0 },
1000 { pdf_link_state_node, pdf_link_state_node_size, NULL, node_fields_whatsit_pdf_link_state, NULL, -1, 0 },
1001
1002 /*tex That's it. */
1003
1004 { -1, -1, NULL, NULL, NULL, -1, 0 },
1005
1006 };
1007
1008 void l_set_whatsit_data(void) {
1009 init_node_key(whatsit_node_data, open_node, open)
1010 init_node_key(whatsit_node_data, write_node, write)
1011 init_node_key(whatsit_node_data, close_node, close)
1012 init_node_key(whatsit_node_data, special_node, special)
1013 init_node_key(whatsit_node_data, late_special_node, late_special)
1014 init_node_key(whatsit_node_data, save_pos_node, save_pos)
1015 init_node_key(whatsit_node_data, late_lua_node, late_lua)
1016 init_node_key(whatsit_node_data, user_defined_node, user_defined)
1017
1018 init_field_key(node_fields_whatsit_close, 0, attr);
1019 init_field_key(node_fields_whatsit_close, 1, stream);
1020 init_field_nop(node_fields_whatsit_close, 2);
1021
1022 init_field_key(node_fields_whatsit_late_lua, 0, attr);
1023 init_field_key(node_fields_whatsit_late_lua, 1, reg);
1024 init_field_key(node_fields_whatsit_late_lua, 2, data);
1025 init_field_key(node_fields_whatsit_late_lua, 3, name);
1026 init_field_key(node_fields_whatsit_late_lua, 4, string);
1027 init_field_nop(node_fields_whatsit_late_lua, 5);
1028
1029 init_field_key(node_fields_whatsit_open, 0, attr);
1030 init_field_key(node_fields_whatsit_open, 1, stream);
1031 init_field_key(node_fields_whatsit_open, 2, name);
1032 init_field_key(node_fields_whatsit_open, 3, area);
1033 init_field_key(node_fields_whatsit_open, 4, ext);
1034 init_field_nop(node_fields_whatsit_open, 5);
1035
1036 init_field_key(node_fields_whatsit_save_pos, 0, attr);
1037 init_field_nop(node_fields_whatsit_save_pos, 1);
1038
1039 init_field_key(node_fields_whatsit_special, 0, attr);
1040 init_field_key(node_fields_whatsit_special, 1, data);
1041 init_field_nop(node_fields_whatsit_special, 2);
1042
1043 init_field_key(node_fields_whatsit_user_defined, 0, attr);
1044 init_field_key(node_fields_whatsit_user_defined, 1, user_id);
1045 init_field_key(node_fields_whatsit_user_defined, 2, type);
1046 init_field_key(node_fields_whatsit_user_defined, 3, value);
1047 init_field_nop(node_fields_whatsit_user_defined, 4);
1048
1049 init_field_key(node_fields_whatsit_write, 0, attr);
1050 init_field_key(node_fields_whatsit_write, 1, stream);
1051 init_field_key(node_fields_whatsit_write, 2, data);
1052 init_field_nop(node_fields_whatsit_write, 3);
1053
1054 init_node_key(whatsit_node_data, pdf_literal_node, pdf_literal)
1055 init_node_key(whatsit_node_data, pdf_late_literal_node,pdf_late_literal)
1056 init_node_key(whatsit_node_data, pdf_refobj_node, pdf_refobj)
1057 init_node_key(whatsit_node_data, pdf_annot_node, pdf_annot)
1058 init_node_key(whatsit_node_data, pdf_start_link_node, pdf_start_link)
1059 init_node_key(whatsit_node_data, pdf_end_link_node, pdf_end_link)
1060 init_node_key(whatsit_node_data, pdf_dest_node, pdf_dest)
1061 init_node_key(whatsit_node_data, pdf_action_node, pdf_action)
1062 init_node_key(whatsit_node_data, pdf_thread_node, pdf_thread)
1063 init_node_key(whatsit_node_data, pdf_start_thread_node,pdf_start_thread)
1064 init_node_key(whatsit_node_data, pdf_end_thread_node, pdf_end_thread)
1065 init_node_key(whatsit_node_data, pdf_thread_data_node, pdf_thread_data)
1066 init_node_key(whatsit_node_data, pdf_link_data_node, pdf_link_data)
1067 init_node_key(whatsit_node_data, pdf_colorstack_node, pdf_colorstack)
1068 init_node_key(whatsit_node_data, pdf_setmatrix_node, pdf_setmatrix)
1069 init_node_key(whatsit_node_data, pdf_save_node, pdf_save)
1070 init_node_key(whatsit_node_data, pdf_restore_node, pdf_restore)
1071 init_node_key(whatsit_node_data, pdf_link_state_node, pdf_link_state)
1072
1073 init_node_key(node_values_pdf_destination, 0, xyz)
1074 init_node_key(node_values_pdf_destination, 1, fit)
1075 init_node_key(node_values_pdf_destination, 2, fith)
1076 init_node_key(node_values_pdf_destination, 3, fitv)
1077 init_node_key(node_values_pdf_destination, 4, fitb)
1078 init_node_key(node_values_pdf_destination, 5, fitbh)
1079 init_node_key(node_values_pdf_destination, 6, fitbv)
1080 init_node_key(node_values_pdf_destination, 7, fitr)
1081
1082 init_node_key(node_values_pdf_literal, set_origin, origin)
1083 init_node_key(node_values_pdf_literal, direct_page, page)
1084 init_node_key(node_values_pdf_literal, direct_always, always)
1085 init_node_key(node_values_pdf_literal, direct_raw, raw)
1086 init_node_key(node_values_pdf_literal, direct_text, text)
1087 init_node_key(node_values_pdf_literal, direct_font, font)
1088 init_node_key(node_values_pdf_literal, scan_special, special)
1089
1090 init_node_key(node_values_pdf_action, 0, page)
1091 init_node_key(node_values_pdf_action, 1, goto)
1092 init_node_key(node_values_pdf_action, 2, thread)
1093 init_node_key(node_values_pdf_action, 3, user)
1094
1095 init_node_key(node_values_pdf_window, 0, unset)
1096 init_node_key(node_values_pdf_window, 1, new)
1097 init_node_key(node_values_pdf_window, 2, nonew)
1098
1099 init_node_key(node_values_color_stack, 0, set)
1100 init_node_key(node_values_color_stack, 1, push)
1101 init_node_key(node_values_color_stack, 2, pop)
1102 init_node_key(node_values_color_stack, 3, current)
1103
1104 init_field_key(node_fields_whatsit_pdf_action, 0, action_type);
1105 init_field_key(node_fields_whatsit_pdf_action, 1, named_id);
1106 init_field_key(node_fields_whatsit_pdf_action, 2, action_id);
1107 init_field_key(node_fields_whatsit_pdf_action, 3, file);
1108 init_field_key(node_fields_whatsit_pdf_action, 4, new_window);
1109 init_field_key(node_fields_whatsit_pdf_action, 5, data);
1110 init_field_key(node_fields_whatsit_pdf_action, 6, struct_id);
1111 init_field_nop(node_fields_whatsit_pdf_action, 7);
1112
1113 init_field_key(node_fields_whatsit_pdf_annot, 0, attr);
1114 init_field_key(node_fields_whatsit_pdf_annot, 1, width);
1115 init_field_key(node_fields_whatsit_pdf_annot, 2, depth);
1116 init_field_key(node_fields_whatsit_pdf_annot, 3, height);
1117 init_field_key(node_fields_whatsit_pdf_annot, 4, objnum);
1118 init_field_key(node_fields_whatsit_pdf_annot, 5, data);
1119 init_field_nop(node_fields_whatsit_pdf_annot, 6);
1120
1121 init_field_key(node_fields_whatsit_pdf_colorstack, 0, attr);
1122 init_field_key(node_fields_whatsit_pdf_colorstack, 1, stack);
1123 init_field_key(node_fields_whatsit_pdf_colorstack, 2, cmd);
1124 init_field_key(node_fields_whatsit_pdf_colorstack, 3, data);
1125 init_field_nop(node_fields_whatsit_pdf_colorstack, 4);
1126
1127 init_field_key(node_fields_whatsit_pdf_dest, 0, attr);
1128 init_field_key(node_fields_whatsit_pdf_dest, 1, width);
1129 init_field_key(node_fields_whatsit_pdf_dest, 2, depth);
1130 init_field_key(node_fields_whatsit_pdf_dest, 3, height);
1131 init_field_key(node_fields_whatsit_pdf_dest, 4, named_id);
1132 init_field_key(node_fields_whatsit_pdf_dest, 5, dest_id);
1133 init_field_key(node_fields_whatsit_pdf_dest, 6, dest_type);
1134 init_field_key(node_fields_whatsit_pdf_dest, 7, xyz_zoom);
1135 init_field_key(node_fields_whatsit_pdf_dest, 8, objnum);
1136 init_field_nop(node_fields_whatsit_pdf_dest, 9);
1137
1138 init_field_key(node_fields_whatsit_pdf_end_link, 0, attr);
1139 init_field_nop(node_fields_whatsit_pdf_end_link, 1);
1140
1141 init_field_key(node_fields_whatsit_pdf_link_state, 0, attr);
1142 init_field_key(node_fields_whatsit_pdf_link_state, 1, value);
1143 init_field_nop(node_fields_whatsit_pdf_link_state, 2);
1144
1145 init_field_key(node_fields_whatsit_pdf_end_thread, 0, attr);
1146 init_field_nop(node_fields_whatsit_pdf_end_thread, 1);
1147
1148 init_field_key(node_fields_whatsit_pdf_literal, 0, attr);
1149 init_field_key(node_fields_whatsit_pdf_literal, 1, mode);
1150 init_field_key(node_fields_whatsit_pdf_literal, 2, data);
1151 init_field_nop(node_fields_whatsit_pdf_literal, 3);
1152
1153 init_field_key(node_fields_whatsit_pdf_refobj, 0, attr);
1154 init_field_key(node_fields_whatsit_pdf_refobj, 1, objnum);
1155 init_field_nop(node_fields_whatsit_pdf_refobj, 2);
1156
1157 init_field_key(node_fields_whatsit_pdf_restore, 0, attr);
1158 init_field_nop(node_fields_whatsit_pdf_restore, 1);
1159
1160 init_field_key(node_fields_whatsit_pdf_save, 0, attr);
1161 init_field_nop(node_fields_whatsit_pdf_save, 1);
1162
1163 init_field_key(node_fields_whatsit_pdf_setmatrix, 0, attr);
1164 init_field_key(node_fields_whatsit_pdf_setmatrix, 1, data);
1165 init_field_nop(node_fields_whatsit_pdf_setmatrix, 2);
1166
1167 init_field_key(node_fields_whatsit_pdf_start_link, 0, attr);
1168 init_field_key(node_fields_whatsit_pdf_start_link, 1, width);
1169 init_field_key(node_fields_whatsit_pdf_start_link, 2, depth);
1170 init_field_key(node_fields_whatsit_pdf_start_link, 3, height);
1171 init_field_key(node_fields_whatsit_pdf_start_link, 4, objnum);
1172 init_field_key(node_fields_whatsit_pdf_start_link, 5, link_attr);
1173 init_field_key(node_fields_whatsit_pdf_start_link, 6, action);
1174 init_field_nop(node_fields_whatsit_pdf_start_link, 7);
1175
1176 init_field_key(node_fields_whatsit_pdf_start_thread, 0, attr);
1177 init_field_key(node_fields_whatsit_pdf_start_thread, 1, width);
1178 init_field_key(node_fields_whatsit_pdf_start_thread, 2, depth);
1179 init_field_key(node_fields_whatsit_pdf_start_thread, 3, height);
1180 init_field_key(node_fields_whatsit_pdf_start_thread, 4, named_id);
1181 init_field_key(node_fields_whatsit_pdf_start_thread, 5, thread_id);
1182 init_field_key(node_fields_whatsit_pdf_start_thread, 6, thread_attr);
1183 init_field_nop(node_fields_whatsit_pdf_start_thread, 7);
1184
1185 init_field_key(node_fields_whatsit_pdf_thread, 0, attr);
1186 init_field_key(node_fields_whatsit_pdf_thread, 1, width);
1187 init_field_key(node_fields_whatsit_pdf_thread, 2, depth);
1188 init_field_key(node_fields_whatsit_pdf_thread, 3, height);
1189 init_field_key(node_fields_whatsit_pdf_thread, 4, named_id);
1190 init_field_key(node_fields_whatsit_pdf_thread, 5, thread_id);
1191 init_field_key(node_fields_whatsit_pdf_thread, 6, thread_attr);
1192 init_field_nop(node_fields_whatsit_pdf_thread, 7);
1193
1194 }
1195
1196 #define last_whatsit_node pdf_restore_node
1197
1198 /*tex
1199
1200 When we copy a node list, there are several possibilities: we do the same as
1201 a new node, we copy the entry to the table in properties (a reference), we do
1202 a deep copy of a table in the properties, we create a new table and give it
1203 the original one as a metatable. After some experiments (that also included
1204 timing) with these scenarios I decided that a deep copy made no sense, nor
1205 did nilling. In the end both the shallow copy and the metatable variant were
1206 both ok, although the second one is slower. The most important aspect to keep
1207 in mind is that references to other nodes in properties no longer can be
1208 valid for that copy. We could use two tables (one unique and one shared) or
1209 metatables but that only complicates matters.
1210
1211 When defining a new node, we could already allocate a table but it is rather
1212 easy to do that at the lua end e.g. using a metatable __index method. That
1213 way it is under macro package control.
1214
1215 When deleting a node, we could keep the slot (e.g. setting it to false) but
1216 it could make memory consumption raise unneeded when we have temporary large
1217 node lists and after that only small lists.
1218
1219 So, in the end this is what we ended up with. For the record, I also
1220 experimented with the following:
1221
1222 \startitemize
1223
1224 \startitem
1225 Copy attributes to the properties so that we have fast access at the
1226 lua end: in the end the overhead is not compensated by speed and
1227 convenience, in fact, attributes are not that slow when it comes to
1228 accessing them.
1229 \stopitem
1230
1231 \startitem
1232 A bitset in the node but again the gain compared to attributes is
1233 neglectable and it also demands a pretty string agreement over what
1234 bit represents what, and this is unlikely to succeed in the tex
1235 community (I could use it for font handling, which is cross package,
1236 but decided that it doesn't pay off.
1237 \stopitem
1238
1239 \stopitemize
1240
1241 In case one wonders why properties make sense then, well, it is not so much
1242 speed that we gain, but more convenience: storing all kind of (temporary)
1243 data in attributes is no fun and this mechanism makes sure that properties
1244 are cleaned up when a node is freed. Also, the advantage of a more or less
1245 global properties table is that we stay at the lua end. An alternative is to
1246 store a reference in the node itself but that is complicated by the fact that
1247 the register has some limitations (no numeric keys) and we also don't want to
1248 mess with it too much.
1249
1250 */
1251
1252 int lua_properties_level = 0 ;
1253 int lua_properties_enabled = 0 ;
1254 int lua_properties_use_metatable = 0 ;
1255
1256 /*tex
1257
1258 We keep track of nesting so that we don't oveflow the stack, and, what is
1259 more important, don't keep resolving the registry index.
1260
1261 */
1262
1263 #define lua_properties_push do { \
1264 if (lua_properties_enabled) { \
1265 lua_properties_level = lua_properties_level + 1 ; \
1266 if (lua_properties_level == 1) { \
1267 lua_get_metatablelua_l(Luas,node_properties); \
1268 } \
1269 } \
1270 } while(0)
1271
1272 #define lua_properties_pop do { \
1273 if (lua_properties_enabled) { \
1274 if (lua_properties_level == 1) \
1275 lua_pop(Luas,1); \
1276 lua_properties_level = lua_properties_level - 1 ; \
1277 } \
1278 } while(0)
1279
1280 /*tex No setting is needed: */
1281
1282 #define lua_properties_set(target) do { \
1283 } while(0)
1284
1285 /*tex Resetting boils down to nilling. */
1286
1287 #define lua_properties_reset(target) do { \
1288 if (lua_properties_enabled) { \
1289 if (lua_properties_level == 0) { \
1290 lua_get_metatablelua_l(Luas,node_properties); \
1291 lua_pushnil(Luas); \
1292 lua_rawseti(Luas,-2,target); \
1293 lua_pop(Luas,1); \
1294 } else { \
1295 lua_pushnil(Luas); \
1296 lua_rawseti(Luas,-2,target); \
1297 } \
1298 } \
1299 } while(0)
1300
1301 /*tex
1302
1303 For a moment I considered supporting all kind of data types but in practice
1304 that makes no sense. So we stick to a cheap shallow copy with as option a
1305 metatable. BTW, a deep copy would look like this:
1306
1307 \starttyping
1308 static void copy_lua_table(lua_State* L, int index) {
1309 lua_newtable(L);
1310 lua_pushnil(L);
1311 while(lua_next(L, index-1) != 0) {
1312 lua_pushvalue(L, -2);
1313 lua_insert(L, -2);
1314 if (lua_type(L,-1)==LUA_TTABLE)
1315 copy_lua_table(L,-1);
1316 lua_settable(L, -4);
1317 }
1318 lua_pop(L,1);
1319 }
1320
1321 #define lua_properties_copy(target, source) do { \
1322 if (lua_properties_enabled) { \
1323 lua_pushinteger(Luas,source); \
1324 lua_rawget(Luas,-2); \
1325 if (lua_type(Luas,-1)==LUA_TTABLE) { \
1326 copy_lua_table(Luas,-1); \
1327 lua_pushinteger(Luas,target); \
1328 lua_insert(Luas,-2); \
1329 lua_rawset(Luas,-3); \
1330 } else { \
1331 lua_pop(Luas,1); \
1332 } \
1333 } \
1334 } while(0)
1335 \stoptyping
1336
1337 */
1338
1339 /*tex Isn't there a faster way to metatable? */
1340
1341 /*tex
1342
1343 \starttyping
1344 #define lua_properties_copy(target,source) do { \
1345 if (lua_properties_enabled) { \
1346 if (lua_properties_level == 0) { \
1347 lua_get_metatablelua_l(Luas,node_properties); \
1348 lua_rawgeti(Luas,-1,source); \
1349 if (lua_type(Luas,-1)==LUA_TTABLE) { \
1350 if (lua_properties_use_metatable) { \
1351 lua_newtable(Luas); \
1352 lua_insert(Luas,-2); \
1353 lua_setfield(Luas,-2,"__index"); \
1354 lua_newtable(Luas); \
1355 lua_insert(Luas,-2); \
1356 lua_setmetatable(Luas,-2); \
1357 } \
1358 lua_rawseti(Luas,-2,target); \
1359 } else { \
1360 lua_pop(Luas,1); \
1361 } \
1362 lua_pop(Luas,1); \
1363 } else { \
1364 lua_rawgeti(Luas,-1,source); \
1365 if (lua_type(Luas,-1)==LUA_TTABLE) { \
1366 if (lua_properties_use_metatable) { \
1367 lua_newtable(Luas); \
1368 lua_insert(Luas,-2); \
1369 lua_setfield(Luas,-2,"__index"); \
1370 lua_newtable(Luas); \
1371 lua_insert(Luas,-2); \
1372 lua_setmetatable(Luas,-2); \
1373 } \
1374 lua_rawseti(Luas,-2,target); \
1375 } else { \
1376 lua_pop(Luas,1); \
1377 } \
1378 } \
1379 } \
1380 } while(0)
1381 \stoptyping
1382
1383 */
1384
1385 /*tex
1386
1387 A simple testrun on many pages of dumb text shows 1% gain (of course it
1388 depends on how properties are used but some other tests confirm it).
1389
1390 */
1391
1392 #define lua_properties_copy(target,source) do { \
1393 if (lua_properties_enabled) { \
1394 if (lua_properties_level == 0) { \
1395 lua_get_metatablelua_l(Luas,node_properties); \
1396 lua_rawgeti(Luas,-1,source); \
1397 if (lua_type(Luas,-1)==LUA_TTABLE) { \
1398 if (lua_properties_use_metatable) { \
1399 lua_newtable(Luas); \
1400 lua_insert(Luas,-2); \
1401 lua_push_string_by_name(Luas,__index); \
1402 lua_insert(Luas,-2); \
1403 lua_rawset(Luas, -3); \
1404 lua_newtable(Luas); \
1405 lua_insert(Luas,-2); \
1406 lua_setmetatable(Luas,-2); \
1407 } \
1408 lua_rawseti(Luas,-2,target); \
1409 } else { \
1410 lua_pop(Luas,1); \
1411 } \
1412 lua_pop(Luas,1); \
1413 } else { \
1414 lua_rawgeti(Luas,-1,source); \
1415 if (lua_type(Luas,-1)==LUA_TTABLE) { \
1416 if (lua_properties_use_metatable) { \
1417 lua_newtable(Luas); \
1418 lua_insert(Luas,-2); \
1419 lua_push_string_by_name(Luas,__index); \
1420 lua_insert(Luas,-2); \
1421 lua_rawset(Luas, -3); \
1422 lua_newtable(Luas); \
1423 lua_insert(Luas,-2); \
1424 lua_setmetatable(Luas,-2); \
1425 } \
1426 lua_rawseti(Luas,-2,target); \
1427 } else { \
1428 lua_pop(Luas,1); \
1429 } \
1430 } \
1431 } \
1432 } while(0)
1433
1434 /*tex Here end the property handlers. */
1435
1436 int valid_node(halfword p)
1437 {
1438 if (p > my_prealloc && p < var_mem_max) {
1439 if (varmem_sizes[p] > 0) {
1440 return 1;
1441 }
1442 }
1443 return 0;
1444 }
1445
1446 static int test_count = 1;
1447
1448 #define dorangetest(a,b,c) do { \
1449 if (!(b>=0 && b<c)) { \
1450 fprintf(stdout,"For node p:=%d, 0<=%d<%d (l.%d,r.%d)\n", \
1451 (int)a, (int)b, (int)c, __LINE__,test_count); \
1452 confusion("node range test failed"); \
1453 } } while (0)
1454
1455 #define dotest(a,b,c) do { \
1456 if (b!=c) { \
1457 fprintf(stdout,"For node p:=%d, %d==%d (l.%d,r.%d)\n", \
1458 (int)a, (int)b, (int)c, __LINE__,test_count); \
1459 confusion("node test failed"); \
1460 } } while (0)
1461
1462 #define check_action_ref(a) { dorangetest(p,a,var_mem_max); }
1463 #define check_attribute_ref(a) { dorangetest(p,a,var_mem_max); }
1464
1465 /*tex hm, we can just pass |p| then. */
1466
1467 #define check_token_ref(p) { \
1468 if (type(p) == whatsit_node) { \
1469 formatted_error("nodes","fuzzy token cleanup in whatsit node with type %s and subtype %i",node_data[type(p)].name,subtype(p)); \
1470 } else { \
1471 formatted_error("nodes","fuzzy token cleanup in node with type %s",node_data[type(p)].name); \
1472 } \
1473 }
1474
1475 static void check_static_node_mem(void)
1476 {
1477 dotest(zero_glue, width(zero_glue), 0);
1478 dotest(zero_glue, type(zero_glue), glue_spec_node);
1479 dotest(zero_glue, vlink(zero_glue), null);
1480 dotest(zero_glue, stretch(zero_glue), 0);
1481 dotest(zero_glue, stretch_order(zero_glue), normal);
1482 dotest(zero_glue, shrink(zero_glue), 0);
1483 dotest(zero_glue, shrink_order(zero_glue), normal);
1484
1485 dotest(sfi_glue, width(sfi_glue), 0);
1486 dotest(sfi_glue, type(sfi_glue), glue_spec_node);
1487 dotest(sfi_glue, vlink(sfi_glue), null);
1488 dotest(sfi_glue, stretch(sfi_glue), 0);
1489 dotest(sfi_glue, stretch_order(sfi_glue), sfi);
1490 dotest(sfi_glue, shrink(sfi_glue), 0);
1491 dotest(sfi_glue, shrink_order(sfi_glue), normal);
1492
1493 dotest(fil_glue, width(fil_glue), 0);
1494 dotest(fil_glue, type(fil_glue), glue_spec_node);
1495 dotest(fil_glue, vlink(fil_glue), null);
1496 dotest(fil_glue, stretch(fil_glue), unity);
1497 dotest(fil_glue, stretch_order(fil_glue), fil);
1498 dotest(fil_glue, shrink(fil_glue), 0);
1499 dotest(fil_glue, shrink_order(fil_glue), normal);
1500
1501 dotest(fill_glue, width(fill_glue), 0);
1502 dotest(fill_glue, type(fill_glue), glue_spec_node);
1503 dotest(fill_glue, vlink(fill_glue), null);
1504 dotest(fill_glue, stretch(fill_glue), unity);
1505 dotest(fill_glue, stretch_order(fill_glue), fill);
1506 dotest(fill_glue, shrink(fill_glue), 0);
1507 dotest(fill_glue, shrink_order(fill_glue), normal);
1508
1509 dotest(ss_glue, width(ss_glue), 0);
1510 dotest(ss_glue, type(ss_glue), glue_spec_node);
1511 dotest(ss_glue, vlink(ss_glue), null);
1512 dotest(ss_glue, stretch(ss_glue), unity);
1513 dotest(ss_glue, stretch_order(ss_glue), fil);
1514 dotest(ss_glue, shrink(ss_glue), unity);
1515 dotest(ss_glue, shrink_order(ss_glue), fil);
1516
1517 dotest(fil_neg_glue, width(fil_neg_glue), 0);
1518 dotest(fil_neg_glue, type(fil_neg_glue), glue_spec_node);
1519 dotest(fil_neg_glue, vlink(fil_neg_glue), null);
1520 dotest(fil_neg_glue, stretch(fil_neg_glue), -unity);
1521 dotest(fil_neg_glue, stretch_order(fil_neg_glue), fil);
1522 dotest(fil_neg_glue, shrink(fil_neg_glue), 0);
1523 dotest(fil_neg_glue, shrink_order(fil_neg_glue), normal);
1524 }
1525
1526 static void node_mem_dump(halfword p)
1527 {
1528 halfword r;
1529 for (r = my_prealloc + 1; r < var_mem_max; r++) {
1530 if (vlink(r) == p) {
1531 halfword s = r;
1532 while (s > my_prealloc && varmem_sizes[s] == 0) {
1533 s--;
1534 }
1535 if (s != null
1536 && s != my_prealloc
1537 && s != var_mem_max
1538 && (r - s) < get_node_size(type(s), subtype(s))
1539 && alink(s) != p) {
1540 if (type(s) == disc_node) {
1541 fprintf(stdout," pointed to from %s node %d (vlink %d, alink %d): ",
1542 get_node_name(type(s), subtype(s)), (int) s,
1543 (int) vlink(s), (int) alink(s));
1544 fprintf(stdout, "pre_break(%d,%d,%d), ",
1545 (int) vlink_pre_break(s), (int) tlink(pre_break(s)),
1546 (int) alink(pre_break(s)));
1547 fprintf(stdout, "post_break(%d,%d,%d), ",
1548 (int) vlink_post_break(s),
1549 (int) tlink(post_break(s)),
1550 (int) alink(post_break(s)));
1551 fprintf(stdout, "no_break(%d,%d,%d)",
1552 (int) vlink_no_break(s), (int) tlink(no_break(s)),
1553 (int) alink(no_break(s)));
1554 fprintf(stdout, "\n");
1555 } else {
1556 if (vlink(s) == p
1557 || (type(s) == glyph_node && lig_ptr (s) == p)
1558 || (type(s) == vlist_node && list_ptr(s) == p)
1559 || (type(s) == hlist_node && list_ptr(s) == p)
1560 || (type(s) == unset_node && list_ptr(s) == p)
1561 || (type(s) == ins_node && ins_ptr (s) == p)
1562 ) {
1563 fprintf(stdout," pointed to from %s node %d (vlink %d, alink %d): ",
1564 get_node_name(type(s), subtype(s)), (int) s,
1565 (int) vlink(s), (int) alink(s));
1566 if (type(s) == glyph_node) {
1567 fprintf(stdout, "lig_ptr(%d)", (int) lig_ptr(s));
1568 } else if (type(s) == vlist_node || type(s) == hlist_node) {
1569 fprintf(stdout, "list_ptr(%d)", (int) list_ptr(s));
1570 }
1571 fprintf(stdout, "\n");
1572 } else {
1573 if ((type(s) != penalty_node) && (type(s) != math_node) && (type(s) != kern_node)) {
1574 fprintf(stdout, " pointed to from %s node %d\n",
1575 get_node_name(type(s), subtype(s)), (int) s);
1576 }
1577 }
1578 }
1579 }
1580 }
1581 }
1582 }
1583
1584 static int free_error(halfword p)
1585 {
1586 if (p > my_prealloc && p < var_mem_max) {
1587 int i;
1588 if (varmem_sizes[p] == 0) {
1589 check_static_node_mem();
1590 for (i = (my_prealloc + 1); i < var_mem_max; i++) {
1591 if (varmem_sizes[i] > 0) {
1592 check_node(i);
1593 }
1594 }
1595 test_count++;
1596 if (type(p) == glyph_node) {
1597 formatted_error("nodes", "attempt to double-free glyph (%c) node %d, ignored", (int) character(p), (int) p);
1598 } else {
1599 formatted_error("nodes", "attempt to double-free %s node %d, ignored", get_node_name(type(p), subtype(p)), (int) p);
1600 }
1601 node_mem_dump(p);
1602 return 1;
1603 }
1604 } else {
1605 formatted_error("nodes", "attempt to free an impossible node %d", (int) p);
1606 return 1;
1607 }
1608 return 0;
1609 }
1610
1611 static int copy_error(halfword p)
1612 {
1613 if (p >= 0 && p < var_mem_max) {
1614 if (p > my_prealloc && varmem_sizes[p] == 0) {
1615 if (type(p) == glyph_node) {
1616 formatted_warning("nodes", "attempt to copy free glyph (%c) node %d, ignored", (int) character(p), (int) p);
1617 } else {
1618 formatted_warning("nodes", "attempt to copy free %s node %d, ignored", get_node_name(type(p), subtype(p)), (int) p);
1619 }
1620 return 1;
1621 }
1622 } else {
1623 formatted_error("nodes", "attempt to copy an impossible node %d", (int) p);
1624 return 1;
1625 }
1626 return 0;
1627 }
1628
1629 /*tex
1630
1631 Because of the 5-10\% overhead that \SYNTEX\ creates some options have been
1632 implemented controlled by |synctex_anyway_mode|.
1633
1634 \startabulate
1635 \NC \type {1} \NC all but glyphs \NC \NR
1636 \NC \type {2} \NC also glyphs \NC \NR
1637 \NC \type {3} \NC glyphs and glue \NC \NR
1638 \NC \type {4} \NC only glyphs \NC \NR
1639 \stoptabulate
1640
1641 */
1642
1643 static halfword synctex_anyway_mode = 0;
1644 static halfword synctex_line_field = 0;
1645 static halfword synctex_no_files = 0;
1646
1647 void synctex_set_mode(int m)
1648 {
1649 synctex_anyway_mode = m;
1650 }
1651
1652 int synctex_get_mode(void)
1653 {
1654 return synctex_anyway_mode;
1655 }
1656
1657 void synctex_set_no_files(int f)
1658 {
1659 synctex_no_files = f;
1660 }
1661
1662 int synctex_get_no_files(void)
1663 {
1664 return (int) synctex_no_files ;
1665 }
1666
1667 void synctex_set_tag(int t)
1668 {
1669 cur_input.synctex_tag_field = t;
1670 }
1671
1672 int synctex_get_tag(void)
1673 {
1674 return (int) cur_input.synctex_tag_field;
1675 }
1676
1677 int synctex_get_line(void)
1678 {
1679 return (int) synctex_line_field;
1680 }
1681
1682 static int forced_tag = 0;
1683 static int forced_line = 0;
1684
1685 void synctex_force_tag(int t)
1686 {
1687 forced_tag = t;
1688 }
1689
1690 void synctex_force_line(int t)
1691 {
1692 forced_line = t;
1693 }
1694
1695 void synctex_set_line(int l)
1696 {
1697 synctex_line_field = l;
1698 }
1699
1700 /*tex |if_stack| is called a lot so maybe optimize that one. */
1701
1702 halfword new_node(int i, int j)
1703 {
1704 int s = get_node_size(i, j);
1705 halfword n = get_node(s);
1706 /*tex
1707
1708 It should be possible to do this memset at |free_node()|. Both type() and
1709 subtype() will be set below, and vlink() is set to null by |get_node()|,
1710 so we can do we clearing one word less than |s|.
1711
1712 */
1713 (void) memset((void *) (varmem + n + 1), 0, (sizeof(memory_word) * ((unsigned) s - 1)));
1714 switch (i) {
1715 case glyph_node:
1716 init_lang_data(n);
1717 break;
1718 case hlist_node:
1719 case vlist_node:
1720 box_dir(n) = -1;
1721 break;
1722 case disc_node:
1723 pre_break(n) = pre_break_head(n);
1724 type(pre_break(n)) = nesting_node;
1725 subtype(pre_break(n)) = pre_break_head(0);
1726 post_break(n) = post_break_head(n);
1727 type(post_break(n)) = nesting_node;
1728 subtype(post_break(n)) = post_break_head(0);
1729 no_break(n) = no_break_head(n);
1730 type(no_break(n)) = nesting_node;
1731 subtype(no_break(n)) = no_break_head(0);
1732 break;
1733 case rule_node:
1734 depth(n) = null_flag;
1735 height(n) = null_flag;
1736 width(n) = null_flag;
1737 rule_dir(n) = -1;
1738 rule_index(n) = 0;
1739 rule_transform(n) = 0;
1740 break;
1741 case whatsit_node:
1742 if (j == open_node) {
1743 open_name(n) = get_nullstr();
1744 open_area(n) = open_name(n);
1745 open_ext(n) = open_name(n);
1746 }
1747 break;
1748 case unset_node:
1749 width(n) = null_flag;
1750 break;
1751 case pseudo_line_node:
1752 case shape_node:
1753 /*tex
1754
1755 This is a trick that makes |pseudo_files| slightly slower, but
1756 the overall allocation faster then an explicit test at the top of
1757 |new_node()|.
1758
1759 */
1760 if (j>0) {
1761 free_node(n, variable_node_size);
1762 n = slow_get_node(j);
1763 (void) memset((void *) (varmem + n + 1), 0, (sizeof(memory_word) * ((unsigned) j - 1)));
1764 }
1765 break;
1766 case fraction_noad:
1767 fraction_fam(n) = -1;
1768 break;
1769 case simple_noad:
1770 noad_fam(n) = -1;
1771 break;
1772 default:
1773 break;
1774 }
1775 if (synctex_anyway_mode) {
1776 /*tex See table above. */
1777 switch (i) {
1778 case glyph_node:
1779 if (synctex_anyway_mode > 1) {
1780 synctex_tag_glyph(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1781 synctex_line_glyph(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1782 }
1783 break;
1784 case glue_node:
1785 if (synctex_anyway_mode < 4) {
1786 synctex_tag_glue(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1787 synctex_line_glue(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1788 }
1789 break;
1790 case kern_node:
1791 if (synctex_anyway_mode < 3) {
1792 synctex_tag_kern(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1793 synctex_line_kern(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1794 }
1795 break;
1796 case hlist_node:
1797 case vlist_node:
1798 case unset_node:
1799 /*tex Rather useless: */
1800 if (synctex_anyway_mode < 3) {
1801 synctex_tag_box(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1802 synctex_line_box(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1803 }
1804 break;
1805 case rule_node:
1806 if (synctex_anyway_mode < 3) {
1807 synctex_tag_rule(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1808 synctex_line_rule(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1809 }
1810 break;
1811 case math_node:
1812 /*tex Noads probably make more sense but let's not change that. */
1813 if (synctex_anyway_mode < 3) {
1814 synctex_tag_math(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1815 synctex_line_math(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1816 }
1817 break;
1818 }
1819 } else if (synctex_par) {
1820 /*tex Handle the \SYNTEX\ extension. */
1821 switch (i) {
1822 case glue_node:
1823 synctex_tag_glue(n) = cur_input.synctex_tag_field;
1824 synctex_line_glue(n) = line;
1825 break;
1826 case kern_node:
1827 if (j != 0) {
1828 synctex_tag_kern(n) = cur_input.synctex_tag_field;
1829 synctex_line_kern(n) = line;
1830 }
1831 break;
1832 case hlist_node:
1833 case vlist_node:
1834 case unset_node:
1835 synctex_tag_box(n) = cur_input.synctex_tag_field;
1836 synctex_line_box(n) = line;
1837 break;
1838 case rule_node:
1839 synctex_tag_rule(n) = cur_input.synctex_tag_field;
1840 synctex_line_rule(n) = line;
1841 break;
1842 case math_node:
1843 synctex_tag_math(n) = cur_input.synctex_tag_field;
1844 synctex_line_math(n) = line;
1845 break;
1846 }
1847 }
1848 /*tex Take care of attributes. */
1849 if (nodetype_has_attributes(i)) {
1850 build_attribute_list(n);
1851 /*tex No need for |lua_properties_set|. */
1852 }
1853 type(n) = (quarterword) i;
1854 subtype(n) = (quarterword) j;
1855 return n;
1856 }
1857
1858 halfword raw_glyph_node(void)
1859 {
1860 register halfword n = get_node(glyph_node_size);
1861 (void) memset((void *) (varmem + n + 1), 0, (sizeof(memory_word) * (glyph_node_size - 1)));
1862 if (synctex_anyway_mode > 1) {
1863 synctex_tag_glyph(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1864 synctex_line_glyph(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1865 }
1866 type(n) = glyph_node;
1867 subtype(n) = 0;
1868 return n;
1869 }
1870
1871 halfword new_glyph_node(void)
1872 {
1873 register halfword n = get_node(glyph_node_size);
1874 (void) memset((void *) (varmem + n + 1), 0, (sizeof(memory_word) * (glyph_node_size - 1)));
1875 if (synctex_anyway_mode > 1) {
1876 synctex_tag_glyph(n) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
1877 synctex_line_glyph(n) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
1878 }
1879 type(n) = glyph_node;
1880 subtype(n) = 0;
1881 build_attribute_list(n);
1882 /*tex No need for |lua_properties_set|. */
1883 return n;
1884 }
1885
1886 /*tex
1887
1888 This makes a duplicate of the node list that starts at |p| and returns a
1889 pointer to the new list.
1890
1891 */
1892
1893 halfword do_copy_node_list(halfword p, halfword end)
1894 {
1895 /*tex previous position in new list */
1896 halfword q = null;
1897 /*tex head of the list */
1898 halfword h = null;
1899 register halfword s ;
1900 /*tex saves stack and time */
1901 lua_properties_push;
1902 while (p != end) {
1903 s = copy_node(p);
1904 if (h == null) {
1905 h = s;
1906 } else {
1907 couple_nodes(q, s);
1908 }
1909 q = s;
1910 p = vlink(p);
1911 }
1912 /*tex saves stack and time */
1913 lua_properties_pop;
1914 return h;
1915 }
1916
1917 halfword copy_node_list(halfword p)
1918 {
1919 return do_copy_node_list(p, null);
1920 }
1921
1922 #define copy_sub_list(target,source) do { \
1923 if (source != null) { \
1924 s = do_copy_node_list(source, null); \
1925 target = s; \
1926 } else { \
1927 target = null; \
1928 } \
1929 } while (0)
1930
1931 #define copy_sub_node(target,source) do { \
1932 if (source != null) { \
1933 s = copy_node(source); \
1934 target = s ; \
1935 } else { \
1936 target = null; \
1937 } \
1938 } while (0)
1939
1940 /*tex Make a dupe of a single node. */
1941
1942 static void copy_node_wrapup_core(halfword p, halfword r)
1943 {
1944 halfword s ;
1945 switch (subtype(p)) {
1946 case write_node:
1947 case special_node:
1948 case late_special_node:
1949 add_token_ref(write_tokens(p));
1950 break;
1951 case late_lua_node:
1952 copy_late_lua(r, p);
1953 break;
1954 case user_defined_node:
1955 switch (user_node_type(p)) {
1956 case 'a':
1957 add_node_attr_ref(user_node_value(p));
1958 break;
1959 case 'l':
1960 copy_user_lua(r, p);
1961 break;
1962 case 'n':
1963 s = copy_node_list(user_node_value(p));
1964 user_node_value(r) = s;
1965 break;
1966 case 's':
1967 /* |add_string_ref(user_node_value(p));| */
1968 break;
1969 case 't':
1970 add_token_ref(user_node_value(p));
1971 break;
1972 }
1973 break;
1974 default:
1975 break ;
1976 }
1977 }
1978
1979 void copy_node_wrapup_dvi(halfword p, halfword r)
1980 {
1981 }
1982
1983 void copy_node_wrapup_pdf(halfword p, halfword r)
1984 {
1985 switch(subtype(p)) {
1986 case pdf_literal_node:
1987 case pdf_late_literal_node:
1988 copy_pdf_literal(r, p);
1989 break;
1990 case pdf_colorstack_node:
1991 if (pdf_colorstack_cmd(p) <= colorstack_data)
1992 add_token_ref(pdf_colorstack_data(p));
1993 break;
1994 case pdf_setmatrix_node:
1995 add_token_ref(pdf_setmatrix_data(p));
1996 break;
1997 case pdf_annot_node:
1998 add_token_ref(pdf_annot_data(p));
1999 break;
2000 case pdf_start_link_node:
2001 if (pdf_link_attr(r) != null)
2002 add_token_ref(pdf_link_attr(r));
2003 add_action_ref(pdf_link_action(r));
2004 break;
2005 case pdf_dest_node:
2006 if (pdf_dest_named_id(p) > 0)
2007 add_token_ref(pdf_dest_id(p));
2008 break;
2009 case pdf_thread_node:
2010 case pdf_start_thread_node:
2011 if (pdf_thread_named_id(p) > 0)
2012 add_token_ref(pdf_thread_id(p));
2013 if (pdf_thread_attr(p) != null)
2014 add_token_ref(pdf_thread_attr(p));
2015 break;
2016 default:
2017 break;
2018 }
2019 }
2020
2021 static void check_disc(halfword p)
2022 {
2023 if (p != null) {
2024 if (vlink(p) != null) {
2025 tlink(p) = tail_of_list(vlink(p));
2026 } else {
2027 tlink(p) = null;
2028 }
2029 }
2030 }
2031
2032 halfword copy_node(const halfword p)
2033 {
2034 /*tex current node being fabricated for new list */
2035 halfword r;
2036 /*tex whatsit subtype */
2037 halfword w;
2038 /*tex type of node */
2039 halfword t;
2040 /*tex a helper variable for copying into variable mem */
2041 register halfword s;
2042 register int i;
2043 if (copy_error(p)) {
2044 r = new_node(temp_node, 0);
2045 return r;
2046 }
2047 t = type(p);
2048 i = get_node_size(t,subtype(p));
2049 r = get_node(i);
2050 (void) memcpy((void *) (varmem + r), (void *) (varmem + p), (sizeof(memory_word) * (unsigned) i));
2051 /*tex A possible speedup:
2052
2053 \starttyping
2054 if t == glue_spec) {
2055 return r;
2056 }
2057 \stoptyping
2058
2059 */
2060 if (synctex_anyway_mode) {
2061 /*tex Not:
2062
2063 \starttyping
2064 if (t == glyph_node) {
2065 if (synctex_anyway_mode > 1) {
2066 synctex_tag_glyph(r) = forced_tag ? forced_tag : cur_input.synctex_tag_field;
2067 synctex_line_glyph(r) = forced_line ? forced_line : synctex_line_field ? synctex_line_field : line;
2068 }
2069 }
2070 \stoptyping
2071 */
2072 } else if (synctex_par) {
2073 /*tex Handle synctex extension. */
2074 switch (t) {
2075 case math_node:
2076 synctex_tag_math(r) = cur_input.synctex_tag_field;
2077 synctex_line_math(r) = line;
2078 break;
2079 case kern_node:
2080 synctex_tag_kern(r) = cur_input.synctex_tag_field;
2081 synctex_line_kern(r) = line;
2082 break;
2083 }
2084 }
2085 if (nodetype_has_attributes(t)) {
2086 add_node_attr_ref(node_attr(p));
2087 alink(r) = null;
2088 lua_properties_copy(r,p);
2089 }
2090 vlink(r) = null;
2091 switch (t) {
2092 case glyph_node:
2093 copy_sub_list(lig_ptr(r),lig_ptr(p)) ;
2094 break;
2095 case glue_node:
2096 copy_sub_list(leader_ptr(r),leader_ptr(p)) ;
2097 break;
2098 case hlist_node:
2099 case vlist_node:
2100 case unset_node:
2101 copy_sub_list(list_ptr(r),list_ptr(p)) ;
2102 break;
2103 case disc_node:
2104 pre_break(r) = pre_break_head(r);
2105 post_break(r) = post_break_head(r);
2106 no_break(r) = no_break_head(r);
2107 if (vlink(pre_break(p)) != null) {
2108 s = copy_node_list(vlink(pre_break(p)));
2109 vlink(pre_break(r)) = s;
2110 check_disc(pre_break(r));
2111 }
2112 if (vlink(post_break(p)) != null) {
2113 s = copy_node_list(vlink(post_break(p)));
2114 vlink(post_break(r)) = s;
2115 check_disc(post_break(r));
2116 }
2117 if (vlink(no_break(p)) != null) {
2118 s = copy_node_list(vlink(no_break(p)));
2119 vlink(no_break(r)) = s;
2120 check_disc(no_break(r));
2121 }
2122 break;
2123 case math_node:
2124 break;
2125 case ins_node:
2126 copy_sub_list(ins_ptr(r),ins_ptr(p)) ;
2127 break;
2128 case margin_kern_node:
2129 copy_sub_node(margin_char(r),margin_char(p));
2130 break;
2131 case mark_node:
2132 add_token_ref(mark_ptr(p));
2133 break;
2134 case adjust_node:
2135 copy_sub_list(adjust_ptr(r),adjust_ptr(p));
2136 break;
2137 case choice_node:
2138 copy_sub_list(display_mlist(r),display_mlist(p)) ;
2139 copy_sub_list(text_mlist(r),text_mlist(p)) ;
2140 copy_sub_list(script_mlist(r),script_mlist(p)) ;
2141 copy_sub_list(script_script_mlist(r),script_script_mlist(p)) ;
2142 break;
2143 case simple_noad:
2144 copy_sub_list(nucleus(r),nucleus(p)) ;
2145 copy_sub_list(subscr(r),subscr(p)) ;
2146 copy_sub_list(supscr(r),supscr(p)) ;
2147 break;
2148 case radical_noad:
2149 copy_sub_list(nucleus(r),nucleus(p)) ;
2150 copy_sub_list(subscr(r),subscr(p)) ;
2151 copy_sub_list(supscr(r),supscr(p)) ;
2152 copy_sub_node(left_delimiter(r),left_delimiter(p)) ;
2153 copy_sub_list(degree(r),degree(p)) ;
2154 break;
2155 case accent_noad:
2156 copy_sub_list(nucleus(r),nucleus(p)) ;
2157 copy_sub_list(subscr(r),subscr(p)) ;
2158 copy_sub_list(supscr(r),supscr(p)) ;
2159 copy_sub_list(top_accent_chr(r),top_accent_chr(p)) ;
2160 copy_sub_list(bot_accent_chr(r),bot_accent_chr(p)) ;
2161 copy_sub_list(overlay_accent_chr(r),overlay_accent_chr(p)) ;
2162 break;
2163 case fence_noad:
2164 copy_sub_node(delimiter(r),delimiter(p)) ;
2165 break;
2166 case sub_box_node:
2167 case sub_mlist_node:
2168 copy_sub_list(math_list(r),math_list(p)) ;
2169 break;
2170 case fraction_noad:
2171 copy_sub_list(numerator(r),numerator(p)) ;
2172 copy_sub_list(denominator(r),denominator(p)) ;
2173 copy_sub_node(left_delimiter(r),left_delimiter(p)) ;
2174 copy_sub_node(right_delimiter(r),right_delimiter(p)) ;
2175 break;
2176 case glue_spec_node:
2177 break;
2178 case dir_node:
2179 break;
2180 case local_par_node:
2181 copy_sub_list(local_box_left(r),local_box_left(p));
2182 copy_sub_list(local_box_right(r),local_box_right(p));
2183 case boundary_node:
2184 break;
2185 case whatsit_node:
2186 w = subtype(p) ;
2187 if (w >= backend_first_pdf_whatsit) {
2188 copy_node_wrapup_pdf(p,r);
2189 } else if (w >= backend_first_dvi_whatsit) {
2190 copy_node_wrapup_dvi(p,r);
2191 } else {
2192 copy_node_wrapup_core(p,r);
2193 }
2194 break;
2195 }
2196 return r;
2197 }
2198
2199 #define free_sub_list(source) if (source != null) flush_node_list(source);
2200 #define free_sub_node(source) if (source != null) flush_node(source);
2201
2202 static void flush_node_wrapup_core(halfword p)
2203 {
2204 switch (subtype(p)) {
2205 case open_node:
2206 case close_node:
2207 case save_pos_node:
2208 break;
2209 case write_node:
2210 /* Not similar to elsewhere, already flushed? */
2211 break;
2212 case special_node:
2213 case late_special_node:
2214 delete_token_ref(special_tokens(p));
2215 break;
2216 case late_lua_node:
2217 free_late_lua(p);
2218 break;
2219 case user_defined_node:
2220 switch (user_node_type(p)) {
2221 case 'a':
2222 delete_attribute_ref(user_node_value(p));
2223 break;
2224 case 'd':
2225 break;
2226 case 'l':
2227 free_user_lua(p);
2228 break;
2229 case 'n':
2230 flush_node_list(user_node_value(p));
2231 break;
2232 case 's':
2233 /*tex |delete_string_ref(user_node_value(p));| *//* if this was mpost .. */
2234 break;
2235 case 't':
2236 delete_token_ref(user_node_value(p));
2237 break;
2238 default:
2239 {
2240 const char *hlp[] = {
2241 "The type of the value in a user defined whatsit node should be one",
2242 "of 'a' (attribute list), 'd' (number), 'n' (node list), 's' (string),",
2243 "or 't' (tokenlist). Yours has an unknown type, and therefore I don't",
2244 "know how to free the node's value. A memory leak may result.",
2245 NULL
2246 };
2247 tex_error("Unidentified user defined whatsit", hlp);
2248 }
2249 break;
2250 }
2251 break;
2252 }
2253 }
2254
2255 void flush_node_wrapup_dvi(halfword p)
2256 {
2257 }
2258
2259 void flush_node_wrapup_pdf(halfword p)
2260 {
2261 switch(subtype(p)) {
2262 case pdf_save_node:
2263 case pdf_restore_node:
2264 case pdf_link_state_node:
2265 case pdf_refobj_node:
2266 case pdf_end_link_node:
2267 case pdf_end_thread_node:
2268 break;
2269 case pdf_literal_node:
2270 case pdf_late_literal_node:
2271 free_pdf_literal(p);
2272 break;
2273 case pdf_colorstack_node:
2274 if (pdf_colorstack_cmd(p) <= colorstack_data)
2275 delete_token_ref(pdf_colorstack_data(p));
2276 break;
2277 case pdf_setmatrix_node:
2278 delete_token_ref(pdf_setmatrix_data(p));
2279 break;
2280 case pdf_annot_node:
2281 delete_token_ref(pdf_annot_data(p));
2282 break;
2283 case pdf_link_data_node:
2284 break;
2285 case pdf_start_link_node:
2286 if (pdf_link_attr(p) != null)
2287 delete_token_ref(pdf_link_attr(p));
2288 delete_action_ref(pdf_link_action(p));
2289 break;
2290 case pdf_dest_node:
2291 if (pdf_dest_named_id(p) > 0)
2292 delete_token_ref(pdf_dest_id(p));
2293 break;
2294 case pdf_action_node:
2295 if (pdf_action_type(p) == pdf_action_user) {
2296 delete_token_ref(pdf_action_tokens(p));
2297 } else {
2298 if (pdf_action_file(p) != null)
2299 delete_token_ref(pdf_action_file(p));
2300 if (pdf_action_type(p) == pdf_action_page)
2301 delete_token_ref(pdf_action_tokens(p));
2302 else if (pdf_action_named_id(p) & 1)
2303 delete_token_ref(pdf_action_id(p));
2304 if (pdf_action_named_id(p) & 2)
2305 delete_token_ref(pdf_action_struct_id(p));
2306 }
2307 break;
2308 case pdf_thread_data_node:
2309 break;
2310 case pdf_thread_node:
2311 case pdf_start_thread_node:
2312 if (pdf_thread_named_id(p) > 0)
2313 delete_token_ref(pdf_thread_id(p));
2314 if (pdf_thread_attr(p) != null)
2315 delete_token_ref(pdf_thread_attr(p));
2316 break;
2317 }
2318 }
2319
2320 void flush_node(halfword p)
2321 {
2322 halfword w;
2323 if (p == null){
2324 /*tex legal, but no-op. */
2325 return;
2326 }
2327 if (free_error(p))
2328 return;
2329 switch (type(p)) {
2330 case glyph_node:
2331 free_sub_list(lig_ptr(p));
2332 break;
2333 case glue_node:
2334 free_sub_list(leader_ptr(p));
2335 break;
2336 case hlist_node:
2337 case vlist_node:
2338 case unset_node:
2339 free_sub_list(list_ptr(p));
2340 break;
2341 case disc_node:
2342 /*tex Watch the start at temp node hack! */
2343 free_sub_list(vlink(pre_break(p)));
2344 free_sub_list(vlink(post_break(p)));
2345 free_sub_list(vlink(no_break(p)));
2346 break;
2347 case rule_node:
2348 case kern_node:
2349 case penalty_node:
2350 case math_node:
2351 break;
2352 case glue_spec_node:
2353 /*tex This allows free-ing of lua-allocated glue specs. */
2354 break ;
2355 case dir_node:
2356 break;
2357 case local_par_node:
2358 free_sub_list(local_box_left(p));
2359 free_sub_list(local_box_right(p));
2360 break;
2361 case boundary_node:
2362 break;
2363 case whatsit_node:
2364 w = subtype(p) ;
2365 if (w >= backend_first_pdf_whatsit) {
2366 flush_node_wrapup_pdf(p);
2367 } else if (w >= backend_first_dvi_whatsit) {
2368 flush_node_wrapup_dvi(p);
2369 } else {
2370 flush_node_wrapup_core(p);
2371 }
2372 break;
2373 case ins_node:
2374 flush_node_list(ins_ptr(p));
2375 break;
2376 case margin_kern_node:
2377 flush_node(margin_char(p));
2378 break;
2379 case mark_node:
2380 delete_token_ref(mark_ptr(p));
2381 break;
2382 case adjust_node:
2383 flush_node_list(adjust_ptr(p));
2384 break;
2385 case style_node:
2386 /*tex Nothing to do. */
2387 break;
2388 case choice_node:
2389 free_sub_list(display_mlist(p));
2390 free_sub_list(text_mlist(p));
2391 free_sub_list(script_mlist(p));
2392 free_sub_list(script_script_mlist(p));
2393 break;
2394 case simple_noad:
2395 free_sub_list(nucleus(p));
2396 free_sub_list(subscr(p));
2397 free_sub_list(supscr(p));
2398 break;
2399 case radical_noad:
2400 free_sub_list(nucleus(p));
2401 free_sub_list(subscr(p));
2402 free_sub_list(supscr(p));
2403 free_sub_node(left_delimiter(p));
2404 free_sub_list(degree(p));
2405 break;
2406 case accent_noad:
2407 free_sub_list(nucleus(p));
2408 free_sub_list(subscr(p));
2409 free_sub_list(supscr(p));
2410 free_sub_list(top_accent_chr(p));
2411 free_sub_list(bot_accent_chr(p));
2412 free_sub_list(overlay_accent_chr(p));
2413 break;
2414 case fence_noad:
2415 free_sub_list(delimiter(p));
2416 break;
2417 case delim_node:
2418 case math_char_node:
2419 case math_text_char_node:
2420 /*tex Nothing to do. */
2421 break;
2422 case sub_box_node:
2423 case sub_mlist_node:
2424 free_sub_list(math_list(p));
2425 break;
2426 case fraction_noad:
2427 free_sub_list(numerator(p));
2428 free_sub_list(denominator(p));
2429 free_sub_node(left_delimiter(p));
2430 free_sub_node(right_delimiter(p));
2431 break;
2432 case pseudo_file_node:
2433 free_sub_list(pseudo_lines(p));
2434 break;
2435 case pseudo_line_node:
2436 case shape_node:
2437 free_node(p, subtype(p));
2438 return;
2439 break;
2440 case align_stack_node:
2441 case span_node:
2442 case movement_node:
2443 case if_node:
2444 case nesting_node:
2445 case unhyphenated_node:
2446 case hyphenated_node:
2447 case delta_node:
2448 case passive_node:
2449 case inserting_node:
2450 case split_up_node:
2451 case expr_node:
2452 case attribute_node:
2453 case attribute_list_node:
2454 case temp_node:
2455 break;
2456 default:
2457 formatted_error("nodes","flushing weird node type %d", type(p));
2458 return;
2459 }
2460 if (nodetype_has_attributes(type(p))) {
2461 delete_attribute_ref(node_attr(p));
2462 lua_properties_reset(p);
2463 }
2464 free_node(p, get_node_size(type(p), subtype(p)));
2465 return;
2466 }
2467
2468 /*tex Erase the list of nodes starting at |pp|. */
2469
2470 void flush_node_list(halfword pp)
2471 {
2472 register halfword p = pp;
2473 if (p == null) {
2474 /*tex Legal, but no-op. */
2475 return;
2476 }
2477 if (free_error(p))
2478 return;
2479 /*tex Saves stack and time. */
2480 lua_properties_push;
2481 while (p != null) {
2482 register halfword q = vlink(p);
2483 flush_node(p);
2484 p = q;
2485 }
2486 /*tex Saves stack and time. */
2487 lua_properties_pop;
2488 }
2489
2490 static void check_node_wrapup_core(halfword p)
2491 {
2492 switch (subtype(p)) {
2493 /*tex Frontend code. */
2494 case special_node:
2495 case late_special_node:
2496 check_token_ref(p);
2497 break;
2498 case user_defined_node:
2499 switch (user_node_type(p)) {
2500 case 'a':
2501 check_attribute_ref(user_node_value(p));
2502 break;
2503 case 't':
2504 check_token_ref(p);
2505 break;
2506 case 'n':
2507 dorangetest(p, user_node_value(p), var_mem_max);
2508 break;
2509 case 's':
2510 case 'd':
2511 case 'l':
2512 break;
2513 default:
2514 confusion("unknown user node type");
2515 break;
2516 }
2517 break;
2518 case open_node:
2519 case write_node:
2520 case close_node:
2521 case save_pos_node:
2522 break;
2523 }
2524 }
2525
2526 void check_node_wrapup_dvi(halfword p)
2527 {
2528 }
2529
2530 void check_node_wrapup_pdf(halfword p)
2531 {
2532 switch (subtype(p)) {
2533 case pdf_literal_node:
2534 case pdf_late_literal_node:
2535 if (pdf_literal_type(p) == normal)
2536 check_token_ref(p);
2537 break;
2538 case pdf_colorstack_node:
2539 if (pdf_colorstack_cmd(p) <= colorstack_data)
2540 check_token_ref(p);
2541 break;
2542 case pdf_setmatrix_node:
2543 check_token_ref(p);
2544 break;
2545 case late_lua_node:
2546 if (late_lua_name(p) > 0)
2547 check_token_ref(p);
2548 if (late_lua_type(p) == normal)
2549 check_token_ref(p);
2550 break;
2551 case pdf_annot_node:
2552 check_token_ref(p);
2553 break;
2554 case pdf_start_link_node:
2555 if (pdf_link_attr(p) != null)
2556 check_token_ref(p);
2557 check_action_ref(pdf_link_action(p));
2558 break;
2559 case pdf_dest_node:
2560 if (pdf_dest_named_id(p) > 0)
2561 check_token_ref(p);
2562 break;
2563 case pdf_thread_node:
2564 case pdf_start_thread_node:
2565 if (pdf_thread_named_id(p) > 0)
2566 check_token_ref(p);
2567 if (pdf_thread_attr(p) != null)
2568 check_token_ref(p);
2569 break;
2570 case pdf_save_node:
2571 case pdf_restore_node:
2572 case pdf_link_state_node:
2573 case pdf_refobj_node:
2574 case pdf_end_link_node:
2575 case pdf_end_thread_node:
2576 break;
2577 default:
2578 confusion("wrapup pdf nodes");
2579 break;
2580 }
2581 }
2582
2583 void check_node(halfword p)
2584 {
2585 halfword w ;
2586 switch (type(p)) {
2587 case glyph_node:
2588 dorangetest(p, lig_ptr(p), var_mem_max);
2589 break;
2590 case glue_node:
2591 dorangetest(p, leader_ptr(p), var_mem_max);
2592 break;
2593 case hlist_node:
2594 case vlist_node:
2595 case unset_node:
2596 case align_record_node:
2597 dorangetest(p, list_ptr(p), var_mem_max);
2598 break;
2599 case ins_node:
2600 dorangetest(p, ins_ptr(p), var_mem_max);
2601 break;
2602 case whatsit_node:
2603 w = subtype(p) ;
2604 if (w >= backend_first_pdf_whatsit) {
2605 check_node_wrapup_pdf(p);
2606 } else if (w >= backend_first_dvi_whatsit) {
2607 check_node_wrapup_dvi(p);
2608 } else {
2609 check_node_wrapup_core(p);
2610 }
2611 break;
2612 case margin_kern_node:
2613 check_node(margin_char(p));
2614 break;
2615 case math_node:
2616 break;
2617 case disc_node:
2618 dorangetest(p, vlink(pre_break(p)), var_mem_max);
2619 dorangetest(p, vlink(post_break(p)), var_mem_max);
2620 dorangetest(p, vlink(no_break(p)), var_mem_max);
2621 break;
2622 case adjust_node:
2623 dorangetest(p, adjust_ptr(p), var_mem_max);
2624 break;
2625 case pseudo_file_node:
2626 dorangetest(p, pseudo_lines(p), var_mem_max);
2627 break;
2628 case pseudo_line_node:
2629 case shape_node:
2630 break;
2631 case choice_node:
2632 dorangetest(p, display_mlist(p), var_mem_max);
2633 dorangetest(p, text_mlist(p), var_mem_max);
2634 dorangetest(p, script_mlist(p), var_mem_max);
2635 dorangetest(p, script_script_mlist(p), var_mem_max);
2636 break;
2637 case fraction_noad:
2638 dorangetest(p, numerator(p), var_mem_max);
2639 dorangetest(p, denominator(p), var_mem_max);
2640 dorangetest(p, left_delimiter(p), var_mem_max);
2641 dorangetest(p, right_delimiter(p), var_mem_max);
2642 break;
2643 case simple_noad:
2644 dorangetest(p, nucleus(p), var_mem_max);
2645 dorangetest(p, subscr(p), var_mem_max);
2646 dorangetest(p, supscr(p), var_mem_max);
2647 break;
2648 case radical_noad:
2649 dorangetest(p, nucleus(p), var_mem_max);
2650 dorangetest(p, subscr(p), var_mem_max);
2651 dorangetest(p, supscr(p), var_mem_max);
2652 dorangetest(p, degree(p), var_mem_max);
2653 dorangetest(p, left_delimiter(p), var_mem_max);
2654 break;
2655 case accent_noad:
2656 dorangetest(p, nucleus(p), var_mem_max);
2657 dorangetest(p, subscr(p), var_mem_max);
2658 dorangetest(p, supscr(p), var_mem_max);
2659 dorangetest(p, top_accent_chr(p), var_mem_max);
2660 dorangetest(p, bot_accent_chr(p), var_mem_max);
2661 dorangetest(p, overlay_accent_chr(p), var_mem_max);
2662 break;
2663 case fence_noad:
2664 dorangetest(p, delimiter(p), var_mem_max);
2665 break;
2666 case local_par_node:
2667 dorangetest(p, local_box_left(p), var_mem_max);
2668 dorangetest(p, local_box_right(p), var_mem_max);
2669 break;
2670 /*tex
2671
2672 There is no need for useless cases:
2673
2674 \starttyping
2675 case rule_node:
2676 case kern_node:
2677 case penalty_node:
2678 case mark_node:
2679 case style_node:
2680 case attribute_list_node:
2681 case attribute_node:
2682 case glue_spec_node:
2683 case temp_node:
2684 case align_stack_node:
2685 case movement_node:
2686 case if_node:
2687 case nesting_node:
2688 case span_node:
2689 case unhyphenated_node:
2690 case hyphenated_node:
2691 case delta_node:
2692 case passive_node:
2693 case expr_node:
2694 case dir_node:
2695 case boundary_node:
2696 break;
2697 default:
2698 fprintf(stdout, "check_node: type is %d\n", type(p));
2699 \stoptyping
2700
2701 */
2702 }
2703 }
2704
2705 halfword fix_node_list(halfword head)
2706 {
2707 halfword next, tail;
2708 if (head == null)
2709 return null;
2710 tail = head;
2711 next = vlink(head);
2712 while (next != null) {
2713 alink(next) = tail;
2714 tail = next;
2715 next = vlink(tail);
2716 }
2717 return tail;
2718 }
2719
2720 halfword get_node(int s)
2721 {
2722 register halfword r;
2723
2724 if (s < MAX_CHAIN_SIZE) {
2725 r = free_chain[s];
2726 if (r != null) {
2727 free_chain[s] = vlink(r);
2728 varmem_sizes[r] = (char) s;
2729 vlink(r) = null;
2730 /*tex Maintain usage statistics. */
2731 var_used += s;
2732 return r;
2733 }
2734 /*tex This is the end of the \quote {inner loop}. */
2735 return slow_get_node(s);
2736 } else {
2737 normal_error("nodes","there is a problem in getting a node, case 1");
2738 return null;
2739 }
2740 }
2741
2742 void free_node(halfword p, int s)
2743 {
2744 if (p <= my_prealloc) {
2745 formatted_error("nodes", "node number %d of type %d should not be freed", (int) p, type(p));
2746 return;
2747 }
2748 varmem_sizes[p] = 0;
2749 if (s < MAX_CHAIN_SIZE) {
2750 vlink(p) = free_chain[s];
2751 free_chain[s] = p;
2752 } else {
2753 /*tex Todo: it is perhaps possible to merge this node with an existing rover? */
2754 node_size(p) = s;
2755 vlink(p) = rover;
2756 while (vlink(rover) != vlink(p)) {
2757 rover = vlink(rover);
2758 }
2759 vlink(rover) = p;
2760 }
2761 /*tex Maintain statistics. */
2762 var_used -= s;
2763 }
2764
2765 static void free_node_chain(halfword q, int s)
2766 {
2767 register halfword p = q;
2768 while (vlink(p) != null) {
2769 varmem_sizes[p] = 0;
2770 var_used -= s;
2771 p = vlink(p);
2772 }
2773 var_used -= s;
2774 varmem_sizes[p] = 0;
2775 vlink(p) = free_chain[s];
2776 free_chain[s] = q;
2777 }
2778
2779 /*tex
2780
2781 At the start of the node memory area we reserve some special nodes, for
2782 instance frequently used glue specifications. We could as well just use
2783 new_glue here but for the moment we stick to the traditional approach.
2784
2785 */
2786
2787 #define initialize_glue(n,wi,st,sh,sto,sho) \
2788 vlink(n) = null; \
2789 type(n) = glue_spec_node; \
2790 width(n) = wi; \
2791 stretch(n) = st; \
2792 shrink(n) = sh; \
2793 stretch_order(n) = sto; \
2794 shrink_order(n) = sho;
2795
2796 #define initialize_whatever(n,t) \
2797 vinfo(n) = 0; \
2798 type(n) = t; \
2799 vlink(n) = null; \
2800 alink(n) = null;
2801
2802 #define initialize_point(n) \
2803 type(n) = glyph_node; \
2804 subtype(n) = 0; \
2805 vlink(n) = null; \
2806 vinfo(n + 1) = null; \
2807 alink(n) = null; \
2808 font(n) = 0; \
2809 character(n) = '.'; \
2810 vinfo(n + 3) = 0; \
2811 vlink(n + 3) = 0; \
2812 vinfo(n + 4) = 0; \
2813 vlink(n + 4) = 0;
2814
2815 void init_node_mem(int t)
2816 {
2817 my_prealloc = var_mem_stat_max;
2818
2819 varmem = (memory_word *) realloc((void *) varmem, sizeof(memory_word) * (unsigned) t);
2820 if (varmem == NULL) {
2821 overflow("node memory size", (unsigned) var_mem_max);
2822 }
2823 memset((void *) (varmem), 0, (unsigned) t * sizeof(memory_word));
2824 varmem_sizes = (char *) realloc(varmem_sizes, sizeof(char) * (unsigned) t);
2825 if (varmem_sizes == NULL) {
2826 overflow("node memory size", (unsigned) var_mem_max);
2827 }
2828 memset((void *) varmem_sizes, 0, sizeof(char) * (unsigned) t);
2829 var_mem_max = t;
2830 rover = var_mem_stat_max + 1;
2831 vlink(rover) = rover;
2832 node_size(rover) = (t - rover);
2833 var_used = 0;
2834
2835 /*tex Initialize static glue specs. */
2836
2837 initialize_glue(zero_glue,0,0,0,0,0);
2838 initialize_glue(sfi_glue,0,0,0,sfi,0);
2839 initialize_glue(fil_glue,0,unity,0,fil,0);
2840 initialize_glue(fill_glue,0,unity,0,fill,0);
2841 initialize_glue(ss_glue,0,unity,unity,fil,fil);
2842 initialize_glue(fil_neg_glue,0,-unity,0,fil,0);
2843
2844 /*tex Initialize node list heads. */
2845
2846 initialize_whatever(page_ins_head,temp_node);
2847 initialize_whatever(contrib_head,temp_node);
2848 initialize_whatever(page_head,temp_node);
2849 initialize_whatever(temp_head,temp_node);
2850 initialize_whatever(hold_head,temp_node);
2851 initialize_whatever(adjust_head,temp_node);
2852 initialize_whatever(pre_adjust_head,temp_node);
2853 initialize_whatever(align_head,temp_node);
2854
2855 initialize_whatever(active,unhyphenated_node);
2856 initialize_whatever(end_span,span_node);
2857
2858 initialize_point(begin_point);
2859 initialize_point(end_point);
2860 }
2861
2862 void dump_node_mem(void)
2863 {
2864 dump_int(var_mem_max);
2865 dump_int(rover);
2866 dump_things(varmem[0], var_mem_max);
2867 dump_things(varmem_sizes[0], var_mem_max);
2868 dump_things(free_chain[0], MAX_CHAIN_SIZE);
2869 dump_int(var_used);
2870 dump_int(my_prealloc);
2871 }
2872
2873 /*tex
2874
2875 It makes sense to enlarge the varmem array immediately.
2876
2877 */
2878
2879 void undump_node_mem(void)
2880 {
2881 int x;
2882 undump_int(x);
2883 undump_int(rover);
2884 var_mem_max = (x < 100000 ? 100000 : x);
2885 varmem = xmallocarray(memory_word, (unsigned) var_mem_max);
2886 undump_things(varmem[0], x);
2887 varmem_sizes = xmallocarray(char, (unsigned) var_mem_max);
2888 memset((void *) varmem_sizes, 0, (unsigned) var_mem_max * sizeof(char));
2889 undump_things(varmem_sizes[0], x);
2890 undump_things(free_chain[0], MAX_CHAIN_SIZE);
2891 undump_int(var_used);
2892 undump_int(my_prealloc);
2893 if (var_mem_max > x) {
2894 /*tex Todo: is it perhaps possible to merge the new node with an existing rover? */
2895 vlink(x) = rover;
2896 node_size(x) = (var_mem_max - x);
2897 while (vlink(rover) != vlink(x)) {
2898 rover = vlink(rover);
2899 }
2900 vlink(rover) = x;
2901 }
2902 }
2903
2904 halfword slow_get_node(int s)
2905 {
2906 register int t;
2907
2908 RETRY:
2909 t = node_size(rover);
2910 if (vlink(rover) < var_mem_max && vlink(rover) != 0) {
2911 if (t > s) {
2912 /*tex Allocating from the bottom helps decrease page faults. */
2913 register halfword r = rover;
2914 rover += s;
2915 vlink(rover) = vlink(r);
2916 node_size(rover) = node_size(r) - s;
2917 if (vlink(rover) != r) {
2918 /*tex The list is longer than one. */
2919 halfword q = r;
2920 while (vlink(q) != r) {
2921 q = vlink(q);
2922 }
2923 vlink(q) += s;
2924 } else {
2925 vlink(rover) += s;
2926 }
2927 if (vlink(rover) < var_mem_max) {
2928 varmem_sizes[r] = (char) (s > 127 ? 127 : s);
2929 vlink(r) = null;
2930 /*tex Maintain usage statistics. */
2931 var_used += s;
2932 /*tex This is the only exit. */
2933 return r;
2934 } else {
2935 normal_error("nodes","there is a problem in getting a node, case 2");
2936 return null;
2937 }
2938 } else {
2939 /*tex Attempt to keep the free list small. */
2940 int x;
2941 if (vlink(rover) != rover) {
2942 if (t < MAX_CHAIN_SIZE) {
2943 halfword l = vlink(rover);
2944 vlink(rover) = free_chain[t];
2945 free_chain[t] = rover;
2946 rover = l;
2947 while (vlink(l) != free_chain[t]) {
2948 l = vlink(l);
2949 }
2950 vlink(l) = rover;
2951 goto RETRY;
2952 } else {
2953 halfword l = rover;
2954 while (vlink(rover) != l) {
2955 if (node_size(rover) > s) {
2956 goto RETRY;
2957 }
2958 rover = vlink(rover);
2959 }
2960 }
2961 }
2962 /*tex If we are still here, it was apparently impossible to get a match. */
2963 x = (var_mem_max >> 2) + s;
2964 varmem = (memory_word *) realloc((void *) varmem, sizeof(memory_word) * (unsigned) (var_mem_max + x));
2965 if (varmem == NULL) {
2966 overflow("node memory size", (unsigned) var_mem_max);
2967 }
2968 memset((void *) (varmem + var_mem_max), 0, (unsigned) x * sizeof(memory_word));
2969 varmem_sizes = (char *) realloc(varmem_sizes, sizeof(char) * (unsigned) (var_mem_max + x));
2970 if (varmem_sizes == NULL) {
2971 overflow("node memory size", (unsigned) var_mem_max);
2972 }
2973 memset((void *) (varmem_sizes + var_mem_max), 0, (unsigned) (x) * sizeof(char));
2974 /*tex Todo: is it perhaps possible to merge the new memory with an existing rover? */
2975 vlink(var_mem_max) = rover;
2976 node_size(var_mem_max) = x;
2977 while (vlink(rover) != vlink(var_mem_max)) {
2978 rover = vlink(rover);
2979 }
2980 vlink(rover) = var_mem_max;
2981 rover = var_mem_max;
2982 var_mem_max += x;
2983 goto RETRY;
2984 }
2985 } else {
2986 normal_error("nodes","there is a problem in getting a node, case 3");
2987 return null;
2988 }
2989 }
2990
2991 char *sprint_node_mem_usage(void)
2992 {
2993 char *s;
2994 char *ss;
2995 int i;
2996 int b = 0;
2997 char msg[256];
2998 int node_counts[last_normal_node + last_whatsit_node + 2] = { 0 };
2999 s = strdup("");
3000 for (i = (var_mem_max - 1); i > my_prealloc; i--) {
3001 if (varmem_sizes[i] > 0) {
3002 if (type(i) > last_normal_node + last_whatsit_node) {
3003 node_counts[last_normal_node + last_whatsit_node + 1]++;
3004 } else if (type(i) == whatsit_node) {
3005 node_counts[(subtype(i) + last_normal_node + 1)]++;
3006 } else {
3007 node_counts[type(i)]++;
3008 }
3009 }
3010 }
3011 for (i = 0; i < last_normal_node + last_whatsit_node + 2; i++) {
3012 if (node_counts[i] > 0) {
3013 int j =
3014 (i > (last_normal_node + 1) ? (i - last_normal_node - 1) : 0);
3015 snprintf(msg, 255, "%s%d %s", (b ? ", " : ""), (int) node_counts[i],
3016 get_node_name((i > last_normal_node ? whatsit_node : i), j));
3017 ss = xmalloc((unsigned) (strlen(s) + strlen(msg) + 1));
3018 strcpy(ss, s);
3019 strcat(ss, msg);
3020 free(s);
3021 s = ss;
3022 b = 1;
3023 }
3024 }
3025 return s;
3026 }
3027
3028 halfword list_node_mem_usage(void)
3029 {
3030 halfword q = null;
3031 halfword p = null;
3032 halfword i, j;
3033 char *saved_varmem_sizes = xmallocarray(char, (unsigned) var_mem_max);
3034 memcpy(saved_varmem_sizes, varmem_sizes, (size_t) var_mem_max);
3035 for (i = my_prealloc + 1; i < (var_mem_max - 1); i++) {
3036 if (saved_varmem_sizes[i] > 0) {
3037 j = copy_node(i);
3038 if (p == null) {
3039 q = j;
3040 } else {
3041 vlink(p) = j;
3042 }
3043 p = j;
3044 }
3045 }
3046 free(saved_varmem_sizes);
3047 return q;
3048 }
3049
3050 void print_node_mem_stats(void)
3051 {
3052 int i, b;
3053 halfword j;
3054 char msg[256];
3055 char *s;
3056 int free_chain_counts[MAX_CHAIN_SIZE] = { 0 };
3057 snprintf(msg, 255, " %d words of node memory still in use:", (int) (var_used + my_prealloc));
3058 tprint_nl(msg);
3059 s = sprint_node_mem_usage();
3060 tprint_nl(" ");
3061 tprint(s);
3062 free(s);
3063 tprint(" nodes");
3064 tprint_nl(" avail lists: ");
3065 b = 0;
3066 for (i = 1; i < MAX_CHAIN_SIZE; i++) {
3067 for (j = free_chain[i]; j != null; j = vlink(j))
3068 free_chain_counts[i]++;
3069 if (free_chain_counts[i] > 0) {
3070 snprintf(msg, 255, "%s%d:%d", (b ? "," : ""), i, (int) free_chain_counts[i]);
3071 tprint(msg);
3072 b = 1;
3073 }
3074 }
3075 /*tex A newline, if needed: */
3076 print_nlp();
3077 }
3078
3079 halfword new_span_node(halfword n, int s, scaled w)
3080 {
3081 halfword p = new_node(span_node, 0);
3082 span_link(p) = n;
3083 span_span(p) = s;
3084 width(p) = w;
3085 return p;
3086 }
3087
3088 /* Now comes some attribute stuff. */
3089
3090 static halfword new_attribute_node(unsigned int i, int v)
3091 {
3092 register halfword r = get_node(attribute_node_size);
3093 type(r) = attribute_node;
3094 attribute_id(r) = (halfword) i;
3095 attribute_value(r) = v;
3096 /* not used but nicer in print */
3097 subtype(r) = 0;
3098 return r;
3099 }
3100
3101 halfword copy_attribute_list(halfword n)
3102 {
3103 halfword q = get_node(attribute_node_size);
3104 register halfword p = q;
3105 type(p) = attribute_list_node;
3106 attr_list_ref(p) = 0;
3107 n = vlink(n);
3108 while (n != null) {
3109 register halfword r = get_node(attribute_node_size);
3110 /*tex The link will be fixed automatically in the next loop. */
3111 (void) memcpy((void *) (varmem + r), (void *) (varmem + n), (sizeof(memory_word) * attribute_node_size));
3112 vlink(p) = r;
3113 p = r;
3114 n = vlink(n);
3115 }
3116 return q;
3117 }
3118
3119 void update_attribute_cache(void)
3120 {
3121 halfword p;
3122 register int i;
3123 attr_list_cache = get_node(attribute_node_size);
3124 type(attr_list_cache) = attribute_list_node;
3125 attr_list_ref(attr_list_cache) = 0;
3126 p = attr_list_cache;
3127 for (i = 0; i <= max_used_attr; i++) {
3128 register int v = attribute(i);
3129 if (v > UNUSED_ATTRIBUTE) {
3130 register halfword r = new_attribute_node((unsigned) i, v);
3131 vlink(p) = r;
3132 p = r;
3133 }
3134 }
3135 if (vlink(attr_list_cache) == null) {
3136 free_node(attr_list_cache, attribute_node_size);
3137 attr_list_cache = null;
3138 }
3139 return;
3140 }
3141
3142 void build_attribute_list(halfword b)
3143 {
3144 if (max_used_attr >= 0) {
3145 if (attr_list_cache == cache_disabled|| attr_list_cache == null) {
3146 update_attribute_cache();
3147 if (attr_list_cache == null)
3148 return;
3149 }
3150 attr_list_ref(attr_list_cache)++;
3151 node_attr(b) = attr_list_cache;
3152 }
3153 }
3154
3155 halfword current_attribute_list(void)
3156 {
3157 if (max_used_attr >= 0) {
3158 if (attr_list_cache == cache_disabled) {
3159 update_attribute_cache();
3160 }
3161 return attr_list_cache ;
3162 }
3163 return null ;
3164 }
3165
3166 void reassign_attribute(halfword n, halfword new)
3167 {
3168 halfword old;
3169 old = node_attr(n);
3170 if (new == null) {
3171 /*tex There is nothing to assign but we need to check for an old value. */
3172 if (old != null) {
3173 /*tex This also nulls |attr| field of |n|. */
3174 delete_attribute_ref(old);
3175 }
3176 } else if (old == null) {
3177 /*tex Nothing is assigned so we just do that now. */
3178 assign_attribute_ref(n,new);
3179 } else if (old != new) {
3180 /*tex Something is assigned so we need to clean up and assign then. */
3181 delete_attribute_ref(old);
3182 assign_attribute_ref(n,new);
3183 }
3184 /*tex The same value so there is no need to assign and change the refcount. */
3185 node_attr(n) = new ;
3186 }
3187
3188 void delete_attribute_ref(halfword b)
3189 {
3190 if (b != null) {
3191 if (type(b) == attribute_list_node){
3192 attr_list_ref(b)--;
3193 if (attr_list_ref(b) == 0) {
3194 if (b == attr_list_cache)
3195 attr_list_cache = cache_disabled;
3196 free_node_chain(b, attribute_node_size);
3197 }
3198 /*tex Maintain sanity. */
3199 if (attr_list_ref(b) < 0) {
3200 attr_list_ref(b) = 0;
3201 }
3202 } else {
3203 normal_error("nodes","trying to delete an attribute reference of a non attribute node");
3204 }
3205 }
3206 }
3207
3208 void reset_node_properties(halfword b)
3209 {
3210 if (b != null) {
3211 lua_properties_reset(b);
3212 }
3213 }
3214
3215 /*tex Here |p| is an attr list head, or zero. */
3216
3217 halfword do_set_attribute(halfword p, int i, int val)
3218 {
3219 register halfword q;
3220 register int j = 0;
3221 if (p == null) {
3222 /*tex Add a new head \& node. */
3223 q = get_node(attribute_node_size);
3224 type(q) = attribute_list_node;
3225 attr_list_ref(q) = 1;
3226 p = new_attribute_node((unsigned) i, val);
3227 vlink(q) = p;
3228 return q;
3229 }
3230 q = p;
3231 if (vlink(p) != null) {
3232 while (vlink(p) != null) {
3233 int t = attribute_id(vlink(p));
3234 if (t == i && attribute_value(vlink(p)) == val) {
3235 /*tex There is no need to do anything. */
3236 return q;
3237 }
3238 if (t >= i)
3239 break;
3240 j++;
3241 p = vlink(p);
3242 }
3243 p = q;
3244 while (j-- > 0)
3245 p = vlink(p);
3246 if (attribute_id(vlink(p)) == i) {
3247 attribute_value(vlink(p)) = val;
3248 } else {
3249 /*tex Add a new node. */
3250 halfword r = new_attribute_node((unsigned) i, val);
3251 vlink(r) = vlink(p);
3252 vlink(p) = r;
3253 }
3254 return q;
3255 } else {
3256 normal_error("nodes","trying to set an attribute fails, case 1");
3257 return null ;
3258 }
3259 }
3260
3261 void set_attribute(halfword n, int i, int val)
3262 {
3263 register halfword p;
3264 register int j = 0;
3265 /*tex Not all nodes can have an attribute list. */
3266 if (!nodetype_has_attributes(type(n)))
3267 return;
3268 /*tex If we have no list, we create one and quit. */
3269 p = node_attr(n);
3270 if (p == null) { /* add a new head \& node */
3271 p = get_node(attribute_node_size);
3272 type(p) = attribute_list_node;
3273 attr_list_ref(p) = 1;
3274 node_attr(n) = p;
3275 p = new_attribute_node((unsigned) i, val);
3276 vlink(node_attr(n)) = p;
3277 return;
3278 }
3279 /*tex We check if we have this attribute already and quit if the value stays the same. */
3280 if (vlink(p) != null) {
3281 while (vlink(p) != null) {
3282 int t = attribute_id(vlink(p));
3283 if (t == i && attribute_value(vlink(p)) == val)
3284 return;
3285 if (t >= i)
3286 break;
3287 j++;
3288 p = vlink(p);
3289 }
3290 /*tex If found |j| has now the position and we assume a sorted list ! */
3291 p = node_attr(n);
3292 if (attr_list_ref(p) == 0 ) {
3293 /*tex The list is invalid i.e. freed already. */
3294 formatted_warning("nodes","node %d has an attribute list that is free already, case 1",(int) n);
3295 /*tex The still dangling list gets ref count 1. */
3296 attr_list_ref(p) = 1;
3297 } else if (attr_list_ref(p) == 1) {
3298 /*tex This can really happen! */
3299 if (p == attr_list_cache) {
3300 /*tex
3301
3302 We can invalidate the cache setting with |attr_list_cache =
3303 cache_disabled| or or save the list, as done below.
3304
3305 */
3306 p = copy_attribute_list(p);
3307 node_attr(n) = p;
3308 /*tex The copied list gets ref count 1. */
3309 attr_list_ref(p) = 1;
3310 }
3311 } else {
3312 /*tex The list is used multiple times so we make a copy. */
3313 p = copy_attribute_list(p);
3314 /*tex We decrement the ref count or the original. */
3315 delete_attribute_ref(node_attr(n));
3316 node_attr(n) = p;
3317 /*tex The copied list gets ref count 1. */
3318 attr_list_ref(p) = 1;
3319 }
3320 /*tex We go to position |j| in the list. */
3321 while (j-- > 0)
3322 p = vlink(p);
3323 /*tex If we have a hit we just set the value otherwise we add a new node. */
3324 if (attribute_id(vlink(p)) == i) {
3325 attribute_value(vlink(p)) = val;
3326 } else {
3327 /*tex Add a new node. */
3328 halfword r = new_attribute_node((unsigned) i, val);
3329 vlink(r) = vlink(p);
3330 vlink(p) = r;
3331 }
3332 } else {
3333 normal_error("nodes","trying to set an attribute fails, case 2");
3334 }
3335 }
3336
3337 int unset_attribute(halfword n, int i, int val)
3338 {
3339 register halfword p;
3340 register int t;
3341 register int j = 0;
3342 if (!nodetype_has_attributes(type(n)))
3343 return null;
3344 p = node_attr(n);
3345 if (p == null)
3346 return UNUSED_ATTRIBUTE;
3347 if (attr_list_ref(p) == 0) {
3348 formatted_warning("nodes","node %d has an attribute list that is free already, case 2", (int) n);
3349 return UNUSED_ATTRIBUTE;
3350 }
3351 if (vlink(p) != null) {
3352 while (vlink(p) != null) {
3353 t = attribute_id(vlink(p));
3354 if (t > i)
3355 return UNUSED_ATTRIBUTE;
3356 if (t == i) {
3357 p = vlink(p);
3358 break;
3359 }
3360 j++;
3361 p = vlink(p);
3362 }
3363 if (attribute_id(p) != i)
3364 return UNUSED_ATTRIBUTE;
3365 /*tex If we are still here, the attribute exists. */
3366 p = node_attr(n);
3367 if (attr_list_ref(p) > 1 || p == attr_list_cache) {
3368 halfword q = copy_attribute_list(p);
3369 if (attr_list_ref(p) > 1) {
3370 delete_attribute_ref(node_attr(n));
3371 }
3372 attr_list_ref(q) = 1;
3373 node_attr(n) = q;
3374 }
3375 p = vlink(node_attr(n));
3376 while (j-- > 0)
3377 p = vlink(p);
3378 t = attribute_value(p);
3379 if (val == UNUSED_ATTRIBUTE || t == val) {
3380 attribute_value(p) = UNUSED_ATTRIBUTE;
3381 }
3382 return t;
3383 } else {
3384 normal_error("nodes","trying to unset an attribute fails");
3385 return null;
3386 }
3387 }
3388
3389 int has_attribute(halfword n, int i, int val)
3390 {
3391 register halfword p;
3392 if (!nodetype_has_attributes(type(n)))
3393 return UNUSED_ATTRIBUTE;
3394 p = node_attr(n);
3395 if (p == null || vlink(p) == null)
3396 return UNUSED_ATTRIBUTE;
3397 p = vlink(p);
3398 while (p != null) {
3399 if (attribute_id(p) == i) {
3400 int ret = attribute_value(p);
3401 if (val == UNUSED_ATTRIBUTE || val == ret)
3402 return ret;
3403 return UNUSED_ATTRIBUTE;
3404 } else if (attribute_id(p) > i) {
3405 return UNUSED_ATTRIBUTE;
3406 }
3407 p = vlink(p);
3408 }
3409 return UNUSED_ATTRIBUTE;
3410 }
3411
3412 void print_short_node_contents(halfword p)
3413 {
3414 switch (type(p)) {
3415 case hlist_node:
3416 case vlist_node:
3417 case ins_node:
3418 case whatsit_node:
3419 case mark_node:
3420 case adjust_node:
3421 case unset_node:
3422 print_char('[');
3423 print_char(']');
3424 break;
3425 case rule_node:
3426 print_char('|');
3427 break;
3428 case glue_node:
3429 if (! glue_is_zero(p))
3430 print_char(' ');
3431 break;
3432 case math_node:
3433 print_char('$');
3434 break;
3435 case disc_node:
3436 short_display(vlink(pre_break(p)));
3437 short_display(vlink(post_break(p)));
3438 break;
3439 }
3440 }
3441
3442 static void show_pdftex_whatsit_rule_spec(int p)
3443 {
3444 tprint("(");
3445 print_rule_dimen(height(p));
3446 print_char('+');
3447 print_rule_dimen(depth(p));
3448 tprint(")x");
3449 print_rule_dimen(width(p));
3450 }
3451
3452 /*tex
3453
3454 Each new type of node that appears in our data structure must be capable of
3455 being displayed, copied, destroyed, and so on. The routines that we need for
3456 write-oriented whatsits are somewhat like those for mark nodes; other
3457 extensions might, of course, involve more subtlety here.
3458
3459 */
3460
3461 static void print_write_whatsit(const char *s, pointer p)
3462 {
3463 tprint_esc(s);
3464 if (write_stream(p) < 16)
3465 print_int(write_stream(p));
3466 else if (write_stream(p) == 16)
3467 print_char('*');
3468 else
3469 print_char('-');
3470 }
3471
3472 static void show_node_wrapup_core(int p)
3473 {
3474 switch (subtype(p)) {
3475 case open_node:
3476 print_write_whatsit("openout", p);
3477 print_char('=');
3478 print_file_name(open_name(p), open_area(p), open_ext(p));
3479 break;
3480 case write_node:
3481 print_write_whatsit("write", p);
3482 print_mark(write_tokens(p));
3483 break;
3484 case close_node:
3485 print_write_whatsit("closeout", p);
3486 break;
3487 case special_node:
3488 tprint_esc("special");
3489 print_mark(special_tokens(p));
3490 break;
3491 case late_special_node:
3492 tprint_esc("latespecial");
3493 print_mark(late_lua_data(p));
3494 break;
3495 case late_lua_node:
3496 show_late_lua(p);
3497 break;
3498 case save_pos_node:
3499 tprint_esc("savepos");
3500 break;
3501 case user_defined_node:
3502 tprint_esc("whatsit");
3503 print_int(user_node_id(p));
3504 print_char('=');
3505 switch (user_node_type(p)) {
3506 case 'a':
3507 tprint("<>");
3508 break;
3509 case 'n':
3510 tprint("[");
3511 show_node_list(user_node_value(p));
3512 tprint("]");
3513 break;
3514 case 's':
3515 print_char('"');
3516 print(user_node_value(p));
3517 print_char('"');
3518 break;
3519 case 't':
3520 print_mark(user_node_value(p));
3521 break;
3522 default: /* only 'd' */
3523 print_int(user_node_value(p));
3524 break;
3525 }
3526 break;
3527 }
3528 }
3529
3530 void show_node_wrapup_dvi(int p)
3531 {
3532 }
3533
3534 void show_node_wrapup_pdf(int p)
3535 {
3536 switch (subtype(p)) {
3537 case pdf_literal_node:
3538 case pdf_late_literal_node:
3539 show_pdf_literal(p);
3540 break;
3541 case pdf_colorstack_node:
3542 tprint_esc("pdfcolorstack ");
3543 print_int(pdf_colorstack_stack(p));
3544 switch (pdf_colorstack_cmd(p)) {
3545 case colorstack_set:
3546 tprint(" set ");
3547 break;
3548 case colorstack_push:
3549 tprint(" push ");
3550 break;
3551 case colorstack_pop:
3552 tprint(" pop");
3553 break;
3554 case colorstack_current:
3555 tprint(" current");
3556 break;
3557 default:
3558 confusion("colorstack");
3559 break;
3560 }
3561 if (pdf_colorstack_cmd(p) <= colorstack_data)
3562 print_mark(pdf_colorstack_data(p));
3563 break;
3564 case pdf_setmatrix_node:
3565 tprint_esc("pdfsetmatrix");
3566 print_mark(pdf_setmatrix_data(p));
3567 break;
3568 case pdf_save_node:
3569 tprint_esc("pdfsave");
3570 break;
3571 case pdf_restore_node:
3572 tprint_esc("pdfrestore");
3573 break;
3574 case pdf_link_state_node:
3575 tprint_esc("pdflinkstate ");
3576 print_int(pdf_link_state(p));
3577 break;
3578 case pdf_refobj_node:
3579 tprint_esc("pdfrefobj");
3580 if (obj_obj_is_stream(static_pdf, pdf_obj_objnum(p))) {
3581 if (obj_obj_stream_attr(static_pdf, pdf_obj_objnum(p)) != LUA_NOREF) {
3582 tprint(" attr");
3583 lua_rawgeti(Luas, LUA_REGISTRYINDEX, obj_obj_stream_attr(static_pdf, pdf_obj_objnum(p)));
3584 print_char(' ');
3585 tprint((const char *) lua_tostring(Luas, -1));
3586 lua_pop(Luas, 1);
3587 }
3588 tprint(" stream");
3589 }
3590 if (obj_obj_is_file(static_pdf, pdf_obj_objnum(p)))
3591 tprint(" file");
3592 if (obj_obj_data(static_pdf, pdf_obj_objnum(p)) != LUA_NOREF) {
3593 lua_rawgeti(Luas, LUA_REGISTRYINDEX, obj_obj_data(static_pdf, pdf_obj_objnum(p)));
3594 print_char(' ');
3595 tprint((const char *) lua_tostring(Luas, -1));
3596 lua_pop(Luas, 1);
3597 }
3598 break;
3599 case pdf_annot_node:
3600 tprint_esc("pdfannot");
3601 show_pdftex_whatsit_rule_spec(p);
3602 print_mark(pdf_annot_data(p));
3603 break;
3604 case pdf_start_link_node:
3605 tprint_esc("pdfstartlink");
3606 show_pdftex_whatsit_rule_spec(p);
3607 if (pdf_link_attr(p) != null) {
3608 tprint(" attr");
3609 print_mark(pdf_link_attr(p));
3610 }
3611 tprint(" action");
3612 if (pdf_action_type(pdf_link_action(p)) == pdf_action_user) {
3613 tprint(" user");
3614 print_mark(pdf_action_tokens(pdf_link_action(p)));
3615 return;
3616 }
3617 if (pdf_action_file(pdf_link_action(p)) != null) {
3618 tprint(" file");
3619 print_mark(pdf_action_file(pdf_link_action(p)));
3620 }
3621 if (pdf_action_struct_id(pdf_link_action(p)) != null) {
3622 tprint(" struct");
3623 if (pdf_action_file(pdf_link_action(p)) != null) {
3624 print_mark(pdf_action_struct_id(pdf_link_action(p)));
3625 } else if (pdf_action_named_id(pdf_link_action(p)) & 2) {
3626 tprint(" name");
3627 print_mark(pdf_action_struct_id(pdf_link_action(p)));
3628 } else {
3629 tprint(" num");
3630 print_int(pdf_action_struct_id(pdf_link_action(p)));
3631 }
3632 }
3633 switch (pdf_action_type(pdf_link_action(p))) {
3634 case pdf_action_goto:
3635 if (pdf_action_named_id(pdf_link_action(p)) & 1) {
3636 tprint(" goto name");
3637 print_mark(pdf_action_id(pdf_link_action(p)));
3638 } else {
3639 tprint(" goto num");
3640 print_int(pdf_action_id(pdf_link_action(p)));
3641 }
3642 break;
3643 case pdf_action_page:
3644 tprint(" page");
3645 print_int(pdf_action_id(pdf_link_action(p)));
3646 print_mark(pdf_action_tokens(pdf_link_action(p)));
3647 break;
3648 case pdf_action_thread:
3649 if (pdf_action_named_id(pdf_link_action(p)) & 1) {
3650 tprint(" thread name");
3651 print_mark(pdf_action_id(pdf_link_action(p)));
3652 } else {
3653 tprint(" thread num");
3654 print_int(pdf_action_id(pdf_link_action(p)));
3655 }
3656 break;
3657 default:
3658 normal_error("pdf backend", "unknown action type for link");
3659 break;
3660 }
3661 break;
3662 case pdf_end_link_node:
3663 tprint_esc("pdfendlink");
3664 break;
3665 case pdf_dest_node:
3666 tprint_esc("pdfdest");
3667 if (pdf_dest_named_id(p) > 0) {
3668 tprint(" name");
3669 print_mark(pdf_dest_id(p));
3670 } else {
3671 tprint(" num");
3672 print_int(pdf_dest_id(p));
3673 }
3674 print_char(' ');
3675 switch (pdf_dest_type(p)) {
3676 case pdf_dest_xyz:
3677 tprint("xyz");
3678 if (pdf_dest_xyz_zoom(p) != null) {
3679 tprint(" zoom");
3680 print_int(pdf_dest_xyz_zoom(p));
3681 }
3682 break;
3683 case pdf_dest_fitbh:
3684 tprint("fitbh");
3685 break;
3686 case pdf_dest_fitbv:
3687 tprint("fitbv");
3688 break;
3689 case pdf_dest_fitb:
3690 tprint("fitb");
3691 break;
3692 case pdf_dest_fith:
3693 tprint("fith");
3694 break;
3695 case pdf_dest_fitv:
3696 tprint("fitv");
3697 break;
3698 case pdf_dest_fitr:
3699 tprint("fitr");
3700 show_pdftex_whatsit_rule_spec(p);
3701 break;
3702 case pdf_dest_fit:
3703 tprint("fit");
3704 break;
3705 default:
3706 tprint("unknown!");
3707 break;
3708 }
3709 break;
3710 case pdf_thread_node:
3711 case pdf_start_thread_node:
3712 if (subtype(p) == pdf_thread_node)
3713 tprint_esc("pdfthread");
3714 else
3715 tprint_esc("pdfstartthread");
3716 tprint("(");
3717 print_rule_dimen(height(p));
3718 print_char('+');
3719 print_rule_dimen(depth(p));
3720 tprint(")x");
3721 print_rule_dimen(width(p));
3722 if (pdf_thread_attr(p) != null) {
3723 tprint(" attr");
3724 print_mark(pdf_thread_attr(p));
3725 }
3726 if (pdf_thread_named_id(p) > 0) {
3727 tprint(" name");
3728 print_mark(pdf_thread_id(p));
3729 } else {
3730 tprint(" num");
3731 print_int(pdf_thread_id(p));
3732 }
3733 break;
3734 case pdf_end_thread_node:
3735 tprint_esc("pdfendthread");
3736 break;
3737 default:
3738 break;
3739 }
3740 }
3741
3742 /*tex
3743
3744 Now we are ready for |show_node_list| itself. This procedure has been written
3745 to be ``extra robust'' in the sense that it should not crash or get into a
3746 loop even if the data structures have been messed up by bugs in the rest of
3747 the program. You can safely call its parent routine |show_box(p)| for
3748 arbitrary values of |p| when you are debugging \TeX. However, in the presence
3749 of bad data, the procedure may fetch a |memory_word| whose variant is
3750 different from the way it was stored; for example, it might try to read
3751 |mem[p].hh| when |mem[p]| contains a scaled integer, if |p| is a pointer that
3752 has been clobbered or chosen at random.
3753
3754 */
3755
3756 #define node_list_display(A) do { \
3757 append_char('.'); \
3758 show_node_list(A); \
3759 flush_char(); \
3760 } while (0)
3761
3762 #define node_list_display_x(A,B) do { \
3763 if ((B) != null) { \
3764 append_char('.'); \
3765 append_char(A); \
3766 append_char(' '); \
3767 show_node_list(B); \
3768 flush_char(); \
3769 flush_char(); \
3770 flush_char(); \
3771 } \
3772 } while (0)
3773
3774 /*tex Print a node list symbolically: */
3775
3776 void show_node_list(int p)
3777 {
3778 /*tex The number of items already printed at this level: */
3779 int n = 0;
3780 halfword w;
3781 /*tex A glue ratio, as a floating point number: */
3782 real g;
3783 if ((int) cur_length > depth_threshold) {
3784 if (p > null) {
3785 /*tex Indicate that there's been some truncation. */
3786 tprint(" []");
3787 }
3788 return;
3789 }
3790 while (p != null) {
3791 print_ln();
3792 print_current_string();
3793 /*tex Display the nesting history. */
3794 if (tracing_online_par < -2)
3795 print_int(p);
3796 incr(n);
3797 if (n > breadth_max) {
3798 /*tex Time to stop. */
3799 tprint("etc.");
3800 return;
3801 }
3802 /*tex Display node |p|. */
3803 if (is_char_node(p)) {
3804 print_font_and_char(p);
3805 if (is_ligature(p)) {
3806 /*tex Display ligature |p|. */
3807 tprint(" (ligature ");
3808 if (is_leftboundary(p))
3809 print_char('|');
3810 font_in_short_display = font(p);
3811 short_display(lig_ptr(p));
3812 if (is_rightboundary(p))
3813 print_char('|');
3814 print_char(')');
3815 }
3816 } else {
3817 switch (type(p)) {
3818 case hlist_node:
3819 case vlist_node:
3820 case unset_node:
3821 /*tex Display box |p|. */
3822 if (type(p) == hlist_node)
3823 tprint_esc("h");
3824 else if (type(p) == vlist_node)
3825 tprint_esc("v");
3826 else
3827 tprint_esc("unset");
3828 tprint("box(");
3829 print_scaled(height(p));
3830 print_char('+');
3831 print_scaled(depth(p));
3832 tprint(")x");
3833 print_scaled(width(p));
3834 if (type(p) == unset_node) {
3835 /*tex Display special fields of the unset node |p|. */
3836 if (span_count(p) != min_quarterword) {
3837 tprint(" (");
3838 print_int(span_count(p) + 1);
3839 tprint(" columns)");
3840 }
3841 if (glue_stretch(p) != 0) {
3842 tprint(", stretch ");
3843 print_glue(glue_stretch(p), glue_order(p), NULL);
3844 }
3845 if (glue_shrink(p) != 0) {
3846 tprint(", shrink ");
3847 print_glue(glue_shrink(p), glue_sign(p), NULL);
3848 }
3849 } else {
3850 /*tex
3851
3852 Display the value of |glue_set(p)|. The code will
3853 have to change in this place if |glue_ratio| is a
3854 structured type instead of an ordinary |real|. Note
3855 that this routine should avoid arithmetic errors even
3856 if the |glue_set| field holds an arbitrary random
3857 value. The following code assumes that a properly
3858 formed nonzero |real| number has absolute value
3859 $2^{20}$ or more when it is regarded as an integer;
3860 this precaution was adequate to prevent floating
3861 point underflow on the author's computer.
3862
3863 */
3864 g = (real) (glue_set(p));
3865 if ((g != 0.0) && (glue_sign(p) != normal)) {
3866 tprint(", glue set ");
3867 if (glue_sign(p) == shrinking)
3868 tprint("- ");
3869 if (g > 20000.0 || g < -20000.0) {
3870 if (g > 0.0)
3871 print_char('>');
3872 else
3873 tprint("< -");
3874 print_glue(20000 * unity, glue_order(p), NULL);
3875 } else {
3876 print_glue(round(unity * g), glue_order(p), NULL);
3877 }
3878 }
3879 if (shift_amount(p) != 0) {
3880 tprint(", shifted ");
3881 print_scaled(shift_amount(p));
3882 }
3883 tprint(", direction ");
3884 print_dir_par(box_dir(p));
3885 }
3886 /*tex Recursive call: */
3887 node_list_display(list_ptr(p));
3888 break;
3889 case rule_node:
3890 /*tex Display rule |p|. */
3891 if (subtype(p) == normal_rule) {
3892 tprint_esc("rule(");
3893 } else if (subtype(p) == empty_rule) {
3894 tprint_esc("norule(");
3895 } else if (subtype(p) == user_rule) {
3896 tprint_esc("userrule(");
3897 } else if (subtype(p) == box_rule) {
3898 tprint_esc("box(");
3899 } else if (subtype(p) == image_rule) {
3900 tprint_esc("image(");
3901 }
3902 print_rule_dimen(height(p));
3903 print_char('+');
3904 print_rule_dimen(depth(p));
3905 tprint(")x");
3906 print_rule_dimen(width(p));
3907 break;
3908 case ins_node:
3909 /*tex Display insertion |p|. */
3910 tprint_esc("insert");
3911 print_int(subtype(p));
3912 tprint(", natural size ");
3913 print_scaled(height(p));
3914 tprint("; split(");
3915 print_spec(split_top_ptr(p), NULL);
3916 print_char(',');
3917 print_scaled(depth(p));
3918 tprint("); float cost ");
3919 print_int(float_cost(p));
3920 /*tex Recursive call. */
3921 node_list_display(ins_ptr(p));
3922 break;
3923 case dir_node:
3924 if (subtype(p) == cancel_dir) {
3925 tprint_esc("enddir");
3926 } else {
3927 tprint_esc("begindir");
3928 }
3929 print_char(' ');
3930 print_dir_par(dir_dir(p));
3931 break;
3932 case local_par_node:
3933 tprint_esc("localpar");
3934 append_char('.');
3935 print_ln();
3936 print_current_string();
3937 tprint_esc("localinterlinepenalty");
3938 print_char('=');
3939 print_int(local_pen_inter(p));
3940 print_ln();
3941 print_current_string();
3942 tprint_esc("localbrokenpenalty");
3943 print_char('=');
3944 print_int(local_pen_broken(p));
3945 print_ln();
3946 print_current_string();
3947 tprint_esc("localleftbox");
3948 if (local_box_left(p) == null) {
3949 tprint("=null");
3950 } else {
3951 append_char('.');
3952 show_node_list(local_box_left(p));
3953 decr(cur_length);
3954 }
3955 print_ln();
3956 print_current_string();
3957 tprint_esc("localrightbox");
3958 if (local_box_right(p) == null) {
3959 tprint("=null");
3960 } else {
3961 append_char('.');
3962 show_node_list(local_box_right(p));
3963 decr(cur_length);
3964 }
3965 decr(cur_length);
3966 break;
3967 case boundary_node:
3968 if (subtype(p)==0) {
3969 tprint_esc("noboundary");
3970 } else {
3971 switch (subtype(p)) {
3972 case 1:
3973 tprint_esc("boundary");
3974 break;
3975 case 2:
3976 tprint_esc("protrusionboundary");
3977 break;
3978 case 3:
3979 tprint_esc("wordboundary");
3980 break;
3981 default:
3982 tprint_esc("boundary");
3983 print_char(':');
3984 print_int(subtype(p));
3985 break;
3986 }
3987 print_char('=');
3988 print_int(boundary_value(p));
3989 }
3990 break;
3991 case whatsit_node:
3992 w = subtype(p) ;
3993 if (w >= backend_first_pdf_whatsit) {
3994 show_node_wrapup_pdf(p);
3995 } else if (w >= backend_first_dvi_whatsit) {
3996 show_node_wrapup_dvi(p);
3997 } else {
3998 show_node_wrapup_core(p);
3999 }
4000 break;
4001 case glue_node:
4002 /*tex Display glue |p|. */
4003 if (subtype(p) >= a_leaders) {
4004 /*tex Display leaders |p|. */
4005 tprint_esc("");
4006 switch (subtype(p)) {
4007 case a_leaders:
4008 break;
4009 case c_leaders:
4010 print_char('c');
4011 break;
4012 case x_leaders:
4013 print_char('x');
4014 break;
4015 case g_leaders:
4016 print_char('g');
4017 break;
4018 default:
4019 normal_warning("nodes","weird glue leader subtype ignored");
4020 }
4021 tprint("leaders ");
4022 print_spec(p, NULL);
4023 /*tex Recursive call: */
4024 node_list_display(leader_ptr(p));
4025 } else {
4026 tprint_esc("glue");
4027 if (subtype(p) != normal) {
4028 print_char('(');
4029 if ((subtype(p) - 1) < thin_mu_skip_code) {
4030 print_cmd_chr(assign_glue_cmd, glue_base + (subtype(p) - 1));
4031 } else if (subtype(p) < cond_math_glue) {
4032 print_cmd_chr(assign_mu_glue_cmd, glue_base + (subtype(p) - 1));
4033 } else if (subtype(p) == cond_math_glue) {
4034 tprint_esc("nonscript");
4035 } else {
4036 tprint_esc("mskip");
4037 }
4038 print_char(')');
4039 }
4040 if (subtype(p) != cond_math_glue) {
4041 print_char(' ');
4042 if (subtype(p) < cond_math_glue)
4043 print_spec(p, NULL);
4044 else
4045 print_spec(p, "mu");
4046 }
4047 }
4048 break;
4049 case margin_kern_node:
4050 tprint_esc("kern");
4051 print_scaled(width(p));
4052 if (subtype(p) == left_side)
4053 tprint(" (left margin)");
4054 else
4055 tprint(" (right margin)");
4056 break;
4057 case kern_node:
4058 /*tex Display kern |p| */
4059 if (subtype(p) != mu_glue) {
4060 tprint_esc("kern");
4061 /*tex
4062
4063 \starttyping
4064 if (subtype(p) != normal) {
4065 print_char(' ');
4066 }
4067 \stoptyping
4068
4069 */
4070 print_scaled(width(p));
4071 if (subtype(p) == font_kern)
4072 tprint(" (font)");
4073 else if (subtype(p) == italic_kern)
4074 tprint(" (italic)");
4075 else if (subtype(p) == accent_kern)
4076 tprint(" (accent)");
4077 } else {
4078 tprint_esc("mkern");
4079 print_scaled(width(p));
4080 tprint("mu");
4081 }
4082 break;
4083 case math_node:
4084 /*tex Display math node |p|. */
4085 tprint_esc("math");
4086 if (subtype(p) == before)
4087 tprint("on");
4088 else
4089 tprint("off");
4090 if (!glue_is_zero(p)) {
4091 tprint(", glued ");
4092 print_spec(p, NULL);
4093 } else if (surround(p) != 0) {
4094 tprint(", surrounded ");
4095 print_scaled(surround(p));
4096 }
4097 break;
4098 case penalty_node:
4099 /*tex Display penalty |p|. */
4100 tprint_esc("penalty ");
4101 print_int(penalty(p));
4102 break;
4103 case disc_node:
4104 /*tex
4105
4106 Display discretionary |p|. The |post_break| list of a
4107 discretionary node is indicated by a prefixed
4108 `\.{\char'174}' instead of the `\..' before the
4109 |pre_break| list.
4110
4111 We're not compatible anyway so ...
4112
4113 \starttyping
4114 tprint_esc("discretionary");
4115 print_int(disc_penalty(p));
4116 print_char('|');
4117 if (vlink(no_break(p)) != null) {
4118 tprint(" replacing ");
4119 node_list_display(vlink(no_break(p)));
4120 }
4121 node_list_display(vlink(pre_break(p)));
4122 append_char('|');
4123 show_node_list(vlink(post_break(p)));
4124 flush_char();
4125 \stoptyping
4126
4127 has become:
4128
4129 */
4130 tprint_esc("discretionary");
4131 tprint(" (penalty ");
4132 print_int(disc_penalty(p));
4133 print_char(')');
4134 node_list_display_x('<',vlink(pre_break(p)));
4135 node_list_display_x('>',vlink(post_break(p)));
4136 node_list_display_x('=',vlink(no_break(p)));
4137 break;
4138 case mark_node:
4139 /*tex Display mark |p|. */
4140 tprint_esc("mark");
4141 if (mark_class(p) != 0) {
4142 print_char('s');
4143 print_int(mark_class(p));
4144 }
4145 print_mark(mark_ptr(p));
4146 break;
4147 case adjust_node:
4148 /*tex Display adjustment |p|. */
4149 tprint_esc("vadjust");
4150 if (subtype(p) != 0)
4151 tprint(" pre ");
4152 /*tex Recursive call. */
4153 node_list_display(adjust_ptr(p));
4154 break;
4155 case glue_spec_node:
4156 tprint("<glue_spec ");
4157 print_spec(p, NULL);
4158 tprint(">");
4159 break;
4160 default:
4161 show_math_node(p);
4162 break;
4163 }
4164 }
4165 p = vlink(p);
4166 }
4167 }
4168
4169 /*tex
4170
4171 This routine finds the 'base' width of a horizontal box, using the same logic
4172 that \TeX82 used for \.{\\predisplaywidth}.
4173
4174 */
4175
4176 static pointer get_actual_box_width(pointer r,pointer p, scaled initial_width)
4177 {
4178 /*tex increment to |v| */
4179 scaled d;
4180 /*tex calculated |size| */
4181 scaled w = -max_dimen;
4182 /*tex |w| plus possible glue amount */
4183 scaled v = initial_width;
4184 while (p != null) {
4185 if (is_char_node(p)) {
4186 d = glyph_width(p);
4187 goto FOUND;
4188 }
4189 switch (type(p)) {
4190 case hlist_node:
4191 case vlist_node:
4192 case rule_node:
4193 d = width(p);
4194 goto FOUND;
4195 break;
4196 case margin_kern_node:
4197 d = width(p);
4198 break;
4199 case kern_node:
4200 d = width(p);
4201 break;
4202 case disc_node:
4203 /*tex At the end of the line we should actually take the |pre|. */
4204 if (no_break(p) != null) {
4205 d = get_actual_box_width(r,vlink_no_break(p),0);
4206 if (d <= -max_dimen || d >= max_dimen) {
4207 d = 0;
4208 }
4209 } else {
4210 d = 0;
4211 }
4212 goto FOUND;
4213 break;
4214 case math_node:
4215 /*tex Begin mathskip code. */
4216 if (glue_is_zero(p)) {
4217 d = surround(p);
4218 break;
4219 } else {
4220 /*tex Fall through. */
4221 }
4222 /*tex End mathskip code. */
4223 case glue_node:
4224 /*tex
4225
4226 We need to be careful that |w|, |v|, and |d| do not depend on
4227 any |glue_set| values, since such values are subject to
4228 system-dependent rounding. System-dependent numbers are not
4229 allowed to infiltrate parameters like |pre_display_size|,
4230 since \TeX82 is supposed to make the same decisions on all
4231 machines.
4232
4233 */
4234 d = width(p);
4235 if (glue_sign(r) == stretching) {
4236 if ((glue_order(r) == stretch_order(p)) && (stretch(p) != 0))
4237 v = max_dimen;
4238 } else if (glue_sign(r) == shrinking) {
4239 if ((glue_order(r) == shrink_order(p)) && (shrink(p) != 0))
4240 v = max_dimen;
4241 }
4242 if (subtype(p) >= a_leaders)
4243 goto FOUND;
4244 break;
4245 default:
4246 d = 0;
4247 break;
4248 }
4249 if (v < max_dimen)
4250 v = v + d;
4251 goto NOT_FOUND;
4252 FOUND:
4253 if (v < max_dimen) {
4254 v = v + d;
4255 w = v;
4256 } else {
4257 w = max_dimen;
4258 break;
4259 }
4260 NOT_FOUND:
4261 p = vlink(p);
4262 }
4263 return w;
4264 }
4265
4266 pointer actual_box_width(pointer r, scaled base_width)
4267 {
4268 /*tex
4269
4270 Often this is the same as:
4271
4272 \starttyping
4273 return + shift_amount(r) + base_width +
4274 natural_sizes(list_ptr(r),null,(glue_ratio) glue_set(r),glue_sign(r),glue_order(r),box_dir(r));
4275 \stoptyping
4276 */
4277 return get_actual_box_width(r,list_ptr(r),shift_amount(r) + base_width);
4278 }
4279
4280 halfword tail_of_list(halfword p)
4281 {
4282 halfword q = p;
4283 while (vlink(q) != null)
4284 q = vlink(q);
4285 return q;
4286 }
4287
4288 int var_used;
4289
4290 /*tex
4291
4292 Attribute lists need two extra globals to increase processing efficiency.
4293 |max_used_attr| limits the test loop that checks for set attributes, and
4294 |attr_list_cache| contains a pointer to an already created attribute list. It
4295 is set to the special value |cache_disabled| when the current value can no
4296 longer be trusted: after an assignment to an attribute register, and after a
4297 group has ended.
4298
4299 */
4300
4301 /*tex The maximum assigned attribute id: */
4302
4303 int max_used_attr;
4304 halfword attr_list_cache;
4305
4306 /*tex
4307
4308 From the computer's standpoint, \TeX's chief mission is to create horizontal
4309 and vertical lists. We shall now investigate how the elements of these lists
4310 are represented internally as nodes in the dynamic memory.
4311
4312 A horizontal or vertical list is linked together by |link| fields in the
4313 first word of each node. Individual nodes represent boxes, glue, penalties,
4314 or special things like discretionary hyphens; because of this variety, some
4315 nodes are longer than others, and we must distinguish different kinds of
4316 nodes. We do this by putting a `|type|' field in the first word, together
4317 with the link and an optional `|subtype|'.
4318
4319 Character nodes appear only in horizontal lists, never in vertical lists.
4320
4321 An |hlist_node| stands for a box that was made from a horizontal list. Each
4322 |hlist_node| is seven words long, and contains the following fields (in
4323 addition to the mandatory |type| and |link|, which we shall not mention
4324 explicitly when discussing the other node types): The |height| and |width|
4325 and |depth| are scaled integers denoting the dimensions of the box. There is
4326 also a |shift_amount| field, a scaled integer indicating how much this box
4327 should be lowered (if it appears in a horizontal list), or how much it should
4328 be moved to the right (if it appears in a vertical list). There is a
4329 |list_ptr| field, which points to the beginning of the list from which this
4330 box was fabricated; if |list_ptr| is |null|, the box is empty. Finally, there
4331 are three fields that represent the setting of the glue: |glue_set(p)| is a
4332 word of type |glue_ratio| that represents the proportionality constant for
4333 glue setting; |glue_sign(p)| is |stretching| or |shrinking| or |normal|
4334 depending on whether or not the glue should stretch or shrink or remain
4335 rigid; and |glue_order(p)| specifies the order of infinity to which glue
4336 setting applies (|normal|, |sfi|, |fil|, |fill|, or |filll|). The |subtype|
4337 field is not used.
4338
4339 The |new_null_box| function returns a pointer to an |hlist_node| in which all
4340 subfields have the values corresponding to `\.{\\hbox\{\}}'. The |subtype|
4341 field is set to |min_quarterword|, since that's the desired |span_count|
4342 value if this |hlist_node| is changed to an |unset_node|.
4343
4344 */
4345
4346 /*tex Create a new box node. */
4347
4348 halfword new_null_box(void)
4349 {
4350 halfword p = new_node(hlist_node, min_quarterword);
4351 box_dir(p) = text_direction_par;
4352 return p;
4353 }
4354
4355 /*tex
4356
4357 A |vlist_node| is like an |hlist_node| in all respects except that it
4358 contains a vertical list.
4359
4360 A |rule_node| stands for a solid black rectangle; it has |width|, |depth|,
4361 and |height| fields just as in an |hlist_node|. However, if any of these
4362 dimensions is $-2^{30}$, the actual value will be determined by running the
4363 rule up to the boundary of the innermost enclosing box. This is called a
4364 ``running dimension.'' The |width| is never running in an hlist; the |height|
4365 and |depth| are never running in a~vlist.
4366
4367 A new rule node is delivered by the |new_rule| function. It makes all the
4368 dimensions ``running,'' so you have to change the ones that are not allowed
4369 to run.
4370
4371 */
4372
4373 halfword new_rule(int s)
4374 {
4375 halfword p = new_node(rule_node,s);
4376 return p;
4377 }
4378
4379 /*tex
4380
4381 Insertions are represented by |ins_node| records, where the |subtype|
4382 indicates the corresponding box number. For example, `\.{\\insert 250}' leads
4383 to an |ins_node| whose |subtype| is |250+min_quarterword|. The |height| field
4384 of an |ins_node| is slightly misnamed; it actually holds the natural height
4385 plus depth of the vertical list being inserted. The |depth| field holds the
4386 |split_max_depth| to be used in case this insertion is split, and the
4387 |split_top_ptr| points to the corresponding |split_top_skip|. The
4388 |float_cost| field holds the |floating_penalty| that will be used if this
4389 insertion floats to a subsequent page after a split insertion of the same
4390 class. There is one more field, the |ins_ptr|, which points to the beginning
4391 of the vlist for the insertion.
4392
4393 A |mark_node| has a |mark_ptr| field that points to the reference count of a
4394 token list that contains the user's \.{\\mark} text. In addition there is a
4395 |mark_class| field that contains the mark class.
4396
4397 An |adjust_node|, which occurs only in horizontal lists, specifies material
4398 that will be moved out into the surrounding vertical list; i.e., it is used
4399 to implement \TeX's `\.{\\vadjust}' operation. The |adjust_ptr| field points
4400 to the vlist containing this material.
4401
4402 A |glyph_node|, which occurs only in horizontal lists, specifies a glyph in a
4403 particular font, along with its attribute list. Older versions of \TeX\ could
4404 use token memory for characters, because the font,char combination would fit
4405 in a single word (both values were required to be strictly less than
4406 $2^{16}$). In LuaTeX, room is needed for characters that are larger than
4407 that, as well as a pointer to a potential attribute list, and the two
4408 displacement values.
4409
4410 In turn, that made the node so large that it made sense to merge ligature
4411 glyphs as well, as that requires only one extra pointer. A few extra classes
4412 of glyph nodes will be introduced later. The unification of all those types
4413 makes it easier to manipulate lists of glyphs. The subtype differentiates
4414 various glyph kinds.
4415
4416 First, here is a function that returns a pointer to a glyph node for a given
4417 glyph in a given font. If that glyph doesn't exist, |null| is returned
4418 instead. Nodes of this subtype are directly created only for accents and
4419 their base (through |make_accent|), and math nucleus items (in the conversion
4420 from |mlist| to |hlist|).
4421
4422 */
4423
4424 halfword new_glyph(int f, int c)
4425 {
4426 halfword p = null;
4427 if ((f == 0) || (char_exists(f, c))) {
4428 p = new_glyph_node();
4429 set_to_glyph(p);
4430 font(p) = f;
4431 character(p) = c;
4432 }
4433 return p;
4434 }
4435
4436 /*tex
4437
4438 A subset of the glyphs nodes represent ligatures: characters fabricated from
4439 the interaction of two or more actual characters. The characters that
4440 generated the ligature have not been forgotten, since they are needed for
4441 diagnostic messages; the |lig_ptr| field points to a linked list of character
4442 nodes for all original characters that have been deleted. (This list might be
4443 empty if the characters that generated the ligature were retained in other
4444 nodes.)
4445
4446 The |subtype| field of these |glyph_node|s is 1, plus 2 and/or 1 if the
4447 original source of the ligature included implicit left and/or right
4448 boundaries. These nodes are created by the C function |new_ligkern|.
4449
4450 A third general type of glyphs could be called a character, as it only
4451 appears in lists that are not yet processed by the ligaturing and kerning
4452 steps of the program.
4453
4454 |main_control| inserts these, and they are later converted to
4455 |subtype_normal| by |new_ligkern|.
4456
4457 */
4458
4459 quarterword norm_min(int h)
4460 {
4461 if (h <= 0)
4462 return 1;
4463 else if (h >= 255)
4464 return 255;
4465 else
4466 return (quarterword) h;
4467 }
4468
4469 halfword new_char(int f, int c)
4470 {
4471 halfword p;
4472 p = new_glyph_node();
4473 set_to_character(p);
4474 font(p) = f;
4475 character(p) = c;
4476 lang_data(p) = make_lang_data(uc_hyph_par, cur_lang_par, left_hyphen_min_par, right_hyphen_min_par);
4477 return p;
4478 }
4479
4480 /*tex
4481
4482 Left and right ghost glyph nodes are the result of \.{\\leftghost} and
4483 \.{\\rightghost}, respectively. They are going to be removed by
4484 |new_ligkern|, at the end of which they are no longer needed.
4485
4486 Here are a few handy helpers used by the list output routines. The yoffset
4487 has some history but we now give some control over its treatment:
4488
4489 0: what we had before
4490 1: compensate height and depth
4491 2: compensate height and depth, take max
4492 3: we keep height and depth
4493
4494 The modes are controlled by a variable because we need to retain downward
4495 compatibility.
4496
4497 */
4498
4499 scaled glyph_width(halfword p)
4500 {
4501 scaled w = char_width(font(p), character(p));
4502 return w;
4503 }
4504
4505 scaled glyph_height(halfword p)
4506 {
4507 scaled h = char_height(font(p), character(p));
4508 scaled y = y_displace(p);
4509 if ((glyph_dimensions_par == 0) || (glyph_dimensions_par == 1) || (glyph_dimensions_par == 2 && y > 0))
4510 h += y;
4511 if (h < 0)
4512 h = 0;
4513 return h;
4514 }
4515
4516 scaled glyph_depth(halfword p) /* not used */
4517 {
4518 scaled d = char_depth(font(p), character(p));
4519 scaled y = y_displace(p);
4520 if ((glyph_dimensions_par == 0 && y > 0) || (glyph_dimensions_par == 1) || (glyph_dimensions_par == 2 && y < 0))
4521 d -= y;
4522 if (d < 0)
4523 d = 0;
4524 return d;
4525 }
4526
4527 /*tex
4528
4529 A |disc_node|, which occurs only in horizontal lists, specifies a
4530 ``dis\-cretion\-ary'' line break. If such a break occurs at node |p|, the
4531 text that starts at |pre_break(p)| will precede the break, the text that
4532 starts at |post_break(p)| will follow the break, and text that appears in
4533 |no_break(p)| nodes will be ignored. For example, an ordinary discretionary
4534 hyphen, indicated by `\.{\\-}', yields a |disc_node| with |pre_break|
4535 pointing to a |char_node| containing a hyphen, |post_break=null|, and
4536 |no_break=null|.
4537
4538 If |subtype(p)=automatic_disc|, the |ex_hyphen_penalty| will be charged for
4539 this break. Otherwise the |hyphen_penalty| will be charged. The texts will
4540 actually be substituted into the list by the line-breaking algorithm if it
4541 decides to make the break, and the discretionary node will disappear at that
4542 time; thus, the output routine sees only discretionaries that were not
4543 chosen.
4544
4545 */
4546
4547 halfword new_disc(void)
4548 {
4549 halfword p = new_node(disc_node, 0);
4550 disc_penalty(p) = hyphen_penalty_par;
4551 return p;
4552 }
4553
4554 /*
4555
4556 A |whatsit_node| is a wild card reserved for extensions to \TeX. The
4557 |subtype| field in its first word says what `\\{whatsit}' it is, and
4558 implicitly determines the node size (which must be 2 or more) and the format
4559 of the remaining words. When a |whatsit_node| is encountered in a list,
4560 special actions are invoked; knowledgeable people who are careful not to mess
4561 up the rest of \TeX\ are able to make \TeX\ do new things by adding code at
4562 the end of the program. For example, there might be a `\TeX nicolor'
4563 extension to specify different colors of ink, and the whatsit node might
4564 contain the desired parameters.
4565
4566 The present implementation of \TeX\ treats the features associated with
4567 `\.{\\write}' and `\.{\\special}' as if they were extensions, in order to
4568 illustrate how such routines might be coded. We shall defer further
4569 discussion of extensions until the end of this program.
4570
4571 A |math_node|, which occurs only in horizontal lists, appears before and
4572 after mathematical formulas. The |subtype| field is |before| before the
4573 formula and |after| after it. There is a |surround| field, which represents
4574 the amount of surrounding space inserted by \.{\\mathsurround}.
4575
4576 */
4577
4578 halfword new_math(scaled w, int s)
4579 {
4580 halfword p = new_node(math_node, s);
4581 surround(p) = w;
4582 return p;
4583 }
4584
4585 /*tex
4586
4587 \TeX\ makes use of the fact that |hlist_node|, |vlist_node|, |rule_node|,
4588 |ins_node|, |mark_node|, |adjust_node|, |disc_node|, |whatsit_node|, and
4589 |math_node| are at the low end of the type codes, by permitting a break at
4590 glue in a list if and only if the |type| of the previous node is less than
4591 |math_node|. Furthermore, a node is discarded after a break if its type is
4592 |math_node| or~more.
4593
4594 A |glue_node| represents glue in a list. However, it is really only a pointer
4595 to a separate glue specification, since \TeX\ makes use of the fact that many
4596 essentially identical nodes of glue are usually present. If |p| points to a
4597 |glue_node|, |glue_ptr(p)| points to another packet of words that specify the
4598 stretch and shrink components, etc.
4599
4600 Glue nodes also serve to represent leaders; the |subtype| is used to
4601 distinguish between ordinary glue (which is called |normal|) and the three
4602 kinds of leaders (which are called |a_leaders|, |c_leaders|, and
4603 |x_leaders|). The |leader_ptr| field points to a rule node or to a box node
4604 containing the leaders; it is set to |null| in ordinary glue nodes.
4605
4606 Many kinds of glue are computed from \TeX's ``skip'' parameters, and it is
4607 helpful to know which parameter has led to a particular glue node. Therefore
4608 the |subtype| is set to indicate the source of glue, whenever it originated
4609 as a parameter. We will be defining symbolic names for the parameter numbers
4610 later (e.g., |line_skip_code=0|, |baseline_skip_code=1|, etc.); it suffices
4611 for now to say that the |subtype| of parametric glue will be the same as the
4612 parameter number, plus~one.
4613
4614 In math formulas there are two more possibilities for the |subtype| in a glue
4615 node: |mu_glue| denotes an \.{\\mskip} (where the units are scaled \.{mu}
4616 instead of scaled \.{pt}); and |cond_math_glue| denotes the `\.{\\nonscript}'
4617 feature that cancels the glue node immediately following if it appears in a
4618 subscript.
4619
4620 A glue specification has a halfword reference count in its first word,
4621 representing |null| plus the number of glue nodes that point to it (less
4622 one). Note that the reference count appears in the same position as the
4623 |link| field in list nodes; this is the field that is initialized to |null|
4624 when a node is allocated, and it is also the field that is flagged by
4625 |empty_flag| in empty nodes.
4626
4627 Glue specifications also contain three |scaled| fields, for the |width|,
4628 |stretch|, and |shrink| dimensions. Finally, there are two one-byte fields
4629 called |stretch_order| and |shrink_order|; these contain the orders of
4630 infinity (|normal|, |sfi|, |fil|, |fill|, or |filll|) corresponding to the
4631 stretch and shrink values.
4632
4633 Here is a function that returns a pointer to a copy of a glue spec. The
4634 reference count in the copy is |null|, because there is assumed to be exactly
4635 one reference to the new specification.
4636
4637 */
4638
4639 halfword new_spec(halfword q)
4640 {
4641 if (q == null) {
4642 return copy_node(zero_glue);
4643 } else if (type(q) == glue_spec_node) {
4644 return copy_node(q);
4645 } else if (type(q) == glue_node) {
4646 halfword p = copy_node(zero_glue);
4647 width(p) = width(q);
4648 stretch(p) = stretch(q);
4649 shrink(p) = shrink(q);
4650 stretch_order(p) = stretch_order(q);
4651 shrink_order(p) = shrink_order(q);
4652 return p;
4653 } else {
4654 /*tex Alternatively we can issue a warning. */
4655 return copy_node(zero_glue);
4656 }
4657 }
4658
4659 /*tex
4660
4661 And here's a function that creates a glue node for a given parameter
4662 identified by its code number; for example, |new_param_glue(line_skip_code)|
4663 returns a pointer to a glue node for the current \.{\\lineskip}.
4664
4665 */
4666
4667 halfword new_param_glue(int n)
4668 {
4669 halfword p = new_node(glue_node, n + 1);
4670 halfword q = glue_par(n);
4671 width(p) = width(q);
4672 stretch(p) = stretch(q);
4673 shrink(p) = shrink(q);
4674 stretch_order(p) = stretch_order(q);
4675 shrink_order(p) = shrink_order(q);
4676 return p;
4677 }
4678
4679 /*tex
4680
4681 Glue nodes that are more or less anonymous are created by |new_glue|, whose
4682 argument points to a glue specification.
4683
4684 */
4685
4686 halfword new_glue(halfword q)
4687 {
4688 halfword p = new_node(glue_node, normal);
4689 width(p) = width(q);
4690 stretch(p) = stretch(q);
4691 shrink(p) = shrink(q);
4692 stretch_order(p) = stretch_order(q);
4693 shrink_order(p) = shrink_order(q);
4694 return p;
4695 }
4696
4697 /*tex
4698
4699 Still another subroutine is needed: This one is sort of a combination of
4700 |new_param_glue| and |new_glue|. It creates a glue node for one of the
4701 current glue parameters, but it makes a fresh copy of the glue specification,
4702 since that specification will probably be subject to change, while the
4703 parameter will stay put.
4704
4705 The global variable |temp_ptr| is set to the address of the new spec.
4706
4707 */
4708
4709 halfword new_skip_param(int n)
4710 {
4711 halfword p = new_node(glue_node, n + 1);
4712 halfword q = glue_par(n);
4713 width(p) = width(q);
4714 stretch(p) = stretch(q);
4715 shrink(p) = shrink(q);
4716 stretch_order(p) = stretch_order(q);
4717 shrink_order(p) = shrink_order(q);
4718 return p;
4719 }
4720
4721 /*tex
4722
4723 A |kern_node| has a |width| field to specify a (normally negative) amount of
4724 spacing. This spacing correction appears in horizontal lists between letters
4725 like A and V when the font designer said that it looks better to move them
4726 closer together or further apart. A kern node can also appear in a vertical
4727 list, when its `|width|' denotes additional spacing in the vertical
4728 direction. The |subtype| is either |normal| (for kerns inserted from font
4729 information or math mode calculations) or |explicit| (for kerns inserted from
4730 \.{\\kern} and \.{\\/} commands) or |acc_kern| (for kerns inserted from
4731 non-math accents) or |mu_glue| (for kerns inserted from \.{\\mkern}
4732 specifications in math formulas).
4733
4734 The |new_kern| function creates a kern node having a given width.
4735
4736 */
4737
4738 halfword new_kern(scaled w)
4739 {
4740 halfword p = new_node(kern_node, normal);
4741 width(p) = w;
4742 return p;
4743 }
4744
4745 /*tex
4746
4747 A |penalty_node| specifies the penalty associated with line or page breaking,
4748 in its |penalty| field. This field is a fullword integer, but the full range
4749 of integer values is not used: Any penalty |>=10000| is treated as infinity,
4750 and no break will be allowed for such high values. Similarly, any penalty
4751 |<=-10000| is treated as negative infinity, and a break will be forced.
4752
4753 Anyone who has been reading the last few sections of the program will be able
4754 to guess what comes next.
4755
4756 */
4757
4758 halfword new_penalty(int m, int s)
4759 {
4760 halfword p = new_node(penalty_node, 0);
4761 penalty(p) = m;
4762 subtype(p) = s;
4763 return p;
4764 }
4765
4766 /*tex
4767
4768 You might think that we have introduced enough node types by now. Well,
4769 almost, but there is one more: An |unset_node| has nearly the same format as
4770 an |hlist_node| or |vlist_node|; it is used for entries in \.{\\halign} or
4771 \.{\\valign} that are not yet in their final form, since the box dimensions
4772 are their ``natural'' sizes before any glue adjustment has been made. The
4773 |glue_set| word is not present; instead, we have a |glue_stretch| field,
4774 which contains the total stretch of order |glue_order| that is present in the
4775 hlist or vlist being boxed. Similarly, the |shift_amount| field is replaced
4776 by a |glue_shrink| field, containing the total shrink of order |glue_sign|
4777 that is present. The |subtype| field is called |span_count|; an unset box
4778 typically contains the data for |qo(span_count)+1| columns. Unset nodes will
4779 be changed to box nodes when alignment is completed.
4780
4781 In fact, there are still more types coming. When we get to math formula
4782 processing we will see that a |style_node| has |type=14|; and a number of
4783 larger type codes will also be defined, for use in math mode only.
4784
4785 Warning: If any changes are made to these data structure layouts, such as
4786 changing any of the node sizes or even reordering the words of nodes, the
4787 |copy_node_list| procedure and the memory initialization code below may have
4788 to be changed. Such potentially dangerous parts of the program are listed in
4789 the index under `data structure assumptions'. However, other references to
4790 the nodes are made symbolically in terms of the \.{WEB} macro definitions
4791 above, so that format changes will leave \TeX's other algorithms intact.
4792
4793 */
4794
4795 halfword make_local_par_node(int mode)
4796 {
4797 int callback_id;
4798 halfword q;
4799 halfword p = new_node(local_par_node,mode);
4800 local_pen_inter(p) = local_inter_line_penalty_par;
4801 local_pen_broken(p) = local_broken_penalty_par;
4802 if (local_left_box_par != null) {
4803 q = copy_node_list(local_left_box_par);
4804 local_box_left(p) = q;
4805 local_box_left_width(p) = width(local_left_box_par);
4806 }
4807 if (local_right_box_par != null) {
4808 q = copy_node_list(local_right_box_par);
4809 local_box_right(p) = q;
4810 local_box_right_width(p) = width(local_right_box_par);
4811 }
4812 local_par_dir(p) = par_direction_par;
4813 /*tex Callback with node passed: */
4814 callback_id = callback_defined(insert_local_par_callback);
4815 if (callback_id > 0) {
4816 /*tex Todo: use general mechanism/wrapper. */
4817 int sfix = lua_gettop(Luas);
4818 if (!get_callback(Luas, callback_id)) {
4819 lua_settop(Luas, sfix);
4820 } else {
4821 int i;
4822 nodelist_to_lua(Luas, p);
4823 lua_push_local_par_mode(Luas,mode)
4824 /*tex 2 arg, 0 result */
4825 i = lua_pcall(Luas, 2, 0, 0);
4826 if (i != 0) {
4827 lua_gc(Luas, LUA_GCCOLLECT, 0);
4828 Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1));
4829 }
4830 lua_settop(Luas, sfix);
4831 }
4832 }
4833 return p;
4834 }