Make C++ happy.

For most functions taking an enum flags parameter, we use 0 value to
indicate that no flags should be applied.

C++ has a stronger type system than C and will not implicitly convert
int's to enum's. Thus, we create valid 0 enum values for enum types
where it makes sense.

Signed-off-by: Wander Lairson Costa <wander.lairson@gmail.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
Makefile.am: drop AM_LFLAGS

We don't use a lex/flex anymore so this is not used.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: don't use enum yytokentype

byacc doesn't support this, it just puts out #define's for the tokens.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: use %pure-parser instead of %define api.pure

Both bison and byacc support this syntax. Bison manpage says something
about this giving more or less options, but we don't care.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: drop %name-prefix, use -p yacc argument instead

Even though the %name-prefix is more sensible, byacc doesn't support it,
but both bison and byacc support the -p argument.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: don't use %locations

byacc doesn't support this feature.

We print the line/col of the last scanned token instead. This is slightly
less in case of *parser* errors (not syntax errors), but I couldn't make
it point to another line, and this are pretty cryptic anyways. So it's
good enough. Also might be a bit faster, but haven't checked.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: add a workaround for byacc

Unlike bison, byacc outputs its own parser code *after* our own parser.y
code, which includes the #undef. So this fix is needed for the 'scanner'
-> 'param->scanner' translation to work in the parser.c code generated
by byacc.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: add some notes about byacc working

We now also work with byacc (version tested: 20130925) which some people
prefer, perhaps due to its license (public domain) or performance
(haven't compared).

When using byacc, currently the following warning comes up:
    src/xkbcomp/parser.c:954:14: warning: declaration shadows a variable in the global scope [-Wshadow]
        YYSTYPE  yylval;
                ^
    src/xkbcomp/parser.c:37:20: note: expanded from macro 'yylval'
    #define yylval     _xkbcommon_lval
                    ^
    ./src/xkbcomp/parser.h:96:16: note: previous declaration is here
    extern YYSTYPE _xkbcommon_lval;

This is due to a bug in byacc - it shouldn't output that extern line in
%pure-parser mode. So the warning stays.

Signed-off-by: Ran Benita <ran234@gmail.com>
symbols: fix use of uninitialized variable

'tmp' is stack allocated so tmp->merge is used uninitialized by
AddModMapEntry(). The value doesn't matter much, but it used to
make some modmap merging decision (which doesn't have many
conflicts usually).

Bug inherited from xkbcomp.

Signed-off-by: Ran Benita <ran234@gmail.com>
keysym-utf: Fix a warning about shadowing

Change variable names to avoid the name clash. The warning seen is

src/keysym-utf.c: In function 'bin_search':
src/keysym-utf.c:841: warning: declaration of 'min' shadows a global declaration
src/utils.h:109: warning: shadowed declaration is here
src/keysym-utf.c:842: warning: declaration of 'max' shadows a global declaration
src/utils.h:115: warning: shadowed declaration is here

Signed-off-by: Siddharth Heroor <heroor@ti.com>
scanner: remove unnecessary cast

'tok' is already an int now.

Signed-off-by: Ran Benita <ran234@gmail.com>
rules: reduce variable scopes

There are some big functions there, and this might help reduce the
cognitive load a bit.

Signed-off-by: Ran Benita <ran234@gmail.com>
rules: improve error logging macros

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>
rules: use strlen_safe

Signed-off-by: Ran Benita <ran234@gmail.com>
rules: simplify a bit of code

Signed-off-by: Ran Benita <ran234@gmail.com>
keymap: call strlen on keymap string instead of SIZE_MAX

I wanted to avoid the strlen, but we'd better keep the scanner a bit
less surprising and encourage people to use xkb_keymap_new_from_buffer()
instead of they do in fact have access to the size.

Signed-off-by: Ran Benita <ran234@gmail.com>
rulescomp: increase BENCHMARK_ITERATIONS from 1000 to 2500

1000 is a bit too low for statistical significance on this 6 years old
CPU. Since the benchmark is run manually this shouldn't be a problem.

Signed-off-by: Ran Benita <ran234@gmail.com>
configure.ac: add AM_PROG_CC_C_O

Older Automakes give this error without this directive:

Makefile.am: C objects in subdir but `AM_PROG_CC_C_O' not in `configure.ac'

In newer autotools this is included under AC_PROG_CC, but it's harmless
to add.

https://github.com/xkbcommon/libxkbcommon/issues/3

Signed-off-by: Ran Benita <ran234@gmail.com>
Replace ctype.h functions with ascii ones

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>
rules: fix scanning of line-continuation without leading space

We were failing to scan something like\
this correctly.

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