Fix alt_is_meta regression
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Mon, 7 Oct 2013 13:48:57 +0000 (17:48 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Mon, 7 Oct 2013 14:13:31 +0000 (18:13 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/libkeymap/kmap.c
tests/Makefile.am
tests/alt-is-meta.in [new file with mode: 0755]
tests/alt-is-meta.map [new file with mode: 0644]
tests/alt-is-meta.output [new file with mode: 0644]
tests/libkeymap-showmaps.c [new file with mode: 0644]

index ca97ed5..c7945bc 100644 (file)
@@ -149,10 +149,10 @@ lk_add_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index, int k
                int type = KTYP(keycode);
                int val = KVAL(keycode);
 
-               if (alttable != k_table && !lk_key_exists(ctx, alttable, k_index) &&
-                   (type == KT_LATIN || type == KT_LETTER) && val < 128) {
-                       if (lk_add_map(ctx, alttable) < 0)
-                               return -1;
+               if (alttable != k_table && lk_map_exists(ctx, alttable) &&
+                   !lk_key_exists(ctx, alttable, k_index) &&
+                   (type == KT_LATIN || type == KT_LETTER) &&
+                   val < 128) {
                        if (lk_add_key(ctx, alttable, k_index, K(KT_META, val)) < 0)
                                return -1;
                }
index e7d22c2..d9a9f61 100644 (file)
@@ -7,10 +7,12 @@ AM_CFLAGS = $(CHECK_CFLAGS)
 LDADD  = $(top_builddir)/src/libkeymap/libkeymap.la $(CHECK_LIBS)
 
 EXTRA_DIST = \
+       alt-is-meta.in \
        dumpkeys-bkeymap.in \
        dumpkeys-fulltable.in \
        dumpkeys-mktable.in \
        \
+       alt-is-meta.map \
        charset-keymap0.map \
        dumpkeys.full.ruwin_cplk-UTF-8.map \
        dumpkeys.qwerty-layout.map \
@@ -19,15 +21,16 @@ EXTRA_DIST = \
        keymap0.map keymap1.map keymap2.map keymap3.map keymap4.map keymap5.map keymap6.map \
        VoidSymbol.map \
        \
+       alt-is-meta.output \
        dumpkeys.bkeymap.bin \
        dumpkeys.defkeymap.c
 
-check_SCRIPTS  = dumpkeys-fulltable dumpkeys-mktable dumpkeys-bkeymap
+check_SCRIPTS  = dumpkeys-fulltable dumpkeys-mktable dumpkeys-bkeymap alt-is-meta
 check_PROGRAMS = libkeymap-init libkeymap-kmap libkeymap-keys libkeymap-parse \
        libkeymap-charset
 
 noinst_PROGRAMS = \
-       libkeymap-dumpkeys libkeymap-mktable libkeymap-bkeymap \
+       libkeymap-dumpkeys libkeymap-mktable libkeymap-bkeymap libkeymap-showmaps \
        $(check_PROGRAMS)
 
 TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
@@ -41,6 +44,7 @@ libkeymap_charset_SOURCES  = libkeymap-charset.c
 libkeymap_dumpkeys_SOURCES = libkeymap-dumpkeys.c
 libkeymap_mktable_SOURCES  = libkeymap-mktable.c
 libkeymap_bkeymap_SOURCES  = libkeymap-bkeymap.c
+libkeymap_showmaps_SOURCES = libkeymap-showmaps.c
 
 %: %.in
        sed \
diff --git a/tests/alt-is-meta.in b/tests/alt-is-meta.in
new file mode 100755 (executable)
index 0000000..ddd5ed8
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh -efu
+
+cwd="$(readlink -ev "${0%/*}")"
+
+cd "$cwd"
+
+rc=0
+temp="$(mktemp "@BUILDDIR@/temp.XXXXXXXXX")"
+
+./libkeymap-showmaps "@DATADIR@"/alt-is-meta.map > "$temp" || rc=$?
+cmp -s "@DATADIR@//alt-is-meta.output" "$temp" || rc=$?
+
+if [ "$rc" != 0 ]; then
+       printf 'failed\n'
+else
+       rm -f -- "$temp"
+fi
+
+exit $rc
diff --git a/tests/alt-is-meta.map b/tests/alt-is-meta.map
new file mode 100644 (file)
index 0000000..fa182a5
--- /dev/null
@@ -0,0 +1,12 @@
+keymaps 0-9,12-13,16-20,22,24-25,28,32-41,44-45,48-52,54,56-57,60
+alt_is_meta
+keycode  16 = +q           Q            backslash    backslash    Control_q   \
+              Control_q    Control_backslash         Control_backslash        \
+              Meta_q       Meta_Q       VoidSymbol   VoidSymbol   +Q          \
+              q            VoidSymbol   VoidSymbol   VoidSymbol   VoidSymbol  \
+              Meta_Q       Meta_q       VoidSymbol                            \
+              +q           Q            backslash    backslash    Control_q   \
+              Control_q    Control_backslash         Control_backslash        \
+              Meta_q       Meta_Q       VoidSymbol   VoidSymbol   +Q          \
+              q            VoidSymbol   VoidSymbol   VoidSymbol   VoidSymbol  \
+              Meta_Q       Meta_q       VoidSymbol
diff --git a/tests/alt-is-meta.output b/tests/alt-is-meta.output
new file mode 100644 (file)
index 0000000..25abb20
--- /dev/null
@@ -0,0 +1,42 @@
+keymap 000
+keymap 001
+keymap 002
+keymap 003
+keymap 004
+keymap 005
+keymap 006
+keymap 007
+keymap 008
+keymap 009
+keymap 012
+keymap 013
+keymap 016
+keymap 017
+keymap 018
+keymap 019
+keymap 020
+keymap 022
+keymap 024
+keymap 025
+keymap 028
+keymap 032
+keymap 033
+keymap 034
+keymap 035
+keymap 036
+keymap 037
+keymap 038
+keymap 039
+keymap 040
+keymap 041
+keymap 044
+keymap 045
+keymap 048
+keymap 049
+keymap 050
+keymap 051
+keymap 052
+keymap 054
+keymap 056
+keymap 057
+keymap 060
diff --git a/tests/libkeymap-showmaps.c b/tests/libkeymap-showmaps.c
new file mode 100644 (file)
index 0000000..acbf9f1
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <keymap.h>
+
+#include "contextP.h"
+
+int main(int argc, char **argv)
+{
+       int i;
+       struct lk_ctx *ctx;
+       lkfile_t f;
+
+       ctx = lk_init();
+
+       f.pipe = 0;
+       strcpy(f.pathname, argv[1]);
+       f.fd = fopen( argv[1], "r");
+
+       lk_parse_keymap(ctx, &f);
+
+       for (i = 0; i < ctx->keymap->total; i++) {
+               if (!lk_map_exists(ctx, i))
+                       continue;
+               printf("keymap %03d\n", i);
+       }
+
+       lk_free(ctx);
+       return 0;
+}