OSDN Git Service

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