OSDN Git Service

updated backend.
[putex/putex.git] / src / texsourc / tex4.c
1 #ifdef _WINDOWS
2   #define NOCOMM
3   #define NOSOUND
4   #define NODRIVERS
5   #define STRICT
6   #pragma warning(disable:4115) // kill rpcasync.h complaint
7   #include <windows.h>
8   #define MYLIBAPI __declspec(dllexport)
9 #endif
10
11 #pragma warning(disable:4996)
12 #pragma warning(disable:4131) // old style declarator
13 #pragma warning(disable:4135) // conversion between different integral types 
14 #pragma warning(disable:4127) // conditional expression is constant
15
16 #include <setjmp.h>
17
18 #define EXTERN extern
19
20 #include "texd.h"
21
22 #pragma warning(disable:4244)       /* 96/Jan/10 */
23
24 /* sec 0581 */
25 void char_warning_(internal_font_number f, eight_bits c)
26
27   if (tracing_lost_chars > 0)
28   {
29     if (show_missing == 0)
30       begin_diagnostic();
31
32     if (show_missing) /* add ! before 94/June/10 */
33     {
34       print_nl("! ");
35       print_string("Missing character: there is no ");
36     }
37     else
38       print_nl("Missing character: there is no ");
39
40     print(c);
41
42     if (show_numeric) /* bkph 93/Dec/21 */
43     {
44       print_char(' ');
45       print_char('(');
46
47       if (c / 100 > 0)
48       {
49         print_char(48 + c / 100);
50 /*      c = c % 100; */
51         c = c - (c / 100) * 100;      /* ? */
52         print_char(48 + c / 10);
53       }
54       else
55       {
56 /*      c = c % 100; */
57         c = c - (c / 100) * 100;      /* ? */
58         if (c / 10 > 0) print_char(48 + c / 10);
59       }
60       print_char(48 + c % 10);
61       print_char(')');
62 /*    print_char(32); */
63     }
64 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
65     print_string(" in font ");
66     slow_print(font_name[f]);
67     print_char('!');
68 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
69 /*  if (show_missing) show_context(); */    /* in tex2.c 94/June/10 */
70     if (show_missing)
71     {
72       if (f != 0)
73         show_context();     /* not if its the nullfont */
74     }
75
76     if (show_missing == 0)            /* show on screen 94/June/10 */
77       end_diagnostic(false);
78
79     missing_characters++;           /* bkph 93/Dec/16 */
80 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
81   }
82 }
83 /* sec 0582 */
84 halfword new_character_(internal_font_number f, eight_bits c)
85 {
86   halfword p;
87
88   if (font_bc[f] <= c)
89     if (font_ec[f] >= c)
90       if (char_exists(char_info(f, c)))
91       {
92         p = get_avail();
93         font(p) = f;
94         character(p) = c;
95         return p;
96       }
97
98   char_warning(f, c);
99   return 0;
100 }
101 /* sec 0598 */
102 void dvi_swap (void)
103
104   if (trace_flag)
105   {
106     show_char('\n');
107     sprintf(log_line, "dvi_swap %d", dvi_gone);
108     show_line(log_line, 0);
109   }
110
111   if (dvi_limit == dvi_buf_size)
112   {
113     write_dvi(0, half_buf - 1);
114     dvi_limit = half_buf;
115     dvi_offset = dvi_offset + dvi_buf_size;
116     dvi_ptr = 0;
117   }
118   else
119   {
120     write_dvi(half_buf, dvi_buf_size - 1);
121     dvi_limit = dvi_buf_size;
122   }
123
124   dvi_gone = dvi_gone + half_buf;
125 }
126 /* attempt at speeding up bkph - is compiler smart ? */
127 /* sec 0600 */
128 void dvi_four_(integer x)
129
130   if (x >= 0)
131     dvi_out(x / 0100000000); // dvi_out((x >> 24));
132   else
133   {
134     x = x + 010000000000;
135     x = x + 010000000000;
136     dvi_out((x / 0100000000) + 128); // dvi_out((x >> 24) + 128);
137   }
138
139   x = x % 0100000000; // x = x & 16777215L;
140   dvi_out(x / 0200000); // dvi_out((x >> 16));
141   x = x % 0200000; // x = x & 65535L;
142   dvi_out(x / 0400); // dvi_out((x >> 8));
143   dvi_out(x % 0400); // dvi_out(x & 255);
144 }
145 /* following needs access to dvi_buf=zdvibuf see coerce.h */
146 /* sec 0601 */
147 void zdvipop(integer l)
148 {
149   if ((l == dvi_offset + dvi_ptr) && (dvi_ptr > 0))
150     decr(dvi_ptr);
151   else
152     dvi_out(142);
153 }
154 /* following needs access to dvi_buf=zdvibuf see coerce.h */
155 /* sec 0602 */
156 void dvi_font_def_(internal_font_number f)
157 {
158   pool_pointer k;
159
160 #ifdef INCREASEFONTS
161   if (f <= 256)
162   {
163     dvi_out(fnt_def1);
164     dvi_out(f - 1);
165   }
166   else
167   {
168     dvi_out(fnt_def2);
169     dvi_out(((f - 1) >> 8));
170     dvi_out(((f - 1) & 255));
171   }
172 #else
173   dvi_out(fnt_def1);
174   dvi_out(f - 1);
175 #endif
176
177   dvi_out(font_check[f].b0);
178   dvi_out(font_check[f].b1);
179   dvi_out(font_check[f].b2);
180   dvi_out(font_check[f].b3);
181   dvi_four(font_size[f]); 
182   dvi_four(font_dsize[f]);
183   dvi_out(length(font_area[f]));
184   dvi_out(length(font_name[f]));
185
186   for (k = str_start[font_area[f]]; k <= str_start[font_area[f] + 1] - 1; k++)
187     dvi_out(str_pool[k]);
188
189   for (k = str_start[font_name[f]]; k <= str_start[font_name[f] + 1] - 1; k++)
190     dvi_out(str_pool[k]);
191 }
192 /* sec 0607 */
193 void zmovement(scaled w, eight_bits o)
194 {
195   small_number mstate;
196   halfword p, q;
197   integer k;
198
199   q = get_node(movement_node_size);
200   width(q) = w;
201   location(q) = dvi_offset + dvi_ptr;
202
203   if (o == down1)
204   {
205     link(q) = down_ptr;
206     down_ptr = q;
207   }
208   else
209   {
210     link(q) = right_ptr;
211     right_ptr = q;
212   }
213
214   p = link(q);
215   mstate = none_seen;
216
217   while (p != 0)
218   {
219     if (width(p) == w)
220       switch(mstate + info(p))
221       {
222         case none_seen + yz_OK:
223         case none_seen + y_OK:
224         case z_seen + yz_OK:
225         case z_seen + y_OK:
226           if (location(p) < dvi_gone)
227             goto lab45;
228           else
229           {
230             k = location(p) - dvi_offset;
231
232             if (k < 0)
233               k = k + dvi_buf_size;
234
235             dvi_buf[k] = dvi_buf[k] + y1 - down1;
236             info(p) = y_here;
237             goto lab40;
238           }
239           break;
240
241         case none_seen + z_OK:
242         case y_seen + yz_OK:
243         case y_seen + z_OK:
244           if (location(p) < dvi_gone)
245             goto lab45;
246           else
247           {
248             k = location(p) - dvi_offset;
249
250             if (k < 0)
251               k = k + dvi_buf_size;
252
253             dvi_buf[k] = dvi_buf[k] + z1 - down1;
254             info(p) = z_here;
255             goto lab40;
256           }
257           break;
258
259         case none_seen + y_here:
260         case none_seen + z_here:
261         case y_seen + z_here:
262         case z_seen + y_here:
263           goto lab40;
264           break;
265
266         default:
267           break;
268       }
269     else switch (mstate + info(p))
270     {
271       case none_seen + y_here:
272         mstate = y_seen;
273         break;
274
275       case none_seen + z_here:
276         mstate = z_seen;
277         break;
278
279       case y_seen + z_here:
280       case z_seen + y_here:
281         goto lab45;
282         break;
283
284       default:
285         break;
286     }
287     p = link(p);
288   }
289 lab45:
290
291   info(q) = yz_OK;
292
293   if (abs(w) >= 8388608L) /* 2^23 */
294   {
295     dvi_out(o + 3);
296     dvi_four(w);
297     return;
298   }
299
300   if (abs(w) >= 32768L)
301   {
302     dvi_out(o + 2);
303
304     if (w < 0)
305       w = w + 16777216L;  /* 2^24 */
306     //dvi_out(w / 65536L);
307     dvi_out((w >> 16));
308 /*    w = w % 65536L; */
309     w = w & 65535L;
310     goto lab2;
311   }
312
313   if (abs(w)>= 128)
314   {
315     dvi_out(o + 1);
316
317     if (w < 0)
318       w = w + 65536L;
319
320     goto lab2;
321   }
322
323   dvi_out(o);
324
325   if (w < 0)
326     w = w + 256;
327
328   goto lab1;
329 lab2:
330   //dvi_out(w / 256);
331   dvi_out((w >> 8));
332 lab1:
333   //dvi_out(w % 256);
334   dvi_out(w & 255);
335   return;
336 lab40:
337   info(q) = info(p);
338
339   if (info(q) == y_here)
340   {
341     dvi_out(o + y0 - down1);
342
343     while (link(q) != p)
344     {
345       q = link(q);
346
347       switch (info(q))
348       {
349         case yz_OK:
350           info(q) = z_OK;
351           break;
352
353         case y_OK:
354           info(q) = d_fixed;
355           break;
356
357         default:
358           break;
359       }
360     }
361   }
362   else
363   {
364     dvi_out(o + z0 - down1);
365
366     while (link(q) != p)
367     {
368       q = link(q);
369
370       switch (info(q))
371       {
372         case yz_OK:
373           info(q) = y_OK;
374           break;
375
376         case z_OK:
377           info(q) = d_fixed;
378           break;
379
380         default:
381           break;
382       }
383     }
384   }
385 }
386 /* sec 0615 */
387 void prune_movements_(integer l)
388 {
389   halfword p;
390
391   while (down_ptr != 0)
392   {
393     if (location(down_ptr) < l)
394       goto lab30;
395
396     p = down_ptr;
397     down_ptr = link(p);
398     free_node(p, movement_node_size);
399   }
400
401 lab30:
402   while (right_ptr != 0)
403   {
404     if (location(right_ptr) < l)
405       return;
406
407     p = right_ptr;
408     right_ptr = link(p);
409     free_node(p, movement_node_size);
410   }
411 }
412 /* following needs access to dvi_buf=zdvibuf see coerce.h */
413 /* sec 1368 */
414 void special_out_(halfword p)
415 {
416   char old_setting;
417   pool_pointer k;
418
419   if (cur_h != dvi_h)
420   {
421     movement(cur_h - dvi_h, right1);
422     dvi_h = cur_h;
423   }
424
425   if (cur_v != dvi_v)
426   {
427     movement(cur_v - dvi_v, down1);
428     dvi_v = cur_v;
429   }
430
431   old_setting = selector;
432   selector = new_string;
433
434 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
435 /* About output \special{...} make some space in string pool 97/Mar/9 */
436 #ifdef ALLOCATESTRING
437   if (pool_ptr + 32000 > current_pool_size)
438     str_pool = realloc_str_pool (increment_pool_size);
439 /* We don't bother to check whether this worked - will catch later */
440 #endif
441 /* Potential problem here if current_pool_size is not much more than pool_ptr! */
442 /* Fixed 97/Mar/9 in version 2.0.3 */
443 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
444 #ifdef ALLOCATESTRING
445   show_token_list(link(write_tokens(p)), 0, 10000000L);
446 /*  Above is safe, since print/print_char/print_esc will extend string space */
447 #else
448 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
449   show_token_list(link(write_tokens(p)), 0, pool_size - pool_ptr);
450 #endif
451   selector = old_setting;
452   str_room(1);
453
454   if (cur_length < 256)  /* can use xxx1 ? */
455   {
456     dvi_out(xxx1);
457     dvi_out(cur_length);
458   }
459   else
460   {
461     dvi_out(xxx4);
462     dvi_four(cur_length); 
463   } 
464
465   for (k = str_start[str_ptr]; k <= pool_ptr - 1; k++)
466     dvi_out(str_pool[k]);
467
468   pool_ptr = str_start[str_ptr];
469 }
470 /* noew returns -1 if it fails */
471 /* sec 1370 */
472 void write_out_(halfword p)
473 {
474   char old_setting;
475 /*  integer oldmode;  */
476   int oldmode;          /* 1995/Jan/7 */
477 /*  small_number j;  */
478   int j;              /* 1995/Jan/7 */
479   halfword q, r;
480
481   q = get_avail();
482   info(q) = right_brace_token + '}';
483   r = get_avail();
484   link(q) = r;
485   info(r) = end_write_token;
486   ins_list(q);
487   begin_token_list(write_tokens(p), write_text);
488   q = get_avail();
489   info(q) = left_brace_token + '{';
490   ins_list(q);
491   oldmode = mode;
492   mode = 0;
493   cur_cs = write_loc;
494   q = scan_toks(false, true);
495   get_token();
496
497   if (cur_tok != end_write_token)
498   {
499     print_err("Unbalanced write command");
500     help2("On this page there's a \\write with fewer real {'s than }'s.",
501         "I can't handle that very well; good luck.");
502     error();
503
504     do
505       {
506         get_token();
507       }
508     while(!(cur_tok == end_write_token)); /*1996/Jan/10*/
509   }
510
511   mode = oldmode;
512   end_token_list();
513   old_setting = selector;
514   j = write_stream(p);
515
516   if (write_open[j])
517     selector = j;
518   else
519   {
520     if ((j == 17) && (selector == term_and_log))
521       selector = log_only;
522
523     print_nl("");
524   }
525
526   token_show(def_ref);
527   print_ln();
528   flush_list(def_ref);
529   selector = old_setting;
530 }
531 /* sec 1373 */
532 void out_what_(halfword p)
533 {
534 /*  small_number j;  */
535   int j;            /* 1995/Jan/7 */
536
537   switch (subtype(p))
538   {
539     case open_node:
540     case write_node:
541     case close_node:
542       if (!doing_leaders)
543       {
544         j = write_stream(p);
545
546         if (subtype(p) == write_node)
547         {
548           write_out(p);
549         }
550         else
551         {
552           if (write_open[j])
553             (void) a_close(write_file[j]); 
554
555           if (subtype(p) == close_node)
556             write_open[j]= false; 
557           else if (j < 16)
558           {
559             cur_name = open_name(p);
560             cur_area = open_area(p);
561             cur_ext = open_ext(p); 
562
563             if (cur_ext == 335)  /* "" */
564               cur_ext = 785;  /* => ".tex" */
565
566             pack_file_name(cur_name, cur_area, cur_ext);
567
568             while(! a_open_out(write_file[j]))
569             {
570               prompt_file_name("output file name", ".tex");
571             }
572
573             write_open[j] = true;
574           }
575         }
576       }
577       break; 
578
579     case special_node:
580       special_out(p); 
581       break;
582
583     case language_node:
584       ;
585       break;
586
587     default:
588       {
589         confusion("ext4");
590         return;       // abort_flag set
591       }
592       break;
593   }
594 }
595 /* following needs access to dvi_buf=zdvibuf see coerce.h */
596 /* sec 0619 */
597 void hlist_out (void)
598 {
599   scaled base_line;
600   scaled left_edge;
601   scaled save_h, save_v;
602   halfword this_box;
603 /*  glue_ord g_order;  */
604   int g_order;           /* 95/Jan/7 */
605 /*  char g_sign;  */
606   int g_sign;            /* 95/Jan/7 */
607   halfword p;
608   integer save_loc;
609   halfword leader_box;
610   scaled leader_wd;
611   scaled lx;
612   bool outer_doing_leaders;
613   scaled edge;
614   real glue_temp;
615   real cur_glue;
616   scaled cur_g;
617
618   cur_g = 0;
619   cur_glue = 0.0;
620   this_box = temp_ptr;
621   g_order = glue_order(this_box);
622   g_sign = glue_sign(this_box);
623   p = list_ptr(this_box);
624   incr(cur_s);
625
626   if (cur_s > 0)
627     dvi_out(141);
628
629   if (cur_s > max_push)
630     max_push = cur_s;
631
632   save_loc = dvi_offset + dvi_ptr;
633   base_line = cur_v;
634   left_edge = cur_h;
635
636   while (p != 0)
637 lab21:
638     if (is_char_node(p))
639     {
640       synch_h();
641       synch_v();
642
643       do
644         {
645           f = font(p);
646           c = character(p);
647
648           if (f != dvi_f)
649           {
650             if (!font_used[f])
651             {
652               dvi_font_def(f);
653               font_used[f] = true;
654             }
655
656             if (f <= 64 + font_base)
657               dvi_out(f - font_base - 1 + fnt_num_0);
658 #ifdef INCREASEFONTS
659             /* if we allow greater than 256 fonts */
660             else if (f <= 256)
661             {
662               dvi_out(fnt1);
663               dvi_out(f - 1);
664             }
665 #else
666             /* normal TeX 82 case */
667             else
668             {
669               dvi_out(fnt1);
670               dvi_out(f - 1);
671             }
672 #endif
673
674 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
675 #ifdef INCREASEFONTS
676             /* fnt2 followed by f / 256,  f % 256 */
677             else
678             {
679               dvi_out(fnt2);
680               dvi_out(((f - 1) >> 8));  /* top byte */
681               dvi_out(((f - 1) & 255)); /* bottom byte */
682             }
683 #endif
684 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
685             dvi_f = f;
686           }
687
688           if (c >= 128)
689             dvi_out(set1);
690
691           dvi_out(c);
692           cur_h = cur_h + char_width(f, char_info(f, c));
693           p = link(p);
694         }
695       while(!(!(p >= hi_mem_min)));
696
697       dvi_h = cur_h;
698   }
699   else
700   {
701     switch (type(p))
702     {
703       case hlist_node:
704       case vlist_node:
705         if (list_ptr(p) == 0)
706           cur_h = cur_h + width(p);
707         else
708         {
709           save_h = dvi_h;
710           save_v = dvi_v;
711           cur_v = base_line + shift_amount(p);
712           temp_ptr = p;
713           edge = cur_h;
714
715           if (type(p) == vlist_node)
716             vlist_out();
717           else
718             hlist_out();
719
720           dvi_h = save_h;
721           dvi_v = save_v;
722           cur_h = edge + width(p);
723           cur_v = base_line;
724         }
725         break;
726
727       case rule_node:
728         {
729           rule_ht = height(p);
730           rule_dp = depth(p);
731           rule_wd = width(p);
732           goto lab14;
733         }
734         break;
735
736       case whatsit_node:
737         out_what(p);
738         break;
739
740       case glue_node:
741         {
742           g = glue_ptr(p);
743           rule_wd = width(g) - cur_g;
744
745           if (g_sign != normal)
746           {
747             if (g_sign == stretching)
748             {
749               if (stretch_order(g) == g_order)
750               {
751                 cur_glue = cur_glue + stretch(g);
752                 glue_temp = glue_set(this_box) * cur_glue;
753
754                 if (glue_temp > 1000000000.0)
755                   glue_temp = 1000000000.0;
756                 else if (glue_temp < -1000000000.0)
757                   glue_temp = -1000000000.0;
758
759                 cur_g = round(glue_temp);
760               }
761             }
762             else if (shrink_order(g) == g_order)
763             {
764               cur_glue = cur_glue - shrink(g);
765               glue_temp = glue_set(this_box) * cur_glue;
766
767               if (glue_temp > 1000000000.0)
768                 glue_temp = 1000000000.0;
769               else if (glue_temp < -1000000000.0)
770                 glue_temp = -1000000000.0;
771
772               cur_g = round(glue_temp);
773             }
774           }
775
776           rule_wd = rule_wd + cur_g;
777
778           if (subtype(p) >= a_leaders)
779           {
780             leader_box = leader_ptr(p);
781
782             if (type(leader_box) == rule_node)
783             {
784               rule_ht = height(leader_box);
785               rule_dp = depth(leader_box);
786               goto lab14;
787             }
788
789             leader_wd = width(leader_box);
790
791             if ((leader_wd > 0) && (rule_wd > 0))
792             {
793               rule_wd = rule_wd + 10;
794               edge = cur_h + rule_wd;
795               lx = 0;
796
797               if (subtype(p) == a_leaders)
798               {
799                 save_h = cur_h;
800                 cur_h = left_edge + leader_wd * ((cur_h - left_edge) / leader_wd);
801
802                 if (cur_h < save_h)
803                   cur_h = cur_h + leader_wd;
804               }
805               else
806               {
807                 lq = rule_wd / leader_wd;
808                 lr = rule_wd % leader_wd;
809
810                 if (subtype(p) == c_leaders)
811                   cur_h = cur_h + (lr / 2);
812                 else
813                 {
814                   lx =(2 * lr + lq + 1) / (2 * lq + 2);
815                   cur_h = cur_h + ((lr - (lq - 1)* lx) / 2);
816                 }
817               }
818
819               while (cur_h + leader_wd <= edge)
820               {
821                 cur_v = base_line + shift_amount(leader_box);
822                 synch_v();
823                 save_v = dvi_v;
824                 synch_h();
825                 save_h = dvi_h;
826                 temp_ptr = leader_box;
827                 outer_doing_leaders = doing_leaders;
828                 doing_leaders = true;
829
830                 if (type(leader_box) == vlist_node)
831                   vlist_out();
832                 else
833                   hlist_out();
834
835                 doing_leaders = outer_doing_leaders;
836                 dvi_v = save_v;
837                 dvi_h = save_h;
838                 cur_v = base_line;
839                 cur_h = save_h + leader_wd + lx;
840               }
841
842               cur_h = edge - 10;
843               goto lab15;
844             }
845           }
846
847           goto lab13;
848         }
849         break;
850
851       case kern_node:
852       case math_node:
853         cur_h = cur_h + width(p);
854         break;
855
856       case ligature_node:
857         {
858           mem[lig_trick] = mem[lig_char(p)];
859           link(lig_trick) = link(p);
860           p = lig_trick;
861           goto lab21;
862         }
863         break;
864
865       default:
866         break;
867     }
868
869     goto lab15;
870 lab14:
871     if ((rule_ht == -1073741824L))  /* - 2^30 */
872       rule_ht = height(this_box);
873
874     if ((rule_dp == -1073741824L))     /* - 2^30 */
875       rule_dp = depth(this_box);
876
877     rule_ht = rule_ht + rule_dp;
878
879     if ((rule_ht > 0) && (rule_wd > 0))
880     {
881       synch_h();
882       cur_v = base_line + rule_dp;
883       synch_v();
884       dvi_out(set_rule);
885       dvi_four(rule_ht);
886       dvi_four(rule_wd);
887       cur_v = base_line;
888       dvi_h = dvi_h + rule_wd;
889     }
890 lab13:
891     cur_h = cur_h + rule_wd;
892 lab15:
893     p = link(p);
894   }
895
896   prune_movements(save_loc);
897
898   if (cur_s > 0)
899     dvi_pop(save_loc);
900
901   decr(cur_s);
902 }
903 /* following needs access to dvi_buf=zdvibuf see coerce.h */
904 /* sec 0629 */
905 void vlist_out (void)
906 {
907   scaled left_edge;
908   scaled top_edge;
909   scaled save_h, save_v;
910   halfword this_box;
911 /*  glue_ord g_order;  */
912   int g_order;         /* 95/Jan/7 */
913 /*  char g_sign;  */
914   int g_sign;          /* 95/Jan/7 */
915   halfword p;
916   integer save_loc;
917   halfword leader_box;
918   scaled leader_ht;
919   scaled lx;
920   bool outer_doing_leaders;
921   scaled edge;
922   real glue_temp;
923   real cur_glue;
924   scaled cur_g;
925
926   cur_g = 0;
927   cur_glue = 0.0;
928   this_box = temp_ptr;
929   g_order = glue_order(this_box);
930   g_sign = glue_sign(this_box);
931   p = list_ptr(this_box);
932   incr(cur_s);
933
934   if (cur_s > 0)
935     dvi_out(141);
936
937   if (cur_s > max_push)
938     max_push = cur_s;
939
940   save_loc = dvi_offset + dvi_ptr;
941   left_edge = cur_h;
942   cur_v = cur_v - height(this_box);
943   top_edge = cur_v;
944
945   while (p != 0)
946   {
947     if ((p >= hi_mem_min))
948     {
949       confusion("vlistout");
950       return;       // abort_flag set
951     }
952     else
953     {
954       switch (type(p))
955       {
956         case hlist_node:
957         case vlist_node:
958           if (list_ptr(p) == 0)
959             cur_v = cur_v + height(p) + depth(p);
960           else
961           {
962             cur_v = cur_v + height(p);
963             synch_v();
964             save_h = dvi_h;
965             save_v = dvi_v;
966             cur_h = left_edge + shift_amount(p);
967             temp_ptr = p;
968
969             if (type(p) == vlist_node)
970               vlist_out();
971             else
972               hlist_out();
973
974             dvi_h = save_h;
975             dvi_v = save_v;
976             cur_v = save_v + depth(p);
977             cur_h = left_edge;
978           }
979           break;
980
981         case rule_node:
982           {
983             rule_ht = height(p);
984             rule_dp = depth(p);
985             rule_wd = width(p);
986             goto lab14;
987           }
988           break;
989
990         case whatsit_node:
991           out_what(p);
992           break;
993
994         case glue_node:
995           {
996             g = glue_ptr(p);
997             rule_ht = width(g) - cur_g;
998
999             if (g_sign != normal)
1000             {
1001               if (g_sign == stretching)
1002               {
1003                 if (stretch_order(g) == g_order)
1004                 {
1005                   cur_glue = cur_glue + stretch(g);
1006                   glue_temp = glue_set(this_box) * cur_glue;
1007
1008                   if (glue_temp > 1000000000.0)
1009                     glue_temp = 1000000000.0;
1010                   else if (glue_temp < -1000000000.0)
1011                     glue_temp = -1000000000.0;
1012
1013                   cur_g = round(glue_temp);
1014                 }
1015               }
1016               else if (shrink_order(g) == g_order)   /* BUG FIX !!! */
1017               {
1018                 cur_glue = cur_glue - shrink(g);
1019                 glue_temp = glue_set(this_box) * cur_glue;
1020
1021                 if (glue_temp > 1000000000.0)
1022                   glue_temp = 1000000000.0;
1023                 else if (glue_temp < -1000000000.0)
1024                   glue_temp = -1000000000.0;
1025
1026                 cur_g = round(glue_temp);
1027               }
1028             }
1029
1030             rule_ht = rule_ht + cur_g;
1031
1032             if (subtype(p) >= a_leaders)
1033             {
1034               leader_box = leader_ptr(p);
1035
1036               if (type(leader_box) == rule_node)
1037               {
1038                 rule_wd = width(leader_box);
1039                 rule_dp = 0;
1040                 goto lab14;
1041               }
1042
1043               leader_ht = height(leader_box) + depth(leader_box);
1044
1045               if ((leader_ht > 0) && (rule_ht > 0))
1046               {
1047                 rule_ht = rule_ht + 10;
1048                 edge = cur_v + rule_ht;
1049                 lx = 0;
1050
1051                 if (subtype(p) == a_leaders)
1052                 {
1053                   save_v = cur_v;
1054                   cur_v = top_edge + leader_ht * ((cur_v - top_edge) / leader_ht);
1055
1056                   if (cur_v < save_v)
1057                     cur_v = cur_v + leader_ht;
1058                 }
1059                 else
1060                 {
1061                   lq = rule_ht / leader_ht;
1062                   lr = rule_ht % leader_ht;
1063
1064                   if (subtype(p) == c_leaders)
1065                     cur_v = cur_v + (lr / 2);
1066                   else
1067                   {
1068                     lx = (2 * lr + lq + 1) / (2 * lq + 2);
1069                     cur_v = cur_v + ((lr - (lq - 1) * lx) / 2);
1070                   }
1071                 }
1072
1073                 while (cur_v + leader_ht <= edge)
1074                 {
1075                   cur_h = left_edge + shift_amount(leader_box);
1076                   synch_h();
1077                   save_h = dvi_h;
1078                   cur_v = cur_v + height(leader_box);
1079                   synch_v();
1080                   save_v = dvi_v;
1081                   temp_ptr = leader_box;
1082                   outer_doing_leaders = doing_leaders;
1083                   doing_leaders = true;
1084
1085                   if (type(leader_box) == vlist_node)
1086                     vlist_out();
1087                   else
1088                     hlist_out();
1089
1090                   doing_leaders = outer_doing_leaders;
1091                   dvi_v = save_v;
1092                   dvi_h = save_h;
1093                   cur_h = left_edge;
1094                   cur_v = save_v - height(leader_box) + leader_ht + lx;
1095                 }
1096
1097                 cur_v = edge - 10;
1098                 goto lab15;
1099               }
1100             }
1101
1102             goto lab13;
1103           }
1104           break;
1105
1106         case kern_node:
1107           cur_v = cur_v + width(p);
1108           break;
1109
1110         default:
1111           break;
1112       }
1113       goto lab15;
1114 lab14:
1115       if ((rule_wd == -1073741824L))    /* -2^30 */
1116         rule_wd = width(this_box);
1117
1118       rule_ht = rule_ht + rule_dp;
1119       cur_v = cur_v + rule_ht;
1120
1121       if ((rule_ht > 0) && (rule_wd > 0))
1122       {
1123         synch_h();
1124         synch_v();
1125         dvi_out(put_rule);
1126         dvi_four(rule_ht);
1127         dvi_four(rule_wd);
1128       }
1129
1130       goto lab15;
1131 lab13:
1132       cur_v = cur_v + rule_ht;
1133     }
1134 lab15:
1135     p = link(p);
1136   }
1137
1138   prune_movements(save_loc);
1139
1140   if (cur_s > 0)
1141     dvi_pop(save_loc);
1142
1143   decr(cur_s);
1144 }
1145 /* sec 0638 */
1146 /* following needs access to dvi_buf=zdvibuf see coerce.h */
1147 /* sec 0638 */
1148 void dvi_ship_out_(halfword p)
1149 {
1150   integer page_loc;
1151   char j, k;
1152   pool_pointer s;
1153   char old_setting;
1154
1155   if (tracing_output > 0)
1156   {
1157     print_nl("");
1158     print_ln();
1159     print_string("Completed box being shipped out");
1160   }
1161
1162   if (term_offset > max_print_line - 9)
1163     print_ln();
1164   else if ((term_offset > 0) || (file_offset > 0))
1165     print_char(' ');
1166
1167   print_char('[');
1168   j = 9;
1169
1170   while((count(j) == 0) && (j > 0))
1171     decr(j);
1172
1173   for (k = 0; k <= j; k++)
1174   {
1175     print_int(count(k));
1176
1177     if (k < j)
1178       print_char('.');
1179   }
1180
1181 #ifndef _WINDOWS
1182   fflush(stdout);
1183 #endif
1184
1185   if (tracing_output > 0)
1186   {
1187     print_char(']');
1188     begin_diagnostic();
1189     show_box(p);
1190     end_diagnostic(true);
1191   }
1192
1193   if ((height(p) > max_dimen) || (depth(p) > max_dimen) ||
1194       (height(p) + depth(p) + v_offset > max_dimen) ||
1195       (width(p) + h_offset > max_dimen))
1196   {
1197     print_err("Huge page cannot be shipped out");
1198     help2("The page just created is more than 18 feet tall or",
1199         "more than 18 feet wide, so I suspect something went wrong.");
1200     error();
1201
1202     if (tracing_output <= 0)
1203     {
1204       begin_diagnostic();
1205       print_nl("The following box has been deleted:");
1206       show_box(p);
1207       end_diagnostic(true);
1208     }
1209
1210     goto lab30;
1211   }
1212
1213   if (height(p) + depth(p) + v_offset > max_v)
1214     max_v = height(p) + depth(p) + v_offset;
1215
1216   if (width(p) + h_offset > max_h)
1217     max_h = width(p) + h_offset;
1218
1219   dvi_h = 0;
1220   dvi_v = 0;
1221   cur_h = h_offset;
1222   dvi_f = null_font;
1223
1224   if (output_file_name == 0)
1225   {
1226     if (job_name == 0)
1227       open_log_file();
1228
1229     pack_job_name(".dvi");
1230
1231     while(!b_open_out(dvi_file))
1232     {
1233       prompt_file_name("file name for output", ".dvi");
1234     }
1235
1236     output_file_name = b_make_name_string(dvi_file);
1237   }
1238
1239   if (total_pages == 0)
1240   {
1241     dvi_out(pre);
1242     dvi_out(id_byte);
1243     dvi_four(25400000L);  /* magic DVI scale factor */
1244     dvi_four(473628672L); /* 7227 * 65536 */
1245     prepare_mag();
1246     dvi_four(mag);
1247     old_setting = selector;
1248     selector = new_string;
1249     print_string(" TeX output ");
1250     print_int(year);
1251     print_char('.');
1252     print_two(month);
1253     print_char('.');
1254     print_two(day);
1255     print_char(':');
1256     print_two(tex_time / 60);
1257     print_two(tex_time % 60);
1258     selector = old_setting;
1259     dvi_out(cur_length);
1260
1261     for (s = str_start[str_ptr]; s <= pool_ptr - 1; s++)
1262       dvi_out(str_pool[s]);
1263
1264     pool_ptr = str_start[str_ptr];
1265   }
1266
1267   page_loc = dvi_offset + dvi_ptr;
1268   dvi_out(bop);
1269
1270   for (k = 0; k <= 9; k++)
1271     dvi_four(count(k));
1272
1273   dvi_four(last_bop);
1274   last_bop = page_loc;
1275   cur_v = height(p) + v_offset;
1276   temp_ptr = p;
1277
1278   if (type(p) == vlist_node)
1279     vlist_out();
1280   else
1281     hlist_out();
1282
1283   dvi_out(eop); // do not need a endpage in haru.
1284   incr(total_pages);
1285   cur_s = -1;
1286 lab30:;
1287   if (tracing_output <= 0)
1288     print_char(']');
1289
1290   dead_cycles = 0;
1291
1292 #ifndef _WINDOWS
1293   fflush(stdout);
1294 #endif
1295
1296 #ifdef STAT
1297   if (tracing_stats > 1)
1298   {
1299     print_nl("Memory usage before: ");
1300     print_int(var_used);
1301     print_char('&');
1302     print_int(dyn_used);
1303     print_char(';');
1304   }
1305 #endif /* STAT */
1306
1307   flush_node_list(p);
1308
1309 #ifdef STAT
1310   if (tracing_stats > 1)
1311   {
1312     print_string(" after: ");
1313     print_int(var_used);
1314     print_char('&');
1315     print_int(dyn_used);
1316     print_string("; still utouched: ");
1317     print_int(hi_mem_min - lo_mem_max - 1); /* somewhat inaccurate free mem */
1318     print_ln();
1319   }
1320 #endif /* STAT */
1321 }
1322 void ship_out_(halfword p)
1323 {
1324   if (pdf_output_flag)
1325     pdf_ship_out(p);
1326   else
1327     dvi_ship_out_(p);
1328 }
1329 /* sec 0645 */
1330 void scan_spec_(group_code c, bool three_codes)
1331 {
1332   integer s;
1333   char spec_code;
1334
1335   if (three_codes)
1336     s = saved(0);
1337
1338   if (scan_keyword("to"))
1339     spec_code = exactly;
1340   else if (scan_keyword("spread"))
1341     spec_code = additional;
1342   else
1343   {
1344     spec_code = additional;
1345     cur_val = 0;
1346     goto lab40;
1347   }
1348
1349   scan_dimen(false, false, false);
1350
1351 lab40:
1352   if (three_codes)
1353   {
1354     saved(0) = s;
1355     incr(save_ptr);
1356   }
1357
1358   saved(0) = spec_code;
1359   saved(1) = cur_val;
1360   save_ptr = save_ptr + 2;
1361   new_save_level(c);
1362   scan_left_brace();
1363 }
1364 /* sec 0649 */
1365 halfword hpack_(halfword p, scaled w, small_number m)
1366 {
1367   halfword r;
1368   halfword q;
1369   scaled h, d, x;
1370   scaled s;
1371   halfword g;
1372 /*  glue_ord o;  */
1373   int o;              /* 95/Jan/7 */
1374   internal_font_number f;
1375   ffourquarters i;
1376   eight_bits hd;
1377
1378   last_badness = 0;
1379   r = get_node(box_node_size);
1380   type(r) = hlist_node;
1381   subtype(r) = 0;
1382   shift_amount(r) = 0;
1383   q = r + list_offset;
1384   link(q) = p;
1385   h = 0;
1386   d = 0;
1387   x = 0;
1388   total_stretch[normal] = 0;
1389   total_shrink[normal] = 0;
1390   total_stretch[fil] = 0;
1391   total_shrink[fil] = 0;
1392   total_stretch[fill] = 0;
1393   total_shrink[fill] = 0;
1394   total_stretch[filll] = 0;
1395   total_shrink[filll] = 0;
1396
1397   while (p != 0)
1398   {
1399 lab21:
1400     while ((p >= hi_mem_min))
1401     {
1402       f = font(p);
1403       i = char_info(f, character(p));
1404       hd = height_depth(i);
1405       x = x + char_width(f, i);
1406       s = char_height(f, hd);
1407
1408       if (s > h)
1409         h = s;
1410
1411       s = char_depth(f, hd);
1412
1413       if (s > d)
1414         d = s;
1415
1416       p = link(p);
1417     }
1418
1419     if (p != 0)
1420     {
1421       switch (type(p))
1422       {
1423         case hlist_node:
1424         case vlist_node:
1425         case rule_node:
1426         case unset_node:
1427           {
1428             x = x + width(p);
1429
1430             if (type(p) >= rule_node)
1431               s = 0;
1432             else
1433               s = shift_amount(p);
1434
1435             if (height(p) - s > h)
1436               h = height(p) - s;
1437
1438             if (depth(p) + s > d)
1439               d = depth(p) + s;
1440           }
1441           break;
1442
1443         case ins_node:
1444         case mark_node:
1445         case adjust_node:
1446           if (adjust_tail != 0)
1447           {
1448             while (link(q) != p)
1449               q = link(q);
1450
1451             if (type(p) == adjust_node)
1452             {
1453               link(adjust_tail) = adjust_ptr(p);
1454
1455               while (link(adjust_tail)!= 0)
1456                 adjust_tail = link(adjust_tail);
1457
1458               p = link(p);
1459               free_node(link(q), small_node_size);
1460             }
1461             else
1462             {
1463               link(adjust_tail) = p;
1464               adjust_tail = p;
1465               p = link(p);
1466             }
1467
1468             link(q) = p;
1469             p = q;
1470           }
1471           break;
1472
1473         case whatsit_node:
1474           break;
1475         case glue_node:
1476           {
1477             g = glue_ptr(p);
1478             x = x + width(g);
1479             o = stretch_order(g);
1480             total_stretch[o] = total_stretch[o] + stretch(g);
1481             o = shrink_order(g);
1482             total_shrink[o] = total_shrink[o] + shrink(g);
1483
1484             if (subtype(p) >= a_leaders)
1485             {
1486               g = leader_ptr(p);
1487
1488               if (height(g) > h)
1489                 h = height(g);
1490
1491               if (depth(g) > d)
1492                 d = depth(g);
1493             }
1494           }
1495           break;
1496
1497         case kern_node:
1498         case math_node:
1499           x = x + width(p);
1500           break;
1501
1502         case ligature_node:
1503           {
1504             mem[lig_trick] = mem[lig_char(p)];
1505             link(lig_trick) = link(p);
1506             p = lig_trick;
1507             goto lab21;
1508           }
1509           break;
1510
1511         default:
1512           break;
1513       }
1514       p = link(p);
1515     }
1516   }
1517
1518   if (adjust_tail != 0)
1519     link(adjust_tail) = 0;
1520
1521   height(r) = h;
1522   depth(r) = d;
1523
1524   if (m == additional)
1525     w = x + w;
1526
1527   width(r) = w;
1528   x = w - x;
1529
1530   if (x == 0)
1531   {
1532     glue_sign(r) = normal;
1533     glue_order(r) = normal;
1534     glue_set(r) = 0.0;
1535     goto lab10;
1536   }
1537   else if (x > 0)
1538   {
1539     if (total_stretch[filll] != 0)
1540       o = filll;
1541     else if (total_stretch[fill] != 0)
1542       o = fill;
1543     else if (total_stretch[fil] != 0)
1544       o = fil;
1545     else
1546       o = normal;
1547
1548     glue_order(r) = o;
1549     glue_sign(r) = stretching;
1550
1551     if (total_stretch[o] != 0)
1552       glue_set(r) = x / ((double) total_stretch[o]);
1553     else
1554     {
1555       glue_sign(r) = normal;
1556       glue_set(r) = 0.0;
1557     }
1558
1559     if (o == normal)
1560       if (list_ptr(r) != 0)
1561       {
1562         last_badness = badness(x, total_stretch[normal]);
1563
1564         if (last_badness > hbadness)
1565         {
1566           print_ln();
1567
1568           if (last_badness > 100)
1569             print_nl("Underfull");
1570           else
1571             print_nl("Loose");
1572
1573           print_string(" \\hbox (badness ");
1574           print_int(last_badness);
1575
1576           if (last_badness > 100) /* Y&Y TeX */
1577             underfull_hbox++;   /* 1996/Feb/9 */
1578
1579           goto lab50;
1580         }
1581       }
1582       goto lab10;
1583   }
1584   else
1585   {
1586     if (total_shrink[filll] != 0)
1587       o = filll;
1588     else if (total_shrink[fill] != 0)
1589       o = fill;
1590     else if (total_shrink[fil] != 0)
1591       o = fil;
1592     else
1593       o = normal;
1594
1595     glue_order(r) = o;
1596     glue_sign(r) = shrinking;
1597
1598     if (total_shrink[o] != 0)
1599       glue_set(r) =(- (integer) x) / ((double) total_shrink[o]);
1600     else
1601     {
1602       glue_sign(r) = normal;
1603       glue_set(r) = 0.0;
1604     }
1605
1606     if ((total_shrink[o] < - (integer) x) && (o == 0) && (list_ptr(r) != 0))
1607     {
1608       last_badness = 1000000L;
1609       glue_set(r) = 1.0;
1610
1611       if ((- (integer) x - total_shrink[normal] > hfuzz) || (hbadness < 100))
1612       {
1613           if ((overfull_rule > 0) && (- (integer) x - total_shrink[0] > hfuzz))
1614           {
1615               while(link(q) != 0)
1616                 q = link(q);
1617  
1618               link(q) = new_rule();
1619               width(link(q)) = overfull_rule;
1620           }
1621
1622           print_ln();
1623           print_nl("Overfull \\hbox (");
1624           print_scaled(- (integer) x - total_shrink[normal]);
1625           print_string("pt too wide");
1626
1627           overfull_hbox++;      /* 1996/Feb/9 */
1628
1629           goto lab50;
1630       }
1631     }
1632     else if (o == normal)
1633       if (list_ptr(r) != 0)
1634       {
1635         last_badness = badness(- (integer) x, total_shrink[normal]);
1636
1637         if (last_badness > hbadness)
1638         {
1639           print_ln();
1640           print_nl("Tight \\hbox (badness ");
1641           print_int(last_badness);
1642           goto lab50;
1643         }
1644       }
1645       goto lab10;
1646   }
1647 lab50:
1648   if (output_active)
1649     print_string(") has occurred while \\output is active");
1650   else
1651   {
1652     if (pack_begin_line != 0)
1653     {
1654       if (pack_begin_line > 0)
1655         print_string(") in paragraph at lines ");
1656       else
1657         print_string(") in alignment at lines ");
1658
1659       print_int(abs(pack_begin_line));
1660       print_string("--");
1661     }
1662     else
1663       print_string(") detected at line ");
1664
1665     print_int(line);
1666   }
1667
1668   print_ln();
1669   font_in_short_display = null_font;
1670   short_display(list_ptr(r));
1671   print_ln();
1672   begin_diagnostic();
1673   show_box(r);
1674   end_diagnostic(true);
1675 lab10:
1676   return r;
1677 }
1678 /* sec 0668 */
1679 halfword vpackage_(halfword p, scaled h, small_number m, scaled l)
1680 {
1681   halfword r;
1682   scaled w, d, x;
1683   scaled s;
1684   halfword g;
1685 /*  glue_ord o;  */
1686   int o;              /* 95/Jan/7 */
1687
1688   last_badness = 0;
1689   r = get_node(box_node_size);
1690   type(r) = vlist_node;
1691   subtype(r) = min_quarterword;
1692   shift_amount(r) = 0;
1693   list_ptr(r) = p;
1694   w = 0;
1695   d = 0;
1696   x = 0;
1697   total_stretch[normal] = 0;
1698   total_shrink[normal] = 0;
1699   total_stretch[fil] = 0;
1700   total_shrink[fil] = 0;
1701   total_stretch[fill] = 0;
1702   total_shrink[fill] = 0;
1703   total_stretch[filll] = 0;
1704   total_shrink[filll] = 0;
1705
1706   while (p != 0)
1707   {
1708     if ((p >= hi_mem_min))
1709     {
1710       confusion("vpack");
1711       return 0;       // abort_flag set
1712     }
1713     else switch (type(p))
1714     {
1715       case hlist_node:
1716       case vlist_node:
1717       case rule_node:
1718       case unset_node:
1719         {
1720           x = x + d + height(p);
1721           d = depth(p);
1722
1723           if (type(p) >= rule_node)
1724             s = 0;
1725           else
1726             s = shift_amount(p);
1727
1728           if (width(p) + s > w)
1729             w = width(p) + s;
1730         }
1731         break;
1732
1733       case whatsit_node:
1734         break;
1735
1736       case glue_node:
1737         {
1738           x = x + d;
1739           d = 0;
1740           g = glue_ptr(p);
1741           x = x + width(g);
1742           o = stretch_order(g);
1743           total_stretch[o] = total_stretch[o] + stretch(g);
1744           o = shrink_order(g);
1745           total_shrink[o] = total_shrink[o] + shrink(g);
1746
1747           if (subtype(p) >= a_leaders)
1748           {
1749             g = leader_ptr(p);
1750
1751             if (width(g) > w)
1752               w = width(g);
1753           }
1754         }
1755         break;
1756
1757       case kern_node:
1758         {
1759           x = x + d + width(p);
1760           d = 0;
1761         }
1762         break;
1763
1764       default:
1765         break;
1766     }
1767     p = link(p);
1768   }
1769
1770   width(r) = w;
1771
1772   if (d > l)
1773   {
1774     x = x + d - l;
1775     depth(r) = l;
1776   }
1777   else
1778     depth(r) = d;
1779
1780   if (m == additional)
1781     h = x + h;
1782
1783   height(r) = h;
1784   x = h - x;
1785
1786   if (x == 0)
1787   {
1788     glue_sign(r) = normal;
1789     glue_order(r) = normal;
1790     glue_set(r) = 0.0;
1791     goto lab10;
1792   }
1793   else if (x > 0)
1794   {
1795     if (total_stretch[filll] != 0)
1796       o = filll;
1797     else if (total_stretch[fill] != 0)
1798       o = fill;
1799     else if (total_stretch[fil] != 0)
1800       o = fil;
1801     else
1802       o = normal;
1803
1804     glue_order(r) = o;
1805     glue_sign(r) = stretching;
1806
1807     if (total_stretch[o] != 0)
1808       glue_set(r) = x / ((double) total_stretch[o]);
1809     else
1810     {
1811       glue_sign(r) = normal;
1812       glue_set(r) = 0.0;
1813     }
1814
1815     if (o == normal)
1816       if (list_ptr(r) != 0)
1817       {
1818         last_badness = badness(x, total_stretch[normal]);
1819
1820         if (last_badness > vbadness)
1821         {
1822           print_ln();
1823
1824           if (last_badness > 100)
1825             print_nl("Underfull");
1826           else
1827             print_nl("Loose");
1828
1829           print_string(" \\vbox (badness ");
1830           print_int(last_badness);
1831
1832           if (last_badness > 100)
1833             underfull_vbox++; /* 1996/Feb/9 */
1834
1835           goto lab50;
1836         }
1837       }
1838       goto lab10;
1839   }
1840   else
1841   {
1842     if (total_shrink[filll] != 0)
1843       o = filll;
1844     else if (total_shrink[fill] != 0)
1845       o = fill;
1846     else if (total_shrink[fil] != 0)
1847       o = fil;
1848     else
1849       o = normal;
1850
1851     glue_order(r) = o;
1852     glue_sign(r) = shrinking;
1853
1854     if (total_shrink[o] != 0)
1855       glue_set(r) =(- (integer) x)/ ((double) total_shrink[o]);
1856     else
1857     {
1858       glue_sign(r) = normal;
1859       glue_set(r) = 0.0;
1860     }
1861
1862     if ((total_shrink[o] < - (integer) x) && (o == 0) && (list_ptr(r) != 0))
1863     {
1864       last_badness = 1000000L;
1865       glue_set(r) = 1.0;
1866
1867       if ((- (integer) x - total_shrink[0] > vfuzz) || (vbadness < 100))
1868       {
1869         print_ln();
1870         print_nl("Overfull \\vbox (");
1871         print_scaled(- (integer) x - total_shrink[0]);
1872         print_string("pt too high");
1873
1874         overfull_vbox++;    /* 1996/Feb/9 */
1875
1876         goto lab50;
1877       }
1878     }
1879     else if (o == 0)
1880       if (list_ptr(r) != 0)
1881       {
1882         last_badness = badness(- (integer) x, total_shrink[normal]);
1883         if (last_badness > vbadness)
1884         {
1885           print_ln();
1886           print_nl("Tight \\vbox (badness ");
1887           print_int(last_badness);
1888           goto lab50;
1889         }
1890       }
1891     goto lab10;
1892   }
1893 lab50:
1894   if (output_active)
1895     print_string(") has occurred while \\output is active");
1896   else
1897   {
1898     if (pack_begin_line != 0)
1899     {
1900       print_string(") in alignment at lines ");
1901       print_int(abs(pack_begin_line));
1902       print_string("--");
1903     }
1904     else
1905       print_string(") detected at line ");
1906
1907     print_int(line);
1908     print_ln();
1909   }
1910
1911   begin_diagnostic();
1912   show_box(r);
1913   end_diagnostic(true);
1914 lab10:
1915   return r;
1916 }
1917 /* sec 0679 */
1918 void append_to_vlist_(halfword b)
1919 {
1920   scaled d;
1921   halfword p;
1922
1923   if (cur_list.aux_field.cint > ignore_depth)
1924   {
1925     d = width(baseline_skip) - prev_depth - height(b);
1926
1927     if (d < line_skip_limit)
1928       p = new_param_glue(line_skip_code);
1929     else
1930     {
1931       p = new_skip_param(baseline_skip_code);
1932       width(temp_ptr) = d;
1933     }
1934     link(tail) = p;
1935     tail = p;
1936   }
1937
1938   link(tail) = b;
1939   tail = b;
1940   prev_depth = depth(b);
1941 }
1942 /* sec 0686 */
1943 halfword new_noad (void)
1944 {
1945   halfword p;
1946
1947   p = get_node(noad_size);
1948   type(p) = ord_noad;
1949   subtype(p) = normal;
1950   mem[nucleus(p)].hh = empty_field;
1951   mem[subscr(p)].hh = empty_field;
1952   mem[supscr(p)].hh = empty_field;
1953
1954   return p;
1955 }
1956 /* sec 0688 */
1957 halfword new_style_(small_number s)
1958 {
1959   halfword p;
1960
1961   p = get_node(style_node_size);
1962   type(p) = style_node;
1963   subtype(p) = s;
1964   width(p) = 0;
1965   depth(p) = 0;
1966
1967   return p;
1968 }
1969 /* sec 0689 */
1970 halfword new_choice (void)
1971 {
1972   halfword p;
1973
1974   p = get_node(style_node_size);
1975   type(p) = choice_node;
1976   subtype(p) = 0;
1977   display_mlist(p) = 0;
1978   text_mlist(p) = 0;
1979   script_mlist(p) = 0;
1980   script_script_mlist(p) = 0;
1981
1982   return p;
1983 }
1984 /* sec 0693 */
1985 void show_info (void)
1986 {
1987   show_node_list(info(temp_ptr));
1988 }
1989 /* sec 0704 */
1990 halfword fraction_rule_(scaled t)
1991 {
1992   halfword p;
1993
1994   p = new_rule();
1995   height(p) = t;
1996   depth(p) = 0;
1997
1998   return p;
1999 }
2000 /* sec 0705 */
2001 halfword overbar_(halfword b, scaled k, scaled t)
2002 {
2003   halfword p, q;
2004
2005   p = new_kern(k);
2006   link(p) = b;
2007   q = fraction_rule(t);
2008   link(q) = p;
2009   p = new_kern(t);
2010   link(p) = q;
2011   return vpackage(p, 0, 1, 1073741823L); /* 2^30 - 1 */
2012 }
2013 /* sec 0709 */
2014 halfword char_box_(internal_font_number f, quarterword c)
2015 {
2016   ffourquarters q;
2017   eight_bits hd;
2018   halfword b, p;
2019
2020   q = char_info(f, c);
2021   hd = height_depth(q);
2022   b = new_null_box();
2023   width(b) = char_width(f, q) + char_italic(f, q);
2024   height(b) = char_height(f, hd);
2025   depth(b) = char_depth(f, hd);
2026   p = get_avail();
2027   character(p) = c;
2028   font(p) = f;
2029   list_ptr(b) = p;
2030
2031   return b;
2032 }
2033 /* sec 0711 */
2034 void stack_into_box_(halfword b, internal_font_number f, quarterword c)
2035 {
2036   halfword p;
2037
2038   p = char_box(f, c);
2039   link(p) = list_ptr(b);
2040   list_ptr(b) = p;
2041   height(b) = height(p);
2042 }
2043 /* sec 0712 */
2044 scaled height_plus_depth_(internal_font_number f, fquarterword c)
2045 {
2046   ffourquarters q;
2047   eight_bits hd;
2048
2049   q = char_info(f, c);
2050   hd = height_depth(q);
2051   return char_height(f, hd) + char_depth(f, hd);
2052 }
2053 /* sec 0706 */
2054 halfword var_delimiter_(halfword d, small_number s, scaled v)
2055 {
2056   halfword b;
2057   internal_font_number f, g;
2058   quarterword c, x, y;
2059   integer m, n;
2060   scaled u;
2061   scaled w;
2062   ffourquarters q;
2063   ffourquarters r;
2064   eight_bits hd;
2065 /*  small_number z;  */
2066   int z;                  /* 95/Jan/7 */
2067 /*  bool large_attempt;  */
2068   int large_attempt;           /* 95/Jan/7 */
2069
2070   f = null_font;
2071   w = 0;
2072   large_attempt = false;
2073   z = small_fam(d);
2074   x = small_char(d);
2075
2076   while (true)
2077   {
2078     if ((z != 0) || (x != 0))
2079     {
2080       z = z + s + 16;
2081
2082       do
2083         {
2084           z = z - 16;
2085           g = fam_fnt(z);
2086
2087           if (g != null_font)
2088           {
2089             y = x;
2090
2091             if ((y >= font_bc[g]) && (y <= font_ec[g]))
2092             {
2093 lab22:
2094               q = char_info(g, y);
2095               
2096               if ((q.b0 > 0))
2097               {
2098                 if (char_tag(q) == ext_tag)
2099                 {
2100                   f = g;
2101                   c = y;
2102                   goto lab40;
2103                 }
2104
2105                 hd = height_depth(q);
2106                 u = char_height(g, hd) + char_depth(g, hd);
2107
2108                 if (u > w)
2109                 {
2110                   f = g;
2111                   c = y;
2112                   w = u;
2113
2114                   if (u >= v)
2115                     goto lab40;
2116                 }
2117
2118                 if (char_tag(q) == list_tag)
2119                 {
2120                   y = rem_byte(q);
2121                   goto lab22;
2122                 }
2123               }
2124             }
2125           }
2126         }
2127       while (!(z < 16));
2128     }
2129
2130     if (large_attempt)
2131       goto lab40;
2132
2133     large_attempt = true;
2134     z = large_fam(d);
2135     x = large_char(d);
2136   }
2137 lab40:
2138   if (f != null_font)
2139     if (char_tag(q) == ext_tag)
2140     {
2141       b = new_null_box();
2142       type(b) = vlist_node;
2143       r = font_info[exten_base[f] + rem_byte(q)].qqqq;
2144       c = ext_rep(r);
2145       u = height_plus_depth(f, c);
2146       w = 0;
2147       q = char_info(f, c);
2148       width(b) = char_width(f, q) + char_italic(f, q);
2149       c = ext_bot(r);
2150
2151       if (c != min_quarterword)
2152         w = w + height_plus_depth(f, c);
2153
2154       c = ext_mid(r);
2155
2156       if (c != min_quarterword)
2157         w = w + height_plus_depth(f, c);
2158
2159       c = ext_top(r);
2160
2161       if (c != min_quarterword)
2162         w = w + height_plus_depth(f, c);
2163
2164       n = 0;
2165
2166       if (u > 0)
2167         while(w < v)
2168         {
2169           w = w + u;
2170           incr(n);
2171
2172           if (ext_mid(r) != min_quarterword)
2173             w = w + u;
2174         }
2175
2176       c = ext_bot(r);
2177
2178       if (c != min_quarterword)
2179         stack_into_box(b, f, c);
2180
2181       c = ext_rep(r);
2182
2183       for (m = 1; m <= n; m++)
2184         stack_into_box(b, f, c);
2185
2186       c = ext_mid(r);
2187
2188       if (c != min_quarterword)
2189       {
2190         stack_into_box(b, f, c);
2191         c = ext_rep(r);
2192
2193         for (m = 1; m <= n; m++)
2194           stack_into_box(b, f, c);
2195       }
2196
2197       c = ext_top(r);
2198
2199       if (c != 0)
2200         stack_into_box(b, f, c);
2201       
2202       depth(b) = w - height(b);
2203     }
2204     else
2205       b = char_box(f, c);
2206   else
2207   {
2208     b = new_null_box();
2209     width(b) = null_delimiter_space;
2210   }
2211
2212   shift_amount(b) = half(height(b) - depth(b)) - axis_height(s);
2213
2214   return b;
2215 }
2216 /* rebox_ etc used to follow here in tex4.c */