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 short 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 nameForOverlayKey;
74 unsigned long allowNone;
79 * Init the given key info to sane values.
82 InitKeyInfo(KeyInfo * info)
85 static char dflt[4] = "*";
87 info->defs.defined = 0;
88 info->defs.fileID = 0;
89 info->defs.merge = MergeOverride;
90 info->defs.next = NULL;
91 info->name = KeyNameToLong(dflt);
93 info->typesDefined = info->symsDefined = info->actsDefined = 0;
94 for (i = 0; i < XkbNumKbdGroups; i++)
96 info->numLevels[i] = 0;
97 info->types[i] = None;
101 info->dfltType = None;
102 info->behavior.type = XkbKB_Default;
103 info->behavior.data = 0;
105 info->nameForOverlayKey = 0;
106 info->repeat = RepeatUndefined;
111 * Free memory associated with this key info and reset to sane values.
114 FreeKeyInfo(KeyInfo * info)
118 info->defs.defined = 0;
119 info->defs.fileID = 0;
120 info->defs.merge = MergeOverride;
121 info->defs.next = NULL;
123 info->typesDefined = info->symsDefined = info->actsDefined = 0;
124 for (i = 0; i < XkbNumKbdGroups; i++)
126 info->numLevels[i] = 0;
127 info->types[i] = None;
129 info->syms[i] = NULL;
131 info->acts[i] = NULL;
133 info->dfltType = None;
134 info->behavior.type = XkbKB_Default;
135 info->behavior.data = 0;
137 info->nameForOverlayKey = 0;
138 info->repeat = RepeatUndefined;
143 * Copy old into new, optionally reset old to 0.
144 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
145 * newly allocated and new points to the new memory areas.
148 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
153 new->defs.next = NULL;
156 for (i = 0; i < XkbNumKbdGroups; i++)
158 old->numLevels[i] = 0;
166 for (i = 0; i < XkbNumKbdGroups; i++)
168 width = new->numLevels[i];
169 if (old->syms[i] != NULL)
171 new->syms[i] = uTypedCalloc(width, xkb_keysym_t);
175 new->numLevels[i] = 0;
178 memcpy(new->syms[i], old->syms[i], width * sizeof(xkb_keysym_t));
180 if (old->acts[i] != NULL)
182 new->acts[i] = uTypedCalloc(width, union xkb_action);
188 memcpy(new->acts[i], old->acts[i],
189 width * sizeof(union xkb_action));
196 /***====================================================================***/
198 typedef struct _ModMapEntry
205 unsigned long keyName;
210 #define SYMBOLS_INIT_SIZE 110
211 #define SYMBOLS_CHUNK 20
212 typedef struct _SymbolsInfo
214 char *name; /* e.g. pc+us+inet(evdev) */
218 unsigned explicit_group;
226 xkb_atom_t groupNames[XkbNumKbdGroups];
233 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
238 info->explicit_group = 0;
239 info->errorCount = 0;
241 info->merge = MergeOverride;
243 info->szKeys = SYMBOLS_INIT_SIZE;
245 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
247 for (i = 0; i < XkbNumKbdGroups; i++)
248 info->groupNames[i] = None;
249 InitKeyInfo(&info->dflt);
250 InitVModInfo(&info->vmods, xkb);
252 info->aliases = NULL;
256 FreeSymbolsInfo(SymbolsInfo * info)
263 for (i = 0; i < info->nKeys; i++)
264 FreeKeyInfo(&info->keys[i]);
268 ClearCommonInfo(&info->modMap->defs);
270 ClearAliases(&info->aliases);
271 memset(info, 0, sizeof(SymbolsInfo));
275 ResizeKeyGroup(KeyInfo * key,
276 unsigned group, unsigned atLeastSize, Bool forceActions)
281 tooSmall = (key->numLevels[group] < atLeastSize);
283 newWidth = atLeastSize;
285 newWidth = key->numLevels[group];
287 if ((key->syms[group] == NULL) || tooSmall)
289 key->syms[group] = uTypedRecalloc(key->syms[group],
290 key->numLevels[group], newWidth,
292 if (!key->syms[group])
295 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
296 (tooSmall && (key->acts[group] != NULL)))
298 key->acts[group] = uTypedRecalloc(key->acts[group],
299 key->numLevels[group], newWidth,
301 if (!key->acts[group])
304 key->numLevels[group] = newWidth;
309 MergeKeyGroups(SymbolsInfo * info,
310 KeyInfo * into, KeyInfo * from, unsigned group)
312 xkb_keysym_t *resultSyms;
313 union xkb_action *resultActs;
316 Bool report, clobber;
318 clobber = (from->defs.merge != MergeAugment);
319 report = (warningLevel > 9) ||
320 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
321 if (into->numLevels[group] >= from->numLevels[group])
323 resultSyms = into->syms[group];
324 resultActs = into->acts[group];
325 resultWidth = into->numLevels[group];
329 resultSyms = from->syms[group];
330 resultActs = from->acts[group];
331 resultWidth = from->numLevels[group];
333 if (resultSyms == NULL)
335 resultSyms = uTypedCalloc(resultWidth, xkb_keysym_t);
338 WSGO("Could not allocate symbols for group merge\n");
339 ACTION("Group %d of key %s not merged\n", group,
340 longText(into->name));
344 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
346 resultActs = uTypedCalloc(resultWidth, union xkb_action);
349 WSGO("Could not allocate actions for group merge\n");
350 ACTION("Group %d of key %s not merged\n", group,
351 longText(into->name));
352 if (resultSyms != into->syms[group] &&
353 resultSyms != from->syms[group])
358 for (i = 0; i < resultWidth; i++)
360 xkb_keysym_t fromSym, toSym;
361 if (from->syms[group] && (i < from->numLevels[group]))
362 fromSym = from->syms[group][i];
365 if (into->syms[group] && (i < into->numLevels[group]))
366 toSym = into->syms[group][i];
369 if ((fromSym == NoSymbol) || (fromSym == toSym))
370 resultSyms[i] = toSym;
371 else if (toSym == NoSymbol)
372 resultSyms[i] = fromSym;
375 xkb_keysym_t use, ignore;
389 ("Multiple symbols for level %d/group %d on key %s\n",
390 i + 1, group + 1, longText(into->name));
391 ACTION("Using %s, ignoring %s\n",
392 XkbcKeysymText(use), XkbcKeysymText(ignore));
396 if (resultActs != NULL)
398 union xkb_action *fromAct, *toAct;
399 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
400 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
401 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
404 resultActs[i] = *toAct;
406 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
407 && (fromAct != NULL))
409 resultActs[i] = *fromAct;
413 union xkb_action *use, *ignore;
427 ("Multiple actions for level %d/group %d on key %s\n",
428 i + 1, group + 1, longText(into->name));
429 ACTION("Using %s, ignoring %s\n",
430 XkbcActionTypeText(use->type),
431 XkbcActionTypeText(ignore->type));
434 resultActs[i] = *use;
438 if (resultSyms != into->syms[group])
439 free(into->syms[group]);
440 if (resultSyms != from->syms[group])
441 free(from->syms[group]);
442 if (resultActs != into->acts[group])
443 free(into->acts[group]);
444 if (resultActs != from->acts[group])
445 free(from->acts[group]);
446 into->numLevels[group] = resultWidth;
447 into->syms[group] = resultSyms;
448 from->syms[group] = NULL;
449 into->acts[group] = resultActs;
450 from->acts[group] = NULL;
451 into->symsDefined |= (1 << group);
452 from->symsDefined &= ~(1 << group);
453 into->actsDefined |= (1 << group);
454 from->actsDefined &= ~(1 << group);
459 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
462 unsigned collide = 0;
465 if (from->defs.merge == MergeReplace)
467 for (i = 0; i < XkbNumKbdGroups; i++)
469 if (into->numLevels[i] != 0)
476 memset(from, 0, sizeof(KeyInfo));
479 report = ((warningLevel > 9) ||
480 ((into->defs.fileID == from->defs.fileID)
481 && (warningLevel > 0)));
482 for (i = 0; i < XkbNumKbdGroups; i++)
484 if (from->numLevels[i] > 0)
486 if (into->numLevels[i] == 0)
488 into->numLevels[i] = from->numLevels[i];
489 into->syms[i] = from->syms[i];
490 into->acts[i] = from->acts[i];
491 into->symsDefined |= (1 << i);
492 from->syms[i] = NULL;
493 from->acts[i] = NULL;
494 from->numLevels[i] = 0;
495 from->symsDefined &= ~(1 << i);
497 into->defs.defined |= _Key_Syms;
499 into->defs.defined |= _Key_Acts;
506 collide |= _Key_Syms;
508 collide |= _Key_Acts;
510 MergeKeyGroups(info, into, from, (unsigned) i);
513 if (from->types[i] != None)
515 if ((into->types[i] != None) && (report) &&
516 (into->types[i] != from->types[i]))
518 xkb_atom_t use, ignore;
519 collide |= _Key_Types;
520 if (from->defs.merge != MergeAugment)
522 use = from->types[i];
523 ignore = into->types[i];
527 use = into->types[i];
528 ignore = from->types[i];
531 ("Multiple definitions for group %d type of key %s\n",
532 i, longText(into->name));
533 ACTION("Using %s, ignoring %s\n",
535 XkbcAtomText(ignore));
537 if ((from->defs.merge != MergeAugment)
538 || (into->types[i] == None))
540 into->types[i] = from->types[i];
544 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
546 into->behavior = from->behavior;
547 into->nameForOverlayKey = from->nameForOverlayKey;
548 into->defs.defined |= _Key_Behavior;
550 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
552 into->vmodmap = from->vmodmap;
553 into->defs.defined |= _Key_VModMap;
555 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
557 into->repeat = from->repeat;
558 into->defs.defined |= _Key_Repeat;
560 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
562 into->dfltType = from->dfltType;
563 into->defs.defined |= _Key_Type_Dflt;
565 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
567 into->groupInfo = from->groupInfo;
568 into->defs.defined |= _Key_GroupInfo;
572 WARN("Symbol map for key %s redefined\n",
573 longText(into->name));
574 ACTION("Using %s definition for conflicting fields\n",
575 (from->defs.merge == MergeAugment ? "first" : "last"));
581 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
584 unsigned long real_name;
586 for (i = 0; i < info->nKeys; i++)
588 if (info->keys[i].name == key->name)
589 return MergeKeys(info, &info->keys[i], key);
591 if (FindKeyNameForAlias(xkb, key->name, &real_name))
593 for (i = 0; i < info->nKeys; i++)
595 if (info->keys[i].name == real_name)
596 return MergeKeys(info, &info->keys[i], key);
599 if (info->nKeys >= info->szKeys)
601 info->szKeys += SYMBOLS_CHUNK;
603 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
606 WSGO("Could not allocate key symbols descriptions\n");
607 ACTION("Some key symbols definitions may be lost\n");
611 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
615 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
620 clobber = (new->defs.merge != MergeAugment);
621 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
623 if (new->haveSymbol && mm->haveSymbol
624 && (new->u.keySym == mm->u.keySym))
626 unsigned use, ignore;
627 if (mm->modifier != new->modifier)
632 ignore = mm->modifier;
637 ignore = new->modifier;
640 ("%s added to symbol map for multiple modifiers\n",
641 XkbcKeysymText(new->u.keySym));
642 ACTION("Using %s, ignoring %s.\n",
643 XkbcModIndexText(use),
644 XkbcModIndexText(ignore));
649 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
650 (new->u.keyName == mm->u.keyName))
652 unsigned use, ignore;
653 if (mm->modifier != new->modifier)
658 ignore = mm->modifier;
663 ignore = new->modifier;
665 ERROR("Key %s added to map for multiple modifiers\n",
666 longText(new->u.keyName));
667 ACTION("Using %s, ignoring %s.\n",
668 XkbcModIndexText(use),
669 XkbcModIndexText(ignore));
675 mm = uTypedAlloc(ModMapEntry);
678 WSGO("Could not allocate modifier map entry\n");
679 ACTION("Modifier map for %s will be incomplete\n",
680 XkbcModIndexText(new->modifier));
684 mm->defs.next = &info->modMap->defs;
689 /***====================================================================***/
692 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
693 unsigned merge, struct xkb_desc * xkb)
698 if (from->errorCount > 0)
700 into->errorCount += from->errorCount;
703 if (into->name == NULL)
705 into->name = from->name;
708 for (i = 0; i < XkbNumKbdGroups; i++)
710 if (from->groupNames[i] != None)
712 if ((merge != MergeAugment) || (into->groupNames[i] == None))
713 into->groupNames[i] = from->groupNames[i];
716 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
718 if (merge != MergeDefault)
719 key->defs.merge = merge;
720 if (!AddKeySymbols(into, key, xkb))
723 if (from->modMap != NULL)
725 ModMapEntry *mm, *next;
726 for (mm = from->modMap; mm != NULL; mm = next)
728 if (merge != MergeDefault)
729 mm->defs.merge = merge;
730 if (!AddModMapEntry(into, mm))
732 next = (ModMapEntry *) mm->defs.next;
737 if (!MergeAliases(&into->aliases, &from->aliases, merge))
741 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
742 struct xkb_desc * /* xkb */ ,
743 unsigned /* merge */ ,
744 SymbolsInfo * /* included */
748 HandleIncludeSymbols(IncludeStmt * stmt,
749 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
753 SymbolsInfo included;
757 if ((stmt->file == NULL) && (stmt->map == NULL))
761 memset(info, 0, sizeof(SymbolsInfo));
763 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
765 InitSymbolsInfo(&included, xkb);
766 included.fileID = included.dflt.defs.fileID = rtrn->id;
767 included.merge = included.dflt.defs.merge = MergeOverride;
770 included.explicit_group = atoi(stmt->modifier) - 1;
774 included.explicit_group = info->explicit_group;
776 (*hndlr) (rtrn, xkb, MergeOverride, &included);
777 if (stmt->stmt != NULL)
780 included.name = stmt->stmt;
787 info->errorCount += 10;
790 if ((stmt->next != NULL) && (included.errorCount < 1))
794 SymbolsInfo next_incl;
796 for (next = stmt->next; next != NULL; next = next->next)
798 if ((next->file == NULL) && (next->map == NULL))
801 MergeIncludedSymbols(&included, info, next->merge, xkb);
802 FreeSymbolsInfo(info);
804 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
806 InitSymbolsInfo(&next_incl, xkb);
807 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
808 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
811 next_incl.explicit_group = atoi(next->modifier) - 1;
815 next_incl.explicit_group = info->explicit_group;
817 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
818 MergeIncludedSymbols(&included, &next_incl, op, xkb);
819 FreeSymbolsInfo(&next_incl);
824 info->errorCount += 10;
833 MergeIncludedSymbols(info, &included, newMerge, xkb);
834 FreeSymbolsInfo(&included);
836 return (info->errorCount == 0);
843 GetGroupIndex(KeyInfo * key,
844 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
854 if (arrayNdx == NULL)
859 defined = key->symsDefined;
861 defined = key->actsDefined;
863 for (i = 0; i < XkbNumKbdGroups; i++)
865 if ((defined & (1 << i)) == 0)
871 ERROR("Too many groups of %s for key %s (max %d)\n", name,
872 longText(key->name), XkbNumKbdGroups + 1);
873 ACTION("Ignoring %s defined for extra groups\n", name);
876 if (!ExprResolveGroup(arrayNdx, &tmp))
878 ERROR("Illegal group index for %s of key %s\n", name,
879 longText(key->name));
880 ACTION("Definition with non-integer array index ignored\n");
883 *ndx_rtrn = tmp.uval - 1;
888 AddSymbolsToKey(KeyInfo * key,
889 struct xkb_desc * xkb,
891 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
896 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
900 key->symsDefined |= (1 << ndx);
903 if (value->op != ExprKeysymList)
905 ERROR("Expected a list of symbols, found %s\n",
906 exprOpText(value->op));
907 ACTION("Ignoring symbols for group %d of %s\n", ndx,
908 longText(key->name));
911 if (key->syms[ndx] != NULL)
913 WSGO("Symbols for key %s, group %d already defined\n",
914 longText(key->name), ndx);
917 nSyms = value->value.list.nSyms;
918 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
919 (!ResizeKeyGroup(key, ndx, nSyms, False)))
921 WSGO("Could not resize group %d of key %s\n", ndx,
922 longText(key->name));
923 ACTION("Symbols lost\n");
926 key->symsDefined |= (1 << ndx);
927 for (i = 0; i < nSyms; i++) {
928 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
929 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
930 key->syms[ndx][i] = NoSymbol;
933 for (i = key->numLevels[ndx] - 1;
934 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
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 (uStrCaseCmp(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 (uStrCaseCmp(field, "symbols") == 0)
1068 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1069 else if (uStrCaseCmp(field, "actions") == 0)
1070 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1071 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1072 (uStrCaseCmp(field, "virtualmods") == 0) ||
1073 (uStrCaseCmp(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 ((uStrCaseCmp(field, "locking") == 0)
1090 || (uStrCaseCmp(field, "lock") == 0)
1091 || (uStrCaseCmp(field, "locks") == 0))
1093 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1095 key->behavior.type = tmp.uval;
1096 key->defs.defined |= _Key_Behavior;
1098 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1099 (uStrCaseCmp(field, "permanentradiogroup") == 0) ||
1100 (uStrCaseEqual(field, "allownone")))
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 Bool permanent = False;
1112 if (uStrCasePrefix("permanent", field))
1115 which = &field[sizeof("permanentoverlay") - 1];
1119 which = &field[sizeof("overlay") - 1];
1121 if (sscanf(which, "%d", &overlayNdx) == 1)
1123 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1125 ERROR("Illegal overlay %d specified for %s\n",
1126 overlayNdx, longText(key->name));
1127 ACTION("Ignored\n");
1131 else if (*which == '\0')
1133 else if (warningLevel > 0)
1135 ERROR("Illegal overlay \"%s\" specified for %s\n",
1136 which, longText(key->name));
1137 ACTION("Ignored\n");
1140 ok = ExprResolveKeyName(value, &tmp);
1143 ERROR("Illegal overlay key specification for %s\n",
1144 longText(key->name));
1145 ACTION("Overlay key must be specified by name\n");
1148 if (overlayNdx == 1)
1149 key->behavior.type = XkbKB_Overlay1;
1151 key->behavior.type = XkbKB_Overlay2;
1153 key->behavior.type |= XkbKB_Permanent;
1155 key->behavior.data = 0;
1156 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1157 key->defs.defined |= _Key_Behavior;
1159 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1160 (uStrCaseCmp(field, "repeats") == 0) ||
1161 (uStrCaseCmp(field, "repeat") == 0))
1163 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1166 ERROR("Illegal repeat setting for %s\n",
1167 longText(key->name));
1168 ACTION("Non-boolean repeat setting ignored\n");
1171 key->repeat = tmp.uval;
1172 key->defs.defined |= _Key_Repeat;
1174 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1175 (uStrCaseCmp(field, "wrapgroups") == 0))
1177 ok = ExprResolveBoolean(value, &tmp);
1180 ERROR("Illegal groupsWrap setting for %s\n",
1181 longText(key->name));
1182 ACTION("Non-boolean value ignored\n");
1186 key->groupInfo = XkbWrapIntoRange;
1188 key->groupInfo = XkbClampIntoRange;
1189 key->defs.defined |= _Key_GroupInfo;
1191 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1192 (uStrCaseCmp(field, "clampgroups") == 0))
1194 ok = ExprResolveBoolean(value, &tmp);
1197 ERROR("Illegal groupsClamp setting for %s\n",
1198 longText(key->name));
1199 ACTION("Non-boolean value ignored\n");
1203 key->groupInfo = XkbClampIntoRange;
1205 key->groupInfo = XkbWrapIntoRange;
1206 key->defs.defined |= _Key_GroupInfo;
1208 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1209 (uStrCaseCmp(field, "redirectgroups") == 0))
1211 if (!ExprResolveGroup(value, &tmp))
1213 ERROR("Illegal group index for redirect of key %s\n",
1214 longText(key->name));
1215 ACTION("Definition with non-integer group ignored\n");
1219 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1220 key->defs.defined |= _Key_GroupInfo;
1224 ERROR("Unknown field %s in a symbol interpretation\n", field);
1225 ACTION("Definition ignored\n");
1232 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1234 ExprResult tmp, name;
1236 if ((arrayNdx == NULL) && (warningLevel > 0))
1238 WARN("You must specify an index when specifying a group name\n");
1239 ACTION("Group name definition without array subscript ignored\n");
1242 if (!ExprResolveGroup(arrayNdx, &tmp))
1244 ERROR("Illegal index in group name definition\n");
1245 ACTION("Definition with non-integer array index ignored\n");
1248 if (!ExprResolveString(value, &name))
1250 ERROR("Group name must be a string\n");
1251 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1254 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1255 xkb_intern_atom(name.str);
1262 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1264 ExprResult elem, field, tmp;
1268 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1269 return 0; /* internal error, already reported */
1270 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1272 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1275 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1276 (uStrCaseCmp(field.str, "groupname") ==
1279 ret = SetGroupName(info, arrayNdx, stmt->value);
1281 else if ((elem.str == NULL)
1282 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1283 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1285 if (!ExprResolveBoolean(stmt->value, &tmp))
1287 ERROR("Illegal setting for global groupsWrap\n");
1288 ACTION("Non-boolean value ignored\n");
1293 info->groupInfo = XkbWrapIntoRange;
1295 info->groupInfo = XkbClampIntoRange;
1299 else if ((elem.str == NULL)
1300 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1301 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1303 if (!ExprResolveBoolean(stmt->value, &tmp))
1305 ERROR("Illegal setting for global groupsClamp\n");
1306 ACTION("Non-boolean value ignored\n");
1311 info->groupInfo = XkbClampIntoRange;
1313 info->groupInfo = XkbWrapIntoRange;
1317 else if ((elem.str == NULL)
1318 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1319 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1321 if (!ExprResolveGroup(stmt->value, &tmp))
1323 ERROR("Illegal group index for global groupsRedirect\n");
1324 ACTION("Definition with non-integer group ignored\n");
1328 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1333 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1335 ERROR("Radio groups not supported\n");
1336 ACTION("Ignoring \"allow none\" specification\n");
1340 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1350 HandleSymbolsBody(VarDef * def,
1351 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1354 ExprResult tmp, field;
1357 for (; def != NULL; def = (VarDef *) def->common.next)
1359 if ((def->name) && (def->name->type == ExprFieldRef))
1361 ok = HandleSymbolsVar(def, xkb, info);
1366 if (def->name == NULL)
1368 if ((def->value == NULL)
1369 || (def->value->op == ExprKeysymList))
1370 field.str = strdup("symbols");
1372 field.str = strdup("actions");
1377 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1380 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1389 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1391 unsigned group = info->explicit_group;
1396 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1399 WARN("For the map %s an explicit group specified\n", info->name);
1400 WARN("but key %s has more than one group defined\n",
1401 longText(key->name));
1402 ACTION("All groups except first one will be ignored\n");
1403 for (i = 1; i < XkbNumKbdGroups; i++)
1405 key->numLevels[i] = 0;
1407 key->syms[i] = NULL;
1409 key->acts[i] = NULL;
1413 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1415 key->numLevels[group] = key->numLevels[0];
1416 key->numLevels[0] = 0;
1417 key->syms[group] = key->syms[0];
1418 key->syms[0] = NULL;
1419 key->acts[group] = key->acts[0];
1420 key->acts[0] = NULL;
1421 key->types[group] = key->types[0];
1427 HandleSymbolsDef(SymbolsDef * stmt,
1428 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1433 CopyKeyInfo(&info->dflt, &key, False);
1434 key.defs.merge = stmt->merge;
1435 key.name = KeyNameToLong(stmt->keyName);
1436 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1442 if (!SetExplicitGroup(info, &key))
1448 if (!AddKeySymbols(info, &key, xkb))
1457 HandleModMapDef(ModMapDef * def,
1458 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1465 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1467 ERROR("Illegal modifier map definition\n");
1468 ACTION("Ignoring map for non-modifier \"%s\"\n",
1469 XkbcAtomText(def->modifier));
1473 tmp.modifier = rtrn.uval;
1474 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1476 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1478 tmp.haveSymbol = False;
1479 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1481 else if (ExprResolveKeySym(key, &rtrn))
1483 tmp.haveSymbol = True;
1484 tmp.u.keySym = rtrn.uval;
1488 ERROR("Modmap entries may contain only key names or keysyms\n");
1489 ACTION("Illegal definition for %s modifier ignored\n",
1490 XkbcModIndexText(tmp.modifier));
1494 ok = AddModMapEntry(info, &tmp) && ok;
1500 HandleSymbolsFile(XkbFile * file,
1501 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1506 info->name = _XkbDupString(file->name);
1510 switch (stmt->stmtType)
1513 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1517 case StmtSymbolsDef:
1518 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1522 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1526 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1530 ERROR("Interpretation files may not include other types\n");
1531 ACTION("Ignoring definition of symbol interpretation\n");
1534 case StmtKeycodeDef:
1535 ERROR("Interpretation files may not include other types\n");
1536 ACTION("Ignoring definition of key name\n");
1540 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1544 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1549 if (info->errorCount > 10)
1552 ERROR("Too many errors\n");
1554 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1561 FindKeyForSymbol(struct xkb_desc * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1570 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1572 if (j < (int) XkbKeyNumSyms(xkb, i))
1575 if (XkbKeySym(xkb, i, j) == sym)
1589 * Find the given name in the xkb->map->types and return its index.
1591 * @param atom The atom to search for.
1592 * @param type_rtrn Set to the index of the name if found.
1594 * @return True if found, False otherwise.
1597 FindNamedType(struct xkb_desc * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1600 const char *name = XkbcAtomText(atom);
1602 if (xkb && xkb->map && xkb->map->types)
1604 for (n = 0; n < xkb->map->num_types; n++)
1606 if (strcmp(xkb->map->types[n].name, name) == 0)
1617 * Assign a type to the given sym and return the Atom for the type assigned.
1620 * - ONE_LEVEL for width 0/1
1621 * - ALPHABETIC for 2 shift levels, with lower/upercase
1622 * - KEYPAD for keypad keys.
1623 * - TWO_LEVEL for other 2 shift level keys.
1624 * and the same for four level keys.
1626 * @param width Number of sysms in syms.
1627 * @param syms The keysyms for the given key (must be size width).
1628 * @param typeNameRtrn Set to the Atom of the type name.
1630 * @returns True if a type could be found, False otherwise.
1633 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1637 if ((width == 1) || (width == 0))
1639 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1642 else if (width == 2)
1644 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1646 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1648 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1650 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1655 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1659 else if (width <= 4)
1661 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1662 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1664 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1666 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1668 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1669 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1671 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1672 /* XXX: why not set autoType here? */
1674 return ((width >= 0) && (width <= 4));
1678 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1679 * groups, and reduce to one group if all groups are identical anyway.
1682 PrepareKeyDef(KeyInfo * key)
1684 int i, j, width, defined, lastGroup;
1687 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1688 /* get highest group number */
1689 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1691 if (defined & (1 << i))
1699 /* If there are empty groups between non-empty ones fill them with data */
1700 /* from the first group. */
1701 /* We can make a wrong assumption here. But leaving gaps is worse. */
1702 for (i = lastGroup; i > 0; i--)
1704 if (defined & (1 << i))
1706 width = key->numLevels[0];
1707 if (key->typesDefined & 1)
1709 for (j = 0; j < width; j++)
1711 key->types[i] = key->types[0];
1713 key->typesDefined |= 1 << i;
1715 if ((key->actsDefined & 1) && key->acts[0])
1717 key->acts[i] = uTypedCalloc(width, union xkb_action);
1718 if (key->acts[i] == NULL)
1720 memcpy(key->acts[i], key->acts[0],
1721 width * sizeof(union xkb_action));
1722 key->actsDefined |= 1 << i;
1724 if ((key->symsDefined & 1) && key->syms[0])
1726 key->syms[i] = uTypedCalloc(width, xkb_keysym_t);
1727 if (key->syms[i] == NULL)
1729 memcpy(key->syms[i], key->syms[0], width * sizeof(xkb_keysym_t));
1730 key->symsDefined |= 1 << i;
1734 key->numLevels[i] = key->numLevels[0];
1737 /* If all groups are completely identical remove them all */
1738 /* exept the first one. */
1740 for (i = lastGroup; i > 0; i--)
1742 if ((key->numLevels[i] != key->numLevels[0]) ||
1743 (key->types[i] != key->types[0]))
1748 if ((key->syms[i] != key->syms[0]) &&
1749 (key->syms[i] == NULL || key->syms[0] == NULL ||
1750 memcmp(key->syms[i], key->syms[0],
1751 sizeof(xkb_keysym_t) * key->numLevels[0])))
1756 if ((key->acts[i] != key->acts[0]) &&
1757 (key->acts[i] == NULL || key->acts[0] == NULL ||
1758 memcmp(key->acts[i], key->acts[0],
1759 sizeof(union xkb_action) * key->numLevels[0])))
1767 for (i = lastGroup; i > 0; i--)
1769 key->numLevels[i] = 0;
1771 key->syms[i] = NULL;
1773 key->acts[i] = NULL;
1776 key->symsDefined &= 1;
1777 key->actsDefined &= 1;
1778 key->typesDefined &= 1;
1783 * Copy the KeyInfo into the keyboard description.
1785 * This function recurses.
1788 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1791 xkb_keycode_t okc, kc;
1792 unsigned width, tmp, nGroups;
1793 struct xkb_key_type * type;
1794 Bool haveActions, autoType, useAlias;
1795 xkb_keysym_t *outSyms;
1796 union xkb_action *outActs;
1797 unsigned types[XkbNumKbdGroups];
1799 useAlias = (start_from == 0);
1801 /* get the keycode for the key. */
1802 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1805 if ((start_from == 0) && (warningLevel >= 5))
1807 WARN("Key %s not found in keycodes\n", longText(key->name));
1808 ACTION("Symbols ignored\n");
1813 haveActions = False;
1814 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1816 if (((i + 1) > nGroups)
1817 && (((key->symsDefined | key->actsDefined) & (1 << i))
1818 || (key->typesDefined) & (1 << i)))
1823 /* Assign the type to the key, if it is missing. */
1824 if (key->types[i] == None)
1826 if (key->dfltType != None)
1827 key->types[i] = key->dfltType;
1828 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1829 &key->types[i], &autoType))
1834 if (warningLevel >= 5)
1836 WARN("No automatic type for %d symbols\n",
1837 (unsigned int) key->numLevels[i]);
1838 ACTION("Using %s for the %s key (keycode %d)\n",
1839 XkbcAtomText(key->types[i]),
1840 longText(key->name), kc);
1844 if (FindNamedType(xkb, key->types[i], &types[i]))
1846 if (!autoType || key->numLevels[i] > 2)
1847 xkb->server->explicit[kc] |= (1 << i);
1851 if (warningLevel >= 3)
1853 WARN("Type \"%s\" is not defined\n",
1854 XkbcAtomText(key->types[i]));
1855 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1856 longText(key->name), kc);
1858 types[i] = XkbTwoLevelIndex;
1860 /* if the type specifies less syms than the key has, shrink the key */
1861 type = &xkb->map->types[types[i]];
1862 if (type->num_levels < key->numLevels[i])
1864 if (warningLevel > 0)
1866 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
1867 type->name, type->num_levels,
1868 XkbcAtomText(key->name), key->numLevels[i]);
1869 ACTION("Ignoring extra symbols\n");
1871 key->numLevels[i] = type->num_levels;
1873 if (key->numLevels[i] > width)
1874 width = key->numLevels[i];
1875 if (type->num_levels > width)
1876 width = type->num_levels;
1879 /* width is now the largest width found */
1881 i = width * nGroups;
1882 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1883 if (outSyms == NULL)
1885 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1886 longText(key->name), kc);
1891 outActs = XkbcResizeKeyActions(xkb, kc, i);
1892 if (outActs == NULL)
1894 WSGO("Could not enlarge actions for %s (key %d)\n",
1895 longText(key->name), kc);
1898 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1902 if (key->defs.defined & _Key_GroupInfo)
1905 i = xkb->map->key_sym_map[kc].group_info;
1907 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1908 xkb->map->key_sym_map[kc].width = width;
1909 for (i = 0; i < nGroups; i++)
1911 /* assign kt_index[i] to the index of the type in map->types.
1912 * kt_index[i] may have been set by a previous run (if we have two
1913 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1914 * default group if we dont even have keys for this group anyway.
1916 * FIXME: There should be a better fix for this.
1918 if (key->numLevels[i])
1919 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
1920 if (key->syms[i] != NULL)
1922 /* fill key to "width" symbols*/
1923 for (tmp = 0; tmp < width; tmp++)
1925 if (tmp < key->numLevels[i])
1926 outSyms[tmp] = key->syms[i][tmp];
1928 outSyms[tmp] = NoSymbol;
1929 if ((outActs != NULL) && (key->acts[i] != NULL))
1931 if (tmp < key->numLevels[i])
1932 outActs[tmp] = key->acts[i][tmp];
1934 outActs[tmp].type = XkbSA_NoAction;
1942 switch (key->behavior.type & XkbKB_OpMask)
1946 case XkbKB_Overlay1:
1947 case XkbKB_Overlay2:
1948 /* find key by name! */
1949 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
1950 CreateKeyNames(xkb), 0))
1952 if (warningLevel >= 1)
1954 WARN("Key %s not found in keycodes\n",
1955 longText(key->nameForOverlayKey));
1956 ACTION("Not treating %s as an overlay key \n",
1957 longText(key->name));
1961 key->behavior.data = okc;
1963 xkb->server->behaviors[kc] = key->behavior;
1964 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
1967 if (key->defs.defined & _Key_VModMap)
1969 xkb->server->vmodmap[kc] = key->vmodmap;
1970 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
1972 if (key->repeat != RepeatUndefined)
1974 if (key->repeat == RepeatYes)
1975 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
1977 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
1978 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
1981 if (nGroups > xkb->ctrls->num_groups)
1982 xkb->ctrls->num_groups = nGroups;
1984 /* do the same thing for the next key */
1985 CopySymbolsDef(xkb, key, kc + 1);
1990 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
1994 if ((!entry->haveSymbol)
1997 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
1999 if (warningLevel >= 5)
2001 WARN("Key %s not found in keycodes\n",
2002 longText(entry->u.keyName));
2003 ACTION("Modifier map entry for %s not updated\n",
2004 XkbcModIndexText(entry->modifier));
2008 else if (entry->haveSymbol
2009 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2011 if (warningLevel > 5)
2013 WARN("Key \"%s\" not found in symbol map\n",
2014 XkbcKeysymText(entry->u.keySym));
2015 ACTION("Modifier map entry for %s not updated\n",
2016 XkbcModIndexText(entry->modifier));
2020 xkb->map->modmap[kc] |= (1 << entry->modifier);
2025 * Handle the xkb_symbols section of an xkb file.
2027 * @param file The parsed xkb_symbols section of the xkb file.
2028 * @param xkb Handle to the keyboard description to store the symbols in.
2029 * @param merge Merge strategy (e.g. MergeOverride).
2032 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2037 InitSymbolsInfo(&info, xkb);
2038 info.dflt.defs.fileID = file->id;
2039 info.dflt.defs.merge = merge;
2040 HandleSymbolsFile(file, xkb, merge, &info);
2042 if (info.nKeys == 0) {
2043 FreeSymbolsInfo(&info);
2047 if (info.errorCount == 0)
2051 /* alloc memory in the xkb struct */
2052 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
2054 WSGO("Can not allocate names in CompileSymbols\n");
2055 ACTION("Symbols not added\n");
2058 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2061 WSGO("Could not allocate client map in CompileSymbols\n");
2062 ACTION("Symbols not added\n");
2065 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2067 WSGO("Could not allocate server map in CompileSymbols\n");
2068 ACTION("Symbols not added\n");
2071 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2073 WSGO("Could not allocate controls in CompileSymbols\n");
2074 ACTION("Symbols not added\n");
2078 /* now copy info into xkb. */
2080 ApplyAliases(xkb, &info.aliases);
2081 for (i = 0; i < XkbNumKbdGroups; i++)
2083 if (info.groupNames[i] != None)
2085 free((char *) xkb->names->groups[i]);
2086 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2090 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2095 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2097 if (!CopySymbolsDef(xkb, key, 0))
2100 if (warningLevel > 3)
2102 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2104 if (xkb->names->keys[i].name[0] == '\0')
2106 if (XkbKeyNumGroups(xkb, i) < 1)
2109 memcpy(buf, xkb->names->keys[i].name, 4);
2112 ("No symbols defined for <%s> (keycode %d)\n",
2119 ModMapEntry *mm, *next;
2120 for (mm = info.modMap; mm != NULL; mm = next)
2122 if (!CopyModMapDef(xkb, mm))
2124 next = (ModMapEntry *) mm->defs.next;
2127 FreeSymbolsInfo(&info);
2131 FreeSymbolsInfo(&info);