OSDN Git Service

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