OSDN Git Service

pre-pTeX: tex7.c, tex8.c, tex9.c.
[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 /* *** some changes in above file name handling *** */
974       (!extensionirrelevantp(name_of_file, name_length, "tex")))
975       {
976         name_of_file[name_length + 1] = '.';
977         name_of_file[name_length + 2] = 't';
978         name_of_file[name_length + 3] = 'e';
979         name_of_file[name_length + 4] = 'x';
980         name_of_file[name_length + 5] = ' ';
981         name_length = name_length + 4;
982
983         if (a_open_in(read_file[n], TEXINPUTPATH))
984           read_open[n] = just_open;
985         else
986         {
987           name_length = name_length - 4;      /* remove ".tex" again */
988           name_of_file[name_length + 1] = ' ';
989
990           if ((cur_ext == 335) && a_open_in(read_file[n], TEXINPUTPATH))
991             read_open[n] = 1;
992           else if (maketextex() && a_open_in(read_file[n], TEXINPUTPATH))
993             read_open[n] = 1;
994         }
995       }
996   }
997 }
998 /* sec 1279 */
999 void issue_message (void)
1000 {
1001   char old_setting;
1002   char c;
1003   str_number s;
1004
1005   c = cur_chr;
1006   link(garbage) = scan_toks(false, true);
1007   old_setting = selector;
1008   selector = new_string;
1009   token_show(def_ref);
1010   selector = old_setting;
1011   flush_list(def_ref);
1012   str_room(1);
1013   s = make_string();
1014
1015   if (c == 0)
1016   {
1017     if (term_offset + length(s) > max_print_line - 2)
1018       print_ln();
1019     else if ((term_offset > 0) || (file_offset > 0))
1020       print_char(' ');
1021
1022     slow_print(s);
1023
1024 #ifndef _WINDOWS
1025     fflush(stdout);
1026 #endif
1027   }
1028   else
1029   {
1030     print_err("");
1031     slow_print(s);
1032
1033     if (err_help != 0)
1034       use_err_help = true;
1035     else if (long_help_seen)
1036       help1("(That was another \\errmessage.)");
1037     else
1038     {
1039       if (interaction < error_stop_mode)
1040         long_help_seen = true;
1041
1042       help4("This error message was generated by an \\errmessage",
1043         "command, so I can't give any explicit help.",
1044         "Pretend that you're Hercule Poirot: Examine all clues,",
1045         "and deduce the truth by order and method.");
1046     }
1047
1048     error();
1049     use_err_help = false;
1050   }
1051
1052   flush_string();
1053 }
1054 /* sec 1288 */
1055 void shift_case (void)
1056 {
1057   halfword b;
1058   halfword p;
1059   halfword t;
1060   eight_bits c;
1061
1062   b = cur_chr;
1063   p = scan_toks(false, false);
1064   p = link(def_ref);
1065
1066   while (p != 0)
1067   {
1068     t = info(p); 
1069
1070     if (t < cs_token_flag + single_base)
1071     {
1072       c = t % 256;
1073
1074       if (equiv(b + c) != 0)
1075         info(p) = t - c + equiv(b + c);
1076     }
1077
1078     p = link(p);
1079   }
1080
1081   begin_token_list(link(def_ref), 3);
1082   free_avail(def_ref);
1083 }
1084 /* sec 1293 */
1085 void show_whatever (void)
1086 {
1087   halfword p;
1088
1089   switch(cur_chr)
1090   {
1091     case show_lists:
1092       {
1093         begin_diagnostic();
1094         show_activities();
1095       }
1096       break;
1097
1098     case show_box_code:
1099       {
1100         scan_eight_bit_int();
1101         begin_diagnostic();
1102         print_nl("> \\box");
1103         print_int(cur_val);
1104         print_char('=');
1105
1106         if (box(cur_val) == 0)
1107           print_string("void");
1108         else
1109           show_box(box(cur_val));
1110       }
1111       break;
1112
1113     case show_code:
1114       {
1115         get_token();
1116
1117         if (interaction == error_stop_mode)
1118           ;
1119
1120         print_nl("> ");
1121
1122         if (cur_cs != 0)
1123         {
1124           sprint_cs(cur_cs);
1125           print_char('=');
1126         }
1127
1128         print_meaning();
1129         goto lab50;
1130       }
1131       break;
1132
1133     default:
1134       {
1135         p = the_toks();
1136
1137         if (interaction == error_stop_mode)
1138           ;
1139
1140         print_nl("> ");
1141         token_show(temp_head);
1142         flush_list(link(temp_head));
1143         goto lab50;
1144       }
1145       break;
1146   }
1147
1148   end_diagnostic(true);
1149   print_err("OK");
1150
1151   if (selector == term_and_log)
1152     if (tracing_online <= 0)
1153     {
1154       selector = term_only;
1155       print_string(" (see the transcript file)");
1156       selector = term_and_log;
1157     }
1158
1159 lab50:
1160
1161   if (interaction < error_stop_mode)
1162   {
1163     help_ptr = 0;
1164     decr(error_count);
1165   }
1166   else if (tracing_online > 0)
1167   {
1168     help3("This isn't an error message; I'm just \\showing something.",
1169       "Type `I\\show...' to show more (e.g., \\show\\cs,",
1170       "\\showthe\\count10, \\showbox255, \\showlists).");
1171   }
1172   else
1173   {
1174     help5("This isn't an error message; I'm just \\showing something.",
1175       "Type `I\\show...' to show more (e.g., \\show\\cs,",
1176       "\\showthe\\count10, \\showbox255, \\showlists).",
1177       "And type `I\\tracingonline=1\\show...' to show boxes and",
1178       "lists on your terminal as well as in the transcript file.");
1179   }
1180   error();
1181 }
1182 /* sec 1349 */
1183 void new_whatsit_(small_number s, small_number w)
1184 {
1185   halfword p;
1186
1187   p = get_node(w);
1188   type(p) = whatsit_node;
1189   subtype(p) = s;
1190   link(tail) = p;
1191   tail = p;
1192 }
1193 /* sec 1350 */
1194 void new_write_whatsit_(small_number w)
1195 {
1196   new_whatsit(cur_chr, w);
1197
1198   if (w != write_node_size)
1199   {
1200     scan_four_bit_int();
1201   }
1202   else
1203   {
1204     scan_int();
1205
1206     if (cur_val < 0)
1207       cur_val = 17;
1208     else if (cur_val > 15)
1209       cur_val = 16;
1210   }
1211
1212   write_stream(tail) = cur_val;
1213 }
1214 /* sec 1348 */
1215 void do_extension (void)
1216 {
1217 /*  integer i, j, k;  */
1218   integer k;
1219 /*  halfword p, q, r;  */
1220   halfword p;
1221
1222   switch(cur_chr)
1223   {
1224     case open_node:
1225       {
1226         new_write_whatsit(open_node_size);
1227         scan_optional_equals();
1228         scan_file_name();
1229         open_name(tail) = cur_name;
1230         open_area(tail) = cur_area;
1231         open_ext(tail) = cur_ext;
1232       }
1233       break;
1234
1235     case write_node:
1236       {
1237         k = cur_cs;
1238         new_write_whatsit(write_node_size);
1239         cur_cs = k;
1240         p = scan_toks(false, false);
1241         write_tokens(tail) = def_ref;
1242       }
1243       break;
1244
1245     case close_node:
1246       {
1247         new_write_whatsit(write_node_size);
1248         write_tokens(tail) = 0;
1249       }
1250       break;
1251
1252     case special_node:
1253       {
1254         new_whatsit(special_node, write_node_size);
1255         write_stream(tail) = 0;
1256         p = scan_toks(false, true);
1257         write_tokens(tail) = def_ref;
1258       }
1259       break;
1260
1261     case immediate_code:
1262       {
1263         get_x_token();
1264
1265         if ((cur_cmd == extension) && (cur_chr <= close_node))
1266         {
1267           p = tail;
1268           do_extension();
1269           out_what(tail);
1270           flush_node_list(tail);
1271           tail = p;
1272           link(p) = 0;
1273         }
1274         else
1275           back_input();
1276       }
1277       break;
1278
1279     case set_language_code:
1280       if (abs(mode) != hmode)
1281       {
1282         report_illegal_case();
1283       }
1284       else
1285       {
1286         new_whatsit(language_node, small_node_size);
1287         scan_int();
1288
1289         if (cur_val <= 0)
1290           clang = 0;
1291         else if (cur_val > 255)
1292           clang = 0;
1293         else
1294           clang = cur_val;
1295
1296         what_lang(tail) = clang;
1297         what_lhm(tail) = norm_min(left_hyphen_min);
1298         what_rhm(tail) = norm_min(right_hyphen_min);
1299       }
1300       break;
1301
1302     default:
1303       {
1304         confusion("ext1");
1305         return;       // abort_flag set
1306       }
1307       break;
1308   }
1309 }
1310 /* sec 1376 */
1311 void fix_language (void)
1312 {
1313 /*  ASCII_code l;  */
1314   int l;                  /* 95/Jan/7 */
1315
1316   if (language <= 0)
1317     l = 0; 
1318   else if (language > 255)
1319     l = 0;
1320   else
1321     l = language;
1322
1323   if (l != clang)
1324   {
1325     new_whatsit(language_node, small_node_size);
1326     what_lang(tail) = l;
1327     clang = l;
1328     what_lhm(tail) = norm_min(left_hyphen_min);
1329     what_rhm(tail) = norm_min(right_hyphen_min);
1330   }
1331 }
1332 /* sec 1068 */
1333 void handle_right_brace (void)
1334 {
1335   halfword p, q;
1336   scaled d;
1337   integer f;
1338
1339   switch(cur_group)
1340   {
1341     case simple_group:
1342       unsave();
1343       break;
1344
1345     case bottom_level:
1346       {
1347         print_err("Too many }'s");
1348         help2("You've closed more groups than you opened.",
1349           "Such booboos are generally harmless, so keep going.");
1350         error();
1351       }
1352       break;
1353
1354     case semi_simple_group:
1355     case math_shift_group:
1356     case math_left_group:
1357       extra_right_brace();
1358       break;
1359
1360     case hbox_group:
1361       package(0);
1362       break;
1363
1364     case adjust_hbox_group:
1365       {
1366         adjust_tail = adjust_head;
1367         package(0);
1368       }
1369       break;
1370
1371     case vbox_group:
1372       {
1373         end_graf();
1374         package(0);
1375       }
1376       break;
1377
1378     case vtop_group:
1379       {
1380         end_graf();
1381         package(vtop_code);
1382       }
1383       break;
1384
1385     case insert_group:
1386       {
1387         end_graf();
1388         q = split_top_skip;
1389         add_glue_ref(q);
1390         d = split_max_depth;
1391         f = floating_penalty;
1392         unsave();
1393         decr(save_ptr);
1394         p = vpackage(link(head), 0, 1, 1073741823L);  /* 2^30 - 1 */
1395         pop_nest();
1396
1397         if (saved(0) < 255)
1398         {
1399           tail_append(get_node(ins_node_size));
1400           type(tail) = ins_node;
1401           subtype(tail) = saved(0);
1402           height(tail) = height(p) + depth(p);
1403           ins_ptr(tail) = list_ptr(p);
1404           split_top_ptr(tail) = q;
1405           depth(tail) = d;
1406           float_cost(tail) = f;
1407         }
1408         else
1409         {
1410           tail_append(get_node(small_node_size));
1411           type(tail) = adjust_node;
1412           subtype(tail) = 0;
1413           adjust_ptr(tail) = list_ptr(p);
1414           delete_glue_ref(q);
1415         }
1416         free_node(p, box_node_size);
1417
1418         if (nest_ptr == 0)
1419         {
1420           build_page();
1421         }
1422       }
1423       break;
1424     case output_group:
1425       {
1426         if ((cur_input.loc_field != 0) || ((token_type != output_text) && (token_type != backed_up)))
1427         {
1428           print_err("Unbalanced output routine");
1429           help2("Your sneaky output routine has problematic {'s and/or }'s.",
1430             "I can't handle that very well; good luck.");
1431           error();
1432
1433           do
1434             {
1435               get_token();
1436             }
1437           while (!(cur_input.loc_field == 0));
1438         }
1439
1440         end_token_list();
1441         end_graf();
1442         unsave();
1443         output_active = false;
1444         insert_penalties = 0;
1445
1446         if (box(255) != 0)
1447         {
1448           print_err("Output routine didn't use all of ");
1449           print_esc("box");
1450           print_int(255);
1451           help3("Your \\output commands should empty \\box255,",
1452             "e.g., by saying `\\shipout\\box255'.",
1453             "Proceed; I'll discard its present contents.");
1454           box_error(255);
1455         }
1456
1457         if (tail != head)
1458         {
1459           link(page_tail) = link(head);
1460           page_tail = tail;
1461         }
1462
1463         if (link(page_head) != 0)
1464         {
1465           if (link(contrib_head) == 0)
1466             nest[0].tail_field = page_tail;
1467
1468           link(page_tail) = link(contrib_head);
1469           link(contrib_head) = link(page_head);
1470           link(page_head) = 0;
1471           page_tail = page_head;
1472         }
1473         pop_nest();
1474         build_page();
1475       }
1476       break;
1477
1478     case disc_group:
1479       build_discretionary();
1480       break;
1481
1482     case align_group:
1483       {
1484         back_input();
1485         cur_tok = cs_token_flag + frozen_cr;
1486         print_err("Missing ");
1487         print_esc("cr");
1488         print_string("inserted");
1489         help1("I'm guessing that you meant to end an alignment here.");
1490         ins_error();
1491       }
1492       break;
1493
1494     case no_align_group:
1495       {
1496         end_graf();
1497         unsave();
1498         align_peek();
1499       }
1500       break;
1501
1502     case vcenter_group:
1503       {
1504         end_graf();
1505         unsave();
1506         save_ptr = save_ptr - 2;
1507         p = vpackage(link(head), saved(1), saved(0), 1073741823L);   /* 2^30 - 1 */
1508         pop_nest();
1509         tail_append(new_noad());
1510         type(tail) = vcenter_noad;
1511         math_type(nucleus(tail)) = sub_box;
1512         info(nucleus(tail)) = p;
1513       }
1514       break;
1515
1516     case math_choice_group:
1517       build_choices();
1518       break;
1519
1520     case math_group:
1521       {
1522         unsave();
1523         decr(save_ptr);
1524         math_type(saved(0)) = sub_mlist;
1525         p = fin_mlist(0);
1526         info(saved(0)) = p;
1527
1528         if (p != 0)
1529           if (link(p) == 0)
1530             if (type(p) == ord_noad)
1531             {
1532               if (math_type(subscr(p)) == 0)
1533                 if (math_type(supscr(p)) == 0)
1534                 {
1535                   mem[saved(0)].hh = mem[nucleus(p)].hh;
1536                   free_node(p, noad_size);
1537                 }
1538             }
1539             else if (type(p) == accent_noad)
1540               if (saved(0) == nucleus(tail))
1541                 if (type(tail) == ord_noad)
1542                 {
1543                   q = head;
1544
1545                   while(link(q) != tail)
1546                     q = link(q);
1547
1548                   link(q) = p;
1549                   free_node(tail, noad_size);
1550                   tail = p;
1551                 }
1552       }
1553       break;
1554     default:
1555       {
1556         confusion("rightbrace");
1557         return;       // abort_flag set
1558       }
1559       break;
1560   }
1561 }
1562 /* sec 1030 */
1563 void main_control (void) 
1564 {
1565   integer t;
1566   integer bSuppress; /* 199/Jan/5 */
1567
1568   if (every_job != 0)
1569     begin_token_list(every_job, every_job_text);
1570
1571 lab60:
1572   get_x_token();       /* big_switch */
1573
1574 lab21:
1575   if (interrupt != 0)
1576     if (OK_to_interrupt)
1577     {
1578       back_input();
1579       {
1580         if (interrupt != 0)
1581         {
1582           pause_for_instructions();
1583         }
1584       }
1585       goto lab60;
1586     }
1587
1588 #ifdef DEBUG
1589   if (panicking)
1590     check_mem(false);
1591 #endif
1592
1593   if (tracing_commands > 0)
1594     show_cur_cmd_chr();
1595
1596 /*  the big switch --- don't bother to test abort_flag ??? */
1597   switch(abs(mode) + cur_cmd)
1598   {
1599     case hmode + letter:
1600     case hmode + other_char:
1601     case hmode + char_given:
1602       goto lab70;
1603       break;
1604
1605     case hmode + char_num:
1606       {
1607         scan_char_num();
1608         cur_chr = cur_val;
1609         goto lab70;
1610       }
1611       break;
1612
1613     case hmode + no_boundary:
1614       {
1615         get_x_token();
1616
1617         if ((cur_cmd == letter) || (cur_cmd == other_char) ||
1618           (cur_cmd == char_given) || (cur_cmd == char_num))
1619           cancel_boundary = true;
1620         goto lab21;
1621       }
1622       break;
1623
1624     case hmode + spacer:
1625       if (space_factor == 1000)
1626         goto lab120;
1627       else
1628         app_space();
1629       break;
1630
1631     case hmode + ex_space:
1632     case mmode + ex_space:
1633       goto lab120;
1634       break;
1635
1636     case any_mode(relax):
1637     case vmode + spacer:
1638     case mmode + spacer:
1639     case mmode + no_boundary:
1640       ;
1641       break;
1642
1643     case any_mode(ignore_spaces):
1644       {
1645         do
1646           {
1647             get_x_token();
1648           }
1649         while(!(cur_cmd != spacer));
1650         goto lab21;
1651       }
1652       break;
1653
1654     case vmode + stop:
1655       if (its_all_over())
1656         return;
1657       break;
1658
1659     case vmode + vmove:
1660     case hmode + hmove:
1661     case mmode + hmove:
1662     case any_mode(last_item):
1663     case vmode + vadjust:
1664     case vmode + ital_corr:
1665     case non_math(eq_no):
1666     case any_mode(mac_param):
1667       report_illegal_case();
1668       break;
1669
1670     case non_math(sup_mark):
1671     case non_math(sub_mark):
1672     case non_math(math_char_num):
1673     case non_math(math_given):
1674     case non_math(math_comp):
1675     case non_math(delim_num):
1676     case non_math(left_right):
1677     case non_math(above):
1678     case non_math(radical):
1679     case non_math(math_style):
1680     case non_math(math_choice):
1681     case non_math(vcenter):
1682     case non_math(non_script):
1683     case non_math(mkern):
1684     case non_math(limit_switch):
1685     case non_math(mskip):
1686     case non_math(math_accent):
1687     case mmode + endv:
1688     case mmode + par_end:
1689     case mmode + stop:
1690     case mmode + vskip:
1691     case mmode + un_vbox:
1692     case mmode + valign:
1693     case mmode + hrule:
1694       insert_dollar_sign();
1695       break;
1696
1697     case vmode + hrule:
1698     case hmode + vrule:
1699     case mmode + vrule:
1700       {
1701         tail_append(scan_rule_spec());
1702
1703         if (abs(mode) == vmode)
1704           prev_depth = ignore_depth;
1705         else if (abs(mode) == hmode)
1706           space_factor = 1000;
1707       }
1708       break;
1709
1710     case vmode + vskip:
1711     case hmode + hskip:
1712     case mmode + hskip:
1713     case mmode + mskip:
1714       append_glue();
1715       break;
1716
1717     case any_mode(kern):
1718     case mmode + mkern:
1719       append_kern();
1720       break;
1721
1722     case non_math(left_brace):
1723       new_save_level(simple_group);
1724       break;
1725
1726     case any_mode(begin_group):
1727       new_save_level(semi_simple_group);
1728       break;
1729
1730     case any_mode(end_group):
1731       if (cur_group == semi_simple_group)
1732         unsave();
1733       else
1734         off_save();
1735       break;
1736
1737     case any_mode(right_brace):
1738       handle_right_brace();
1739       break;
1740
1741     case vmode + hmove:
1742     case hmode + vmove:
1743     case mmode + vmove:
1744       {
1745         t = cur_chr;
1746         scan_dimen(false, false, false);
1747
1748         if (t == 0)
1749           scan_box(cur_val);
1750         else
1751           scan_box(- (integer) cur_val);
1752       }
1753       break;
1754
1755     case any_mode(leader_ship):
1756       scan_box(leader_flag - a_leaders + cur_chr);
1757       break;
1758
1759     case any_mode(make_box):
1760       begin_box(0);
1761       break;
1762
1763     case vmode + start_par:
1764       new_graf(cur_chr > 0);
1765       break;
1766
1767     case vmode + letter:
1768     case vmode + other_char:
1769     case vmode + char_num:
1770     case vmode + char_given:
1771     case vmode + math_shift:
1772     case vmode + un_hbox:
1773     case vmode + vrule:
1774     case vmode + accent:
1775     case vmode + discretionary:
1776     case vmode + hskip:
1777     case vmode + valign:
1778     case vmode + ex_space:
1779     case vmode + no_boundary:
1780       {
1781         back_input();
1782         new_graf(true);
1783       }
1784       break;
1785
1786     case hmode + start_par:
1787     case mmode + start_par:
1788       indent_in_hmode();
1789       break;
1790
1791     case vmode + par_end:
1792       {
1793         normal_paragraph();
1794
1795         if (mode > 0)
1796           build_page();
1797       }
1798       break;
1799
1800     case hmode + par_end:
1801       {
1802         if (align_state < 0)
1803           off_save();
1804
1805         end_graf();
1806
1807         if (mode == 1)
1808           build_page();
1809       }
1810       break;
1811
1812     case hmode + stop:
1813     case hmode + vskip:
1814     case hmode + hrule:
1815     case hmode + un_vbox:
1816     case hmode + halign:
1817       head_for_vmode();
1818       break;
1819
1820     case any_mode(insert):
1821     case hmode + vadjust:
1822     case mmode + vadjust:
1823       begin_insert_or_adjust();
1824       break;
1825
1826     case any_mode(mark):
1827       make_mark();
1828       break;
1829
1830     case any_mode(break_penalty):
1831       append_penalty();
1832       break;
1833
1834     case any_mode(remove_item):
1835       delete_last();
1836       break;
1837
1838     case vmode + un_vbox:
1839     case hmode + un_hbox:
1840     case mmode + un_hbox:
1841       unpackage();
1842       break;
1843
1844     case hmode + ital_corr:
1845       append_italic_correction();
1846       break;
1847
1848     case mmode + ital_corr:
1849       tail_append(new_kern(0));
1850       break;
1851
1852     case hmode + discretionary:
1853     case mmode + discretionary:
1854       append_discretionary();
1855       break;
1856
1857     case hmode + accent:
1858       make_accent();
1859       break;
1860
1861     case any_mode(car_ret):
1862     case any_mode(tab_mark):
1863       align_error();
1864       break;
1865
1866     case any_mode(no_align):
1867       noalign_error();
1868       break;
1869
1870     case any_mode(omit):
1871       omit_error();
1872       break;
1873
1874     case vmode + halign:
1875     case hmode + valign:
1876       init_align();
1877       break;
1878
1879     case mmode + halign:
1880       if (privileged ())
1881         if (cur_group == math_shift_group)
1882           init_align();
1883         else
1884           off_save();
1885       break;
1886
1887     case vmode + endv:
1888     case hmode + endv:
1889       do_endv();
1890       break;
1891
1892     case any_mode(end_cs_name):
1893       cs_error();
1894       break;
1895
1896     case hmode + math_shift:
1897       init_math();
1898       break;
1899
1900     case mmode + eq_no:
1901       if (privileged ())
1902         if (cur_group == math_shift_group)
1903           start_eq_no();
1904         else
1905           off_save();
1906       break;
1907
1908     case mmode + left_brace:
1909       {
1910         tail_append(new_noad());
1911         back_input();
1912         scan_math(nucleus(tail));
1913       }
1914       break;
1915
1916     case mmode + letter:
1917     case mmode + other_char:
1918     case mmode + char_given:
1919       set_math_char(math_code(cur_chr));
1920       break;
1921
1922     case mmode + char_num:
1923       {
1924         scan_char_num();
1925         cur_chr = cur_val;
1926         set_math_char(math_code(cur_chr));
1927       }
1928       break;
1929
1930     case mmode + math_char_num:
1931       {
1932         scan_fifteen_bit_int();
1933         set_math_char(cur_val);
1934       }
1935       break;
1936
1937     case mmode + math_given:
1938       set_math_char(cur_chr);
1939       break;
1940
1941     case mmode + delim_num:
1942       {
1943         scan_twenty_seven_bit_int();
1944         set_math_char(cur_val / 4096);
1945       }
1946       break;
1947
1948     case mmode + math_comp:
1949       {
1950         tail_append(new_noad());
1951         type(tail) = cur_chr;
1952         scan_math(nucleus(tail));
1953       }
1954       break;
1955
1956     case mmode + limit_switch:
1957       math_limit_switch();
1958       break;
1959
1960     case mmode + radical:
1961       math_radical();
1962       break;
1963
1964     case mmode + accent:
1965     case mmode + math_accent:
1966       math_ac();
1967       break;
1968
1969     case mmode + vcenter:
1970       {
1971         scan_spec(vcenter_group, false);
1972         normal_paragraph();
1973         push_nest();
1974         mode = -1;
1975         prev_depth = ignore_depth;
1976
1977         if (every_vbox != 0)
1978           begin_token_list(every_vbox, every_vbox_text);
1979       }
1980       break;
1981
1982     case mmode + math_style:
1983       tail_append(new_style(cur_chr));
1984       break;
1985
1986     case mmode + non_script:
1987       {
1988         tail_append(new_glue(0));
1989         subtype(tail) = cond_math_glue;
1990       }
1991       break;
1992
1993     case mmode + math_choice:
1994       append_choices();
1995       break;
1996
1997     case mmode + sub_mark:
1998     case mmode + sup_mark:
1999       sub_sup();
2000       break;
2001
2002     case mmode + above:
2003       math_fraction();
2004       break;
2005
2006     case mmode + left_right:
2007       math_left_right();
2008       break;
2009
2010     case mmode + math_shift:
2011       if (cur_group == math_shift_group)
2012         after_math();
2013       else
2014         off_save();
2015       break;
2016
2017     case any_mode(toks_register):
2018     case any_mode(assign_toks):
2019     case any_mode(assign_int):
2020     case any_mode(assign_dimen):
2021     case any_mode(assign_glue):
2022     case any_mode(assign_mu_glue):
2023     case any_mode(assign_font_dimen):
2024     case any_mode(assign_font_int):
2025     case any_mode(set_aux):
2026     case any_mode(set_prev_graf):
2027     case any_mode(set_page_dimen):
2028     case any_mode(set_page_int):
2029     case any_mode(set_box_dimen):
2030     case any_mode(set_shape):
2031     case any_mode(def_code):
2032     case any_mode(def_family):
2033     case any_mode(set_font):
2034     case any_mode(def_font):
2035     case any_mode(tex_register):
2036     case any_mode(advance):
2037     case any_mode(multiply):
2038     case any_mode(divide):
2039     case any_mode(prefix):
2040     case any_mode(let):
2041     case any_mode(shorthand_def):
2042     case any_mode(read_to_cs):
2043     case any_mode(def):
2044     case any_mode(set_box):
2045     case any_mode(hyph_data):
2046     case any_mode(set_interaction):
2047       prefixed_command();
2048       break;
2049
2050     case any_mode(after_assignment):
2051       {
2052         get_token();
2053         after_token = cur_tok;
2054       }
2055       break;
2056
2057     case any_mode(after_group):
2058       {
2059         get_token();
2060         save_for_after(cur_tok);
2061       }
2062       break;
2063
2064     case any_mode(in_stream):
2065       open_or_close_in();
2066       break;
2067
2068     case any_mode(message):
2069       issue_message();
2070       break;
2071
2072     case any_mode(case_shift):
2073       shift_case();
2074       break;
2075
2076     case any_mode(xray):
2077       show_whatever();
2078       break;
2079
2080     case any_mode(extension):
2081       do_extension();
2082       break;
2083   } /* end of big switch */
2084   goto lab60; /*  main_loop */
2085
2086 lab70:
2087   adjust_space_factor();
2088   main_f = cur_font;
2089   bchar = font_bchar[main_f];
2090   false_bchar = font_false_bchar[main_f];
2091
2092   if (mode > 0)
2093     if (language != clang)
2094       fix_language();
2095   {
2096     lig_stack = avail;
2097
2098     if (lig_stack == 0)
2099       lig_stack = get_avail();
2100     else
2101     {
2102       avail = mem[lig_stack].hh.v.RH;
2103       mem[lig_stack].hh.v.RH = 0;
2104 #ifdef STAT
2105       incr(dyn_used);
2106 #endif /* STAT */
2107     }
2108   }
2109
2110   font(lig_stack) = main_f;
2111   cur_l = cur_chr;
2112   character(lig_stack) = cur_l;
2113   cur_q = tail;
2114
2115   if (cancel_boundary)
2116   {
2117     cancel_boundary = false;
2118     main_k = non_address;
2119   }
2120   else
2121     main_k = bchar_label[main_f];
2122
2123   if (main_k == non_address)
2124     goto lab92;
2125
2126   cur_r = cur_l;
2127   cur_l = non_char;
2128   goto lab111;
2129
2130 lab80: 
2131   wrapup(rt_hit);
2132
2133 /*  main_loop_move */
2134 lab90:
2135   if (lig_stack == 0)
2136     goto lab21;
2137
2138   cur_q = tail;
2139   cur_l = character(lig_stack);
2140
2141 lab91:
2142   if (!(lig_stack >= hi_mem_min))
2143     goto lab95;
2144
2145 lab92:
2146   if ((cur_chr < font_bc[main_f]) || (cur_chr > font_ec[main_f]))
2147   {
2148     char_warning(main_f, cur_chr);
2149     free_avail(lig_stack);
2150     goto lab60;
2151   }
2152
2153   main_i = char_info(main_f, cur_l);
2154
2155   if (!(main_i.b0 > 0))
2156   {
2157     char_warning(main_f, cur_chr);
2158     free_avail(lig_stack);
2159     goto lab60; 
2160   }
2161   {
2162     link(tail) = lig_stack;
2163     tail = lig_stack;
2164   }
2165
2166 /*  main_loop_lookahead */
2167 lab100:
2168   get_next();
2169
2170   if (cur_cmd == letter)
2171     goto lab101;
2172   if (cur_cmd == other_char)
2173     goto lab101;
2174   if (cur_cmd == char_given)
2175     goto lab101;
2176
2177   x_token();
2178
2179   if (cur_cmd == letter)
2180     goto lab101;
2181   if (cur_cmd == other_char)
2182     goto lab101;
2183   if (cur_cmd == char_given)
2184     goto lab101;
2185
2186   if (cur_cmd == char_num)
2187   {
2188     scan_char_num();
2189     cur_chr = cur_val;
2190     goto lab101;
2191   }
2192
2193   if (cur_cmd == no_boundary)
2194     bchar = non_char;
2195
2196   cur_r = bchar;
2197   lig_stack = 0;
2198   goto lab110;
2199
2200 lab101:
2201   adjust_space_factor();
2202
2203   {
2204     lig_stack = avail;
2205
2206     if (lig_stack == 0)
2207       lig_stack = get_avail();
2208     else
2209     {
2210       avail = mem[lig_stack].hh.v.RH;
2211       mem[lig_stack].hh.v.RH = 0;
2212 #ifdef STAT
2213       incr(dyn_used);
2214 #endif /* STAT */
2215     }
2216   }
2217
2218   font(lig_stack) = main_f;
2219   cur_r = cur_chr;
2220   character(lig_stack) = cur_r;
2221
2222   if (cur_r == false_bchar)
2223     cur_r = non_char;
2224
2225 // main_lig_loop:@<If there's a ligature/kern command relevant to |cur_l| and
2226 //  |cur_r|, adjust the text appropriately; exit to |main_loop_wrapup|@>;
2227 lab110:
2228
2229   if (char_tag(main_i) != lig_tag)
2230     goto lab80;
2231
2232   if (cur_r == non_char)
2233     goto lab80;
2234
2235   main_k = lig_kern_start(main_f, main_i);
2236   main_j = font_info[main_k].qqqq;
2237
2238   if (skip_byte(main_j) <= stop_flag)
2239     goto lab112;
2240
2241   main_k = lig_kern_restart(main_f, main_j);
2242
2243 /* main_lig_loop+1:main_j:=font_info[main_k].qqqq; */
2244 lab111:
2245   main_j = font_info[main_k].qqqq;
2246
2247 lab112:
2248 /* provide for suppression of f-ligatures 99/Jan/5 */
2249   bSuppress = 0;
2250
2251   if (suppress_f_ligs && next_char(main_j) == cur_r && op_byte(main_j) == no_tag)
2252   {
2253     if (cur_l == 'f')
2254       bSuppress = 1;
2255   }
2256
2257   if (next_char(main_j) == cur_r && bSuppress == 0)  /* 99/Jan/5 */
2258     if (skip_byte(main_j) <= stop_flag)
2259     {
2260       if (op_byte(main_j) >= kern_flag)
2261       {
2262         wrapup(rt_hit);
2263         tail_append(new_kern(char_kern(main_f, main_j)));
2264         goto lab90;
2265       }
2266
2267       if (cur_l == non_char)
2268         lft_hit = true;
2269       else if (lig_stack == 0)
2270         rt_hit = true;
2271
2272       {
2273         if (interrupt != 0)
2274         {
2275           pause_for_instructions();
2276         }
2277       }
2278
2279       switch (op_byte(main_j))
2280       {
2281         case 1:
2282         case 5:
2283           {
2284             cur_l = rem_byte(main_j);
2285             main_i = char_info(main_f, cur_l);
2286             ligature_present = true;
2287           }
2288           break;
2289         case 2:
2290         case 6:
2291           {
2292             cur_r = rem_byte(main_j);
2293
2294             if (lig_stack == 0)
2295             {
2296               lig_stack = new_lig_item(cur_r);
2297               bchar = non_char;
2298             }
2299             else if ((lig_stack >= hi_mem_min))
2300             {
2301               main_p = lig_stack;
2302               lig_stack = new_lig_item(cur_r);
2303               lig_ptr(lig_stack) = main_p;
2304             }
2305             else
2306               character(lig_stack) = cur_r;
2307           }
2308           break;
2309         case 3:
2310           {
2311             cur_r = rem_byte(main_j);
2312             main_p = lig_stack;
2313             lig_stack = new_lig_item(cur_r);
2314             link(lig_stack) = main_p;
2315           }
2316           break;
2317         case 7:
2318         case 11:
2319           {
2320             wrapup(false);
2321             cur_q = tail;
2322             cur_l = rem_byte(main_j);
2323             main_i = char_info(main_f, cur_l);
2324             ligature_present = true;
2325           }
2326           break;
2327         default:
2328           {
2329             cur_l = rem_byte(main_j);
2330             ligature_present = true;
2331  
2332             if (lig_stack == 0)
2333               goto lab80;
2334             else
2335               goto lab91;
2336           }
2337           break;
2338       }
2339
2340       if (op_byte(main_j) > 4)
2341         if (op_byte(main_j) != 7)
2342           goto lab80;
2343
2344       if (cur_l < non_char)
2345         goto lab110;
2346
2347       main_k = bchar_label[main_f];
2348       goto lab111;
2349     }
2350
2351     if (skip_byte(main_j) == 0)
2352       incr(main_k);
2353     else
2354     {
2355       if (skip_byte(main_j) >= stop_flag)
2356         goto lab80;
2357
2358       main_k = main_k + skip_byte(main_j) + 1;
2359     }
2360
2361     goto lab111;
2362
2363 /*  main_move_log */
2364 lab95:
2365   main_p = lig_ptr(lig_stack);
2366
2367   if (main_p != 0)     /* BUG FIX */
2368     tail_append(main_p);
2369
2370   temp_ptr = lig_stack;
2371   lig_stack = link(temp_ptr);
2372   free_node(temp_ptr, small_node_size);
2373   main_i = char_info(main_f, cur_l);
2374   ligature_present = true;
2375
2376   if (lig_stack == 0)
2377     if (main_p != 0)   /* BUG FIX */
2378       goto lab100;
2379     else
2380       cur_r = bchar;
2381   else
2382     cur_r = character(lig_stack);
2383
2384   goto lab110;
2385
2386 /*  append_normal_space */
2387 lab120:
2388   if (space_skip == 0)
2389   {
2390     {
2391       main_p = font_glue[cur_font];
2392
2393       if (main_p == 0)
2394       {
2395         main_p = new_spec(zero_glue);
2396         main_k = param_base[cur_font] + space_code;
2397         width(main_p) = font_info[main_k].cint;
2398         stretch(main_p) = font_info[main_k + 1].cint;
2399         shrink(main_p) = font_info[main_k + 2].cint;
2400         font_glue[cur_font] = main_p;
2401       }
2402     }
2403     temp_ptr = new_glue(main_p);
2404   }
2405   else
2406     temp_ptr = new_param_glue(space_skip_code);
2407
2408   link(tail) = temp_ptr;
2409   tail = temp_ptr;
2410   goto lab60;
2411 }
2412 /* give_err_help etc followed here in the old tex8.c */