2 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of Silicon Graphics not be
10 * used in advertising or publicity pertaining to distribution
11 * of the software without specific prior written permission.
12 * Silicon Graphics makes no representation about the suitability
13 * of this software for any purpose. It is provided "as is"
14 * without any express or implied warranty.
16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into)
37 darray_free(into->map);
39 for (i = 0; i < into->num_levels; i++)
40 free(into->level_names[i]);
41 free(into->level_names);
45 darray_copy(into->map, from->map);
47 if (from->preserve && !darray_empty(into->map)) {
48 into->preserve = calloc(darray_size(into->map),
49 sizeof(*into->preserve));
52 memcpy(into->preserve, from->preserve,
53 darray_size(into->map) * sizeof(*into->preserve));
56 if (from->level_names && into->num_levels > 0) {
57 into->level_names = calloc(into->num_levels,
58 sizeof(*into->level_names));
59 if (!into->level_names)
62 for (i = 0; i < into->num_levels; i++)
63 into->level_names[i] = strdup(from->level_names[i]);
70 XkbcResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
73 size_t old_ndx, old_num_acts, new_ndx;
80 if (XkbKeyHasActions(key) && key->width >= needed)
81 return XkbKeyActionsPtr(keymap, key);
84 * The key may already be in the array, but without enough space.
85 * This should not happen often, so in order to avoid moving and
86 * copying stuff from acts and key_acts, we just allocate new
87 * space for the key at the end, and leave the old space alone.
90 old_ndx = key->acts_index;
91 old_num_acts = XkbKeyNumActions(key);
92 new_ndx = darray_size(keymap->acts);
94 darray_resize0(keymap->acts, new_ndx + needed);
95 key->acts_index = new_ndx;
98 * The key was already in the array, copy the old actions to the
102 memcpy(darray_mem(keymap->acts, new_ndx),
103 darray_mem(keymap->acts, old_ndx),
104 old_num_acts * sizeof(union xkb_action));
106 return XkbKeyActionsPtr(keymap, key);
110 free_types(struct xkb_keymap *keymap)
112 struct xkb_key_type *type;
114 darray_foreach(type, keymap->types) {
116 darray_free(type->map);
117 free(type->preserve);
118 for (j = 0; j < type->num_levels; j++)
119 free(type->level_names[j]);
120 free(type->level_names);
123 darray_free(keymap->types);
127 free_keys(struct xkb_keymap *keymap)
131 darray_foreach(key, keymap->keys) {
132 free(key->sym_index);
134 darray_free(key->syms);
137 darray_free(keymap->keys);
141 free_names(struct xkb_keymap *keymap)
145 for (i = 0; i < XkbNumVirtualMods; i++)
146 free(keymap->vmod_names[i]);
148 for (i = 0; i < XkbNumIndicators; i++)
149 free(keymap->indicator_names[i]);
151 for (i = 0; i < XkbNumKbdGroups; i++)
152 free(keymap->group_names[i]);
154 darray_free(keymap->key_aliases);
156 free(keymap->keycodes_section_name);
157 free(keymap->symbols_section_name);
158 free(keymap->types_section_name);
159 free(keymap->compat_section_name);
163 XkbcAllocKeyboard(struct xkb_context *ctx)
165 struct xkb_keymap *keymap;
167 keymap = calloc(1, sizeof(*keymap));
172 keymap->ctx = xkb_context_ref(ctx);
178 XkbcFreeKeyboard(struct xkb_keymap *keymap)
184 darray_free(keymap->acts);
185 darray_free(keymap->sym_interpret);
188 xkb_context_unref(keymap->ctx);