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>
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
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];