Removed build dependency on kbproto.
[platform/upstream/libxkbcommon.git] / tools / xkbcli.c
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
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            /* WARNING: The following is parsed by the bash completion script.
41             *          Any change to the format (in particular to the indentation)
42             *          should kept in the script in sync. */
43            "Commands:\n"
44 #if HAVE_XKBCLI_LIST
45            "  list\n"
46            "    List available rules, models, layouts, variants and options\n"
47            "\n"
48 #endif
49 #if HAVE_XKBCLI_INTERACTIVE_WAYLAND
50            "  interactive-wayland\n"
51            "    Interactive debugger for XKB keymaps for Wayland\n"
52            "\n"
53 #endif
54 #if HAVE_XKBCLI_INTERACTIVE_X11
55            "  interactive-x11\n"
56            "    Interactive debugger for XKB keymaps for X11\n"
57            "\n"
58 #endif
59 #if HAVE_XKBCLI_INTERACTIVE_EVDEV
60            "  interactive-evdev\n"
61            "    Interactive debugger for XKB keymaps for evdev\n"
62            "\n"
63 #endif
64 #if HAVE_XKBCLI_COMPILE_KEYMAP
65            "  compile-keymap\n"
66            "    Compile an XKB keymap\n"
67            "\n"
68 #endif
69 #if HAVE_XKBCLI_HOW_TO_TYPE
70            "  how-to-type\n"
71            "    Print key sequences to type a Unicode codepoint\n"
72            "\n"
73 #endif
74            );
75 }
76
77 int
78 main(int argc, char **argv)
79 {
80     enum options {
81         OPT_HELP = 1,
82         OPT_VERSION,
83     };
84     int option_index = 0;
85
86     while (1) {
87         int c;
88         static struct option opts[] = {
89             { "help",    no_argument, 0, OPT_HELP },
90             { "version", no_argument, 0, OPT_VERSION },
91             { 0, 0, 0, 0}
92         };
93
94         c = getopt_long(argc, argv, "+hV", opts, &option_index);
95         if (c == -1)
96             break;
97
98         switch(c) {
99             case 'h':
100             case OPT_HELP:
101                 usage();
102                 return EXIT_SUCCESS;
103             case 'V':
104             case OPT_VERSION:
105                 printf("%s\n", LIBXKBCOMMON_VERSION);
106                 return EXIT_SUCCESS;
107             default:
108                 usage();
109                 return EXIT_INVALID_USAGE;
110         }
111     }
112
113     if (optind >= argc) {
114         usage();
115         return EXIT_INVALID_USAGE;
116     }
117
118     argv += optind;
119     argc -= optind;
120
121     return tools_exec_command("xkbcli", argc, argv);
122 }