keymap: move ModNameToIndex from text.c and use it in keymap.c

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: rename wrap_group_into_range -> XkbWrapGroupIntoRange

It better fits with the naming convention in keymap.h.

Signed-off-by: Ran Benita <ran234@gmail.com>
Add struct xkb_mod_set

The only thing that the compilation phase needs the keymap for currently
is for access to the modifier information (it also modifies it in
place!). We want to only pass along the neccessary information, to make
it more tractable and testable, so instead of passing the entire keymap
we add a new 'mod_set' object and pass a (const) reference to that.
The new object is just the old array of 'struct xkb_mod'.

Signed-off-by: Ran Benita <ran234@gmail.com>
text: take xkb_mod_set instead of the entire keymap

The modifier printing functions only need the modifier information, they
don't care about keys or leds, etc.

Signed-off-by: Ran Benita <ran234@gmail.com>
expr: take xkb_mod_set instead of the entire keymap

The modifier-resolving functions only need the modifier information.

Signed-off-by: Ran Benita <ran234@gmail.com>
action: take xkb_mod_set instead of the entire keymap

A couple of modiifer actions need this information, but not the entire
keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
vmod: take xkb_mod_set instead of the entire keymap

This is the only place where the modifier information is modified. We
will make it local to a given XKB file (after which it will be merged
into the keymap). Currently it changes the keymap directly, which
sidesteps the abstraction and leaves side-effects even if the XkbFile's
compilation fails.

Signed-off-by: Ran Benita <ran234@gmail.com>
compat: use xkb_mod_set instead of entire keymap

Signed-off-by: Ran Benita <ran234@gmail.com>
types: use xkb_mod_set instead of entire keymap

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: use xkb_mod_set instead of entire keymap

The keymap is not removed entirely from the Info (just constified),
since it is still needed in AddKeySymbols() for looking up aliases. This
dependency will be removed in the future.

Signed-off-by: Ran Benita <ran234@gmail.com>
utils: detect overflow in memdup()

Signed-off-by: Ran Benita <ran234@gmail.com>
darray: remove unused darray_foreach_reverse()

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: protect xkb_foreach_key macro params

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: rename xkb_foreach_key to xkb_keys_foreach

We'll use the format xkb_foos_foreach and xkb_foos_enumerate for the
various iterators.

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: add and use xkb_mods_{foreach,enumerate}()

To iterate over an xkb_mod_set. Slightly nicer interface and makes
transitioning from darray easier.

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: don't use darray in xkb_mod_set

Instead just statically allocate the mods array (of size MAX_MOD_SIZE =
32). The limit is not going anywhere, and static allocations are nicer
(nicer code, no OOM, etc.). It's also small and dense enough.

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap, keycodes, compat: don't use darray for LEDs

Use a static array of size XKB_MAX_LEDS instead, as in xkb_mod_set.

Signed-off-by: Ran Benita <ran234@gmail.com>
xkbcomp: use straight assignment instead of CopyModSet

Signed-off-by: Ran Benita <ran234@gmail.com>
xkbcomp: don't align enum values

Signed-off-by: Ran Benita <ran234@gmail.com>
keycodes: fix uninitialized variable

Happened in one of the previous commits. For some reason, gcc doesn't
warn about this, but clang does...

Signed-off-by: Ran Benita <ran234@gmail.com>