2 * Copyright © 2020 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.
30 #include "xkbcommon/xkbregistry.h"
33 usage(const char *progname, FILE *fp)
36 "Usage: %s [OPTIONS] [/path/to/xkb_base_directory [/path2]...]\n"
39 " --verbose, -v .......... Increase verbosity, use multiple times for debugging output\n"
40 " --ruleset=foo .......... Load the 'foo' ruleset\n"
41 " --skip-default-paths ... Do not load the default XKB paths\n"
42 " --load-exotic .......... Load the exotic (extra) rulesets\n"
44 "Trailing arguments are treated as XKB base directory installations.\n",
49 main(int argc, char **argv)
52 struct rxkb_context *ctx = NULL;
54 struct rxkb_layout *l;
55 struct rxkb_option_group *g;
56 enum rxkb_context_flags flags = RXKB_CONTEXT_NO_FLAGS;
57 bool load_defaults = true;
59 const char *ruleset = DEFAULT_XKB_RULES;
61 static const struct option opts[] = {
62 {"help", no_argument, 0, 'h'},
63 {"verbose", no_argument, 0, 'v'},
64 {"load-exotic", no_argument, 0, 'e'},
65 {"skip-default-paths", no_argument, 0, 'd'},
66 {"ruleset", required_argument, 0, 'r'},
74 c = getopt_long(argc, argv, "hev", opts, &option_index);
80 usage(argv[0], stdout);
83 usage(argv[0], stderr);
84 return EXIT_INVALID_USAGE;
86 load_defaults = false;
89 flags |= RXKB_CONTEXT_LOAD_EXOTIC_RULES;
101 flags |= RXKB_CONTEXT_NO_DEFAULT_INCLUDES;
103 ctx = rxkb_context_new(flags);
108 rxkb_context_set_log_level(ctx, RXKB_LOG_LEVEL_ERROR);
111 rxkb_context_set_log_level(ctx, RXKB_LOG_LEVEL_INFO);
114 rxkb_context_set_log_level(ctx, RXKB_LOG_LEVEL_DEBUG);
119 for (int i = optind; i < argc; i++) {
120 if (!rxkb_context_include_path_append(ctx, argv[i])) {
121 fprintf(stderr, "Failed to append include path '%s'\n",
128 if (!rxkb_context_include_path_append_default(ctx)) {
129 fprintf(stderr, "Failed to include default paths.\n");
134 if (!rxkb_context_parse(ctx, ruleset)) {
135 fprintf(stderr, "Failed to parse XKB descriptions.\n");
140 m = rxkb_model_first(ctx);
141 assert(m); /* Empty model list is usually a bug or a bad xml file */
143 const char *vendor = rxkb_model_get_vendor(m);
144 printf("- name: %s\n"
146 " description: %s\n",
147 rxkb_model_get_name(m),
148 vendor ? vendor : "''",
149 rxkb_model_get_description(m));
150 m = rxkb_model_next(m);
154 printf("layouts:\n");
155 l = rxkb_layout_first(ctx);
156 assert(l); /* Empty layout list is usually a bug or a bad xml file */
158 struct rxkb_iso639_code *iso639;
159 struct rxkb_iso3166_code *iso3166;
160 const char *variant = rxkb_layout_get_variant(l);
161 const char *brief = rxkb_layout_get_brief(l);
163 printf("- layout: '%s'\n"
166 " description: %s\n",
167 rxkb_layout_get_name(l),
168 variant ? variant : "",
169 brief ? brief : "''",
170 rxkb_layout_get_description(l));
172 printf(" iso639: [");
173 iso639 = rxkb_layout_get_iso639_first(l);
175 const char *sep = "";
177 printf("%s'%s'", sep, rxkb_iso639_code_get_code(iso639));
178 iso639 = rxkb_iso639_code_next(iso639);
183 printf(" iso3166: [");
184 iso3166 = rxkb_layout_get_iso3166_first(l);
186 const char *sep = "";
188 printf("%s'%s'", sep, rxkb_iso3166_code_get_code(iso3166));
189 iso3166 = rxkb_iso3166_code_next(iso3166);
194 l = rxkb_layout_next(l);
197 printf("option_groups:\n");
198 g = rxkb_option_group_first(ctx);
199 assert(g); /* Empty option goups list is usually a bug or a bad xml file */
201 struct rxkb_option *o;
203 printf("- name: '%s'\n"
205 " allows_multiple: %s\n"
207 rxkb_option_group_get_name(g),
208 rxkb_option_group_get_description(g),
209 rxkb_option_group_allows_multiple(g) ? "true" : "false");
211 o = rxkb_option_first(g);
212 assert(o); /* Empty option list is usually a bug or a bad xml file */
214 const char *brief = rxkb_option_get_brief(o);
216 printf(" - name: '%s'\n"
218 " description: '%s'\n",
219 rxkb_option_get_name(o),
221 rxkb_option_get_description(o));
222 o = rxkb_option_next(o);
225 g = rxkb_option_group_next(g);
232 rxkb_context_unref(ctx);