OSDN Git Service

25376589bb25af02010e26857a81e6816547f8ff
[putex/putex.git] / src / texsourc / tex8.c
1 /* Copyright 2014 Clerk Ma
2
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful, but
9    WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16    02110-1301 USA.  */
17
18 #define EXTERN extern
19
20 #include "texd.h"
21
22 /* sec 1181 */
23 void math_fraction (void)
24 {
25   small_number c;
26
27   c = cur_chr;
28
29   if (incompleat_noad != 0)
30   {
31     if (c >= delimited_code)
32     {
33       scan_delimiter(garbage, false);
34       scan_delimiter(garbage, false);
35     }
36
37     if (c % delimited_code == 0)
38       scan_dimen(false, false, false);
39
40     print_err("Ambiguous; you need another { and }");
41     help3("I'm ignoring this fraction specification, since I don't",
42       "know whether a construction like `x \\over y \\over z'",
43       "means `{x \\over y} \\over z' or `x \\over {y \\over z}'.");
44     error();
45   }
46   else
47   {
48     incompleat_noad = get_node(fraction_noad_size);
49     type(incompleat_noad) = fraction_noad;
50     subtype(incompleat_noad) = normal;
51     math_type(numerator(incompleat_noad)) = sub_mlist;
52     info(numerator(incompleat_noad)) = link(head);
53     mem[denominator(incompleat_noad)].hh = empty_field;
54     mem[left_delimiter(incompleat_noad)].qqqq = null_delimiter;
55     mem[right_delimiter(incompleat_noad)].qqqq = null_delimiter;
56     link(head) = 0;
57     tail = head;
58
59     if (c >= delimited_code)
60     {
61       scan_delimiter(left_delimiter(incompleat_noad), false);
62       scan_delimiter(right_delimiter(incompleat_noad), false);
63     }
64
65     switch (c % delimited_code)
66     {
67       case above_code:
68         scan_dimen(false, false, false);
69         thickness(incompleat_noad) = cur_val;
70         break;
71
72       case over_code:
73         thickness(incompleat_noad) = default_code;
74         break;
75
76       case atop_code:
77         thickness(incompleat_noad) = 0;
78         break;
79     }
80   }
81 }
82 /* sec 1191 */
83 void math_left_right (void)
84 {
85   small_number t;
86   halfword p;
87
88   t = cur_chr;
89
90   if ((t == right_noad) && (cur_group != math_left_group))
91   {
92     if (cur_group == math_shift_group)
93     {
94       scan_delimiter(garbage, false);
95       print_err("Extra ");
96       print_esc("right");
97       help1("I'm ignoring a \\right that had no matching \\left.");
98       error();
99     }
100     else
101     {
102       off_save();
103     }
104   }
105   else
106   {
107     p = new_noad();
108     type(p) = t;
109     scan_delimiter(delimiter(p), false);
110
111     if (t == left_noad)
112     {
113       push_math(math_left_group);
114       link(tail) = p;
115       tail = p;
116     }
117     else
118     {
119       p = fin_mlist(p);
120       unsave();
121       tail_append(new_noad());
122       type(tail) = inner_noad;
123       math_type(nucleus(tail)) = sub_mlist;
124       info(nucleus(tail)) = p;
125     }
126   }
127 }
128 /* sec 1194 */
129 void after_math (void)
130 {
131   bool l;
132   bool danger;
133   integer m;
134   halfword p;
135   halfword a;
136   halfword b;
137   scaled w;
138   scaled z;
139   scaled e;
140   scaled q;
141   scaled d;
142   scaled s;
143   small_number g1, g2;
144   halfword r;
145   halfword t;
146
147   danger = false;
148   
149   if ((font_params[fam_fnt(2 + text_size)] < total_mathsy_params) ||
150     (font_params[fam_fnt(2 + script_size)] < total_mathsy_params) ||
151     (font_params[fam_fnt(2 + script_script_size)] < total_mathsy_params))
152   {
153     print_err("Math formula deleted: Insufficient symbol fonts");
154     help3("Sorry, but I can't typeset math unless \\textfont 2",
155         "and \\scriptfont 2 and \\scriptscriptfont 2 have all",
156         "the \\fontdimen values needed in math symbol fonts.");
157     error();
158     flush_math();
159     danger = true;
160   }
161   else if ((font_params[fam_fnt(3 + text_size)] < total_mathex_params) ||
162     (font_params[fam_fnt(3 + script_size)] < total_mathex_params) ||
163     (font_params[fam_fnt(3 + script_script_size)] < total_mathex_params))
164   {
165     print_err("Math formula deleted: Insufficient extension fonts");
166     help3("Sorry, but I can't typeset math unless \\textfont 3",
167         "and \\scriptfont 3 and \\scriptscriptfont 3 have all",
168         "the \\fontdimen values needed in math extension fonts.");
169     error();
170     flush_math();
171     danger = true;
172   }
173
174   m = mode;
175   l = false;
176   p = fin_mlist(0);
177
178   if (mode == - (integer) m)
179   {
180     {
181       get_x_token();
182
183       if (cur_cmd != math_shift)
184       {
185         print_err("Display math should end with $$");
186         help2("The `$' that I just saw supposedly matches a previous `$$'.",
187             "So I shall assume that you typed `$$' both times.");
188         back_error();
189       }
190     }
191
192     cur_mlist = p;
193     cur_style = text_style;
194     mlist_penalties = false;
195     mlist_to_hlist();
196     a = hpack(link(temp_head), 0, 1);
197     unsave();
198     decr(save_ptr);
199
200     if (saved(0) == 1)
201       l = true;
202
203     danger = false;
204
205     if ((font_params[fam_fnt(2 + text_size)] < total_mathsy_params) ||
206       (font_params[fam_fnt(2 + script_size)] < total_mathsy_params) ||
207       (font_params[fam_fnt(2 + script_script_size)] < total_mathsy_params))
208     {
209       print_err("Math formula deleted: Insufficient symbol fonts");
210       help3("Sorry, but I can't typeset math unless \\textfont 2",
211           "and \\scriptfont 2 and \\scriptscriptfont 2 have all",
212           "the \\fontdimen values needed in math symbol fonts.");
213       error();
214       flush_math();
215       danger = true;
216     }
217     else if ((font_params[fam_fnt(3 + text_size)] < total_mathex_params) ||
218       (font_params[fam_fnt(3 + script_size)] < total_mathex_params) ||
219       (font_params[fam_fnt(3 + script_script_size)] < total_mathex_params))
220     {
221       print_err("Math formula deleted: Insufficient extension fonts");
222       help3("Sorry, but I can't typeset math unless \\textfont 3",
223         "and \\scriptfont 3 and \\scriptscriptfont 3 have all",
224         "the \\fontdimen values needed in math extension fonts.");
225       error();
226       flush_math();
227       danger = true;
228     }
229
230     m = mode;
231     p = fin_mlist(0);
232   }
233   else
234     a = 0;
235
236   if (m < 0)
237   {
238     tail_append(new_math(math_surround, 0));
239     cur_mlist = p;
240     cur_style = text_style;
241     mlist_penalties = (mode > 0);
242     mlist_to_hlist();
243     link(tail) = link(temp_head);
244
245     while(link(tail) != 0)
246       tail = link(tail);
247
248     tail_append(new_math(math_surround, 1));
249     space_factor = 1000;
250     unsave();
251   }
252   else
253   {
254     if (a == 0)
255     {
256       get_x_token();
257
258       if (cur_cmd != math_shift)
259       {
260         print_err("Display math should end with $$");
261         help2("The `$' that I just saw supposedly matches a previous `$$'.",
262             "So I shall assume that you typed `$$' both times.");
263         back_error();
264       }
265     }
266
267     cur_mlist = p;
268     cur_style = display_style;
269     mlist_penalties = false;
270     mlist_to_hlist();
271     p = link(temp_head);
272     adjust_tail = adjust_head;
273     b = hpack(p, 0, 1);
274     p = list_ptr(b);
275     t = adjust_tail;
276     adjust_tail = 0;
277     w = width(b);
278     z = display_width;
279     s = display_indent;
280
281     if ((a == 0) || danger)
282     {
283       e = 0;
284       q = 0;
285     }
286     else
287     {
288       e = width(a);
289       q = e + math_quad(text_size);
290     }
291
292     if (w + q > z)
293     {
294       if ((e != 0) && ((w - total_shrink[normal] + q <= z) || (total_shrink[fil] != 0) ||
295         (total_shrink[fill] != 0) || (total_shrink[filll] != 0)))
296       {
297         free_node(b, box_node_size);
298         b = hpack(p, z - q, 0);
299       }
300       else
301       {
302         e = 0;
303
304         if (w > z)
305         {
306           free_node(b, box_node_size);
307           b = hpack(p, z, 0);
308         }
309       }
310       w = width(b);
311     }
312
313     d = half(z - w);
314
315     if ((e > 0) && (d < 2 * e))
316     {
317       d = half(z - w - e);
318
319       if (p != 0)
320         if (!(p >= hi_mem_min))
321           if (type(p) == glue_node)
322             d = 0;
323     }
324
325     tail_append(new_penalty(pre_display_penalty));
326
327     if ((d + s <= pre_display_size) || l)
328     {
329       g1 = above_display_skip_code;
330       g2 = below_display_skip_code;
331     }
332     else
333     {
334       g1 = above_display_short_skip_code;
335       g2 = below_display_short_skip_code;
336     }
337     if (l && (e == 0))
338     {
339       shift_amount(a) = s;
340       append_to_vlist(a);
341       tail_append(new_penalty(10000));
342     }
343     else
344     {
345       tail_append(new_param_glue(g1));
346     }
347
348     if (e != 0)
349     {
350       r = new_kern(z - w - e - d);
351
352       if (l)
353       {
354         link(a) = r;
355         link(r) = b;
356         b = a;
357         d = 0;
358       }
359       else
360       {
361         link(b) = r;
362         link(r) = a;
363       }
364       b = hpack(b, 0, 1);
365     }
366
367     shift_amount(b) = s + d;
368     append_to_vlist(b);
369
370     if ((a != 0) && (e == 0) && !l)
371     {
372       tail_append(new_penalty(10000));
373       shift_amount(a) = s + z - width(a);
374       append_to_vlist(a);
375       g2 = 0;
376     }
377
378     if (t != adjust_head)
379     {
380       link(tail) = link(adjust_head);
381       tail = t;
382     }
383
384     tail_append(new_penalty(post_display_penalty));
385
386     if (g2 > 0)
387     {
388       tail_append(new_param_glue(g2));
389     }
390
391     resume_after_display();
392   }
393 }
394 /* sec 1200 */
395 void resume_after_display (void)
396 {
397   if (cur_group != math_shift_group)
398   {
399     confusion("display");
400     return;       // abort_flag set
401   }
402
403   unsave();
404   prev_graf = prev_graf + 3;
405   push_nest();
406   mode = hmode;
407   space_factor = 1000;
408   set_cur_lang();
409   clang = cur_lang;
410   prev_graf =(norm_min(left_hyphen_min) * 64 + norm_min(right_hyphen_min)) * 65536L + cur_lang;
411
412   {
413     get_x_token();
414
415     if (cur_cmd != spacer)
416       back_input();
417   }
418
419   if (nest_ptr == 1)
420   {
421     build_page();
422   }
423 }
424 /* sec 1215 */
425 void get_r_token (void)
426 {
427 lab20:
428   do
429     {
430       get_token();
431     }
432   while (!(cur_tok != space_token));
433
434   if ((cur_cs == 0) || (cur_cs > frozen_control_sequence))
435   {
436     print_err("Missing control sequence inserted");
437     help5("Please don't say `\\def cs{...}', say `\\def\\cs{...}'.",
438       "I've inserted an inaccessible control sequence so that your",
439       "definition will be completed without mixing me up too badly.",
440       "You can recover graciously from this error, if you're",
441       "careful; see exercise 27.2 in The TeXbook.");
442
443     if (cur_cs == 0)
444       back_input();
445
446     cur_tok = cs_token_flag + frozen_protection;
447     ins_error();
448     goto lab20;
449   }
450 }
451 /* sec 1229 */
452 void trap_zero_glue (void)
453 {
454   if ((width(cur_val) == 0) && (stretch(cur_val) == 0) && (shrink(cur_val) == 0))
455   {
456     add_glue_ref(zero_glue);
457     delete_glue_ref(cur_val);
458     cur_val = 0;
459   }
460 }
461 /* sec 1236 */
462 void do_register_command_ (small_number a)
463 {
464   halfword l, q, r, s;
465   char p;
466
467   q = cur_cmd;
468
469   {
470     if (q != tex_register)
471     {
472       get_x_token();
473
474       if ((cur_cmd >= assign_int) && (cur_cmd <= assign_mu_glue))
475       {
476         l = cur_chr;
477         p = cur_cmd - assign_int;
478         goto lab40;
479       }
480
481       if (cur_cmd != tex_register)
482       {
483         print_err("You can't use `");
484         print_cmd_chr(cur_cmd, cur_chr);
485         print_string("' after ");
486         print_cmd_chr(q, 0);
487         help1("I'm forgetting what you said and not changing anything.");
488         error();
489         return;
490       }
491     }
492
493     p = cur_chr;
494     scan_eight_bit_int();
495
496     switch (p)
497     {
498       case int_val:
499         l = cur_val + count_base;
500         break;
501
502       case dimen_val:
503         l = cur_val + scaled_base;
504         break;
505
506       case glue_val:
507         l = cur_val + skip_base;
508         break;
509
510       case mu_val:
511         l = cur_val + mu_skip_base;
512         break;
513     }
514   }
515
516 lab40:
517   if (q == tex_register)
518     scan_optional_equals();
519   else
520     if (scan_keyword("by"));
521
522   arith_error = false;
523
524   if (q < multiply)
525     if (p < glue_val)
526     {
527       if (p == int_val)
528         scan_int();
529       else
530         scan_dimen(false, false, false);
531
532       if (q == advance)
533         cur_val = cur_val + eqtb[l].cint;
534     }
535     else
536     {
537       scan_glue(p);
538
539       if (q == advance)
540       {
541         q = new_spec(cur_val);
542         r = equiv(l);
543         delete_glue_ref(cur_val);
544         width(q) = width(q) + width(r);
545
546         if (stretch(q) == 0)
547           stretch_order(q) = normal;
548
549         if (stretch_order(q) == stretch_order(r))
550           stretch(q) = stretch(q) + stretch(r);
551         else if ((stretch_order(q) < stretch_order(r)) && (stretch(r) != 0))
552         {
553           stretch(q) = stretch(r);
554           stretch_order(q) = stretch_order(r);
555         }
556
557         if (shrink(q) == 0)
558           shrink_order(q) = normal;
559
560         if (shrink_order(q) == shrink_order(r))
561           shrink(q) = shrink(q) + shrink(r);
562         else if ((shrink_order(q) < shrink_order(r)) && (shrink(r) != 0))
563         {
564           shrink(q) = shrink(r);
565           shrink_order(q) = shrink_order(r);
566         }
567         cur_val = q;
568       }
569     }
570   else
571   {
572     scan_int();
573
574     if (p < glue_val)
575       if (q == multiply)
576         if (p == int_val)
577           cur_val = mult_and_add(eqtb[l].cint, cur_val, 0, 2147483647L); /*  2^31 - 1 */
578         else
579           cur_val = mult_and_add(eqtb[l].cint, cur_val, 0, 1073741823L); /*  2^30 - 1 */
580       else
581         cur_val = x_over_n(eqtb[l].cint, cur_val);
582     else
583     {
584       s = equiv(l);
585       r = new_spec(s);
586
587       if (q == multiply)
588       {
589         width(r) = mult_and_add(width(s), cur_val, 0, 1073741823L);  /* 2^30 - 1 */
590         stretch(r) = mult_and_add(stretch(s), cur_val, 0, 1073741823L);  /* 2^30 - 1 */
591         shrink(r) = mult_and_add(shrink(s), cur_val, 0, 1073741823L);  /* 2^30 - 1 */
592       }
593       else
594       {
595         width(r) = x_over_n(width(s), cur_val);
596         stretch(r) = x_over_n(stretch(s), cur_val);
597         shrink(r) = x_over_n(shrink(s), cur_val);
598       }
599       cur_val = r;
600     }
601   }
602
603   if (arith_error)
604   {
605     print_err("Arithmetic overflow");
606     help2("I can't carry out that multiplication or division,",
607         "since the result is out of range.");
608
609     if (p >= glue_val)
610       delete_glue_ref(cur_val);
611
612     error();
613     return;
614   }
615
616   if (p < glue_val)
617   {
618     if ((a >= 4))
619       geq_word_define(l, cur_val);
620     else
621       eq_word_define(l, cur_val);
622   }
623   else
624   {
625     trap_zero_glue();
626
627     if ((a >= 4))
628       geq_define(l, glue_ref, cur_val);
629     else
630       eq_define(l, glue_ref, cur_val);
631   }
632 }
633 /* sec 1243 */
634 void alter_aux (void)
635 {
636   halfword c;
637
638   if (cur_chr != abs(mode))
639   {
640     report_illegal_case();
641   }
642   else
643   {
644     c = cur_chr;
645     scan_optional_equals();
646
647     if (c == vmode)
648     {
649       scan_dimen(false, false, false);
650       prev_depth = cur_val;
651     }
652     else
653     {
654       scan_int();
655
656       if ((cur_val <= 0) || (cur_val > 32767))
657       {
658         print_err("Bad space factor");
659         help1("I allow only values in the range 1..32767 here.");
660         int_error(cur_val);
661       }
662       else
663         space_factor = cur_val;
664     }
665   }
666 }
667 /* sec 1244 */
668 void alter_prev_graf (void)
669 {
670   integer p;
671
672   nest[nest_ptr] = cur_list;
673   p = nest_ptr;
674
675   while (abs(nest[p].mode_field) != vmode)
676     decr(p);
677
678   scan_optional_equals();
679   scan_int();
680
681   if (cur_val < 0)
682   {
683     print_err("Bad ");
684     print_esc("prevgraf");
685     help1("I allow only nonnegative values here.");
686     int_error(cur_val);
687   }
688   else
689   {
690     nest[p].pg_field = cur_val;
691     cur_list = nest[nest_ptr];
692   }
693 }
694 /* sec 1245 */
695 void alter_page_so_far (void)
696 {
697   char c;
698
699   c = cur_chr;
700   scan_optional_equals();
701   scan_dimen(false, false, false);
702   page_so_far[c] = cur_val;
703 }
704 /* sec 1246 */
705 void alter_integer (void)
706 {
707   char c;
708
709   c = cur_chr;
710   scan_optional_equals();
711   scan_int();
712
713   if (c == 0)
714     dead_cycles = cur_val;
715   else
716     insert_penalties = cur_val;
717 }
718 /* sec 1247 */
719 void alter_box_dimen (void)
720 {
721   small_number c;
722   eight_bits b;
723
724   c = cur_chr;
725   scan_eight_bit_int();
726   b = cur_val;
727   scan_optional_equals();
728   scan_dimen(false, false, false);
729
730   if (box(b) != 0)
731     mem[box(b) + c].cint = cur_val;
732 }
733 /* sec 1257 */
734 void new_font_(small_number a)
735 {
736   halfword u;
737   scaled s;
738   internal_font_number f;
739   str_number t;
740   char old_setting;
741   str_number flushable_string;
742
743   if (job_name == 0)
744     open_log_file();
745
746   get_r_token();
747   u = cur_cs;
748
749   if (u >= hash_base)
750     t = text(u);
751   else if (u >= single_base)
752     if (u == null_cs)
753       t = 1213;     /* FONT */
754     else
755       t = u - single_base;
756   else
757   {
758     old_setting = selector;
759     selector = new_string;
760     print_string("FONT");
761     print(u - active_base);
762     selector = old_setting;
763     str_room(1);
764     t = make_string();
765   }
766
767   if ((a >= 4))
768     geq_define(u, set_font, 0);
769   else
770     eq_define(u, set_font, 0);
771
772   scan_optional_equals();
773   scan_file_name();
774
775   name_in_progress = true;
776
777   if (scan_keyword("at"))
778   {
779     scan_dimen(false, false, false);
780     s = cur_val; 
781
782     if ((s <= 0) || (s >= 134217728L)) /* 2^27 */
783     {
784       print_err("Improper `at' size (");
785       print_scaled(s);
786       print_string("pt), replaced by 10pt");
787       help2("I can only handle fonts at positive sizes that are",
788         "less than 2048pt, so I've changed what you said to 10pt.");
789       error();
790       s = 10 * 65536L;
791     }
792   }
793   else if (scan_keyword("scaled"))
794   {
795     scan_int();
796     s = - (integer) cur_val;
797
798     if ((cur_val <= 0) || (cur_val > 32768L))
799     {
800       print_err("Illegal magnification has been changed to 1000");
801       help1("The magnification ratio must be between 1 and 32768.");
802       int_error(cur_val);
803       s = -1000;
804     }
805   }
806   else
807     s = -1000;
808
809   name_in_progress = false;
810
811   flushable_string = str_ptr - 1;
812
813   if (trace_flag)
814   {
815     int i, k1, k2, l1, l2;
816     char *sch = log_line;
817     k1 = str_start[cur_area];
818     k2 = str_start[cur_name];
819     l1 = length(cur_area);
820     l2 = length(cur_name);
821     show_char('\n');
822     show_line("FONT ", 0);
823
824     for (i = 0; i < l1; i++)
825     {
826       *sch++ = str_pool[i + k1];
827     }
828
829     for (i = 0; i < l2; i++)
830     {
831       *sch++ = str_pool[i + k2];
832     }
833
834     *sch++ = ' ';
835     *sch++ = '\0';
836     show_line(log_line, 0);
837   }
838
839   for (f = font_base + 1; f < font_ptr; f++)
840   {
841     if (str_eq_str(font_name[f], cur_name) && str_eq_str(font_area[f], cur_area))
842     {
843       if (cur_name == flushable_string)
844       {
845         flush_string();
846         cur_name = font_name[f];
847       }
848
849       if (s > 0)
850       {
851         if (s == font_size[f])
852         {
853           if (ignore_frozen == 0 || f > frozen_font_ptr)
854           {
855             if (trace_flag)
856             {
857               sprintf(log_line, "SKIPPING %ld ", s);
858               show_line(log_line, 0);
859             }
860             goto lab50;
861           }
862         }
863       }
864       else if (font_size[f] == xn_over_d(font_dsize[f], - (integer) s, 1000))
865       {
866         if (ignore_frozen == 0 || f > frozen_font_ptr)
867         {
868           if (trace_flag)
869           {
870             sprintf(log_line, "SKIPPING %ld ", s);
871             show_line(log_line, 0);
872           }
873           goto lab50;
874         }
875       }
876     }
877   }
878
879   if (trace_flag)
880     show_line("READING ", 0);
881
882   f = read_font_info(u, cur_name, cur_area, s); 
883
884 lab50:
885   if (trace_flag)
886   {
887     sprintf(log_line, "NEW FONT %d ", f);
888     show_line(log_line, 0);
889   }
890
891   equiv(u) = f;
892   eqtb[font_id_base + f] = eqtb[u];
893
894 #ifdef SHORTHASH
895   if (t > 65535L)
896   {
897     sprintf(log_line, "ERROR: %s too large %d\n",  "hash_used", t);
898     show_line(log_line, 1);
899   }
900 #endif
901   font_id_text(f) = t;
902 }
903 /* sec 1265 */
904 void new_interaction (void)
905 {
906   print_ln();
907   interaction = cur_chr;
908
909   if (interaction == batch_mode)
910     selector = no_print;
911   else
912     selector = term_only;
913
914   if (log_opened)
915     selector = selector + 2;
916 }
917 /* sec 1270 */
918 void do_assignments (void)
919 {
920   while (true)
921   {
922     do
923       {
924         get_x_token();
925       }
926     while (!((cur_cmd != spacer) && (cur_cmd != relax)));
927
928     if (cur_cmd <= max_non_prefixed_command)
929       return;
930
931     set_box_allowed = false;
932     prefixed_command();
933     set_box_allowed = true;
934   }
935 }
936 /* sec 1275 */
937 void open_or_close_in (void)
938 {
939   char c;
940   char n;
941
942   c = cur_chr;
943   scan_four_bit_int();
944   n = cur_val;
945
946   if (read_open[n] != closed)
947   {
948     (void) a_close(read_file[n]);
949     read_open[n] = closed;
950   }
951
952   if (c != 0)
953   {
954     scan_optional_equals();
955     scan_file_name();
956     pack_file_name(cur_name, cur_area, cur_ext);
957
958     if ((cur_ext != 335) && a_open_in(read_file[n], TEXINPUTPATH))
959       read_open[n] = 1;
960     else if ((cur_ext != 785) && (name_length + 5 < PATHMAX))
961     {
962       strncpy((char *) name_of_file + name_length + 1, ".tex ", 5);
963       name_length = name_length + 4;
964
965       if (a_open_in(read_file[n], TEXINPUTPATH))
966         read_open[n] = just_open;
967       else
968       {
969         name_length = name_length - 4;
970         name_of_file[name_length + 1] = ' ';
971
972         if ((cur_ext == 335) && a_open_in(read_file[n], TEXINPUTPATH))
973           read_open[n] = 1;
974       }
975     }
976   }
977 }
978 /* sec 1279 */
979 void issue_message (void)
980 {
981   char old_setting;
982   char c;
983   str_number s;
984
985   c = cur_chr;
986   link(garbage) = scan_toks(false, true);
987   old_setting = selector;
988   selector = new_string;
989   token_show(def_ref);
990   selector = old_setting;
991   flush_list(def_ref);
992   str_room(1);
993   s = make_string();
994
995   if (c == 0)
996   {
997     if (term_offset + length(s) > max_print_line - 2)
998       print_ln();
999     else if ((term_offset > 0) || (file_offset > 0))
1000       print_char(' ');
1001
1002     slow_print(s);
1003
1004 #ifndef _WINDOWS
1005     fflush(stdout);
1006 #endif
1007   }
1008   else
1009   {
1010     print_err("");
1011     slow_print(s);
1012
1013     if (err_help != 0)
1014       use_err_help = true;
1015     else if (long_help_seen)
1016       help1("(That was another \\errmessage.)");
1017     else
1018     {
1019       if (interaction < error_stop_mode)
1020         long_help_seen = true;
1021
1022       help4("This error message was generated by an \\errmessage",
1023         "command, so I can't give any explicit help.",
1024         "Pretend that you're Hercule Poirot: Examine all clues,",
1025         "and deduce the truth by order and method.");
1026     }
1027
1028     error();
1029     use_err_help = false;
1030   }
1031
1032   flush_string();
1033 }
1034 /* sec 1288 */
1035 void shift_case (void)
1036 {
1037   halfword b;
1038   halfword p;
1039   halfword t;
1040   eight_bits c;
1041
1042   b = cur_chr;
1043   p = scan_toks(false, false);
1044   p = link(def_ref);
1045
1046   while (p != 0)
1047   {
1048     t = info(p); 
1049
1050     if (t < cs_token_flag + single_base)
1051     {
1052       c = t % 256;
1053
1054       if (equiv(b + c) != 0)
1055         info(p) = t - c + equiv(b + c);
1056     }
1057
1058     p = link(p);
1059   }
1060
1061   begin_token_list(link(def_ref), 3);
1062   free_avail(def_ref);
1063 }
1064 /* sec 1293 */
1065 void show_whatever (void)
1066 {
1067   halfword p;
1068
1069   switch (cur_chr)
1070   {
1071     case show_lists:
1072       {
1073         begin_diagnostic();
1074         show_activities();
1075       }
1076       break;
1077
1078     case show_box_code:
1079       {
1080         scan_eight_bit_int();
1081         begin_diagnostic();
1082         print_nl("> \\box");
1083         print_int(cur_val);
1084         print_char('=');
1085
1086         if (box(cur_val) == 0)
1087           print_string("void");
1088         else
1089           show_box(box(cur_val));
1090       }
1091       break;
1092
1093     case show_code:
1094       {
1095         get_token();
1096
1097         if (interaction == error_stop_mode)
1098           ;
1099
1100         print_nl("> ");
1101
1102         if (cur_cs != 0)
1103         {
1104           sprint_cs(cur_cs);
1105           print_char('=');
1106         }
1107
1108         print_meaning();
1109         goto lab50;
1110       }
1111       break;
1112
1113     default:
1114       {
1115         p = the_toks();
1116
1117         if (interaction == error_stop_mode)
1118           ;
1119
1120         print_nl("> ");
1121         token_show(temp_head);
1122         flush_list(link(temp_head));
1123         goto lab50;
1124       }
1125       break;
1126   }
1127
1128   end_diagnostic(true);
1129   print_err("OK");
1130
1131   if (selector == term_and_log)
1132     if (tracing_online <= 0)
1133     {
1134       selector = term_only;
1135       print_string(" (see the transcript file)");
1136       selector = term_and_log;
1137     }
1138
1139 lab50:
1140
1141   if (interaction < error_stop_mode)
1142   {
1143     help_ptr = 0;
1144     decr(error_count);
1145   }
1146   else if (tracing_online > 0)
1147   {
1148     help3("This isn't an error message; I'm just \\showing something.",
1149       "Type `I\\show...' to show more (e.g., \\show\\cs,",
1150       "\\showthe\\count10, \\showbox255, \\showlists).");
1151   }
1152   else
1153   {
1154     help5("This isn't an error message; I'm just \\showing something.",
1155       "Type `I\\show...' to show more (e.g., \\show\\cs,",
1156       "\\showthe\\count10, \\showbox255, \\showlists).",
1157       "And type `I\\tracingonline=1\\show...' to show boxes and",
1158       "lists on your terminal as well as in the transcript file.");
1159   }
1160
1161   error();
1162 }
1163 /* sec 1349 */
1164 void new_whatsit_(small_number s, small_number w)
1165 {
1166   halfword p;
1167
1168   p = get_node(w);
1169   type(p) = whatsit_node;
1170   subtype(p) = s;
1171   link(tail) = p;
1172   tail = p;
1173 }
1174 /* sec 1350 */
1175 void new_write_whatsit_(small_number w)
1176 {
1177   new_whatsit(cur_chr, w);
1178
1179   if (w != write_node_size)
1180   {
1181     scan_four_bit_int();
1182   }
1183   else
1184   {
1185     scan_int();
1186
1187     if (cur_val < 0)
1188       cur_val = 17;
1189     else if (cur_val > 15)
1190       cur_val = 16;
1191   }
1192
1193   write_stream(tail) = cur_val;
1194 }
1195 /* sec 1348 */
1196 void do_extension (void)
1197 {
1198   integer k;
1199   halfword p;
1200
1201   switch(cur_chr)
1202   {
1203     case open_node:
1204       {
1205         new_write_whatsit(open_node_size);
1206         scan_optional_equals();
1207         scan_file_name();
1208         open_name(tail) = cur_name;
1209         open_area(tail) = cur_area;
1210         open_ext(tail) = cur_ext;
1211       }
1212       break;
1213
1214     case write_node:
1215       {
1216         k = cur_cs;
1217         new_write_whatsit(write_node_size);
1218         cur_cs = k;
1219         p = scan_toks(false, false);
1220         write_tokens(tail) = def_ref;
1221       }
1222       break;
1223
1224     case close_node:
1225       {
1226         new_write_whatsit(write_node_size);
1227         write_tokens(tail) = 0;
1228       }
1229       break;
1230
1231     case special_node:
1232       {
1233         new_whatsit(special_node, write_node_size);
1234         write_stream(tail) = 0;
1235         p = scan_toks(false, true);
1236         write_tokens(tail) = def_ref;
1237       }
1238       break;
1239
1240     case immediate_code:
1241       {
1242         get_x_token();
1243
1244         if ((cur_cmd == extension) && (cur_chr <= close_node))
1245         {
1246           p = tail;
1247           do_extension();
1248           out_what(tail);
1249           flush_node_list(tail);
1250           tail = p;
1251           link(p) = 0;
1252         }
1253         else
1254           back_input();
1255       }
1256       break;
1257
1258     case set_language_code:
1259       if (abs(mode) != hmode)
1260       {
1261         report_illegal_case();
1262       }
1263       else
1264       {
1265         new_whatsit(language_node, small_node_size);
1266         scan_int();
1267
1268         if (cur_val <= 0)
1269           clang = 0;
1270         else if (cur_val > 255)
1271           clang = 0;
1272         else
1273           clang = cur_val;
1274
1275         what_lang(tail) = clang;
1276         what_lhm(tail) = norm_min(left_hyphen_min);
1277         what_rhm(tail) = norm_min(right_hyphen_min);
1278       }
1279       break;
1280
1281     default:
1282       {
1283         confusion("ext1");
1284         return;       // abort_flag set
1285       }
1286       break;
1287   }
1288 }
1289 /* sec 1376 */
1290 void fix_language (void)
1291 {
1292 /*  ASCII_code l;  */
1293   int l;                  /* 95/Jan/7 */
1294
1295   if (language <= 0)
1296     l = 0; 
1297   else if (language > 255)
1298     l = 0;
1299   else
1300     l = language;
1301
1302   if (l != clang)
1303   {
1304     new_whatsit(language_node, small_node_size);
1305     what_lang(tail) = l;
1306     clang = l;
1307     what_lhm(tail) = norm_min(left_hyphen_min);
1308     what_rhm(tail) = norm_min(right_hyphen_min);
1309   }
1310 }
1311 /* sec 1068 */
1312 void handle_right_brace (void)
1313 {
1314   halfword p, q;
1315   scaled d;
1316   integer f;
1317
1318   switch(cur_group)
1319   {
1320     case simple_group:
1321       unsave();
1322       break;
1323
1324     case bottom_level:
1325       {
1326         print_err("Too many }'s");
1327         help2("You've closed more groups than you opened.",
1328           "Such booboos are generally harmless, so keep going.");
1329         error();
1330       }
1331       break;
1332
1333     case semi_simple_group:
1334     case math_shift_group:
1335     case math_left_group:
1336       extra_right_brace();
1337       break;
1338
1339     case hbox_group:
1340       package(0);
1341       break;
1342
1343     case adjust_hbox_group:
1344       {
1345         adjust_tail = adjust_head;
1346         package(0);
1347       }
1348       break;
1349
1350     case vbox_group:
1351       {
1352         end_graf();
1353         package(0);
1354       }
1355       break;
1356
1357     case vtop_group:
1358       {
1359         end_graf();
1360         package(vtop_code);
1361       }
1362       break;
1363
1364     case insert_group:
1365       {
1366         end_graf();
1367         q = split_top_skip;
1368         add_glue_ref(q);
1369         d = split_max_depth;
1370         f = floating_penalty;
1371         unsave();
1372         decr(save_ptr);
1373         p = vpackage(link(head), 0, 1, 1073741823L);  /* 2^30 - 1 */
1374         pop_nest();
1375
1376         if (saved(0) < 255)
1377         {
1378           tail_append(get_node(ins_node_size));
1379           type(tail) = ins_node;
1380           subtype(tail) = saved(0);
1381           height(tail) = height(p) + depth(p);
1382           ins_ptr(tail) = list_ptr(p);
1383           split_top_ptr(tail) = q;
1384           depth(tail) = d;
1385           float_cost(tail) = f;
1386         }
1387         else
1388         {
1389           tail_append(get_node(small_node_size));
1390           type(tail) = adjust_node;
1391           subtype(tail) = 0;
1392           adjust_ptr(tail) = list_ptr(p);
1393           delete_glue_ref(q);
1394         }
1395         free_node(p, box_node_size);
1396
1397         if (nest_ptr == 0)
1398         {
1399           build_page();
1400         }
1401       }
1402       break;
1403     case output_group:
1404       {
1405         if ((cur_input.loc_field != 0) || ((token_type != output_text) && (token_type != backed_up)))
1406         {
1407           print_err("Unbalanced output routine");
1408           help2("Your sneaky output routine has problematic {'s and/or }'s.",
1409             "I can't handle that very well; good luck.");
1410           error();
1411
1412           do
1413             {
1414               get_token();
1415             }
1416           while (!(cur_input.loc_field == 0));
1417         }
1418
1419         end_token_list();
1420         end_graf();
1421         unsave();
1422         output_active = false;
1423         insert_penalties = 0;
1424
1425         if (box(255) != 0)
1426         {
1427           print_err("Output routine didn't use all of ");
1428           print_esc("box");
1429           print_int(255);
1430           help3("Your \\output commands should empty \\box255,",
1431             "e.g., by saying `\\shipout\\box255'.",
1432             "Proceed; I'll discard its present contents.");
1433           box_error(255);
1434         }
1435
1436         if (tail != head)
1437         {
1438           link(page_tail) = link(head);
1439           page_tail = tail;
1440         }
1441
1442         if (link(page_head) != 0)
1443         {
1444           if (link(contrib_head) == 0)
1445             nest[0].tail_field = page_tail;
1446
1447           link(page_tail) = link(contrib_head);
1448           link(contrib_head) = link(page_head);
1449           link(page_head) = 0;
1450           page_tail = page_head;
1451         }
1452         pop_nest();
1453         build_page();
1454       }
1455       break;
1456
1457     case disc_group:
1458       build_discretionary();
1459       break;
1460
1461     case align_group:
1462       {
1463         back_input();
1464         cur_tok = cs_token_flag + frozen_cr;
1465         print_err("Missing ");
1466         print_esc("cr");
1467         print_string("inserted");
1468         help1("I'm guessing that you meant to end an alignment here.");
1469         ins_error();
1470       }
1471       break;
1472
1473     case no_align_group:
1474       {
1475         end_graf();
1476         unsave();
1477         align_peek();
1478       }
1479       break;
1480
1481     case vcenter_group:
1482       {
1483         end_graf();
1484         unsave();
1485         save_ptr = save_ptr - 2;
1486         p = vpackage(link(head), saved(1), saved(0), 1073741823L);   /* 2^30 - 1 */
1487         pop_nest();
1488         tail_append(new_noad());
1489         type(tail) = vcenter_noad;
1490         math_type(nucleus(tail)) = sub_box;
1491         info(nucleus(tail)) = p;
1492       }
1493       break;
1494
1495     case math_choice_group:
1496       build_choices();
1497       break;
1498
1499     case math_group:
1500       {
1501         unsave();
1502         decr(save_ptr);
1503         math_type(saved(0)) = sub_mlist;
1504         p = fin_mlist(0);
1505         info(saved(0)) = p;
1506
1507         if (p != 0)
1508           if (link(p) == 0)
1509             if (type(p) == ord_noad)
1510             {
1511               if (math_type(subscr(p)) == 0)
1512                 if (math_type(supscr(p)) == 0)
1513                 {
1514                   mem[saved(0)].hh = mem[nucleus(p)].hh;
1515                   free_node(p, noad_size);
1516                 }
1517             }
1518             else if (type(p) == accent_noad)
1519               if (saved(0) == nucleus(tail))
1520                 if (type(tail) == ord_noad)
1521                 {
1522                   q = head;
1523
1524                   while(link(q) != tail)
1525                     q = link(q);
1526
1527                   link(q) = p;
1528                   free_node(tail, noad_size);
1529                   tail = p;
1530                 }
1531       }
1532       break;
1533     default:
1534       {
1535         confusion("rightbrace");
1536         return;       // abort_flag set
1537       }
1538       break;
1539   }
1540 }
1541 /* sec 1030 */
1542 void main_control (void) 
1543 {
1544   integer t;
1545   integer bSuppress; /* 199/Jan/5 */
1546
1547   if (every_job != 0)
1548     begin_token_list(every_job, every_job_text);
1549
1550 lab60:
1551   get_x_token();       /* big_switch */
1552
1553 lab21:
1554   if (interrupt != 0)
1555     if (OK_to_interrupt)
1556     {
1557       back_input();
1558       {
1559         if (interrupt != 0)
1560         {
1561           pause_for_instructions();
1562         }
1563       }
1564       goto lab60;
1565     }
1566
1567 #ifdef DEBUG
1568   if (panicking)
1569     check_mem(false);
1570 #endif
1571
1572   if (tracing_commands > 0)
1573     show_cur_cmd_chr();
1574
1575 /*  the big switch --- don't bother to test abort_flag ??? */
1576   switch(abs(mode) + cur_cmd)
1577   {
1578     case hmode + letter:
1579     case hmode + other_char:
1580     case hmode + char_given:
1581       goto lab70;
1582       break;
1583
1584     case hmode + char_num:
1585       {
1586         scan_char_num();
1587         cur_chr = cur_val;
1588         goto lab70;
1589       }
1590       break;
1591
1592     case hmode + no_boundary:
1593       {
1594         get_x_token();
1595
1596         if ((cur_cmd == letter) || (cur_cmd == other_char) ||
1597           (cur_cmd == char_given) || (cur_cmd == char_num))
1598           cancel_boundary = true;
1599         goto lab21;
1600       }
1601       break;
1602
1603     case hmode + spacer:
1604       if (space_factor == 1000)
1605         goto lab120;
1606       else
1607         app_space();
1608       break;
1609
1610     case hmode + ex_space:
1611     case mmode + ex_space:
1612       goto lab120;
1613       break;
1614
1615     case any_mode(relax):
1616     case vmode + spacer:
1617     case mmode + spacer:
1618     case mmode + no_boundary:
1619       ;
1620       break;
1621
1622     case any_mode(ignore_spaces):
1623       {
1624         do
1625           {
1626             get_x_token();
1627           }
1628         while(!(cur_cmd != spacer));
1629         goto lab21;
1630       }
1631       break;
1632
1633     case vmode + stop:
1634       if (its_all_over())
1635         return;
1636       break;
1637
1638     case vmode + vmove:
1639     case hmode + hmove:
1640     case mmode + hmove:
1641     case any_mode(last_item):
1642     case vmode + vadjust:
1643     case vmode + ital_corr:
1644     case non_math(eq_no):
1645     case any_mode(mac_param):
1646       report_illegal_case();
1647       break;
1648
1649     case non_math(sup_mark):
1650     case non_math(sub_mark):
1651     case non_math(math_char_num):
1652     case non_math(math_given):
1653     case non_math(math_comp):
1654     case non_math(delim_num):
1655     case non_math(left_right):
1656     case non_math(above):
1657     case non_math(radical):
1658     case non_math(math_style):
1659     case non_math(math_choice):
1660     case non_math(vcenter):
1661     case non_math(non_script):
1662     case non_math(mkern):
1663     case non_math(limit_switch):
1664     case non_math(mskip):
1665     case non_math(math_accent):
1666     case mmode + endv:
1667     case mmode + par_end:
1668     case mmode + stop:
1669     case mmode + vskip:
1670     case mmode + un_vbox:
1671     case mmode + valign:
1672     case mmode + hrule:
1673       insert_dollar_sign();
1674       break;
1675
1676     case vmode + hrule:
1677     case hmode + vrule:
1678     case mmode + vrule:
1679       {
1680         tail_append(scan_rule_spec());
1681
1682         if (abs(mode) == vmode)
1683           prev_depth = ignore_depth;
1684         else if (abs(mode) == hmode)
1685           space_factor = 1000;
1686       }
1687       break;
1688
1689     case vmode + vskip:
1690     case hmode + hskip:
1691     case mmode + hskip:
1692     case mmode + mskip:
1693       append_glue();
1694       break;
1695
1696     case any_mode(kern):
1697     case mmode + mkern:
1698       append_kern();
1699       break;
1700
1701     case non_math(left_brace):
1702       new_save_level(simple_group);
1703       break;
1704
1705     case any_mode(begin_group):
1706       new_save_level(semi_simple_group);
1707       break;
1708
1709     case any_mode(end_group):
1710       if (cur_group == semi_simple_group)
1711         unsave();
1712       else
1713         off_save();
1714       break;
1715
1716     case any_mode(right_brace):
1717       handle_right_brace();
1718       break;
1719
1720     case vmode + hmove:
1721     case hmode + vmove:
1722     case mmode + vmove:
1723       {
1724         t = cur_chr;
1725         scan_dimen(false, false, false);
1726
1727         if (t == 0)
1728           scan_box(cur_val);
1729         else
1730           scan_box(- (integer) cur_val);
1731       }
1732       break;
1733
1734     case any_mode(leader_ship):
1735       scan_box(leader_flag - a_leaders + cur_chr);
1736       break;
1737
1738     case any_mode(make_box):
1739       begin_box(0);
1740       break;
1741
1742     case vmode + start_par:
1743       new_graf(cur_chr > 0);
1744       break;
1745
1746     case vmode + letter:
1747     case vmode + other_char:
1748     case vmode + char_num:
1749     case vmode + char_given:
1750     case vmode + math_shift:
1751     case vmode + un_hbox:
1752     case vmode + vrule:
1753     case vmode + accent:
1754     case vmode + discretionary:
1755     case vmode + hskip:
1756     case vmode + valign:
1757     case vmode + ex_space:
1758     case vmode + no_boundary:
1759       {
1760         back_input();
1761         new_graf(true);
1762       }
1763       break;
1764
1765     case hmode + start_par:
1766     case mmode + start_par:
1767       indent_in_hmode();
1768       break;
1769
1770     case vmode + par_end:
1771       {
1772         normal_paragraph();
1773
1774         if (mode > 0)
1775           build_page();
1776       }
1777       break;
1778
1779     case hmode + par_end:
1780       {
1781         if (align_state < 0)
1782           off_save();
1783
1784         end_graf();
1785
1786         if (mode == 1)
1787           build_page();
1788       }
1789       break;
1790
1791     case hmode + stop:
1792     case hmode + vskip:
1793     case hmode + hrule:
1794     case hmode + un_vbox:
1795     case hmode + halign:
1796       head_for_vmode();
1797       break;
1798
1799     case any_mode(insert):
1800     case hmode + vadjust:
1801     case mmode + vadjust:
1802       begin_insert_or_adjust();
1803       break;
1804
1805     case any_mode(mark):
1806       make_mark();
1807       break;
1808
1809     case any_mode(break_penalty):
1810       append_penalty();
1811       break;
1812
1813     case any_mode(remove_item):
1814       delete_last();
1815       break;
1816
1817     case vmode + un_vbox:
1818     case hmode + un_hbox:
1819     case mmode + un_hbox:
1820       unpackage();
1821       break;
1822
1823     case hmode + ital_corr:
1824       append_italic_correction();
1825       break;
1826
1827     case mmode + ital_corr:
1828       tail_append(new_kern(0));
1829       break;
1830
1831     case hmode + discretionary:
1832     case mmode + discretionary:
1833       append_discretionary();
1834       break;
1835
1836     case hmode + accent:
1837       make_accent();
1838       break;
1839
1840     case any_mode(car_ret):
1841     case any_mode(tab_mark):
1842       align_error();
1843       break;
1844
1845     case any_mode(no_align):
1846       noalign_error();
1847       break;
1848
1849     case any_mode(omit):
1850       omit_error();
1851       break;
1852
1853     case vmode + halign:
1854     case hmode + valign:
1855       init_align();
1856       break;
1857
1858     case mmode + halign:
1859       if (privileged ())
1860         if (cur_group == math_shift_group)
1861           init_align();
1862         else
1863           off_save();
1864       break;
1865
1866     case vmode + endv:
1867     case hmode + endv:
1868       do_endv();
1869       break;
1870
1871     case any_mode(end_cs_name):
1872       cs_error();
1873       break;
1874
1875     case hmode + math_shift:
1876       init_math();
1877       break;
1878
1879     case mmode + eq_no:
1880       if (privileged ())
1881         if (cur_group == math_shift_group)
1882           start_eq_no();
1883         else
1884           off_save();
1885       break;
1886
1887     case mmode + left_brace:
1888       {
1889         tail_append(new_noad());
1890         back_input();
1891         scan_math(nucleus(tail));
1892       }
1893       break;
1894
1895     case mmode + letter:
1896     case mmode + other_char:
1897     case mmode + char_given:
1898       set_math_char(math_code(cur_chr));
1899       break;
1900
1901     case mmode + char_num:
1902       {
1903         scan_char_num();
1904         cur_chr = cur_val;
1905         set_math_char(math_code(cur_chr));
1906       }
1907       break;
1908
1909     case mmode + math_char_num:
1910       {
1911         scan_fifteen_bit_int();
1912         set_math_char(cur_val);
1913       }
1914       break;
1915
1916     case mmode + math_given:
1917       set_math_char(cur_chr);
1918       break;
1919
1920     case mmode + delim_num:
1921       {
1922         scan_twenty_seven_bit_int();
1923         set_math_char(cur_val / 4096);
1924       }
1925       break;
1926
1927     case mmode + math_comp:
1928       {
1929         tail_append(new_noad());
1930         type(tail) = cur_chr;
1931         scan_math(nucleus(tail));
1932       }
1933       break;
1934
1935     case mmode + limit_switch:
1936       math_limit_switch();
1937       break;
1938
1939     case mmode + radical:
1940       math_radical();
1941       break;
1942
1943     case mmode + accent:
1944     case mmode + math_accent:
1945       math_ac();
1946       break;
1947
1948     case mmode + vcenter:
1949       {
1950         scan_spec(vcenter_group, false);
1951         normal_paragraph();
1952         push_nest();
1953         mode = -1;
1954         prev_depth = ignore_depth;
1955
1956         if (every_vbox != 0)
1957           begin_token_list(every_vbox, every_vbox_text);
1958       }
1959       break;
1960
1961     case mmode + math_style:
1962       tail_append(new_style(cur_chr));
1963       break;
1964
1965     case mmode + non_script:
1966       {
1967         tail_append(new_glue(0));
1968         subtype(tail) = cond_math_glue;
1969       }
1970       break;
1971
1972     case mmode + math_choice:
1973       append_choices();
1974       break;
1975
1976     case mmode + sub_mark:
1977     case mmode + sup_mark:
1978       sub_sup();
1979       break;
1980
1981     case mmode + above:
1982       math_fraction();
1983       break;
1984
1985     case mmode + left_right:
1986       math_left_right();
1987       break;
1988
1989     case mmode + math_shift:
1990       if (cur_group == math_shift_group)
1991         after_math();
1992       else
1993         off_save();
1994       break;
1995
1996     case any_mode(toks_register):
1997     case any_mode(assign_toks):
1998     case any_mode(assign_int):
1999     case any_mode(assign_dimen):
2000     case any_mode(assign_glue):
2001     case any_mode(assign_mu_glue):
2002     case any_mode(assign_font_dimen):
2003     case any_mode(assign_font_int):
2004     case any_mode(set_aux):
2005     case any_mode(set_prev_graf):
2006     case any_mode(set_page_dimen):
2007     case any_mode(set_page_int):
2008     case any_mode(set_box_dimen):
2009     case any_mode(set_shape):
2010     case any_mode(def_code):
2011     case any_mode(def_family):
2012     case any_mode(set_font):
2013     case any_mode(def_font):
2014     case any_mode(tex_register):
2015     case any_mode(advance):
2016     case any_mode(multiply):
2017     case any_mode(divide):
2018     case any_mode(prefix):
2019     case any_mode(let):
2020     case any_mode(shorthand_def):
2021     case any_mode(read_to_cs):
2022     case any_mode(def):
2023     case any_mode(set_box):
2024     case any_mode(hyph_data):
2025     case any_mode(set_interaction):
2026       prefixed_command();
2027       break;
2028
2029     case any_mode(after_assignment):
2030       {
2031         get_token();
2032         after_token = cur_tok;
2033       }
2034       break;
2035
2036     case any_mode(after_group):
2037       {
2038         get_token();
2039         save_for_after(cur_tok);
2040       }
2041       break;
2042
2043     case any_mode(in_stream):
2044       open_or_close_in();
2045       break;
2046
2047     case any_mode(message):
2048       issue_message();
2049       break;
2050
2051     case any_mode(case_shift):
2052       shift_case();
2053       break;
2054
2055     case any_mode(xray):
2056       show_whatever();
2057       break;
2058
2059     case any_mode(extension):
2060       do_extension();
2061       break;
2062   } /* end of big switch */
2063   goto lab60; /*  main_loop */
2064
2065 lab70:
2066   adjust_space_factor();
2067   main_f = cur_font;
2068   bchar = font_bchar[main_f];
2069   false_bchar = font_false_bchar[main_f];
2070
2071   if (mode > 0)
2072     if (language != clang)
2073       fix_language();
2074   {
2075     lig_stack = avail;
2076
2077     if (lig_stack == 0)
2078       lig_stack = get_avail();
2079     else
2080     {
2081       avail = mem[lig_stack].hh.v.RH;
2082       mem[lig_stack].hh.v.RH = 0;
2083 #ifdef STAT
2084       incr(dyn_used);
2085 #endif /* STAT */
2086     }
2087   }
2088
2089   font(lig_stack) = main_f;
2090   cur_l = cur_chr;
2091   character(lig_stack) = cur_l;
2092   cur_q = tail;
2093
2094   if (cancel_boundary)
2095   {
2096     cancel_boundary = false;
2097     main_k = non_address;
2098   }
2099   else
2100     main_k = bchar_label[main_f];
2101
2102   if (main_k == non_address)
2103     goto lab92;
2104
2105   cur_r = cur_l;
2106   cur_l = non_char;
2107   goto lab111;
2108
2109 lab80: 
2110   wrapup(rt_hit);
2111
2112 /*  main_loop_move */
2113 lab90:
2114   if (lig_stack == 0)
2115     goto lab21;
2116
2117   cur_q = tail;
2118   cur_l = character(lig_stack);
2119
2120 lab91:
2121   if (!(lig_stack >= hi_mem_min))
2122     goto lab95;
2123
2124 lab92:
2125   if ((cur_chr < font_bc[main_f]) || (cur_chr > font_ec[main_f]))
2126   {
2127     char_warning(main_f, cur_chr);
2128     free_avail(lig_stack);
2129     goto lab60;
2130   }
2131
2132   main_i = char_info(main_f, cur_l);
2133
2134   if (!(main_i.b0 > 0))
2135   {
2136     char_warning(main_f, cur_chr);
2137     free_avail(lig_stack);
2138     goto lab60; 
2139   }
2140   {
2141     link(tail) = lig_stack;
2142     tail = lig_stack;
2143   }
2144
2145 /*  main_loop_lookahead */
2146 lab100:
2147   get_next();
2148
2149   if (cur_cmd == letter)
2150     goto lab101;
2151   if (cur_cmd == other_char)
2152     goto lab101;
2153   if (cur_cmd == char_given)
2154     goto lab101;
2155
2156   x_token();
2157
2158   if (cur_cmd == letter)
2159     goto lab101;
2160   if (cur_cmd == other_char)
2161     goto lab101;
2162   if (cur_cmd == char_given)
2163     goto lab101;
2164
2165   if (cur_cmd == char_num)
2166   {
2167     scan_char_num();
2168     cur_chr = cur_val;
2169     goto lab101;
2170   }
2171
2172   if (cur_cmd == no_boundary)
2173     bchar = non_char;
2174
2175   cur_r = bchar;
2176   lig_stack = 0;
2177   goto lab110;
2178
2179 lab101:
2180   adjust_space_factor();
2181
2182   {
2183     lig_stack = avail;
2184
2185     if (lig_stack == 0)
2186       lig_stack = get_avail();
2187     else
2188     {
2189       avail = mem[lig_stack].hh.v.RH;
2190       mem[lig_stack].hh.v.RH = 0;
2191 #ifdef STAT
2192       incr(dyn_used);
2193 #endif /* STAT */
2194     }
2195   }
2196
2197   font(lig_stack) = main_f;
2198   cur_r = cur_chr;
2199   character(lig_stack) = cur_r;
2200
2201   if (cur_r == false_bchar)
2202     cur_r = non_char;
2203
2204 // main_lig_loop:@<If there's a ligature/kern command relevant to |cur_l| and
2205 //  |cur_r|, adjust the text appropriately; exit to |main_loop_wrapup|@>;
2206 lab110:
2207
2208   if (char_tag(main_i) != lig_tag)
2209     goto lab80;
2210
2211   if (cur_r == non_char)
2212     goto lab80;
2213
2214   main_k = lig_kern_start(main_f, main_i);
2215   main_j = font_info[main_k].qqqq;
2216
2217   if (skip_byte(main_j) <= stop_flag)
2218     goto lab112;
2219
2220   main_k = lig_kern_restart(main_f, main_j);
2221
2222 /* main_lig_loop+1:main_j:=font_info[main_k].qqqq; */
2223 lab111:
2224   main_j = font_info[main_k].qqqq;
2225
2226 lab112:
2227 /* provide for suppression of f-ligatures 99/Jan/5 */
2228   bSuppress = 0;
2229
2230   if (suppress_f_ligs && next_char(main_j) == cur_r && op_byte(main_j) == no_tag)
2231   {
2232     if (cur_l == 'f')
2233       bSuppress = 1;
2234   }
2235
2236   if (next_char(main_j) == cur_r && bSuppress == 0)  /* 99/Jan/5 */
2237     if (skip_byte(main_j) <= stop_flag)
2238     {
2239       if (op_byte(main_j) >= kern_flag)
2240       {
2241         wrapup(rt_hit);
2242         tail_append(new_kern(char_kern(main_f, main_j)));
2243         goto lab90;
2244       }
2245
2246       if (cur_l == non_char)
2247         lft_hit = true;
2248       else if (lig_stack == 0)
2249         rt_hit = true;
2250
2251       {
2252         if (interrupt != 0)
2253         {
2254           pause_for_instructions();
2255         }
2256       }
2257
2258       switch (op_byte(main_j))
2259       {
2260         case 1:
2261         case 5:
2262           {
2263             cur_l = rem_byte(main_j);
2264             main_i = char_info(main_f, cur_l);
2265             ligature_present = true;
2266           }
2267           break;
2268         case 2:
2269         case 6:
2270           {
2271             cur_r = rem_byte(main_j);
2272
2273             if (lig_stack == 0)
2274             {
2275               lig_stack = new_lig_item(cur_r);
2276               bchar = non_char;
2277             }
2278             else if ((lig_stack >= hi_mem_min))
2279             {
2280               main_p = lig_stack;
2281               lig_stack = new_lig_item(cur_r);
2282               lig_ptr(lig_stack) = main_p;
2283             }
2284             else
2285               character(lig_stack) = cur_r;
2286           }
2287           break;
2288         case 3:
2289           {
2290             cur_r = rem_byte(main_j);
2291             main_p = lig_stack;
2292             lig_stack = new_lig_item(cur_r);
2293             link(lig_stack) = main_p;
2294           }
2295           break;
2296         case 7:
2297         case 11:
2298           {
2299             wrapup(false);
2300             cur_q = tail;
2301             cur_l = rem_byte(main_j);
2302             main_i = char_info(main_f, cur_l);
2303             ligature_present = true;
2304           }
2305           break;
2306         default:
2307           {
2308             cur_l = rem_byte(main_j);
2309             ligature_present = true;
2310  
2311             if (lig_stack == 0)
2312               goto lab80;
2313             else
2314               goto lab91;
2315           }
2316           break;
2317       }
2318
2319       if (op_byte(main_j) > 4)
2320         if (op_byte(main_j) != 7)
2321           goto lab80;
2322
2323       if (cur_l < non_char)
2324         goto lab110;
2325
2326       main_k = bchar_label[main_f];
2327       goto lab111;
2328     }
2329
2330     if (skip_byte(main_j) == 0)
2331       incr(main_k);
2332     else
2333     {
2334       if (skip_byte(main_j) >= stop_flag)
2335         goto lab80;
2336
2337       main_k = main_k + skip_byte(main_j) + 1;
2338     }
2339
2340     goto lab111;
2341
2342 /*  main_move_log */
2343 lab95:
2344   main_p = lig_ptr(lig_stack);
2345
2346   if (main_p != 0)     /* BUG FIX */
2347     tail_append(main_p);
2348
2349   temp_ptr = lig_stack;
2350   lig_stack = link(temp_ptr);
2351   free_node(temp_ptr, small_node_size);
2352   main_i = char_info(main_f, cur_l);
2353   ligature_present = true;
2354
2355   if (lig_stack == 0)
2356     if (main_p != 0)   /* BUG FIX */
2357       goto lab100;
2358     else
2359       cur_r = bchar;
2360   else
2361     cur_r = character(lig_stack);
2362
2363   goto lab110;
2364
2365 /*  append_normal_space */
2366 lab120:
2367   if (space_skip == 0)
2368   {
2369     {
2370       main_p = font_glue[cur_font];
2371
2372       if (main_p == 0)
2373       {
2374         main_p = new_spec(zero_glue);
2375         main_k = param_base[cur_font] + space_code;
2376         width(main_p) = font_info[main_k].cint;
2377         stretch(main_p) = font_info[main_k + 1].cint;
2378         shrink(main_p) = font_info[main_k + 2].cint;
2379         font_glue[cur_font] = main_p;
2380       }
2381     }
2382     temp_ptr = new_glue(main_p);
2383   }
2384   else
2385     temp_ptr = new_param_glue(space_skip_code);
2386
2387   link(tail) = temp_ptr;
2388   tail = temp_ptr;
2389   goto lab60;
2390 }
2391 /* give_err_help etc followed here in the old tex8.c */