summaryrefslogtreecommitdiff
path: root/source/luametatex/source/tex
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex/source/tex')
-rw-r--r--source/luametatex/source/tex/texadjust.c2
-rw-r--r--source/luametatex/source/tex/texalign.c71
-rw-r--r--source/luametatex/source/tex/texbuildpage.c2
-rw-r--r--source/luametatex/source/tex/texcommands.h36
-rw-r--r--source/luametatex/source/tex/texconditional.c31
-rw-r--r--source/luametatex/source/tex/texconditional.h10
-rw-r--r--source/luametatex/source/tex/texequivalents.c31
-rw-r--r--source/luametatex/source/tex/texequivalents.h80
-rw-r--r--source/luametatex/source/tex/texerrors.c23
-rw-r--r--source/luametatex/source/tex/texerrors.h18
-rw-r--r--source/luametatex/source/tex/texexpand.c10
-rw-r--r--source/luametatex/source/tex/texinputstack.c32
-rw-r--r--source/luametatex/source/tex/texinputstack.h76
-rw-r--r--source/luametatex/source/tex/texinserts.c2
-rw-r--r--source/luametatex/source/tex/texmaincontrol.c562
-rw-r--r--source/luametatex/source/tex/texmath.c20
-rw-r--r--source/luametatex/source/tex/texnesting.c63
-rw-r--r--source/luametatex/source/tex/texnesting.h45
-rw-r--r--source/luametatex/source/tex/texnodes.c429
-rw-r--r--source/luametatex/source/tex/texpackaging.c298
-rw-r--r--source/luametatex/source/tex/texprimitive.c8
-rw-r--r--source/luametatex/source/tex/texprinting.c2
-rw-r--r--source/luametatex/source/tex/texrules.c11
-rw-r--r--source/luametatex/source/tex/texscanning.c11
-rw-r--r--source/luametatex/source/tex/textoken.c341
-rw-r--r--source/luametatex/source/tex/textoken.h52
-rw-r--r--source/luametatex/source/tex/textypes.h17
27 files changed, 1402 insertions, 881 deletions
diff --git a/source/luametatex/source/tex/texadjust.c b/source/luametatex/source/tex/texadjust.c
index 882227ec2..f57853caf 100644
--- a/source/luametatex/source/tex/texadjust.c
+++ b/source/luametatex/source/tex/texadjust.c
@@ -145,7 +145,7 @@ void tex_run_vadjust(void)
tex_scan_left_brace();
tex_normal_paragraph(vadjust_par_context);
tex_push_nest();
- cur_list.mode = -vmode;
+ cur_list.mode = internal_vmode;
cur_list.prev_depth = ignore_depth_criterium_par;
}
diff --git a/source/luametatex/source/tex/texalign.c b/source/luametatex/source/tex/texalign.c
index 46d3153cf..c8e4ed9dc 100644
--- a/source/luametatex/source/tex/texalign.c
+++ b/source/luametatex/source/tex/texalign.c
@@ -199,10 +199,11 @@
limit that (and redundant boxes and glue are the only things we can do here). It actually
also saves a bit of runtime. This feature has not been tested yet with |\span| and |\omit|.
-*/
+ The |\noalign| command accepts a couple of keywords that specify options to be applied to the
+ next row. These options are similar to the ones for boxes.
+
+ Maybe: lefttabskip righttabskip middletabskip
-/*
- Todo: lefttabskip righttabskip middletabskip
*/
typedef struct alignment_row_state {
@@ -239,8 +240,8 @@ typedef struct alignment_state_info {
halfword cell_source;
halfword wrap_source; /*tex There's also a field in the row_state. */
halfword callback;
- // halfword reverse; // todo
- // halfword discard_skips; // todo
+ /* halfword reverse; */ /* maybe */
+ /* halfword discard_skips; */ /* maybe */
halfword row_state_set;
halfword padding;
alignment_row_state row_state;
@@ -267,8 +268,8 @@ static alignment_state_info lmt_alignment_state = {
.cell_source = 0,
.wrap_source = 0,
.callback = 0,
- // .reverse = 0,
- // .discard_skips = 0,
+ /* .reverse = 0, */
+ /* .discard_skips = 0, */
.row_state_set = 0,
.padding = 0,
.row_state = {
@@ -305,9 +306,9 @@ static void tex_aux_wipe_row_state(void)
typedef enum saved_align_items {
saved_align_specification,
saved_align_reverse,
- saved_align_discard,
- saved_align_noskips, /*tex Saving is not needed but it doesn't hurt either */
- saved_align_callback,
+ saved_align_discard,
+ saved_align_noskips, /*tex currently fetched from the state (not used anyway) */
+ saved_align_callback, /*tex currently fetched from the state */
saved_align_n_of_items,
} saved_align_items;
@@ -338,7 +339,7 @@ inline static void tex_aux_change_list_type(halfword n, quarterword type)
box_d_offset(n) = 0; /* box_span_count */
box_x_offset(n) = 0; /* align_record_u_part */
box_y_offset(n) = 0; /* align_record_v_part */
- // box_geometry(n) = 0; /* box_size */
+ /* box_geometry(n) = 0; */ /* box_size */
box_orientation(n) = 0; /* box_size */
}
@@ -352,6 +353,10 @@ inline static void tex_aux_change_list_type(halfword n, quarterword type)
and such. But then it even makes sense to have explicit commands (in addition to the seperator)
to tags individual cells. It's too much hassle for now and the advantages are not that large.
+ This code has a history so changing it now is tricky. For instance we could the top of the align
+ stack instead of the copied values. On the other hand, working with copies makes that we can
+ mess with these. And the gain would be little anywya, if at all.
+
*/
static void tex_aux_push_alignment(void)
@@ -623,10 +628,10 @@ static void tex_aux_scan_align_spec(quarterword c)
add_attribute_reference(attrlist);
tex_set_saved_record(saved_align_specification, box_spec_save_type, mode, amount);
/* We save them but could put them in the state as we do for some anyway. */
- tex_set_saved_record(saved_align_reverse, box_reverse_save_type, reverse, 0);
- tex_set_saved_record(saved_align_discard, box_discard_save_type, noskips ? 0 : discard, 0);
- tex_set_saved_record(saved_align_noskips, box_noskips_save_type, noskips, 0);
- tex_set_saved_record(saved_align_callback, box_callback_save_type, callback, 0);
+ tex_set_saved_record(saved_align_reverse, box_reverse_save_type, 0, reverse);
+ tex_set_saved_record(saved_align_discard, box_discard_save_type, 0, noskips ? 0 : discard);
+ tex_set_saved_record(saved_align_noskips, box_noskips_save_type, 0, noskips);
+ tex_set_saved_record(saved_align_callback, box_callback_save_type, 0, callback);
lmt_save_state.save_stack_data.ptr += saved_align_n_of_items;
tex_new_save_level(c);
if (! brace) {
@@ -810,7 +815,7 @@ static void tex_aux_run_no_align(void)
tex_new_save_level(no_align_group);
++lmt_alignment_state.no_align_level;
tex_aux_trace_no_align("entering");
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
tex_normal_paragraph(no_align_par_context);
}
}
@@ -823,7 +828,7 @@ static int tex_aux_nested_no_align(void)
tex_new_save_level(no_align_group);
++lmt_alignment_state.no_align_level;
tex_aux_trace_no_align("entering");
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
tex_normal_paragraph(no_align_par_context);
}
}
@@ -925,7 +930,7 @@ void tex_run_alignment_initialize(void)
value that produces the correct baseline calculations.
*/
if (cur_list.mode == mmode) {
- cur_list.mode = -vmode;
+ cur_list.mode = internal_vmode;
cur_list.prev_depth = lmt_nest_state.nest[lmt_nest_state.nest_data.ptr - 2].prev_depth;
} else if (cur_list.mode > 0) {
cur_list.mode = -cur_list.mode;
@@ -1060,7 +1065,7 @@ void tex_finish_alignment_group(void)
static void tex_aux_initialize_span(halfword p)
{
tex_push_nest();
- if (cur_list.mode == -hmode) {
+ if (cur_list.mode == restricted_hmode) {
cur_list.space_factor = 1000;
} else {
cur_list.prev_depth = ignore_depth_criterium_par;
@@ -1082,7 +1087,7 @@ static void tex_aux_initialize_row(void)
{
tex_push_nest();
cur_list.mode = (- hmode - vmode) - cur_list.mode; /* weird code : - 3 - cur_list.mode : so a buogus line */
- if (cur_list.mode == -hmode) {
+ if (cur_list.mode == restricted_hmode) {
cur_list.space_factor = 0;
} else {
cur_list.prev_depth = 0;
@@ -1302,7 +1307,7 @@ static int tex_aux_finish_column(void)
size = box_size(lmt_alignment_state.cur_align);
packing = packing_exactly;
}
- if (cur_list.mode == -hmode) {
+ if (cur_list.mode == restricted_hmode) {
lmt_packaging_state.post_adjust_tail = lmt_alignment_state.cur_post_adjust_tail;
lmt_packaging_state.pre_adjust_tail = lmt_alignment_state.cur_pre_adjust_tail;
lmt_packaging_state.post_migrate_tail = lmt_alignment_state.cur_post_migrate_tail;
@@ -1396,7 +1401,7 @@ static int tex_aux_finish_column(void)
static void tex_aux_finish_row(void)
{
halfword row;
- if (cur_list.mode == -hmode) {
+ if (cur_list.mode == restricted_hmode) {
row = tex_filtered_hpack(cur_list.head, cur_list.tail, 0, packing_additional, finish_row_group, direction_unknown, 0, null, 0, 0);
tex_pop_nest();
if (lmt_alignment_state.cur_pre_adjust_head != lmt_alignment_state.cur_pre_adjust_tail) {
@@ -1566,6 +1571,11 @@ static void tex_aux_strip_zero_tab_skips(halfword q)
}
}
+/*tex
+ We currently have a mix of states but maybe some day we will exposer the save stack and then it
+ is handy to have the state values there. So for now I keep this (as reminder).
+*/
+
static void tex_aux_finish_align(void)
{
/*tex a shared register for the list operations (others are localized) */
@@ -1574,7 +1584,7 @@ static void tex_aux_finish_align(void)
scaled offset = 0;
/*tex something new */
halfword reverse = 0;
- halfword callback = lmt_alignment_state.callback;
+ halfword callback = lmt_alignment_state.callback; /* see below for variant */
halfword discard = normalize_line_mode_permitted(normalize_line_mode_par, discard_zero_tab_skips_mode);
/*tex The |align_group| was for individual entries: */
if (cur_group != align_group) {
@@ -1591,8 +1601,9 @@ static void tex_aux_finish_align(void)
}
lmt_save_state.save_stack_data.ptr -= saved_align_n_of_items;
lmt_packaging_state.pack_begin_line = -cur_list.mode_line;
- reverse = saved_level(saved_align_reverse); /* we can as well save these in the state */
- discard = discard || saved_level(saved_align_discard); /* we can as well save these in the state */
+ reverse = saved_value(saved_align_reverse); /* we can as well save these in the state */
+ discard = discard || saved_value(saved_align_discard); /* we can as well save these in the state */
+ /* callback = saved_value(saved_align_callback); */ /* already fetched from the state */
/*tex
All content is available now so this is a perfect spot for some processing. However, we
cannot mess with the unset boxes (as these can have special properties). The main reason
@@ -1712,7 +1723,7 @@ static void tex_aux_finish_align(void)
alignment is overfull or underfull.
*/
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
halfword rule_save = overfull_rule_par;
/*tex Prevent the rule from being packaged. */
overfull_rule_par = 0;
@@ -1757,7 +1768,7 @@ static void tex_aux_finish_align(void)
*/
halfword preptr;
halfword colptr;
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
/* tex_aux_change_list_type(rowptr, hlist_node); */ /* too much */
node_type(rowptr) = hlist_node;
box_width(rowptr) = box_width(preroll);
@@ -1829,11 +1840,11 @@ static void tex_aux_finish_align(void)
}
preptr = node_next(preptr);
{
- halfword box = tex_new_null_box_node(cur_list.mode == -vmode ? hlist_node : vlist_node, align_cell_list);
+ halfword box = tex_new_null_box_node(cur_list.mode == internal_vmode ? hlist_node : vlist_node, align_cell_list);
tex_couple_nodes(tail, box);
tex_attach_attribute_list_attribute(box, lmt_alignment_state.attr_list);
total += box_width(preptr);
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
box_width(box) = box_width(preptr);
} else {
box_height(box) = box_width(preptr);
@@ -1841,7 +1852,7 @@ static void tex_aux_finish_align(void)
tail = box;
}
}
- if (cur_list.mode == -vmode) {
+ if (cur_list.mode == internal_vmode) {
/*tex
Make the unset node |r| into an |hlist_node| of width |w|,
setting the glue as if the width were |t|.
diff --git a/source/luametatex/source/tex/texbuildpage.c b/source/luametatex/source/tex/texbuildpage.c
index fb7a2dde5..947ef1776 100644
--- a/source/luametatex/source/tex/texbuildpage.c
+++ b/source/luametatex/source/tex/texbuildpage.c
@@ -1130,7 +1130,7 @@ static void tex_aux_fire_up(halfword c)
lmt_page_builder_state.output_active = 1;
++lmt_page_builder_state.dead_cycles;
tex_push_nest();
- cur_list.mode = -vmode;
+ cur_list.mode = internal_vmode;
cur_list.prev_depth = ignore_depth_criterium_par;
cur_list.mode_line = -lmt_input_state.input_line;
tex_begin_token_list(output_routine_par, output_text);
diff --git a/source/luametatex/source/tex/texcommands.h b/source/luametatex/source/tex/texcommands.h
index be0639af7..6495c93f0 100644
--- a/source/luametatex/source/tex/texcommands.h
+++ b/source/luametatex/source/tex/texcommands.h
@@ -336,27 +336,31 @@ typedef enum tex_command_code {
# define is_nodebased_cmd(cmd) (cmd >= gluespec_cmd && cmd <= fontspec_cmd)
# define is_constant_cmd(cmd) (cmd >= integer_cmd && cmd <= gluespec_cmd)
-# if (main_control_mode == 1)
-
-/*tex Once these were different numbers, no series: */
+/*tex Once these were different numbers, no series (see archive): */
typedef enum tex_modes {
- nomode,
- vmode,
- hmode,
- mmode,
+ nomode = 0,
+ vmode = 1,
+ hmode = 2,
+ mmode = 3,
+ internal_vmode = -1,
+ restricted_hmode = -2,
+ inline_mmode = -3,
} tex_modes;
-# else
-
-typedef enum tex_modes {
- nomode = 0,
- vmode = 1, /*tex vertical mode */
- hmode = 1 + max_command_cmd + 1, /*tex horizontal mode */
- mmode = 1 + 2*(max_command_cmd + 1), /*tex math mode */
-} tex_modes;
+inline int is_v_mode(halfword mode) { return mode == vmode || mode == internal_vmode; }
+inline int is_h_mode(halfword mode) { return mode == hmode || mode == restricted_hmode; }
+inline int is_m_mode(halfword mode) { return mode == mmode || mode == inline_mmode; }
-# endif
+inline int tex_normalized_mode(halfword mode)
+{
+ switch (mode) {
+ case internal_vmode : return vmode;
+ case restricted_hmode: return hmode;
+ case inline_mmode : return mmode;
+ default : return mode;
+ }
+}
typedef enum arithmic_codes {
advance_code,
diff --git a/source/luametatex/source/tex/texconditional.c b/source/luametatex/source/tex/texconditional.c
index 925e9fac9..9cbdeed2b 100644
--- a/source/luametatex/source/tex/texconditional.c
+++ b/source/luametatex/source/tex/texconditional.c
@@ -41,13 +41,17 @@
condition_state_info lmt_condition_state = {
.cond_ptr = null,
- .if_limit = 0,
.cur_if = 0,
+ .cur_unless = 0,
+ .if_step = 0,
+ .if_unless = 0,
+ .if_limit = 0,
.if_line = 0,
.skip_line = 0,
.chk_num = 0,
.chk_dim = 0,
.if_nesting = 0,
+ .padding = 0,
};
/*tex
@@ -89,9 +93,8 @@ static void tex_aux_pass_text(void)
}
case or_else_code:
case or_unless_code:
- do {
- tex_get_next();
- } while (cur_cmd == spacer_cmd);
+ tex_get_next_non_spacer();
+ /*tex So we skip the token after |\orelse| or |\orunless| without testing it! */
break;
default:
++level;
@@ -143,9 +146,7 @@ static int tex_aux_pass_text_x(int tracing_ifs, int tracing_commands)
} else if (tracing_ifs) {
tex_show_cmd_chr(cur_cmd, cur_chr);
}
- do {
- tex_get_next();
- } while (cur_cmd == spacer_cmd);
+ tex_get_next_non_spacer();
if (lmt_condition_state.if_limit == if_code) {
if (cur_cmd == if_test_cmd && cur_chr >= first_real_if_test_code) {
goto OKAY;
@@ -218,6 +219,11 @@ static void tex_aux_if_warning(void)
}
}
+/*tex
+ We can consider a dedicated condition stack so that we can copy faster. Or we can just emulate
+ an if node in |lmt_condition_state|.
+*/
+
static void tex_aux_push_condition_stack(int code, int unless)
{
halfword p = tex_get_node(if_node_size);
@@ -591,13 +597,13 @@ void tex_conditional_if(halfword code, int unless)
result = odd(tex_scan_int(0, NULL));
goto RESULT;
case if_vmode_code:
- result = abs(cur_list.mode) == vmode;
+ result = is_v_mode(cur_list.mode);
goto RESULT;
case if_hmode_code:
- result = abs(cur_list.mode) == hmode;
+ result = is_h_mode(cur_list.mode);
goto RESULT;
case if_mmode_code:
- result = abs(cur_list.mode) == mmode;
+ result = is_m_mode(cur_list.mode);
goto RESULT;
case if_inner_code:
result = cur_list.mode < nomode;
@@ -1216,7 +1222,6 @@ void tex_conditional_if(halfword code, int unless)
} else {
/*tex Wait for |\fi|. */
//lmt_condition_state.if_step = code;
-
lmt_condition_state.if_limit = fi_code;
}
}
@@ -1234,9 +1239,7 @@ void tex_conditional_fi_or_else(void)
tex_show_cmd_chr(if_test_cmd, cur_chr);
}
if (cur_chr == or_else_code || cur_chr == or_unless_code) {
- do {
- tex_get_next();
- } while (cur_cmd == spacer_cmd);
+ tex_get_next_non_spacer();
} else if (cur_chr > lmt_condition_state.if_limit) {
if (lmt_condition_state.if_limit == if_code) {
/*tex
diff --git a/source/luametatex/source/tex/texconditional.h b/source/luametatex/source/tex/texconditional.h
index a0c22cd38..47157556c 100644
--- a/source/luametatex/source/tex/texconditional.h
+++ b/source/luametatex/source/tex/texconditional.h
@@ -111,14 +111,14 @@ typedef enum if_test_codes {
//define last_real_if_test_code if_bitwise_and_code
typedef struct condition_state_info {
- halfword cond_ptr; /*tex top of the condition stack */
- int cur_if; /*tex type of conditional being worked on */
+ halfword cond_ptr; /*tex top of the condition stack */
+ int cur_if; /*tex type of conditional being worked on */
int cur_unless;
int if_step;
int if_unless;
- int if_limit; /*tex upper bound on |fi_or_else| codes */
- int if_line; /*tex line where that conditional began */
- int skip_line; /*tex skipping began here */
+ int if_limit; /*tex upper bound on |fi_or_else| codes */
+ int if_line; /*tex line where that conditional began */
+ int skip_line; /*tex skipping began here */
halfword chk_num;
scaled chk_dim;
halfword if_nesting;
diff --git a/source/luametatex/source/tex/texequivalents.c b/source/luametatex/source/tex/texequivalents.c
index 827f68a77..e61db3826 100644
--- a/source/luametatex/source/tex/texequivalents.c
+++ b/source/luametatex/source/tex/texequivalents.c
@@ -94,7 +94,7 @@ save_state_info lmt_save_state = {
.current_level = 0,
.current_group = 0,
.current_boundary = 0,
- .padding = 0,
+ // .padding = 0,
};
/*tex
@@ -517,7 +517,7 @@ static int tex_aux_saved_box_spec(halfword *packing, halfword *amount)
{
int i = tex_aux_found_save_type(box_spec_save_type);
if (i) {
- *packing = saved_level(i);
+ *packing = saved_extra(i);
*amount = saved_value(i);
} else {
*packing = 0;
@@ -580,7 +580,7 @@ void tex_show_save_groups(void)
break;
case align_group:
if (alignmentstate == 0) {
- package = (mode == -vmode) ? "halign" : "valign";
+ package = (mode == internal_vmode) ? "halign" : "valign";
alignmentstate = 1;
goto FOUND1;
} else {
@@ -675,7 +675,7 @@ void tex_show_save_groups(void)
goto FOUND2;
case math_fence_group:
/* kind of ugly ... maybe also save that one */ /* todo: operator */
- tex_print_str_esc((node_subtype(lmt_nest_state.nest[pointer + 1].delim) == left_fence_side) ? "left" : "middle");
+ tex_print_str_esc((node_subtype(lmt_nest_state.nest[pointer + 1].delimiter) == left_fence_side) ? "left" : "middle");
goto FOUND2;
default:
tex_confusion("show groups");
@@ -692,7 +692,7 @@ void tex_show_save_groups(void)
scaled shift = tex_aux_save_value(saved_full_spec_item_shift);
if (shift != null_flag) {
/*tex We passed the safeguard. */
- singleword cmd = (abs(lmt_nest_state.nest[pointer].mode) == vmode) ? hmove_cmd : vmove_cmd;
+ singleword cmd = is_v_mode(lmt_nest_state.nest[pointer].mode) ? hmove_cmd : vmove_cmd;
tex_print_cmd_chr(cmd, (shift > 0) ? move_forward_code : move_backward_code);
tex_print_dimension(abs(shift), pt_unit);
}
@@ -1011,16 +1011,17 @@ inline static int tex_aux_equal_eq(halfword p, singleword cmd, singleword flag,
case register_toks_cmd:
/*tex Again we have references. */
if (eq_value(p) == chr) {
- // if (eq_value(p) == chr && eq_level(p) == cur_level) {
+ // if (eq_value(p) == chr && eq_level(p) == cur_level) {
return 1;
} else {
return 0;
}
- // case dimension_cmd:
- // case integer_cmd:
- // if (eq_type(p) == cmd && eq_value(p) == chr && eq_level(p) == cur_level) {
- // return 1;
- // }
+ case dimension_cmd:
+ case integer_cmd:
+ if (eq_type(p) == cmd && eq_value(p) == chr) {
+ // if (eq_type(p) == cmd && eq_value(p) == chr && eq_level(p) == cur_level) {
+ return 1;
+ }
default:
/*tex
We can best also check the level because for integer defs etc we run into
@@ -1303,7 +1304,9 @@ void tex_define_swapped(int g, halfword p1, halfword p2, int force)
goto NOTDONE;
}
}
- {
+ if (v1 == v2) {
+ return;
+ } else {
switch (t1) {
case register_int_cmd:
case register_attribute_cmd:
@@ -1823,7 +1826,7 @@ void tex_aux_show_eqtb(halfword n)
tex_print_cmd_chr(eq_type(n), eq_value(n));
if (eq_type(n) >= call_cmd) {
tex_print_char(':');
- tex_token_show(eq_value(n), default_token_show_min);
+ tex_token_show(eq_value(n));
}
} else {
switch (eq_type(n)) {
@@ -1835,7 +1838,7 @@ void tex_aux_show_eqtb(halfword n)
tex_print_int(register_toks_number(n));
TOKS:
tex_print_char('=');
- tex_token_show(eq_value(n), default_token_show_min);
+ tex_token_show(eq_value(n));
break;
case internal_box_reference_cmd:
tex_print_cmd_chr(eq_type(n), n);
diff --git a/source/luametatex/source/tex/texequivalents.h b/source/luametatex/source/tex/texequivalents.h
index ca32280ef..4a18c4d87 100644
--- a/source/luametatex/source/tex/texequivalents.h
+++ b/source/luametatex/source/tex/texequivalents.h
@@ -802,8 +802,8 @@ extern void tex_undump_equivalents_mem (dumpstream f);
*/
typedef struct save_record {
- quarterword saved_level;
- quarterword saved_type; /*tex We need less so we can actually decide to store the offset as check. */
+ union { quarterword saved_level; quarterword saved_extra; };
+ quarterword saved_type;
halfword saved_value; /*tex Started out as padding, is now actually used for value. */
memoryword saved_word;
} save_record;
@@ -814,7 +814,7 @@ typedef struct save_state_info {
quarterword current_level; /*tex current nesting level for groups */
quarterword current_group; /*tex current group type */
int current_boundary; /*tex where the current level begins */
- int padding;
+ // int padding;
} save_state_info;
extern save_state_info lmt_save_state;
@@ -826,22 +826,20 @@ extern save_state_info lmt_save_state;
/*tex
We use the notation |saved(k)| to stand for an item that appears in location |save_ptr + k| of
- the save stack.
-
- The level field is also available for other purposes, so maybe we need an alias that is more
- generic.
+ the save stack. The level field is also available for other purposes, so we have |extra| as an
+ more generic alias.
*/
# define save_type(A) lmt_save_state.save_stack[(A)].saved_type /*tex classifies a |save_stack| entry */
-# define save_extra(A) lmt_save_state.save_stack[(A)].saved_level /*tex a more generic alias: to be used */
+# define save_extra(A) lmt_save_state.save_stack[(A)].saved_extra /*tex a more generic alias */
# define save_level(A) lmt_save_state.save_stack[(A)].saved_level /*tex saved level for regions 5 and 6, or group code, or ... */
# define save_value(A) lmt_save_state.save_stack[(A)].saved_value /*tex |eqtb| location or token or |save_stack| location or ... */
# define save_word(A) lmt_save_state.save_stack[(A)].saved_word /*tex |eqtb| entry */
# define saved_valid(A) (lmt_save_state.save_stack_data.ptr + (A) >= 0)
# define saved_type(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_type
-# define saved_extra(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_level
+# define saved_extra(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_extra
# define saved_level(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_level
# define saved_value(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_value
# define saved_word(A) lmt_save_state.save_stack[lmt_save_state.save_stack_data.ptr + (A)].saved_word
@@ -1209,26 +1207,50 @@ typedef enum flag_bit {
# define remove_conditional_flag(a) ((a) & ~conditional_flag_bit)
# define remove_value_flag(a) ((a) & ~value_flag_bit)
-# define is_frozen(a) (((a) & frozen_flag_bit) == frozen_flag_bit)
-# define is_permanent(a) (((a) & permanent_flag_bit) == permanent_flag_bit)
-# define is_immutable(a) (((a) & immutable_flag_bit) == immutable_flag_bit)
-# define is_primitive(a) (((a) & primitive_flag_bit) == primitive_flag_bit)
-# define is_mutable(a) (((a) & mutable_flag_bit) == mutable_flag_bit)
-# define is_noaligned(a) (((a) & noaligned_flag_bit) == noaligned_flag_bit)
-# define is_instance(a) (((a) & instance_flag_bit) == instance_flag_bit)
-# define is_untraced(a) (((a) & untraced_flag_bit) == untraced_flag_bit)
-
-# define is_global(a) (((a) & global_flag_bit) == global_flag_bit)
-# define is_tolerant(a) (((a) & tolerant_flag_bit) == tolerant_flag_bit)
-# define is_protected(a) (((a) & protected_flag_bit) == protected_flag_bit)
-# define is_semiprotected(a) (((a) & semiprotected_flag_bit) == semiprotected_flag_bit)
-# define is_overloaded(a) (((a) & overloaded_flag_bit) == overloaded_flag_bit)
-# define is_aliased(a) (((a) & aliased_flag_bit) == aliased_flag_bit)
-# define is_immediate(a) (((a) & immediate_flag_bit) == immediate_flag_bit)
-# define is_conditional(a) (((a) & conditional_flag_bit) == conditional_flag_bit)
-# define is_value(a) (((a) & value_flag_bit) == value_flag_bit)
-# define is_inherited(a) (((a) & inherited_flag_bit) == inherited_flag_bit)
-# define is_constant(a) (((a) & constant_flag_bit) == constant_flag_bit)
+// do we really need the == here
+
+// # define is_frozen(a) (((a) & frozen_flag_bit) == frozen_flag_bit)
+// # define is_permanent(a) (((a) & permanent_flag_bit) == permanent_flag_bit)
+// # define is_immutable(a) (((a) & immutable_flag_bit) == immutable_flag_bit)
+// # define is_primitive(a) (((a) & primitive_flag_bit) == primitive_flag_bit)
+// # define is_mutable(a) (((a) & mutable_flag_bit) == mutable_flag_bit)
+// # define is_noaligned(a) (((a) & noaligned_flag_bit) == noaligned_flag_bit)
+// # define is_instance(a) (((a) & instance_flag_bit) == instance_flag_bit)
+// # define is_untraced(a) (((a) & untraced_flag_bit) == untraced_flag_bit)
+//
+// # define is_global(a) (((a) & global_flag_bit) == global_flag_bit)
+// # define is_tolerant(a) (((a) & tolerant_flag_bit) == tolerant_flag_bit)
+// # define is_protected(a) (((a) & protected_flag_bit) == protected_flag_bit)
+// # define is_semiprotected(a) (((a) & semiprotected_flag_bit) == semiprotected_flag_bit)
+// # define is_overloaded(a) (((a) & overloaded_flag_bit) == overloaded_flag_bit)
+// # define is_aliased(a) (((a) & aliased_flag_bit) == aliased_flag_bit)
+// # define is_immediate(a) (((a) & immediate_flag_bit) == immediate_flag_bit)
+// # define is_conditional(a) (((a) & conditional_flag_bit) == conditional_flag_bit)
+// # define is_value(a) (((a) & value_flag_bit) == value_flag_bit)
+// # define is_inherited(a) (((a) & inherited_flag_bit) == inherited_flag_bit)
+// # define is_constant(a) (((a) & constant_flag_bit) == constant_flag_bit)
+
+# define is_frozen(a) (((a) & frozen_flag_bit))
+# define is_permanent(a) (((a) & permanent_flag_bit))
+# define is_immutable(a) (((a) & immutable_flag_bit))
+# define is_primitive(a) (((a) & primitive_flag_bit))
+# define is_mutable(a) (((a) & mutable_flag_bit))
+# define is_noaligned(a) (((a) & noaligned_flag_bit))
+# define is_instance(a) (((a) & instance_flag_bit))
+# define is_untraced(a) (((a) & untraced_flag_bit))
+
+# define is_global(a) (((a) & global_flag_bit))
+# define is_tolerant(a) (((a) & tolerant_flag_bit))
+# define is_protected(a) (((a) & protected_flag_bit))
+# define is_semiprotected(a) (((a) & semiprotected_flag_bit))
+# define is_overloaded(a) (((a) & overloaded_flag_bit))
+# define is_aliased(a) (((a) & aliased_flag_bit))
+# define is_immediate(a) (((a) & immediate_flag_bit))
+# define is_conditional(a) (((a) & conditional_flag_bit))
+# define is_value(a) (((a) & value_flag_bit))
+# define is_inherited(a) (((a) & inherited_flag_bit))
+# define is_constant(a) (((a) & constant_flag_bit))
+
# define is_expandable(cmd) (cmd > max_command_cmd)
diff --git a/source/luametatex/source/tex/texerrors.c b/source/luametatex/source/tex/texerrors.c
index 1d1e83dc9..5d94b75d3 100644
--- a/source/luametatex/source/tex/texerrors.c
+++ b/source/luametatex/source/tex/texerrors.c
@@ -42,7 +42,7 @@ error_state_info lmt_error_state = {
.last_warning = NULL,
.last_error_context = NULL,
.help_text = NULL,
- .print_buffer = "",
+ /* .print_buffer = "", */
.intercept = 0,
.last_intercept = 0,
.interaction = 0,
@@ -50,7 +50,7 @@ error_state_info lmt_error_state = {
.set_box_allowed = 0,
.history = 0,
.error_count = 0,
- .err_old_setting = 0,
+ .saved_selector = 0,
.in_error = 0,
.long_help_seen = 0,
.context_indent = 4,
@@ -117,7 +117,7 @@ static void tex_aux_set_last_error_context(void)
static void tex_aux_flush_error(void)
{
if (lmt_error_state.in_error) {
- lmt_print_state.selector = lmt_error_state.err_old_setting;
+ lmt_print_state.selector = lmt_error_state.saved_selector;
lmt_memory_free(lmt_error_state.last_error);
lmt_error_state.last_error = tex_take_string(NULL);
if (lmt_error_state.last_error) {
@@ -141,7 +141,7 @@ static int tex_aux_error_callback_set(void)
static void tex_aux_start_error(void)
{
if (tex_aux_error_callback_set()) {
- lmt_error_state.err_old_setting = lmt_print_state.selector;
+ lmt_error_state.saved_selector = lmt_print_state.selector;
lmt_print_state.selector = new_string_selector_code;
lmt_error_state.in_error = 1 ;
lmt_memory_free(lmt_error_state.last_error);
@@ -521,10 +521,11 @@ void tex_normal_warning(const char *t, const char *p)
int tex_formatted_error(const char *t, const char *fmt, ...)
{
+ char print_buffer[print_buffer_size];
va_list args;
va_start(args, fmt);
- vsnprintf(lmt_error_state.print_buffer, print_buffer_size, fmt, args);
- return tex_normal_error(t, lmt_error_state.print_buffer);
+ vsnprintf(print_buffer, print_buffer_size, fmt, args);
+ return tex_normal_error(t, print_buffer);
/*
va_end(args);
return 0;
@@ -533,19 +534,21 @@ int tex_formatted_error(const char *t, const char *fmt, ...)
void tex_formatted_warning(const char *t, const char *fmt, ...)
{
+ char print_buffer[print_buffer_size];
va_list args;
va_start(args, fmt);
- vsnprintf(lmt_error_state.print_buffer, print_buffer_size, fmt, args);
- tex_normal_warning(t, lmt_error_state.print_buffer);
+ vsnprintf(print_buffer, print_buffer_size, fmt, args);
+ tex_normal_warning(t, print_buffer);
va_end(args);
}
void tex_emergency_message(const char *t, const char *fmt, ...)
{
+ char print_buffer[print_buffer_size];
va_list args;
va_start(args, fmt);
- vsnprintf(lmt_error_state.print_buffer, print_buffer_size, fmt, args);
- fprintf(stdout,"%s : %s\n",t,lmt_error_state.print_buffer);
+ vsnprintf(print_buffer, print_buffer_size, fmt, args);
+ fprintf(stdout,"%s : %s\n", t, print_buffer);
va_end(args);
}
diff --git a/source/luametatex/source/tex/texerrors.h b/source/luametatex/source/tex/texerrors.h
index 8c67b9a45..ea125166c 100644
--- a/source/luametatex/source/tex/texerrors.h
+++ b/source/luametatex/source/tex/texerrors.h
@@ -29,22 +29,22 @@ typedef struct error_state_info {
char *last_warning_tag;
char *last_warning;
char *last_error_context;
- char *help_text; /*tex helps for the next |error| */
- char print_buffer[print_buffer_size];
- int intercept; /*tex intercept error state */
- int last_intercept; /*tex error state number / dimen scanner */
- int interaction; /*tex current level of interaction */
- int default_exit_code; /*tex the exit code can be overloaded */
+ char *help_text; /*tex helps for the next |error| */
+ /* char print_buffer[print_buffer_size]; */
+ int intercept; /*tex intercept error state */
+ int last_intercept; /*tex error state number / dimen scanner */
+ int interaction; /*tex current level of interaction */
+ int default_exit_code; /*tex the exit code can be overloaded */
int set_box_allowed;
int history;
int error_count;
- int err_old_setting;
+ int saved_selector;
int in_error;
int long_help_seen;
int context_indent;
int padding;
- limits_data line_limits;
- limits_data half_line_limits;
+ limits_data line_limits; /*tex these might go some day */
+ limits_data half_line_limits; /*tex these might go some day */
} error_state_info;
extern error_state_info lmt_error_state;
diff --git a/source/luametatex/source/tex/texexpand.c b/source/luametatex/source/tex/texexpand.c
index f257f8b0f..feb20c8d9 100644
--- a/source/luametatex/source/tex/texexpand.c
+++ b/source/luametatex/source/tex/texexpand.c
@@ -88,8 +88,8 @@ inline static void tex_aux_expand_after(void)
if (cur_cmd > max_command_cmd) {
tex_expand_current_token();
} else {
- tex_back_input(t2);
- /* token_link(t1) = t2; */ /* no gain, rarely happens */
+ tex_back_input(t2);
+ /* token_link(t1) = t2; */ /* no gain, rarely happens */
}
tex_back_input(t1);
}
@@ -980,7 +980,7 @@ static void tex_aux_macro_call(halfword cs, halfword cmd, halfword chr)
} else {
/* maybe move the preamble scanner to here */
}
- tex_token_show(chr, default_token_show_max);
+ tex_token_show(chr);
}
tex_end_diagnostic();
}
@@ -1355,7 +1355,7 @@ static void tex_aux_macro_call(halfword cs, halfword cmd, halfword chr)
if (tracing) {
tex_begin_diagnostic();
tex_print_format("%c%c<-", match_visualizer, '0' + nofscanned + (nofscanned > 9 ? gap_match_count : 0));
- tex_show_token_list(pstack[nofscanned - 1], null, default_token_show_max, 0);
+ tex_show_token_list(pstack[nofscanned - 1], 0);
tex_end_diagnostic();
}
} else {
@@ -1449,7 +1449,7 @@ static void tex_aux_macro_call(halfword cs, halfword cmd, halfword chr)
This comes last, after the cleanup and the start of the macro list.
*/
if (nofscanned) {
- tex_copy_pstack_to_param_stack(&pstack[0], nofscanned);
+ tex_copy_to_parameter_stack(&pstack[0], nofscanned);
}
EXIT:
lmt_expand_state.arguments = nofarguments;
diff --git a/source/luametatex/source/tex/texinputstack.c b/source/luametatex/source/tex/texinputstack.c
index 52262e486..7780c17bc 100644
--- a/source/luametatex/source/tex/texinputstack.c
+++ b/source/luametatex/source/tex/texinputstack.c
@@ -67,10 +67,10 @@ input_file_state_info input_file_state = {
are unlikely to overrun.
*/
-# define reserved_input_stack_slots 2
-# define reserved_in_stack_slots 2
-//define reserved_param_stack_slots 32
-# define reserved_param_stack_slots (2 * max_match_count)
+# define reserved_input_stack_slots 2
+# define reserved_in_stack_slots 2
+//define reserved_parameter_stack_slots 32
+# define reserved_parameter_stack_slots (2 * max_match_count)
void tex_initialize_input_state(void)
{
@@ -94,7 +94,7 @@ void tex_initialize_input_state(void)
}
{
int size = lmt_input_state.parameter_stack_data.minimum;
- lmt_input_state.parameter_stack = aux_allocate_clear_array(sizeof(halfword), size, reserved_param_stack_slots);
+ lmt_input_state.parameter_stack = aux_allocate_clear_array(sizeof(halfword), size, reserved_parameter_stack_slots);
if (lmt_input_state.parameter_stack) {
lmt_input_state.parameter_stack_data.allocated = size;
} else {
@@ -155,7 +155,7 @@ static int tex_aux_room_on_in_stack(void) /* quite similar to save_stack checker
return 1;
}
-static int tex_aux_room_on_param_stack(void) /* quite similar to save_stack checker so maybe share */
+static int tex_aux_room_on_parameter_stack(void) /* quite similar to save_stack checker so maybe share */
{
int top = lmt_input_state.parameter_stack_data.ptr;
if (top > lmt_input_state.parameter_stack_data.top) {
@@ -168,7 +168,7 @@ static int tex_aux_room_on_param_stack(void) /* quite similar to save_stack chec
}
if (top > lmt_input_state.parameter_stack_data.allocated) {
lmt_input_state.parameter_stack_data.allocated = top;
- tmp = aux_reallocate_array(lmt_input_state.parameter_stack, sizeof(halfword), top, reserved_param_stack_slots);
+ tmp = aux_reallocate_array(lmt_input_state.parameter_stack, sizeof(halfword), top, reserved_parameter_stack_slots);
lmt_input_state.parameter_stack = tmp;
}
lmt_run_memory_callback("parameter", tmp ? 1 : 0);
@@ -181,9 +181,9 @@ static int tex_aux_room_on_param_stack(void) /* quite similar to save_stack chec
return 1;
}
-void tex_copy_pstack_to_param_stack(halfword *pstack, int n)
+void tex_copy_to_parameter_stack(halfword *pstack, int n)
{
- if (tex_aux_room_on_param_stack()) {
+ if (tex_aux_room_on_parameter_stack()) {
memcpy(&lmt_input_state.parameter_stack[lmt_input_state.parameter_stack_data.ptr], pstack, n * sizeof(halfword));
lmt_input_state.parameter_stack_data.ptr += n;
}
@@ -232,7 +232,7 @@ void tex_show_validity(void)
}
if (p) {
tex_print_ln();
- tex_token_show(p, default_token_show_max > lmt_error_state.line_limits.size - 10 ? lmt_error_state.line_limits.size - 10 : default_token_show_max);
+ tex_token_show(p);
tex_print_ln();
}
}
@@ -266,12 +266,12 @@ void tex_show_runaway(void)
/*tex
- The |param_stack| is an auxiliary array used to hold pointers to the token lists for parameters
+ The |parameter_stack| is an auxiliary array used to hold pointers to the token lists for parameters
at the current level and subsidiary levels of input. This stack is maintained with convention
(2), and it grows at a different rate from the others.
- So, the token list pointers for parameters is |param_stack|, the first unused entry in
- |param_stack| is |param_ptr| which is in the range |0 .. param_size + 9|.
+ So, the token list pointers for parameters is |parameter_stack|, the first unused entry in
+ |parameter_stack| is |parameter_ptr| which is in the range |0 .. parameter_size + 9|.
The input routines must also interact with the processing of |\halign| and |\valign|, since the
appearance of tab marks and |\cr| in certain places is supposed to trigger the beginning of
@@ -543,7 +543,7 @@ void tex_show_context(void)
lmt_print_state.trick_count = 1000000;
if (lmt_input_state.cur_input.state == token_list_state) {
halfword head = lmt_input_state.cur_input.token_type < macro_text ? lmt_input_state.cur_input.start : token_link(lmt_input_state.cur_input.start);
- tex_show_token_list(head, lmt_input_state.cur_input.loc, default_token_show_max, 0);
+ tex_show_token_list_context(head, lmt_input_state.cur_input.loc);
} else if (lmt_input_state.cur_input.name == io_lua_input_code) {
skip = 1;
} else {
@@ -708,7 +708,7 @@ void tex_begin_token_list(halfword t, quarterword kind)
break;
}
tex_print_str("->");
- tex_token_show(t, default_token_show_max);
+ tex_token_show(t);
tex_end_diagnostic();
}
}
@@ -1092,7 +1092,7 @@ void tex_tex_string_start(int iotype, int cattable)
halfword head = tex_scan_general_text(NULL);
int saved_selector = lmt_print_state.selector;
lmt_print_state.selector = new_string_selector_code;
- tex_show_token_list(head, null, extreme_token_show_max, 0);
+ tex_show_token_list(head, 0);
lmt_print_state.selector = saved_selector;
tex_flush_token_list(head);
}
diff --git a/source/luametatex/source/tex/texinputstack.h b/source/luametatex/source/tex/texinputstack.h
index 51ff2ef56..3231365ac 100644
--- a/source/luametatex/source/tex/texinputstack.h
+++ b/source/luametatex/source/tex/texinputstack.h
@@ -21,20 +21,20 @@ typedef struct in_state_record {
union { unsigned short index; unsigned short token_type; }; /*tex: So, no macro but name. */
union { halfword limit; halfword parameter_start; }; /*tex: So, no macro but name. */
halfword name;
- signed short cattable; /*tex The category table used by the current line (see |textoken.c|). */
- unsigned short partial; /*tex Is the current line partial (see |textoken.c|)? */
- int state_file; /*tex Here we stack the tag of the current file. */
- int state_line; /*tex Not used. */
+ short cattable; /*tex The category table used by the current line (see |textoken.c|). */
+ unsigned short partial; /*tex Is the current line partial (see |textoken.c|)? */
+ int state_file; /*tex Here we stack the tag of the current file. */
+ int state_line; /*tex Not used. */
} in_state_record;
typedef struct input_stack_record {
- halfword input_file_callback_id;
- halfword line;
- halfword end_of_file_seen;
- halfword group;
- halfword if_ptr;
- halfword padding;
- char *full_source_filename;
+ halfword input_file_callback_id;
+ halfword line;
+ halfword end_of_file_seen;
+ halfword group;
+ halfword if_ptr;
+ halfword padding;
+ char *full_source_filename;
} input_stack_record;
// todo: better names for in_state_record and input_stack_record ... now mixed up
@@ -421,32 +421,32 @@ typedef enum token_types {
local_loop_text,
} token_types;
-extern void tex_initialize_input_state (void);
-/* int tex_room_on_param_stack (void); */
-/* int tex_room_on_in_stack (void); */
-/* int tex_room_on_input_stack (void); */
-extern void tex_copy_pstack_to_param_stack (halfword *pstack, int n);
-extern void tex_show_context (void);
-extern void tex_show_validity (void);
-extern void tex_set_trick_count (void);
-extern void tex_begin_token_list (halfword t, quarterword kind); /* include some tracing */
-extern void tex_begin_parameter_list (halfword t); /* less inlining code */
-extern void tex_begin_backed_up_list (halfword t); /* less inlining code */
-extern void tex_begin_inserted_list (halfword t); /* less inlining code */
-extern void tex_begin_macro_list (halfword t); /* less inlining code */
-extern void tex_end_token_list (void);
-extern void tex_cleanup_input_state (void);
-extern void tex_back_input (halfword t);
-extern void tex_reinsert_token (halfword t);
-extern void tex_insert_input (halfword h);
-extern void tex_append_input (halfword h);
-extern void tex_begin_file_reading (void);
-extern void tex_end_file_reading (void);
-extern void tex_initialize_inputstack (void);
-extern void tex_lua_string_start (void);
-extern void tex_tex_string_start (int iotype, int cattable);
-extern void tex_any_string_start (char *s);
-extern halfword tex_wrapped_token_list (halfword h);
-extern const char *tex_current_input_file_name (void);
+extern void tex_initialize_input_state (void);
+/* int tex_room_on_parameter_stack (void); */
+/* int tex_room_on_in_stack (void); */
+/* int tex_room_on_input_stack (void); */
+extern void tex_copy_to_parameter_stack (halfword *pstack, int n);
+extern void tex_show_context (void);
+extern void tex_show_validity (void);
+extern void tex_set_trick_count (void);
+extern void tex_begin_token_list (halfword t, quarterword kind); /* include some tracing */
+extern void tex_begin_parameter_list (halfword t); /* less inlining code */
+extern void tex_begin_backed_up_list (halfword t); /* less inlining code */
+extern void tex_begin_inserted_list (halfword t); /* less inlining code */
+extern void tex_begin_macro_list (halfword t); /* less inlining code */
+extern void tex_end_token_list (void);
+extern void tex_cleanup_input_state (void);
+extern void tex_back_input (halfword t);
+extern void tex_reinsert_token (halfword t);
+extern void tex_insert_input (halfword h);
+extern void tex_append_input (halfword h);
+extern void tex_begin_file_reading (void);
+extern void tex_end_file_reading (void);
+extern void tex_initialize_inputstack (void);
+extern void tex_lua_string_start (void);
+extern void tex_tex_string_start (int iotype, int cattable);
+extern void tex_any_string_start (char *s);
+extern halfword tex_wrapped_token_list (halfword h);
+extern const char *tex_current_input_file_name (void);
# endif
diff --git a/source/luametatex/source/tex/texinserts.c b/source/luametatex/source/tex/texinserts.c
index 4ff07625d..15d4b8c53 100644
--- a/source/luametatex/source/tex/texinserts.c
+++ b/source/luametatex/source/tex/texinserts.c
@@ -450,7 +450,7 @@ void tex_run_insert(void)
tex_scan_left_brace();
tex_normal_paragraph(insert_par_context);
tex_push_nest();
- cur_list.mode = -vmode;
+ cur_list.mode = internal_vmode;
cur_list.prev_depth = ignore_depth_criterium_par;
}
diff --git a/source/luametatex/source/tex/texmaincontrol.c b/source/luametatex/source/tex/texmaincontrol.c
index 11007d9cd..a5f3b5334 100644
--- a/source/luametatex/source/tex/texmaincontrol.c
+++ b/source/luametatex/source/tex/texmaincontrol.c
@@ -391,10 +391,8 @@ static void tex_aux_set_lua_value(int a) {
*/
static void tex_aux_run_math_space(void) {
- if (! disable_spaces_par) {
- if (node_type(cur_list.tail) == simple_noad) {
- noad_options(cur_list.tail) |= noad_option_followed_by_space;
- }
+ if (! disable_spaces_par && node_type(cur_list.tail) == simple_noad) {
+ noad_options(cur_list.tail) |= noad_option_followed_by_space;
}
}
@@ -780,10 +778,10 @@ static void tex_aux_run_move(void) {
*/
typedef enum saved_localbox_items {
- saved_localbox_item_location = 0,
- saved_localbox_item_index = 1,
- saved_localbox_item_options = 2,
- saved_localbox_n_of_items = 3,
+ saved_localbox_item_location,
+ saved_localbox_item_index,
+ saved_localbox_item_options,
+ saved_localbox_n_of_items,
} saved_localbox_items;
static void tex_aux_scan_local_box(int code) {
@@ -797,7 +795,7 @@ static void tex_aux_scan_local_box(int code) {
tex_new_save_level(local_box_group);
tex_scan_left_brace();
tex_push_nest();
- cur_list.mode = -hmode;
+ cur_list.mode = restricted_hmode;
cur_list.space_factor = 1000;
}
@@ -1525,24 +1523,12 @@ static void tex_aux_run_lua_function_call(void)
/*tex
The |main_control| uses a jump table, and |init_main_control| sets that table up. We need to
- assign an entry for {\em each} of the three modes!
+ assign an entry for {\em each} of the three modes! The jump table is gone.
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 to have a macro for that as well.
-*/
-
-# if (main_control_mode == 0)
-
- typedef void (*main_control_function)(void);
-
- static main_control_function *jump_table;
-
-# endif
-
-/*tex
-
Here is |main_control| itself. It is quite short nowadays. The initializer is at the end of
this file which saves a nunch of forward declarations.
@@ -1613,7 +1599,7 @@ void tex_local_control(int obeymode)
lmt_main_control_state.local_level += 1;
lmt_main_control_state.control_state = goto_next_state;
if (! obeymode) {
- cur_list.mode = -hmode;
+ cur_list.mode = restricted_hmode;
}
while (1) {
if (lmt_main_control_state.control_state == goto_skip_token_state) {
@@ -1863,7 +1849,7 @@ halfword tex_local_scan_box(void)
{
int old_mode = cur_list.mode;
int old_level = lmt_main_control_state.local_level;
- cur_list.mode = -hmode;
+ cur_list.mode = restricted_hmode;
tex_aux_scan_box(lua_scan_flag, 0, null_flag, -1);
if (lmt_main_control_state.local_level == old_level) {
/*tex |\directlua{print(token.scan_list())}\hbox{!}| (n n) */
@@ -1905,7 +1891,7 @@ static void tex_aux_wrapup_local_scan_box(void)
static void tex_aux_run_insert_dollar_sign(void)
{
tex_back_input(cur_tok);
- cur_tok = math_shift_token + '$';
+ cur_tok = dollar_token_m;
tex_handle_error(
insert_error_type,
"Missing $ inserted",
@@ -2012,20 +1998,33 @@ static void tex_aux_run_end_job(void) {
*/
+static const int glue_filler_codes[] = {
+ fil_glue,
+ fill_glue,
+ filll_glue,
+ fil_neg_glue,
+};
+
static void tex_aux_run_glue(void)
{
switch (cur_chr) {
+ // case fil_code:
+ // tex_tail_append(tex_new_glue_node(fil_glue, user_skip_glue));
+ // break;
+ // case fill_code:
+ // tex_tail_append(tex_new_glue_node(fill_glue, user_skip_glue));
+ // break;
+ // case filll_code: /*tex aka |ss_code| */
+ // tex_tail_append(tex_new_glue_node(filll_glue, user_skip_glue));
+ // break;
+ // case fil_neg_code:
+ // tex_tail_append(tex_new_glue_node(fil_neg_glue, user_skip_glue));
+ // break;
case fil_code:
- tex_tail_append(tex_new_glue_node(fil_glue, user_skip_glue));
- break;
case fill_code:
- tex_tail_append(tex_new_glue_node(fill_glue, user_skip_glue));
- break;
- case filll_code: /*tex aka |ss_code| */
- tex_tail_append(tex_new_glue_node(filll_glue, user_skip_glue));
- break;
+ case filll_code:
case fil_neg_code:
- tex_tail_append(tex_new_glue_node(fil_neg_glue, user_skip_glue));
+ tex_tail_append(tex_new_glue_node(glue_filler_codes[cur_chr], user_skip_glue));
break;
case skip_code:
{
@@ -2215,7 +2214,7 @@ static void tex_aux_run_discretionary(void)
tex_new_save_level(discretionary_group);
tex_scan_left_brace();
tex_push_nest();
- cur_list.mode = -hmode;
+ cur_list.mode = restricted_hmode;
cur_list.space_factor = default_space_factor; /* hm, quite hard coded */
}
break;
@@ -2399,7 +2398,7 @@ static void tex_aux_finish_discretionary(void)
tex_new_save_level(discretionary_group);
tex_scan_left_brace();
tex_push_nest();
- cur_list.mode = -hmode;
+ cur_list.mode = restricted_hmode;
cur_list.space_factor = default_space_factor;
} else {
tex_confusion("finish discretionary");
@@ -3615,11 +3614,17 @@ static void tex_aux_arithmic_register(int a, int code)
case int_val_level:
case attr_val_level:
case dimen_val_level:
- value += original;
- break;
+ if (value) {
+ value += original;
+ break;
+ } else {
+ return;
+ }
case glue_val_level:
case mu_val_level:
- {
+ if (tex_glue_is_zero(value)) {
+ return;
+ } else {
/* Compute the sum of two glue specs */
halfword newvalue = tex_new_glue_spec_node(value);
tex_flush_node(value);
@@ -3651,7 +3656,7 @@ static void tex_aux_arithmic_register(int a, int code)
}
/*tex There is no overflow detection for addition, just wraparound. */
if (simple) {
- tex_define(a, index, simple, value);
+ tex_define(a, index, (singleword) simple, value);
} else {
tex_aux_update_register(a, level, index, value, varcmd);
}
@@ -3662,70 +3667,78 @@ static void tex_aux_arithmic_register(int a, int code)
case multiply_by_code:
{
halfword amount = tex_scan_int(0, NULL);
- switch (level) {
- case int_val_level:
- case attr_val_level:
- value = tex_multiply_integers(original, amount);
- break;
- case dimen_val_level:
- value = tex_nx_plus_y(original, amount, 0);
- break;
- case glue_val_level:
- case mu_val_level:
- {
- halfword newvalue = tex_new_glue_spec_node(original);
- glue_amount(newvalue) = tex_nx_plus_y(glue_amount(original), amount, 0);
- glue_stretch(newvalue) = tex_nx_plus_y(glue_stretch(original), amount, 0);
- glue_shrink(newvalue) = tex_nx_plus_y(glue_shrink(original), amount, 0);
- value = newvalue;
+ if (amount == 1) {
+ return;
+ } else {
+ switch (level) {
+ case int_val_level:
+ case attr_val_level:
+ value = tex_multiply_integers(original, amount);
break;
- }
- default:
- /* error */
- break;
- }
- if (lmt_scanner_state.arithmic_error) {
- tex_aux_arithmic_overflow_error(level, value);
- } else if (simple) {
- tex_define(a, index, simple, value);
- } else {
- tex_aux_update_register(a, level, index, value, varcmd);
+ case dimen_val_level:
+ value = tex_nx_plus_y(original, amount, 0);
+ break;
+ case glue_val_level:
+ case mu_val_level:
+ {
+ halfword newvalue = tex_new_glue_spec_node(original);
+ glue_amount(newvalue) = tex_nx_plus_y(glue_amount(original), amount, 0);
+ glue_stretch(newvalue) = tex_nx_plus_y(glue_stretch(original), amount, 0);
+ glue_shrink(newvalue) = tex_nx_plus_y(glue_shrink(original), amount, 0);
+ value = newvalue;
+ break;
+ }
+ default:
+ /* error */
+ break;
+ }
+ if (lmt_scanner_state.arithmic_error) {
+ tex_aux_arithmic_overflow_error(level, value);
+ } else if (simple) {
+ tex_define(a, index, (singleword) simple, value);
+ } else {
+ tex_aux_update_register(a, level, index, value, varcmd);
+ }
+ break;
}
- break;
}
case divide_code:
tex_scan_optional_keyword("by");
case divide_by_code:
{
halfword amount = tex_scan_int(0, NULL);
- switch (level) {
- case int_val_level:
- case attr_val_level:
- case dimen_val_level:
- value = tex_x_over_n(original, amount);
- break;
- case glue_val_level:
- case mu_val_level:
- {
- halfword newvalue = tex_new_glue_spec_node(original);
- glue_amount(newvalue) = tex_x_over_n(glue_amount(original), amount);
- glue_stretch(newvalue) = tex_x_over_n(glue_stretch(original), amount);
- glue_shrink(newvalue) = tex_x_over_n(glue_shrink(original), amount);
- value = newvalue;
+ if (amount == 1) {
+ return;
+ } else {
+ switch (level) {
+ case int_val_level:
+ case attr_val_level:
+ case dimen_val_level:
+ value = tex_x_over_n(original, amount);
break;
- }
- default:
- /* error */
- break;
- }
- if (lmt_scanner_state.arithmic_error) {
- tex_aux_arithmic_overflow_error(level, value);
- } else if (simple) {
- tex_define(a, index, simple, value);
- } else {
- tex_aux_update_register(a, level, index, value, varcmd);
+ case glue_val_level:
+ case mu_val_level:
+ {
+ halfword newvalue = tex_new_glue_spec_node(original);
+ glue_amount(newvalue) = tex_x_over_n(glue_amount(original), amount);
+ glue_stretch(newvalue) = tex_x_over_n(glue_stretch(original), amount);
+ glue_shrink(newvalue) = tex_x_over_n(glue_shrink(original), amount);
+ value = newvalue;
+ break;
+ }
+ default:
+ /* error */
+ break;
+ }
+ if (lmt_scanner_state.arithmic_error) {
+ tex_aux_arithmic_overflow_error(level, value);
+ } else if (simple) {
+ tex_define(a, index, (singleword) simple, value);
+ } else {
+ tex_aux_update_register(a, level, index, value, varcmd);
+ }
+ break;
}
- break;
}
/*
case advance_by_plus_one_code:
@@ -5355,9 +5368,8 @@ static void tex_aux_set_combine_toks(halfword a)
tex_run_combine_the_toks();
}
-static int tex_aux_set_some_item(halfword a)
+static int tex_aux_set_some_item(void)
{
- (void) a;
switch (cur_chr) {
case lastpenalty_code:
lmt_page_builder_state.last_penalty = tex_scan_int(1, NULL);
@@ -5408,7 +5420,7 @@ static void tex_aux_set_constant_register(halfword cmd, halfword cs, halfword fl
v = tex_scan_glue(mu_val_level, 1);
break;
}
- tex_define(flags, cs, cmd, v);
+ tex_define(flags, cs, (singleword) cmd, v);
}
void tex_run_prefixed_command(void)
@@ -5564,7 +5576,7 @@ void tex_run_prefixed_command(void)
tex_aux_set_combine_toks(flags);
break;
case some_item_cmd:
- if (! tex_aux_set_some_item(flags)) {
+ if (! tex_aux_set_some_item()) {
tex_aux_run_illegal_case();
}
break;
@@ -5665,11 +5677,6 @@ void tex_assign_internal_int_value(int a, halfword p, int val)
{
switch (internal_int_number(p)) {
case par_direction_code:
- {
- check_direction_value(val);
- tex_word_define(a, p, val);
- }
- break;
case math_direction_code:
{
check_direction_value(val);
@@ -5712,13 +5719,13 @@ void tex_assign_internal_int_value(int a, halfword p, int val)
case glyph_scale_code:
case glyph_x_scale_code:
case glyph_y_scale_code:
- if (! val) {
- /* maybe an error message */
- return;
+ /* todo: check for reasonable */
+ if (val) {
+ tex_word_define(a, p, val);
} else {
- /* todo: check for reasonable */
- goto DEFINE;
+ /* maybe an error message */
}
+ break;
case glyph_text_scale_code:
case glyph_script_scale_code:
case glyph_scriptscript_scale_code:
@@ -5732,7 +5739,8 @@ void tex_assign_internal_int_value(int a, halfword p, int val)
);
val = max_limited_scale;
}
- goto DEFINE;
+ tex_word_define(a, p, val);
+ break;
case math_begin_class_code:
case math_end_class_code:
case math_left_class_code:
@@ -5845,7 +5853,7 @@ void tex_assign_internal_int_value(int a, halfword p, int val)
else if (val > adjust_spacing_font) {
val = adjust_spacing_font;
}
- goto DEFINE;
+ goto DEFINE; /* par property */
case protrude_chars_code:
if (val < protrude_chars_off) {
val = protrude_chars_off;
@@ -5853,20 +5861,20 @@ void tex_assign_internal_int_value(int a, halfword p, int val)
else if (val > protrude_chars_advanced) {
val = protrude_chars_advanced;
}
- goto DEFINE;
+ goto DEFINE; /* par property */
case glyph_options_code:
if (val < glyph_option_normal_glyph) {
val = glyph_option_normal_glyph;
} else if (val > glyph_option_all) {
val = glyph_option_all;
}
- goto DEFINE;
+ tex_word_define(a, p, val);
+ break;
case overload_mode_code:
- if (overload_mode_par == 255) {
- return;
- } else {
- goto DEFINE;
+ if (overload_mode_par != 255) {
+ tex_word_define(a, p, val);
}
+ break;
/* We only synchronize these four one way. */
case post_binary_penalty_code:
tex_word_define(a, internal_int_location(first_math_post_penalty_code + binary_noad_subtype), val);
@@ -5959,7 +5967,7 @@ static strnumber tex_aux_scan_string(void)
halfword result = tex_scan_toks_expand(0, NULL, 0);
// saved_selector = lmt_print_state.selector;
lmt_print_state.selector = new_string_selector_code;
- tex_token_show(result, extreme_token_show_max);
+ tex_token_show(result);
tex_flush_token_list(result);
lmt_print_state.selector = saved_selector;
return tex_make_string(); /* todo: we can use take_string instead but happens only @ error */
@@ -6170,7 +6178,7 @@ static void tex_aux_run_show_whatever(void)
halfword head = tex_the_value_toks(the_code, NULL, 0);
tex_print_nlp();
tex_print_str("> ");
- tex_show_token_list(head, null, default_token_show_max, 0);
+ tex_show_token_list(head, 0);
tex_flush_token_list(head);
goto COMMON_ENDING;
}
@@ -6193,7 +6201,7 @@ static void tex_aux_run_show_whatever(void)
halfword head = tex_the_detokenized_toks(NULL);
tex_print_nlp();
tex_print_str("> ");
- tex_show_token_list(head, null, default_token_show_max, 0);
+ tex_show_token_list(head, 0);
tex_flush_token_list(head);
goto COMMON_ENDING;
}
@@ -6260,31 +6268,7 @@ static void tex_aux_run_show_whatever(void)
*/
-# if (main_control_mode == 0)
-
-# define register_runner(A,B,C,D) \
- jump_table[vmode+(A)] = B; \
- jump_table[hmode+(A)] = C; \
- jump_table[mmode+(A)] = D
-
-# define register_simple(A,B) \
- jump_table[vmode+(A)] = B; \
- jump_table[hmode+(A)] = B; \
- jump_table[mmode+(A)] = B
-
-# define register_asmath(A,B,C) \
- jump_table[vmode+(A)] = B; \
- jump_table[hmode+(A)] = B; \
- jump_table[mmode+(A)] = C
-
-inline static void init_main_control(void)
-{
-
- jump_table = lmt_memory_malloc((mmode + max_command_cmd + 1) * sizeof(main_control_function)) ;
-
- if (jump_table) {
-
-# elif (main_control_mode == 1)
+# if 0
# define register_runner(A,B,C,D) \
case A: \
@@ -6305,31 +6289,6 @@ inline static void tex_aux_big_switch(int mode, int cmd)
{
switch (cmd) {
-
-# else
-
-# define register_runner(A,B,C,D) \
- case (vmode + A): B(); break; \
- case (hmode + A): C(); break; \
- case (mmode + A): D(); break;
-
-# define register_simple(A,B) \
- case (vmode + A): B(); break; \
- case (hmode + A): B(); break; \
- case (mmode + A): B(); break;
-
-# define register_asmath(A,B,C) \
- case (vmode + A): B(); break; \
- case (hmode + A): B(); break; \
- case (mmode + A): C(); break;
-
-inline static void tex_aux_big_switch(int mode, int cmd)
-{
-
- switch (mode + cmd) {
-
-# endif
-
/*tex These have the same handler for each mode: */
register_simple(arithmic_cmd, tex_run_prefixed_command);
@@ -6482,31 +6441,280 @@ inline static void tex_aux_big_switch(int mode, int cmd)
/*tex The next is unlikely to happen but compilers like the check. */
-# if (main_control_mode == 0)
- } else {
-# else
default:
- printf("cmd code %i", cmd);
+ /* printf("cmd code %i", cmd); */
tex_confusion("unknown cmd code");
break;
-# endif
}
}
-# if (main_control_mode == 0)
+# else
inline static void tex_aux_big_switch(int mode, int cmd)
{
- (jump_table[mode + cmd])();
+
+ switch (cmd) {
+
+ case arithmic_cmd:
+ case register_attribute_cmd:
+ case internal_attribute_cmd:
+ case register_dimen_cmd:
+ case internal_dimen_cmd:
+ case set_font_property_cmd :
+ case register_glue_cmd:
+ case internal_glue_cmd:
+ case register_int_cmd :
+ case internal_int_cmd :
+ case register_mu_glue_cmd:
+ case internal_mu_glue_cmd:
+ case register_toks_cmd:
+ case internal_toks_cmd:
+ case define_char_code_cmd:
+ case def_cmd:
+ case define_family_cmd:
+ case define_font_cmd:
+ case hyphenation_cmd:
+ case let_cmd:
+ case prefix_cmd:
+ case register_cmd:
+ case set_auxiliary_cmd:
+ case set_box_cmd:
+ case set_box_property_cmd:
+ case set_font_cmd:
+ case set_interaction_cmd:
+ case set_math_parameter_cmd:
+ case set_page_property_cmd:
+ case set_specification_cmd:
+ case shorthand_def_cmd:
+ case lua_value_cmd:
+ case integer_cmd:
+ case dimension_cmd:
+ case gluespec_cmd:
+ case mugluespec_cmd:
+ case combine_toks_cmd:
+ case some_item_cmd: tex_run_prefixed_command(); break;
+ case fontspec_cmd: tex_run_font_spec(); break;
+ case iterator_value_cmd:
+ case parameter_cmd: tex_aux_run_illegal_case(); break;
+ case after_something_cmd: tex_aux_run_after_something(); break;
+ case begin_group_cmd: tex_aux_run_begin_group(); break;
+ case penalty_cmd: tex_aux_run_penalty(); break;
+ case case_shift_cmd: tex_aux_run_shift_case(); break;
+ case catcode_table_cmd: tex_aux_run_catcode_table(); break;
+ case end_cs_name_cmd: tex_aux_run_cs_error(); break;
+ case end_group_cmd: tex_aux_run_end_group(); break;
+ case end_local_cmd: tex_aux_run_end_local(); break;
+ case ignore_something_cmd: tex_aux_run_ignore_something(); break;
+ case insert_cmd: tex_run_insert(); break;
+ case kern_cmd: tex_aux_run_kern(); break;
+ case leader_cmd: tex_aux_run_leader(); break;
+ case legacy_cmd: tex_aux_run_legacy(); break;
+ case local_box_cmd: tex_aux_run_local_box(); break;
+ case lua_protected_call_cmd: tex_aux_run_lua_protected_call(); break;
+ case lua_function_call_cmd: tex_aux_run_lua_function_call(); break;
+ case make_box_cmd: tex_aux_run_make_box(); break;
+ case set_mark_cmd: tex_run_mark(); break;
+ case message_cmd: tex_aux_run_message(); break;
+ case node_cmd: tex_aux_run_node(); break;
+ case relax_cmd:
+ case ignore_cmd: tex_aux_run_relax(); break;
+ case active_char_cmd: tex_aux_run_active(); break;
+ case remove_item_cmd: tex_aux_run_remove_item(); break;
+ case right_brace_cmd: tex_aux_run_right_brace(); break;
+ case vcenter_cmd: tex_run_vcenter(); break;
+ case xray_cmd: tex_aux_run_show_whatever(); break;
+ case alignment_cmd:
+ case alignment_tab_cmd: tex_run_alignment_error(); break;
+ case end_template_cmd: tex_run_alignment_end_template(); break;
+
+ /* */
+
+ case math_fraction_cmd: mode == mmode ? tex_run_math_fraction() : tex_aux_run_insert_dollar_sign(); break;
+ case delimiter_number_cmd: mode == mmode ? tex_run_math_delimiter_number() : tex_aux_run_insert_dollar_sign(); break;
+ case math_fence_cmd: mode == mmode ? tex_run_math_fence() : tex_aux_run_insert_dollar_sign(); break;
+ case math_modifier_cmd: mode == mmode ? tex_run_math_modifier() : tex_aux_run_insert_dollar_sign(); break;
+ case math_accent_cmd: mode == mmode ? tex_run_math_accent() : tex_aux_run_insert_dollar_sign(); break;
+ case math_choice_cmd: mode == mmode ? tex_run_math_choice() : tex_aux_run_insert_dollar_sign(); break;
+ case math_component_cmd: mode == mmode ? tex_run_math_math_component() : tex_aux_run_insert_dollar_sign(); break;
+ case math_style_cmd: mode == mmode ? tex_run_math_style() : tex_aux_run_insert_dollar_sign(); break;
+ case mkern_cmd: mode == mmode ? tex_aux_run_mkern() : tex_aux_run_insert_dollar_sign(); break;
+ case mskip_cmd: mode == mmode ? tex_aux_run_mglue() : tex_aux_run_insert_dollar_sign(); break;
+ case math_radical_cmd: mode == mmode ? tex_run_math_radical() : tex_aux_run_insert_dollar_sign(); break;
+ case subscript_cmd:
+ case superscript_cmd:
+ case math_script_cmd: mode == mmode ? tex_run_math_script() : tex_aux_run_insert_dollar_sign(); break;
+
+ case equation_number_cmd: mode == mmode ? tex_run_math_equation_number() : tex_aux_run_illegal_case(); break;
+ case left_brace_cmd: mode == mmode ? tex_run_math_left_brace() : tex_aux_run_left_brace(); break;
+
+ /* */
+
+ case vadjust_cmd: mode == vmode ? tex_aux_run_illegal_case() : tex_run_vadjust(); break;
+ case discretionary_cmd: mode == vmode ? tex_aux_run_new_paragraph() : tex_aux_run_discretionary(); break;
+ case explicit_space_cmd: mode == vmode ? tex_aux_run_new_paragraph() : tex_aux_run_space(); break;
+ case hmove_cmd: mode == vmode ? tex_aux_run_move() : tex_aux_run_illegal_case(); break;
+ case vmove_cmd: mode == vmode ? tex_aux_run_illegal_case() : tex_aux_run_move(); break;
+ case hskip_cmd: mode == vmode ? tex_aux_run_new_paragraph() : tex_aux_run_glue(); break;
+ case un_hbox_cmd: mode == vmode ? tex_aux_run_new_paragraph() : tex_run_unpackage(); break;
+
+ /* */
+
+ case math_char_number_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_math_non_math(); break;
+ case hmode: tex_run_text_math_char_number(); break;
+ case mmode: tex_run_math_math_char_number(); break;
+ }
+ break;
+ case italic_correction_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_illegal_case(); break;
+ case hmode: tex_aux_run_text_italic_correction(); break;
+ case mmode: tex_run_math_italic_correction(); break;
+ }
+ break;
+ case mathspec_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_math_non_math(); break;
+ case hmode: tex_run_text_math_spec(); break;
+ case mmode: tex_run_math_math_spec(); break;
+ }
+ break;
+ case char_given_cmd:
+ case other_char_cmd:
+ case letter_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_aux_run_text_letter(); break;
+ case mmode: tex_run_math_letter(); break;
+ }
+ break;
+
+ case accent_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_aux_run_text_accent(); break;
+ case mmode: tex_run_math_accent(); break;
+ }
+ break;
+ case boundary_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_par_boundary(); break;
+ case hmode: tex_aux_run_text_boundary(); break;
+ case mmode: tex_aux_run_math_boundary(); break;
+ }
+ break;
+ case char_number_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_aux_run_text_char_number(); break;
+ case mmode: tex_run_math_char_number(); break;
+ }
+ break;
+ case math_shift_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_run_math_initialize(); break;
+ case mmode: tex_run_math_shift(); break;
+ }
+ break;
+ case math_shift_cs_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_run_math_initialize(); break;
+ case mmode: tex_run_math_shift(); break;
+ }
+ break;
+ case end_paragraph_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_paragraph_end_vmode(); break;
+ case hmode: tex_aux_run_paragraph_end_hmode(); break;
+ case mmode: tex_aux_run_relax(); break;
+ }
+ break;
+ case spacer_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_relax(); break;
+ case hmode: tex_aux_run_space(); break;
+ case mmode: tex_aux_run_math_space(); break;
+ }
+ break;
+ case begin_paragraph_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_begin_paragraph_vmode(); break;
+ case hmode: tex_aux_run_begin_paragraph_hmode(); break;
+ case mmode: tex_aux_run_begin_paragraph_mmode(); break;
+ }
+ break;
+ case end_job_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_end_job(); break;
+ case hmode: tex_aux_run_head_for_vmode(); break;
+ case mmode: tex_aux_run_insert_dollar_sign(); break;
+ }
+ break;
+
+ case vskip_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_glue(); break;
+ case hmode: tex_aux_run_head_for_vmode(); break;
+ case mmode: tex_aux_run_insert_dollar_sign(); break;
+ }
+ break;
+ case un_vbox_cmd:
+ switch (mode) {
+ case vmode: tex_run_unpackage(); break;
+ case hmode: tex_aux_run_head_for_vmode(); break;
+ case mmode: tex_aux_run_insert_dollar_sign(); break;
+ }
+ break;
+
+ case halign_cmd:
+ switch (mode) {
+ case vmode: tex_run_alignment_initialize(); break;
+ case hmode: tex_aux_run_head_for_vmode(); break;
+ case mmode: tex_aux_run_halign_mmode(); break;
+ }
+ break;
+ case valign_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_run_alignment_initialize(); break;
+ case mmode: tex_aux_run_insert_dollar_sign(); break;
+ }
+ break;
+
+ case hrule_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_hrule(); break;
+ case hmode: tex_aux_run_head_for_vmode(); break;
+ case mmode: tex_aux_run_insert_dollar_sign(); break;
+ }
+ break;
+ case vrule_cmd:
+ switch (mode) {
+ case vmode: tex_aux_run_new_paragraph(); break;
+ case hmode: tex_aux_run_vrule(); break;
+ case mmode: tex_aux_run_mrule(); break;
+ }
+ break;
+
+ /* */
+
+ default:
+ /*tex The next is unlikely to happen but compilers like the check. */
+ tex_confusion("unknown cmd code");
+ break;
+ }
+
}
-# endif
+# endif
/*tex
Some preset values no longer make sense, like family 1 for some math symbols but we keep them
for compatibility reasons. All settings are moved to the relevant modules.
-
*/
void tex_initialize_variables(void)
diff --git a/source/luametatex/source/tex/texmath.c b/source/luametatex/source/tex/texmath.c
index ec30de1ca..134399c53 100644
--- a/source/luametatex/source/tex/texmath.c
+++ b/source/luametatex/source/tex/texmath.c
@@ -315,7 +315,7 @@ static void tex_aux_unsave_math(void)
/*tex
Sometimes it is necessary to destroy an mlist. The following subroutine empties the current
- list, assuming that |abs(mode) = mmode|.
+ list, assuming that |abs(mode) = mmode| aka |is_m_mode(mode)|.
*/
@@ -1225,7 +1225,7 @@ static void tex_aux_push_math(quarterword group, int style)
cur_list.math_end = math_end_class_par;
cur_list.math_main_style = style;
tex_push_nest();
- cur_list.mode = -mmode;
+ cur_list.mode = inline_mmode;
cur_list.incomplete_noad = null;
cur_list.math_style = style;
tex_aux_new_save_level_math(group);
@@ -1938,7 +1938,7 @@ static void tex_aux_append_math_fence(halfword fence, quarterword mathclass)
node_subtype(fence) = left_fence_side;
node_next(cur_list.head) = fence;
cur_list.tail = fence;
- cur_list.delim = fence;
+ cur_list.delimiter = fence;
}
break;
case close_noad_subtype:
@@ -1962,7 +1962,7 @@ static void tex_aux_append_math_fence(halfword fence, quarterword mathclass)
node_subtype(fence) = middle_fence_side;
node_next(cur_list.head) = q;
cur_list.tail = fence;
- cur_list.delim = fence;
+ cur_list.delimiter = fence;
}
break;
}
@@ -3047,12 +3047,12 @@ void tex_run_math_choice(void) {
int tex_current_math_style(void)
{
- return (abs(cur_list.mode) == mmode) ? cur_list.math_style : -1;
+ return is_m_mode(cur_list.mode) ? cur_list.math_style : -1;
}
int tex_current_math_main_style(void)
{
- return (abs(cur_list.mode) == mmode) ? cur_list.math_main_style : -1;
+ return is_m_mode(cur_list.mode) ? cur_list.math_main_style : -1;
}
void tex_finish_math_choice(void)
@@ -3740,11 +3740,11 @@ static halfword tex_aux_finish_math_list(halfword p)
if (p) {
halfword numerator = fraction_numerator(cur_list.incomplete_noad);
q = kernel_math_list(numerator);
- if ((node_type(q) != fence_noad) || (node_subtype(q) != left_fence_side) || (! cur_list.delim)) {
+ if ((node_type(q) != fence_noad) || (node_subtype(q) != left_fence_side) || (! cur_list.delimiter)) {
tex_confusion("right fence");
}
- kernel_math_list(numerator) = node_next(cur_list.delim);
- node_next(cur_list.delim) = cur_list.incomplete_noad;
+ kernel_math_list(numerator) = node_next(cur_list.delimiter);
+ node_next(cur_list.delimiter) = cur_list.incomplete_noad;
node_next(cur_list.incomplete_noad) = p;
} else {
q = cur_list.incomplete_noad;
@@ -4171,7 +4171,7 @@ void tex_run_math_fence(void)
tex_aux_push_math(math_fence_group, style);
node_next(cur_list.head) = fence;
cur_list.tail = fence;
- cur_list.delim = fence;
+ cur_list.delimiter = fence;
tex_set_saved_record(saved_operator_item_variant, operator_variant_save_type, 0, math_limits_top);
lmt_save_state.save_stack_data.ptr += saved_operator_n_of_items;
tex_aux_push_math(math_operator_group, tex_math_style_variant(style, math_parameter_superscript_variant));
diff --git a/source/luametatex/source/tex/texnesting.c b/source/luametatex/source/tex/texnesting.c
index 4ec68b28b..81d716958 100644
--- a/source/luametatex/source/tex/texnesting.c
+++ b/source/luametatex/source/tex/texnesting.c
@@ -48,48 +48,25 @@
switch} can select the appropriate thing to do by computing the value |abs(mode) + cur_cmd|,
where |mode| is the current mode and |cur_cmd| is the current command code.
-*/
-
-# if main_control_mode == 0
+ Per end December 2022 we no longer use the larg emode numbers that also encode the command at
+ hand. That code is in the archive.
-const char *tex_string_mode(int m)
-{
- if (m > 0) {
- switch (m / (max_command_cmd + 1)) {
- case 0: return "vertical mode";
- case 1: return "horizontal mode";
- case 2: return "display math mode";
- }
- } else if (m == 0) {
- return "no mode";
- } else {
- switch ((-m) / (max_command_cmd + 1)) {
- case 0: return "internal vertical mode";
- case 1: return "restricted horizontal mode";
- case 2: return "math mode";
- }
- }
- return "unknown mode";
-}
-
-# else
+*/
const char *tex_string_mode(int m)
{
switch (m) {
- case nomode: return "no mode";
- case vmode : return "vertical mode";
- case hmode : return "horizontal mode";
- case mmode : return "display math mode";
- case -vmode : return "internal vertical mode";
- case -hmode : return "restricted horizontal mode";
- case -mmode : return "math mode";
- default : return "unknown mode";
+ case nomode : return "no mode";
+ case vmode : return "vertical mode";
+ case hmode : return "horizontal mode";
+ case mmode : return "display math mode";
+ case internal_vmode : return "internal vertical mode";
+ case restricted_hmode: return "restricted horizontal mode";
+ case inline_mmode : return "inline math mode";
+ default : return "unknown mode";
}
}
-# endif
-
/*tex
The state of affairs at any semantic level can be represented by five values:
@@ -244,7 +221,7 @@ void tex_initialize_nesting(void)
cur_list.mode = vmode;
cur_list.head = contribute_head;
cur_list.tail = contribute_head;
- cur_list.delim = null;
+ cur_list.delimiter = null;
cur_list.prev_graf = 0;
cur_list.mode_line = 0;
cur_list.prev_depth = ignore_depth; /*tex |ignore_depth_criterium_par| is not yet available! */
@@ -297,7 +274,7 @@ void tex_push_nest(void)
cur_list.mode = top->mode;
cur_list.head = tex_new_temp_node();
cur_list.tail = cur_list.head;
- cur_list.delim = null;
+ cur_list.delimiter = null;
cur_list.prev_graf = 0;
cur_list.mode_line = lmt_input_state.input_line;
cur_list.prev_depth = top->prev_depth;
@@ -386,8 +363,9 @@ void tex_show_activities(void)
tex_show_box(node_next(n.head));
tex_print_format("%l[end list]");
/*tex Show the auxiliary field, |a|. */
- switch (abs(n.mode) / (max_command_cmd + 1)) {
- case 0:
+ switch (n.mode) {
+ case vmode:
+ case internal_vmode:
{
if (n.prev_depth <= ignore_depth_criterium_par) {
tex_print_format("%l[prevdepth ignored");
@@ -400,11 +378,8 @@ void tex_show_activities(void)
tex_print_char(']');
break;
}
- case 1:
- {
- break;
- }
- case 2:
+ case mmode:
+ case inline_mmode:
{
if (n.incomplete_noad) {
tex_print_format("%l[this will be denominator of:]");
@@ -421,7 +396,7 @@ void tex_show_activities(void)
int tex_vmode_nest_index(void)
{
int p = lmt_nest_state.nest_data.ptr; /* index into |nest| */
- while (abs(lmt_nest_state.nest[p].mode) != vmode) {
+ while (! is_v_mode(lmt_nest_state.nest[p].mode)) {
--p;
}
return p;
diff --git a/source/luametatex/source/tex/texnesting.h b/source/luametatex/source/tex/texnesting.h
index 91251eee0..1f87dbb22 100644
--- a/source/luametatex/source/tex/texnesting.h
+++ b/source/luametatex/source/tex/texnesting.h
@@ -5,32 +5,37 @@
# ifndef LMT_NESTING_H
# define LMT_NESTING_H
+/*
+ Todo: make this record 6*4 smaller, not all are halfwords, although padding might then make us
+ end up with the same size. We also end up with plenty of casts elsewhere.
+*/
+
typedef struct list_state_record {
- int mode;
- halfword head;
- halfword tail;
- int prev_graf;
- int mode_line;
- halfword prev_depth; // scaled
- halfword space_factor;
- halfword direction_stack;
- int math_dir;
- int math_style;
- int math_scale;
- int math_main_style;
- halfword delim;
- halfword incomplete_noad;
- halfword math_flatten;
- halfword math_begin;
- halfword math_end;
- halfword math_mode;
+ int mode; // singleword
+ halfword head;
+ halfword tail;
+ int prev_graf;
+ int mode_line;
+ halfword prev_depth; // scaled
+ halfword space_factor;
+ halfword direction_stack;
+ int math_dir; // singleword
+ int math_style; // singleword
+ int math_scale;
+ int math_main_style; // singleword
+ halfword delimiter; // todo: get rid of these and use the stack
+ halfword incomplete_noad; // todo: get rid of these and use the stack
+ halfword math_flatten; // singleword
+ halfword math_begin; // singleword
+ halfword math_end; // singleword
+ halfword math_mode; // singleword
} list_state_record;
typedef struct nest_state_info {
list_state_record *nest;
memory_data nest_data;
- int shown_mode;
- int math_mode;
+ int shown_mode; // singleword
+ int math_mode; // singleword
} nest_state_info;
extern nest_state_info lmt_nest_state;
diff --git a/source/luametatex/source/tex/texnodes.c b/source/luametatex/source/tex/texnodes.c
index f6daab056..27b9520e3 100644
--- a/source/luametatex/source/tex/texnodes.c
+++ b/source/luametatex/source/tex/texnodes.c
@@ -1114,7 +1114,7 @@ halfword tex_copy_node_only(halfword p)
} \
} while (0)
-halfword tex_copy_node(halfword p)
+halfword tex_copy_node(halfword p) /* how about null */
{
/*tex
We really need a stub for copying because mem might move in the meantime due to resizing!
@@ -2728,10 +2728,10 @@ void tex_show_node_list(halfword p, int threshold, int max)
tex_print_format(", yoffset %R", rule_y_offset(p));
}
if (rule_font(p)) {
- if (rule_font(p) < 0 || rule_font(p) >= rule_font_fam_offset) {
- tex_print_format(", font %F", rule_font(p));
- } else {
+ if (rule_font(p) >= rule_font_fam_offset) {
tex_print_format(", family %i", rule_font(p) - rule_font_fam_offset);
+ } else {
+ tex_print_format(", font %F", rule_font(p) < 0 ? 0 : rule_font(p));
}
}
if (rule_character(p)) {
@@ -3365,30 +3365,6 @@ scaled tex_glyph_depth(halfword p) /* not used */
return d < 0 ? 0 : d;
}
-// scaledwhd tex_glyph_dimensions(halfword p)
-// {
-// scaledwhd whd = { 0, 0, 0, 0 };
-// scaled x = glyph_x_offset(p);
-// scaled y = glyph_y_offset(p);
-// whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p);
-// whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p);
-// whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p));
-// if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) {
-// whd.wd += x;
-// }
-// if (y && tex_has_glyph_option(p, glyph_option_apply_y_offset)) {
-// whd.ht += y;
-// whd.dp -= y;
-// }
-// if (whd.ht < 0) {
-// whd.ht = 0;
-// }
-// if (whd.dp < 0) {
-// whd.dp = 0;
-// }
-// return whd;
-// }
-
scaledwhd tex_glyph_dimensions(halfword p)
{
scaledwhd whd = tex_char_whd_from_glyph(p);
@@ -3413,33 +3389,6 @@ scaledwhd tex_glyph_dimensions(halfword p)
return whd;
}
-// scaledwhd tex_glyph_dimensions_ex(halfword p)
-// {
-// scaledwhd whd = { 0, 0, 0, 0 };
-// scaled x = glyph_x_offset(p);
-// scaled y = glyph_y_offset(p);
-// whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p);
-// whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p);
-// whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p));
-// if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) {
-// whd.wd += x;
-// }
-// if (y && tex_has_glyph_option(p, glyph_option_apply_y_offset)) {
-// whd.ht += y;
-// whd.dp -= y;
-// }
-// if (whd.ht < 0) {
-// whd.ht = 0;
-// }
-// if (whd.dp < 0) {
-// whd.dp = 0;
-// }
-// if (whd.wd && glyph_expansion(p)) {
-// whd.wd = tex_ext_xn_over_d(whd.wd, 1000000 + glyph_expansion(p), 1000000);
-// }
-// return whd;
-// }
-
scaledwhd tex_glyph_dimensions_ex(halfword p)
{
scaledwhd whd = tex_char_whd_from_glyph(p);
@@ -3467,38 +3416,11 @@ scaledwhd tex_glyph_dimensions_ex(halfword p)
return whd;
}
-
scaled tex_glyph_total(halfword p)
{
- // scaled ht = tex_char_height_from_glyph(p);
- // scaled dp = tex_char_depth_from_glyph(p);
- // if (ht < 0) {
- // ht = 0;
- // }
- // if (dp < 0) {
- // dp = 0;
- // }
- // return ht + dp;
return tex_char_total_from_glyph(p);
}
-// int tex_glyph_has_dimensions(halfword p)
-// {
-// scaled offset = glyph_x_offset(p);
-// scaled amount = tex_char_width_from_glyph(p);
-// if (offset && tex_has_glyph_option(p, glyph_option_apply_x_offset)) {
-// amount += offset;
-// }
-// amount -= (glyph_left(p) + glyph_right(p));
-// if (amount) {
-// return 1;
-// } else {
-// amount = tex_char_total_from_glyph(p);
-// /* here offset and raise just moves */
-// return amount != 0;
-// }
-// }
-
int tex_glyph_has_dimensions(halfword p)
{
scaledwhd whd = tex_char_whd_from_glyph(p);
@@ -3880,6 +3802,7 @@ static halfword tex_aux_internal_to_par_code(halfword cmd, halfword index) {
case shaping_penalties_mode_code : return par_shaping_penalties_mode_code;
case shaping_penalty_code : return par_shaping_penalty_code;
}
+ break;
case internal_dimen_cmd:
switch (index) {
case hsize_code : return par_hsize_code;
@@ -3888,6 +3811,7 @@ static halfword tex_aux_internal_to_par_code(halfword cmd, halfword index) {
case emergency_stretch_code : return par_emergency_stretch_code;
case line_skip_limit_code : return par_line_skip_limit_code;
}
+ break;
case internal_glue_cmd:
switch (index) {
case left_skip_code : return par_left_skip_code;
@@ -3899,6 +3823,7 @@ static halfword tex_aux_internal_to_par_code(halfword cmd, halfword index) {
case baseline_skip_code : return par_baseline_skip_code;
case line_skip_code : return par_line_skip_code;
}
+ break;
case specification_reference_cmd:
switch (index) {
case par_shape_code : return par_par_shape_code;
@@ -3908,6 +3833,7 @@ static halfword tex_aux_internal_to_par_code(halfword cmd, halfword index) {
case display_widow_penalties_code: return par_display_widow_penalties_code;
case orphan_penalties_code : return par_orphan_penalties_code;
}
+ break;
}
return -1;
}
@@ -4150,6 +4076,82 @@ void tex_set_par_par(halfword p, halfword what, halfword v, int force)
}
}
+/*
+ This is the reference but as it's called often we use an inlined variant with less redudant
+ testing and branching.
+*/
+
+/*
+ void tex_snapshot_par(halfword p, halfword what)
+ {
+ if (p && lmt_main_state.run_state != initializing_state) {
+ int unset = 0;
+ if (what) {
+ if (what < 0) {
+ unset = 1;
+ what = -what;
+ }
+ if (what > par_all_category) {
+ what = par_all_category;
+ }
+ } else {
+ unset = 1;
+ what = par_all_category;
+ }
+ if (tex_par_to_be_set(what, par_hsize_code)) { tex_set_par_par(p, par_hsize_code, unset ? null : hsize_par, 1); }
+ if (tex_par_to_be_set(what, par_left_skip_code)) { tex_set_par_par(p, par_left_skip_code, unset ? null : left_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_right_skip_code)) { tex_set_par_par(p, par_right_skip_code, unset ? null : right_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_hang_indent_code)) { tex_set_par_par(p, par_hang_indent_code, unset ? null : hang_indent_par, 1); }
+ if (tex_par_to_be_set(what, par_hang_after_code)) { tex_set_par_par(p, par_hang_after_code, unset ? null : hang_after_par, 1); }
+ if (tex_par_to_be_set(what, par_par_indent_code)) { tex_set_par_par(p, par_par_indent_code, unset ? null : par_indent_par, 1); }
+ if (tex_par_to_be_set(what, par_par_fill_left_skip_code)) { tex_set_par_par(p, par_par_fill_left_skip_code, unset ? null : par_fill_left_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_par_fill_right_skip_code)) { tex_set_par_par(p, par_par_fill_right_skip_code, unset ? null : par_fill_right_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_par_init_left_skip_code)) { tex_set_par_par(p, par_par_init_left_skip_code, unset ? null : par_init_left_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_par_init_right_skip_code)) { tex_set_par_par(p, par_par_init_right_skip_code, unset ? null : par_init_right_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_adjust_spacing_code)) { tex_set_par_par(p, par_adjust_spacing_code, unset ? null : adjust_spacing_par, 1); }
+ if (tex_par_to_be_set(what, par_protrude_chars_code)) { tex_set_par_par(p, par_protrude_chars_code, unset ? null : protrude_chars_par, 1); }
+ if (tex_par_to_be_set(what, par_pre_tolerance_code)) { tex_set_par_par(p, par_pre_tolerance_code, unset ? null : pre_tolerance_par, 1); }
+ if (tex_par_to_be_set(what, par_tolerance_code)) { tex_set_par_par(p, par_tolerance_code, unset ? null : tolerance_par, 1); }
+ if (tex_par_to_be_set(what, par_emergency_stretch_code)) { tex_set_par_par(p, par_emergency_stretch_code, unset ? null : emergency_stretch_par, 1); }
+ if (tex_par_to_be_set(what, par_looseness_code)) { tex_set_par_par(p, par_looseness_code, unset ? null : looseness_par, 1); }
+ if (tex_par_to_be_set(what, par_last_line_fit_code)) { tex_set_par_par(p, par_last_line_fit_code, unset ? null : last_line_fit_par, 1); }
+ if (tex_par_to_be_set(what, par_line_penalty_code)) { tex_set_par_par(p, par_line_penalty_code, unset ? null : line_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_inter_line_penalty_code)) { tex_set_par_par(p, par_inter_line_penalty_code, unset ? null : inter_line_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_club_penalty_code)) { tex_set_par_par(p, par_club_penalty_code, unset ? null : club_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_widow_penalty_code)) { tex_set_par_par(p, par_widow_penalty_code, unset ? null : widow_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_display_widow_penalty_code)) { tex_set_par_par(p, par_display_widow_penalty_code, unset ? null : display_widow_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_orphan_penalty_code)) { tex_set_par_par(p, par_orphan_penalty_code, unset ? null : orphan_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_broken_penalty_code)) { tex_set_par_par(p, par_broken_penalty_code, unset ? null : broken_penalty_par, 1); }
+ if (tex_par_to_be_set(what, par_adj_demerits_code)) { tex_set_par_par(p, par_adj_demerits_code, unset ? null : adj_demerits_par, 1); }
+ if (tex_par_to_be_set(what, par_double_hyphen_demerits_code)) { tex_set_par_par(p, par_double_hyphen_demerits_code, unset ? null : double_hyphen_demerits_par, 1); }
+ if (tex_par_to_be_set(what, par_final_hyphen_demerits_code)) { tex_set_par_par(p, par_final_hyphen_demerits_code, unset ? null : final_hyphen_demerits_par, 1); }
+ if (tex_par_to_be_set(what, par_par_shape_code)) { tex_set_par_par(p, par_par_shape_code, unset ? null : par_shape_par, 1); }
+ if (tex_par_to_be_set(what, par_inter_line_penalties_code)) { tex_set_par_par(p, par_inter_line_penalties_code, unset ? null : inter_line_penalties_par, 1); }
+ if (tex_par_to_be_set(what, par_club_penalties_code)) { tex_set_par_par(p, par_club_penalties_code, unset ? null : club_penalties_par, 1); }
+ if (tex_par_to_be_set(what, par_widow_penalties_code)) { tex_set_par_par(p, par_widow_penalties_code, unset ? null : widow_penalties_par, 1); }
+ if (tex_par_to_be_set(what, par_display_widow_penalties_code)) { tex_set_par_par(p, par_display_widow_penalties_code, unset ? null : display_widow_penalties_par, 1); }
+ if (tex_par_to_be_set(what, par_orphan_penalties_code)) { tex_set_par_par(p, par_orphan_penalties_code, unset ? null : orphan_penalties_par, 1); }
+ if (tex_par_to_be_set(what, par_baseline_skip_code)) { tex_set_par_par(p, par_baseline_skip_code, unset ? null : baseline_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_line_skip_code)) { tex_set_par_par(p, par_line_skip_code, unset ? null : line_skip_par, 1); }
+ if (tex_par_to_be_set(what, par_line_skip_limit_code)) { tex_set_par_par(p, par_line_skip_limit_code, unset ? null : line_skip_limit_par, 1); }
+ if (tex_par_to_be_set(what, par_adjust_spacing_step_code)) { tex_set_par_par(p, par_adjust_spacing_step_code, unset ? null : adjust_spacing_step_par, 1); }
+ if (tex_par_to_be_set(what, par_adjust_spacing_shrink_code)) { tex_set_par_par(p, par_adjust_spacing_shrink_code, unset ? null : adjust_spacing_shrink_par, 1); }
+ if (tex_par_to_be_set(what, par_adjust_spacing_stretch_code)) { tex_set_par_par(p, par_adjust_spacing_stretch_code, unset ? null : adjust_spacing_stretch_par, 1); }
+ if (tex_par_to_be_set(what, par_hyphenation_mode_code)) { tex_set_par_par(p, par_hyphenation_mode_code, unset ? null : hyphenation_mode_par, 1); }
+ if (tex_par_to_be_set(what, par_shaping_penalties_mode_code)) { tex_set_par_par(p, par_shaping_penalties_mode_code, unset ? null : shaping_penalties_mode_par, 1); }
+ if (tex_par_to_be_set(what, par_shaping_penalty_code)) { tex_set_par_par(p, par_shaping_penalty_code, unset ? null : shaping_penalty_par, 1); }
+
+ if (what == par_all_category) {
+ par_state(p) = unset ? 0 : par_all_category;
+ } else if (unset) {
+ par_state(p) &= ~(what | par_state(p));
+ } else {
+ par_state(p) |= what;
+ }
+ }
+ }
+*/
+
void tex_snapshot_par(halfword p, halfword what)
{
if (p && lmt_main_state.run_state != initializing_state) {
@@ -4166,49 +4168,189 @@ void tex_snapshot_par(halfword p, halfword what)
unset = 1;
what = par_all_category;
}
- if (tex_par_to_be_set(what, par_hsize_code)) { tex_set_par_par(p, par_hsize_code, unset ? null : hsize_par, 1); }
- if (tex_par_to_be_set(what, par_left_skip_code)) { tex_set_par_par(p, par_left_skip_code, unset ? null : left_skip_par, 1); }
- if (tex_par_to_be_set(what, par_right_skip_code)) { tex_set_par_par(p, par_right_skip_code, unset ? null : right_skip_par, 1); }
- if (tex_par_to_be_set(what, par_hang_indent_code)) { tex_set_par_par(p, par_hang_indent_code, unset ? null : hang_indent_par, 1); }
- if (tex_par_to_be_set(what, par_hang_after_code)) { tex_set_par_par(p, par_hang_after_code, unset ? null : hang_after_par, 1); }
- if (tex_par_to_be_set(what, par_par_indent_code)) { tex_set_par_par(p, par_par_indent_code, unset ? null : par_indent_par, 1); }
- if (tex_par_to_be_set(what, par_par_fill_left_skip_code)) { tex_set_par_par(p, par_par_fill_left_skip_code, unset ? null : par_fill_left_skip_par, 1); }
- if (tex_par_to_be_set(what, par_par_fill_right_skip_code)) { tex_set_par_par(p, par_par_fill_right_skip_code, unset ? null : par_fill_right_skip_par, 1); }
- if (tex_par_to_be_set(what, par_par_init_left_skip_code)) { tex_set_par_par(p, par_par_init_left_skip_code, unset ? null : par_init_left_skip_par, 1); }
- if (tex_par_to_be_set(what, par_par_init_right_skip_code)) { tex_set_par_par(p, par_par_init_right_skip_code, unset ? null : par_init_right_skip_par, 1); }
- if (tex_par_to_be_set(what, par_adjust_spacing_code)) { tex_set_par_par(p, par_adjust_spacing_code, unset ? null : adjust_spacing_par, 1); }
- if (tex_par_to_be_set(what, par_protrude_chars_code)) { tex_set_par_par(p, par_protrude_chars_code, unset ? null : protrude_chars_par, 1); }
- if (tex_par_to_be_set(what, par_pre_tolerance_code)) { tex_set_par_par(p, par_pre_tolerance_code, unset ? null : pre_tolerance_par, 1); }
- if (tex_par_to_be_set(what, par_tolerance_code)) { tex_set_par_par(p, par_tolerance_code, unset ? null : tolerance_par, 1); }
- if (tex_par_to_be_set(what, par_emergency_stretch_code)) { tex_set_par_par(p, par_emergency_stretch_code, unset ? null : emergency_stretch_par, 1); }
- if (tex_par_to_be_set(what, par_looseness_code)) { tex_set_par_par(p, par_looseness_code, unset ? null : looseness_par, 1); }
- if (tex_par_to_be_set(what, par_last_line_fit_code)) { tex_set_par_par(p, par_last_line_fit_code, unset ? null : last_line_fit_par, 1); }
- if (tex_par_to_be_set(what, par_line_penalty_code)) { tex_set_par_par(p, par_line_penalty_code, unset ? null : line_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_inter_line_penalty_code)) { tex_set_par_par(p, par_inter_line_penalty_code, unset ? null : inter_line_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_club_penalty_code)) { tex_set_par_par(p, par_club_penalty_code, unset ? null : club_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_widow_penalty_code)) { tex_set_par_par(p, par_widow_penalty_code, unset ? null : widow_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_display_widow_penalty_code)) { tex_set_par_par(p, par_display_widow_penalty_code, unset ? null : display_widow_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_orphan_penalty_code)) { tex_set_par_par(p, par_orphan_penalty_code, unset ? null : orphan_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_broken_penalty_code)) { tex_set_par_par(p, par_broken_penalty_code, unset ? null : broken_penalty_par, 1); }
- if (tex_par_to_be_set(what, par_adj_demerits_code)) { tex_set_par_par(p, par_adj_demerits_code, unset ? null : adj_demerits_par, 1); }
- if (tex_par_to_be_set(what, par_double_hyphen_demerits_code)) { tex_set_par_par(p, par_double_hyphen_demerits_code, unset ? null : double_hyphen_demerits_par, 1); }
- if (tex_par_to_be_set(what, par_final_hyphen_demerits_code)) { tex_set_par_par(p, par_final_hyphen_demerits_code, unset ? null : final_hyphen_demerits_par, 1); }
- if (tex_par_to_be_set(what, par_par_shape_code)) { tex_set_par_par(p, par_par_shape_code, unset ? null : par_shape_par, 1); }
- if (tex_par_to_be_set(what, par_inter_line_penalties_code)) { tex_set_par_par(p, par_inter_line_penalties_code, unset ? null : inter_line_penalties_par, 1); }
- if (tex_par_to_be_set(what, par_club_penalties_code)) { tex_set_par_par(p, par_club_penalties_code, unset ? null : club_penalties_par, 1); }
- if (tex_par_to_be_set(what, par_widow_penalties_code)) { tex_set_par_par(p, par_widow_penalties_code, unset ? null : widow_penalties_par, 1); }
- if (tex_par_to_be_set(what, par_display_widow_penalties_code)) { tex_set_par_par(p, par_display_widow_penalties_code, unset ? null : display_widow_penalties_par, 1); }
- if (tex_par_to_be_set(what, par_orphan_penalties_code)) { tex_set_par_par(p, par_orphan_penalties_code, unset ? null : orphan_penalties_par, 1); }
- if (tex_par_to_be_set(what, par_baseline_skip_code)) { tex_set_par_par(p, par_baseline_skip_code, unset ? null : baseline_skip_par, 1); }
- if (tex_par_to_be_set(what, par_line_skip_code)) { tex_set_par_par(p, par_line_skip_code, unset ? null : line_skip_par, 1); }
- if (tex_par_to_be_set(what, par_line_skip_limit_code)) { tex_set_par_par(p, par_line_skip_limit_code, unset ? null : line_skip_limit_par, 1); }
- if (tex_par_to_be_set(what, par_adjust_spacing_step_code)) { tex_set_par_par(p, par_adjust_spacing_step_code, unset ? null : adjust_spacing_step_par, 1); }
- if (tex_par_to_be_set(what, par_adjust_spacing_shrink_code)) { tex_set_par_par(p, par_adjust_spacing_shrink_code, unset ? null : adjust_spacing_shrink_par, 1); }
- if (tex_par_to_be_set(what, par_adjust_spacing_stretch_code)) { tex_set_par_par(p, par_adjust_spacing_stretch_code, unset ? null : adjust_spacing_stretch_par, 1); }
- if (tex_par_to_be_set(what, par_hyphenation_mode_code)) { tex_set_par_par(p, par_hyphenation_mode_code, unset ? null : hyphenation_mode_par, 1); }
- if (tex_par_to_be_set(what, par_shaping_penalties_mode_code)) { tex_set_par_par(p, par_shaping_penalties_mode_code, unset ? null : shaping_penalties_mode_par, 1); }
- if (tex_par_to_be_set(what, par_shaping_penalty_code)) { tex_set_par_par(p, par_shaping_penalty_code, unset ? null : shaping_penalty_par, 1); }
-
+ if (tex_par_to_be_set(what, par_hsize_code)) {
+ par_hsize(p) = unset ? null : hsize_par;
+ }
+ if (tex_par_to_be_set(what, par_left_skip_code)) {
+ halfword v = unset ? null : left_skip_par;
+ if (par_left_skip(p)) {
+ tex_flush_node(par_left_skip(p));
+ }
+ par_left_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_right_skip_code)) {
+ halfword v = unset ? null : right_skip_par;
+ if (par_right_skip(p)) {
+ tex_flush_node(par_right_skip(p));
+ }
+ par_right_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_hang_indent_code)) {
+ par_hang_indent(p) = unset ? null : hang_indent_par;
+ }
+ if (tex_par_to_be_set(what, par_hang_after_code)) {
+ par_hang_after(p) = unset ? null : hang_after_par;
+ }
+ if (tex_par_to_be_set(what, par_par_indent_code)) {
+ par_par_indent(p) = unset ? null : par_indent_par;
+ }
+ if (tex_par_to_be_set(what, par_par_fill_left_skip_code)) {
+ halfword v = unset ? null : par_fill_left_skip_par;
+ if (par_par_fill_left_skip(p)) {
+ tex_flush_node(par_par_fill_left_skip(p));
+ }
+ par_par_fill_left_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_par_fill_right_skip_code)) {
+ halfword v = unset ? null : par_fill_right_skip_par;
+ if (par_par_fill_right_skip(p)) {
+ tex_flush_node(par_par_fill_right_skip(p));
+ }
+ par_par_fill_right_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_par_init_left_skip_code)) {
+ halfword v = unset ? null : par_init_left_skip_par;
+ if (par_par_init_left_skip(p)) {
+ tex_flush_node(par_par_init_left_skip(p));
+ }
+ par_par_init_left_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_par_init_right_skip_code)) {
+ halfword v = unset ? null : par_init_right_skip_par;
+ if (par_par_init_right_skip(p)) {
+ tex_flush_node(par_par_init_right_skip(p));
+ }
+ par_par_init_right_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_adjust_spacing_code)) {
+ par_adjust_spacing(p) = unset ? null : adjust_spacing_par;
+ }
+ if (tex_par_to_be_set(what, par_protrude_chars_code)) {
+ par_protrude_chars(p) = unset ? null : protrude_chars_par;
+ }
+ if (tex_par_to_be_set(what, par_pre_tolerance_code)) {
+ par_pre_tolerance(p) = unset ? null : pre_tolerance_par;
+ }
+ if (tex_par_to_be_set(what, par_tolerance_code)) {
+ par_tolerance(p) = unset ? null : tolerance_par;
+ }
+ if (tex_par_to_be_set(what, par_emergency_stretch_code)) {
+ par_emergency_stretch(p) = unset ? null : emergency_stretch_par;
+ }
+ if (tex_par_to_be_set(what, par_looseness_code)) {
+ par_looseness(p) = unset ? null : looseness_par;
+ }
+ if (tex_par_to_be_set(what, par_last_line_fit_code)) {
+ par_last_line_fit(p) = unset ? null : last_line_fit_par;
+ }
+ if (tex_par_to_be_set(what, par_line_penalty_code)) {
+ par_line_penalty(p) = unset ? null : line_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_inter_line_penalty_code)) {
+ par_inter_line_penalty(p) = unset ? null : inter_line_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_club_penalty_code)) {
+ par_club_penalty(p) = unset ? null : club_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_widow_penalty_code)) {
+ par_widow_penalty(p) = unset ? null : widow_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_display_widow_penalty_code)) {
+ par_display_widow_penalty(p) = unset ? null : display_widow_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_orphan_penalty_code)) {
+ par_orphan_penalty(p) = unset ? null : orphan_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_broken_penalty_code)) {
+ par_broken_penalty(p) = unset ? null : broken_penalty_par;
+ }
+ if (tex_par_to_be_set(what, par_adj_demerits_code)) {
+ par_adj_demerits(p) = unset ? null : adj_demerits_par;
+ }
+ if (tex_par_to_be_set(what, par_double_hyphen_demerits_code)){
+ par_double_hyphen_demerits(p) = unset ? null : double_hyphen_demerits_par;
+ }
+ if (tex_par_to_be_set(what, par_final_hyphen_demerits_code)) {
+ par_final_hyphen_demerits(p) = unset ? null : final_hyphen_demerits_par;
+ }
+ if (tex_par_to_be_set(what, par_par_shape_code)) {
+ halfword v = unset ? null : par_shape_par;
+ if (par_par_shape(p)) {
+ tex_flush_node(par_par_shape(p));
+ }
+ par_par_shape(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_inter_line_penalties_code)) {
+ halfword v = unset ? null : inter_line_penalties_par;
+ if (par_inter_line_penalties(p)) {
+ tex_flush_node(par_inter_line_penalties(p));
+ }
+ par_inter_line_penalties(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_club_penalties_code)) {
+ halfword v = unset ? null : club_penalties_par;
+ if (par_club_penalties(p)) {
+ tex_flush_node(par_club_penalties(p));
+ }
+ par_club_penalties(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_widow_penalties_code)) {
+ halfword v = unset ? null : widow_penalties_par;
+ if (par_widow_penalties(p)) {
+ tex_flush_node(par_widow_penalties(p));
+ }
+ par_widow_penalties(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_display_widow_penalties_code)) {
+ halfword v = unset ? null : display_widow_penalties_par;
+ if (par_display_widow_penalties(p)) {
+ tex_flush_node(par_display_widow_penalties(p));
+ }
+ par_display_widow_penalties(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_orphan_penalties_code)) {
+ halfword v = unset ? null : orphan_penalties_par;
+ if (par_orphan_penalties(p)) {
+ tex_flush_node(par_orphan_penalties(p));
+ }
+ par_orphan_penalties(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_baseline_skip_code)) {
+ halfword v = unset ? null : baseline_skip_par;
+ if (par_baseline_skip(p)) {
+ tex_flush_node(par_baseline_skip(p));
+ }
+ par_baseline_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_line_skip_code)) {
+ halfword v = unset ? null : line_skip_par;
+ if (par_line_skip(p)) {
+ tex_flush_node(par_line_skip(p));
+ }
+ par_line_skip(p) = v ? tex_copy_node(v) : null;
+ }
+ if (tex_par_to_be_set(what, par_line_skip_limit_code)) {
+ par_line_skip_limit(p) = unset ? null : line_skip_limit_par;
+ }
+ if (tex_par_to_be_set(what, par_adjust_spacing_step_code)) {
+ par_adjust_spacing_step(p) = unset ? null : adjust_spacing_step_par;
+ }
+ if (tex_par_to_be_set(what, par_adjust_spacing_shrink_code)) {
+ par_adjust_spacing_shrink(p) = unset ? null : adjust_spacing_shrink_par;
+ }
+ if (tex_par_to_be_set(what, par_adjust_spacing_stretch_code)) {
+ par_adjust_spacing_stretch(p) = unset ? null : adjust_spacing_stretch_par;
+ }
+ if (tex_par_to_be_set(what, par_hyphenation_mode_code)) {
+ par_hyphenation_mode(p) = unset ? null : hyphenation_mode_par;
+ }
+ if (tex_par_to_be_set(what, par_shaping_penalties_mode_code)) {
+ par_shaping_penalties_mode(p) = unset ? null : shaping_penalties_mode_par;
+ }
+ if (tex_par_to_be_set(what, par_shaping_penalty_code)) {
+ par_shaping_penalty(p) = unset ? null : shaping_penalty_par;
+ }
+ // tex_set_par_state(p, what);
if (what == par_all_category) {
par_state(p) = unset ? 0 : par_all_category;
} else if (unset) {
@@ -4360,23 +4502,26 @@ void tex_shift_specification_list(halfword a, int n, int rotate)
specification_pointer(a) = b;
}
} else {
- halfword o = 0;
- halfword m = 0;
- memoryword *b = NULL;
- if (n > 0 && c > 0 && n < c) {
- size_t s = 0;
- memoryword *p = specification_pointer(a);
- o = specification_options(a);
- m = c - n;
- b = tex_aux_allocate_specification(m, &s);
- memcpy(b, p + n, s);
- }
- if (c > 0) {
- tex_aux_deallocate_specification(specification_pointer(a), c);
+ /* changed: zero check, else we wipe */
+ if (n > 0) {
+ halfword o = 0;
+ halfword m = 0;
+ memoryword *b = NULL;
+ if (n > 0 && c > 0 && n < c) {
+ size_t s = 0;
+ memoryword *p = specification_pointer(a);
+ o = specification_options(a);
+ m = c - n;
+ b = tex_aux_allocate_specification(m, &s);
+ memcpy(b, p + n, s);
+ }
+ if (c > 0) {
+ tex_aux_deallocate_specification(specification_pointer(a), c);
+ }
+ specification_pointer(a) = b;
+ specification_count(a) = m;
+ specification_options(a) = o;
}
- specification_pointer(a) = b;
- specification_count(a) = m;
- specification_options(a) = o;
}
}
}
@@ -4469,8 +4614,8 @@ halfword tex_flatten_discretionaries(halfword head, int *count, int nest)
if (list) {
box_list(current) = tex_flatten_discretionaries(list, count, nest);
}
- break;
}
+ break;
}
current = next;
}
diff --git a/source/luametatex/source/tex/texpackaging.c b/source/luametatex/source/tex/texpackaging.c
index 6ad1f5718..1eb9cc694 100644
--- a/source/luametatex/source/tex/texpackaging.c
+++ b/source/luametatex/source/tex/texpackaging.c
@@ -67,7 +67,7 @@
static void tex_aux_scan_full_spec(halfword context, quarterword c, quarterword spec_direction, int just_pack, scaled shift, halfword slot)
{
- quarterword spec_code = packing_additional;
+ quarterword spec_packing = packing_additional;
int spec_amount = 0;
halfword attrlist = null;
halfword orientation = 0;
@@ -99,7 +99,7 @@ static void tex_aux_scan_full_spec(halfword context, quarterword c, quarterword
}
break;
case 'o': case 'O':
- spec_code = packing_exactly;
+ spec_packing = packing_exactly;
spec_amount = tex_scan_dimen(0, 0, 0, 0, NULL);
break;
default:
@@ -111,7 +111,7 @@ static void tex_aux_scan_full_spec(halfword context, quarterword c, quarterword
switch (tex_scan_character("dntxDNTX", 0, 0, 0)) {
case 'd': case 'D':
if (tex_scan_mandate_keyword("adapt", 2)) {
- spec_code = packing_adapted;
+ spec_packing = packing_adapted;
spec_amount = tex_scan_limited_scale(0);
}
break;
@@ -164,7 +164,7 @@ static void tex_aux_scan_full_spec(halfword context, quarterword c, quarterword
break;
case 'p': case 'P':
if (tex_scan_mandate_keyword("spread", 2)) {
- spec_code = packing_additional;
+ spec_packing = packing_additional;
spec_amount = tex_scan_dimen(0, 0, 0, 0, NULL);
}
break;
@@ -301,7 +301,7 @@ static void tex_aux_scan_full_spec(halfword context, quarterword c, quarterword
/* */
tex_set_saved_record(saved_full_spec_item_context, box_context_save_type, slot, context); /* slot fits in a quarterword */
/*tex Traditionally these two are packed into one record: */
- tex_set_saved_record(saved_full_spec_item_packaging, box_spec_save_type, spec_code, spec_amount);
+ tex_set_saved_record(saved_full_spec_item_packaging, box_spec_save_type, spec_packing, spec_amount);
/*tex Adjust |text_dir_ptr| for |scan_spec|: */
if (spec_direction != direction_unknown) {
tex_set_saved_record(saved_full_spec_item_direction, box_direction_save_type, spec_direction, lmt_dir_state.text_dir_ptr);
@@ -2368,7 +2368,7 @@ void tex_run_vcenter(void)
tex_aux_scan_full_spec(direct_box_flag, vcenter_group, direction_l2r, 0, 0, -1);
tex_normal_paragraph(vcenter_par_context);
tex_push_nest();
- cur_list.mode = -vmode;
+ cur_list.mode = internal_vmode;
cur_list.prev_depth = ignore_depth_criterium_par;
if (every_vbox_par) {
tex_begin_token_list(every_vbox_par, every_vbox_text);
@@ -2413,7 +2413,7 @@ void tex_package(singleword nature)
halfword boxnode = null; /*tex Aka |cur_box|. */
tex_unsave();
lmt_save_state.save_stack_data.ptr -= saved_full_spec_n_of_items;
- slot = saved_level(saved_full_spec_item_context);
+ slot = saved_extra(saved_full_spec_item_context);
context = saved_value(saved_full_spec_item_context);
spec = saved_value(saved_full_spec_item_packaging);
dirptr = saved_value(saved_full_spec_item_direction);
@@ -2429,17 +2429,17 @@ void tex_package(singleword nature)
mainclass = saved_value(saved_full_spec_item_class);
state = saved_value(saved_full_spec_item_state);
retain = saved_value(saved_full_spec_item_retain);
- if (cur_list.mode == -hmode) {
- boxnode = tex_filtered_hpack(cur_list.head, cur_list.tail, spec, saved_level(saved_full_spec_item_packaging),
- grp, saved_level(saved_full_spec_item_direction), justpack, attrlist, state, retain);
+ if (cur_list.mode == restricted_hmode) {
+ boxnode = tex_filtered_hpack(cur_list.head, cur_list.tail, spec, saved_extra(saved_full_spec_item_packaging),
+ grp, saved_extra(saved_full_spec_item_direction), justpack, attrlist, state, retain);
node_subtype(boxnode) = hbox_list;
if (saved_value(saved_full_spec_item_reverse)) {
box_list(boxnode) = tex_reversed_node_list(box_list(boxnode));
}
box_package_state(boxnode) = hbox_package_state;
} else {
- boxnode = tex_filtered_vpack(node_next(cur_list.head), spec, saved_level(saved_full_spec_item_packaging),
- maxdepth, grp, saved_level(saved_full_spec_item_direction), justpack, attrlist, state, retain);
+ boxnode = tex_filtered_vpack(node_next(cur_list.head), spec, saved_extra(saved_full_spec_item_packaging),
+ maxdepth, grp, saved_extra(saved_full_spec_item_direction), justpack, attrlist, state, retain);
tex_aux_set_vnature(boxnode, nature);
}
if (dirptr) {
@@ -2540,144 +2540,161 @@ void tex_run_unpackage(void)
halfword b = box_register(n);
if (! b) {
return;
- } else if ((abs(cur_list.mode) == mmode)
- || ((abs(cur_list.mode) == vmode) && (node_type(b) != vlist_node))
- || ((abs(cur_list.mode) == hmode) && (node_type(b) != hlist_node))) {
- tex_handle_error(
- normal_error_type,
- "Incompatible list can't be unboxed",
- "Sorry, Pandora. (You sneaky devil.) I refuse to unbox an \\hbox in vertical mode\n"
- "or vice versa. And I can't open any boxes in math mode."
- );
- return;
- } else {
-
- /* todo: check head, not needed, always a temp */
-
- /*tex Via variables for varmem assignment. */
- halfword list = box_list(b);
- halfword pre_migrated = code == unpack_code ? null : box_pre_migrated(b);
- halfword post_migrated = code == unpack_code ? null : box_post_migrated(b);
- // halfword pre_adjusted = code == unpack_code || (abs(cur_list.mode) == hmode) ? null : box_pre_adjusted(b);
- // halfword post_adjusted = code == unpack_code || (abs(cur_list.mode) == hmode) ? null : box_post_adjusted(b);
- // halfword pre_adjusted = code == unpack_code ? null : box_pre_adjusted(b);
- // halfword post_adjusted = code == unpack_code ? null : box_post_adjusted(b);
- halfword pre_adjusted = box_pre_adjusted(b);
- halfword post_adjusted = box_post_adjusted(b);
- if (pre_adjusted) {
- if (code == copy_code) {
- pre_adjusted = tex_copy_node_list(pre_adjusted, null);
- } else {
- box_pre_adjusted(b) = null;
- }
- while (pre_adjusted) {
- halfword p = pre_adjusted;
- halfword h = adjust_list(pre_adjusted);
- if (h) {
- if (abs(cur_list.mode) == hmode) {
- halfword n = tex_new_node(adjust_node, pre_adjust_code);
- adjust_list(n) = h;
- h = n;
- }
- if (! head) {
- head = h;
- }
- tex_try_couple_nodes(tail, h);
- tail = tex_tail_of_node_list(h);
- adjust_list(pre_adjusted) = null;
+ } else {
+ int bad = 0;
+ switch (cur_list.mode) {
+ case vmode:
+ case internal_vmode:
+ if (node_type(b) != vlist_node) {
+ bad = 1;
}
- pre_adjusted = node_next(pre_adjusted);
- tex_flush_node(p);
- }
- }
- if (pre_migrated) {
- if (code == copy_code) {
- pre_migrated = tex_copy_node_list(pre_migrated, null);
- } else {
- box_pre_migrated(b) = null;
- }
- tex_try_couple_nodes(tail, pre_migrated);
- tail = tex_tail_of_node_list(pre_migrated);
- if (! head) {
- head = pre_migrated;
- }
+ break;
+ case hmode:
+ case restricted_hmode:
+ if (node_type(b) != hlist_node) {
+ bad = 1;
+ }
+ break;
+ case mmode:
+ case inline_mmode:
+ bad = 1;
+ break;
}
- if (list) {
- if (code == copy_code) {
- list = tex_copy_node_list(list, null);
- } else {
- box_list(b) = null;
- }
- tex_try_couple_nodes(tail, list);
- tail = tex_tail_of_node_list(list);
- if (! head) {
- head = list;
+ if (bad) {
+ tex_handle_error(
+ normal_error_type,
+ "Incompatible list can't be unboxed",
+ "Sorry, Pandora. (You sneaky devil.) I refuse to unbox an \\hbox in vertical mode\n"
+ "or vice versa. And I can't open any boxes in math mode."
+ );
+ return;
+ } else {
+ /*tex Todo: check head, not needed, always a temp. */
+ /*tex Via variables for varmem assignment. */
+ halfword list = box_list(b);
+ halfword pre_migrated = code == unpack_code ? null : box_pre_migrated(b);
+ halfword post_migrated = code == unpack_code ? null : box_post_migrated(b);
+ // halfword pre_adjusted = code == (unpack_code || is_h_mode(cur_list.mode)) ? null : box_pre_adjusted(b);
+ // halfword post_adjusted = code == (unpack_code || is_h_mode(cur_list.mode)) ? null : box_post_adjusted(b);
+ // halfword pre_adjusted = code == unpack_code ? null : box_pre_adjusted(b);
+ // halfword post_adjusted = code == unpack_code ? null : box_post_adjusted(b);
+ halfword pre_adjusted = box_pre_adjusted(b);
+ halfword post_adjusted = box_post_adjusted(b);
+ if (pre_adjusted) {
+ if (code == copy_code) {
+ pre_adjusted = tex_copy_node_list(pre_adjusted, null);
+ } else {
+ box_pre_adjusted(b) = null;
+ }
+ while (pre_adjusted) {
+ halfword p = pre_adjusted;
+ halfword h = adjust_list(pre_adjusted);
+ if (h) {
+ if (is_h_mode(cur_list.mode)) {
+ halfword n = tex_new_node(adjust_node, pre_adjust_code);
+ adjust_list(n) = h;
+ h = n;
+ }
+ if (! head) {
+ head = h;
+ }
+ tex_try_couple_nodes(tail, h);
+ tail = tex_tail_of_node_list(h);
+ adjust_list(pre_adjusted) = null;
+ }
+ pre_adjusted = node_next(pre_adjusted);
+ tex_flush_node(p);
+ }
}
- }
- if (post_migrated) {
- if (code == copy_code) {
- post_migrated = tex_copy_node_list(post_migrated, null);
- } else {
- box_post_migrated(b) = null;
+ if (pre_migrated) {
+ if (code == copy_code) {
+ pre_migrated = tex_copy_node_list(pre_migrated, null);
+ } else {
+ box_pre_migrated(b) = null;
+ }
+ tex_try_couple_nodes(tail, pre_migrated);
+ tail = tex_tail_of_node_list(pre_migrated);
+ if (! head) {
+ head = pre_migrated;
+ }
}
- tex_try_couple_nodes(tail, post_migrated);
- tail = tex_tail_of_node_list(post_migrated);
- if (! head) {
- head = post_migrated;
+ if (list) {
+ if (code == copy_code) {
+ list = tex_copy_node_list(list, null);
+ } else {
+ box_list(b) = null;
+ }
+ tex_try_couple_nodes(tail, list);
+ tail = tex_tail_of_node_list(list);
+ if (! head) {
+ head = list;
+ }
}
- }
- if (post_adjusted) {
- if (code == copy_code) {
- post_adjusted = tex_copy_node_list(post_adjusted, null);
- } else {
- box_post_adjusted(b) = null;
+ if (post_migrated) {
+ if (code == copy_code) {
+ post_migrated = tex_copy_node_list(post_migrated, null);
+ } else {
+ box_post_migrated(b) = null;
+ }
+ tex_try_couple_nodes(tail, post_migrated);
+ tail = tex_tail_of_node_list(post_migrated);
+ if (! head) {
+ head = post_migrated;
+ }
}
- while (post_adjusted) {
- halfword p = post_adjusted;
- halfword h = adjust_list(post_adjusted);
- if (h) {
- if (abs(cur_list.mode) == hmode) {
- halfword n = tex_new_node(adjust_node, post_adjust_code);
- adjust_list(n) = h;
- h = n;
- }
- if (! head) {
- head = h;
+ if (post_adjusted) {
+ if (code == copy_code) {
+ post_adjusted = tex_copy_node_list(post_adjusted, null);
+ } else {
+ box_post_adjusted(b) = null;
+ }
+ while (post_adjusted) {
+ halfword p = post_adjusted;
+ halfword h = adjust_list(post_adjusted);
+ if (h) {
+ if (is_h_mode(cur_list.mode)) {
+ halfword n = tex_new_node(adjust_node, post_adjust_code);
+ adjust_list(n) = h;
+ h = n;
+ }
+ if (! head) {
+ head = h;
+ }
+ tex_try_couple_nodes(tail, h);
+ tail = tex_tail_of_node_list(h);
+ adjust_list(post_adjusted) = null;
}
- tex_try_couple_nodes(tail, h);
- tail = tex_tail_of_node_list(h);
- adjust_list(post_adjusted) = null;
+ post_adjusted = node_next(post_adjusted);
+ tex_flush_node(p);
}
- post_adjusted = node_next(post_adjusted);
- tex_flush_node(p);
}
- }
- if (code != copy_code) {
- box_register(n) = null;
- tex_flush_node(b);
- }
- if (! head) {
- tail = null;
- } else if (node_type(b) == hlist_node && normalize_line_mode_permitted(normalize_line_mode_par, remove_margin_kerns_mode)) {
- /* only here head is used ... */
- tail = head;
- while (1) {
- halfword next = node_next(tail);
- if (next) {
- if (tex_is_margin_kern(next)) {
- tex_try_couple_nodes(tail, node_next(next));
- tex_flush_node(next);
+ if (code != copy_code) {
+ box_register(n) = null;
+ tex_flush_node(b);
+ }
+ if (! head) {
+ tail = null;
+ } else if (node_type(b) == hlist_node && normalize_line_mode_permitted(normalize_line_mode_par, remove_margin_kerns_mode)) {
+ /* only here head is used ... */
+ tail = head;
+ while (1) {
+ halfword next = node_next(tail);
+ if (next) {
+ if (tex_is_margin_kern(next)) {
+ tex_try_couple_nodes(tail, node_next(next));
+ tex_flush_node(next);
+ } else {
+ tail = next;
+ }
} else {
- tail = next;
+ break;
}
- } else {
- break;
}
+ } else {
+ tail = tex_tail_of_node_list(tail);
}
- } else {
- tail = tex_tail_of_node_list(tail);
+ cur_list.tail = tail;
}
- cur_list.tail = tail;
break;
}
}
@@ -2709,7 +2726,7 @@ void tex_run_unpackage(void)
if (tex_valid_insert_id(index)) {
halfword boxnode = tex_get_insert_content(index); /* also checks for id */
if (boxnode) {
- if (abs(cur_list.mode) != vmode) {
+ if (! is_v_mode(cur_list.mode)) {
tex_handle_error(
normal_error_type,
"Unpacking an inserts can only happen in vertical mode.",
@@ -3244,7 +3261,7 @@ void tex_begin_box(int boxcontext, scaled shift, halfword slot)
point to it; otherwise set |boxnode := null|.
*/
boxnode = null;
- if (abs(cur_list.mode) == mmode) {
+ if (is_m_mode(cur_list.mode)) {
tex_you_cant_error(
"Sorry; this \\lastbox will be void."
);
@@ -3380,17 +3397,20 @@ void tex_begin_box(int boxcontext, scaled shift, halfword slot)
int group = vbox_group;
int mode = vmode;
int adjusted = 0;
- switch (abs(cur_list.mode)) {
+ switch (cur_list.mode) {
case vmode:
+ case internal_vmode:
direction = dir_lefttoright;
if (boxcontext == direct_box_flag) {
adjusted = 1;
}
break;
case hmode:
+ case restricted_hmode:
direction = (singleword) text_direction_par;
break;
case mmode:
+ case inline_mmode:
direction = (singleword) math_direction_par;
break;
default:
diff --git a/source/luametatex/source/tex/texprimitive.c b/source/luametatex/source/tex/texprimitive.c
index 9875e06dd..cab68f841 100644
--- a/source/luametatex/source/tex/texprimitive.c
+++ b/source/luametatex/source/tex/texprimitive.c
@@ -174,8 +174,8 @@ static int tex_aux_room_in_hash(void)
Because we seldom use uppercase we get many misses, multiplying a chr j[k] by k actually gives
a better spread.
- Making a \CONTEXT\ format takes some 250.000 hash calculations while the \LUAMETATEX\ needs
- some 1.7 million for just over 250 pages (with an average string length of 15).
+ Making a \CONTEXT\ format takes some 250.000 hash calculations while the \LUAMETATEX\ manual
+ needs some 1.7 million for just over 250 pages (with an average string length of 15).
The primitive hash lookups are needed when we initialize and when we lookup an internal
variable.
@@ -205,11 +205,13 @@ halfword tex_prim_lookup(strnumber s)
/*tex The index in the |hash| array: */
if (s >= cs_offset_value) {
unsigned char *j = str_string(s);
- unsigned l = (unsigned) str_length(s);
+ // unsigned l = (unsigned) str_length(s);
+ halfword l = str_length(s);
halfword h = tex_aux_compute_prim((char *) j, l);
/*tex We start searching here; note that |0 <= h < hash_prime|. */
halfword p = h + 1;
while (1) {
+ /* When using |halfword text = prim_text(p)| no intelliugense warning for first test in: */
if (prim_text(p) > 0 && str_length(prim_text(p)) == l && tex_str_eq_str(prim_text(p), s)) {
return p;
} else if (prim_next(p)) {
diff --git a/source/luametatex/source/tex/texprinting.c b/source/luametatex/source/tex/texprinting.c
index 86fa47e28..1e384a9cd 100644
--- a/source/luametatex/source/tex/texprinting.c
+++ b/source/luametatex/source/tex/texprinting.c
@@ -992,7 +992,7 @@ void tex_print_token_list(const char *s, halfword p)
}
tex_print_char('{');
if ((p >= 0) && (p <= (int) lmt_token_memory_state.tokens_data.top)) {
- tex_show_token_list(p, null, default_token_show_max, 0);
+ tex_show_token_list(p, 0);
} else {
tex_print_str(error_string_clobbered(21));
}
diff --git a/source/luametatex/source/tex/texrules.c b/source/luametatex/source/tex/texrules.c
index 768f640b1..1d272f89e 100644
--- a/source/luametatex/source/tex/texrules.c
+++ b/source/luametatex/source/tex/texrules.c
@@ -187,15 +187,14 @@ void tex_aux_check_text_strut_rule(halfword rule, halfword style)
halfword fnt = tex_get_rule_font(rule, style);
halfword chr = rule_character(rule);
if (fnt > 0 && chr && tex_char_exists(fnt, chr)) {
+ scaledwhd whd = tex_char_whd_from_font(fnt, chr);
if (ht == null_flag) {
- ht = tex_char_height_from_font(fnt, chr);
+ rule_height(rule) = whd.ht;
}
if (dp == null_flag) {
- dp = tex_char_depth_from_font(fnt, chr);
+ rule_depth(rule) = whd.dp;
}
}
- rule_height(rule) = ht;
- rule_depth(rule) = dp;
}
}
}
@@ -203,7 +202,7 @@ void tex_aux_check_text_strut_rule(halfword rule, halfword style)
halfword tex_get_rule_font(halfword n, halfword style)
{
halfword fnt = rule_font(n);
- if (fnt > rule_font_fam_offset) {
+ if (fnt >= rule_font_fam_offset) {
halfword fam = fnt - rule_font_fam_offset;
if (fam_par_in_range(fam)) {
fnt = tex_fam_fnt(fam, tex_size_of_style(style));
@@ -219,7 +218,7 @@ halfword tex_get_rule_font(halfword n, halfword style)
halfword tex_get_rule_family(halfword n)
{
halfword fnt = rule_font(n);
- if (fnt > rule_font_fam_offset) {
+ if (fnt >= rule_font_fam_offset) {
halfword fam = fnt - rule_font_fam_offset;
if (fam_par_in_range(fam)) {
return fam;
diff --git a/source/luametatex/source/tex/texscanning.c b/source/luametatex/source/tex/texscanning.c
index a78a68a23..845b6fa55 100644
--- a/source/luametatex/source/tex/texscanning.c
+++ b/source/luametatex/source/tex/texscanning.c
@@ -895,10 +895,9 @@ static int tex_aux_set_cur_val_by_some_cmd(int code)
static void tex_aux_set_cur_val_by_auxiliary_cmd(int chr)
{
- halfword mode = abs(cur_list.mode);
switch (chr) {
case space_factor_code:
- if (mode == hmode) {
+ if (is_h_mode(cur_list.mode)) {
cur_val = cur_list.space_factor;
} else {
tex_handle_error(normal_error_type, "Improper %C", set_auxiliary_cmd, chr,
@@ -910,7 +909,7 @@ static void tex_aux_set_cur_val_by_auxiliary_cmd(int chr)
cur_val_level = int_val_level;
break;
case prev_depth_code:
- if (mode == vmode) {
+ if (is_v_mode(cur_list.mode)) {
cur_val = cur_list.prev_depth;
} else {
tex_handle_error(normal_error_type, "Improper %C", set_auxiliary_cmd, chr,
@@ -922,7 +921,7 @@ static void tex_aux_set_cur_val_by_auxiliary_cmd(int chr)
cur_val_level = dimen_val_level;
break;
case prev_graf_code:
- if (mode == nomode) {
+ if (cur_list.mode == nomode) {
/*tex So |prev_graf=0| within |\write|, not that we have that. */
cur_val = 0;
} else {
@@ -3071,7 +3070,7 @@ halfword tex_the_detokenized_toks(halfword *tail)
halfword head = tex_scan_general_text(tail);
int saved_selector;
push_selector;
- tex_show_token_list(head, null, extreme_token_show_max, 0);
+ tex_show_token_list(head, 0);
pop_selector;
tex_flush_token_list(head);
return tex_cur_str_toks(tail);
@@ -3127,7 +3126,7 @@ strnumber tex_the_scanned_result(void)
break;
case tok_val_level:
if (cur_val) {
- tex_token_show(cur_val, extreme_token_show_max);
+ tex_token_show(cur_val);
break;
} else {
r = get_nullstr();
diff --git a/source/luametatex/source/tex/textoken.c b/source/luametatex/source/tex/textoken.c
index 79e2e5e64..dfdc9f73d 100644
--- a/source/luametatex/source/tex/textoken.c
+++ b/source/luametatex/source/tex/textoken.c
@@ -266,7 +266,7 @@ halfword tex_get_available_token(halfword t)
lmt_token_memory_state.available = token_link(p);
} else if (lmt_token_memory_state.tokens_data.top < lmt_token_memory_state.tokens_data.allocated) {
p = ++lmt_token_memory_state.tokens_data.top;
- } else {
+ } else {
tex_aux_bump_token_memory();
p = ++lmt_token_memory_state.tokens_data.top;
}
@@ -336,8 +336,8 @@ void tex_add_token_reference(halfword p)
{
if (get_token_reference(p) < max_token_reference) {
add_token_reference(p);
- // } else {
- // tex_overflow_error("reference count", max_token_reference);
+ // } else {
+ // tex_overflow_error("reference count", max_token_reference);
}
}
@@ -352,24 +352,13 @@ void tex_increment_token_reference(halfword p, int n)
}
}
-// void tex_delete_token_reference(halfword p)
-// {
-// if (p) {
-// if (get_token_reference(p)) {
-// sub_token_reference(p);
-// } else {
-// tex_flush_token_list(p);
-// }
-// }
-// }
-
void tex_delete_token_reference(halfword p)
{
if (p) {
halfword r = get_token_reference(p);
if (! r) {
tex_flush_token_list(p);
- } if(r < max_token_reference) {
+ } if (r < max_token_reference) {
sub_token_reference(p);
}
}
@@ -499,12 +488,7 @@ void tex_print_meaning(halfword code)
tex_print_cs(cur_cs);
tex_print_char(' ');
if (cur_chr && token_link(cur_chr)) {
- halfword body = get_token_preamble(cur_chr) ? tex_show_token_list(token_link(cur_chr), null, default_token_show_max, 1) : token_link(cur_chr);
- tex_print_char('{');
- if (body) {
- tex_show_token_list(body, null, default_token_show_max, 0);
- }
- tex_print_char('}');
+ tex_show_token_list(token_link(cur_chr), get_token_preamble(cur_chr));
}
return;
}
@@ -514,7 +498,7 @@ void tex_print_meaning(halfword code)
tex_print_cmd_chr((singleword) cur_cmd, cur_chr);
tex_print_char(':');
tex_print_nlp();
- tex_token_show(tex_get_some_mark(cur_chr, 0), default_token_show_max);
+ tex_token_show(tex_get_some_mark(cur_chr, 0));
return;
case lua_value_cmd:
case lua_call_cmd:
@@ -547,7 +531,7 @@ void tex_print_meaning(halfword code)
tex_print_char(':');
DETAILS:
tex_print_nlp();
- tex_token_show(cur_chr, default_token_show_max);
+ tex_token_show(cur_chr);
}
/*tex
@@ -581,6 +565,9 @@ void tex_print_meaning(halfword code)
In \LUAMETATEX\ we have some more node types and token types so we also have additional tracing.
Because there is some more granularity in for instance nodes (subtypes) more detail is reported.
+ It made sense to split the |tex_show_token_list| funciton in two, ine specialized for showing
+ the context. That saves some testing and passing arguments.
+
*/
static const char *tex_aux_special_cmd_string(halfword cmd, halfword chr, const char *unknown)
@@ -600,42 +587,120 @@ static const char *tex_aux_special_cmd_string(halfword cmd, halfword chr, const
}
}
-halfword tex_show_token_list(halfword p, halfword q, int l, int asis)
+void tex_show_token_list(halfword p, int asis)
+{
+ if (p) {
+ unsigned char n = 0;
+ int max = lmt_token_memory_state.tokens_data.top;
+ while (p) {
+ if (p < 0 || p > max) {
+ tex_print_str(error_string_clobbered(41));
+ return;
+ } else if (token_info(p) >= cs_token_flag) {
+ tex_print_cs_checked(token_info(p) - cs_token_flag);
+ } else if (token_info(p) > 0) {
+ int cmd = token_cmd(token_info(p));
+ int chr = token_chr(token_info(p));
+ switch (cmd) {
+ case left_brace_cmd:
+ case right_brace_cmd:
+ case math_shift_cmd:
+ case alignment_tab_cmd:
+ case superscript_cmd:
+ case subscript_cmd:
+ case spacer_cmd:
+ case letter_cmd:
+ case other_char_cmd:
+ case active_char_cmd:
+ case ignore_cmd:
+ tex_print_tex_str(chr);
+ break;
+ case parameter_cmd:
+ if (! lmt_token_state.in_lua_escape && (lmt_expand_state.cs_name_level == 0)) {
+ tex_print_tex_str(chr);
+ }
+ tex_print_tex_str(chr);
+ break;
+ case parameter_reference_cmd:
+ tex_print_tex_str(match_visualizer);
+ if (chr <= 9) {
+ tex_print_char(chr + '0');
+ } else if (chr <= max_match_count) {
+ tex_print_char(chr + '0' + gap_match_count);
+ } else {
+ tex_print_char('!');
+ return;
+ }
+ break;
+ case match_cmd:
+ tex_print_char(match_visualizer);
+ if (is_valid_match_ref(chr)) {
+ ++n;
+ }
+ tex_print_char(chr ? chr : '0');
+ if (n > max_match_count) {
+ return;
+ } else {
+ break;
+ }
+ case end_match_cmd:
+ if (asis) {
+ tex_print_char('{');
+ } else if (chr == 0) {
+ tex_print_str("->");
+ }
+ break;
+ case ignore_something_cmd:
+ break;
+ case set_font_cmd:
+ tex_print_format("[font->%s]", font_original(cur_val));
+ break;
+ case end_paragraph_cmd:
+ /* tex_print_format("%e%s", "par "); */
+ tex_print_str_esc("par ");
+ break;
+ default:
+ tex_print_str(tex_aux_special_cmd_string(cmd, chr, error_string_bad(43)));
+ break;
+ }
+ } else {
+ tex_print_str(error_string_bad(42));
+ }
+ p = token_link(p);
+ }
+ if (asis) {
+ tex_print_char('}');
+ }
+ }
+}
+
+void tex_show_token_list_context(halfword p, halfword q)
{
if (p) {
/*tex the highest parameter number, as an \ASCII\ digit */
unsigned char n = 0;
- int min = 0;
int max = lmt_token_memory_state.tokens_data.top;
lmt_print_state.tally = 0;
-// if (l <= 0) {
- l = extreme_token_show_max;
-// }
- while (p && (lmt_print_state.tally < l)) {
+ while (p) {
if (p == q) {
/*tex Do magic computation. We only end up here in context showing. */
tex_set_trick_count();
}
/*tex Display token |p|, and |return| if there are problems. */
- if (p < min || p > max) {
+ if (p < 0 || p > max) {
tex_print_str(error_string_clobbered(41));
- return null;
+ return;
} else if (token_info(p) >= cs_token_flag) {
// if (! ((print_state.inhibit_par_tokens) && (token_info(p) == token_state.par_token))) {
tex_print_cs_checked(token_info(p) - cs_token_flag);
// }
- } else if (token_info(p) < 0) {
- tex_print_str(error_string_bad(42));
- } else if (token_info(p) == 0) {
- tex_print_str(error_string_bad(44));
- } else {
+ } else if (token_info(p) > 0) {
int cmd = token_cmd(token_info(p));
int chr = token_chr(token_info(p));
/*
Display the token (|cmd|,|chr|). The procedure usually \quote {learns} the character
code used for macro parameters by seeing one in a |match| command before it runs
- into any |out_param| commands.
-
+ into any |out_param| commands. This is probably not true any longer.
*/
switch (cmd) {
case left_brace_cmd:
@@ -665,7 +730,7 @@ halfword tex_show_token_list(halfword p, halfword q, int l, int asis)
tex_print_char(chr + '0' + gap_match_count);
} else {
tex_print_char('!');
- return null;
+ return;
}
break;
case match_cmd:
@@ -676,16 +741,12 @@ halfword tex_show_token_list(halfword p, halfword q, int l, int asis)
tex_print_char(chr ? chr : '0');
if (n > max_match_count) {
/*tex Can this happen at all? */
- return null;
+ return;
} else {
break;
}
case end_match_cmd:
- if (asis) {
- return token_link(p);
- } else if (chr == 0) {
- tex_print_str("->");
- }
+ tex_print_str("->");
break;
case ignore_something_cmd:
break;
@@ -693,12 +754,17 @@ halfword tex_show_token_list(halfword p, halfword q, int l, int asis)
tex_print_format("[font->%s]", font_original(cur_val));
break;
case end_paragraph_cmd:
- tex_print_format("%e%s", "par ");
+ /* tex_print_format("%e%s", "par "); */
+ tex_print_str_esc("par ");
break;
default:
tex_print_str(tex_aux_special_cmd_string(cmd, chr, error_string_bad(43)));
break;
}
+ // } else if (token_info(p) == 0) {
+ // tex_print_str(error_string_bad(44));
+ } else {
+ tex_print_str(error_string_bad(42));
}
p = token_link(p);
}
@@ -706,7 +772,6 @@ halfword tex_show_token_list(halfword p, halfword q, int l, int asis)
tex_print_str_esc("ETC.");
}
}
- return p;
}
/*
@@ -736,10 +801,10 @@ inline static halfword get_unichar_from_buffer(int *b)
*/
-void tex_token_show(halfword p, int max)
+void tex_token_show(halfword p)
{
if (p && token_link(p)) {
- tex_show_token_list(token_link(p), null, max, 0);
+ tex_show_token_list(token_link(p), 0);
}
}
@@ -807,7 +872,6 @@ static next_line_retval tex_aux_next_line(void);
halfword tex_scan_character(const char *s, int left_brace, int skip_space, int skip_relax)
{
halfword save_cur_cs = cur_cs;
-// (void) skip_space; /* some day */
while (1) {
tex_get_x_token();
switch (cur_cmd) {
@@ -942,8 +1006,8 @@ int tex_scan_mandate_keyword(const char *s, int offset)
goto BAD_NEWS;
}
break;
- // case spacer_cmd: /* normally spaces are not pushed back */
- // case relax_cmd: /* normally not, should be option */
+ // case spacer_cmd: /* normally spaces are not pushed back */
+ // case relax_cmd: /* normally not, should be option */
// if (done) {
// back_input(cur_tok);
// goto BAD_NEWS;
@@ -952,7 +1016,7 @@ int tex_scan_mandate_keyword(const char *s, int offset)
// }
// default:
// goto BAD_NEWS;
- case spacer_cmd: /* normally spaces are not pushed back */
+ case spacer_cmd: /* normally spaces are not pushed back */
if (done) {
goto BAD_NEWS;
} else {
@@ -1713,59 +1777,61 @@ static int tex_aux_scan_control_sequence(void)
static void tex_aux_file_warning(void)
{
- halfword cond_ptr = lmt_save_state.save_stack_data.ptr; /*tex saved value of |save_ptr| or |cond_ptr| */
- int cur_if = cur_group; /*tex saved value of |cur_group| or |cur_if| */
- int cur_unless = 0;
- int if_step = 0;
- int if_unless = 0;
- int if_limit = cur_level; /*tex saved value of |cur_level| or |if_limit| */
- int if_line = 0; /*tex saved value of |if_line| */
- lmt_save_state.save_stack_data.ptr = cur_boundary;
- while (lmt_input_state.in_stack[lmt_input_state.in_stack_data.ptr].group != lmt_save_state.save_stack_data.ptr) {
- --cur_level;
- tex_print_nlp();
- tex_print_format("Warning: end of file when %G is incomplete", 1);
- cur_group = save_level(lmt_save_state.save_stack_data.ptr);
- lmt_save_state.save_stack_data.ptr = save_value(lmt_save_state.save_stack_data.ptr);
- }
- /*tex Restore old values. */
- lmt_save_state.save_stack_data.ptr = cond_ptr;
- cur_level = (quarterword) if_limit;
- cur_group = (quarterword) cur_if;
- cond_ptr = lmt_condition_state.cond_ptr;
- cur_if = lmt_condition_state.cur_if;
- cur_unless = lmt_condition_state.cur_unless;
- if_step = lmt_condition_state.if_step;
- if_unless = lmt_condition_state.if_unless;
- if_limit = lmt_condition_state.if_limit;
- if_line = lmt_condition_state.if_line;
- while (lmt_input_state.in_stack[lmt_input_state.in_stack_data.ptr].if_ptr != lmt_condition_state.cond_ptr) {
- /* todo, more info */
- tex_print_nlp();
- tex_print_format("Warning: end of file when %C", if_test_cmd, lmt_condition_state.cur_if);
- if (lmt_condition_state.if_limit == fi_code) {
- tex_print_str_esc("else");
+ {
+ // save_state_info saved_save_stack_data = lmt_save_state;
+ halfword saved_stack_ptr = lmt_save_state.save_stack_data.ptr;
+ quarterword saved_group = cur_group;
+ quarterword saved_level = cur_level;
+ lmt_save_state.save_stack_data.ptr = cur_boundary;
+ while (lmt_input_state.in_stack[lmt_input_state.in_stack_data.ptr].group != lmt_save_state.save_stack_data.ptr) {
+ --cur_level;
+ tex_print_nlp();
+ tex_print_format("Warning: end of file when %G is incomplete", 1);
+ cur_group = save_level(lmt_save_state.save_stack_data.ptr);
+ lmt_save_state.save_stack_data.ptr = save_value(lmt_save_state.save_stack_data.ptr);
}
- if (lmt_condition_state.if_line) {
- tex_print_format(" entered on line %i", lmt_condition_state.if_line);
+ // lmt_save_state = saved_save_stack_data;
+ lmt_save_state.save_stack_data.ptr = saved_stack_ptr;
+ cur_level = saved_level;
+ cur_group = saved_group;
+ }
+ {
+ condition_state_info saved_condition_state = lmt_condition_state;
+ // halfword cond_ptr = lmt_condition_state.cond_ptr;
+ // int cur_if = lmt_condition_state.cur_if;
+ // int cur_unless = lmt_condition_state.cur_unless;
+ // int if_step = lmt_condition_state.if_step;
+ // int if_unless = lmt_condition_state.if_unless;
+ // int if_limit = lmt_condition_state.if_limit;
+ // int if_line = lmt_condition_state.if_line;
+ while (lmt_input_state.in_stack[lmt_input_state.in_stack_data.ptr].if_ptr != lmt_condition_state.cond_ptr) {
+ /* todo, more info */
+ tex_print_nlp();
+ tex_print_format("Warning: end of file when %C", if_test_cmd, lmt_condition_state.cur_if);
+ if (lmt_condition_state.if_limit == fi_code) {
+ tex_print_str_esc("else");
+ }
+ if (lmt_condition_state.if_line) {
+ tex_print_format(" entered on line %i", lmt_condition_state.if_line);
+ }
+ tex_print_str(" is incomplete");
+ lmt_condition_state.cur_if = if_limit_subtype(lmt_condition_state.cond_ptr);
+ lmt_condition_state.cur_unless = if_limit_unless(lmt_condition_state.cond_ptr);
+ lmt_condition_state.if_step = if_limit_step(lmt_condition_state.cond_ptr);
+ lmt_condition_state.if_unless = if_limit_stepunless(lmt_condition_state.cond_ptr);
+ lmt_condition_state.if_limit = if_limit_type(lmt_condition_state.cond_ptr);
+ lmt_condition_state.if_line = if_limit_line(lmt_condition_state.cond_ptr);
+ lmt_condition_state.cond_ptr = node_next(lmt_condition_state.cond_ptr);
}
- tex_print_str(" is incomplete");
- lmt_condition_state.cur_if = if_limit_subtype(lmt_condition_state.cond_ptr);
- lmt_condition_state.cur_unless = if_limit_unless(lmt_condition_state.cond_ptr);
- lmt_condition_state.if_step = if_limit_step(lmt_condition_state.cond_ptr);
- lmt_condition_state.if_unless = if_limit_stepunless(lmt_condition_state.cond_ptr);
- lmt_condition_state.if_limit = if_limit_type(lmt_condition_state.cond_ptr);
- lmt_condition_state.if_line = if_limit_line(lmt_condition_state.cond_ptr);
- lmt_condition_state.cond_ptr = node_next(lmt_condition_state.cond_ptr);
- }
- /*tex restore old values */
- lmt_condition_state.cond_ptr = cond_ptr;
- lmt_condition_state.cur_if = cur_if;
- lmt_condition_state.cur_unless = cur_unless;
- lmt_condition_state.if_step = if_step;
- lmt_condition_state.if_unless = if_unless;
- lmt_condition_state.if_limit = if_limit;
- lmt_condition_state.if_line = if_line;
+ lmt_condition_state = saved_condition_state;
+ // lmt_condition_state.cond_ptr = cond_ptr;
+ // lmt_condition_state.cur_if = cur_if;
+ // lmt_condition_state.cur_unless = cur_unless;
+ // lmt_condition_state.if_step = if_step;
+ // lmt_condition_state.if_unless = if_unless;
+ // lmt_condition_state.if_limit = if_limit;
+ // lmt_condition_state.if_line = if_line;
+ }
tex_print_nlp();
if (tracing_nesting_par > 1) {
tex_show_context();
@@ -1818,12 +1884,12 @@ static next_line_retval tex_aux_next_line(void)
switch (lmt_input_state.cur_input.name) {
case io_lua_input_code:
{
- halfword n = null;
+ halfword result = null;
int cattable = 0;
int partial = 0;
int finalline = 0;
- int t = lmt_cstring_input(&n, &cattable, &partial, &finalline);
- switch (t) {
+ int type = lmt_cstring_input(&result, &cattable, &partial, &finalline);
+ switch (type) {
case eof_tex_input:
lmt_token_state.force_eof = 1;
break;
@@ -1841,24 +1907,24 @@ static next_line_retval tex_aux_next_line(void)
break;
case token_tex_input:
/*tex token */
- if (n >= cs_token_flag && eq_type(n - cs_token_flag) == input_cmd && eq_value(n - cs_token_flag) == end_of_input_code && lmt_input_state.cur_input.index > 0) {
+ if (result >= cs_token_flag && eq_type(result - cs_token_flag) == input_cmd && eq_value(result - cs_token_flag) == end_of_input_code && lmt_input_state.cur_input.index > 0) {
tex_end_file_reading();
}
- tex_back_input(n);
+ tex_back_input(result);
return next_line_restart;
case token_list_tex_input:
/*tex token */
- tex_begin_backed_up_list(n);
+ tex_begin_backed_up_list(result);
return next_line_restart;
case node_tex_input:
/*tex node */
- if (node_token_overflow(n)) {
- tex_back_input(token_val(ignore_cmd, node_token_lsb(n)));
- tex_reinsert_token(token_val(node_cmd, node_token_msb(n)));
+ if (node_token_overflow(result)) {
+ tex_back_input(token_val(ignore_cmd, node_token_lsb(result)));
+ tex_reinsert_token(token_val(node_cmd, node_token_msb(result)));
return next_line_restart;
} else {
/*tex |0x10FFFF == 1114111| */
- tex_back_input(token_val(node_cmd, n));
+ tex_back_input(token_val(node_cmd, result));
return next_line_restart;
}
default:
@@ -1871,12 +1937,12 @@ static next_line_retval tex_aux_next_line(void)
case io_token_eof_input_code:
{
/* can be simplified but room for extensions now */
- halfword n = null;
+ halfword result = null;
int cattable = 0;
int partial = 0;
int finalline = 0;
- int t = lmt_cstring_input(&n, &cattable, &partial, &finalline);
- switch (t) {
+ int type = lmt_cstring_input(&result, &cattable, &partial, &finalline);
+ switch (type) {
case eof_tex_input:
lmt_token_state.force_eof = 1;
if (lmt_input_state.cur_input.name == io_token_eof_input_code && every_eof_par) {
@@ -2062,6 +2128,43 @@ void tex_get_next(void)
}
}
+void tex_get_next_non_spacer(void)
+{
+ while (1) {
+ cur_cs = 0;
+ if (lmt_input_state.cur_input.state != token_list_state) {
+ /*tex Input from external file, |goto restart| if no input found. */
+ if (! tex_aux_get_next_file()) {
+ continue;
+ } else {
+ /*tex Check align state later on! */
+ }
+ } else if (! lmt_input_state.cur_input.loc) {
+ /*tex List exhausted, resume previous level. */
+ tex_end_token_list();
+ continue;
+ } else if (! tex_aux_get_next_tokenlist()) {
+ /*tex Parameter needs to be expanded. */
+ continue;
+ }
+ switch (cur_cmd) {
+ case spacer_cmd:
+ continue;
+ case alignment_tab_cmd:
+ case alignment_cmd:
+ if (lmt_input_state.align_state == 0) {
+ /*tex If an alignment entry has just ended, take appropriate action. */
+ tex_insert_alignment_template();
+ continue;
+ } else {
+ return;
+ }
+ default:
+ return;
+ }
+ }
+}
+
/*tex
Since |get_next| is used so frequently in \TEX, it is convenient to define three related
@@ -2834,7 +2937,7 @@ void tex_run_convert_tokens(halfword code)
lmt_input_state.scanner_status = saved_scanner_status;
t = tex_get_available_token(cur_tok);
push_selector;
- tex_show_token_list(t, null, extreme_token_show_max, 0);
+ tex_show_token_list(t, 0);
tex_put_available_token(t);
pop_selector;
break;
@@ -3054,7 +3157,7 @@ strnumber tex_tokens_to_string(halfword p)
} else {
int saved_selector = lmt_print_state.selector;
lmt_print_state.selector = new_string_selector_code;
- tex_token_show(p, extreme_token_show_max);
+ tex_token_show(p);
lmt_print_state.selector = saved_selector;
return tex_make_string();
}
diff --git a/source/luametatex/source/tex/textoken.h b/source/luametatex/source/tex/textoken.h
index 68632792b..345c04c23 100644
--- a/source/luametatex/source/tex/textoken.h
+++ b/source/luametatex/source/tex/textoken.h
@@ -95,7 +95,7 @@ typedef enum catcode_table_presets {
*/
typedef struct token_state_info {
- halfword null_list; /*tex permanently empty list */
+ halfword null_list; /*tex permanently empty list */
int in_lua_escape;
int force_eof;
int luacstrings;
@@ -165,20 +165,22 @@ extern token_state_info lmt_token_state;
yet when we're here. so we can't use for instance |token_val (spacer_cmd, 20)| yet.
*/
-# define left_brace_token token_val( 1, 0) // token_val(left_brace_cmd,0)
-# define right_brace_token token_val( 2, 0) // token_val(right_brace_cmd,0)
-# define math_shift_token token_val( 3, 0) // token_val(math_shift_cmd,0)
-# define alignment_token token_val( 4, 0)
-# define superscript_token token_val( 7, 0)
-# define subscript_token token_val( 8, 0)
-# define ignore_token token_val( 9, 0) // token_val(ignore_cmd,0)
-# define space_token token_val(10,32) // token_val(spacer_cmd,32)
-# define letter_token token_val(11, 0) // token_val(letter_cmd,0)
-# define other_token token_val(12, 0) // token_val(other_char_cmd,0)
-# define active_token token_val(13, 0)
-
-# define match_token token_val(19,0) // token_val(match_cmd,0)
-# define end_match_token token_val(20,0) // token_val(end_match_cmd,0)
+# define left_brace_token token_val( 1, 0) /* token_val(left_brace_cmd, 0) */
+# define right_brace_token token_val( 2, 0) /* token_val(right_brace_cmd, 0) */
+# define math_shift_token token_val( 3, 0) /* token_val(math_shift_cmd, 0) */
+# define alignment_token token_val( 4, 0) /* token_val(alignment_tab_cmd, 0) */
+# define endline_token token_val( 5, 0) /* token_val(end_line_cmd, 0) */
+# define parameter_token token_val( 6, 0) /* token_val(parameter_cmd, 0) */
+# define superscript_token token_val( 7, 0) /* token_val(superscript_cmd, 0) */
+# define subscript_token token_val( 8, 0) /* token_val(subscript_cmd, 0) */
+# define ignore_token token_val( 9, 0) /* token_val(ignore_cmd, 0) */
+# define space_token token_val(10,32) /* token_val(spacer_cmd, 32) */
+# define letter_token token_val(11, 0) /* token_val(letter_cmd 0) */
+# define other_token token_val(12, 0) /* token_val(other_char_cmd, 0) */
+# define active_token token_val(13, 0) /* token_val(active_char_cmd, 0) */
+
+# define match_token token_val(19, 0) /* token_val(match_cmd, 0) */
+# define end_match_token token_val(20, 0) /* token_val(end_match_cmd, 0) */
# define left_brace_limit right_brace_token
# define right_brace_limit math_shift_token
@@ -200,13 +202,13 @@ extern token_state_info lmt_token_state;
# define less_token (other_token + '<')
# define more_token (other_token + '>')
# define exclamation_token_o (other_token + '!')
-# define exclamation_token_l (letter_token + '!')
+# define exclamation_token_l (letter_token + '!') /* letter */
# define underscore_token (other_token + '_')
# define underscore_token_o (other_token + '_')
-# define underscore_token_l (letter_token + '_')
+# define underscore_token_l (letter_token + '_') /* letter */
# define circumflex_token (other_token + '^')
# define circumflex_token_o (other_token + '^')
-# define circumflex_token_l (letter_token + '^')
+# define circumflex_token_l (letter_token + '^') /* letter */
# define escape_token (other_token + '\\')
# define left_parent_token (other_token + '(')
# define right_parent_token (other_token + ')')
@@ -215,6 +217,8 @@ extern token_state_info lmt_token_state;
# define seven_token (other_token + '7')
# define nine_token (other_token + '9') /*tex zero, the smallest digit */
+# define dollar_token_m (math_shift_token + '$')
+
# define a_token_l (letter_token + 'a') /*tex the smallest special hex digit */
# define a_token_o (other_token + 'a')
@@ -338,11 +342,11 @@ extern void tex_increment_token_reference (halfword p, int n);
# define no_expand_flag special_char /* no_expand_relax_code */
-/*tex A few special values: */
+/*tex A few special values; these are no longer used as we always go for maxima. */
# define default_token_show_min 32
-# define default_token_show_max 2500
-# define extreme_token_show_max 0x3FFFFFFF
+# define default_token_show_max 2500
+# define extreme_token_show_max 0x3FFFFFFF
/*tex All kind of helpers: */
@@ -351,11 +355,13 @@ extern void tex_undump_token_mem (dumpstream f);
extern void tex_print_meaning (halfword code);
extern void tex_flush_token_list (halfword p);
extern void tex_flush_token_list_head_tail (halfword h, halfword t, int n);
-extern halfword tex_show_token_list (halfword p, halfword q, int l, int asis); /* Here |l| will go away. */
-extern void tex_token_show (halfword p, int max);
+extern void tex_show_token_list_context (halfword p, halfword q);
+extern void tex_show_token_list (halfword p, int asis);
+extern void tex_token_show (halfword p);
/* void tex_add_token_ref (halfword p); */
/* void tex_delete_token_ref (halfword p); */
extern void tex_get_next (void);
+extern void tex_get_next_non_spacer (void);
extern halfword tex_scan_character (const char *s, int left_brace, int skip_space, int skip_relax);
extern int tex_scan_optional_keyword (const char *s);
extern int tex_scan_mandate_keyword (const char *s, int offset);
diff --git a/source/luametatex/source/tex/textypes.h b/source/luametatex/source/tex/textypes.h
index 05324db83..2ca761e59 100644
--- a/source/luametatex/source/tex/textypes.h
+++ b/source/luametatex/source/tex/textypes.h
@@ -416,6 +416,18 @@ typedef union memoryword {
void *P;
} memoryword;
+typedef union tokenword {
+ union {
+ halfword info;
+ halfword val;
+ struct {
+ int cmd:8;
+ int chr:24;
+ };
+ };
+ halfword link;
+} tokenword;
+
/*tex
These symbolic names will be used in the definitions of tokens and nodes, the core data
@@ -636,9 +648,10 @@ can be neglected (no differences on the test suite) because the bottleneck in \C
I occasionally test the variants. The last test showed that mode 1 gives a bit larger binary. There
is no real difference in performance.
-*/
+Well, per end December 2022 we only have the case with modes left but one can always find the old
+code in the archive.
-# define main_control_mode 1
+*/
/*tex For the moment here. */