OSDN Git Service

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