OSDN Git Service

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