1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
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.
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.
25 ********************************************************/
31 #include "parseutils.h"
33 #include <X11/keysym.h>
43 extern uint32_t tok_ONE_LEVEL;
44 extern uint32_t tok_TWO_LEVEL;
45 extern uint32_t tok_KEYPAD;
47 /***====================================================================***/
51 #define RepeatUndefined ~((unsigned)0)
53 #define _Key_Syms (1<<0)
54 #define _Key_Acts (1<<1)
55 #define _Key_Repeat (1<<2)
56 #define _Key_Behavior (1<<3)
57 #define _Key_Type_Dflt (1<<4)
58 #define _Key_Types (1<<5)
59 #define _Key_GroupInfo (1<<6)
60 #define _Key_VModMap (1<<7)
62 typedef struct _KeyInfo
65 unsigned long name; /* the 4 chars of the key name, as long */
66 unsigned char groupInfo;
67 unsigned char typesDefined;
68 unsigned char symsDefined;
69 unsigned char actsDefined;
70 short numLevels[XkbNumKbdGroups];
71 uint32_t *syms[XkbNumKbdGroups];
72 union xkb_action *acts[XkbNumKbdGroups];
73 uint32_t types[XkbNumKbdGroups];
75 struct xkb_behavior behavior;
76 unsigned short vmodmap;
77 unsigned long nameForOverlayKey;
78 unsigned long allowNone;
83 * Init the given key info to sane values.
86 InitKeyInfo(KeyInfo * info)
89 static char dflt[4] = "*";
91 info->defs.defined = 0;
92 info->defs.fileID = 0;
93 info->defs.merge = MergeOverride;
94 info->defs.next = NULL;
95 info->name = KeyNameToLong(dflt);
97 info->typesDefined = info->symsDefined = info->actsDefined = 0;
98 for (i = 0; i < XkbNumKbdGroups; i++)
100 info->numLevels[i] = 0;
101 info->types[i] = None;
102 info->syms[i] = NULL;
103 info->acts[i] = NULL;
105 info->dfltType = None;
106 info->behavior.type = XkbKB_Default;
107 info->behavior.data = 0;
109 info->nameForOverlayKey = 0;
110 info->repeat = RepeatUndefined;
116 * Free memory associated with this key info and reset to sane values.
119 FreeKeyInfo(KeyInfo * info)
123 info->defs.defined = 0;
124 info->defs.fileID = 0;
125 info->defs.merge = MergeOverride;
126 info->defs.next = NULL;
128 info->typesDefined = info->symsDefined = info->actsDefined = 0;
129 for (i = 0; i < XkbNumKbdGroups; i++)
131 info->numLevels[i] = 0;
132 info->types[i] = None;
133 if (info->syms[i] != NULL)
135 info->syms[i] = NULL;
136 if (info->acts[i] != NULL)
138 info->acts[i] = NULL;
140 info->dfltType = None;
141 info->behavior.type = XkbKB_Default;
142 info->behavior.data = 0;
144 info->nameForOverlayKey = 0;
145 info->repeat = RepeatUndefined;
151 * Copy old into new, optionally reset old to 0.
152 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
153 * newly allocated and new points to the new memory areas.
156 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
161 new->defs.next = NULL;
164 for (i = 0; i < XkbNumKbdGroups; i++)
166 old->numLevels[i] = 0;
174 for (i = 0; i < XkbNumKbdGroups; i++)
176 width = new->numLevels[i];
177 if (old->syms[i] != NULL)
179 new->syms[i] = uTypedCalloc(width, uint32_t);
183 new->numLevels[i] = 0;
186 memcpy((char *) new->syms[i], (char *) old->syms[i],
187 width * sizeof(uint32_t));
189 if (old->acts[i] != NULL)
191 new->acts[i] = uTypedCalloc(width, union xkb_action);
197 memcpy((char *) new->acts[i], (char *) old->acts[i],
198 width * sizeof(union xkb_action));
205 /***====================================================================***/
207 typedef struct _ModMapEntry
214 unsigned long keyName;
219 #define SYMBOLS_INIT_SIZE 110
220 #define SYMBOLS_CHUNK 20
221 typedef struct _SymbolsInfo
223 char *name; /* e.g. pc+us+inet(evdev) */
227 unsigned explicit_group;
235 uint32_t groupNames[XkbNumKbdGroups];
242 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
246 tok_ONE_LEVEL = xkb_intern_atom("ONE_LEVEL");
247 tok_TWO_LEVEL = xkb_intern_atom("TWO_LEVEL");
248 tok_KEYPAD = xkb_intern_atom("KEYPAD");
250 info->explicit_group = 0;
251 info->errorCount = 0;
253 info->merge = MergeOverride;
255 info->szKeys = SYMBOLS_INIT_SIZE;
257 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
259 for (i = 0; i < XkbNumKbdGroups; i++)
260 info->groupNames[i] = None;
261 InitKeyInfo(&info->dflt);
262 InitVModInfo(&info->vmods, xkb);
264 info->aliases = NULL;
269 FreeSymbolsInfo(SymbolsInfo * info)
278 for (i = 0; i < info->nKeys; i++)
280 FreeKeyInfo(&info->keys[i]);
287 ClearCommonInfo(&info->modMap->defs);
292 ClearAliases(&info->aliases);
293 info->aliases = NULL;
295 bzero((char *) info, sizeof(SymbolsInfo));
300 ResizeKeyGroup(KeyInfo * key,
301 unsigned group, unsigned atLeastSize, Bool forceActions)
306 tooSmall = (key->numLevels[group] < atLeastSize);
308 newWidth = atLeastSize;
310 newWidth = key->numLevels[group];
312 if ((key->syms[group] == NULL) || tooSmall)
314 key->syms[group] = uTypedRecalloc(key->syms[group],
315 key->numLevels[group], newWidth,
317 if (!key->syms[group])
320 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
321 (tooSmall && (key->acts[group] != NULL)))
323 key->acts[group] = uTypedRecalloc(key->acts[group],
324 key->numLevels[group], newWidth,
326 if (!key->acts[group])
329 key->numLevels[group] = newWidth;
334 MergeKeyGroups(SymbolsInfo * info,
335 KeyInfo * into, KeyInfo * from, unsigned group)
337 uint32_t *resultSyms;
338 union xkb_action *resultActs;
341 Bool report, clobber;
343 clobber = (from->defs.merge != MergeAugment);
344 report = (warningLevel > 9) ||
345 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
346 if (into->numLevels[group] >= from->numLevels[group])
348 resultSyms = into->syms[group];
349 resultActs = into->acts[group];
350 resultWidth = into->numLevels[group];
354 resultSyms = from->syms[group];
355 resultActs = from->acts[group];
356 resultWidth = from->numLevels[group];
358 if (resultSyms == NULL)
360 resultSyms = uTypedCalloc(resultWidth, uint32_t);
363 WSGO("Could not allocate symbols for group merge\n");
364 ACTION("Group %d of key %s not merged\n", group,
365 longText(into->name));
369 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
371 resultActs = uTypedCalloc(resultWidth, union xkb_action);
374 WSGO("Could not allocate actions for group merge\n");
375 ACTION("Group %d of key %s not merged\n", group,
376 longText(into->name));
380 for (i = 0; i < resultWidth; i++)
382 uint32_t fromSym, toSym;
383 if (from->syms[group] && (i < from->numLevels[group]))
384 fromSym = from->syms[group][i];
387 if (into->syms[group] && (i < into->numLevels[group]))
388 toSym = into->syms[group][i];
391 if ((fromSym == NoSymbol) || (fromSym == toSym))
392 resultSyms[i] = toSym;
393 else if (toSym == NoSymbol)
394 resultSyms[i] = fromSym;
397 uint32_t use, ignore;
411 ("Multiple symbols for level %d/group %d on key %s\n",
412 i + 1, group + 1, longText(into->name));
413 ACTION("Using %s, ignoring %s\n",
414 XkbcKeysymText(use), XkbcKeysymText(ignore));
418 if (resultActs != NULL)
420 union xkb_action *fromAct, *toAct;
421 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
422 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
423 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
426 resultActs[i] = *toAct;
428 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
429 && (fromAct != NULL))
431 resultActs[i] = *fromAct;
435 union xkb_action *use, *ignore;
449 ("Multiple actions for level %d/group %d on key %s\n",
450 i + 1, group + 1, longText(into->name));
451 ACTION("Using %s, ignoring %s\n",
452 XkbcActionTypeText(use->type),
453 XkbcActionTypeText(ignore->type));
455 resultActs[i] = *use;
459 if ((into->syms[group] != NULL) && (resultSyms != into->syms[group]))
460 free(into->syms[group]);
461 if ((from->syms[group] != NULL) && (resultSyms != from->syms[group]))
462 free(from->syms[group]);
463 if ((into->acts[group] != NULL) && (resultActs != into->acts[group]))
464 free(into->acts[group]);
465 if ((from->acts[group] != NULL) && (resultActs != from->acts[group]))
466 free(from->acts[group]);
467 into->numLevels[group] = resultWidth;
468 into->syms[group] = resultSyms;
469 from->syms[group] = NULL;
470 into->acts[group] = resultActs;
471 from->acts[group] = NULL;
472 into->symsDefined |= (1 << group);
473 from->symsDefined &= ~(1 << group);
474 into->actsDefined |= (1 << group);
475 from->actsDefined &= ~(1 << group);
480 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
483 unsigned collide = 0;
486 if (from->defs.merge == MergeReplace)
488 for (i = 0; i < XkbNumKbdGroups; i++)
490 if (into->numLevels[i] != 0)
499 bzero(from, sizeof(KeyInfo));
502 report = ((warningLevel > 9) ||
503 ((into->defs.fileID == from->defs.fileID)
504 && (warningLevel > 0)));
505 for (i = 0; i < XkbNumKbdGroups; i++)
507 if (from->numLevels[i] > 0)
509 if (into->numLevels[i] == 0)
511 into->numLevels[i] = from->numLevels[i];
512 into->syms[i] = from->syms[i];
513 into->acts[i] = from->acts[i];
514 into->symsDefined |= (1 << i);
515 from->syms[i] = NULL;
516 from->acts[i] = NULL;
517 from->numLevels[i] = 0;
518 from->symsDefined &= ~(1 << i);
520 into->defs.defined |= _Key_Syms;
522 into->defs.defined |= _Key_Acts;
529 collide |= _Key_Syms;
531 collide |= _Key_Acts;
533 MergeKeyGroups(info, into, from, (unsigned) i);
536 if (from->types[i] != None)
538 if ((into->types[i] != None) && (report) &&
539 (into->types[i] != from->types[i]))
541 uint32_t use, ignore;
542 collide |= _Key_Types;
543 if (from->defs.merge != MergeAugment)
545 use = from->types[i];
546 ignore = into->types[i];
550 use = into->types[i];
551 ignore = from->types[i];
554 ("Multiple definitions for group %d type of key %s\n",
555 i, longText(into->name));
556 ACTION("Using %s, ignoring %s\n",
558 XkbcAtomText(ignore));
560 if ((from->defs.merge != MergeAugment)
561 || (into->types[i] == None))
563 into->types[i] = from->types[i];
567 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
569 into->behavior = from->behavior;
570 into->nameForOverlayKey = from->nameForOverlayKey;
571 into->defs.defined |= _Key_Behavior;
573 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
575 into->vmodmap = from->vmodmap;
576 into->defs.defined |= _Key_VModMap;
578 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
580 into->repeat = from->repeat;
581 into->defs.defined |= _Key_Repeat;
583 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
585 into->dfltType = from->dfltType;
586 into->defs.defined |= _Key_Type_Dflt;
588 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
590 into->groupInfo = from->groupInfo;
591 into->defs.defined |= _Key_GroupInfo;
595 WARN("Symbol map for key %s redefined\n",
596 longText(into->name));
597 ACTION("Using %s definition for conflicting fields\n",
598 (from->defs.merge == MergeAugment ? "first" : "last"));
604 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
607 unsigned long real_name;
609 for (i = 0; i < info->nKeys; i++)
611 if (info->keys[i].name == key->name)
612 return MergeKeys(info, &info->keys[i], key);
614 if (FindKeyNameForAlias(xkb, key->name, &real_name))
616 for (i = 0; i < info->nKeys; i++)
618 if (info->keys[i].name == real_name)
619 return MergeKeys(info, &info->keys[i], key);
622 if (info->nKeys >= info->szKeys)
624 info->szKeys += SYMBOLS_CHUNK;
626 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
629 WSGO("Could not allocate key symbols descriptions\n");
630 ACTION("Some key symbols definitions may be lost\n");
634 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
638 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
643 clobber = (new->defs.merge != MergeAugment);
644 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
646 if (new->haveSymbol && mm->haveSymbol
647 && (new->u.keySym == mm->u.keySym))
649 unsigned use, ignore;
650 if (mm->modifier != new->modifier)
655 ignore = mm->modifier;
660 ignore = new->modifier;
663 ("%s added to symbol map for multiple modifiers\n",
664 XkbcKeysymText(new->u.keySym));
665 ACTION("Using %s, ignoring %s.\n",
666 XkbcModIndexText(use),
667 XkbcModIndexText(ignore));
672 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
673 (new->u.keyName == mm->u.keyName))
675 unsigned use, ignore;
676 if (mm->modifier != new->modifier)
681 ignore = mm->modifier;
686 ignore = new->modifier;
688 ERROR("Key %s added to map for multiple modifiers\n",
689 longText(new->u.keyName));
690 ACTION("Using %s, ignoring %s.\n",
691 XkbcModIndexText(use),
692 XkbcModIndexText(ignore));
698 mm = uTypedAlloc(ModMapEntry);
701 WSGO("Could not allocate modifier map entry\n");
702 ACTION("Modifier map for %s will be incomplete\n",
703 XkbcModIndexText(new->modifier));
707 mm->defs.next = &info->modMap->defs;
712 /***====================================================================***/
715 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
716 unsigned merge, struct xkb_desc * xkb)
721 if (from->errorCount > 0)
723 into->errorCount += from->errorCount;
726 if (into->name == NULL)
728 into->name = from->name;
731 for (i = 0; i < XkbNumKbdGroups; i++)
733 if (from->groupNames[i] != None)
735 if ((merge != MergeAugment) || (into->groupNames[i] == None))
736 into->groupNames[i] = from->groupNames[i];
739 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
741 if (merge != MergeDefault)
742 key->defs.merge = merge;
743 if (!AddKeySymbols(into, key, xkb))
746 if (from->modMap != NULL)
748 ModMapEntry *mm, *next;
749 for (mm = from->modMap; mm != NULL; mm = next)
751 if (merge != MergeDefault)
752 mm->defs.merge = merge;
753 if (!AddModMapEntry(into, mm))
755 next = (ModMapEntry *) mm->defs.next;
760 if (!MergeAliases(&into->aliases, &from->aliases, merge))
765 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
766 struct xkb_desc * /* xkb */ ,
767 unsigned /* merge */ ,
768 SymbolsInfo * /* included */
772 HandleIncludeSymbols(IncludeStmt * stmt,
773 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
777 SymbolsInfo included;
781 if ((stmt->file == NULL) && (stmt->map == NULL))
785 bzero(info, sizeof(SymbolsInfo));
787 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
789 InitSymbolsInfo(&included, xkb);
790 included.fileID = included.dflt.defs.fileID = rtrn->id;
791 included.merge = included.dflt.defs.merge = MergeOverride;
794 included.explicit_group = atoi(stmt->modifier) - 1;
798 included.explicit_group = info->explicit_group;
800 (*hndlr) (rtrn, xkb, MergeOverride, &included);
801 if (stmt->stmt != NULL)
803 if (included.name != NULL)
805 included.name = stmt->stmt;
811 info->errorCount += 10;
814 if ((stmt->next != NULL) && (included.errorCount < 1))
818 SymbolsInfo next_incl;
820 for (next = stmt->next; next != NULL; next = next->next)
822 if ((next->file == NULL) && (next->map == NULL))
825 MergeIncludedSymbols(&included, info, next->merge, xkb);
826 FreeSymbolsInfo(info);
828 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
830 InitSymbolsInfo(&next_incl, xkb);
831 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
832 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
835 next_incl.explicit_group = atoi(next->modifier) - 1;
839 next_incl.explicit_group = info->explicit_group;
841 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
842 MergeIncludedSymbols(&included, &next_incl, op, xkb);
843 FreeSymbolsInfo(&next_incl);
847 info->errorCount += 10;
856 MergeIncludedSymbols(info, &included, newMerge, xkb);
857 FreeSymbolsInfo(&included);
859 return (info->errorCount == 0);
866 GetGroupIndex(KeyInfo * key,
867 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
877 if (arrayNdx == NULL)
882 defined = key->symsDefined;
884 defined = key->actsDefined;
886 for (i = 0; i < XkbNumKbdGroups; i++)
888 if ((defined & (1 << i)) == 0)
894 ERROR("Too many groups of %s for key %s (max %d)\n", name,
895 longText(key->name), XkbNumKbdGroups + 1);
896 ACTION("Ignoring %s defined for extra groups\n", name);
899 if (!ExprResolveGroup(arrayNdx, &tmp))
901 ERROR("Illegal group index for %s of key %s\n", name,
902 longText(key->name));
903 ACTION("Definition with non-integer array index ignored\n");
906 *ndx_rtrn = tmp.uval - 1;
911 AddSymbolsToKey(KeyInfo * key,
912 struct xkb_desc * xkb,
914 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
919 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
923 key->symsDefined |= (1 << ndx);
926 if (value->op != ExprKeysymList)
928 ERROR("Expected a list of symbols, found %s\n",
929 exprOpText(value->op));
930 ACTION("Ignoring symbols for group %d of %s\n", ndx,
931 longText(key->name));
934 if (key->syms[ndx] != NULL)
936 WSGO("Symbols for key %s, group %d already defined\n",
937 longText(key->name), ndx);
940 nSyms = value->value.list.nSyms;
941 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
942 (!ResizeKeyGroup(key, ndx, nSyms, False)))
944 WSGO("Could not resize group %d of key %s\n", ndx,
945 longText(key->name));
946 ACTION("Symbols lost\n");
949 key->symsDefined |= (1 << ndx);
950 for (i = 0; i < nSyms; i++) {
951 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
952 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
953 key->syms[ndx][i] = NoSymbol;
956 for (i = key->numLevels[ndx] - 1;
957 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
959 key->numLevels[ndx]--;
965 AddActionsToKey(KeyInfo * key,
966 struct xkb_desc * xkb,
968 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
973 struct xkb_any_action *toAct;
975 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
980 key->actsDefined |= (1 << ndx);
983 if (value->op != ExprActionList)
985 WSGO("Bad expression type (%d) for action list value\n", value->op);
986 ACTION("Ignoring actions for group %d of %s\n", ndx,
987 longText(key->name));
990 if (key->acts[ndx] != NULL)
992 WSGO("Actions for key %s, group %d already defined\n",
993 longText(key->name), ndx);
996 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
998 act = (ExprDef *) act->common.next;
1002 WSGO("Action list but not actions in AddActionsToKey\n");
1005 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1006 (!ResizeKeyGroup(key, ndx, nActs, True)))
1008 WSGO("Could not resize group %d of key %s\n", ndx,
1009 longText(key->name));
1010 ACTION("Actions lost\n");
1013 key->actsDefined |= (1 << ndx);
1015 toAct = (struct xkb_any_action *) key->acts[ndx];
1016 act = value->value.child;
1017 for (i = 0; i < nActs; i++, toAct++)
1019 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1021 ERROR("Illegal action definition for %s\n",
1022 longText(key->name));
1023 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1025 act = (ExprDef *) act->common.next;
1031 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1034 unsigned radio_groups = 0;
1036 if (arrayNdx == NULL)
1038 radio_groups = XkbAllRadioGroupsMask;
1042 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1044 ERROR("Illegal index in group name definition\n");
1045 ACTION("Definition with non-integer array index ignored\n");
1048 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1050 ERROR("Illegal radio group specified (must be 1..%d)\n",
1051 XkbMaxRadioGroups + 1);
1052 ACTION("Value of \"allow none\" for group %d ignored\n",
1056 radio_groups |= (1 << (tmp.uval - 1));
1058 if (!ExprResolveBoolean(value, &tmp))
1060 ERROR("Illegal \"allow none\" value for %s\n",
1061 longText(key->name));
1062 ACTION("Non-boolean value ignored\n");
1066 key->allowNone |= radio_groups;
1068 key->allowNone &= ~radio_groups;
1073 static LookupEntry lockingEntries[] = {
1074 {"true", XkbKB_Lock},
1075 {"yes", XkbKB_Lock},
1077 {"false", XkbKB_Default},
1078 {"no", XkbKB_Default},
1079 {"off", XkbKB_Default},
1080 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1084 static LookupEntry repeatEntries[] = {
1085 {"true", RepeatYes},
1088 {"false", RepeatNo},
1091 {"default", RepeatUndefined},
1096 SetSymbolsField(KeyInfo * key,
1097 struct xkb_desc * xkb,
1099 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1104 if (uStrCaseCmp(field, "type") == 0)
1107 if ((!ExprResolveString(value, &tmp))
1108 && (warningLevel > 0))
1110 WARN("The type field of a key symbol map must be a string\n");
1111 ACTION("Ignoring illegal type definition\n");
1113 if (arrayNdx == NULL)
1115 key->dfltType = xkb_intern_atom(tmp.str);
1116 key->defs.defined |= _Key_Type_Dflt;
1118 else if (!ExprResolveGroup(arrayNdx, &ndx))
1120 ERROR("Illegal group index for type of key %s\n",
1121 longText(key->name));
1122 ACTION("Definition with non-integer array index ignored\n");
1128 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1129 key->typesDefined |= (1 << (ndx.uval - 1));
1133 else if (uStrCaseCmp(field, "symbols") == 0)
1134 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1135 else if (uStrCaseCmp(field, "actions") == 0)
1136 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1137 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1138 (uStrCaseCmp(field, "virtualmods") == 0) ||
1139 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1141 ok = ExprResolveVModMask(value, &tmp, xkb);
1144 key->vmodmap = (tmp.uval >> 8);
1145 key->defs.defined |= _Key_VModMap;
1149 ERROR("Expected a virtual modifier mask, found %s\n",
1150 exprOpText(value->op));
1151 ACTION("Ignoring virtual modifiers definition for key %s\n",
1152 longText(key->name));
1155 else if ((uStrCaseCmp(field, "locking") == 0)
1156 || (uStrCaseCmp(field, "lock") == 0)
1157 || (uStrCaseCmp(field, "locks") == 0))
1159 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1161 key->behavior.type = tmp.uval;
1162 key->defs.defined |= _Key_Behavior;
1164 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1165 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1167 Bool permanent = False;
1168 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1170 if (ExprResolveString(value, &tmp)) {
1171 ok = (strcmp(tmp.str, "none") == 0);
1177 ok = ExprResolveInteger(value, &tmp);
1181 ERROR("Illegal radio group specification for %s\n",
1182 longText(key->name));
1183 ACTION("Non-integer radio group ignored\n");
1188 key->behavior.type = XkbKB_Default;
1189 key->behavior.data = 0;
1192 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1195 ("Radio group specification for %s out of range (1..32)\n",
1196 longText(key->name));
1197 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1200 key->behavior.type =
1201 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1202 key->behavior.data = tmp.uval - 1;
1203 if (key->allowNone & (1 << (tmp.uval - 1)))
1204 key->behavior.data |= XkbKB_RGAllowNone;
1205 key->defs.defined |= _Key_Behavior;
1207 else if (uStrCaseEqual(field, "allownone"))
1209 ok = SetAllowNone(key, arrayNdx, value);
1211 else if (uStrCasePrefix("overlay", field) ||
1212 uStrCasePrefix("permanentoverlay", field))
1214 Bool permanent = False;
1217 if (uStrCasePrefix("permanent", field))
1220 which = &field[sizeof("permanentoverlay") - 1];
1224 which = &field[sizeof("overlay") - 1];
1226 if (sscanf(which, "%d", &overlayNdx) == 1)
1228 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1230 ERROR("Illegal overlay %d specified for %s\n",
1231 overlayNdx, longText(key->name));
1232 ACTION("Ignored\n");
1236 else if (*which == '\0')
1238 else if (warningLevel > 0)
1240 ERROR("Illegal overlay \"%s\" specified for %s\n",
1241 which, longText(key->name));
1242 ACTION("Ignored\n");
1245 ok = ExprResolveKeyName(value, &tmp);
1248 ERROR("Illegal overlay key specification for %s\n",
1249 longText(key->name));
1250 ACTION("Overlay key must be specified by name\n");
1253 if (overlayNdx == 1)
1254 key->behavior.type = XkbKB_Overlay1;
1256 key->behavior.type = XkbKB_Overlay2;
1258 key->behavior.type |= XkbKB_Permanent;
1260 key->behavior.data = 0;
1261 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1262 key->defs.defined |= _Key_Behavior;
1264 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1265 (uStrCaseCmp(field, "repeats") == 0) ||
1266 (uStrCaseCmp(field, "repeat") == 0))
1268 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1271 ERROR("Illegal repeat setting for %s\n",
1272 longText(key->name));
1273 ACTION("Non-boolean repeat setting ignored\n");
1276 key->repeat = tmp.uval;
1277 key->defs.defined |= _Key_Repeat;
1279 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1280 (uStrCaseCmp(field, "wrapgroups") == 0))
1282 ok = ExprResolveBoolean(value, &tmp);
1285 ERROR("Illegal groupsWrap setting for %s\n",
1286 longText(key->name));
1287 ACTION("Non-boolean value ignored\n");
1291 key->groupInfo = XkbWrapIntoRange;
1293 key->groupInfo = XkbClampIntoRange;
1294 key->defs.defined |= _Key_GroupInfo;
1296 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1297 (uStrCaseCmp(field, "clampgroups") == 0))
1299 ok = ExprResolveBoolean(value, &tmp);
1302 ERROR("Illegal groupsClamp setting for %s\n",
1303 longText(key->name));
1304 ACTION("Non-boolean value ignored\n");
1308 key->groupInfo = XkbClampIntoRange;
1310 key->groupInfo = XkbWrapIntoRange;
1311 key->defs.defined |= _Key_GroupInfo;
1313 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1314 (uStrCaseCmp(field, "redirectgroups") == 0))
1316 if (!ExprResolveGroup(value, &tmp))
1318 ERROR("Illegal group index for redirect of key %s\n",
1319 longText(key->name));
1320 ACTION("Definition with non-integer group ignored\n");
1324 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1325 key->defs.defined |= _Key_GroupInfo;
1329 ERROR("Unknown field %s in a symbol interpretation\n", field);
1330 ACTION("Definition ignored\n");
1337 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1339 ExprResult tmp, name;
1341 if ((arrayNdx == NULL) && (warningLevel > 0))
1343 WARN("You must specify an index when specifying a group name\n");
1344 ACTION("Group name definition without array subscript ignored\n");
1347 if (!ExprResolveGroup(arrayNdx, &tmp))
1349 ERROR("Illegal index in group name definition\n");
1350 ACTION("Definition with non-integer array index ignored\n");
1353 if (!ExprResolveString(value, &name))
1355 ERROR("Group name must be a string\n");
1356 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1359 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1360 xkb_intern_atom(name.str);
1367 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1369 ExprResult elem, field, tmp;
1373 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1374 return 0; /* internal error, already reported */
1375 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1377 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1380 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1381 (uStrCaseCmp(field.str, "groupname") ==
1384 ret = SetGroupName(info, arrayNdx, stmt->value);
1386 else if ((elem.str == NULL)
1387 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1388 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1390 if (!ExprResolveBoolean(stmt->value, &tmp))
1392 ERROR("Illegal setting for global groupsWrap\n");
1393 ACTION("Non-boolean value ignored\n");
1398 info->groupInfo = XkbWrapIntoRange;
1400 info->groupInfo = XkbClampIntoRange;
1404 else if ((elem.str == NULL)
1405 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1406 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1408 if (!ExprResolveBoolean(stmt->value, &tmp))
1410 ERROR("Illegal setting for global groupsClamp\n");
1411 ACTION("Non-boolean value ignored\n");
1416 info->groupInfo = XkbClampIntoRange;
1418 info->groupInfo = XkbWrapIntoRange;
1422 else if ((elem.str == NULL)
1423 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1424 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1426 if (!ExprResolveGroup(stmt->value, &tmp))
1428 ERROR("Illegal group index for global groupsRedirect\n");
1429 ACTION("Definition with non-integer group ignored\n");
1433 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1438 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1440 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1443 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1453 HandleSymbolsBody(VarDef * def,
1454 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1457 ExprResult tmp, field;
1460 for (; def != NULL; def = (VarDef *) def->common.next)
1462 if ((def->name) && (def->name->type == ExprFieldRef))
1464 ok = HandleSymbolsVar(def, xkb, info);
1469 if (def->name == NULL)
1471 if ((def->value == NULL)
1472 || (def->value->op == ExprKeysymList))
1473 field.str = strdup("symbols");
1475 field.str = strdup("actions");
1480 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1483 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1492 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1494 unsigned group = info->explicit_group;
1499 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1502 WARN("For the map %s an explicit group specified\n", info->name);
1503 WARN("but key %s has more than one group defined\n",
1504 longText(key->name));
1505 ACTION("All groups except first one will be ignored\n");
1506 for (i = 1; i < XkbNumKbdGroups; i++)
1508 key->numLevels[i] = 0;
1509 if (key->syms[i] != NULL)
1511 key->syms[i] = (uint32_t *) NULL;
1512 if (key->acts[i] != NULL)
1514 key->acts[i] = (union xkb_action *) NULL;
1515 key->types[i] = (uint32_t) 0;
1518 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1520 key->numLevels[group] = key->numLevels[0];
1521 key->numLevels[0] = 0;
1522 key->syms[group] = key->syms[0];
1523 key->syms[0] = (uint32_t *) NULL;
1524 key->acts[group] = key->acts[0];
1525 key->acts[0] = (union xkb_action *) NULL;
1526 key->types[group] = key->types[0];
1527 key->types[0] = (uint32_t) 0;
1532 HandleSymbolsDef(SymbolsDef * stmt,
1533 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1538 CopyKeyInfo(&info->dflt, &key, False);
1539 key.defs.merge = stmt->merge;
1540 key.name = KeyNameToLong(stmt->keyName);
1541 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1547 if (!SetExplicitGroup(info, &key))
1553 if (!AddKeySymbols(info, &key, xkb))
1562 HandleModMapDef(ModMapDef * def,
1563 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1570 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1572 ERROR("Illegal modifier map definition\n");
1573 ACTION("Ignoring map for non-modifier \"%s\"\n",
1574 XkbcAtomText(def->modifier));
1578 tmp.modifier = rtrn.uval;
1579 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1581 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1583 tmp.haveSymbol = False;
1584 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1586 else if (ExprResolveKeySym(key, &rtrn))
1588 tmp.haveSymbol = True;
1589 tmp.u.keySym = rtrn.uval;
1593 ERROR("Modmap entries may contain only key names or keysyms\n");
1594 ACTION("Illegal definition for %s modifier ignored\n",
1595 XkbcModIndexText(tmp.modifier));
1599 ok = AddModMapEntry(info, &tmp) && ok;
1605 HandleSymbolsFile(XkbFile * file,
1606 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1610 info->name = _XkbDupString(file->name);
1614 switch (stmt->stmtType)
1617 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1621 case StmtSymbolsDef:
1622 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1626 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1630 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1634 ERROR("Interpretation files may not include other types\n");
1635 ACTION("Ignoring definition of symbol interpretation\n");
1638 case StmtKeycodeDef:
1639 ERROR("Interpretation files may not include other types\n");
1640 ACTION("Ignoring definition of key name\n");
1644 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1648 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1653 if (info->errorCount > 10)
1656 ERROR("Too many errors\n");
1658 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1666 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1669 register Bool gotOne;
1675 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1677 if (j < (int) XkbKeyNumSyms(xkb, i))
1680 if ((XkbKeySym(xkb, i, j) == sym))
1694 * Find the given name in the xkb->map->types and return its index.
1696 * @param name The atom to search for.
1697 * @param type_rtrn Set to the index of the name if found.
1699 * @return True if found, False otherwise.
1702 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1704 register unsigned n;
1706 if (xkb && xkb->map && xkb->map->types)
1708 for (n = 0; n < xkb->map->num_types; n++)
1710 if (xkb->map->types[n].name == (uint32_t) name)
1721 * Assign a type to the given sym and return the Atom for the type assigned.
1724 * - ONE_LEVEL for width 0/1
1725 * - ALPHABETIC for 2 shift levels, with lower/upercase
1726 * - KEYPAD for keypad keys.
1727 * - TWO_LEVEL for other 2 shift level keys.
1728 * and the same for four level keys.
1730 * @param width Number of sysms in syms.
1731 * @param syms The keysyms for the given key (must be size width).
1732 * @param typeNameRtrn Set to the Atom of the type name.
1734 * @returns True if a type could be found, False otherwise.
1737 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1741 if ((width == 1) || (width == 0))
1743 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1746 else if (width == 2)
1748 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1750 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1752 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1754 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1759 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1763 else if (width <= 4)
1765 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1766 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1768 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1770 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1772 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1773 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1775 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1776 /* XXX: why not set autoType here? */
1778 return ((width >= 0) && (width <= 4));
1782 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1783 * groups, and reduce to one group if all groups are identical anyway.
1786 PrepareKeyDef(KeyInfo * key)
1788 int i, j, width, defined, lastGroup;
1791 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1792 /* get highest group number */
1793 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1795 if (defined & (1 << i))
1803 /* If there are empty groups between non-empty ones fill them with data */
1804 /* from the first group. */
1805 /* We can make a wrong assumption here. But leaving gaps is worse. */
1806 for (i = lastGroup; i > 0; i--)
1808 if (defined & (1 << i))
1810 width = key->numLevels[0];
1811 if (key->typesDefined & 1)
1813 for (j = 0; j < width; j++)
1815 key->types[i] = key->types[0];
1817 key->typesDefined |= 1 << i;
1819 if ((key->actsDefined & 1) && key->acts[0])
1821 key->acts[i] = uTypedCalloc(width, union xkb_action);
1822 if (key->acts[i] == NULL)
1824 memcpy((void *) key->acts[i], (void *) key->acts[0],
1825 width * sizeof(union xkb_action));
1826 key->actsDefined |= 1 << i;
1828 if ((key->symsDefined & 1) && key->syms[0])
1830 key->syms[i] = uTypedCalloc(width, uint32_t);
1831 if (key->syms[i] == NULL)
1833 memcpy((void *) key->syms[i], (void *) key->syms[0],
1834 width * sizeof(uint32_t));
1835 key->symsDefined |= 1 << i;
1839 key->numLevels[i] = key->numLevels[0];
1842 /* If all groups are completely identical remove them all */
1843 /* exept the first one. */
1845 for (i = lastGroup; i > 0; i--)
1847 if ((key->numLevels[i] != key->numLevels[0]) ||
1848 (key->types[i] != key->types[0]))
1853 if ((key->syms[i] != key->syms[0]) &&
1854 (key->syms[i] == NULL || key->syms[0] == NULL ||
1855 memcmp((void *) key->syms[i], (void *) key->syms[0],
1856 sizeof(uint32_t) * key->numLevels[0])))
1861 if ((key->acts[i] != key->acts[0]) &&
1862 (key->acts[i] == NULL || key->acts[0] == NULL ||
1863 memcmp((void *) key->acts[i], (void *) key->acts[0],
1864 sizeof(union xkb_action) * key->numLevels[0])))
1872 for (i = lastGroup; i > 0; i--)
1874 key->numLevels[i] = 0;
1875 if (key->syms[i] != NULL)
1877 key->syms[i] = (uint32_t *) NULL;
1878 if (key->acts[i] != NULL)
1880 key->acts[i] = (union xkb_action *) NULL;
1881 key->types[i] = (uint32_t) 0;
1883 key->symsDefined &= 1;
1884 key->actsDefined &= 1;
1885 key->typesDefined &= 1;
1891 * Copy the KeyInfo into the keyboard description.
1893 * This function recurses.
1896 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1899 xkb_keycode_t okc, kc;
1900 unsigned width, tmp, nGroups;
1901 struct xkb_key_type * type;
1902 Bool haveActions, autoType, useAlias;
1904 union xkb_action *outActs;
1905 unsigned types[XkbNumKbdGroups];
1907 useAlias = (start_from == 0);
1909 /* get the keycode for the key. */
1910 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1913 if ((start_from == 0) && (warningLevel >= 5))
1915 WARN("Key %s not found in %s keycodes\n",
1916 longText(key->name),
1917 XkbcAtomText(xkb->names->keycodes));
1918 ACTION("Symbols ignored\n");
1923 haveActions = False;
1924 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1926 if (((i + 1) > nGroups)
1927 && (((key->symsDefined | key->actsDefined) & (1 << i))
1928 || (key->typesDefined) & (1 << i)))
1933 /* Assign the type to the key, if it is missing. */
1934 if (key->types[i] == None)
1936 if (key->dfltType != None)
1937 key->types[i] = key->dfltType;
1938 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1939 &key->types[i], &autoType))
1944 if (warningLevel >= 5)
1946 WARN("No automatic type for %d symbols\n",
1947 (unsigned int) key->numLevels[i]);
1948 ACTION("Using %s for the %s key (keycode %d)\n",
1949 XkbcAtomText(key->types[i]),
1950 longText(key->name), kc);
1954 if (FindNamedType(xkb, key->types[i], &types[i]))
1956 if (!autoType || key->numLevels[i] > 2)
1957 xkb->server->explicit[kc] |= (1 << i);
1961 if (warningLevel >= 3)
1963 WARN("Type \"%s\" is not defined\n",
1964 XkbcAtomText(key->types[i]));
1965 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1966 longText(key->name), kc);
1968 types[i] = XkbTwoLevelIndex;
1970 /* if the type specifies less syms than the key has, shrink the key */
1971 type = &xkb->map->types[types[i]];
1972 if (type->num_levels < key->numLevels[i])
1974 if (warningLevel > 0)
1977 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1978 XkbcAtomText(type->name),
1979 (unsigned int) type->num_levels,
1980 longText(key->name),
1981 (unsigned int) key->numLevels[i]);
1982 ACTION("Ignoring extra symbols\n");
1984 key->numLevels[i] = type->num_levels;
1986 if (key->numLevels[i] > width)
1987 width = key->numLevels[i];
1988 if (type->num_levels > width)
1989 width = type->num_levels;
1992 /* width is now the largest width found */
1994 i = width * nGroups;
1995 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1996 if (outSyms == NULL)
1998 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1999 longText(key->name), kc);
2004 outActs = XkbcResizeKeyActions(xkb, kc, i);
2005 if (outActs == NULL)
2007 WSGO("Could not enlarge actions for %s (key %d)\n",
2008 longText(key->name), kc);
2011 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2015 if (key->defs.defined & _Key_GroupInfo)
2018 i = xkb->map->key_sym_map[kc].group_info;
2020 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2021 xkb->map->key_sym_map[kc].width = width;
2022 for (i = 0; i < nGroups; i++)
2024 /* assign kt_index[i] to the index of the type in map->types.
2025 * kt_index[i] may have been set by a previous run (if we have two
2026 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2027 * default group if we dont even have keys for this group anyway.
2029 * FIXME: There should be a better fix for this.
2031 if (key->numLevels[i])
2032 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2033 if (key->syms[i] != NULL)
2035 /* fill key to "width" symbols*/
2036 for (tmp = 0; tmp < width; tmp++)
2038 if (tmp < key->numLevels[i])
2039 outSyms[tmp] = key->syms[i][tmp];
2041 outSyms[tmp] = NoSymbol;
2042 if ((outActs != NULL) && (key->acts[i] != NULL))
2044 if (tmp < key->numLevels[i])
2045 outActs[tmp] = key->acts[i][tmp];
2047 outActs[tmp].type = XkbSA_NoAction;
2055 switch (key->behavior.type & XkbKB_OpMask)
2059 case XkbKB_Overlay1:
2060 case XkbKB_Overlay2:
2061 /* find key by name! */
2062 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2063 CreateKeyNames(xkb), 0))
2065 if (warningLevel >= 1)
2067 WARN("Key %s not found in %s keycodes\n",
2068 longText(key->nameForOverlayKey),
2069 XkbcAtomText(xkb->names->keycodes));
2070 ACTION("Not treating %s as an overlay key \n",
2071 longText(key->name));
2075 key->behavior.data = okc;
2077 xkb->server->behaviors[kc] = key->behavior;
2078 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2081 if (key->defs.defined & _Key_VModMap)
2083 xkb->server->vmodmap[kc] = key->vmodmap;
2084 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2086 if (key->repeat != RepeatUndefined)
2088 if (key->repeat == RepeatYes)
2089 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2091 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2092 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2095 if (nGroups > xkb->ctrls->num_groups)
2096 xkb->ctrls->num_groups = nGroups;
2098 /* do the same thing for the next key */
2099 CopySymbolsDef(xkb, key, kc + 1);
2104 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2108 if ((!entry->haveSymbol)
2111 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2113 if (warningLevel >= 5)
2115 WARN("Key %s not found in %s keycodes\n",
2116 longText(entry->u.keyName),
2117 XkbcAtomText(xkb->names->keycodes));
2118 ACTION("Modifier map entry for %s not updated\n",
2119 XkbcModIndexText(entry->modifier));
2123 else if (entry->haveSymbol
2124 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2126 if (warningLevel > 5)
2128 WARN("Key \"%s\" not found in %s symbol map\n",
2129 XkbcKeysymText(entry->u.keySym),
2130 XkbcAtomText(xkb->names->symbols));
2131 ACTION("Modifier map entry for %s not updated\n",
2132 XkbcModIndexText(entry->modifier));
2136 xkb->map->modmap[kc] |= (1 << entry->modifier);
2141 * Handle the xkb_symbols section of an xkb file.
2143 * @param file The parsed xkb_symbols section of the xkb file.
2144 * @param xkb Handle to the keyboard description to store the symbols in.
2145 * @param merge Merge strategy (e.g. MergeOverride).
2148 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2153 InitSymbolsInfo(&info, xkb);
2154 info.dflt.defs.fileID = file->id;
2155 info.dflt.defs.merge = merge;
2156 HandleSymbolsFile(file, xkb, merge, &info);
2158 if (info.nKeys == 0) {
2159 FreeSymbolsInfo(&info);
2163 if (info.errorCount == 0)
2167 /* alloc memory in the xkb struct */
2168 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2171 WSGO("Can not allocate names in CompileSymbols\n");
2172 ACTION("Symbols not added\n");
2175 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2178 WSGO("Could not allocate client map in CompileSymbols\n");
2179 ACTION("Symbols not added\n");
2182 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2184 WSGO("Could not allocate server map in CompileSymbols\n");
2185 ACTION("Symbols not added\n");
2188 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2190 WSGO("Could not allocate controls in CompileSymbols\n");
2191 ACTION("Symbols not added\n");
2195 /* now copy info into xkb. */
2196 xkb->names->symbols = xkb_intern_atom(info.name);
2198 ApplyAliases(xkb, False, &info.aliases);
2199 for (i = 0; i < XkbNumKbdGroups; i++)
2201 if (info.groupNames[i] != None)
2202 xkb->names->groups[i] = info.groupNames[i];
2205 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2210 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2212 if (!CopySymbolsDef(xkb, key, 0))
2215 if (warningLevel > 3)
2217 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2219 if (xkb->names->keys[i].name[0] == '\0')
2221 if (XkbKeyNumGroups(xkb, i) < 1)
2224 memcpy(buf, xkb->names->keys[i].name, 4);
2227 ("No symbols defined for <%s> (keycode %d)\n",
2234 ModMapEntry *mm, *next;
2235 for (mm = info.modMap; mm != NULL; mm = next)
2237 if (!CopyModMapDef(xkb, mm))
2239 next = (ModMapEntry *) mm->defs.next;
2242 FreeSymbolsInfo(&info);
2246 FreeSymbolsInfo(&info);