summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-07-07 10:40:05 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2020-07-08 15:21:19 +1000
commitfd39147175394b37af64dc2ab314d354fea83a12 (patch)
treefbf14e7340b288bb0458928d7d8c37a256d118ac /tools
parent09d6b965405bd9a1371e3fbd6d8d18a16c17d8a1 (diff)
downloadxorg-lib-libxkbcommon-fd39147175394b37af64dc2ab314d354fea83a12.tar.gz
tools: add ability to print the KcCGST components for rmlvo-to-keymap
This makes the rmlvo-to-kccgst tool obsolete. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/rmlvo-to-kccgst.c106
-rw-r--r--tools/rmlvo-to-keymap.c76
2 files changed, 63 insertions, 119 deletions
diff --git a/tools/rmlvo-to-kccgst.c b/tools/rmlvo-to-kccgst.c
deleted file mode 100644
index 9501890..0000000
--- a/tools/rmlvo-to-kccgst.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright © 2012 Ran Benita <ran234@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "config.h"
-
-#include <unistd.h>
-#include <getopt.h>
-
-#include "xkbcomp/xkbcomp-priv.h"
-#include "xkbcomp/rules.h"
-
-int
-main(int argc, char *argv[])
-{
- struct xkb_rule_names rmlvo = { NULL };
- struct xkb_context *ctx;
- struct xkb_component_names kccgst;
-
- static struct option opts[] = {
- {"help", no_argument, 0, 'h'},
- {"rules", required_argument, 0, 'r'},
- {"model", required_argument, 0, 'm'},
- {"layout", required_argument, 0, 'l'},
- {"variant", required_argument, 0, 'v'},
- {"options", required_argument, 0, 'o'},
- {0, 0, 0, 0},
- };
-
- while (1) {
- int c;
- int option_index = 0;
-
- c = getopt_long(argc, argv, "r:m:l:v:o:h", opts, &option_index);
- if (c == -1)
- break;
-
- switch (c) {
- case 'r':
- rmlvo.rules = optarg;
- break;
- case 'm':
- rmlvo.model = optarg;
- break;
- case 'l':
- rmlvo.layout = optarg;
- break;
- case 'v':
- rmlvo.variant = optarg;
- break;
- case 'o':
- rmlvo.options = optarg;
- break;
- case 'h':
- case '?':
- fprintf(stderr, "Usage: %s [-r <rules>] [-m <model>] "
- "[-l <layout>] [-v <variant>] [-o <options>]\n",
- argv[0]);
- return 1;
- }
- }
-
- ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
- if (!ctx) {
- fprintf(stderr, "Failed to get xkb context\n");
- return 1;
- }
-
- xkb_context_sanitize_rule_names(ctx, &rmlvo);
-
- if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst))
- return 1;
-
- printf("xkb_keymap {\n"
- " xkb_keycodes { include \"%s\" };\n"
- " xkb_types { include \"%s\" };\n"
- " xkb_compat { include \"%s\" };\n"
- " xkb_symbols { include \"%s\" };\n"
- "};\n", kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
-
- free(kccgst.keycodes);
- free(kccgst.types);
- free(kccgst.compat);
- free(kccgst.symbols);
- xkb_context_unref(ctx);
- return 0;
-}
diff --git a/tools/rmlvo-to-keymap.c b/tools/rmlvo-to-keymap.c
index 40ef52f..77e350f 100644
--- a/tools/rmlvo-to-keymap.c
+++ b/tools/rmlvo-to-keymap.c
@@ -31,8 +31,16 @@
#include <stdlib.h>
#include <string.h>
+#include "xkbcomp/xkbcomp-priv.h"
+#include "xkbcomp/rules.h"
#include "xkbcommon/xkbcommon.h"
+static bool verbose = false;
+static enum output_format {
+ FORMAT_KEYMAP,
+ FORMAT_KCCGST,
+} output_format = FORMAT_KEYMAP;
+
static void
usage(char **argv)
{
@@ -43,6 +51,8 @@ usage(char **argv)
"Options:\n"
" --verbose\n"
" Enable verbose debugging output\n"
+ " --kccgst\n"
+ " Print a keymap which only includes the KcCGST component names instead of the full keymap\n"
"\n"
"XKB-specific options:\n"
" --rules <rules>\n"
@@ -63,10 +73,11 @@ usage(char **argv)
}
static bool
-parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names)
+parse_options(int argc, char **argv, struct xkb_rule_names *names)
{
enum options {
OPT_VERBOSE,
+ OPT_KCCGST,
OPT_RULES,
OPT_MODEL,
OPT_LAYOUT,
@@ -76,6 +87,7 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
static struct option opts[] = {
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, OPT_VERBOSE},
+ {"kccgst", no_argument, 0, OPT_KCCGST},
{"rules", required_argument, 0, OPT_RULES},
{"model", required_argument, 0, OPT_MODEL},
{"layout", required_argument, 0, OPT_LAYOUT},
@@ -96,7 +108,10 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
usage(argv);
exit(0);
case OPT_VERBOSE:
- *verbose = true;
+ verbose = true;
+ break;
+ case OPT_KCCGST:
+ output_format = FORMAT_KCCGST;
break;
case OPT_RULES:
names->rules = optarg;
@@ -123,11 +138,48 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
return true;
}
+static bool
+print_kccgst(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo)
+{
+ struct xkb_component_names kccgst;
+
+ if (!xkb_components_from_rules(ctx, rmlvo, &kccgst))
+ return false;
+
+ printf("xkb_keymap {\n"
+ " xkb_keycodes { include \"%s\" };\n"
+ " xkb_types { include \"%s\" };\n"
+ " xkb_compat { include \"%s\" };\n"
+ " xkb_symbols { include \"%s\" };\n"
+ "};\n",
+ kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
+ free(kccgst.keycodes);
+ free(kccgst.types);
+ free(kccgst.compat);
+ free(kccgst.symbols);
+
+ return true;
+}
+
+static bool
+print_keymap(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo)
+{
+ struct xkb_keymap *keymap;
+
+ keymap = xkb_keymap_new_from_names(ctx, rmlvo, XKB_KEYMAP_COMPILE_NO_FLAGS);
+ if (keymap == NULL)
+ return false;
+
+ printf("%s\n", xkb_keymap_get_as_string(keymap,
+ XKB_KEYMAP_FORMAT_TEXT_V1));
+ xkb_keymap_unref(keymap);
+ return true;
+}
+
int
main(int argc, char **argv)
{
struct xkb_context *ctx;
- struct xkb_keymap *keymap;
struct xkb_rule_names names = {
.rules = NULL,
.model = NULL,
@@ -135,15 +187,14 @@ main(int argc, char **argv)
.variant = NULL,
.options = NULL,
};
- int rc;
- bool verbose = false;
+ int rc = 1;
if (argc <= 1) {
usage(argv);
return 1;
}
- if (!parse_options(argc, argv, &verbose, &names))
+ if (!parse_options(argc, argv, &names))
return 1;
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
@@ -154,16 +205,15 @@ main(int argc, char **argv)
xkb_context_set_log_verbosity(ctx, 10);
}
+ xkb_context_sanitize_rule_names(ctx, &names);
xkb_context_include_path_append_default(ctx);
- keymap = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
- rc = (keymap == NULL);
-
- if (rc == 0)
- printf("%s\n", xkb_keymap_get_as_string(keymap,
- XKB_KEYMAP_FORMAT_TEXT_V1));
+ if (output_format == FORMAT_KEYMAP) {
+ rc = print_keymap(ctx, &names) ? EXIT_SUCCESS : EXIT_FAILURE;
+ } else if (output_format == FORMAT_KCCGST) {
+ rc = print_kccgst(ctx, &names) ? EXIT_SUCCESS : EXIT_FAILURE;
+ }
- xkb_keymap_unref(keymap);
xkb_context_unref(ctx);
return rc;