OSDN Git Service

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