Commit 59d947c9c1df624c47ccfd1c6f13eb1f408ea16a

Ran Benita 2012-08-05T19:24:44

Add and use xkb_level_index_t Several types are used over the code for shift levels; better to use just one. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 01f7572..2c19d9e 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -657,7 +657,8 @@ write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
               struct xkb_key *key, xkb_group_index_t group)
 {
     const xkb_keysym_t *syms;
-    int num_syms, level;
+    int num_syms;
+    xkb_level_index_t level;
 #define OUT_BUF_LEN 128
     char out_buf[OUT_BUF_LEN];
 
diff --git a/src/map.c b/src/map.c
index 1108a81..d602c90 100644
--- a/src/map.c
+++ b/src/map.c
@@ -213,14 +213,14 @@ xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name)
 /**
  * Returns the level to use for the given key and state, or -1 if invalid.
  */
-unsigned int
+xkb_level_index_t
 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
                   xkb_group_index_t group)
 {
     struct xkb_keymap *keymap = xkb_state_get_map(state);
     struct xkb_key_type *type;
     struct xkb_kt_map_entry *entry;
-    unsigned int active_mods;
+    xkb_mod_mask_t active_mods;
 
     if (!XkbKeycodeInRange(keymap, kc))
         return 0;
@@ -281,7 +281,7 @@ xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc)
  */
 int
 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
-                          xkb_group_index_t group, unsigned int level,
+                          xkb_group_index_t group, xkb_level_index_t level,
                           const xkb_keysym_t **syms_out)
 {
     int num_syms;
@@ -314,7 +314,7 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
     struct xkb_keymap *keymap = xkb_state_get_map(state);
     struct xkb_key *key;
     xkb_group_index_t group;
-    unsigned int level;
+    xkb_level_index_t level;
 
     if (!state || !XkbKeycodeInRange(keymap, kc))
         return -1;
diff --git a/src/state.c b/src/state.c
index f527c90..15aacd9 100644
--- a/src/state.c
+++ b/src/state.c
@@ -110,7 +110,7 @@ static union xkb_action *
 xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
 {
     xkb_group_index_t group;
-    unsigned int level;
+    xkb_level_index_t level;
     struct xkb_key *key = NULL;
 
     if (XkbKeycodeInRange(state->keymap, kc))
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 7bfa660..f570665 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -91,6 +91,8 @@
 #include "darray.h"
 #include "list.h"
 
+typedef uint16_t xkb_level_index_t;
+
 enum xkb_file_type {
     /* The top level file which includes the other component files. */
     FILE_TYPE_KEYMAP = (1 << 0),
@@ -241,13 +243,13 @@ struct xkb_mods {
 };
 
 struct xkb_kt_map_entry {
-    uint16_t level;
+    xkb_level_index_t level;
     struct xkb_mods mods;
 };
 
 struct xkb_key_type {
     struct xkb_mods mods;
-    uint16_t num_levels;
+    xkb_level_index_t num_levels;
     darray(struct xkb_kt_map_entry) map;
     struct xkb_mods *preserve;
     const char *name;
@@ -317,7 +319,7 @@ struct xkb_key {
 
     xkb_group_index_t num_groups;
     /* How many levels the largest group has. */
-    unsigned char width;
+    xkb_level_index_t width;
 
     uint8_t out_of_range_group_action;
     xkb_group_index_t out_of_range_group_number;
@@ -400,7 +402,7 @@ XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
     return &darray_item(keymap->types, XkbKeyTypeIndex(key, group));
 }
 
-static inline uint16_t
+static inline xkb_level_index_t
 XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
                  xkb_group_index_t group)
 {
@@ -408,7 +410,8 @@ XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
 }
 
 static inline unsigned int
-XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
+XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group,
+              xkb_level_index_t level)
 {
     return key->num_syms[group * key->width + level];
 }
@@ -421,13 +424,14 @@ XkbKeySym(struct xkb_key *key, int ndx)
 
 static inline int
 XkbKeySymOffset(struct xkb_key *key, xkb_group_index_t group,
-                unsigned int level)
+                xkb_level_index_t level)
 {
     return key->sym_index[group * key->width + level];
 }
 
 static inline xkb_keysym_t *
-XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
+XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
+               xkb_level_index_t level)
 {
     return XkbKeySym(key, XkbKeySymOffset(key, group, level));
 }
@@ -454,7 +458,7 @@ XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
 
 static inline union xkb_action *
 XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
-                  xkb_group_index_t group, unsigned int level)
+                  xkb_group_index_t group, xkb_level_index_t level)
 {
     if (XkbKeyHasActions(key))
         return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
@@ -492,13 +496,13 @@ xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
 xkb_group_index_t
 xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
 
-extern unsigned int
+xkb_level_index_t
 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
                   xkb_group_index_t group);
 
 extern int
 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
-                          xkb_group_index_t group, unsigned int level,
+                          xkb_group_index_t group, xkb_level_index_t level,
                           const xkb_keysym_t **syms_out);
 
 /**
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index c2a91ab..662b6c1 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1334,7 +1334,7 @@ UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
  */
 static struct xkb_sym_interpret *
 FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
-                 xkb_group_index_t group, uint32_t level)
+                 xkb_group_index_t group, xkb_level_index_t level)
 {
     struct xkb_sym_interpret *ret = NULL;
     struct xkb_sym_interpret *interp;
@@ -1399,8 +1399,8 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
     xkb_mod_mask_t vmodmask = 0;
     int num_acts = 0;
     xkb_group_index_t group;
-    int level;
-    int i;
+    xkb_level_index_t level;
+    unsigned int i;
 
     /* If we've been told not to bind interps to this key, then don't. */
     if (key->explicit & XkbExplicitInterpretMask)
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index ffb02e1..8a79f00 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -509,7 +509,7 @@ ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
 
 bool
 ExprResolveLevel(struct xkb_context *ctx, const ExprDef *expr,
-                 unsigned int *level_rtrn)
+                 xkb_level_index_t *level_rtrn)
 {
     bool ok;
     int result;
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index 1432838..7a2bf78 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -76,7 +76,7 @@ ExprResolveInteger(struct xkb_context *ctx, const ExprDef *expr,
 
 bool
 ExprResolveLevel(struct xkb_context *ctx, const ExprDef *expr,
-                 unsigned int *level_rtrn);
+                 xkb_level_index_t *level_rtrn);
 
 bool
 ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 781681a..aa7c365 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -53,7 +53,7 @@ typedef struct _KeyTypeInfo {
     xkb_atom_t name;
     xkb_mod_mask_t mask;
     xkb_mod_mask_t vmask;
-    unsigned numLevels;
+    xkb_level_index_t numLevels;
     darray(struct xkb_kt_map_entry) entries;
     struct list preserves;
     darray(xkb_atom_t) lvlNames;
@@ -491,7 +491,7 @@ AddMapEntry(KeyTypesInfo *info, KeyTypeInfo *type,
     if ((old = FindMatchingMapEntry(type, new->mods.real_mods,
                                     new->mods.vmods))) {
         if (report && (old->level != new->level)) {
-            unsigned use, ignore;
+            xkb_level_index_t use, ignore;
             if (clobber) {
                 use = new->level + 1;
                 ignore = old->level + 1;
@@ -634,7 +634,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
 
 static bool
 AddLevelName(KeyTypesInfo *info, KeyTypeInfo *type,
-             unsigned level, xkb_atom_t name, bool clobber)
+             xkb_level_index_t level, xkb_atom_t name, bool clobber)
 {
     if (level >= darray_size(type->lvlNames))
         darray_resize0(type->lvlNames, level + 1);
@@ -670,7 +670,7 @@ static bool
 SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
              ExprDef *value)
 {
-    unsigned level;
+    xkb_level_index_t level;
     xkb_atom_t level_name;
     struct xkb_context *ctx = info->keymap->ctx;
     const char *str;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 8295371..83f63da 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -24,8 +24,6 @@
  *
  ********************************************************/
 
-#include <limits.h>
-
 #include "xkbcomp-priv.h"
 #include "parseutils.h"
 #include "action.h"
@@ -72,7 +70,7 @@ typedef struct _KeyInfo {
     unsigned char typesDefined;
     unsigned char symsDefined;
     unsigned char actsDefined;
-    unsigned int numLevels[XkbNumKbdGroups];
+    xkb_level_index_t numLevels[XkbNumKbdGroups];
 
     /* syms[group] -> Single array for all the keysyms in the group. */
     darray_xkb_keysym_t syms[XkbNumKbdGroups];
@@ -249,10 +247,11 @@ FreeSymbolsInfo(SymbolsInfo * info)
 }
 
 static bool
-ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group, unsigned int numLevels,
-               unsigned sizeSyms, bool forceActions)
+ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group,
+               xkb_level_index_t numLevels, unsigned sizeSyms,
+               bool forceActions)
 {
-    int i;
+    xkb_level_index_t i;
 
     if (darray_size(keyi->syms[group]) < sizeSyms)
         darray_resize0(keyi->syms[group], sizeSyms);
@@ -292,10 +291,10 @@ MergeKeyGroups(SymbolsInfo * info,
     darray_xkb_keysym_t resultSyms;
     enum key_group_selector using = NONE;
     darray_xkb_action resultActs;
-    unsigned int resultWidth;
+    xkb_level_index_t resultWidth;
     unsigned int resultSize = 0;
     int cur_idx = 0;
-    int i;
+    xkb_level_index_t i;
     bool report, clobber;
     int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
 
@@ -852,8 +851,9 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
                 ExprDef *value)
 {
     xkb_group_index_t ndx;
-    size_t nSyms, nLevels;
-    size_t i;
+    size_t nSyms;
+    xkb_level_index_t nLevels;
+    xkb_level_index_t i;
     int j;
 
     if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
@@ -1471,8 +1471,8 @@ static struct xkb_key *
 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
 {
     struct xkb_key *key, *ret = NULL;
-    xkb_group_index_t group, min_group = UINT_MAX;
-    unsigned int level, min_level = UINT_MAX;
+    xkb_group_index_t group, min_group = UINT32_MAX;
+    xkb_level_index_t level, min_level = UINT16_MAX;
 
     xkb_foreach_key(key, keymap) {
         for (group = 0; group < key->num_groups; group++) {
@@ -1553,7 +1553,7 @@ FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
  *        symbol per level.
  */
 static bool
-FindAutomaticType(struct xkb_keymap *keymap, int width,
+FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
                   const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
                   bool *autoType)
 {
@@ -1605,7 +1605,8 @@ static void
 PrepareKeyDef(KeyInfo *keyi)
 {
     xkb_group_index_t i, lastGroup;
-    int j, width, defined;
+    unsigned int defined;
+    xkb_level_index_t j, width;
     bool identical;
 
     defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
@@ -1722,7 +1723,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
     struct xkb_key *key;
     size_t sizeSyms = 0;
     xkb_group_index_t i, nGroups;
-    unsigned width, tmp;
+    xkb_level_index_t width, tmp;
     struct xkb_key_type * type;
     bool haveActions, autoType, useAlias;
     unsigned types[XkbNumKbdGroups];