state: remove unused next field from xkb_filter

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: use darray for ModMapEntry instead of list

There's no need for a list here.
[This also happens to be the last place list.h is used.]

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap-dump: don't write spaces between multiple-syms-per-level

This can get a bit unwieldy.

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

GroupInfo keeps all of the info for a specific group in one struct.
This is the old array-of-structures vs. structure-of-arrays, but in this
case readability wins. It would also help with lifting the
XkbNumKbdGroups limit, because we only have to worry about one array
(instead of 6).

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: consolidate group merging in MergeGroups

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: shorten symsMapNumEntries to uint from size_t

size_t is too wide for this in 64-bit machines.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: make xkb_key::syms a plain array

It's never resized.

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

Add a LevelInfo to hold a single array of level specific info inside
a GroupInfo, instead of keeping the acts, symsMapIndex and
symsMapNumEntries arrays and the numLevels field separate and in sync.
This simplifies the code, and goes a long way toward making  the
key-merging code somewhat understandable. Also uses less memory.

Note that the syms array is still in GroupInfo for now, with the levels
holding offsets into it.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: remove unneeded recursion form CopySymbolsDef

This function does some funky stuff, which, as far as I can tell, was
needed to support the functionality of giving different keycodes the
same name and thus make them duplicates (MERGE_ALT_FORM). This stuff was
removed as useless in 0765064b3, but this leftover wasn't noticed.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: remove mention of keycodes in CopySymbolsDef

Since now we only use the keycode in this function for logging, it's
better not to mention the keycode at all because the XkbKeyGetKeycode
macro is implemented using a dirty hack 0_0
The key name is sufficient to determine uniquely where to look.

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

Like in the other sections.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: fix real/alias key merge ordering bug

Background:

The CopySymbolsDef has a comment on a couple of lines which supposedly
fixed a bug:

    /*
     * kt_index[i] may have been set by a previous run (if we have two
     * layouts specified). Let's not overwrite it with the ONE_LEVEL
     * default group if we dont even have keys for this group anyway.
     *
     * FIXME: There should be a better fix for this.
     */
    if (!darray_empty(groupi->levels))
        key->kt_index[i] = types[i];

But neither the comment nor the fix make any sense, because the kt_index
is indexed per group, i.e. each group gets its own type.
The original xkbcomp commit which added this (36fecff58) points to this
bug: https://bugzilla.redhat.com/show_bug.cgi?id=436626
which complains about -layout "ru,us" -variant "phonetic," not working
properly. And indeed when we try:
    sudo ./test/interactive -l ru,us -v
the first group doesn't get any syms for the main keys.

The problem (Clearly the fix above is useless):

The ru(phonetic) map is specified using aliases, e.g. LatQ, LatW instead
of AD01, AD02, etc. When combined with another layout which uses the
real names (AD01, AD02), the symbols code should recognize they are the
same key and merge them into one KeyInfo. The current code does that,
but it doesn't catch the case where the alias was processes *before* the
real one; so we get two KeyInfo's and the later one wins. So e.g. the
ru(phonetic) symbols are ignored.

The fix:

Before adding a new KeyInfo to the keys array, always replace its name
by the real name, which avoids the entire issue. Luckily this is done
pretty late so most error messages should still show the alias name.

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

The code is better without it.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: store actions from symbols in the right offset

This regression was introduced in 93ce9c7d4f7. This meant that actions
specified inside key {} statments were always going to the first group.
But actions are almost never specified in xkb_symbols so this wasn't
noticed.

Signed-off-by: Ran Benita <ran234@gmail.com>
keyseq: test that de(neo) is working properly

This layout stretches us pretty well, so it's good for testing nothing
breaks. There are a couple of things that need looking into, though
(particularly the level5 issue).

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: FindAutomaticType only needs the context

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

To make it easier to follow.

Signed-off-by: Ran Benita <ran234@gmail.com>
Clean up Init/Clear functions

- The Clear* functions should just free the memory associated with the
  object. If the object is used again, it is Init'd again.
- s/Free/Clear if the actual pointer is not free'd.
- Zeroise object in Init and only initialize non-zero fields.

Signed-off-by: Ran Benita <ran234@gmail.com>
rules: fix mmap failure handling

Signed-off-by: Ran Benita <ran234@gmail.com>
state, map: use keycodes only for the API functions

The policy is now consistent: every API functions which recieves a
keycode should resolve it to an xkb_key first thing, and all the
internal functions use that instead of the keycode.
To facilitate it a bit, we move the KeycodeInRange check to XkbKey
itself, which returns NULL if the keycode is illegal.

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