1 /*
2 * Copyright © 2020 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25
26 #include <getopt.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "tools-common.h"
31
32 static void
usage(void)33 usage(void)
34 {
35 printf("Usage: xkbcli [--help|-h] [--version|-V] <command> [<args>]\n"
36 "\n"
37 "Global options:\n"
38 " -h, --help ...... show this help and exit\n"
39 " -V, --version ... show version information and exit\n"
40 "Commands:\n"
41 #if HAVE_XKBCLI_LIST
42 " list\n"
43 " List available rules, models, layouts, variants and options\n"
44 "\n"
45 #endif
46 #if HAVE_XKBCLI_INTERACTIVE_WAYLAND
47 " interactive-wayland\n"
48 " Interactive debugger for XKB keymaps for Wayland\n"
49 "\n"
50 #endif
51 #if HAVE_XKBCLI_INTERACTIVE_X11
52 " interactive-x11\n"
53 " Interactive debugger for XKB keymaps for X11\n"
54 "\n"
55 #endif
56 #if HAVE_XKBCLI_INTERACTIVE_EVDEV
57 " interactive-evdev\n"
58 " Interactive debugger for XKB keymaps for evdev (Linux)\n"
59 "\n"
60 #endif
61 #if HAVE_XKBCLI_COMPILE_KEYMAP
62 " compile-keymap\n"
63 " Compile an XKB keymap\n"
64 "\n"
65 #endif
66 #if HAVE_XKBCLI_HOW_TO_TYPE
67 " how-to-type\n"
68 " Print key sequences to type a Unicode codepoint\n"
69 "\n"
70 #endif
71 );
72 }
73
74 int
main(int argc,char ** argv)75 main(int argc, char **argv)
76 {
77 enum options {
78 OPT_HELP = 1,
79 OPT_VERSION,
80 };
81 int option_index = 0;
82
83 while (1) {
84 int c;
85 static struct option opts[] = {
86 { "help", no_argument, 0, OPT_HELP },
87 { "version", no_argument, 0, OPT_VERSION },
88 { 0, 0, 0, 0}
89 };
90
91 c = getopt_long(argc, argv, "+hV", opts, &option_index);
92 if (c == -1)
93 break;
94
95 switch(c) {
96 case 'h':
97 case OPT_HELP:
98 usage();
99 return EXIT_SUCCESS;
100 case 'V':
101 case OPT_VERSION:
102 printf("%s\n", LIBXKBCOMMON_VERSION);
103 return EXIT_SUCCESS;
104 default:
105 usage();
106 return EXIT_INVALID_USAGE;
107 }
108 }
109
110 if (optind >= argc) {
111 usage();
112 return EXIT_INVALID_USAGE;
113 }
114
115 argv += optind;
116 argc -= optind;
117
118 return tools_exec_command("xkbcli", argc, argv);
119 }
120