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 #include "xkbcommon/xkbcommon.h"
31 #include "XKBcommonint.h"
32 #include <X11/extensions/XKB.h>
35 XkbcAllocCompatMap(struct xkb_desc * xkb, unsigned which, unsigned nSI)
37 struct xkb_compat_map * compat;
38 struct xkb_sym_interpret *prev_interpret;
44 if (xkb->compat->size_si >= nSI)
48 compat->size_si = nSI;
49 if (!compat->sym_interpret)
52 prev_interpret = compat->sym_interpret;
53 compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
54 nSI, struct xkb_sym_interpret);
55 if (!compat->sym_interpret) {
57 compat->size_si = compat->num_si = 0;
61 if (compat->num_si != 0)
62 _XkbClearElems(compat->sym_interpret, compat->num_si,
63 compat->size_si - 1, struct xkb_sym_interpret);
68 compat = _XkbTypedCalloc(1, struct xkb_compat_map);
73 compat->sym_interpret = _XkbTypedCalloc(nSI, struct xkb_sym_interpret);
74 if (!compat->sym_interpret) {
79 compat->size_si = nSI;
81 memset(&compat->groups[0], 0, XkbNumKbdGroups * sizeof(struct xkb_mods));
89 XkbcFreeCompatMap(struct xkb_desc * xkb)
91 struct xkb_compat_map * compat;
93 if (!xkb || !xkb->compat)
98 free(compat->sym_interpret);
104 XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases)
106 struct xkb_names * names;
112 xkb->names = _XkbTypedCalloc(1, struct xkb_names);
118 if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
120 struct xkb_key_type * type;
122 type = xkb->map->types;
123 for (i = 0; i < xkb->map->num_types; i++, type++) {
124 if (!type->level_names) {
125 type->level_names = _XkbTypedCalloc(type->num_levels, const char *);
126 if (!type->level_names)
132 if ((which & XkbKeyNamesMask) && !names->keys) {
133 if (!xkb_keymap_keycode_range_is_legal(xkb))
136 names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
141 if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
142 if (!names->key_aliases)
143 names->key_aliases = _XkbTypedCalloc(nTotalAliases,
144 struct xkb_key_alias);
145 else if (nTotalAliases > names->num_key_aliases) {
146 struct xkb_key_alias *prev_aliases = names->key_aliases;
148 names->key_aliases = _XkbTypedRealloc(names->key_aliases,
150 struct xkb_key_alias);
151 if (names->key_aliases)
152 _XkbClearElems(names->key_aliases, names->num_key_aliases,
153 nTotalAliases - 1, struct xkb_key_alias);
158 if (!names->key_aliases) {
159 names->num_key_aliases = 0;
163 names->num_key_aliases = nTotalAliases;
170 XkbcFreeNames(struct xkb_desc * xkb)
172 struct xkb_names * names;
173 struct xkb_client_map * map;
176 if (!xkb || !xkb->names)
182 if (map && map->types) {
183 struct xkb_key_type * type = map->types;
185 for (i = 0; i < map->num_types; i++, type++) {
187 for (j = 0; j < type->num_levels; j++)
188 free((char *) type->level_names[i]);
189 free(type->level_names);
190 type->level_names = NULL;
194 for (i = 0; i < XkbNumVirtualMods; i++)
195 free((char *) names->vmods[i]);
196 for (i = 0; i < XkbNumIndicators; i++)
197 free((char *) names->indicators[i]);
198 for (i = 0; i < XkbNumKbdGroups; i++)
199 free((char *) names->groups[i]);
202 free(names->key_aliases);
208 XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
214 xkb->ctrls = _XkbTypedCalloc(1, struct xkb_controls);
219 if (!xkb->ctrls->per_key_repeat) {
220 xkb->ctrls->per_key_repeat = _XkbTypedCalloc(xkb->max_key_code << 3,
222 if (!xkb->ctrls->per_key_repeat)
230 XkbcFreeControls(struct xkb_desc * xkb)
232 if (xkb && xkb->ctrls) {
233 free(xkb->ctrls->per_key_repeat);
240 XkbcAllocIndicatorMaps(struct xkb_desc * xkb)
245 if (!xkb->indicators) {
246 xkb->indicators = _XkbTypedCalloc(1, struct xkb_indicator);
247 if (!xkb->indicators)
255 XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
258 free(xkb->indicators);
259 xkb->indicators = NULL;
264 XkbcAllocKeyboard(void)
266 struct xkb_desc *xkb;
268 xkb = _XkbTypedCalloc(1, struct xkb_desc);
270 xkb->device_spec = XkbUseCoreKbd;
275 XkbcFreeKeyboard(struct xkb_desc * xkb)
280 XkbcFreeClientMap(xkb);
281 XkbcFreeServerMap(xkb);
282 XkbcFreeCompatMap(xkb);
283 XkbcFreeIndicatorMaps(xkb);
285 XkbcFreeControls(xkb);