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 /***====================================================================***/
47 #define RepeatUndefined ~((unsigned)0)
49 #define _Key_Syms (1<<0)
50 #define _Key_Acts (1<<1)
51 #define _Key_Repeat (1<<2)
52 #define _Key_Behavior (1<<3)
53 #define _Key_Type_Dflt (1<<4)
54 #define _Key_Types (1<<5)
55 #define _Key_GroupInfo (1<<6)
56 #define _Key_VModMap (1<<7)
58 typedef struct _KeyInfo
61 unsigned long name; /* the 4 chars of the key name, as long */
62 unsigned char groupInfo;
63 unsigned char typesDefined;
64 unsigned char symsDefined;
65 unsigned char actsDefined;
66 unsigned int numLevels[XkbNumKbdGroups];
67 xkb_keysym_t *syms[XkbNumKbdGroups];
68 union xkb_action *acts[XkbNumKbdGroups];
69 xkb_atom_t types[XkbNumKbdGroups];
71 struct xkb_behavior behavior;
72 unsigned short vmodmap;
73 unsigned long allowNone;
78 * Init the given key info to sane values.
81 InitKeyInfo(KeyInfo * info)
84 static char dflt[4] = "*";
86 info->defs.defined = 0;
87 info->defs.fileID = 0;
88 info->defs.merge = MergeOverride;
89 info->defs.next = NULL;
90 info->name = KeyNameToLong(dflt);
92 info->typesDefined = info->symsDefined = info->actsDefined = 0;
93 for (i = 0; i < XkbNumKbdGroups; i++)
95 info->numLevels[i] = 0;
96 info->types[i] = XKB_ATOM_NONE;
100 info->dfltType = XKB_ATOM_NONE;
101 info->behavior.type = XkbKB_Default;
102 info->behavior.data = 0;
104 info->repeat = RepeatUndefined;
109 * Free memory associated with this key info and reset to sane values.
112 FreeKeyInfo(KeyInfo * info)
116 info->defs.defined = 0;
117 info->defs.fileID = 0;
118 info->defs.merge = MergeOverride;
119 info->defs.next = NULL;
121 info->typesDefined = info->symsDefined = info->actsDefined = 0;
122 for (i = 0; i < XkbNumKbdGroups; i++)
124 info->numLevels[i] = 0;
125 info->types[i] = XKB_ATOM_NONE;
127 info->syms[i] = NULL;
129 info->acts[i] = NULL;
131 info->dfltType = XKB_ATOM_NONE;
132 info->behavior.type = XkbKB_Default;
133 info->behavior.data = 0;
135 info->repeat = RepeatUndefined;
140 * Copy old into new, optionally reset old to 0.
141 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
142 * newly allocated and new points to the new memory areas.
145 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
150 new->defs.next = NULL;
153 for (i = 0; i < XkbNumKbdGroups; i++)
155 old->numLevels[i] = 0;
163 for (i = 0; i < XkbNumKbdGroups; i++)
165 width = new->numLevels[i];
166 if (old->syms[i] != NULL)
168 new->syms[i] = uTypedCalloc(width, xkb_keysym_t);
172 new->numLevels[i] = 0;
175 memcpy(new->syms[i], old->syms[i], width * sizeof(xkb_keysym_t));
177 if (old->acts[i] != NULL)
179 new->acts[i] = uTypedCalloc(width, union xkb_action);
185 memcpy(new->acts[i], old->acts[i],
186 width * sizeof(union xkb_action));
193 /***====================================================================***/
195 typedef struct _ModMapEntry
202 unsigned long keyName;
207 #define SYMBOLS_INIT_SIZE 110
208 #define SYMBOLS_CHUNK 20
209 typedef struct _SymbolsInfo
211 char *name; /* e.g. pc+us+inet(evdev) */
215 unsigned explicit_group;
223 xkb_atom_t groupNames[XkbNumKbdGroups];
230 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
235 info->explicit_group = 0;
236 info->errorCount = 0;
238 info->merge = MergeOverride;
240 info->szKeys = SYMBOLS_INIT_SIZE;
242 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
244 for (i = 0; i < XkbNumKbdGroups; i++)
245 info->groupNames[i] = XKB_ATOM_NONE;
246 InitKeyInfo(&info->dflt);
247 InitVModInfo(&info->vmods, xkb);
249 info->aliases = NULL;
253 FreeSymbolsInfo(SymbolsInfo * info)
260 for (i = 0; i < info->nKeys; i++)
261 FreeKeyInfo(&info->keys[i]);
265 ClearCommonInfo(&info->modMap->defs);
267 ClearAliases(&info->aliases);
268 memset(info, 0, sizeof(SymbolsInfo));
272 ResizeKeyGroup(KeyInfo * key,
273 unsigned group, unsigned atLeastSize, Bool forceActions)
278 tooSmall = (key->numLevels[group] < atLeastSize);
280 newWidth = atLeastSize;
282 newWidth = key->numLevels[group];
284 if ((key->syms[group] == NULL) || tooSmall)
286 key->syms[group] = uTypedRecalloc(key->syms[group],
287 key->numLevels[group], newWidth,
289 if (!key->syms[group])
292 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
293 (tooSmall && (key->acts[group] != NULL)))
295 key->acts[group] = uTypedRecalloc(key->acts[group],
296 key->numLevels[group], newWidth,
298 if (!key->acts[group])
301 key->numLevels[group] = newWidth;
306 MergeKeyGroups(SymbolsInfo * info,
307 KeyInfo * into, KeyInfo * from, unsigned group)
309 xkb_keysym_t *resultSyms;
310 union xkb_action *resultActs;
311 unsigned int resultWidth;
313 Bool report, clobber;
315 clobber = (from->defs.merge != MergeAugment);
316 report = (warningLevel > 9) ||
317 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
318 if (into->numLevels[group] >= from->numLevels[group])
320 resultSyms = into->syms[group];
321 resultActs = into->acts[group];
322 resultWidth = into->numLevels[group];
326 resultSyms = from->syms[group];
327 resultActs = from->acts[group];
328 resultWidth = from->numLevels[group];
330 if (resultSyms == NULL)
332 resultSyms = uTypedCalloc(resultWidth, xkb_keysym_t);
335 WSGO("Could not allocate symbols for group merge\n");
336 ACTION("Group %d of key %s not merged\n", group,
337 longText(into->name));
341 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
343 resultActs = uTypedCalloc(resultWidth, union xkb_action);
346 WSGO("Could not allocate actions for group merge\n");
347 ACTION("Group %d of key %s not merged\n", group,
348 longText(into->name));
349 if (resultSyms != into->syms[group] &&
350 resultSyms != from->syms[group])
355 for (i = 0; i < resultWidth; i++)
357 xkb_keysym_t fromSym, toSym;
358 if (from->syms[group] && (i < from->numLevels[group]))
359 fromSym = from->syms[group][i];
361 fromSym = XKB_KEYSYM_NO_SYMBOL;
362 if (into->syms[group] && (i < into->numLevels[group]))
363 toSym = into->syms[group][i];
365 toSym = XKB_KEYSYM_NO_SYMBOL;
366 if ((fromSym == XKB_KEYSYM_NO_SYMBOL) || (fromSym == toSym))
367 resultSyms[i] = toSym;
368 else if (toSym == XKB_KEYSYM_NO_SYMBOL)
369 resultSyms[i] = fromSym;
372 xkb_keysym_t use, ignore;
386 ("Multiple symbols for level %d/group %d on key %s\n",
387 i + 1, group + 1, longText(into->name));
388 ACTION("Using %s, ignoring %s\n",
389 XkbcKeysymText(use), XkbcKeysymText(ignore));
393 if (resultActs != NULL)
395 union xkb_action *fromAct, *toAct;
396 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
397 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
398 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
401 resultActs[i] = *toAct;
403 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
404 && (fromAct != NULL))
406 resultActs[i] = *fromAct;
410 union xkb_action *use, *ignore;
424 ("Multiple actions for level %d/group %d on key %s\n",
425 i + 1, group + 1, longText(into->name));
426 ACTION("Using %s, ignoring %s\n",
427 XkbcActionTypeText(use->type),
428 XkbcActionTypeText(ignore->type));
431 resultActs[i] = *use;
435 if (resultSyms != into->syms[group])
436 free(into->syms[group]);
437 if (resultSyms != from->syms[group])
438 free(from->syms[group]);
439 if (resultActs != into->acts[group])
440 free(into->acts[group]);
441 if (resultActs != from->acts[group])
442 free(from->acts[group]);
443 into->numLevels[group] = resultWidth;
444 into->syms[group] = resultSyms;
445 from->syms[group] = NULL;
446 into->acts[group] = resultActs;
447 from->acts[group] = NULL;
448 into->symsDefined |= (1 << group);
449 from->symsDefined &= ~(1 << group);
450 into->actsDefined |= (1 << group);
451 from->actsDefined &= ~(1 << group);
456 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
459 unsigned collide = 0;
462 if (from->defs.merge == MergeReplace)
464 for (i = 0; i < XkbNumKbdGroups; i++)
466 if (into->numLevels[i] != 0)
473 memset(from, 0, sizeof(KeyInfo));
476 report = ((warningLevel > 9) ||
477 ((into->defs.fileID == from->defs.fileID)
478 && (warningLevel > 0)));
479 for (i = 0; i < XkbNumKbdGroups; i++)
481 if (from->numLevels[i] > 0)
483 if (into->numLevels[i] == 0)
485 into->numLevels[i] = from->numLevels[i];
486 into->syms[i] = from->syms[i];
487 into->acts[i] = from->acts[i];
488 into->symsDefined |= (1 << i);
489 from->syms[i] = NULL;
490 from->acts[i] = NULL;
491 from->numLevels[i] = 0;
492 from->symsDefined &= ~(1 << i);
494 into->defs.defined |= _Key_Syms;
496 into->defs.defined |= _Key_Acts;
503 collide |= _Key_Syms;
505 collide |= _Key_Acts;
507 MergeKeyGroups(info, into, from, (unsigned) i);
510 if (from->types[i] != XKB_ATOM_NONE)
512 if ((into->types[i] != XKB_ATOM_NONE) && report &&
513 (into->types[i] != from->types[i]))
515 xkb_atom_t use, ignore;
516 collide |= _Key_Types;
517 if (from->defs.merge != MergeAugment)
519 use = from->types[i];
520 ignore = into->types[i];
524 use = into->types[i];
525 ignore = from->types[i];
528 ("Multiple definitions for group %d type of key %s\n",
529 i, longText(into->name));
530 ACTION("Using %s, ignoring %s\n",
532 XkbcAtomText(ignore));
534 if ((from->defs.merge != MergeAugment)
535 || (into->types[i] == XKB_ATOM_NONE))
537 into->types[i] = from->types[i];
541 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
543 into->behavior = from->behavior;
544 into->defs.defined |= _Key_Behavior;
546 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
548 into->vmodmap = from->vmodmap;
549 into->defs.defined |= _Key_VModMap;
551 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
553 into->repeat = from->repeat;
554 into->defs.defined |= _Key_Repeat;
556 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
558 into->dfltType = from->dfltType;
559 into->defs.defined |= _Key_Type_Dflt;
561 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
563 into->groupInfo = from->groupInfo;
564 into->defs.defined |= _Key_GroupInfo;
568 WARN("Symbol map for key %s redefined\n",
569 longText(into->name));
570 ACTION("Using %s definition for conflicting fields\n",
571 (from->defs.merge == MergeAugment ? "first" : "last"));
577 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
580 unsigned long real_name;
582 for (i = 0; i < info->nKeys; i++)
584 if (info->keys[i].name == key->name)
585 return MergeKeys(info, &info->keys[i], key);
587 if (FindKeyNameForAlias(xkb, key->name, &real_name))
589 for (i = 0; i < info->nKeys; i++)
591 if (info->keys[i].name == real_name)
592 return MergeKeys(info, &info->keys[i], key);
595 if (info->nKeys >= info->szKeys)
597 info->szKeys += SYMBOLS_CHUNK;
599 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
602 WSGO("Could not allocate key symbols descriptions\n");
603 ACTION("Some key symbols definitions may be lost\n");
607 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
611 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
616 clobber = (new->defs.merge != MergeAugment);
617 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
619 if (new->haveSymbol && mm->haveSymbol
620 && (new->u.keySym == mm->u.keySym))
622 unsigned use, ignore;
623 if (mm->modifier != new->modifier)
628 ignore = mm->modifier;
633 ignore = new->modifier;
636 ("%s added to symbol map for multiple modifiers\n",
637 XkbcKeysymText(new->u.keySym));
638 ACTION("Using %s, ignoring %s.\n",
639 XkbcModIndexText(use),
640 XkbcModIndexText(ignore));
645 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
646 (new->u.keyName == mm->u.keyName))
648 unsigned use, ignore;
649 if (mm->modifier != new->modifier)
654 ignore = mm->modifier;
659 ignore = new->modifier;
661 ERROR("Key %s added to map for multiple modifiers\n",
662 longText(new->u.keyName));
663 ACTION("Using %s, ignoring %s.\n",
664 XkbcModIndexText(use),
665 XkbcModIndexText(ignore));
671 mm = uTypedAlloc(ModMapEntry);
674 WSGO("Could not allocate modifier map entry\n");
675 ACTION("Modifier map for %s will be incomplete\n",
676 XkbcModIndexText(new->modifier));
680 mm->defs.next = &info->modMap->defs;
685 /***====================================================================***/
688 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
689 unsigned merge, struct xkb_desc * xkb)
694 if (from->errorCount > 0)
696 into->errorCount += from->errorCount;
699 if (into->name == NULL)
701 into->name = from->name;
704 for (i = 0; i < XkbNumKbdGroups; i++)
706 if (from->groupNames[i] != XKB_ATOM_NONE)
708 if ((merge != MergeAugment) ||
709 (into->groupNames[i] == XKB_ATOM_NONE))
710 into->groupNames[i] = from->groupNames[i];
713 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
715 if (merge != MergeDefault)
716 key->defs.merge = merge;
717 if (!AddKeySymbols(into, key, xkb))
720 if (from->modMap != NULL)
722 ModMapEntry *mm, *next;
723 for (mm = from->modMap; mm != NULL; mm = next)
725 if (merge != MergeDefault)
726 mm->defs.merge = merge;
727 if (!AddModMapEntry(into, mm))
729 next = (ModMapEntry *) mm->defs.next;
734 if (!MergeAliases(&into->aliases, &from->aliases, merge))
738 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
739 struct xkb_desc * /* xkb */ ,
740 unsigned /* merge */ ,
741 SymbolsInfo * /* included */
745 HandleIncludeSymbols(IncludeStmt * stmt,
746 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
750 SymbolsInfo included;
754 if ((stmt->file == NULL) && (stmt->map == NULL))
758 memset(info, 0, sizeof(SymbolsInfo));
760 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
762 InitSymbolsInfo(&included, xkb);
763 included.fileID = included.dflt.defs.fileID = rtrn->id;
764 included.merge = included.dflt.defs.merge = MergeOverride;
767 included.explicit_group = atoi(stmt->modifier) - 1;
771 included.explicit_group = info->explicit_group;
773 (*hndlr) (rtrn, xkb, MergeOverride, &included);
774 if (stmt->stmt != NULL)
777 included.name = stmt->stmt;
784 info->errorCount += 10;
787 if ((stmt->next != NULL) && (included.errorCount < 1))
791 SymbolsInfo next_incl;
793 for (next = stmt->next; next != NULL; next = next->next)
795 if ((next->file == NULL) && (next->map == NULL))
798 MergeIncludedSymbols(&included, info, next->merge, xkb);
799 FreeSymbolsInfo(info);
801 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
803 InitSymbolsInfo(&next_incl, xkb);
804 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
805 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
808 next_incl.explicit_group = atoi(next->modifier) - 1;
812 next_incl.explicit_group = info->explicit_group;
814 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
815 MergeIncludedSymbols(&included, &next_incl, op, xkb);
816 FreeSymbolsInfo(&next_incl);
821 info->errorCount += 10;
830 MergeIncludedSymbols(info, &included, newMerge, xkb);
831 FreeSymbolsInfo(&included);
833 return (info->errorCount == 0);
840 GetGroupIndex(KeyInfo * key,
841 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
851 if (arrayNdx == NULL)
856 defined = key->symsDefined;
858 defined = key->actsDefined;
860 for (i = 0; i < XkbNumKbdGroups; i++)
862 if ((defined & (1 << i)) == 0)
868 ERROR("Too many groups of %s for key %s (max %d)\n", name,
869 longText(key->name), XkbNumKbdGroups + 1);
870 ACTION("Ignoring %s defined for extra groups\n", name);
873 if (!ExprResolveGroup(arrayNdx, &tmp))
875 ERROR("Illegal group index for %s of key %s\n", name,
876 longText(key->name));
877 ACTION("Definition with non-integer array index ignored\n");
880 *ndx_rtrn = tmp.uval - 1;
885 AddSymbolsToKey(KeyInfo * key,
886 struct xkb_desc * xkb,
888 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
894 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
898 key->symsDefined |= (1 << ndx);
901 if (value->op != ExprKeysymList)
903 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
904 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
905 longText(key->name));
908 if (key->syms[ndx] != NULL)
910 ERROR("Symbols for key %s, group %d already defined\n",
911 longText(key->name), ndx + 1);
912 ACTION("Ignoring duplicate definition\n");
915 nSyms = value->value.list.nSyms;
916 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
917 (!ResizeKeyGroup(key, ndx, nSyms, False)))
919 WSGO("Could not resize group %d of key %s to contain %d levels\n",
920 ndx + 1, longText(key->name), nSyms);
921 ACTION("Symbols lost\n");
924 key->symsDefined |= (1 << ndx);
925 for (i = 0; i < nSyms; i++) {
926 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
927 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
928 value->value.list.syms[i], longText(key->name), ndx + 1,
929 XkbcAtomText(info->groupNames[ndx]), nSyms);
930 key->syms[ndx][i] = XKB_KEYSYM_NO_SYMBOL;
933 for (j = key->numLevels[ndx] - 1;
934 (j >= 0) && (key->syms[ndx][j] == XKB_KEYSYM_NO_SYMBOL); j--)
936 key->numLevels[ndx]--;
942 AddActionsToKey(KeyInfo * key,
943 struct xkb_desc * xkb,
945 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
950 struct xkb_any_action *toAct;
952 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
957 key->actsDefined |= (1 << ndx);
960 if (value->op != ExprActionList)
962 WSGO("Bad expression type (%d) for action list value\n", value->op);
963 ACTION("Ignoring actions for group %d of %s\n", ndx,
964 longText(key->name));
967 if (key->acts[ndx] != NULL)
969 WSGO("Actions for key %s, group %d already defined\n",
970 longText(key->name), ndx);
973 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
975 act = (ExprDef *) act->common.next;
979 WSGO("Action list but not actions in AddActionsToKey\n");
982 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
983 (!ResizeKeyGroup(key, ndx, nActs, True)))
985 WSGO("Could not resize group %d of key %s\n", ndx,
986 longText(key->name));
987 ACTION("Actions lost\n");
990 key->actsDefined |= (1 << ndx);
992 toAct = (struct xkb_any_action *) key->acts[ndx];
993 act = value->value.child;
994 for (i = 0; i < nActs; i++, toAct++)
996 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
998 ERROR("Illegal action definition for %s\n",
999 longText(key->name));
1000 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1002 act = (ExprDef *) act->common.next;
1007 static const LookupEntry lockingEntries[] = {
1008 {"true", XkbKB_Lock},
1009 {"yes", XkbKB_Lock},
1011 {"false", XkbKB_Default},
1012 {"no", XkbKB_Default},
1013 {"off", XkbKB_Default},
1014 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1018 static const LookupEntry repeatEntries[] = {
1019 {"true", RepeatYes},
1022 {"false", RepeatNo},
1025 {"default", RepeatUndefined},
1030 SetSymbolsField(KeyInfo * key,
1031 struct xkb_desc * xkb,
1033 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1038 if (strcasecmp(field, "type") == 0)
1041 if ((!ExprResolveString(value, &tmp))
1042 && (warningLevel > 0))
1044 WARN("The type field of a key symbol map must be a string\n");
1045 ACTION("Ignoring illegal type definition\n");
1047 if (arrayNdx == NULL)
1049 key->dfltType = xkb_intern_atom(tmp.str);
1050 key->defs.defined |= _Key_Type_Dflt;
1052 else if (!ExprResolveGroup(arrayNdx, &ndx))
1054 ERROR("Illegal group index for type of key %s\n",
1055 longText(key->name));
1056 ACTION("Definition with non-integer array index ignored\n");
1062 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1063 key->typesDefined |= (1 << (ndx.uval - 1));
1067 else if (strcasecmp(field, "symbols") == 0)
1068 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1069 else if (strcasecmp(field, "actions") == 0)
1070 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1071 else if ((strcasecmp(field, "vmods") == 0) ||
1072 (strcasecmp(field, "virtualmods") == 0) ||
1073 (strcasecmp(field, "virtualmodifiers") == 0))
1075 ok = ExprResolveVModMask(value, &tmp, xkb);
1078 key->vmodmap = (tmp.uval >> 8);
1079 key->defs.defined |= _Key_VModMap;
1083 ERROR("Expected a virtual modifier mask, found %s\n",
1084 exprOpText(value->op));
1085 ACTION("Ignoring virtual modifiers definition for key %s\n",
1086 longText(key->name));
1089 else if ((strcasecmp(field, "locking") == 0) ||
1090 (strcasecmp(field, "lock") == 0) ||
1091 (strcasecmp(field, "locks") == 0))
1093 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1095 key->behavior.type = tmp.uval;
1096 key->defs.defined |= _Key_Behavior;
1098 else if ((strcasecmp(field, "radiogroup") == 0) ||
1099 (strcasecmp(field, "permanentradiogroup") == 0) ||
1100 (strcasecmp(field, "allownone") == 0))
1102 ERROR("Radio groups not supported\n");
1103 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1106 else if (uStrCasePrefix("overlay", field) ||
1107 uStrCasePrefix("permanentoverlay", field))
1109 ERROR("Overlays not supported\n");
1110 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1112 else if ((strcasecmp(field, "repeating") == 0) ||
1113 (strcasecmp(field, "repeats") == 0) ||
1114 (strcasecmp(field, "repeat") == 0))
1116 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1119 ERROR("Illegal repeat setting for %s\n",
1120 longText(key->name));
1121 ACTION("Non-boolean repeat setting ignored\n");
1124 key->repeat = tmp.uval;
1125 key->defs.defined |= _Key_Repeat;
1127 else if ((strcasecmp(field, "groupswrap") == 0) ||
1128 (strcasecmp(field, "wrapgroups") == 0))
1130 ok = ExprResolveBoolean(value, &tmp);
1133 ERROR("Illegal groupsWrap setting for %s\n",
1134 longText(key->name));
1135 ACTION("Non-boolean value ignored\n");
1139 key->groupInfo = XkbWrapIntoRange;
1141 key->groupInfo = XkbClampIntoRange;
1142 key->defs.defined |= _Key_GroupInfo;
1144 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1145 (strcasecmp(field, "clampgroups") == 0))
1147 ok = ExprResolveBoolean(value, &tmp);
1150 ERROR("Illegal groupsClamp setting for %s\n",
1151 longText(key->name));
1152 ACTION("Non-boolean value ignored\n");
1156 key->groupInfo = XkbClampIntoRange;
1158 key->groupInfo = XkbWrapIntoRange;
1159 key->defs.defined |= _Key_GroupInfo;
1161 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1162 (strcasecmp(field, "redirectgroups") == 0))
1164 if (!ExprResolveGroup(value, &tmp))
1166 ERROR("Illegal group index for redirect of key %s\n",
1167 longText(key->name));
1168 ACTION("Definition with non-integer group ignored\n");
1172 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1173 key->defs.defined |= _Key_GroupInfo;
1177 ERROR("Unknown field %s in a symbol interpretation\n", field);
1178 ACTION("Definition ignored\n");
1185 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1187 ExprResult tmp, name;
1189 if ((arrayNdx == NULL) && (warningLevel > 0))
1191 WARN("You must specify an index when specifying a group name\n");
1192 ACTION("Group name definition without array subscript ignored\n");
1195 if (!ExprResolveGroup(arrayNdx, &tmp))
1197 ERROR("Illegal index in group name definition\n");
1198 ACTION("Definition with non-integer array index ignored\n");
1201 if (!ExprResolveString(value, &name))
1203 ERROR("Group name must be a string\n");
1204 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1207 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1208 xkb_intern_atom(name.str);
1215 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1217 ExprResult elem, field, tmp;
1221 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1222 return 0; /* internal error, already reported */
1223 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1225 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1228 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1229 (strcasecmp(field.str, "groupname") ==
1232 ret = SetGroupName(info, arrayNdx, stmt->value);
1234 else if ((elem.str == NULL)
1235 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1236 (strcasecmp(field.str, "wrapgroups") == 0)))
1238 if (!ExprResolveBoolean(stmt->value, &tmp))
1240 ERROR("Illegal setting for global groupsWrap\n");
1241 ACTION("Non-boolean value ignored\n");
1246 info->groupInfo = XkbWrapIntoRange;
1248 info->groupInfo = XkbClampIntoRange;
1252 else if ((elem.str == NULL)
1253 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1254 (strcasecmp(field.str, "clampgroups") == 0)))
1256 if (!ExprResolveBoolean(stmt->value, &tmp))
1258 ERROR("Illegal setting for global groupsClamp\n");
1259 ACTION("Non-boolean value ignored\n");
1264 info->groupInfo = XkbClampIntoRange;
1266 info->groupInfo = XkbWrapIntoRange;
1270 else if ((elem.str == NULL)
1271 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1272 (strcasecmp(field.str, "redirectgroups") == 0)))
1274 if (!ExprResolveGroup(stmt->value, &tmp))
1276 ERROR("Illegal group index for global groupsRedirect\n");
1277 ACTION("Definition with non-integer group ignored\n");
1281 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1286 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1288 ERROR("Radio groups not supported\n");
1289 ACTION("Ignoring \"allow none\" specification\n");
1293 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1303 HandleSymbolsBody(VarDef * def,
1304 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1307 ExprResult tmp, field;
1310 for (; def != NULL; def = (VarDef *) def->common.next)
1312 if ((def->name) && (def->name->type == ExprFieldRef))
1314 ok = HandleSymbolsVar(def, xkb, info);
1319 if (def->name == NULL)
1321 if ((def->value == NULL)
1322 || (def->value->op == ExprKeysymList))
1323 field.str = strdup("symbols");
1325 field.str = strdup("actions");
1330 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1333 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1342 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1344 unsigned group = info->explicit_group;
1349 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1352 WARN("For the map %s an explicit group specified\n", info->name);
1353 WARN("but key %s has more than one group defined\n",
1354 longText(key->name));
1355 ACTION("All groups except first one will be ignored\n");
1356 for (i = 1; i < XkbNumKbdGroups; i++)
1358 key->numLevels[i] = 0;
1360 key->syms[i] = NULL;
1362 key->acts[i] = NULL;
1366 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1368 key->numLevels[group] = key->numLevels[0];
1369 key->numLevels[0] = 0;
1370 key->syms[group] = key->syms[0];
1371 key->syms[0] = NULL;
1372 key->acts[group] = key->acts[0];
1373 key->acts[0] = NULL;
1374 key->types[group] = key->types[0];
1380 HandleSymbolsDef(SymbolsDef * stmt,
1381 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1386 CopyKeyInfo(&info->dflt, &key, False);
1387 key.defs.merge = stmt->merge;
1388 key.name = KeyNameToLong(stmt->keyName);
1389 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1395 if (!SetExplicitGroup(info, &key))
1401 if (!AddKeySymbols(info, &key, xkb))
1410 HandleModMapDef(ModMapDef * def,
1411 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1418 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1420 ERROR("Illegal modifier map definition\n");
1421 ACTION("Ignoring map for non-modifier \"%s\"\n",
1422 XkbcAtomText(def->modifier));
1426 tmp.modifier = rtrn.uval;
1427 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1429 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1431 tmp.haveSymbol = False;
1432 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1434 else if (ExprResolveKeySym(key, &rtrn))
1436 tmp.haveSymbol = True;
1437 tmp.u.keySym = rtrn.uval;
1441 ERROR("Modmap entries may contain only key names or keysyms\n");
1442 ACTION("Illegal definition for %s modifier ignored\n",
1443 XkbcModIndexText(tmp.modifier));
1447 ok = AddModMapEntry(info, &tmp) && ok;
1453 HandleSymbolsFile(XkbFile * file,
1454 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1459 info->name = uDupString(file->name);
1463 switch (stmt->stmtType)
1466 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1470 case StmtSymbolsDef:
1471 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1475 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1479 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1483 ERROR("Interpretation files may not include other types\n");
1484 ACTION("Ignoring definition of symbol interpretation\n");
1487 case StmtKeycodeDef:
1488 ERROR("Interpretation files may not include other types\n");
1489 ACTION("Ignoring definition of key name\n");
1493 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1497 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1502 if (info->errorCount > 10)
1505 ERROR("Too many errors\n");
1507 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1514 FindKeyForSymbol(struct xkb_desc * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1523 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1525 if (j < (int) XkbKeyNumSyms(xkb, i))
1528 if (XkbKeySym(xkb, i, j) == sym)
1542 * Find the given name in the xkb->map->types and return its index.
1544 * @param atom The atom to search for.
1545 * @param type_rtrn Set to the index of the name if found.
1547 * @return True if found, False otherwise.
1550 FindNamedType(struct xkb_desc * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1553 const char *name = XkbcAtomText(atom);
1555 if (xkb && xkb->map && xkb->map->types)
1557 for (n = 0; n < xkb->map->num_types; n++)
1559 if (strcmp(xkb->map->types[n].name, name) == 0)
1570 * Assign a type to the given sym and return the Atom for the type assigned.
1573 * - ONE_LEVEL for width 0/1
1574 * - ALPHABETIC for 2 shift levels, with lower/upercase
1575 * - KEYPAD for keypad keys.
1576 * - TWO_LEVEL for other 2 shift level keys.
1577 * and the same for four level keys.
1579 * @param width Number of sysms in syms.
1580 * @param syms The keysyms for the given key (must be size width).
1581 * @param typeNameRtrn Set to the Atom of the type name.
1583 * @returns True if a type could be found, False otherwise.
1586 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1590 if ((width == 1) || (width == 0))
1592 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1595 else if (width == 2)
1597 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1599 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1601 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1603 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1608 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1612 else if (width <= 4)
1614 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1615 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1617 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1619 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1621 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1622 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1624 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1625 /* XXX: why not set autoType here? */
1627 return ((width >= 0) && (width <= 4));
1631 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1632 * groups, and reduce to one group if all groups are identical anyway.
1635 PrepareKeyDef(KeyInfo * key)
1637 int i, j, width, defined, lastGroup;
1640 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1641 /* get highest group number */
1642 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1644 if (defined & (1 << i))
1652 /* If there are empty groups between non-empty ones fill them with data */
1653 /* from the first group. */
1654 /* We can make a wrong assumption here. But leaving gaps is worse. */
1655 for (i = lastGroup; i > 0; i--)
1657 if (defined & (1 << i))
1659 width = key->numLevels[0];
1660 if (key->typesDefined & 1)
1662 for (j = 0; j < width; j++)
1664 key->types[i] = key->types[0];
1666 key->typesDefined |= 1 << i;
1668 if ((key->actsDefined & 1) && key->acts[0])
1670 key->acts[i] = uTypedCalloc(width, union xkb_action);
1671 if (key->acts[i] == NULL)
1673 memcpy(key->acts[i], key->acts[0],
1674 width * sizeof(union xkb_action));
1675 key->actsDefined |= 1 << i;
1677 if ((key->symsDefined & 1) && key->syms[0])
1679 key->syms[i] = uTypedCalloc(width, xkb_keysym_t);
1680 if (key->syms[i] == NULL)
1682 memcpy(key->syms[i], key->syms[0], width * sizeof(xkb_keysym_t));
1683 key->symsDefined |= 1 << i;
1687 key->numLevels[i] = key->numLevels[0];
1690 /* If all groups are completely identical remove them all */
1691 /* exept the first one. */
1693 for (i = lastGroup; i > 0; i--)
1695 if ((key->numLevels[i] != key->numLevels[0]) ||
1696 (key->types[i] != key->types[0]))
1701 if ((key->syms[i] != key->syms[0]) &&
1702 (key->syms[i] == NULL || key->syms[0] == NULL ||
1703 memcmp(key->syms[i], key->syms[0],
1704 sizeof(xkb_keysym_t) * key->numLevels[0])))
1709 if ((key->acts[i] != key->acts[0]) &&
1710 (key->acts[i] == NULL || key->acts[0] == NULL ||
1711 memcmp(key->acts[i], key->acts[0],
1712 sizeof(union xkb_action) * key->numLevels[0])))
1720 for (i = lastGroup; i > 0; i--)
1722 key->numLevels[i] = 0;
1724 key->syms[i] = NULL;
1726 key->acts[i] = NULL;
1729 key->symsDefined &= 1;
1730 key->actsDefined &= 1;
1731 key->typesDefined &= 1;
1736 * Copy the KeyInfo into the keyboard description.
1738 * This function recurses.
1741 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1745 unsigned width, tmp, nGroups;
1746 struct xkb_key_type * type;
1747 Bool haveActions, autoType, useAlias;
1748 xkb_keysym_t *outSyms;
1749 union xkb_action *outActs;
1750 unsigned types[XkbNumKbdGroups];
1752 useAlias = (start_from == 0);
1754 /* get the keycode for the key. */
1755 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1758 if ((start_from == 0) && (warningLevel >= 5))
1760 WARN("Key %s not found in keycodes\n", longText(key->name));
1761 ACTION("Symbols ignored\n");
1766 haveActions = False;
1767 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1769 if (((i + 1) > nGroups)
1770 && (((key->symsDefined | key->actsDefined) & (1 << i))
1771 || (key->typesDefined) & (1 << i)))
1776 /* Assign the type to the key, if it is missing. */
1777 if (key->types[i] == XKB_ATOM_NONE)
1779 if (key->dfltType != XKB_ATOM_NONE)
1780 key->types[i] = key->dfltType;
1781 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1782 &key->types[i], &autoType))
1787 if (warningLevel >= 5)
1789 WARN("No automatic type for %d symbols\n",
1790 (unsigned int) key->numLevels[i]);
1791 ACTION("Using %s for the %s key (keycode %d)\n",
1792 XkbcAtomText(key->types[i]),
1793 longText(key->name), kc);
1797 if (FindNamedType(xkb, key->types[i], &types[i]))
1799 if (!autoType || key->numLevels[i] > 2)
1800 xkb->server->explicit[kc] |= (1 << i);
1804 if (warningLevel >= 3)
1806 WARN("Type \"%s\" is not defined\n",
1807 XkbcAtomText(key->types[i]));
1808 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1809 longText(key->name), kc);
1811 types[i] = XkbTwoLevelIndex;
1813 /* if the type specifies less syms than the key has, shrink the key */
1814 type = &xkb->map->types[types[i]];
1815 if (type->num_levels < key->numLevels[i])
1817 if (warningLevel > 0)
1819 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
1820 type->name, type->num_levels,
1821 XkbcAtomText(key->name), key->numLevels[i]);
1822 ACTION("Ignoring extra symbols\n");
1824 key->numLevels[i] = type->num_levels;
1826 if (key->numLevels[i] > width)
1827 width = key->numLevels[i];
1828 if (type->num_levels > width)
1829 width = type->num_levels;
1832 /* width is now the largest width found */
1834 i = width * nGroups;
1835 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1836 if (outSyms == NULL)
1838 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1839 longText(key->name), kc);
1844 outActs = XkbcResizeKeyActions(xkb, kc, i);
1845 if (outActs == NULL)
1847 WSGO("Could not enlarge actions for %s (key %d)\n",
1848 longText(key->name), kc);
1851 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1855 if (key->defs.defined & _Key_GroupInfo)
1858 i = xkb->map->key_sym_map[kc].group_info;
1860 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1861 xkb->map->key_sym_map[kc].width = width;
1862 for (i = 0; i < nGroups; i++)
1864 /* assign kt_index[i] to the index of the type in map->types.
1865 * kt_index[i] may have been set by a previous run (if we have two
1866 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1867 * default group if we dont even have keys for this group anyway.
1869 * FIXME: There should be a better fix for this.
1871 if (key->numLevels[i])
1872 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
1873 if (key->syms[i] != NULL)
1875 /* fill key to "width" symbols*/
1876 for (tmp = 0; tmp < width; tmp++)
1878 if (tmp < key->numLevels[i])
1879 outSyms[tmp] = key->syms[i][tmp];
1881 outSyms[tmp] = XKB_KEYSYM_NO_SYMBOL;
1882 if ((outActs != NULL) && (key->acts[i] != NULL))
1884 if (tmp < key->numLevels[i])
1885 outActs[tmp] = key->acts[i][tmp];
1887 outActs[tmp].type = XkbSA_NoAction;
1895 switch (key->behavior.type & XkbKB_OpMask)
1900 xkb->server->behaviors[kc] = key->behavior;
1901 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
1904 if (key->defs.defined & _Key_VModMap)
1906 xkb->server->vmodmap[kc] = key->vmodmap;
1907 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
1909 if (key->repeat != RepeatUndefined)
1911 if (key->repeat == RepeatYes)
1912 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
1914 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
1915 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
1918 if (nGroups > xkb->ctrls->num_groups)
1919 xkb->ctrls->num_groups = nGroups;
1921 /* do the same thing for the next key */
1922 CopySymbolsDef(xkb, key, kc + 1);
1927 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
1931 if ((!entry->haveSymbol)
1934 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
1936 if (warningLevel >= 5)
1938 WARN("Key %s not found in keycodes\n",
1939 longText(entry->u.keyName));
1940 ACTION("Modifier map entry for %s not updated\n",
1941 XkbcModIndexText(entry->modifier));
1945 else if (entry->haveSymbol
1946 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
1948 if (warningLevel > 5)
1950 WARN("Key \"%s\" not found in symbol map\n",
1951 XkbcKeysymText(entry->u.keySym));
1952 ACTION("Modifier map entry for %s not updated\n",
1953 XkbcModIndexText(entry->modifier));
1957 xkb->map->modmap[kc] |= (1 << entry->modifier);
1962 * Handle the xkb_symbols section of an xkb file.
1964 * @param file The parsed xkb_symbols section of the xkb file.
1965 * @param xkb Handle to the keyboard description to store the symbols in.
1966 * @param merge Merge strategy (e.g. MergeOverride).
1969 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
1974 InitSymbolsInfo(&info, xkb);
1975 info.dflt.defs.fileID = file->id;
1976 info.dflt.defs.merge = merge;
1977 HandleSymbolsFile(file, xkb, merge, &info);
1979 if (info.nKeys == 0) {
1980 FreeSymbolsInfo(&info);
1984 if (info.errorCount == 0)
1988 /* alloc memory in the xkb struct */
1989 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
1991 WSGO("Can not allocate names in CompileSymbols\n");
1992 ACTION("Symbols not added\n");
1995 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
1998 WSGO("Could not allocate client map in CompileSymbols\n");
1999 ACTION("Symbols not added\n");
2002 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2004 WSGO("Could not allocate server map in CompileSymbols\n");
2005 ACTION("Symbols not added\n");
2008 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2010 WSGO("Could not allocate controls in CompileSymbols\n");
2011 ACTION("Symbols not added\n");
2015 /* now copy info into xkb. */
2017 ApplyAliases(xkb, &info.aliases);
2018 for (i = 0; i < XkbNumKbdGroups; i++)
2020 if (info.groupNames[i] != XKB_ATOM_NONE)
2022 free(UNCONSTIFY(xkb->names->groups[i]));
2023 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2027 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2032 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2034 if (!CopySymbolsDef(xkb, key, 0))
2037 if (warningLevel > 3)
2039 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2041 if (xkb->names->keys[i].name[0] == '\0')
2043 if (XkbKeyNumGroups(xkb, i) < 1)
2046 memcpy(buf, xkb->names->keys[i].name, 4);
2049 ("No symbols defined for <%s> (keycode %d)\n",
2056 ModMapEntry *mm, *next;
2057 for (mm = info.modMap; mm != NULL; mm = next)
2059 if (!CopyModMapDef(xkb, mm))
2061 next = (ModMapEntry *) mm->defs.next;
2064 FreeSymbolsInfo(&info);
2068 FreeSymbolsInfo(&info);