OSDN Git Service

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