6 #pragma warning(disable:4115) // kill rpcasync.h complaint
8 #define MYLIBAPI __declspec(dllexport)
11 #pragma warning(disable:4131) // old style declarator
12 #pragma warning(disable:4135) // conversion between different integral types
13 #pragma warning(disable:4127) // conditional expression is constant
21 #pragma warning(disable:4244) /* 96/Jan/10 */
24 void align_peek (void)
27 align_state = 1000000L;
33 while (!(cur_cmd != spacer));
35 if (cur_cmd == no_align)
39 new_save_level(no_align_group);
44 else if (cur_cmd == right_brace)
48 else if ((cur_cmd == car_ret) && (cur_chr == cr_cr_code))
56 /* used in itex.c only */
58 halfword finite_shrink_(halfword p)
62 if (no_shrink_error_yet)
64 no_shrink_error_yet = false;
65 print_err("Infinite glue shrinkage found in a paragraph");
66 help5("The paragraph just ended includes some glue that has",
67 "infinite shrinkability, e.g., `\\hskip 0pt minus 1fil'.",
68 "Such glue doesn't belong there---it allows a paragraph",
69 "of any length to fit on one line. But it's safe to proceed,",
70 "since the offensive shrinkability has been made finite.");
75 shrink_order(q) = normal;
81 void try_break_ (integer pi, small_number break_type)
92 internal_font_number f;
94 bool node_r_stays_active;
97 halfword b; /* current badness */
99 bool artificial_demerits;
103 if (abs(pi)>= inf_penalty)
112 do_all_six(copy_to_cur_active);
114 cur_active_width[1] = active_width[1];
115 cur_active_width[2] = active_width[2];
116 cur_active_width[3] = active_width[3];
117 cur_active_width[4] = active_width[4];
118 cur_active_width[5] = active_width[5];
119 cur_active_width[6] = active_width[6];
126 if (type(r) == delta_node)
128 do_all_six(update_width);
130 cur_active_width[1] = cur_active_width[1] + mem[r + 1].cint;
131 cur_active_width[2] = cur_active_width[2] + mem[r + 2].cint;
132 cur_active_width[3] = cur_active_width[3] + mem[r + 3].cint;
133 cur_active_width[4] = cur_active_width[4] + mem[r + 4].cint;
134 cur_active_width[5] = cur_active_width[5] + mem[r + 5].cint;
135 cur_active_width[6] = cur_active_width[6] + mem[r + 6].cint;
137 prev_prev_r = prev_r;
147 if ((minimum_demerits < awful_bad) && ((old_l != easyline) || (r == active)))
151 no_break_yet = false;
152 do_all_six(set_break_width_to_background);
154 break_width[1] = background[1];
155 break_width[2] = background[2];
156 break_width[3] = background[3];
157 break_width[4] = background[4];
158 break_width[5] = background[5];
159 break_width[6] = background[6];
163 if (break_type > unhyphenated)
166 t = replace_count(cur_p);
168 s = post_break(cur_p);
175 if ((v >= hi_mem_min))
178 break_width[1] = break_width[1] - char_width(f, char_info(f, character(v)));
180 else switch (type(v))
184 f = font(lig_char(v));
185 break_width[1] = break_width[1] - char_width(f, char_info(f, character(lig_char(v))));
193 break_width[1] = break_width[1] - width(v);
199 return; // abort_flag set
207 if ((s >= hi_mem_min))
210 break_width[1] = break_width[1] + char_width(f, char_info(f, character(s)));
216 f = font(lig_char(s));
217 break_width[1] = break_width[1] + char_width(f, char_info(f, character(lig_char(s))));
225 break_width[1] = break_width[1] + width(s);
231 return; // abort_flag set
239 break_width[1] = break_width[1] + disc_width;
241 if (post_break(cur_p) == 0)
247 if ((s >= hi_mem_min))
255 break_width[1] = break_width[1] - width(v);
256 break_width[2 + stretch_order(v)] = break_width[2 + stretch_order(v)] - stretch(v);
257 break_width[6] = break_width[6] - shrink(v);
266 break_width[1] = break_width[1] - width(s);
270 if (subtype(s) != explicit)
273 break_width[1] = break_width[1] - width(s);
286 if (type(prev_r) == delta_node)
288 do_all_six(convert_to_break_width);
290 mem[prev_r + 1].cint = mem[prev_r + 1].cint - cur_active_width[1] + break_width[1];
291 mem[prev_r + 2].cint = mem[prev_r + 2].cint - cur_active_width[2] + break_width[2];
292 mem[prev_r + 3].cint = mem[prev_r + 3].cint - cur_active_width[3] + break_width[3];
293 mem[prev_r + 4].cint = mem[prev_r + 4].cint - cur_active_width[4] + break_width[4];
294 mem[prev_r + 5].cint = mem[prev_r + 5].cint - cur_active_width[5] + break_width[5];
295 mem[prev_r + 6].cint = mem[prev_r + 6].cint - cur_active_width[6] + break_width[6];
298 else if (prev_r == active)
300 do_all_six(store_break_width);
302 active_width[1] = break_width[1];
303 active_width[2] = break_width[2];
304 active_width[3] = break_width[3];
305 active_width[4] = break_width[4];
306 active_width[5] = break_width[5];
307 active_width[6] = break_width[6];
312 q = get_node(delta_node_size);
314 type(q) = delta_node;
316 do_all_six(new_delta_to_break_width);
318 mem[q + 1].cint = break_width[1]- cur_active_width[1];
319 mem[q + 2].cint = break_width[2]- cur_active_width[2];
320 mem[q + 3].cint = break_width[3]- cur_active_width[3];
321 mem[q + 4].cint = break_width[4]- cur_active_width[4];
322 mem[q + 5].cint = break_width[5]- cur_active_width[5];
323 mem[q + 6].cint = break_width[6]- cur_active_width[6];
326 prev_prev_r = prev_r;
330 if (abs(adj_demerits) >= awful_bad - minimum_demerits)
331 minimum_demerits = awful_bad - 1;
333 minimum_demerits = minimum_demerits + abs(adj_demerits);
335 for (fit_class = very_loose_fit; fit_class <= tight_fit; fit_class++)
337 if (minimal_demerits[fit_class] <= minimum_demerits)
339 q = get_node(passive_node_size);
342 cur_break(q) = cur_p;
345 serial(q) = pass_number;
347 prev_break(q) = best_place[fit_class];
348 q = get_node(active_node_size);
349 break_node(q) = passive;
350 line_number(q) = best_pl_line[fit_class] + 1;
351 fitness(q) = fit_class;
352 type(q) = break_type;
353 total_demerits(q) = minimal_demerits[fit_class];
358 if (tracing_paragraphs > 0)
361 print_int(serial(passive));
362 print_string(": line ");
363 print_int(line_number(q) - 1);
365 print_int(fit_class);
367 if (break_type == hyphenated)
371 print_int(total_demerits(q));
372 print_string(" -> @@");
374 if (prev_break(passive) == 0)
377 print_int(serial(prev_break(passive)));
382 minimal_demerits[fit_class] = awful_bad;
385 minimum_demerits = 1073741823L; /* 2^30 - 1 */
389 q = get_node(delta_node_size);
391 type(q) = delta_node;
393 do_all_six(new_delta_from_break_width);
395 mem[q + 1].cint = cur_active_width[1] - break_width[1];
396 mem[q + 2].cint = cur_active_width[2] - break_width[2];
397 mem[q + 3].cint = cur_active_width[3] - break_width[3];
398 mem[q + 4].cint = cur_active_width[4] - break_width[4];
399 mem[q + 5].cint = cur_active_width[5] - break_width[5];
400 mem[q + 6].cint = cur_active_width[6] - break_width[6];
403 prev_prev_r = prev_r;
413 line_width = second_width;
414 old_l = max_halfword - 1; /*262142L*/ /* 2^18 - 2 ? */
420 if (l > last_special_line)
421 line_width = second_width;
422 else if (par_shape_ptr == 0)
423 line_width = first_width;
425 line_width = mem[par_shape_ptr + 2 * l].cint;
431 artificial_demerits = false;
432 shortfall = line_width - cur_active_width[1];
435 if ((cur_active_width[3] != 0) || (cur_active_width[4] != 0) || (cur_active_width[5] != 0))
438 fit_class = decent_fit;
442 if (shortfall > 7230584L)
443 if (cur_active_width[2] < 1663497L)
446 fit_class = very_loose_fit;
450 b = badness(shortfall, cur_active_width[2]);
454 fit_class = very_loose_fit;
456 fit_class = loose_fit;
458 fit_class = decent_fit;
463 if (- (integer) shortfall > cur_active_width[6])
466 b = badness(- (integer) shortfall, cur_active_width[6]);
469 fit_class = tight_fit;
471 fit_class = decent_fit;
474 if ((b > inf_bad) || (pi == eject_penalty))
476 if (final_pass && (minimum_demerits == awful_bad) && (link(r) == active) && (prev_r == active))
477 artificial_demerits = true;
478 else if (b > threshold)
481 node_r_stays_active = false;
490 node_r_stays_active = true;
493 if (artificial_demerits)
497 d = line_penalty + b;
507 else if (pi > -10000)
510 if ((break_type == hyphenated) && (type(r) == hyphenated))
512 d = d + double_hyphen_demerits;
514 d = d + final_hyphen_demerits;
516 if (abs(toint(fit_class)- toint(fitness(r))) > 1)
517 d = d + adj_demerits;
521 if (tracing_paragraphs > 0)
523 if (printed_node != cur_p)
528 short_display(link(printed_node));
531 save_link = link(cur_p);
534 short_display(link(printed_node));
535 link(cur_p) = save_link;
538 printed_node = cur_p;
545 else if (type(cur_p) != glue_node)
547 if (type(cur_p) == penalty_node)
548 print_esc("penalty");
549 else if (type(cur_p) == disc_node)
550 print_esc("discretionary");
551 else if (type(cur_p) == kern_node)
557 print_string(" via @@");
559 if (break_node(r) == 0)
562 print_int(serial(break_node(r)));
575 if (artificial_demerits)
582 d = d + total_demerits(r);
584 if (d <= minimal_demerits[fit_class])
586 minimal_demerits[fit_class] = d;
587 best_place[fit_class] = break_node(r);
588 best_pl_line[fit_class] = l;
590 if (d < minimum_demerits)
591 minimum_demerits = d;
594 if (node_r_stays_active)
597 link(prev_r) = link(r);
598 free_node(r, active_node_size);
600 if (prev_r == active)
604 if (type(r) == delta_node)
606 do_all_six(update_active);
607 do_all_six(copy_to_cur_active);
609 active_width[1] = active_width[1] + mem[r + 1].cint;
610 active_width[2] = active_width[2] + mem[r + 2].cint;
611 active_width[3] = active_width[3] + mem[r + 3].cint;
612 active_width[4] = active_width[4] + mem[r + 4].cint;
613 active_width[5] = active_width[5] + mem[r + 5].cint;
614 active_width[6] = active_width[6] + mem[r + 6].cint;
615 cur_active_width[1] = active_width[1];
616 cur_active_width[2] = active_width[2];
617 cur_active_width[3] = active_width[3];
618 cur_active_width[4] = active_width[4];
619 cur_active_width[5] = active_width[5];
620 cur_active_width[6] = active_width[6];
622 link(active) = link(r);
623 free_node(r, delta_node_size);
626 else if (type(prev_r) == delta_node)
632 do_all_six(downdate_width);
634 cur_active_width[1] = cur_active_width[1] - mem[prev_r + 1].cint;
635 cur_active_width[2] = cur_active_width[2] - mem[prev_r + 2].cint;
636 cur_active_width[3] = cur_active_width[3] - mem[prev_r + 3].cint;
637 cur_active_width[4] = cur_active_width[4] - mem[prev_r + 4].cint;
638 cur_active_width[5] = cur_active_width[5] - mem[prev_r + 5].cint;
639 cur_active_width[6] = cur_active_width[6] - mem[prev_r + 6].cint;
641 link(prev_prev_r) = active;
642 free_node(prev_r, delta_node_size);
643 prev_r = prev_prev_r;
645 else if (type(r) == delta_node)
647 do_all_six(update_width);
648 do_all_six(combine_two_deltas);
650 cur_active_width[1] = cur_active_width[1] + mem[r + 1].cint;
651 cur_active_width[2] = cur_active_width[2] + mem[r + 2].cint;
652 cur_active_width[3] = cur_active_width[3] + mem[r + 3].cint;
653 cur_active_width[4] = cur_active_width[4] + mem[r + 4].cint;
654 cur_active_width[5] = cur_active_width[5] + mem[r + 5].cint;
655 cur_active_width[6] = cur_active_width[6] + mem[r + 6].cint;
656 mem[prev_r + 1].cint = mem[prev_r + 1].cint + mem[r + 1].cint;
657 mem[prev_r + 2].cint = mem[prev_r + 2].cint + mem[r + 2].cint;
658 mem[prev_r + 3].cint = mem[prev_r + 3].cint + mem[r + 3].cint;
659 mem[prev_r + 4].cint = mem[prev_r + 4].cint + mem[r + 4].cint;
660 mem[prev_r + 5].cint = mem[prev_r + 5].cint + mem[r + 5].cint;
661 mem[prev_r + 6].cint = mem[prev_r + 6].cint + mem[r + 6].cint;
663 link(prev_r) = link(r);
664 free_node(r, delta_node_size);
672 if (cur_p == printed_node)
674 if (type(cur_p) == disc_node)
676 t = replace_count(cur_p);
681 printed_node = link(printed_node);
685 /* must exit here, there are no internal return - except for confusion */
686 /* savedbadness = b; */ /* 96/Feb/9 - for test in itex.c */
688 /* end of the old tex5.c here */
690 void post_line_break_(integer final_widow_penalty)
694 bool post_disc_break;
701 q = break_node(best_bet);
708 next_break(r) = cur_p;
713 cur_line = prev_graf + 1;
717 q = cur_break(cur_p);
719 post_disc_break = false;
722 if (type(q) == glue_node)
724 delete_glue_ref(glue_ptr(q));
725 glue_ptr(q) = right_skip;
726 subtype(q) = right_skip_code + 1;
727 add_glue_ref(right_skip);
732 if (type(q) == disc_node)
734 t = replace_count(q);
751 flush_node_list(link(q));
752 replace_count(q) = 0;
755 if (post_break(q) != 0)
765 post_disc_break = true;
768 if (pre_break(q) != 0)
783 else if ((type(q) == math_node) || (type(q) == kern_node))
794 r = new_param_glue(right_skip_code);
806 r = new_param_glue(left_skip_code);
811 if (cur_line > last_special_line)
813 cur_width = second_width;
814 cur_indent = second_indent;
816 else if (par_shape_ptr == 0)
818 cur_width = first_width;
819 cur_indent = first_indent;
823 cur_width = mem[par_shape_ptr + 2 * cur_line].cint;
824 cur_indent = mem[par_shape_ptr + 2 * cur_line - 1].cint;
827 adjust_tail = adjust_head;
828 just_box = hpack(q, cur_width, 0);
829 shift_amount(just_box) = cur_indent;
830 append_to_vlist(just_box);
832 if (adjust_head != adjust_tail)
834 link(tail) = link(adjust_head);
840 if (cur_line + 1 != best_line)
842 pen = inter_line_penalty;
844 if (cur_line == prev_graf + 1)
845 pen = pen + club_penalty;
847 if (cur_line + 2 == best_line)
848 pen = pen + final_widow_penalty;
851 pen = pen + broken_penalty;
855 r = new_penalty(pen);
862 cur_p = next_break(cur_p);
865 if (!post_disc_break)
873 if (q == cur_break(cur_p))
876 if ((q >= hi_mem_min))
879 if (non_discardable(q))
882 if (type(q) == kern_node)
892 flush_node_list(link(temp_head));
897 while (!(cur_p == 0));
899 if ((cur_line != best_line) || (link(temp_head) != 0))
901 confusion("line breaking");
902 return; // abort_flag set
905 prev_graf = best_line - 1;
907 /* Reconstitute ligatures during hyphenation pass */
909 small_number reconstitute_(small_number j, small_number n, halfword bchar, halfword hchar)
928 ligature_present = init_lig;
931 if (ligature_present)
934 while(p != 0) /* 94/Mar/22 BUG FIX */
936 append_charnode_to_t(character(p));
940 else if (cur_l < 256)
942 append_charnode_to_t(cur_l);
949 if (cur_l == non_char)
953 if (k == non_address) /* i.e. 0 --- 96/Jan/15 */
956 q = font_info[k].qqqq;
960 q = char_info(hf, cur_l);
962 if (char_tag(q) != lig_tag)
965 k = lig_kern_start(hf, q);
966 q = font_info[k].qqqq;
968 if (skip_byte(q) > stop_flag)
970 k = lig_kern_restart(hf, q);
971 q = font_info[k].qqqq;
974 if (cur_rh < non_char)
981 if (next_char(q) == test_char)
982 if (skip_byte(q) <= 128)
983 if (cur_rh < non_char)
988 goto lab22; /* goto continue; */
992 if (hchar < non_char)
999 if (op_byte(q) < kern_flag)
1001 if (cur_l == non_char)
1011 pause_for_instructions();
1020 cur_l = rem_byte(q);
1021 ligature_present = true;
1028 cur_r = rem_byte(q);
1031 character(lig_stack) = cur_r;
1034 lig_stack = new_lig_item(cur_r);
1041 list_ptr(lig_stack) = p;
1042 character(p) = hu[j + 1];
1051 cur_r = rem_byte(q);
1053 lig_stack = new_lig_item(cur_r);
1054 link(lig_stack) = p;
1061 if (ligature_present)
1063 p = new_ligature(hf, cur_l, mem[cur_q].hh.v.RH);
1071 if (lig_stack == 0){
1074 } */ /* removed 99/Jan/6 */
1075 mem[cur_q].hh.v.RH = p;
1077 ligature_present = false;
1080 cur_l = rem_byte(q);
1081 ligature_present = true;
1087 cur_l = rem_byte(q);
1088 ligature_present = true;
1090 if (lig_stack != 0) /* BUG FIX */
1092 if (mem[lig_stack + 1].hh.v.RH != 0) /* l.17828 ? */
1094 mem[t].hh.v.RH = mem[lig_stack + 1].hh.v.RH;
1099 lig_stack = mem[p].hh.v.RH;
1101 if (lig_stack == 0) /* if lig_stack=null ? */
1113 cur_r = mem[lig_stack].hh.b1;
1119 append_charnode_to_t(cur_r);
1128 if (op_byte(q) != 7)
1134 w = char_kern(hf, q);
1138 if (q.b0 >= stop_flag)
1139 if (cur_rh == non_char)
1147 k = k + skip_byte(q) + 1;
1148 q = font_info[k].qqqq;
1155 link(t) = new_kern(w);
1160 if (lig_stack != 0) /* l.17841 */
1163 cur_l = character(lig_stack);
1164 ligature_present = true;
1171 /* #pragma optimize ("g", off) */ /* not needed for MSVC it seems ... */
1173 void hyphenate (void)
1177 int l; /* 95/Jan/7 */
1180 halfword major_tail, minor_tail;
1182 int c; /* 95/Jan/7 */
1184 /* integer r_count; */
1185 int r_count; /* 95/Jan/7 */
1193 for (j = 0; j <= hn; j++)
1200 for (j = 2; j <= hn; j++)
1201 h = (h + h + hc[j]) % hyphen_prime;
1213 if (length(k) == hn)
1220 if (str_pool[u] < hc[j])
1223 if (str_pool[u] > hc[j])
1235 hyf[mem[s].hh.v.LH] = 1;
1251 if (trie_trc[cur_lang + 1] != cur_lang)
1258 for (j = 0; j <= hn - rhyf + 1; j++)
1260 z = trie_trl[cur_lang + 1] + hc[j];
1263 while (hc[l] == trie_trc[z])
1265 if (trie_tro[z] != min_trie_op)
1271 v = v + op_start[cur_lang];
1272 i = l - hyf_distance[v];
1274 if (hyf_num[v] > hyf[i])
1279 while(!(v == min_trie_op));
1283 z = trie_trl[z] + hc[l];
1287 for (j = 0; j <= lhyf - 1; j++)
1290 for (j = 0; j <= rhyf - 1; j++)
1293 for (j = lhyf; j <= hn - rhyf; j++)
1305 if ((ha >= hi_mem_min))
1312 hu[0] = character(ha);
1314 else if (type(ha) == ligature_node)
1315 if (font(lig_char(ha)) != hf)
1319 init_list = lig_ptr(ha);
1321 init_lft = (subtype(ha) > 1);
1322 hu[0] = character(lig_char(ha));
1331 free_node(ha, small_node_size);
1335 if (!(r >= hi_mem_min))
1336 if (type(r) == ligature_node)
1348 while (link(s) != ha)
1365 j = reconstitute(j, hn, bchar, hyf_char) + 1;
1367 if (hyphen_passed == 0)
1369 link(s) = link(hold_head);
1371 while (link(s) != 0) /* l.17903 */
1374 if (odd(hyf[j - 1]))
1377 hyphen_passed = j - 1;
1378 link(hold_head) = 0;
1382 if (hyphen_passed > 0)
1385 r = get_node(small_node_size);
1386 link(r) = link(hold_head);
1387 type(r) = disc_node;
1391 while (mem[major_tail].hh.v.RH != 0)
1393 major_tail = link(major_tail);
1401 hyf_node = new_character(hf, hyf_char);
1408 free_avail(hyf_node);
1413 l = reconstitute(l, i, font_bchar[hf], non_char) + 1;
1415 if (link(hold_head) != 0) /* BUG FIX ??? */
1417 if (minor_tail == 0)
1418 pre_break(r) = link(hold_head);
1420 link(minor_tail) = link(hold_head);
1422 minor_tail = link(hold_head);
1424 while (link(minor_tail) != 0) /* BUG FIX */
1425 minor_tail = link(minor_tail);
1429 if (hyf_node != 0) /* if hyf_node<>null then l.17956 */
1440 if (bchar_label[hf] != non_address) /* i.e. 0 --- 96/Jan/15 */
1452 l = reconstitute(l, hn, bchar, 256) + 1;
1456 hu[c_loc] = c; /* c may be used ... */
1460 if (link(hold_head) != 0) /* BUG FIX */
1462 if (minor_tail == 0) /* begin if minor_tail=null then */
1463 post_break(r) = link(hold_head);
1465 link(minor_tail) = link(hold_head);
1467 minor_tail = link(hold_head);
1469 while (link(minor_tail) != 0) /* ??? */
1470 minor_tail = link(minor_tail);
1477 j = reconstitute(j, hn, bchar, non_char) + 1;
1478 link(major_tail) = link(hold_head);
1480 while (mem[major_tail].hh.v.RH != 0)
1482 major_tail = link(major_tail);
1497 replace_count(r) = r_count;
1501 hyphen_passed = j - 1;
1502 link(hold_head) = 0;
1504 while(!(! odd(hyf[j - 1])));
1509 flush_list(init_list);
1511 /* #pragma optimize ("g", off) */ /* not needed for MSVC it seems ... */
1512 /* used only in itex.c */
1514 void new_hyph_exceptions (void)
1516 /* small_number n; */ /* in 3.141 */
1518 /* small_number j; */ /* in 3.141 */
1553 if (lc_code(cur_chr) == 0)
1555 print_err("Not a letter");
1556 help2("Letters in \\hyphenation words must have \\lccode>0.",
1557 "Proceed; I'll ignore the character I just read.");
1563 hc[n] = lc_code(cur_chr);
1572 cur_cmd = char_given;
1587 for (j = 1; j <= n; j++)
1589 h = (h + h + hc[j]) % hyphen_prime;
1595 if (hyph_count == hyphen_prime)
1597 overflow("exception dictionary", hyphen_prime); /* exception dictionary - NOT DYNAMIC */
1598 /* not dynamic ---- but can be set -e=... from command line in ini-TeX */
1599 return; // abort_flag set
1604 while (hyph_word[h] != 0)
1608 if (length(k) < length(s))
1611 if (length(k) > length(s))
1619 if (str_pool[u] < str_pool[v])
1622 if (str_pool[u] > str_pool[v])
1628 while(!(u == str_start[k + 1]));
1647 if (cur_cmd == right_brace)
1657 print_err("Improper ");
1658 print_esc("hyphenation");
1659 print_string(" will be flushed");
1660 help2("Hyphenation exceptions must contain only letters",
1661 "and hyphens. But continue; I'll forgive and forget.");
1665 } /* end of switch */
1669 halfword prune_page_top_(halfword p)
1675 link(temp_head) = p;
1684 q = new_skip_param(split_top_skip_code);
1688 if (width(temp_ptr) > height(p))
1689 width(temp_ptr) = width(temp_ptr) - height(p);
1691 width(temp_ptr) = 0;
1720 confusion("pruning");
1721 return 0; // abort_flag set
1726 return link(temp_head);
1729 halfword vert_break_(halfword p, scaled h, scaled d)
1736 halfword best_place;
1738 /* small_number t; */
1739 int t; /* 95/Jan/7 */
1742 least_cost = awful_bad;
1743 do_all_six(set_height_zero);
1745 active_width[1] = 0;
1746 active_width[2] = 0;
1747 active_width[3] = 0;
1748 active_width[4] = 0;
1749 active_width[5] = 0;
1750 active_width[6] = 0;
1758 else switch(type(p))
1764 cur_height = cur_height + prev_dp + height(p);
1775 if (precedes_break(prev_p))
1806 confusion("vertbreak");
1807 return 0; // abort_flag set
1812 if (pi < inf_penalty)
1815 if ((active_width[3] != 0) || (active_width[4] != 0) || (active_width[5]!= 0))
1818 b = badness(h - cur_height, active_width[2]);
1819 else if (active_width[1] - h > active_width[6])
1822 b = badness(cur_height - h, active_width[6]);
1825 if (pi <= eject_penalty)
1827 else if (b < inf_bad)
1832 if (b <= least_cost)
1836 best_height_plus_depth = cur_height + prev_dp;
1839 if ((b == awful_bad) || (pi <= eject_penalty))
1843 if ((type(p) < glue_node) || (type(p) > kern_node))
1846 if (type(p) == kern_node)
1851 active_width[2 + stretch_order(q)] = active_width[2 + stretch_order(q)] + stretch(q);
1852 active_width[6] = active_width[6] + shrink(q);
1854 if ((shrink_order(q) != normal) && (shrink(q) != 0))
1856 print_err("Infinite glue shrinkage found in box being split");
1857 help4("The box you are \\vsplitting contains some infinitely",
1858 "shrinkable glue, e.g., `\\vss' or `\\vskip 0pt minus 1fil'.",
1859 "Such glue doesn't belong there; but you can safely proceed,",
1860 "since the offensive shrinkability has been made finite.");
1863 shrink_order(r) = normal;
1870 cur_height = cur_height + prev_dp + width(q);
1875 cur_height = cur_height + prev_dp - d;
1885 /* called only from tex7.c */
1887 halfword vsplit_(eight_bits n, scaled h)
1895 if (split_first_mark != 0)
1897 delete_token_ref(split_first_mark);
1898 split_first_mark = 0;
1899 delete_token_ref(split_bot_mark);
1908 if (type(v) != vlist_node)
1911 print_esc("vsplit");
1912 print_string(" needs a ");
1914 help2("The box you are trying to split is an \\hbox.",
1915 "I can't split such a box, so I'll leave it alone.");
1920 q = vert_break(list_ptr(v), h, split_max_depth);
1927 if (type(p) == mark_node)
1928 if (split_first_mark == 0)
1930 split_first_mark = mark_ptr(p);
1931 split_bot_mark = split_first_mark;
1932 token_ref_count(split_first_mark) = token_ref_count(split_first_mark) + 2;
1936 delete_token_ref(split_bot_mark);
1937 split_bot_mark = mark_ptr(p);
1938 add_token_ref(split_bot_mark);
1949 q = prune_page_top(q);
1951 free_node(v, box_node_size);
1956 box(n) = vpackage(q, 0, 1, 1073741823L); /* 2^30 - 1 */
1958 return vpackage(p, h, exactly, split_max_depth);
1961 void print_totals (void)
1963 print_scaled(page_so_far[1]);
1965 if (page_so_far[2] != 0)
1967 print_string(" plus ");
1968 print_scaled(page_so_far[2]);
1972 if (page_so_far[3] != 0)
1974 print_string(" plus ");
1975 print_scaled(page_so_far[3]);
1976 print_string("fil");
1979 if (page_so_far[4] != 0)
1981 print_string(" plus ");
1982 print_scaled(page_so_far[4]);
1983 print_string("fill");
1986 if (page_so_far[5] != 0)
1988 print_string(" plus ");
1989 print_scaled(page_so_far[5]);
1990 print_string("filll");
1993 if (page_so_far[6] != 0)
1995 print_string(" minus ");
1996 print_scaled(page_so_far[6]);
2000 void freeze_page_specs_(small_number s)
2004 page_max_depth = max_depth;
2006 do_all_six(set_page_so_far_zero);
2015 least_page_cost = awful_bad;
2017 if (tracing_pages > 0)
2020 print_nl("%% goal height=");
2021 print_scaled(page_goal);
2022 print_string(", max depth=");
2023 print_scaled(page_max_depth);
2024 end_diagnostic(false);
2029 void box_error_(eight_bits n)
2033 print_nl("The following box has been deleted:");
2035 end_diagnostic(true);
2036 flush_node_list(box(n));
2040 void ensure_vbox_(eight_bits n)
2047 if (type(p) == hlist_node)
2049 print_err("Insertions can only be added to a vbox");
2050 help3("Tut tut: You're trying to \\insert into a",
2051 "\\box register that now contains an \\hbox.",
2052 "Proceed, and I'll discard its present contents.");
2056 /* called only from tex7.c */
2058 void fire_up_(halfword c)
2060 halfword p, q, r, s;
2062 /* unsigned char n; */
2063 unsigned int n; /* 95/Jan/7 */
2065 integer save_vbadness;
2067 halfword save_split_top_skip;
2069 if (type(best_page_break) == penalty_node)
2071 geq_word_define(int_base + output_penalty_code, penalty(best_page_break));
2072 penalty(best_page_break) = inf_penalty;
2075 geq_word_define(int_base + output_penalty_code, inf_penalty);
2080 delete_token_ref(top_mark);
2082 top_mark = bot_mark;
2083 add_token_ref(top_mark);
2084 delete_token_ref(first_mark);
2088 if (c == best_page_break)
2089 best_page_break = 0;
2095 print_string("255 is not void");
2096 help2("You shouldn't use \\box255 except in \\output routines.",
2097 "Proceed, and I'll discard its present contents.");
2101 insert_penalties = 0;
2102 save_split_top_skip = split_top_skip;
2104 if (holding_inserts <= 0)
2106 r = link(page_ins_head);
2108 while (r != page_ins_head)
2110 if (best_ins_ptr(r) != 0)
2116 box(n) = new_null_box();
2118 p = box(n) + list_offset;
2120 while (link(p) != 0)
2123 last_ins_ptr(r) = p;
2135 while (p != best_page_break)
2137 if (type(p) == ins_node)
2139 if (holding_inserts <= 0)
2141 r = link(page_ins_head);
2143 while (subtype(r) != subtype(p))
2146 if (best_ins_ptr(r) == 0)
2151 s = last_ins_ptr(r);
2152 link(s) = ins_ptr(p);
2154 if (best_ins_ptr(r) == p)
2156 if (type(r) == split_up)
2157 if ((broken_ins(r) == p) && (broken_ins(r) != 0))
2159 while (link(s) != broken_ptr(r))
2163 split_top_skip = split_top_ptr(p);
2164 ins_ptr(p) = prune_page_top(broken_ptr(r));
2166 if (ins_ptr(p) != 0)
2168 temp_ptr = vpackage(ins_ptr(p), 0, 1, 1073741823L); /* 2^30 - 1 */
2169 height(p) = height(temp_ptr) + depth(temp_ptr);
2170 free_node(temp_ptr, box_node_size);
2175 best_ins_ptr(r) = 0;
2177 temp_ptr = list_ptr(box(n));
2178 free_node(box(n), box_node_size);
2179 box(n) = vpackage(temp_ptr, 0, 1, 1073741823L); /* 2^30 - 1 */
2183 while (link(s) != 0)
2186 last_ins_ptr(r) = s;
2190 link(prev_p) = link(p);
2197 incr(insert_penalties);
2201 delete_glue_ref(split_top_ptr(p));
2202 free_node(p, ins_node_size);
2208 else if (type(p) == mark_node)
2210 if (first_mark == 0)
2212 first_mark = mark_ptr(p);
2213 add_token_ref(first_mark);
2217 delete_token_ref(bot_mark);
2219 bot_mark = mark_ptr(p);
2220 add_token_ref(bot_mark);
2226 split_top_skip = save_split_top_skip;
2228 if (p != 0) /* if p<>null then l.19730 */
2230 if (link(contrib_head) == 0)
2234 nest[0].tail_field = page_tail;
2236 link(page_tail) = link(contrib_head);
2237 link(contrib_head) = p;
2241 save_vbadness = vbadness;
2245 box(255) = vpackage(link(page_head), best_size, 0, page_max_depth);
2246 vbadness = save_vbadness;
2249 if (last_glue != empty_flag)
2250 delete_glue_ref(last_glue);
2253 page_tail = page_head;
2254 link(page_head) = 0;
2255 last_glue = empty_flag;
2263 link(page_head) = link(hold_head);
2267 r = link(page_ins_head);
2269 while (r != page_ins_head)
2272 free_node(r, page_ins_node_size);
2276 link(page_ins_head) = page_ins_head;
2278 if ((top_mark != 0) && (first_mark == 0))
2280 first_mark = top_mark;
2281 add_token_ref(top_mark);
2284 if (output_routine != 0)
2285 if (dead_cycles >= max_dead_cycles)
2287 print_err("Output loop---");
2288 print_int(dead_cycles);
2289 print_string(" consecutive dead cycles");
2290 help3("I've concluded that your \\output is awry; it never does",
2291 "\\ship_out, so I'm shipping \box255 out myself. Next ",
2292 "increase \\maxdeadcycles if you want me to be more patient!");
2297 output_active = true;
2301 cur_list.aux_field.cint = ignore_depth;
2302 mode_line = - (integer) line;
2303 begin_token_list(output_routine, output_text);
2304 new_save_level(output_group);
2311 if (link(page_head) != 0)
2313 if (link(contrib_head) == 0)
2317 nest[0].tail_field = page_tail;
2319 link(page_tail) = link(contrib_head);
2321 link(contrib_head) = link(page_head);
2322 link(page_head) = 0;
2323 page_tail = page_head;
2330 /* used to continue here with build_page etc in tex6.c */