Commit e5d4056e2fbca78816b78c23545a05b94c7f35bc

Peter Hutterer 2020-06-22T13:04:43

test: untangle print-compiled-keymap from the test headers Commit 16c84cdd819db516fff089c76b99248fb7dd4e8c removed the getopt handling for RMLVO arguments, so now this tool only takes a keymap file and compiles it. Using test helpers to init the context gives it fairly specific behavior; unless the user sets the right environment variables and/or calls it from the right PWD, it may or may not include the test data. Let's drop this behavior, make it a default tool to compile a keymap. If there is a specific need to modify the include paths, we can add this later. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

diff --git a/test/print-compiled-keymap.c b/test/print-compiled-keymap.c
index bda33fd..e595ab1 100644
--- a/test/print-compiled-keymap.c
+++ b/test/print-compiled-keymap.c
@@ -23,9 +23,11 @@
 
 #include "config.h"
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
-#include "test.h"
+#include "xkbcommon/xkbcommon.h"
 
 int
 main(int argc, char *argv[])
@@ -35,6 +37,7 @@ main(int argc, char *argv[])
     struct xkb_context *ctx = NULL;
     struct xkb_keymap *keymap = NULL;
     const char *keymap_path = NULL;
+    FILE *file = NULL;
     char *dump;
 
     while ((opt = getopt(argc, argv, "h")) != -1) {
@@ -53,13 +56,20 @@ main(int argc, char *argv[])
 
     keymap_path = argv[optind];
 
-    ctx = test_get_context(0);
+    ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
     if (!ctx) {
         fprintf(stderr, "Couldn't create xkb context\n");
         goto out;
     }
 
-    keymap = test_compile_file(ctx, keymap_path);
+    file = fopen(keymap_path, "rb");
+    if (!file) {
+        fprintf(stderr, "Failed to open path: %s\n", keymap_path);
+        goto out;
+    }
+
+    keymap = xkb_keymap_new_from_file(ctx, file,
+                                      XKB_KEYMAP_FORMAT_TEXT_V1, 0);
     if (!keymap) {
         fprintf(stderr, "Couldn't create xkb keymap\n");
         goto out;
@@ -76,6 +86,8 @@ main(int argc, char *argv[])
     ret = EXIT_SUCCESS;
     free(dump);
 out:
+    if (file)
+        fclose(file);
     xkb_keymap_unref(keymap);
     xkb_context_unref(ctx);
     return ret;