| 1 |
/* |
| 2 |
* Copyright © 2022 Ran Benita <[email protected]> |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "config.h" |
| 7 |
|
| 8 |
#include "src/darray.h" |
| 9 |
#include <stdio.h> |
| 10 |
#include <stdbool.h> |
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
#include "xkbcommon/xkbcommon-compose.h" |
| 14 |
#include "src/compose/escape.h" |
| 15 |
#include "src/compose/constants.h" |
| 16 |
#include "src/keysym.h" |
| 17 |
#include "src/utils.h" |
| 18 |
#include "test/compose-iter.h" |
| 19 |
|
| 20 |
/* Reference implentation of Compose table traversal */ |
| 21 |
static void |
| 22 |
for_each_helper(struct xkb_compose_table *table, |
| 23 |
xkb_compose_table_iter_t iter, |
| 24 |
void *data, |
| 25 |
xkb_keysym_t *syms, |
| 26 |
size_t nsyms, |
| 27 |
uint32_t p) |
| 28 |
{ |
| 29 |
if (!p) { |
| 30 |
return; |
| 31 |
} |
| 32 |
const struct compose_node *node = &darray_item(table->nodes, p); |
| 33 |
for_each_helper(table, iter, data, syms, nsyms, node->lokid); |
| 34 |
syms[nsyms++] = node->keysym; |
| 35 |
if (node->is_leaf) { |
| 36 |
struct xkb_compose_table_entry entry = { |
| 37 |
.sequence = syms, |
| 38 |
.sequence_length = nsyms, |
| 39 |
.keysym = node->leaf.keysym, |
| 40 |
.utf8 = &darray_item(table->utf8, node->leaf.utf8), |
| 41 |
}; |
| 42 |
iter(&entry, data); |
| 43 |
} else { |
| 44 |
for_each_helper(table, iter, data, syms, nsyms, node->internal.eqkid); |
| 45 |
} |
| 46 |
nsyms--; |
| 47 |
for_each_helper(table, iter, data, syms, nsyms, node->hikid); |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
xkb_compose_table_for_each(struct xkb_compose_table *table, |
| 52 |
xkb_compose_table_iter_t iter, |
| 53 |
void *data) |
| 54 |
{ |
| 55 |
if (darray_size(table->nodes) <= 1) { |
| 56 |
return; |
| 57 |
} |
| 58 |
xkb_keysym_t syms[COMPOSE_MAX_LHS_LEN]; |
| 59 |
for_each_helper(table, iter, data, syms, 0, 1); |
| 60 |
} |