summaryrefslogtreecommitdiff
path: root/src/xkbcomp
Commit message (Collapse)AuthorAgeFilesLines
* Add support for modmap None (#291)Wismill2023-05-012-9/+24
| | | | | | | | | | | | | | | | | | | Unlike current xkbcommon, X11’s xkbcomp allows to remove entries in the modifiers’ map using “modifier_map None { … }”. “None” is translated to the special value “XkbNoModifier” defined in “X11/extensions/XKB.h”. Then it relies on the fact that in "CopyModMapDef", the following code: 1U << entry->modifier ends up being zero when “entry->modifier” is “XkbNoModifier” (i.e. 0xFF). Indeed, it relies on the overflow behaviour of the left shift, which in practice resolves to use only the 5 low bits of the shift amount, i.e. 0x1F here. Then the result of “1U << 0xFF” is cast to “char”, i.e. 0. This is a good trick but too magical, so in libxkbcommon we will use an explicit test against our new constant XKB_MOD_NONE.
* context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312)Ronan Pigott2022-12-161-1/+1
| | | | | | | | | This flag is useful for clients that may have relatively benign capabilities set, like CAP_SYS_NICE, that also want to use the xkb configuration from the environment and user configs in XDG_CONFIG_HOME. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/308 Fixes: https://github.com/xkbcommon/libxkbcommon/issues/129 Signed-off-by: Ran Benita <ran@unusedvar.com>
* scanner: prefix functions with `scanner_` to avoid symbol conflictsRan Benita2022-03-142-80/+80
| | | | | | | | Particularly `eof()` in mingw-w64. Fixes: https://github.com/xkbcommon/libxkbcommon/pull/285 Reported-by: Marko Lindqvist Signed-off-by: Ran Benita <ran@unusedvar.com>
* ignore: remove no longer relevant gitignore filesRan Benita2021-05-221-2/+0
| | | | | | These were relevant for the autoconf build but now we're meson only. Signed-off-by: Ran Benita <ran@unusedvar.com>
* ast: remove comment re. anonymous structRan Benita2021-03-301-1/+0
| | | | | | | C11 is not sufficient for this, needs `--ms-extensions` which we don't want to enable. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: remove useless assignmentPeter Hutterer2021-03-301-1/+1
| | | | | | | | | ../../../src/xkbcomp/compat.c:693:16: warning: Although the value stored to 'merge' is used in the enclosing expression, the value is never actually read from 'merge' [deadcode.DeadStores] si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge); Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: use memcpy over strncpy to avoid analyzer warningsPeter Hutterer2021-03-301-4/+5
| | | | | | | | The target buffer is 7 bytes long, null-termination is optional (as the comment already suggests). Coverity is unhappy about this though so let's use memset and memcpy instead. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: plug a potential memory leakPeter Hutterer2021-03-191-3/+8
| | | | | | | | | | | | | | libxkbcommon-1.0.3/src/xkbcomp/ast-build.c:526: leaked_storage: Variable "file" going out of scope leaks the storage it points to. Where we exit the loop early, we don't release the various allocated memory. Make this patch more obvious my moving the declaration for those into the loop as well, this way we know that they aren't used outside the loop anywhere. Found by coverity Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* keymap-dump: follow xkbcomp in printing affect=both in pointer actionsRan Benita2020-11-231-4/+6
| | | | | | It is equivalent to nothing but good to match up. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: where a keysym cannot be resolved, set it to NoSymbolPeter Hutterer2020-10-201-1/+3
| | | | | | | | | | | | | | | | Where resolve_keysym fails we warn but use the otherwise uninitialized variable as our keysym. That later ends up in the keymap as random garbage hex value. Simplest test case, set this in the 'us' keymap: key <TLDE> { [ xyz ] }; And without this patch we get random garbage: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ 0x018a5cf0 ] }; With this patch, we now get NoSymbol: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ NoSymbol ] };
* parser: fix another format string for int64_t (#191)hhb2020-09-111-1/+1
|
* Add /etc/xkb as extra lookup path for system data filesPeter Hutterer2020-08-301-0/+7
| | | | | | | | | | | | | | | This completes the usual triplet of configuration locations available for most processes: - vendor-provided data files in /usr/share/X11/xkb - system-specific data files in /etc/xkb - user-specific data files in $XDG_CONFIG_HOME/xkb The default lookup order user, system, vendor, just like everything else that uses these conventions. For include directives in rules files, the '%E' resolves to that path. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: allow including kccgst files from other pathsPeter Hutterer2020-08-303-22/+49
| | | | | | | | | | | | | Previously, a 'symbols/us' file in path A would shadow the same file in path B. This is suboptimal, we rarely need to hide the system files - we care mostly about *extending* them. By continuing to check other lookup paths, we make it possible for a XDG_CONFIG_HOME/xkb/symbols/us file to have sections including those from /usr/share/X11/xkb/symbols/us. Note that this is not possible for rules files which need to be manually controlled to get the right bits resolved. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: simplify the include path handlingPeter Hutterer2020-08-301-18/+11
| | | | | | | Streamline the code a bit - instead of handling all the if (!file) conditions handle the case of where we have a file and jump to the end. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: move the logging of include paths into a helper functionPeter Hutterer2020-08-301-18/+26
| | | | | | No functional changes, prep work for some other refacturing. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: return NULL, not false in place of a FILE*Peter Hutterer2020-07-131-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: simplify buffer handling in the include handlingPeter Hutterer2020-07-131-23/+9
| | | | | | | | Don't do the realloc dance, just asprintf to the buffer and move on. The check is likely pointless anyway, if we run out of asprintf size, log_error will probably blow up as well. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp/rules: support \r\n line endingsRan Benita2019-12-281-1/+3
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* Open files in binary modeRan Benita2019-12-282-2/+2
| | | | | | This turns off some misfeatures on Windows, and does nothing on POSIX. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: remove cast which triggers warning on gccRan Benita2019-12-271-1/+1
| | | | | | Will need some other way to take care of the warning on MSVC. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: make a couple of casts explicit to mark them as checkedRan Benita2019-12-272-2/+5
| | | | | | This acknowledges some "possible loss of data cast" warnings from MSVC. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp/keywords: regenerate with newer gperfRan Benita2019-12-273-70/+109
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix format string for int64_tRan Benita2019-12-271-1/+1
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: fix wrong return typeRan Benita2019-12-271-1/+1
| | | | | | | | 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>
* parser: use int64_t for all numbersRan Benita2019-12-271-6/+4
| | | | | | | | | | | 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>
* build: include config.h manuallyRan Benita2019-12-2716-0/+31
| | | | | | | | | 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>
* utils: use MIN/MAX instead of min/maxRan Benita2019-12-271-2/+2
| | | | | | min/max symbols conflict on some systems (msvc), so just use the macros. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: downgrade "Symbol added to modifier map for multiple modifiers" log ↵Ran Benita2019-12-271-12/+12
| | | | | | | | | | | | | | | | 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>
* rules: eliminate an extra fopen/fclose cyclePeter Hutterer2019-12-241-15/+15
| | | | | | | | 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>
* rules: add include statements to rules filesPeter Hutterer2019-12-241-2/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* rules: move the matcher result handling to the callerPeter Hutterer2019-12-241-38/+37
| | | | | | | | 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>
* rules: put the scanner on the stackPeter Hutterer2019-12-241-58/+65
| | | | | | This allows nesting the scanner for the future !include directive. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* rules: simplify an error pathPeter Hutterer2019-12-241-3/+3
| | | | | | | 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>
* rules: rename a variable from 's' to 'str'Peter Hutterer2019-12-241-11/+11
| | | | | | To avoid name conflicts with a future patch. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* rules: drop the matcher_err() macro and use scanner_err directlyPeter Hutterer2019-12-241-17/+14
| | | | | | | 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>
* rules: factor out the function to parse a rules filePeter Hutterer2019-12-241-13/+36
| | | | | | | 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>
* parser: fix the remaining pointer chasingRan Benita2019-12-141-22/+21
| | | | | | Fix the TODO added in 7c42945. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix quadratic pointer chasingRan Benita2019-11-143-61/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* parser: remove an unneeded checkRan Benita2019-11-141-7/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* compat: reject interpret modifier predicate with more than one valueRan Benita2019-11-121-1/+1
| | | | | | | | | | 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>
* expr: fix log message on some unexpected expression typesRan Benita2019-11-121-0/+6
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* Replace some tabs that sneaked in with spacesRan Benita2019-11-121-5/+5
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix merge mode only applied to first vmod in a virtual_modifiers ↵Ran Benita2019-11-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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>
* ast: use a separate expr struct for action listRan Benita2019-11-125-4/+28
| | | | | | Currently it's under UnaryExpr, which just doesn't make sense. Signed-off-by: Ran Benita <ran@unusedvar.com>
* ast-build: get rid of unhelpful macroRan Benita2019-11-121-17/+36
| | | | | | Straightforward code is better here. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: get rid of "stealing" atomsRan Benita2019-11-081-2/+2
| | | | | | | | | This requires (well, at least implemented by) casting away `const` which is undefined behavior, and clang started to warn about it. The micro optimization didn't save too many allocations, anyway. Signed-off-by: Ran Benita <ran@unusedvar.com>
* keymap-dump: use consistent capitalization for "Group<N>"Ran Benita2019-10-161-2/+2
| | | | | | It's used capitalized everywhere except a couple places. Signed-off-by: Ran Benita <ran@unusedvar.com>
* keymap-dump: fix invalid names used for levels above 8Ran Benita2019-10-161-2/+2
| | | | | | | | | | | | xkbcomp only accepts the "Level" prefix for a level name for levels 1 to 8, but the keymap dumping code added it always, e.g. "Level15". The plain integer, e.g. "8", "15" is always accepted, so just use that. Fixes https://github.com/xkbcommon/libxkbcommon/issues/113 Signed-off-by: Ran Benita <ran@unusedvar.com> Reported-by: progandy
* symbols: add a comment to suppress warning from code analyzersKonstantin Kharlamov2019-03-231-0/+3
| | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Fix off-by-one error in index check in xkb_file_type_to_stringAlan Coopersmith2018-09-301-1/+1
| | | | | | | | | | | Found by Oracle's Parfait 2.2 static analyzer: Error: Buffer overrun Read outside array bounds [read-outside-array-bounds] (CWE 125): In array dereference of xkb_file_type_strings[type] with index type Array size is 56 bytes, index <= 56 at line 734 of src/xkbcomp/ast-build.c in function 'xkb_file_type_to_string'. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>