symbols: fold PrepareKeyDef into CopySymbolsDef The function is big enough already but it's nicer to read sequentially. Signed-off-by: Ran Benita <ran234@gmail.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
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 2f4c9f8..e17dcfb 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1396,48 +1396,12 @@ FindAutomaticType(struct xkb_context *ctx, xkb_level_index_t width,
return width <= 4;
}
-/**
- * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
- * groups.
- */
-static void
-PrepareKeyDef(KeyInfo *keyi)
-{
- xkb_layout_index_t i, lastGroup;
- const GroupInfo *group0;
-
- /* get highest group number */
- lastGroup = 0;
- for (i = 1; i < XKB_NUM_GROUPS; i++)
- if (keyi->groups[i].defined)
- lastGroup = i;
-
- if (lastGroup == 0)
- return;
-
- group0 = &keyi->groups[0];
-
- /* If there are empty groups between non-empty ones fill them with data */
- /* from the first group. */
- /* We can make a wrong assumption here. But leaving gaps is worse. */
- for (i = 1; i < lastGroup; i++) {
- GroupInfo *groupi = &keyi->groups[i];
-
- if (groupi->defined)
- continue;
-
- groupi->type = group0->type;
- darray_copy(groupi->syms, group0->syms);
- darray_copy(groupi->levels, group0->levels);
- groupi->defined = group0->defined;
- }
-}
-
static bool
CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
{
struct xkb_keymap *keymap = info->keymap;
struct xkb_key *key;
+ const GroupInfo *group0;
xkb_layout_index_t i;
bool haveActions;
unsigned int sizeSyms;
@@ -1455,15 +1419,33 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
return false;
}
- /*
- * Find the range of groups we need. (There shouldn't be any gaps,
- * see PrepareKeyDef).
- */
+ /* Find the range of groups we need. */
key->num_groups = 0;
for (i = 0; i < XKB_NUM_GROUPS; i++)
if (keyi->groups[i].defined)
key->num_groups = i + 1;
+ if (key->num_groups <= 0)
+ return false; /* WSGO */
+
+ /*
+ * If there are empty groups between non-empty ones, fill them with data
+ * from the first group.
+ * We can make a wrong assumption here. But leaving gaps is worse.
+ */
+ group0 = &keyi->groups[0];
+ for (i = 1; i < key->num_groups - 1; i++) {
+ GroupInfo *groupi = &keyi->groups[i];
+
+ if (groupi->defined)
+ continue;
+
+ groupi->type = group0->type;
+ darray_copy(groupi->syms, group0->syms);
+ darray_copy(groupi->levels, group0->levels);
+ groupi->defined = group0->defined;
+ }
+
/* See if we need to allocate an actions array. */
haveActions = false;
for (i = 0; i < key->num_groups; i++) {
@@ -1649,11 +1631,9 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
if (info->groupNames[i] != XKB_ATOM_NONE)
keymap->group_names[i] = info->groupNames[i];
- darray_foreach(keyi, info->keys) {
- PrepareKeyDef(keyi);
+ darray_foreach(keyi, info->keys)
if (!CopySymbolsDef(info, keyi))
info->errorCount++;
- }
if (xkb_get_log_verbosity(keymap->ctx) > 3) {
xkb_foreach_key(key, keymap) {