OSDN Git Service

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