OSDN Git Service

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