Disallow producing NULL character with escape sequences
[platform/upstream/libxkbcommon.git] / tools / interactive-x11.c
index d98433e..9fe0c10 100644 (file)
@@ -26,6 +26,7 @@
 #include <locale.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <xcb/xkb.h>
 
@@ -242,10 +243,11 @@ process_event(xcb_generic_event_t *gevent, struct keyboard *kbd)
         xkb_keycode_t keycode = event->detail;
 
         tools_print_keycode_state(kbd->state, NULL, keycode,
-                                  XKB_CONSUMED_MODE_XKB);
+                                  XKB_CONSUMED_MODE_XKB,
+                                  PRINT_ALL_FIELDS);
 
         /* Exit on ESC. */
-        if (keycode == 9)
+        if (xkb_state_key_get_one_sym(kbd->state, keycode) == XKB_KEY_Escape)
             terminate = true;
         break;
     }
@@ -336,6 +338,14 @@ main(int argc, char *argv[])
     struct xkb_context *ctx;
     struct keyboard core_kbd;
 
+    if (argc != 1) {
+        ret = strcmp(argv[1], "--help");
+        fprintf(ret ? stderr : stdout, "Usage: %s [--help]\n", argv[0]);
+        if (ret)
+            fprintf(stderr, "unrecognized option: %s\n", argv[1]);
+        return ret ? EXIT_INVALID_USAGE : EXIT_SUCCESS;
+    }
+
     setlocale(LC_ALL, "");
 
     conn = xcb_connect(NULL, NULL);