OSDN Git Service

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