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;
115 * Free memory associated with this key info and reset to sane values.
118 FreeKeyInfo(KeyInfo * info)
122 info->defs.defined = 0;
123 info->defs.fileID = 0;
124 info->defs.merge = MergeOverride;
125 info->defs.next = NULL;
127 info->typesDefined = info->symsDefined = info->actsDefined = 0;
128 for (i = 0; i < XkbNumKbdGroups; i++)
130 info->numLevels[i] = 0;
131 info->types[i] = None;
133 info->syms[i] = NULL;
135 info->acts[i] = NULL;
137 info->dfltType = None;
138 info->behavior.type = XkbKB_Default;
139 info->behavior.data = 0;
141 info->nameForOverlayKey = 0;
142 info->repeat = RepeatUndefined;
147 * Copy old into new, optionally reset old to 0.
148 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
149 * newly allocated and new points to the new memory areas.
152 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
157 new->defs.next = NULL;
160 for (i = 0; i < XkbNumKbdGroups; i++)
162 old->numLevels[i] = 0;
170 for (i = 0; i < XkbNumKbdGroups; i++)
172 width = new->numLevels[i];
173 if (old->syms[i] != NULL)
175 new->syms[i] = uTypedCalloc(width, uint32_t);
179 new->numLevels[i] = 0;
182 memcpy((char *) new->syms[i], (char *) old->syms[i],
183 width * sizeof(uint32_t));
185 if (old->acts[i] != NULL)
187 new->acts[i] = uTypedCalloc(width, union xkb_action);
193 memcpy((char *) new->acts[i], (char *) old->acts[i],
194 width * sizeof(union xkb_action));
201 /***====================================================================***/
203 typedef struct _ModMapEntry
210 unsigned long keyName;
215 #define SYMBOLS_INIT_SIZE 110
216 #define SYMBOLS_CHUNK 20
217 typedef struct _SymbolsInfo
219 char *name; /* e.g. pc+us+inet(evdev) */
223 unsigned explicit_group;
231 uint32_t groupNames[XkbNumKbdGroups];
238 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
242 tok_ONE_LEVEL = xkb_intern_atom("ONE_LEVEL");
243 tok_TWO_LEVEL = xkb_intern_atom("TWO_LEVEL");
244 tok_KEYPAD = xkb_intern_atom("KEYPAD");
246 info->explicit_group = 0;
247 info->errorCount = 0;
249 info->merge = MergeOverride;
251 info->szKeys = SYMBOLS_INIT_SIZE;
253 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
255 for (i = 0; i < XkbNumKbdGroups; i++)
256 info->groupNames[i] = None;
257 InitKeyInfo(&info->dflt);
258 InitVModInfo(&info->vmods, xkb);
260 info->aliases = NULL;
264 FreeSymbolsInfo(SymbolsInfo * info)
271 for (i = 0; i < info->nKeys; i++)
272 FreeKeyInfo(&info->keys[i]);
276 ClearCommonInfo(&info->modMap->defs);
278 ClearAliases(&info->aliases);
279 memset(info, 0, sizeof(SymbolsInfo));
283 ResizeKeyGroup(KeyInfo * key,
284 unsigned group, unsigned atLeastSize, Bool forceActions)
289 tooSmall = (key->numLevels[group] < atLeastSize);
291 newWidth = atLeastSize;
293 newWidth = key->numLevels[group];
295 if ((key->syms[group] == NULL) || tooSmall)
297 key->syms[group] = uTypedRecalloc(key->syms[group],
298 key->numLevels[group], newWidth,
300 if (!key->syms[group])
303 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
304 (tooSmall && (key->acts[group] != NULL)))
306 key->acts[group] = uTypedRecalloc(key->acts[group],
307 key->numLevels[group], newWidth,
309 if (!key->acts[group])
312 key->numLevels[group] = newWidth;
317 MergeKeyGroups(SymbolsInfo * info,
318 KeyInfo * into, KeyInfo * from, unsigned group)
320 uint32_t *resultSyms;
321 union xkb_action *resultActs;
324 Bool report, clobber;
326 clobber = (from->defs.merge != MergeAugment);
327 report = (warningLevel > 9) ||
328 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
329 if (into->numLevels[group] >= from->numLevels[group])
331 resultSyms = into->syms[group];
332 resultActs = into->acts[group];
333 resultWidth = into->numLevels[group];
337 resultSyms = from->syms[group];
338 resultActs = from->acts[group];
339 resultWidth = from->numLevels[group];
341 if (resultSyms == NULL)
343 resultSyms = uTypedCalloc(resultWidth, uint32_t);
346 WSGO("Could not allocate symbols for group merge\n");
347 ACTION("Group %d of key %s not merged\n", group,
348 longText(into->name));
352 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
354 resultActs = uTypedCalloc(resultWidth, union xkb_action);
357 WSGO("Could not allocate actions for group merge\n");
358 ACTION("Group %d of key %s not merged\n", group,
359 longText(into->name));
363 for (i = 0; i < resultWidth; i++)
365 uint32_t fromSym, toSym;
366 if (from->syms[group] && (i < from->numLevels[group]))
367 fromSym = from->syms[group][i];
370 if (into->syms[group] && (i < into->numLevels[group]))
371 toSym = into->syms[group][i];
374 if ((fromSym == NoSymbol) || (fromSym == toSym))
375 resultSyms[i] = toSym;
376 else if (toSym == NoSymbol)
377 resultSyms[i] = fromSym;
380 uint32_t use, ignore;
394 ("Multiple symbols for level %d/group %d on key %s\n",
395 i + 1, group + 1, longText(into->name));
396 ACTION("Using %s, ignoring %s\n",
397 XkbcKeysymText(use), XkbcKeysymText(ignore));
401 if (resultActs != NULL)
403 union xkb_action *fromAct, *toAct;
404 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
405 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
406 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
409 resultActs[i] = *toAct;
411 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
412 && (fromAct != NULL))
414 resultActs[i] = *fromAct;
418 union xkb_action *use, *ignore;
432 ("Multiple actions for level %d/group %d on key %s\n",
433 i + 1, group + 1, longText(into->name));
434 ACTION("Using %s, ignoring %s\n",
435 XkbcActionTypeText(use->type),
436 XkbcActionTypeText(ignore->type));
439 resultActs[i] = *use;
443 if (resultSyms != into->syms[group])
444 free(into->syms[group]);
445 if (resultSyms != from->syms[group])
446 free(from->syms[group]);
447 if (resultActs != into->acts[group])
448 free(into->acts[group]);
449 if (resultActs != from->acts[group])
450 free(from->acts[group]);
451 into->numLevels[group] = resultWidth;
452 into->syms[group] = resultSyms;
453 from->syms[group] = NULL;
454 into->acts[group] = resultActs;
455 from->acts[group] = NULL;
456 into->symsDefined |= (1 << group);
457 from->symsDefined &= ~(1 << group);
458 into->actsDefined |= (1 << group);
459 from->actsDefined &= ~(1 << group);
464 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
467 unsigned collide = 0;
470 if (from->defs.merge == MergeReplace)
472 for (i = 0; i < XkbNumKbdGroups; i++)
474 if (into->numLevels[i] != 0)
481 memset(from, 0, sizeof(KeyInfo));
484 report = ((warningLevel > 9) ||
485 ((into->defs.fileID == from->defs.fileID)
486 && (warningLevel > 0)));
487 for (i = 0; i < XkbNumKbdGroups; i++)
489 if (from->numLevels[i] > 0)
491 if (into->numLevels[i] == 0)
493 into->numLevels[i] = from->numLevels[i];
494 into->syms[i] = from->syms[i];
495 into->acts[i] = from->acts[i];
496 into->symsDefined |= (1 << i);
497 from->syms[i] = NULL;
498 from->acts[i] = NULL;
499 from->numLevels[i] = 0;
500 from->symsDefined &= ~(1 << i);
502 into->defs.defined |= _Key_Syms;
504 into->defs.defined |= _Key_Acts;
511 collide |= _Key_Syms;
513 collide |= _Key_Acts;
515 MergeKeyGroups(info, into, from, (unsigned) i);
518 if (from->types[i] != None)
520 if ((into->types[i] != None) && (report) &&
521 (into->types[i] != from->types[i]))
523 uint32_t use, ignore;
524 collide |= _Key_Types;
525 if (from->defs.merge != MergeAugment)
527 use = from->types[i];
528 ignore = into->types[i];
532 use = into->types[i];
533 ignore = from->types[i];
536 ("Multiple definitions for group %d type of key %s\n",
537 i, longText(into->name));
538 ACTION("Using %s, ignoring %s\n",
540 XkbcAtomText(ignore));
542 if ((from->defs.merge != MergeAugment)
543 || (into->types[i] == None))
545 into->types[i] = from->types[i];
549 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
551 into->behavior = from->behavior;
552 into->nameForOverlayKey = from->nameForOverlayKey;
553 into->defs.defined |= _Key_Behavior;
555 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
557 into->vmodmap = from->vmodmap;
558 into->defs.defined |= _Key_VModMap;
560 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
562 into->repeat = from->repeat;
563 into->defs.defined |= _Key_Repeat;
565 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
567 into->dfltType = from->dfltType;
568 into->defs.defined |= _Key_Type_Dflt;
570 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
572 into->groupInfo = from->groupInfo;
573 into->defs.defined |= _Key_GroupInfo;
577 WARN("Symbol map for key %s redefined\n",
578 longText(into->name));
579 ACTION("Using %s definition for conflicting fields\n",
580 (from->defs.merge == MergeAugment ? "first" : "last"));
586 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
589 unsigned long real_name;
591 for (i = 0; i < info->nKeys; i++)
593 if (info->keys[i].name == key->name)
594 return MergeKeys(info, &info->keys[i], key);
596 if (FindKeyNameForAlias(xkb, key->name, &real_name))
598 for (i = 0; i < info->nKeys; i++)
600 if (info->keys[i].name == real_name)
601 return MergeKeys(info, &info->keys[i], key);
604 if (info->nKeys >= info->szKeys)
606 info->szKeys += SYMBOLS_CHUNK;
608 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
611 WSGO("Could not allocate key symbols descriptions\n");
612 ACTION("Some key symbols definitions may be lost\n");
616 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
620 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
625 clobber = (new->defs.merge != MergeAugment);
626 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
628 if (new->haveSymbol && mm->haveSymbol
629 && (new->u.keySym == mm->u.keySym))
631 unsigned use, ignore;
632 if (mm->modifier != new->modifier)
637 ignore = mm->modifier;
642 ignore = new->modifier;
645 ("%s added to symbol map for multiple modifiers\n",
646 XkbcKeysymText(new->u.keySym));
647 ACTION("Using %s, ignoring %s.\n",
648 XkbcModIndexText(use),
649 XkbcModIndexText(ignore));
654 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
655 (new->u.keyName == mm->u.keyName))
657 unsigned use, ignore;
658 if (mm->modifier != new->modifier)
663 ignore = mm->modifier;
668 ignore = new->modifier;
670 ERROR("Key %s added to map for multiple modifiers\n",
671 longText(new->u.keyName));
672 ACTION("Using %s, ignoring %s.\n",
673 XkbcModIndexText(use),
674 XkbcModIndexText(ignore));
680 mm = uTypedAlloc(ModMapEntry);
683 WSGO("Could not allocate modifier map entry\n");
684 ACTION("Modifier map for %s will be incomplete\n",
685 XkbcModIndexText(new->modifier));
689 mm->defs.next = &info->modMap->defs;
694 /***====================================================================***/
697 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
698 unsigned merge, struct xkb_desc * xkb)
703 if (from->errorCount > 0)
705 into->errorCount += from->errorCount;
708 if (into->name == NULL)
710 into->name = from->name;
713 for (i = 0; i < XkbNumKbdGroups; i++)
715 if (from->groupNames[i] != None)
717 if ((merge != MergeAugment) || (into->groupNames[i] == None))
718 into->groupNames[i] = from->groupNames[i];
721 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
723 if (merge != MergeDefault)
724 key->defs.merge = merge;
725 if (!AddKeySymbols(into, key, xkb))
728 if (from->modMap != NULL)
730 ModMapEntry *mm, *next;
731 for (mm = from->modMap; mm != NULL; mm = next)
733 if (merge != MergeDefault)
734 mm->defs.merge = merge;
735 if (!AddModMapEntry(into, mm))
737 next = (ModMapEntry *) mm->defs.next;
742 if (!MergeAliases(&into->aliases, &from->aliases, merge))
746 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
747 struct xkb_desc * /* xkb */ ,
748 unsigned /* merge */ ,
749 SymbolsInfo * /* included */
753 HandleIncludeSymbols(IncludeStmt * stmt,
754 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
758 SymbolsInfo included;
762 if ((stmt->file == NULL) && (stmt->map == NULL))
766 memset(info, 0, sizeof(SymbolsInfo));
768 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
770 InitSymbolsInfo(&included, xkb);
771 included.fileID = included.dflt.defs.fileID = rtrn->id;
772 included.merge = included.dflt.defs.merge = MergeOverride;
775 included.explicit_group = atoi(stmt->modifier) - 1;
779 included.explicit_group = info->explicit_group;
781 (*hndlr) (rtrn, xkb, MergeOverride, &included);
782 if (stmt->stmt != NULL)
785 included.name = stmt->stmt;
791 info->errorCount += 10;
794 if ((stmt->next != NULL) && (included.errorCount < 1))
798 SymbolsInfo next_incl;
800 for (next = stmt->next; next != NULL; next = next->next)
802 if ((next->file == NULL) && (next->map == NULL))
805 MergeIncludedSymbols(&included, info, next->merge, xkb);
806 FreeSymbolsInfo(info);
808 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
810 InitSymbolsInfo(&next_incl, xkb);
811 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
812 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
815 next_incl.explicit_group = atoi(next->modifier) - 1;
819 next_incl.explicit_group = info->explicit_group;
821 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
822 MergeIncludedSymbols(&included, &next_incl, op, xkb);
823 FreeSymbolsInfo(&next_incl);
827 info->errorCount += 10;
836 MergeIncludedSymbols(info, &included, newMerge, xkb);
837 FreeSymbolsInfo(&included);
839 return (info->errorCount == 0);
846 GetGroupIndex(KeyInfo * key,
847 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
857 if (arrayNdx == NULL)
862 defined = key->symsDefined;
864 defined = key->actsDefined;
866 for (i = 0; i < XkbNumKbdGroups; i++)
868 if ((defined & (1 << i)) == 0)
874 ERROR("Too many groups of %s for key %s (max %d)\n", name,
875 longText(key->name), XkbNumKbdGroups + 1);
876 ACTION("Ignoring %s defined for extra groups\n", name);
879 if (!ExprResolveGroup(arrayNdx, &tmp))
881 ERROR("Illegal group index for %s of key %s\n", name,
882 longText(key->name));
883 ACTION("Definition with non-integer array index ignored\n");
886 *ndx_rtrn = tmp.uval - 1;
891 AddSymbolsToKey(KeyInfo * key,
892 struct xkb_desc * xkb,
894 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
899 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
903 key->symsDefined |= (1 << ndx);
906 if (value->op != ExprKeysymList)
908 ERROR("Expected a list of symbols, found %s\n",
909 exprOpText(value->op));
910 ACTION("Ignoring symbols for group %d of %s\n", ndx,
911 longText(key->name));
914 if (key->syms[ndx] != NULL)
916 WSGO("Symbols for key %s, group %d already defined\n",
917 longText(key->name), ndx);
920 nSyms = value->value.list.nSyms;
921 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
922 (!ResizeKeyGroup(key, ndx, nSyms, False)))
924 WSGO("Could not resize group %d of key %s\n", ndx,
925 longText(key->name));
926 ACTION("Symbols lost\n");
929 key->symsDefined |= (1 << ndx);
930 for (i = 0; i < nSyms; i++) {
931 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
932 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
933 key->syms[ndx][i] = NoSymbol;
936 for (i = key->numLevels[ndx] - 1;
937 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
939 key->numLevels[ndx]--;
945 AddActionsToKey(KeyInfo * key,
946 struct xkb_desc * xkb,
948 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
953 struct xkb_any_action *toAct;
955 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
960 key->actsDefined |= (1 << ndx);
963 if (value->op != ExprActionList)
965 WSGO("Bad expression type (%d) for action list value\n", value->op);
966 ACTION("Ignoring actions for group %d of %s\n", ndx,
967 longText(key->name));
970 if (key->acts[ndx] != NULL)
972 WSGO("Actions for key %s, group %d already defined\n",
973 longText(key->name), ndx);
976 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
978 act = (ExprDef *) act->common.next;
982 WSGO("Action list but not actions in AddActionsToKey\n");
985 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
986 (!ResizeKeyGroup(key, ndx, nActs, True)))
988 WSGO("Could not resize group %d of key %s\n", ndx,
989 longText(key->name));
990 ACTION("Actions lost\n");
993 key->actsDefined |= (1 << ndx);
995 toAct = (struct xkb_any_action *) key->acts[ndx];
996 act = value->value.child;
997 for (i = 0; i < nActs; i++, toAct++)
999 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1001 ERROR("Illegal action definition for %s\n",
1002 longText(key->name));
1003 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1005 act = (ExprDef *) act->common.next;
1011 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1014 unsigned radio_groups = 0;
1016 if (arrayNdx == NULL)
1018 radio_groups = XkbAllRadioGroupsMask;
1022 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1024 ERROR("Illegal index in group name definition\n");
1025 ACTION("Definition with non-integer array index ignored\n");
1028 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1030 ERROR("Illegal radio group specified (must be 1..%d)\n",
1031 XkbMaxRadioGroups + 1);
1032 ACTION("Value of \"allow none\" for group %d ignored\n",
1036 radio_groups |= (1 << (tmp.uval - 1));
1038 if (!ExprResolveBoolean(value, &tmp))
1040 ERROR("Illegal \"allow none\" value for %s\n",
1041 longText(key->name));
1042 ACTION("Non-boolean value ignored\n");
1046 key->allowNone |= radio_groups;
1048 key->allowNone &= ~radio_groups;
1053 static LookupEntry lockingEntries[] = {
1054 {"true", XkbKB_Lock},
1055 {"yes", XkbKB_Lock},
1057 {"false", XkbKB_Default},
1058 {"no", XkbKB_Default},
1059 {"off", XkbKB_Default},
1060 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1064 static LookupEntry repeatEntries[] = {
1065 {"true", RepeatYes},
1068 {"false", RepeatNo},
1071 {"default", RepeatUndefined},
1076 SetSymbolsField(KeyInfo * key,
1077 struct xkb_desc * xkb,
1079 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1084 if (uStrCaseCmp(field, "type") == 0)
1087 if ((!ExprResolveString(value, &tmp))
1088 && (warningLevel > 0))
1090 WARN("The type field of a key symbol map must be a string\n");
1091 ACTION("Ignoring illegal type definition\n");
1093 if (arrayNdx == NULL)
1095 key->dfltType = xkb_intern_atom(tmp.str);
1096 key->defs.defined |= _Key_Type_Dflt;
1098 else if (!ExprResolveGroup(arrayNdx, &ndx))
1100 ERROR("Illegal group index for type of key %s\n",
1101 longText(key->name));
1102 ACTION("Definition with non-integer array index ignored\n");
1108 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1109 key->typesDefined |= (1 << (ndx.uval - 1));
1113 else if (uStrCaseCmp(field, "symbols") == 0)
1114 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1115 else if (uStrCaseCmp(field, "actions") == 0)
1116 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1117 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1118 (uStrCaseCmp(field, "virtualmods") == 0) ||
1119 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1121 ok = ExprResolveVModMask(value, &tmp, xkb);
1124 key->vmodmap = (tmp.uval >> 8);
1125 key->defs.defined |= _Key_VModMap;
1129 ERROR("Expected a virtual modifier mask, found %s\n",
1130 exprOpText(value->op));
1131 ACTION("Ignoring virtual modifiers definition for key %s\n",
1132 longText(key->name));
1135 else if ((uStrCaseCmp(field, "locking") == 0)
1136 || (uStrCaseCmp(field, "lock") == 0)
1137 || (uStrCaseCmp(field, "locks") == 0))
1139 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1141 key->behavior.type = tmp.uval;
1142 key->defs.defined |= _Key_Behavior;
1144 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1145 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1147 Bool permanent = False;
1148 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1150 if (ExprResolveString(value, &tmp)) {
1151 ok = (strcmp(tmp.str, "none") == 0);
1157 ok = ExprResolveInteger(value, &tmp);
1161 ERROR("Illegal radio group specification for %s\n",
1162 longText(key->name));
1163 ACTION("Non-integer radio group ignored\n");
1168 key->behavior.type = XkbKB_Default;
1169 key->behavior.data = 0;
1172 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1175 ("Radio group specification for %s out of range (1..32)\n",
1176 longText(key->name));
1177 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1180 key->behavior.type =
1181 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1182 key->behavior.data = tmp.uval - 1;
1183 if (key->allowNone & (1 << (tmp.uval - 1)))
1184 key->behavior.data |= XkbKB_RGAllowNone;
1185 key->defs.defined |= _Key_Behavior;
1187 else if (uStrCaseEqual(field, "allownone"))
1189 ok = SetAllowNone(key, arrayNdx, value);
1191 else if (uStrCasePrefix("overlay", field) ||
1192 uStrCasePrefix("permanentoverlay", field))
1194 Bool permanent = False;
1197 if (uStrCasePrefix("permanent", field))
1200 which = &field[sizeof("permanentoverlay") - 1];
1204 which = &field[sizeof("overlay") - 1];
1206 if (sscanf(which, "%d", &overlayNdx) == 1)
1208 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1210 ERROR("Illegal overlay %d specified for %s\n",
1211 overlayNdx, longText(key->name));
1212 ACTION("Ignored\n");
1216 else if (*which == '\0')
1218 else if (warningLevel > 0)
1220 ERROR("Illegal overlay \"%s\" specified for %s\n",
1221 which, longText(key->name));
1222 ACTION("Ignored\n");
1225 ok = ExprResolveKeyName(value, &tmp);
1228 ERROR("Illegal overlay key specification for %s\n",
1229 longText(key->name));
1230 ACTION("Overlay key must be specified by name\n");
1233 if (overlayNdx == 1)
1234 key->behavior.type = XkbKB_Overlay1;
1236 key->behavior.type = XkbKB_Overlay2;
1238 key->behavior.type |= XkbKB_Permanent;
1240 key->behavior.data = 0;
1241 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1242 key->defs.defined |= _Key_Behavior;
1244 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1245 (uStrCaseCmp(field, "repeats") == 0) ||
1246 (uStrCaseCmp(field, "repeat") == 0))
1248 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1251 ERROR("Illegal repeat setting for %s\n",
1252 longText(key->name));
1253 ACTION("Non-boolean repeat setting ignored\n");
1256 key->repeat = tmp.uval;
1257 key->defs.defined |= _Key_Repeat;
1259 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1260 (uStrCaseCmp(field, "wrapgroups") == 0))
1262 ok = ExprResolveBoolean(value, &tmp);
1265 ERROR("Illegal groupsWrap setting for %s\n",
1266 longText(key->name));
1267 ACTION("Non-boolean value ignored\n");
1271 key->groupInfo = XkbWrapIntoRange;
1273 key->groupInfo = XkbClampIntoRange;
1274 key->defs.defined |= _Key_GroupInfo;
1276 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1277 (uStrCaseCmp(field, "clampgroups") == 0))
1279 ok = ExprResolveBoolean(value, &tmp);
1282 ERROR("Illegal groupsClamp setting for %s\n",
1283 longText(key->name));
1284 ACTION("Non-boolean value ignored\n");
1288 key->groupInfo = XkbClampIntoRange;
1290 key->groupInfo = XkbWrapIntoRange;
1291 key->defs.defined |= _Key_GroupInfo;
1293 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1294 (uStrCaseCmp(field, "redirectgroups") == 0))
1296 if (!ExprResolveGroup(value, &tmp))
1298 ERROR("Illegal group index for redirect of key %s\n",
1299 longText(key->name));
1300 ACTION("Definition with non-integer group ignored\n");
1304 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1305 key->defs.defined |= _Key_GroupInfo;
1309 ERROR("Unknown field %s in a symbol interpretation\n", field);
1310 ACTION("Definition ignored\n");
1317 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1319 ExprResult tmp, name;
1321 if ((arrayNdx == NULL) && (warningLevel > 0))
1323 WARN("You must specify an index when specifying a group name\n");
1324 ACTION("Group name definition without array subscript ignored\n");
1327 if (!ExprResolveGroup(arrayNdx, &tmp))
1329 ERROR("Illegal index in group name definition\n");
1330 ACTION("Definition with non-integer array index ignored\n");
1333 if (!ExprResolveString(value, &name))
1335 ERROR("Group name must be a string\n");
1336 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1339 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1340 xkb_intern_atom(name.str);
1347 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1349 ExprResult elem, field, tmp;
1353 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1354 return 0; /* internal error, already reported */
1355 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1357 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1360 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1361 (uStrCaseCmp(field.str, "groupname") ==
1364 ret = SetGroupName(info, arrayNdx, stmt->value);
1366 else if ((elem.str == NULL)
1367 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1368 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1370 if (!ExprResolveBoolean(stmt->value, &tmp))
1372 ERROR("Illegal setting for global groupsWrap\n");
1373 ACTION("Non-boolean value ignored\n");
1378 info->groupInfo = XkbWrapIntoRange;
1380 info->groupInfo = XkbClampIntoRange;
1384 else if ((elem.str == NULL)
1385 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1386 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1388 if (!ExprResolveBoolean(stmt->value, &tmp))
1390 ERROR("Illegal setting for global groupsClamp\n");
1391 ACTION("Non-boolean value ignored\n");
1396 info->groupInfo = XkbClampIntoRange;
1398 info->groupInfo = XkbWrapIntoRange;
1402 else if ((elem.str == NULL)
1403 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1404 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1406 if (!ExprResolveGroup(stmt->value, &tmp))
1408 ERROR("Illegal group index for global groupsRedirect\n");
1409 ACTION("Definition with non-integer group ignored\n");
1413 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1418 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1420 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1423 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1433 HandleSymbolsBody(VarDef * def,
1434 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1437 ExprResult tmp, field;
1440 for (; def != NULL; def = (VarDef *) def->common.next)
1442 if ((def->name) && (def->name->type == ExprFieldRef))
1444 ok = HandleSymbolsVar(def, xkb, info);
1449 if (def->name == NULL)
1451 if ((def->value == NULL)
1452 || (def->value->op == ExprKeysymList))
1453 field.str = strdup("symbols");
1455 field.str = strdup("actions");
1460 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1463 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1472 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1474 unsigned group = info->explicit_group;
1479 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1482 WARN("For the map %s an explicit group specified\n", info->name);
1483 WARN("but key %s has more than one group defined\n",
1484 longText(key->name));
1485 ACTION("All groups except first one will be ignored\n");
1486 for (i = 1; i < XkbNumKbdGroups; i++)
1488 key->numLevels[i] = 0;
1490 key->syms[i] = (uint32_t *) NULL;
1492 key->acts[i] = (union xkb_action *) NULL;
1493 key->types[i] = (uint32_t) 0;
1496 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1498 key->numLevels[group] = key->numLevels[0];
1499 key->numLevels[0] = 0;
1500 key->syms[group] = key->syms[0];
1501 key->syms[0] = (uint32_t *) NULL;
1502 key->acts[group] = key->acts[0];
1503 key->acts[0] = (union xkb_action *) NULL;
1504 key->types[group] = key->types[0];
1505 key->types[0] = (uint32_t) 0;
1510 HandleSymbolsDef(SymbolsDef * stmt,
1511 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1516 CopyKeyInfo(&info->dflt, &key, False);
1517 key.defs.merge = stmt->merge;
1518 key.name = KeyNameToLong(stmt->keyName);
1519 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1525 if (!SetExplicitGroup(info, &key))
1531 if (!AddKeySymbols(info, &key, xkb))
1540 HandleModMapDef(ModMapDef * def,
1541 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1548 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1550 ERROR("Illegal modifier map definition\n");
1551 ACTION("Ignoring map for non-modifier \"%s\"\n",
1552 XkbcAtomText(def->modifier));
1556 tmp.modifier = rtrn.uval;
1557 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1559 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1561 tmp.haveSymbol = False;
1562 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1564 else if (ExprResolveKeySym(key, &rtrn))
1566 tmp.haveSymbol = True;
1567 tmp.u.keySym = rtrn.uval;
1571 ERROR("Modmap entries may contain only key names or keysyms\n");
1572 ACTION("Illegal definition for %s modifier ignored\n",
1573 XkbcModIndexText(tmp.modifier));
1577 ok = AddModMapEntry(info, &tmp) && ok;
1583 HandleSymbolsFile(XkbFile * file,
1584 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1588 info->name = _XkbDupString(file->name);
1592 switch (stmt->stmtType)
1595 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1599 case StmtSymbolsDef:
1600 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1604 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1608 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1612 ERROR("Interpretation files may not include other types\n");
1613 ACTION("Ignoring definition of symbol interpretation\n");
1616 case StmtKeycodeDef:
1617 ERROR("Interpretation files may not include other types\n");
1618 ACTION("Ignoring definition of key name\n");
1622 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1626 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1631 if (info->errorCount > 10)
1634 ERROR("Too many errors\n");
1636 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1643 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1652 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1654 if (j < (int) XkbKeyNumSyms(xkb, i))
1657 if (XkbKeySym(xkb, i, j) == sym)
1671 * Find the given name in the xkb->map->types and return its index.
1673 * @param name The atom to search for.
1674 * @param type_rtrn Set to the index of the name if found.
1676 * @return True if found, False otherwise.
1679 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1683 if (xkb && xkb->map && xkb->map->types)
1685 for (n = 0; n < xkb->map->num_types; n++)
1687 if (xkb->map->types[n].name == (uint32_t) name)
1698 * Assign a type to the given sym and return the Atom for the type assigned.
1701 * - ONE_LEVEL for width 0/1
1702 * - ALPHABETIC for 2 shift levels, with lower/upercase
1703 * - KEYPAD for keypad keys.
1704 * - TWO_LEVEL for other 2 shift level keys.
1705 * and the same for four level keys.
1707 * @param width Number of sysms in syms.
1708 * @param syms The keysyms for the given key (must be size width).
1709 * @param typeNameRtrn Set to the Atom of the type name.
1711 * @returns True if a type could be found, False otherwise.
1714 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1718 if ((width == 1) || (width == 0))
1720 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1723 else if (width == 2)
1725 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1727 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1729 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1731 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1736 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1740 else if (width <= 4)
1742 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1743 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1745 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1747 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1749 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1750 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1752 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1753 /* XXX: why not set autoType here? */
1755 return ((width >= 0) && (width <= 4));
1759 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1760 * groups, and reduce to one group if all groups are identical anyway.
1763 PrepareKeyDef(KeyInfo * key)
1765 int i, j, width, defined, lastGroup;
1768 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1769 /* get highest group number */
1770 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1772 if (defined & (1 << i))
1780 /* If there are empty groups between non-empty ones fill them with data */
1781 /* from the first group. */
1782 /* We can make a wrong assumption here. But leaving gaps is worse. */
1783 for (i = lastGroup; i > 0; i--)
1785 if (defined & (1 << i))
1787 width = key->numLevels[0];
1788 if (key->typesDefined & 1)
1790 for (j = 0; j < width; j++)
1792 key->types[i] = key->types[0];
1794 key->typesDefined |= 1 << i;
1796 if ((key->actsDefined & 1) && key->acts[0])
1798 key->acts[i] = uTypedCalloc(width, union xkb_action);
1799 if (key->acts[i] == NULL)
1801 memcpy((void *) key->acts[i], (void *) key->acts[0],
1802 width * sizeof(union xkb_action));
1803 key->actsDefined |= 1 << i;
1805 if ((key->symsDefined & 1) && key->syms[0])
1807 key->syms[i] = uTypedCalloc(width, uint32_t);
1808 if (key->syms[i] == NULL)
1810 memcpy((void *) key->syms[i], (void *) key->syms[0],
1811 width * sizeof(uint32_t));
1812 key->symsDefined |= 1 << i;
1816 key->numLevels[i] = key->numLevels[0];
1819 /* If all groups are completely identical remove them all */
1820 /* exept the first one. */
1822 for (i = lastGroup; i > 0; i--)
1824 if ((key->numLevels[i] != key->numLevels[0]) ||
1825 (key->types[i] != key->types[0]))
1830 if ((key->syms[i] != key->syms[0]) &&
1831 (key->syms[i] == NULL || key->syms[0] == NULL ||
1832 memcmp((void *) key->syms[i], (void *) key->syms[0],
1833 sizeof(uint32_t) * key->numLevels[0])))
1838 if ((key->acts[i] != key->acts[0]) &&
1839 (key->acts[i] == NULL || key->acts[0] == NULL ||
1840 memcmp((void *) key->acts[i], (void *) key->acts[0],
1841 sizeof(union xkb_action) * key->numLevels[0])))
1849 for (i = lastGroup; i > 0; i--)
1851 key->numLevels[i] = 0;
1853 key->syms[i] = (uint32_t *) NULL;
1855 key->acts[i] = (union xkb_action *) NULL;
1856 key->types[i] = (uint32_t) 0;
1858 key->symsDefined &= 1;
1859 key->actsDefined &= 1;
1860 key->typesDefined &= 1;
1865 * Copy the KeyInfo into the keyboard description.
1867 * This function recurses.
1870 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1873 xkb_keycode_t okc, kc;
1874 unsigned width, tmp, nGroups;
1875 struct xkb_key_type * type;
1876 Bool haveActions, autoType, useAlias;
1878 union xkb_action *outActs;
1879 unsigned types[XkbNumKbdGroups];
1881 useAlias = (start_from == 0);
1883 /* get the keycode for the key. */
1884 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1887 if ((start_from == 0) && (warningLevel >= 5))
1889 WARN("Key %s not found in %s keycodes\n",
1890 longText(key->name),
1891 XkbcAtomText(xkb->names->keycodes));
1892 ACTION("Symbols ignored\n");
1897 haveActions = False;
1898 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1900 if (((i + 1) > nGroups)
1901 && (((key->symsDefined | key->actsDefined) & (1 << i))
1902 || (key->typesDefined) & (1 << i)))
1907 /* Assign the type to the key, if it is missing. */
1908 if (key->types[i] == None)
1910 if (key->dfltType != None)
1911 key->types[i] = key->dfltType;
1912 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1913 &key->types[i], &autoType))
1918 if (warningLevel >= 5)
1920 WARN("No automatic type for %d symbols\n",
1921 (unsigned int) key->numLevels[i]);
1922 ACTION("Using %s for the %s key (keycode %d)\n",
1923 XkbcAtomText(key->types[i]),
1924 longText(key->name), kc);
1928 if (FindNamedType(xkb, key->types[i], &types[i]))
1930 if (!autoType || key->numLevels[i] > 2)
1931 xkb->server->explicit[kc] |= (1 << i);
1935 if (warningLevel >= 3)
1937 WARN("Type \"%s\" is not defined\n",
1938 XkbcAtomText(key->types[i]));
1939 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1940 longText(key->name), kc);
1942 types[i] = XkbTwoLevelIndex;
1944 /* if the type specifies less syms than the key has, shrink the key */
1945 type = &xkb->map->types[types[i]];
1946 if (type->num_levels < key->numLevels[i])
1948 if (warningLevel > 0)
1951 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1952 XkbcAtomText(type->name),
1953 (unsigned int) type->num_levels,
1954 longText(key->name),
1955 (unsigned int) key->numLevels[i]);
1956 ACTION("Ignoring extra symbols\n");
1958 key->numLevels[i] = type->num_levels;
1960 if (key->numLevels[i] > width)
1961 width = key->numLevels[i];
1962 if (type->num_levels > width)
1963 width = type->num_levels;
1966 /* width is now the largest width found */
1968 i = width * nGroups;
1969 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1970 if (outSyms == NULL)
1972 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1973 longText(key->name), kc);
1978 outActs = XkbcResizeKeyActions(xkb, kc, i);
1979 if (outActs == NULL)
1981 WSGO("Could not enlarge actions for %s (key %d)\n",
1982 longText(key->name), kc);
1985 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1989 if (key->defs.defined & _Key_GroupInfo)
1992 i = xkb->map->key_sym_map[kc].group_info;
1994 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1995 xkb->map->key_sym_map[kc].width = width;
1996 for (i = 0; i < nGroups; i++)
1998 /* assign kt_index[i] to the index of the type in map->types.
1999 * kt_index[i] may have been set by a previous run (if we have two
2000 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2001 * default group if we dont even have keys for this group anyway.
2003 * FIXME: There should be a better fix for this.
2005 if (key->numLevels[i])
2006 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2007 if (key->syms[i] != NULL)
2009 /* fill key to "width" symbols*/
2010 for (tmp = 0; tmp < width; tmp++)
2012 if (tmp < key->numLevels[i])
2013 outSyms[tmp] = key->syms[i][tmp];
2015 outSyms[tmp] = NoSymbol;
2016 if ((outActs != NULL) && (key->acts[i] != NULL))
2018 if (tmp < key->numLevels[i])
2019 outActs[tmp] = key->acts[i][tmp];
2021 outActs[tmp].type = XkbSA_NoAction;
2029 switch (key->behavior.type & XkbKB_OpMask)
2033 case XkbKB_Overlay1:
2034 case XkbKB_Overlay2:
2035 /* find key by name! */
2036 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2037 CreateKeyNames(xkb), 0))
2039 if (warningLevel >= 1)
2041 WARN("Key %s not found in %s keycodes\n",
2042 longText(key->nameForOverlayKey),
2043 XkbcAtomText(xkb->names->keycodes));
2044 ACTION("Not treating %s as an overlay key \n",
2045 longText(key->name));
2049 key->behavior.data = okc;
2051 xkb->server->behaviors[kc] = key->behavior;
2052 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2055 if (key->defs.defined & _Key_VModMap)
2057 xkb->server->vmodmap[kc] = key->vmodmap;
2058 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2060 if (key->repeat != RepeatUndefined)
2062 if (key->repeat == RepeatYes)
2063 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2065 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2066 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2069 if (nGroups > xkb->ctrls->num_groups)
2070 xkb->ctrls->num_groups = nGroups;
2072 /* do the same thing for the next key */
2073 CopySymbolsDef(xkb, key, kc + 1);
2078 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2082 if ((!entry->haveSymbol)
2085 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2087 if (warningLevel >= 5)
2089 WARN("Key %s not found in %s keycodes\n",
2090 longText(entry->u.keyName),
2091 XkbcAtomText(xkb->names->keycodes));
2092 ACTION("Modifier map entry for %s not updated\n",
2093 XkbcModIndexText(entry->modifier));
2097 else if (entry->haveSymbol
2098 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2100 if (warningLevel > 5)
2102 WARN("Key \"%s\" not found in %s symbol map\n",
2103 XkbcKeysymText(entry->u.keySym),
2104 XkbcAtomText(xkb->names->symbols));
2105 ACTION("Modifier map entry for %s not updated\n",
2106 XkbcModIndexText(entry->modifier));
2110 xkb->map->modmap[kc] |= (1 << entry->modifier);
2115 * Handle the xkb_symbols section of an xkb file.
2117 * @param file The parsed xkb_symbols section of the xkb file.
2118 * @param xkb Handle to the keyboard description to store the symbols in.
2119 * @param merge Merge strategy (e.g. MergeOverride).
2122 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2127 InitSymbolsInfo(&info, xkb);
2128 info.dflt.defs.fileID = file->id;
2129 info.dflt.defs.merge = merge;
2130 HandleSymbolsFile(file, xkb, merge, &info);
2132 if (info.nKeys == 0) {
2133 FreeSymbolsInfo(&info);
2137 if (info.errorCount == 0)
2141 /* alloc memory in the xkb struct */
2142 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2145 WSGO("Can not allocate names in CompileSymbols\n");
2146 ACTION("Symbols not added\n");
2149 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2152 WSGO("Could not allocate client map in CompileSymbols\n");
2153 ACTION("Symbols not added\n");
2156 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2158 WSGO("Could not allocate server map in CompileSymbols\n");
2159 ACTION("Symbols not added\n");
2162 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2164 WSGO("Could not allocate controls in CompileSymbols\n");
2165 ACTION("Symbols not added\n");
2169 /* now copy info into xkb. */
2170 xkb->names->symbols = xkb_intern_atom(info.name);
2172 ApplyAliases(xkb, False, &info.aliases);
2173 for (i = 0; i < XkbNumKbdGroups; i++)
2175 if (info.groupNames[i] != None)
2176 xkb->names->groups[i] = info.groupNames[i];
2179 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2184 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2186 if (!CopySymbolsDef(xkb, key, 0))
2189 if (warningLevel > 3)
2191 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2193 if (xkb->names->keys[i].name[0] == '\0')
2195 if (XkbKeyNumGroups(xkb, i) < 1)
2198 memcpy(buf, xkb->names->keys[i].name, 4);
2201 ("No symbols defined for <%s> (keycode %d)\n",
2208 ModMapEntry *mm, *next;
2209 for (mm = info.modMap; mm != NULL; mm = next)
2211 if (!CopyModMapDef(xkb, mm))
2213 next = (ModMapEntry *) mm->defs.next;
2216 FreeSymbolsInfo(&info);
2220 FreeSymbolsInfo(&info);