OSDN Git Service

compress .fmt files to .gz via zlib.
[putex/putex.git] / src / texsourc / itex.c
1 /* Copyright 1992 Karl Berry
2    Copyright 2007 TeX Users Group
3    Copyright 2014 Clerk Ma
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301 USA.  */
19
20 #define EXTERN extern
21
22 #include "texd.h"
23
24 #define BEGINFMTCHECKSUM 367403084L
25 #define ENDFMTCHECKSUM   69069L
26
27 extern clock_t start_time, main_time, finish_time; /* in local.c */
28
29 #ifdef INITEX
30   void do_initex (void);
31 #endif
32
33 /* sec 0004 */
34 void initialize (void)
35 {
36   integer i; 
37   integer k; 
38   integer flag; /* bkph */
39
40 #ifndef ALLOCATEHYPHEN
41   hyph_pointer z;
42 #endif
43
44   if (!non_ascii)
45   {
46     for (i = 0; i <= 255; i++)
47       xchr[i] = (char) i;
48
49 #ifdef JOKE
50     xchr[32] = ' ';  xchr[33] = '!';  xchr[34] = '"';  xchr[35] = '#';
51     xchr[36] = '$';  xchr[37] = '%';  xchr[38] = '&';  xchr[39] = '\'';
52     xchr[40] = '(';  xchr[41] = ')';  xchr[42] = '*';  xchr[43] = '+';
53     xchr[44] = ',';  xchr[45] = '-';  xchr[46] = '.';  xchr[47] = '/';
54     xchr[48] = '0';  xchr[49] = '1';  xchr[50] = '2';  xchr[51] = '3';
55     xchr[52] = '4';  xchr[53] = '5';  xchr[54] = '6';  xchr[55] = '7';
56     xchr[56] = '8';  xchr[57] = '9';  xchr[58] = ':';  xchr[59] = ';';
57     xchr[60] = '<';  xchr[61] = '=';  xchr[62] = '>';  xchr[63] = '?';
58     xchr[64] = '@';  xchr[65] = 'A';  xchr[66] = 'B';  xchr[67] = 'C';
59     xchr[68] = 'D';  xchr[69] = 'E';  xchr[70] = 'F';  xchr[71] = 'G';
60     xchr[72] = 'H';  xchr[73] = 'I';  xchr[74] = 'J';  xchr[75] = 'K';
61     xchr[76] = 'L';  xchr[77] = 'M';  xchr[78] = 'N';  xchr[79] = 'O';
62     xchr[80] = 'P';  xchr[81] = 'Q';  xchr[82] = 'R';  xchr[83] = 'S';
63     xchr[84] = 'T';  xchr[85] = 'U';  xchr[86] = 'V';  xchr[87] = 'W';
64     xchr[88] = 'X';  xchr[89] = 'Y';  xchr[90] = 'Z';  xchr[91] = '[';
65     xchr[92] = '\\'; xchr[93] = ']';  xchr[94] = '^';  xchr[95] = '_';
66     xchr[96] = '`';  xchr[97] = 'a';  xchr[98] = 'b';  xchr[99] = 'c';
67     xchr[100] = 'd'; xchr[101] = 'e'; xchr[102] = 'f'; xchr[103] = 'g';
68     xchr[104] = 'h'; xchr[105] = 'i'; xchr[106] = 'j'; xchr[107] = 'k';
69     xchr[108] = 'l'; xchr[109] = 'm'; xchr[110] = 'n'; xchr[111] = 'o';
70     xchr[112] = 'p'; xchr[113] = 'q'; xchr[114] = 'r'; xchr[115] = 's';
71     xchr[116] = 't'; xchr[117] = 'u'; xchr[118] = 'v'; xchr[119] = 'w';
72     xchr[120] = 'x'; xchr[121] = 'y'; xchr[122] = 'z'; xchr[123] = '{';
73     xchr[124] = '|'; xchr[125] = '}'; xchr[126] = '~';
74
75     for (i = 0; i <= 31; i++)
76       xchr[i] = chr(i);
77
78     for (i = 127; i <= 255; i++)
79       xchr[i]= chr(i);
80 #endif
81   }
82
83   for (i = 0; i <= 255; i++)
84     xord[chr(i)] = 127;
85
86 #ifdef JOKE
87   for (i = 128; i <= 255 ; i++)
88     xord[xchr[i]] = i;
89
90   for (i = 0; i <= 126; i++)
91     xord[xchr[i]] = i;
92 #endif
93
94   for (i = 0; i <= 255; i++)
95     xord[xchr[i]] = (char) i;
96
97   xord[127] = 127;
98
99   flag = 0;
100
101   if (trace_flag != 0)
102   {
103     for (k = 0; k < 256; k++)
104       if (xord[k] != k)
105       {
106         flag = 1;
107         break;
108       }
109
110     if (flag)
111     {
112       show_line("Inverted mapping xord[] pairs:\n", 0);
113
114       for (k = 0; k < 256; k++)
115       {
116         if (xord[k] != 127)
117         {
118           sprintf(log_line, "%d => %d\n", k, xord[k]);
119           show_line(log_line, 0);
120         }
121       }
122     }
123   }
124
125   if (interaction < batch_mode)
126     interaction = error_stop_mode;
127
128   deletions_allowed = true;
129   set_box_allowed = true;
130   error_count = 0;
131   help_ptr = 0;
132   use_err_help = false;
133   interrupt = 0;
134   OK_to_interrupt = true;
135
136 #ifdef DEBUG
137   was_mem_end = mem_min;
138 /*  was_lo_max = mem_min; */
139   was_lo_max = mem_bot;
140 /*  was_hi_min = mem_max; */
141   was_hi_min = mem_top;
142   panicking = false;
143 #endif
144
145   nest_ptr = 0;
146   max_nest_stack = 0;
147   mode = 1;
148   head = contrib_head;
149   tail = contrib_head;
150   cur_list.aux_field.cint = ignore_depth;
151   mode_line = 0;
152   prev_graf = 0;
153   shown_mode = 0;
154   page_contents = 0;
155   page_tail = page_head;
156
157 #ifdef ALLOCATEMAIN
158   if (is_initex)
159 #endif
160     link(page_head) = 0;
161
162   last_glue = empty_flag;
163   last_penalty = 0;
164   last_kern = 0;
165   page_so_far[7] = 0;
166   page_max_depth = 0;
167
168   for (k = int_base; k <= eqtb_size; k++)
169     xeq_level[k] = level_one;
170
171   no_new_control_sequence = true;
172   next(hash_base) = 0;
173   text(hash_base) = 0;
174
175   for (k = hash_base + 1; k <= undefined_control_sequence - 1; k++)
176     hash[k] = hash[hash_base];
177
178   save_ptr = 0;
179   cur_level = 1;
180   cur_group = 0;
181   cur_boundary = 0;
182   max_save_stack = 0;
183   mag_set = 0;
184   cur_mark[0] = 0;
185   cur_mark[1] = 0;
186   cur_mark[2] = 0;
187   cur_mark[3] = 0;
188   cur_mark[4] = 0;
189   cur_val = 0;
190   cur_val_level = 0;
191   radix = 0;
192   cur_order = 0;
193
194   for (k = 0; k <= 16; k++)
195     read_open[k] = 2;
196
197   cond_ptr = 0;
198   if_limit = 0;
199   cur_if = 0;
200   if_line = 0;
201
202   for (k = 0; k <= font_max; k++)
203     font_used[k] = false;
204
205   null_character.b0 = 0;
206   null_character.b1 = 0;
207   null_character.b2 = 0;
208   null_character.b3 = 0;
209   total_pages = 0;
210   max_v = 0;
211   max_h = 0;
212   max_push = 0;
213   last_bop = -1;
214   doing_leaders = false;
215   dead_cycles = 0;
216   cur_s = -1;
217   half_buf = dvi_buf_size / 2;
218   dvi_limit = dvi_buf_size;
219   dvi_ptr = 0;
220   dvi_offset = 0;
221   dvi_gone = 0;
222   down_ptr = 0;
223   right_ptr = 0;
224   adjust_tail = 0;
225   last_badness = 0;
226   pack_begin_line = 0;
227   empty_field.v.RH = 0;
228   empty_field.v.LH = 0;
229   null_delimiter.b0 = 0;
230   null_delimiter.b1 = 0;
231   null_delimiter.b2 = 0;
232   null_delimiter.b3 = 0;
233   align_ptr = 0;
234   cur_align = 0;
235   cur_span = 0;
236   cur_loop = 0;
237   cur_head = 0;
238   cur_tail = 0;
239
240
241 /*  *not* OK with ALLOCATEHYPHEN, since may not be allocated yet */
242 #ifndef ALLOCATEHYPHEN
243   for (z = 0; z <= hyphen_prime; z++)
244   {
245     hyph_word[z] = 0;
246     hyph_list[z] = 0;
247   }
248 #endif
249
250   hyph_count = 0;
251   output_active = false;
252   insert_penalties = 0;
253   ligature_present = false;
254   cancel_boundary = false;
255   lft_hit = false;
256   rt_hit = false;
257   ins_disc = false;
258   after_token = 0;
259   long_help_seen = false;
260   format_ident = 0;
261
262   for (k = 0; k <= 17; k++)
263     write_open[k] = false;
264
265   edit_name_start = 0;
266
267 #ifdef INITEX
268   if (is_initex)
269   {
270     do_initex();
271   }
272 #endif
273 }
274
275 /* do the part of initialize() that requires mem_top, mem_max or mem[] */
276 /* do this part after allocating main memory */
277
278 #ifdef ALLOCATEMAIN
279 void initialize_aux (void)
280 {
281 #ifdef DEBUG
282   was_mem_end = mem_min;
283 /*  was_lo_max = mem_min; */
284   was_lo_max = mem_bot;
285 /*  was_hi_min = mem_max; */
286   was_hi_min = mem_top;
287   panicking = false;
288 #endif /* DEBUG */
289 /*  nest_ptr = 0; */
290 /*  max_nest_stack = 0; */
291   mode = 1;
292   head = contrib_head;
293   tail = contrib_head;
294   cur_list.aux_field.cint = ignore_depth;
295   mode_line = 0;
296   prev_graf = 0;
297 /*  shown_mode = 0; */
298 /*  page_contents = 0; */
299   page_tail = page_head;
300   link(page_head) = 0;
301 }
302 #endif  // end of ifdef ALLOCATEMAIN
303 /* sec 0815 */
304 void line_break_ (integer final_widow_penalty)
305 {
306   bool auto_breaking;
307   halfword prevp;
308   halfword q, r, s, prevs;
309   internal_font_number f;
310 /*  small_number j;  */
311   int j;                /* 95/Jan/7 */
312 /*  unsigned char c;  */
313   unsigned int c;           /* 95/Jan/7 */
314 /*  savedbadness = 0; */    /* 96/Feb/9 */
315
316   pack_begin_line = mode_line;
317   link(temp_head) = link(head);
318
319   if ((tail >= hi_mem_min))
320   {
321     tail_append(new_penalty(inf_penalty));
322   } 
323   else if (type(tail) != glue_node)
324   {
325     tail_append(new_penalty(inf_penalty));
326   }
327   else
328   {
329     type(tail) = penalty_node;
330     delete_glue_ref(glue_ptr(tail));
331     flush_node_list(leader_ptr(tail));
332     penalty(tail) = inf_penalty;
333   }
334
335   link(tail) = new_param_glue(par_fill_skip_code);
336   init_cur_lang = prev_graf % 65536L;
337   init_l_hyf = prev_graf / 4194304L; /* 2^22 */
338   init_r_hyf = (prev_graf / 65536L) % 64;
339   pop_nest();
340   no_shrink_error_yet = true;
341
342   if ((shrink_order(left_skip) != normal) && (shrink(left_skip) != 0))
343   {
344     left_skip = finite_shrink(left_skip);
345   }
346
347   if ((shrink_order(right_skip) != normal) && (shrink(right_skip) != 0))
348   {
349     right_skip = finite_shrink(right_skip);
350   }
351
352   q = left_skip;
353   r = right_skip;
354   background[1] = width(q) + width(r);
355   background[2] = 0;
356   background[3] = 0;
357   background[4] = 0;
358   background[5] = 0;
359   background[2 + stretch_order(q)] = stretch(q);
360   background[2 + stretch_order(r)] = background[2 + stretch_order(r)] + stretch(r);
361   background[6] = shrink(q) + shrink(r);
362
363   minimum_demerits = 1073741823L; /* 2^30 - 1 *//* 40000000 hex - 1 */
364   minimal_demerits[tight_fit] = 1073741823L;
365   minimal_demerits[decent_fit] = 1073741823L;
366   minimal_demerits[loose_fit] = 1073741823L;
367   minimal_demerits[very_loose_fit] = 1073741823L;
368
369   if (par_shape_ptr == 0)
370     if (hang_indent == 0)
371     {
372       last_special_line = 0;
373       second_width = hsize;
374       second_indent = 0;
375     }
376     else
377     {
378       last_special_line = abs(hang_after);
379
380       if (hang_after < 0)
381       {
382         first_width = hsize - abs(hang_indent);
383
384         if (hang_indent >= 0)
385           first_indent = hang_indent;
386         else
387           first_indent = 0;
388
389         second_width = hsize;
390         second_indent = 0;
391       }
392       else
393       {
394         first_width = hsize;
395         first_indent = 0;
396         second_width = hsize - abs(hang_indent);
397
398         if (hang_indent >= 0)
399           second_indent = hang_indent;
400         else
401           second_indent = 0;
402       }
403     }
404   else
405   {
406     last_special_line = info(par_shape_ptr) - 1;
407     second_width = mem[par_shape_ptr + 2 * (last_special_line + 1)].cint;
408     second_indent = mem[par_shape_ptr + 2 * last_special_line + 1].cint;
409   }
410
411   if (looseness == 0)
412     easyline = last_special_line;
413   else
414     easyline = empty_flag;
415
416   threshold = pretolerance;
417
418   if (threshold >= 0)
419   {
420 #ifdef STAT
421     if (tracing_paragraphs > 0)
422     {
423       begin_diagnostic();
424       print_nl("@firstpass");
425     }
426 #endif /* STAT */
427     second_pass = false;
428     final_pass = false;
429     first_pass_count++; /* 96 Feb 9 */
430   }
431   else
432   {
433     threshold = tolerance;
434     second_pass = true;
435     final_pass = (emergency_stretch <= 0);
436 #ifdef STAT
437     if (tracing_paragraphs > 0)
438       begin_diagnostic();
439 #endif /* STAT */
440   }
441
442   while (true)
443   {
444     if (threshold > inf_bad)
445       threshold = inf_bad;
446
447     if (second_pass)
448     {
449 #ifdef INITEX
450       if (is_initex)
451       {
452         if (trie_not_ready)
453           init_trie();
454       } /* bkph */
455 #endif /* INITEX */
456
457       cur_lang = init_cur_lang;
458       lhyf = init_l_hyf;
459       rhyf = init_r_hyf;
460     }
461
462     q = get_node(3);
463     type(q) = unhyphenated;
464     fitness(q) = decent_fit;
465     link(q) = active;
466     break_node(q) = 0;
467     line_number(q) = prev_graf + 1;
468     total_demerits(q) = 0;
469     link(active) = q;
470     active_width[1] = background[1];
471     active_width[2] = background[2];
472     active_width[3] = background[3];
473     active_width[4] = background[4];
474     active_width[5] = background[5];
475     active_width[6] = background[6];
476
477     passive = 0;
478     printed_node = temp_head;
479     pass_number = 0;
480     font_in_short_display = 0;
481
482     cur_p = link(temp_head);
483     auto_breaking = true;
484     prevp = cur_p;
485
486     while((cur_p != 0) && (link(active) != active))
487     {
488       if ((cur_p >= hi_mem_min))
489       {
490         prevp = cur_p;
491
492         do
493           {
494             f = font(cur_p);
495             active_width[1] = active_width[1] + char_width(f, char_info(f, character(cur_p)));
496             cur_p = link(cur_p);
497           }
498         while(!(!(cur_p >= hi_mem_min)));
499       }
500
501       switch(type(cur_p))
502       {
503         case hlist_node:
504         case vlist_node:
505         case rule_node:
506           active_width[1] = active_width[1] + width(cur_p);
507           break;
508         case whatsit_node:
509           if (subtype(cur_p) == language_node)
510           {
511             cur_lang = what_lang(cur_p);
512             lhyf = what_lhm(cur_p);
513             rhyf = what_rhm(cur_p);
514           }
515           break;
516         case glue_node:
517           {
518             if (auto_breaking)
519             {
520               if ((prevp >= hi_mem_min))
521                 try_break(0, unhyphenated);
522               else if ((mem[prevp].hh.b0 < 9))
523                 try_break(0, unhyphenated);
524               else if ((type(prevp) == kern_node) && (subtype(prevp) != explicit))
525                 try_break(0, unhyphenated);
526             }
527
528             if ((mem[glue_ptr(cur_p)].hh.b1 != 0) && (mem[glue_ptr(cur_p) + 3].cint != 0))
529             {
530               glue_ptr(cur_p) = finite_shrink(glue_ptr(cur_p));
531             }
532
533             q = glue_ptr(cur_p);
534             active_width[1] = active_width[1]+ width(q);
535             active_width[2 + stretch_order(q)] = active_width[2 + stretch_order(q)] + stretch(q);
536             active_width[6] = active_width[6] + shrink(q);
537
538             if (second_pass && auto_breaking)
539             {
540               prevs = cur_p;
541               s = link(prevs);
542
543               if (s != 0)
544               {
545                 while (true)
546                 {
547                   if ((s >= hi_mem_min))
548                   {
549                     c = character(s);
550                     hf = font(s);
551                   }
552                   else if (type(s) == ligature_node)
553                     if (lig_ptr(s) == 0)
554                       goto lab22;
555                     else
556                     {
557                       q = lig_ptr(s);
558                       c = character(q);
559                       hf = font(q);
560                     }
561                   else if ((type(s) == kern_node) && (subtype(s) == normal))
562                     goto lab22;
563                   else if (type(s) == whatsit_node)
564                   {
565                     if (subtype(s) == language_node)
566                     {
567                       cur_lang = what_lang(s);
568                       lhyf = what_lhm(s);
569                       rhyf = what_rhm(s);
570                     }
571                     goto lab22;
572                   }
573                   else
574                     goto lab31;
575
576                   if (lc_code(c) != 0)
577                     if ((lc_code(c) == (halfword) c) || (uc_hyph > 0)) /* fixed signed tyoe */
578                       goto lab32;
579                     else
580                       goto lab31;
581 lab22:
582                   prevs = s;
583                   s = link(prevs);
584                 }
585 lab32:
586                 hyf_char = hyphen_char[hf];
587
588                 if (hyf_char < 0)
589                   goto lab31; 
590
591                 if (hyf_char > 255)
592                   goto lab31; /* ? */
593
594                 ha = prevs;
595
596                 if (lhyf + rhyf > 63)
597                   goto lab31;
598
599                 hn = 0;
600
601                 while (true)
602                 {
603                   if ((s >= hi_mem_min))
604                   {
605                     if (font(s) != hf)
606                       goto lab33;
607
608                     hyfbchar = character(s);
609
610                     c = hyfbchar;     /*  unsigned char c;  */
611
612                     if (lc_code(c) == 0)
613                       goto lab33;
614
615                     if (hn == 63)
616                       goto lab33;
617
618                     hb = s;
619                     incr(hn);
620                     hu[hn] = c;
621                     hc[hn]= lc_code(c);
622                     hyfbchar = non_char;
623                   }
624                   else if (type(s) == ligature_node)
625                   {
626                     if (font(lig_char(s)) != hf)
627                       goto lab33;
628
629                     j = hn;
630                     q = lig_ptr(s);
631
632                     if (q != 0) /* 94/Mar/23 BUG FIX */
633                       hyfbchar = character(q);
634
635                     while (q != 0) /* 94/Mar/23 BUG FIX */
636                     {
637                       c = character(q);
638
639                       if (lc_code(c) == 0)
640                         goto lab33;
641
642                       if (j == 63)
643                         goto lab33;
644
645                       incr(j);
646                       hu[j] = c;
647                       hc[j] = lc_code(c);
648                       q = link(q);
649                     }
650
651                     hb = s;
652                     hn = j;
653
654                     if (odd(subtype(s)))
655                       hyfbchar = font_bchar[hf];
656                     else
657                       hyfbchar = non_char;
658                   }
659                   else if ((type(s) == kern_node) && (subtype(s) == normal))
660                   {
661                     hb = s;
662                     hyfbchar = font_bchar[hf];
663                   }
664                   else
665                     goto lab33;
666
667                   s = link(s);
668                 }
669 lab33:;
670                 if (hn < lhyf + rhyf)
671                   goto lab31;
672
673                 while (true)
674                 {
675                   if (!((s >= hi_mem_min)))
676                     switch(type(s))
677                     {
678                       case ligature_node:
679                         break;
680                       case kern_node:
681                         if (subtype(s) != normal)
682                           goto lab34;
683                         break;
684                       case whatsit_node:
685                       case glue_node:
686                       case penalty_node:
687                       case ins_node:
688                       case adjust_node:
689                       case mark_node:
690                         goto lab34;
691                         break;
692                       default:
693                         goto lab31;
694                         break;
695                     }
696                   s = link(s);
697                 }
698 lab34:;
699                 hyphenate();
700               }
701 lab31:;
702             }
703           }
704           break;
705         case kern_node:
706           if (subtype(cur_p) == explicit)
707           {
708             if (!(link(cur_p) >= hi_mem_min) && auto_breaking)
709               if (type(link(cur_p)) == glue_node)
710                 try_break(0, unhyphenated);
711
712             active_width[1] = active_width[1] + width(cur_p);
713           }
714           else
715             active_width[1] = active_width[1] + width(cur_p);
716           break;
717         case ligature_node:
718           {
719             f = font(lig_char(cur_p));
720             active_width[1] = active_width[1] + char_width(f, char_info(f, character(lig_char(cur_p))));
721           }
722           break;
723         case disc_node:
724           {
725             s = pre_break(cur_p);
726             disc_width = 0;
727
728             if (s == 0)
729               try_break(ex_hyphen_penalty, hyphenated);
730             else
731             {
732               do
733               {
734                 if ((s >= hi_mem_min))
735                 {
736                   f = font(s);
737                   disc_width = disc_width + char_width(f, char_info(f, character(s)));
738                 }
739                 else switch(type(s))
740                 {
741                   case ligature_node:
742                     {
743                       f = font(lig_char(s));
744                       disc_width = disc_width + font_info[width_base[f] + font_info[char_base[f]+ mem[s + 1].hh.b1].qqqq.b0].cint;
745                     }
746                     break;
747                   case hlist_node:
748                   case vlist_node:
749                   case rule_node:
750                   case kern_node:
751                     disc_width = disc_width + width(s);
752                     break;
753                   default:
754                     {
755                       confusion("disc3");
756                       return;       // abort_flag set
757                     }
758                     break;
759                 }
760                 s = link(s);
761               }
762               while(!(s == 0));
763
764               active_width[1] = active_width[1] + disc_width;
765               try_break(hyphen_penalty, hyphenated);
766               active_width[1] = active_width[1] - disc_width;
767             }
768             r = replace_count(cur_p);
769             s = link(cur_p);
770
771             while (r > 0)
772             {
773               if ((s >= hi_mem_min))
774               {
775                 f = font(s);
776                 active_width[1] = active_width[1] + char_width(f, char_info(f, character(s)));
777               }
778               else switch(type(s))
779               {
780                 case ligature_node:
781                   {
782                     f = font(lig_char(s));
783                     active_width[1] = active_width[1] + char_width(f, char_info(f, character(lig_char(s))));
784                   }
785                   break;
786                 case hlist_node:
787                 case vlist_node:
788                 case rule_node:
789                 case kern_node:
790                   active_width[1] = active_width[1] + width(s);
791                   break;
792                 default:
793                   {
794                     confusion("disc4");
795                     return;       // abort_flag set
796                   }
797                   break;
798               }
799               decr(r);
800               s = link(s);
801             }
802             prevp = cur_p;
803             cur_p = s;
804             goto lab35;
805           }
806           break;
807         case math_node:
808           {
809             auto_breaking = (subtype(cur_p) == 1);
810             {
811               if (!(link(cur_p) >= hi_mem_min) && auto_breaking)
812                 if (type(link(cur_p)) == glue_node)
813                   try_break(0, unhyphenated);
814
815               active_width[1] = active_width[1] + width(cur_p);
816             }
817           }
818           break;
819         case penalty_node:
820           try_break(penalty(cur_p), unhyphenated);
821           break;
822         case mark_node:
823         case ins_node:
824         case adjust_node:
825           break;
826         default:
827           {
828             confusion("paragraph");
829             return;       // abort_flag set
830           }
831           break;
832       }
833       prevp = cur_p;
834       cur_p = link(cur_p);
835 lab35:;
836     }
837
838     if (cur_p == 0)
839     {
840       try_break(eject_penalty, hyphenated);
841
842       if (link(active) != active)
843       {
844         r = link(active);
845         fewest_demerits = 1073741823L; /* 2^30 - 1 */
846
847         do
848         {
849           if (type(r) != 2)
850             if (total_demerits(r) < fewest_demerits)
851             {
852               fewest_demerits = total_demerits(r);
853               best_bet = r;
854             }
855           r = link(r);
856         }
857         while (!(r == active));
858         best_line = line_number(best_bet);
859
860         if (looseness == 0)
861         {
862           goto lab30;           /* normal exit */
863         }
864
865         {
866           r = link(active);
867           actual_looseness = 0;
868           do
869           {
870             if (type(r) != 2)
871             {
872               line_diff = toint(line_number(r)) - toint(best_line);
873
874               if (((line_diff < actual_looseness) && (looseness <= line_diff)) ||
875                   ((line_diff > actual_looseness) && (looseness >= line_diff)))
876               {
877                 best_bet = r;
878                 actual_looseness = line_diff;
879                 fewest_demerits = total_demerits(r);
880               }
881               else if ((line_diff == actual_looseness) && (total_demerits(r) < fewest_demerits))
882               {
883                 best_bet = r;
884                 fewest_demerits = total_demerits(r);
885               }
886             }
887             r = link(r);
888           }
889           while (!(r == active));
890           best_line = line_number(best_bet);
891         }
892
893         if ((actual_looseness == looseness) || final_pass)
894         {
895           goto lab30;
896         }
897       }
898     }
899
900     q = link(active);
901
902     while (q != active)
903     {
904       cur_p = link(q);
905
906       if (type(q) == 2)
907         free_node(q, 7);
908       else
909         free_node(q, 3);
910
911       q = cur_p;
912     }
913
914     q = passive;
915
916     while (q != 0)
917     {
918       cur_p = link(q);
919       free_node(q, 2);
920       q = cur_p;
921     }
922
923     if (! second_pass)
924     {
925 #ifdef STAT
926       if (tracing_paragraphs > 0)
927         print_nl("@secondpass");
928 #endif /* STAT */
929       threshold = tolerance;
930       second_pass = true;
931       second_pass_count++;          /* 96 Feb 9 */
932       final_pass = (emergency_stretch <= 0);
933     }
934     else
935     {
936 #ifdef STAT
937       if (tracing_paragraphs > 0)
938         print_nl("@emergencypass");
939 #endif /* STAT */
940 /*     can only get here is \emergencystretch has been set positive */
941       background[2] = background[2] + emergency_stretch;
942       final_pass = true;
943       ++final_pass_count;         /* 96 Feb 9 */
944     } /* end of if second_pass */
945   } /* end of while(true)do */
946 /* cannot drop through from above loop */
947 lab30:                /* common exit point */
948   if (best_line == 2)
949     single_line++;
950
951 #ifdef STAT
952   if (tracing_paragraphs > 0)
953   {
954     end_diagnostic(true);
955     normalize_selector();
956   }
957 #endif /* STAT */
958
959   post_line_break(final_widow_penalty);
960   q = link(active);
961
962   while (q != active)
963   {
964     cur_p = link(q);
965
966     if (type(q) == 2)
967       free_node(q, 7);
968     else
969       free_node(q, 3);
970
971     q = cur_p;
972   }
973
974   q = passive;
975
976   while (q != 0)
977   {
978     cur_p = link(q);
979     free_node(q, 2);
980     q = cur_p;
981   }
982
983   pack_begin_line = 0;
984 }
985 /* sec 1211 */
986 void prefixed_command (void)
987 {
988   small_number a;
989   internal_font_number f;
990   halfword j;
991   font_index k;
992   halfword p, q;
993   integer n;
994   bool e;
995
996   a = 0;
997
998   while (cur_cmd == prefix)
999   {
1000     if (!odd(a / cur_chr))
1001       a = a + cur_chr;
1002
1003     do
1004       {
1005         get_x_token();
1006       }
1007     while(!((cur_cmd != spacer) && (cur_cmd != relax)));
1008
1009     if (cur_cmd <= max_non_prefixed_command)
1010     {
1011       print_err("You can't use a prefix with `");
1012       print_cmd_chr(cur_cmd, cur_chr);
1013       print_char('\'');
1014       help1("I'll pretend you didn't say \\long or \\outer or \\global.");
1015       back_error();
1016       return;
1017     }
1018   }
1019
1020   if ((cur_cmd != def) && (a % 4 != 0))
1021   {
1022     print_err("You can't use `");
1023     print_esc("long");
1024     print_string("' or `");
1025     print_esc("outer");
1026     print_string("' with `");
1027     print_cmd_chr(cur_cmd, cur_chr); 
1028     print_char('\'');
1029     help1("I'll pretend you didn't say \\long or \\outer here.");
1030     error();
1031   }
1032
1033   if (global_defs != 0)
1034     if (global_defs < 0)
1035     {
1036       if ((a >= 4))
1037         a = a - 4;
1038     }
1039     else
1040     {
1041       if (!(a >= 4))
1042         a = a + 4;
1043     }
1044
1045   switch (cur_cmd)
1046   {
1047     case set_font:
1048       if ((a >= 4))
1049         geq_define(cur_font_loc, data, cur_chr);
1050       else
1051         eq_define(cur_font_loc, data, cur_chr);
1052       break;
1053
1054     case def:
1055       {
1056         if (odd(cur_chr) && !(a >= 4) && (global_defs >= 0))
1057           a = a + 4;
1058
1059         e = (cur_chr >= 2);
1060         get_r_token();
1061         p = cur_cs;
1062         q = scan_toks(true, e);
1063
1064         if ((a >= 4))
1065           geq_define(p, call + (a % 4), def_ref);
1066         else
1067           eq_define(p, call + (a % 4), def_ref);
1068       }
1069       break;
1070
1071     case let:
1072       {
1073         n = cur_chr;
1074         get_r_token();
1075         p = cur_cs;
1076
1077         if (n == 0)
1078         {
1079           do
1080             {
1081               get_token();
1082             }
1083           while (!(cur_cmd != spacer));
1084
1085           if (cur_tok == other_token + '=')
1086           {
1087             get_token();
1088
1089             if (cur_cmd == spacer)
1090               get_token();
1091           }
1092         }
1093         else
1094         {
1095           get_token();
1096           q = cur_tok;
1097           get_token();
1098           back_input();
1099           cur_tok = q;
1100           back_input();
1101         }
1102
1103         if (cur_cmd >= call)
1104           incr(mem[cur_chr].hh.v.LH);
1105
1106         if ((a >= 4))
1107           geq_define(p, cur_cmd, cur_chr);
1108         else
1109           eq_define(p, cur_cmd, cur_chr);
1110       }
1111       break;
1112
1113     case shorthand_def:
1114       {
1115         n = cur_chr;
1116         get_r_token();
1117         p = cur_cs;
1118
1119         if ((a >= 4))
1120           geq_define(p, relax, 256);
1121         else
1122           eq_define(p, relax, 256);
1123
1124         scan_optional_equals();
1125
1126         switch (n)
1127         {
1128           case char_def_code:
1129             {
1130               scan_char_num();
1131
1132               if ((a >= 4))
1133                 geq_define(p, char_given, cur_val);
1134               else
1135                 eq_define(p, char_given, cur_val);
1136             }
1137             break;
1138
1139           case math_char_def_code:
1140             {
1141               scan_fifteen_bit_int();
1142
1143               if ((a >= 4))
1144                 geq_define(p, math_given, cur_val);
1145               else
1146                 eq_define(p, math_given, cur_val);
1147             }
1148             break;
1149
1150           default:
1151             {
1152               scan_eight_bit_int();
1153
1154               switch (n)
1155               {
1156                 case count_def_code:
1157                   if ((a >= 4))
1158                     geq_define(p, assign_int, count_base + cur_val);
1159                   else
1160                     eq_define(p, assign_int, count_base + cur_val);
1161                   break;
1162
1163                 case dimen_def_code:
1164                   if ((a >= 4))
1165                     geq_define(p, assign_dimen, scaled_base + cur_val);
1166                   else
1167                     eq_define(p, assign_dimen, scaled_base + cur_val);
1168                   break;
1169
1170                 case skip_def_code:
1171                   if ((a >= 4)) 
1172                     geq_define(p, assign_glue, skip_base + cur_val);
1173                   else
1174                     eq_define(p, assign_glue, skip_base + cur_val);
1175                   break;
1176
1177                 case mu_skip_def_code:
1178                   if ((a >= 4))
1179                     geq_define(p, assign_mu_glue, mu_skip_base + cur_val);
1180                   else
1181                     eq_define(p, assign_mu_glue, mu_skip_base + cur_val);
1182                   break;
1183
1184                 case toks_def_code:
1185                   if ((a >= 4))
1186                     geq_define(p, assign_toks, toks_base + cur_val);
1187                   else
1188                     eq_define(p, assign_toks, toks_base + cur_val);
1189                   break;
1190               }
1191             }
1192             break;
1193         }
1194       }
1195       break;
1196
1197     case read_to_cs:
1198       {
1199         scan_int();
1200         n = cur_val;
1201
1202         if (! scan_keyword("to"))
1203         {
1204           print_err("Missing `to' inserted");
1205           help2("You should have said `\\read<number> to \\cs'.",
1206               "I'm going to look for the \\cs now.");
1207           error();
1208         }
1209
1210         get_r_token();
1211         p = cur_cs;
1212         read_toks(n, p);
1213
1214         if ((a >= 4))
1215           geq_define(p, call, cur_val);
1216         else
1217           eq_define(p, call, cur_val);
1218       }
1219       break;
1220
1221     case toks_register:
1222     case assign_toks:
1223       {
1224         q = cur_cs;
1225
1226         if (cur_cmd == toks_register)
1227         {
1228           scan_eight_bit_int();
1229           p = toks_base + cur_val;
1230         }
1231         else
1232           p = cur_chr;
1233
1234         scan_optional_equals();
1235
1236         do
1237           {
1238             get_x_token();
1239           }
1240         while(!((cur_cmd != spacer) && (cur_cmd != relax)));
1241
1242         if (cur_cmd != left_brace)
1243         {
1244           if (cur_cmd == toks_register)
1245           {
1246             scan_eight_bit_int();
1247             cur_cmd = assign_toks;
1248             cur_chr = toks_base + cur_val;
1249           }
1250
1251           if (cur_cmd == assign_toks)
1252           {
1253             q = equiv(cur_chr);
1254
1255             if (q == 0)
1256               if ((a >= 4))
1257                 geq_define(p, undefined_cs, 0);
1258               else
1259                 eq_define(p, undefined_cs, 0);
1260             else
1261             {
1262               incr(mem[q].hh.v.LH);
1263
1264               if ((a >= 4))
1265                 geq_define(p, call, q);
1266               else
1267                 eq_define(p, call, q);
1268             }
1269             goto lab30;
1270           }
1271         }
1272
1273         back_input();
1274         cur_cs = q;
1275         q = scan_toks(false, false);
1276
1277         if (link(def_ref) == 0)
1278         {
1279           if ((a >= 4))
1280             geq_define(p, undefined_cs, 0);
1281           else
1282             eq_define(p, undefined_cs, 0);
1283
1284           free_avail(def_ref);
1285         }
1286         else
1287         {
1288           if (p == output_routine_loc)
1289           {
1290             link(q) = get_avail();
1291             q = link(q);
1292             info(q) = right_brace_token + '}';
1293             q = get_avail();
1294             info(q) = left_brace_token + '{';
1295             link(q) = link(def_ref);
1296             link(def_ref) = q;
1297           }
1298
1299           if ((a >= 4))
1300             geq_define(p, call, def_ref);
1301           else
1302             eq_define(p, call, def_ref);
1303         }
1304       }
1305       break;
1306
1307     case assign_int:
1308       {
1309         p = cur_chr;
1310         scan_optional_equals();
1311         scan_int();
1312
1313         if ((a >= 4))
1314           geq_word_define(p, cur_val);
1315         else
1316           eq_word_define(p, cur_val);
1317       }
1318       break;
1319
1320     case assign_dimen:
1321       {
1322         p = cur_chr;
1323         scan_optional_equals();
1324         scan_dimen(false, false, false);
1325
1326         if ((a >= 4))
1327           geq_word_define(p, cur_val);
1328         else
1329           eq_word_define(p, cur_val);
1330       }
1331       break;
1332
1333     case assign_glue:
1334     case assign_mu_glue:
1335       {
1336         p = cur_chr;
1337         n = cur_cmd;
1338         scan_optional_equals();
1339
1340         if (n == assign_mu_glue)
1341           scan_glue(mu_val);
1342         else
1343           scan_glue(glue_val);
1344
1345         trap_zero_glue();
1346
1347         if ((a >= 4))
1348           geq_define(p, glue_ref, cur_val);
1349         else
1350           eq_define(p, glue_ref, cur_val);
1351       }
1352       break;
1353
1354     case def_code:
1355       {
1356         if (cur_chr == cat_code_base)
1357           n = max_char_code;
1358         else if (cur_chr == math_code_base)
1359           n = 32768L;                 /* 2^15 */
1360         else if (cur_chr == sf_code_base)
1361           n = 32767;                /* 2^15 - 1*/
1362         else if (cur_chr == del_code_base)
1363           n = 16777215L;              /* 2^24 - 1 */
1364         else
1365           n = 255;             /* 2^8 - 1 */
1366
1367         p = cur_chr;
1368         scan_char_num();
1369         p = p + cur_val;
1370         scan_optional_equals();
1371         scan_int();
1372
1373         if (((cur_val < 0) && (p < del_code_base)) ||(cur_val > n))
1374         {
1375           print_err("Invalid code(");
1376           print_int(cur_val);
1377
1378           if (p < del_code_base)
1379             print_string("), should be in the range 0..");
1380           else
1381             print_string("), should be at most ");
1382
1383           print_int(n);
1384           help1("I'm going to use 0 instead of that illegal code value.");
1385           error();
1386           cur_val = 0;
1387         }
1388
1389         if (p < math_code_base)
1390           if ((a >= 4))
1391             geq_define(p, data, cur_val);
1392           else
1393             eq_define(p, data, cur_val);
1394         else if (p < del_code_base)
1395           if ((a >= 4))
1396             geq_define(p, data, cur_val);
1397           else
1398             eq_define(p, data, cur_val);
1399         else 
1400           if ((a >= 4))
1401             geq_word_define(p, cur_val);
1402           else
1403             eq_word_define(p, cur_val);
1404       }
1405       break;
1406
1407     case def_family:
1408       {
1409         p = cur_chr;
1410         scan_four_bit_int();
1411         p = p + cur_val;
1412         scan_optional_equals();
1413         scan_font_ident();
1414
1415         if ((a >= 4))
1416           geq_define(p, data, cur_val);
1417         else
1418           eq_define(p, data, cur_val);
1419       }
1420       break;
1421
1422     case tex_register:
1423     case advance:
1424     case multiply:
1425     case divide:
1426       do_register_command(a);
1427       break;
1428
1429     case set_box:
1430       {
1431         scan_eight_bit_int();
1432
1433         if ((a >= 4))
1434           n = 256 + cur_val;
1435         else
1436           n = cur_val;
1437
1438         scan_optional_equals();
1439
1440         if (set_box_allowed)
1441         {
1442           scan_box(box_flag + n);
1443         }
1444         else
1445         {
1446           print_err("Improper ");
1447           print_esc("setbox");
1448           help2("Sorry, \\setbox is not allowed after \\halign in a display,",
1449               "or between \\accent and an accented character.");
1450           error();
1451         }
1452       }
1453       break;
1454
1455     case set_aux:
1456       alter_aux();
1457       break;
1458
1459     case set_prev_graf:
1460       alter_prev_graf();
1461       break;
1462
1463     case set_page_dimen:
1464       alter_page_so_far();
1465       break;
1466
1467     case set_page_int:
1468       alter_integer();
1469       break;
1470
1471     case set_box_dimen:
1472       alter_box_dimen();
1473       break;
1474
1475     case set_shape:
1476       {
1477         scan_optional_equals();
1478         scan_int();
1479         n = cur_val;
1480
1481         if (n <= 0)
1482           p = 0;
1483         else
1484         {
1485           p = get_node(2 * n + 1);
1486           info(p) = n;
1487
1488           for (j = 1; j <= n; j++)
1489           {
1490             scan_dimen(false, false, false);
1491             mem[p + 2 * j - 1].cint = cur_val;
1492             scan_dimen(false, false, false);
1493             mem[p + 2 * j].cint = cur_val;
1494           }
1495         }
1496
1497         if ((a >= 4))
1498           geq_define(par_shape_loc, shape_ref, p);
1499         else
1500           eq_define(par_shape_loc, shape_ref, p);
1501       }
1502       break;
1503
1504     case hyph_data:
1505       if (cur_chr == 1)
1506       {
1507 #ifdef INITEX
1508         if (is_initex)
1509         {
1510           new_patterns();
1511           goto lab30;
1512         }
1513 #endif /* INITEX */
1514         print_err("Patterns can be loaded only by INITEX");
1515         help_ptr = 0;
1516         error();
1517
1518         do
1519           {
1520             get_token();
1521           }
1522         while(!(cur_cmd == right_brace));
1523
1524         return;
1525       }
1526       else
1527       {
1528         new_hyph_exceptions();
1529         goto lab30;
1530       }
1531       break;
1532
1533     case assign_font_dimen:
1534       {
1535         find_font_dimen(true);
1536         k = cur_val;
1537         scan_optional_equals();
1538         scan_dimen(false, false, false);
1539         font_info[k].cint = cur_val;
1540       }
1541       break;
1542
1543     case assign_font_int:
1544       {
1545         n = cur_chr;
1546         scan_font_ident();
1547         f = cur_val;
1548         scan_optional_equals();
1549         scan_int();
1550
1551         if (n == 0)
1552           hyphen_char[f] = cur_val;
1553         else
1554           skew_char[f] = cur_val;
1555       }
1556       break;
1557
1558     case def_font:
1559       new_font(a);
1560       break;
1561
1562     case set_interaction:
1563       new_interaction();
1564       break;
1565
1566     default:
1567       {
1568         confusion("prefix");
1569         return;       // abort_flag set
1570       }
1571       break;
1572   }
1573
1574 lab30:
1575   if (after_token != 0)
1576   {
1577     cur_tok = after_token;
1578     back_input();
1579     after_token = 0;
1580   }
1581 }
1582
1583 void bad_formator_pool (char *name, char *defaultname, char *envvar)
1584 {
1585   if (name == NULL)
1586     name = defaultname;
1587
1588   sprintf(log_line, "(Perhaps %s is for an older version of TeX)\n", name);
1589   show_line(log_line, 0);
1590   name_of_file[name_length + 1] = '\0';
1591   sprintf(log_line, "(Alternatively, %s may have been corrupted)\n", name_of_file + 1);
1592   show_line(log_line, 0);
1593   name_of_file[name_length + 1] = ' ';
1594   sprintf(log_line, "(Perhaps your %s environment variable is not set correctly)\n", envvar);
1595   show_line(log_line, 0);
1596
1597   {
1598     char *s;
1599
1600     if ((s = grabenv(envvar)) != NULL)
1601     {
1602       sprintf(log_line, "(%s=%s)\n", envvar, s);
1603       show_line(log_line, 0);
1604     }
1605     else
1606     {
1607       sprintf(log_line, "%s environment variable not set\n", envvar);
1608       show_line(log_line, 0);
1609     }
1610   }
1611
1612 #ifndef _WINDOWS
1613   fflush(stdout);
1614 #endif
1615 }
1616 /* sec 1303 */
1617 bool load_fmt_file (void)
1618 {
1619   integer j, k;
1620   halfword p, q;
1621   integer x;
1622
1623   undump_int(x);
1624
1625   if (x != BEGINFMTCHECKSUM) /* magic FMT file start 4C 20 E6 15 hex */
1626     goto lab6666;
1627
1628   undump_int(x); /* mem_bot */
1629
1630   if (x != mem_bot)
1631     goto lab6666;
1632
1633   undump_int(x); /* mem_top */
1634
1635 #ifdef ALLOCATEMAIN
1636 /* we already read this once earlier to grab mem_top */
1637   if (trace_flag)
1638   {
1639     sprintf(log_line, "Read from fmt file mem_top = %d TeX words\n", x);
1640     show_line(log_line, 0);
1641   }
1642
1643   mem = allocate_main_memory(x); /* allocate main memory at this point */
1644
1645   if (mem == NULL)
1646     exit(1);                     /* redundant sanity test ! */
1647
1648   initialize_aux();              /* do `mem' part of initialize */
1649 /*  mem = zmem; */               /* update pointer to main memory */
1650 #endif
1651
1652   if (x != mem_top)
1653     goto lab6666;
1654
1655   undump_int(x); /* eqtbsize */
1656
1657   if (x != (eqtb_size))
1658     goto lab6666;
1659
1660   undump_int(x); /* hash_prime */
1661
1662   if (x != hash_prime)
1663     goto lab6666;
1664
1665   undump_int(x); /* hyphen_prime */
1666
1667 #ifdef ALLOCATEHYPHEN
1668 /* allow format files dumped with arbitrary (prime) hyphenation exceptions */
1669   realloc_hyphen(x); /* reset_hyphen(); */
1670   hyphen_prime = x;
1671 #endif
1672
1673   if (x != hyphen_prime)
1674     goto lab6666;
1675
1676   {
1677     undump_int(x); /* pool_size */
1678
1679     if (x < 0)
1680       goto lab6666; 
1681
1682 #ifdef ALLOCATESTRING
1683     if (x > current_pool_size)
1684     {
1685       if (trace_flag)
1686       {
1687         sprintf(log_line, "undump string pool reallocation (%d > %d)\n", x, current_pool_size);
1688         show_line(log_line, 0);
1689       }
1690       str_pool = realloc_str_pool (x - current_pool_size + increment_pool_size);
1691     }
1692     if (x > current_pool_size)   /* 94/Jan/24 */
1693 #else
1694     if (x > pool_size)
1695 #endif
1696     {
1697       sprintf(log_line, "%s%s\n",  "---! Must increase the ", "string pool size");
1698       show_line(log_line, 0);
1699       goto lab6666;
1700     }
1701     else
1702       pool_ptr = x;
1703   }
1704   {
1705     undump_int(x);  /* max_strings */
1706     if (x < 0)
1707       goto lab6666;
1708
1709 #ifdef ALLOCATESTRING
1710     if (x > current_max_strings)
1711     {
1712       if (trace_flag)
1713       {
1714         sprintf(log_line, "undump string pointer reallocation (%d > %d)\n", x, current_max_strings);
1715         show_line(log_line, 0);
1716       }
1717       str_start = realloc_str_start(x - current_max_strings + increment_max_strings);
1718     }
1719     if (x > current_max_strings) /* 94/Jan/24 */
1720 #else
1721     if (x > max_strings)
1722 #endif
1723     {
1724       sprintf(log_line,  "%s%s\n",  "---! Must increase the ", "max strings");
1725       show_line(log_line, 0);
1726       goto lab6666;
1727     }
1728     else
1729       str_ptr = x;
1730   }
1731
1732   if (undumpthings(str_start[0], str_ptr + 1)) /* undump string ptrs */
1733     return -1;
1734   if (undumpthings(str_pool[0], pool_ptr)) /*  undump string pool */
1735     return -1;
1736
1737   init_str_ptr = str_ptr;
1738   init_pool_ptr = pool_ptr;
1739 /*  undump the dynamic memory - paragraph 1312 in the book */
1740   {
1741     undump_int(x);
1742     if ((x < lo_mem_stat_max + 1000) || (x > hi_mem_stat_min - 1))
1743       goto lab6666;
1744     else
1745       lo_mem_max = x;
1746   }
1747   {
1748     undump_int(x);
1749     if ((x < lo_mem_stat_max + 1) || (x > lo_mem_max))
1750       goto lab6666;
1751     else
1752       rover = x;
1753   }
1754   p = 0;                  /* mem_bot */
1755   q = rover;
1756
1757   do
1758   {
1759     if (undumpthings(mem[p], q + 2 - p))
1760       return -1;
1761
1762     p = q + node_size(q);
1763
1764     if ((p > lo_mem_max) || ((q >= rlink(q)) && (rlink(q) != rover)))
1765       goto lab6666;
1766
1767     q = rlink(q);
1768   } while (!(q == rover));
1769
1770   if (undumpthings(mem[p], lo_mem_max + 1 - p))
1771     return -1;
1772
1773   if (mem_min < mem_bot - 2)          /*  ? splice in block below */
1774   {
1775 /*  or call add_variable_space(mem_bot - (mem_min + 1)) */
1776     if (trace_flag)
1777       show_line("Splicing in mem_min space in undump!\n", 0);
1778
1779     p = llink(rover);
1780     q = mem_min + 1;
1781     link(mem_min) = 0;       /* null */
1782     info(mem_min) = 0;       /* null */
1783     rlink(p) = q;
1784     llink(rover) = q;
1785     rlink(q) = rover;
1786     llink(q) = p;
1787     link(q) = empty_flag;
1788     node_size(q) = mem_bot - q;     /* ? size of block  */
1789   }
1790   {
1791     undump_int(x);
1792     if ((x < lo_mem_max + 1) || (x > hi_mem_stat_min))
1793       goto lab6666;
1794     else
1795       hi_mem_min = x;
1796   }
1797   {
1798     undump_int(x);
1799
1800     if ((x < mem_bot) || (x > mem_top))
1801       goto lab6666;
1802     else
1803       avail = x;
1804   }
1805   mem_end = mem_top;
1806
1807   if (undumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min))
1808     return -1;
1809
1810   undump_int(var_used);
1811   undump_int(dyn_used);
1812
1813   k = active_base;
1814   do {
1815     undump_int(x);
1816     if ((x < 1) || (k + x > (eqtb_size + 1)))
1817       goto lab6666;
1818
1819     if (undumpthings(eqtb[k], x))
1820       return -1;
1821
1822     k = k + x;
1823     undump_int(x);
1824
1825     if ((x < 0) || (k + x > (eqtb_size + 1)))
1826       goto lab6666;
1827
1828     for (j = k; j <= k + x - 1; j++)
1829     {
1830       eqtb[j] = eqtb[k - 1];
1831     }
1832     k = k + x;
1833   } while(!(k > (eqtb_size)));
1834   {
1835     undump_int(x);
1836     if ((x < hash_base) || (x > (frozen_control_sequence)))  /*96/Jan/10*/
1837       goto lab6666;
1838     else
1839       par_loc = x;
1840   }
1841   par_token = 4095 + par_loc;
1842   {
1843     undump_int(x);
1844     if ((x < hash_base) || (x > (frozen_control_sequence))) /*96/Jan/10*/
1845       goto lab6666;
1846     else
1847       write_loc = x;
1848   }
1849   {
1850     undump_int(x);
1851     if ((x < hash_base) || (x > (frozen_control_sequence))) /*96/Jan/10*/
1852       goto lab6666;
1853     else
1854       hash_used = x;
1855   }
1856   p = hash_base - 1;
1857   do {
1858     {
1859       undump_int(x);
1860       if ((x < p + 1) || (x > hash_used))
1861         goto lab6666;
1862       else
1863         p = x;
1864     }
1865     undump_hh(hash[p]);
1866   } while (!(p == hash_used));
1867
1868   if (undumpthings(hash[hash_used + 1], (undefined_control_sequence - 1) - hash_used))
1869     return -1;
1870
1871   undump_int(cs_count);     /* cs_count */
1872   if (trace_flag)
1873   {
1874     sprintf(log_line, "itex undump cs_count %d ", cs_count); /* debugging */
1875     show_line(log_line, 0);
1876   }
1877   {
1878     undump_int(x);        /* font_mem_size */
1879     if (x < 7)
1880       goto lab6666;
1881 #ifdef ALLOCATEFONT
1882     if (trace_flag)
1883     {
1884       sprintf(log_line, "Read from fmt fmem_ptr = %d\n", x);
1885       show_line(log_line, 0);
1886     }
1887
1888     if (x > current_font_mem_size) /* 93/Nov/28 dynamic allocate font_info */
1889     {
1890       if (trace_flag)
1891       {
1892         sprintf(log_line, "Undump realloc font_info (%d > %d)\n", x, current_font_mem_size);
1893         show_line(log_line, 0);
1894       }
1895       font_info = realloc_font_info (x - current_font_mem_size + increment_font_mem_size);
1896     }
1897     if (x > current_font_mem_size)  /* in case allocation failed 94/Jan/24 */
1898 #else
1899     if (x > font_mem_size)
1900 #endif
1901     {
1902       sprintf(log_line, "%s%s\n",  "---! Must increase the ", "font mem size");
1903       show_line(log_line, 0);
1904       goto lab6666;
1905     }
1906     else
1907       fmem_ptr = x;
1908   }
1909   {
1910     if (undumpthings(font_info[0], fmem_ptr))
1911       return -1;
1912     {
1913       undump_int(x); /* font_max */
1914       if (x < 0)
1915         goto lab6666;
1916       if (x > font_max)
1917       {
1918         sprintf(log_line, "%s%s\n",  "---! Must increase the ", "font max"); 
1919         show_line(log_line, 0);
1920         goto lab6666;
1921       }
1922       else
1923         font_ptr = x;
1924     }
1925     frozen_font_ptr = font_ptr; /* remember number of fonts frozen into format */
1926     if (undumpthings(font_check[0], font_ptr + 1))
1927       return -1;
1928     if (undumpthings(font_size[0], font_ptr + 1))
1929       return -1;
1930     if (undumpthings(font_dsize[0], font_ptr + 1))
1931       return -1;
1932     if (undumpthings(font_params[0], font_ptr + 1))
1933       return -1;
1934     if (undumpthings(hyphen_char[0], font_ptr + 1))
1935       return -1;
1936     if (undumpthings(skew_char[0], font_ptr + 1))
1937       return -1;
1938     if (undumpthings(font_name[0], font_ptr + 1))
1939       return -1;
1940     if (undumpthings(font_area[0], font_ptr + 1))
1941       return -1;
1942     if (undumpthings(font_bc[0], font_ptr + 1))
1943       return -1;
1944     if (undumpthings(font_ec[0], font_ptr + 1))
1945       return -1;
1946     if (undumpthings(char_base[0], font_ptr + 1))
1947       return -1;
1948     if (undumpthings(width_base[0], font_ptr + 1))
1949       return -1;
1950     if (undumpthings(height_base[0], font_ptr + 1))
1951       return -1;
1952     if (undumpthings(depth_base[0], font_ptr + 1))
1953       return -1;
1954     if (undumpthings(italic_base[0], font_ptr + 1))
1955       return -1;
1956     if (undumpthings(lig_kern_base[0], font_ptr + 1))
1957       return -1;
1958     if (undumpthings(kern_base[0], font_ptr + 1))
1959       return -1;
1960     if (undumpthings(exten_base[0], font_ptr + 1))
1961       return -1;
1962     if (undumpthings(param_base[0], font_ptr + 1))
1963       return -1;
1964     if (undumpthings(font_glue[0], font_ptr + 1))
1965       return -1;
1966     if (undumpthings(bchar_label[0], font_ptr + 1))
1967       return -1;
1968     if (undumpthings(font_bchar[0], font_ptr + 1))
1969       return -1;
1970     if (undumpthings(font_false_bchar[0], font_ptr + 1))
1971       return -1;
1972   }
1973
1974 /* log not opened yet, so can't show fonts frozen into format */
1975 /* May be able to avoid the following since we switched to */
1976 /* non_address from font_mem_size to 0 96/Jan/15 ??? */
1977
1978 #ifdef ALLOCATEFONT
1979 /* deal with fmt files dumped with *different* font_mem_size 93/Nov/29 */
1980  {
1981    int count = 0, oldfont_mem_size = 0;
1982
1983    for (x = 0; x <= font_ptr; x++)
1984    {
1985      if (bchar_label[x] > oldfont_mem_size)
1986        oldfont_mem_size = bchar_label[x];
1987    }
1988
1989 /* somewhat arbitrary sanity check ... */
1990 /* if (oldfont_mem_size != font_mem_size && oldfont_mem_size > font_max) { */
1991    if (oldfont_mem_size != non_address && oldfont_mem_size > font_max) /* 96/Jan/16 */
1992    {
1993      for (x = 0; x <= font_ptr; x++)
1994      {
1995        if (bchar_label[x] == oldfont_mem_size)
1996        {
1997          /* bchar_label[x] = font_mem_size; */
1998          bchar_label[x] = non_address;  /* 96/Jan/16 */
1999          count++;
2000        }
2001      }
2002      if (trace_flag)
2003      {
2004        sprintf(log_line, "oldfont_mem_size is %d --- hit %d times. Using non_address %d\n",
2005            oldfont_mem_size, count, non_address);
2006        show_line(log_line, 0);
2007      }
2008    }
2009  }
2010 #endif
2011 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
2012 /* undump(0)(hyph_size)(hyph_count); */
2013   {
2014     undump_int(x);
2015
2016     if ((x < 0) || (x > hyphen_prime))
2017       goto lab6666;
2018     else
2019       hyph_count = x;
2020   }
2021 /* undump hypenation exception tables p.1325 */
2022   for (k = 1; k <= hyph_count; k++)
2023   {
2024     {
2025       undump_int(x);
2026       if ((x < 0) || (x > hyphen_prime))
2027         goto lab6666;
2028       else
2029         j = x;
2030     }
2031     {
2032       undump_int(x);
2033       if ((x < 0) || (x > str_ptr))
2034         goto lab6666;
2035       else
2036         hyph_word[j] = x;
2037     }
2038     {
2039       undump_int(x);
2040       if ((x < 0) || (x > max_halfword)) /* mem_top ? no p.1325 */
2041         goto lab6666;
2042       else
2043         hyph_list[j] = x;
2044     }
2045   }
2046
2047 #ifdef ALLOCATEHYPHEN
2048 /* if user specified new hyphen prime - flush existing exception patterns ! */
2049 /* but, we can reclaim the string storage wasted ... */
2050   if (is_initex)
2051   {
2052     if (new_hyphen_prime != 0)
2053     {
2054       realloc_hyphen(new_hyphen_prime); /* reset_hyphen(); */
2055       hyphen_prime = new_hyphen_prime;
2056     }
2057   }
2058 #endif
2059
2060   {
2061     undump_int(x);
2062     if (x < 0)
2063       goto lab6666;
2064
2065 #ifdef ALLOCATETRIES
2066     if (!is_initex)
2067     {
2068       allocate_tries(x); /* allocate only as much as is needed */
2069 /* trie_size = x; */ /* ??? */
2070     }
2071 #endif
2072
2073     if (x > trie_size)
2074     {
2075       sprintf(log_line, "%s%s\n",  "---! Must increase the ", "trie size");
2076       show_line(log_line, 0);
2077       goto lab6666;
2078     }
2079     else
2080       j = x;
2081   }
2082 #ifdef INITEX
2083   if (is_initex) /* bkph */
2084     trie_max = j;
2085 #endif /* INITEX */
2086   if (undumpthings(trie_trl[0], j + 1))
2087     return -1;
2088   if (undumpthings(trie_tro[0], j + 1))
2089     return -1;
2090   if (undumpthings(trie_trc[0], j + 1))
2091     return -1;
2092   {
2093     undump_int(x);
2094     if (x < 0)
2095       goto lab6666;
2096     if (x > trie_op_size)
2097     {
2098       sprintf(log_line, "%s%s\n",  "---! Must increase the ", "trie op size");
2099       show_line(log_line, 0);
2100       goto lab6666;
2101     }
2102     else
2103       j = x;
2104   }
2105
2106 #ifdef INITEX
2107   if (is_initex)   /* bkph */
2108     trie_op_ptr = j;
2109 #endif /* INITEX */
2110   
2111   if (undumpthings(hyf_distance[1], j))
2112     return -1;
2113   if (undumpthings(hyf_num[1], j))
2114     return -1;
2115   if (undumpthings(hyf_next[1], j))
2116     return -1;
2117
2118 #ifdef INITEX
2119   if (is_initex)    /* bkph */
2120   {
2121     for (k = 0; k <= 255; k++)
2122     {
2123         trie_used[k] = 0;
2124     }
2125   }
2126 #endif /* INITEX */
2127   k = 256;
2128   while (j > 0) {
2129     {
2130       undump_int(x);
2131       if ((x < 0) || (x > k - 1))
2132         goto lab6666;
2133       else
2134         k = x;
2135     }
2136     {
2137       undump_int(x);
2138       if ((x < 1) || (x > j))
2139         goto lab6666;
2140       else
2141         x = x;
2142     }
2143 #ifdef INITEX
2144     if (is_initex)          /* bkph */
2145       trie_used[k] = x;
2146 #endif /* INITEX */
2147 /*   j:=j-x; op_start[k]:=qo(j); */
2148     j = j - x;
2149     op_start[k] = j;
2150   }
2151 #ifdef INITEX
2152   if (is_initex)          /* bkph */
2153     trie_not_ready = false;
2154 #endif /* INITEX */
2155   {
2156     undump_int(x);
2157     if ((x < batch_mode) || (x > error_stop_mode))
2158       goto lab6666;
2159 /*    else interaction = x;  */
2160     if (interaction < batch_mode)    /* may now set in local.c bkph 94/Jan/8 */
2161       interaction = x;
2162   }
2163   {
2164     undump_int(x);
2165     if ((x < 0) || (x > str_ptr))
2166       goto lab6666;
2167     else
2168       format_ident = x;
2169   }
2170   undump_int(x);
2171   
2172   if ((x != ENDFMTCHECKSUM) || feof(fmt_file))
2173     goto lab6666;
2174
2175   return true;
2176
2177 lab6666:;
2178   sprintf(log_line, "(Fatal format file error; I'm stymied)\n");
2179   show_line(log_line, 1);
2180
2181   if (!knuth_flag)
2182     bad_formator_pool(format_file, "the format file", "TEXFORMATS");
2183
2184   return false;
2185 }
2186 /* sec 1335 */
2187 void final_cleanup (void)
2188 {
2189   small_number c;
2190
2191   c = cur_chr;
2192
2193   if (job_name == 0)
2194     open_log_file();
2195
2196   while (input_ptr > 0)
2197   {
2198     if (cur_input.state_field == 0)
2199     {
2200       end_token_list();
2201     }
2202     else
2203       end_file_reading();
2204   }
2205
2206   while (open_parens > 0)
2207   {
2208     print_string(" )");
2209     decr(open_parens);
2210   }
2211
2212   if (cur_level > level_one)
2213   {
2214     print_nl("(");
2215     print_esc("end occurred ");
2216     print_string("inside a group at level ");
2217     print_int(cur_level - 1);
2218     print_char(')');
2219   }
2220
2221   while (cond_ptr != 0)
2222   {
2223     print_nl("(");
2224     print_esc("end occurred ");
2225     print_string("when ");
2226     print_cmd_chr('i', cur_if);
2227
2228     if (if_line != 0)
2229     {
2230       print_string("on line ");
2231       print_int(if_line);
2232     }
2233
2234     print_string(" was incomplete)");
2235     if_line = mem[cond_ptr + 1].cint;
2236     cur_if = mem[cond_ptr].hh.b1;
2237     temp_ptr = cond_ptr;
2238     cond_ptr = mem[cond_ptr].hh.v.RH;
2239     free_node(temp_ptr, 2);
2240   }
2241
2242   if (history != spotless)
2243     if (((history == warning_issued) || (interaction < error_stop_mode)))
2244       if (selector == term_and_log)
2245       {
2246         selector = term_only;
2247         print_nl("(see the transcript file for additional information)");
2248         selector = term_and_log;
2249       }
2250
2251   if (c == 1)
2252   {
2253 #ifdef INITEX
2254     if (is_initex)
2255     {
2256       for (c = 0; c <= 4; c++)
2257       {
2258         if (cur_mark[c] != 0)
2259           delete_token_ref(cur_mark[c]);
2260       }
2261
2262       if (last_glue != max_halfword)
2263         delete_glue_ref(last_glue);
2264       store_fmt_file(); // returns a value ?
2265     }
2266 #endif
2267
2268     if (!is_initex)
2269       print_nl("(\\dump is performed only by INITEX)");
2270   }
2271 }
2272
2273 void show_frozen (void)
2274 {
2275   int i, j, n;
2276
2277   fprintf(log_file, "\n");
2278   fprintf(log_file, "(%d fonts frozen in format file:\n", font_ptr);
2279
2280   for (i = 1; i <= font_ptr; i++)
2281   {
2282     if (i > 1)
2283       fprintf(log_file, ", ");
2284
2285     if ((i % 8) == 0)
2286       fprintf(log_file, "\n");
2287
2288     n = str_start[font_name[i] + 1] - str_start[font_name[i]];
2289
2290     for (j = 0; j < n; j++)
2291     {
2292       putc(str_pool[str_start[font_name[i]] + j], log_file);
2293     }
2294   }
2295
2296   fprintf(log_file, ") ");
2297 }
2298
2299 int texbody (void)
2300 {
2301   history = fatal_error_stop;
2302
2303   if (ready_already == 314159L)
2304     goto lab1;
2305
2306   bad = 0;
2307
2308   if ((half_error_line < 30) || (half_error_line > error_line - 15))
2309     bad = 1;
2310
2311   if (max_print_line < 60)
2312     bad = 2;
2313
2314   if (dvi_buf_size % 8 != 0)
2315     bad = 3;
2316
2317   if (mem_bot + 1100 > mem_top)
2318     bad = 4;
2319
2320   if (hash_prime > (hash_size + hash_extra))
2321     bad = 5;
2322
2323   if (max_in_open >= 128)
2324     bad = 6;
2325
2326   if (mem_top < 256 + 11)
2327     bad = 7;
2328
2329 #ifdef INITEX
2330   if (is_initex)
2331   {
2332     if ((mem_min != 0) || (mem_max != mem_top))
2333       bad = 10;
2334   }
2335 #endif
2336
2337   if ((mem_min > mem_bot) || (mem_max < mem_top))
2338     bad = 10;
2339
2340   if ((min_quarterword > 0) || (max_quarterword < 255))
2341     bad = 11;
2342
2343   if ((min_halfword > 0) || (max_halfword < 32767))
2344     bad = 12;
2345
2346   if ((min_quarterword < min_halfword) || (max_quarterword > max_halfword))
2347     bad = 13;
2348
2349   if ((mem_min < min_halfword) || (mem_max >= max_halfword) || (mem_bot - mem_min >= max_halfword))
2350     bad = 14;
2351
2352   if (mem_max > mem_top + mem_extra_high)
2353     bad = 14;
2354
2355   if ((0 < min_quarterword) || (font_max > max_quarterword))
2356     bad = 15;
2357
2358 #ifdef INCREASEFONTS
2359   if (font_max > 1024)
2360 #else
2361   if (font_max > 256)
2362 #endif
2363     bad = 16;
2364
2365   if ((save_size > max_halfword) || (max_strings > max_halfword))
2366     bad = 17;
2367
2368   if (buf_size > max_halfword)
2369     bad = 18;
2370
2371   if (max_quarterword - min_quarterword < 255)
2372     bad = 19;
2373
2374   if (cs_token_flag + undefined_control_sequence > max_halfword)
2375     bad = 21;
2376
2377   if (format_default_length > PATHMAX)
2378     bad = 31;
2379
2380   if (max_halfword < (mem_top - mem_min) / 2)
2381     bad = 41;
2382
2383   if (bad > 0)
2384   {
2385     sprintf(log_line, "%s%s%ld\n", "Ouch---my internal constants have been clobbered!",
2386         "---case ", (long) bad);
2387     show_line(log_line, 1);
2388
2389     if (!knuth_flag)
2390       bad_formator_pool(format_file, "the format file", "TEXFORMATS");
2391
2392     goto lab9999;
2393   }
2394
2395   initialize();
2396
2397 #ifdef INITEX
2398   if (is_initex)
2399   {
2400     if (!get_strings_started())
2401       goto lab9999;
2402
2403     init_prim();
2404     init_str_ptr = str_ptr;
2405     init_pool_ptr = pool_ptr;
2406     fix_date_and_time();
2407   }
2408 #endif
2409
2410   ready_already = 314159L;
2411
2412 lab1:
2413   selector = term_only;
2414   tally = 0;
2415   term_offset = 0;
2416   file_offset = 0;
2417   show_line(tex_version, 0);
2418
2419   {
2420 #ifdef _WIN32
2421   #ifdef _WIN64
2422     sprintf(log_line, " (%s %s/Windows 64bit)", application, yandyversion);
2423   #else
2424     sprintf(log_line, " (%s %s/Windows 32bit)", application, yandyversion);
2425   #endif
2426 #else
2427     sprintf(log_line, " (%s %s/Linux)", application, yandyversion);
2428 #endif
2429   }
2430
2431   show_line(log_line, 0);
2432
2433   if (format_ident > 0)
2434     slow_print(format_ident);
2435
2436   print_ln();
2437
2438 #ifndef _WINDOWS
2439   fflush(stdout);
2440 #endif
2441
2442   job_name = 0;
2443   name_in_progress = false;
2444   log_opened = false;
2445   output_file_name = 0;
2446
2447   {
2448     {
2449       input_ptr = 0;
2450       max_in_stack = 0;
2451       in_open = 0;
2452       high_in_open = 0;
2453       open_parens = 0;
2454       max_open_parens = 0;
2455       max_buf_stack = 0;
2456       param_ptr = 0;
2457       max_param_stack = 0;
2458
2459 #ifdef ALLOCATEBUFFER
2460       memset (buffer, 0, current_buf_size);
2461 #else
2462       memset (buffer, 0, buf_size);
2463 #endif
2464
2465       first = 0;
2466       scanner_status = 0;
2467       warning_index = 0;
2468       first = 1;
2469       cur_input.state_field = 33;
2470       cur_input.start_field = 1;
2471       cur_input.index_field = 0;
2472       line = 0;
2473       cur_input.name_field = 0;
2474       force_eof = false;
2475       align_state = 1000000L;
2476
2477       if (!init_terminal())
2478         goto lab9999;
2479
2480       cur_input.limit_field = last;
2481       first = last + 1;
2482     }
2483     
2484     if ((format_ident == 0) ||
2485         (buffer[cur_input.loc_field] == '&') ||
2486         (buffer[cur_input.loc_field] == '+'))
2487     {
2488       if (format_ident != 0)
2489         initialize();
2490
2491       if (!open_fmt_file ())
2492         goto lab9999;
2493
2494       if (!load_fmt_file ())
2495       {
2496 #ifdef COMPACTFORMAT
2497         gzclose(gz_fmt_file);
2498 #else
2499         w_close(fmt_file);
2500 #endif
2501         goto lab9999;
2502       }
2503
2504 #ifdef COMPACTFORMAT
2505       gzclose(gz_fmt_file);
2506 #else
2507       w_close(fmt_file);
2508 #endif
2509
2510       while ((cur_input.loc_field < cur_input.limit_field) &&
2511           (buffer[cur_input.loc_field] == ' '))
2512         incr(cur_input.loc_field);
2513     }
2514
2515     if ((end_line_char < 0) || (end_line_char > 255))
2516       decr(cur_input.limit_field);
2517     else
2518       buffer[cur_input.limit_field] = end_line_char;
2519
2520     fix_date_and_time();
2521     magic_offset = str_start[886] - 9 * ord_noad;
2522
2523     if (interaction == batch_mode)
2524       selector = no_print;
2525     else
2526       selector = term_only;
2527
2528     if ((cur_input.loc_field < cur_input.limit_field) &&
2529       (cat_code(buffer[cur_input.loc_field]) != escape))
2530       start_input();
2531   }
2532
2533   if (show_tfm_flag && log_opened && font_ptr > 0)
2534     show_frozen();
2535
2536   main_time = clock();
2537   history = 0;
2538
2539   if (show_cs_names)
2540     print_cs_names(stdout, 0);
2541
2542   main_control();
2543
2544   if (show_cs_names)
2545     print_cs_names(stdout, 1);
2546
2547   final_cleanup();
2548
2549   close_files_and_terminate();
2550
2551 lab9999:
2552   {
2553     int code;
2554
2555 #ifndef _WINDOWS
2556     fflush(stdout);
2557 #endif
2558
2559     ready_already = 0;
2560
2561     if ((history != 0) && (history != 1))
2562       code = 1;
2563     else
2564       code = 0;
2565
2566     return code;
2567   }
2568 }
2569
2570 #ifdef ALLOCATEMAIN
2571 /* add a block of variable size node space below mem_bot */
2572 void add_variable_space(int size)
2573 {
2574   halfword p;
2575   halfword q;
2576   integer t;
2577
2578   if (mem_min == 0)
2579     t = mem_min;
2580   else
2581     t = mem_min + 1;
2582
2583   mem_min = t - (size + 1);     /* first word in new block - 1 */
2584
2585   if (mem_min < mem_start)      /* sanity test */
2586   {
2587     if (trace_flag)
2588       show_line("WARNING: mem_min < mem_start!\n", 0);
2589
2590     mem_min = mem_start;
2591   }
2592
2593   p = llink(rover);
2594   q = mem_min + 1;
2595   link(mem_min) = 0; /* insert blank word below ??? */
2596   info(mem_min) = 0; /* insert blank word below ??? */
2597   rlink(p) = q;
2598   llink(rover) = q;
2599   rlink(q) = rover;
2600   llink(q) = p;
2601   link(q) = empty_flag;
2602   info(q) = t - q; /* block size */
2603   rover = q;
2604 }
2605 #endif
2606
2607 /**************************************************************************/
2608
2609 #ifdef INITEX
2610 /* split out to allow sharing of code from do_initex and newpattern */
2611 void reset_trie (void)
2612 {
2613   integer k;
2614
2615   for (k = - (integer) trie_op_size; k <= trie_op_size; k++)
2616     trie_op_hash[k] = 0;
2617
2618   for (k = 0; k <= 255; k++)
2619     trie_used[k] = min_trie_op;
2620
2621   max_op_used = min_trie_op;
2622   trie_op_ptr = 0;
2623   trie_not_ready = true;
2624   trie_l[0] = 0;
2625   trie_c[0] = 0;
2626   trie_ptr = 0;
2627   trie_not_ready = true;
2628 }
2629 /* borrowed code from initialize() */
2630 void reset_hyphen (void)
2631 {
2632   hyph_pointer z;
2633
2634   for (z = 0; z <= hyphen_prime; z++)
2635   {
2636     hyph_word[z] = 0;
2637     hyph_list[z] = 0;
2638   }
2639
2640   hyph_count = 0;
2641 }
2642 /* split out to allow optimize for space, not time */
2643 void do_initex (void)
2644 {
2645 /*  integer i; */
2646   integer k;
2647 /*  hyph_pointer z; */
2648
2649   for (k = mem_bot + 1; k <= lo_mem_stat_max; k++)
2650     mem[k].cint = 0;
2651
2652   k = mem_bot;
2653
2654   while (k <= lo_mem_stat_max)
2655   {
2656     glue_ref_count(k) = 1;
2657     stretch_order(k) = normal;
2658     shrink_order(k) = normal;
2659     k = k + glue_spec_size;
2660   }
2661
2662   stretch(fil_glue) = 65535L;
2663   stretch_order(fil_glue) = fil;
2664   stretch(fill_glue) = 65535L;
2665   stretch_order(fill_glue) = fill;
2666   stretch(ss_glue) = 65535L;
2667   stretch_order(ss_glue) = fil;
2668   shrink(ss_glue) = 65535L;
2669   shrink_order(ss_glue) = fil;
2670   stretch(fil_neg_glue) = -65536L;
2671   stretch_order(fil_neg_glue) = fil;
2672   rover = lo_mem_stat_max + 1;
2673   link(rover) = empty_flag;
2674   node_size(rover) = block_size;
2675   llink(rover) = rover;
2676   rlink(rover) = rover;
2677   lo_mem_max = rover + block_size;
2678   link(lo_mem_max) = 0;
2679   info(lo_mem_max) = 0;
2680
2681   for (k = hi_mem_stat_min; k <= mem_top; k++)
2682     mem[k] = mem[lo_mem_max];
2683
2684   info(omit_template) = end_template_token;
2685   link(end_span) = max_quarterword + 1;
2686   info(end_span) = 0;
2687   type(last_active) = hyphenated;
2688   line_number(last_active) = max_halfword;
2689   subtype(last_active) = 0;
2690   subtype(page_ins_head) = 255;
2691   type(page_ins_head) = split_up;
2692   link(mem_top) = page_ins_head;
2693   type(page_head) = glue_node;
2694   subtype(page_head) = normal;
2695   avail = 0;                   /* avail <- null p.164 */
2696   mem_end = mem_top;
2697   hi_mem_min = hi_mem_stat_min;
2698   var_used = lo_mem_stat_max + 1 - mem_bot;
2699   dyn_used = hi_mem_stat_usage;
2700   eq_type(undefined_control_sequence) = undefined_cs;
2701   equiv(undefined_control_sequence) = 0;
2702   eq_level(undefined_control_sequence) = level_zero;
2703
2704   for (k = active_base; k <= undefined_control_sequence - 1; k++)
2705     eqtb[k] = eqtb[undefined_control_sequence];
2706
2707   equiv(glue_base) = zero_glue;
2708   eq_level(glue_base) = level_one;
2709   eq_type(glue_base) = glue_ref;
2710
2711   for (k = glue_base + 1; k <= local_base - 1; k++)
2712     eqtb[k] = eqtb[glue_base];
2713
2714   glue_ref_count(zero_glue) = glue_ref_count(zero_glue) + local_base - glue_base;
2715
2716   par_shape_ptr = 0;
2717   eq_type(par_shape_loc) = shape_ref;
2718   eq_level(par_shape_loc) = level_one;
2719
2720   for (k = output_routine_loc; k <= toks_base + 255; k++)
2721     eqtb[k] = eqtb[undefined_control_sequence];
2722
2723   box(0) = 0;
2724   eq_type(box_base) = box_ref;
2725   eq_level(box_base) = level_one;
2726
2727   for (k = box_base + 1; k <= box_base + 255; k++)
2728     eqtb[k] = eqtb[box_base];
2729
2730   cur_font = null_font;
2731   eq_type(cur_font_loc) = data;
2732   eq_level(cur_font_loc) = level_one;
2733
2734   for (k = math_font_base; k <= math_font_base + 47; k++)
2735     eqtb[k] = eqtb[cur_font_loc];
2736
2737   equiv(cat_code_base) = 0;
2738   eq_type(cat_code_base) = data;
2739   eq_level(cat_code_base) = level_one;
2740
2741   for (k = cat_code_base; k <= int_base - 1; k++)
2742     eqtb[k] = eqtb[cat_code_base];
2743
2744   for (k = 0; k <= 255; k++)
2745   {
2746     cat_code(k) = other_char;
2747     math_code(k) = k;
2748     sf_code(k) = 1000;
2749   }
2750
2751   cat_code(carriage_return) = car_ret;
2752   cat_code(' ') = spacer;
2753   cat_code('\\') = escape;
2754   cat_code('%') = comment;
2755   cat_code(invalid_code) = invalid_char;
2756   cat_code(null_code) = ignore;
2757
2758   for (k = '0'; k <= '9'; k++)
2759     math_code(k) = k + var_code;
2760
2761   for (k = 'A'; k <= 'Z'; k++)
2762   {
2763     cat_code(k) = letter;
2764     cat_code(k + 'a' - 'A') = letter;
2765     math_code(k) = k + var_code + 0x100;
2766     math_code(k + 'a' - 'A') = k + 'a' - 'A' + var_code + 0x100;
2767     lc_code(k) = k + 'a' - 'A';
2768     lc_code(k + 'a' - 'A') = k + 'a' - 'A';
2769     uc_code(k) = k;
2770     uc_code(k + 'a' - 'A') = k;
2771     sf_code(k) = 999;
2772   }
2773
2774   for (k = int_base; k <= del_code_base - 1; k++)
2775     eqtb[k].cint = 0;
2776
2777   mag = 1000;
2778   tolerance = 10000;
2779   hang_after = 1;
2780   max_dead_cycles = 25;
2781   escape_char = '\\';
2782   end_line_char = carriage_return;
2783
2784   for (k = 0; k <= 255; k++)
2785     del_code(k) = -1;
2786
2787   del_code('.') = 0;
2788
2789   for (k = dimen_base; k <= eqtb_size; k++)
2790     eqtb[k].cint = 0;
2791
2792   hash_used = frozen_control_sequence;
2793   cs_count = 0;
2794
2795   if (trace_flag)
2796     show_line("initex cs_count = 0 ", 0);
2797
2798   eq_type(frozen_dont_expand) = dont_expand;
2799   text(frozen_dont_expand) = 499;  /* notexpanded */
2800
2801   font_ptr                    = null_font;
2802   fmem_ptr                    = 7;
2803   font_name[null_font]        = 795; /* nullfont */
2804   font_area[null_font]        = 335; /* "" */
2805   hyphen_char[null_font]      = '-';
2806   skew_char[null_font]        = -1; 
2807   bchar_label[null_font]      = non_address;
2808   font_bchar[null_font]       = non_char;
2809   font_false_bchar[null_font] = non_char;
2810   font_bc[null_font]          = 1;
2811   font_ec[null_font]          = 0;
2812   font_size[null_font]        = 0;
2813   font_dsize[null_font]       = 0;
2814   char_base[null_font]        = 0;
2815   width_base[null_font]       = 0;
2816   height_base[null_font]      = 0;
2817   depth_base[null_font]       = 0;
2818   italic_base[null_font]      = 0;
2819   lig_kern_base[null_font]    = 0;
2820   kern_base[null_font]        = 0;
2821   exten_base[null_font]       = 0;
2822   font_glue[null_font]        = 0;
2823   font_params[null_font]      = 7;
2824   param_base[null_font]       = -1;
2825   reset_trie();
2826   text(frozen_protection) = 1184; /* "inaccessible" */
2827   format_ident = 1251;
2828   text(end_write) = 1290;
2829   eq_level(end_write) = level_one;
2830   eq_type(end_write) = outer_call;
2831   equiv(end_write) = 0;
2832 }
2833 #endif
2834
2835 #ifdef INITEX
2836 /* sec 0047 */
2837 bool get_strings_started (void)
2838 {
2839   integer k;
2840   str_number g;
2841
2842   pool_ptr = 0;
2843   str_ptr = 0;
2844   str_start[0] = 0;
2845
2846   for (k = 0; k <= 255; k++)
2847   {
2848     if (((k < ' ') || (k > '~')))
2849     {
2850       append_char('^');
2851       append_char('^');
2852
2853       if (k < 64)
2854         append_char(k + 64);
2855       else
2856         if (k < 128)
2857           append_char(k - 64);
2858         else
2859         {
2860           append_lc_hex(k / 16);
2861           append_lc_hex(k % 16);
2862         }
2863     }
2864     else
2865       append_char(k);
2866
2867     g = make_string();
2868   }
2869
2870   g = load_pool_strings(pool_size - string_vacancies);
2871
2872   if (g == 0)
2873   {
2874     fprintf(stdout , "%s\n",  "! You have to increase POOLSIZE." );
2875     return false;
2876   }
2877
2878   return true;
2879 }
2880 #endif /* INITEX */
2881
2882 #ifdef INITEX
2883 /* sec 0131 */
2884 void sort_avail (void)
2885 {
2886   halfword p, q, r;
2887   halfword old_rover;
2888
2889   p = get_node(1073741824L); /* 2^30 merge adjacent free nodes */
2890   p = rlink(rover);
2891   rlink(rover) = empty_flag;
2892   old_rover = rover;
2893
2894   while (p != old_rover)
2895   {
2896     if (p < rover)
2897     {
2898       q = p;
2899       p = rlink(q);
2900       rlink(q) = rover;
2901       rover = q;
2902     }
2903     else
2904     {
2905       q = rover;
2906
2907       while (rlink(q) < p)
2908         q = rlink(q);
2909
2910       r = rlink(p);
2911       rlink(p) = rlink(q);
2912       rlink(q) = p;
2913       p = r;
2914     }
2915   }
2916
2917   p = rover;
2918
2919   while (rlink(p) != empty_flag)
2920   {
2921     llink(rlink(p)) = p;
2922     p = rlink(p);
2923   }
2924
2925   rlink(p) = rover;
2926   llink(rover) = p;
2927 }
2928 #endif /* INITEX */
2929
2930 #ifdef INITEX
2931 str_number make_string_pool (char *s)
2932 {
2933   int slen = strlen(s);
2934
2935   if (slen == 1)
2936   {
2937     return ((str_number)s[0]);
2938   }
2939   else
2940   {
2941     memcpy(str_pool + pool_ptr, s, slen);
2942     pool_ptr += slen;
2943     return (make_string());
2944   }
2945 }
2946 /* sec 0264 */
2947 void primitive_ (str_number s, quarterword c, halfword o)
2948
2949   pool_pointer k;
2950   small_number j;
2951 /*  small_number l;  */
2952   int l; /* 95/Jan/7 */
2953
2954   if (s < 256)
2955     cur_val = s + single_base;
2956   else
2957   {
2958     k = str_start[s];
2959     l = str_start[s + 1] - k; /* small_number l */
2960
2961     for (j = 0; j <= l - 1; j++)
2962       buffer[j] = str_pool[k + j];
2963
2964     cur_val = id_lookup(0, l);
2965     flush_string();
2966
2967 #ifdef SHORTHASH
2968     if (s > 65535L)
2969       show_line("ERROR: hash entry too large\n", 1);
2970 #endif
2971
2972     text(cur_val) = s;
2973   }
2974
2975   eq_level(cur_val) = level_one;
2976   eq_type(cur_val) = c;
2977   equiv(cur_val) = o;
2978 }
2979 #endif
2980
2981 #ifdef INITEX
2982 /* sec 0944 */
2983 trie_op_code new_trie_op_ (small_number d, small_number n, trie_op_code v)
2984 {
2985   integer h;
2986   trie_op_code u;
2987   integer l;
2988
2989   h = abs(n + 313 * d + 361 * v + 1009 * cur_lang) % (trie_op_size + trie_op_size) + neg_trie_op_size;
2990
2991   while (true)
2992   {
2993     l = trie_op_hash[h];
2994
2995     if (l == 0)
2996     {
2997       if (trie_op_ptr == trie_op_size)
2998       {
2999         overflow("pattern memory ops", trie_op_size);
3000         return 0;     // abort_flag set
3001       }
3002
3003       u = trie_used[cur_lang];
3004
3005       if (u == max_trie_op)
3006       {
3007         overflow("pattern memory ops per language", max_trie_op - min_trie_op);
3008         return 0;     // abort_flag set
3009       }
3010
3011       incr(trie_op_ptr);
3012       incr(u);
3013       trie_used[cur_lang] = u;
3014
3015       if (u > max_op_used)
3016         max_op_used = u;
3017
3018       hyf_distance[trie_op_ptr] = d;
3019       hyf_num[trie_op_ptr] = n;
3020       hyf_next[trie_op_ptr] = v;
3021       trie_op_lang[trie_op_ptr] = cur_lang;
3022       trie_op_hash[h] = trie_op_ptr;
3023       trie_op_val[trie_op_ptr] = u;
3024       return u;
3025     }
3026
3027     if ((hyf_distance[l]== d) && (hyf_num[l]== n) && (hyf_next[l]== v) && (trie_op_lang[l]== cur_lang))
3028     {
3029       return trie_op_val[l];
3030     }
3031
3032     if (h > - (integer) trie_op_size)
3033       decr(h);
3034     else
3035       h = trie_op_size;
3036   }
3037 }
3038 /* sec 0948 */
3039 trie_pointer trie_node_ (trie_pointer p)
3040 {
3041   trie_pointer h;
3042   trie_pointer q;
3043
3044   /* the 1009, 2718, 3142 are hard-wired constants here (not hyphen_prime) */
3045   /* compute hash value */
3046   h = abs(trie_c[p] + 1009 * trie_o[p] + 2718 * trie_l[p] + 3142 * trie_r[p]) % trie_size;
3047
3048   while (true)
3049   {
3050     q = trie_hash[h];
3051
3052     if (q == 0)
3053     {
3054       trie_hash[h] = p;
3055       return p;
3056     }
3057
3058     if ((trie_c[q] == trie_c[p]) && (trie_o[q] == trie_o[p]) &&
3059       (trie_l[q] == trie_l[p]) && (trie_r[q] == trie_r[p]))
3060     {
3061       return q;
3062     }
3063
3064     if (h > 0)
3065       decr(h);
3066     else
3067       h = trie_size;
3068   }
3069 }
3070 /* sec 0949 */
3071 trie_pointer compress_trie_ (trie_pointer p)
3072 {
3073   if (p == 0)
3074     return 0;
3075   else
3076   {
3077     trie_l[p] = compress_trie(trie_l[p]);
3078     trie_r[p] = compress_trie(trie_r[p]);
3079     return trie_node(p);
3080   }
3081 }
3082 /* sec 0953 */
3083 void first_fit_ (trie_pointer p)
3084 {
3085   trie_pointer h;
3086   trie_pointer z;
3087   trie_pointer q;
3088   ASCII_code c;
3089   trie_pointer l, r;
3090   short ll;
3091
3092   c = trie_c[p];
3093   z = trie_min[c];
3094
3095   while (true)
3096   {
3097     h = z - c;
3098
3099     if (trie_max < h + 256)
3100     {
3101       if (trie_size <= h + 256)
3102       {
3103         overflow("pattern memory", trie_size);
3104 /*      not dynamic ---- but can be set -h=... from command line in ini-TeX */
3105         return;     // abort_flag set
3106       }
3107
3108       do
3109         {
3110           incr(trie_max);
3111           trie_taken[trie_max] = false;
3112           trie_trl[trie_max] = trie_max + 1;
3113           trie_tro[trie_max] = trie_max - 1;
3114         }
3115       while (!(trie_max == h + 256));
3116     }
3117
3118     if (trie_taken[h])
3119       goto lab45;
3120
3121     q = trie_r[p];
3122
3123     while (q > 0)
3124     {
3125       if (trie_trl[h + trie_c[q]] == 0)
3126         goto lab45;
3127
3128       q = trie_r[q];
3129     }
3130
3131     goto lab40;
3132 lab45:
3133     z = trie_trl[z];
3134   }
3135 lab40:
3136   trie_taken[h] = true; /* h may be used without ... */
3137   trie_hash[p] = h;
3138   q = p;
3139
3140   do {
3141     z = h + trie_c[q];
3142     l = trie_tro[z];
3143     r = trie_trl[z];
3144     trie_tro[r] = l;
3145     trie_trl[l] = r;
3146     trie_trl[z] = 0;
3147
3148     if (l < 256)
3149     {
3150       if (z < 256)
3151         ll = z;         /* short ll */
3152       else
3153         ll = 256;
3154
3155       do {
3156         trie_min[l] = r;
3157         incr(l);
3158       } while (!(l == ll));
3159     }
3160     q = trie_r[q];
3161   } while (!(q == 0));
3162 }
3163 /* sec 0957 */
3164 void trie_pack_ (trie_pointer p)
3165 {
3166   trie_pointer q;
3167
3168   do
3169     {
3170       q = trie_l[p];
3171
3172       if ((q > 0) && (trie_hash[q]== 0))
3173       {
3174         first_fit(q);
3175         trie_pack(q);
3176       }
3177
3178       p = trie_r[p];
3179     }
3180   while(!(p == 0));
3181 }
3182 /* sec 0959 */
3183 void trie_fix_ (trie_pointer p)
3184 {
3185   trie_pointer q;
3186   ASCII_code c;
3187   trie_pointer z;
3188
3189   z = trie_hash[p];
3190
3191   do
3192     {
3193       q = trie_l[p];
3194       c = trie_c[p];
3195       trie_trl[z + c] = trie_hash[q];
3196       trie_trc[z + c] = c;
3197       trie_tro[z + c] = trie_o[p];
3198
3199       if (q > 0)
3200         trie_fix(q);
3201
3202       p = trie_r[p];
3203     }
3204   while(!(p == 0));
3205 }
3206 /* sec 0960 */
3207 void new_patterns (void)
3208 {
3209 /* ******************************************************************* */
3210 /*  was small_number k, l;  in 3.141 */
3211   char k, l;
3212 /* ******************************************************************* */
3213   bool digitsensed;
3214   trie_op_code v;
3215   trie_pointer p, q;
3216   bool firstchild;
3217 /*  ASCII_code c;  */
3218   int c;                /* 95/Jan/7 */
3219
3220   if (!trie_not_ready) /* new stuff */
3221   {
3222     if (allow_patterns)
3223     {
3224       if (trace_flag)
3225         show_line("Resetting patterns\n", 0);
3226
3227       reset_trie();         /* RESET PATTERNS -  93/Nov/26 */
3228
3229       if (reset_exceptions)
3230       {
3231         if (trace_flag)
3232           show_line("Resetting exceptions\n", 0);
3233
3234         reset_hyphen();     /* RESET HYPHENEXCEPTIONS -  93/Nov/26 */
3235       }
3236     }
3237   }
3238 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
3239   if (trie_not_ready)
3240   {
3241     set_cur_lang();
3242     scan_left_brace();
3243     k = 0;
3244     hyf[0] = 0;
3245     digitsensed = false;
3246
3247     while (true)
3248     {
3249       get_x_token();
3250
3251       switch (cur_cmd)
3252       {
3253         case letter:
3254         case other_char:
3255           if (digitsensed || (cur_chr < '0') || (cur_chr > '9'))
3256           {
3257             if (cur_chr == '.')
3258               cur_chr = 0;
3259             else
3260             {
3261               cur_chr = lc_code(cur_chr);
3262
3263               if (cur_chr == 0)
3264               {
3265                 print_err("Nonletter");
3266                 help1("(See Appendix H.)");
3267                 error();
3268               }
3269             }
3270
3271             if (k < 63)
3272             {
3273               incr(k);
3274               hc[k] = cur_chr;
3275               hyf[k] = 0;
3276               digitsensed = false;
3277             }
3278           }
3279           else if (k < 63)
3280           {
3281             hyf[k] = cur_chr - '0';
3282             digitsensed = true;
3283           }
3284           break;
3285         case spacer:
3286         case right_brace:
3287           {
3288             if (k > 0)
3289             {
3290               if (hc[1] == 0)
3291                 hyf[0] = 0;
3292
3293               if (hc[k] == 0)
3294                 hyf[k] = 0;
3295
3296               l = k;
3297               v = min_trie_op;
3298
3299               while (true) {
3300                 if (hyf[l]!= 0)
3301                   v = new_trie_op(k - l, hyf[l], v);
3302
3303                 if (l > 0)
3304                   decr(l);
3305                 else
3306                   goto lab31;
3307               }
3308 lab31:
3309               q = 0;
3310               hc[0] = cur_lang;
3311
3312               while (l <= k) {
3313                 c = hc[l];
3314                 incr(l);
3315                 p = trie_l[q];
3316                 firstchild = true;
3317
3318                 while ((p > 0) && (c > trie_c[p])) {
3319                   q = p;
3320                   p = trie_r[q];
3321                   firstchild = false;
3322                 }
3323
3324                 if ((p == 0) || (c < trie_c[p]))
3325                 {
3326                   if (trie_ptr == trie_size)
3327                   {
3328                     overflow("pattern memory", trie_size);  /* pattern memory - NOT DYNAMIC */
3329 /*      not dynamic ---- but can be set -h=... from command line in ini-TeX */
3330                     return;     // abort_flag set
3331                   }
3332
3333                   incr(trie_ptr);
3334                   trie_r[trie_ptr] = p;
3335                   p = trie_ptr;
3336                   trie_l[p] = 0;
3337
3338                   if (firstchild)
3339                     trie_l[q]= p;
3340                   else
3341                     trie_r[q]= p;
3342
3343                   trie_c[p] = c;
3344                   trie_o[p] = min_trie_op;
3345                 }
3346                 q = p;
3347               }
3348
3349               if (trie_o[q]!= min_trie_op)
3350               {
3351                 print_err("Duplicate pattern");
3352                 help1("(See Appendix H.)");
3353                 error();
3354               }
3355
3356               trie_o[q]= v;
3357             }
3358
3359             if (cur_cmd == right_brace)
3360               goto lab30;
3361
3362             k = 0;
3363             hyf[0] = 0;
3364             digitsensed = false;
3365           }
3366           break;
3367         default:
3368           {
3369             print_err("Bad ");
3370             print_esc("patterns");
3371             help1("(See Appendix H.)");
3372             error();
3373           }
3374           break;
3375       }
3376     }
3377 lab30:;
3378   }
3379   else
3380   {
3381     print_err("Too late for ");
3382     print_esc("patterns");
3383     help1("All patterns must be given before typesetting begins.");
3384     error();
3385     link(garbage) = scan_toks(false, false);
3386     flush_list(def_ref);
3387   }
3388 }
3389 /* sec 0966 */
3390 void init_trie (void)
3391 {
3392   trie_pointer p;
3393 /*  integer j, k, t;  */
3394   integer j, k;
3395   int t;                  /* 95/Jan/7 */
3396   trie_pointer r, s;
3397
3398   op_start[0] = - (integer) min_trie_op;
3399
3400   for (j = 1; j <= 255; j++)
3401   {
3402     op_start[j] = op_start[j - 1] + trie_used[j - 1];
3403   }
3404
3405   for (j = 1; j <= trie_op_ptr; j++)
3406   {
3407     trie_op_hash[j] = op_start[trie_op_lang[j]] + trie_op_val[j];
3408   }
3409
3410   for (j = 1; j <= trie_op_ptr; j++)
3411   {
3412     while (trie_op_hash[j] > j)
3413     {
3414       k = trie_op_hash[j];
3415       t = hyf_distance[k];
3416       hyf_distance[k] = hyf_distance[j];
3417       hyf_distance[j] = t;
3418       t = hyf_num[k];
3419       hyf_num[k] = hyf_num[j];
3420       hyf_num[j] = t;
3421       t = hyf_next[k];
3422       hyf_next[k] = hyf_next[j];
3423       hyf_next[j]= t;
3424       trie_op_hash[j] = trie_op_hash[k];
3425       trie_op_hash[k] = k;
3426     }
3427   }
3428
3429   for (p = 0; p <= trie_size; p++)
3430   {
3431     trie_hash[p] = 0;
3432   }
3433
3434   trie_l[0] = compress_trie(trie_l[0]);
3435
3436   for (p = 0; p <= trie_ptr; p++)
3437   {
3438     trie_hash[p]= 0;
3439   }
3440
3441   for (p = 0; p <= 255; p++)
3442   {
3443     trie_min[p] = p + 1;
3444   }
3445
3446   trie_trl[0] = 1;
3447   trie_max = 0;
3448
3449   if (trie_l[0] != 0)
3450   {
3451     first_fit(trie_l[0]);
3452     trie_pack(trie_l[0]);
3453   }
3454
3455   if (trie_l[0] == 0)
3456   {
3457     for (r = 0; r <= 256; r++)
3458     {
3459       trie_trl[r] = 0;
3460       trie_tro[r] = min_trie_op;
3461       trie_trc[r] = 0;
3462     }
3463     trie_max = 256;
3464   }
3465   else
3466   {
3467     trie_fix(trie_l[0]);
3468     r = 0;
3469
3470     do
3471       {
3472         s = trie_trl[r];
3473         {
3474           trie_trl[r] = 0;
3475           trie_tro[r] = min_trie_op;
3476           trie_trc[r] = 0;
3477         }
3478
3479         r = s;
3480       }
3481     while(!(r > trie_max));
3482   }
3483   trie_trc[0] = 63;
3484   trie_not_ready = false;
3485 }
3486 #endif /* INITEX */
3487
3488 #ifdef INITEX
3489 /* sec 1302 */
3490 void store_fmt_file (void)
3491 {
3492   integer j, k, l;
3493   halfword p, q;
3494   integer x;
3495
3496   if (!is_initex)   /* redundant check 94/Feb/14 */
3497   {
3498     show_line("! \\dump is performed only by INITEX\n", 1);
3499
3500     if (! knuth_flag)
3501       show_line("  (Use -i on the command line)\n", 0);
3502
3503     abort_flag++;
3504     return;
3505   }
3506
3507   if (save_ptr != 0)
3508   {
3509     print_err("You can't dump inside a group");
3510     help1("`{...\\dump}' is a no-no.");
3511     succumb();
3512   }
3513
3514   selector = new_string;
3515   print_string(" (format=");
3516   print(job_name);
3517   print_char(' ');
3518   print_int(year);
3519   print_char('.');
3520   print_int(month);
3521   print_char('.');
3522   print_int(day);
3523   print_char(')');
3524
3525   if (interaction == 0)
3526     selector = log_only;
3527   else
3528     selector = term_and_log;
3529
3530   str_room(1);
3531   format_ident = make_string();
3532   pack_job_name(".fmt");
3533
3534   while(!w_open_out(fmt_file))
3535   {
3536     prompt_file_name("format file name", ".fmt");
3537   }
3538
3539   print_nl("Beginning to dump on file ");
3540   slow_print(w_make_name_string(fmt_file));
3541   flush_string();
3542   print_nl("");
3543   slow_print(format_ident);
3544
3545   dump_int(BEGINFMTCHECKSUM); /* magic FMT file start 4C 20 E6 15 hex */
3546
3547   dump_int(mem_bot);
3548   dump_int(mem_top);
3549   dump_int(eqtb_size);
3550   dump_int(hash_prime);
3551   dump_int(hyphen_prime);   /* bkph */
3552
3553   dump_int(pool_ptr);
3554   dump_int(str_ptr);
3555
3556   if (dumpthings(str_start[0], str_ptr + 1))
3557     return;
3558
3559   if (dumpthings(str_pool[0], pool_ptr))
3560     return;
3561
3562   print_ln();
3563   print_int(str_ptr);
3564   print_string(" strings of total length ");
3565   print_int(pool_ptr);
3566
3567   sort_avail();
3568   var_used = 0;
3569   dump_int(lo_mem_max);
3570   dump_int(rover);
3571   p = 0;
3572   q = rover;
3573   x = 0;
3574
3575   do
3576     {
3577       if (dumpthings(mem[p], q + 2 - p))
3578         return;
3579
3580       x = x + q + 2 - p;
3581       var_used = var_used + q - p;
3582       p = q + mem[q].hh.v.LH;
3583       q = mem[q + 1].hh.v.RH;
3584     }
3585   while (!(q == rover));
3586
3587   var_used = var_used + lo_mem_max - p;
3588   dyn_used = mem_end + 1 - hi_mem_min;
3589
3590   if (dumpthings(mem[p], lo_mem_max + 1 - p))
3591     return;
3592
3593   x = x + lo_mem_max + 1 - p;
3594   dump_int(hi_mem_min);
3595   dump_int(avail);
3596
3597   if (dumpthings(mem[hi_mem_min], mem_end + 1 - hi_mem_min))
3598     return;
3599
3600   x = x + mem_end + 1 - hi_mem_min;
3601   p = avail;
3602
3603   while (p != 0)
3604   {
3605     decr(dyn_used);
3606     p = mem[p].hh.v.RH;
3607   }
3608
3609   dump_int(var_used);
3610   dump_int(dyn_used);
3611   print_ln();
3612   print_int(x);
3613   print_string(" memory locations dumped; current usage is ");
3614   print_int(var_used);
3615   print_char('&');
3616   print_int(dyn_used);
3617
3618   k = active_base;
3619
3620   do
3621     {
3622       j = k;
3623
3624       while (j < (int_base - 1))
3625       {
3626         if ((equiv(j) == equiv(j + 1)) &&
3627           (eq_type(j) == eq_type(j + 1)) &&
3628           (eq_level(j) == eq_level(j + 1)))
3629           goto lab41;
3630         incr(j);
3631       }
3632
3633       l = (int_base);
3634       goto lab31;
3635 lab41:
3636       incr(j);
3637       l = j;
3638       while (j < (int_base - 1))
3639       {
3640         if ((equiv(j) != equiv(j + 1)) ||
3641           (eq_type(j) != eq_type(j + 1)) ||
3642           (eq_level(j) != eq_level(j + 1)))
3643           goto lab31;
3644         incr(j);
3645       }
3646 lab31:
3647       dump_int(l - k);
3648
3649       if (dumpthings(eqtb[k], l - k))
3650         return;
3651
3652       k = j + 1;
3653       dump_int(k - l);
3654     }
3655   while (!(k == (int_base)));
3656
3657   do {
3658     j = k;
3659     while (j < (eqtb_size)) {
3660       if (eqtb[j].cint == eqtb[j + 1].cint)
3661         goto lab42;
3662       incr(j);
3663     }
3664     l = (eqtb_size + 1);
3665     goto lab32;
3666 lab42:
3667     incr(j);
3668     l = j;
3669     while (j < (eqtb_size)) {
3670       if (eqtb[j].cint != eqtb[j + 1].cint)
3671         goto lab32;
3672       incr(j);
3673     }
3674 lab32:
3675     dump_int(l - k);
3676     if (dumpthings(eqtb[k], l - k))
3677       return;
3678     k = j + 1;
3679     dump_int(k - l);
3680   } while (!(k > (eqtb_size)));
3681
3682   dump_int(par_loc);
3683   dump_int(write_loc);
3684
3685   dump_int(hash_used);
3686   cs_count = frozen_control_sequence - 1 - hash_used;
3687
3688   if (trace_flag)
3689   {
3690     sprintf(log_line, "itex cs_count %d hash_size %d hash_extra %d hash_used %d",
3691         cs_count, hash_size, hash_extra, hash_used);
3692     show_line(log_line, 0);
3693   }
3694
3695   for (p = hash_base; p <= hash_used; p++)
3696   {
3697     if (hash[p].v.RH != 0)
3698     {
3699       dump_int(p);
3700       dump_hh(hash[p]);
3701       incr(cs_count);
3702
3703       if (trace_flag)
3704       {
3705         sprintf(log_line, "itex cs_count++ ");
3706         show_line(log_line, 0); /* debugging */
3707       }
3708
3709     }
3710   }
3711 /*  ??? */
3712 /* for p <- hash_used+1 to undefined_control_sequence-1 do dump_hh(hash[p]) */
3713   if (dumpthings(hash[hash_used + 1], (hash_size + 780) - hash_used))
3714     return;
3715
3716   dump_int(cs_count);
3717   print_ln();
3718   print_int(cs_count);
3719   print_string(" multiletter control sequences");
3720
3721   dump_int(fmem_ptr);
3722   {
3723     if (dumpthings(font_info[0], fmem_ptr))
3724       return;
3725
3726     dump_int(font_ptr);
3727
3728     if (dumpthings(font_check[0], font_ptr + 1))
3729       return;
3730
3731     if (dumpthings(font_size[0], font_ptr + 1))
3732       return;
3733
3734     if (dumpthings(font_dsize[0], font_ptr + 1))
3735       return;
3736
3737     if (dumpthings(font_params[0], font_ptr + 1))
3738       return;
3739
3740     if (dumpthings(hyphen_char[0], font_ptr + 1))
3741       return;
3742
3743     if (dumpthings(skew_char[0], font_ptr + 1))
3744       return;
3745
3746     if (dumpthings(font_name[0], font_ptr + 1))
3747       return;
3748
3749     if (dumpthings(font_area[0], font_ptr + 1))
3750       return;
3751
3752     if (dumpthings(font_bc[0], font_ptr + 1))
3753       return;
3754
3755     if (dumpthings(font_ec[0], font_ptr + 1))
3756       return;
3757
3758     if (dumpthings(char_base[0], font_ptr + 1))
3759       return;
3760
3761     if (dumpthings(width_base[0], font_ptr + 1))
3762       return;
3763
3764     if (dumpthings(height_base[0], font_ptr + 1))
3765       return;
3766
3767     if (dumpthings(depth_base[0], font_ptr + 1))
3768       return;
3769
3770     if (dumpthings(italic_base[0], font_ptr + 1))
3771       return;
3772
3773     if (dumpthings(lig_kern_base[0], font_ptr + 1))
3774       return;
3775
3776     if (dumpthings(kern_base[0], font_ptr + 1))
3777       return;
3778
3779     if (dumpthings(exten_base[0], font_ptr + 1))
3780       return;
3781
3782     if (dumpthings(param_base[0], font_ptr + 1))
3783       return;
3784
3785     if (dumpthings(font_glue[0], font_ptr + 1))
3786       return;
3787
3788     if (dumpthings(bchar_label[0], font_ptr + 1))
3789       return;
3790
3791     if (dumpthings(font_bchar[0], font_ptr + 1))
3792       return;
3793
3794     if (dumpthings(font_false_bchar[0], font_ptr + 1))
3795       return;
3796
3797     for (k = 0; k <= font_ptr; k++)
3798     {
3799       print_nl("\\font");
3800 /*  print_esc(hash[(hash_size + 524) + k].v.RH);  */
3801 /*  print_esc(hash[(hash_size + hash_extra + 524) + k].v.RH); */
3802       print_esc("");print(hash[(hash_size + hash_extra + 524) + k].v.RH);
3803       print_char('=');
3804       print_file_name(font_name[k], font_area[k], 335);
3805
3806       if (font_size[k] != font_dsize[k])
3807       {
3808         print_string(" at ");
3809         print_scaled(font_size[k]);
3810         print_string("pt");
3811       }
3812     }
3813   }
3814
3815   print_ln();
3816   print_int(fmem_ptr - 7);
3817   print_string(" words of font info for ");
3818   print_int(font_ptr - 0);
3819   print_string(" preloaded font");
3820
3821   if (font_ptr != 1)
3822     print_char('s');
3823
3824   dump_int(hyph_count);
3825
3826   for (k = 0; k <= hyphen_prime; k++)
3827   {
3828     if (hyph_word[k]!= 0)
3829     {
3830       dump_int(k);
3831       dump_int(hyph_word[k]);
3832       dump_int(hyph_list[k]);
3833     }
3834   }
3835
3836   print_ln();
3837   print_int(hyph_count);
3838   print_string(" hyphenation exception");
3839
3840   if (hyph_count != 1)
3841     print_char('s');
3842
3843   if (trie_not_ready)
3844     init_trie();
3845
3846   dump_int(trie_max);
3847
3848   if (dumpthings(trie_trl[0], trie_max + 1))
3849     return;
3850
3851   if (dumpthings(trie_tro[0], trie_max + 1))
3852     return;
3853
3854   if (dumpthings(trie_trc[0], trie_max + 1))
3855     return;
3856
3857   dump_int(trie_op_ptr);
3858
3859   if (dumpthings(hyf_distance[1], trie_op_ptr))
3860     return;
3861
3862   if (dumpthings(hyf_num[1], trie_op_ptr))
3863     return;
3864
3865   if (dumpthings(hyf_next[1], trie_op_ptr))
3866     return;
3867
3868   print_nl("Hyphenation trie of length ");
3869   print_int(trie_max);
3870   print_string(" has ");
3871   print_int(trie_op_ptr);
3872   print_string(" op");
3873
3874   if (trie_op_ptr != 1)
3875     print_char('s');
3876
3877   print_string(" out of ");
3878   print_int(trie_op_size);
3879
3880   for (k = 255; k >= 0; k--)
3881   {
3882     if (trie_used[k] > 0)
3883     {
3884       print_nl("  ");
3885       print_int(trie_used[k]);
3886       print_string(" for language ");
3887       print_int(k);
3888       dump_int(k);
3889       dump_int(trie_used[k]);
3890     }
3891   }
3892
3893   dump_int(interaction);
3894   dump_int(format_ident);
3895   dump_int(ENDFMTCHECKSUM); /* magic checksum end of FMT file --- change ??? */ 
3896   tracing_stats = 0;
3897
3898 #ifdef COMPACTFORMAT
3899   gzclose(gz_fmt_file);
3900 #else
3901   w_close(fmt_file);
3902 #endif
3903 }
3904 #endif /* INITEX */
3905
3906 #ifdef INITEX
3907 /* sec 01336 */
3908 void init_prim (void)
3909 {
3910   no_new_control_sequence = false;
3911   primitive("lineskip", assign_glue, glue_base + line_skip_code);
3912   primitive("baselineskip", assign_glue, glue_base + baseline_skip_code);
3913   primitive("parskip", assign_glue, glue_base + par_skip_code);
3914   primitive("abovedisplayskip", assign_glue, glue_base + above_display_skip_code);
3915   primitive("belowdisplayskip", assign_glue, glue_base + below_display_skip_code);
3916   primitive("abovedisplayshortskip", assign_glue, glue_base + above_display_short_skip_code);
3917   primitive("belowdisplayshortskip", assign_glue, glue_base + below_display_short_skip_code);
3918   primitive("leftskip", assign_glue, glue_base + left_skip_code);
3919   primitive("rightskip", assign_glue, glue_base + right_skip_code);
3920   primitive("topskip", assign_glue, glue_base + top_skip_code);
3921   primitive("splittopskip", assign_glue, glue_base + split_top_skip_code);
3922   primitive("tabskip", assign_glue, glue_base + tab_skip_code);
3923   primitive("spaceskip", assign_glue, glue_base + space_skip_code);
3924   primitive("xspaceskip", assign_glue, glue_base + xspace_skip_code);
3925   primitive("parfillskip", assign_glue, glue_base + par_fill_skip_code);
3926   primitive("thinmuskip", assign_mu_glue, glue_base + thin_mu_skip_code);
3927   primitive("medmuskip", assign_mu_glue, glue_base + med_mu_skip_code);
3928   primitive("thickmuskip", assign_mu_glue, glue_base + thick_mu_skip_code);
3929   primitive("output", assign_toks, output_routine_loc);
3930   primitive("everypar", assign_toks, every_par_loc);
3931   primitive("everymath", assign_toks, every_math_loc);
3932   primitive("everydisplay", assign_toks, every_display_loc);
3933   primitive("everyhbox", assign_toks, every_hbox_loc);
3934   primitive("everyvbox", assign_toks, every_vbox_loc);
3935   primitive("everyjob", assign_toks, every_job_loc);
3936   primitive("everycr", assign_toks, every_cr_loc);
3937   primitive("errhelp", assign_toks, err_help_loc);
3938   primitive("pretolerance", assign_int, int_base + pretolerance_code);
3939   primitive("tolerance", assign_int, int_base + tolerance_code);
3940   primitive("linepenalty", assign_int, int_base + line_penalty_code);
3941   primitive("hyphenpenalty", assign_int, int_base + hyphen_penalty_code);
3942   primitive("exhyphenpenalty", assign_int, int_base + ex_hyphen_penalty_code);
3943   primitive("clubpenalty", assign_int, int_base + club_penalty_code);
3944   primitive("widowpenalty", assign_int, int_base + widow_penalty_code);
3945   primitive("displaywidowpenalty", assign_int, int_base + display_widow_penalty_code);
3946   primitive("brokenpenalty", assign_int, int_base + broken_penalty_code);
3947   primitive("binoppenalty", assign_int, int_base + bin_op_penalty_code);
3948   primitive("relpenalty", assign_int, int_base + rel_penalty_code);
3949   primitive("predisplaypenalty", assign_int, int_base + pre_display_penalty_code);
3950   primitive("postdisplaypenalty", assign_int, int_base + post_display_penalty_code);
3951   primitive("interlinepenalty", assign_int, int_base + inter_line_penalty_code);
3952   primitive("doublehyphendemerits", assign_int, int_base + double_hyphen_demerits_code);
3953   primitive("finalhyphendemerits", assign_int, int_base + final_hyphen_demerits_code);
3954   primitive("adjdemerits", assign_int, int_base + adj_demerits_code);
3955   primitive("mag", assign_int, int_base + mag_code);
3956   primitive("delimiterfactor", assign_int, int_base + delimiter_factor_code);
3957   primitive("looseness", assign_int, int_base + looseness_code);
3958   primitive("time", assign_int, int_base + time_code);
3959   primitive("day", assign_int, int_base + day_code);
3960   primitive("month", assign_int, int_base + month_code);
3961   primitive("year", assign_int, int_base + year_code);
3962   primitive("showboxbreadth", assign_int, int_base + show_box_breadth_code);
3963   primitive("showboxdepth", assign_int, int_base + show_box_depth_code);
3964   primitive("hbadness", assign_int, int_base + hbadness_code);
3965   primitive("vbadness", assign_int, int_base + vbadness_code);
3966   primitive("pausing", assign_int, int_base + pausing_code);
3967   primitive("tracingonline", assign_int, int_base + tracing_online_code);
3968   primitive("tracingmacros", assign_int, int_base + tracing_macros_code);
3969   primitive("tracingstats", assign_int, int_base + tracing_stats_code);
3970   primitive("tracingparagraphs", assign_int, int_base + tracing_paragraphs_code);
3971   primitive("tracingpages", assign_int, int_base + tracing_pages_code);
3972   primitive("tracingoutput", assign_int, int_base + tracing_output_code);
3973   primitive("tracinglostchars", assign_int, int_base + tracing_lost_chars_code);
3974   primitive("tracingcommands", assign_int, int_base + tracing_commands_code);
3975   primitive("tracingrestores", assign_int, int_base + tracing_restores_code);
3976   primitive("uchyph", assign_int, int_base + uc_hyph_code);
3977   primitive("outputpenalty", assign_int, int_base + output_penalty_code);
3978   primitive("maxdeadcycles", assign_int, int_base + max_dead_cycles_code);
3979   primitive("hangafter", assign_int, int_base + hang_after_code);
3980   primitive("floatingpenalty", assign_int, int_base + floating_penalty_code);
3981   primitive("globaldefs", assign_int, int_base + global_defs_code);
3982   primitive("fam", assign_int, int_base + cur_fam_code);
3983   primitive("escapechar", assign_int, int_base + escape_char_code);
3984   primitive("defaulthyphenchar", assign_int, int_base + default_hyphen_char_code);
3985   primitive("defaultskewchar", assign_int, int_base + default_skew_char_code);
3986   primitive("endlinechar", assign_int, int_base + end_line_char_code);
3987   primitive("newlinechar", assign_int, int_base + new_line_char_code);
3988   primitive("language", assign_int, int_base + language_code);
3989   primitive("lefthyphenmin", assign_int, int_base + left_hyphen_min_code);
3990   primitive("righthyphenmin", assign_int, int_base + right_hyphen_min_code);
3991   primitive("holdinginserts", assign_int, int_base + holding_inserts_code);
3992   primitive("errorcontextlines", assign_int, int_base + error_context_lines_code);
3993   primitive("parindent", assign_dimen, dimen_base + par_indent_code);
3994   primitive("mathsurround", assign_dimen, dimen_base + math_surround_code);
3995   primitive("lineskiplimit", assign_dimen, dimen_base + line_skip_limit_code);
3996   primitive("hsize", assign_dimen, dimen_base + hsize_code);
3997   primitive("vsize", assign_dimen, dimen_base + vsize_code);
3998   primitive("maxdepth", assign_dimen, dimen_base + max_depth_code);
3999   primitive("splitmaxdepth", assign_dimen, dimen_base + split_max_depth_code);
4000   primitive("boxmaxdepth", assign_dimen, dimen_base + box_max_depth_code);
4001   primitive("hfuzz", assign_dimen, dimen_base + hfuzz_code);
4002   primitive("vfuzz", assign_dimen, dimen_base + vfuzz_code);
4003   primitive("delimitershortfall", assign_dimen, dimen_base + delimiter_shortfall_code);
4004   primitive("nulldelimiterspace", assign_dimen, dimen_base + null_delimiter_space_code);
4005   primitive("scriptspace", assign_dimen, dimen_base + script_space_code);
4006   primitive("predisplaysize", assign_dimen, dimen_base + pre_display_size_code);
4007   primitive("displaywidth", assign_dimen, dimen_base + display_width_code);
4008   primitive("displayindent", assign_dimen, dimen_base + display_indent_code);
4009   primitive("overfullrule", assign_dimen, dimen_base + overfull_rule_code);
4010   primitive("hangindent", assign_dimen, dimen_base + hang_indent_code);
4011   primitive("hoffset", assign_dimen, dimen_base + h_offset_code);
4012   primitive("voffset", assign_dimen, dimen_base + v_offset_code);
4013   primitive("emergencystretch", assign_dimen, dimen_base + emergency_stretch_code);
4014   primitive(" ", ex_space, 0);
4015   primitive("/", ital_corr, 0);
4016   primitive("accent", accent, 0);
4017   primitive("advance", advance, 0);
4018   primitive("afterassignment", after_assignment, 0);
4019   primitive("aftergroup", after_group, 0);
4020   primitive("begingroup", begin_group, 0);
4021   primitive("char", char_num, 0);
4022   primitive("csname", cs_name, 0);
4023   primitive("delimiter", delim_num, 0);
4024   primitive("divide", divide, 0);
4025   primitive("endcsname", end_cs_name, 0);
4026   primitive("endgroup", end_group, 0);
4027   text(frozen_end_group) = make_string_pool("endgroup");
4028   eqtb[frozen_end_group] = eqtb[cur_val]; 
4029   primitive("expandafter", expand_after, 0);
4030   primitive("font", def_font, 0);
4031   primitive("fontdimen", assign_font_dimen, 0);
4032   primitive("halign", halign, 0);
4033   primitive("hrule", hrule, 0);
4034   primitive("ignorespaces", ignore_spaces, 0);
4035   primitive("insert", insert, 0);
4036   primitive("mark", mark, 0);
4037   primitive("mathaccent", math_accent, 0);
4038   primitive("mathchar", math_char_num, 0);
4039   primitive("mathchoice", math_choice, 0);
4040   primitive("multiply", multiply, 0);
4041   primitive("noalign", no_align, 0);
4042   primitive("noboundary", no_boundary, 0);
4043   primitive("noexpand", no_expand, 0);
4044   primitive("nonscript", non_script, 0);
4045   primitive("omit", omit, 0);
4046   primitive("parshape", set_shape, 0);
4047   primitive("penalty", break_penalty, 0);
4048   primitive("prevgraf", set_prev_graf, 0);
4049   primitive("radical", radical, 0);
4050   primitive("read", read_to_cs, 0);
4051   primitive("relax", relax, 256);
4052   text(frozen_relax) = make_string_pool("relax");
4053   eqtb[frozen_relax] = eqtb[cur_val];
4054   primitive("setbox", set_box, 0);
4055   primitive("the", the, 0);
4056   primitive("toks", toks_register, 0);
4057   primitive("vadjust", vadjust, 0);
4058   primitive("valign", valign, 0);
4059   primitive("vcenter", vcenter, 0);
4060   primitive("vrule", vrule, 0);
4061   primitive("par", par_end, 256);
4062   par_loc = cur_val; 
4063   par_token = cs_token_flag + par_loc;
4064   primitive("input", input, 0);
4065   primitive("endinput", input, 1);
4066   primitive("topmark", top_bot_mark, 0);
4067   primitive("firstmark", top_bot_mark, 1);
4068   primitive("botmark", top_bot_mark, 2);
4069   primitive("splitfirstmark", top_bot_mark, 3);
4070   primitive("splitbotmark", top_bot_mark, 4);
4071   primitive("count", tex_register, 0);
4072   primitive("dimen", tex_register, 1);
4073   primitive("skip", tex_register, 2);
4074   primitive("muskip", tex_register, 3);
4075   primitive("spacefactor", set_aux, 102);
4076   primitive("prevdepth", set_aux, 1);
4077   primitive("deadcycles", set_page_int, 0);
4078   primitive("insertpenalties", set_page_int, 1);
4079   primitive("wd", set_box_dimen, 1);
4080   primitive("ht", set_box_dimen, 3);
4081   primitive("dp", set_box_dimen, 2);
4082   primitive("lastpenalty", last_item, 0);
4083   primitive("lastkern", last_item, 1);
4084   primitive("lastskip", last_item, 2);
4085   primitive("inputlineno", last_item, 3);
4086   primitive("badness", last_item, 4);
4087   primitive("number", convert, 0);
4088   primitive("romannumeral", convert, 1);
4089   primitive("string", convert, 2);
4090   primitive("meaning", convert, 3);
4091   primitive("fontname", convert, 4);
4092   primitive("jobname", convert, 5);
4093   primitive("if", if_test, 0);
4094   primitive("ifcat", if_test, 1);
4095   primitive("ifnum", if_test, 2);
4096   primitive("ifdim", if_test, 3);
4097   primitive("ifodd", if_test, 4);
4098   primitive("ifvmode", if_test, 5);
4099   primitive("ifhmode", if_test, 6);
4100   primitive("ifmmode", if_test, 7);
4101   primitive("ifinner", if_test, 8);
4102   primitive("ifvoid", if_test, 9);
4103   primitive("ifhbox", if_test, 10);
4104   primitive("ifvbox", if_test, 11);
4105   primitive("ifx", if_test, 12);
4106   primitive("ifeof", if_test, 13);
4107   primitive("iftrue", if_test, 14);
4108   primitive("iffalse", if_test, 15);
4109   primitive("ifcase", if_test, 16);
4110   primitive("fi", fi_or_else, 2);
4111   text(frozen_fi) = make_string_pool("fi");
4112   eqtb[frozen_fi] = eqtb[cur_val];
4113   primitive("or", fi_or_else, 4);
4114   primitive("else", fi_or_else, 3);
4115   primitive("nullfont", set_font, 0);
4116   text(frozen_null_font) = 795;
4117   eqtb[frozen_null_font] = eqtb[cur_val];
4118   primitive("span", tab_mark, 256);
4119   primitive("cr", car_ret, 257);
4120   text(frozen_cr) = make_string_pool("cr");
4121   eqtb[frozen_cr] = eqtb[cur_val];
4122   primitive("crcr", car_ret, 258);
4123   text(frozen_end_template) = make_string_pool("endtemplate");
4124   text(frozen_endv) = make_string_pool("endtemplate");
4125   eq_type(frozen_endv) = endv;
4126   equiv(frozen_endv) = null_list; 
4127   eq_level(frozen_endv) = level_one; 
4128   eqtb[frozen_end_template] = eqtb[frozen_endv]; 
4129   eq_type(frozen_end_template) = end_template;
4130   primitive("pagegoal", set_page_dimen, 0);
4131   primitive("pagetotal", set_page_dimen, 1);
4132   primitive("pagestretch", set_page_dimen, 2);
4133   primitive("pagefilstretch", set_page_dimen, 3);
4134   primitive("pagefillstretch", set_page_dimen, 4);
4135   primitive("pagefilllstretch", set_page_dimen, 5);
4136   primitive("pageshrink", set_page_dimen, 6);
4137   primitive("pagedepth", set_page_dimen, 7);
4138   primitive("end", end_match, 0);
4139   primitive("dump", stop, 1);
4140   primitive("hskip", hskip, 4);
4141   primitive("hfil", hskip, 0);
4142   primitive("hfill", hskip, 1);
4143   primitive("hss", hskip, 2);
4144   primitive("hfilneg", hskip, 3);
4145   primitive("vskip", vskip, 4);
4146   primitive("vfil", vskip, 0);
4147   primitive("vfill", vskip, 1);
4148   primitive("vss", vskip, 2);
4149   primitive("vfilneg", vskip, 3);
4150   primitive("mskip", mskip, 5);
4151   primitive("kern", kern, 1);
4152   primitive("mkern", mkern, 99);
4153   primitive("moveleft", hmove, 1);
4154   primitive("moveright", hmove, 0);
4155   primitive("raise", vmove, 1);
4156   primitive("lower", vmove, 0);
4157   primitive("box", make_box, 0);
4158   primitive("copy", make_box, 1);
4159   primitive("lastbox", make_box, 2);
4160   primitive("vsplit", make_box, 3);
4161   primitive("vtop", make_box, 4);
4162   primitive("vbox", make_box, 5);
4163   primitive("hbox", make_box, 106);
4164   primitive("shipout", leader_ship, 99);
4165   primitive("leaders", leader_ship, 100);
4166   primitive("cleaders", leader_ship, 101);
4167   primitive("xleaders", leader_ship, 102);
4168   primitive("indent", start_par, 1);
4169   primitive("noindent", start_par, 0);
4170   primitive("unpenalty", remove_item, 12);
4171   primitive("unkern", remove_item, 11);
4172   primitive("unskip", remove_item, 10);
4173   primitive("unhbox", un_hbox, 0);
4174   primitive("unhcopy", un_hbox, 1);
4175   primitive("unvbox", un_vbox, 0);
4176   primitive("unvcopy", un_vbox, 1);
4177   primitive("-", discretionary, 1);
4178   primitive("discretionary", discretionary, 0);
4179   primitive("eqno", eq_no, 0);
4180   primitive("leqno", eq_no, 1);
4181   primitive("mathord", math_comp, 16);
4182   primitive("mathop", math_comp, 17);
4183   primitive("mathbin", math_comp, 18);
4184   primitive("mathrel", math_comp, 19);
4185   primitive("mathopen", math_comp, 20);
4186   primitive("mathclose", math_comp, 21);
4187   primitive("mathpunct", math_comp, 22);
4188   primitive("mathinner", math_comp, 23);
4189   primitive("underline", math_comp, 26);
4190   primitive("overline", math_comp, 27);
4191   primitive("displaylimits", limit_switch, 0);
4192   primitive("limits", limit_switch, 1);
4193   primitive("nolimits", limit_switch, 2);
4194   primitive("displaystyle", math_style, 0);
4195   primitive("textstyle", math_style, 2);
4196   primitive("scriptstyle", math_style, 4);
4197   primitive("scriptscriptstyle", math_style, 6);
4198   primitive("above", above, 0);
4199   primitive("over", above, 1);
4200   primitive("atop", above, 2);
4201   primitive("abovewithdelims", above, 3);
4202   primitive("overwithdelims", above, 4);
4203   primitive("atopwithdelims", above, 5);
4204   primitive("left", left_right, 30);
4205   primitive("right", left_right, 31);
4206   text(frozen_right) = make_string_pool("right");
4207   eqtb[frozen_right] = eqtb[cur_val]; 
4208   primitive("long", prefix, 1);
4209   primitive("outer", prefix, 2);
4210   primitive("global", prefix, 4);
4211   primitive("def", def, 0);
4212   primitive("gdef", def, 1);
4213   primitive("edef", def, 2);
4214   primitive("xdef", def, 3);
4215   primitive("let", let, 0);
4216   primitive("futurelet", let, 1);
4217   primitive("chardef", shorthand_def, 0);
4218   primitive("mathchardef", shorthand_def, 1);
4219   primitive("countdef", shorthand_def, 2);
4220   primitive("dimendef", shorthand_def, 3);
4221   primitive("skipdef", shorthand_def, 4);
4222   primitive("muskipdef", shorthand_def, 5);
4223   primitive("toksdef", shorthand_def, 6);
4224   primitive("catcode", def_code, cat_code_base);
4225   primitive("mathcode", def_code, math_code_base);
4226   primitive("lccode", def_code, lc_code_base);
4227   primitive("uccode", def_code, uc_code_base);
4228   primitive("sfcode", def_code, sf_code_base);
4229   primitive("delcode", def_code, (hash_size + 3474));
4230   primitive("textfont", def_family, (hash_size + 1835));
4231   primitive("scriptfont", def_family, (hash_size + 1851));
4232   primitive("scriptscriptfont", def_family, (hash_size + 1867));
4233   primitive("hyphenation", hyph_data, 0);
4234   primitive("patterns", hyph_data, 1);
4235   primitive("hyphenchar", assign_font_int, 0);
4236   primitive("skewchar", assign_font_int, 1);
4237   primitive("batchmode", set_interaction, 0);
4238   primitive("nonstopmode", set_interaction, 1);
4239   primitive("scrollmode", set_interaction, 2);
4240   primitive("errorstopmode", set_interaction, 3);
4241   primitive("openin", in_stream, 1);
4242   primitive("closein", in_stream, 0);
4243   primitive("message", message, 0);
4244   primitive("errmessage", message, 1);
4245   primitive("lowercase", case_shift, (hash_size + 2139));
4246   primitive("uppercase", case_shift, (hash_size + 2395));
4247   primitive("show", xray, 0);
4248   primitive("showbox", xray, 1);
4249   primitive("showthe", xray, 2);
4250   primitive("showlists", xray, 3);
4251   primitive("openout", extension, 0);
4252   primitive("write", extension, 1);
4253   write_loc = cur_val;
4254   primitive("closeout", extension, 2);
4255   primitive("special", extension, 3);
4256   primitive("immediate", extension, 4);
4257   primitive("setlanguage", extension, 5);
4258   no_new_control_sequence = true; 
4259 }
4260 #endif