6 #pragma warning(disable:4115) // kill rpcasync.h complaint
8 #define MYLIBAPI __declspec(dllexport)
13 #pragma warning(disable:4131) // old style declarator
14 #pragma warning(disable:4135) // conversion between different integral types
15 #pragma warning(disable:4127) // conditional expression is constant
23 #pragma warning(disable:4244) /* 96/Jan/10 */
26 void align_peek (void)
29 align_state = 1000000L;
35 while (!(cur_cmd != spacer));
37 if (cur_cmd == no_align)
41 new_save_level(no_align_group);
46 else if (cur_cmd == right_brace)
50 else if ((cur_cmd == car_ret) && (cur_chr == cr_cr_code))
58 /* used in itex.c only */
60 halfword finite_shrink_(halfword p)
64 if (no_shrink_error_yet)
66 no_shrink_error_yet = false;
67 print_err("Infinite glue shrinkage found in a paragraph");
68 help5("The paragraph just ended includes some glue that has",
69 "infinite shrinkability, e.g., `\\hskip 0pt minus 1fil'.",
70 "Such glue doesn't belong there---it allows a paragraph",
71 "of any length to fit on one line. But it's safe to proceed,",
72 "since the offensive shrinkability has been made finite.");
77 shrink_order(q) = normal;
82 void try_break_ (integer pi, small_number breaktype)
93 internal_font_number f;
95 bool noderstaysactive;
98 halfword b; /* current badness */
100 bool artificialdemerits;
113 cur_active_width[1] = active_width[1];
114 cur_active_width[2] = active_width[2];
115 cur_active_width[3] = active_width[3];
116 cur_active_width[4] = active_width[4];
117 cur_active_width[5] = active_width[5];
118 cur_active_width[6] = active_width[6];
122 r = mem[prevr].hh.v.RH;
123 if (mem[r].hh.b0 == 2)
125 cur_active_width[1] = cur_active_width[1] + mem[r + 1].cint;
126 cur_active_width[2] = cur_active_width[2] + mem[r + 2].cint;
127 cur_active_width[3] = cur_active_width[3] + mem[r + 3].cint;
128 cur_active_width[4] = cur_active_width[4] + mem[r + 4].cint;
129 cur_active_width[5] = cur_active_width[5] + mem[r + 5].cint;
130 cur_active_width[6] = cur_active_width[6] + mem[r + 6].cint;
136 l = mem[r + 1].hh.v.LH;
139 if ((minimum_demerits < 1073741823L) && /* 2^30 - 1 */
140 ((oldl != easyline) || (r == active)))
145 break_width[1] = background[1];
146 break_width[2] = background[2];
147 break_width[3] = background[3];
148 break_width[4] = background[4];
149 break_width[5] = background[5];
150 break_width[6] = background[6];
152 /* if break_type>unhyphenated then if cur_p<>null then l.16451 */
156 t = mem[cur_p].hh.b1;
158 s = mem[cur_p + 1].hh.v.RH;
163 if ((v >= hi_mem_min))
166 break_width[1] = break_width[1]- font_info[width_base[f]+ font_info[char_base[f]+ mem[v].hh.b1].qqqq.b0].cint;
168 else switch (mem[v].hh.b0)
172 f = mem[v + 1].hh.b0;
173 break_width[1] = break_width[1]- font_info[width_base[f]+ font_info[char_base[f]+ mem[v + 1].hh.b1].qqqq.b0].cint;
180 break_width[1] = break_width[1]- mem[v + 1].cint;
185 return; // abort_flag set
191 { /* while s<>null do l.16453 */
192 if ((s >= hi_mem_min))
195 break_width[1] = break_width[1]+ font_info[width_base[f]+ font_info[char_base[f]+ mem[s].hh.b1].qqqq.b0].cint;
197 else switch(mem[s].hh.b0)
201 f = mem[s + 1].hh.b0;
202 break_width[1] = break_width[1]+ font_info[width_base[f]+ font_info[char_base[f]+ mem[s + 1].hh.b1].qqqq.b0].cint;
208 /* didn't used to drop through to case 11 from case 2 in 3.141 */
210 /* used to be some extra code here in case 11 in 3.141 */
211 break_width[1] = break_width[1]+ mem[s + 1].cint;
216 return; // abort_flag set
220 /* used to be an increment t here in 3.141 */
223 break_width[1] = break_width[1] + disc_width;
224 /* used to be a test on t here instead in 3.141 */
225 if (mem[cur_p + 1].hh.v.RH == 0)
230 if ((s >= hi_mem_min))
236 v = mem[s + 1].hh.v.LH;
237 break_width[1] = break_width[1] - mem[v + 1].cint;
238 break_width[2 + mem[v].hh.b0] = break_width[2 + mem[v].hh.b0] - mem[v + 2].cint;
239 break_width[6] = break_width[6] - mem[v + 3].cint;
246 /* case 9 used to drop through to case 11 in 3.141 */
247 break_width[1] = break_width[1] - mem[s + 1].cint;
250 /* changes here in nature of test since 3.141 */
251 if (mem[s].hh.b1 != 1)
254 break_width[1] = break_width[1] - mem[s + 1].cint;
264 if (mem[prevr].hh.b0 == 2)
266 mem[prevr + 1].cint = mem[prevr + 1].cint - cur_active_width[1] + break_width[1];
267 mem[prevr + 2].cint = mem[prevr + 2].cint - cur_active_width[2] + break_width[2];
268 mem[prevr + 3].cint = mem[prevr + 3].cint - cur_active_width[3] + break_width[3];
269 mem[prevr + 4].cint = mem[prevr + 4].cint - cur_active_width[4] + break_width[4];
270 mem[prevr + 5].cint = mem[prevr + 5].cint - cur_active_width[5] + break_width[5];
271 mem[prevr + 6].cint = mem[prevr + 6].cint - cur_active_width[6] + break_width[6];
273 else if (prevr == active)
275 active_width[1] = break_width[1];
276 active_width[2] = break_width[2];
277 active_width[3] = break_width[3];
278 active_width[4] = break_width[4];
279 active_width[5] = break_width[5];
280 active_width[6] = break_width[6];
288 mem[q + 1].cint = break_width[1]- cur_active_width[1];
289 mem[q + 2].cint = break_width[2]- cur_active_width[2];
290 mem[q + 3].cint = break_width[3]- cur_active_width[3];
291 mem[q + 4].cint = break_width[4]- cur_active_width[4];
292 mem[q + 5].cint = break_width[5]- cur_active_width[5];
293 mem[q + 6].cint = break_width[6]- cur_active_width[6];
294 mem[prevr].hh.v.RH = q;
298 if (abs(adj_demerits) >= 1073741823L - minimum_demerits)
299 minimum_demerits = 1073741822L; /* 2^30 - 2 */
301 minimum_demerits = minimum_demerits + abs(adj_demerits);
303 register integer for_end;
306 if (fitclass <= for_end) do
308 if (minimal_demerits[fitclass] <= minimum_demerits)
311 mem[q].hh.v.RH = passive;
313 mem[q + 1].hh.v.RH = cur_p;
316 mem[q].hh.v.LH = pass_number;
318 mem[q + 1].hh.v.LH = best_place[fitclass];
320 mem[q + 1].hh.v.RH = passive;
321 mem[q + 1].hh.v.LH = best_pl_line[fitclass] + 1;
322 mem[q].hh.b1 = fitclass;
323 mem[q].hh.b0 = breaktype;
324 mem[q + 2].cint = minimal_demerits[fitclass];
326 mem[prevr].hh.v.RH = q;
329 if (tracing_paragraphs > 0)
332 print_int(mem[passive].hh.v.LH);
333 print_string(": line ");
334 print_int(mem[q + 1].hh.v.LH - 1);
340 print_int(mem[q + 2].cint);
341 print_string(" -> @@");
342 if (mem[passive + 1].hh.v.LH == 0)
345 print_int(mem[mem[passive + 1].hh.v.LH].hh.v.LH);
349 minimal_demerits[fitclass] = 1073741823L; /* 2^30 - 1 */
351 while (fitclass++ < for_end);
353 minimum_demerits = 1073741823L; /* 2^30 - 1 */
360 mem[q + 1].cint = cur_active_width[1] - break_width[1];
361 mem[q + 2].cint = cur_active_width[2] - break_width[2];
362 mem[q + 3].cint = cur_active_width[3] - break_width[3];
363 mem[q + 4].cint = cur_active_width[4] - break_width[4];
364 mem[q + 5].cint = cur_active_width[5] - break_width[5];
365 mem[q + 6].cint = cur_active_width[6] - break_width[6];
366 mem[prevr].hh.v.RH = q;
375 linewidth = second_width;
376 oldl = 262142L; /* 2^18 - 2 ? */
381 if (l > last_special_line)
382 linewidth = second_width;
383 else if (par_shape_ptr == 0)
384 linewidth = first_width;
386 linewidth = mem[par_shape_ptr + 2 * l].cint;
391 artificialdemerits = false;
392 shortfall = linewidth - cur_active_width[1]; /* linewidth may be ... */
394 if ((cur_active_width[3]!= 0) || (cur_active_width[4]!= 0) || (cur_active_width[5]!= 0))
401 if (shortfall > 7230584L)
402 if (cur_active_width[2]< 1663497L)
408 b = badness(shortfall, cur_active_width[2]);
421 if (- (integer) shortfall > cur_active_width[6])
424 b = badness(- (integer) shortfall, cur_active_width[6]);
430 if ((b > 10000) || (pi == -10000))
432 if (final_pass && (minimum_demerits == 1073741823L) && /* 2^30 - 1 */
433 (mem[r].hh.v.RH == active) && (prevr == active))
434 artificialdemerits = true;
435 else if (b > threshold)
437 noderstaysactive = false;
444 noderstaysactive = true;
446 if (artificialdemerits)
450 d = line_penalty + b;
458 else if (pi > -10000)
460 if ((breaktype == 1) && (mem[r].hh.b0 == 1))
462 d = d + double_hyphen_demerits;
464 d = d + final_hyphen_demerits;
465 if (abs(toint(fitclass)- toint(mem[r].hh.b1)) > 1)
466 d = d + adj_demerits;
469 if (tracing_paragraphs > 0)
471 if (printed_node != cur_p)
475 short_display(mem[printed_node].hh.v.RH);
478 savelink = mem[cur_p].hh.v.RH;
479 mem[cur_p].hh.v.RH = 0;
481 short_display(mem[printed_node].hh.v.RH);
482 mem[cur_p].hh.v.RH = savelink;
484 printed_node = cur_p;
489 else if (mem[cur_p].hh.b0 != 10)
491 if (mem[cur_p].hh.b0 == 12)
492 print_esc("penalty");
493 else if (mem[cur_p].hh.b0 == 7)
494 print_esc("discretionary");
495 else if (mem[cur_p].hh.b0 == 11)
500 print_string(" via @@");
501 if (mem[r + 1].hh.v.RH == 0)
504 print_int(mem[mem[r + 1].hh.v.RH].hh.v.LH);
512 if (artificialdemerits)
518 d = d + mem[r + 2].cint;
519 if (d <= minimal_demerits[fitclass])
521 minimal_demerits[fitclass] = d;
522 best_place[fitclass] = mem[r + 1].hh.v.RH;
523 best_pl_line[fitclass] = l;
524 if (d < minimum_demerits)
525 minimum_demerits = d;
527 if (noderstaysactive)
530 mem[prevr].hh.v.RH = mem[r].hh.v.RH;
534 r = mem[active].hh.v.RH;
535 if (mem[r].hh.b0 == 2)
537 active_width[1] = active_width[1] + mem[r + 1].cint;
538 active_width[2] = active_width[2] + mem[r + 2].cint;
539 active_width[3] = active_width[3] + mem[r + 3].cint;
540 active_width[4] = active_width[4] + mem[r + 4].cint;
541 active_width[5] = active_width[5] + mem[r + 5].cint;
542 active_width[6] = active_width[6] + mem[r + 6].cint;
543 cur_active_width[1] = active_width[1];
544 cur_active_width[2] = active_width[2];
545 cur_active_width[3] = active_width[3];
546 cur_active_width[4] = active_width[4];
547 cur_active_width[5] = active_width[5];
548 cur_active_width[6] = active_width[6];
549 mem[active].hh.v.RH = mem[r].hh.v.RH;
553 else if (mem[prevr].hh.b0 == 2)
555 r = mem[prevr].hh.v.RH;
558 cur_active_width[1] = cur_active_width[1] - mem[prevr + 1].cint;
559 cur_active_width[2] = cur_active_width[2] - mem[prevr + 2].cint;
560 cur_active_width[3] = cur_active_width[3] - mem[prevr + 3].cint;
561 cur_active_width[4] = cur_active_width[4] - mem[prevr + 4].cint;
562 cur_active_width[5] = cur_active_width[5] - mem[prevr + 5].cint;
563 cur_active_width[6] = cur_active_width[6] - mem[prevr + 6].cint;
564 mem[prevprevr].hh.v.RH = active; /* prevprevr may be used ... */
568 else if (mem[r].hh.b0 == 2)
570 cur_active_width[1] = cur_active_width[1] + mem[r + 1].cint;
571 cur_active_width[2] = cur_active_width[2] + mem[r + 2].cint;
572 cur_active_width[3] = cur_active_width[3] + mem[r + 3].cint;
573 cur_active_width[4] = cur_active_width[4] + mem[r + 4].cint;
574 cur_active_width[5] = cur_active_width[5] + mem[r + 5].cint;
575 cur_active_width[6] = cur_active_width[6] + mem[r + 6].cint;
576 mem[prevr + 1].cint = mem[prevr + 1].cint + mem[r + 1].cint;
577 mem[prevr + 2].cint = mem[prevr + 2].cint + mem[r + 2].cint;
578 mem[prevr + 3].cint = mem[prevr + 3].cint + mem[r + 3].cint;
579 mem[prevr + 4].cint = mem[prevr + 4].cint + mem[r + 4].cint;
580 mem[prevr + 5].cint = mem[prevr + 5].cint + mem[r + 5].cint;
581 mem[prevr + 6].cint = mem[prevr + 6].cint + mem[r + 6].cint;
582 mem[prevr].hh.v.RH = mem[r].hh.v.RH;
591 if (cur_p == printed_node)
593 if (mem[cur_p].hh.b0 == 7)
595 t = mem[cur_p].hh.b1;
599 printed_node = mem[printed_node].hh.v.RH;
603 /* must exit here, there are no internal return - except for confusion */
604 /* savedbadness = b; */ /* 96/Feb/9 - for test in itex.c */
606 /* end of the old tex5.c here */
608 void post_line_break_(integer final_widow_penalty)
619 q = mem[best_bet + 1].hh.v.RH;
624 q = mem[q + 1].hh.v.LH;
625 mem[r + 1].hh.v.LH = cur_p;
629 curline = prev_graf + 1;
632 q = mem[cur_p + 1].hh.v.RH;
634 postdiscbreak = false;
636 if (mem[q].hh.b0 == 10)
638 delete_glue_ref(mem[q + 1].hh.v.LH);
639 mem[q + 1].hh.v.LH = eqtb[(hash_size + 790)].hh.v.RH;
641 incr(mem[eqtb[(hash_size + 790)].hh.v.RH].hh.v.RH);
646 if (mem[q].hh.b0 == 7)
662 flush_node_list(mem[q].hh.v.RH);
665 if (mem[q + 1].hh.v.RH != 0)
667 s = mem[q + 1].hh.v.RH;
668 while (mem[s].hh.v.RH != 0)
671 r = mem[q + 1].hh.v.RH;
672 mem[q + 1].hh.v.RH = 0;
673 postdiscbreak = true;
675 if (mem[q + 1].hh.v.LH != 0)
677 s = mem[q + 1].hh.v.LH;
679 while (mem[s].hh.v.RH != 0)
681 mem[q + 1].hh.v.LH = 0;
687 else if ((mem[q].hh.b0 == 9) || (mem[q].hh.b0 == 11))
693 while (mem[q].hh.v.RH != 0)
696 r = new_param_glue(8);
697 mem[r].hh.v.RH = mem[q].hh.v.RH;
704 q = mem[temp_head].hh.v.RH;
705 mem[temp_head].hh.v.RH = r;
706 if (eqtb[(hash_size + 789)].hh.v.RH != 0)
708 r = new_param_glue(7);
712 if (curline > last_special_line)
714 curwidth = second_width;
715 curindent = second_indent;
717 else if (par_shape_ptr == 0)
719 curwidth = first_width;
720 curindent = first_indent;
724 curwidth = mem[par_shape_ptr + 2 * curline].cint;
725 curindent = mem[par_shape_ptr + 2 * curline - 1].cint;
727 adjust_tail = adjust_head;
728 just_box = hpack(q, curwidth, 0);
729 mem[just_box + 4].cint = curindent;
730 append_to_vlist(just_box);
731 /* if adjust_head<>adjust_tail then l.17346 */
732 if (adjust_head != adjust_tail)
734 mem[tail].hh.v.RH = mem[adjust_head].hh.v.RH;
737 adjust_tail = 0; /* adjust_tail:=null */
738 if (curline + 1 != best_line)
740 pen = inter_line_penalty;
741 if (curline == prev_graf + 1)
742 pen = pen + club_penalty;
743 if (curline + 2 == best_line)
744 pen = pen + final_widow_penalty;
746 pen = pen + broken_penalty;
749 r = new_penalty(pen);
750 mem[tail].hh.v.RH = r;
755 cur_p = mem[cur_p + 1].hh.v.LH;
763 if (q == mem[cur_p + 1].hh.v.RH)
765 if ((q >= hi_mem_min))
767 if ((mem[q].hh.b0 < 9))
769 /* change in tests here from 3.141 != 1 instead of == 2 */
770 if (mem[q].hh.b0 == 11)
771 if (mem[q].hh.b1 != 1)
779 flush_node_list(mem[temp_head].hh.v.RH);
780 mem[temp_head].hh.v.RH = q;
784 while (!(cur_p == 0));
785 if ((curline != best_line) || (mem[temp_head].hh.v.RH != 0))
788 return; // abort_flag set
790 prev_graf = best_line - 1;
792 /* Reconstitute ligatures during hyphenation pass */
794 small_number reconstitute_(small_number j, small_number n, halfword bchar, halfword hchar)
796 register small_number Result;
804 hyphen_passed = 0; /* paragraph 907 ? */
807 mem[hold_head].hh.v.RH = 0;
812 ligature_present = init_lig;
814 if (ligature_present)
816 /* while p>null do l.17772 */
817 /* while(p > 0){ */ /* NO! */
819 { /* 94/Mar/22 BUG FIX */
821 /* append_charnode_to_t(character(p)); */
822 mem[t].hh.v.RH = get_avail();
825 mem[t].hh.b1 = mem[p].hh.b1;
827 p = mem[p].hh.v.RH; /* p:=link(p); */
830 else if (cur_l < 256)
832 mem[t].hh.v.RH = get_avail();
835 mem[t].hh.b1 = cur_l;
837 lig_stack = 0; /* lig_stack:=null; */
849 if (cur_l == 256) /* if cur_l = non_char then */
851 k = bchar_label[hf]; /* begin k:=bchar_label[hf]; */
852 /* if k=non_address then goto done@+else q:=font_info[k].qqqq; l.17812 */
853 /* if (k == font_mem_size) */
854 if (k == non_address) /* i.e. 0 --- 96/Jan/15 */
857 q = font_info[k].qqqq;
861 q = font_info[char_base[hf]+ cur_l].qqqq;
862 if (((q.b2) % 4)!= 1)
864 k = lig_kern_base[hf] + q.b3;
865 q = font_info[k].qqqq;
868 k = lig_kern_base[hf]+ 256 * q.b2 + q.b3 + 32768L - 256 *(128);
869 q = font_info[k].qqqq;
872 if (currh < 256) /* if cur_rh < non_char then test_char:=cur_rh */
875 testchar = cur_r; /* else test_char:=cur_r; l.17817 */
876 /* loop@+begin if next_char(q)=test_char then if skip_byte(q)<=stop_flag then */
879 if (q.b1 == testchar)
881 if (currh < 256) /* if cur_rh<non_char then */
886 goto lab22; /* goto continue; */
889 { /* else begin if hchar<non_char then if odd(hyf[j]) then */
896 if (q.b2 < 128) /* if op_byte(q)<kern_flag then */
898 // @<Carry out a ligature replacement, updating the cursor structure
899 // and possibly advancing~|j|; |goto continue| if the cursor doesn't
900 // advance, otherwise |goto done|@>; => l.17869
901 if (cur_l == 256) /* begin if cur_l=non_char then lft_hit:=true; */
904 if (lig_stack == 0)/* if lig_stack=null ? */
909 pause_for_instructions();
912 switch(q.b2) /* case op_byte(q) of */
918 ligature_present = true;
925 /* if lig_stack>null then character(lig_stack):=cur_r */
926 /* if (lig_stack > 0) */ /* 94/Mar/22 */
927 if (lig_stack != 0) /* line breaking?? */
928 mem[lig_stack].hh.b1 = cur_r; /* l.17877 ? */
931 lig_stack = new_lig_item(cur_r);
937 mem[lig_stack + 1].hh.v.RH = p;
938 mem[p].hh.b1 = hu[j + 1];
948 lig_stack = new_lig_item(cur_r);
949 mem[lig_stack].hh.v.RH = p;
955 if (ligature_present)
957 p = new_ligature(hf, cur_l, mem[cur_q].hh.v.RH);
967 } */ /* removed 99/Jan/6 */
968 mem[cur_q].hh.v.RH = p;
970 ligature_present = false;
974 ligature_present = true;
979 /* othercases begin cur_l:=rem_byte(q);
980 ligature_present:=true; {\.{=:}} l.17869 */
982 ligature_present = true;
983 /* if lig_stack>null then pop_lig_stack l.17870 => l.17828 */
984 /* if (lig_stack > 0)*/ /* 94/Mar/22 ??? */
985 if (lig_stack != 0) /* BUG FIX */
987 /* if (mem[lig_stack + 1].hh.v.RH > 0) */ /* 94/Mar/22 */
988 if (mem[lig_stack + 1].hh.v.RH != 0) /* l.17828 ? */
990 mem[t].hh.v.RH = mem[lig_stack + 1].hh.v.RH;
995 lig_stack = mem[p].hh.v.RH;
997 if (lig_stack == 0) /* if lig_stack=null ? */
1009 cur_r = mem[lig_stack].hh.b1;
1016 mem[t].hh.v.RH = get_avail();
1019 mem[t].hh.b1 = cur_r;
1041 w = font_info[kern_base[hf]+ 256 * q.b2 + q.b3].cint;
1053 q = font_info[k].qqqq;
1056 if (ligature_present)
1058 p = new_ligature(hf, cur_l, mem[cur_q].hh.v.RH);
1065 if (lig_stack == 0) /* if lig_stack=null ? */
1070 mem[cur_q].hh.v.RH = p;
1072 ligature_present = false;
1076 mem[t].hh.v.RH = new_kern(w);
1080 /* if (lig_stack > 0)*/ /* 94/Mar/22 ??? l.17870 */
1081 if (lig_stack != 0) /* l.17841 */
1083 /* begin cur_q:=t; cur_l:=character(lig_stack);
1084 ligature_present:=true; l.17842 */
1086 cur_l = mem[lig_stack].hh.b1;
1087 ligature_present = true;
1089 /* pop_lig_stack; goto continue; l.17843 => l.17828 */
1090 /* if (mem[lig_stack + 1].hh.v.RH > 0) *//* 94/Mar/22 */
1091 if (mem[lig_stack + 1].hh.v.RH != 0) /* BUG FIX */
1093 mem[t].hh.v.RH = mem[lig_stack + 1].hh.v.RH;
1098 lig_stack = mem[p].hh.v.RH;
1112 cur_r = mem[lig_stack].hh.b1;
1119 /* #pragma optimize ("g", off) */ /* not needed for MSVC it seems ... */
1121 void hyphenate (void)
1125 int l; /* 95/Jan/7 */
1128 halfword majortail, minortail;
1130 int c; /* 95/Jan/7 */
1132 /* integer rcount; */
1133 int rcount; /* 95/Jan/7 */
1141 for (j = 0; j <= hn; j++) hyf[j] = 0;
1145 for (j = 2; j <= hn; j++) h = (h + h + hc[j]) % hyphen_prime;
1153 if (length(k) == hn)
1159 if (str_pool[u] < hc[j])
1161 if (str_pool[u] > hc[j])
1169 { /* while s<>null do l.18173 */
1170 hyf[mem[s].hh.v.LH] = 1;
1185 if (trie_trc[cur_lang + 1]!= cur_lang)
1190 for (j = 0; j <= hn - rhyf + 1; j++)
1192 z = trie_trl[cur_lang + 1] + hc[j];
1194 while (hc[l]== trie_trc[z])
1196 if (trie_tro[z]!= min_trie_op)
1201 v = v + op_start[cur_lang];
1202 i = l - hyf_distance[v];
1203 if (hyf_num[v] > hyf[i])
1207 while(!(v == min_trie_op));
1210 z = trie_trl[z]+ hc[l];
1214 for (j = 0; j <= lhyf - 1; j++)
1216 for (j = 0; j <= rhyf - 1; j++)
1218 for (j = lhyf; j <= hn - rhyf; j++)
1223 q = mem[hb].hh.v.RH;
1224 mem[hb].hh.v.RH = 0;
1225 r = mem[ha].hh.v.RH;
1226 mem[ha].hh.v.RH = 0;
1228 if ((ha >= hi_mem_min))
1229 if (mem[ha].hh.b0 != hf)
1235 hu[0] = mem[ha].hh.b1;
1237 else if (mem[ha].hh.b0 == 6)
1238 if (mem[ha + 1].hh.b0 != hf)
1242 init_list = mem[ha + 1].hh.v.RH;
1244 init_lft = (mem[ha].hh.b1 > 1);
1245 hu[0] = mem[ha + 1].hh.b1;
1256 if (!(r >= hi_mem_min))
1257 if (mem[r].hh.b0 == 6)
1258 if (mem[r].hh.b1 > 1)
1266 while (mem[s].hh.v.RH != ha)
1281 j = reconstitute(j, hn, bchar, hyf_char) + 1;
1282 if (hyphen_passed == 0)
1284 mem[s].hh.v.RH = mem[hold_head].hh.v.RH;
1285 /* while(mem[s].hh.v.RH > 0)*/ /* 94/Mar/22 */
1286 while (link(s) != 0) /* l.17903 */
1288 if (odd(hyf[j - 1]))
1291 hyphen_passed = j - 1;
1292 mem[hold_head].hh.v.RH = 0; /* link(hold_head):=null; */
1295 if (hyphen_passed > 0)
1299 mem[r].hh.v.RH = mem[hold_head].hh.v.RH;
1303 /* while link(major_tail) > null do advance_major_tail; l.17929 */
1304 /* while(mem[majortail].hh.v.RH > 0) { */ /* 94/Mar/22 */
1305 while (mem[majortail].hh.v.RH != 0)
1307 majortail = mem[majortail].hh.v.RH;
1313 mem[r + 1].hh.v.LH = 0;
1314 hyfnode = new_character(hf, hyf_char);
1321 mem[hyfnode].hh.v.RH = avail;
1330 l = reconstitute(l, i, font_bchar[hf], 256) + 1;
1331 /* if (mem[hold_head].hh.v.RH > 0)*/ /* 94/Mar/22 */
1332 if (mem[hold_head].hh.v.RH != 0) /* BUG FIX ??? */
1334 if (minortail == 0) /* if minor_tail=null then */
1335 mem[r + 1].hh.v.LH = mem[hold_head].hh.v.RH;
1337 mem[minortail].hh.v.RH = mem[hold_head].hh.v.RH;
1338 minortail = mem[hold_head].hh.v.RH;
1339 /* while(mem[minortail].hh.v.RH > 0)*/ /* 94/Mar/22 */
1340 while (mem[minortail].hh.v.RH != 0) /* BUG FIX */
1341 minortail = mem[minortail].hh.v.RH;
1344 if (hyfnode != 0) /* if hyf_node<>null then l.17956 */
1351 mem[r + 1].hh.v.RH = 0;
1353 /* if bchar_label[hf]<non_address then l.17991 3.1415 */
1354 /* if (bchar_label[hf]< font_mem_size) */
1355 /* if bchar_label[hf]<>non_address then l.17991 3.14159 */
1356 if (bchar_label[hf]!= non_address) /* i.e. 0 --- 96/Jan/15 */
1367 l = reconstitute(l, hn, bchar, 256) + 1;
1370 hu[cloc] = c; /* c may be used ... */
1373 /* if (mem[hold_head].hh.v.RH > 0) */ /* 94/Mar/22 ??? */
1374 if (mem[hold_head].hh.v.RH != 0) /* BUG FIX */
1376 if (minortail == 0) /* begin if minor_tail=null then */
1377 mem[r + 1].hh.v.RH = mem[hold_head].hh.v.RH;
1379 mem[minortail].hh.v.RH = mem[hold_head].hh.v.RH;
1380 minortail = mem[hold_head].hh.v.RH;
1381 /* while link(minor_tail)>null do minor_tail:=link(minor_tail); l.17977 */
1382 /* while(mem[minortail].hh.v.RH > 0)*/ /* 94/Mar/22 */
1383 while (mem[minortail].hh.v.RH != 0) /* ??? */
1384 minortail = mem[minortail].hh.v.RH;
1390 j = reconstitute(j, hn, bchar, 256) + 1;
1391 mem[majortail].hh.v.RH = mem[hold_head].hh.v.RH;
1392 /* while (mem[majortail].hh.v.RH > 0) { */ /* 94/Mar/22 */
1393 while (mem[majortail].hh.v.RH != 0)
1395 majortail = mem[majortail].hh.v.RH;
1402 mem[s].hh.v.RH = mem[r].hh.v.RH;
1403 mem[r].hh.v.RH = 0; /* link(r):=null */
1409 mem[r].hh.b1 = rcount;
1412 hyphen_passed = j - 1;
1413 mem[hold_head].hh.v.RH = 0; /* link(hold_head):=null; */
1414 } while(!(! odd(hyf[j - 1])));
1417 flush_list(init_list);
1419 /* #pragma optimize ("g", off) */ /* not needed for MSVC it seems ... */
1420 /* used only in itex.c */
1422 void new_hyph_exceptions (void)
1424 /* small_number n; */ /* in 3.141 */
1426 /* small_number j; */ /* in 3.141 */
1437 else if (language > 255)
1440 cur_lang = language;
1465 if (eqtb[(hash_size + 2139) + cur_chr].hh.v.RH == 0)
1467 print_err("Not a letter");
1468 help2("Letters in \\hyphenation words must have \\lccode>0.",
1469 "Proceed; I'll ignore the character I just read.");
1475 hc[n]= eqtb[(hash_size + 2139) + cur_chr].hh.v.RH;
1496 for (j = 1; j <= n; j++)
1498 h =(h + h + hc[j]) % hyphen_prime;
1500 str_pool[pool_ptr]= hc[j];
1505 /* if (hyph_count == 607)*/
1506 if (hyph_count == hyphen_prime)
1508 /* overflow(942, 607); */
1509 overflow("exception dictionary", hyphen_prime); /* exception dictionary - NOT DYNAMIC */
1510 /* not dynamic ---- but can be set -e=... from command line in ini-TeX */
1511 return; // abort_flag set
1514 while (hyph_word[h]!= 0)
1517 if (length(k) < length(s))
1519 if (length(k) > length(s))
1525 if (str_pool[u] < str_pool[v])
1527 if (str_pool[u] > str_pool[v])
1532 while(!(u == str_start[k + 1]));
1558 print_err("Improper ");
1559 print_esc("hyphenation");
1560 print_string("will be flushed");
1561 help2("Hyphenation exceptions must contain only letters",
1562 "and hyphens. But continue; I'll forgive and forget.");
1566 } /* end of switch */
1570 halfword prune_page_top_(halfword p)
1572 register halfword Result;
1577 mem[temp_head].hh.v.RH = p;
1578 /* while p<>null do l.18803 */
1580 switch(mem[p].hh.b0)
1586 q = new_skip_param(10);
1587 mem[prevp].hh.v.RH = q;
1589 if (mem[temp_ptr + 1].cint > mem[p + 3].cint)
1590 mem[temp_ptr + 1].cint = mem[temp_ptr + 1].cint - mem[p + 3].cint;
1592 mem[temp_ptr + 1].cint = 0;
1593 p = 0; /* p:=null */
1601 p = mem[prevp].hh.v.RH;
1611 mem[prevp].hh.v.RH = p;
1617 confusion("pruning");
1618 return 0; // abort_flag set
1622 Result = mem[temp_head].hh.v.RH;
1626 halfword vert_break_(halfword p, scaled h, scaled d)
1628 register halfword Result;
1634 halfword best_place;
1636 /* small_number t; */
1637 int t; /* 95/Jan/7 */
1640 leastcost = 1073741823L; /* 2^30 - 1 */
1641 active_width[1] = 0;
1642 active_width[2] = 0;
1643 active_width[3] = 0;
1644 active_width[4] = 0;
1645 active_width[5] = 0;
1646 active_width[6] = 0;
1650 if (p == 0) /* if p=null l.18879 */
1652 else switch(mem[p].hh.b0)
1658 active_width[1]= active_width[1]+ prevdp + mem[p + 3].cint;
1659 prevdp = mem[p + 2].cint;
1667 if ((mem[prevp].hh.b0 < 9))
1674 if (mem[p].hh.v.RH == 0)/* if link(p)=null l.18903 */
1677 t = mem[mem[p].hh.v.RH].hh.b0;
1685 pi = mem[p + 1].cint;
1693 confusion("vertbreak");
1694 return 0; // abort_flag set
1698 if (pi < 10000) /* pi may be used ... */
1700 if (active_width[1] < h)
1701 if ((active_width[3] != 0) || (active_width[4] != 0) || (active_width[5]!= 0))
1704 b = badness(h - active_width[1], active_width[2]);
1705 else if (active_width[1] - h > active_width[6])
1706 b = 1073741823L; /* 2^30 - 1 */
1708 b = badness(active_width[1] - h, active_width[6]);
1709 if (b < 1073741823L) /* 2^30 - 1 */
1720 best_height_plus_depth = active_width[1]+ prevdp;
1722 if ((b == 1073741823L) || (pi <= -10000)) /* 2^30 - 1 */
1725 if ((mem[p].hh.b0 < 10) || (mem[p].hh.b0 > 11))
1728 if (mem[p].hh.b0 == 11)
1732 q = mem[p + 1].hh.v.LH;
1733 active_width[2 + mem[q].hh.b0] = active_width[2 + mem[q].hh.b0]+ mem[q + 2].cint;
1734 active_width[6] = active_width[6]+ mem[q + 3].cint;
1735 if ((mem[q].hh.b1 != 0)&&(mem[q + 3].cint != 0))
1737 print_err("Infinite glue shrinkage found in box being split");
1738 help4("The box you are \\vsplitting contains some infinitely",
1739 "shrinkable glue, e.g., `\\vss' or `\\vskip 0pt minus 1fil'.",
1740 "Such glue doesn't belong there; but you can safely proceed,",
1741 "since the offensive shrinkability has been made finite.");
1746 mem[p + 1].hh.v.LH = r;
1750 active_width[1] = active_width[1]+ prevdp + mem[q + 1].cint;
1755 active_width[1] = active_width[1]+ prevdp - d;
1759 p = mem[prevp].hh.v.RH;
1762 Result = best_place; /* best_place may be used ... */
1765 /* called only from tex7.c */
1767 halfword vsplit_(eight_bits n, scaled h)
1769 register halfword Result;
1774 v = eqtb[(hash_size + 1578) + n].hh.v.RH;
1775 if (cur_mark[3]!= 0)
1777 delete_token_ref(cur_mark[3]);
1779 delete_token_ref(cur_mark[4]);
1782 if (v == 0) /* if v=null then l.18999 */
1784 Result = 0; /* begin vsplit:=null; return; */
1787 if (mem[v].hh.b0 != 1)
1790 print_esc("vsplit");
1791 print_string("needs a ");
1793 help2("The box you are trying to split is an \\hbox.",
1794 "I can't split such a box, so I'll leave it alone.");
1799 q = vert_break(mem[v + 5].hh.v.RH, h, split_max_depth);
1800 p = mem[v + 5].hh.v.RH;
1802 mem[v + 5].hh.v.RH = 0;
1805 if (mem[p].hh.b0 == 4)
1806 if (cur_mark[3]== 0)
1808 cur_mark[3] = mem[p + 1].cint;
1809 cur_mark[4] = cur_mark[3];
1810 mem[cur_mark[3]].hh.v.LH = mem[cur_mark[3]].hh.v.LH + 2;
1814 delete_token_ref(cur_mark[4]);
1815 cur_mark[4]= mem[p + 1].cint;
1816 incr(mem[cur_mark[4]].hh.v.LH);
1818 if (mem[p].hh.v.RH == q)
1826 q = prune_page_top(q);
1827 p = mem[v + 5].hh.v.RH;
1829 if (q == 0) /* if q=null l.18993 */
1830 eqtb[(hash_size + 1578) + n].hh.v.RH = 0; /* then box(n):=null */
1832 eqtb[(hash_size + 1578) + n].hh.v.RH = vpackage(q, 0, 1, 1073741823L); /* 2^30 - 1 */
1833 Result = vpackage(p, h, 0, split_max_depth);
1837 void print_totals (void)
1839 print_scaled(page_so_far[1]);
1840 if (page_so_far[2] != 0)
1842 print_string(" plus ");
1843 print_scaled(page_so_far[2]);
1846 if (page_so_far[3] != 0)
1848 print_string(" plus ");
1849 print_scaled(page_so_far[3]);
1850 print_string("fil");
1852 if (page_so_far[4] != 0)
1854 print_string(" plus ");
1855 print_scaled(page_so_far[4]);
1856 print_string("fill");
1858 if (page_so_far[5] != 0)
1860 print_string(" plus ");
1861 print_scaled(page_so_far[5]);
1862 print_string("filll");
1864 if (page_so_far[6] != 0)
1866 print_string(" minus ");
1867 print_scaled(page_so_far[6]);
1871 void freeze_page_specs_(small_number s)
1874 page_so_far[0] = vsize;
1875 page_max_depth = max_depth;
1883 least_page_cost = 1073741823L; /* 2^30 - 1 */
1885 if (tracing_pages > 0)
1888 print_nl("might split");
1889 print_scaled(page_so_far[0]);
1890 print_string(", max depth=");
1891 print_scaled(page_max_depth);
1892 end_diagnostic(false);
1897 void box_error_(eight_bits n)
1901 print_nl("The following box has been deleted:");
1902 show_box(eqtb[(hash_size + 1578) + n].hh.v.RH);
1903 end_diagnostic(true);
1904 flush_node_list(eqtb[(hash_size + 1578) + n].hh.v.RH);
1905 eqtb[(hash_size + 1578) + n].hh.v.RH = 0;
1908 void ensure_vbox_(eight_bits n)
1911 p = eqtb[(hash_size + 1578) + n].hh.v.RH;
1912 if (p != 0) /* if p<>null then if type(p)=hlist_node then l.19324 */
1913 if (mem[p].hh.b0 == 0)
1915 print_err("Insertions can only be added to a vbox");
1916 help3("Tut tut: You're trying to \\insert into a",
1917 "\\box register that now contains an \\hbox.",
1918 "Proceed, and I'll discard its present contents.");
1922 /* called only from tex7.c */
1924 void fire_up_(halfword c)
1926 halfword p, q, r, s;
1928 /* unsigned char n; */
1929 unsigned int n; /* 95/Jan/7 */
1931 integer savevbadness;
1933 halfword savesplittopskip;
1935 if (mem[best_page_break].hh.b0 == 12)
1937 geq_word_define((hash_size + 3202), mem[best_page_break + 1].cint);
1938 mem[best_page_break + 1].cint = 10000;
1941 geq_word_define((hash_size + 3202), 10000);
1942 if (cur_mark[2]!= 0)
1944 if (cur_mark[0]!= 0)
1945 delete_token_ref(cur_mark[0]);
1946 cur_mark[0]= cur_mark[2];
1947 incr(mem[cur_mark[0]].hh.v.LH);
1948 delete_token_ref(cur_mark[1]);
1951 if (c == best_page_break)
1952 best_page_break = 0;
1953 if (eqtb[(hash_size + 1833)].hh.v.RH != 0)
1957 print_string("255 is not void");
1958 help2("You shouldn't use \\box255 except in \\output routines.",
1959 "Proceed, and I'll discard its present contents.");
1962 insert_penalties = 0;
1963 savesplittopskip = eqtb[(hash_size + 792)].hh.v.RH;
1964 if (holding_inserts <= 0)
1966 r = mem[mem_top].hh.v.RH;
1967 while (r != mem_top)
1969 if (mem[r + 2].hh.v.LH != 0)
1973 /* if box(n)=null then box(n):=new_null_box; l.19759 */
1974 if (eqtb[(hash_size + 1578) + n].hh.v.RH == 0)
1975 eqtb[(hash_size + 1578) + n].hh.v.RH = new_null_box();
1976 p = eqtb[(hash_size + 1578) + n].hh.v.RH + 5;
1977 while (mem[p].hh.v.RH != 0)
1979 mem[r + 2].hh.v.RH = p;
1987 p = mem[prevp].hh.v.RH;
1988 while (p != best_page_break)
1990 if (mem[p].hh.b0 == 3)
1992 if (holding_inserts <= 0)
1994 r = mem[mem_top].hh.v.RH;
1995 while (mem[r].hh.b1 != mem[p].hh.b1)
1997 /* if best_ins_ptr(r)=null then wait:=true l.19783 */
1998 if (mem[r + 2].hh.v.LH == 0)
2003 s = mem[r + 2].hh.v.RH;
2004 mem[s].hh.v.RH = mem[p + 4].hh.v.LH;
2005 if (mem[r + 2].hh.v.LH == p)
2007 if (mem[r].hh.b0 == 1)
2008 if ((mem[r + 1].hh.v.LH == p) && (mem[r + 1].hh.v.RH != 0))
2010 while (mem[s].hh.v.RH != mem[r + 1].hh.v.RH)
2013 eqtb[(hash_size + 792)].hh.v.RH = mem[p + 4].hh.v.RH;
2014 mem[p + 4].hh.v.LH = prune_page_top(mem[r + 1].hh.v.RH);
2015 if (mem[p + 4].hh.v.LH != 0)
2017 temp_ptr = vpackage(mem[p + 4].hh.v.LH, 0, 1, 1073741823L); /* 2^30 - 1 */
2018 mem[p + 3].cint = mem[temp_ptr + 3].cint + mem[temp_ptr + 2].cint;
2019 free_node(temp_ptr, 7);
2023 mem[r + 2].hh.v.LH = 0;
2025 temp_ptr = mem[eqtb[(hash_size + 1578) + n].hh.v.RH + 5].hh.v.RH;
2026 free_node(eqtb[(hash_size + 1578) + n].hh.v.RH, 7);
2027 eqtb[(hash_size + 1578) + n].hh.v.RH = vpackage(temp_ptr, 0, 1, 1073741823L); /* 2^30 - 1 */
2031 while (mem[s].hh.v.RH != 0)
2033 mem[r + 2].hh.v.RH = s;
2036 mem[prevp].hh.v.RH = mem[p].hh.v.RH;
2042 incr(insert_penalties);
2046 delete_glue_ref(mem[p + 4].hh.v.RH);
2052 else if (mem[p].hh.b0 == 4)
2054 if (cur_mark[1] == 0)
2056 cur_mark[1]= mem[p + 1].cint;
2057 incr(mem[cur_mark[1]].hh.v.LH);
2059 if (cur_mark[2] != 0)
2060 delete_token_ref(cur_mark[2]);
2061 cur_mark[2]= mem[p + 1].cint;
2062 incr(mem[cur_mark[2]].hh.v.LH);
2065 p = mem[prevp].hh.v.RH;
2067 eqtb[(hash_size + 792)].hh.v.RH = savesplittopskip;
2068 if (p != 0) /* if p<>null then l.19730 */
2070 if (mem[contrib_head].hh.v.RH == 0)/* if link(contrib_head)=null then */
2074 nest[0].tail_field = page_tail;
2075 mem[page_tail].hh.v.RH = mem[contrib_head].hh.v.RH;
2076 mem[contrib_head].hh.v.RH = p;
2077 mem[prevp].hh.v.RH = 0; /* link(prev_p):=null; */
2079 savevbadness = vbadness;
2081 savevfuzz = eqtb[(hash_size + 3739)].cint;
2082 eqtb[(hash_size + 3739)].cint = 1073741823L; /* 2^30 - 1 */
2083 eqtb[(hash_size + 1833)].hh.v.RH = vpackage(mem[page_head].hh.v.RH, best_size, 0, page_max_depth);
2084 vbadness = savevbadness;
2085 eqtb[(hash_size + 3739)].cint = savevfuzz;
2086 /* if (last_glue != 262143L) */
2087 if (last_glue != empty_flag)
2088 delete_glue_ref(last_glue);
2090 page_tail = page_head;
2091 mem[page_head].hh.v.RH = 0;
2092 /* last_glue = 262143L; */
2093 last_glue = empty_flag;
2100 mem[page_head].hh.v.RH = mem[hold_head].hh.v.RH;
2103 r = mem[mem_top].hh.v.RH;
2104 while (r != mem_top)
2110 mem[mem_top].hh.v.RH = mem_top;
2111 /* if (top_mark<>null)and(first_mark=null) then l.19654 */
2112 if ((cur_mark[0]!= 0) && (cur_mark[1]== 0))
2114 cur_mark[1] = cur_mark[0];
2115 incr(mem[cur_mark[0]].hh.v.LH);
2117 /* if output_routine<>null then */
2118 if (output_routine != 0)
2119 if (dead_cycles >= max_dead_cycles)
2121 print_err("Output loop---");
2122 print_int(dead_cycles);
2123 print_string(" consecutive dead cycles");
2124 help3("I've concluded that your \\output is awry; it never does",
2125 "\\ship_out, so I'm shipping \box255 out myself. Next ",
2126 "increase \\maxdeadcycles if you want me to be more patient!");
2131 output_active = true;
2135 cur_list.aux_field.cint = ignore_depth;
2136 mode_line = - (integer) line;
2137 begin_token_list(output_routine, 6); /* output */
2144 if (mem[page_head].hh.v.RH != 0)
2146 if (mem[contrib_head].hh.v.RH == 0)
2150 nest[0].tail_field = page_tail;
2152 mem[page_tail].hh.v.RH = mem[contrib_head].hh.v.RH;
2153 mem[contrib_head].hh.v.RH = mem[page_head].hh.v.RH;
2154 mem[page_head].hh.v.RH = 0;
2155 page_tail = page_head;
2157 ship_out(eqtb[(hash_size + 1833)].hh.v.RH);
2158 eqtb[(hash_size + 1833)].hh.v.RH = 0;
2161 /* used to continue here with build_page etc in tex6.c */