compose: use anonymous union Signed-off-by: Ran Benita <ran@unusedvar.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
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 {