OSDN Git Service

update.
[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 = mem[p + 1].hh.v.RH;
778             if (mem[leaderbox].hh.b0 == 2)
779             {
780               rule_ht = mem[leaderbox + 3].cint;
781               rule_dp = mem[leaderbox + 2].cint;
782               goto lab14;
783             }
784             leaderwd = mem[leaderbox + 1].cint;
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 (mem[p].hh.b1 == 100)
791       {
792         saveh = cur_h; 
793         cur_h = leftedge + leaderwd *((cur_h - leftedge)/ leaderwd)
794      ; 
795         if (cur_h < saveh)
796         cur_h = cur_h + leaderwd; 
797       } 
798       else {
799     
800         lq = rule_wd / leaderwd; 
801         lr = rule_wd % leaderwd; 
802         if (mem[p].hh.b1 == 101)
803         cur_h = cur_h +(lr / 2); 
804         else {
805       
806     lx =(2 * lr + lq + 1)/(2 * lq + 2); 
807     cur_h = cur_h +((lr -(lq - 1)* lx)/ 2); 
808         } 
809       } 
810       while(cur_h + leaderwd <= edge){
811     
812         cur_v = baseline + mem[leaderbox + 4].cint; 
813         if (cur_v != dvi_v)
814         {
815     movement(cur_v - dvi_v, 157); /* 157 == down1 */
816     dvi_v = cur_v; 
817         } 
818         savev = dvi_v; 
819         if (cur_h != dvi_h)
820         {
821     movement(cur_h - dvi_h, 143); /* 143 == right1 */
822     dvi_h = cur_h; 
823         } 
824         saveh = dvi_h; 
825         temp_ptr = leaderbox; 
826         outerdoingleaders = doing_leaders; 
827         doing_leaders = true; 
828         if (mem[leaderbox].hh.b0 == 1)vlist_out(); 
829         else hlist_out();
830         doing_leaders = outerdoingleaders; 
831         dvi_v = savev; 
832         dvi_h = saveh; 
833 /* ****************************************************************** */
834 /*        cur_v = saveh;  */  
835         cur_v = baseline;   /* changed in 3.1415 */
836 /* ****************************************************************** */
837         cur_h = saveh + leaderwd + lx; 
838       } 
839       cur_h = edge - 10; 
840       goto lab15; 
841     } 
842   } 
843   goto lab13; 
844       } 
845       break; 
846     case 11 : 
847     case 9 : 
848       cur_h = cur_h + mem[p + 1].cint; 
849       break; 
850     case 6 : 
851       {
852   mem[lig_trick]= mem[p + 1]; 
853   mem[lig_trick].hh.v.RH = mem[p].hh.v.RH; 
854   p = lig_trick; 
855   goto lab21; 
856       } 
857       break; 
858       default: 
859    ; 
860       break; 
861     } 
862     goto lab15; 
863     lab14: if ((rule_ht == -1073741824L))  /* - 2^30 */
864     rule_ht = mem[thisbox + 3].cint; 
865     if ((rule_dp == -1073741824L))     /* - 2^30 */
866     rule_dp = mem[thisbox + 2].cint; 
867     rule_ht = rule_ht + rule_dp; 
868     if ((rule_ht > 0)&&(rule_wd > 0)) 
869     {
870       if (cur_h != dvi_h)
871       {
872   movement(cur_h - dvi_h, 143);   /* 143 == right1 */
873   dvi_h = cur_h; 
874       } 
875       cur_v = baseline + rule_dp; 
876       if (cur_v != dvi_v)
877       {
878   movement(cur_v - dvi_v, 157);   /* 157 == down1 */
879   dvi_v = cur_v; 
880       }
881       dvi_out(132);
882       dvi_four(rule_ht); 
883       dvi_four(rule_wd); 
884       cur_v = baseline; 
885       dvi_h = dvi_h + rule_wd; 
886     } 
887     lab13: cur_h = cur_h + rule_wd; 
888     lab15: p = mem[p].hh.v.RH; 
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 void vlist_out (void) 
897 {/* 13 14 15 */ 
898   scaled leftedge; 
899   scaled topedge; 
900   scaled saveh, savev; 
901   halfword thisbox; 
902 /*  glue_ord gorder;  */
903   int gorder;         /* 95/Jan/7 */
904 /*  char gsign;  */
905   int gsign;          /* 95/Jan/7 */
906   halfword p; 
907   integer saveloc; 
908   halfword leaderbox; 
909   scaled leaderht; 
910   scaled lx; 
911   bool outerdoingleaders; 
912   scaled edge; 
913 /* ************************************************************************ */
914   real gluetemp;  /* new in 3.14159 */
915 /* ************************************************************************ */
916   thisbox = temp_ptr; 
917   gorder = mem[thisbox + 5].hh.b1; 
918   gsign = mem[thisbox + 5].hh.b0; 
919   p = mem[thisbox + 5].hh.v.RH; 
920   incr(cur_s); 
921   if (cur_s > 0)
922     dvi_out(141);
923   if (cur_s > max_push)
924   max_push = cur_s; 
925   saveloc = dvi_offset + dvi_ptr; 
926   leftedge = cur_h; 
927   cur_v = cur_v - mem[thisbox + 3].cint; 
928   topedge = cur_v; 
929   while(p != 0){  /* while p<>null do l.12494 OK */
930     if ((p >= hi_mem_min)) {
931     confusion("vlistout");
932     return;       // abort_flag set
933   }
934     else {
935       switch(mem[p].hh.b0)
936       {case 0 : 
937       case 1 : 
938 /* if list_ptr(p)=null then cur_v:=cur_v+height(p)+depth(p) l.12529 */
939   if (mem[p + 5].hh.v.RH == 0)
940   cur_v = cur_v + mem[p + 3].cint + mem[p + 2].cint; 
941   else {
942       
943     cur_v = cur_v + mem[p + 3].cint; 
944     if (cur_v != dvi_v)
945     {
946       movement(cur_v - dvi_v, 157);   /* 157 == down1 */
947       dvi_v = cur_v; 
948     } 
949     saveh = dvi_h; 
950     savev = dvi_v; 
951     cur_h = leftedge + mem[p + 4].cint; 
952     temp_ptr = p; 
953     if (mem[p].hh.b0 == 1)vlist_out(); 
954     else hlist_out();
955     dvi_h = saveh; 
956     dvi_v = savev; 
957     cur_v = savev + mem[p + 2].cint; 
958     cur_h = leftedge; 
959   } 
960   break; 
961       case 2 : 
962   {
963     rule_ht = mem[p + 3].cint; 
964     rule_dp = mem[p + 2].cint; 
965     rule_wd = mem[p + 1].cint; 
966     goto lab14; 
967   } 
968   break; 
969       case 8 : 
970       out_what(p);
971       break; 
972       case 10 : 
973   {
974     g = mem[p + 1].hh.v.LH; 
975     rule_ht = mem[g + 1].cint; 
976     if (gsign != 0)
977     {
978       if (gsign == 1)
979       {
980         if (mem[g].hh.b0 == gorder)
981 /* ************************************************************************ */
982 /*        rule_ht = rule_ht + round(mem[thisbox + 6].gr * mem[g + 2].cint); */
983 /* ************************ 3.14159 **************************************** */
984         {
985     gluetemp = mem[thisbox + 6].gr * mem[g + 2].cint; 
986     if (gluetemp > 1000000000.0)
987     gluetemp = 1000000000.0; 
988     else if (gluetemp < -1000000000.0)
989     gluetemp = -1000000000.0; 
990     rule_ht = rule_ht + round(gluetemp); 
991         } 
992 /* ************************************************************************* */
993       } 
994 /* ************************************************************************* */
995 /*      else { */
996 /*        if (mem[g].hh.b1 == gorder) */
997 /*        rule_ht = rule_ht - round(mem[thisbox + 6].gr * mem[g + 3].cint); */
998 /*      } */
999       else if (mem[g].hh.b1 == gorder)   /* BUG FIX !!! */
1000         {
1001         gluetemp = mem[thisbox + 6].gr * mem[g + 3].cint; 
1002         if (gluetemp > 1000000000.0)
1003         gluetemp = 1000000000.0; 
1004         else if (gluetemp < -1000000000.0)
1005         gluetemp = -1000000000.0; 
1006         rule_ht = rule_ht - round(gluetemp); 
1007       } 
1008 /* ************************************************************************* */
1009     } 
1010     if (mem[p].hh.b1 >= 100)
1011     {
1012       leaderbox = mem[p + 1].hh.v.RH; 
1013       if (mem[leaderbox].hh.b0 == 2)
1014       {
1015         rule_wd = mem[leaderbox + 1].cint; 
1016         rule_dp = 0; 
1017         goto lab14; 
1018       } 
1019       leaderht = mem[leaderbox + 3].cint + mem[leaderbox + 2]
1020      .cint; 
1021       if ((leaderht > 0)&&(rule_ht > 0)) 
1022       {
1023         rule_ht = rule_ht + 10; 
1024         edge = cur_v + rule_ht; 
1025         lx = 0; 
1026         if (mem[p].hh.b1 == 100)
1027         {
1028     savev = cur_v; 
1029     cur_v = topedge + leaderht *((cur_v - topedge)/ leaderht)
1030     ; 
1031     if (cur_v < savev)
1032     cur_v = cur_v + leaderht; 
1033         } 
1034         else {
1035       
1036     lq = rule_ht / leaderht; 
1037     lr = rule_ht % leaderht; 
1038     if (mem[p].hh.b1 == 101)
1039     cur_v = cur_v +(lr / 2); 
1040     else {
1041         
1042       lx =(2 * lr + lq + 1)/(2 * lq + 2); 
1043       cur_v = cur_v +((lr -(lq - 1)* lx)/ 2); 
1044     } 
1045         } 
1046         while(cur_v + leaderht <= edge){
1047       
1048     cur_h = leftedge + mem[leaderbox + 4].cint; 
1049     if (cur_h != dvi_h)
1050     {
1051       movement(cur_h - dvi_h, 143);   /* 143 == right1 */
1052       dvi_h = cur_h; 
1053     } 
1054     saveh = dvi_h; 
1055     cur_v = cur_v + mem[leaderbox + 3].cint; 
1056     if (cur_v != dvi_v)
1057     {
1058       movement(cur_v - dvi_v, 157);   /* 157 == down1 */
1059       dvi_v = cur_v; 
1060     } 
1061     savev = dvi_v; 
1062     temp_ptr = leaderbox; 
1063     outerdoingleaders = doing_leaders; 
1064     doing_leaders = true; 
1065     if (mem[leaderbox].hh.b0 == 1)vlist_out(); 
1066     else hlist_out(); 
1067     doing_leaders = outerdoingleaders; 
1068     dvi_v = savev; 
1069     dvi_h = saveh; 
1070 /* ************************************************************************ */
1071 /*    cur_h = saveh;  */
1072     cur_h = leftedge;  /* 3.1415 */
1073 /* ************************************************************************ */
1074     cur_v = savev - mem[leaderbox + 3].cint + leaderht + lx; 
1075         } 
1076         cur_v = edge - 10; 
1077         goto lab15; 
1078       } 
1079     } 
1080     goto lab13; 
1081   } 
1082   break; 
1083       case 11 : 
1084   cur_v = cur_v + mem[p + 1].cint; 
1085   break; 
1086   default: 
1087   ; 
1088   break; 
1089       } 
1090       goto lab15; 
1091       lab14: if ((rule_wd == -1073741824L))    /* -2^30 */
1092       rule_wd = mem[thisbox + 1].cint; 
1093       rule_ht = rule_ht + rule_dp; 
1094       cur_v = cur_v + rule_ht; 
1095       if ((rule_ht > 0)&&(rule_wd > 0)) 
1096       {
1097   if (cur_h != dvi_h)
1098   {
1099     movement(cur_h - dvi_h, 143);   /* 143 == right1 */
1100     dvi_h = cur_h; 
1101   } 
1102   if (cur_v != dvi_v)
1103   {
1104     movement(cur_v - dvi_v, 157);   /* 157 == down1 */
1105     dvi_v = cur_v; 
1106   }
1107   dvi_out(137);
1108   dvi_four(rule_ht); 
1109   dvi_four(rule_wd); 
1110       } 
1111       goto lab15; 
1112       lab13: cur_v = cur_v + rule_ht; 
1113     } 
1114     lab15: p = mem[p].hh.v.RH; 
1115   } 
1116   prune_movements(saveloc); 
1117   if (cur_s > 0)
1118   dvi_pop(saveloc); 
1119   decr(cur_s); 
1120 }
1121 /****************HPDF******************/
1122 /*
1123 void error_handler (HPDF_STATUS error_no, HPDF_STATUS detail_no, void * user_data)
1124 {
1125     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no);
1126 }
1127 */
1128 /****************HPDF******************/
1129 /* sec 0638 */
1130 /* following needs access to dvi_buf=zdvibuf see coerce.h */
1131 void ship_out_(halfword p)
1132 {
1133   integer pageloc;
1134   char j, k;
1135   pool_pointer s;
1136   char old_setting;
1137   if (tracing_output > 0) {
1138     print_nl("");
1139     print_ln();
1140     print_string("Completed box being shipped out");
1141   }
1142   if (term_offset > max_print_line - 9)
1143     print_ln(); 
1144   else if ((term_offset > 0)||(file_offset > 0))
1145     print_char(' ');
1146   print_char('[');
1147   j = 9;
1148   while((eqtb[(hash_size + 3218) + j].cint == 0) && (j > 0))
1149     decr(j);
1150   {
1151     register integer for_end; 
1152     k = 0; 
1153     for_end = j; 
1154     if (k <= for_end) do 
1155     {
1156       print_int(eqtb[(hash_size + 3218) + k].cint); 
1157       if (k < j)
1158         print_char('.');
1159     } while(k++ < for_end);
1160   } 
1161 #ifndef _WINDOWS
1162   fflush(stdout); 
1163 #endif
1164   if (tracing_output > 0)
1165   {
1166     print_char(']');
1167     begin_diagnostic(); 
1168     show_box(p); 
1169     end_diagnostic(true); 
1170   } 
1171   if ((mem[p + 3].cint > 1073741823L) || /* 2^30 - 1 */
1172     (mem[p + 2].cint > 1073741823L) ||
1173     (mem[p + 3].cint + mem[p + 2].cint + v_offset > 1073741823L) ||
1174     (mem[p + 1].cint + h_offset > 1073741823L)) {
1175           print_err("Huge page cannot be shipped out");
1176           help2("The page just created is more than 18 feet tall or",
1177                   "more than 18 feet wide, so I suspect something went wrong.");
1178     error(); 
1179     if (tracing_output <= 0) {
1180       begin_diagnostic(); 
1181       print_nl("The following box has been deleted:");
1182       show_box(p); 
1183       end_diagnostic(true); 
1184     } 
1185     goto lab30; 
1186   } 
1187   if (mem[p + 3].cint + mem[p + 2].cint + v_offset > max_v)
1188     max_v = mem[p + 3].cint + mem[p + 2].cint + v_offset;
1189   if (mem[p + 1].cint + h_offset > max_h)
1190     max_h = mem[p + 1].cint + h_offset;
1191   dvi_h = 0;
1192   dvi_v = 0;
1193   cur_h = h_offset;
1194   dvi_f = 0;
1195   if (output_file_name == 0) {
1196     if (job_name == 0)
1197       open_log_file();
1198     pack_job_name(788);   /* .dvi */
1199     while(!b_open_out(dvi_file)) {
1200       prompt_file_name(789, 788); /* file name for output  .dvi */
1201     }
1202     output_file_name = b_make_name_string(dvi_file);
1203   }
1204
1205   if (total_pages == 0) {
1206     dvi_out(247);
1207     dvi_out(2);
1208 /********BINDING WITH LIBHARU*********/
1209 /*
1210     yandy_pdf = HPDF_New(error_handler, NULL);
1211     yandy_page = HPDF_AddPage(yandy_pdf);
1212     HPDF_SetInfoAttr(yandy_pdf, HPDF_INFO_PRODUCER, "Y&Y TeX with ApTeX");
1213     HPDF_SetCompressionMode (yandy_pdf, HPDF_COMP_ALL);
1214     HPDF_Page_SetSize (yandy_page, HPDF_PAGE_SIZE_A5, HPDF_PAGE_PORTRAIT);
1215     yandy_font = HPDF_GetFont (yandy_pdf, "Times-Roman", NULL);
1216     HPDF_Page_BeginText (yandy_page);
1217     HPDF_Page_SetFontAndSize (yandy_page, yandy_font, 16);
1218     HPDF_Page_TextOut (yandy_page, 60, HPDF_Page_GetHeight (yandy_page)-90,  "This is the \xAErst page.");
1219     HPDF_Page_TextOut (yandy_page, 60, HPDF_Page_GetHeight (yandy_page)-180, "Wait for ...");
1220     HPDF_Page_EndText (yandy_page);
1221     HPDF_SaveToFile (yandy_pdf, "NOTICE.pdf");
1222     HPDF_Free(yandy_pdf);
1223  */
1224 /********BINDING WITH LIBHARU*********/
1225     dvi_four(25400000L);  /* magic DVI scale factor */
1226     dvi_four(473628672L); /* 7227 * 65536 */
1227     prepare_mag();
1228     dvi_four(mag);
1229     old_setting = selector;
1230     selector = 21;
1231     print_string(" TeX output ");
1232     print_int(year);
1233     print_char('.');
1234     print_two(month);
1235     print_char('.');
1236     print_two(day);
1237     print_char(':');
1238     print_two(tex_time / 60);
1239     print_two(tex_time % 60);
1240     selector = old_setting;
1241 /* long to unsigned char ... */
1242     dvi_out(cur_length);
1243     for (s = str_start[str_ptr]; s <= pool_ptr - 1; s++) dvi_out(str_pool[s]);
1244     pool_ptr = str_start[str_ptr]; 
1245   } // end of if total_pages == 0
1246
1247   pageloc = dvi_offset + dvi_ptr;
1248   dvi_out(139);
1249   for (k = 0; k <= 9; k++) dvi_four(eqtb[(hash_size + 3218) + k].cint);
1250   dvi_four(last_bop);
1251   last_bop = pageloc;
1252   cur_v = mem[p + 3].cint + v_offset;
1253   temp_ptr = p;
1254   if (mem[p].hh.b0 == 1)
1255     vlist_out();
1256   else
1257     hlist_out();
1258   dvi_out(140);
1259   incr(total_pages);
1260   cur_s = -1;
1261 lab30:;
1262   if (tracing_output <= 0)
1263     print_char(']');
1264   dead_cycles = 0;
1265 #ifndef _WINDOWS
1266   fflush(stdout);
1267 #endif
1268   ;
1269 #ifdef STAT
1270   if (tracing_stats > 1) {
1271     print_nl("Memory usage before: ");
1272     print_int(var_used);
1273     print_char('&');
1274     print_int(dyn_used);
1275     print_char(';');
1276   }
1277 #endif /* STAT */
1278   flush_node_list(p);
1279   ;
1280 #ifdef STAT
1281   if (tracing_stats > 1) {
1282     print_string("after");
1283     print_int(var_used);
1284     print_char('&');
1285     print_int(dyn_used);
1286     print_string("still utouched");
1287     print_int(hi_mem_min - lo_mem_max - 1); /* somewhat inaccurate free mem */
1288     print_ln();
1289   } 
1290 #endif /* STAT */
1291
1292 void scan_spec_(group_code c, bool threecodes)
1293 {
1294   integer s;
1295   char speccode;
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     speccode = 1;
1304     cur_val = 0;
1305     goto lab40;
1306   }
1307   scan_dimen(false, false, false);
1308 lab40:
1309   if (threecodes) {
1310     save_stack[save_ptr + 0].cint = s;  /* s may be used without ... */
1311     incr(save_ptr);
1312   }
1313   save_stack[save_ptr + 0].cint = speccode;
1314   save_stack[save_ptr + 1].cint = cur_val;
1315   save_ptr = save_ptr + 2;
1316   new_save_level(c);
1317   scan_left_brace();
1318 }
1319 halfword hpack_(halfword p, scaled w, small_number m)
1320 {
1321   register halfword Result;
1322   halfword r;
1323   halfword q;
1324   scaled h, d, x;
1325   scaled s;
1326   halfword g;
1327 /*  glue_ord o;  */
1328   int o;              /* 95/Jan/7 */
1329   internal_font_number f;
1330   ffourquarters i;
1331   eight_bits hd;
1332   last_badness = 0;
1333   r = get_node(7);
1334   mem[r].hh.b0 = 0;
1335   mem[r].hh.b1 = 0;
1336   mem[r + 4].cint = 0;
1337   q = r + 5;
1338   mem[q].hh.v.RH = p;
1339   h = 0;
1340   d = 0;
1341   x = 0;
1342   total_stretch[0] = 0;
1343   total_shrink[0] = 0;
1344   total_stretch[1] = 0;
1345   total_shrink[1] = 0;
1346   total_stretch[2] = 0;
1347   total_shrink[2] = 0;
1348   total_stretch[3] = 0;
1349   total_shrink[3] = 0;
1350   while (p != 0) { /* while p<>null do l.12862 */
1351 lab21:
1352     while ((p >= hi_mem_min)) {
1353       f = mem[p].hh.b0;
1354       i = font_info[char_base[f] + mem[p].hh.b1].qqqq;
1355       hd = i.b1;
1356       x = x + font_info[width_base[f] + i.b0].cint;
1357       s = font_info[height_base[f] + (hd) / 16].cint;
1358       if (s > h)
1359         h = s;
1360       s = font_info[depth_base[f]+(hd)% 16].cint;
1361       if (s > d)
1362         d = s;
1363       p = mem[p].hh.v.RH;
1364     }
1365     if (p != 0)  /* if p<>null then l.12886 */
1366     {
1367       switch (mem[p].hh.b0)
1368       {
1369       case 0:
1370       case 1:
1371       case 2:
1372       case 13:
1373         {
1374           x = x + mem[p + 1].cint;
1375           if (mem[p].hh.b0 >= 2)
1376             s = 0;
1377           else
1378             s = mem[p + 4].cint;
1379           if (mem[p + 3].cint - s > h)
1380             h = mem[p + 3].cint - s;
1381           if (mem[p + 2].cint + s > d)
1382             d = mem[p + 2].cint + s;
1383         }
1384         break; 
1385       case 3:
1386       case 4:
1387       case 5:
1388 /* if adjust_tail<>null then link(adjust_tail):=null; l.12865 / 12891 */
1389         if (adjust_tail != 0)
1390         {
1391           while (mem[q].hh.v.RH != p)
1392             q = mem[q].hh.v.RH;
1393           if (mem[p].hh.b0 == 5) {
1394             mem[adjust_tail].hh.v.RH = mem[p + 1].cint;
1395             while (mem[adjust_tail].hh.v.RH != 0)
1396               adjust_tail = mem[adjust_tail].hh.v.RH;
1397             p = mem[p].hh.v.RH;
1398             free_node(mem[q].hh.v.RH, 2);
1399           } else {
1400             mem[adjust_tail].hh.v.RH = p;
1401             adjust_tail = p;
1402             p = mem[p].hh.v.RH;
1403           }
1404           mem[q].hh.v.RH = p;
1405           p = q;
1406         }
1407         break;
1408       case 8:
1409         ;
1410         break;
1411       case 10:
1412         {
1413           g = mem[p + 1].hh.v.LH;
1414           x = x + mem[g + 1].cint;
1415           o = mem[g].hh.b0;
1416           total_stretch[o]= total_stretch[o]+ mem[g + 2].cint;
1417           o = mem[g].hh.b1;
1418           total_shrink[o]= total_shrink[o]+ mem[g + 3].cint;
1419           if (mem[p].hh.b1 >= 100) {
1420             g = mem[p + 1].hh.v.RH;
1421             if (mem[g + 3].cint > h)
1422               h = mem[g + 3].cint;
1423             if (mem[g + 2].cint > d)
1424               d = mem[g + 2].cint;
1425           }
1426         }
1427         break;
1428       case 11:
1429       case 9:
1430         x = x + mem[p + 1].cint;
1431         break;
1432       case 6:
1433         {
1434           mem[lig_trick]= mem[p + 1];
1435           mem[lig_trick].hh.v.RH = mem[p].hh.v.RH;
1436           p = lig_trick;
1437           goto lab21;
1438         }
1439         break;
1440       default:
1441         ;
1442         break;
1443       }
1444       p = mem[p].hh.v.RH;
1445     }
1446   }
1447   if (adjust_tail != 0)
1448     mem[adjust_tail].hh.v.RH = 0;
1449   mem[r + 3].cint = h;
1450   mem[r + 2].cint = d;
1451   if (m == 1)
1452     w = x + w;
1453   mem[r + 1].cint = w;
1454   x = w - x;
1455   if (x == 0) {
1456     mem[r + 5].hh.b0 = 0;
1457     mem[r + 5].hh.b1 = 0;
1458     mem[r + 6].gr = 0.0;
1459     goto lab10;
1460   } else if (x > 0) {
1461     if (total_stretch[3] != 0)
1462       o = 3; 
1463     else if (total_stretch[2] != 0)
1464       o = 2;
1465     else if (total_stretch[1] != 0)
1466       o = 1;
1467     else
1468       o = 0;
1469     mem[r + 5].hh.b1 = o;
1470     mem[r + 5].hh.b0 = 1;
1471 /* if total_stretch[o]<>0 then glue_set(r):=... l.12982 */
1472     if (total_stretch[o]!= 0)
1473       mem[r + 6].gr = x / ((double) total_stretch[o]); 
1474     else {
1475       mem[r + 5].hh.b0 = 0;
1476       mem[r + 6].gr = 0.0;
1477     }
1478 /* if o=normal then if list_ptr(r)<>null then l.12987 */
1479     if (o == 0)
1480       if (mem[r + 5].hh.v.RH != 0)
1481       {
1482         last_badness = badness(x, total_stretch[0]);
1483         if (last_badness > hbadness) {
1484           print_ln();
1485           if (last_badness > 100)
1486             print_nl("Underfull");
1487           else
1488             print_nl("Loose");
1489           print_string(" \\hbox (badness ");
1490           print_int(last_badness);
1491           if (last_badness > 100)
1492             underfull_hbox++;   /* 1996/Feb/9 */
1493           goto lab50;
1494         }
1495       }
1496       goto lab10;
1497   } else {
1498     if (total_shrink[3] != 0)
1499       o = 3; 
1500     else if (total_shrink[2] != 0)
1501       o = 2;
1502     else if (total_shrink[1] != 0)
1503       o = 1;
1504     else
1505       o = 0;
1506     mem[r + 5].hh.b1 = o;
1507     mem[r + 5].hh.b0 = 2;
1508     if (total_shrink[o] != 0)
1509       mem[r + 6].gr =(- (integer) x) / ((double) total_shrink[o]);
1510     else {
1511       mem[r + 5].hh.b0 = 0;
1512       mem[r + 6].gr = 0.0;
1513     } 
1514 /* if (total_shrink[o]<-x)and(o=normal)and(list_ptr(r)<>null) then l.13946 */
1515     if ((total_shrink[o]< - (integer) x) && (o == 0) && (mem[r + 5].hh.v.RH != 0)) {
1516       last_badness = 1000000L;
1517 /*   set_glue_ratio_one(glue_set(r)); {use the maximum shrinkage} */
1518       mem[r + 6].gr = 1.0;
1519 /* if (-x-total_shrink[normal]>hfuzz)or(hbadness<100) then */
1520       if ((- (integer) x - total_shrink[0] > hfuzz) || 
1521         (hbadness < 100)) {
1522           if ((overfull_rule > 0) &&
1523             (- (integer) x - total_shrink[0] > hfuzz)) {
1524               while(mem[q].hh.v.RH != 0)q = mem[q].hh.v.RH;
1525               mem[q].hh.v.RH = new_rule();
1526               mem[mem[q].hh.v.RH + 1].cint = overfull_rule;
1527           }
1528           print_ln();
1529           print_nl("Overfull \\hbox(");
1530           print_scaled(- (integer) x - total_shrink[0]);
1531           print_string("pt too wide");
1532           overfull_hbox++;      /* 1996/Feb/9 */
1533           goto lab50;
1534       }
1535     } else if (o == 0)
1536       if (mem[r + 5].hh.v.RH != 0) {
1537         last_badness = badness(- (integer) x, total_shrink[0]);
1538         if (last_badness > hbadness) {
1539           print_ln();
1540           print_nl("Tight \\hbox (badness ");
1541           print_int(last_badness);
1542           goto lab50;
1543         }
1544       }
1545       goto lab10; 
1546   }
1547 lab50:
1548   if (output_active)
1549     print_string(") has occurred while \\output is active");
1550   else {
1551     if (pack_begin_line != 0) {
1552       if (pack_begin_line > 0)
1553         print_string(") in paragraph at lines ");
1554       else
1555         print_string(") in alignment at lines ");
1556       print_int(abs(pack_begin_line));
1557       print_string("--");
1558     } else print_string(")detected at line ");
1559     print_int(line);
1560   }
1561   print_ln();
1562   font_in_short_display = 0;
1563   short_display(mem[r + 5].hh.v.RH);
1564   print_ln();
1565   begin_diagnostic();
1566   show_box(r);
1567   end_diagnostic(true);
1568 lab10:
1569   Result = r;
1570   return Result;
1571 }
1572 halfword vpackage_(halfword p, scaled h, small_number m, scaled l)
1573 {
1574   register halfword Result;
1575   halfword r;
1576   scaled w, d, x;
1577   scaled s;
1578   halfword g;
1579 /*  glue_ord o;  */
1580   int o;              /* 95/Jan/7 */
1581   last_badness = 0;
1582   r = get_node(7);
1583   mem[r].hh.b0 = 1;
1584   mem[r].hh.b1 = 0;
1585   mem[r + 4].cint = 0;
1586   mem[r + 5].hh.v.RH = p;
1587   w = 0;
1588   d = 0;
1589   x = 0;
1590   total_stretch[0] = 0;
1591   total_shrink[0] = 0;
1592   total_stretch[1] = 0;
1593   total_shrink[1] = 0;
1594   total_stretch[2] = 0;
1595   total_shrink[2] = 0;
1596   total_stretch[3] = 0;
1597   total_shrink[3] = 0;
1598   while (p != 0) {
1599     if ((p >= hi_mem_min)) {
1600       confusion("vpack");
1601       return 0;       // abort_flag set
1602     } else switch (mem[p].hh.b0)
1603     {
1604     case 0:
1605     case 1:
1606     case 2:
1607     case 13:
1608       {
1609         x = x + d + mem[p + 3].cint;
1610         d = mem[p + 2].cint;
1611         if (mem[p].hh.b0 >= 2)
1612           s = 0;
1613         else s = mem[p + 4].cint;
1614         if (mem[p + 1].cint + s > w)
1615           w = mem[p + 1].cint + s;
1616       }
1617       break;
1618     case 8:
1619       ;
1620       break;
1621     case 10:
1622       {
1623         x = x + d;
1624         d = 0;
1625         g = mem[p + 1].hh.v.LH;
1626         x = x + mem[g + 1].cint;
1627         o = mem[g].hh.b0;
1628         total_stretch[o] = total_stretch[o]+ mem[g + 2].cint;
1629         o = mem[g].hh.b1;
1630         total_shrink[o]= total_shrink[o]+ mem[g + 3].cint;
1631         if (mem[p].hh.b1 >= 100) {
1632           g = mem[p + 1].hh.v.RH;
1633           if (mem[g + 1].cint > w)
1634             w = mem[g + 1].cint;
1635         }
1636       }
1637       break;
1638     case 11:
1639       {
1640         x = x + d + mem[p + 1].cint;
1641         d = 0;
1642       }
1643       break;
1644       default:
1645         ;
1646       break;
1647     }
1648     p = mem[p].hh.v.RH;
1649   }
1650   mem[r + 1].cint = w;
1651   if (d > l) {
1652     x = x + d - l;
1653     mem[r + 2].cint = l;
1654   } else mem[r + 2].cint = d;
1655   if (m == 1)
1656     h = x + h;
1657   mem[r + 3].cint = h;
1658   x = h - x;
1659   if (x == 0) {
1660     mem[r + 5].hh.b0 = 0;
1661     mem[r + 5].hh.b1 = 0;
1662     mem[r + 6].gr = 0.0;
1663     goto lab10;
1664   } else if (x > 0) {
1665     if (total_stretch[3] != 0)
1666       o = 3;
1667     else if (total_stretch[2]!= 0)
1668       o = 2;
1669     else if (total_stretch[1]!= 0)
1670       o = 1;
1671     else
1672       o = 0;
1673     mem[r + 5].hh.b1 = o;
1674     mem[r + 5].hh.b0 = 1;
1675     if (total_stretch[o] != 0)
1676       mem[r + 6].gr = x / ((double) total_stretch[o]);
1677     else {
1678       mem[r + 5].hh.b0 = 0;
1679       mem[r + 6].gr = 0.0;
1680     }
1681     if (o == 0)
1682       if (mem[r + 5].hh.v.RH != 0) {
1683         last_badness = badness(x, total_stretch[0]);
1684         if (last_badness > vbadness) {
1685           print_ln();
1686           if (last_badness > 100)
1687             print_nl("Underfull");
1688           else
1689             print_nl("Loose");
1690           print_string(" \\vbox (badness ");
1691           print_int(last_badness);
1692           if (last_badness > 100)
1693             underfull_vbox++; /* 1996/Feb/9 */
1694           goto lab50;
1695         }
1696       }
1697       goto lab10;
1698   } else {
1699     if (total_shrink[3] != 0)
1700       o = 3;
1701     else if (total_shrink[2] != 0)
1702       o = 2;
1703     else if (total_shrink[1]!= 0)
1704       o = 1;
1705     else
1706       o = 0;
1707     mem[r + 5].hh.b1 = o;
1708     mem[r + 5].hh.b0 = 2;
1709     if (total_shrink[o]!= 0)
1710       mem[r + 6].gr =(- (integer) x)/ ((double) total_shrink[o]);
1711     else {
1712       mem[r + 5].hh.b0 = 0;
1713       mem[r + 6].gr = 0.0;
1714     }
1715 /* if (total_shrink[o]<-x)and(o=normal)and(list_ptr(r)<>null) then l.13046 */
1716     if ((total_shrink[o] < - (integer) x) && (o == 0) && (mem[r + 5].hh.v.RH != 0)) {
1717       last_badness = 1000000L;
1718       mem[r + 6].gr = 1.0;
1719       if ((- (integer) x - total_shrink[0] > eqtb[(hash_size + 3739)].cint) || 
1720         (vbadness < 100)) {
1721           print_ln();
1722           print_nl("Overfull \\vbox(");
1723           print_scaled(- (integer) x - total_shrink[0]);
1724           print_string("pt too high");
1725           overfull_vbox++;    /* 1996/Feb/9 */
1726           goto lab50;
1727       }
1728     }
1729 /* else if o=normal then if list_ptr(r)<>null then l.13052  */
1730     else if (o == 0)
1731       if (mem[r + 5].hh.v.RH != 0) {
1732         last_badness = badness(- (integer) x, total_shrink[0]); 
1733         if (last_badness > vbadness) {
1734           print_ln();
1735           print_nl("Tight \\vbox (badness ");
1736           print_int(last_badness);
1737           goto lab50;
1738         }
1739       }
1740     goto lab10; 
1741   }
1742 lab50:
1743   if (output_active)
1744     print_string(") has occurred while \\output is active");
1745   else {
1746     if (pack_begin_line != 0) {
1747       print_string(") in alignment at lines ");
1748       print_int(abs(pack_begin_line));
1749       print_string("--");
1750     } else print_string(") detected at line ");
1751     print_int(line);
1752     print_ln();
1753   }
1754   begin_diagnostic();
1755   show_box(r);
1756   end_diagnostic(true);
1757 lab10:
1758   Result = r;
1759   return Result;
1760 }
1761 void append_to_vlist_(halfword b)
1762 {
1763   scaled d;
1764   halfword p;
1765   if (cur_list.aux_field.cint > ignore_depth) {
1766     d = mem[eqtb[(hash_size + 783)].hh.v.RH + 1].cint - cur_list.aux_field.cint - mem[b + 3].cint;
1767     if (d < line_skip_limit)
1768       p = new_param_glue(0);
1769     else {
1770       p = new_skip_param(1);
1771       mem[temp_ptr + 1].cint = d;
1772     }
1773     mem[tail].hh.v.RH = p;
1774     tail = p;
1775   }
1776   mem[tail].hh.v.RH = b;
1777   tail = b;
1778   cur_list.aux_field.cint = mem[b + 2].cint;
1779 }
1780 halfword new_noad (void) 
1781 {
1782   register halfword Result;
1783   halfword p;
1784   p = get_node(4);
1785   mem[p].hh.b0 = 16;
1786   mem[p].hh.b1 = 0;
1787   mem[p + 1].hh = empty_field;
1788   mem[p + 3].hh = empty_field;
1789   mem[p + 2].hh = empty_field;
1790   Result = p;
1791   return Result;
1792
1793 halfword new_style_(small_number s)
1794 {
1795   register halfword Result;
1796   halfword p;
1797   p = get_node(3);
1798   mem[p].hh.b0 = 14;
1799   mem[p].hh.b1 = s;
1800   mem[p + 1].cint = 0;
1801   mem[p + 2].cint = 0;
1802   Result = p;
1803   return Result;
1804 }
1805 halfword new_choice (void)
1806 {
1807   register halfword Result;
1808   halfword p;
1809   p = get_node(3);
1810   mem[p].hh.b0 = 15;
1811   mem[p].hh.b1 = 0;
1812   mem[p + 1].hh.v.LH = 0;
1813   mem[p + 1].hh.v.RH = 0;
1814   mem[p + 2].hh.v.LH = 0;
1815   mem[p + 2].hh.v.RH = 0;
1816   Result = p;
1817   return Result;
1818 }
1819 void show_info (void)
1820 {
1821   show_node_list(mem[temp_ptr].hh.v.LH);
1822 }
1823 halfword fraction_rule_(scaled t)
1824 {
1825   register halfword Result;
1826   halfword p;
1827   p = new_rule();
1828   mem[p + 3].cint = t;
1829   mem[p + 2].cint = 0;
1830   Result = p;
1831   return Result;
1832 }
1833 halfword overbar_(halfword b, scaled k, scaled t)
1834 {
1835   register halfword Result;
1836   halfword p, q;
1837   p = new_kern(k);
1838   mem[p].hh.v.RH = b;
1839   q = fraction_rule(t);
1840   mem[q].hh.v.RH = p;
1841   p = new_kern(t);
1842   mem[p].hh.v.RH = q;
1843   Result = vpackage(p, 0, 1, 1073741823L); /* 2^30 - 1 */
1844   return Result;
1845 }
1846 halfword char_box_(internal_font_number f, quarterword c)
1847 {
1848   register halfword Result;
1849   ffourquarters q;
1850   eight_bits hd;
1851   halfword b, p;
1852   q = font_info[char_base[f]+ c].qqqq;
1853   hd = q.b1;
1854   b = new_null_box();
1855   mem[b + 1].cint = font_info[width_base[f]+ q.b0].cint + font_info[italic_base[f]+(q.b2) / 4].cint;
1856   mem[b + 3].cint = font_info[height_base[f]+(hd) / 16].cint;
1857   mem[b + 2].cint = font_info[depth_base[f]+(hd) % 16].cint;
1858 /*  long to unsigned short ... */
1859   p = get_avail();
1860   mem[p].hh.b1 = c;
1861   mem[p].hh.b0 = f;
1862   mem[b + 5].hh.v.RH = p;
1863   Result = b;
1864   return Result;
1865 }
1866 void stack_into_box_(halfword b, internal_font_number f, quarterword c)
1867 {
1868   halfword p;
1869   p = char_box(f, c);
1870   mem[p].hh.v.RH = mem[b + 5].hh.v.RH;
1871   mem[b + 5].hh.v.RH = p;
1872   mem[b + 3].cint = mem[p + 3].cint;
1873
1874 scaled height_plus_depth_(internal_font_number f, fquarterword c)
1875 {
1876   register scaled Result;
1877   ffourquarters q;
1878   eight_bits hd;
1879   q = font_info[char_base[f]+ c].qqqq;
1880   hd = q.b1;
1881   Result = font_info[height_base[f]+(hd)/ 16].cint + font_info[depth_base[f]+(hd) % 16].cint;
1882   return Result;
1883 }
1884 halfword var_delimiter_(halfword d, small_number s, scaled v)
1885 {
1886   register halfword Result;
1887   halfword b;
1888   internal_font_number f, g;
1889   quarterword c, x, y;
1890   integer m, n;
1891   scaled u;
1892   scaled w;
1893   ffourquarters q;
1894   ffourquarters r;
1895   eight_bits hd;
1896 /*  small_number z;  */
1897   int z;                  /* 95/Jan/7 */
1898 /*  bool largeattempt;  */
1899   int largeattempt;           /* 95/Jan/7 */
1900   f = 0;
1901   w = 0;
1902   largeattempt = false;
1903   z = mem[d].qqqq.b0;
1904   x = mem[d].qqqq.b1;
1905   while (true) {
1906     if ((z != 0) || (x != 0)) {
1907       z = z + s + 16;
1908       do {
1909         z = z - 16;
1910         g = eqtb[(hash_size + 1835) + z].hh.v.RH;
1911         if (g != 0) {
1912           y = x;
1913           if ((y >= font_bc[g]) && (y <= font_ec[g])) {
1914 lab22:
1915             q = font_info[char_base[g]+ y].qqqq;
1916             if ((q.b0 > 0)) {
1917               if (((q.b2) % 4) == 3) {
1918                 f = g;
1919                 c = y;
1920                 goto lab40;
1921               }
1922               hd = q.b1;
1923               u = font_info[height_base[g]+(hd)/ 16].cint + font_info[depth_base[g]+(hd)% 16].cint;
1924               if (u > w) {
1925                 f = g;
1926                 c = y;
1927                 w = u;
1928                 if (u >= v)
1929                   goto lab40;
1930               }
1931               if (((q.b2)% 4)== 2) {
1932                 y = q.b3;
1933                 goto lab22;
1934               }
1935             }
1936           }
1937         }
1938       } while (!(z < 16));
1939     } 
1940     if (largeattempt)
1941       goto lab40;
1942     largeattempt = true;
1943     z = mem[d].qqqq.b2;
1944     x = mem[d].qqqq.b3;
1945   }
1946 lab40:
1947   if (f != 0)
1948     if (((q.b2) % 4)== 3)   /* q may be used without ... */
1949     {
1950       b = new_null_box(); 
1951       mem[b].hh.b0 = 1; 
1952       r = font_info[exten_base[f]+ q.b3].qqqq;
1953       c = r.b3;
1954       u = height_plus_depth(f, c);
1955       w = 0;
1956       q = font_info[char_base[f]+ c].qqqq;
1957       mem[b + 1].cint = font_info[width_base[f]+ q.b0].cint + font_info[italic_base[f]+(q.b2) / 4].cint;
1958       c = r.b2;
1959       if (c != 0)
1960         w = w + height_plus_depth(f, c);
1961       c = r.b1;
1962       if (c != 0)
1963         w = w + height_plus_depth(f, c);
1964       c = r.b0; 
1965       if (c != 0)
1966         w = w + height_plus_depth(f, c);
1967       n = 0;
1968       if (u > 0)
1969         while(w < v) {
1970           w = w + u;
1971           incr(n);
1972           if (r.b1 != 0)
1973             w = w + u;
1974         }
1975         c = r.b2;
1976         if (c != 0)
1977           stack_into_box(b, f, c); 
1978         c = r.b3;
1979         {
1980           register integer for_end;
1981           m = 1;
1982           for_end = n;
1983           if (m <= for_end) do
1984           stack_into_box(b, f, c); 
1985           while (m++ < for_end);
1986         }
1987         c = r.b1;
1988         if (c != 0) {
1989           stack_into_box(b, f, c); 
1990           c = r.b3;
1991           {
1992             register integer for_end;
1993             m = 1;
1994             for_end = n;
1995             if (m <= for_end) do
1996             stack_into_box(b, f, c);
1997             while(m++ < for_end);
1998           }
1999         }
2000         c = r.b0;
2001         if (c != 0)
2002           stack_into_box(b, f, c);
2003         mem[b + 2].cint = w - mem[b + 3].cint;
2004     } else b = char_box(f, c);
2005   else {    /* c may be used without ... */
2006     b = new_null_box();
2007     mem[b + 1].cint = null_delimiter_space;
2008   } 
2009   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; 
2010   Result = b;
2011   return Result;
2012 }
2013 /* rebox_ etc used to follow here in tex4.c */