Clean up xkb_sym_interpret a bit
authorRan Benita <ran234@gmail.com>
Thu, 18 Oct 2012 19:04:27 +0000 (21:04 +0200)
committerRan Benita <ran234@gmail.com>
Thu, 18 Oct 2012 19:04:27 +0000 (21:04 +0200)
First we split the LEVEL_ONE_ONLY bit off of the 'match' field, which
allows us to turn enum xkb_match_operation to a simple enum and remove
the need for MATCH_OP_MASK.

Next we rename 'act' to 'action', because we've settled on that
everywhere else.

Finally, SIMatchText is changed to not handle illegal values - it
shouldn't get any. This removes one usage of the GetBuffer hack.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/keymap-dump.c
src/keymap.h
src/text.c
src/xkbcomp/compat.c
src/xkbcomp/keymap.c

index 5ff3b84..82a301f 100644 (file)
@@ -528,12 +528,12 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
             write_buf(buf, "\t\t\tvirtualModifier= %s;\n",
                       ModIndexText(keymap, interp->virtual_mod));
 
-        if (interp->match & MATCH_LEVEL_ONE_ONLY)
+        if (interp->level_one_only)
             write_buf(buf, "\t\t\tuseModMapMods=level1;\n");
         if (interp->repeat)
             write_buf(buf, "\t\t\trepeat= True;\n");
 
-        write_action(keymap, buf, &interp->act, "\t\t\taction= ", ";\n");
+        write_action(keymap, buf, &interp->action, "\t\t\taction= ", ";\n");
         write_buf(buf, "\t\t};\n");
     }
 
index f72599e..1684979 100644 (file)
@@ -171,15 +171,11 @@ enum xkb_action_controls {
 };
 
 enum xkb_match_operation {
-    MATCH_NONE = 0,
-    MATCH_ANY_OR_NONE = 1,
-    MATCH_ANY = 2,
-    MATCH_ALL = 3,
-    MATCH_EXACTLY = 4,
-    MATCH_OP_MASK = \
-        (MATCH_NONE | MATCH_ANY_OR_NONE | MATCH_ANY | MATCH_ALL | \
-         MATCH_EXACTLY),
-    MATCH_LEVEL_ONE_ONLY = (1 << 7),
+    MATCH_NONE,
+    MATCH_ANY_OR_NONE,
+    MATCH_ANY,
+    MATCH_ALL,
+    MATCH_EXACTLY,
 };
 
 struct xkb_mods {
@@ -277,11 +273,12 @@ struct xkb_key_type {
 
 struct xkb_sym_interpret {
     xkb_keysym_t sym;
-    bool repeat;
     enum xkb_match_operation match;
+    bool level_one_only;
     xkb_mod_mask_t mods;
     xkb_mod_index_t virtual_mod;
-    union xkb_action act;
+    union xkb_action action;
+    bool repeat;
 };
 
 struct xkb_indicator_map {
index 6b96b72..66f21b0 100644 (file)
@@ -329,16 +329,5 @@ KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
 const char *
 SIMatchText(enum xkb_match_operation type)
 {
-    const char *name;
-    char *buf;
-
-    type &= MATCH_OP_MASK;
-
-    name = LookupValue(symInterpretMatchMaskNames, type);
-    if (name)
-        return name;
-
-    buf = GetBuffer(40);
-    snprintf(buf, 40, "0x%x", type);
-    return buf;
+    return LookupValue(symInterpretMatchMaskNames, type);
 }
index 8edd587..dc51a6e 100644 (file)
@@ -399,7 +399,7 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
         }
         if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
                               &collide)) {
-            old->interp.act = new->interp.act;
+            old->interp.action = new->interp.action;
             old->defined |= SI_FIELD_ACTION;
         }
         if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
@@ -409,8 +409,7 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
         }
         if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
                               &collide)) {
-            old->interp.match &= ~MATCH_LEVEL_ONE_ONLY;
-            old->interp.match |= (new->interp.match & MATCH_LEVEL_ONE_ONLY);
+            old->interp.level_one_only = new->interp.level_one_only;
             old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
         }
 
@@ -641,7 +640,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
         if (arrayNdx)
             return ReportSINotArray(info, si, field);
 
-        if (!HandleActionDef(value, keymap, &si->interp.act, info->actions))
+        if (!HandleActionDef(value, keymap, &si->interp.action, info->actions))
             return false;
 
         si->defined |= SI_FIELD_ACTION;
@@ -685,11 +684,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
         if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValueNames))
             return ReportSIBadType(info, si, field, "level specification");
 
-        if (val)
-            si->interp.match |= MATCH_LEVEL_ONE_ONLY;
-        else
-            si->interp.match &= ~MATCH_LEVEL_ONE_ONLY;
-
+        si->interp.level_one_only = !!val;
         si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
     }
     else {
@@ -862,7 +857,6 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
     }
 
     si = info->dflt;
-
     si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
 
     if (!LookupKeysym(def->sym, &si.interp.sym)) {
@@ -873,8 +867,7 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
         return false;
     }
 
-    si.interp.match = pred & MATCH_OP_MASK;
-
+    si.interp.match = pred;
     si.interp.mods = mods;
 
     if (!HandleInterpBody(info, def->def, &si)) {
@@ -991,14 +984,10 @@ CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred)
 {
     SymInterpInfo *si;
 
-    darray_foreach(si, info->interps) {
-        if (((si->interp.match & MATCH_OP_MASK) != pred) ||
-            (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
-            (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
-            continue;
-
-        darray_append(info->keymap->sym_interprets, si->interp);
-    }
+    darray_foreach(si, info->interps)
+        if (si->interp.match == pred &&
+            (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
+            darray_append(info->keymap->sym_interprets, si->interp);
 }
 
 static void
@@ -1061,11 +1050,13 @@ CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
     if (!darray_empty(info->interps)) {
         /* Most specific to least specific. */
         CopyInterps(info, true, MATCH_EXACTLY);
-        CopyInterps(info, true, MATCH_ALL | MATCH_NONE);
+        CopyInterps(info, true, MATCH_ALL);
+        CopyInterps(info, true, MATCH_NONE);
         CopyInterps(info, true, MATCH_ANY);
         CopyInterps(info, true, MATCH_ANY_OR_NONE);
         CopyInterps(info, false, MATCH_EXACTLY);
-        CopyInterps(info, false, MATCH_ALL | MATCH_NONE);
+        CopyInterps(info, false, MATCH_ALL);
+        CopyInterps(info, false, MATCH_NONE);
         CopyInterps(info, false, MATCH_ANY);
         CopyInterps(info, false, MATCH_ANY_OR_NONE);
     }
index cd1f79c..a3503b8 100644 (file)
@@ -66,7 +66,7 @@ static const struct xkb_sym_interpret default_interpret = {
     .match = MATCH_ANY_OR_NONE,
     .mods = 0,
     .virtual_mod = XKB_MOD_INVALID,
-    .act = { .type = ACTION_TYPE_NONE },
+    .action = { .type = ACTION_TYPE_NONE },
 };
 
 /**
@@ -101,12 +101,12 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
             interp->sym != XKB_KEY_NoSymbol)
             continue;
 
-        if (level == 0 || !(interp->match & MATCH_LEVEL_ONE_ONLY))
-            mods = key->modmap;
-        else
+        if (interp->level_one_only && level != 0)
             mods = 0;
+        else
+            mods = key->modmap;
 
-        switch (interp->match & MATCH_OP_MASK) {
+        switch (interp->match) {
         case MATCH_NONE:
             found = !(interp->mods & mods);
             break;
@@ -122,9 +122,6 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
         case MATCH_EXACTLY:
             found = (interp->mods == mods);
             break;
-        default:
-            found = false;
-            break;
         }
 
         if (found)
@@ -158,14 +155,12 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
                 if (!(key->explicit & EXPLICIT_REPEAT) && interp->repeat)
                     key->repeats = true;
 
-            if ((group == 0 && level == 0) ||
-                !(interp->match & MATCH_LEVEL_ONE_ONLY)) {
+            if ((group == 0 && level == 0) || !interp->level_one_only)
                 if (interp->virtual_mod != XKB_MOD_INVALID)
                     vmodmap |= (1 << interp->virtual_mod);
-            }
 
-            if (interp->act.type != ACTION_TYPE_NONE)
-                key->groups[group].levels[level].action = interp->act;
+            if (interp->action.type != ACTION_TYPE_NONE)
+                key->groups[group].levels[level].action = interp->action;
         }
     }