Commit Graph

1166 Commits (bac0c323b6559e37af04c4d6c8eb118d926ce07c)

Author SHA1 Message Date
Ran Benita f774f819d6 Replace some strncmp's with memcmp
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-18 13:23:53 +03:00
Ran Benita a4cc119bf5 compose/parser: save len in keysym_from_name cache
This reduces a lot of strcmp's, and allows to use a faster memcmp.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-18 13:05:18 +03:00
Ran Benita 30e7445d84 state: correctly infer inactive type entries
The current test is incorrect, since 'map[None]' is entirely valid. In
most cases this doesn't cause any problems, since the default fallback
is Level1, and it's almost always 'map[None] = Level1' anyway. But in
one case in xkeyboard-config it isn't, in types/numpad(mac):

    type "KEYPAD" {
        modifiers = None;
        map[None] = Level2;
        level_name[Level2] = "Number";
    };

So before checking if no modifiers were mapped, make sure there *were*
any modifiers at all.

https://bugs.freedesktop.org/show_bug.cgi?id=85092

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:17:59 +03:00
Ran Benita a4c667adf2 symbols: don't warn about conflicting syms if they are the same
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:17:14 +03:00
Ran Benita 2e5530ad20 parser: bring back warning about includes of files with no default
Using the same format as xkbcomp.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:17:14 +03:00
Ran Benita c6e63fd71c compose/parser: fix parsing of multiple modifiers
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-14 11:28:57 +03:00
Ran Benita d1c5dd14e0 compose/parser: parse (! mods) properly
We don't actually do anything with them. But if someone uses them we can
at least not choke.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:56:57 +03:00
Ran Benita 3c0c3afa09 compose/parser: resolve keysyms in parser instead of scanner
It will become context-sensitive.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:56:50 +03:00
Ran Benita 0b99c63cf4 compose/parser: use parameter as intended
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:54:58 +03:00
Ran Benita 8bba4b34ec compose/parser: one more skip_to_eol()
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:54:52 +03:00
Ran Benita a3116f97d0 compose/parser: fix segfault when including
The keysym cache for the new scanner was not initialized.
To avoid such errors also in the future, require passing the priv
argument in scanner_init(), instead of initializing it separately.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:54:52 +03:00
Ran Benita 65c355aa7a COPYING: add copyright notice from libX11:modules/im/ximcp/imLcPrs.c
We have used some portions of it, so add the notice.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-13 18:54:52 +03:00
Ran Benita 8a0acf2c67 scanner-utils: optimize one-line comments
Compose files have a lot of those.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-08 00:03:34 +03:00
Ran Benita edc98b5403 compose: add xkbcommon-compose - implementation
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-05 12:56:46 +03:00
Ran Benita 29a1a78008 scanner-utils: add priv member
For when a user of the scanner wants to pass something along with it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-03 00:15:39 +03:00
Ran Benita e8b112325c darray: add darray_shrink()
If we have a big array which can be finalized, on average we can give
back 1/4 of its size, which the allocator might be able to use.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-03 00:15:39 +03:00
Ran Benita b3f2396588 keysym: add function to test if a keysym is for a modifier
Needed for compose.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-03 00:15:36 +03:00
Ran Benita 94a8e01c52 scanner-utils: add helper for appending an entire string
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-02 22:21:06 +03:00
Ran Benita 8eb024d589 scanner-utils: add helper for hex string escape
Like the already existing oct.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-02 22:21:06 +03:00
Ran Benita 4ed68120de scanner-utils: optimize str()/lit()
Replace the dog-slow unneeded strncasecmp() with an inlineable memcmp().

Before:
compiled 2500 keymaps in 8.348715629s

After:
compiled 2500 keymaps in 7.872640338s

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-01 19:24:36 +03:00
Ran Benita 725ae134d4 keymap: rename XkbKeyGroupWidth to XkbKeyNumLevels
The "width" terminology comes from the group*width+level layout of the
keysyms in a key, as used in the old implementations. We don't keep all
the keysyms of a key in one array so change it to a more accurate name.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-25 22:01:17 +03:00
Ran Benita 2c259f1782 symbols: improve FindKeyForSymbol()
A bit more involved, but can short circuit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-25 21:55:52 +03:00
Ran Benita 485b736f17 symbols: use correct max value
xkb_level_index_t was initially uint16_t, now it's 32.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-25 21:26:26 +03:00
Ran Benita 68962aa1f9 keymap-dump: combine modifier_map's with the same modifier
A bit less efficient, but makes for shorter, nicer output.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-22 00:05:38 +03:00
Ran Benita 0224283fdf rules: fix mlvo-not-used warning
An mlvo can also be used in an expansion, but we didn't mark them in
this case in commit d8a4f52cb9. This caused wrongful warnings on
something like -l ch -v fr -- the `fr` is only added via expansion.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-21 17:09:58 +03:00
Ran Benita d8a4f52cb9 rules: warn when an RMLVO component isn't used
Due to wildcard matches in the rules file, this is only really useful
for misspelled or missing options, e.g.

$ ./test/rmlvo-to-kccgst -o comprose:ralt > /dev/null
xkbcommon: ERROR: Unrecognized RMLVO option "comprose:ralt" was ignored

Although it is more of a warning, it indicates a misconfiguration which
the user probably wants to see. Therefore the log level is ERROR.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-20 16:18:26 +03:00
Ran Benita d0c6fce24d parser: use "atom" instead of "sval" in yylval
"sval" is already used for "struct sval".

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-20 15:06:13 +03:00
Ran Benita 1054962d4c symbols: use darray_foreach_from for nicer loop
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-11 02:57:37 +03:00
Ran Benita f03dcf9fb6 Remove compatibility symbols
Remove the deprecated symbols that were used for ABI compatibility
during the transition period to the first stable version, 0.2.0.

The old *names* can still be used, programs which use the old names will
continue to work, as long as they were compiled against a stable
version (as they have been #defined to the new names from the start; see
xkbcommon/xkbcommon-compat.h). Namely, this will break binaries which:

1. Were compiled against a pre-stable version of libxkbcommon, and
2. Are linked against the next version of libxkbcommon, and
3. Expect to work.

This scenario is very unlikely, and will break in many other ways
anyway. Also, retaining support for these means including them in the
new symbol version file, which I would like to avoid.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-10 19:11:41 +03:00
Ran Benita a931740cc7 keycodes: fix keymap compilation with no aliases and malloc(0)==NULL
If the keymap doesn't have any key-aliases (which is certainly
possible), the calloc(num_key_aliases, ...) is allowed to return NULL
according to the C standard, but this is not an error.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-10 13:44:33 +03:00
Ran Benita 7a87c202b7 ast-build: fix leak in error path
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-10 13:10:33 +03:00
Ran Benita a1f0595a68 state: make sure the mods are fully resolved after xkb_state_update_mask()
Virtual modifiers can have "mappings" to real modifiers, e.g. NumLock
may also set Mod2. In a normal turn of events, the various components
(depressed, latched, locked, and consequently effective) include the
mapped mods, because the masks are pre-resolved everywhere. However,
xkb_state_update_mask() accepts arbitrary mod masks, which may not be
resolved (if it comes from somewhere other than
xkb_state_serialize_mods()). So let's always resolve them ourselves.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-18 21:46:39 +03:00
Ran Benita 99184f1614 Make the effective mod mask calculation available to other files
We will want to use that function in state.c as well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-18 20:26:19 +03:00
Ran Benita 80ae8e61ff state: no need for loop in xkb_state_update_mask()
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-18 20:08:53 +03:00
Ran Benita 56de0115e6 x11/keymap: handle private actions
Previously we treated them as NoAction().

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-09 22:42:45 +03:00
Ran Benita ead816e515 utils: add a STATIC_ASSERT macro
It'd be nicer to use C11's static_assert(), but it's easier to roll our
own C99 version using a trick I saw in xv6.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-09 22:42:45 +03:00
Ran Benita d38ff018b1 keymap: remove "flags" field of xkb_private_action
Private actions have no flags - only serialized data.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-09 22:42:45 +03:00
Ran Benita f00e779ab5 x11/keymap: be more defensive about the number of modifiers
There can be at most 16 vmods, and we rely on the facts that #vmods +
NUM_REAL_MODS (8) <= XKB_MAX_MODS (32) when accessing keymap->mods.mods.
But msb_pos() can potentially return up to #vmods = 32 if the server is
malicious, so we need to truncate it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-08 17:29:42 +03:00
Ran Benita 01753c0475 x11/keymap: don't forget to add the vmod offset in get_vmods
The first 8 modifiers in keymap->mods are the real modifiers; the virtual
 modifiers are then at slots 8-24. But XkbGetMap's virtualMods mask
starts the virtual modifiers at zero, so we need to add an offset (like
we do correctly in get_vmod_names()).

https://github.com/xkbcommon/libxkbcommon/issues/9

Reported-by: @rtcm
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-08 16:50:11 +03:00
Ran Benita 40f109af56 ast-build: make sure InterpDef is freeable
With the following two rules:

    InterpretDecl   :       INTERPRET InterpretMatch OBRACE
                                VarDeclList
                            CBRACE SEMI
                            { $2->def = $4; $$ = $2; }
                    ;

    InterpretMatch  :       KeySym PLUS Expr
                            { $$ = InterpCreate($1, $3); }
                    |       KeySym
                            { $$ = InterpCreate($1, NULL); }
                    ;

And the fact that InterpCreate doesn't initialize ->def, if the
VarDeclList fails, the %destructor tries to recursively free the
uninitialized ->def VarDef. So always initialize it.

That was the only problematic code in the parser for %destructor (I'm
pretty sure).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-27 14:32:18 +03:00
Ran Benita 37cf20c906 parser: silence bison "unused value" warnings
Previous commit triggered these for some reason:

/home/ran/src/libxkbcommon/src/xkbcomp/parser.y:555.25-33: warning: unused value: $1 [-Wother]
 CoordList       :       CoordList COMMA Coord
                         ^^^^^^^^^

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 22:49:30 +03:00
Ran Benita 7ec00933c1 parser: don't leak AST nodes for discarded symbols
If the parser has symbols on the stack, and then enters an error, it
discards the symbols and fails. But their actions which allocate AST
nodes had already ran. So we must free these to avoid leaks.

We use %destructor declarations, see
http://www.gnu.org/software/bison/manual/html_node/Destructor-Decl.html

Note: byacc only supports %destructor when compiled with
--enable-btyacc. Also, it doesn't support using the parse-param in the
destructor. So we might revert this commit before the next release, or
forget about byacc.

https://github.com/xkbcommon/libxkbcommon/issues/8

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 22:46:01 +03:00
Ran Benita 61fed8dab9 Replace darray_mem with a new darray_steal
That's a more declarative interface.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 00:19:34 +03:00
Ran Benita fbd9286036 ast-build: use cast instead of ->common
Missed in 1b2bb204e0.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 00:13:54 +03:00
Ran Benita 5f5b960c71 types: refactor CopyKeyTypesToKeymap
So it's OOM-safe and doesn't clobber keymap on failure.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-25 23:45:04 +03:00
Ran Benita 320e5ffaf1 keycodes: split CopyKeyInfoToKeymap to several functions
It's a bit easier to read and self-documenting. Also handles OOM better.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-25 23:45:04 +03:00
Ran Benita cb4bae714e parser: don't shadow "str"
It's a name of a function in scanner-utils.h and also of some
parameters.

https://bugs.freedesktop.org/show_bug.cgi?id=79898

Reported-by: Bryce Harrington <b.harrington@samsung.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-30 14:52:30 +03:00
Ran Benita 9c30d6da4e x11: don't iterate on empty batches
If count % SIZE == 0 we did a useless iteration where start==stop. It's
harmless but strange, so don't do that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-15 15:30:51 +03:00
Ran Benita 67d884ec14 Remove unnecessary !!(expressions)
_Bool already does that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-01 15:24:10 +03:00
Ran Benita d6f2d8ecd0 rules: fix leak on failure
matcher_match() builds up the kccgst's, and we steal the memory on
success. But on error we didn't free it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-05-28 20:36:58 +03:00