Bug Summary

File:xkmread.c
Location:line 1216, column 6
Description:Function call argument is an uninitialized value

Annotated Source Code

1/************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3
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.
15
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.
24
25 ********************************************************/
26
27#ifdef HAVE_DIX_CONFIG_H
28#include <dix-config.h>
29#elif defined(HAVE_CONFIG_H1)
30#include <config.h>
31#endif
32
33#include <stdio.h>
34
35#include <X11/Xos.h>
36#include <X11/Xfuncs.h>
37
38#ifndef XKB_IN_SERVER
39
40#include <stdlib.h>
41#include <X11/Xlib.h>
42#include <X11/keysym.h>
43
44#include <X11/XKBlib.h>
45
46#include <X11/extensions/XKBgeom.h>
47#include "XKMformat.h"
48#include "XKBfileInt.h"
49
50#else
51
52#include <X11/X.h>
53#include <X11/Xproto.h>
54#include <X11/keysym.h>
55#include "misc.h"
56#include "inputstr.h"
57#include <X11/extensions/XKBstr.h>
58#define XKBSRV_NEED_FILE_FUNCS
59#include <X11/extensions/XKBsrv.h>
60#include <X11/extensions/XKBgeom.h>
61
62Atom
63XkbInternAtom(Display *dpy,char *str,Boolint only_if_exists)
64{
65 if (str==NULL((void*)0))
66 return None0L;
67 return MakeAtom(str,strlen(str),!only_if_exists);
68}
69
70#endif
71
72#ifndef SEEK_SET0
73#define SEEK_SET0 0
74#endif
75
76/***====================================================================***/
77
78static XPointer
79XkmInsureSize(XPointer oldPtr,int oldCount,int *newCountRtrn,int elemSize)
80{
81int newCount= *newCountRtrn;
82
83 if (oldPtr==NULL((void*)0)) {
84 if (newCount==0)
85 return NULL((void*)0);
86 oldPtr= (XPointer)_XkbCalloc(newCount,elemSize)calloc((newCount),(elemSize));
87 }
88 else if (oldCount<newCount) {
89 oldPtr= (XPointer)_XkbRealloc(oldPtr,newCount*elemSize)realloc((oldPtr),(newCount*elemSize));
90 if (oldPtr!=NULL((void*)0)) {
91 char *tmp= (char *)oldPtr;
92 bzero(&tmp[oldCount*elemSize],(newCount-oldCount)*elemSize)memset(&tmp[oldCount*elemSize],0,(newCount-oldCount)*elemSize
)
;
93 }
94 }
95 else if (newCount<oldCount) {
96 *newCountRtrn= oldCount;
97 }
98 return oldPtr;
99}
100
101#define XkmInsureTypedSize(p,o,n,t)((p)=((t *)XkmInsureSize((char *)(p),(o),(n),sizeof(t)))) ((p)=((t *)XkmInsureSize((char *)(p),(o),(n),sizeof(t))))
102
103static CARD8
104XkmGetCARD8(FILE *file,int *pNRead)
105{
106int tmp;
107 tmp= getc(file)_IO_getc (file);
108 if (pNRead&&(tmp!=EOF(-1)))
109 (*pNRead)+= 1;
110 return tmp;
111}
112
113static CARD16
114XkmGetCARD16(FILE *file,int *pNRead)
115{
116CARD16 val;
117
118 if ((fread(&val,2,1,file)==1)&&(pNRead))
119 (*pNRead)+= 2;
120 return val;
121}
122
123static CARD32
124XkmGetCARD32(FILE *file,int *pNRead)
125{
126CARD32 val;
127
128 if ((fread(&val,4,1,file)==1)&&(pNRead))
129 (*pNRead)+= 4;
130 return val;
131}
132
133static int
134XkmSkipPadding(FILE *file,unsigned pad)
135{
136register int i,nRead=0;
137
138 for (i=0;i<pad;i++) {
139 if (getc(file)_IO_getc (file)!=EOF(-1))
140 nRead++;
141 }
142 return nRead;
143}
144
145static int
146XkmGetCountedString(FILE *file,char *str,int max_len)
147{
148int count,nRead=0;
149
150 count= XkmGetCARD16(file,&nRead);
151 if (count>0) {
152 int tmp;
153 if (count>max_len) {
154 tmp= fread(str,1,max_len,file);
155 while (tmp<count) {
156 if ((getc(file)_IO_getc (file))!=EOF(-1))
157 tmp++;
158 else break;
159 }
160 }
161 else {
162 tmp= fread(str,1,count,file);
163 }
164 nRead+= tmp;
165 }
166 if (count>=max_len) str[max_len-1]= '\0';
167 else str[count]= '\0';
168 count= XkbPaddedSize(nRead)((((unsigned int)(nRead)+3) >> 2) << 2)-nRead;
169 if (count>0)
170 nRead+= XkmSkipPadding(file,count);
171 return nRead;
172}
173
174/***====================================================================***/
175
176static int
177ReadXkmVirtualMods(FILE *file,XkbFileInfo *result,XkbChangesPtr changes)
178{
179register unsigned int i,bit;
180unsigned int bound,named,tmp;
181int nRead=0;
182XkbDescPtr xkb;
183
184 xkb= result->xkb;
185 if (XkbAllocServerMap(xkb,XkbVirtualModsMask(1<<6),0)!=Success0) {
186 _XkbLibError(_XkbErrBadAlloc,"ReadXkmVirtualMods",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmVirtualMods");
_XkbErrData= (0); }
;
187 return -1;
188 }
189 bound= XkmGetCARD16(file,&nRead);
190 named= XkmGetCARD16(file,&nRead);
191 for (i=tmp=0,bit=1;i<XkbNumVirtualMods16;i++,bit<<=1) {
192 if (bound&bit) {
193 xkb->server->vmods[i]= XkmGetCARD8(file,&nRead);
194 if (changes)
195 changes->map.vmods|= bit;
196 tmp++;
197 }
198 }
199 if ((i= XkbPaddedSize(tmp)((((unsigned int)(tmp)+3) >> 2) << 2)-tmp)>0)
200 nRead+= XkmSkipPadding(file,i);
201 if (XkbAllocNames(xkb,XkbVirtualModNamesMask(1<<11),0,0)!=Success0) {
202 _XkbLibError(_XkbErrBadAlloc,"ReadXkmVirtualMods",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmVirtualMods");
_XkbErrData= (0); }
;
203 return -1;
204 }
205 for (i=0,bit=1;i<XkbNumVirtualMods16;i++,bit<<=1) {
206 char name[100];
207 if (named&bit) {
208 if (nRead+=XkmGetCountedString(file,name,100)) {
209 xkb->names->vmods[i]= XkbInternAtom(xkb->dpy,name,False0);
210 if (changes)
211 changes->names.changed_vmods|= bit;
212 }
213 }
214 }
215 return nRead;
216}
217
218/***====================================================================***/
219
220static int
221ReadXkmKeycodes(FILE *file,XkbFileInfo *result,XkbChangesPtr changes)
222{
223register int i;
224unsigned minKC,maxKC,nAl;
225int nRead=0;
226char name[100];
227XkbKeyNamePtr pN;
228XkbDescPtr xkb;
229
230 xkb= result->xkb;
231 name[0]= '\0';
232 nRead+= XkmGetCountedString(file,name,100);
233 minKC= XkmGetCARD8(file,&nRead);
234 maxKC= XkmGetCARD8(file,&nRead);
235 if (xkb->min_key_code==0) {
236 xkb->min_key_code= minKC;
237 xkb->max_key_code= maxKC;
238 }
239 else {
240 if (minKC<xkb->min_key_code)
241 xkb->min_key_code= minKC;
242 if (maxKC>xkb->max_key_code) {
243 _XkbLibError(_XkbErrBadValue,"ReadXkmKeycodes",maxKC){ _XkbErrCode= (16); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (maxKC); }
;
244 return -1;
245 }
246 }
247 nAl= XkmGetCARD8(file,&nRead);
248 nRead+= XkmSkipPadding(file,1);
249
250#define WANTED((1<<0)|(1<<9)|(1<<10)) (XkbKeycodesNameMask(1<<0)|XkbKeyNamesMask(1<<9)|XkbKeyAliasesMask(1<<10))
251 if (XkbAllocNames(xkb,WANTED((1<<0)|(1<<9)|(1<<10)),0,nAl)!=Success0) {
252 _XkbLibError(_XkbErrBadAlloc,"ReadXkmKeycodes",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
253 return -1;
254 }
255 if (name[0]!='\0') {
256 xkb->names->keycodes= XkbInternAtom(xkb->dpy,name,False0);
257 }
258
259 for (pN=&xkb->names->keys[minKC],i=minKC;i<=(int)maxKC;i++,pN++) {
260 if (fread(pN,1,XkbKeyNameLength4,file)!=XkbKeyNameLength4) {
261 _XkbLibError(_XkbErrBadLength,"ReadXkmKeycodes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
262 return -1;
263 }
264 nRead+= XkbKeyNameLength4;
265 }
266 if (nAl>0) {
267 XkbKeyAliasPtr pAl;
268 for (pAl= xkb->names->key_aliases,i=0;i<nAl;i++,pAl++) {
269 int tmp;
270 tmp= fread(pAl,1,2*XkbKeyNameLength4,file);
271 if (tmp!=2*XkbKeyNameLength4) {
272 _XkbLibError(_XkbErrBadLength,"ReadXkmKeycodes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
273 return -1;
274 }
275 nRead+= 2*XkbKeyNameLength4;
276 }
277 if (changes)
278 changes->names.changed|= XkbKeyAliasesMask(1<<10);
279 }
280 if (changes)
281 changes->names.changed|= XkbKeyNamesMask(1<<9);
282 return nRead;
283}
284
285/***====================================================================***/
286
287static int
288ReadXkmKeyTypes(FILE *file,XkbFileInfo *result,XkbChangesPtr changes)
289{
290register unsigned i,n;
291unsigned num_types;
292int nRead=0;
293int tmp;
294XkbKeyTypePtr type;
295xkmKeyTypeDesc wire;
296XkbKTMapEntryPtr entry;
297xkmKTMapEntryDesc wire_entry;
298char buf[100];
299XkbDescPtr xkb;
300
301 xkb= result->xkb;
302 if ((tmp= XkmGetCountedString(file,buf,100))<1) {
303 _XkbLibError(_XkbErrBadLength,"ReadXkmKeyTypes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
304 return -1;
305 }
306 nRead+= tmp;
307 if (buf[0]!='\0') {
308 if (XkbAllocNames(xkb,XkbTypesNameMask(1<<4),0,0)!=Success0) {
309 _XkbLibError(_XkbErrBadAlloc,"ReadXkmKeyTypes",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
310 return -1;
311 }
312 xkb->names->types= XkbInternAtom(xkb->dpy,buf,False0);
313 }
314 num_types= XkmGetCARD16(file,&nRead);
315 nRead+= XkmSkipPadding(file,2);
316 if (num_types<1)
317 return nRead;
318 if (XkbAllocClientMap(xkb,XkbKeyTypesMask(1<<0),num_types)!=Success0) {
319 _XkbLibError(_XkbErrBadAlloc,"ReadXkmKeyTypes",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
320 return nRead;
321 }
322 xkb->map->num_types= num_types;
323 if (num_types<XkbNumRequiredTypes(3 +1)) {
324 _XkbLibError(_XkbErrMissingReqTypes,"ReadXkmKeyTypes",0){ _XkbErrCode= (3); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
325 return -1;
326 }
327 type= xkb->map->types;
328 for (i=0;i<num_types;i++,type++) {
329 if ((int)fread(&wire,SIZEOF(xkmKeyTypeDesc)8,1,file)<1) {
330 _XkbLibError(_XkbErrBadLength,"ReadXkmKeyTypes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
331 return -1;
332 }
333 nRead+= SIZEOF(xkmKeyTypeDesc)8;
334 if (((i==XkbOneLevelIndex0)&&(wire.numLevels!=1))||
335 (((i==XkbTwoLevelIndex1)||(i==XkbAlphabeticIndex2)||
336 ((i)==XkbKeypadIndex3))&&(wire.numLevels!=2))) {
337 _XkbLibError(_XkbErrBadTypeWidth,"ReadXkmKeyTypes",i){ _XkbErrCode= (19); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (i); }
;
338 return -1;
339 }
340 tmp= wire.nMapEntries;
341 XkmInsureTypedSize(type->map,type->map_count,&tmp,XkbKTMapEntryRec)((type->map)=((XkbKTMapEntryRec *)XkmInsureSize((char *)(type
->map),(type->map_count),(&tmp),sizeof(XkbKTMapEntryRec
))))
;
342 if ((wire.nMapEntries>0)&&(type->map==NULL((void*)0))) {
343 _XkbLibError(_XkbErrBadValue,"ReadXkmKeyTypes",wire.nMapEntries){ _XkbErrCode= (16); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (wire.nMapEntries); }
;
344 return -1;
345 }
346 for (n=0,entry= type->map;n<wire.nMapEntries;n++,entry++) {
347 if (fread(&wire_entry,SIZEOF(xkmKTMapEntryDesc)4,1,file)<(int)1) {
348 _XkbLibError(_XkbErrBadLength,"ReadXkmKeyTypes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
349 return -1;
350 }
351 nRead+= SIZEOF(xkmKTMapEntryDesc)4;
352 entry->active= (wire_entry.virtualMods==0);
353 entry->level= wire_entry.level;
354 entry->mods.mask= wire_entry.realMods;
355 entry->mods.real_mods= wire_entry.realMods;
356 entry->mods.vmods= wire_entry.virtualMods;
357 }
358 nRead+= XkmGetCountedString(file,buf,100);
359 if (((i==XkbOneLevelIndex0)&&(strcmp(buf,"ONE_LEVEL")!=0))||
360 ((i==XkbTwoLevelIndex1)&&(strcmp(buf,"TWO_LEVEL")!=0))||
361 ((i==XkbAlphabeticIndex2)&&(strcmp(buf,"ALPHABETIC")!=0))||
362 ((i==XkbKeypadIndex3)&&(strcmp(buf,"KEYPAD")!=0))) {
363 _XkbLibError(_XkbErrBadTypeName,"ReadXkmKeyTypes",0){ _XkbErrCode= (18); _XkbErrLocation= ("ReadXkmKeyTypes"); _XkbErrData
= (0); }
;
364 return -1;
365 }
366 if (buf[0]!='\0') {
367 type->name= XkbInternAtom(xkb->dpy,buf,False0);
368 }
369 else type->name= None0L;
370
371 if (wire.preserve) {
372 xkmModsDesc p_entry;
373 XkbModsPtr pre;
374 XkmInsureTypedSize(type->preserve,type->map_count,&tmp,((type->preserve)=((XkbModsRec *)XkmInsureSize((char *)(type
->preserve),(type->map_count),(&tmp),sizeof(XkbModsRec
))))
375 XkbModsRec)((type->preserve)=((XkbModsRec *)XkmInsureSize((char *)(type
->preserve),(type->map_count),(&tmp),sizeof(XkbModsRec
))))
;
376 if (type->preserve==NULL((void*)0)) {
377 _XkbLibError(_XkbErrBadMatch,"ReadXkmKeycodes",0){ _XkbErrCode= (17); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
378 return -1;
379 }
380 for (n=0,pre=type->preserve;n<wire.nMapEntries;n++,pre++) {
381 if (fread(&p_entry,SIZEOF(xkmModsDesc)4,1,file)<1) {
382 _XkbLibError(_XkbErrBadLength,"ReadXkmKeycodes",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
383 return -1;
384 }
385 nRead+= SIZEOF(xkmModsDesc)4;
386 pre->mask= p_entry.realMods;
387 pre->real_mods= p_entry.realMods;
388 pre->vmods= p_entry.virtualMods;
389 }
390 }
391 if (wire.nLevelNames>0) {
392 int width= wire.numLevels;
393 if (wire.nLevelNames>(unsigned)width) {
394 _XkbLibError(_XkbErrBadMatch,"ReadXkmKeycodes",0){ _XkbErrCode= (17); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
395 return -1;
396 }
397 XkmInsureTypedSize(type->level_names,type->num_levels,&width,Atom)((type->level_names)=((Atom *)XkmInsureSize((char *)(type->
level_names),(type->num_levels),(&width),sizeof(Atom))
))
;
398 if (type->level_names!=NULL((void*)0)) {
399 for (n=0;n<wire.nLevelNames;n++) {
400 if ((tmp=XkmGetCountedString(file,buf,100))<1)
401 return -1;
402 nRead+= tmp;
403 if (strlen(buf)==0)
404 type->level_names[n]= None0L;
405 else type->level_names[n]= XkbInternAtom(xkb->dpy,buf,0);
406 }
407 }
408 }
409 type->mods.mask= wire.realMods;
410 type->mods.real_mods= wire.realMods;
411 type->mods.vmods= wire.virtualMods;
412 type->num_levels= wire.numLevels;
413 type->map_count= wire.nMapEntries;
414 }
415 if (changes) {
416 changes->map.changed|= XkbKeyTypesMask(1<<0);
417 changes->map.first_type= 0;
418 changes->map.num_types= xkb->map->num_types;
419 }
420 return nRead;
421}
422
423/***====================================================================***/
424
425static int
426ReadXkmCompatMap(FILE *file,XkbFileInfo *result,XkbChangesPtr changes)
427{
428register int i;
429unsigned num_si,groups;
430char name[100];
431XkbSymInterpretPtr interp;
432xkmSymInterpretDesc wire;
433unsigned tmp;
434int nRead=0;
435XkbDescPtr xkb;
436XkbCompatMapPtr compat;
437
438 xkb= result->xkb;
439 if ((tmp= XkmGetCountedString(file,name,100))<1) {
440 _XkbLibError(_XkbErrBadLength,"ReadXkmCompatMap",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmCompatMap"); _XkbErrData
= (0); }
;
441 return -1;
442 }
443 nRead+= tmp;
444 if (name[0]!='\0') {
445 if (XkbAllocNames(xkb,XkbCompatNameMask(1<<5),0,0)!=Success0) {
446 _XkbLibError(_XkbErrBadAlloc,"ReadXkmCompatMap",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmCompatMap"); _XkbErrData
= (0); }
;
447 return -1;
448 }
449 xkb->names->compat= XkbInternAtom(xkb->dpy,name,False0);
450 }
451 num_si= XkmGetCARD16(file,&nRead);
452 groups= XkmGetCARD8(file,&nRead);
453 nRead+= XkmSkipPadding(file,1);
454 if (XkbAllocCompatMap(xkb,XkbAllCompatMask(0x3),num_si)!=Success0)
455 return -1;
456 compat= xkb->compat;
457 compat->num_si= num_si;
458 interp= compat->sym_interpret;
459 for (i=0;i<num_si;i++,interp++) {
460 tmp= fread(&wire,SIZEOF(xkmSymInterpretDesc)16,1,file);
461 nRead+= tmp*SIZEOF(xkmSymInterpretDesc)16;
462 interp->sym= wire.sym;
463 interp->mods= wire.mods;
464 interp->match= wire.match;
465 interp->virtual_mod= wire.virtualMod;
466 interp->flags= wire.flags;
467 interp->act.type= wire.actionType;
468 interp->act.data[0]= wire.actionData[0];
469 interp->act.data[1]= wire.actionData[1];
470 interp->act.data[2]= wire.actionData[2];
471 interp->act.data[3]= wire.actionData[3];
472 interp->act.data[4]= wire.actionData[4];
473 interp->act.data[5]= wire.actionData[5];
474 interp->act.data[6]= wire.actionData[6];
475 }
476 if ((num_si>0)&&(changes)) {
477 changes->compat.first_si= 0;
478 changes->compat.num_si= num_si;
479 }
480 if (groups) {
481 register unsigned bit;
482 for (i=0,bit=1;i<XkbNumKbdGroups4;i++,bit<<=1) {
483 xkmModsDesc md;
484 if (groups&bit) {
485 tmp= fread(&md,SIZEOF(xkmModsDesc)4,1,file);
486 nRead+= tmp*SIZEOF(xkmModsDesc)4;
487 xkb->compat->groups[i].real_mods= md.realMods;
488 xkb->compat->groups[i].vmods= md.virtualMods;
489 if (md.virtualMods != 0) {
490 unsigned mask;
491 if (XkbVirtualModsToReal(xkb,md.virtualMods,&mask))
492 xkb->compat->groups[i].mask= md.realMods|mask;
493 }
494 else xkb->compat->groups[i].mask= md.realMods;
495 }
496 }
497 if (changes)
498 changes->compat.changed_groups|= groups;
499 }
500 return nRead;
501}
502
503static int
504ReadXkmIndicators(FILE *file,XkbFileInfo *result,XkbChangesPtr changes)
505{
506register unsigned nLEDs;
507xkmIndicatorMapDesc wire;
508char buf[100];
509unsigned tmp;
510int nRead=0;
511XkbDescPtr xkb;
512
513 xkb= result->xkb;
514 if ((xkb->indicators==NULL((void*)0))&&(XkbAllocIndicatorMaps(xkb)!=Success0)) {
515 _XkbLibError(_XkbErrBadAlloc,"indicator rec",0){ _XkbErrCode= (23); _XkbErrLocation= ("indicator rec"); _XkbErrData
= (0); }
;
516 return -1;
517 }
518 if (XkbAllocNames(xkb,XkbIndicatorNamesMask(1<<8),0,0)!=Success0) {
519 _XkbLibError(_XkbErrBadAlloc,"indicator names",0){ _XkbErrCode= (23); _XkbErrLocation= ("indicator names"); _XkbErrData
= (0); }
;
520 return -1;
521 }
522 nLEDs= XkmGetCARD8(file,&nRead);
523 nRead+= XkmSkipPadding(file,3);
524 xkb->indicators->phys_indicators= XkmGetCARD32(file,&nRead);
525 while (nLEDs-->0) {
526 Atom name;
527 XkbIndicatorMapPtr map;
528
529 if ((tmp=XkmGetCountedString(file,buf,100))<1) {
530 _XkbLibError(_XkbErrBadLength,"ReadXkmIndicators",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmIndicators"); _XkbErrData
= (0); }
;
531 return -1;
532 }
533 nRead+= tmp;
534 if (buf[0]!='\0')
535 name= XkbInternAtom(xkb->dpy,buf,False0);
536 else name= None0L;
537 if ((tmp=fread(&wire,SIZEOF(xkmIndicatorMapDesc)12,1,file))<1) {
538 _XkbLibError(_XkbErrBadLength,"ReadXkmIndicators",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmIndicators"); _XkbErrData
= (0); }
;
539 return -1;
540 }
541 nRead+= tmp*SIZEOF(xkmIndicatorMapDesc)12;
542 if (xkb->names) {
543 xkb->names->indicators[wire.indicator-1]= name;
544 if (changes)
545 changes->names.changed_indicators|= (1<<(wire.indicator-1));
546 }
547 map= &xkb->indicators->maps[wire.indicator-1];
548 map->flags= wire.flags;
549 map->which_groups= wire.which_groups;
550 map->groups= wire.groups;
551 map->which_mods= wire.which_mods;
552 map->mods.mask= wire.real_mods;
553 map->mods.real_mods= wire.real_mods;
554 map->mods.vmods= wire.vmods;
555 map->ctrls= wire.ctrls;
556 }
557 return nRead;
558}
559
560static XkbKeyTypePtr
561FindTypeForKey(XkbDescPtr xkb,Atom name,unsigned width,KeySym *syms)
562{
563 if ((!xkb)||(!xkb->map))
564 return NULL((void*)0);
565 if (name!=None0L) {
566 register unsigned i;
567 for (i=0;i<xkb->map->num_types;i++) {
568 if (xkb->map->types[i].name==name) {
569#ifdef DEBUG
570 if (xkb->map->types[i].num_levels!=width)
571 fprintf(stderrstderr,"Group width mismatch between key and type\n");
572#endif
573 return &xkb->map->types[i];
574 }
575 }
576 }
577 if ((width<2)||((syms!=NULL((void*)0))&&(syms[1]==NoSymbol0L)))
578 return &xkb->map->types[XkbOneLevelIndex0];
579 if (syms!=NULL((void*)0)) {
580 if (XkbKSIsLower(syms[0])(_XkbKSCheckCase(syms[0])&(1<<0))&&XkbKSIsUpper(syms[1])(_XkbKSCheckCase(syms[1])&(1<<1)))
581 return &xkb->map->types[XkbAlphabeticIndex2];
582 else if (XkbKSIsKeypad(syms[0])(((syms[0])>=0xff80)&&((syms[0])<=0xffbd))||XkbKSIsKeypad(syms[1])(((syms[1])>=0xff80)&&((syms[1])<=0xffbd)))
583 return &xkb->map->types[XkbKeypadIndex3];
584 }
585 return &xkb->map->types[XkbTwoLevelIndex1];
586}
587
588static int
589ReadXkmSymbols(FILE *file,XkbFileInfo *result)
590{
591register int i,g,s,totalVModMaps;
592xkmKeySymMapDesc wireMap;
593char buf[100];
594unsigned minKC,maxKC,groupNames,tmp;
595int nRead=0;
596XkbDescPtr xkb;
597
598 xkb= result->xkb;
599 if ((tmp=XkmGetCountedString(file,buf,100))<1)
600 return -1;
601 nRead+= tmp;
602 minKC= XkmGetCARD8(file,&nRead);
603 maxKC= XkmGetCARD8(file,&nRead);
604 groupNames= XkmGetCARD8(file,&nRead);
605 totalVModMaps= XkmGetCARD8(file,&nRead);
606 if (XkbAllocNames(xkb,
607 XkbSymbolsNameMask(1<<2)|XkbPhysSymbolsNameMask(1<<3)|XkbGroupNamesMask(1<<12),
608 0,0)!=Success0) {
609 _XkbLibError(_XkbErrBadAlloc,"physical names",0){ _XkbErrCode= (23); _XkbErrLocation= ("physical names"); _XkbErrData
= (0); }
;
610 return -1;
611 }
612 if ((buf[0]!='\0')&&(xkb->names)) {
613 Atom name;
614 name= XkbInternAtom(xkb->dpy,buf,0);
615 xkb->names->symbols= name;
616 xkb->names->phys_symbols= name;
617 }
618 for (i=0,g=1;i<XkbNumKbdGroups4;i++,g<<=1) {
619 if (groupNames&g) {
620 if ((tmp=XkmGetCountedString(file,buf,100))<1)
621 return -1;
622 nRead+= tmp;
623 if ((buf[0]!='\0')&&(xkb->names)) {
624 Atom name;
625 name= XkbInternAtom(xkb->dpy,buf,0);
626 xkb->names->groups[i]= name;
627 }
628 else xkb->names->groups[i]= None0L;
629 }
630 }
631 if (XkbAllocServerMap(xkb,XkbAllServerInfoMask((1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<
7))
,0)!=Success0) {
632 _XkbLibError(_XkbErrBadAlloc,"server map",0){ _XkbErrCode= (23); _XkbErrLocation= ("server map"); _XkbErrData
= (0); }
;
633 return -1;
634 }
635 if (XkbAllocClientMap(xkb,XkbAllClientInfoMask((1<<0)|(1<<1)|(1<<2)),0)!=Success0) {
636 _XkbLibError(_XkbErrBadAlloc,"client map",0){ _XkbErrCode= (23); _XkbErrLocation= ("client map"); _XkbErrData
= (0); }
;
637 return -1;
638 }
639 if (XkbAllocControls(xkb,XkbAllControlsMask(0xF8001FFF))!=Success0) {
640 _XkbLibError(_XkbErrBadAlloc,"controls",0){ _XkbErrCode= (23); _XkbErrLocation= ("controls"); _XkbErrData
= (0); }
;
641 return -1;
642 }
643 if ((xkb->map==NULL((void*)0))||(xkb->server==NULL((void*)0)))
644 return -1;
645 if (xkb->min_key_code<8) xkb->min_key_code= minKC;
646 if (xkb->max_key_code<8) xkb->max_key_code= maxKC;
647 if ((minKC>=8)&&(minKC<xkb->min_key_code))
648 xkb->min_key_code= minKC;
649 if ((maxKC>=8)&&(maxKC>xkb->max_key_code)) {
650 _XkbLibError(_XkbErrBadValue,"keys in symbol map",maxKC){ _XkbErrCode= (16); _XkbErrLocation= ("keys in symbol map");
_XkbErrData= (maxKC); }
;
651 return -1;
652 }
653 for (i=minKC;i<=(int)maxKC;i++) {
654 Atom typeName[XkbNumKbdGroups4];
655 XkbKeyTypePtr type[XkbNumKbdGroups4];
656 if ((tmp=fread(&wireMap,SIZEOF(xkmKeySymMapDesc)4,1,file))<1) {
657 _XkbLibError(_XkbErrBadLength,"ReadXkmSymbols",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmSymbols"); _XkbErrData
= (0); }
;
658 return -1;
659 }
660 nRead+= tmp*SIZEOF(xkmKeySymMapDesc)4;
661 bzero((char *)typeName,XkbNumKbdGroups*sizeof(Atom))memset((char *)typeName,0,4*sizeof(Atom));
662 bzero((char *)type,XkbNumKbdGroups*sizeof(XkbKeyTypePtr))memset((char *)type,0,4*sizeof(XkbKeyTypePtr));
663 if (wireMap.flags&XkmKeyHasTypes(0x0f)) {
664 register int g;
665 for (g=0;g<XkbNumKbdGroups4;g++) {
666 if ((wireMap.flags&(1<<g))&&
667 ((tmp=XkmGetCountedString(file,buf,100))>0)) {
668 typeName[g]= XkbInternAtom(xkb->dpy,buf,1);
669 nRead+= tmp;
670 }
671 type[g]=FindTypeForKey(xkb,typeName[g],wireMap.width,NULL((void*)0));
672 if (type[g]==NULL((void*)0)) {
673 _XkbLibError(_XkbErrMissingTypes,"ReadXkmSymbols",0){ _XkbErrCode= (2); _XkbErrLocation= ("ReadXkmSymbols"); _XkbErrData
= (0); }
;
674 return -1;
675 }
676 if (typeName[g]==type[g]->name)
677 xkb->server->explicit[i]|= (1<<g);
678 }
679 }
680 if (wireMap.flags&XkmRepeatingKey(1<<6)) {
681 xkb->ctrls->per_key_repeat[i/8]|= (1<<(i%8));
682 xkb->server->explicit[i]|= XkbExplicitAutoRepeatMask(1<<5);
683 }
684 else if (wireMap.flags&XkmNonRepeatingKey(1<<7)) {
685 xkb->ctrls->per_key_repeat[i/8]&= ~(1<<(i%8));
686 xkb->server->explicit[i]|= XkbExplicitAutoRepeatMask(1<<5);
687 }
688 xkb->map->modmap[i]= wireMap.modifier_map;
689 if (XkbNumGroups(wireMap.num_groups)((wireMap.num_groups)&0x0f)>0) {
690 KeySym *sym;
691 int nSyms;
692
693 if (XkbNumGroups(wireMap.num_groups)((wireMap.num_groups)&0x0f)>xkb->ctrls->num_groups)
694 xkb->ctrls->num_groups= wireMap.num_groups;
695 nSyms= XkbNumGroups(wireMap.num_groups)((wireMap.num_groups)&0x0f)*wireMap.width;
696 sym= XkbResizeKeySyms(xkb,i,nSyms);
697 if (!sym)
698 return -1;
699 for (s=0;s<nSyms;s++) {
700 *sym++= XkmGetCARD32(file,&nRead);
701 }
702 if (wireMap.flags&XkmKeyHasActions(1<<4)) {
703 XkbAction * act;
704 act= XkbResizeKeyActions(xkb,i,nSyms);
705 for (s=0;s<nSyms;s++,act++) {
706 tmp=fread(act,SIZEOF(xkmActionDesc)8,1,file);
707 nRead+= tmp*SIZEOF(xkmActionDesc)8;
708 }
709 xkb->server->explicit[i]|= XkbExplicitInterpretMask(1<<4);
710 }
711 }
712 for (g=0;g<XkbNumGroups(wireMap.num_groups)((wireMap.num_groups)&0x0f);g++) {
713 if (((xkb->server->explicit[i]&(1<<g))==0)||(type[g]==NULL((void*)0))) {
714 KeySym *tmpSyms;
715 tmpSyms= XkbKeySymsPtr(xkb,i)((&((xkb)->map)->syms[(((xkb)->map)->key_sym_map
[(i)].offset)]))
+(wireMap.width*g);
716 type[g]= FindTypeForKey(xkb,None0L,wireMap.width,tmpSyms);
717 }
718 xkb->map->key_sym_map[i].kt_index[g]= type[g]-(&xkb->map->types[0]);
719 }
720 xkb->map->key_sym_map[i].group_info= wireMap.num_groups;
721 xkb->map->key_sym_map[i].width= wireMap.width;
722 if (wireMap.flags&XkmKeyHasBehavior(1<<5)) {
723 xkmBehaviorDesc b;
724 tmp= fread(&b,SIZEOF(xkmBehaviorDesc)4,1,file);
725 nRead+= tmp*SIZEOF(xkmBehaviorDesc)4;
726 xkb->server->behaviors[i].type= b.type;
727 xkb->server->behaviors[i].data= b.data;
728 xkb->server->explicit[i]|= XkbExplicitBehaviorMask(1<<6);
729 }
730 }
731 if (totalVModMaps>0) {
732 xkmVModMapDesc v;
733 for (i=0;i<totalVModMaps;i++) {
734 tmp= fread(&v,SIZEOF(xkmVModMapDesc)4,1,file);
735 nRead+= tmp*SIZEOF(xkmVModMapDesc)4;
736 if (tmp>0)
737 xkb->server->vmodmap[v.key]= v.vmods;
738 }
739 }
740 return nRead;
741}
742
743static int
744ReadXkmGeomDoodad(
745 FILE * file,
746 Display * dpy,
747 XkbGeometryPtr geom,
748 XkbSectionPtr section)
749{
750XkbDoodadPtr doodad;
751xkmDoodadDesc doodadWire;
752char buf[100];
753unsigned tmp;
754int nRead=0;
755
756 nRead+= XkmGetCountedString(file,buf,100);
757 tmp= fread(&doodadWire,SIZEOF(xkmDoodadDesc)16,1,file);
758 nRead+= SIZEOF(xkmDoodadDesc)16*tmp;
759 doodad= XkbAddGeomDoodad(geom,section,XkbInternAtom(dpy,buf,False0));
760 if (!doodad)
761 return nRead;
762 doodad->any.type= doodadWire.any.type;
763 doodad->any.priority= doodadWire.any.priority;
764 doodad->any.top= doodadWire.any.top;
765 doodad->any.left= doodadWire.any.left;
766 switch (doodadWire.any.type) {
767 case XkbOutlineDoodad1:
768 case XkbSolidDoodad2:
769 doodad->shape.angle= doodadWire.shape.angle;
770 doodad->shape.color_ndx= doodadWire.shape.color_ndx;
771 doodad->shape.shape_ndx= doodadWire.shape.shape_ndx;
772 break;
773 case XkbTextDoodad3:
774 doodad->text.angle= doodadWire.text.angle;
775 doodad->text.width= doodadWire.text.width;
776 doodad->text.height= doodadWire.text.height;
777 doodad->text.color_ndx= doodadWire.text.color_ndx;
778 nRead+= XkmGetCountedString(file,buf,100);
779 doodad->text.text= _XkbDupString(buf);
780 nRead+= XkmGetCountedString(file,buf,100);
781 doodad->text.font= _XkbDupString(buf);
782 break;
783 case XkbIndicatorDoodad4:
784 doodad->indicator.shape_ndx= doodadWire.indicator.shape_ndx;
785 doodad->indicator.on_color_ndx= doodadWire.indicator.on_color_ndx;
786 doodad->indicator.off_color_ndx= doodadWire.indicator.off_color_ndx;
787 break;
788 case XkbLogoDoodad5:
789 doodad->logo.angle= doodadWire.logo.angle;
790 doodad->logo.color_ndx= doodadWire.logo.color_ndx;
791 doodad->logo.shape_ndx= doodadWire.logo.shape_ndx;
792 nRead+= XkmGetCountedString(file,buf,100);
793 doodad->logo.logo_name= _XkbDupString(buf);
794 break;
795 default:
796 /* report error? */
797 return nRead;
798 }
799 return nRead;
800}
801
802static int
803ReadXkmGeomOverlay( FILE * file,
804 Display * dpy,
805 XkbGeometryPtr geom,
806 XkbSectionPtr section)
807{
808char buf[100];
809unsigned tmp;
810int nRead=0;
811XkbOverlayPtr ol;
812XkbOverlayRowPtr row;
813xkmOverlayDesc olWire;
814xkmOverlayRowDesc rowWire;
815register int r;
816
817 nRead+= XkmGetCountedString(file,buf,100);
818 tmp= fread(&olWire,SIZEOF(xkmOverlayDesc)4,1,file);
819 nRead+= tmp*SIZEOF(xkmOverlayDesc)4;
820 ol= XkbAddGeomOverlay(section,XkbInternAtom(dpy,buf,False0),
821 olWire.num_rows);
822 if (!ol)
823 return nRead;
824 for (r=0;r<olWire.num_rows;r++) {
825 int k;
826 xkmOverlayKeyDesc keyWire;
827 tmp= fread(&rowWire,SIZEOF(xkmOverlayRowDesc)4,1,file);
828 nRead+= tmp*SIZEOF(xkmOverlayRowDesc)4;
829 row= XkbAddGeomOverlayRow(ol,rowWire.row_under,rowWire.num_keys);
830 if (!row) {
831 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeomOverlay",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeomOverlay");
_XkbErrData= (0); }
;
832 return nRead;
833 }
834 for (k=0;k<rowWire.num_keys;k++) {
835 tmp= fread(&keyWire,SIZEOF(xkmOverlayKeyDesc)8,1,file);
836 nRead+= tmp*SIZEOF(xkmOverlayKeyDesc)8;
837 memcpy(row->keys[k].over.name,keyWire.over,XkbKeyNameLength4);
838 memcpy(row->keys[k].under.name,keyWire.under,XkbKeyNameLength4);
839 }
840 row->num_keys= rowWire.num_keys;
841 }
842 return nRead;
843}
844
845static int
846ReadXkmGeomSection( FILE * file,
847 Display * dpy,
848 XkbGeometryPtr geom)
849{
850register int i;
851XkbSectionPtr section;
852xkmSectionDesc sectionWire;
853unsigned tmp;
854int nRead= 0;
855char buf[100];
856Atom nameAtom;
857
858 nRead+= XkmGetCountedString(file,buf,100);
859 nameAtom= XkbInternAtom(dpy,buf,False0);
860 tmp= fread(&sectionWire,SIZEOF(xkmSectionDesc)16,1,file);
861 nRead+= SIZEOF(xkmSectionDesc)16*tmp;
862 section= XkbAddGeomSection(geom,nameAtom,sectionWire.num_rows,
863 sectionWire.num_doodads,
864 sectionWire.num_overlays);
865 if (!section) {
866 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeomSection",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeomSection");
_XkbErrData= (0); }
;
867 return nRead;
868 }
869 section->top= sectionWire.top;
870 section->left= sectionWire.left;
871 section->width= sectionWire.width;
872 section->height= sectionWire.height;
873 section->angle= sectionWire.angle;
874 section->priority= sectionWire.priority;
875 if (sectionWire.num_rows>0) {
876 register int k;
877 XkbRowPtr row;
878 xkmRowDesc rowWire;
879 XkbKeyPtr key;
880 xkmKeyDesc keyWire;
881
882 for (i=0;i<sectionWire.num_rows;i++) {
883 tmp= fread(&rowWire,SIZEOF(xkmRowDesc)8,1,file);
884 nRead+= SIZEOF(xkmRowDesc)8*tmp;
885 row= XkbAddGeomRow(section,rowWire.num_keys);
886 if (!row) {
887 _XkbLibError(_XkbErrBadAlloc,"ReadXkmKeycodes",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmKeycodes"); _XkbErrData
= (0); }
;
888 return nRead;
889 }
890 row->top= rowWire.top;
891 row->left= rowWire.left;
892 row->vertical= rowWire.vertical;
893 for (k=0;k<rowWire.num_keys;k++) {
894 tmp= fread(&keyWire,SIZEOF(xkmKeyDesc)8,1,file);
895 nRead+= SIZEOF(xkmKeyDesc)8*tmp;
896 key= XkbAddGeomKey(row);
897 if (!key) {
898 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeomSection",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeomSection");
_XkbErrData= (0); }
;
899 return nRead;
900 }
901 memcpy(key->name.name,keyWire.name,XkbKeyNameLength4);
902 key->gap= keyWire.gap;
903 key->shape_ndx= keyWire.shape_ndx;
904 key->color_ndx= keyWire.color_ndx;
905 }
906 }
907 }
908 if (sectionWire.num_doodads>0) {
909 for (i=0;i<sectionWire.num_doodads;i++) {
910 tmp= ReadXkmGeomDoodad(file,dpy,geom,section);
911 nRead+= tmp;
912 if (tmp<1)
913 return nRead;
914 }
915 }
916 if (sectionWire.num_overlays>0) {
917 for (i=0;i<sectionWire.num_overlays;i++) {
918 tmp= ReadXkmGeomOverlay(file,dpy,geom,section);
919 nRead+= tmp;
920 if (tmp<1)
921 return nRead;
922 }
923 }
924 return nRead;
925}
926
927static int
928ReadXkmGeometry(FILE *file,XkbFileInfo *result)
929{
930register int i;
931char buf[100];
932unsigned tmp;
933int nRead= 0;
934xkmGeometryDesc wireGeom;
935XkbGeometryPtr geom;
936XkbGeometrySizesRec sizes;
937
938 nRead+= XkmGetCountedString(file,buf,100);
939 tmp= fread(&wireGeom,SIZEOF(xkmGeometryDesc)20,1,file);
940 nRead+= tmp*SIZEOF(xkmGeometryDesc)20;
941 sizes.which= XkbGeomAllMask(0x3f);
942 sizes.num_properties= wireGeom.num_properties;
943 sizes.num_colors= wireGeom.num_colors;
944 sizes.num_shapes= wireGeom.num_shapes;
945 sizes.num_sections= wireGeom.num_sections;
946 sizes.num_doodads= wireGeom.num_doodads;
947 sizes.num_key_aliases= wireGeom.num_key_aliases;
948 if (XkbAllocGeometry(result->xkb,&sizes)!=Success0) {
949 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeometry",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
950 return nRead;
951 }
952 geom= result->xkb->geom;
953 geom->name= XkbInternAtom(result->xkb->dpy,buf,False0);
954 geom->width_mm= wireGeom.width_mm;
955 geom->height_mm= wireGeom.height_mm;
956 nRead+= XkmGetCountedString(file,buf,100);
957 geom->label_font= _XkbDupString(buf);
958 if (wireGeom.num_properties>0) {
959 char val[1024];
960 for (i=0;i<wireGeom.num_properties;i++) {
961 nRead+= XkmGetCountedString(file,buf,100);
962 nRead+= XkmGetCountedString(file,val,1024);
963 if (XkbAddGeomProperty(geom,buf,val)==NULL((void*)0)) {
964 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeometry",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
965 return nRead;
966 }
967 }
968 }
969 if (wireGeom.num_colors>0) {
970 for (i=0;i<wireGeom.num_colors;i++) {
971 nRead+= XkmGetCountedString(file,buf,100);
972 if (XkbAddGeomColor(geom,buf,i)==NULL((void*)0)) {
973 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeometry",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
974 return nRead;
975 }
976 }
977 }
978 geom->base_color= &geom->colors[wireGeom.base_color_ndx];
979 geom->label_color= &geom->colors[wireGeom.label_color_ndx];
980 if (wireGeom.num_shapes>0) {
981 XkbShapePtr shape;
982 xkmShapeDesc shapeWire;
983 Atom nameAtom;
984 for (i=0;i<wireGeom.num_shapes;i++) {
985 register int n;
986 XkbOutlinePtr ol;
987 xkmOutlineDesc olWire;
988 nRead+= XkmGetCountedString(file,buf,100);
989 nameAtom= XkbInternAtom(result->xkb->dpy,buf,False0);
990 tmp= fread(&shapeWire,SIZEOF(xkmShapeDesc)4,1,file);
991 nRead+= tmp*SIZEOF(xkmShapeDesc)4;
992 shape= XkbAddGeomShape(geom,nameAtom,shapeWire.num_outlines);
993 if (!shape) {
994 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeometry",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
995 return nRead;
996 }
997 for (n=0;n<shapeWire.num_outlines;n++) {
998 register int p;
999 xkmPointDesc ptWire;
1000 tmp= fread(&olWire,SIZEOF(xkmOutlineDesc)4,1,file);
1001 nRead+= tmp*SIZEOF(xkmOutlineDesc)4;
1002 ol= XkbAddGeomOutline(shape,olWire.num_points);
1003 if (!ol) {
1004 _XkbLibError(_XkbErrBadAlloc,"ReadXkmGeometry",0){ _XkbErrCode= (23); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
1005 return nRead;
1006 }
1007 ol->num_points= olWire.num_points;
1008 ol->corner_radius= olWire.corner_radius;
1009 for (p=0;p<olWire.num_points;p++) {
1010 tmp= fread(&ptWire,SIZEOF(xkmPointDesc)4,1,file);
1011 nRead+= tmp*SIZEOF(xkmPointDesc)4;
1012 ol->points[p].x= ptWire.x;
1013 ol->points[p].y= ptWire.y;
1014 if (ptWire.x<shape->bounds.x1) shape->bounds.x1= ptWire.x;
1015 if (ptWire.x>shape->bounds.x2) shape->bounds.x2= ptWire.x;
1016 if (ptWire.y<shape->bounds.y1) shape->bounds.y1= ptWire.y;
1017 if (ptWire.y>shape->bounds.y2) shape->bounds.y2= ptWire.y;
1018 }
1019 }
1020 if (shapeWire.primary_ndx!=XkbNoShape0xff)
1021 shape->primary= &shape->outlines[shapeWire.primary_ndx];
1022 if (shapeWire.approx_ndx!=XkbNoShape0xff)
1023 shape->approx= &shape->outlines[shapeWire.approx_ndx];
1024 }
1025 }
1026 if (wireGeom.num_sections>0) {
1027 for (i=0;i<wireGeom.num_sections;i++) {
1028 tmp= ReadXkmGeomSection(file,result->xkb->dpy,geom);
1029 nRead+= tmp;
1030 if (tmp==0)
1031 return nRead;
1032 }
1033 }
1034 if (wireGeom.num_doodads>0) {
1035 for (i=0;i<wireGeom.num_doodads;i++) {
1036 tmp= ReadXkmGeomDoodad(file,result->xkb->dpy,geom,NULL((void*)0));
1037 nRead+= tmp;
1038 if (tmp==0)
1039 return nRead;
1040 }
1041 }
1042 if ((wireGeom.num_key_aliases>0)&&(geom->key_aliases)) {
1043 int sz= XkbKeyNameLength4*2;
1044 int num= wireGeom.num_key_aliases;
1045 if (fread(geom->key_aliases,sz,num,file)!=num) {
1046 _XkbLibError(_XkbErrBadLength,"ReadXkmGeometry",0){ _XkbErrCode= (24); _XkbErrLocation= ("ReadXkmGeometry"); _XkbErrData
= (0); }
;
1047 return -1;
1048 }
1049 nRead+= (num*sz);
1050 geom->num_key_aliases= num;
1051 }
1052 return nRead;
1053}
1054
1055Boolint
1056XkmProbe(FILE *file)
1057{
1058unsigned hdr,tmp;
1059int nRead=0;
1060
1061 hdr= (('x'<<24)|('k'<<16)|('m'<<8)|XkmFileVersion15);
1062 tmp= XkmGetCARD32(file,&nRead);
1063 if (tmp!=hdr) {
1064 if ((tmp&(~0xff))==(hdr&(~0xff))) {
1065 _XkbLibError(_XkbErrBadFileVersion,"XkmProbe",tmp&0xff){ _XkbErrCode= (21); _XkbErrLocation= ("XkmProbe"); _XkbErrData
= (tmp&0xff); }
;
1066 }
1067 return 0;
1068 }
1069 return 1;
1070}
1071
1072Boolint
1073XkmReadTOC(FILE *file,xkmFileInfo* file_info,int max_toc,xkmSectionInfo *toc)
1074{
1075unsigned hdr,tmp;
1076int nRead=0;
1077unsigned i,size_toc;
1078
1079 hdr= (('x'<<24)|('k'<<16)|('m'<<8)|XkmFileVersion15);
1080 tmp= XkmGetCARD32(file,&nRead);
1081 if (tmp!=hdr) {
1082 if ((tmp&(~0xff))==(hdr&(~0xff))) {
1083 _XkbLibError(_XkbErrBadFileVersion,"XkmReadTOC",tmp&0xff){ _XkbErrCode= (21); _XkbErrLocation= ("XkmReadTOC"); _XkbErrData
= (tmp&0xff); }
;
1084 }
1085 else {
1086 _XkbLibError(_XkbErrBadFileType,"XkmReadTOC",tmp){ _XkbErrCode= (20); _XkbErrLocation= ("XkmReadTOC"); _XkbErrData
= (tmp); }
;
1087 }
1088 return 0;
1089 }
1090 fread(file_info,SIZEOF(xkmFileInfo)8,1,file);
1091 size_toc= file_info->num_toc;
1092 if (size_toc>max_toc) {
1093#ifdef DEBUG
1094 fprintf(stderrstderr,"Warning! Too many TOC entries; last %d ignored\n",
1095 size_toc-max_toc);
1096#endif
1097 size_toc= max_toc;
1098 }
1099 for (i=0;i<size_toc;i++) {
1100 fread(&toc[i],SIZEOF(xkmSectionInfo)8,1,file);
1101 }
1102 return 1;
1103}
1104
1105xkmSectionInfo *
1106XkmFindTOCEntry(xkmFileInfo *finfo,xkmSectionInfo *toc,unsigned type)
1107{
1108register int i;
1109
1110 for (i=0;i<finfo->num_toc;i++) {
1111 if (toc[i].type==type)
1112 return &toc[i];
1113 }
1114 return NULL((void*)0);
1115}
1116
1117Boolint
1118XkmReadFileSection( FILE * file,
1119 xkmSectionInfo * toc,
1120 XkbFileInfo * result,
1121 unsigned * loaded_rtrn)
1122{
1123xkmSectionInfo tmpTOC;
1124int nRead;
1125
1126 if ((!result)||(!result->xkb)) {
1127 _XkbLibError(_XkbErrBadMatch,"XkmReadFileSection",0){ _XkbErrCode= (17); _XkbErrLocation= ("XkmReadFileSection");
_XkbErrData= (0); }
;
1128 return 0;
1129 }
1130 fseek(file,toc->offset,SEEK_SET0);
1131 fread(&tmpTOC,SIZEOF(xkmSectionInfo)8,1,file);
1132 nRead= SIZEOF(xkmSectionInfo)8;
1133 if ((tmpTOC.type!=toc->type)||(tmpTOC.format!=toc->format)||
1134 (tmpTOC.size!=toc->size)||(tmpTOC.offset!=toc->offset)) {
1135 _XkbLibError(_XkbErrIllegalContents,"XkmReadFileSection",0){ _XkbErrCode= (12); _XkbErrLocation= ("XkmReadFileSection");
_XkbErrData= (0); }
;
1136 return 0;
1137 }
1138 switch (tmpTOC.type) {
1139 case XkmVirtualModsIndex6:
1140 nRead+= ReadXkmVirtualMods(file,result,NULL((void*)0));
1141 if ((loaded_rtrn)&&(nRead>=0))
1142 *loaded_rtrn|= XkmVirtualModsMask(1<<6);
1143 break;
1144 case XkmTypesIndex0:
1145 nRead+= ReadXkmKeyTypes(file,result,NULL((void*)0));
1146 if ((loaded_rtrn)&&(nRead>=0))
1147 *loaded_rtrn|= XkmTypesMask(1<<0);
1148 break;
1149 case XkmCompatMapIndex1:
1150 nRead+= ReadXkmCompatMap(file,result,NULL((void*)0));
1151 if ((loaded_rtrn)&&(nRead>=0))
1152 *loaded_rtrn|= XkmCompatMapMask(1<<1);
1153 break;
1154 case XkmKeyNamesIndex4:
1155 nRead+= ReadXkmKeycodes(file,result,NULL((void*)0));
1156 if ((loaded_rtrn)&&(nRead>=0))
1157 *loaded_rtrn|= XkmKeyNamesMask(1<<4);
1158 break;
1159 case XkmSymbolsIndex2:
1160 nRead+= ReadXkmSymbols(file,result);
1161 if ((loaded_rtrn)&&(nRead>=0))
1162 *loaded_rtrn|= XkmSymbolsMask(1<<2);
1163 break;
1164 case XkmIndicatorsIndex3:
1165 nRead+= ReadXkmIndicators(file,result,NULL((void*)0));
1166 if ((loaded_rtrn)&&(nRead>=0))
1167 *loaded_rtrn|= XkmIndicatorsMask(1<<3);
1168 break;
1169 case XkmGeometryIndex5:
1170 nRead+= ReadXkmGeometry(file,result);
1171 if ((loaded_rtrn)&&(nRead>=0))
1172 *loaded_rtrn|= XkmGeometryMask(1<<5);
1173 break;
1174 default:
1175 _XkbLibError(_XkbErrBadImplementation,{ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
1176 XkbConfigText(tmpTOC.type,XkbMessage),0){ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
;
1177 nRead= 0;
1178 break;
1179 }
1180 if (nRead!=tmpTOC.size) {
1181 _XkbLibError(_XkbErrBadLength,XkbConfigText(tmpTOC.type,XkbMessage),{ _XkbErrCode= (24); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (nRead-tmpTOC.size); }
1182 nRead-tmpTOC.size){ _XkbErrCode= (24); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (nRead-tmpTOC.size); }
;
1183 return 0;
1184 }
1185 return (nRead>=0);
1186}
1187
1188char *
1189XkmReadFileSectionName(FILE *file,xkmSectionInfo *toc)
1190{
1191xkmSectionInfo tmpTOC;
1192char name[100];
1193
1194 if ((!file)||(!toc))
1
Assuming 'file' is non-null
2
Assuming 'toc' is non-null
3
Taking false branch
1195 return NULL((void*)0);
1196 switch (toc->type) {
4
Control jumps to the 'default' case at line 1215
1197 case XkmVirtualModsIndex6:
1198 case XkmIndicatorsIndex3:
1199 break;
1200 case XkmTypesIndex0:
1201 case XkmCompatMapIndex1:
1202 case XkmKeyNamesIndex4:
1203 case XkmSymbolsIndex2:
1204 case XkmGeometryIndex5:
1205 fseek(file,toc->offset,SEEK_SET0);
1206 fread(&tmpTOC,SIZEOF(xkmSectionInfo)8,1,file);
1207 if ((tmpTOC.type!=toc->type)||(tmpTOC.format!=toc->format)||
1208 (tmpTOC.size!=toc->size)||(tmpTOC.offset!=toc->offset)) {
1209 _XkbLibError(_XkbErrIllegalContents,"XkmReadFileSectionName",0){ _XkbErrCode= (12); _XkbErrLocation= ("XkmReadFileSectionName"
); _XkbErrData= (0); }
;
1210 return NULL((void*)0);
1211 }
1212 if (XkmGetCountedString(file,name,100)>0)
1213 return _XkbDupString(name);
1214 break;
1215 default:
1216 _XkbLibError(_XkbErrBadImplementation,{ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
5
Within the expansion of the macro '_XkbLibError':
a
Function call argument is an uninitialized value
1217 XkbConfigText(tmpTOC.type,XkbMessage),0){ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
;
1218 break;
1219 }
1220 return NULL((void*)0);
1221}
1222
1223/***====================================================================***/
1224
1225#define MAX_TOC16 16
1226unsigned
1227XkmReadFile(FILE *file,unsigned need,unsigned want,XkbFileInfo *result)
1228{
1229register unsigned i;
1230xkmSectionInfo toc[MAX_TOC16],tmpTOC;
1231xkmFileInfo fileInfo;
1232unsigned tmp,nRead=0;
1233unsigned which= need|want;
1234
1235 if (!XkmReadTOC(file,&fileInfo,MAX_TOC16,toc))
1236 return which;
1237 if ((fileInfo.present&need)!=need) {
1238 _XkbLibError(_XkbErrIllegalContents,"XkmReadFile",{ _XkbErrCode= (12); _XkbErrLocation= ("XkmReadFile"); _XkbErrData
= (need&(~fileInfo.present)); }
1239 need&(~fileInfo.present)){ _XkbErrCode= (12); _XkbErrLocation= ("XkmReadFile"); _XkbErrData
= (need&(~fileInfo.present)); }
;
1240 return which;
1241 }
1242 result->type= fileInfo.type;
1243 if (result->xkb==NULL((void*)0))
1244 result->xkb= XkbAllocKeyboard();
1245 for (i=0;i<fileInfo.num_toc;i++) {
1246#ifdef SEEK_SET0
1247 fseek(file,toc[i].offset,SEEK_SET0);
1248#else
1249 fseek(file,toc[i].offset,0);
1250#endif
1251 tmp= fread(&tmpTOC,SIZEOF(xkmSectionInfo)8,1,file);
1252 nRead= tmp*SIZEOF(xkmSectionInfo)8;
1253 if ((tmpTOC.type!=toc[i].type)||(tmpTOC.format!=toc[i].format)||
1254 (tmpTOC.size!=toc[i].size)||(tmpTOC.offset!=toc[i].offset)) {
1255 return which;
1256 }
1257 if ((which&(1<<tmpTOC.type))==0) {
1258 continue;
1259 }
1260 switch (tmpTOC.type) {
1261 case XkmVirtualModsIndex6:
1262 tmp= ReadXkmVirtualMods(file,result,NULL((void*)0));
1263 break;
1264 case XkmTypesIndex0:
1265 tmp= ReadXkmKeyTypes(file,result,NULL((void*)0));
1266 break;
1267 case XkmCompatMapIndex1:
1268 tmp= ReadXkmCompatMap(file,result,NULL((void*)0));
1269 break;
1270 case XkmKeyNamesIndex4:
1271 tmp= ReadXkmKeycodes(file,result,NULL((void*)0));
1272 break;
1273 case XkmIndicatorsIndex3:
1274 tmp= ReadXkmIndicators(file,result,NULL((void*)0));
1275 break;
1276 case XkmSymbolsIndex2:
1277 tmp= ReadXkmSymbols(file,result);
1278 break;
1279 case XkmGeometryIndex5:
1280 tmp= ReadXkmGeometry(file,result);
1281 break;
1282 default:
1283 _XkbLibError(_XkbErrBadImplementation,{ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
1284 XkbConfigText(tmpTOC.type,XkbMessage),0){ _XkbErrCode= (26); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (0); }
;
1285 tmp= 0;
1286 break;
1287 }
1288 if (tmp>0) {
1289 nRead+= tmp;
1290 which&= ~(1<<toc[i].type);
1291 result->defined|= (1<<toc[i].type);
1292 }
1293 if (nRead!=tmpTOC.size) {
1294 _XkbLibError(_XkbErrBadLength,XkbConfigText(tmpTOC.type,XkbMessage),{ _XkbErrCode= (24); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (nRead-tmpTOC.size); }
1295 nRead-tmpTOC.size){ _XkbErrCode= (24); _XkbErrLocation= (XkbConfigText(tmpTOC.type
,3)); _XkbErrData= (nRead-tmpTOC.size); }
;
1296 }
1297 }
1298 return which;
1299}