diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-06-24 09:00:08 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-06-25 10:32:08 +1000 |
commit | 8b8a464576789b13e2d48d4ede662acac3141263 (patch) | |
tree | aa70bd876630056d7c6fc5b41f38d59ddf83e82f /tools | |
parent | 0ecd55223d3f872e70cf1a5302c34248ed854ce6 (diff) | |
download | xorg-lib-libxkbcommon-8b8a464576789b13e2d48d4ede662acac3141263.tar.gz |
tools: allow stdin for compiling keymaps
This connects two tools to be useful together:
xkbcommon-rmlvo-to-kccgst | xkbcommon-print-compiled-keymap -
which will result in the full keymap generated by the former tool.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/print-compiled-keymap.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/tools/print-compiled-keymap.c b/tools/print-compiled-keymap.c index e595ab1..04d98ba 100644 --- a/tools/print-compiled-keymap.c +++ b/tools/print-compiled-keymap.c @@ -27,6 +27,7 @@ #include <stdlib.h> #include <unistd.h> +#include "utils.h" #include "xkbcommon/xkbcommon.h" int @@ -62,10 +63,42 @@ main(int argc, char *argv[]) goto out; } - file = fopen(keymap_path, "rb"); - if (!file) { - fprintf(stderr, "Failed to open path: %s\n", keymap_path); - goto out; + if (streq(keymap_path, "-")) { + FILE *tmp; + + tmp = tmpfile(); + if (!tmp) { + fprintf(stderr, "Failed to create tmpfile\n"); + goto out; + } + + while (true) { + char buf[4096]; + size_t len; + + len = fread(buf, 1, sizeof(buf), stdin); + if (ferror(stdin)) { + fprintf(stderr, "Failed to read from stdin\n"); + goto out; + } + if (len > 0) { + size_t wlen = fwrite(buf, 1, len, tmp); + if (wlen != len) { + fprintf(stderr, "Failed to write to tmpfile\n"); + goto out; + } + } + if (feof(stdin)) + break; + } + fseek(tmp, 0, SEEK_SET); + file = tmp; + } else { + 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, |