texmaincontrol.h /size: 4535 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_MAINCONTROL_H
6# define LMT_MAINCONTROL_H
7
8/*tex
9
10    To handle the execution state of |main_control|'s eternal loop, an extra global variable is
11    used, along with a macro to define its values.
12
13*/
14
15typedef enum control_states {
16    goto_next_state,
17    goto_skip_token_state,
18    goto_return_state,
19} control_states;
20
21typedef struct main_control_state_info {
22    control_states control_state;
23    int            local_level;
24    halfword       after_token;
25    halfword       after_tokens;
26    halfword       last_par_trigger;
27    halfword       last_par_context;
28    halfword       loop_iterator;
29    halfword       loop_nesting;
30    halfword       loop_stack_head;
31    halfword       loop_stack_tail; 
32    halfword       quit_loop;
33    halfword       padding;
34} main_control_state_info;
35
36extern main_control_state_info lmt_main_control_state;
37
38extern void     tex_initialize_variables            (void);
39extern int      tex_main_control                    (void);
40
41extern void     tex_normal_paragraph                (int context);
42extern void     tex_begin_paragraph                 (int doindent, int context);
43extern void     tex_end_paragraph                   (int group, int context);
44extern int      tex_wrapped_up_paragraph            (int context, int final);
45
46extern void     tex_insert_paragraph_token          (void);
47
48extern int      tex_in_privileged_mode              (void);
49extern void     tex_you_cant_error                  (const char *helpinfo);
50
51extern void     tex_off_save                        (void);
52
53extern halfword tex_local_scan_box                  (void);
54extern void     tex_box_end                         (int boxcontext, halfword boxnode, scaled shift, halfword mainclass, halfword slot, halfword callback);
55
56extern void     tex_get_r_token                     (void);
57
58extern void     tex_begin_local_control             (void);
59extern void     tex_end_local_control               (void);
60extern void     tex_local_control                   (int obeymode);
61extern void     tex_local_control_message           (const char *s);
62extern void     tex_page_boundary_message           (const char *s, halfword boundary);
63
64extern void     tex_inject_text_or_line_dir         (int d, int check_glue);
65
66extern void     tex_handle_assignments              (void); /*tex Used in math. */
67
68extern void     tex_assign_internal_integer_value   (int a, halfword p, int val);
69extern void     tex_assign_internal_attribute_value (int a, halfword p, int val);
70extern void     tex_assign_internal_posit_value     (int a, halfword p, int val);
71extern void     tex_assign_internal_dimension_value (int a, halfword p, int val);
72extern void     tex_assign_internal_skip_value      (int a, halfword p, int val);
73extern void     tex_assign_internal_unit_value      (int a, halfword p, int val);
74
75extern void     tex_aux_lua_call                    (halfword cmd, halfword chr);
76
77extern halfword tex_nested_loop_iterator            (void);
78extern halfword tex_previous_loop_iterator          (void);
79extern halfword tex_expand_parameter                (halfword tok, halfword *tail);
80extern halfword tex_expand_iterator                 (halfword tok);
81
82extern void     tex_show_discretionary_group        (void);
83extern int      tex_show_discretionary_record       (void);
84
85inline int valid_parameter_reference(int r) 
86{
87    switch (r) {
88        case I_token_l: case I_token_o: // iterator
89        case P_token_l: case P_token_o: // parent iterator
90        case G_token_l: case G_token_o: // grandparent iterator
91        case H_token_l: case H_token_o: // hash escape
92        case L_token_l: case L_token_o: // newline escape (\n)
93     // case N_token_l: case N_token_o: // no break space
94        case Q_token_l: case Q_token_o: // double quote
95        case R_token_l: case R_token_o: // return escape (\r)
96        case S_token_l: case S_token_o: // space escape
97        case T_token_l: case T_token_o: // tab escape (\t)
98        case X_token_l: case X_token_o: // backslash escape
99     // case Z_token_l: case Z_token_o: // zero width space
100            return token_chr(r);
101        default:
102            return 0;
103    }
104}
105
106inline int valid_iterator_reference(int r) 
107{
108    switch (r) {
109        case I_token_l: case I_token_o: // iterator
110        case P_token_l: case P_token_o: // parent iterator
111        case G_token_l: case G_token_o: // grandparent iterator
112            return token_chr(r);
113        default:
114            return 0;
115    }
116}
117
118# endif
119