xkbcli: Promote compose to xkbcli-compile-compose Previously this tool was only used for internal testing and thus not installed. But it is useful for debugging, much like xkbcli-compile-keymap.
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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
diff --git a/meson.build b/meson.build
index eaef4fb..d5c4c74 100644
--- a/meson.build
+++ b/meson.build
@@ -460,6 +460,7 @@ if build_tools
install: true,
install_dir: dir_libexec)
install_man('tools/xkbcli-compile-keymap.1')
+ configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
# The same tool again, but with access to some private APIs.
executable('compile-keymap',
'tools/compile-keymap.c',
@@ -470,12 +471,13 @@ if build_tools
install: false)
# Tool: compose
- executable('compose',
- 'tools/compose.c',
+ executable('xkbcli-compile-compose',
+ 'tools/compile-compose.c',
dependencies: tools_dep,
- include_directories: [include_directories('src', 'include')],
- install: false)
- configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
+ install: true,
+ install_dir: dir_libexec)
+ install_man('tools/xkbcli-compile-compose.1')
+ configh_data.set10('HAVE_XKBCLI_COMPILE_COMPOSE', true)
# Tool: how-to-type
executable('xkbcli-how-to-type',
diff --git a/test/tool-option-parsing.py b/test/tool-option-parsing.py
index 4d07661..521c0c3 100755
--- a/test/tool-option-parsing.py
+++ b/test/tool-option-parsing.py
@@ -152,6 +152,7 @@ class TestXkbcli(unittest.TestCase):
)
cls.xkbcli_how_to_type = XkbcliTool("how-to-type")
cls.xkbcli_compile_keymap = XkbcliTool("compile-keymap")
+ cls.xkbcli_compile_compose = XkbcliTool("compile-compose")
cls.xkbcli_interactive_evdev = XkbcliTool(
"interactive-evdev",
skipIf=(
@@ -197,6 +198,7 @@ class TestXkbcli(unittest.TestCase):
cls.xkbcli_list,
cls.xkbcli_how_to_type,
cls.xkbcli_compile_keymap,
+ cls.xkbcli_compile_compose,
cls.xkbcli_interactive_evdev,
cls.xkbcli_interactive_x11,
cls.xkbcli_interactive_wayland,
diff --git a/tools/compile-compose.c b/tools/compile-compose.c
new file mode 100644
index 0000000..e9b7716
--- /dev/null
+++ b/tools/compile-compose.c
@@ -0,0 +1,195 @@
+/*
+ * Copyright © 2021 Ran Benita <ran@unusedvar.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 <getopt.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "xkbcommon/xkbcommon.h"
+#include "xkbcommon/xkbcommon-keysyms.h"
+#include "xkbcommon/xkbcommon-compose.h"
+
+static void
+usage(FILE *fp, char *progname)
+{
+ fprintf(fp,
+ "Usage: %s [--help] [--file FILE] [--locale LOCALE | --locale-from-env | --locale-from-setlocale]\n",
+ progname);
+ fprintf(fp,
+ "\n"
+ "Compile a Compose file and print it\n"
+ "\n"
+ "Options:\n"
+ " --help\n"
+ " Print this help and exit\n"
+ " --file FILE\n"
+ " Specify a Compose file to load\n"
+ " --locale LOCALE\n"
+ " Specify the locale directly\n"
+ " --locale-from-env\n"
+ " Get the locale from the LC_ALL/LC_CTYPE/LANG environment variables (falling back to C)\n"
+ " --locale-from-setlocale\n"
+ " Get the locale using setlocale(3)\n"
+ );
+}
+
+static void
+print_compose_table_entry(struct xkb_compose_table_entry *entry)
+{
+ size_t nsyms;
+ const xkb_keysym_t *syms = xkb_compose_table_entry_sequence(entry, &nsyms);
+ char buf[128];
+ for (size_t i = 0; i < nsyms; i++) {
+ xkb_keysym_get_name(syms[i], buf, sizeof(buf));
+ printf("<%s>", buf);
+ if (i + 1 < nsyms) {
+ printf(" ");
+ }
+ }
+ printf(":");
+ const char *utf8 = xkb_compose_table_entry_utf8(entry);
+ if (*utf8 != '\0') {
+ printf(" \"%s\"", utf8);
+ }
+ const xkb_keysym_t keysym = xkb_compose_table_entry_keysym(entry);
+ if (keysym != XKB_KEY_NoSymbol) {
+ xkb_keysym_get_name(keysym, buf, sizeof(buf));
+ printf(" %s", buf);
+ }
+ printf("\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ret = EXIT_FAILURE;
+ struct xkb_context *ctx = NULL;
+ struct xkb_compose_table *compose_table = NULL;
+ const char *locale = NULL;
+ const char *path = NULL;
+ enum xkb_compose_format format = XKB_COMPOSE_FORMAT_TEXT_V1;
+ enum options {
+ OPT_FILE,
+ OPT_LOCALE,
+ OPT_LOCALE_FROM_ENV,
+ OPT_LOCALE_FROM_SETLOCALE,
+ };
+ static struct option opts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"file", required_argument, 0, OPT_FILE},
+ {"locale", required_argument, 0, OPT_LOCALE},
+ {"locale-from-env", no_argument, 0, OPT_LOCALE_FROM_ENV},
+ {"locale-from-setlocale", no_argument, 0, OPT_LOCALE_FROM_SETLOCALE},
+ {0, 0, 0, 0},
+ };
+
+ setlocale(LC_ALL, "");
+
+ while (1) {
+ int opt;
+ int option_index = 0;
+
+ opt = getopt_long(argc, argv, "h", opts, &option_index);
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case OPT_FILE:
+ path = optarg;
+ break;
+ case OPT_LOCALE:
+ locale = optarg;
+ break;
+ case OPT_LOCALE_FROM_ENV:
+ locale = getenv("LC_ALL");
+ if (!locale)
+ locale = getenv("LC_CTYPE");
+ if (!locale)
+ locale = getenv("LANG");
+ if (!locale)
+ locale = "C";
+ break;
+ case OPT_LOCALE_FROM_SETLOCALE:
+ locale = setlocale(LC_CTYPE, NULL);
+ break;
+ case 'h':
+ usage(stdout, argv[0]);
+ return EXIT_SUCCESS;
+ case '?':
+ usage(stderr, argv[0]);
+ return EXIT_INVALID_USAGE;
+ }
+ }
+ if (locale == NULL) {
+ usage(stderr, argv[0]);
+ return EXIT_INVALID_USAGE;
+ }
+
+ ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ if (!ctx) {
+ fprintf(stderr, "Couldn't create xkb context\n");
+ goto out;
+ }
+
+ if (path != NULL) {
+ FILE *file = fopen(path, "rb");
+ if (file == NULL) {
+ perror(path);
+ goto file_error;
+ }
+ compose_table =
+ xkb_compose_table_new_from_file(ctx, file, locale, format,
+ XKB_COMPOSE_COMPILE_NO_FLAGS);
+ fclose(file);
+ if (!compose_table) {
+ fprintf(stderr, "Couldn't create compose from file: %s\n", path);
+ goto out;
+ }
+ } else {
+ compose_table =
+ xkb_compose_table_new_from_locale(ctx, locale,
+ XKB_COMPOSE_COMPILE_NO_FLAGS);
+ if (!compose_table) {
+ fprintf(stderr,
+ "Couldn't create compose from locale \"%s\"\n", locale);
+ goto out;
+ }
+ }
+
+ struct xkb_compose_table_iterator *iter = xkb_compose_table_iterator_new(compose_table);
+ struct xkb_compose_table_entry *entry;
+ while ((entry = xkb_compose_table_iterator_next(iter))) {
+ print_compose_table_entry(entry);
+ }
+ xkb_compose_table_iterator_free(iter);
+
+out:
+ xkb_compose_table_unref(compose_table);
+file_error:
+ xkb_context_unref(ctx);
+
+ return ret;
+}
diff --git a/tools/compose.c b/tools/compose.c
deleted file mode 100644
index 3a77347..0000000
--- a/tools/compose.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright © 2021 Ran Benita <ran@unusedvar.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 <getopt.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "xkbcommon/xkbcommon.h"
-#include "xkbcommon/xkbcommon-keysyms.h"
-#include "xkbcommon/xkbcommon-compose.h"
-
-static void
-usage(FILE *fp, char *progname)
-{
- fprintf(fp,
- "Usage: %s [--file FILE] [--locale LOCALE | --locale-from-env | --locale-from-setlocale]\n",
- progname);
- fprintf(fp,
- " --file - specify a file to load\n"
- " --locale - specify the locale directly\n"
- " --locale-from-env - get the locale from the LC_ALL/LC_CTYPE/LANG environment variables (falling back to C)\n"
- " --locale-from-setlocale - get the locale using setlocale(3)\n"
- );
-}
-
-static void
-print_compose_table_entry(struct xkb_compose_table_entry *entry)
-{
- size_t nsyms;
- const xkb_keysym_t *syms = xkb_compose_table_entry_sequence(entry, &nsyms);
- char buf[128];
- for (size_t i = 0; i < nsyms; i++) {
- xkb_keysym_get_name(syms[i], buf, sizeof(buf));
- printf("<%s>", buf);
- if (i + 1 < nsyms) {
- printf(" ");
- }
- }
- printf(":");
- const char *utf8 = xkb_compose_table_entry_utf8(entry);
- if (*utf8 != '\0') {
- printf(" \"%s\"", utf8);
- }
- const xkb_keysym_t keysym = xkb_compose_table_entry_keysym(entry);
- if (keysym != XKB_KEY_NoSymbol) {
- xkb_keysym_get_name(keysym, buf, sizeof(buf));
- printf(" %s", buf);
- }
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- int ret = EXIT_FAILURE;
- struct xkb_context *ctx = NULL;
- struct xkb_compose_table *compose_table = NULL;
- const char *locale = NULL;
- const char *path = NULL;
- enum xkb_compose_format format = XKB_COMPOSE_FORMAT_TEXT_V1;
- enum options {
- OPT_FILE,
- OPT_LOCALE,
- OPT_LOCALE_FROM_ENV,
- OPT_LOCALE_FROM_SETLOCALE,
- };
- static struct option opts[] = {
- {"file", required_argument, 0, OPT_FILE},
- {"locale", required_argument, 0, OPT_LOCALE},
- {"locale-from-env", no_argument, 0, OPT_LOCALE_FROM_ENV},
- {"locale-from-setlocale", no_argument, 0, OPT_LOCALE_FROM_SETLOCALE},
- {0, 0, 0, 0},
- };
-
- setlocale(LC_ALL, "");
-
- while (1) {
- int opt;
- int option_index = 0;
-
- opt = getopt_long(argc, argv, "h", opts, &option_index);
- if (opt == -1)
- break;
-
- switch (opt) {
- case OPT_FILE:
- path = optarg;
- break;
- case OPT_LOCALE:
- locale = optarg;
- break;
- case OPT_LOCALE_FROM_ENV:
- locale = getenv("LC_ALL");
- if (!locale)
- locale = getenv("LC_CTYPE");
- if (!locale)
- locale = getenv("LANG");
- if (!locale)
- locale = "C";
- break;
- case OPT_LOCALE_FROM_SETLOCALE:
- locale = setlocale(LC_CTYPE, NULL);
- break;
- case 'h':
- usage(stdout, argv[0]);
- return EXIT_SUCCESS;
- case '?':
- usage(stderr, argv[0]);
- return EXIT_INVALID_USAGE;
- }
- }
- if (locale == NULL) {
- usage(stderr, argv[0]);
- return EXIT_INVALID_USAGE;
- }
-
- ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
- if (!ctx) {
- fprintf(stderr, "Couldn't create xkb context\n");
- goto out;
- }
-
- if (path != NULL) {
- FILE *file = fopen(path, "rb");
- if (file == NULL) {
- perror(path);
- goto file_error;
- }
- compose_table =
- xkb_compose_table_new_from_file(ctx, file, locale, format,
- XKB_COMPOSE_COMPILE_NO_FLAGS);
- fclose(file);
- if (!compose_table) {
- fprintf(stderr, "Couldn't create compose from file: %s\n", path);
- goto out;
- }
- } else {
- compose_table =
- xkb_compose_table_new_from_locale(ctx, locale,
- XKB_COMPOSE_COMPILE_NO_FLAGS);
- if (!compose_table) {
- fprintf(stderr, "Couldn't create compose from locale\n");
- goto out;
- }
- }
-
- struct xkb_compose_table_iterator *iter = xkb_compose_table_iterator_new(compose_table);
- struct xkb_compose_table_entry *entry;
- while ((entry = xkb_compose_table_iterator_next(iter))) {
- print_compose_table_entry(entry);
- }
- xkb_compose_table_iterator_free(iter);
-
-out:
- xkb_compose_table_unref(compose_table);
-file_error:
- xkb_context_unref(ctx);
-
- return ret;
-}
diff --git a/tools/xkbcli-bash-completion.sh b/tools/xkbcli-bash-completion.sh
index fdab116..c900e0f 100755
--- a/tools/xkbcli-bash-completion.sh
+++ b/tools/xkbcli-bash-completion.sh
@@ -73,6 +73,13 @@ ___xkbcli_subcommand()
return;;
esac
;;
+ compile-compose)
+ case ${COMP_WORDS[COMP_CWORD-1]} in
+ --file)
+ _filedir
+ return;;
+ esac
+ ;;
list)
if [[ ${COMP_WORDS[COMP_CWORD]} != -* ]]; then
_filedir
diff --git a/tools/xkbcli-compile-compose.1 b/tools/xkbcli-compile-compose.1
new file mode 100644
index 0000000..6dc65ae
--- /dev/null
+++ b/tools/xkbcli-compile-compose.1
@@ -0,0 +1,39 @@
+.Dd November 7, 2023
+.Dt XKBCLI\-COMPILE\-COMPOSE 1
+.Os
+.
+.Sh NAME
+.Nm "xkbcli compile-compose"
+.Nd compile a Compose file
+.
+.Sh SYNOPSIS
+.Nm
+.Op Ar options
+.
+.Sh DESCRIPTION
+.Nm
+compile and print a Compose file based on the given options
+.
+.Bl -tag -width Ds
+.It Fl \-help
+Print help and exit
+.
+.It Fl \-file Ar FILE
+Specify a Compose file to load
+.
+.It Fl \-locale Ar LOCALE
+Specify a locale
+.
+.It Fl \-locale-from-env
+Get the locale from the LC_ALL/LC_CTYPE/LANG environment variables
+(falling back to C)
+.
+.It Fl \-locale\-from\-setlocale
+Get the locale using
+.Xr setlocale 3
+.El
+.
+.Sh SEE ALSO
+.Xr xkbcli 1 ,
+.Xr Compose 5 ,
+.Lk https://xkbcommon.org "The libxkbcommon online documentation"
diff --git a/tools/xkbcli.1 b/tools/xkbcli.1
index 18f7732..285f463 100644
--- a/tools/xkbcli.1
+++ b/tools/xkbcli.1
@@ -30,7 +30,11 @@ Print the version and exit
.It Ic compile\-keymap
Compile an XKB keymap, see
.Xr xkbcli\-compile\-keymap 1
-
+.
+.It Ic compile\-compose
+Compile a compose file, see
+.Xr xkbcli\-compile\-compose 1
+.
.It Ic how\-to\-type
Show how to type a given Unicode codepoint, see
.Xr xkbcli\-how\-to\-type 1
diff --git a/tools/xkbcli.c b/tools/xkbcli.c
index 3602fb9..df045f5 100644
--- a/tools/xkbcli.c
+++ b/tools/xkbcli.c
@@ -66,6 +66,11 @@ usage(void)
" Compile an XKB keymap\n"
"\n"
#endif
+#if HAVE_XKBCLI_COMPILE_COMPOSE
+ " compile-compose\n"
+ " Compile a Compose file\n"
+ "\n"
+#endif
#if HAVE_XKBCLI_HOW_TO_TYPE
" how-to-type\n"
" Print key sequences to type a Unicode codepoint\n"