2 * Copyright © 2009 Dan Nicholson
3 * Copyright © 2012 Intel Corporation
4 * Copyright © 2012 Ran Benita <ran234@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Authors: Dan Nicholson <dbn.lists@gmail.com>
26 * Ran Benita <ran234@gmail.com>
27 * Daniel Stone <daniel@fooishbar.org>
30 #include "xkbcomp-priv.h"
33 static struct xkb_keymap *
34 compile_keymap_file(struct xkb_context *ctx, XkbFile *file,
35 enum xkb_keymap_format format,
36 enum xkb_keymap_compile_flags flags)
38 struct xkb_keymap *keymap;
40 keymap = xkb_keymap_new(ctx, format, flags);
44 if (file->file_type != FILE_TYPE_KEYMAP) {
45 log_err(ctx, "Cannot compile a %s file alone into a keymap\n",
46 xkb_file_type_to_string(file->file_type));
50 if (!CompileKeymap(file, keymap, MERGE_OVERRIDE)) {
51 log_err(ctx, "Failed to compile keymap\n");
58 xkb_keymap_unref(keymap);
62 XKB_EXPORT struct xkb_keymap *
63 xkb_keymap_new_from_names(struct xkb_context *ctx,
64 const struct xkb_rule_names *rmlvo_in,
65 enum xkb_keymap_compile_flags flags)
68 struct xkb_component_names kccgst;
69 struct xkb_rule_names rmlvo = *rmlvo_in;
71 struct xkb_keymap *keymap;
73 if (isempty(rmlvo.rules))
74 rmlvo.rules = DEFAULT_XKB_RULES;
75 if (isempty(rmlvo.model))
76 rmlvo.model = DEFAULT_XKB_MODEL;
77 if (isempty(rmlvo.layout))
78 rmlvo.layout = DEFAULT_XKB_LAYOUT;
81 "Compiling from RMLVO: rules '%s', model '%s', layout '%s', "
82 "variant '%s', options '%s'\n",
83 strnull(rmlvo.rules), strnull(rmlvo.model),
84 strnull(rmlvo.layout), strnull(rmlvo.variant),
85 strnull(rmlvo.options));
87 ok = xkb_components_from_rules(ctx, &rmlvo, &kccgst);
90 "Couldn't look up rules '%s', model '%s', layout '%s', "
91 "variant '%s', options '%s'\n",
92 strnull(rmlvo.rules), strnull(rmlvo.model),
93 strnull(rmlvo.layout), strnull(rmlvo.variant),
94 strnull(rmlvo.options));
99 "Compiling from KcCGST: keycodes '%s', types '%s', "
100 "compat '%s', symbols '%s'\n",
101 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
103 file = XkbFileFromComponents(ctx, &kccgst);
105 free(kccgst.keycodes);
108 free(kccgst.symbols);
112 "Failed to generate parsed XKB file from components\n");
116 keymap = compile_keymap_file(ctx, file, XKB_KEYMAP_FORMAT_TEXT_V1, flags);
121 XKB_EXPORT struct xkb_keymap *
122 xkb_keymap_new_from_string(struct xkb_context *ctx,
124 enum xkb_keymap_format format,
125 enum xkb_keymap_compile_flags flags)
128 struct xkb_keymap *keymap;
130 if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
131 log_err(ctx, "Unsupported keymap format %d\n", format);
136 log_err(ctx, "No string specified to generate XKB keymap\n");
140 file = XkbParseString(ctx, string, "input");
142 log_err(ctx, "Failed to parse input xkb file\n");
146 keymap = compile_keymap_file(ctx, file, format, flags);
151 XKB_EXPORT struct xkb_keymap *
152 xkb_keymap_new_from_file(struct xkb_context *ctx,
154 enum xkb_keymap_format format,
155 enum xkb_keymap_compile_flags flags)
158 struct xkb_keymap *keymap;
160 if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
161 log_err(ctx, "Unsupported keymap format %d\n", format);
166 log_err(ctx, "No file specified to generate XKB keymap\n");
170 xkb_file = XkbParseFile(ctx, file, "(unknown file)");
172 log_err(ctx, "Failed to parse input xkb file\n");
176 keymap = compile_keymap_file(ctx, xkb_file, format, flags);
177 FreeXkbFile(xkb_file);