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.
29 #include "X11/XkbCommon.h"
30 #include "XkbCommonInt.h"
32 #include <X11/Xdefs.h>
33 #include <X11/extensions/XKB.h>
36 XkbcAllocCompatMap(XkbcDescPtr xkb,unsigned which,unsigned nSI)
38 XkbCompatMapPtr compat;
39 XkbSymInterpretRec *prev_interpret;
44 if (xkb->compat->size_si>=nSI)
48 if (compat->sym_interpret==NULL)
50 prev_interpret = compat->sym_interpret;
51 compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret,
52 nSI,XkbSymInterpretRec);
53 if (compat->sym_interpret==NULL) {
54 _XkbFree(prev_interpret);
55 compat->size_si= compat->num_si= 0;
58 if (compat->num_si!=0) {
59 _XkbClearElems(compat->sym_interpret,compat->num_si,
60 compat->size_si-1,XkbSymInterpretRec);
64 compat= _XkbTypedCalloc(1,XkbCompatMapRec);
68 compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec);
69 if (!compat->sym_interpret) {
76 bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
83 XkbcFreeCompatMap(XkbcDescPtr xkb,unsigned which,Bool freeMap)
85 register XkbCompatMapPtr compat;
87 if ((xkb==NULL)||(xkb->compat==NULL))
91 which= XkbAllCompatMask;
92 if (which&XkbGroupCompatMask)
93 bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
94 if (which&XkbSymInterpMask) {
95 if ((compat->sym_interpret)&&(compat->size_si>0))
96 _XkbFree(compat->sym_interpret);
97 compat->size_si= compat->num_si= 0;
98 compat->sym_interpret= NULL;
108 XkbcAllocNames(XkbcDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
114 if (xkb->names==NULL) {
115 xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
116 if (xkb->names==NULL)
120 if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
124 type= xkb->map->types;
125 for (i=0;i<xkb->map->num_types;i++,type++) {
126 if (type->level_names==NULL) {
127 type->level_names= _XkbTypedCalloc(type->num_levels,Atom);
128 if (type->level_names==NULL)
133 if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
134 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
135 (!XkbIsLegalKeycode(xkb->max_key_code))||
136 (xkb->max_key_code<xkb->min_key_code))
138 names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec);
139 if (names->keys==NULL)
142 if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) {
143 if (names->key_aliases==NULL) {
144 names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec);
146 else if (nTotalAliases>names->num_key_aliases) {
147 XkbKeyAliasRec *prev_aliases = names->key_aliases;
149 names->key_aliases= _XkbTypedRealloc(names->key_aliases,
150 nTotalAliases,XkbKeyAliasRec);
151 if (names->key_aliases!=NULL) {
152 _XkbClearElems(names->key_aliases,names->num_key_aliases,
153 nTotalAliases-1,XkbKeyAliasRec);
155 _XkbFree(prev_aliases);
158 if (names->key_aliases==NULL) {
159 names->num_key_aliases= 0;
162 names->num_key_aliases= nTotalAliases;
164 if ((which&XkbRGNamesMask)&&(nTotalRG>0)) {
165 if (names->radio_groups==NULL) {
166 names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom);
168 else if (nTotalRG>names->num_rg) {
169 Atom *prev_radio_groups = names->radio_groups;
171 names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG,
173 if (names->radio_groups!=NULL) {
174 _XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1,
177 _XkbFree(prev_radio_groups);
180 if (names->radio_groups==NULL)
182 names->num_rg= nTotalRG;
188 XkbcFreeNames(XkbcDescPtr xkb,unsigned which,Bool freeMap)
192 if ((xkb==NULL)||(xkb->names==NULL))
196 which= XkbAllNamesMask;
197 if (which&XkbKTLevelNamesMask) {
198 XkbClientMapPtr map= xkb->map;
199 if ((map!=NULL)&&(map->types!=NULL)) {
201 register XkbKeyTypePtr type;
203 for (i=0;i<map->num_types;i++,type++) {
204 if (type->level_names!=NULL) {
205 _XkbFree(type->level_names);
206 type->level_names= NULL;
211 if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
212 _XkbFree(names->keys);
216 if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
217 _XkbFree(names->key_aliases);
218 names->key_aliases=NULL;
219 names->num_key_aliases=0;
221 if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
222 _XkbFree(names->radio_groups);
223 names->radio_groups= NULL;
234 XkbcAllocControls(XkbcDescPtr xkb,unsigned which)
239 if (xkb->ctrls==NULL) {
240 xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec);
248 XkbcFreeControls(XkbcDescPtr xkb,unsigned which,Bool freeMap)
250 if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
251 _XkbFree(xkb->ctrls);
258 XkbcAllocIndicatorMaps(XkbcDescPtr xkb)
262 if (xkb->indicators==NULL) {
263 xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec);
264 if (!xkb->indicators)
271 XkbcFreeIndicatorMaps(XkbcDescPtr xkb)
273 if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
274 _XkbFree(xkb->indicators);
275 xkb->indicators= NULL;
281 XkbcAllocKeyboard(void)
285 xkb = _XkbTypedCalloc(1,XkbcDescRec);
287 xkb->device_spec= XkbUseCoreKbd;
292 XkbcFreeKeyboard(XkbcDescPtr xkb,unsigned which,Bool freeAll)
297 which= XkbAllComponentsMask;
298 if (which&XkbClientMapMask)
299 XkbcFreeClientMap(xkb,XkbAllClientInfoMask,True);
300 if (which&XkbServerMapMask)
301 XkbcFreeServerMap(xkb,XkbAllServerInfoMask,True);
302 if (which&XkbCompatMapMask)
303 XkbcFreeCompatMap(xkb,XkbAllCompatMask,True);
304 if (which&XkbIndicatorMapMask)
305 XkbcFreeIndicatorMaps(xkb);
306 if (which&XkbNamesMask)
307 XkbcFreeNames(xkb,XkbAllNamesMask,True);
308 if ((which&XkbGeometryMask) && (xkb->geom!=NULL))
309 XkbcFreeGeometry(xkb->geom,XkbGeomAllMask,True);
310 if (which&XkbControlsMask)
311 XkbcFreeControls(xkb,XkbAllControlsMask,True);
318 XkbcAllocClientMap(XkbcDescPtr xkb,unsigned which,unsigned nTotalTypes)
323 if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes)))
325 if ((which&XkbKeySymsMask)&&
326 ((!XkbIsLegalKeycode(xkb->min_key_code))||
327 (!XkbIsLegalKeycode(xkb->max_key_code))||
328 (xkb->max_key_code<xkb->min_key_code))) {
330 fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
331 xkb->min_key_code,xkb->max_key_code);
336 if (xkb->map==NULL) {
337 map= _XkbTypedCalloc(1,XkbClientMapRec);
344 if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) {
345 if (map->types==NULL) {
346 map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec);
347 if (map->types==NULL)
350 map->size_types= nTotalTypes;
352 else if (map->size_types<nTotalTypes) {
353 XkbKeyTypeRec *prev_types = map->types;
355 map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec);
356 if (map->types==NULL) {
357 _XkbFree(prev_types);
358 map->num_types= map->size_types= 0;
361 map->size_types= nTotalTypes;
362 bzero(&map->types[map->num_types],
363 ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec)));
366 if (which&XkbKeySymsMask) {
367 int nKeys= XkbNumKeys(xkb);
368 if (map->syms==NULL) {
369 map->size_syms= (nKeys*15)/10;
370 map->syms= _XkbTypedCalloc(map->size_syms,KeySym);
376 map->syms[0]= NoSymbol;
378 if (map->key_sym_map==NULL) {
379 i= xkb->max_key_code+1;
380 map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec);
381 if (map->key_sym_map==NULL)
385 if (which&XkbModifierMapMask) {
386 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
387 (!XkbIsLegalKeycode(xkb->max_key_code))||
388 (xkb->max_key_code<xkb->min_key_code))
390 if (map->modmap==NULL) {
391 i= xkb->max_key_code+1;
392 map->modmap= _XkbTypedCalloc(i,unsigned char);
393 if (map->modmap==NULL)
401 XkbcAllocServerMap(XkbcDescPtr xkb,unsigned which,unsigned nNewActions)
408 if (xkb->server==NULL) {
409 map= _XkbTypedCalloc(1,XkbServerMapRec);
412 for (i=0;i<XkbNumVirtualMods;i++) {
413 map->vmods[i]= XkbNoModifierMask;
417 else map= xkb->server;
418 if (which&XkbExplicitComponentsMask) {
419 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
420 (!XkbIsLegalKeycode(xkb->max_key_code))||
421 (xkb->max_key_code<xkb->min_key_code))
423 if (map->explicit==NULL) {
424 i= xkb->max_key_code+1;
425 map->explicit= _XkbTypedCalloc(i,unsigned char);
426 if (map->explicit==NULL)
430 if (which&XkbKeyActionsMask) {
431 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
432 (!XkbIsLegalKeycode(xkb->max_key_code))||
433 (xkb->max_key_code<xkb->min_key_code))
437 if (map->acts==NULL) {
438 map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction);
442 map->size_acts= nNewActions+1;
444 else if ((map->size_acts-map->num_acts)<nNewActions) {
446 XkbAction *prev_acts = map->acts;
447 need= map->num_acts+nNewActions;
448 map->acts= _XkbTypedRealloc(map->acts,need,XkbAction);
449 if (map->acts==NULL) {
451 map->num_acts= map->size_acts= 0;
454 map->size_acts= need;
455 bzero(&map->acts[map->num_acts],
456 ((map->size_acts-map->num_acts)*sizeof(XkbAction)));
458 if (map->key_acts==NULL) {
459 i= xkb->max_key_code+1;
460 map->key_acts= _XkbTypedCalloc(i,unsigned short);
461 if (map->key_acts==NULL)
465 if (which&XkbKeyBehaviorsMask) {
466 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
467 (!XkbIsLegalKeycode(xkb->max_key_code))||
468 (xkb->max_key_code<xkb->min_key_code))
470 if (map->behaviors==NULL) {
471 i= xkb->max_key_code+1;
472 map->behaviors= _XkbTypedCalloc(i,XkbBehavior);
473 if (map->behaviors==NULL)
477 if (which&XkbVirtualModMapMask) {
478 if ((!XkbIsLegalKeycode(xkb->min_key_code))||
479 (!XkbIsLegalKeycode(xkb->max_key_code))||
480 (xkb->max_key_code<xkb->min_key_code))
482 if (map->vmodmap==NULL) {
483 i= xkb->max_key_code+1;
484 map->vmodmap= _XkbTypedCalloc(i,unsigned short);
485 if (map->vmodmap==NULL)
493 XkbcFreeClientMap(XkbcDescPtr xkb,unsigned what,Bool freeMap)
497 if ((xkb==NULL)||(xkb->map==NULL))
500 what= XkbAllClientInfoMask;
502 if (what&XkbKeyTypesMask) {
503 if (map->types!=NULL) {
504 if (map->num_types>0) {
507 for (i=0,type=map->types;i<map->num_types;i++,type++) {
508 if (type->map!=NULL) {
512 if (type->preserve!=NULL) {
513 _XkbFree(type->preserve);
514 type->preserve= NULL;
517 if (type->level_names!=NULL) {
518 _XkbFree(type->level_names);
519 type->level_names= NULL;
523 _XkbFree(map->types);
524 map->num_types= map->size_types= 0;
528 if (what&XkbKeySymsMask) {
529 if (map->key_sym_map!=NULL) {
530 _XkbFree(map->key_sym_map);
531 map->key_sym_map= NULL;
533 if (map->syms!=NULL) {
535 map->size_syms= map->num_syms= 0;
539 if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
540 _XkbFree(map->modmap);
551 XkbcFreeServerMap(XkbcDescPtr xkb,unsigned what,Bool freeMap)
555 if ((xkb==NULL)||(xkb->server==NULL))
558 what= XkbAllServerInfoMask;
560 if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) {
561 _XkbFree(map->explicit);
564 if (what&XkbKeyActionsMask) {
565 if (map->key_acts!=NULL) {
566 _XkbFree(map->key_acts);
569 if (map->acts!=NULL) {
571 map->num_acts= map->size_acts= 0;
575 if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
576 _XkbFree(map->behaviors);
577 map->behaviors= NULL;
579 if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) {
580 _XkbFree(map->vmodmap);
585 _XkbFree(xkb->server);