From 8b09e1772c142688a9c34f14f777ecd04d7941c8 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 30 Mar 2021 20:12:08 +0300 Subject: compose: use anonymous union Signed-off-by: Ran Benita --- src/compose/parser.c | 30 +++++++++++++++--------------- src/compose/state.c | 10 +++++----- src/compose/table.c | 4 ++-- src/compose/table.h | 8 +++++--- 4 files changed, 27 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/compose/parser.c b/src/compose/parser.c index dea3d3b..a8458ac 100644 --- a/src/compose/parser.c +++ b/src/compose/parser.c @@ -382,11 +382,11 @@ add_production(struct xkb_compose_table *table, struct scanner *s, break; if (node->is_leaf) { - if (node->u.leaf.utf8 != 0 || - node->u.leaf.keysym != XKB_KEY_NoSymbol) { + if (node->leaf.utf8 != 0 || + node->leaf.keysym != XKB_KEY_NoSymbol) { scanner_warn(s, "a sequence already exists which is a prefix of this sequence; overriding"); - node->u.leaf.utf8 = 0; - node->u.leaf.keysym = XKB_KEY_NoSymbol; + node->leaf.utf8 = 0; + node->leaf.keysym = XKB_KEY_NoSymbol; } { @@ -394,11 +394,11 @@ add_production(struct xkb_compose_table *table, struct scanner *s, /* Refetch since add_node could have realloc()ed. */ node = &darray_item(table->nodes, curr); node->is_leaf = false; - node->u.successor = successor; + node->internal.successor = successor; } } - curr = node->u.successor; + curr = node->internal.successor; node = &darray_item(table->nodes, curr); } @@ -407,19 +407,19 @@ add_production(struct xkb_compose_table *table, struct scanner *s, return; } - if (node->u.leaf.utf8 != 0 || node->u.leaf.keysym != XKB_KEY_NoSymbol) { + if (node->leaf.utf8 != 0 || node->leaf.keysym != XKB_KEY_NoSymbol) { bool same_string = - (node->u.leaf.utf8 == 0 && !production->has_string) || + (node->leaf.utf8 == 0 && !production->has_string) || ( - node->u.leaf.utf8 != 0 && production->has_string && - streq(&darray_item(table->utf8, node->u.leaf.utf8), + node->leaf.utf8 != 0 && production->has_string && + streq(&darray_item(table->utf8, node->leaf.utf8), production->string) ); bool same_keysym = - (node->u.leaf.keysym == XKB_KEY_NoSymbol && !production->has_keysym) || + (node->leaf.keysym == XKB_KEY_NoSymbol && !production->has_keysym) || ( - node->u.leaf.keysym != XKB_KEY_NoSymbol && production->has_keysym && - node->u.leaf.keysym == production->keysym + node->leaf.keysym != XKB_KEY_NoSymbol && production->has_keysym && + node->leaf.keysym == production->keysym ); if (same_string && same_keysym) { scanner_warn(s, "this compose sequence is a duplicate of another; skipping line"); @@ -429,12 +429,12 @@ add_production(struct xkb_compose_table *table, struct scanner *s, } if (production->has_string) { - node->u.leaf.utf8 = darray_size(table->utf8); + node->leaf.utf8 = darray_size(table->utf8); darray_append_items(table->utf8, production->string, strlen(production->string) + 1); } if (production->has_keysym) { - node->u.leaf.keysym = production->keysym; + node->leaf.keysym = production->keysym; } } diff --git a/src/compose/state.c b/src/compose/state.c index 00c1abe..de08a90 100644 --- a/src/compose/state.c +++ b/src/compose/state.c @@ -109,7 +109,7 @@ xkb_compose_state_feed(struct xkb_compose_state *state, xkb_keysym_t keysym) node = &darray_item(state->table->nodes, state->context); - context = (node->is_leaf ? 0 : node->u.successor); + context = (node->is_leaf ? 0 : node->internal.successor); node = &darray_item(state->table->nodes, context); while (node->keysym != keysym && node->next != 0) { @@ -164,11 +164,11 @@ xkb_compose_state_get_utf8(struct xkb_compose_state *state, /* If there's no string specified, but only a keysym, try to do the * most helpful thing. */ - if (node->u.leaf.utf8 == 0 && node->u.leaf.keysym != XKB_KEY_NoSymbol) { + if (node->leaf.utf8 == 0 && node->leaf.keysym != XKB_KEY_NoSymbol) { char name[64]; int ret; - ret = xkb_keysym_to_utf8(node->u.leaf.keysym, name, sizeof(name)); + ret = xkb_keysym_to_utf8(node->leaf.keysym, name, sizeof(name)); if (ret < 0 || ret == 0) { /* ret < 0 is impossible. * ret == 0 means the keysym has no string representation. */ @@ -179,7 +179,7 @@ xkb_compose_state_get_utf8(struct xkb_compose_state *state, } return snprintf(buffer, size, "%s", - &darray_item(state->table->utf8, node->u.leaf.utf8)); + &darray_item(state->table->utf8, node->leaf.utf8)); fail: if (size > 0) @@ -194,5 +194,5 @@ xkb_compose_state_get_one_sym(struct xkb_compose_state *state) &darray_item(state->table->nodes, state->context); if (!node->is_leaf) return XKB_KEY_NoSymbol; - return node->u.leaf.keysym; + return node->leaf.keysym; } diff --git a/src/compose/table.c b/src/compose/table.c index 38d4406..dbd255e 100644 --- a/src/compose/table.c +++ b/src/compose/table.c @@ -61,8 +61,8 @@ xkb_compose_table_new(struct xkb_context *ctx, root.keysym = XKB_KEY_NoSymbol; root.next = 0; root.is_leaf = true; - root.u.leaf.utf8 = 0; - root.u.leaf.keysym = XKB_KEY_NoSymbol; + root.leaf.utf8 = 0; + root.leaf.keysym = XKB_KEY_NoSymbol; darray_append(table->nodes, root); darray_append(table->utf8, '\0'); diff --git a/src/compose/table.h b/src/compose/table.h index a051e1b..467ccf7 100644 --- a/src/compose/table.h +++ b/src/compose/table.h @@ -78,14 +78,16 @@ struct compose_node { bool is_leaf; union { - /* Offset into xkb_compose_table::nodes. */ - uint16_t successor; + struct { + /* Offset into xkb_compose_table::nodes. */ + uint16_t successor; + } internal; struct { /* Offset into xkb_compose_table::utf8. */ uint32_t utf8; xkb_keysym_t keysym; } leaf; - } u; + }; }; struct xkb_compose_table { -- cgit v1.2.1