symbols: refactor AddModMapEntry It really asks for it. 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
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index d773660..32c7855 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -442,55 +442,40 @@ AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
static bool
AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
{
- ModMapEntry *mm;
- bool clobber;
-
- clobber = (new->merge != MERGE_AUGMENT);
- darray_foreach(mm, info->modMaps) {
- if (new->haveSymbol && mm->haveSymbol
- && (new->u.keySym == mm->u.keySym)) {
- xkb_mod_index_t use, ignore;
- if (mm->modifier != new->modifier) {
- if (clobber) {
- use = new->modifier;
- ignore = mm->modifier;
- }
- else {
- use = mm->modifier;
- ignore = new->modifier;
- }
- log_err(info->keymap->ctx,
- "%s added to symbol map for multiple modifiers; "
- "Using %s, ignoring %s.\n",
- KeysymText(new->u.keySym),
- ModIndexText(info->keymap, use),
- ModIndexText(info->keymap, ignore));
- mm->modifier = use;
- }
- return true;
- }
- if ((!new->haveSymbol) && (!mm->haveSymbol) &&
- (new->u.keyName == mm->u.keyName)) {
- xkb_mod_index_t use, ignore;
- if (mm->modifier != new->modifier) {
- if (clobber) {
- use = new->modifier;
- ignore = mm->modifier;
- }
- else {
- use = mm->modifier;
- ignore = new->modifier;
- }
- log_err(info->keymap->ctx,
- "Key %s added to map for multiple modifiers; "
- "Using %s, ignoring %s.\n",
- KeyNameText(info->keymap->ctx, new->u.keyName),
- ModIndexText(info->keymap, use),
- ModIndexText(info->keymap, ignore));
- mm->modifier = use;
- }
+ ModMapEntry *old;
+ bool clobber = (new->merge != MERGE_AUGMENT);
+
+ darray_foreach(old, info->modMaps) {
+ xkb_mod_index_t use, ignore;
+
+ if ((new->haveSymbol != old->haveSymbol) ||
+ (new->haveSymbol && new->u.keySym != old->u.keySym) ||
+ (!new->haveSymbol && new->u.keyName != old->u.keyName))
+ continue;
+
+ if (new->modifier == old->modifier)
return true;
- }
+
+ use = (clobber ? new->modifier : old->modifier);
+ ignore = (clobber ? old->modifier : new->modifier);
+
+ if (new->haveSymbol)
+ log_err(info->keymap->ctx,
+ "Symbol \"%s\" added to modifier map for multiple modifiers; "
+ "Using %s, ignoring %s\n",
+ KeysymText(new->u.keySym),
+ ModIndexText(info->keymap, use),
+ ModIndexText(info->keymap, ignore));
+ else
+ log_err(info->keymap->ctx,
+ "Key \"%s\" added to modifier map for multiple modifiers; "
+ "Using %s, ignoring %s\n",
+ KeyNameText(info->keymap->ctx, new->u.keyName),
+ ModIndexText(info->keymap, use),
+ ModIndexText(info->keymap, ignore));
+
+ old->modifier = use;
+ return true;
}
darray_append(info->modMaps, *new);