Commit Graph

1840 Commits (faac4ba7de5ae805a612eb1236a17087e392c7c3)

Author SHA1 Message Date
Ran Benita faac4ba7de test/data: ensure files are checked out with LF, not CRLF
The tests stringcomp and buffercomp do binary comparison on some files;
if the files are changed to CRLF on checkout, the tests fail.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 15:59:47 +02:00
Adrian Perez de Castro b30bf21c82 CI: some tweaks
[ran: extracted generic bits from Windows commit.]

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 15:32:30 +02:00
Ran Benita fadfb13c42 xkbcomp/rules: support \r\n line endings
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 14:19:22 +02:00
Ran Benita d1e39c111e test/atom: use correct format specifier for size_t
From MSVC:

test\atom.c(98): note: consider using '%zu' in the format string
test\atom.c(98): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 1 has type 'size_t'
test\atom.c(100): note: consider using '%zu' in the format string
test\atom.c(100): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 1 has type 'size_t'
test\atom.c(114): note: consider using '%zu' in the format string
test\atom.c(114): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 1 has type 'size_t'
test\atom.c(128): note: consider using '%zu' in the format string
test\atom.c(128): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 1 has type 'size_t'
test\atom.c(130): note: consider using '%zu' in the format string
test\atom.c(130): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 1 has type 'size_t'
test\atom.c(137): note: consider using '%zu' in the format string
test\atom.c(137): warning C4477: 'fprintf' : format string '%lu' requires an argument of type 'unsigned long', but variadic argument 2 has type 'size_t'

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 14:13:52 +02:00
Ran Benita da4a90c13e Open files in binary mode
This turns off some misfeatures on Windows, and does nothing on POSIX.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 13:49:40 +02:00
Ran Benita fe417d841e test/common: avoid double // in path
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 13:40:38 +02:00
Ran Benita eb23982cab test/common: simplify test_get_path()
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 13:39:33 +02:00
Ran Benita 521bb498ed xkbcomp: remove cast which triggers warning on gcc
Will need some other way to take care of the warning on MSVC.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 22:09:34 +02:00
Ran Benita fbd0e643d8 xkbcomp: make a couple of casts explicit to mark them as checked
This acknowledges some "possible loss of data cast" warnings from MSVC.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 21:55:14 +02:00
Ran Benita f967d46b65 test/context: use a more portable directory-exists check
MSVC doesn't have opendir/closedir.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:47:49 +02:00
Ran Benita 1849158afd xkbcomp/keywords: regenerate with newer gperf
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +02:00
Ran Benita 823708b73e parser: fix format string for int64_t
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +02:00
Ran Benita 670566f0d4 Only add GCC diagnostic pragmas when compiler is GCC compatible
Avoid "unknown pragma" warnings on other compilers.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +02:00
Ran Benita 40bea8e9fa xkbcomp: fix wrong return type
Detected by MSVC:

xkbcomp\xkbcomp.c(111): warning C4047: 'return': 'bool' differs in levels of indirection from 'void *'

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:04:40 +02:00
Ran Benita 6ca1a0c9f6 parser: use int64_t for all numbers
Don't use int which can have different size on different machines.
Also avoid some warnings from MSVC:

xkbcomp/parser.y(760): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data
xkbcomp/parser.y(761): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data
xkbcomp/parser.y(767): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 14:17:55 +02:00
Ran Benita c3ac58a941 scanner-utils: avoid possible implicit truncating of line/column
This increases the size of the struct a bit but it's not very important.

Fixes these MSVC warnings:

src\scanner-utils.h(112): warning C4267: '+=': conversion from 'size_t' to 'unsigned int', possible loss of data
src\scanner-utils.h(147): warning C4267: '+=': conversion from 'size_t' to 'unsigned int', possible loss of data

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 14:06:47 +02:00
Ran Benita 0fdd29bb7b utils: move macro defines to before they're used
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:55:24 +02:00
Ran Benita 64137a4ab5 utils: fix typo in strndup fallback
Fixup 93a1305 - we will have CI for this soon.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:52:51 +02:00
Adrian Perez de Castro d59ff39d22 meson.build: Take win_bison as a possible variant for Bison
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:21:34 +02:00
Ran Benita 40aab05e77 build: include config.h manually
Previously we included it with an `-include` compiler directive. But
that's not portable. And it's better to be explicit anyway.

Every .c file should have `include "config.h"` first thing.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:09:11 +02:00
Adrian Perez de Castro bdff8ebe3c Provide a fallback implementation of [v]asprintf()
Some environments (e.g. Windows + MSVC) do not provide asprintf() or
vasprintf(). This tries to detect their presence, and provides suitable
fallback implementations when not available.
2019-12-27 12:45:34 +02:00
Adrian Perez de Castro 93a13050d6 Provide a fallback implementation of strndup()
Some environments (e.g. Windows + MSVC) do not provide strndup(), this
tries to detect its presence and provide a fallback implementation when
not available.

[ran: some tweaks]
2019-12-27 12:45:14 +02:00
Adrian Perez de Castro a8acc2ff5c Use built-in istr[n]cmp() instead of strcase[n]cmp()
This avoids the problem that MSVC does not provide strcasecmp() nor
strncasecmp(), and at the same time avoids potential problems due to
locale configuration by using istrcmp() and istrncmp() which are
already in the source tree and written to cover only ASCII.
2019-12-27 12:36:39 +02:00
Ran Benita 34122f9f06 utils: use MIN/MAX instead of min/max
min/max symbols conflict on some systems (msvc), so just use the macros.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 12:34:49 +02:00
Ran Benita ade131307c xkbcomp: downgrade "Symbol added to modifier map for multiple modifiers" log to a warning
This condition happens in xkeyboard-config keymaps and seems hard to
fix. Currently it incessantly spams people's logs who have no idea what
to do about it. So downgrade to "warning" level, so it doesn't show up
by default.

When working on keymaps, set `XKB_LOG_LEVEL=debug XKB_LOG_VERBOSITY=10`
to see all possible messages.

Refs https://github.com/xkbcommon/libxkbcommon/issues/111
Fixes https://github.com/xkbcommon/libxkbcommon/issues/128
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 12:26:35 +02:00
Peter Hutterer 00f31e0d27 rules: eliminate an extra fopen/fclose cycle
FindXkbFileInPath() opens the file so we're guaranteed that the file not only
exists, but that we can read it. Changing that would alter behavior so instead
let's just pass that file handle along and do the same for include files.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer ca033a29d2 rules: add include statements to rules files
The majority use-case for extending XKB on a machine is to override one or a
few keys with custom keycodes, not to define whole layouts.

Previously, we relied on the rules file to be a single file, making it hard to
extend. libxkbcommon parses $XDG_CONFIG_HOME/xkb/ but that only works as long
as there is a rule that matches the user-specified RMLVO. This works for MLV
but not for options which don't have a wildcard defined. Users have to copy
the whole rules file and then work from there - not something easy to extend
and maintain.

This patch adds a new ! include directive to rules files that allows including
another file. The file path must be without quotes and may not start with the
literal "include". Two directives are supported, %H to $HOME and %S for the
system-installed rules directory (usually /usr/share/X11/xkb/rules).

A user would typically use a custom rules file like this:

! option                =       symbols
  custom:foo            =       +custom(foo)
  custom:bar            =       +custom(baz)

! include %S/evdev

Where the above defines the two options and then includes the system-installed
evdev rule. Since most current implementations default to loading the "evdev"
ruleset, it's best to name this $XDG_CONFIG_HOME/xkb/rules/evdev, but any
valid name is allowed.

The include functionally replaces the line with the content of the included
file which means the behavior of rules files is maintained. Specifically,
custom options must be defined before including another file because the first
match usually wins. In other words, the following ruleset will not assign
my_model as one would expect:

! include %S/evdev

! model                 =  symbols
  my_model              =  +custom(foo)

The default evdev ruleset has wildcards for model and those match before the
my_model is hit.

The actual resolved components need only be in one of the XKB lookup
directories, e.g. for the example above:

$ cat $XDG_CONFIG_HOME/xkb/symbols/custom
partial alphanumeric_keys
xkb_symbols "foo" {
    key <TLDE> {        [      VoidSymbol ]       };
};

partial alphanumeric_keys
xkb_symbols "baz" {
    key <AB01> {        [      k, K ]       };
};

This can then be loaded with the XKB option "custom:foo,custom:bar".

The use of "custom" is just as an example, there are no naming requirements
beyond avoiding already-used ones. Also note the bar/baz above - the option
names don't have to match the component names.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 67b538ddc0 context: add a helper function to return the default system include path
No functional changes but we'll need that same lookup in the rules file
include handling in a future patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 3c57b3289a rules: move the matcher result handling to the caller
This shouldn't be processed in the matcher itself, especially in the glorious
future when we can have nested matchers. Only handle this once in the caller
to the original parsed file.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 2ec07b62b5 rules: put the scanner on the stack
This allows nesting the scanner for the future !include directive.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer bb7551a649 rules: simplify an error path
Initialize to NULL so we don't have to care about whether the cleanups can be
called or not.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer d9b9885624 rules: rename a variable from 's' to 'str'
To avoid name conflicts with a future patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 2a578a60b3 rules: drop the matcher_err() macro and use scanner_err directly
No functional changes, this is what the macro expanded to anyway. Prep work
for putting the scanner on the stack and removing it from the matcher struct.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer f57c13ea4f rules: factor out the function to parse a rules file
No functional changes, this just makes the part to parse a single rules file
re-usable.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 13b30f4f0d keysym: handle ssharp in XConvertCase()
lowercase: LATIN SMALL LETTER SHARP S (U+00DF)
uppercase: LATIN CAPITAL LETTER SHARP S (U+1E9E)

The uppercase sharp s (XK_ssharp) is a relatively recent addition to unicode
but was added to the relevant keyboard layouts in xkeyboard-config-2.25
(d1411e5e95c)
https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/issues/144

Alas, the CapsLock behavior was broken on the finnish layout (maybe others).
This was due XConvertCase() never returning the uppercase characters.

Let's make this function return the right lower/upper symbols for the sharp s
and hope that the world won't get any worse because of it.

Corresponding Xlib issue:
https://gitlab.freedesktop.org/xorg/lib/libx11/issues/110

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-22 10:12:53 +02:00
Ran Benita 068e38edca meson: remove redundant malloc scribbling
Turns out meson already sets this (at least MALLOC_PERTURB) on its own
for the `test` target.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-14 13:48:10 +02:00
Ran Benita a237f4f699 parser: fix the remaining pointer chasing
Fix the TODO added in 7c42945.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-14 13:45:05 +02:00
Peter Hutterer 1de2f174c2 test: let rmlvo-to-kccgst take long options like rmlvo-to-keymap
The short options were left for backwards compatibility.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-18 15:32:35 +02:00
Ran Benita 7c42945e04 parser: fix quadratic pointer chasing
In the AST, lists (e.g. the list of statements in a file) are kept in
singly-linked lists -- each AST node has a `next` pointer available for
this purpose.

Previously, a node was added to the list by starting from the head,
chasing to the last, and appending. So creating a list of length N would
take ~N^2/2 pointer dereferences.

Now, we always (temporarily) keep the last as well, so appending is O(1)
instead of O(N).

Given a keymap

    xkb_keymap {
    xkb_keycodes {
    minimum = 8;
    minimum = 8;
    minimum = 8;
    minimum = 8;
    minimum = 8;
    [... repeated N times ...]
    };
    xkb_types {};
    xkb_compat {};
    xkb_symbols {};
    };

The compilation times are

N       | Before   | After
--------|----------|-------
10,000  | 0.407s   | 0.006s
20,000  | 1.851s   | 0.015s
30,000  | 5.737s   | 0.021s
40,000  | 12.759s  | 0.023s
50,000  | 21.489s  | 0.035s
60,000  | 40.473s  | 0.041s
70,000  | 53.336s  | 0.039s
80,000  | 72.485s  | 0.044s
90,000  | 94.703s  | 0.048s
100,000 | 118.390s | 0.057s

Another option is to ditch the linked lists and use arrays instead. I
got it to work, but its more involved and allocation heavy so turns out
to be worse without further optimizations.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-14 22:10:09 +02:00
Ran Benita f9b95c06c1 parser: remove an unneeded check
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-14 22:10:09 +02:00
Peter Hutterer 59d2a71383 docs: update the include path documentation
Missing from e23f1061b2 and
3a91788d92.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-14 10:17:46 +02:00
Ran Benita 3d43f4806d compat: reject interpret modifier predicate with more than one value
Given

    interpret ISO_Level3_Shift+AnyOf(all,extraneous) { ... };

Previously, extraneous (and further) was ignored. Now it's rejected.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:31:46 +02:00
Ran Benita 7d44c7a9f9 expr: fix log message on some unexpected expression types
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:09:19 +02:00
Ran Benita 406beecae5 Replace some tabs that sneaked in with spaces
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:06:02 +02:00
Ran Benita 322cd8563c parser: fix merge mode only applied to first vmod in a virtual_modifiers statement
Given

    augment virtual_modifiers NumLock,Alt,LevelThree

Previously it was expanded (directly in the parser) to

    augment virtual_modifiers NumLock;
    virtual_modifiers Alt;
    virtual_modifiers LevelThree;

Now it expands to

    augment virtual_modifiers NumLock;
    augment virtual_modifiers Alt;
    augment virtual_modifiers LevelThree;

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 20:37:09 +02:00
Ran Benita 400cc84911 ast: use a separate expr struct for action list
Currently it's under UnaryExpr, which just doesn't make sense.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 20:07:12 +02:00
Ran Benita 8c62d48c0c ast-build: get rid of unhelpful macro
Straightforward code is better here.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 19:16:08 +02:00
Ran Benita 4849bc1914 atom: a string is greater than its prefix
Bug accidentally introduced in 9a92b46.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 22:11:22 +02:00
Ran Benita c79c80335b atom: combine atom_intern() and atom_lookup()
Use an "add" bool parameter instead. This simplifies the code a bit.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 21:28:43 +02:00
Ran Benita adbd9c6f08 atom: correct iteration count in hash function
Fixup of ccab349 - unlike the commit message, hash a byte twice instead
of zero times, which is probably better. This is how it was before.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 13:50:59 +02:00