OSDN Git Service

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