OSDN Git Service

ae9e0362575000da2909b16b0af8650e29dc9b91
[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     pack_job_name(788);   /* .dvi */
1192     while(!b_open_out(dvi_file))
1193     {
1194       prompt_file_name(789, 788); /* file name for output  .dvi */
1195     }
1196     output_file_name = b_make_name_string(dvi_file);
1197   }
1198
1199   if (total_pages == 0)
1200   {
1201     dvi_out(247);
1202     dvi_out(2);
1203 /********BINDING WITH LIBHARU*********/
1204 /*
1205     yandy_pdf = HPDF_New(error_handler, NULL);
1206     yandy_page = HPDF_AddPage(yandy_pdf);
1207     HPDF_SetInfoAttr(yandy_pdf, HPDF_INFO_PRODUCER, "Y&Y TeX with ApTeX");
1208     HPDF_SetCompressionMode (yandy_pdf, HPDF_COMP_ALL);
1209     HPDF_Page_SetSize (yandy_page, HPDF_PAGE_SIZE_A5, HPDF_PAGE_PORTRAIT);
1210     yandy_font = HPDF_GetFont (yandy_pdf, "Times-Roman", NULL);
1211     HPDF_Page_BeginText (yandy_page);
1212     HPDF_Page_SetFontAndSize (yandy_page, yandy_font, 16);
1213     HPDF_Page_TextOut (yandy_page, 60, HPDF_Page_GetHeight (yandy_page)-90,  "This is the \xAErst page.");
1214     HPDF_Page_TextOut (yandy_page, 60, HPDF_Page_GetHeight (yandy_page)-180, "Wait for ...");
1215     HPDF_Page_EndText (yandy_page);
1216     HPDF_SaveToFile (yandy_pdf, "NOTICE.pdf");
1217     HPDF_Free(yandy_pdf);
1218  */
1219 /********BINDING WITH LIBHARU*********/
1220     dvi_four(25400000L);  /* magic DVI scale factor */
1221     dvi_four(473628672L); /* 7227 * 65536 */
1222     prepare_mag();
1223     dvi_four(mag);
1224     old_setting = selector;
1225     selector = new_string;
1226     print_string(" TeX output ");
1227     print_int(year);
1228     print_char('.');
1229     print_two(month);
1230     print_char('.');
1231     print_two(day);
1232     print_char(':');
1233     print_two(tex_time / 60);
1234     print_two(tex_time % 60);
1235     selector = old_setting;
1236 /* long to unsigned char ... */
1237     dvi_out(cur_length);
1238     for (s = str_start[str_ptr]; s <= pool_ptr - 1; s++)
1239       dvi_out(str_pool[s]);
1240     pool_ptr = str_start[str_ptr];
1241   } // end of if total_pages == 0
1242
1243   pageloc = dvi_offset + dvi_ptr;
1244   dvi_out(139);
1245   for (k = 0; k <= 9; k++)
1246     dvi_four(count(k));
1247   dvi_four(last_bop);
1248   last_bop = pageloc;
1249   cur_v = height(p) + v_offset;
1250   temp_ptr = p;
1251   if (type(p) == vlist_node)
1252     vlist_out();
1253   else
1254     hlist_out();
1255   dvi_out(140);
1256   incr(total_pages);
1257   cur_s = -1;
1258 lab30:;
1259   if (tracing_output <= 0)
1260     print_char(']');
1261   dead_cycles = 0;
1262 #ifndef _WINDOWS
1263   fflush(stdout);
1264 #endif
1265
1266 #ifdef STAT
1267   if (tracing_stats > 1)
1268   {
1269     print_nl("Memory usage before: ");
1270     print_int(var_used);
1271     print_char('&');
1272     print_int(dyn_used);
1273     print_char(';');
1274   }
1275 #endif /* STAT */
1276   flush_node_list(p);
1277 #ifdef STAT
1278   if (tracing_stats > 1)
1279   {
1280     print_string(" after: ");
1281     print_int(var_used);
1282     print_char('&');
1283     print_int(dyn_used);
1284     print_string("; still utouched: ");
1285     print_int(hi_mem_min - lo_mem_max - 1); /* somewhat inaccurate free mem */
1286     print_ln();
1287   }
1288 #endif /* STAT */
1289 }
1290 /* sec 0645 */
1291 void scan_spec_(group_code c, bool threecodes)
1292 {
1293   integer s;
1294   char speccode;
1295
1296   if (threecodes)
1297     s = save_stack[save_ptr + 0].cint;
1298   if (scan_keyword("to"))
1299     speccode = 0;
1300   else if (scan_keyword("spread"))
1301     speccode = 1;
1302   else
1303   {
1304     speccode = 1;
1305     cur_val = 0;
1306     goto lab40;
1307   }
1308   scan_dimen(false, false, false);
1309 lab40:
1310   if (threecodes)
1311   {
1312     save_stack[save_ptr + 0].cint = s;  /* s may be used without ... */
1313     incr(save_ptr);
1314   }
1315   save_stack[save_ptr + 0].cint = speccode;
1316   save_stack[save_ptr + 1].cint = cur_val;
1317   save_ptr = save_ptr + 2;
1318   new_save_level(c);
1319   scan_left_brace();
1320 }
1321 /* sec 0649 */
1322 halfword hpack_(halfword p, scaled w, small_number m)
1323 {
1324   register halfword Result;
1325   halfword r;
1326   halfword q;
1327   scaled h, d, x;
1328   scaled s;
1329   halfword g;
1330 /*  glue_ord o;  */
1331   int o;              /* 95/Jan/7 */
1332   internal_font_number f;
1333   ffourquarters i;
1334   eight_bits hd;
1335
1336   last_badness = 0;
1337   r = get_node(box_node_size);
1338   type(r) = hlist_node;
1339   subtype(r) = 0;
1340   shift_amount(r) = 0;
1341   q = r + list_offset;
1342   link(q) = p;
1343   h = 0;
1344   d = 0;
1345   x = 0;
1346   total_stretch[normal] = 0;
1347   total_shrink[normal] = 0;
1348   total_stretch[fil] = 0;
1349   total_shrink[fil] = 0;
1350   total_stretch[fill] = 0;
1351   total_shrink[fill] = 0;
1352   total_stretch[filll] = 0;
1353   total_shrink[filll] = 0;
1354   while (p != 0)
1355   { /* while p<>null do l.12862 */
1356 lab21:
1357     while ((p >= hi_mem_min))
1358     {
1359       f = font(p);
1360       i = font_info[char_base[f] + mem[p].hh.b1].qqqq;
1361       hd = i.b1;
1362       x = x + font_info[width_base[f] + i.b0].cint;
1363       s = font_info[height_base[f] + (hd) / 16].cint;
1364       if (s > h)
1365         h = s;
1366       s = font_info[depth_base[f] + (hd) % 16].cint;
1367       if (s > d)
1368         d = s;
1369       p = link(p);
1370     }
1371     if (p != 0)  /* if p<>null then l.12886 */
1372     {
1373       switch (mem[p].hh.b0)
1374       {
1375         case hlist_node:
1376         case vlist_node:
1377         case rule_node:
1378         case unset_node:
1379           {
1380             x = x + width(p);
1381             if (type(p) >= rule_node)
1382               s = 0;
1383             else
1384               s = shift_amount(p);
1385             if (height(p) - s > h)
1386               h = height(p) - s;
1387             if (depth(p) + s > d)
1388               d = depth(p) + s;
1389           }
1390           break;
1391         case ins_node:
1392         case mark_node:
1393         case adjust_node:
1394           if (adjust_tail != 0)
1395           {
1396             while (link(q) != p)
1397               q = link(q);
1398             if (type(p) == adjust_node)
1399             {
1400               link(adjust_tail) = adjust_ptr(p);
1401               while (link(adjust_tail)!= 0)
1402                 adjust_tail = link(adjust_tail);
1403               p = link(p);
1404               free_node(link(q), small_node_size);
1405             }
1406             else
1407             {
1408               link(adjust_tail) = p;
1409               adjust_tail = p;
1410               p = link(p);
1411             }
1412             link(q) = p;
1413             p = q;
1414           }
1415           break;
1416         case whatsit_node:
1417           break;
1418         case glue_node:
1419           {
1420             g = glue_ptr(p);
1421             x = x + width(g);
1422             o = stretch_order(g);
1423             total_stretch[o]= total_stretch[o] + stretch(g);
1424             o = shrink_order(g);
1425             total_shrink[o]= total_shrink[o] + shrink(g);
1426             if (subtype(p) >= a_leaders)
1427             {
1428               g = leader_ptr(p);
1429               if (height(g) > h)
1430                 h = height(g);
1431               if (depth(g) > d)
1432                 d = depth(g);
1433             }
1434           }
1435           break;
1436         case kern_node:
1437         case math_node:
1438           x = x + width(p);
1439           break;
1440         case ligature_node:
1441           {
1442             mem[lig_trick] = mem[lig_char(p)];
1443             link(lig_trick) = link(p);
1444             p = lig_trick;
1445             goto lab21;
1446           }
1447           break;
1448         default:
1449           break;
1450       }
1451       p = link(p);
1452     }
1453   }
1454   if (adjust_tail != 0)
1455     link(adjust_tail) = 0;
1456   height(r) = h;
1457   depth(r) = d;
1458   if (m == 1)
1459     w = x + w;
1460   width(r) = w;
1461   x = w - x;
1462   if (x == 0)
1463   {
1464     glue_sign(r) = normal;
1465     glue_order(r) = normal;
1466     glue_set(r) = 0.0;
1467     goto lab10;
1468   }
1469   else if (x > 0)
1470   {
1471     if (total_stretch[filll] != 0)
1472       o = filll;
1473     else if (total_stretch[fill] != 0)
1474       o = fill;
1475     else if (total_stretch[fil] != 0)
1476       o = fil;
1477     else
1478       o = normal;
1479     glue_order(r) = o;
1480     glue_sign(r) = stretching;
1481     if (total_stretch[o]!= 0)
1482       glue_set(r) = x / ((double) total_stretch[o]);
1483     else
1484     {
1485       glue_sign(r) = normal;
1486       glue_set(r) = 0.0;
1487     }
1488     if (o == normal)
1489       if (list_ptr(r) != 0)
1490       {
1491         last_badness = badness(x, total_stretch[0]);
1492         if (last_badness > hbadness)
1493         {
1494           print_ln();
1495           if (last_badness > 100)
1496             print_nl("Underfull");
1497           else
1498             print_nl("Loose");
1499           print_string(" \\hbox (badness ");
1500           print_int(last_badness);
1501           if (last_badness > 100) /* Y&Y TeX */
1502             underfull_hbox++;   /* 1996/Feb/9 */
1503           goto lab50;
1504         }
1505       }
1506       goto lab10;
1507   }
1508   else
1509   {
1510     if (total_shrink[filll] != 0)
1511       o = filll;
1512     else if (total_shrink[fill] != 0)
1513       o = fill;
1514     else if (total_shrink[fil] != 0)
1515       o = fil;
1516     else
1517       o = normal;
1518     glue_order(r) = o;
1519     glue_sign(r) = shrinking;
1520     if (total_shrink[o] != 0)
1521       glue_set(r) =(- (integer) x) / ((double) total_shrink[o]);
1522     else
1523     {
1524       glue_sign(r) = normal;
1525       glue_set(r) = 0.0;
1526     }
1527     if ((total_shrink[o] < - (integer) x) && (o == 0) && (list_ptr(r) != 0))
1528     {
1529       last_badness = 1000000L;
1530       glue_set(r) = 1.0;
1531       if ((- (integer) x - total_shrink[0] > hfuzz) || (hbadness < 100))
1532       {
1533           if ((overfull_rule > 0) && (- (integer) x - total_shrink[0] > hfuzz))
1534           {
1535               while(link(q) != 0)
1536                 q = link(q);
1537               link(q) = new_rule();
1538               width(link(q)) = overfull_rule;
1539           }
1540           print_ln();
1541           print_nl("Overfull \\hbox(");
1542           print_scaled(- (integer) x - total_shrink[0]);
1543           print_string("pt too wide");
1544           overfull_hbox++;      /* 1996/Feb/9 */
1545           goto lab50;
1546       }
1547     }
1548     else if (o == normal)
1549       if (list_ptr(r) != 0)
1550       {
1551         last_badness = badness(- (integer) x, total_shrink[normal]);
1552         if (last_badness > hbadness)
1553         {
1554           print_ln();
1555           print_nl("Tight \\hbox (badness ");
1556           print_int(last_badness);
1557           goto lab50;
1558         }
1559       }
1560       goto lab10;
1561   }
1562 lab50:
1563   if (output_active)
1564     print_string(") has occurred while \\output is active");
1565   else
1566   {
1567     if (pack_begin_line != 0)
1568     {
1569       if (pack_begin_line > 0)
1570         print_string(") in paragraph at lines ");
1571       else
1572         print_string(") in alignment at lines ");
1573       print_int(abs(pack_begin_line));
1574       print_string("--");
1575     }
1576     else
1577       print_string(") detected at line ");
1578     print_int(line);
1579   }
1580   print_ln();
1581   font_in_short_display = 0;
1582   short_display(list_ptr(r));
1583   print_ln();
1584   begin_diagnostic();
1585   show_box(r);
1586   end_diagnostic(true);
1587 lab10:
1588   Result = r;
1589   return Result;
1590 }
1591 /* sec 0668 */
1592 halfword vpackage_(halfword p, scaled h, small_number m, scaled l)
1593 {
1594   register halfword Result;
1595   halfword r;
1596   scaled w, d, x;
1597   scaled s;
1598   halfword g;
1599 /*  glue_ord o;  */
1600   int o;              /* 95/Jan/7 */
1601
1602   last_badness = 0;
1603   r = get_node(box_node_size);
1604   type(r) = vlist_node;
1605   subtype(r) = 0;
1606   shift_amount(r) = 0;
1607   list_ptr(r) = p;
1608   w = 0;
1609   d = 0;
1610   x = 0;
1611   total_stretch[normal] = 0;
1612   total_shrink[normal] = 0;
1613   total_stretch[fil] = 0;
1614   total_shrink[fil] = 0;
1615   total_stretch[fill] = 0;
1616   total_shrink[fill] = 0;
1617   total_stretch[filll] = 0;
1618   total_shrink[filll] = 0;
1619
1620   while (p != 0)
1621   {
1622     if ((p >= hi_mem_min))
1623     {
1624       confusion("vpack");
1625       return 0;       // abort_flag set
1626     }
1627     else switch (mem[p].hh.b0)
1628     {
1629       case hlist_node:
1630       case vlist_node:
1631       case rule_node:
1632       case unset_node:
1633         {
1634           x = x + d + height(p);
1635           d = depth(p);
1636           if (type(p) >= rule_node)
1637             s = 0;
1638           else
1639             s = shift_amount(p);
1640           if (width(p) + s > w)
1641             w = width(p) + s;
1642         }
1643         break;
1644       case whatsit_node:
1645         break;
1646       case glue_node:
1647         {
1648           x = x + d;
1649           d = 0;
1650           g = glue_ptr(p);
1651           x = x + width(g);
1652           o = stretch_order(g);
1653           total_stretch[o] = total_stretch[o] + stretch(g);
1654           o = shrink_order(g);
1655           total_shrink[o] = total_shrink[o] + shrink(g);
1656
1657           if (subtype(p) >= a_leaders)
1658           {
1659             g = leader_ptr(p);
1660             if (width(g) > w)
1661               w = width(g);
1662           }
1663         }
1664         break;
1665       case kern_node:
1666         {
1667           x = x + d + width(p);
1668           d = 0;
1669         }
1670         break;
1671       default:
1672         break;
1673     }
1674     p = link(p);
1675   }
1676   width(r) = w;
1677
1678   if (d > l)
1679   {
1680     x = x + d - l;
1681     depth(r) = l;
1682   }
1683   else
1684     depth(r) = d;
1685
1686   if (m == 1)
1687     h = x + h;
1688   height(r) = h;
1689   x = h - x;
1690   if (x == 0)
1691   {
1692     glue_sign(r) = normal;
1693     glue_order(r) = normal;
1694     glue_set(r) = 0.0;
1695     goto lab10;
1696   }
1697   else if (x > 0)
1698   {
1699     if (total_stretch[filll] != 0)
1700       o = filll;
1701     else if (total_stretch[fill] != 0)
1702       o = fill;
1703     else if (total_stretch[fil] != 0)
1704       o = fil;
1705     else
1706       o = normal;
1707     glue_order(r) = o;
1708     glue_sign(r) = stretching;
1709
1710     if (total_stretch[o] != 0)
1711       glue_set(r) = x / ((double) total_stretch[o]);
1712     else
1713     {
1714       glue_sign(r) = normal;
1715       glue_set(r) = 0.0;
1716     }
1717
1718     if (o == normal)
1719       if (list_ptr(r) != 0)
1720       {
1721         last_badness = badness(x, total_stretch[normal]);
1722         if (last_badness > vbadness)
1723         {
1724           print_ln();
1725           if (last_badness > 100)
1726             print_nl("Underfull");
1727           else
1728             print_nl("Loose");
1729           print_string(" \\vbox (badness ");
1730           print_int(last_badness);
1731           if (last_badness > 100)
1732             underfull_vbox++; /* 1996/Feb/9 */
1733           goto lab50;
1734         }
1735       }
1736       goto lab10;
1737   }
1738   else
1739   {
1740     if (total_shrink[filll] != 0)
1741       o = filll;
1742     else if (total_shrink[fill] != 0)
1743       o = fill;
1744     else if (total_shrink[fil] != 0)
1745       o = fil;
1746     else
1747       o = normal;
1748     glue_order(r) = o;
1749     glue_sign(r) = shrinking;
1750     if (total_shrink[o]!= 0)
1751       glue_set(r) =(- (integer) x)/ ((double) total_shrink[o]);
1752     else
1753     {
1754       glue_sign(r) = normal;
1755       glue_set(r) = 0.0;
1756     }
1757
1758     if ((total_shrink[o] < - (integer) x) && (o == 0) && (list_ptr(r) != 0))
1759     {
1760       last_badness = 1000000L;
1761       glue_set(r) = 1.0;
1762       if ((- (integer) x - total_shrink[0] > vfuzz) || (vbadness < 100))
1763       {
1764         print_ln();
1765         print_nl("Overfull \\vbox(");
1766         print_scaled(- (integer) x - total_shrink[0]);
1767         print_string("pt too high");
1768         overfull_vbox++;    /* 1996/Feb/9 */
1769         goto lab50;
1770       }
1771     }
1772     else if (o == 0)
1773       if (list_ptr(r) != 0)
1774       {
1775         last_badness = badness(- (integer) x, total_shrink[normal]);
1776         if (last_badness > vbadness)
1777         {
1778           print_ln();
1779           print_nl("Tight \\vbox (badness ");
1780           print_int(last_badness);
1781           goto lab50;
1782         }
1783       }
1784     goto lab10;
1785   }
1786 lab50:
1787   if (output_active)
1788     print_string(") has occurred while \\output is active");
1789   else {
1790     if (pack_begin_line != 0)
1791     {
1792       print_string(") in alignment at lines ");
1793       print_int(abs(pack_begin_line));
1794       print_string("--");
1795     }
1796     else
1797       print_string(") detected at line ");
1798     print_int(line);
1799     print_ln();
1800   }
1801   begin_diagnostic();
1802   show_box(r);
1803   end_diagnostic(true);
1804 lab10:
1805   Result = r;
1806   return Result;
1807 }
1808 /* sec 0679 */
1809 void append_to_vlist_(halfword b)
1810 {
1811   scaled d;
1812   halfword p;
1813
1814   if (cur_list.aux_field.cint > ignore_depth)
1815   {
1816     d = width(baseline_skip) - cur_list.aux_field.cint - height(b);
1817
1818     if (d < line_skip_limit)
1819       p = new_param_glue(line_skip_code);
1820     else
1821     {
1822       p = new_skip_param(baseline_skip_code);
1823       width(temp_ptr) = d;
1824     }
1825     link(tail) = p;
1826     tail = p;
1827   }
1828   link(tail) = b;
1829   tail = b;
1830   cur_list.aux_field.cint = depth(b);
1831 }
1832 /* sec 0686 */
1833 halfword new_noad (void)
1834 {
1835   halfword p;
1836   p = get_node(noad_size);
1837   type(p) = ord_noad;
1838   subtype(p) = normal;
1839   mem[nucleus(p)].hh = empty_field;
1840   mem[subscr(p)].hh = empty_field;
1841   mem[supscr(p)].hh = empty_field;
1842   return p;
1843 }
1844 /* sec 0688 */
1845 halfword new_style_(small_number s)
1846 {
1847   halfword p;
1848   p = get_node(style_node_size);
1849   type(p) = style_node;
1850   subtype(p) = s;
1851   width(p) = 0;
1852   depth(p) = 0;
1853   return p;
1854 }
1855 /* sec 0689 */
1856 halfword new_choice (void)
1857 {
1858   halfword p;
1859   p = get_node(style_node_size);
1860   type(p) = choice_node;
1861   subtype(p) = 0;
1862   display_mlist(p) = 0;
1863   text_mlist(p) = 0;
1864   script_mlist(p) = 0;
1865   script_script_mlist(p) = 0;
1866   return p;
1867 }
1868 /* sec 0693 */
1869 void show_info (void)
1870 {
1871   show_node_list(info(temp_ptr));
1872 }
1873 /* sec 0704 */
1874 halfword fraction_rule_(scaled t)
1875 {
1876   halfword p;
1877   p = new_rule();
1878   height(p) = t;
1879   depth(p) = 0;
1880   return p;
1881 }
1882 halfword overbar_(halfword b, scaled k, scaled t)
1883 {
1884   register halfword Result;
1885   halfword p, q;
1886   p = new_kern(k);
1887   mem[p].hh.v.RH = b;
1888   q = fraction_rule(t);
1889   mem[q].hh.v.RH = p;
1890   p = new_kern(t);
1891   mem[p].hh.v.RH = q;
1892   Result = vpackage(p, 0, 1, 1073741823L); /* 2^30 - 1 */
1893   return Result;
1894 }
1895 halfword char_box_(internal_font_number f, quarterword c)
1896 {
1897   register halfword Result;
1898   ffourquarters q;
1899   eight_bits hd;
1900   halfword b, p;
1901   q = font_info[char_base[f] + c].qqqq;
1902   hd = q.b1;
1903   b = new_null_box();
1904   mem[b + 1].cint = font_info[width_base[f] + q.b0].cint + font_info[italic_base[f] + (q.b2) / 4].cint;
1905   mem[b + 3].cint = font_info[height_base[f] + (hd) / 16].cint;
1906   mem[b + 2].cint = font_info[depth_base[f] + (hd) % 16].cint;
1907 /*  long to unsigned short ... */
1908   p = get_avail();
1909   mem[p].hh.b1 = c;
1910   mem[p].hh.b0 = f;
1911   mem[b + 5].hh.v.RH = p;
1912   Result = b;
1913   return Result;
1914 }
1915 void stack_into_box_(halfword b, internal_font_number f, quarterword c)
1916 {
1917   halfword p;
1918   p = char_box(f, c);
1919   mem[p].hh.v.RH = mem[b + 5].hh.v.RH;
1920   mem[b + 5].hh.v.RH = p;
1921   mem[b + 3].cint = mem[p + 3].cint;
1922
1923 scaled height_plus_depth_(internal_font_number f, fquarterword c)
1924 {
1925   register scaled Result;
1926   ffourquarters q;
1927   eight_bits hd;
1928   q = font_info[char_base[f]+ c].qqqq;
1929   hd = q.b1;
1930   Result = font_info[height_base[f] + (hd) / 16].cint + font_info[depth_base[f] + (hd) % 16].cint;
1931   return Result;
1932 }
1933 halfword var_delimiter_(halfword d, small_number s, scaled v)
1934 {
1935   register halfword Result;
1936   halfword b;
1937   internal_font_number f, g;
1938   quarterword c, x, y;
1939   integer m, n;
1940   scaled u;
1941   scaled w;
1942   ffourquarters q;
1943   ffourquarters r;
1944   eight_bits hd;
1945 /*  small_number z;  */
1946   int z;                  /* 95/Jan/7 */
1947 /*  bool largeattempt;  */
1948   int largeattempt;           /* 95/Jan/7 */
1949   f = 0;
1950   w = 0;
1951   largeattempt = false;
1952   z = mem[d].qqqq.b0;
1953   x = mem[d].qqqq.b1;
1954   while (true)
1955   {
1956     if ((z != 0) || (x != 0))
1957     {
1958       z = z + s + 16;
1959       do
1960       {
1961         z = z - 16;
1962         g = eqtb[(hash_size + 1835) + z].hh.v.RH;
1963         if (g != 0) {
1964           y = x;
1965           if ((y >= font_bc[g]) && (y <= font_ec[g]))
1966           {
1967 lab22:
1968             q = font_info[char_base[g]+ y].qqqq;
1969             if ((q.b0 > 0))
1970             {
1971               if (((q.b2) % 4) == 3)
1972               {
1973                 f = g;
1974                 c = y;
1975                 goto lab40;
1976               }
1977               hd = q.b1;
1978               u = font_info[height_base[g] + (hd) / 16].cint + font_info[depth_base[g] + (hd) % 16].cint;
1979               if (u > w) {
1980                 f = g;
1981                 c = y;
1982                 w = u;
1983                 if (u >= v)
1984                   goto lab40;
1985               }
1986               if (((q.b2)% 4)== 2) {
1987                 y = q.b3;
1988                 goto lab22;
1989               }
1990             }
1991           }
1992         }
1993       } while (!(z < 16));
1994     } 
1995     if (largeattempt)
1996       goto lab40;
1997     largeattempt = true;
1998     z = mem[d].qqqq.b2;
1999     x = mem[d].qqqq.b3;
2000   }
2001 lab40:
2002   if (f != 0)
2003     if (((q.b2) % 4)== 3)   /* q may be used without ... */
2004     {
2005       b = new_null_box(); 
2006       mem[b].hh.b0 = 1; 
2007       r = font_info[exten_base[f]+ q.b3].qqqq;
2008       c = r.b3;
2009       u = height_plus_depth(f, c);
2010       w = 0;
2011       q = font_info[char_base[f]+ c].qqqq;
2012       mem[b + 1].cint = font_info[width_base[f]+ q.b0].cint + font_info[italic_base[f]+(q.b2) / 4].cint;
2013       c = r.b2;
2014       if (c != 0)
2015         w = w + height_plus_depth(f, c);
2016       c = r.b1;
2017       if (c != 0)
2018         w = w + height_plus_depth(f, c);
2019       c = r.b0; 
2020       if (c != 0)
2021         w = w + height_plus_depth(f, c);
2022       n = 0;
2023       if (u > 0)
2024         while(w < v) {
2025           w = w + u;
2026           incr(n);
2027           if (r.b1 != 0)
2028             w = w + u;
2029         }
2030         c = r.b2;
2031         if (c != 0)
2032           stack_into_box(b, f, c); 
2033         c = r.b3;
2034         for (m = 1; m <= n; m++)
2035         {
2036           stack_into_box(b, f, c);
2037         }
2038         c = r.b1;
2039         if (c != 0) {
2040           stack_into_box(b, f, c); 
2041           c = r.b3;
2042           for (m = 1; m <= n; m++)
2043           {
2044             stack_into_box(b, f, c);
2045           }
2046         }
2047         c = r.b0;
2048         if (c != 0)
2049           stack_into_box(b, f, c);
2050         mem[b + 2].cint = w - mem[b + 3].cint;
2051     } else b = char_box(f, c);
2052   else {    /* c may be used without ... */
2053     b = new_null_box();
2054     mem[b + 1].cint = null_delimiter_space;
2055   } 
2056   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;
2057   Result = b;
2058   return Result;
2059 }
2060 /* rebox_ etc used to follow here in tex4.c */