From bc330c00e66b237a683ed2c5421233a774faa923 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Tue, 7 Nov 2023 12:58:20 +0100 Subject: [PATCH] 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. --- meson.build | 12 ++++---- test/tool-option-parsing.py | 2 ++ tools/{compose.c => compile-compose.c} | 24 ++++++++++++---- tools/xkbcli-bash-completion.sh | 7 +++++ tools/xkbcli-compile-compose.1 | 39 ++++++++++++++++++++++++++ tools/xkbcli.1 | 6 +++- tools/xkbcli.c | 5 ++++ 7 files changed, 83 insertions(+), 12 deletions(-) rename tools/{compose.c => compile-compose.c} (86%) create mode 100644 tools/xkbcli-compile-compose.1 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/compose.c b/tools/compile-compose.c similarity index 86% rename from tools/compose.c rename to tools/compile-compose.c index 3a77347..e9b7716 100644 --- a/tools/compose.c +++ b/tools/compile-compose.c @@ -36,13 +36,23 @@ static void usage(FILE *fp, char *progname) { fprintf(fp, - "Usage: %s [--file FILE] [--locale LOCALE | --locale-from-env | --locale-from-setlocale]\n", + "Usage: %s [--help] [--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" + "\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" ); } @@ -88,6 +98,7 @@ main(int argc, char *argv[]) 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}, @@ -162,7 +173,8 @@ main(int argc, char *argv[]) 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"); + fprintf(stderr, + "Couldn't create compose from locale \"%s\"\n", locale); goto out; } } 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"