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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
diff --git a/meson.build b/meson.build
index 9645abb..9a5079d 100644
--- a/meson.build
+++ b/meson.build
@@ -520,7 +520,6 @@ tools_dep = declare_dependency(
)
if cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
- executable('xkbcommon-rmlvo-to-kccgst', 'tools/rmlvo-to-kccgst.c', dependencies: tools_dep)
executable('xkbcommon-rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
executable('xkbcommon-print-compiled-keymap', 'tools/print-compiled-keymap.c', dependencies: tools_dep)
executable('xkbcommon-how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
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;