summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2023-01-04 12:09:26 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2023-01-04 12:09:26 +0100
commit705b807c950a697d3c8be592c452a6fb3e561c7e (patch)
tree82904661aca945d008f07deb568ee7f05b55df4f /source
parent62d980c99a617ff260f29ac2d3bdb084049f25b0 (diff)
downloadcontext-705b807c950a697d3c8be592c452a6fb3e561c7e.tar.gz
2023-01-04 11:35:00
Diffstat (limited to 'source')
-rw-r--r--source/luametatex/source/libraries/avl/avl.c110
-rw-r--r--source/luametatex/source/libraries/avl/readme.txt3
-rw-r--r--source/luametatex/source/lua/lmtmplib.c28
-rw-r--r--source/luametatex/source/lua/lmttexlib.c679
-rw-r--r--source/luametatex/source/lua/lmttexlib.h2
-rw-r--r--source/luametatex/source/lua/lmttokenlib.c25
-rw-r--r--source/luametatex/source/luametatex.h2
-rw-r--r--source/luametatex/source/luarest/lmtmd5lib.c2
-rw-r--r--source/luametatex/source/luarest/lmtoslibext.c27
-rw-r--r--source/luametatex/source/luarest/lmtstrlibext.c2
-rw-r--r--source/luametatex/source/mp/mpc/mp.c96
-rw-r--r--source/luametatex/source/mp/mpc/mp.h20
-rw-r--r--source/luametatex/source/mp/mpw/mp.w117
-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
-rw-r--r--source/luametatex/source/utilities/auxsparsearray.c27
-rw-r--r--source/luametatex/source/utilities/auxsparsearray.h10
42 files changed, 1996 insertions, 1437 deletions
diff --git a/source/luametatex/source/libraries/avl/avl.c b/source/luametatex/source/libraries/avl/avl.c
index e1c18ceb5..89f01e34e 100644
--- a/source/luametatex/source/libraries/avl/avl.c
+++ b/source/luametatex/source/libraries/avl/avl.c
@@ -58,9 +58,7 @@ typedef struct avl_node { /* aligned */
int padding;
} avl_node;
-/*
- * avl_tree structure
- */
+/* avl_tree structure */
struct avl_tree_ { /* aligned */
avl_node *root;
@@ -99,7 +97,7 @@ struct avl_tree_ { /* aligned */
# define AVL_MIN_DEPTH 0
-/* helper structure */
+/* Helper structure. */
typedef enum {
OP_BACKUP,
@@ -107,7 +105,8 @@ typedef enum {
OP_FREE
} whichop_t;
-typedef struct ptr_handler { /* swapped and aligned */
+typedef struct ptr_handler {
+ /* swapped and aligned */
void *ptr;
whichop_t whichop;
int padding;
@@ -121,7 +120,7 @@ static void clear_node(avl_node *a)
rbal(a) = 4u;
}
-/* Called by 'avl_ins', 'avl_dup', 'node_slice' */
+/* Called by 'avl_ins', 'avl_dup', 'node_slice'. */
static avl_node *new_node(void *item, avl_node *up, avl_tree t)
{
@@ -144,7 +143,7 @@ static void free_node(avl_node *a, avl_tree t)
(*t->dealloc)(a);
}
-/* function to detach node [a] from tree [t] (compiler will inline if needed) */
+/* Function to detach node [a] from tree [t] (compiler will inline if needed). */
static void detach_node(avl_node *a, avl_tree t, struct ptr_handler *h)
{
@@ -163,7 +162,7 @@ static void detach_node(avl_node *a, avl_tree t, struct ptr_handler *h)
t->count--;
}
-/* Tree methods */
+/* Tree methods. */
avl_tree avl_create (
avl_compare_func compare,
@@ -190,7 +189,7 @@ avl_tree avl_create (
return t;
}
-/* Empty the tree, using rotations */
+/* Empty the tree using rotations. */
static void node_empty(avl_tree t)
{
@@ -215,7 +214,7 @@ static void node_empty(avl_tree t)
t->root = NULL;
}
-/* [t] is an existing tree handle; this function invokes node_empty() */
+/* [t] is an existing tree handle; this function invokes node_empty(). */
void avl_reset (
avl_tree t,
@@ -243,7 +242,7 @@ void avl_empty(avl_tree t)
}
}
-/* Destroy nodes, free handle */
+/* Destroy nodes and free handle. */
void avl_destroy(avl_tree t)
{
@@ -308,7 +307,7 @@ avl_tree avl_dup(avl_tree t, void *param)
goto recover;
}
}
- /* recovery code */
+ /* recovery code */
recover:
while (1) {
s = sub_right(c);
@@ -432,7 +431,7 @@ static avl_size_t get_index(avl_node *a)
return n;
}
-/* Find item by index */
+/* Find item by index. */
static avl_node *node_find_index(avl_size_t idx, avl_tree t)
{
@@ -457,7 +456,7 @@ static avl_node *node_find_index(avl_size_t idx, avl_tree t)
}
}
-/* Rebalance starting from node [a] where a->sub[d_] is deeper post-insertion */
+/* Rebalance starting from node [a] where a->sub[d_] is deeper post-insertion. */
static avl_code_t rebalance_ins(avl_node *a, int dir, avl_tree t)
{
@@ -478,8 +477,7 @@ static avl_code_t rebalance_ins(avl_node *a, int dir, avl_tree t)
}
}
}
- /* Now bal(a) == -1 or +1 */
- /* Rotate if need be */
+ /* Now bal(a) == -1 or +1. Rotate if needed. */
if (dir == 0) {
if (is_rskew(a))
unset_rskew(a);
@@ -589,8 +587,7 @@ static avl_code_t rebalance_ins(avl_node *a, int dir, avl_tree t)
p->up = a;
*r = a;
}
- /* The tree rooted at 'a' is now valid */
- /* Finish adjusting ranks */
+ /* The tree rooted at 'a' is now valid. Finish adjusting ranks */
while ((p = a->up)) {
incr_rank(p, (rbal_t)(a == sub_left(p)));
a = p;
@@ -838,10 +835,7 @@ void *avl_find(const void *item, avl_tree t)
}
}
-/*
- Return smallest index i in [1:len] s.t. tree[i] matches [item], or zero if
- not found
-*/
+/* Return smallest index i in [1:len] s.t. tree[i] matches [item], or zero if not found. */
avl_size_t avl_index(const void *item, avl_tree t)
{
@@ -869,8 +863,8 @@ avl_size_t avl_index(const void *item, avl_tree t)
}
/*
- (lo,hi) where lo smallest index s.t. t[lo] >= lo_item, or t->count+1 and hi
- greatest index s.t. t[hi] <= hi_item, or 0
+ (lo,hi) where lo smallest index s.t. t[lo] >= lo_item, or t->count+1 and hi greatest index s.t.
+ t[hi] <= hi_item, or 0.
*/
avl_code_t avl_span(const void *lo_item, const void *hi_item, avl_tree t, avl_size_t *lo_idx, avl_size_t *hi_idx)
@@ -915,7 +909,7 @@ avl_code_t avl_span(const void *lo_item, const void *hi_item, avl_tree t, avl_si
return -1;
}
-/* Find the smallest item in tree [t] that is GEQ the passed item */
+/* Find the smallest item in tree [t] that is GEQ the passed item. */
void *avl_find_atleast(const void *item, avl_tree t)
{
@@ -938,7 +932,7 @@ void *avl_find_atleast(const void *item, avl_tree t)
}
}
-/* Find the greatest item in tree [t] that is LEQ the passed item */
+/* Find the greatest item in tree [t] that is LEQ the passed item. */
void *avl_find_atmost(const void *item, avl_tree t)
{
@@ -961,7 +955,7 @@ void *avl_find_atmost(const void *item, avl_tree t)
}
}
-/* Retrieve item of index [idx] in tree [t] */
+/* Retrieve item of index [idx] in tree [t]. */
void *avl_find_index(avl_size_t idx, avl_tree t)
{
@@ -973,9 +967,9 @@ void *avl_find_index(avl_size_t idx, avl_tree t)
}
}
-/* Iterative insertion */
+/* Iterative insertion. */
-avl_code_t avl_ins (void *item, avl_tree t, avl_bool_t allow_duplicates)
+avl_code_t avl_ins(void *item, avl_tree t, avl_bool_t allow_duplicates)
{
if (t) {
avl_compare_func cmp = t->compare;
@@ -1013,7 +1007,7 @@ avl_code_t avl_del(void *item, avl_tree t, void **backup)
}
}
-/* helper function */
+/* Helper function. */
static avl_code_t node_del_first(avl_tree t, struct ptr_handler *h)
{
@@ -1221,11 +1215,7 @@ static avl_code_t node_del_last(avl_tree t, struct ptr_handler *h)
return 1;
}
-/*
- [p] : juncture node(zeroed out)
- [n] : rank of [p] in resulting tree
- [delta] = depth_1 - depth_0
-*/
+/* [p] is juncture node(zeroed out), [n] is rank of [p] in resulting tree, [delta] = depth_1 - depth_0 */
static avl_code_t join_left(avl_node *p, avl_node **r0, avl_node *r1, int delta, int n)
{
@@ -1329,10 +1319,7 @@ static avl_code_t join_left(avl_node *p, avl_node **r0, avl_node *r1, int delta,
return 1;
}
-/*
- [p] : juncture node
- [n] : rank of [p] in resulting tree
-*/
+/* [p] is juncture node and [n] is rank of [p] in resulting tree. */
static avl_code_t join_right(avl_node *p, avl_node *r0, avl_node **r1, int delta, int n)
{
@@ -1376,8 +1363,7 @@ static avl_code_t join_right(avl_node *p, avl_node *r0, avl_node **r1, int delta
a = a->up;
}
}
- /* Rotate if need be */
- /* No (-2,0) rotation to do */
+ /* Rotate if need be. No (-2,0) rotation to do. */
if (is_rskew(a)) {
unset_rskew(a);
} else {
@@ -1519,7 +1505,7 @@ avl_code_t avl_del_index(avl_size_t idx, avl_tree t, void **backup)
}
}
-/* Outcome: [t0] handles the concatenation of [t0] and [t1] */
+/* Outcome: [t0] handles the concatenation of [t0] and [t1]. */
void avl_cat(avl_tree t0, avl_tree t1)
{
@@ -1551,10 +1537,7 @@ void avl_cat(avl_tree t0, avl_tree t1)
}
}
-/*
- - [t0] and [t1] are existing handles
- - See Donald Knuth, TAOCP Vol.3 "Sorting and searching"
-*/
+/* [t0] and [t1] are existing handles; see Donald Knuth, TAOCP Vol.3 "Sorting and searching". */
avl_code_t avl_split(const void *item, avl_tree t, avl_tree t0, avl_tree t1)
{
@@ -1566,7 +1549,7 @@ avl_code_t avl_split(const void *item, avl_tree t, avl_tree t0, avl_tree t1)
t1->root = NULL;
t0->count = 0;
t1->count = 0;
- /* invariant: [na]= size of tree rooted at [a] plus one */
+ /* invariant: [na] = size of tree rooted at [a] plus one */
for (a = t->root, na = (int) (t->count + 1), k = 0;;) {
int d_ = item_compare(cmp, t, item, get_item(a));
if (d_) {
@@ -1615,7 +1598,7 @@ avl_code_t avl_split(const void *item, avl_tree t, avl_tree t0, avl_tree t1)
ha = depth(a);
h[0] = ha - (is_rskew(a) ? 2 : 1);
h[1] = ha - (is_lskew(a) ? 2 : 1);
- n[0] = get_rank(a); /* size of r[0] plus one */
+ n[0] = get_rank(a); /* size of r[0] plus one */
n[1] = (avl_size_t) na - n[0]; /* size of r[1] plus one */
for (p = a->up, d_ = a != sub_left(p);;) {
a = p; /* a: juncture node */
@@ -1681,7 +1664,7 @@ avl_code_t avl_split(const void *item, avl_tree t, avl_tree t0, avl_tree t1)
}
}
-/* Inorder traversal */
+/* Inorder traversal. */
void avl_walk(avl_tree t, avl_item_func proc, void *param)
{
@@ -1711,13 +1694,13 @@ void avl_walk(avl_tree t, avl_item_func proc, void *param)
}
}
-/* recursive helper for 'avl_slice' */
+/* Recursive helper for 'avl_slice'. */
static int node_slice(avl_node **root, avl_node **cur, avl_tree tree, avl_size_t len)
{
avl_size_t mid = len / 2;
if (mid == 0) {
- if ((*root = new_node ((*cur)->item, /*parent */ NULL, tree)) == NULL) {
+ if ((*root = new_node ((*cur)->item, /* parent */ NULL, tree)) == NULL) {
return -1;
} else {
sub_left(*root) = NULL;
@@ -1726,7 +1709,7 @@ static int node_slice(avl_node **root, avl_node **cur, avl_tree tree, avl_size_t
*cur = node_next(*cur);
return 0;
}
- } else if ((*root = new_node(NULL, /*parent */ NULL, tree))) {
+ } else if ((*root = new_node(NULL, /* parent */ NULL, tree))) {
avl_node *p = *root;
int h0, h1 = -1;
rbal(p) = (mid + 1) << 2;
@@ -1756,7 +1739,7 @@ static int node_slice(avl_node **root, avl_node **cur, avl_tree tree, avl_size_t
}
}
-/* Return a slice t[lo,hi) as a new tree */
+/* Return a slice t[lo,hi) as a new tree. */
avl_tree avl_slice(avl_tree t, avl_size_t lo_idx, avl_size_t hi_idx, void *param)
{
@@ -1792,13 +1775,13 @@ avl_tree avl_slice(avl_tree t, avl_size_t lo_idx, avl_size_t hi_idx, void *param
}
}
-/* recursive helper for 'avl_xload' */
+/* Recursive helper for 'avl_xload'. */
static int node_load(avl_node **root, avl_itersource cur, void **pres, avl_tree desc, avl_size_t len)
{
avl_size_t mid = len / 2;
if (mid == 0) {
- if (0 != (*cur->f) (cur, pres) || (*root = new_node (*pres, /*parent */ NULL, desc)) == NULL) {
+ if (0 != (*cur->f) (cur, pres) || (*root = new_node (*pres, /* parent */ NULL, desc)) == NULL) {
return -1;
} else {
sub_left(*root) = NULL;
@@ -1806,7 +1789,7 @@ static int node_load(avl_node **root, avl_itersource cur, void **pres, avl_tree
rbal(*root) = 4;
return 0;
}
- } else if ((*root = new_node (NULL, /*parent */ NULL, desc))) {
+ } else if ((*root = new_node (NULL, /* parent */ NULL, desc))) {
avl_node *p = *root;
int h0, h1 = -1;
rbal(p) = (mid + 1) << 2;
@@ -1837,7 +1820,7 @@ static int node_load(avl_node **root, avl_itersource cur, void **pres, avl_tree
}
}
-/* Load 'len' items from itersource */
+/* Load 'len' items from itersource. */
avl_tree avl_xload(avl_itersource src, void **pres, avl_size_t len, avl_config conf, void *tree_param)
{
@@ -1885,8 +1868,8 @@ struct avl_iterator_
# define set_in_iterator(i) i->status = AVL_ITERATOR_INTREE
/*
- Position existing iterator [iter] at node matching [item] in its own tree,
- if it exists ; otherwise do nothing
+ Position existing iterator [iter] at node matching [item] in its own tree, if it exists;
+ otherwise do nothing.
*/
void avl_iterator_seek(const void *item, avl_iterator iter)
@@ -1907,7 +1890,7 @@ void avl_iterator_seek_index(avl_size_t idx, avl_iterator iter)
}
}
-/* Return item pointer at current position */
+/* Return item pointer at current position. */
void *avl_iterator_cur(avl_iterator iter)
{
@@ -1961,10 +1944,7 @@ avl_iterator avl_iterator_new(avl_tree t, avl_ini_t ini, ...)
return iter;
}
-/*
- The following used to write to memory after it was freed. Corrected by: David
- Turner <novalis@openplans.org>
-*/
+/* The following used to write to memory after it was freed. */
void avl_iterator_kill(avl_iterator iter)
{
@@ -2022,7 +2002,7 @@ void *avl_iterator_prev(avl_iterator iter)
}
}
-/* Remove node at current position and move cursor to next position */
+/* Remove node at current position and move cursor to next position. */
avl_code_t avl_iterator_del(avl_iterator iter, void **backup)
{
diff --git a/source/luametatex/source/libraries/avl/readme.txt b/source/luametatex/source/libraries/avl/readme.txt
index de5d4993e..90ff0949b 100644
--- a/source/luametatex/source/libraries/avl/readme.txt
+++ b/source/luametatex/source/libraries/avl/readme.txt
@@ -17,4 +17,7 @@ information mentioned above. The files had some (experimental) code as well as o
values. As I don't expect updates (the code has been okay for quite a while) I made the tests mandate
and removed the experimental code.
+We can strip this library and save some 10K on the binary because we don't need that much of it. That
+might happen at some point.
+
Hans Hagen \ No newline at end of file
diff --git a/source/luametatex/source/lua/lmtmplib.c b/source/luametatex/source/lua/lmtmplib.c
index 83fe3efd4..e7df5e963 100644
--- a/source/luametatex/source/lua/lmtmplib.c
+++ b/source/luametatex/source/lua/lmtmplib.c
@@ -2761,44 +2761,38 @@ static void mplib_aux_push_color(lua_State *L, struct mp_graphic_object *p)
{
if (p) {
int object_color_model;
- double object_color_a, object_color_b, object_color_c, object_color_d;
+ mp_color object_color;
switch (p->type) {
case mp_fill_code:
case mp_stroked_code:
{
mp_shape_object *h = (mp_shape_object *) p;
object_color_model = h->color_model;
- object_color_a = h->color.a_val;
- object_color_b = h->color.b_val;
- object_color_c = h->color.c_val;
- object_color_d = h->color.d_val;
+ object_color = h->color;
}
break;
default:
object_color_model = mp_no_model;
- object_color_a = 0.0;
- object_color_b = 0.0;
- object_color_c = 0.0;
- object_color_d = 0.0;
+ object_color = (mp_color) { { 0.0 }, { 0.0 }, { 0.0 }, { 0.0 } };
break;
}
switch (object_color_model) {
case mp_grey_model:
lua_createtable(L, 1, 0);
- lua_push_number_at_index(L, 1, object_color_d);
+ lua_push_number_at_index(L, 1, object_color.gray);
break;
case mp_rgb_model:
lua_createtable(L, 3, 0);
- lua_push_number_at_index(L, 1, object_color_a);
- lua_push_number_at_index(L, 2, object_color_b);
- lua_push_number_at_index(L, 3, object_color_c);
+ lua_push_number_at_index(L, 1, object_color.red);
+ lua_push_number_at_index(L, 2, object_color.green);
+ lua_push_number_at_index(L, 3, object_color.blue);
break;
case mp_cmyk_model:
lua_createtable(L, 4, 0);
- lua_push_number_at_index(L, 1, object_color_a);
- lua_push_number_at_index(L, 2, object_color_b);
- lua_push_number_at_index(L, 3, object_color_c);
- lua_push_number_at_index(L, 4, object_color_d);
+ lua_push_number_at_index(L, 1, object_color.cyan);
+ lua_push_number_at_index(L, 2, object_color.magenta);
+ lua_push_number_at_index(L, 3, object_color.yellow);
+ lua_push_number_at_index(L, 4, object_color.black);
break;
default:
lua_pushnil(L);
diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c
index 9c1247884..ecc0d63ed 100644
--- a/source/luametatex/source/lua/lmttexlib.c
+++ b/source/luametatex/source/lua/lmttexlib.c
@@ -126,8 +126,11 @@ static void texlib_aux_show_half_error(lua_State *L, int i)
*/
-# define FULL_LINE 0
-# define PARTIAL_LINE 1
+typedef enum line_modes {
+ full_line_mode = 0,
+ partial_line_mode = 1,
+} line_modes;
+
# define PACKED_SIZE 8
# define INITIAL_SIZE 32
# define MAX_ROPE_CACHE 5000
@@ -199,31 +202,31 @@ inline static void texlib_aux_reset_spindle(int i)
inline static spindle_rope *texlib_aux_new_rope(void)
{
- spindle_rope *r;
+ spindle_rope *rope;
if (lmt_spindle_state.rope_cache) {
- r = lmt_spindle_state.rope_cache;
- lmt_spindle_state.rope_cache = r->next;
+ rope = lmt_spindle_state.rope_cache;
+ lmt_spindle_state.rope_cache = rope->next;
} else {
- r = (spindle_rope *) lmt_memory_malloc(sizeof(spindle_rope));
+ rope = (spindle_rope *) lmt_memory_malloc(sizeof(spindle_rope));
++lmt_spindle_state.rope_count;
- if (r) {
- r->next = NULL;
+ if (rope) {
+ rope->next = NULL;
} else {
tex_overflow_error("spindle", sizeof(spindle_rope));
}
}
- return r;
+ return rope;
}
-inline static void texlib_aux_dispose_rope(spindle_rope *r)
+inline static void texlib_aux_dispose_rope(spindle_rope *rope)
{
- if (r) {
+ if (rope) {
if (lmt_spindle_state.rope_count > MAX_ROPE_CACHE) {
- lmt_memory_free(r);
+ lmt_memory_free(rope);
--lmt_spindle_state.rope_count;
} else {
- r->next = lmt_spindle_state.rope_cache;
- lmt_spindle_state.rope_cache = r;
+ rope->next = lmt_spindle_state.rope_cache;
+ lmt_spindle_state.rope_cache = rope;
}
}
}
@@ -246,10 +249,10 @@ static void texlib_aux_initialize(void)
We could convert strings into tokenlists here but conceptually the split is cleaner.
*/
-static int texlib_aux_store(lua_State *L, int i, int partial, int cattable)
+static int texlib_aux_store(lua_State *L, int i, int partial, int cattable, int append)
{
size_t tsize = 0;
- spindle_rope *rn = NULL;
+ spindle_rope *rope = NULL;
unsigned char kind = unset_lua_input;
spindle_data data = { .h = 0 };
switch (lua_type(L, i)) {
@@ -274,8 +277,22 @@ static int texlib_aux_store(lua_State *L, int i, int partial, int cattable)
} else {
/*tex
We could append to a previous but partial interferes and in practice it then
- never can be done.
+ never can be done. How often do we print char by char?
*/
+ // if (append && write_spindle.tail && partial && partial == write_spindle.tail->partial) {
+ // if (write_spindle.tail->kind == packed_lua_input && write_spindle.tail->cattable == cattable) {
+ // size_t s = write_spindle.tail->tsize;
+ // if (tsize + s <= PACKED_SIZE) {
+ // for (unsigned i = 0; i < tsize; i++) {
+ // write_spindle.tail->data.c[s++] = (unsigned char) sttemp[i];
+ // }
+ // write_spindle.tail->tsize += tsize;
+ // // lmt_token_state.luacstrings++; /* already set */
+ // // write_spindle.complete = 0; /* already set */
+ // return 1;
+ // }
+ // }
+ // }
for (unsigned i = 0; i < tsize; i++) {
/*tex When we end up here we often don't have that many bytes. */
data.c[i] = (unsigned char) sttemp[i];
@@ -368,97 +385,97 @@ static int texlib_aux_store(lua_State *L, int i, int partial, int cattable)
return 0;
}
lmt_token_state.luacstrings++;
- rn = texlib_aux_new_rope();
+ rope = texlib_aux_new_rope();
/* set */
- rn->tsize = (unsigned) tsize;
- rn->next = NULL;
- rn->kind = kind;
- rn->partial = (unsigned char) partial;
- rn->cattable = (short) cattable;
- rn->data = data;
+ rope->tsize = (unsigned) tsize;
+ rope->next = NULL;
+ rope->kind = kind;
+ rope->partial = (unsigned char) partial;
+ rope->cattable = (short) cattable;
+ rope->data = data;
/* add */
if (write_spindle.head) {
- write_spindle.tail->next = rn;
+ write_spindle.tail->next = rope;
} else {
- write_spindle.head = rn;
+ write_spindle.head = rope;
}
- write_spindle.tail = rn;
+ write_spindle.tail = rope;
write_spindle.complete = 0;
return 1;
}
static void texlib_aux_store_token(halfword token, int partial, int cattable)
{
- spindle_rope *rn = texlib_aux_new_rope();
+ spindle_rope *rope = texlib_aux_new_rope();
/* set */
- rn->tsize = 0;
- rn->next = NULL;
- rn->kind = token_lua_input;
- rn->partial = (unsigned char) partial;
- rn->cattable = (short) cattable;
- rn->data.h = token;
+ rope->tsize = 0;
+ rope->next = NULL;
+ rope->kind = token_lua_input;
+ rope->partial = (unsigned char) partial;
+ rope->cattable = (short) cattable;
+ rope->data.h = token;
/* add */
if (write_spindle.head) {
- write_spindle.tail->next = rn;
+ write_spindle.tail->next = rope;
} else {
- write_spindle.head = rn;
+ write_spindle.head = rope;
}
- write_spindle.tail = rn;
+ write_spindle.tail = rope;
write_spindle.complete = 0;
lmt_token_state.luacstrings++;
}
static void lmx_aux_store_string(char *str, int len, int cattable)
{
- spindle_rope *rn = texlib_aux_new_rope();
- rn->data.h = 0; /* wipes */
+ spindle_rope *rope = texlib_aux_new_rope();
+ rope->data.h = 0; /* wipes */
if (len > PACKED_SIZE) {
- rn->data.t = lmt_memory_malloc((size_t) len + 1);
- if (rn->data.t) {
- memcpy(rn->data.t, str, (size_t) len + 1);
+ rope->data.t = lmt_memory_malloc((size_t) len + 1);
+ if (rope->data.t) {
+ memcpy(rope->data.t, str, (size_t) len + 1);
} else {
len = 0;
}
- rn->kind = string_lua_input;
+ rope->kind = string_lua_input;
} else {
for (int i = 0; i < len; i++) {
/* when we end up here we often don't have that many bytes */
- rn->data.c[i] = (unsigned char) str[i];
+ rope->data.c[i] = (unsigned char) str[i];
}
- rn->kind = packed_lua_input;
+ rope->kind = packed_lua_input;
}
/* set */
- rn->tsize = (unsigned) len;
- rn->next = NULL;
- rn->partial = FULL_LINE;
- rn->cattable = (unsigned char) cattable;
+ rope->tsize = (unsigned) len;
+ rope->next = NULL;
+ rope->partial = full_line_mode,
+ rope->cattable = (unsigned char) cattable;
/* add */
if (write_spindle.head) {
- write_spindle.tail->next = rn;
+ write_spindle.tail->next = rope;
} else {
- write_spindle.head = rn;
+ write_spindle.head = rope;
}
- write_spindle.tail = rn;
+ write_spindle.tail = rope;
write_spindle.complete = 0;
lmt_token_state.luacstrings++;
}
static int texlib_aux_cprint(lua_State *L, int partial, int cattable, int startstrings)
{
- int n = lua_gettop(L);
- int t = lua_type(L, startstrings);
- if (n > startstrings && cattable != no_catcode_table_preset && t == LUA_TNUMBER) {
+ int top = lua_gettop(L);
+ int type = lua_type(L, startstrings);
+ if (top > startstrings && cattable != no_catcode_table_preset && type == LUA_TNUMBER) {
cattable = lmt_tointeger(L, startstrings);
++startstrings;
if (cattable != default_catcode_table_preset && cattable != no_catcode_table_preset && ! tex_valid_catcode_table(cattable)) {
cattable = default_catcode_table_preset;
}
- t = lua_type(L, startstrings);
+ type = lua_type(L, startstrings);
}
- if (t == LUA_TTABLE) {
+ if (type == LUA_TTABLE) {
for (int i = 1;; i++) {
lua_rawgeti(L, startstrings, i);
- if (texlib_aux_store(L, -1, partial, cattable)) {
+ if (texlib_aux_store(L, -1, partial, cattable, i > 1)) {
lua_pop(L, 1);
} else {
lua_pop(L, 1);
@@ -466,8 +483,8 @@ static int texlib_aux_cprint(lua_State *L, int partial, int cattable, int starts
}
}
} else {
- for (int i = startstrings; i <= n; i++) {
- texlib_aux_store(L, i, partial, cattable);
+ for (int i = startstrings; i <= top; i++) {
+ texlib_aux_store(L, i, partial, cattable, i > startstrings);
}
}
return 0;
@@ -500,7 +517,7 @@ void lmt_cstring_print(int cattable, const char *s, int ispartial)
lua_settop(L, 0);
lua_pushinteger(L, cattable);
lua_pushstring(L, s);
- texlib_aux_cprint(L, ispartial ? PARTIAL_LINE : FULL_LINE, default_catcode_table_preset, 1);
+ texlib_aux_cprint(L, ispartial ? partial_line_mode : full_line_mode, default_catcode_table_preset, 1);
lua_settop(L, top);
}
@@ -508,21 +525,21 @@ void lmt_cstring_print(int cattable, const char *s, int ispartial)
static int texlib_write(lua_State *L)
{
- return texlib_aux_cprint(L, FULL_LINE, no_catcode_table_preset, 1);
+ return texlib_aux_cprint(L, full_line_mode, no_catcode_table_preset, 1);
}
/* lua.print */
static int texlib_print(lua_State *L)
{
- return texlib_aux_cprint(L, FULL_LINE, default_catcode_table_preset, 1);
+ return texlib_aux_cprint(L, full_line_mode, default_catcode_table_preset, 1);
}
/* lua.sprint */
static int texlib_sprint(lua_State *L)
{
- return texlib_aux_cprint(L, PARTIAL_LINE, default_catcode_table_preset, 1);
+ return texlib_aux_cprint(L, partial_line_mode, default_catcode_table_preset, 1);
}
static int texlib_mprint(lua_State *L)
@@ -531,7 +548,7 @@ static int texlib_mprint(lua_State *L)
if (tracing_nesting_par > 2) {
tex_local_control_message("entering local control via (run) macro");
}
- texlib_aux_store_token(token_val(end_local_cmd, 0), PARTIAL_LINE, default_catcode_table_preset);
+ texlib_aux_store_token(token_val(end_local_cmd, 0), partial_line_mode, default_catcode_table_preset);
if (lmt_token_state.luacstrings > 0) {
tex_lua_string_start();
}
@@ -541,14 +558,14 @@ static int texlib_mprint(lua_State *L)
int cs = tex_string_locate(name, lname, 0);
int cmd = eq_type(cs);
if (is_call_cmd(cmd)) {
- texlib_aux_store_token(cs_token_flag + cs, PARTIAL_LINE, default_catcode_table_preset);
+ texlib_aux_store_token(cs_token_flag + cs, partial_line_mode, default_catcode_table_preset);
++ini;
} else {
tex_local_control_message("invalid (mprint) macro");
}
}
if (lua_gettop(L) >= ini) {
- texlib_aux_cprint(L, PARTIAL_LINE, default_catcode_table_preset, ini);
+ texlib_aux_cprint(L, partial_line_mode, default_catcode_table_preset, ini);
}
if (tracing_nesting_par > 2) {
tex_local_control_message("entering local control via mprint");
@@ -565,7 +582,7 @@ static int texlib_pushlocal(lua_State *L)
if (tracing_nesting_par > 2) {
tex_local_control_message("pushing local control");
}
- texlib_aux_store_token(token_val(end_local_cmd, 0), PARTIAL_LINE, default_catcode_table_preset);
+ texlib_aux_store_token(token_val(end_local_cmd, 0), partial_line_mode, default_catcode_table_preset);
if (lmt_token_state.luacstrings > 0) {
tex_lua_string_start();
}
@@ -598,7 +615,7 @@ static int texlib_cprint(lua_State *L)
if (lua_type(L, 2) == LUA_TTABLE) {
for (int i = 1; ; i++) {
lua_rawgeti(L, 2, i);
- if (texlib_aux_store(L, -1, PARTIAL_LINE, cattable)) {
+ if (texlib_aux_store(L, -1, partial_line_mode, cattable, i > 1)) {
lua_pop(L, 1);
} else {
lua_pop(L, 1);
@@ -608,7 +625,7 @@ static int texlib_cprint(lua_State *L)
} else {
int n = lua_gettop(L);
for (int i = 2; i <= n; i++) {
- texlib_aux_store(L, i, PARTIAL_LINE, cattable);
+ texlib_aux_store(L, i, partial_line_mode, cattable, i > 2);
}
}
return 0;
@@ -639,7 +656,7 @@ static int texlib_tprint(lua_State *L)
for (int j = startstrings; ; j++) {
lua_pushinteger(L, j);
lua_gettable(L, -2);
- if (texlib_aux_store(L, -1, PARTIAL_LINE, cattable)) {
+ if (texlib_aux_store(L, -1, partial_line_mode, cattable, j > startstrings)) {
lua_pop(L, 1);
} else {
lua_pop(L, 1);
@@ -659,22 +676,20 @@ static int texlib_isprintable(lua_State* L)
okay = 1;
break;
case LUA_TUSERDATA :
- {
- if (lua_getmetatable(L, 1)) {
- lua_get_metatablelua(token_instance);
- if (lua_rawequal(L, -1, -2)) {
+ if (lua_getmetatable(L, 1)) {
+ lua_get_metatablelua(token_instance);
+ if (lua_rawequal(L, -1, -2)) {
+ okay = 1;
+ // lua_pop(L, 2);
+ } else {
+ lua_get_metatablelua(node_instance);
+ if (lua_rawequal(L, -1, -3)) {
okay = 1;
- // lua_pop(L, 2);
- } else {
- lua_get_metatablelua(node_instance);
- if (lua_rawequal(L, -1, -3)) {
- okay = 1;
- }
- // lua_pop(L, 3);
}
+ // lua_pop(L, 3);
}
- break;
}
+ break;
}
lua_pushboolean(L, okay);
return 1;
@@ -682,85 +697,86 @@ static int texlib_isprintable(lua_State* L)
/*tex We actually don't need to copy and could read from the string. */
-int lmt_cstring_input(halfword *n, int *cattable, int *partial, int *finalline)
+int lmt_cstring_input(halfword *result, int *cattable, int *partial, int *finalline)
{
- spindle_rope *t = read_spindle.head;
- int ret = eof_tex_input ;
+ spindle_rope *rope = read_spindle.head;
+ int type = eof_tex_input ;
if (! read_spindle.complete) {
read_spindle.complete = 1;
read_spindle.tail = NULL;
}
- if (t) {
- switch (t->kind) {
+ if (rope) {
+ switch (rope->kind) {
case string_lua_input:
{
- if (t->data.t) {
+ if (rope->data.t) {
/*tex put that thing in the buffer */
- int strsize = (int) t->tsize;
+ int strsize = (int) rope->tsize;
int newlast = lmt_fileio_state.io_first + strsize;
lmt_fileio_state.io_last = lmt_fileio_state.io_first;
if (tex_room_in_buffer(newlast)) {
- memcpy(&lmt_fileio_state.io_buffer[lmt_fileio_state.io_last], &t->data.t[0], sizeof(unsigned char) * strsize);
+ memcpy(&lmt_fileio_state.io_buffer[lmt_fileio_state.io_last], &rope->data.t[0], sizeof(unsigned char) * strsize);
lmt_fileio_state.io_last = newlast;
- lmt_memory_free(t->data.t);
- t->data.t = NULL;
+ lmt_memory_free(rope->data.t);
+ rope->data.t = NULL;
} else {
- return ret;
+ return type;
}
}
- *cattable = t->cattable;
- *partial = t->partial;
- *finalline = (t->next == NULL);
- ret = string_tex_input;
+ *cattable = rope->cattable;
+ *partial = rope->partial;
+ *finalline = (rope->next == NULL);
+ type = string_tex_input;
break;
}
case packed_lua_input:
{
- unsigned strsize = t->tsize;
+ unsigned strsize = rope->tsize;
int newlast = lmt_fileio_state.io_first + strsize;
lmt_fileio_state.io_last = lmt_fileio_state.io_first;
- if (tex_room_in_buffer(newlast)) {
- for (unsigned i = 0; i < strsize; i++) {
- /* when we end up here we often don't have that many bytes */
- lmt_fileio_state.io_buffer[lmt_fileio_state.io_last + i] = t->data.c[i];
- }
+ if (tex_room_in_buffer(newlast)) {
+ memcpy(&lmt_fileio_state.io_buffer[lmt_fileio_state.io_last], &rope->data.c[0], sizeof(unsigned char) * strsize);
+ // for (unsigned i = 0; i < strsize; i++) {
+ // /* when we end up here we often don't have that many bytes */
+ // lmt_fileio_state.io_buffer[lmt_fileio_state.io_last + i] = rope->data.c[i];
+ // }
lmt_fileio_state.io_last = newlast;
- *cattable = t->cattable;
- *partial = t->partial;
- *finalline = (t->next == NULL);
- ret = string_tex_input;
+ *cattable = rope->cattable;
+ *partial = rope->partial;
+ *finalline = (rope->next == NULL);
+ type = string_tex_input;
} else {
- return ret;
+ return type;
}
break;
}
case token_lua_input:
{
- *n = t->data.h;
- ret = token_tex_input;
+ *result = rope->data.h;
+ type = token_tex_input;
break;
}
case token_list_lua_input:
{
- *n = t->data.h;
- ret = token_list_tex_input;
+ *result = rope->data.h;
+ type = token_list_tex_input;
break;
}
case node_lua_input:
{
- *n = t->data.h;
- ret = node_tex_input;
+ *result = rope->data.h;
+ type = node_tex_input;
break;
}
}
texlib_aux_dispose_rope(read_spindle.tail);
- read_spindle.tail = t;
- read_spindle.head = t->next;
+ read_spindle.tail = rope;
+ read_spindle.head = rope->next;
} else {
texlib_aux_dispose_rope(read_spindle.tail);
read_spindle.tail = NULL;
}
- return ret;
+ return type;
}
/*tex Open for reading, and make a new one for writing. */
@@ -785,19 +801,19 @@ void lmt_cstring_start(void)
void lmt_cstring_close(void)
{
- spindle_rope *t;
+ spindle_rope *rope;
spindle_rope *next = read_spindle.head;
while (next) {
if (next->kind == string_tex_input && next->data.t) {
lmt_memory_free(next->data.t);
next->data.t = NULL;
}
- t = next;
+ rope = next;
next = next->next;
- if (t == read_spindle.tail) {
+ if (rope == read_spindle.tail) {
read_spindle.tail = NULL;
}
- texlib_aux_dispose_rope(t);
+ texlib_aux_dispose_rope(rope);
}
read_spindle.head = NULL;
texlib_aux_dispose_rope(read_spindle.tail);
@@ -816,12 +832,12 @@ static const char *texlib_aux_scan_integer_part(lua_State *L, const char *ss, in
int negative = 0; /*tex should the answer be negated? */
int vacuous = 1; /*tex have no digits appeared? */
int overflow = 0;
- int c = 0; /*tex the current character */
- const char *s = ss; /*tex where we stopped in the string |ss| */
+ int chr = 0; /*tex the current character */
+ const char *str = ss; /*tex where we stopped in the string |ss| */
long long result = 0; /*tex return value */
while (1) {
- c = *s++;
- switch (c) {
+ chr = *str++;
+ switch (chr) {
case ' ':
case '+':
break;
@@ -830,71 +846,71 @@ static const char *texlib_aux_scan_integer_part(lua_State *L, const char *ss, in
break;
case '\'':
{
- int d;
+ int digit;
*radix_ret = 8;
- c = *s++;
- while (c) {
- if ((c >= '0') && (c <= '0' + 7)) {
- d = c - '0';
+ chr = *str++;
+ while (chr) {
+ if ((chr >= '0') && (chr <= '0' + 7)) {
+ digit = chr - '0';
} else {
break;
}
if (! overflow) {
vacuous = 0;
- result = result * 8 + d;
+ result = result * 8 + digit;
if (result > max_integer) {
overflow = 1;
}
}
- c = *s++;
+ chr = *str++;
}
goto DONE;
}
case '"':
{
- int d;
+ int digit;
*radix_ret = 16;
- c = *s++;
- while (c) {
- if ((c >= '0') && (c <= '0' + 9)) {
- d = c - '0';
- } else if ((c <= 'A' + 5) && (c >= 'A')) {
- d = c - 'A' + 10;
- } else if ((c <= 'a' + 5) && (c >= 'a')) {
+ chr = *str++;
+ while (chr) {
+ if ((chr >= '0') && (chr <= '0' + 9)) {
+ digit = chr - '0';
+ } else if ((chr <= 'A' + 5) && (chr >= 'A')) {
+ digit = chr - 'A' + 10;
+ } else if ((chr <= 'a' + 5) && (chr >= 'a')) {
/*tex Actually \TEX\ only handles uppercase. */
- d = c - 'a' + 10;
+ digit = chr - 'a' + 10;
} else {
goto DONE;
}
if (! overflow) {
vacuous = 0;
- result = result * 16 + d;
+ result = result * 16 + digit;
if (result > max_integer) {
overflow = 1;
}
}
- c = *s++;
+ chr = *str++;
}
goto DONE;
}
default:
{
- int d;
+ int digit;
*radix_ret = 10;
- while (c) {
- if ((c >= '0') && (c <= '0' + 9)) {
- d = c - '0';
+ while (chr) {
+ if ((chr >= '0') && (chr <= '0' + 9)) {
+ digit = chr - '0';
} else {
goto DONE;
}
if (! overflow) {
vacuous = 0;
- result = result * 10 + d;
+ result = result * 10 + digit;
if (result > max_integer) {
overflow = 1;
}
}
- c = *s++;
+ chr = *str++;
}
goto DONE;
}
@@ -911,10 +927,10 @@ static const char *texlib_aux_scan_integer_part(lua_State *L, const char *ss, in
result = -result;
}
*ret = (int) result;
- if (c != ' ' && s > ss) {
- s--;
+ if (chr != ' ' && str > ss) {
+ str--;
}
- return s;
+ return str;
}
/*tex
@@ -925,23 +941,23 @@ static const char *texlib_aux_scan_integer_part(lua_State *L, const char *ss, in
static const char *texlib_aux_scan_dimen_part(lua_State * L, const char *ss, int *ret)
{
- int negative = 0; /*tex should the answer be negated? */
- int fraction = 0; /*tex numerator of a fraction whose denominator is $2^{16}$ */
+ int negative = 0; /*tex should the answer be negated? */
+ int fraction = 0; /*tex numerator of a fraction whose denominator is $2^{16}$ */
int numerator;
int denominator;
- scaled special; /*tex an internal dimension */
+ scaled special; /*tex an internal dimension */
int result = 0;
- int radix = 0; /*tex the current radix */
- int remainder = 0; /*tex the to be remainder */
- int saved_error = lmt_scanner_state.arithmic_error; /*tex to save |arith_error| */
- const char *s = NULL;
+ int radix = 0;
+ int remainder = 0;
+ int saved_error = lmt_scanner_state.arithmic_error;
+ const char *str = NULL;
if (ss && (*ss == '.' || *ss == ',')) {
- s = ss;
+ str = ss;
goto FRACTION;
} else {
- s = texlib_aux_scan_integer_part(L, ss, &result, &radix);
+ str = texlib_aux_scan_integer_part(L, ss, &result, &radix);
}
- if (! (char) *s) {
+ if (! (char) *str) {
/* error, no unit, assume scaled points */
goto ATTACH_FRACTION;
}
@@ -950,91 +966,91 @@ static const char *texlib_aux_scan_dimen_part(lua_State * L, const char *ss, int
result = -result;
}
FRACTION:
- if ((radix == 0 || radix == 10) && (*s == '.' || *s == ',')) {
+ if ((radix == 0 || radix == 10) && (*str == '.' || *str == ',')) {
unsigned k = 0;
unsigned char digits[18];
- s++;
+ str++;
while (1) {
- int c = *s++;
- if ((c > '0' + 9) || (c < '0')) {
+ unsigned char chr = *str++;
+ if ((chr > '0' + 9) || (chr < '0')) {
break;
} else if (k < 17) {
- digits[k++] = (unsigned char) c - '0';
+ digits[k++] = (unsigned char) chr - '0';
}
}
fraction = tex_round_decimals_digits(digits, k);
- if (*s != ' ') {
- --s;
+ if (*str != ' ') {
+ --str;
}
}
/* the unit can have spaces in front */
/*UNIT: */
- while ((char) *s == ' ') {
- s++;
+ while ((char) *str == ' ') {
+ str++;
}
/* We dropped the |nd| and |nc| units as well as the |true| prefix. */
- if (! (char) *s) {
+ if (! (char) *str) {
goto ATTACH_FRACTION;
- } else if (strncmp(s, "pt", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "pt", 2) == 0) {
+ str += 2;
goto ATTACH_FRACTION;
- } else if (strncmp(s, "mm", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "mm", 2) == 0) {
+ str += 2;
numerator = 7227;
denominator = 2540;
goto CONVERSION;
- } else if (strncmp(s, "cm", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "cm", 2) == 0) {
+ str += 2;
numerator = 7227;
denominator = 254;
goto CONVERSION;
- } else if (strncmp(s, "sp", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "sp", 2) == 0) {
+ str += 2;
goto DONE;
- } else if (strncmp(s, "bp", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "bp", 2) == 0) {
+ str += 2;
numerator = 7227;
denominator = 7200;
goto CONVERSION;
- } else if (strncmp(s, "in", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "in", 2) == 0) {
+ str += 2;
numerator = 7227;
denominator = 100;
goto CONVERSION;
- } else if (strncmp(s, "dd", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "dd", 2) == 0) {
+ str += 2;
numerator = 1238;
denominator = 1157;
goto CONVERSION;
- } else if (strncmp(s, "cc", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "cc", 2) == 0) {
+ str += 2;
numerator = 14856;
denominator = 1157;
goto CONVERSION;
- } else if (strncmp(s, "pc", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "pc", 2) == 0) {
+ str += 2;
numerator = 12;
denominator = 1;
goto CONVERSION;
- } else if (strncmp(s, "dk", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "dk", 2) == 0) {
+ str += 2;
numerator = 49838;
denominator = 7739;
goto CONVERSION;
- } else if (strncmp(s, "em", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "em", 2) == 0) {
+ str += 2;
special = tex_get_font_em_width(cur_font_par);
goto SPECIAL;
- } else if (strncmp(s, "ex", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "ex", 2) == 0) {
+ str += 2;
special = tex_get_font_ex_height(cur_font_par);
goto SPECIAL;
- } else if (strncmp(s, "px", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "px", 2) == 0) {
+ str += 2;
special = px_dimen_par;
goto SPECIAL;
- } else if (strncmp(s, "mu", 2) == 0) {
- s += 2;
+ } else if (strncmp(str, "mu", 2) == 0) {
+ str += 2;
goto ATTACH_FRACTION;
/* } else if (strncmp(s, "true", 4) == 0) { */
/* s += 4; */
@@ -1065,10 +1081,10 @@ static const char *texlib_aux_scan_dimen_part(lua_State * L, const char *ss, int
*ret = negative ? - result : result;
lmt_scanner_state.arithmic_error = saved_error;
/* only when we want to report junk */
- while ((char) *s == ' ') {
- s++;
+ while ((char) *str == ' ') {
+ str++;
}
- return s;
+ return str;
}
static int texlib_aux_dimen_to_number(lua_State *L, const char *s)
@@ -1412,10 +1428,16 @@ static int texlib_getdimen(lua_State *L)
lua_pushinteger(L, state >= 0 ? (state == 2 ? eq_value(index) : tex_get_tex_dimen_register(index, state)) : 0);
// halfword value;
// switch (state) {
- // case 0 : value = dimen_parameter(index); break;
- // case 1 : value = dimen_parameter(index); break;
- // case 2 : value = eq_value(index); break;
- // default: value = 0;
+ // case 0 :
+ // case 1 :
+ // value = dimen_parameter(index);
+ // break;
+ // case 2 :
+ // value = eq_value(index);
+ // break;
+ // default:
+ // value = 0;
+ // break;
// }
// lua_pushinteger(L, value);
return 1;
@@ -1786,25 +1808,25 @@ static int texlib_getmark(lua_State *L)
lua_pushinteger(L, lmt_mark_state.mark_data.ptr);
return 1;
} else if (lua_type(L, 1) == LUA_TSTRING) {
- int mrk = -1;
+ int mark = -1;
const char *s = lua_tostring(L, 1);
if (lua_key_eq(s, top)) {
- mrk = top_marks_code;
+ mark = top_marks_code;
} else if (lua_key_eq(s, first)) {
- mrk = first_marks_code;
+ mark = first_marks_code;
} else if (lua_key_eq(s, bottom)) {
- mrk = bot_marks_code;
+ mark = bot_marks_code;
} else if (lua_key_eq(s, splitfirst)) {
- mrk = split_first_marks_code;
+ mark = split_first_marks_code;
} else if (lua_key_eq(s, splitbottom)) {
- mrk = split_bot_marks_code;
+ mark = split_bot_marks_code;
} else if (lua_key_eq(s, current)) {
- mrk = current_marks_code;
+ mark = current_marks_code;
}
- if (mrk >= 0) {
- int num = lmt_optinteger(L, 2, 0);
- if (num >= 0 && num <= lmt_mark_state.mark_data.ptr) {
- halfword ptr = tex_get_some_mark(mrk, num);
+ if (mark >= 0) {
+ int index = lmt_optinteger(L, 2, 0);
+ if (index >= 0 && index <= lmt_mark_state.mark_data.ptr) {
+ halfword ptr = tex_get_some_mark(mark, index);
if (ptr) {
char *str = tex_tokenlist_to_tstring(ptr, 1, NULL, 0, 0, 0, 0);
if (str) {
@@ -1829,9 +1851,9 @@ int lmt_get_box_id(lua_State *L, int i, int report)
switch (lua_type(L, i)) {
case LUA_TSTRING:
{
- size_t k = 0;
- const char *s = lua_tolstring(L, i, &k);
- int cs = tex_string_locate(s, k, 0);
+ size_t len = 0;
+ const char *str = lua_tolstring(L, i, &len);
+ int cs = tex_string_locate(str, len, 0);
int cmd = eq_type(cs);
switch (cmd) {
case char_given_cmd:
@@ -1874,29 +1896,29 @@ static int texlib_splitbox(lua_State *L)
int index = lmt_get_box_id(L, 1, 1);
if (index >= 0) {
if (lua_isnumber(L, 2)) {
- int m = packing_additional;
+ int packing = packing_additional;
switch (lua_type(L, 3)) {
case LUA_TSTRING:
{
- const char *s = lua_tostring(L, 3);
- if (lua_key_eq(s, exactly)) {
- m = packing_exactly;
- } else if (lua_key_eq(s, additional)) {
- m = packing_additional;
+ const char *str = lua_tostring(L, 3);
+ if (lua_key_eq(str, exactly)) {
+ packing = packing_exactly;
+ } else if (lua_key_eq(str, additional)) {
+ packing = packing_additional;
}
break;
}
case LUA_TNUMBER:
{
- m = lmt_tointeger(L, 3);
- if (m != packing_exactly && m != packing_additional) {
- m = packing_exactly;
+ packing = lmt_tointeger(L, 3);
+ if (packing != packing_exactly && packing != packing_additional) {
+ packing = packing_exactly;
luaL_error(L, "wrong mode in splitbox");
}
break;
}
}
- lmt_node_list_to_lua(L, tex_vsplit(index, lmt_toroundnumber(L, 2), m));
+ lmt_node_list_to_lua(L, tex_vsplit(index, lmt_toroundnumber(L, 2), packing));
} else {
/* maybe a warning */
lua_pushnil(L);
@@ -1921,33 +1943,32 @@ static int texlib_setbox(lua_State *L)
int slot = lmt_check_for_flags(L, 1, &flags, 1, 0);
int index = lmt_get_box_id(L, slot++, 1);
if (index >= 0) {
- int n = null;
+ halfword box = null;
switch (lua_type(L, slot)) {
case LUA_TBOOLEAN:
- n = lua_toboolean(L, slot);
- if (n) {
+ if (lua_toboolean(L, slot)) {
return 0;
} else {
- n = null;
+ box = null;
+ break;
}
- break;
case LUA_TNIL:
case LUA_TNONE:
break;
default:
- n = lmt_node_list_from_lua(L, slot);
- if (n) {
- switch (node_type(n)) {
+ box = lmt_node_list_from_lua(L, slot);
+ if (box) {
+ switch (node_type(box)) {
case hlist_node:
case vlist_node:
break;
default:
- return luaL_error(L, "invalid node type %s passed", get_node_name(node_type(n)));
+ return luaL_error(L, "invalid node type %s passed", get_node_name(node_type(box)));
}
}
break;
}
- tex_set_tex_box_register(index, n, flags, 0);
+ tex_set_tex_box_register(index, box, flags, 0);
}
return 0;
}
@@ -3223,7 +3244,7 @@ static void texlib_get_nest_field(lua_State *L, const char *field, list_state_re
/* we no longer check for special list nodes here so beware of next-of-tail */
lmt_push_node_fast(L, r->tail);
} else if (lua_key_eq(field, delimiter)) {
- lmt_push_node_fast(L, r->delim);
+ lmt_push_node_fast(L, r->delimiter);
} else if (lua_key_eq(field, prevgraf)) {
lua_pushinteger(L, r->prev_graf);
} else if (lua_key_eq(field, modeline)) {
@@ -3254,7 +3275,7 @@ static void texlib_set_nest_field(lua_State *L, int n, const char *field, list_s
} else if (lua_key_eq(field, tail)) {
r->tail = lmt_check_isnode(L, n);
} else if (lua_key_eq(field, delimiter)) {
- r->delim = lmt_check_isnode(L, n);
+ r->delimiter = lmt_check_isnode(L, n);
} else if (lua_key_eq(field, prevgraf)) {
r->prev_graf = lmt_tointeger(L, n);
} else if (lua_key_eq(field, modeline)) {
@@ -3442,12 +3463,12 @@ static int texlib_scale(lua_State *L)
static int texlib_definefont(lua_State *L)
{
- size_t l;
+ size_t len;
int slot = 1;
int flags = (lua_isboolean(L, slot) && lua_toboolean(L, slot++)) ? add_global_flag(0) : 0;
- const char *csname = lua_tolstring(L, slot++, &l);
+ const char *csname = lua_tolstring(L, slot++, &len);
halfword id = lmt_tohalfword(L, slot++);
- int cs = tex_string_locate(csname, l, 1);
+ int cs = tex_string_locate(csname, len, 1);
lmt_check_for_flags(L, slot, &flags, 1, 1);
tex_define(flags, cs, set_font_cmd, id);
return 0;
@@ -3610,16 +3631,16 @@ static void texlib_aux_enableprimitive(const char *pre, size_t prel, const char
static int texlib_enableprimitives(lua_State *L)
{
if (lua_gettop(L) == 2) {
- size_t lpre;
- const char *pre = luaL_checklstring(L, 1, &lpre);
+ size_t prelen;
+ const char *prefix = luaL_checklstring(L, 1, &prelen);
switch (lua_type(L, 2)) {
case LUA_TTABLE:
{
int i = 1;
while (1) {
if (lua_rawgeti(L, 2, i) == LUA_TSTRING) {
- const char *prm = lua_tostring(L, 3);
- texlib_aux_enableprimitive(pre, lpre, prm);
+ const char *primitive = lua_tostring(L, 3);
+ texlib_aux_enableprimitive(prefix, prelen, primitive);
} else {
lua_pop(L, 1);
break;
@@ -3634,8 +3655,8 @@ static int texlib_enableprimitives(lua_State *L)
for (int cs = 0; cs < prim_size; cs++) {
strnumber s = get_prim_text(cs);
if (s > 0) {
- const char *prm = tex_to_cstring(s);
- texlib_aux_enableprimitive(pre, lpre, prm);
+ const char *primitive = tex_to_cstring(s);
+ texlib_aux_enableprimitive(prefix, prelen, primitive);
}
}
}
@@ -4087,7 +4108,7 @@ static int texlib_getinputstateline(lua_State *L)
static int texlib_forcehmode(lua_State *L)
{
- if (abs(cur_list.mode) == vmode) {
+ if (is_v_mode(cur_list.mode)) {
if (lua_type(L, 1) == LUA_TBOOLEAN) {
tex_begin_paragraph(lua_toboolean(L, 1), force_par_begin);
} else {
@@ -4110,20 +4131,20 @@ static int texlib_runlocal(lua_State *L)
{
// int obeymode = lua_toboolean(L, 4);
int obeymode = 1; /* always 1 */
- halfword tok = -1;
- int mac = 0 ;
+ halfword token = -1;
+ int ismacro = 0 ;
switch (lua_type(L, 1)) {
case LUA_TFUNCTION:
{
/* todo: also a variant that calls an already registered function */
- int ref;
- halfword r, t;
+ int reference;
+ halfword c, e;
lua_pushvalue(L, 1);
- ref = luaL_ref(L, LUA_REGISTRYINDEX);
- r = tex_get_available_token(token_val(end_local_cmd, 0));
- t = tex_get_available_token(token_val(lua_local_call_cmd, ref));
- token_link(t) = r;
- tex_begin_inserted_list(t);
+ reference = luaL_ref(L, LUA_REGISTRYINDEX);
+ c = tex_get_available_token(token_val(lua_local_call_cmd, reference));
+ e = tex_get_available_token(token_val(end_local_cmd, 0));
+ token_link(c) = e;
+ tex_begin_inserted_list(c);
if (lmt_token_state.luacstrings > 0) {
tex_lua_string_start();
}
@@ -4131,15 +4152,15 @@ static int texlib_runlocal(lua_State *L)
tex_local_control_message("entering token scanner via function");
}
tex_local_control(obeymode);
- luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ luaL_unref(L, LUA_REGISTRYINDEX, reference);
return 0;
}
case LUA_TNUMBER:
{
halfword k = lmt_checkhalfword(L, 1);
if (k >= 0 && k <= 65535) {
- tok = toks_register(k);
- goto TOK;
+ token = toks_register(k);
+ goto WRAPUP;
} else {
tex_local_control_message("invalid token register number");
return 0;
@@ -4155,8 +4176,8 @@ static int texlib_runlocal(lua_State *L)
// todo: use the better register helpers and range checkers
switch (cmd) {
case register_toks_cmd:
- tok = toks_register(register_toks_number(eq_value(cs)));
- goto TOK;
+ token = toks_register(register_toks_number(eq_value(cs)));
+ goto WRAPUP;
case undefined_cs_cmd:
tex_local_control_message("undefined macro or token register");
return 0;
@@ -4172,22 +4193,22 @@ static int texlib_runlocal(lua_State *L)
tex_local_control_message("macro takes arguments and is ignored");
return 0;
} else {
- tok = cs_token_flag + cs;
- mac = 1 ;
- goto TOK;
+ token = cs_token_flag + cs;
+ ismacro = 1 ;
+ goto WRAPUP;
}
}
}
case LUA_TUSERDATA:
/* no checking yet */
- tok = token_info(lmt_token_code_from_lua(L, 1));
- mac = 1;
- goto TOK;
+ token = token_info(lmt_token_code_from_lua(L, 1));
+ ismacro = 1;
+ goto WRAPUP;
default:
return 0;
}
- TOK:
- if (tok < 0) {
+ WRAPUP:
+ if (token < 0) {
/* nothing to do */
} else if (lmt_input_state.scanner_status != scanner_is_defining || lua_toboolean(L, 2)) {
// todo: make list
@@ -4196,10 +4217,10 @@ static int texlib_runlocal(lua_State *L)
tex_begin_inserted_list(tex_get_available_token(token_val(right_brace_cmd, 0)));
}
tex_begin_inserted_list(tex_get_available_token(token_val(end_local_cmd, 0)));
- if (mac) {
- tex_begin_inserted_list(tex_get_available_token(tok));
+ if (ismacro) {
+ tex_begin_inserted_list(tex_get_available_token(token));
} else {
- tex_begin_token_list(tok, local_text);
+ tex_begin_token_list(token, local_text);
}
if (grouped) {
tex_begin_inserted_list(tex_get_available_token(token_val(left_brace_cmd, 0)));
@@ -4209,19 +4230,19 @@ static int texlib_runlocal(lua_State *L)
tex_lua_string_start();
}
if (tracing_nesting_par > 2) {
- if (mac) {
+ if (ismacro) {
tex_local_control_message("entering token scanner via macro");
} else {
tex_local_control_message("entering token scanner via register");
}
}
tex_local_control(obeymode);
- } else if (mac) {
- tex_back_input(tok);
+ } else if (ismacro) {
+ tex_back_input(token);
} else {
halfword h = null;
halfword t = null;
- halfword r = token_link(tok);
+ halfword r = token_link(token);
while (r) {
t = tex_store_new_token(t, token_info(r));
if (! h) {
@@ -4529,26 +4550,26 @@ static int texlib_fatalerror(lua_State *L)
static int texlib_lastnodetype(lua_State *L)
{
halfword tail = cur_list.tail;
- int t = -1;
- int s = -1;
+ int type = -1;
+ int subtype = -1;
if (tail) {
halfword mode = cur_list.mode;
if (mode != nomode && tail != contribute_head && node_type(tail) != glyph_node) {
- t = node_type(tail);
- s = node_subtype(tail);
+ type = node_type(tail);
+ subtype = node_subtype(tail);
} else if (mode == vmode && tail == cur_list.head) {
- t = lmt_page_builder_state.last_node_type;
- s = lmt_page_builder_state.last_node_subtype;
+ type = lmt_page_builder_state.last_node_type;
+ subtype = lmt_page_builder_state.last_node_subtype;
} else if (mode == nomode || tail == cur_list.head) {
/* already -1 */
} else {
- t = node_type(tail);
- s = node_subtype(tail);
+ type = node_type(tail);
+ subtype = node_subtype(tail);
}
}
- if (t >= 0) {
- lua_pushinteger(L, t);
- lua_pushinteger(L, s);
+ if (type >= 0) {
+ lua_pushinteger(L, type);
+ lua_pushinteger(L, subtype);
} else {
lua_pushnil(L);
lua_pushnil(L);
@@ -4560,10 +4581,10 @@ static int texlib_lastnodetype(lua_State *L)
static int texlib_chardef(lua_State *L)
{
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (s) {
- int cs = tex_string_locate(s, l, 1);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 1);
int flags = 0;
lmt_check_for_flags(L, 3, &flags, 1, 0);
if (tex_define_permitted(cs, flags)) {
@@ -4582,23 +4603,23 @@ static int texlib_chardef(lua_State *L)
static int texlib_mathchardef(lua_State *L)
{
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (s) {
- int cs = tex_string_locate(s, l, 1);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 1);
int flags = 0;
lmt_check_for_flags(L, 5, &flags, 1, 0);
if (tex_define_permitted(cs, flags)) {
- mathcodeval m;
- mathdictval d;
- m.class_value = (short) lmt_tointeger(L, 2);
- m.family_value = (short) lmt_tointeger(L, 3);
- m.character_value = lmt_tointeger(L, 4);
- d.properties = lmt_optquarterword(L, 6, 0);
- d.group = lmt_optquarterword(L, 7, 0);
- d.index = lmt_optinteger(L, 8, 0);
- if (class_in_range(m.class_value) && family_in_range(m.family_value) && character_in_range(m.character_value)) {
- tex_define(flags, cs, mathspec_cmd, tex_new_math_dict_spec(d, m, umath_mathcode));
+ mathcodeval mval;
+ mathdictval dval;
+ mval.class_value = (short) lmt_tointeger(L, 2);
+ mval.family_value = (short) lmt_tointeger(L, 3);
+ mval.character_value = lmt_tointeger(L, 4);
+ dval.properties = lmt_optquarterword(L, 6, 0);
+ dval.group = lmt_optquarterword(L, 7, 0);
+ dval.index = lmt_optinteger(L, 8, 0);
+ if (class_in_range(mval.class_value) && family_in_range(mval.family_value) && character_in_range(mval.character_value)) {
+ tex_define(flags, cs, mathspec_cmd, tex_new_math_dict_spec(dval, mval, umath_mathcode));
} else {
tex_normal_error("lua", "mathchardef needs proper class, family and character codes");
}
@@ -4611,10 +4632,10 @@ static int texlib_mathchardef(lua_State *L)
static int texlib_setintegervalue(lua_State *L)
{
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (s) {
- int cs = tex_string_locate(s, l, 1);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 1);
int flags = 0;
lmt_check_for_flags(L, 3, &flags, 1, 0);
if (tex_define_permitted(cs, flags)) {
@@ -4631,10 +4652,10 @@ static int texlib_setintegervalue(lua_State *L)
static int texlib_setdimensionvalue(lua_State *L)
{
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (s) {
- int cs = tex_string_locate(s, l, 1);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 1);
int flags = 0;
lmt_check_for_flags(L, 3, &flags, 1, 0);
if (tex_define_permitted(cs, flags)) {
@@ -4672,10 +4693,10 @@ static int texlib_aux_getvalue(lua_State *L, halfword level, halfword cs)
static int texlib_getintegervalue(lua_State *L) /* todo, now has duplicate in tokenlib */
{
if (lua_type(L, 1) == LUA_TSTRING) {
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (l > 0) {
- int cs = tex_string_locate(s, l, 0);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 0);
switch (eq_type(cs)) {
case integer_cmd:
lua_pushinteger(L, eq_value(cs));
@@ -4697,10 +4718,10 @@ static int texlib_getintegervalue(lua_State *L) /* todo, now has duplicate in to
static int texlib_getdimensionvalue(lua_State *L) /* todo, now has duplicate in tokenlib */
{
if (lua_type(L, 1) == LUA_TSTRING) {
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- if (l > 0) {
- int cs = tex_string_locate(s, l, 0);
+ size_t len;
+ const char *str = lua_tolstring(L, 1, &len);
+ if (len > 0) {
+ int cs = tex_string_locate(str, len, 0);
switch (eq_type(cs)) {
case dimension_cmd:
lua_pushinteger(L, eq_value(cs));
@@ -4743,7 +4764,7 @@ static int texlib_getmodevalues(lua_State *L)
static int texlib_getmode(lua_State *L)
{
- lua_pushinteger(L, abs(cur_list.mode));
+ lua_pushinteger(L, tex_normalized_mode(cur_list.mode));
return 1;
}
diff --git a/source/luametatex/source/lua/lmttexlib.h b/source/luametatex/source/lua/lmttexlib.h
index b0033535a..adce385f0 100644
--- a/source/luametatex/source/lua/lmttexlib.h
+++ b/source/luametatex/source/lua/lmttexlib.h
@@ -7,7 +7,7 @@
extern void lmt_cstring_start (void);
extern void lmt_cstring_close (void);
-extern int lmt_cstring_input (halfword *n, int *cattable, int *partial, int *finalline);
+extern int lmt_cstring_input (halfword *result, int *cattable, int *partial, int *finalline);
extern void lmt_cstring_print (int cattable, const char *s, int ispartial);
extern void lmt_tstring_store (strnumber s, int cattable);
diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c
index c591bd7f6..dcd17b53e 100644
--- a/source/luametatex/source/lua/lmttokenlib.c
+++ b/source/luametatex/source/lua/lmttokenlib.c
@@ -856,7 +856,7 @@ static int tokenlib_scan_csname(lua_State *L)
int t;
saved_tex_scanner texstate = tokenlib_aux_save_tex_scanner();
if (lua_toboolean(L, 1)) {
- /*tex unchecked (maybe backport this option to luatex) */
+ /*tex Not here: |tex_get_next_non_spacer()| unless we adapt more later on. */
do {
tex_get_token();
} while (cur_tok == space_token);
@@ -864,7 +864,7 @@ static int tokenlib_scan_csname(lua_State *L)
/*tex checked */
tex_get_next();
}
- t = cur_cs ? cs_token_flag + cur_cs : token_val (cur_cmd, cur_chr);
+ t = cur_cs ? cs_token_flag + cur_cs : token_val(cur_cmd, cur_chr);
if (t >= cs_token_flag) {
int allocated = 0;
unsigned char *s = tokenlib_aux_get_cs_text(t - cs_token_flag, &allocated);
@@ -1853,10 +1853,27 @@ static int tokenlib_scan_char(lua_State *L)
return 1;
}
+static const char *token_cmd_to_string[15] = {
+ "\\", /* 0 escape_cmd */
+ "{", /* 1 left_brace_cmd */
+ "}", /* 2 right_brace_cmd */
+ "$", /* 3 math_shift_cmd */
+ "&", /* 4 alignment_tab_cmd */
+ "\n", /* 5 end_line_cmd */
+ "#", /* 6 parameter_cmd */
+ "^", /* 7 superscript_cmd */
+ "_", /* 8 subscript_cmd */
+ "", /* 9 ignore_cmd */
+ " ", /* 10 spacer_cmd */
+ "", /* 11 letter_cmd */
+ "", /* 12 other_char_cmd */
+ "", /* 13 active_char_cmd */
+ "%" /* 14 comment_cmd */
+};
+
static int tokenlib_scan_next_char(lua_State *L)
{
saved_tex_scanner texstate = tokenlib_aux_save_tex_scanner();
- const char mapping[14][2] = { "\\", "{", "}", "$", "&", "\n", "#", "^", "_", " ", "", "", "", "%" };
tex_get_token();
switch (cur_cmd) {
case escape_cmd:
@@ -1871,7 +1888,7 @@ static int tokenlib_scan_next_char(lua_State *L)
case ignore_cmd:
case spacer_cmd:
case comment_cmd:
- lua_pushstring(L, mapping[cur_cmd]);
+ lua_pushstring(L, token_cmd_to_string[cur_cmd]);
break;
case letter_cmd:
case other_char_cmd:
diff --git a/source/luametatex/source/luametatex.h b/source/luametatex/source/luametatex.h
index d0e6ad7e4..ccabddaf4 100644
--- a/source/luametatex/source/luametatex.h
+++ b/source/luametatex/source/luametatex.h
@@ -89,7 +89,7 @@
# define luametatex_version 210
# define luametatex_revision 05
# define luametatex_version_string "2.10.05"
-# define luametatex_development_id 20221228
+# define luametatex_development_id 20230101
# define luametatex_name_camelcase "LuaMetaTeX"
# define luametatex_name_lowercase "luametatex"
diff --git a/source/luametatex/source/luarest/lmtmd5lib.c b/source/luametatex/source/luarest/lmtmd5lib.c
index 2355b53ce..49730471a 100644
--- a/source/luametatex/source/luarest/lmtmd5lib.c
+++ b/source/luametatex/source/luarest/lmtmd5lib.c
@@ -64,7 +64,7 @@ static int md5lib_HEX(lua_State *L)
size_t size = 0; \
const char *data = lua_tolstring(L, 1, &size); \
md5_digest(data, size, (unsigned char *) result, CONVERSION); \
- lua_pushlstring(L, (const char *)result, RESULT_LENGTH); \
+ lua_pushlstring(L, (const char *) result, RESULT_LENGTH); \
return 1; \
} \
return 0; \
diff --git a/source/luametatex/source/luarest/lmtoslibext.c b/source/luametatex/source/luarest/lmtoslibext.c
index 74cbfad9e..0dc5fb940 100644
--- a/source/luametatex/source/luarest/lmtoslibext.c
+++ b/source/luametatex/source/luarest/lmtoslibext.c
@@ -113,15 +113,17 @@ static int oslib_sleep(lua_State *L)
DWORD sLength;
memset(uts, 0, sizeof(*uts));
osver.dwOSVersionInfoSize = sizeof(osver);
- GetVersionEx(&osver);
GetSystemInfo(&sysinfo);
strcpy(uts->sysname, "Windows");
+ /* When |GetVersionEx| becomes obsolete the version and release fields will be set to "". */
+ GetVersionEx(&osver);
sprintf(uts->version, "%ld.%02ld", osver.dwMajorVersion, osver.dwMinorVersion);
if (osver.szCSDVersion[0] != '\0' && (strlen(osver.szCSDVersion) + strlen(uts->version) + 1) < sizeof(uts->version)) {
strcat(uts->version, " ");
strcat(uts->version, osver.szCSDVersion);
}
sprintf(uts->release, "build %ld", osver.dwBuildNumber & 0xFFFF);
+ /* So far for the fragile and actually not that relevant part of |uts|. */
switch (sysinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
strcpy(uts->machine, "x86_64");
@@ -281,14 +283,14 @@ static int oslib_execute(lua_State *L)
static int oslib_getenv(lua_State *L)
{
const char *key = luaL_checkstring(L, 1);
- char* val = NULL;
+ char *val = NULL;
if (key) {
size_t wlen = 0;
LPWSTR wkey = aux_utf8_to_wide(key);
_wgetenv_s(&wlen, NULL, 0, wkey);
if (wlen) {
LPWSTR wval = (LPWSTR) lmt_memory_malloc(wlen * sizeof(WCHAR));
- if (!_wgetenv_s(&wlen, wval, wlen, wkey)) {
+ if (! _wgetenv_s(&wlen, wval, wlen, wkey)) {
val = aux_utf8_from_wide(wval);
}
}
@@ -305,20 +307,15 @@ static int oslib_execute(lua_State *L)
{
const char *key = luaL_optstring(L, 1, NULL);
if (key) {
- LPWSTR wkey = aux_utf8_to_wide(key);
const char *val = luaL_optstring(L, 2, NULL);
- if (val) {
- LPWSTR wval = aux_utf8_to_wide(val);
- if (_wputenv_s(wkey, wval)) {
- return luaL_error(L, "unable to change environment");
- }
- lmt_memory_free(wval);
- } else {
- if (_wputenv_s(wkey, NULL)) {
- return luaL_error(L, "unable to change environment");
- }
- }
+ LPWSTR wkey = aux_utf8_to_wide(key);
+ LPWSTR wval = aux_utf8_to_wide(val ? val : "");
+ int bad = _wputenv_s(wkey, wval);
+ lmt_memory_free(wval);
lmt_memory_free(wkey);
+ if (bad) {
+ return luaL_error(L, "unable to change environment");
+ }
}
lua_pushboolean(L, 1);
return 1;
diff --git a/source/luametatex/source/luarest/lmtstrlibext.c b/source/luametatex/source/luarest/lmtstrlibext.c
index 5478c4b67..ffc687ff4 100644
--- a/source/luametatex/source/luarest/lmtstrlibext.c
+++ b/source/luametatex/source/luarest/lmtstrlibext.c
@@ -564,7 +564,7 @@ static int strlib_format_tounicode16(lua_State *L)
u = u - 0x10000; /* negative when invalid range */
u1 = (unsigned) (u >> 10) + 0xD800;
u2 = (unsigned) (u % 0x400) + 0xDC00;
- s[3] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x000F) >> 0));
+ s[3] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x000F) >> 0));
s[2] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x00F0) >> 4));
s[1] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x0F00) >> 8));
s[0] = strlib_aux_hexdigit((unsigned char) ((u1 & 0xF000) >> 12));
diff --git a/source/luametatex/source/mp/mpc/mp.c b/source/luametatex/source/mp/mpc/mp.c
index 032d8f34a..d171e07a6 100644
--- a/source/luametatex/source/mp/mpc/mp.c
+++ b/source/luametatex/source/mp/mpc/mp.c
@@ -15,10 +15,6 @@
# define loc mp->cur_input.loc_field
# define inf_t mp->math->md_inf_t
# define negative_inf_t mp->math->md_negative_inf_t
-# define check_arith() \
- if (mp->arith_error) { \
- mp_clear_arith(mp); \
- }
# define arc_tol_k mp->math->md_arc_tol_k
# define coef_bound_k mp->math->md_coef_bound_k
# define coef_bound_minus_1 mp->math->md_coef_bound_minus_1
@@ -434,14 +430,14 @@
# define gr_type(A) (A)->type
# define gr_link(A) (A)->next
# define gr_color_model(A) (A)->color_model
-# define gr_red_val(A) (A)->color.a_val
-# define gr_green_val(A) (A)->color.b_val
-# define gr_blue_val(A) (A)->color.c_val
-# define gr_cyan_val(A) (A)->color.a_val
-# define gr_magenta_val(A) (A)->color.b_val
-# define gr_yellow_val(A) (A)->color.c_val
-# define gr_black_val(A) (A)->color.d_val
-# define gr_grey_val(A) (A)->color.d_val
+# define gr_red_val(A) (A)->color.red
+# define gr_green_val(A) (A)->color.green
+# define gr_blue_val(A) (A)->color.blue
+# define gr_cyan_val(A) (A)->color.cyan
+# define gr_magenta_val(A) (A)->color.magenta
+# define gr_yellow_val(A) (A)->color.yellow
+# define gr_black_val(A) (A)->color.black
+# define gr_grey_val(A) (A)->color.gray
# define gr_path_ptr(A) (A)->path
# define gr_htap_ptr(A) (A)->htap
# define gr_pen_ptr(A) (A)->pen
@@ -1520,15 +1516,18 @@ void mp_normalize_selector (MP mp)
mp->selector = mp->interaction == mp_batch_mode ? mp_log_only_selector : mp_term_and_log_selector;
}
-static void mp_clear_arith (MP mp) {
- mp_error(
- mp,
- "Arithmetic overflow",
- "Uh, oh. A little while ago one of the quantities that I was computing got too\n"
- "large, so I'm afraid your answers will be somewhat askew. You'll probably have to\n"
- "adopt different tactics next time. But I shall try to carry on anyway."
- );
- mp->arith_error = 0;
+static void check_arith (MP mp)
+{
+ if (mp->arith_error) {
+ mp_error(
+ mp,
+ "Arithmetic overflow",
+ "Uh, oh. A little while ago one of the quantities that I was computing got too\n"
+ "large, so I'm afraid your answers will be somewhat askew. You'll probably have to\n"
+ "adopt different tactics next time. But I shall try to carry on anyway."
+ );
+ mp->arith_error = 0;
+ }
}
static void mp_print_two (MP mp, mp_number *x, mp_number *y)
@@ -2696,6 +2695,7 @@ void mp_print_variable_name (MP mp, mp_node p)
goto FOUND;
} else if (p->name_type != mp_attribute_operation) {
mp_confusion(mp, "variable");
+ return;
} else {
r = mp_new_symbolic_node(mp);
mp_set_sym_sym(r, mp_get_hashloc(p));
@@ -3563,7 +3563,7 @@ void mp_make_choices (MP mp, mp_knot knots)
int k, n;
mp_knot s, t;
- check_arith();
+ check_arith(mp);
if (number_positive(internal_value(mp_tracing_choices_internal))) {
mp_print_path(mp, knots, ", before choices", 1);
}
@@ -5293,7 +5293,7 @@ static void mp_get_arc_length (MP mp, mp_number *ret, mp_knot h)
free_number(arg4);
free_number(arg5);
free_number(arg6);
- check_arith();
+ check_arith(mp);
number_clone(*ret, a_tot);
free_number(a_tot);
}
@@ -5345,7 +5345,7 @@ static void mp_get_subarc_length (MP mp, mp_number *ret, mp_knot h, mp_number *f
free_number(arg4);
free_number(arg5);
free_number(arg6);
- check_arith();
+ check_arith(mp);
number_clone(*ret, a_tot);
free_number(a_cnt);
free_number(a_tot);
@@ -5366,7 +5366,7 @@ static mp_knot mp_get_arc_time(MP mp, mp_number *ret, mp_knot h, mp_number *arc0
mp_toss_knot_list(mp, p);
free_number(neg_arc0);
}
- check_arith();
+ check_arith(mp);
} else {
mp_knot p, q, k;
mp_number t_tot;
@@ -5424,7 +5424,7 @@ static mp_knot mp_get_arc_time(MP mp, mp_number *ret, mp_knot h, mp_number *arc0
set_number_from_div(d1, d1, v1);
if (number_greater(t_tot, d1)) {
mp->arith_error = 1;
- check_arith();
+ check_arith(mp);
set_number_to_inf(*ret);
free_number(n);
free_number(n1);
@@ -5441,7 +5441,7 @@ static mp_knot mp_get_arc_time(MP mp, mp_number *ret, mp_knot h, mp_number *arc0
}
p = q;
}
- check_arith();
+ check_arith(mp);
if (local) {
number_add(t, two_t);
number_clone(*ret, t);
@@ -13161,7 +13161,7 @@ void mp_flush_cur_exp (MP mp, mp_value v)
break;
}
mp->cur_exp = v;
- mp->cur_exp.type = mp_known_type;
+ mp->cur_exp.type = mp_known_type;
}
static void mp_recycle_value (MP mp, mp_node p)
@@ -13411,7 +13411,7 @@ static void mp_recycle_independent_value (MP mp, mp_node p)
if (mp->fix_needed) {
mp_fix_dependencies(mp);
}
- check_arith();
+ check_arith(mp);
free_number(ret);
}
free_number(v);
@@ -13767,7 +13767,7 @@ static void mp_finish_read (MP mp)
}
static void mp_do_nullary (MP mp, int c)
{
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
mp_show_cmd_mod(mp, mp_nullary_command, c);
}
@@ -13815,7 +13815,7 @@ static void mp_do_nullary (MP mp, int c)
}
break;
}
- check_arith();
+ check_arith(mp);
}
static int mp_pict_color_type (MP mp, int c)
@@ -14699,7 +14699,7 @@ static void mp_do_read_or_close (MP mp, int c)
static void mp_do_unary (MP mp, int c)
{
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
mp_begin_diagnostic(mp);
mp_print_nl(mp, "{");
@@ -15368,7 +15368,7 @@ static void mp_do_unary (MP mp, int c)
}
break;
}
- check_arith();
+ check_arith(mp);
}
static void mp_bad_color_part (MP mp, int c)
@@ -16693,7 +16693,7 @@ static void mp_find_point (MP mp, mp_number *v_orig, int c)
static void mp_finish_binary (MP mp, mp_node old_p, mp_node old_exp)
{
- check_arith();
+ check_arith(mp);
if (old_p != NULL) {
mp_recycle_value(mp, old_p);
mp_free_value_node(mp, old_p);
@@ -16708,7 +16708,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
{
mp_node old_p, old_exp;
mp_value new_expr;
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
mp_begin_diagnostic(mp);
mp_print_nl(mp, "{(");
@@ -16809,7 +16809,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
case mp_greater_or_equal_operation:
case mp_equal_operation:
case mp_unequal_operation:
- check_arith();
+ check_arith(mp);
if ((mp->cur_exp.type > mp_pair_type) && (p->type > mp_pair_type)) {
mp_add_or_subtract(mp, p, NULL, mp_minus_operation);
} else if (mp->cur_exp.type != p->type) {
@@ -17165,7 +17165,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
mp_number r;
new_number(r);
power_of(r, mp_get_value_number(p), cur_exp_value_number);
- check_arith();
+ check_arith(mp);
mp_set_cur_exp_value_number(mp, &r);
free_number(r);
} else
@@ -18180,7 +18180,7 @@ void mp_make_eq (MP mp, mp_node lhs)
announce_bad_equation(mp, lhs);
break;
}
- check_arith();
+ check_arith(mp);
mp_recycle_value(mp, lhs);
free_number(v);
mp_free_value_node(mp, lhs);
@@ -20715,7 +20715,7 @@ void mp_scan_primary (MP mp)
mp_command_code my_var_flag = mp->var_flag;
mp->var_flag = 0;
RESTART:
- check_arith();
+ check_arith(mp);
switch (cur_cmd) {
case mp_left_delimiter_command:
{
@@ -20882,7 +20882,7 @@ void mp_scan_primary (MP mp)
mp_set_cur_exp_value_number(mp, &ret);
free_number(ret);
}
- check_arith();
+ check_arith(mp);
mp_get_x_next(mp);
}
}
@@ -21242,16 +21242,16 @@ static void mp_scan_secondary (MP mp)
}
mp_get_x_next(mp);
mp_scan_primary(mp);
- if (d != mp_primary_def_command) {
- mp_do_binary(mp, p, c);
- } else {
+ if (d == mp_primary_def_command) {
mp_back_input(mp);
mp_binary_mac(mp, p, cc, mac_name);
mp_decr_mac_ref(cc);
mp_get_x_next(mp);
goto RESTART;
+ } else {
+ mp_do_binary(mp, p, c);
+ goto CONTINUE;
}
- goto CONTINUE;
}
}
static void mp_scan_tertiary (MP mp)
@@ -21275,16 +21275,16 @@ static void mp_scan_tertiary (MP mp)
}
mp_get_x_next(mp);
mp_scan_secondary(mp);
- if (d != mp_secondary_def_command) {
- mp_do_binary(mp, p, c);
- } else {
+ if (d == mp_secondary_def_command) {
mp_back_input(mp);
mp_binary_mac(mp, p, cc, mac_name);
mp_decr_mac_ref(cc);
mp_get_x_next(mp);
goto RESTART;
+ } else {
+ mp_do_binary(mp, p, c);
+ goto CONTINUE;
}
- goto CONTINUE;
}
}
static int mp_scan_path (MP mp);
diff --git a/source/luametatex/source/mp/mpc/mp.h b/source/luametatex/source/mp/mpc/mp.h
index 2542bffaa..0b8e3def9 100644
--- a/source/luametatex/source/mp/mpc/mp.h
+++ b/source/luametatex/source/mp/mpc/mp.h
@@ -142,10 +142,22 @@ typedef struct mp_run_data
struct mp_edge_object *edges;
} mp_run_data;
typedef struct mp_color {
- double a_val;
- double b_val;
- double c_val;
- double d_val;
+ union {
+ double red;
+ double cyan;
+ };
+ union {
+ double green;
+ double magenta;
+ };
+ union {
+ double blue;
+ double yellow;
+ };
+ union {
+ double black;
+ double gray;
+ };
} mp_color;
typedef struct mp_dash_object {
double offset;
diff --git a/source/luametatex/source/mp/mpw/mp.w b/source/luametatex/source/mp/mpw/mp.w
index 6acecd35b..5fb24250c 100644
--- a/source/luametatex/source/mp/mpw/mp.w
+++ b/source/luametatex/source/mp/mpw/mp.w
@@ -1673,22 +1673,20 @@ mp->arith_error = 0;
@ At crucial points the program will say |check_arith|, to test if an arithmetic
error has been detected.
-@d check_arith()
+@c
+static void check_arith (MP mp)
+{
if (mp->arith_error) {
- mp_clear_arith(mp);
+ mp_error(
+ mp,
+ "Arithmetic overflow",
+ "Uh, oh. A little while ago one of the quantities that I was computing got too\n"
+ "large, so I'm afraid your answers will be somewhat askew. You'll probably have to\n"
+ "adopt different tactics next time. But I shall try to carry on anyway."
+ );
+ @.Arithmetic overflow@>
+ mp->arith_error = 0;
}
-
-@c
-static void mp_clear_arith (MP mp) {
- mp_error(
- mp,
- "Arithmetic overflow",
- "Uh, oh. A little while ago one of the quantities that I was computing got too\n"
- "large, so I'm afraid your answers will be somewhat askew. You'll probably have to\n"
- "adopt different tactics next time. But I shall try to carry on anyway."
- );
- @.Arithmetic overflow@>
- mp->arith_error = 0;
}
@ The definitions of these are set up by the math initialization. Here
@@ -4755,6 +4753,7 @@ void mp_print_variable_name (MP mp, mp_node p)
goto FOUND;
} else if (p->name_type != mp_attribute_operation) {
mp_confusion(mp, "variable");
+ return;
} else {
r = mp_new_symbolic_node(mp);
/* the hash address */
@@ -6070,7 +6069,7 @@ void mp_make_choices (MP mp, mp_knot knots)
mp_knot p, q; /* consecutive breakpoints being processed */
@<Other local variables for |make_choices|@>
/* make sure that |arith_error=false| */
- check_arith();
+ check_arith(mp);
if (number_positive(internal_value(mp_tracing_choices_internal))) {
mp_print_path(mp, knots, ", before choices", 1);
}
@@ -8529,7 +8528,7 @@ static void mp_get_arc_length (MP mp, mp_number *ret, mp_knot h)
free_number(arg4);
free_number(arg5);
free_number(arg6);
- check_arith();
+ check_arith(mp);
number_clone(*ret, a_tot);
free_number(a_tot);
}
@@ -8574,7 +8573,7 @@ static void mp_get_subarc_length (MP mp, mp_number *ret, mp_knot h, mp_number *f
free_number(arg4);
free_number(arg5);
free_number(arg6);
- check_arith();
+ check_arith(mp);
number_clone(*ret, a_tot);
free_number(a_cnt);
free_number(a_tot);
@@ -8643,7 +8642,7 @@ static mp_knot mp_get_arc_time(MP mp, mp_number *ret, mp_knot h, mp_number *arc0
}
p = q;
}
- check_arith();
+ check_arith(mp);
if (local) {
number_add(t, two_t);
number_clone(*ret, t);
@@ -8689,7 +8688,7 @@ if (mp_left_type(h) == mp_endpoint_knot) {
mp_toss_knot_list(mp, p);
free_number(neg_arc0);
}
-check_arith();
+check_arith(mp);
@ @<Update |t_tot| and |arc| to avoid going around the cyclic...@>=
if (number_positive(arc)) {
@@ -8711,7 +8710,7 @@ if (number_positive(arc)) {
set_number_from_div(d1, d1, v1); /* |d1 = EL_GORDO / v1| */
if (number_greater(t_tot, d1)) {
mp->arith_error = 1;
- check_arith();
+ check_arith(mp);
set_number_to_inf(*ret);
free_number(n);
free_number(n1);
@@ -19895,7 +19894,7 @@ void mp_flush_cur_exp (MP mp, mp_value v)
break;
}
mp->cur_exp = v;
- mp->cur_exp.type = mp_known_type;
+ mp->cur_exp.type = mp_known_type;
}
@ There's a much more general procedure that is capable of releasing the storage
@@ -20209,7 +20208,7 @@ static void mp_recycle_independent_value (MP mp, mp_node p)
if (mp->fix_needed) {
mp_fix_dependencies(mp);
}
- check_arith();
+ check_arith(mp);
free_number(ret);
}
free_number(v);
@@ -20339,7 +20338,7 @@ void mp_scan_primary (MP mp)
mp_command_code my_var_flag = mp->var_flag;
mp->var_flag = 0;
RESTART:
- check_arith();
+ check_arith(mp);
/* Supply diagnostic information, if requested */
switch (cur_cmd) {
case mp_left_delimiter_command:
@@ -20533,7 +20532,7 @@ void mp_scan_primary (MP mp)
mp_set_cur_exp_value_number(mp, &ret);
free_number(ret);
}
- check_arith();
+ check_arith(mp);
mp_get_x_next(mp);
}
}
@@ -21313,16 +21312,16 @@ static void mp_scan_secondary (MP mp)
}
mp_get_x_next(mp);
mp_scan_primary(mp);
- if (d != mp_primary_def_command) {
- mp_do_binary(mp, p, c);
- } else {
+ if (d == mp_primary_def_command) {
mp_back_input(mp);
mp_binary_mac(mp, p, cc, mac_name);
mp_decr_mac_ref(cc);
mp_get_x_next(mp);
goto RESTART;
+ } else {
+ mp_do_binary(mp, p, c);
+ goto CONTINUE;
}
- goto CONTINUE;
}
}
@@ -21365,16 +21364,16 @@ static void mp_scan_tertiary (MP mp)
}
mp_get_x_next(mp);
mp_scan_secondary(mp);
- if (d != mp_secondary_def_command) {
- mp_do_binary(mp, p, c);
- } else {
+ if (d == mp_secondary_def_command) {
mp_back_input(mp);
mp_binary_mac(mp, p, cc, mac_name);
mp_decr_mac_ref(cc);
mp_get_x_next(mp);
goto RESTART;
+ } else {
+ mp_do_binary(mp, p, c);
+ goto CONTINUE;
}
- goto CONTINUE;
}
}
@@ -22335,7 +22334,7 @@ static void push_of_path_result (MP mp, int what, mp_knot p)
@<Declare nullary action procedure@>
static void mp_do_nullary (MP mp, int c)
{
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
mp_show_cmd_mod(mp, mp_nullary_command, c);
}
@@ -22385,7 +22384,7 @@ static void mp_do_nullary (MP mp, int c)
}
break;
}
- check_arith();
+ check_arith(mp);
}
@ @<Declare nullary action procedure@>=
@@ -22476,7 +22475,7 @@ static int mp_pict_color_type (MP mp, int c);
static void mp_do_unary (MP mp, int c)
{
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
/* Trace the current unary operation */
mp_begin_diagnostic(mp);
@@ -23169,7 +23168,7 @@ static void mp_do_unary (MP mp, int c)
}
break;
}
- check_arith();
+ check_arith(mp);
}
@ The |nice_pair| function returns |true| if both components of a pair are known.
@@ -24309,7 +24308,7 @@ binary operation has been safely carried out.
@<Declare binary action procedures@>
static void mp_finish_binary (MP mp, mp_node old_p, mp_node old_exp)
{
- check_arith();
+ check_arith(mp);
/* Recycle any sidestepped |independent| capsules */
if (old_p != NULL) {
mp_recycle_value(mp, old_p);
@@ -24325,7 +24324,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
{
mp_node old_p, old_exp; /* capsules to recycle */
mp_value new_expr;
- check_arith();
+ check_arith(mp);
if (number_greater(internal_value(mp_tracing_commands_internal), two_t)) {
/* Trace the current binary operation */
mp_begin_diagnostic(mp);
@@ -24468,7 +24467,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
case mp_greater_or_equal_operation:
case mp_equal_operation:
case mp_unequal_operation:
- check_arith();
+ check_arith(mp);
/* at this point |arith_error| should be |false|? */
if ((mp->cur_exp.type > mp_pair_type) && (p->type > mp_pair_type)) {
/* |cur_exp:=(p)-cur_exp| */
@@ -24842,7 +24841,7 @@ static void mp_do_binary (MP mp, mp_node p, int c)
mp_number r;
new_number(r);
power_of(r, mp_get_value_number(p), cur_exp_value_number);
- check_arith();
+ check_arith(mp);
mp_set_cur_exp_value_number(mp, &r);
free_number(r);
} else
@@ -27398,7 +27397,7 @@ void mp_make_eq (MP mp, mp_node lhs)
announce_bad_equation(mp, lhs);
break;
}
- check_arith();
+ check_arith(mp);
mp_recycle_value(mp, lhs);
free_number(v);
mp_free_value_node(mp, lhs);
@@ -30120,10 +30119,22 @@ static void mp_ship_out (MP mp, mp_node h);
@<Exported types@>=
typedef struct mp_color {
- double a_val; /* r or c */
- double b_val; /* g or m */
- double c_val; /* b or y */
- double d_val; /* k */
+ union {
+ double red;
+ double cyan;
+ };
+ union {
+ double green;
+ double magenta;
+ };
+ union {
+ double blue;
+ double yellow;
+ };
+ union {
+ double black;
+ double gray;
+ };
} mp_color;
typedef struct mp_dash_object {
@@ -30206,14 +30217,14 @@ typedef struct mp_edge_object {
@d gr_type(A) (A)->type
@d gr_link(A) (A)->next
@d gr_color_model(A) (A)->color_model
-@d gr_red_val(A) (A)->color.a_val
-@d gr_green_val(A) (A)->color.b_val
-@d gr_blue_val(A) (A)->color.c_val
-@d gr_cyan_val(A) (A)->color.a_val
-@d gr_magenta_val(A) (A)->color.b_val
-@d gr_yellow_val(A) (A)->color.c_val
-@d gr_black_val(A) (A)->color.d_val
-@d gr_grey_val(A) (A)->color.d_val
+@d gr_red_val(A) (A)->color.red
+@d gr_green_val(A) (A)->color.green
+@d gr_blue_val(A) (A)->color.blue
+@d gr_cyan_val(A) (A)->color.cyan
+@d gr_magenta_val(A) (A)->color.magenta
+@d gr_yellow_val(A) (A)->color.yellow
+@d gr_black_val(A) (A)->color.black
+@d gr_grey_val(A) (A)->color.gray
@d gr_path_ptr(A) (A)->path
@d gr_htap_ptr(A) (A)->htap
@d gr_pen_ptr(A) (A)->pen
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. */
diff --git a/source/luametatex/source/utilities/auxsparsearray.c b/source/luametatex/source/utilities/auxsparsearray.c
index 3ea8f1c46..117e25ac0 100644
--- a/source/luametatex/source/utilities/auxsparsearray.c
+++ b/source/luametatex/source/utilities/auxsparsearray.c
@@ -111,7 +111,7 @@ int sa_get_item_1(const sa_tree head, int n)
}
}
}
- return (int) head->dflt.uchar_value[n%4];
+ return (int) head->dflt.uchar_value[0];
}
int sa_get_item_2(const sa_tree head, int n)
@@ -125,7 +125,7 @@ int sa_get_item_2(const sa_tree head, int n)
}
}
}
- return (int) head->dflt.ushort_value[n%2];
+ return (int) head->dflt.ushort_value[0];
}
int sa_get_item_4(const sa_tree head, int n, sa_tree_item *v)
@@ -289,20 +289,14 @@ void sa_set_item_n(sa_tree head, int n, int v, int gl)
}
switch (head->bytes) {
case 1:
- {
- head->tree[h][m][l/4].uchar_value[n%4] = (unsigned char) (v < 0 ? 0 : (v > 0xFF ? 0xFF : v));
- break;
- }
+ head->tree[h][m][l/4].uchar_value[n%4] = (unsigned char) (v < 0 ? 0 : (v > 0xFF ? 0xFF : v));
+ break;
case 2:
- {
- head->tree[h][m][l/2].ushort_value[n%2] = (unsigned char) (v < 0 ? 0 : (v > 0xFFFF ? 0xFFFF : v));
- break;
- }
+ head->tree[h][m][l/2].ushort_value[n%2] = (unsigned char) (v < 0 ? 0 : (v > 0xFFFF ? 0xFFFF : v));
+ break;
case 4:
- {
- head->tree[h][m][l].int_value = v;
- break;
- }
+ head->tree[h][m][l].int_value = v;
+ break;
}
}
@@ -418,9 +412,8 @@ sa_tree sa_new_tree(int size, int bytes, sa_tree_item dflt)
void sa_restore_stack(sa_tree head, int gl)
{
if (head->stack) {
- sa_stack_item st;
while (head->sa_stack_ptr > 0 && abs(head->stack[head->sa_stack_ptr].level) >= gl) {
- st = head->stack[head->sa_stack_ptr];
+ sa_stack_item st = head->stack[head->sa_stack_ptr];
if (st.level > 0) {
int code = st.code;
switch (head->bytes) {
@@ -443,7 +436,7 @@ void sa_restore_stack(sa_tree head, int gl)
break;
case 8:
{
- int l = 2*LMT_SA_L_PART(code);
+ int l = 2 * LMT_SA_L_PART(code);
head->tree[LMT_SA_H_PART(code)][LMT_SA_M_PART(code)][l] = st.value_1;
head->tree[LMT_SA_H_PART(code)][LMT_SA_M_PART(code)][l+1] = st.value_2;
}
diff --git a/source/luametatex/source/utilities/auxsparsearray.h b/source/luametatex/source/utilities/auxsparsearray.h
index 91e310074..a0de43496 100644
--- a/source/luametatex/source/utilities/auxsparsearray.h
+++ b/source/luametatex/source/utilities/auxsparsearray.h
@@ -33,6 +33,16 @@
# define LMT_SA_M_PART(a) (((a)>> 7)&127)
# define LMT_SA_L_PART(a) ( (a) &127)
+/* 40K less in 2023 */
+
+// # define LMT_SA_HIGHPART 128
+// # define LMT_SA_MIDPART 256
+// # define LMT_SA_LOWPART 64
+//
+// # define LMT_SA_H_PART(a) (((a)>>14)&127)
+// # define LMT_SA_M_PART(a) (((a)>> 6)&255)
+// # define LMT_SA_L_PART(a) ( (a) &63)
+
/*tex
In the early days of \LUATEX\ we had just simple items, all 32 bit values. Then we put the