Hash :
b4b40d73
Author :
Date :
2012-09-12T16:54:07
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
/*
* Copyright © 2009 Dan Nicholson
* Copyright © 2012 Intel Corporation
* Copyright © 2012 Ran Benita <ran234@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors: Dan Nicholson <dbn.lists@gmail.com>
* Ran Benita <ran234@gmail.com>
* Daniel Stone <daniel@fooishbar.org>
*/
#include "xkbcomp-priv.h"
#include "rules.h"
static struct xkb_keymap *
compile_keymap_file(struct xkb_context *ctx, XkbFile *file)
{
struct xkb_keymap *keymap;
keymap = xkb_map_new(ctx);
if (!keymap)
goto err;
if (file->file_type != FILE_TYPE_KEYMAP) {
log_err(ctx, "Cannot compile a %s file alone into a keymap\n",
xkb_file_type_to_string(file->file_type));
goto err;
}
if (!CompileKeymap(file, keymap, MERGE_OVERRIDE)) {
log_err(ctx, "Failed to compile keymap\n");
goto err;
}
return keymap;
err:
xkb_map_unref(keymap);
return NULL;
}
XKB_EXPORT struct xkb_keymap *
xkb_map_new_from_names(struct xkb_context *ctx,
const struct xkb_rule_names *rmlvo_in,
enum xkb_map_compile_flags flags)
{
bool ok;
struct xkb_component_names kccgst;
struct xkb_rule_names rmlvo = *rmlvo_in;
XkbFile *file;
struct xkb_keymap *keymap;
if (isempty(rmlvo.rules))
rmlvo.rules = DEFAULT_XKB_RULES;
if (isempty(rmlvo.model))
rmlvo.model = DEFAULT_XKB_MODEL;
if (isempty(rmlvo.layout))
rmlvo.layout = DEFAULT_XKB_LAYOUT;
log_dbg(ctx,
"Compiling from RMLVO: rules '%s', model '%s', layout '%s', "
"variant '%s', options '%s'\n",
strnull(rmlvo.rules), strnull(rmlvo.model),
strnull(rmlvo.layout), strnull(rmlvo.variant),
strnull(rmlvo.options));
ok = xkb_components_from_rules(ctx, &rmlvo, &kccgst);
if (!ok) {
log_err(ctx,
"Couldn't look up rules '%s', model '%s', layout '%s', "
"variant '%s', options '%s'\n",
strnull(rmlvo.rules), strnull(rmlvo.model),
strnull(rmlvo.layout), strnull(rmlvo.variant),
strnull(rmlvo.options));
return NULL;
}
log_dbg(ctx,
"Compiling from KcCGST: keycodes '%s', types '%s', "
"compat '%s', symbols '%s'\n",
kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
file = XkbFileFromComponents(ctx, &kccgst);
free(kccgst.keycodes);
free(kccgst.types);
free(kccgst.compat);
free(kccgst.symbols);
if (!file) {
log_err(ctx,
"Failed to generate parsed XKB file from components\n");
return NULL;
}
keymap = compile_keymap_file(ctx, file);
FreeXkbFile(file);
return keymap;
}
XKB_EXPORT struct xkb_keymap *
xkb_map_new_from_string(struct xkb_context *ctx,
const char *string,
enum xkb_keymap_format format,
enum xkb_map_compile_flags flags)
{
bool ok;
XkbFile *file;
struct xkb_keymap *keymap;
if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
log_err(ctx, "Unsupported keymap format %d\n", format);
return NULL;
}
if (!string) {
log_err(ctx, "No string specified to generate XKB keymap\n");
return NULL;
}
ok = XkbParseString(ctx, string, "input", &file);
if (!ok) {
log_err(ctx, "Failed to parse input xkb file\n");
return NULL;
}
keymap = compile_keymap_file(ctx, file);
FreeXkbFile(file);
return keymap;
}
XKB_EXPORT struct xkb_keymap *
xkb_map_new_from_file(struct xkb_context *ctx,
FILE *file,
enum xkb_keymap_format format,
enum xkb_map_compile_flags flags)
{
bool ok;
XkbFile *xkb_file;
struct xkb_keymap *keymap;
if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
log_err(ctx, "Unsupported keymap format %d\n", format);
return NULL;
}
if (!file) {
log_err(ctx, "No file specified to generate XKB keymap\n");
return NULL;
}
ok = XkbParseFile(ctx, file, "(unknown file)", &xkb_file);
if (!ok) {
log_err(ctx, "Failed to parse input xkb file\n");
return NULL;
}
keymap = compile_keymap_file(ctx, xkb_file);
FreeXkbFile(xkb_file);
return keymap;
}