summaryrefslogtreecommitdiff
path: root/src/xkbcomp/action.c
AgeCommit message (Collapse)AuthorFilesLines
2023-09-24Messages: merge macros with and without message codePierre Le Marre1-20/+23
Previously we had two types of macros for logging: with and without message code. They were intended to be merged afterwards. The idea is to use a special code – `XKB_LOG_MESSAGE_NO_ID = 0` – that should *not* be displayed. But we would like to avoid checking this special code at run time. This is achieved using macro tricks; they are detailed in the code (see: `PREPEND_MESSAGE_ID`). Now it is also easier to spot the remaining undocumented log entries: just search `XKB_LOG_MESSAGE_NO_ID`.
2023-09-19Structured log messages with a message registryPierre Le Marre1-23/+31
Currently there is little structure in the log messages, making difficult to use them for the following use cases: - A user looking for help about a log message: the user probably uses a search engine, thus the results will depend on the proper indexing of our documentation and the various forums. It relies only on the wording of the message, which may change with time. - A user wants to filter the logs resulting of the use of one of the components of xkbcommon. A typical example would be testing xkeyboard-config against libxkbcommon. It requires the use of a pattern (simple words detection or regex). The issue is that the pattern may become silently out-of-sync with xkbcommon. A common practice (e.g. in compilers) is to assign unique error codes to reference theses messages, along with an error index for documentation. Thus this commit implements the following features: - Create a message registry (message-registry.yaml) that defines the log messages produced by xkbcommon. This is a simple YAML file that provides, for each message: - A unique numeric code as a short identifier. It is used in the output message and thus can be easily be filtered to spot errors or searched in the internet. It must not change: if the semantics of message changes, it is better to introduce a new message for clarity. - A unique text identifier, meant for two uses: 1. Generate constants dealing with log information in our code base. 2. Generate human-friendly names for the documentation. - A type: currently warning or error. Used to prefix the constants (see hereinabove) and for basic classification in documentation. - A short description, used as concise and mandatory documentation. - An optionnal detailed description. - Optional examples, intended to help the user to fix issues themself. - Version of xkbcommon it was added. For old entries this often unknown, so they will default to 1.0.0. - Version of xkbcommon it was removed (optional) No entry should ever be deleted from this index, even if the message is not used anymore: it ensures we have unique identifiers along the history of xkbcommon, and that users can refer to the documentation even for older versions. - Add the script update-message-registry.py to generate the following files: - messages.h: message code enumeration for the messages currently used in the code base. Currently a private API. - message.registry.md: the error index documentation page. - Modify the logging functions to use structured messages. This is a work in progress.
2021-03-30xkbcomp: use memcpy over strncpy to avoid analyzer warningsPeter Hutterer1-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>
2019-12-27build: include config.h manuallyRan Benita1-0/+2
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>
2018-08-01action: make a note that we may not null-terminate private stringsPeter Hutterer1-0/+1
Coverity complains that a 7-byte string may not be null-terminated when copied into act->data (size 7). This is fine, make a note of it. All the strings in xkeyboard-config only use 6 bytes + null terminator so this won't be an issue. The server (the only user of these) uses an 8-byte array and forcibly null-terminates the string, see XkbDDXPrivate(). Everything else treats it as byte-array size 7 anyway so whether it's null-terminated doesn't matter. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-04-19action: take xkb_mod_set instead of the entire keymapRan Benita1-113/+115
A couple of modiifer actions need this information, but not the entire keymap. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19expr: take xkb_mod_set instead of the entire keymapRan Benita1-1/+2
The modifier-resolving functions only need the modifier information. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-16action: convert a few missed unsigned -> enum xkb_action_typeRan Benita1-5/+5
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16action: unify SetLatch and Lock handler functionsRan Benita1-54/+33
This is a little shorter and follows easier from the spec flag description table. Also a few were too permissive (like allowing LatchToLock in SetMods). Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16action: add a common CheckBooleanFlag functionRan Benita1-52/+32
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16keymap: change action flag NO_ACCEL -> ACCELRan Benita1-2/+3
It's easier to deal with, but we need to set it as "factory default". Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16action: fix SwitchScreen "same" field handlingRan Benita1-2/+3
This used to *unset* a flag called "SwitchApplication"; we changed the flag to "same" but forgot to switch the cases. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15action: don't pass a keymap where a ctx is sufficientRan Benita1-59/+59
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15action: add missing array_ndx checksRan Benita1-4/+9
Only the "data" field can have them, and every other field needs to error out if it appears. But some didn't check. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15action: move array_ndx errors into the Check functionsRan Benita1-75/+44
Makes more sense and flows more nicely this way. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15action: fix missing support for "affect" fieldRan Benita1-18/+34
Support for setting this field was missing from the LockMods and LockControls actions. Based on a xkbcomp patch by Andreas Wettstein. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-14action: simplify Check* functionsRan Benita1-68/+34
Instead of using those t1 t2 variables, pass the final destinations directly (while making sure they are not modified in case of error). This also ensures the types are right, e.g. in CheckGroupField it should be int32_t, not xkb_layout_index_t (and indeed it takes a negation!). Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08action: fix misleading castRan Benita1-1/+1
The type is uint8_t and so is the checked range. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08action: fix printing of underflowed value in error messageRan Benita1-2/+2
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08Fix sign-compare warningsRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-07action: Use ResolveInteger for PtrBtn.count, not ResolveButtonRan Benita1-6/+5
It's not a button. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-07action: check range of MovePtr X,Y valuesRan Benita1-2/+11
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-12action, types: remove unused Report functionsRan Benita1-11/+0
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-11Fix some cppcheck warningsRan Benita1-6/+2
Someone was nice enough to run this for us: ftp://ftp.sunet.se/pub/Linux/distributions/Debian/debian/pool/main/libx/libxkbcommon/libxkbcommon_0.3.1.orig.tar.gz [libxkbcommon-0.3.1/src/keymap.c:86]: (style) The scope of the variable 'j' can be reduced. [libxkbcommon-0.3.1/src/keymap.c:87]: (style) The scope of the variable 'key' can be reduced. [libxkbcommon-0.3.1/src/keysym-utf.c:843]: (style) The scope of the variable 'mid' can be reduced. [libxkbcommon-0.3.1/src/state.c:992]: (style) The scope of the variable 'str' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/action.c:467]: (style) The scope of the variable 'absolute' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:468]: (style) The scope of the variable 'consumed' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:862]: (style) The scope of the variable 'mlvo' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:863]: (style) The scope of the variable 'kccgst' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:865]: (style) The scope of the variable 'match_type' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/symbols.c:753]: (style) The scope of the variable 'toAct' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/symbols.c:1573]: (style) The scope of the variable 'key' can be reduced. [libxkbcommon-0.3.1/test/common.c:80]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [libxkbcommon-0.3.1/test/interactive.c:358]: (style) The scope of the variable 'nevs' can be reduced. [libxkbcommon-0.3.1/test/interactive.c:236]: (style) Checking if unsigned variable 'nsyms' is less than zero. [libxkbcommon-0.3.1/test/interactive.c:226]: (style) Unused variable: unicode Signed-off-by: Ran Benita <ran234@gmail.com>
2013-12-01expr: split expression types and allocate them separatelyRan Benita1-34/+40
Currently, we have one ExprDef type, which contains a tagged union with the value of all expression types. Turns out, this union is quite wasteful memory-wise. Instead, create separate types for all expressions (e.g ExprBinary, ExprInteger) which embed the common fields (ExprCommon), and malloc them per their size; ExprDef then becomes a union of all these types, but is just used as a generic pointer. [Instead of making ExprDef a union, another option is to use ExprCommon as the generic pointer type and then do up-castings, like we do with ParseCommon. But this makes the code much uglier.] The diff is mostly straightforward mechanical adaptations. It could have been much smaller with the help of C11 anonymous structs (which were previously a gnu extension). This will have saved all of the 'op' -> 'expr->op', etc changes. But if we can be a bit more portable for a little effort, we should. Before (./test/rulescomp, x86 32 bit, -O2): ==12974== total heap usage: 145,217 allocs, 145,217 frees, 10,476,238 bytes allocated After: ==11145== total heap usage: 145,217 allocs, 145,217 frees, 8,270,358 bytes allocated Signed-off-by: Ran Benita <ran234@gmail.com>
2013-12-01expr: add constructor for boolean expressionsRan Benita1-2/+2
Also add a 'bool set' to the ExprDef union, instead of using 'ival' as a bool. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-11-30expr: add 'ident' value to ExprDef unionRan Benita1-1/+1
This distinguishes between an identifier expression and a string expression in the union. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18Fix pointer style nitRan Benita1-1/+1
(I really dislike this one for some reason..) Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18Move a couple of general keymap functions from keycodes.cRan Benita1-1/+0
To get a key by name and resolve an alias - this makes sense for everyone. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18More spelling errorsRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18action: s/hndlrType/handler_typeRan Benita1-5/+5
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-30action: don't allow private actions with a known typeRan Benita1-1/+20
Some obscure bug having to do with Private actions; see the comments. This was prompted by: https://bugs.freedesktop.org/show_bug.cgi?id=56491 Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06expr: unify the real and virtual modifier functionsRan Benita1-1/+1
This again pushes the mod type annotation to the original call site, to make it easier to grep to see where the real/virtual distinction matters. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06Use our types instead of int/uint32_t in a few placesRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30Don't use %z printf formatRan Benita1-2/+2
Some libc's don't support it. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24Don't use xkbcommon-compat names in internal codeRan Benita1-3/+3
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14Rename ACTION_TYPE_LAST to _ACTION_TYPE_NUM_ENTRIESRan Benita1-3/+2
It's not really "last" per-se, and we use this other format in some other enums. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-12Copyright updatesDaniel Stone1-0/+27
With Dan Nicholson's permission (via email), update his copyright and license statements to the standard X.Org boilerplate MIT license, as both myself and Ran have been using. Clean up my copyright declarations (in some cases to correct ownership), and add copyright/license statements from myself and/or Ran where appropriate. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10actions: Remove PointerDefault affect fieldDaniel Stone1-5/+3
This was always set to affect the default button, so no need for it. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10kbproto unentanglement: action flagsDaniel Stone1-31/+29
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10kbproto unentanglement: action typesDaniel Stone1-30/+30
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10Remove deprecated actionsDaniel Stone1-331/+1
We didn't do anything with ISO_Lock, ActionMessage, RedirectKey, and the device-specifying variants of the pointer actions, so remove those. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10kbproto unentanglement: XkbNumVirtualModsDaniel Stone1-1/+1
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10kbproto untanglement: XkbKeyNameLengthDaniel Stone1-1/+1
Define it ourselves as XKB_KEY_NAME_LENGTH and use that, instead of the one from XKB.h. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-03Unify some string tables from xkbcomp, text and keymap-dumpRan Benita1-103/+4
We move the LookupEntry struct from expr.h to text.h, along with most of the lookup tables. This makes them available everywhere. Looking up a value in the LookupEntry format is slower than direct index mapping, but it allows multiple names per value (with the canonical one being first) and "all"- and "none"-type masks. These functions are not used anywhere efficiency matters. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03expr: make ResolveString return an atomRan Benita1-2/+6
Almost all callers do xkb_atom_intern on the currently returned string, while ResolveString converts the atom to the string to begin with... uselss double work. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03action: fix LookupEntry for "lockdevbtn"Ran Benita1-1/+1
xkbcomp has that bug as well, guess no one uses it. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03action: remove redundant checkRan Benita1-7/+0
The NoAction handler always errors out with the same message. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03action: keep array of default actions, instead of list of changesRan Benita1-78/+44
The implementation of changing the default properties of actions, e.g. a statements such as (from test/data/compat/basic): setMods.clearLocks= True; latchMods.clearLocks= True; latchMods.latchToLock= True; works by keeping a list of ActionInfo's, each containing the neccesary info from each statement, and then when some action comes up (e.g. in an interpret statment) it goes through the list, and applies the relevent ActionInfo's to the newly-constructed xkb_action. Instead of doing this, we add a struct ActionsInfo, which contains an array of xkb_actions, one for each type. When a default changing statement appears, we change the action in the array; when a new action comes up, we just copy from the array. This is simpler to figure out, and pretty straightforward. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03action: disallow setting an action_field default for all typesRan Benita1-13/+8
Currently where it is possible to write: setMods.clearLocks = True; It's also possible to write: action.clearLocks = True; This will set the default value for the clearLocks action field for *all* action types, as opposed to just setMods in this case. If subsequently an action is used for which this field does not make sense, it will error out. This doesn't make any sense, because any given field is only possible by at most 3 or 4 action types... which you might as well write explicitly and avoid the side effect mentioned above. Needless to say this is one of xkbcomp's "hidden features" and is not used anywhere; remove it. Signed-off-by: Ran Benita <ran234@gmail.com>