Only the input/output functions from <unistd.h> options are used, so
using <io.h> when building with MSVC should be enough. The inclusion
of the header in context-priv.c does not seem to be needed (tested
on GNU/Linux) and so it is removed.
Signed-off-by: Ran Benita <ran@unusedvar.com>
This is a stopgap measure to quickly get tests building with MSVC for
now, at some point the tests could be rewritten to avoid using getopt()
and mkdtemp() or to ship an implementation.
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>
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>
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>
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>
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>
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>
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.
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]
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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>