-
Notifications
You must be signed in to change notification settings - Fork 3
/
maincontrol.c
4348 lines (3985 loc) · 141 KB
/
maincontrol.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
maincontrol.w
Copyright 2009-2010 Taco Hoekwater <taco@@luatex.org>
This file is part of LuaTeX.
LuaTeX is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
LuaTeX is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
*/
#include "ptexlib.h"
#include "lua/luatex-api.h"
#define mode mode_par
#define tail tail_par
#define head head_par
#define dir_save dirs_par
/*tex
We come now to the |main_control| routine, which contains the master switch that
causes all the various pieces of \TeX\ to do their things, in the right order.
In a sense, this is the grand climax of the program: It applies all the tools
that we have worked so hard to construct. In another sense, this is the messiest
part of the program: It necessarily refers to other pieces of code all over the
place, so that a person can't fully understand what is going on without paging
back and forth to be reminded of conventions that are defined elsewhere. We are
now at the hub of the web, the central nervous system that touches most of the
other parts and ties them together. @^brain@>
The structure of |main_control| itself is quite simple. There's a label called
|big_switch|, at which point the next token of input is fetched using
|get_x_token|. Then the program branches at high speed into one of about 100
possible directions, based on the value of the current mode and the newly fetched
command code; the sum |abs(mode)+cur_cmd| indicates what to do next. For example,
the case `|vmode+letter|' arises when a letter occurs in vertical mode (or
internal vertical mode); this case leads to instructions that initialize a new
paragraph and enter horizontal mode.
The big |case| statement that contains this multiway switch has been labeled
|reswitch|, so that the program can |goto reswitch| when the next token has
already been fetched. Most of the cases are quite short; they call an ``action
procedure'' that does the work for that case, and then they either |goto
reswitch| or they ``fall through'' to the end of the |case| statement, which
returns control back to |big_switch|. Thus, |main_control| is not an extremely
large procedure, in spite of the multiplicity of things it must do; it is small
enough to be handled by PASCAL compilers that put severe restrictions on
procedure size. @!@^action procedure@>
One case is singled out for special treatment, because it accounts for most of
\TeX's activities in typical applications. The process of reading simple text and
converting it into |char_node| records, while looking for ligatures and kerns, is
part of \TeX's ``inner loop''; the whole program runs efficiently when its inner
loop is fast, so this part has been written with particular care.
We leave the |space_factor| unchanged if |sf_code(cur_chr)=0|; otherwise we set
it equal to |sf_code(cur_chr)|, except that it should never change from a value
less than 1000 to a value exceeding 1000. The most common case is
|sf_code(cur_chr)=1000|, so we want that case to be fast.
*/
void adjust_space_factor(void)
{
halfword s = get_sf_code(cur_chr);
if (s == 1000) {
space_factor_par = 1000;
} else if (s < 1000) {
if (s > 0)
space_factor_par = s;
} else if (space_factor_par < 1000) {
space_factor_par = 1000;
} else {
space_factor_par = s;
}
}
/*tex
To handle the execution state of |main_control|'s eternal loop, an extra global
variable is used, along with a macro to define its values.
*/
#define goto_next 0
#define goto_skip_token 1
#define goto_return 2
static int main_control_state;
static int local_level = 0;
/*tex
@* Main control helpers.
Here are all the functions that are called from |main_control| that
are not already defined elsewhere. For the moment, this list simply
in the order that the appear in |init_main_control|, below.
*/
static void run_char_num (void) {
scan_char_num();
cur_chr = cur_val;
adjust_space_factor();
tail_append(new_char(cur_font_par, cur_chr));
}
static void run_char (void) {
adjust_space_factor();
tail_append(new_char(cur_font_par, cur_chr));
}
static void run_node (void) {
halfword n = cur_chr;
if (copy_lua_input_nodes_par) {
n = copy_node_list(n);
}
tail_append(n);
if (nodetype_has_attributes(type(n)) && node_attr(n) == null) {
build_attribute_list(n);
}
while (vlink(n) != null) {
n = vlink(n);
tail_append(n);
if (nodetype_has_attributes(type(n)) && node_attr(n) == null) {
build_attribute_list(n);
}
}
}
static void run_lua_call(void) {
if (cur_chr <= 0) {
normal_error("luacall", "invalid number");
} else {
str_number u = save_cur_string();
luacstrings = 0;
luafunctioncall(cur_chr);
restore_cur_string(u);
if (luacstrings > 0)
lua_string_start();
}
}
/*tex
The occurrence of blank spaces is almost part of \TeX's inner loop, since we
usually encounter about one space for every five non-blank characters. Therefore
|main_control| gives second-highest priority to ordinary spaces.
When a glue parameter like \.{\\spaceskip} is set to `\.{0pt}', we will see to it
later that the corresponding glue specification is precisely |zero_glue|, not
merely a pointer to some specification that happens to be full of zeroes.
Therefore it is simple to test whether a glue parameter is zero or~not.
*/
static void run_app_space (void) {
halfword p; /* was a global temp_ptr */
int method = disable_space_par ;
if (method == 1) {
/*tex Don't inject anything, not even zero skip. */
} else if (method == 2) {
p = new_glue(zero_glue);
couple_nodes(tail,p);
tail = p;
} else if ((abs(mode) + cur_cmd == hmode + spacer_cmd) && (!(space_factor_par == 1000))) {
app_space();
} else {
/*tex Append a normal inter-word space to the current list. */
if (glue_is_zero(space_skip_par)) {
/*tex Find the glue specification for text spaces in the current font. */
p = new_glue(zero_glue);
width(p) = space(cur_font_par);
stretch(p) = space_stretch(cur_font_par);
shrink(p) = space_shrink(cur_font_par);
} else {
p = new_param_glue(space_skip_code);
}
/*tex So from now we have a subtype with spaces: */
subtype(p) = space_skip_code + 1 ;
couple_nodes(tail,p);
tail = p;
}
}
/*tex
Append a |boundary_node|
*/
static void run_boundary (void) {
halfword n ;
n = new_node(boundary_node,cur_chr);
if ((cur_chr == 1) || (cur_chr == 2) ) {
/*tex We expect a user boundary or protrusion boundary. */
scan_int();
boundary_value(n) = cur_val;
}
couple_nodes(tail, n);
tail = n;
}
static void run_char_ghost (void) {
int t;
t = cur_chr;
get_x_token();
if ((cur_cmd == letter_cmd) || (cur_cmd == other_char_cmd)
|| (cur_cmd == char_given_cmd) || (cur_cmd == char_num_cmd)) {
halfword p = new_glyph(get_cur_font(), cur_chr);
if (t == 0) {
set_is_leftghost(p);
} else {
set_is_rightghost(p);
}
tail_append(p);
}
}
static void run_relax (void) {
return;
}
/*tex
|ignore_spaces| is a special case: after it has acted, |get_x_token| has already
fetched the next token from the input, so that operation in |main_control| should
be skipped.
*/
static void run_ignore_spaces (void) {
if (cur_chr == 0) {
/*tex Get the next non-blank non-call... */
do {
get_x_token();
} while (cur_cmd == spacer_cmd);
main_control_state = goto_skip_token;
} else {
int t = scanner_status;
scanner_status = normal;
get_next();
scanner_status = t;
cur_cs = prim_lookup(cs_text(cur_cs));
if (cur_cs != undefined_primitive) {
cur_cmd = get_prim_eq_type(cur_cs);
cur_chr = get_prim_equiv(cur_cs);
cur_tok = (cur_cmd * STRING_OFFSET) + cur_chr;
main_control_state = goto_skip_token;
}
}
}
/*tex
|stop| is the second special case. We want |main_control| to return to its caller
if there is nothing left to do.
*/
static void run_stop (void) {
if (its_all_over()) {
/*tex this is the only way out */
main_control_state= goto_return;
}
}
static void run_non_math_math (void) {
back_input();
new_graf(true);
}
/*tex
We build up an argument to |set_math_char|:
*/
static void run_math_char_num (void) {
mathcodeval mval;
if (cur_chr == 0)
mval = scan_mathchar(tex_mathcode);
else if (cur_chr == 1)
mval = scan_mathchar(umath_mathcode);
else
mval = scan_mathchar(umathnum_mathcode);
math_char_in_text(mval);
}
/*tex
We build up an argument to |set_math_char|:
*/
static void run_math_given (void) {
mathcodeval mval;
mval = mathchar_from_integer(cur_chr, tex_mathcode);
math_char_in_text(mval);
}
/*tex
We build up an argument to |set_math_char| the \LUATEX\ way:
*/
static void run_xmath_given (void) {
mathcodeval mval;
mval = mathchar_from_integer(cur_chr, umath_mathcode);
math_char_in_text(mval);
}
/*tex
The most important parts of |main_control| are concerned with \TeX's chief
mission of box-making. We need to control the activities that put entries on
vlists and hlists, as well as the activities that convert those lists into boxes.
All of the necessary machinery has already been developed; it remains for us to
``push the buttons'' at the right times.
As an introduction to these routines, let's consider one of the simplest cases:
What happens when `\.{\\hrule}' occurs in vertical mode, or `\.{\\vrule}' in
horizontal mode or math mode? The code in |main_control| is short, since the
|scan_rule_spec| routine already does most of what is required; thus, there is no
need for a special action procedure.
Note that baselineskip calculations are disabled after a rule in vertical mode,
by setting |prev_depth:=ignore_depth|.
*/
static void run_rule (void) {
tail_append(scan_rule_spec());
if (abs(mode) == vmode)
prev_depth_par = ignore_depth;
else if (abs(mode) == hmode)
space_factor_par = 1000;
}
/*tex
Many of the actions related to box-making are triggered by the appearance of
braces in the input. For example, when the user says `\.{\\hbox} \.{to}
\.{100pt\{$\langle\,\hbox{hlist}\,\rangle$\}}' in vertical mode, the information
about the box size (100pt, |exactly|) is put onto |save_stack| with a level
boundary word just above it, and |cur_group:=adjusted_hbox_group|; \TeX\ enters
restricted horizontal mode to process the hlist. The right brace eventually
causes |save_stack| to be restored to its former state, at which time the
information about the box size (100pt, |exactly|) is available once again; a box
is packaged and we leave restricted horizontal mode, appending the new box to the
current list of the enclosing mode (in this case to the current list of vertical
mode), followed by any vertical adjustments that were removed from the box by
|hpack|.
The next few sections of the program are therefore concerned with the treatment
of left and right curly braces.
If a left brace occurs in the middle of a page or paragraph, it simply introduces
a new level of grouping, and the matching right brace will not have such a
drastic effect. Such grouping affects neither the mode nor the current list.
*/
static void run_left_brace (void) {
new_save_level(simple_group);
eq_word_define(int_base + no_local_whatsits_code, 0);
eq_word_define(int_base + no_local_dirs_code, 0);
}
static void run_begin_group (void) {
new_save_level(semi_simple_group);
eq_word_define(int_base + no_local_whatsits_code, 0);
eq_word_define(int_base + no_local_dirs_code, 0);
}
static void run_end_group (void) {
if (cur_group == semi_simple_group) {
fixup_directions();
} else {
off_save();
}
}
/*tex
Constructions that require a box are started by calling |scan_box| with a
specified context code. The |scan_box| routine verifies that a |make_box| command
comes next and then it calls |begin_box|.
*/
static void run_move (void) {
int t = cur_chr;
scan_normal_dimen();
if (t == 0)
scan_box(cur_val);
else
scan_box(-cur_val);
}
static void run_leader_ship (void) {
scan_box(leader_flag - a_leaders + cur_chr);
}
static void run_make_box (void) {
begin_box(0);
}
static void run_box_dir (void) {
scan_register_num();
cur_box = box(cur_val);
scan_optional_equals();
scan_direction();
if (cur_box != null)
box_dir(cur_box) = cur_val;
}
static void run_box_direction (void) {
scan_register_num();
cur_box = box(cur_val);
scan_optional_equals();
scan_int();
check_dir_value(cur_val);
if (cur_box != null)
box_dir(cur_box) = cur_val;
}
/*tex
There is a really small patch to add a new primitive called \.{\\quitvmode}. In
vertical modes, it is identical to \.{\\indent}, but in horizontal and math modes
it is really a no-op (as opposed to \.{\\indent}, which executes the
|indent_in_hmode| procedure).
A paragraph begins when horizontal-mode material occurs in vertical mode, or when
the paragraph is explicitly started by `\.{\\quitvmode}', `\.{\\indent}' or
`\.{\\noindent}'.
*/
static void run_start_par_vmode (void) {
new_graf((cur_chr > 0));
}
static void run_start_par (void) {
if (cur_chr != 2)
indent_in_hmode();
}
static void run_new_graf (void) {
/* the |partoken_context_code_par| branch is taken from pdftex as-is: */
if (cur_cmd == valign_cmd && partoken_context_code_par > 0 && mode == hmode) {
back_input();
cur_tok = par_token;
back_input();
token_type = inserted;
} else {
back_input();
new_graf(true);
}
}
/*tex
A paragraph ends when a |par_end| command is sensed, or when we are in horizontal
mode when reaching the right brace of vertical-mode routines like \.{\\vbox},
\.{\\insert}, or \.{\\output}.
*/
static void run_par_end_vmode (void) {
normal_paragraph();
if (mode > 0) {
checked_page_filter(vmode_par);
build_page();
}
}
static void run_par_end_hmode (void) {
if (align_state < 0) {
/*tex This tries to recover from an alignment that didn't end properly. */
off_save();
}
/* This takes us to the enclosing mode, if |mode>0|. */
end_graf(bottom_level);
if (mode == vmode) {
checked_page_filter(hmode_par);
build_page();
}
}
static void append_italic_correction_mmode (void) {
tail_append(new_kern(0));
}
static void run_local_box (void) {
append_local_box(cur_chr);
}
static void run_halign_mmode (void) {
if (privileged()) {
if (cur_group == math_shift_group)
init_align();
else
off_save();
}
}
static void run_eq_no (void) {
if (privileged()) {
if (cur_group == math_shift_group)
start_eq_no();
else
off_save();
}
}
static void run_letter_mmode (void) {
set_math_char(get_math_code(cur_chr));
}
static void run_char_num_mmode (void) {
scan_char_num();
cur_chr = cur_val;
set_math_char(get_math_code(cur_chr));
}
static void run_math_char_num_mmode (void) {
mathcodeval mval;
if (cur_chr == 0)
mval = scan_mathchar(tex_mathcode);
else if (cur_chr == 1)
mval = scan_mathchar(umath_mathcode);
else
mval = scan_mathchar(umathnum_mathcode);
set_math_char(mval);
}
static void run_math_given_mmode (void) {
mathcodeval mval;
mval = mathchar_from_integer(cur_chr, tex_mathcode);
set_math_char(mval);
}
static void run_xmath_given_mmode (void) {
mathcodeval mval;
mval = mathchar_from_integer(cur_chr, umath_mathcode);
set_math_char(mval);
}
static void run_delim_num (void) {
mathcodeval mval;
if (cur_chr == 0)
mval = scan_delimiter_as_mathchar(tex_mathcode);
else
mval = scan_delimiter_as_mathchar(umath_mathcode);
set_math_char(mval);
}
static void run_vcenter (void) {
scan_spec(vcenter_group);
normal_paragraph();
push_nest();
mode = -vmode;
prev_depth_par = ignore_depth;
if (every_vbox_par != null)
begin_token_list(every_vbox_par, every_vbox_text);
}
static void run_math_style (void) {
tail_append(new_style((small_number) cur_chr));
}
static void run_non_script (void) {
tail_append(new_glue(zero_glue));
subtype(tail) = cond_math_glue;
}
static void run_math_choice (void) {
if (cur_chr == 0)
append_choices();
else
setup_math_style();
}
static void run_math_shift (void) {
if (cur_group == math_shift_group)
after_math();
else
off_save();
}
static void run_after_assignment (void) {
get_token();
after_token = cur_tok;
}
static void run_after_group (void) {
get_token();
save_for_after(cur_tok);
}
static void run_par_token (void) {
get_token();
if (cur_cs > 0) {
par_loc = cur_cs;
par_token = cur_tok;
}
}
static void run_extension (void) {
do_extension(0, 0);
}
static void run_normal (void) {
{
switch (cur_chr) {
case save_pos_code:
new_whatsit(save_pos_node);
break;
case save_cat_code_table_code:
scan_int();
if ((cur_val < 0) || (cur_val > 0x7FFF)) {
print_err("Invalid \\catcode table");
help1(
"All \\catcode table ids must be between 0 and 0x7FFF"
);
error();
} else {
if (cur_val == cat_code_table_par) {
print_err("Invalid \\catcode table");
help1(
"You cannot overwrite the current \\catcode table"
);
error();
} else {
copy_cat_codes(cat_code_table_par, cur_val);
}
}
break;
case init_cat_code_table_code:
scan_int();
if ((cur_val < 0) || (cur_val > 0x7FFF)) {
print_err("Invalid \\catcode table");
help1(
"All \\catcode table ids must be between 0 and 0x7FFF"
);
error();
} else {
if (cur_val == cat_code_table_par) {
print_err("Invalid \\catcode table");
help1(
"You cannot overwrite the current \\catcode table"
);
error();
} else {
initex_cat_codes(cur_val);
}
}
break;
case set_random_seed_code:
/* Negative random seed values are silently converted to positive ones */
scan_int();
if (cur_val < 0)
negate(cur_val);
random_seed = cur_val;
init_randoms(random_seed);
break;
case late_lua_code:
new_whatsit(late_lua_node); /* type == normal */
late_lua_name(tail) = scan_lua_state();
(void) scan_toks(false, false);
late_lua_data(tail) = def_ref;
break;
case late_lua_call_code:
new_whatsit(late_lua_node);
late_lua_type(tail) = lua_refid_call;
scan_int();
late_lua_data(tail) = cur_val;
break;
case expand_font_code:
read_expand_font();
break;
default:
confusion("int1");
break;
}
}
}
/*tex
This is experimental and not used for production, only for testing and writing
macros (some options stay).
*/
#define mathoption_set_int(A) \
scan_int(); \
word_define(mathoption_int_base+A, cur_val);
static void run_option(void) {
int a = 0 ;
switch (cur_chr) {
case math_option_code:
if (scan_keyword("old")) {
mathoption_set_int(c_mathoption_old_code);
/*
} else if (scan_keyword("umathcodemeaning")) {
mathoption_set_int(c_mathoption_umathcode_meaning_code);
*/
} else {
normal_warning("mathoption","unknown key");
}
break;
default:
/* harmless */
break;
}
}
static void lua_function_call(void) {
scan_int();
if (cur_val <= 0) {
normal_error("luafunctioncall", "invalid number");
} else {
str_number u = save_cur_string();
luacstrings = 0;
luafunctioncall(cur_val);
restore_cur_string(u);
if (luacstrings > 0)
lua_string_start();
}
}
static void lua_bytecode_call(void) {
scan_int();
if (cur_val < 0 || cur_val > 65535) {
normal_error("luabytecodecall", "invalid number");
} else {
str_number u = save_cur_string();
luacstrings = 0;
luabytecodecall(cur_val);
restore_cur_string(u);
if (luacstrings > 0)
lua_string_start();
}
}
/*tex
For mode-independent commands, the following macro is useful.
Also, there is a list of cases where the user has probably gotten into or out of
math mode by mistake. \TeX\ will insert a dollar sign and rescan the current
token, and it makes sense ot have a macro for that as well.
*/
#define any_mode(A,B) jump_table[vmode+(A)]=B; jump_table[hmode+(A)]=B; jump_table[mmode+(A)]=B
#define non_math(A,B) jump_table[vmode+(A)]=B; jump_table[hmode+(A)]=B;
/*tex
The |main_control| uses a jump table, and |init_main_control| sets that table up.
*/
typedef void (*main_control_function) (void);
main_control_function *jump_table;
static void init_main_control (void) {
jump_table = xmalloc((mmode+max_command_cmd+1) * sizeof(main_control_function)) ;
jump_table[hmode + char_num_cmd] = run_char_num;
jump_table[hmode + letter_cmd] = run_char;
jump_table[hmode + other_char_cmd] = run_char;
jump_table[hmode + char_given_cmd] = run_char;
jump_table[hmode + spacer_cmd] = run_app_space;
jump_table[hmode + ex_space_cmd] = run_app_space;
jump_table[mmode + ex_space_cmd] = run_app_space;
jump_table[hmode + boundary_cmd] = run_boundary;
jump_table[hmode + char_ghost_cmd] = run_char_ghost;
jump_table[mmode + char_ghost_cmd] = run_char_ghost;
any_mode(relax_cmd, run_relax);
jump_table[vmode + spacer_cmd] = run_relax;
jump_table[mmode + spacer_cmd] = run_relax;
jump_table[mmode + boundary_cmd] = run_relax;
any_mode(ignore_spaces_cmd,run_ignore_spaces);
jump_table[vmode + stop_cmd] = run_stop;
jump_table[vmode + math_char_num_cmd] = run_non_math_math;
jump_table[vmode + math_given_cmd] = run_non_math_math;
jump_table[vmode + xmath_given_cmd] = run_non_math_math;
jump_table[hmode + math_char_num_cmd] = run_math_char_num;
jump_table[hmode + math_given_cmd] = run_math_given;
jump_table[hmode + xmath_given_cmd] = run_xmath_given;
jump_table[vmode + vmove_cmd] = report_illegal_case;
jump_table[hmode + hmove_cmd] = report_illegal_case;
jump_table[mmode + hmove_cmd] = report_illegal_case;
any_mode(last_item_cmd, report_illegal_case);
jump_table[vmode + vadjust_cmd] = report_illegal_case;
jump_table[vmode + ital_corr_cmd] = report_illegal_case;
non_math(eq_no_cmd,report_illegal_case);
any_mode(mac_param_cmd,report_illegal_case);
non_math(sup_mark_cmd, insert_dollar_sign);
non_math(sub_mark_cmd, insert_dollar_sign);
non_math(super_sub_script_cmd, insert_dollar_sign);
non_math(no_super_sub_script_cmd, insert_dollar_sign);
non_math(math_comp_cmd, insert_dollar_sign);
non_math(delim_num_cmd, insert_dollar_sign);
non_math(left_right_cmd, insert_dollar_sign);
non_math(above_cmd, insert_dollar_sign);
non_math(radical_cmd, insert_dollar_sign);
non_math(math_style_cmd, insert_dollar_sign);
non_math(math_choice_cmd, insert_dollar_sign);
non_math(vcenter_cmd, insert_dollar_sign);
non_math(non_script_cmd, insert_dollar_sign);
non_math(mkern_cmd, insert_dollar_sign);
non_math(limit_switch_cmd, insert_dollar_sign);
non_math(mskip_cmd, insert_dollar_sign);
non_math(math_accent_cmd, insert_dollar_sign);
jump_table[mmode + endv_cmd] = insert_dollar_sign;
jump_table[mmode + par_end_cmd] = insert_dollar_sign_par_end;
jump_table[mmode + stop_cmd] = insert_dollar_sign;
jump_table[mmode + vskip_cmd] = insert_dollar_sign;
jump_table[mmode + un_vbox_cmd] = insert_dollar_sign;
jump_table[mmode + valign_cmd] = insert_dollar_sign;
jump_table[mmode + hrule_cmd] = insert_dollar_sign;
jump_table[mmode + no_hrule_cmd] = insert_dollar_sign;
jump_table[vmode + hrule_cmd] = run_rule;
jump_table[vmode + no_hrule_cmd] = run_rule;
jump_table[hmode + vrule_cmd] = run_rule;
jump_table[hmode + no_vrule_cmd] = run_rule;
jump_table[mmode + vrule_cmd] = run_rule;
jump_table[mmode + no_vrule_cmd] = run_rule;
jump_table[vmode + vskip_cmd] = append_glue;
jump_table[hmode + hskip_cmd] = append_glue;
jump_table[mmode + hskip_cmd] = append_glue;
jump_table[mmode + mskip_cmd] = append_glue;
any_mode(kern_cmd, append_kern);
jump_table[mmode + mkern_cmd] = append_kern;
non_math(left_brace_cmd, run_left_brace);
any_mode(begin_group_cmd,run_begin_group);
any_mode(end_group_cmd, run_end_group);
any_mode(right_brace_cmd, handle_right_brace);
jump_table[vmode + hmove_cmd] = run_move;
jump_table[hmode + vmove_cmd] = run_move;
jump_table[mmode + vmove_cmd] = run_move;
any_mode(leader_ship_cmd, run_leader_ship);
any_mode(make_box_cmd, run_make_box);
any_mode(assign_box_dir_cmd, run_box_dir);
any_mode(assign_box_direction_cmd, run_box_direction);
jump_table[vmode + start_par_cmd] = run_start_par_vmode;
jump_table[hmode + start_par_cmd] = run_start_par;
jump_table[mmode + start_par_cmd] = run_start_par;
jump_table[vmode + letter_cmd] = run_new_graf;
jump_table[vmode + other_char_cmd] = run_new_graf;
jump_table[vmode + char_num_cmd] = run_new_graf;
jump_table[vmode + char_given_cmd] = run_new_graf;
jump_table[vmode + char_ghost_cmd] = run_new_graf;
jump_table[vmode + math_shift_cmd] = run_new_graf;
jump_table[vmode + math_shift_cs_cmd] = run_new_graf;
jump_table[vmode + un_hbox_cmd] = run_new_graf;
jump_table[vmode + vrule_cmd] = run_new_graf;
jump_table[vmode + no_vrule_cmd] = run_new_graf;
jump_table[vmode + accent_cmd] = run_new_graf;
jump_table[vmode + discretionary_cmd] = run_new_graf;
jump_table[vmode + hskip_cmd] = run_new_graf;
jump_table[vmode + valign_cmd] = run_new_graf;
jump_table[vmode + ex_space_cmd] = run_new_graf;
jump_table[vmode + boundary_cmd] = run_new_graf;
jump_table[vmode + par_end_cmd] = run_par_end_vmode;
jump_table[hmode + par_end_cmd] = run_par_end_hmode;
jump_table[hmode + stop_cmd] = head_for_vmode;
jump_table[hmode + vskip_cmd] = head_for_vmode;
jump_table[hmode + hrule_cmd] = head_for_vmode;
jump_table[hmode + no_hrule_cmd] = head_for_vmode;
jump_table[hmode + un_vbox_cmd] = head_for_vmode;
jump_table[hmode + halign_cmd] = head_for_vmode;
any_mode(insert_cmd,begin_insert_or_adjust);
jump_table[hmode + vadjust_cmd] = begin_insert_or_adjust;
jump_table[mmode + vadjust_cmd] = begin_insert_or_adjust;
any_mode(mark_cmd, handle_mark);
any_mode(break_penalty_cmd, append_penalty);
any_mode(remove_item_cmd, delete_last);
jump_table[vmode + un_vbox_cmd] = unpackage;
jump_table[hmode + un_hbox_cmd] = unpackage;
jump_table[mmode + un_hbox_cmd] = unpackage;
jump_table[hmode + ital_corr_cmd] = append_italic_correction;
jump_table[mmode + ital_corr_cmd] = append_italic_correction_mmode;
jump_table[hmode + discretionary_cmd] = append_discretionary;
jump_table[mmode + discretionary_cmd] = append_discretionary;
any_mode(assign_local_box_cmd, run_local_box);
jump_table[hmode + accent_cmd] = make_accent;
any_mode(car_ret_cmd,align_error);
any_mode(tab_mark_cmd,align_error);
any_mode(no_align_cmd,no_align_error);
any_mode(omit_cmd, omit_error);
jump_table[vmode + halign_cmd] = init_align;
jump_table[hmode + valign_cmd] = init_align;
jump_table[mmode + halign_cmd] = run_halign_mmode;
jump_table[vmode + endv_cmd] = do_endv;
jump_table[hmode + endv_cmd] = do_endv;
any_mode(end_cs_name_cmd, cs_error);
jump_table[hmode + math_shift_cmd] = init_math;
jump_table[hmode + math_shift_cs_cmd] = init_math;
jump_table[mmode + eq_no_cmd] = run_eq_no;
jump_table[mmode + left_brace_cmd] = math_left_brace;
jump_table[mmode + letter_cmd] = run_letter_mmode;
jump_table[mmode + other_char_cmd] = run_letter_mmode;
jump_table[mmode + char_given_cmd] = run_letter_mmode;
jump_table[mmode + char_num_cmd] = run_char_num_mmode;
jump_table[mmode + math_char_num_cmd] = run_math_char_num_mmode;
jump_table[mmode + math_given_cmd] = run_math_given_mmode;
jump_table[mmode + xmath_given_cmd] = run_xmath_given_mmode;
jump_table[mmode + delim_num_cmd] = run_delim_num;
jump_table[mmode + math_comp_cmd] = math_math_comp;
jump_table[mmode + limit_switch_cmd] = math_limit_switch;
jump_table[mmode + radical_cmd] = math_radical;
jump_table[mmode + accent_cmd] = math_ac;
jump_table[mmode + math_accent_cmd] = math_ac;
jump_table[mmode + vcenter_cmd] = run_vcenter;
jump_table[mmode + math_style_cmd] = run_math_style;
jump_table[mmode + non_script_cmd] = run_non_script;
jump_table[mmode + math_choice_cmd] = run_math_choice;
jump_table[mmode + above_cmd] = math_fraction;
jump_table[mmode + sub_mark_cmd] = sub_sup;
jump_table[mmode + sup_mark_cmd] = sub_sup;
jump_table[mmode + super_sub_script_cmd] = sub_sup;
jump_table[mmode + no_super_sub_script_cmd] = no_sub_sup;
jump_table[mmode + left_right_cmd] = math_left_right;
jump_table[mmode + math_shift_cmd] = run_math_shift;
jump_table[mmode + math_shift_cs_cmd] = run_math_shift;
any_mode(toks_register_cmd, prefixed_command);
any_mode(assign_toks_cmd, prefixed_command);
any_mode(assign_int_cmd, prefixed_command);
any_mode(assign_attr_cmd, prefixed_command);
any_mode(assign_dir_cmd, prefixed_command);
any_mode(assign_direction_cmd, prefixed_command);
any_mode(assign_dimen_cmd, prefixed_command);
any_mode(assign_glue_cmd, prefixed_command);
any_mode(assign_mu_glue_cmd, prefixed_command);
any_mode(assign_font_dimen_cmd, prefixed_command);
any_mode(assign_font_int_cmd, prefixed_command);
any_mode(set_aux_cmd, prefixed_command);
any_mode(set_prev_graf_cmd, prefixed_command);
any_mode(set_page_dimen_cmd, prefixed_command);
any_mode(set_page_int_cmd, prefixed_command);
any_mode(set_box_dimen_cmd, prefixed_command);
any_mode(set_tex_shape_cmd, prefixed_command);
any_mode(set_etex_shape_cmd, prefixed_command);
any_mode(def_char_code_cmd, prefixed_command);
any_mode(def_del_code_cmd, prefixed_command);
any_mode(extdef_math_code_cmd, prefixed_command);
any_mode(extdef_del_code_cmd, prefixed_command);
any_mode(def_family_cmd, prefixed_command);
any_mode(set_math_param_cmd, prefixed_command);
any_mode(set_font_cmd, prefixed_command);
any_mode(def_font_cmd, prefixed_command);
any_mode(letterspace_font_cmd, prefixed_command);
any_mode(copy_font_cmd, prefixed_command);
any_mode(set_font_id_cmd, prefixed_command);
any_mode(register_cmd, prefixed_command);
any_mode(advance_cmd, prefixed_command);
any_mode(multiply_cmd, prefixed_command);
any_mode(divide_cmd, prefixed_command);
any_mode(prefix_cmd, prefixed_command);
any_mode(let_cmd, prefixed_command);
any_mode(shorthand_def_cmd, prefixed_command);
any_mode(read_to_cs_cmd, prefixed_command);
any_mode(def_cmd, prefixed_command);
any_mode(set_box_cmd, prefixed_command);
any_mode(hyph_data_cmd, prefixed_command);
any_mode(set_interaction_cmd, prefixed_command);
any_mode(after_assignment_cmd,run_after_assignment);
any_mode(after_group_cmd,run_after_group);
any_mode(partoken_name_cmd,run_par_token);
any_mode(in_stream_cmd,open_or_close_in);
any_mode(message_cmd,issue_message);
any_mode(case_shift_cmd, shift_case);
any_mode(xray_cmd, show_whatever);
any_mode(normal_cmd, run_normal);