OSDN Git Service

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