OSDN Git Service

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