OSDN Git Service

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