Bug Summary

File:src/xkb/XKBNames.c
Location:line 622, column 5
Description:Value stored to 'nVMods' 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
35
36static Statusint
37_XkbReadAtoms( XkbReadBufferPtr buf,
38 Atom * atoms,
39 int maxAtoms,
40 CARD32 present)
41{
42register int i,bit;
43
44 for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) {
45 if (present&bit) {
46 if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1))
47 return BadLength16;
48 present&= ~bit;
49 }
50 }
51 return Success0;
52}
53
54Statusint
55_XkbReadGetNamesReply( Display * dpy,
56 xkbGetNamesReply * rep,
57 XkbDescPtr xkb,
58 int * nread_rtrn)
59{
60 int i,len;
61 XkbReadBufferRec buf;
62 register XkbNamesPtr names;
63
64 if ( xkb->device_spec == XkbUseCoreKbd0x0100 )
65 xkb->device_spec = rep->deviceID;
66
67 if ((xkb->names==NULL((void*)0))&&
68 (XkbAllocNames(xkb,rep->which,
69 rep->nRadioGroups,rep->nKeyAliases)!=Success0)) {
70 return BadAlloc11;
71 }
72 names= xkb->names;
73 if (rep->length==0)
74 return Success0;
75
76 if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
77 return BadAlloc11;
78 if (nread_rtrn)
79 *nread_rtrn= (int)rep->length*4;
80
81 if ((rep->which&XkbKeycodesNameMask(1<<0))&&
82 (!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1)))
83 goto BAILOUT;
84 if ((rep->which&XkbGeometryNameMask(1<<1))&&
85 (!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1)))
86 goto BAILOUT;
87 if ((rep->which&XkbSymbolsNameMask(1<<2))&&
88 (!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1)))
89 goto BAILOUT;
90 if ((rep->which&XkbPhysSymbolsNameMask(1<<3))&&
91 (!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1)))
92 goto BAILOUT;
93 if ((rep->which&XkbTypesNameMask(1<<4))&&
94 (!_XkbReadBufferCopy32(&buf,(long *)&names->types,1)))
95 goto BAILOUT;
96 if ((rep->which&XkbCompatNameMask(1<<5))&&
97 (!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1)))
98 goto BAILOUT;
99
100 if ( rep->which & XkbKeyTypeNamesMask(1<<6) ) {
101 XkbClientMapPtr map= xkb->map;
102 XkbKeyTypePtr type;
103
104 len= rep->nTypes*4;
105 if (map!=NULL((void*)0)) {
106 type= map->types;
107 for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) {
108 if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1))
109 goto BAILOUT;
110 len-= 4;
111 }
112 }
113 if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len)))
114 goto BAILOUT;
115 }
116 if ( rep->which&XkbKTLevelNamesMask(1<<7) ) {
117 CARD8 *nLevels;
118 XkbClientMapPtr map= xkb->map;
119 XkbKeyTypePtr type;
120
121 nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes)((((unsigned int)(rep->nTypes)+3) >> 2) << 2));
122 if (nLevels==NULL((void*)0))
123 goto BAILOUT;
124 if (map!=NULL((void*)0)) {
125 type= map->types;
126 for (i=0;i<(int)rep->nTypes;i++,type++) {
127 if (i>=map->num_types) {
128 if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4))
129 goto BAILOUT;
130 continue;
131 }
132 if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) {
133 goto BAILOUT;
134 }
135 if (type->level_names!=NULL((void*)0))
136 Xfree(type->level_names)free((type->level_names));
137 if (nLevels[i]==0) {
138 type->level_names= NULL((void*)0);
139 continue;
140 }
141 type->level_names= _XkbTypedCalloc(nLevels[i],Atom)((Atom *)calloc((((nLevels[i])) == 0 ? 1 : ((nLevels[i]))), (
sizeof(Atom))))
;
142 if (type->level_names!=NULL((void*)0)) {
143 if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names,
144 nLevels[i]))
145 goto BAILOUT;
146 }
147 else {
148 _XkbSkipReadBufferData(&buf,nLevels[i]*4);
149 }
150 }
151 }
152 else {
153 for (i=0;i<(int)rep->nTypes;i++) {
154 _XkbSkipReadBufferData(&buf,nLevels[i]*4);
155 }
156 }
157 }
158 if (rep->which & XkbIndicatorNamesMask(1<<8)) {
159 if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators32,
160 rep->indicators)!=Success0)
161 goto BAILOUT;
162 }
163 if ( rep->which&XkbVirtualModNamesMask(1<<11) ) {
164 if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods16,
165 (CARD32)rep->virtualMods)!=Success0)
166 goto BAILOUT;
167 }
168 if ( rep->which&XkbGroupNamesMask(1<<12) ) {
169 if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups4,
170 (CARD32)rep->groupNames)!=Success0)
171 goto BAILOUT;
172 }
173 if ( rep->which&XkbKeyNamesMask(1<<9) ) {
174 if (names->keys==NULL((void*)0)) {
175 int nKeys;
176 if (xkb->max_key_code==0) {
177 xkb->min_key_code= rep->minKeyCode;
178 xkb->max_key_code= rep->maxKeyCode;
179 }
180 nKeys= xkb->max_key_code+1;
181 names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec)((XkbKeyNameRec *)calloc((((nKeys)) == 0 ? 1 : ((nKeys))), (sizeof
(XkbKeyNameRec))))
;
182 }
183 if (names->keys!=NULL((void*)0)) {
184 if (!_XkbCopyFromReadBuffer(&buf,
185 (char *)&names->keys[rep->firstKey],
186 rep->nKeys*XkbKeyNameLength4))
187 goto BAILOUT;
188 }
189 else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength4);
190 }
191 if ( rep->which&XkbKeyAliasesMask(1<<10) && (rep->nKeyAliases>0) ) {
192 if (XkbAllocNames(xkb,XkbKeyAliasesMask(1<<10),0,rep->nKeyAliases)!=Success0)
193 goto BAILOUT;
194 if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases,
195 rep->nKeyAliases*XkbKeyNameLength4*2))
196 goto BAILOUT;
197 }
198 if ( rep->which&XkbRGNamesMask(1<<13) ) {
199 if (rep->nRadioGroups>0) {
200 Atom *rgNames;
201
202 if (names->radio_groups==NULL((void*)0))
203 names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom)((Atom *)calloc((((rep->nRadioGroups)) == 0 ? 1 : ((rep->
nRadioGroups))), (sizeof(Atom))))
;
204 else if (names->num_rg<rep->nRadioGroups) {
205 names->radio_groups = _XkbTypedRealloc(names->radio_groups,((names->radio_groups)?(Atom *)realloc(((names->radio_groups
)), (((rep->nRadioGroups)*sizeof(Atom)) == 0 ? 1 : ((rep->
nRadioGroups)*sizeof(Atom)))):((Atom *)calloc((((rep->nRadioGroups
)) == 0 ? 1 : ((rep->nRadioGroups))), (sizeof(Atom)))))
206 rep->nRadioGroups,((names->radio_groups)?(Atom *)realloc(((names->radio_groups
)), (((rep->nRadioGroups)*sizeof(Atom)) == 0 ? 1 : ((rep->
nRadioGroups)*sizeof(Atom)))):((Atom *)calloc((((rep->nRadioGroups
)) == 0 ? 1 : ((rep->nRadioGroups))), (sizeof(Atom)))))
207 Atom)((names->radio_groups)?(Atom *)realloc(((names->radio_groups
)), (((rep->nRadioGroups)*sizeof(Atom)) == 0 ? 1 : ((rep->
nRadioGroups)*sizeof(Atom)))):((Atom *)calloc((((rep->nRadioGroups
)) == 0 ? 1 : ((rep->nRadioGroups))), (sizeof(Atom)))))
;
208 }
209 rgNames= names->radio_groups;
210 if (!rgNames) {
211 goto BAILOUT;
212 }
213 if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups))
214 goto BAILOUT;
215 names->num_rg= rep->nRadioGroups;
216 }
217 else if (names->num_rg>0) {
218 names->num_rg= 0;
219 Xfree(names->radio_groups)free((names->radio_groups));
220 }
221 }
222 len= _XkbFreeReadBuffer(&buf);
223 if (len!=0) return BadLength16;
224 else return Success0;
225BAILOUT:
226 _XkbFreeReadBuffer(&buf);
227 return BadLength16;
228}
229
230Statusint
231XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb)
232{
233 register xkbGetNamesReq *req;
234 xkbGetNamesReply rep;
235 Statusint status;
236 XkbInfoPtr xkbi;
237
238 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
239 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
240 return BadAccess10;
241 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
242 xkbi = dpy->xkb_info;
243 if (!xkb->names) {
244 xkb->names = _XkbTypedCalloc(1,XkbNamesRec)((XkbNamesRec *)calloc((((1)) == 0 ? 1 : ((1))), (sizeof(XkbNamesRec
))))
;
245 if (!xkb->names) {
246 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
247 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
248 return BadAlloc11;
249 }
250 }
251 GetReq(kbGetNames, req)req = (xkbGetNamesReq *) _XGetRequest(dpy, 17, 12);
252 req->reqType = xkbi->codes->major_opcode;
253 req->xkbReqType = X_kbGetNames17;
254 req->deviceSpec = xkb->device_spec;
255 req->which = which;
256 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse0)) {
257 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
258 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
259 return BadImplementation17;
260 }
261
262 status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL((void*)0));
263 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
264 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
265 return status;
266}
267
268/***====================================================================***/
269
270static int
271_XkbCountBits(int nBitsMax,unsigned long mask)
272{
273register unsigned long y, nBits;
274
275 y = (mask >> 1) &033333333333;
276 y = mask - y - ((y >>1) & 033333333333);
277 nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
278
279 /* nBitsMax really means max+1 */
280 return (nBits < nBitsMax) ? nBits : (nBitsMax - 1);
281}
282
283static CARD32
284_XkbCountAtoms(Atom *atoms,int maxAtoms,int *count)
285{
286register unsigned int i,bit,nAtoms;
287register CARD32 atomsPresent;
288
289 for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) {
290 if (atoms[i]!=None0L) {
291 atomsPresent|= bit;
292 nAtoms++;
293 }
294 }
295 if (count)
296 *count= nAtoms;
297 return atomsPresent;
298}
299
300static void
301_XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms)
302{
303register unsigned int i,bit;
304
305 for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) {
306 if (mask&bit)
307 Data32(dpy,&atoms[i],4)_XData32(dpy, (long *)&atoms[i], 4);
308 }
309 return;
310}
311
312Boolint
313XkbSetNames( Display * dpy,
314 unsigned int which,
315 unsigned int firstType,
316 unsigned int nTypes,
317 XkbDescPtr xkb)
318{
319 register xkbSetNamesReq *req;
320 int nLvlNames = 0;
321 XkbInfoPtr xkbi;
322 XkbNamesPtr names;
323 unsigned firstLvlType,nLvlTypes;
324 int nVMods,nLEDs,nRG,nKA,nGroups;
325 int nKeys=0,firstKey=0,nAtoms;
326 CARD32 leds,vmods,groups;
327
328 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
329 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
330 return False0;
331 if ((!xkb)||(!xkb->names))
332 return False0;
333 firstLvlType= firstType;
334 nLvlTypes= nTypes;
335 if (nTypes<1)
336 which&= ~(XkbKTLevelNamesMask(1<<7)|XkbKeyTypeNamesMask(1<<6));
337 else if (firstType<=XkbLastRequiredType3) {
338 int adjust;
339 adjust= XkbLastRequiredType3-firstType+1;
340 firstType+= adjust;
341 nTypes-= adjust;
342 if (nTypes<1)
343 which&= ~XkbKeyTypeNamesMask(1<<6);
344 }
345 names= xkb->names;
346 if (which&(XkbKTLevelNamesMask(1<<7)|XkbKeyTypeNamesMask(1<<6))) {
347 register int i;
348 XkbKeyTypePtr type;
349 if((xkb->map==NULL((void*)0))||(xkb->map->types==NULL((void*)0))||(nTypes==0)||
350 (firstType+nTypes>xkb->map->num_types)||
351 (firstLvlType+nLvlTypes>xkb->map->num_types))
352 return False0;
353 if (which&XkbKTLevelNamesMask(1<<7)) {
354 type= &xkb->map->types[firstLvlType];
355 for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
356 if (type->level_names!=NULL((void*)0))
357 nLvlNames+= type->num_levels;
358 }
359 }
360 }
361
362 nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
363 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
364 xkbi = dpy->xkb_info;
365 GetReq(kbSetNames, req)req = (xkbSetNamesReq *) _XGetRequest(dpy, 18, 28);
366 req->reqType = xkbi->codes->major_opcode;
367 req->xkbReqType = X_kbSetNames18;
368 req->deviceSpec = xkb->device_spec;
369 req->firstType = firstType;
370 req->nTypes = nTypes;
371 req->firstKey = xkb->min_key_code;
372 req->nKeys = xkb->max_key_code-xkb->min_key_code+1;
373
374 if (which&XkbKeycodesNameMask(1<<0))
375 nAtoms++;
376 if (which&XkbGeometryNameMask(1<<1))
377 nAtoms++;
378 if (which&XkbSymbolsNameMask(1<<2))
379 nAtoms++;
380 if (which&XkbPhysSymbolsNameMask(1<<3))
381 nAtoms++;
382 if (which&XkbTypesNameMask(1<<4))
383 nAtoms++;
384 if (which&XkbCompatNameMask(1<<5))
385 nAtoms++;
386 if (which&XkbKeyTypeNamesMask(1<<6))
387 nAtoms+= nTypes;
388 if (which&XkbKTLevelNamesMask(1<<7)) {
389 req->firstKTLevel= firstLvlType;
390 req->nKTLevels= nLvlTypes;
391 req->length+= XkbPaddedSize(nLvlTypes)((((unsigned int)(nLvlTypes)+3) >> 2) << 2)/4; /* room for group widths */
392 nAtoms+= nLvlNames;
393 }
394 else req->firstKTLevel= req->nKTLevels= 0;
395
396 if (which&XkbIndicatorNamesMask(1<<8)) {
397 req->indicators= leds=
398 _XkbCountAtoms(names->indicators,XkbNumIndicators32,&nLEDs);
399 if (nLEDs>0)
400 nAtoms+= nLEDs;
401 else which&= ~XkbIndicatorNamesMask(1<<8);
402 }
403 else req->indicators= leds= 0;
404
405 if (which&XkbVirtualModNamesMask(1<<11)) {
406 vmods= req->virtualMods= (CARD16)
407 _XkbCountAtoms(names->vmods,XkbNumVirtualMods16,&nVMods);
408 if (nVMods>0)
409 nAtoms+= nVMods;
410 else which&= ~XkbVirtualModNamesMask(1<<11);
411 }
412 else vmods= req->virtualMods= 0;
413
414 if (which&XkbGroupNamesMask(1<<12)) {
415 groups= req->groupNames= (CARD8)
416 _XkbCountAtoms(names->groups,XkbNumKbdGroups4,&nGroups);
417 if (nGroups>0)
418 nAtoms+= nGroups;
419 else which&= ~XkbGroupNamesMask(1<<12);
420 }
421 else groups= req->groupNames= 0;
422
423 if ((which&XkbKeyNamesMask(1<<9))&&(names->keys!=NULL((void*)0))) {
424 firstKey= req->firstKey;
425 nKeys= req->nKeys;
426 nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
427 }
428 else which&= ~XkbKeyNamesMask(1<<9);
429
430 if (which&XkbKeyAliasesMask(1<<10)) {
431 nKA= ((names->key_aliases!=NULL((void*)0))?names->num_key_aliases:0);
432 if (nKA>0) {
433 req->nKeyAliases= nKA;
434 nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
435 }
436 else {
437 which&= ~XkbKeyAliasesMask(1<<10);
438 req->nKeyAliases = 0;
439 }
440 }
441 else req->nKeyAliases= 0;
442
443 if (which&XkbRGNamesMask(1<<13)) {
444 nRG= names->num_rg;
445 if (nRG>0)
446 nAtoms+= nRG;
447 else which&= ~XkbRGNamesMask(1<<13);
448 }
449
450 req->which= which;
451 req->nRadioGroups= nRG;
452 req->length+= (nAtoms*4)/4;
453
454 if (which&XkbKeycodesNameMask(1<<0))
455 Data32(dpy,(long *)&names->keycodes,4)_XData32(dpy, (long *)(long *)&names->keycodes, 4);
456 if (which&XkbGeometryNameMask(1<<1))
457 Data32(dpy,(long *)&names->geometry,4)_XData32(dpy, (long *)(long *)&names->geometry, 4);
458 if (which&XkbSymbolsNameMask(1<<2))
459 Data32(dpy,(long *)&names->symbols,4)_XData32(dpy, (long *)(long *)&names->symbols, 4);
460 if (which&XkbPhysSymbolsNameMask(1<<3))
461 Data32(dpy,(long *)&names->phys_symbols,4)_XData32(dpy, (long *)(long *)&names->phys_symbols, 4);
462 if (which&XkbTypesNameMask(1<<4))
463 Data32(dpy,(long *)&names->types,4)_XData32(dpy, (long *)(long *)&names->types, 4);
464 if (which&XkbCompatNameMask(1<<5))
465 Data32(dpy,(long *)&names->compat,4)_XData32(dpy, (long *)(long *)&names->compat, 4);
466 if (which&XkbKeyTypeNamesMask(1<<6)) {
467 register int i;
468 register XkbKeyTypePtr type;
469 type= &xkb->map->types[firstType];
470 for (i=0;i<nTypes;i++,type++) {
471 Data32(dpy,(long *)&type->name,4)_XData32(dpy, (long *)(long *)&type->name, 4);
472 }
473 }
474 if (which&XkbKTLevelNamesMask(1<<7)) {
475 XkbKeyTypePtr type;
476 int i;
477 char *tmp;
478
479 BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes))if (dpy->bufptr + (((((unsigned int)(nLvlTypes)+3) >>
2) << 2)) > dpy->bufmax) _XFlush (dpy); tmp = (char
*) dpy->bufptr; memset(tmp, '\0', ((((unsigned int)(nLvlTypes
)+3) >> 2) << 2)); dpy->bufptr += (((((unsigned
int)(nLvlTypes)+3) >> 2) << 2));
;
480 type = &xkb->map->types[firstLvlType];
481 for (i=0;i<nLvlTypes;i++,type++) {
482 *tmp++ = type->num_levels;
483 }
484 type = &xkb->map->types[firstLvlType];
485 for (i=0;i<nLvlTypes;i++,type++) {
486 if (type->level_names!=NULL((void*)0))
487 Data32(dpy,(long *)type->level_names,type->num_levels*4)_XData32(dpy, (long *)(long *)type->level_names, type->
num_levels*4)
;
488 }
489 }
490 if (which&XkbIndicatorNamesMask(1<<8))
491 _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators32);
492 if (which&XkbVirtualModNamesMask(1<<11))
493 _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods16);
494 if (which&XkbGroupNamesMask(1<<12))
495 _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups4);
496 if (which&XkbKeyNamesMask(1<<9)) {
497#ifdef WORD64
498 char *tmp;
499 register int i;
500 BufAlloc(char *,tmp,nKeys*XkbKeyNameLength)if (dpy->bufptr + (nKeys*4) > dpy->bufmax) _XFlush (
dpy); tmp = (char *) dpy->bufptr; memset(tmp, '\0', nKeys*
4); dpy->bufptr += (nKeys*4);
;
501 for (i=0;i<nKeys;i++,tmp+= XkbKeyNameLength4) {
502 tmp[0]= names->keys[firstKey+i].name[0];
503 tmp[1]= names->keys[firstKey+i].name[1];
504 tmp[2]= names->keys[firstKey+i].name[2];
505 tmp[3]= names->keys[firstKey+i].name[3];
506 }
507#else
508 Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength){ if (dpy->bufptr + (nKeys*4) <= dpy->bufmax) { memcpy
(dpy->bufptr, (char *)&names->keys[firstKey], (int)
nKeys*4); dpy->bufptr += ((nKeys*4) + 3) & ~3; } else _XSend
(dpy, (char *)&names->keys[firstKey], nKeys*4); }
;
509#endif
510 }
511 if (which&XkbKeyAliasesMask(1<<10)) {
512#ifdef WORD64
513 char *tmp;
514 register int i;
515 BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2)if (dpy->bufptr + (nKA*4*2) > dpy->bufmax) _XFlush (
dpy); tmp = (char *) dpy->bufptr; memset(tmp, '\0', nKA*4*
2); dpy->bufptr += (nKA*4*2);
;
516 for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength4) {
517 tmp[0]= names->key_aliases[i].real[0];
518 tmp[1]= names->key_aliases[i].real[1];
519 tmp[2]= names->key_aliases[i].real[2];
520 tmp[3]= names->key_aliases[i].real[3];
521 tmp[4]= names->key_aliases[i].alias[0];
522 tmp[5]= names->key_aliases[i].alias[1];
523 tmp[6]= names->key_aliases[i].alias[2];
524 tmp[7]= names->key_aliases[i].alias[3];
525 }
526#else
527 Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2){ if (dpy->bufptr + (nKA*4*2) <= dpy->bufmax) { memcpy
(dpy->bufptr, (char *)names->key_aliases, (int)nKA*4*2)
; dpy->bufptr += ((nKA*4*2) + 3) & ~3; } else _XSend(dpy
, (char *)names->key_aliases, nKA*4*2); }
;
528#endif
529 }
530 if (which&XkbRGNamesMask(1<<13)) {
531 Data32(dpy,(long *)names->radio_groups,nRG*4)_XData32(dpy, (long *)(long *)names->radio_groups, nRG*4);
532 }
533 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
534 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
535 return True1;
536}
537
538Boolint
539XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
540{
541 register xkbSetNamesReq *req;
542 int nLvlNames = 0;
543 XkbInfoPtr xkbi;
544 XkbNamesPtr names;
545 unsigned which,firstType,nTypes;
546 unsigned firstLvlType,nLvlTypes;
547 int nVMods,nLEDs,nRG,nKA,nGroups;
548 int nKeys=0,firstKey=0,nAtoms;
549 CARD32 leds=0,vmods=0,groups=0;
550
551 if ((dpy->flags & XlibDisplayNoXkb(1L << 2)) ||
552 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))))
553 return False0;
554 if ((!xkb)||(!xkb->names)||(!changes))
555 return False0;
556 which= changes->changed;
557 firstType= changes->first_type;
558 nTypes= changes->num_types;
559 firstLvlType= changes->first_lvl;;
560 nLvlTypes= changes->num_lvls;
561 if (which&XkbKeyTypeNamesMask(1<<6)) {
562 if (nTypes<1)
563 which&= ~XkbKeyTypeNamesMask(1<<6);
564 else if (firstType<=XkbLastRequiredType3) {
565 int adjust;
566 adjust= XkbLastRequiredType3-firstType+1;
567 firstType+= adjust;
568 nTypes-= adjust;
569 if (nTypes<1)
570 which&= ~XkbKeyTypeNamesMask(1<<6);
571 }
572 }
573 else firstType= nTypes= 0;
574
575 if (which&XkbKTLevelNamesMask(1<<7)) {
576 if (nLvlTypes<1)
577 which&= ~XkbKTLevelNamesMask(1<<7);
578 }
579 else firstLvlType= nLvlTypes= 0;
580
581 names= xkb->names;
582 if (which&(XkbKTLevelNamesMask(1<<7)|XkbKeyTypeNamesMask(1<<6))) {
583 register int i;
584 XkbKeyTypePtr type;
585 if((xkb->map==NULL((void*)0))||(xkb->map->types==NULL((void*)0))||(nTypes==0)||
586 (firstType+nTypes>xkb->map->num_types)||
587 (firstLvlType+nLvlTypes>xkb->map->num_types))
588 return False0;
589 if (which&XkbKTLevelNamesMask(1<<7)) {
590 type= &xkb->map->types[firstLvlType];
591 for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
592 if (type->level_names!=NULL((void*)0))
593 nLvlNames+= type->num_levels;
594 }
595 }
596 }
597
598 if (changes->num_keys<1)
599 which&= ~XkbKeyNamesMask(1<<9);
600 if ((which&XkbKeyNamesMask(1<<9))==0)
601 changes->first_key= changes->num_keys= 0;
602 else if ((changes->first_key<xkb->min_key_code)||
603 (changes->first_key+changes->num_keys>xkb->max_key_code)) {
604 return False0;
605 }
606
607 if ((which&XkbVirtualModNamesMask(1<<11))==0)
608 changes->changed_vmods= 0;
609 else if (changes->changed_vmods==0)
610 which&= ~XkbVirtualModNamesMask(1<<11);
611
612 if ((which&XkbIndicatorNamesMask(1<<8))==0)
613 changes->changed_indicators= 0;
614 else if (changes->changed_indicators==0)
615 which&= ~XkbIndicatorNamesMask(1<<8);
616
617 if ((which&XkbGroupNamesMask(1<<12))==0)
618 changes->changed_groups= 0;
619 else if (changes->changed_groups==0)
620 which&= ~XkbGroupNamesMask(1<<12);
621
622 nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
Value stored to 'nVMods' is never read
623 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
624 xkbi = dpy->xkb_info;
625 GetReq(kbSetNames, req)req = (xkbSetNamesReq *) _XGetRequest(dpy, 18, 28);
626 req->reqType = xkbi->codes->major_opcode;
627 req->xkbReqType = X_kbSetNames18;
628 req->deviceSpec = xkb->device_spec;
629 req->firstType = firstType;
630 req->nTypes = nTypes;
631 req->firstKey = changes->first_key;
632 req->nKeys = changes->num_keys;
633
634 if (which&XkbKeycodesNameMask(1<<0))
635 nAtoms++;
636 if (which&XkbGeometryNameMask(1<<1))
637 nAtoms++;
638 if (which&XkbSymbolsNameMask(1<<2))
639 nAtoms++;
640 if (which&XkbPhysSymbolsNameMask(1<<3))
641 nAtoms++;
642 if (which&XkbTypesNameMask(1<<4))
643 nAtoms++;
644 if (which&XkbCompatNameMask(1<<5))
645 nAtoms++;
646 if (which&XkbKeyTypeNamesMask(1<<6))
647 nAtoms+= nTypes;
648 if (which&XkbKTLevelNamesMask(1<<7)) {
649 req->firstKTLevel= firstLvlType;
650 req->nKTLevels= nLvlTypes;
651 req->length+= XkbPaddedSize(nLvlTypes)((((unsigned int)(nLvlTypes)+3) >> 2) << 2)/4; /* room for group widths */
652 nAtoms+= nLvlNames;
653 }
654 else req->firstKTLevel= req->nKTLevels= 0;
655
656 if (which&XkbIndicatorNamesMask(1<<8)) {
657 leds= req->indicators= (CARD32)changes->changed_indicators;
658 nLEDs= _XkbCountBits(XkbNumIndicators32,changes->changed_indicators);
659 if (nLEDs>0)
660 nAtoms+= nLEDs;
661 else which&= ~XkbIndicatorNamesMask(1<<8);
662 }
663 else req->indicators= 0;
664
665 if (which&XkbVirtualModNamesMask(1<<11)) {
666 vmods= req->virtualMods= changes->changed_vmods;
667 nVMods= _XkbCountBits(XkbNumVirtualMods16,
668 (unsigned long)changes->changed_vmods);
669 if (nVMods>0)
670 nAtoms+= nVMods;
671 else which&= ~XkbVirtualModNamesMask(1<<11);
672 }
673 else req->virtualMods= 0;
674
675 if (which&XkbGroupNamesMask(1<<12)) {
676 groups= req->groupNames= changes->changed_groups;
677 nGroups= _XkbCountBits(XkbNumKbdGroups4,
678 (unsigned long)changes->changed_groups);
679 if (nGroups>0)
680 nAtoms+= nGroups;
681 else which&= ~XkbGroupNamesMask(1<<12);
682 }
683 else req->groupNames= 0;
684
685 if ((which&XkbKeyNamesMask(1<<9))&&(names->keys!=NULL((void*)0))) {
686 firstKey= req->firstKey;
687 nKeys= req->nKeys;
688 nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */
689 }
690 else which&= ~XkbKeyNamesMask(1<<9);
691
692 if (which&XkbKeyAliasesMask(1<<10)) {
693 nKA= ((names->key_aliases!=NULL((void*)0))?names->num_key_aliases:0);
694 if (nKA>0)
695 nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
696 else which&= ~XkbKeyAliasesMask(1<<10);
697 }
698
699 if (which&XkbRGNamesMask(1<<13)) {
700 nRG= names->num_rg;
701 if (nRG>0)
702 nAtoms+= nRG;
703 else which&= ~XkbRGNamesMask(1<<13);
704 }
705
706 req->which= which;
707 req->nRadioGroups= nRG;
708 req->length+= (nAtoms*4)/4;
709
710 if (which&XkbKeycodesNameMask(1<<0))
711 Data32(dpy,(long *)&names->keycodes,4)_XData32(dpy, (long *)(long *)&names->keycodes, 4);
712 if (which&XkbGeometryNameMask(1<<1))
713 Data32(dpy,(long *)&names->geometry,4)_XData32(dpy, (long *)(long *)&names->geometry, 4);
714 if (which&XkbSymbolsNameMask(1<<2))
715 Data32(dpy,(long *)&names->symbols,4)_XData32(dpy, (long *)(long *)&names->symbols, 4);
716 if (which&XkbPhysSymbolsNameMask(1<<3))
717 Data32(dpy,(long *)&names->phys_symbols,4)_XData32(dpy, (long *)(long *)&names->phys_symbols, 4);
718 if (which&XkbTypesNameMask(1<<4))
719 Data32(dpy,(long *)&names->types,4)_XData32(dpy, (long *)(long *)&names->types, 4);
720 if (which&XkbCompatNameMask(1<<5))
721 Data32(dpy,(long *)&names->compat,4)_XData32(dpy, (long *)(long *)&names->compat, 4);
722 if (which&XkbKeyTypeNamesMask(1<<6)) {
723 register int i;
724 register XkbKeyTypePtr type;
725 type= &xkb->map->types[firstType];
726 for (i=0;i<nTypes;i++,type++) {
727 Data32(dpy,(long *)&type->name,4)_XData32(dpy, (long *)(long *)&type->name, 4);
728 }
729 }
730 if (which&XkbKTLevelNamesMask(1<<7)) {
731 XkbKeyTypePtr type;
732 int i;
733 char *tmp;
734
735 BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes))if (dpy->bufptr + (((((unsigned int)(nLvlTypes)+3) >>
2) << 2)) > dpy->bufmax) _XFlush (dpy); tmp = (char
*) dpy->bufptr; memset(tmp, '\0', ((((unsigned int)(nLvlTypes
)+3) >> 2) << 2)); dpy->bufptr += (((((unsigned
int)(nLvlTypes)+3) >> 2) << 2));
;
736 type = &xkb->map->types[firstLvlType];
737 for (i=0;i<nLvlTypes;i++,type++) {
738 *tmp++ = type->num_levels;
739 }
740 type = &xkb->map->types[firstLvlType];
741 for (i=0;i<nLvlTypes;i++,type++) {
742 if (type->level_names!=NULL((void*)0))
743 Data32(dpy,(long *)type->level_names,type->num_levels*4)_XData32(dpy, (long *)(long *)type->level_names, type->
num_levels*4)
;
744 }
745 }
746 if (which&XkbIndicatorNamesMask(1<<8))
747 _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators32);
748 if (which&XkbVirtualModNamesMask(1<<11))
749 _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods16);
750 if (which&XkbGroupNamesMask(1<<12))
751 _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups4);
752 if (which&XkbKeyNamesMask(1<<9)) {
753#ifdef WORD64
754 char *tmp;
755 register int i;
756 BufAlloc(char *,tmp,nKeys*4)if (dpy->bufptr + (nKeys*4) > dpy->bufmax) _XFlush (
dpy); tmp = (char *) dpy->bufptr; memset(tmp, '\0', nKeys*
4); dpy->bufptr += (nKeys*4);
;
757 for (i=0;i<nKeys;i++,tmp+= 4) {
758 tmp[0]= names->keys[firstKey+i].name[0];
759 tmp[1]= names->keys[firstKey+i].name[1];
760 tmp[2]= names->keys[firstKey+i].name[2];
761 tmp[3]= names->keys[firstKey+i].name[3];
762 }
763#else
764 Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength){ if (dpy->bufptr + (nKeys*4) <= dpy->bufmax) { memcpy
(dpy->bufptr, (char *)&names->keys[firstKey], (int)
nKeys*4); dpy->bufptr += ((nKeys*4) + 3) & ~3; } else _XSend
(dpy, (char *)&names->keys[firstKey], nKeys*4); }
;
765#endif
766 }
767 if (which&XkbKeyAliasesMask(1<<10)) {
768#ifdef WORD64
769 char *tmp;
770 register int i;
771 BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2)if (dpy->bufptr + (nKA*4*2) > dpy->bufmax) _XFlush (
dpy); tmp = (char *) dpy->bufptr; memset(tmp, '\0', nKA*4*
2); dpy->bufptr += (nKA*4*2);
;
772 for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength4) {
773 tmp[0]= names->key_aliases[i].real[0];
774 tmp[1]= names->key_aliases[i].real[1];
775 tmp[2]= names->key_aliases[i].real[2];
776 tmp[3]= names->key_aliases[i].real[3];
777 tmp[4]= names->key_aliases[i].alias[0];
778 tmp[5]= names->key_aliases[i].alias[1];
779 tmp[6]= names->key_aliases[i].alias[2];
780 tmp[7]= names->key_aliases[i].alias[3];
781 }
782#else
783 Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2){ if (dpy->bufptr + (nKA*4*2) <= dpy->bufmax) { memcpy
(dpy->bufptr, (char *)names->key_aliases, (int)nKA*4*2)
; dpy->bufptr += ((nKA*4*2) + 3) & ~3; } else _XSend(dpy
, (char *)names->key_aliases, nKA*4*2); }
;
784#endif
785 }
786 if (which&XkbRGNamesMask(1<<13)) {
787 Data32(dpy,(long *)names->radio_groups,nRG*4)_XData32(dpy, (long *)(long *)names->radio_groups, nRG*4);
788 }
789 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
790 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
791 return True1;
792}
793
794void
795XkbNoteNameChanges( XkbNameChangesPtr old,
796 XkbNamesNotifyEvent * new,
797 unsigned int wanted)
798{
799int first,last,old_last,new_last;
800
801 wanted&= new->changed;
802 if ((old==NULL((void*)0))||(new==NULL((void*)0))||(wanted==0))
803 return;
804 if (wanted&XkbKeyTypeNamesMask(1<<6)) {
805 if (old->changed&XkbKeyTypeNamesMask(1<<6)) {
806 new_last= (new->first_type+new->num_types-1);
807 old_last= (old->first_type+old->num_types-1);
808
809 if (new->first_type<old->first_type)
810 first= new->first_type;
811 else first= old->first_type;
812
813 if (old_last>new_last)
814 last= old_last;
815 else last= new_last;
816
817 old->first_type= first;
818 old->num_types= (last-first)+1;
819 }
820 else {
821 old->first_type= new->first_type;
822 old->num_types= new->num_types;
823 }
824 }
825 if (wanted&XkbKTLevelNamesMask(1<<7)) {
826 if (old->changed&XkbKTLevelNamesMask(1<<7)) {
827 new_last= (new->first_lvl+new->num_lvls-1);
828 old_last= (old->first_lvl+old->num_lvls-1);
829
830 if (new->first_lvl<old->first_lvl)
831 first= new->first_lvl;
832 else first= old->first_lvl;
833
834 if (old_last>new_last)
835 last= old_last;
836 else last= new_last;
837
838 old->first_lvl= first;
839 old->num_lvls= (last-first)+1;
840 }
841 else {
842 old->first_lvl= new->first_lvl;
843 old->num_lvls= new->num_lvls;
844 }
845 }
846 if (wanted&XkbIndicatorNamesMask(1<<8)) {
847 if (old->changed&XkbIndicatorNamesMask(1<<8))
848 old->changed_indicators|= new->changed_indicators;
849 else old->changed_indicators= new->changed_indicators;
850 }
851 if (wanted&XkbKeyNamesMask(1<<9)) {
852 if (old->changed&XkbKeyNamesMask(1<<9)) {
853 new_last= (new->first_key+new->num_keys-1);
854 old_last= (old->first_key+old->num_keys-1);
855
856 first= old->first_key;
857
858 if (new->first_key<old->first_key)
859 first= new->first_key;
860 if (old_last>new_last)
861 new_last= old_last;
862
863 old->first_key= first;
864 old->num_keys= (new_last-first)+1;
865 }
866 else {
867 old->first_key= new->first_key;
868 old->num_keys= new->num_keys;
869 }
870 }
871 if (wanted&XkbVirtualModNamesMask(1<<11)) {
872 if (old->changed&XkbVirtualModNamesMask(1<<11))
873 old->changed_vmods|= new->changed_vmods;
874 else old->changed_vmods= new->changed_vmods;
875 }
876 if (wanted&XkbGroupNamesMask(1<<12)) {
877 if (old->changed&XkbGroupNamesMask(1<<12))
878 old->changed_groups|= new->changed_groups;
879 else old->changed_groups= new->changed_groups;
880 }
881 if (wanted&XkbRGNamesMask(1<<13))
882 old->num_rg= new->num_radio_groups;
883 if (wanted&XkbKeyAliasesMask(1<<10))
884 old->num_aliases= new->num_aliases;
885 old->changed|= wanted;
886 return;
887}