Bug Summary

File:src/xkb/XKBGetMap.c
Location:line 44, column 6
Description:Value stored to 'n' is never read

Annotated Source Code

1/************************************************************
2Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
3
4Permission to use, copy, modify, and distribute this
5software and its documentation for any purpose and without
6fee is hereby granted, provided that the above copyright
7notice appear in all copies and that both that copyright
8notice and this permission notice appear in supporting
9documentation, and that the name of Silicon Graphics not be
10used in advertising or publicity pertaining to distribution
11of the software without specific prior written permission.
12Silicon Graphics makes no representation about the suitability
13of this software for any purpose. It is provided "as is"
14without any express or implied warranty.
15
16SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25********************************************************/
26
27#define NEED_MAP_READERS
28#ifdef HAVE_CONFIG_H1
29#include <config.h>
30#endif
31#include "Xlibint.h"
32#include <X11/extensions/XKBproto.h>
33#include "XKBlibint.h"
34
35static Statusint
36_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
37{
38int i,n,lastMapCount;
39XkbKeyTypePtr type;
40
41 if ( rep->nTypes>0 ) {
42 n = rep->firstType+rep->nTypes;
43 if (xkb->map->num_types>=n)
44 n= xkb->map->num_types;
Value stored to 'n' is never read
45 else if (XkbAllocClientMap(xkb,XkbKeyTypesMask(1<<0),n)!=Success0)
46 return BadAlloc11;
47
48 type = &xkb->map->types[rep->firstType];
49 for (i=0;i<(int)rep->nTypes;i++,type++) {
50 xkbKeyTypeWireDesc *desc;
51 register int ndx;
52
53 ndx= i+rep->firstType;
54 if (ndx>=xkb->map->num_types)
55 xkb->map->num_types= ndx+1;
56
57 desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf,
58 SIZEOF(xkbKeyTypeWireDesc)8);
59 if (desc==NULL((void*)0))
60 return BadLength16;
61
62 lastMapCount= type->map_count;
63 if ( desc->nMapEntries>0 ) {
64 if ((type->map==NULL((void*)0))||(desc->nMapEntries>type->map_count)) {
65 XkbKTMapEntryRec *prev_map = type->map;
66
67 type->map= _XkbTypedRealloc(type->map,desc->nMapEntries,((type->map)?(XkbKTMapEntryRec *)realloc(((type->map)),
(((desc->nMapEntries)*sizeof(XkbKTMapEntryRec)) == 0 ? 1 :
((desc->nMapEntries)*sizeof(XkbKTMapEntryRec)))):((XkbKTMapEntryRec
*)calloc((((desc->nMapEntries)) == 0 ? 1 : ((desc->nMapEntries
))), (sizeof(XkbKTMapEntryRec)))))
68 XkbKTMapEntryRec)((type->map)?(XkbKTMapEntryRec *)realloc(((type->map)),
(((desc->nMapEntries)*sizeof(XkbKTMapEntryRec)) == 0 ? 1 :
((desc->nMapEntries)*sizeof(XkbKTMapEntryRec)))):((XkbKTMapEntryRec
*)calloc((((desc->nMapEntries)) == 0 ? 1 : ((desc->nMapEntries
))), (sizeof(XkbKTMapEntryRec)))))
;
69 if (type->map==NULL((void*)0)) {
70 _XkbFree(prev_map)free((prev_map));
71 return BadAlloc11;
72 }
73 }
74 }
75 else if (type->map!=NULL((void*)0)) {
76 Xfree(type->map)free((type->map));
77 type->map_count= 0;
78 type->map= NULL((void*)0);
79 }
80
81 if ( desc->preserve && (desc->nMapEntries>0) ) {
82 if ((!type->preserve)||
83 (desc->nMapEntries>lastMapCount)) {
84 XkbModsRec *prev_preserve = type->preserve;
85
86 type->preserve= _XkbTypedRealloc(type->preserve,((type->preserve)?(XkbModsRec *)realloc(((type->preserve
)), (((desc->nMapEntries)*sizeof(XkbModsRec)) == 0 ? 1 : (
(desc->nMapEntries)*sizeof(XkbModsRec)))):((XkbModsRec *)calloc
((((desc->nMapEntries)) == 0 ? 1 : ((desc->nMapEntries)
)), (sizeof(XkbModsRec)))))
87 desc->nMapEntries,((type->preserve)?(XkbModsRec *)realloc(((type->preserve
)), (((desc->nMapEntries)*sizeof(XkbModsRec)) == 0 ? 1 : (
(desc->nMapEntries)*sizeof(XkbModsRec)))):((XkbModsRec *)calloc
((((desc->nMapEntries)) == 0 ? 1 : ((desc->nMapEntries)
)), (sizeof(XkbModsRec)))))
88 XkbModsRec)((type->preserve)?(XkbModsRec *)realloc(((type->preserve
)), (((desc->nMapEntries)*sizeof(XkbModsRec)) == 0 ? 1 : (
(desc->nMapEntries)*sizeof(XkbModsRec)))):((XkbModsRec *)calloc
((((desc->nMapEntries)) == 0 ? 1 : ((desc->nMapEntries)
)), (sizeof(XkbModsRec)))))
;
89 if (type->preserve==NULL((void*)0)) {
90 _XkbFree(prev_preserve)free((prev_preserve));
91 return BadAlloc11;
92 }
93 }
94 }
95 else if (type->preserve!=NULL((void*)0)) {
96 Xfree(type->preserve)free((type->preserve));
97 type->preserve= NULL((void*)0);
98 }
99
100 type->mods.mask = desc->mask;
101 type->mods.real_mods = desc->realMods;
102 type->mods.vmods = desc->virtualMods;
103 type->num_levels = desc->numLevels;
104 type->map_count = desc->nMapEntries;
105 if (desc->nMapEntries>0) {
106 register xkbKTMapEntryWireDesc *wire;
107 register XkbKTMapEntryPtr entry;
108 register int size;
109
110 size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc)8;
111 wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size);
112 if (wire==NULL((void*)0))
113 return BadLength16;
114 entry= type->map;
115 for (n=0;n<type->map_count;n++,wire++,entry++) {
116 entry->active= wire->active;
117 entry->level= wire->level;
118 entry->mods.mask= wire->mask;
119 entry->mods.real_mods= wire->realMods;
120 entry->mods.vmods= wire->virtualMods;
121 }
122
123 if (desc->preserve) {
124 register xkbModsWireDesc * pwire;
125 register XkbModsPtr preserve;
126 register int sz;
127
128 sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc)4;
129 pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz);
130 if (pwire==NULL((void*)0))
131 return BadLength16;
132 preserve= type->preserve;
133 for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) {
134 preserve->mask= pwire->mask;
135 preserve->vmods= pwire->virtualMods;
136 preserve->real_mods= pwire->realMods;
137 }
138 }
139 }
140 }
141 }
142 return Success0;
143}
144
145static Statusint
146_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
147{
148register int i;
149XkbClientMapPtr map;
150
151 map= xkb->map;
152 if (map->key_sym_map==NULL((void*)0)) {
153 register int offset;
154 XkbSymMapPtr oldMap;
155 xkbSymMapWireDesc *newMap;
156 map->key_sym_map= _XkbTypedCalloc((xkb->max_key_code+1),XkbSymMapRec)((XkbSymMapRec *)calloc(((((xkb->max_key_code+1))) == 0 ? 1
: (((xkb->max_key_code+1)))), (sizeof(XkbSymMapRec))))
;
157 if (map->key_sym_map==NULL((void*)0))
158 return BadAlloc11;
159 if (map->syms==NULL((void*)0)) {
160 int sz;
161 sz= (rep->totalSyms*12)/10;
162 sz= ((sz+(unsigned)128)/128)*128;
163 map->syms = _XkbTypedCalloc(sz,KeySym)((KeySym *)calloc((((sz)) == 0 ? 1 : ((sz))), (sizeof(KeySym)
)))
;
164 if (map->syms==NULL((void*)0))
165 return BadAlloc11;
166 map->size_syms = sz;
167 }
168 offset = 1;
169 oldMap = &map->key_sym_map[rep->firstKeySym];
170 for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
171 newMap= (xkbSymMapWireDesc *)
172 _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)8);
173 if (newMap==NULL((void*)0))
174 return BadLength16;
175 oldMap->kt_index[0]= newMap->ktIndex[0];
176 oldMap->kt_index[1]= newMap->ktIndex[1];
177 oldMap->kt_index[2]= newMap->ktIndex[2];
178 oldMap->kt_index[3]= newMap->ktIndex[3];
179 oldMap->group_info= newMap->groupInfo;
180 oldMap->width= newMap->width;
181 oldMap->offset= offset;
182 if (offset+newMap->nSyms>=map->size_syms) {
183 register int sz;
184 KeySym *prev_syms = map->syms;
185
186 sz= map->size_syms+128;
187 map->syms= _XkbTypedRealloc(map->syms,sz,KeySym)((map->syms)?(KeySym *)realloc(((map->syms)), (((sz)*sizeof
(KeySym)) == 0 ? 1 : ((sz)*sizeof(KeySym)))):((KeySym *)calloc
((((sz)) == 0 ? 1 : ((sz))), (sizeof(KeySym)))))
;
188 if (map->syms==NULL((void*)0)) {
189 _XkbFree(prev_syms)free((prev_syms));
190 map->size_syms= 0;
191 return BadAlloc11;
192 }
193 map->size_syms= sz;
194 }
195 if (newMap->nSyms>0) {
196 _XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset],
197 newMap->nSyms);
198 offset+= newMap->nSyms;
199 }
200 else {
201 map->syms[offset]= 0;
202 }
203 }
204 map->num_syms= offset;
205 }
206 else {
207 xkbSymMapWireDesc * newMap;
208 XkbSymMapPtr oldMap;
209 KeySym * newSyms;
210 int tmp;
211
212 oldMap = &map->key_sym_map[rep->firstKeySym];
213 for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
214 newMap= (xkbSymMapWireDesc *)
215 _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)8);
216 if (newMap==NULL((void*)0))
217 return BadLength16;
218
219 if (newMap->nSyms>0)
220 tmp= newMap->nSyms;
221 else tmp= 0;
222
223 newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp);
224 if (newSyms==NULL((void*)0))
225 return BadAlloc11;
226 if (newMap->nSyms>0)
227 _XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms);
228 else newSyms[0]= NoSymbol0L;
229 oldMap->kt_index[0] = newMap->ktIndex[0];
230 oldMap->kt_index[1] = newMap->ktIndex[1];
231 oldMap->kt_index[2] = newMap->ktIndex[2];
232 oldMap->kt_index[3] = newMap->ktIndex[3];
233 oldMap->group_info = newMap->groupInfo;
234 oldMap->width = newMap->width;
235 }
236 }
237 return Success0;
238}
239
240static Statusint
241_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep)
242{
243int i;
244CARD8 numDescBuf[248];
245CARD8* numDesc = NULL((void*)0);
246register int nKeyActs;
247Statusint ret = Success0;
248
249 if ( (nKeyActs=rep->nKeyActs)>0 ) {
250 XkbSymMapPtr symMap;
251
252 if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf;
253 else numDesc = Xmalloc (nKeyActs * sizeof(CARD8))malloc(((nKeyActs * sizeof(CARD8)) == 0 ? 1 : (nKeyActs * sizeof
(CARD8))))
;
254
255 if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) {
256 ret = BadLength16;
257 goto done;
258 }
259 i= XkbPaddedSize(nKeyActs)((((unsigned int)(nKeyActs)+3) >> 2) << 2)-nKeyActs;
260 if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) {
261 ret = BadLength16;
262 goto done;
263 }
264 symMap = &info->map->key_sym_map[rep->firstKeyAct];
265 for (i=0;i<(int)rep->nKeyActs;i++,symMap++) {
266 if (numDesc[i]==0) {
267 info->server->key_acts[i+rep->firstKeyAct]= 0;
268 }
269 else {
270 XkbAction *newActs;
271 /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */
272 /* either zero or XkbKeyNumSyms(info,key) */
273 newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct,
274 numDesc[i]);
275 if (newActs==NULL((void*)0)) {
276 ret = BadAlloc11;
277 goto done;
278 }
279 if (!_XkbCopyFromReadBuffer(buf,(char *)newActs,
280 (int)(numDesc[i]*sizeof(XkbAction)))) {
281 ret = BadLength16;
282 goto done;
283 }
284 }
285 }
286 }
287done:
288 if (numDesc != NULL((void*)0) && numDesc != numDescBuf) Xfree (numDesc)free((numDesc));
289 return ret;
290}
291
292static Statusint
293_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
294{
295register int i;
296xkbBehaviorWireDesc *wire;
297
298 if ( rep->totalKeyBehaviors>0 ) {
299 if ( xkb->server->behaviors == NULL((void*)0) ) {
300 int size = xkb->max_key_code+1;
301 xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior)((XkbBehavior *)calloc((((size)) == 0 ? 1 : ((size))), (sizeof
(XkbBehavior))))
;
302 if (xkb->server->behaviors==NULL((void*)0))
303 return BadAlloc11;
304 }
305 else {
306 bzero(&xkb->server->behaviors[rep->firstKeyBehavior],memset(&xkb->server->behaviors[rep->firstKeyBehavior
],0,(rep->nKeyBehaviors*sizeof(XkbBehavior)))
307 (rep->nKeyBehaviors*sizeof(XkbBehavior)))memset(&xkb->server->behaviors[rep->firstKeyBehavior
],0,(rep->nKeyBehaviors*sizeof(XkbBehavior)))
;
308 }
309 for (i=0;i<rep->totalKeyBehaviors;i++) {
310 wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf,
311 SIZEOF(xkbBehaviorWireDesc)4);
312 if (wire==NULL((void*)0))
313 return BadLength16;
314 xkb->server->behaviors[wire->key].type= wire->type;
315 xkb->server->behaviors[wire->key].data= wire->data;
316 }
317 }
318 return Success0;
319}
320
321static Statusint
322_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
323{
324 if ( rep->virtualMods ) {
325 register int i,bit,nVMods;
326 register char *data;
327
328 for (i=nVMods=0,bit=1;i<XkbNumVirtualMods16;i++,bit<<=1) {
329 if (rep->virtualMods&bit)
330 nVMods++;
331 }
332 data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods)((((unsigned int)(nVMods)+3) >> 2) << 2));
333 if (data==NULL((void*)0))
334 return BadLength16;
335 for (i=0,bit=1;(i<XkbNumVirtualMods16)&&(nVMods>0);i++,bit<<=1) {
336 if (rep->virtualMods&bit) {
337 xkb->server->vmods[i]= *data++;
338 nVMods--;
339 }
340 }
341 }
342 return Success0;
343}
344
345static Statusint
346_XkbReadExplicitComponents( XkbReadBufferPtr buf,
347 XkbDescPtr xkb,
348 xkbGetMapReply * rep)
349{
350register int i;
351unsigned char *wire;
352
353 if ( rep->totalKeyExplicit>0 ) {
354 if ( xkb->server->explicit == NULL((void*)0) ) {
355 int size = xkb->max_key_code+1;
356 xkb->server->explicit = _XkbTypedCalloc(size,unsigned char)((unsigned char *)calloc((((size)) == 0 ? 1 : ((size))), (sizeof
(unsigned char))))
;
357 if (xkb->server->explicit==NULL((void*)0))
358 return BadAlloc11;
359 }
360 else {
361 bzero(&xkb->server->explicit[rep->firstKeyExplicit],memset(&xkb->server->explicit[rep->firstKeyExplicit
],0,rep->nKeyExplicit)
362 rep->nKeyExplicit)memset(&xkb->server->explicit[rep->firstKeyExplicit
],0,rep->nKeyExplicit)
;
363 }
364 i= XkbPaddedSize(2*rep->totalKeyExplicit)((((unsigned int)(2*rep->totalKeyExplicit)+3) >> 2) <<
2)
;
365 wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
366 if (!wire)
367 return BadLength16;
368 for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) {
369 xkb->server->explicit[wire[0]]= wire[1];
370 }
371 }
372 return Success0;
373}
374
375static Statusint
376_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
377{
378register int i;
379unsigned char *wire;
380
381 if ( rep->totalModMapKeys>0 ) {
382 if ((xkb->map->modmap==NULL((void*)0))&&
383 (XkbAllocClientMap(xkb,XkbModifierMapMask(1<<2),0)!=Success0)) {
384 return BadAlloc11;
385 }
386 else {
387 bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys)memset(&xkb->map->modmap[rep->firstModMapKey],0,
rep->nModMapKeys)
;
388 }
389 i= XkbPaddedSize(2*rep->totalModMapKeys)((((unsigned int)(2*rep->totalModMapKeys)+3) >> 2) <<
2)
;
390 wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
391 if (!wire)
392 return BadLength16;
393 for (i=0;i<rep->totalModMapKeys;i++,wire+=2) {
394 xkb->map->modmap[wire[0]]= wire[1];
395 }
396 }
397 return Success0;
398}
399
400static Statusint
401_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
402{
403register int i;
404xkbVModMapWireDesc * wire;
405XkbServerMapPtr srv;
406
407 if ( rep->totalVModMapKeys>0 ) {
408 if (((xkb->server==NULL((void*)0))||(xkb->server->vmodmap==NULL((void*)0)))&&
409 (XkbAllocServerMap(xkb,XkbVirtualModMapMask(1<<7),0)!=Success0)) {
410 return BadAlloc11;
411 }
412 else {
413 srv= xkb->server;
414 if (rep->nVModMapKeys > rep->firstVModMapKey)
415 bzero((char *)&srv->vmodmap[rep->firstVModMapKey],memset((char *)&srv->vmodmap[rep->firstVModMapKey],
0,(rep->nVModMapKeys - rep->firstVModMapKey) * sizeof(unsigned
short))
416 (rep->nVModMapKeys - rep->firstVModMapKey) *memset((char *)&srv->vmodmap[rep->firstVModMapKey],
0,(rep->nVModMapKeys - rep->firstVModMapKey) * sizeof(unsigned
short))
417 sizeof(unsigned short))memset((char *)&srv->vmodmap[rep->firstVModMapKey],
0,(rep->nVModMapKeys - rep->firstVModMapKey) * sizeof(unsigned
short))
;
418 }
419 srv= xkb->server;
420 i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc)4;
421 wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i);
422 if (!wire)
423 return BadLength16;
424 for (i=0;i<rep->totalVModMapKeys;i++,wire++) {
425 if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code))
426 srv->vmodmap[wire->key]= wire->vmods;
427 }
428 }
429 return Success0;
430}
431
432static xkbGetMapReq *
433_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb)
434{
435xkbGetMapReq *req;
436
437 GetReq(kbGetMap, req)req = (xkbGetMapReq *) _XGetRequest(dpy, 8, 28);
438 req->reqType = dpy->xkb_info->codes->major_opcode;
439 req->xkbReqType = X_kbGetMap8;
440 req->deviceSpec = xkb->device_spec;
441 req->full = req->partial = 0;
442 req->firstType = req->nTypes = 0;
443 req->firstKeySym = req->nKeySyms = 0;
444 req->firstKeyAct = req->nKeyActs = 0;
445 req->firstKeyBehavior = req->nKeyBehaviors = 0;
446 req->virtualMods = 0;
447 req->firstKeyExplicit = req->nKeyExplicit = 0;
448 req->firstModMapKey = req->nModMapKeys = 0;
449 req->firstVModMapKey = req->nVModMapKeys = 0;
450 return req;
451}
452
453Statusint
454_XkbReadGetMapReply( Display * dpy,
455 xkbGetMapReply *rep,
456 XkbDescPtr xkb,
457 int * nread_rtrn)
458{
459int extraData;
460unsigned mask;
461
462 if ( xkb->device_spec == XkbUseCoreKbd0x0100 )
463 xkb->device_spec= rep->deviceID;
464 xkb->min_key_code = rep->minKeyCode;
465 xkb->max_key_code = rep->maxKeyCode;
466
467 if (!xkb->map) {
468 mask= rep->present&XkbAllClientInfoMask((1<<0)|(1<<1)|(1<<2));
469 if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success0))
470 return BadAlloc11;
471 }
472 if (!xkb->server) {
473 mask= rep->present&XkbAllServerInfoMask((1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<
7))
;
474 if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success0))
475 return BadAlloc11;
476 }
477 extraData= (int)(rep->length*4);
478 extraData-= (SIZEOF(xkbGetMapReply)40-SIZEOF(xGenericReply)32);
479 if (rep->length) {
480 XkbReadBufferRec buf;
481 int left;
482 if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
483 Statusint status= Success0;
484 if (nread_rtrn!=NULL((void*)0))
485 *nread_rtrn= extraData;
486 if (status==Success0)
487 status= _XkbReadKeyTypes(&buf,xkb,rep);
488 if (status==Success0)
489 status= _XkbReadKeySyms(&buf,xkb,rep);
490 if (status==Success0)
491 status= _XkbReadKeyActions(&buf,xkb,rep);
492 if (status==Success0)
493 status= _XkbReadKeyBehaviors(&buf,xkb,rep);
494 if (status==Success0)
495 status= _XkbReadVirtualMods(&buf,xkb,rep);
496 if (status==Success0)
497 status= _XkbReadExplicitComponents(&buf,xkb,rep);
498 if (status==Success0)
499 status= _XkbReadModifierMap(&buf,xkb,rep);
500 if (status==Success0)
501 status= _XkbReadVirtualModMap(&buf,xkb,rep);
502 left= _XkbFreeReadBuffer(&buf);
503 if (status!=Success0) return status;
504 else if ( left || buf.error ) return BadLength16;
505 }
506 else return BadAlloc11;
507 }
508 return Success0;
509}
510
511static Statusint
512_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb)
513{
514xkbGetMapReply rep;
515
516 if (!_XReply(dpy, (xReply *)&rep,
517 ( (SIZEOF(xkbGetMapReply)40-SIZEOF(xGenericReply)32) >> 2 ),
518 xFalse0)) {
519 return BadImplementation17;
520 }
521 return _XkbReadGetMapReply(dpy,&rep,xkb,NULL((void*)0));
522}
523
524Statusint
525XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb)
526{
527 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
528 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
529 return BadAccess10;
530 if (which) {
531 register xkbGetMapReq *req;
532 Statusint status;
533
534 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
535
536 req = _XkbGetGetMapReq(dpy, xkb);
537 req->full = which;
538 status= _XkbHandleGetMapReply(dpy, xkb);
539
540 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
541 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
542 return status;
543 }
544 return Success0;
545}
546
547XkbDescPtr
548XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec)
549{
550XkbDescPtr xkb;
551
552 xkb = _XkbTypedCalloc(1,XkbDescRec)((XkbDescRec *)calloc((((1)) == 0 ? 1 : ((1))), (sizeof(XkbDescRec
))))
;
553 if (xkb) {
554 xkb->device_spec = deviceSpec;
555 xkb->map = _XkbTypedCalloc(1,XkbClientMapRec)((XkbClientMapRec *)calloc((((1)) == 0 ? 1 : ((1))), (sizeof(
XkbClientMapRec))))
;
556 if ((xkb->map==NULL((void*)0))||
557 ((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success0))) {
558 if (xkb->map) {
559 Xfree(xkb->map)free((xkb->map));
560 xkb->map= NULL((void*)0);
561 }
562 Xfree(xkb)free((xkb));
563 return NULL((void*)0);
564 }
565 xkb->dpy= dpy;
566 }
567 return xkb;
568}
569
570Statusint
571XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
572{
573 register xkbGetMapReq *req;
574 Statusint status;
575
576 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
577 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
578 return BadAccess10;
579 if ((num<1)||(num>XkbMaxKeyTypes255))
580 return BadValue2;
581
582 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
583
584 req = _XkbGetGetMapReq(dpy, xkb);
585 req->firstType = first;
586 req->nTypes = num;
587 status= _XkbHandleGetMapReply(dpy, xkb);
588
589 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
590 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
591 return status;
592}
593
594Statusint
595XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
596{
597 register xkbGetMapReq *req;
598 Statusint status;
599
600 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
601 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
602 return BadAccess10;
603
604 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
605 return BadValue2;
606
607 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
608
609 req = _XkbGetGetMapReq(dpy, xkb);
610 req->firstKeyAct = first;
611 req->nKeyActs = num;
612 status= _XkbHandleGetMapReply(dpy, xkb);
613
614 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
615 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
616 return status;
617}
618
619Statusint
620XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
621{
622 register xkbGetMapReq *req;
623 Statusint status;
624
625 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
626 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
627 return BadAccess10;
628
629 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
630 return BadValue2;
631
632 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
633
634 req = _XkbGetGetMapReq(dpy, xkb);
635 req->firstKeySym = first;
636 req->nKeySyms = num;
637 status= _XkbHandleGetMapReply(dpy, xkb);
638
639 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
640 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
641
642 return status;
643}
644
645Statusint
646XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
647{
648 register xkbGetMapReq *req;
649 Statusint status;
650
651 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
652 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
653 return BadAccess10;
654
655 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
656 return BadValue2;
657
658 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
659
660 req = _XkbGetGetMapReq(dpy, xkb);
661 req->firstKeyBehavior = first;
662 req->nKeyBehaviors = num;
663 status= _XkbHandleGetMapReply(dpy, xkb);
664
665 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
666 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
667 return status;
668}
669
670Statusint
671XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
672{
673 register xkbGetMapReq *req;
674 Statusint status;
675
676 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
677 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
678 return BadAccess10;
679
680 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
681
682 req = _XkbGetGetMapReq(dpy, xkb);
683 req->virtualMods = which;
684 status= _XkbHandleGetMapReply(dpy, xkb);
685
686 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
687 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
688 return status;
689}
690
691Statusint
692XkbGetKeyExplicitComponents( Display * dpy,
693 unsigned first,
694 unsigned num,
695 XkbDescPtr xkb)
696{
697 register xkbGetMapReq *req;
698 Statusint status;
699
700 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
701 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
702 return BadAccess10;
703
704 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
705 return BadValue2;
706
707 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
708
709 req = _XkbGetGetMapReq(dpy, xkb);
710 req->firstKeyExplicit = first;
711 req->nKeyExplicit = num;
712 if ((xkb!=NULL((void*)0)) && (xkb->server!=NULL((void*)0)) && (xkb->server->explicit!=NULL((void*)0))) {
713 if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
714 bzero(&xkb->server->explicit[first],num)memset(&xkb->server->explicit[first],0,num);
715 }
716 if (xkb)
717 status= _XkbHandleGetMapReply(dpy, xkb);
718 else
719 status = BadMatch8;
720
721 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
722 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
723 return status;
724}
725
726Statusint
727XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
728{
729 register xkbGetMapReq *req;
730 Statusint status;
731
732 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
733 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
734 return BadAccess10;
735
736 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
737 return BadValue2;
738
739 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
740
741 req = _XkbGetGetMapReq(dpy, xkb);
742 req->firstModMapKey = first;
743 req->nModMapKeys = num;
744 if ((xkb!=NULL((void*)0)) && (xkb->map!=NULL((void*)0)) && (xkb->map->modmap!=NULL((void*)0))) {
745 if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
746 bzero(&xkb->map->modmap[first],num)memset(&xkb->map->modmap[first],0,num);
747 }
748 if (xkb)
749 status= _XkbHandleGetMapReply(dpy, xkb);
750 else
751 status = BadMatch8;
752
753 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
754 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
755 return status;
756}
757
758Statusint
759XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
760{
761 register xkbGetMapReq *req;
762 Statusint status;
763
764 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
765 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
766 return BadAccess10;
767
768 if ((num<1)||(num>XkbMaxKeyCount(255 -8 +1)))
769 return BadValue2;
770
771 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
772
773 req = _XkbGetGetMapReq(dpy, xkb);
774 req->firstVModMapKey = first;
775 req->nVModMapKeys = num;
776 if ((xkb!=NULL((void*)0)) && (xkb->map!=NULL((void*)0)) && (xkb->map->modmap!=NULL((void*)0))) {
777 if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
778 bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short))memset(&xkb->server->vmodmap[first],0,num*sizeof(unsigned
short))
;
779 }
780
781 if (xkb)
782 status= _XkbHandleGetMapReply(dpy, xkb);
783 else
784 status = BadMatch8;
785
786 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
787 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
788 return status;
789}
790
791Statusint
792XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
793{
794 xkbGetMapReq *req;
795
796 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
797 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
798 return BadAccess10;
799 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
800 if (changes->changed) {
801 Statusint status= Success0;
802 req = _XkbGetGetMapReq(dpy, xkb);
803 req->full = 0;
804 req->partial = changes->changed;
805 req->firstType = changes->first_type;
806 req->nTypes = changes->num_types;
807 req->firstKeySym = changes->first_key_sym;
808 req->nKeySyms = changes->num_key_syms;
809 req->firstKeyAct = changes->first_key_act;
810 req->nKeyActs = changes->num_key_acts;
811 req->firstKeyBehavior = changes->first_key_behavior;
812 req->nKeyBehaviors = changes->num_key_behaviors;
813 req->virtualMods = changes->vmods;
814 req->firstKeyExplicit = changes->first_key_explicit;
815 req->nKeyExplicit = changes->num_key_explicit;
816 req->firstModMapKey = changes->first_modmap_key;
817 req->nModMapKeys = changes->num_modmap_keys;
818 req->firstVModMapKey = changes->first_vmodmap_key;
819 req->nVModMapKeys = changes->num_vmodmap_keys;
820 status= _XkbHandleGetMapReply(dpy, xkb);
821 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
822 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
823 return status;
824 }
825 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
826 return Success0;
827}
828