2 * Copyright © 2018 Red Hat, Inc.
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:
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
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.
34 #include "xkbcommon/xkbcommon.h"
36 static bool print = false;
41 printf("Usage: %s [--print] [--rules <rules>] [--layout <layout>] [--variant <variant>] [--options <option>]\n",
43 printf("This tool tests the compilation from RMLVO to a keymap.\n");
44 printf("--print print the resulting keymap\n");
48 parse_options(int argc, char **argv, struct xkb_rule_names *names)
58 static struct option opts[] = {
59 {"help", no_argument, 0, 'h'},
60 {"print", no_argument, 0, OPT_PRINT},
61 {"rules", required_argument, 0, OPT_RULES},
62 {"model", required_argument, 0, OPT_MODEL},
63 {"layout", required_argument, 0, OPT_LAYOUT},
64 {"variant", required_argument, 0, OPT_VARIANT},
65 {"options", required_argument, 0, OPT_OPTION},
72 c = getopt_long(argc, argv, "h", opts, &option_index);
84 names->rules = optarg;
87 names->model = optarg;
90 names->layout = optarg;
93 names->variant = optarg;
96 names->options = optarg;
109 main(int argc, char **argv)
111 struct xkb_context *ctx;
112 struct xkb_keymap *keymap;
113 struct xkb_rule_names names = {
127 if (!parse_options(argc, argv, &names))
130 ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
133 keymap = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
134 rc = (keymap == NULL);
136 if (rc == 0 && print)
137 printf("%s\n", xkb_keymap_get_as_string(keymap,
138 XKB_KEYMAP_FORMAT_TEXT_V1));
140 xkb_keymap_unref(keymap);
141 xkb_context_unref(ctx);