[PATCH] libkeymap: dump action codes for keycode 0

Oleg Bulatov <[email protected]> Fri, 21 Jun 2024 23:41:09 +0200
Newsgroups dev.linux.lists.kbd
Message-ID <[email protected]>
Keymaps in mac/* use keycode 0. For example, mac-qwerty-layout has the
following definition:

    keycode 0 =3D a

Therefore, dumpkeys should print definitions starting from 0, not 1.

Signed-off-by: Oleg Bulatov <[email protected]>
---
 src/libkeymap/dump.c                          |  4 +--
 .../dumpkeys-fulltable/mac-qwerty-layout.map  | 28 +++++++++++++++++++
 .../dumpkeys-fulltable/ruwin_cplk-UTF-8.map   |  1 +
 tests/libkeymap.at                            |  9 ++++++
 4 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 tests/data/dumpkeys-fulltable/mac-qwerty-layout.map

diff --git a/src/libkeymap/dump.c b/src/libkeymap/dump.c
index 4dee51b..499cafd 100644
--- a/src/libkeymap/dump.c
+++ b/src/libkeymap/dump.c
@@ -429,7 +429,7 @@ void lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_tabl=
e_shape table, char numer
 		if (!(j !=3D ja && lk_map_exists(ctx, j) && lk_map_exists(ctx, ja)))
 			continue;
=20
-		for (i =3D 1; i < NR_KEYS; i++) {
+		for (i =3D 0; i < NR_KEYS; i++) {
 			int buf0, buf1, type;
=20
 			buf0 =3D lk_get_key(ctx, j, i);
@@ -455,7 +455,7 @@ void lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_tabl=
e_shape table, char numer
 not_alt_is_meta:
 no_shorthands:
=20
-	for (i =3D 1; i < NR_KEYS; i++) {
+	for (i =3D 0; i < NR_KEYS; i++) {
 		all_holes =3D 1;
=20
 		for (j =3D 0; j < keymapnr; j++) {
diff --git a/tests/data/dumpkeys-fulltable/mac-qwerty-layout.map b/tests/da=
ta/dumpkeys-fulltable/mac-qwerty-layout.map
new file mode 100644
index 0000000..8313b0c
--- /dev/null
+++ b/tests/data/dumpkeys-fulltable/mac-qwerty-layout.map
@@ -0,0 +1,28 @@
+keymaps 0
+alt_is_meta
+keycode   0 =3D a=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   1 =3D s=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   2 =3D d=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   3 =3D f=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   4 =3D h=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   5 =3D g=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   6 =3D z=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   7 =3D x=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   8 =3D c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode   9 =3D v=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  11 =3D b=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  12 =3D q=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  13 =3D w=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  14 =3D e=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  15 =3D r=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  16 =3D y=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  17 =3D t=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  31 =3D o=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  32 =3D u=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  34 =3D i=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  35 =3D p=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  37 =3D l=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  38 =3D j=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  40 =3D k=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  45 =3D n=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+keycode  46 =3D m=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
diff --git a/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map b/tests/dat=
a/dumpkeys-fulltable/ruwin_cplk-UTF-8.map
index 80c6672..625b76a 100644
--- a/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map
+++ b/tests/data/dumpkeys-fulltable/ruwin_cplk-UTF-8.map
@@ -1,4 +1,5 @@
 keymaps 0-255
+keycode   0 =3D 0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200=20=20=20=20=20=20=20=20=20=20
 keycode   1 =3D 0x001b           0x001b           0x001b           0x001b =
          0x0200           0x0200           0x0200           0x0200        =
   0x081b           0x0200           0x081b           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200=20=20=20=20=20=20=20=20=20=20
 keycode   2 =3D 0x0031           0x0021           0x0031           0x0021 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0831           0x0821           0x0831           0x0821           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200=20=20=20=20=20=20=20=20=20=20
 keycode   3 =3D 0x0032           0x0040           0x0032           0x0022 =
          0x0000           0x0200           0x0000           0x0200        =
   0x0832           0x0840           0x0832           0x0840           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200           0x0200           0x0200           0x0200           0x020=
0           0x0200           0x0200           0x0200           0x0200      =
     0x0200           0x0200           0x0200           0x0200           0x=
0200           0x0200           0x0200           0x0200           0x0200   =
        0x0200           0x0200           0x0200           0x0200          =
 0x0200           0x0200           0x0200           0x0200           0x0200=
           0x0200           0x0200           0x0200           0x0200       =
    0x0200           0x0200           0x0200           0x0200           0x0=
200           0x0200           0x0200           0x0200           0x0200    =
       0x0200           0x0200           0x0200           0x0200           =
0x0200           0x0200           0x0200           0x0200           0x0200 =
          0x0200           0x0200           0x0200           0x0200        =
   0x0200           0x0200           0x0200           0x0200           0x02=
00           0x0200           0x0200           0x0200           0x0200     =
      0x0200           0x0200           0x0200           0x0200           0=
x0200           0x0200           0x0200           0x0200           0x0200  =
         0x0200           0x0200           0x0200           0x0200         =
  0x0200=20=20=20=20=20=20=20=20=20=20
diff --git a/tests/libkeymap.at b/tests/libkeymap.at
index 929d1cc..a7f8ccc 100644
--- a/tests/libkeymap.at
+++ b/tests/libkeymap.at
@@ -147,6 +147,15 @@ AT_CHECK([$abs_builddir/helpers/libkeymap-dumpkeys $ab=
s_srcdir/data/dumpkeys-ful
 	[0], [expout])
 AT_CLEANUP
=20
+AT_SETUP([test 25 (keycode 0)])
+AT_KEYWORDS([libkeymap unittest])
+cp -f -- \
+	"$abs_srcdir/data/dumpkeys-fulltable/mac-qwerty-layout.map" \
+	expout
+AT_CHECK([$abs_builddir/helpers/libkeymap-dumpkeys $abs_srcdir/data/dumpke=
ys-fulltable/mac-qwerty-layout.map DEFAULT FALSE],
+	[0], [expout])
+AT_CLEANUP
+
 AT_SETUP([binary keymap (us.map)])
 AT_KEYWORDS([libkeymap unittest])
 AT_SKIP_IF([ test "$(arch)" !=3D "x86_64" ])
--=20
2.44.2