summaryrefslogtreecommitdiff
path: root/src/xkbcomp/rules.c
AgeCommit message (Collapse)AuthorFilesLines
2014-09-21rules: fix mlvo-not-used warningRan Benita1-9/+11
An mlvo can also be used in an expansion, but we didn't mark them in this case in commit d8a4f52cb95d989b4. 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-20rules: warn when an RMLVO component isn't usedRan Benita1-32/+69
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-07-26Replace darray_mem with a new darray_stealRan Benita1-7/+4
That's a more declarative interface. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-05-28rules: fix leak on failureRan Benita1-0/+4
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-02-10scanner: sort out scanner logging functionsRan Benita1-61/+25
First, make the rules and xkb scanners/parsers use the same logging functions instead of rolling their own. Second, use the gcc ##__VA_ARGS extension instead of dealing with C99 stupidity. I hope all relevant compilers support it. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-10rules: always %-expand kccgst valuesRan Benita1-26/+35
Previously the early-exit codepath might have left some values unexpanded, and we'd go looking for e.g "%l%(v)". Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-10rules: print full path in error messagesRan Benita1-3/+3
There can be multiple include paths. But it's nicer in any case. This also makes scanner_error actually use log_err instead of log_warn - oops. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-10rules: include the path in failed-to-map error messageRan Benita1-1/+2
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-09doc: move some file comments into txt files in doc/Ran Benita1-78/+0
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08scanner: make line and column unsignedRan Benita1-2/+2
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08rules: get rid of struct locationRan Benita1-24/+15
Use the scanner token_{line,column} like we do in the other places. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08Use (1u << idx) instead of (1 << idx) where appropriateRan Benita1-6/+6
It doesn't matter (I think), since the implicit conversion doesn't have any effect (e.g. sign-extension). But it's better to be aware of the type. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08Use unsigned int for saving darray_size return valueRan Benita1-1/+1
See: b9b3593cbdeb7f5b02d50cecaba6a0b47d4979ad So these should be unsigned int's now. Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08darray: cleanupRan Benita1-5/+5
We have quite diverged from the upstream file, so let's make it at least easier to look at. Remove some unused macros and rename some for consistency. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-14rules: fix scanning of line-continuation without leading spaceRan Benita1-3/+9
We were failing to scan something like\ this correctly. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-14Replace ctype.h functions with ascii onesRan Benita1-6/+6
ctype.h is locale-dependent, so using it in our scanners is not optimal. Let's be deterministic with our own simple functions. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10rules: simplify a bit of codeRan Benita1-17/+12
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10rules: use strlen_safeRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10rules: improve error logging macrosRan Benita1-11/+6
Improve safety with parenthesis, make the matcher macros use the scanner ones, and make the 1 variant use %s instead of embedding the msg; this way the compiler can reuse the string in the binary. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10rules: reduce variable scopesRan Benita1-34/+27
There are some big functions there, and this might help reduce the cognitive load a bit. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01utils: add {un,}map_file to read an entire fileRan Benita1-23/+7
This wraps the current mmap call and adds a fallback implementation for systems which do not have mmap (e.g. mingw). Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01Add scanner-utils.h for common scanner functionsRan Benita1-95/+1
We want to share the same functions for another scanner. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18rules: be more paranoid in scannerRan Benita1-16/+9
This can't happen, but better safe than sorry. The optimizations were noticeable but negligible. Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18rules: quiet a gcc warningRan Benita1-0/+1
src/xkbcomp/rules.c:620:36: error: 'idx' may be used uninitialized in this function [-Werror=maybe-uninitialized] Can't happen but no harm done. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10Rename XKB_NUM_GROUPS to XKB_MAX_GROUPSRan Benita1-1/+1
This is a more appropriate name now. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30rules: always initialize idx variableRan Benita1-0/+1
gcc didn't catch this one. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24Don't use xkbcommon-compat names in internal codeRan Benita1-17/+17
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-16Organize src/ and test/ headersRan Benita1-2/+0
- Add context.h and move context-related functions from xkb-priv.h to it. - Move xkb_context definition back to context.c. - Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it. - Rename xkb-priv.h to map.h since it only contains keymap-related definitions and declarations now. - Remove unnecessary includes and some and some other small cleanups. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-16include: improve file-not-found error reportingRan Benita1-13/+1
Only report it once, and not only for rules. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14rules: fix mmap failure handlingRan Benita1-3/+3
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-12Copyright updatesDaniel Stone1-0/+23
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-10kbproto untanglement: XkbKbdNumGroupsDaniel Stone1-2/+2
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-05rules: use goto instead of state variableRan Benita1-153/+128
There's no noticeable speed difference, but I think it's nicer and more explicit than the previous code. Some people just don't like goto, though.. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-05rules: rewriteRan Benita1-853/+978
Rewrite the rules file parser for clarity, performance and memory usage reduction. The previous implementation was quite hard to navigate and did a lot of unnecessary work and copying. This implementation keeps along just the state necessary, and doesn't perform any copying of the file's content (although the entire file is mmap'ed as before). Hopefully it's also easier to understand, has better documentation, and better error checking and reporting. We try to reproduce the previous behavior in every case. Note: the diff is pretty confusing; it's likely better to look at the file directly. Benchmarks: On an old 32-bit Intel processor. gcc -O2 -pg ./test/rulescomp bench grof test/rulescomp Before: compiled 1000 keymaps in 14.863564304s % cumulative self self total time seconds seconds calls ms/call ms/call name 49.33 4.43 4.43 30610000 0.00 0.00 yylex 17.93 6.04 1.61 31000 0.05 0.22 yyparse 6.57 6.63 0.59 1000 0.59 0.59 load_rules 3.23 6.92 0.29 3637000 0.00 0.00 AppendStmt 2.45 7.14 0.22 472000 0.00 0.00 AddKeySymbols 2.12 7.33 0.19 3591000 0.00 0.00 atom_intern 2.12 7.52 0.19 518000 0.00 0.00 FindNamedKey 2.00 7.70 0.18 230000 0.00 0.00 FreeStmt 1.78 7.86 0.16 1000 0.16 0.17 UpdateModifiersFromCompat 1.34 7.98 0.12 732000 0.00 0.00 AddKeyName 1.34 8.10 0.12 __x86.get_pc_thunk.bx After: compiled 1000 keymaps in 13.874666269s % cumulative self self total time seconds seconds calls ms/call ms/call name 49.82 4.26 4.26 30610000 0.00 0.00 yylex 22.22 6.16 1.90 31000 0.06 0.22 yyparse 2.92 6.41 0.25 3591000 0.00 0.00 atom_intern 2.57 6.63 0.22 1000 0.22 0.25 xkb_components_from_rules 2.11 6.81 0.18 3637000 0.00 0.00 AppendStmt 2.11 6.99 0.18 230000 0.00 0.00 FreeStmt 1.99 7.16 0.17 518000 0.00 0.00 FindNamedKey 1.99 7.33 0.17 1000 0.17 0.17 UpdateModifiersFromCompat 1.99 7.50 0.17 __x86.get_pc_thunk.bx 1.52 7.63 0.13 150000 0.00 0.00 AddInterp 1.40 7.75 0.12 472000 0.00 0.00 AddKeySymbols On a newer 64-bit Intel processor. gcc -O2 ./test/rules-file bench Before: processed 20000 times in 15.940546625s After: processed 20000 times in 5.295026345s Allocations: gcc -O2 valgrind test/rulescomp Before: total heap usage: 257,519 allocs, 257,519 frees, 14,766,529 bytes allocated After: total heap usage: 240,756 allocs, 240,756 frees, 14,007,886 bytes allocated Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03rules: fix check for appending '|' character when applyingRan Benita1-1/+1
There are two ways to separate multiple files in XKB include statements: '+' will cause the later file to override the first in case of conflict, while '|' will cause it augment it (this is done by xkbcomp). '!' is unrelated here. Since '|' is practically never used, this wasn't noticed. In the modified test, the '|some_compat' previously was just ignored. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01Organize xkbcomp/ header filesRan Benita1-2/+3
Various non-functional changes: - Re-add keycodes.h and move some stuff there. - Add parser-priv.h for internal bison/flex stuff. - Don't include headers from other headers, such that file dependencies are immediate in each file. - Rename xkbcomp.h -> ast.h, parseutils.{c,h} -> ast-build.{c,h} - Rename path.{c,h} -> include.{c,h} - Rename keytypes.c -> types.c - Make the naming of XkbFile-related functions more consistent. - Move xkb_map_{new,ref,unref} to map.c. - Remove most extern keyword from function declarations, it's just noise (XKB_EXPORT is what's important here). - Append XKBCOMP_ to include guards. - Shuffle some code around to make all of this work. Splitting this would be a headache.. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01Allocate xkb_component_names on stackRan Benita1-27/+27
Instead of malloc'ing it as well. Also improve the error handling. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09Fix warningRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-08Rules: mmap() rules file instead of using getc()Daniel Stone1-21/+43
Good for a small performance win on my system. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08Print failed include paths on failure to find rulesDaniel Stone1-5/+9
Thus giving a hint as to which directory we're trying to find. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-27utils: add/replace string equality macrosRan Benita1-20/+18
It's more tidy and less error prone, since we use strcasecmp == 0 a lot. We replace strcmp == 0 by streq, strcasecmp == 0 by istreq, uStrCasePrefix by istreq_prefix and uDupString by strdup_safe. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23rules: use new log functionsRan Benita1-45/+54
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-17Run source tree through uncrustifyDaniel Stone1-71/+81
.uncrustify.cfg committed for future reference also, but had to manually fix up a few things: it really likes justifying struct initialisers. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-12rules: fix parsing of multiple optionsRan Benita1-11/+8
This was broken by commit 18d331b86b4942ba54fe087ca07e47c9383d768b (where only the first option out of a comma-separated string was matched). Do it correctly this time and add a test. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-01rules: remove support for keymap ruleRan Benita1-19/+3
This commit removes the ability to specify a keymap *in a rules file*, e.g. in /usr/share/X11/xkb/rules/evdev or somesuch. This is unused in xkeyboard-data, and the current code has never even supported it, because xkb_map_new_from_kccgst (which is no longer exposed in the API) checks to see that one of the usual components (e.g. symbols, types, ..) has been filled, while the rules parser, on the other hand, doesn't allow to specify a keymap and other stuff at the same time. ( The idea was to remove xkb_map_new_from_kccgst entirely, but it's used by a test so it can stay. ) tl;dr: dead code. Of course passing a keymap file to xkb_map_new_from_file still works. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-01Use enum for file typesRan Benita1-1/+1
enums are nice for some type safety and readability. This one also removes the distinction between file type mask / file type index and some naming consistency. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-06-09darray: some changes for convenienceRan Benita1-4/+4
- Make darray_free also initialize the array back to an empty state, and stop worrying about it everywhere. - Add darray_mem, to access the underlying memory, which we do manually now using &darray_item(arr, 0). This makes a bit more clear when we actually mean to take the address of a specific item. - Add darray_copy, to make a deep copy of a darray. - Add darray_same, to test whether two darrays have the same underlying memory (e.g. if the struct itself was value copied). This should used where previously two arrays were compared for pointer equality. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-06-09darray: tweak parameters a bit for better memory usageRan Benita1-0/+3
Here are some quick numbers from valgrind, running rulescomp only with a simple, common "us,de" rule set: before darray: cb047bb total heap usage: 44,924 allocs, 44,924 frees, 3,162,342 bytes allocated after darray: c87468e total heap usage: 52,670 allocs, 52,670 frees, 2,844,517 bytes allocated tweaking specific inital allocation sizes: total heap usage: 52,652 allocs, 52,652 frees, 2,841,814 bytes allocated changing initial alloc = 2 globally total heap usage: 47,802 allocs, 47,802 frees, 2,833,614 bytes allocated changing initial alloc = 3 globally total heap usage: 47,346 allocs, 47,346 frees, 3,307,110 bytes allocated changing initial alloc = 4 globally total heap usage: 44,643 allocs, 44,643 frees, 2,853,646 bytes allocated [ Changing the geometric progression constant from 2 only made things worse. I tried the golden ratio - not so golden :) ] The last one is obviously the best, so it was chosen, with the specific tweaks thrown in as well (these were there before but don't make much difference). Overall it seems to do better than the previous manual allocations which is a bit surprising. Signed-off-by: Ran Benita <ran234@gmail.com>
2012-05-22rules: use darray for input lineRan Benita1-71/+26
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-05-22rules: use darray for rules and groupsRan Benita1-90/+27
Signed-off-by: Ran Benita <ran234@gmail.com>