Commit Graph

90 Commits (e91d2653dd18e6dcace8923596c1f1a29bb9d1d4)

Author SHA1 Message Date
Ran Benita a392d2682b Replace flex scanner with a hand-written one
The scanner is very similar in structure to the one in xkbcomp/rules.c.
It avoids copying and has nicer error reporting.

It uses gperf to generate a hashtable for the keywords, which gives a
nice speed boost (compared to the naive strcasecmp method at least). But
since there's hardly a reason to regenerate it every time and require
people to install gperf, the output (keywords.c) is added here as well.

Here are some stats from test/rulescomp:

Before:
compiled 1000 keymaps in 4.052939625s
==22063==   total heap usage: 101,101 allocs, 101,101 frees, 11,840,834 bytes allocated

After:
compiled 1000 keymaps in 3.519665434s
==26505==   total heap usage: 99,945 allocs, 99,945 frees, 7,033,608 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 18:20:57 +01:00
Ran Benita e4bceec880 utils: add {un,}map_file to read an entire file
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-01 18:20:56 +01:00
Ran Benita 99f6e6fc28 Add scanner-utils.h for common scanner functions
We want to share the same functions for another scanner.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 18:20:54 +01:00
David Herrmann 36f55c494e keymap: add xkb_keymap_new_from_buffer()
The current API doesn't allow the caller to create keymaps from mmap()'ed
files. The problem is, xkb_keymap_new_from_string() requires a terminating
0 byte. However, there is no way to guarantee that when using mmap() so a
user currently has to copy the whole file just to get the terminating zero
byte (assuming they cannot use xkb_keymap_new_from_file()).

This adds a new entry xkb_keymap_new_from_buffer() which takes a memory
location and the buffer size in bytes.

Internally, we depend on yy_scan_{string,byte}() helpers. According to
flex documentation these already copy the input string because they are
wrappers around yy_scan_buffer().
yy_scan_buffer() on the other hand has some insane requirements. The
buffer must be writeable and the last two bytes must be ASCII-NUL. But the
buffer may contain other 0 bytes just fine.

Because we don't want these constraints in our public API,
xkb_keymap_new_from_buffer() needs to create a copy of the input memory.
But it then calls yy_scan_buffer() directly. Hence, we have the same
number of buffer-copies as with *_from_string() but without the
terminating 0 requirement.
The explicit yy_scan_buffer() call is preferred over yy_scan_byte() so the
buffer-copy operation is not hidden somewhere in flex.

Maybe some day we no longer depend on flex and can have a zero-copy API. A
user could mmap() a file and it would get parsed right from this buffer.
But until then, we shouldn't expose this limitation in the API but instead
provide an API that some day can work with zero-copy.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

[ran: rebased on top of my branch]
Conflicts:
	Makefile.am
	src/xkbcomp/xkbcomp.c
2013-04-01 18:04:06 +01:00
Daniel Stone 38654f5e74 Add key-sequence checking to rulescomp
Make sure we're actually getting the keymaps we're hoping to
compile.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-04-01 17:50:08 +01:00
Ran Benita 71eb033eef Move a couple of general keymap functions from keycodes.c
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-18 22:20:04 +00:00
Ran Benita 79329e1022 Don't try to build linux-specific tests on non-linux
Some tests use linux/input.h (and epoll), but we're building on some
other kernels (e.g. debian freebsd). We could just copy the file but
it's GPL. We could also skip the tests (exit code 77) but it doesn't
really matter.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 14842d6dc9 keymap: abstract a bit over the keymap format
Make it a bit easier to experiment with other formats.

Add a struct xkb_keymap_format_operations, which currently contains the
keymap compilation and _get_as_string functions. Each format can
implement whatever it wants from these.

The current public entry points become wrappers which do some error
reporting, allocation etc., and calling to the specific format. The
wrappers are all moved to src/keymap.c, so there are no XKB_EXPORT's
under src/xkbcomp/ anymore.

The only format available now is normal text_v1.

This is all not very KISS, and adds some indirection, but it is helpful
and somewhat cleaner.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 958b27284f Remove list.h
We don't use it anymore and it's easy to add back if needed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 2b352c11dd Makefile.am: don't create INSTALL and ChangeLog
It may be xorg standard but it's completely useless and clutter the
directory.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Damien Lespiau 2f7385d0e0 build: Make autoreconf honour ACLOCAL_FLAGS
When running autoreconf, it's possible to give flags to the underlying
aclocal by declaring a ACLOCAL_AMFLAGS variable in the top level
Makefile.am.

Putting ${ACLOCAL_FLAGS} there allows the user to set an environment
variable up before running autogen.sh and pull in the right directories
to look for m4 macros, say an up-to-date version of the xorg-util macros.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Cc: Daniel Stone <daniel@fooishbar.org>
2012-10-30 15:08:14 +02:00
Ran Benita 92360016fe Makefile.am: move test.h to libtest_la_SOURCES
Rather than EXTRA_DIST, where it doesn't belong.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-26 15:09:57 +02:00
Ran Benita 22b868fd75 Makefile.am: split sed script into multiple lines
To make it visible on one screen.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-26 15:09:54 +02:00
Ran Benita c1c1b720b0 test: add key processing benchmark
This runs a bunch of random keys against xkb_state_update_key() and
xkb_state_key_get_one_sym(), in a fairly unintelligent way.

It might be nice to check when modifying this code path, or changing it,
to see things haven't slowed down considerably. However, given the
numbers this benchmark gives, it is pretty clear that we are not going
to be the bottleneck for anything. So this can more-or-less be ignored.

Incidentally, this also turned out to be a poor man's fuzzer, because it
turned up the fix in the previous commit. Maybe we should consider
beefing it up with an actual 'break stuff' intention and running it as
part of 'make check'.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-24 23:27:40 +02:00
Ran Benita 5d9a5cb003 Commit and distribute ks_tables.h
The ks_tables.h file is generated by makekeys.py from
xkbcommon-keysyms.h, which in turn is generated initially by 'make
update-keysyms'. The xkbcommon-keysyms.h file is commited to git and
distributed in the tarball. Since ks_tables.h should only ever change
when xkbcommon-keysyms.h changes, it is more sensible to update them
together and treat them the same, instead of generating ks_tables.h
every time for every builder with 'make', as we do now.

This means we don't need python as a build dependency (only the one
running update-keysyms, i.e. no one, needs this), and we can be
sure exactly the same file is used by everyone. We also don't need to
run makekeys.py on every build.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-17 20:09:09 +02:00
Ran Benita 5fff637e07 makekeys: replace helper with python script and binary search
This removes the complicated and undocumented hash-table creation-helper
and replaces it with an autogenerated sorted array. The search uses simple
bsearch() now.

We also tried using gperf but it turned out to generate way to big
hashtables and when reducing the size it isn't really faster than
bsearch() anymore.

There are no users complaining about the speed of keysym lookups and we
have no benchmarks that tell that we are horribly slow. Hence, we can
safely use the simpler approach and drop all that old code.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-16 21:10:04 +02:00
Ran Benita 523e46f41a Change log env vars to XKB_LOG_LEVEL/VERBOSITY
A bit more consistent and descriptive.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-12 10:17:57 +02:00
Ran Benita 108fa1c793 Add support for building doxygen API documentation
Simple HTML docs generated from the doxygen comments.
After running 'make' or 'make doc', try firefox doc/html/index.html to
see it (if you have doxygen). It's also installed with 'make install'.
You can use --enable-docs or --disable-docs, or specifically
--with-doxygen or --without-doxygen (autodetected, default yes).

The docs are currently not distributed in the tarball, because I
couldn't make it work properly in all cases :/

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 18a433223e configure.ac: add XORG_MEMORY_CHECK_FLAGS
Adds some memory checking (e.g. MALLOC_PERTURB_) to tests.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 414007ca67 configure.ac: remove XORG_CHECK_MALLOC_ZERO
We don't use its result.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita bbaa11c6e3 Rename map.{c,h} to keymap.{c,h}
Seeing as we don't like "map" anymore.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Daniel Stone 005dee2bb6 Add _xkbcommon_ prefix to parser and lexer symbols
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:30:17 +10:00
Daniel Stone 80e156814d Add xkbcommon-compat.h and compat.c
So we can start renaming stuff while retaining backwards source and
binary compatibility.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:29:45 +10:00
Ran Benita 2c96828f75 test: add print-compiled-keymap tool
This just prints the compiled keymap string for to the given command
line arguments. This often useful when developing.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-19 16:56:26 +03:00
Ran Benita b21107056e Organize src/ and test/ headers
- 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-16 15:20:18 +03:00
David Herrmann 095a7f4cf0 xkbcommon-keysyms: Add header protection
As there is currently no stable release of xkbcommon, other projects might
want to include a copy of the keysyms so they can be used even though
libxkbcommon may not be available on the machine. However, if xkbcommon.h
is still included, conflicts will occur. Hence, to avoid nasty hacks,
simply include a header protection in xkbcommon upstream.

[daniels: Added protection to Makefile.am's update-keysyms, as well as
          XKB_KEY_NoSymbol, and a comment noting that it shouldn't be
          updated directly.]

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 16:49:04 +01:00
Ran Benita 1aa6e2b1e2 test/rules-file: add benchmark
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 480f919d77 test: add rmlvo-to-kccgst tool
For a quick look at what components result from the rules.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita f3c4032f35 Set log level for tests through env, not directly
This way the test logs have all the information, but we don't get eye
bleed every time we run them manually. One can always use
TESTS_ENVIRONMENT (we correctly use AM_TESTS_ENVIRONMENT now), or set
the envvars from the shell.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 8c1b1b0e9e Add xkbcomp/keymap.c and move some code there
Add CompileKeymap to do most of what compile_keymap_file does now, and
move UpdateKeymapFromModifiers along with it from (mostly unrelated)
compat.c.
Also rename UpdateKeymapFromModifiers to UpdateDerivedKeymapFields,
because it does more than update the modifiers.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita cdc228eaf6 Organize xkbcomp/ header files
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-01 10:58:10 +03:00
Ran Benita 0cc5ae33b5 Remove xkbcomp/misc.c
The KeyName functions are more appropriate in keycodes.c.
The ProcessIncludeFile can go to path.c along with the other functions
dealing with includes.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:20 +03:00
Pekka Paalanen 3199ea7383 android: add build files
squashed: android: set xkb config path

Conflicts:
	Makefile.am
2012-08-08 16:23:31 +02:00
Daniel Stone e756e9b532 test/dump: Remove superfluous test
No longer necessary now we have stringcomp doing a full round-trip test
for us.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 8fe2a484c0 Rename xkey test to keysym
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 5cf4f51044 Staticise xkb_map_new_from_kccgst
We didn't expose this to the outside world, and its only trivial user
was xkb_map_new_from_rules.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Ran Benita 4c21275301 Add an interactive evdev test
The program reads key events from evdev input devices, puts them through
the library and prints some information about them. It's nice for
experimenting, quick testing and trying to break it with random stuff
(already found some!).

It is called "interactive" for lack of a better name. It's a bit
hackish, but can easily be extended, made more portable etc, in the
future.

Signed-off-by: Ran Benita <ran234@gmail.com>

Conflicts:
	Makefile.am
	test/.gitignore
2012-07-28 11:43:15 +02:00
Ran Benita 74be17627e Remove alloc.{c,h}
These functions are more appropriate elsewhere now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:02:59 +03:00
Ran Benita 3dc1252d2d Add test for logging functionality
Just to make sure everything works properly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 70f35cfbc0 Add logging API
Add new public API to provide the library users with some options to
control and customize the logging output from the library. It is based
upon the skeleton from the libabc demo libray:
https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git
which is public domain and works pretty well.

This requires passing in the context object in every logging call, and
thus the conversion is done file by file. We also remove the global
warningLevel variable in favor of a verbosity level in the context,
which can be set by the user and is silent by default.

One issue is the ACTION calls, which, while nice, do not play very well
with line- and priority-based logging, and would require some
line continuation handling or keeping state or some other compromise. So
instead remove these and just inline them with their respective
warning/error. So instead of:
    ERROR("Memory allocation failed\n")
    ACTION("Removing all files on hardisk\n")
its something like that:
    log_err("Memory allocation failed; Removing all files on harddisk\n")

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 5e164ff1f9 build: drop the include/ directory
The include/ dir is somewhat redundant and makes it just a bit harder to
handle the -I directives from out side of automake; without it the
default $(top_buildir) just works.
Here's also some further justifications I found:
http://smcv.pseudorandom.co.uk/2008/09/pc-uninstalled/

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita ba4320f7b3 Move indicators.c code into compat.c
It is only used there. Allows some refactoring.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita dfa0929c6d Convert macros to inline functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita cc8b06826b Move alias.c functions into keycodes.c
They are only used in this file.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita b6e2a56dc0 Add common linked list implementation
Taken from xserver/include/list.h. The changes made are:
* Drop the xorg_ prefix and some typedef from the end.
* Rename _for_each_entry macros to just _foreach (like darray).
* Rename list_is_empty to list_empty (like darray).
* Add a list_replace function which we use later.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:56:13 +03:00
Ran Benita fe4f990902 Move CompileKeymap into xkbcomp.c
It's nicer to see the code where its used. Removes keymap.c.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-14 00:29:31 +03:00
Ran Benita 57374c3237 Rename KSIsLower/Upper and move to keysym.c
Seems like a more natural place, and allows to remove the src/misc.c
file.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-13 19:11:15 +03:00
Ran Benita 3e65531f13 Move ComputeEffectiveMap code and avoid some duplication
The ComputeEffectiveMap function is only called from keytypes.c, with
the last argument NULL, so we can move it there and remove some code.
The function XkbcVirtualModsToRealMods, of which the above is the only
user, is already implemented more simply in compat.c, so make this one
non-static and use it. This leaves src/xkb.c empty, so remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-13 19:07:03 +03:00
Ran Benita a3378338bd remove unused function xkb_canonicalise_components
commit 46441b1184 removed this from the
public API, and we don't need it internally. So send it to the archives.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-13 19:07:03 +03:00
Daniel Stone 3e86ebca06 Add a library of common test functions
Including creating a context (will come in useful soon), opening and
reading files, and compiling keymaps.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-12 14:48:22 +01:00