text: explicitly take mod_type in mod functions
authorRan Benita <ran234@gmail.com>
Sat, 6 Oct 2012 12:34:17 +0000 (14:34 +0200)
committerRan Benita <ran234@gmail.com>
Sat, 6 Oct 2012 19:41:59 +0000 (21:41 +0200)
This essentially "tags" each invocation of the functions with the
modifier type of the argument, which allows for easy grepping for them
(with the aim being, to remove anything but MOD_BOTH).

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

index 261562a..75f2654 100644 (file)
@@ -281,7 +281,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
         write_buf(buf, "\t\ttype \"%s\" {\n",
                   xkb_atom_text(keymap->ctx, type->name));
         write_buf(buf, "\t\t\tmodifiers= %s;\n",
-                  VModMaskText(keymap, type->mods.mods));
+                  ModMaskText(keymap, type->mods.mods, MOD_BOTH));
 
         for (j = 0; j < type->num_entries; j++) {
             const char *str;
@@ -294,7 +294,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
             if (entry->level == 0 && entry->preserve.mods == 0)
                 continue;
 
-            str = VModMaskText(keymap, entry->mods.mods);
+            str = ModMaskText(keymap, entry->mods.mods, MOD_BOTH);
             write_buf(buf, "\t\t\tmap[%s]= Level%d;\n",
                       str, entry->level + 1);
 
@@ -302,7 +302,8 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
                 continue;
 
             write_buf(buf, "\t\t\tpreserve[%s]= ", str);
-            write_buf(buf, "%s;\n", VModMaskText(keymap, entry->preserve.mods));
+            write_buf(buf, "%s;\n",
+                      ModMaskText(keymap, entry->preserve.mods, MOD_BOTH));
         }
 
         if (type->level_names) {
@@ -343,7 +344,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf, int num)
                       get_indicator_state_text(led->which_mods));
         }
         write_buf(buf, "\t\t\tmodifiers= %s;\n",
-                  VModMaskText(keymap, led->mods.mods));
+                  ModMaskText(keymap, led->mods.mods, MOD_BOTH));
     }
 
     if (led->ctrls) {
@@ -377,7 +378,7 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
         if (action->mods.flags & ACTION_MODS_LOOKUP_MODMAP)
             args = "modMapMods";
         else
-            args = VModMaskText(keymap, action->mods.mods.mods);
+            args = ModMaskText(keymap, action->mods.mods.mods, MOD_BOTH);
         write_buf(buf, "%s%s(modifiers=%s%s%s)%s", prefix, type, args,
                   (action->type != ACTION_TYPE_MOD_LOCK &&
                    (action->mods.flags & ACTION_LOCK_CLEAR)) ?
@@ -523,18 +524,14 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
         write_buf(buf, "\t\tinterpret %s+%s(%s) {\n",
                   keysym_name,
                   SIMatchText(interp->match),
-                  VModMaskText(keymap, interp->mods));
+                  ModMaskText(keymap, interp->mods, MOD_REAL));
 
-        if (interp->virtual_mod != XKB_MOD_INVALID) {
-            xkb_mod_index_t idx = interp->virtual_mod;
+        if (interp->virtual_mod != XKB_MOD_INVALID)
             write_buf(buf, "\t\t\tvirtualModifier= %s;\n",
-                      xkb_atom_text(keymap->ctx,
-                                    darray_item(keymap->mods, idx).name));
-        }
+                      ModIndexText(keymap, interp->virtual_mod, MOD_VIRT));
 
         if (interp->match & MATCH_LEVEL_ONE_ONLY)
-            write_buf(buf,
-                      "\t\t\tuseModMapMods=level1;\n");
+            write_buf(buf, "\t\t\tuseModMapMods=level1;\n");
         if (interp->repeat)
             write_buf(buf, "\t\t\trepeat= True;\n");
 
@@ -671,7 +668,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
 
         if (key->vmodmap && (key->explicit & EXPLICIT_VMODMAP))
             write_buf(buf, "\n\t\t\tvirtualMods= %s,",
-                      VModMaskText(keymap, key->vmodmap));
+                      ModMaskText(keymap, key->vmodmap, MOD_VIRT));
 
         switch (key->out_of_range_group_action) {
         case RANGE_SATURATE:
index 843c945..ff783e3 100644 (file)
@@ -231,9 +231,9 @@ GetBuffer(size_t size)
     return rtrn;
 }
 
-static const char *
-mod_mask_text(const struct xkb_keymap *keymap, xkb_mod_mask_t mask,
-              enum mod_type type)
+const char *
+ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask,
+            enum mod_type type)
 {
     xkb_mod_index_t i;
     xkb_mod_mask_t rmask, vmask;
@@ -279,20 +279,22 @@ mod_mask_text(const struct xkb_keymap *keymap, xkb_mod_mask_t mask,
 }
 
 const char *
-ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
+ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
+             enum mod_type type)
 {
-    return mod_mask_text(keymap, mask, MOD_REAL);
-}
+    if (ndx == XKB_MOD_INVALID)
+        return "none";
 
-const char *
-VModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
-{
-    return mod_mask_text(keymap, mask, MOD_BOTH);
+    if (ndx >= darray_size(keymap->mods) ||
+        !(darray_item(keymap->mods, ndx).type & type))
+        return NULL;
+
+    return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, ndx).name);
 }
 
-static xkb_mod_index_t
-mod_name_to_index(const struct xkb_keymap *keymap, xkb_atom_t name,
-                  enum mod_type type)
+xkb_mod_index_t
+ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
+               enum mod_type type)
 {
     xkb_mod_index_t i;
     const struct xkb_mod *mod;
@@ -304,51 +306,6 @@ mod_name_to_index(const struct xkb_keymap *keymap, xkb_atom_t name,
     return XKB_MOD_INVALID;
 }
 
-xkb_mod_index_t
-ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name)
-{
-    return mod_name_to_index(keymap, name, MOD_REAL);
-}
-
-static xkb_mod_index_t
-mod_index_to_name(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
-                  enum mod_type type)
-{
-    if (ndx >= darray_size(keymap->mods) ||
-        !(darray_item(keymap->mods, ndx).type & type))
-        return XKB_ATOM_NONE;
-
-    return darray_item(keymap->mods, ndx).name;
-}
-
-xkb_atom_t
-ModIndexToName(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
-{
-    return mod_index_to_name(keymap, ndx, MOD_REAL);
-}
-
-static const char *
-mod_index_text(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
-               enum mod_type type)
-{
-    xkb_atom_t name;
-
-    name = mod_index_to_name(keymap, ndx, type);
-    if (name)
-        return xkb_atom_text(keymap->ctx, name);
-
-    if (ndx == XKB_MOD_INVALID)
-        return "none";
-
-    return NULL;
-}
-
-const char *
-ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
-{
-    return mod_index_text(keymap, ndx, MOD_REAL);
-}
-
 const char *
 ActionTypeText(unsigned type)
 {
index ee6acf0..a3c1f29 100644 (file)
@@ -48,19 +48,16 @@ extern const LookupEntry actionTypeNames[];
 extern const LookupEntry symInterpretMatchMaskNames[];
 
 const char *
-VModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask);
-
-xkb_mod_index_t
-ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name);
-
-xkb_atom_t
-ModIndexToName(const struct xkb_keymap *keymap, xkb_mod_index_t ndx);
+ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask,
+            enum mod_type type);
 
 const char *
-ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx);
+ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
+             enum mod_type type);
 
-const char *
-ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask);
+xkb_mod_index_t
+ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
+               enum mod_type type);
 
 const char *
 ActionTypeText(enum xkb_action_type type);
index 5678074..522389b 100644 (file)
@@ -210,7 +210,7 @@ siText(SymInterpInfo *si, CompatInfo *info)
     snprintf(buf, sizeof(buf), "%s+%s(%s)",
              KeysymText(si->interp.sym),
              SIMatchText(si->interp.match),
-             ModMaskText(info->keymap, si->interp.mods));
+             ModMaskText(info->keymap, si->interp.mods, MOD_REAL));
     return buf;
 }
 
index f5caa58..69bf30d 100644 (file)
@@ -86,7 +86,7 @@ LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
                enum expr_value_type type, xkb_mod_index_t *val_rtrn)
 {
     const struct xkb_keymap *keymap = priv;
-    *val_rtrn = ModNameToIndex(keymap, field);
+    *val_rtrn = ModNameToIndex(keymap, field, MOD_REAL);
     return (*val_rtrn != XKB_MOD_INVALID);
 }
 
index 14d7668..5c5e6c7 100644 (file)
@@ -463,8 +463,8 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
                         "%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));
+                        ModIndexText(info->keymap, use, MOD_REAL),
+                        ModIndexText(info->keymap, ignore, MOD_REAL));
                 mm->modifier = use;
             }
             return true;
@@ -485,8 +485,8 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
                         "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));
+                        ModIndexText(info->keymap, use, MOD_REAL),
+                        ModIndexText(info->keymap, ignore, MOD_REAL));
                 mm->modifier = use;
             }
             return true;
@@ -1211,7 +1211,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
     bool ok;
     struct xkb_context *ctx = info->keymap->ctx;
 
-    ndx = ModNameToIndex(info->keymap, def->modifier);
+    ndx = ModNameToIndex(info->keymap, def->modifier, MOD_REAL);
     if (ndx == XKB_MOD_INVALID) {
         log_err(info->keymap->ctx,
                 "Illegal modifier map definition; "
@@ -1238,7 +1238,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
             log_err(info->keymap->ctx,
                     "Modmap entries may contain only key names or keysyms; "
                     "Illegal definition for %s modifier ignored\n",
-                    ModIndexText(info->keymap, tmp.modifier));
+                    ModIndexText(info->keymap, tmp.modifier, MOD_REAL));
             continue;
         }
 
@@ -1573,7 +1573,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
                     "Key %s not found in keycodes; "
                     "Modifier map entry for %s not updated\n",
                     KeyNameText(keymap->ctx, entry->u.keyName),
-                    ModIndexText(info->keymap, entry->modifier));
+                    ModIndexText(info->keymap, entry->modifier, MOD_REAL));
             return false;
         }
     }
@@ -1584,7 +1584,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
                     "Key \"%s\" not found in symbol map; "
                     "Modifier map entry for %s not updated\n",
                     KeysymText(entry->u.keySym),
-                    ModIndexText(info->keymap, entry->modifier));
+                    ModIndexText(info->keymap, entry->modifier, MOD_REAL));
             return false;
         }
     }
index 5eff5f4..39a730a 100644 (file)
@@ -168,7 +168,7 @@ typedef struct {
 static inline const char *
 MapEntryTxt(KeyTypesInfo *info, struct xkb_kt_map_entry *entry)
 {
-    return VModMaskText(info->keymap, entry->mods.mods);
+    return ModMaskText(info->keymap, entry->mods.mods, MOD_BOTH);
 }
 
 static inline const char *
@@ -180,7 +180,7 @@ TypeTxt(KeyTypesInfo *info, KeyTypeInfo *type)
 static inline const char *
 TypeMaskTxt(KeyTypesInfo *info, KeyTypeInfo *type)
 {
-    return VModMaskText(info->keymap, type->mods);
+    return ModMaskText(info->keymap, type->mods, MOD_BOTH);
 }
 
 static inline bool
@@ -364,7 +364,6 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
                  "The modifiers field of a key type is not an array; "
                  "Illegal array subscript ignored\n");
 
-    /* get modifier mask for current type */
     if (!ExprResolveVModMask(info->keymap, value, &mods)) {
         log_err(info->keymap->ctx,
                 "Key type mask field must be a modifier mask; "
@@ -378,7 +377,7 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
                  "Using %s, ignoring %s\n",
                  xkb_atom_text(info->keymap->ctx, type->name),
                  TypeMaskTxt(info, type),
-                 VModMaskText(info->keymap, mods));
+                 ModMaskText(info->keymap, mods, MOD_BOTH));
         return false;
     }
 
@@ -457,7 +456,8 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
                 "Map entry for unused modifiers in %s; "
                 "Using %s instead of %s\n",
                 TypeTxt(info, type),
-                VModMaskText(info->keymap, entry.mods.mods & type->mods),
+                ModMaskText(info->keymap, entry.mods.mods & type->mods,
+                            MOD_BOTH),
                 MapEntryTxt(info, &entry));
         entry.mods.mods &= type->mods;
     }
@@ -498,7 +498,7 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
             log_vrb(info->keymap->ctx, 10,
                     "Identical definitions for preserve[%s] in %s; "
                     "Ignored\n",
-                    VModMaskText(info->keymap, mods),
+                    ModMaskText(info->keymap, mods, MOD_BOTH),
                     TypeTxt(info, type));
             return true;
         }
@@ -507,10 +507,10 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
         log_vrb(info->keymap->ctx, 1,
                 "Multiple definitions for preserve[%s] in %s; "
                 "Using %s, ignoring %s\n",
-                VModMaskText(info->keymap, mods),
+                ModMaskText(info->keymap, mods, MOD_BOTH),
                 TypeTxt(info, type),
-                VModMaskText(info->keymap, preserve_mods),
-                VModMaskText(info->keymap, entry->preserve.mods));
+                ModMaskText(info->keymap, preserve_mods, MOD_BOTH),
+                ModMaskText(info->keymap, entry->preserve.mods, MOD_BOTH));
 
         entry->preserve.mods = preserve_mods;
         return true;
@@ -544,9 +544,9 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (mods & ~type->mods) {
         const char *before, *after;
 
-        before = VModMaskText(info->keymap, mods);
+        before = ModMaskText(info->keymap, mods, MOD_BOTH);
         mods &= type->mods;
-        after = VModMaskText(info->keymap, mods);
+        after = ModMaskText(info->keymap, mods, MOD_BOTH);
 
         log_vrb(info->keymap->ctx, 1,
                 "Preserve for modifiers not used by the %s type; "
@@ -558,7 +558,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         log_err(info->keymap->ctx,
                 "Preserve value in a key type is not a modifier mask; "
                 "Ignoring preserve[%s] in type %s\n",
-                VModMaskText(info->keymap, mods),
+                ModMaskText(info->keymap, mods, MOD_BOTH),
                 TypeTxt(info, type));
         return false;
     }
@@ -566,14 +566,14 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (preserve_mods & ~mods) {
         const char *before, *after;
 
-        before = VModMaskText(info->keymap, preserve_mods);
+        before = ModMaskText(info->keymap, preserve_mods, MOD_BOTH);
         preserve_mods &= mods;
-        after = VModMaskText(info->keymap, preserve_mods);
+        after = ModMaskText(info->keymap, preserve_mods, MOD_BOTH);
 
         log_vrb(info->keymap->ctx, 1,
                 "Illegal value for preserve[%s] in type %s; "
                 "Converted %s to %s\n",
-                VModMaskText(info->keymap, mods),
+                ModMaskText(info->keymap, mods, MOD_BOTH),
                 TypeTxt(info, type), before, after);
     }