Bug Summary

File:xkbmisc.c
Location:line 357, column 6
Description:Value stored to 'wantNames' is never read

Annotated Source Code

1/************************************************************
2 Copyright (c) 1995 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#include <ctype.h>
35#include <stdlib.h>
36
37#include <X11/Xos.h>
38#include <X11/Xfuncs.h>
39
40#ifndef XKB_IN_SERVER
41
42#include <X11/Xlib.h>
43#include <X11/keysym.h>
44#include <X11/XKBlib.h>
45#include <X11/extensions/XKBgeom.h>
46#include "XKMformat.h"
47#include "XKBfileInt.h"
48
49#else
50
51#include <X11/X.h>
52#include <X11/keysym.h>
53#include <X11/Xproto.h>
54#include "misc.h"
55#include "inputstr.h"
56#include "dix.h"
57#include <X11/extensions/XKBstr.h>
58#define XKBSRV_NEED_FILE_FUNCS 1
59#include <X11/extensions/XKBsrv.h>
60#include <X11/extensions/XKBgeom.h>
61#include "xkb.h"
62
63#endif
64
65unsigned
66_XkbKSCheckCase(KeySym ks)
67{
68unsigned set,rtrn;
69
70 set= (ks & (~0xff)) >> 8;
71 rtrn= 0;
72 switch (set) {
73 case 0: /* latin 1 */
74 if (((ks>=XK_A0x0041)&&(ks<=XK_Z0x005a))||
75 ((ks>=XK_Agrave0x00c0)&&(ks<=XK_THORN0x00de)&&(ks!=XK_multiply0x00d7))) {
76 rtrn|= _XkbKSUpper(1<<1);
77 }
78 if (((ks>=XK_a0x0061)&&(ks<=XK_z0x007a))||
79 ((ks>=XK_agrave0x00e0)&&(ks<=XK_ydiaeresis0x00ff))) {
80 rtrn|= _XkbKSLower(1<<0);
81 }
82 break;
83 case 1: /* latin 2 */
84 if (((ks>=XK_Aogonek0x01a1)&&(ks<=XK_Zabovedot0x01af)&&(ks!=XK_breve0x01a2))||
85 ((ks>=XK_Racute0x01c0)&&(ks<=XK_Tcedilla0x01de))) {
86 rtrn|= _XkbKSUpper(1<<1);
87 }
88 if (((ks>=XK_aogonek0x01b1)&&(ks<=XK_zabovedot0x01bf)&&(ks!=XK_caron0x01b7))||
89 ((ks>=XK_racute0x01e0)&&(ks<=XK_tcedilla0x01fe))) {
90 rtrn|= _XkbKSLower(1<<0);
91 }
92 break;
93 case 2: /* latin 3 */
94 if (((ks>=XK_Hstroke0x02a1)&&(ks<=XK_Jcircumflex0x02ac))||
95 ((ks>=XK_Cabovedot0x02c5)&&(ks<=XK_Scircumflex0x02de))) {
96 rtrn|= _XkbKSUpper(1<<1);
97 }
98 if (((ks>=XK_hstroke0x02b1)&&(ks<=XK_jcircumflex0x02bc))||
99 ((ks>=XK_cabovedot0x02e5)&&(ks<=XK_scircumflex0x02fe))) {
100 rtrn|= _XkbKSLower(1<<0);
101 }
102 break;
103 case 3: /* latin 4 */
104 if (((ks>=XK_Rcedilla0x03a3)&&(ks<=XK_Tslash0x03ac))||
105 (ks==XK_ENG0x03bd)||
106 ((ks>=XK_Amacron0x03c0)&&(ks<=XK_Umacron0x03de))) {
107 rtrn|= _XkbKSUpper(1<<1);
108 }
109 if (((ks>=XK_rcedilla0x03b3)&&(ks<=XK_tslash0x03bc))||
110 (ks==XK_eng0x03bf)||
111 ((ks>=XK_amacron0x03e0)&&(ks<=XK_umacron0x03fe))) {
112 rtrn|= _XkbKSLower(1<<0);
113 }
114 break;
115 case 18: /* latin 8 */
116 if ((ks==XK_Babovedot0x1001e02)||
117 ((ks>=XK_Dabovedot0x1001e0a)&&(ks<=XK_Wacute0x1001e82))||
118 ((ks>=XK_Ygrave0x1001ef2)&&(ks<=XK_Fabovedot0x1001e1e))||
119 (ks==XK_Mabovedot0x1001e40)||
120 (ks==XK_Pabovedot0x1001e56)||
121 (ks==XK_Sabovedot0x1001e60)||
122 (ks==XK_Wdiaeresis0x1001e84)||
123 ((ks>=XK_Wcircumflex0x1000174)&&(ks<=XK_Ycircumflex0x1000176))) {
124 rtrn|= _XkbKSUpper(1<<1);
125 }
126 if ((ks==XK_babovedot0x1001e03)||
127 (ks==XK_dabovedot0x1001e0b)||
128 (ks==XK_fabovedot0x1001e1f)||
129 (ks==XK_mabovedot0x1001e41)||
130 ((ks>=XK_wgrave0x1001e81)&&(ks<=XK_wacute0x1001e83))||
131 (ks==XK_ygrave0x1001ef3)||
132 ((ks>=XK_wdiaeresis0x1001e85)&&(ks<=XK_ycircumflex0x1000177))) {
133 rtrn|= _XkbKSLower(1<<0);
134 }
135 break;
136 case 19: /* latin 9 */
137 if ((ks==XK_OE0x13bc)||(ks==XK_Ydiaeresis0x13be)) {
138 rtrn|= _XkbKSUpper(1<<1);
139 }
140 if (ks==XK_oe0x13bd) {
141 rtrn|= _XkbKSLower(1<<0);
142 }
143 break;
144 }
145 return rtrn;
146}
147
148/***===================================================================***/
149
150Boolint
151XkbLookupGroupAndLevel( XkbDescPtr xkb,
152 int key,
153 int * mods_inout,
154 int * grp_inout,
155 int * lvl_rtrn)
156{
157int nG,eG;
158
159 if ((!xkb)||(!XkbKeycodeInRange(xkb,key)(((key)>=(xkb)->min_key_code)&& ((key)<=(xkb
)->max_key_code))
)||(!grp_inout))
160 return False0;
161
162 nG= XkbKeyNumGroups(xkb,key)((((((xkb)->map)->key_sym_map[(key)].group_info)&0x0f
)))
;
163 eG= *grp_inout;
164
165 if ( nG==0 ) {
166 *grp_inout= 0;
167 if (lvl_rtrn!=NULL((void*)0))
168 *lvl_rtrn= 0;
169 return False0;
170 }
171 else if ( nG==1 ) {
172 eG= 0;
173 }
174 else if ( eG>=nG ) {
175 unsigned gI= XkbKeyGroupInfo(xkb,key)((((xkb)->map)->key_sym_map[(key)].group_info));
176 switch (XkbOutOfRangeGroupAction(gI)((gI)&0xc0)) {
177 default:
178 eG %= nG;
179 break;
180 case XkbClampIntoRange(0x40):
181 eG = nG-1;
182 break;
183 case XkbRedirectIntoRange(0x80):
184 eG = XkbOutOfRangeGroupNumber(gI)(((gI)&0x30)>>4);
185 if (eG>=nG)
186 eG= 0;
187 break;
188 }
189 }
190 *grp_inout= eG;
191 if (mods_inout!=NULL((void*)0)) {
192 XkbKeyTypePtr type;
193 int preserve;
194
195 type = XkbKeyKeyType(xkb,key,eG)((&((xkb)->map)->types[(((xkb)->map)->key_sym_map
[key].kt_index[eG&0x3])]))
;
196 if (lvl_rtrn!=NULL((void*)0))
197 *lvl_rtrn= 0;
198 preserve= 0;
199 if (type->map) { /* find the shift level */
200 register int i;
201 register XkbKTMapEntryPtr entry;
202 for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
203 if ((entry->active)&&
204 (((*mods_inout)&type->mods.mask)==entry->mods.mask)){
205 if (lvl_rtrn!=NULL((void*)0))
206 *lvl_rtrn= entry->level;
207 if (type->preserve)
208 preserve= type->preserve[i].mask;
209 break;
210 }
211 }
212 }
213 (*mods_inout)&= ~(type->mods.mask&(~preserve));
214 }
215 return True1;
216}
217
218/***===================================================================***/
219
220static Boolint
221XkbWriteSectionFromName(FILE *file, const char *sectionName, const char *name)
222{
223 fprintf(file," xkb_%-20s { include \"%s\" };\n",sectionName,name);
224 return True1;
225}
226
227#define NEED_DESC(n)((!n)||((n)[0]=='+')||((n)[0]=='|')||(strchr((n),'%'))) ((!n)||((n)[0]=='+')||((n)[0]=='|')||(strchr((n),'%')))
228#define COMPLETE(n)((n)&&(!((!n)||((n)[0]=='+')||((n)[0]=='|')||(strchr(
(n),'%')))))
((n)&&(!NEED_DESC(n)((!n)||((n)[0]=='+')||((n)[0]=='|')||(strchr((n),'%')))))
229
230/* ARGSUSED */
231static void
232_AddIncl( FILE * file,
233 XkbFileInfo * result,
234 Boolint topLevel,
235 Boolint showImplicit,
236 int index,
237 void * priv)
238{
239 if ((priv)&&(strcmp((char *)priv,"%")!=0))
240 fprintf(file," include \"%s\"\n",(char *)priv);
241 return;
242}
243
244Boolint
245XkbWriteXKBKeymapForNames( FILE * file,
246 XkbComponentNamesPtr names,
247 Display * dpy,
248 XkbDescPtr xkb,
249 unsigned want,
250 unsigned need)
251{
252char * name,*tmp;
253unsigned complete;
254XkbNamesPtr old_names;
255int multi_section;
256unsigned wantNames,wantConfig,wantDflts;
257XkbFileInfo finfo;
258
259 bzero(&finfo,sizeof(XkbFileInfo))memset(&finfo,0,sizeof(XkbFileInfo));
260
261 complete= 0;
262 if ((name=names->keymap)==NULL((void*)0)) name= "default";
263 if (COMPLETE(names->keycodes)((names->keycodes)&&(!((!names->keycodes)||((names
->keycodes)[0]=='+')||((names->keycodes)[0]=='|')||(strchr
((names->keycodes),'%')))))
) complete|= XkmKeyNamesMask(1<<4);
264 if (COMPLETE(names->types)((names->types)&&(!((!names->types)||((names->
types)[0]=='+')||((names->types)[0]=='|')||(strchr((names->
types),'%')))))
) complete|= XkmTypesMask(1<<0);
265 if (COMPLETE(names->compat)((names->compat)&&(!((!names->compat)||((names->
compat)[0]=='+')||((names->compat)[0]=='|')||(strchr((names
->compat),'%')))))
) complete|= XkmCompatMapMask(1<<1);
266 if (COMPLETE(names->symbols)((names->symbols)&&(!((!names->symbols)||((names
->symbols)[0]=='+')||((names->symbols)[0]=='|')||(strchr
((names->symbols),'%')))))
) complete|= XkmSymbolsMask(1<<2);
267 if (COMPLETE(names->geometry)((names->geometry)&&(!((!names->geometry)||((names
->geometry)[0]=='+')||((names->geometry)[0]=='|')||(strchr
((names->geometry),'%')))))
) complete|= XkmGeometryMask(1<<5);
268 want|= (complete|need);
269 if (want&XkmSymbolsMask(1<<2))
270 want|= XkmKeyNamesMask(1<<4)|XkmTypesMask(1<<0);
271
272 if (want==0)
273 return False0;
274
275 if (xkb!=NULL((void*)0)) {
276 old_names= xkb->names;
277 finfo.type= 0;
278 finfo.defined= 0;
279 finfo.xkb= xkb;
280 if (!XkbDetermineFileType(&finfo,XkbXKBFile2,NULL((void*)0)))
281 return False0;
282 }
283 else old_names= NULL((void*)0);
284
285 wantConfig= want&(~complete);
286 if (xkb!=NULL((void*)0)) {
287 if (wantConfig&XkmTypesMask(1<<0)) {
288 if ((!xkb->map) || (xkb->map->num_types<XkbNumRequiredTypes(3 +1)))
289 wantConfig&= ~XkmTypesMask(1<<0);
290 }
291 if (wantConfig&XkmCompatMapMask(1<<1)) {
292 if ((!xkb->compat) || (xkb->compat->num_si<1))
293 wantConfig&= ~XkmCompatMapMask(1<<1);
294 }
295 if (wantConfig&XkmSymbolsMask(1<<2)) {
296 if ((!xkb->map) || (!xkb->map->key_sym_map))
297 wantConfig&= ~XkmSymbolsMask(1<<2);
298 }
299 if (wantConfig&XkmIndicatorsMask(1<<3)) {
300 if (!xkb->indicators)
301 wantConfig&= ~XkmIndicatorsMask(1<<3);
302 }
303 if (wantConfig&XkmKeyNamesMask(1<<4)) {
304 if ((!xkb->names)||(!xkb->names->keys))
305 wantConfig&= ~XkmKeyNamesMask(1<<4);
306 }
307 if ((wantConfig&XkmGeometryMask(1<<5))&&(!xkb->geom))
308 wantConfig&= ~XkmGeometryMask(1<<5);
309 }
310 else {
311 wantConfig= 0;
312 }
313 complete|= wantConfig;
314
315 wantDflts= 0;
316 wantNames= want&(~complete);
317 if ((xkb!=NULL((void*)0)) && (old_names!=NULL((void*)0))) {
318 if (wantNames&XkmTypesMask(1<<0)) {
319 if (old_names->types!=None0L) {
320 tmp= XkbAtomGetString(dpy,old_names->types);
321 names->types= tmp;
322 }
323 else {
324 wantDflts|= XkmTypesMask(1<<0);
325 }
326 complete|= XkmTypesMask(1<<0);
327 }
328 if (wantNames&XkmCompatMapMask(1<<1)) {
329 if (old_names->compat!=None0L) {
330 tmp= XkbAtomGetString(dpy,old_names->compat);
331 names->compat= tmp;
332 }
333 else wantDflts|= XkmCompatMapMask(1<<1);
334 complete|= XkmCompatMapMask(1<<1);
335 }
336 if (wantNames&XkmSymbolsMask(1<<2)) {
337 if (old_names->symbols==None0L)
338 return False0;
339 tmp= XkbAtomGetString(dpy,old_names->symbols);
340 names->symbols= tmp;
341 complete|= XkmSymbolsMask(1<<2);
342 }
343 if (wantNames&XkmKeyNamesMask(1<<4)) {
344 if (old_names->keycodes!=None0L) {
345 tmp= XkbAtomGetString(dpy,old_names->keycodes);
346 names->keycodes= tmp;
347 }
348 else wantDflts|= XkmKeyNamesMask(1<<4);
349 complete|= XkmKeyNamesMask(1<<4);
350 }
351 if (wantNames&XkmGeometryMask(1<<5)) {
352 if (old_names->geometry==None0L)
353 return False0;
354 tmp= XkbAtomGetString(dpy,old_names->geometry);
355 names->geometry= tmp;
356 complete|= XkmGeometryMask(1<<5);
357 wantNames&= ~XkmGeometryMask(1<<5);
Value stored to 'wantNames' is never read
358 }
359 }
360 if (complete&XkmCompatMapMask(1<<1))
361 complete|= XkmIndicatorsMask(1<<3)|XkmVirtualModsMask(1<<6);
362 else if (complete&(XkmSymbolsMask(1<<2)|XkmTypesMask(1<<0)))
363 complete|= XkmVirtualModsMask(1<<6);
364 if (need & (~complete))
365 return False0;
366 if ((complete&XkmSymbolsMask(1<<2))&&((XkmKeyNamesMask(1<<4)|XkmTypesMask(1<<0))&(~complete)))
367 return False0;
368
369 multi_section= 1;
370 if (((complete&XkmKeymapRequired(((1<<1))|((1<<4)|(1<<2)|(1<<0))))==XkmKeymapRequired(((1<<1))|((1<<4)|(1<<2)|(1<<0))))&&
371 ((complete&(~XkmKeymapLegal((((1<<1))|((1<<4)|(1<<2)|(1<<0)))|((
((1<<0)|(1<<6)|(1<<3))|((1<<6)|(1<<
5)))&(~(((1<<1))|((1<<4)|(1<<2)|(1<<
0))))))
))==0)) {
372 fprintf(file,"xkb_keymap \"%s\" {\n",name);
373 }
374 else if (((complete&XkmSemanticsRequired((1<<1)))==XkmSemanticsRequired((1<<1)))&&
375 ((complete&(~XkmSemanticsLegal(((1<<1))|((1<<0)|(1<<6)|(1<<3)))))==0)) {
376 fprintf(file,"xkb_semantics \"%s\" {\n",name);
377 }
378 else if (((complete&XkmLayoutRequired((1<<4)|(1<<2)|(1<<0)))==XkmLayoutRequired((1<<4)|(1<<2)|(1<<0)))&&
379 ((complete&(~XkmLayoutLegal(((1<<4)|(1<<2)|(1<<0))|((1<<6)|(1<<
5)))
))==0)) {
380 fprintf(file,"xkb_layout \"%s\" {\n",name);
381 }
382 else if (XkmSingleSection(complete&(~XkmVirtualModsMask))((((complete&(~(1<<6)))&(~((((1<<1))|((1<<
4)|(1<<2)|(1<<0)))|((((1<<0)|(1<<6)|(
1<<3))|((1<<6)|(1<<5)))&(~(((1<<1
))|((1<<4)|(1<<2)|(1<<0))))))))==0)&&
(((complete&(~(1<<6)))&(~(complete&(~(1<<
6)))+1))==(complete&(~(1<<6)))))
) {
383 multi_section= 0;
384 }
385 else {
386 return False0;
387 }
388
389 wantNames= complete&(~(wantConfig|wantDflts));
390 name= names->keycodes;
391 if (wantConfig&XkmKeyNamesMask(1<<4))
392 XkbWriteXKBKeycodes(file,&finfo,False0,False0,_AddIncl,name);
393 else if (wantDflts&XkmKeyNamesMask(1<<4))
394 fprintf(stderrstderr,"Default symbols not implemented yet!\n");
395 else if (wantNames&XkmKeyNamesMask(1<<4))
396 XkbWriteSectionFromName(file,"keycodes",name);
397
398 name= names->types;
399 if (wantConfig&XkmTypesMask(1<<0))
400 XkbWriteXKBKeyTypes(file,&finfo,False0,False0,_AddIncl,name);
401 else if (wantDflts&XkmTypesMask(1<<0))
402 fprintf(stderrstderr,"Default types not implemented yet!\n");
403 else if (wantNames&XkmTypesMask(1<<0))
404 XkbWriteSectionFromName(file,"types",name);
405
406 name= names->compat;
407 if (wantConfig&XkmCompatMapMask(1<<1))
408 XkbWriteXKBCompatMap(file,&finfo,False0,False0,_AddIncl,name);
409 else if (wantDflts&XkmCompatMapMask(1<<1))
410 fprintf(stderrstderr,"Default interps not implemented yet!\n");
411 else if (wantNames&XkmCompatMapMask(1<<1))
412 XkbWriteSectionFromName(file,"compatibility",name);
413
414 name= names->symbols;
415 if (wantConfig&XkmSymbolsMask(1<<2))
416 XkbWriteXKBSymbols(file,&finfo,False0,False0,_AddIncl,name);
417 else if (wantNames&XkmSymbolsMask(1<<2))
418 XkbWriteSectionFromName(file,"symbols",name);
419
420 name= names->geometry;
421 if (wantConfig&XkmGeometryMask(1<<5))
422 XkbWriteXKBGeometry(file,&finfo,False0,False0,_AddIncl,name);
423 else if (wantNames&XkmGeometryMask(1<<5))
424 XkbWriteSectionFromName(file,"geometry",name);
425
426 if (multi_section)
427 fprintf(file,"};\n");
428 return True1;
429}
430
431/***====================================================================***/
432
433/*ARGSUSED*/
434Statusint
435XkbMergeFile(XkbDescPtr xkb,XkbFileInfo finfo)
436{
437 return BadImplementation17;
438}
439
440/***====================================================================***/
441
442int
443XkbFindKeycodeByName(XkbDescPtr xkb,char *name,Boolint use_aliases)
444{
445register int i;
446
447 if ((!xkb)||(!xkb->names)||(!xkb->names->keys))
448 return 0;
449 for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
450 if (strncmp(xkb->names->keys[i].name,name,XkbKeyNameLength4)==0)
451 return i;
452 }
453 if (!use_aliases)
454 return 0;
455 if (xkb->geom && xkb->geom->key_aliases) {
456 XkbKeyAliasPtr a;
457 a= xkb->geom->key_aliases;
458 for (i=0;i<xkb->geom->num_key_aliases;i++,a++) {
459 if (strncmp(name,a->alias,XkbKeyNameLength4)==0)
460 return XkbFindKeycodeByName(xkb,a->real,False0);
461 }
462 }
463 if (xkb->names && xkb->names->key_aliases) {
464 XkbKeyAliasPtr a;
465 a= xkb->names->key_aliases;
466 for (i=0;i<xkb->names->num_key_aliases;i++,a++) {
467 if (strncmp(name,a->alias,XkbKeyNameLength4)==0)
468 return XkbFindKeycodeByName(xkb,a->real,False0);
469 }
470 }
471 return 0;
472}
473
474
475unsigned
476XkbConvertGetByNameComponents(Boolint toXkm,unsigned orig)
477{
478unsigned rtrn;
479
480 rtrn= 0;
481 if (toXkm) {
482 if (orig&XkbGBN_TypesMask(1L << 0)) rtrn|= XkmTypesMask(1<<0);
483 if (orig&XkbGBN_CompatMapMask(1L << 1)) rtrn|= XkmCompatMapMask(1<<1);
484 if (orig&XkbGBN_SymbolsMask((1L << 2)|(1L << 3))) rtrn|= XkmSymbolsMask(1<<2);
485 if (orig&XkbGBN_IndicatorMapMask(1L << 4)) rtrn|= XkmIndicatorsMask(1<<3);
486 if (orig&XkbGBN_KeyNamesMask(1L << 5)) rtrn|= XkmKeyNamesMask(1<<4);
487 if (orig&XkbGBN_GeometryMask(1L << 6)) rtrn|= XkmGeometryMask(1<<5);
488 }
489 else {
490 if (orig&XkmTypesMask(1<<0)) rtrn|= XkbGBN_TypesMask(1L << 0);
491 if (orig&XkmCompatMapMask(1<<1)) rtrn|= XkbGBN_CompatMapMask(1L << 1);
492 if (orig&XkmSymbolsMask(1<<2)) rtrn|= XkbGBN_SymbolsMask((1L << 2)|(1L << 3));
493 if (orig&XkmIndicatorsMask(1<<3)) rtrn|= XkbGBN_IndicatorMapMask(1L << 4);
494 if (orig&XkmKeyNamesMask(1<<4)) rtrn|= XkbGBN_KeyNamesMask(1L << 5);
495 if (orig&XkmGeometryMask(1<<5)) rtrn|= XkbGBN_GeometryMask(1L << 6);
496 if (orig!=0) rtrn|= XkbGBN_OtherNamesMask(1L << 7);
497 }
498 return rtrn;
499}
500
501unsigned
502XkbConvertXkbComponents(Boolint toXkm,unsigned orig)
503{
504unsigned rtrn;
505
506 rtrn= 0;
507 if (toXkm) {
508 if (orig&XkbClientMapMask(1L << 0)) rtrn|= XkmTypesMask(1<<0)|XkmSymbolsMask(1<<2);
509 if (orig&XkbServerMapMask(1L << 1)) rtrn|= XkmTypesMask(1<<0)|XkmSymbolsMask(1<<2);
510 if (orig&XkbCompatMapMask(1L << 2)) rtrn|= XkmCompatMapMask(1<<1);
511 if (orig&XkbIndicatorMapMask(1L << 3)) rtrn|= XkmIndicatorsMask(1<<3);
512 if (orig&XkbNamesMask(1L << 4)) rtrn|= XkmKeyNamesMask(1<<4);
513 if (orig&XkbGeometryMask(1L << 5)) rtrn|= XkmGeometryMask(1<<5);
514 }
515 else {
516 if (orig!=0) rtrn|= XkbNamesMask(1L << 4);
517 if (orig&XkmTypesMask(1<<0)) rtrn|= XkbClientMapMask(1L << 0);
518 if (orig&XkmCompatMapMask(1<<1))
519 rtrn|= XkbCompatMapMask(1L << 2)|XkbIndicatorMapMask(1L << 3);
520 if (orig&XkmSymbolsMask(1<<2)) rtrn|=XkbClientMapMask(1L << 0)|XkbServerMapMask(1L << 1);
521 if (orig&XkmIndicatorsMask(1<<3)) rtrn|= XkbIndicatorMapMask(1L << 3);
522 if (orig&XkmKeyNamesMask(1<<4))
523 rtrn|= XkbNamesMask(1L << 4)|XkbIndicatorMapMask(1L << 3);
524 if (orig&XkmGeometryMask(1<<5)) rtrn|= XkbGeometryMask(1L << 5);
525 }
526 return rtrn;
527}
528
529Boolint
530XkbDetermineFileType(XkbFileInfoPtr finfo,int format,int *opts_missing)
531{
532unsigned present;
533XkbDescPtr xkb;
534
535 if ((!finfo)||(!finfo->xkb))
536 return False0;
537 if (opts_missing)
538 *opts_missing= 0;
539 xkb= finfo->xkb;
540 present= 0;
541 if ((xkb->names)&&(xkb->names->keys)) present|= XkmKeyNamesMask(1<<4);
542 if ((xkb->map)&&(xkb->map->types)) present|= XkmTypesMask(1<<0);
543 if (xkb->compat) present|= XkmCompatMapMask(1<<1);
544 if ((xkb->map)&&(xkb->map->num_syms>1)) present|= XkmSymbolsMask(1<<2);
545 if (xkb->indicators) present|= XkmIndicatorsMask(1<<3);
546 if (xkb->geom) present|= XkmGeometryMask(1<<5);
547 if (!present)
548 return False0;
549 else switch (present) {
550 case XkmKeyNamesMask(1<<4):
551 finfo->type= XkmKeyNamesIndex4;
552 finfo->defined= present;
553 return True1;
554 case XkmTypesMask(1<<0):
555 finfo->type= XkmTypesIndex0;
556 finfo->defined= present;
557 return True1;
558 case XkmCompatMapMask(1<<1):
559 finfo->type= XkmCompatMapIndex1;
560 finfo->defined= present;
561 return True1;
562 case XkmSymbolsMask(1<<2):
563 if (format!=XkbXKMFile0) {
564 finfo->type= XkmSymbolsIndex2;
565 finfo->defined= present;
566 return True1;
567 }
568 break;
569 case XkmGeometryMask(1<<5):
570 finfo->type= XkmGeometryIndex5;
571 finfo->defined= present;
572 return True1;
573 }
574 if ((present&(~XkmSemanticsLegal(((1<<1))|((1<<0)|(1<<6)|(1<<3)))))==0) {
575 if ((XkmSemanticsRequired((1<<1))&present)==XkmSemanticsRequired((1<<1))) {
576 if (opts_missing)
577 *opts_missing= XkmSemanticsOptional((1<<0)|(1<<6)|(1<<3))&(~present);
578 finfo->type= XkmSemanticsFile20;
579 finfo->defined= present;
580 return True1;
581 }
582 }
583 else if ((present&(~XkmLayoutLegal(((1<<4)|(1<<2)|(1<<0))|((1<<6)|(1<<
5)))
))==0) {
584 if ((XkmLayoutRequired((1<<4)|(1<<2)|(1<<0))&present)==XkmLayoutRequired((1<<4)|(1<<2)|(1<<0))) {
585 if (opts_missing)
586 *opts_missing= XkmLayoutOptional((1<<6)|(1<<5))&(~present);
587 finfo->type= XkmLayoutFile21;
588 finfo->defined= present;
589 return True1;
590 }
591 }
592 else if ((present&(~XkmKeymapLegal((((1<<1))|((1<<4)|(1<<2)|(1<<0)))|((
((1<<0)|(1<<6)|(1<<3))|((1<<6)|(1<<
5)))&(~(((1<<1))|((1<<4)|(1<<2)|(1<<
0))))))
))==0) {
593 if ((XkmKeymapRequired(((1<<1))|((1<<4)|(1<<2)|(1<<0)))&present)==XkmKeymapRequired(((1<<1))|((1<<4)|(1<<2)|(1<<0)))) {
594 if (opts_missing)
595 *opts_missing= XkmKeymapOptional((((1<<0)|(1<<6)|(1<<3))|((1<<6)|(1<<
5)))&(~(((1<<1))|((1<<4)|(1<<2)|(1<<
0)))))
&(~present);
596 finfo->type= XkmKeymapFile22;
597 finfo->defined= present;
598 return True1;
599 }
600 }
601 return False0;
602}
603
604/* all latin-1 alphanumerics, plus parens, slash, minus, underscore and */
605/* wildcards */
606
607static unsigned char componentSpecLegal[] = {
608 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
609 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
610 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
611 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
612};
613
614void
615XkbEnsureSafeMapName(char *name)
616{
617 if (name==NULL((void*)0))
618 return;
619 while (*name!='\0') {
620 if ((componentSpecLegal[(*name)/8]&(1<<((*name)%8)))==0)
621 *name= '_';
622 name++;
623 }
624 return;
625}
626
627/***====================================================================***/
628
629#define UNMATCHABLE(c)(((c)=='(')||((c)==')')||((c)=='/')) (((c)=='(')||((c)==')')||((c)=='/'))
630
631Boolint
632XkbNameMatchesPattern(char *name,char *ptrn)
633{
634 while (ptrn[0]!='\0') {
635 if (name[0]=='\0') {
636 if (ptrn[0]=='*') {
637 ptrn++;
638 continue;
639 }
640 return False0;
641 }
642 if (ptrn[0]=='?') {
643 if (UNMATCHABLE(name[0])(((name[0])=='(')||((name[0])==')')||((name[0])=='/')))
644 return False0;
645 }
646 else if (ptrn[0]=='*') {
647 if ((!UNMATCHABLE(name[0])(((name[0])=='(')||((name[0])==')')||((name[0])=='/')))&&XkbNameMatchesPattern(name+1,ptrn))
648 return True1;
649 return XkbNameMatchesPattern(name,ptrn+1);
650 }
651 else if (ptrn[0]!=name[0])
652 return False0;
653 name++;
654 ptrn++;
655 }
656 /* if we get here, the pattern is exhausted (-:just like me:-) */
657 return (name[0]=='\0');
658}
659
660#ifdef NEED_STRCASECMP
661_X_HIDDEN__attribute__((visibility("hidden"))) int
662_XkbStrCaseCmpstrcasecmp(char *str1,char *str2)
663{
664 const u_char *us1 = (const u_char *)str1, *us2 = (const u_char *)str2;
665
666 while (tolower(*us1) == tolower(*us2)) {
667 if (*us1++ == '\0')
668 return (0);
669 us2++;
670 }
671
672 return (tolower(*us1) - tolower(*us2));
673}
674#endif