OSDN Git Service

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