OSDN Git Service

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