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)
36 struct xkb_keymap *keymap;
38 keymap = xkb_keymap_new(ctx);
42 if (file->file_type != FILE_TYPE_KEYMAP) {
43 log_err(ctx, "Cannot compile a %s file alone into a keymap\n",
44 xkb_file_type_to_string(file->file_type));
48 if (!CompileKeymap(file, keymap, MERGE_OVERRIDE)) {
49 log_err(ctx, "Failed to compile keymap\n");
56 xkb_keymap_unref(keymap);
60 XKB_EXPORT struct xkb_keymap *
61 xkb_keymap_new_from_names(struct xkb_context *ctx,
62 const struct xkb_rule_names *rmlvo_in,
63 enum xkb_keymap_compile_flags flags)
66 struct xkb_component_names kccgst;
67 struct xkb_rule_names rmlvo = *rmlvo_in;
69 struct xkb_keymap *keymap;
71 if (isempty(rmlvo.rules))
72 rmlvo.rules = DEFAULT_XKB_RULES;
73 if (isempty(rmlvo.model))
74 rmlvo.model = DEFAULT_XKB_MODEL;
75 if (isempty(rmlvo.layout))
76 rmlvo.layout = DEFAULT_XKB_LAYOUT;
79 "Compiling from RMLVO: rules '%s', model '%s', layout '%s', "
80 "variant '%s', options '%s'\n",
81 strnull(rmlvo.rules), strnull(rmlvo.model),
82 strnull(rmlvo.layout), strnull(rmlvo.variant),
83 strnull(rmlvo.options));
85 ok = xkb_components_from_rules(ctx, &rmlvo, &kccgst);
88 "Couldn't look up rules '%s', model '%s', layout '%s', "
89 "variant '%s', options '%s'\n",
90 strnull(rmlvo.rules), strnull(rmlvo.model),
91 strnull(rmlvo.layout), strnull(rmlvo.variant),
92 strnull(rmlvo.options));
97 "Compiling from KcCGST: keycodes '%s', types '%s', "
98 "compat '%s', symbols '%s'\n",
99 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
101 file = XkbFileFromComponents(ctx, &kccgst);
103 free(kccgst.keycodes);
106 free(kccgst.symbols);
110 "Failed to generate parsed XKB file from components\n");
114 keymap = compile_keymap_file(ctx, file);
119 XKB_EXPORT struct xkb_keymap *
120 xkb_keymap_new_from_string(struct xkb_context *ctx,
122 enum xkb_keymap_format format,
123 enum xkb_keymap_compile_flags flags)
127 struct xkb_keymap *keymap;
129 if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
130 log_err(ctx, "Unsupported keymap format %d\n", format);
135 log_err(ctx, "No string specified to generate XKB keymap\n");
139 ok = XkbParseString(ctx, string, "input", &file);
141 log_err(ctx, "Failed to parse input xkb file\n");
145 keymap = compile_keymap_file(ctx, file);
150 XKB_EXPORT struct xkb_keymap *
151 xkb_keymap_new_from_file(struct xkb_context *ctx,
153 enum xkb_keymap_format format,
154 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 ok = XkbParseFile(ctx, file, "(unknown file)", &xkb_file);
172 log_err(ctx, "Failed to parse input xkb file\n");
176 keymap = compile_keymap_file(ctx, xkb_file);
177 FreeXkbFile(xkb_file);