Bug Summary

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