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 ********************************************************/
32 #include "parseutils.h"
34 #include <X11/keysym.h>
44 extern uint32_t tok_ONE_LEVEL;
45 extern uint32_t tok_TWO_LEVEL;
46 extern uint32_t tok_KEYPAD;
48 /***====================================================================***/
52 #define RepeatUndefined ~((unsigned)0)
54 #define _Key_Syms (1<<0)
55 #define _Key_Acts (1<<1)
56 #define _Key_Repeat (1<<2)
57 #define _Key_Behavior (1<<3)
58 #define _Key_Type_Dflt (1<<4)
59 #define _Key_Types (1<<5)
60 #define _Key_GroupInfo (1<<6)
61 #define _Key_VModMap (1<<7)
63 typedef struct _KeyInfo
66 unsigned long name; /* the 4 chars of the key name, as long */
67 unsigned char groupInfo;
68 unsigned char typesDefined;
69 unsigned char symsDefined;
70 unsigned char actsDefined;
71 short numLevels[XkbNumKbdGroups];
72 uint32_t *syms[XkbNumKbdGroups];
73 union xkb_action *acts[XkbNumKbdGroups];
74 uint32_t types[XkbNumKbdGroups];
76 struct xkb_behavior behavior;
77 unsigned short vmodmap;
78 unsigned long nameForOverlayKey;
79 unsigned long allowNone;
84 * Init the given key info to sane values.
87 InitKeyInfo(KeyInfo * info)
90 static char dflt[4] = "*";
92 info->defs.defined = 0;
93 info->defs.fileID = 0;
94 info->defs.merge = MergeOverride;
95 info->defs.next = NULL;
96 info->name = KeyNameToLong(dflt);
98 info->typesDefined = info->symsDefined = info->actsDefined = 0;
99 for (i = 0; i < XkbNumKbdGroups; i++)
101 info->numLevels[i] = 0;
102 info->types[i] = None;
103 info->syms[i] = NULL;
104 info->acts[i] = NULL;
106 info->dfltType = None;
107 info->behavior.type = XkbKB_Default;
108 info->behavior.data = 0;
110 info->nameForOverlayKey = 0;
111 info->repeat = RepeatUndefined;
117 * Free memory associated with this key info and reset to sane values.
120 FreeKeyInfo(KeyInfo * info)
124 info->defs.defined = 0;
125 info->defs.fileID = 0;
126 info->defs.merge = MergeOverride;
127 info->defs.next = NULL;
129 info->typesDefined = info->symsDefined = info->actsDefined = 0;
130 for (i = 0; i < XkbNumKbdGroups; i++)
132 info->numLevels[i] = 0;
133 info->types[i] = None;
134 if (info->syms[i] != NULL)
136 info->syms[i] = NULL;
137 if (info->acts[i] != NULL)
139 info->acts[i] = NULL;
141 info->dfltType = None;
142 info->behavior.type = XkbKB_Default;
143 info->behavior.data = 0;
145 info->nameForOverlayKey = 0;
146 info->repeat = RepeatUndefined;
152 * Copy old into new, optionally reset old to 0.
153 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
154 * newly allocated and new points to the new memory areas.
157 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
162 new->defs.next = NULL;
165 for (i = 0; i < XkbNumKbdGroups; i++)
167 old->numLevels[i] = 0;
175 for (i = 0; i < XkbNumKbdGroups; i++)
177 width = new->numLevels[i];
178 if (old->syms[i] != NULL)
180 new->syms[i] = uTypedCalloc(width, uint32_t);
184 new->numLevels[i] = 0;
187 memcpy((char *) new->syms[i], (char *) old->syms[i],
188 width * sizeof(uint32_t));
190 if (old->acts[i] != NULL)
192 new->acts[i] = uTypedCalloc(width, union xkb_action);
198 memcpy((char *) new->acts[i], (char *) old->acts[i],
199 width * sizeof(union xkb_action));
206 /***====================================================================***/
208 typedef struct _ModMapEntry
215 unsigned long keyName;
220 #define SYMBOLS_INIT_SIZE 110
221 #define SYMBOLS_CHUNK 20
222 typedef struct _SymbolsInfo
224 char *name; /* e.g. pc+us+inet(evdev) */
228 unsigned explicit_group;
236 uint32_t groupNames[XkbNumKbdGroups];
243 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
247 tok_ONE_LEVEL = xkb_intern_atom("ONE_LEVEL");
248 tok_TWO_LEVEL = xkb_intern_atom("TWO_LEVEL");
249 tok_KEYPAD = xkb_intern_atom("KEYPAD");
251 info->explicit_group = 0;
252 info->errorCount = 0;
254 info->merge = MergeOverride;
256 info->szKeys = SYMBOLS_INIT_SIZE;
258 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
260 for (i = 0; i < XkbNumKbdGroups; i++)
261 info->groupNames[i] = None;
262 InitKeyInfo(&info->dflt);
263 InitVModInfo(&info->vmods, xkb);
265 info->aliases = NULL;
270 FreeSymbolsInfo(SymbolsInfo * info)
279 for (i = 0; i < info->nKeys; i++)
281 FreeKeyInfo(&info->keys[i]);
288 ClearCommonInfo(&info->modMap->defs);
293 ClearAliases(&info->aliases);
294 info->aliases = NULL;
296 bzero((char *) info, sizeof(SymbolsInfo));
301 ResizeKeyGroup(KeyInfo * key,
302 unsigned group, unsigned atLeastSize, Bool forceActions)
307 tooSmall = (key->numLevels[group] < atLeastSize);
309 newWidth = atLeastSize;
311 newWidth = key->numLevels[group];
313 if ((key->syms[group] == NULL) || tooSmall)
315 key->syms[group] = uTypedRecalloc(key->syms[group],
316 key->numLevels[group], newWidth,
318 if (!key->syms[group])
321 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
322 (tooSmall && (key->acts[group] != NULL)))
324 key->acts[group] = uTypedRecalloc(key->acts[group],
325 key->numLevels[group], newWidth,
327 if (!key->acts[group])
330 key->numLevels[group] = newWidth;
335 MergeKeyGroups(SymbolsInfo * info,
336 KeyInfo * into, KeyInfo * from, unsigned group)
338 uint32_t *resultSyms;
339 union xkb_action *resultActs;
342 Bool report, clobber;
344 clobber = (from->defs.merge != MergeAugment);
345 report = (warningLevel > 9) ||
346 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
347 if (into->numLevels[group] >= from->numLevels[group])
349 resultSyms = into->syms[group];
350 resultActs = into->acts[group];
351 resultWidth = into->numLevels[group];
355 resultSyms = from->syms[group];
356 resultActs = from->acts[group];
357 resultWidth = from->numLevels[group];
359 if (resultSyms == NULL)
361 resultSyms = uTypedCalloc(resultWidth, uint32_t);
364 WSGO("Could not allocate symbols for group merge\n");
365 ACTION("Group %d of key %s not merged\n", group,
366 longText(into->name));
370 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
372 resultActs = uTypedCalloc(resultWidth, union xkb_action);
375 WSGO("Could not allocate actions for group merge\n");
376 ACTION("Group %d of key %s not merged\n", group,
377 longText(into->name));
381 for (i = 0; i < resultWidth; i++)
383 uint32_t fromSym, toSym;
384 if (from->syms[group] && (i < from->numLevels[group]))
385 fromSym = from->syms[group][i];
388 if (into->syms[group] && (i < into->numLevels[group]))
389 toSym = into->syms[group][i];
392 if ((fromSym == NoSymbol) || (fromSym == toSym))
393 resultSyms[i] = toSym;
394 else if (toSym == NoSymbol)
395 resultSyms[i] = fromSym;
398 uint32_t use, ignore;
412 ("Multiple symbols for level %d/group %d on key %s\n",
413 i + 1, group + 1, longText(into->name));
414 ACTION("Using %s, ignoring %s\n",
415 XkbcKeysymText(use), XkbcKeysymText(ignore));
419 if (resultActs != NULL)
421 union xkb_action *fromAct, *toAct;
422 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
423 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
424 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
427 resultActs[i] = *toAct;
429 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
430 && (fromAct != NULL))
432 resultActs[i] = *fromAct;
436 union xkb_action *use, *ignore;
450 ("Multiple actions for level %d/group %d on key %s\n",
451 i + 1, group + 1, longText(into->name));
452 ACTION("Using %s, ignoring %s\n",
453 XkbcActionTypeText(use->type),
454 XkbcActionTypeText(ignore->type));
456 resultActs[i] = *use;
460 if ((into->syms[group] != NULL) && (resultSyms != into->syms[group]))
461 free(into->syms[group]);
462 if ((from->syms[group] != NULL) && (resultSyms != from->syms[group]))
463 free(from->syms[group]);
464 if ((into->acts[group] != NULL) && (resultActs != into->acts[group]))
465 free(into->acts[group]);
466 if ((from->acts[group] != NULL) && (resultActs != from->acts[group]))
467 free(from->acts[group]);
468 into->numLevels[group] = resultWidth;
469 into->syms[group] = resultSyms;
470 from->syms[group] = NULL;
471 into->acts[group] = resultActs;
472 from->acts[group] = NULL;
473 into->symsDefined |= (1 << group);
474 from->symsDefined &= ~(1 << group);
475 into->actsDefined |= (1 << group);
476 from->actsDefined &= ~(1 << group);
481 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
484 unsigned collide = 0;
487 if (from->defs.merge == MergeReplace)
489 for (i = 0; i < XkbNumKbdGroups; i++)
491 if (into->numLevels[i] != 0)
500 bzero(from, sizeof(KeyInfo));
503 report = ((warningLevel > 9) ||
504 ((into->defs.fileID == from->defs.fileID)
505 && (warningLevel > 0)));
506 for (i = 0; i < XkbNumKbdGroups; i++)
508 if (from->numLevels[i] > 0)
510 if (into->numLevels[i] == 0)
512 into->numLevels[i] = from->numLevels[i];
513 into->syms[i] = from->syms[i];
514 into->acts[i] = from->acts[i];
515 into->symsDefined |= (1 << i);
516 from->syms[i] = NULL;
517 from->acts[i] = NULL;
518 from->numLevels[i] = 0;
519 from->symsDefined &= ~(1 << i);
521 into->defs.defined |= _Key_Syms;
523 into->defs.defined |= _Key_Acts;
530 collide |= _Key_Syms;
532 collide |= _Key_Acts;
534 MergeKeyGroups(info, into, from, (unsigned) i);
537 if (from->types[i] != None)
539 if ((into->types[i] != None) && (report) &&
540 (into->types[i] != from->types[i]))
542 uint32_t use, ignore;
543 collide |= _Key_Types;
544 if (from->defs.merge != MergeAugment)
546 use = from->types[i];
547 ignore = into->types[i];
551 use = into->types[i];
552 ignore = from->types[i];
555 ("Multiple definitions for group %d type of key %s\n",
556 i, longText(into->name));
557 ACTION("Using %s, ignoring %s\n",
559 XkbcAtomText(ignore));
561 if ((from->defs.merge != MergeAugment)
562 || (into->types[i] == None))
564 into->types[i] = from->types[i];
568 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
570 into->behavior = from->behavior;
571 into->nameForOverlayKey = from->nameForOverlayKey;
572 into->defs.defined |= _Key_Behavior;
574 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
576 into->vmodmap = from->vmodmap;
577 into->defs.defined |= _Key_VModMap;
579 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
581 into->repeat = from->repeat;
582 into->defs.defined |= _Key_Repeat;
584 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
586 into->dfltType = from->dfltType;
587 into->defs.defined |= _Key_Type_Dflt;
589 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
591 into->groupInfo = from->groupInfo;
592 into->defs.defined |= _Key_GroupInfo;
596 WARN("Symbol map for key %s redefined\n",
597 longText(into->name));
598 ACTION("Using %s definition for conflicting fields\n",
599 (from->defs.merge == MergeAugment ? "first" : "last"));
605 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
608 unsigned long real_name;
610 for (i = 0; i < info->nKeys; i++)
612 if (info->keys[i].name == key->name)
613 return MergeKeys(info, &info->keys[i], key);
615 if (FindKeyNameForAlias(xkb, key->name, &real_name))
617 for (i = 0; i < info->nKeys; i++)
619 if (info->keys[i].name == real_name)
620 return MergeKeys(info, &info->keys[i], key);
623 if (info->nKeys >= info->szKeys)
625 info->szKeys += SYMBOLS_CHUNK;
627 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
630 WSGO("Could not allocate key symbols descriptions\n");
631 ACTION("Some key symbols definitions may be lost\n");
635 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
639 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
644 clobber = (new->defs.merge != MergeAugment);
645 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
647 if (new->haveSymbol && mm->haveSymbol
648 && (new->u.keySym == mm->u.keySym))
650 unsigned use, ignore;
651 if (mm->modifier != new->modifier)
656 ignore = mm->modifier;
661 ignore = new->modifier;
664 ("%s added to symbol map for multiple modifiers\n",
665 XkbcKeysymText(new->u.keySym));
666 ACTION("Using %s, ignoring %s.\n",
667 XkbcModIndexText(use),
668 XkbcModIndexText(ignore));
673 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
674 (new->u.keyName == mm->u.keyName))
676 unsigned use, ignore;
677 if (mm->modifier != new->modifier)
682 ignore = mm->modifier;
687 ignore = new->modifier;
689 ERROR("Key %s added to map for multiple modifiers\n",
690 longText(new->u.keyName));
691 ACTION("Using %s, ignoring %s.\n",
692 XkbcModIndexText(use),
693 XkbcModIndexText(ignore));
699 mm = uTypedAlloc(ModMapEntry);
702 WSGO("Could not allocate modifier map entry\n");
703 ACTION("Modifier map for %s will be incomplete\n",
704 XkbcModIndexText(new->modifier));
708 mm->defs.next = &info->modMap->defs;
713 /***====================================================================***/
716 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
717 unsigned merge, struct xkb_desc * xkb)
722 if (from->errorCount > 0)
724 into->errorCount += from->errorCount;
727 if (into->name == NULL)
729 into->name = from->name;
732 for (i = 0; i < XkbNumKbdGroups; i++)
734 if (from->groupNames[i] != None)
736 if ((merge != MergeAugment) || (into->groupNames[i] == None))
737 into->groupNames[i] = from->groupNames[i];
740 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
742 if (merge != MergeDefault)
743 key->defs.merge = merge;
744 if (!AddKeySymbols(into, key, xkb))
747 if (from->modMap != NULL)
749 ModMapEntry *mm, *next;
750 for (mm = from->modMap; mm != NULL; mm = next)
752 if (merge != MergeDefault)
753 mm->defs.merge = merge;
754 if (!AddModMapEntry(into, mm))
756 next = (ModMapEntry *) mm->defs.next;
761 if (!MergeAliases(&into->aliases, &from->aliases, merge))
766 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
767 struct xkb_desc * /* xkb */ ,
768 unsigned /* merge */ ,
769 SymbolsInfo * /* included */
773 HandleIncludeSymbols(IncludeStmt * stmt,
774 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
778 SymbolsInfo included;
782 if ((stmt->file == NULL) && (stmt->map == NULL))
786 bzero(info, sizeof(SymbolsInfo));
788 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
790 InitSymbolsInfo(&included, xkb);
791 included.fileID = included.dflt.defs.fileID = rtrn->id;
792 included.merge = included.dflt.defs.merge = MergeOverride;
795 included.explicit_group = atoi(stmt->modifier) - 1;
799 included.explicit_group = info->explicit_group;
801 (*hndlr) (rtrn, xkb, MergeOverride, &included);
802 if (stmt->stmt != NULL)
804 if (included.name != NULL)
806 included.name = stmt->stmt;
812 info->errorCount += 10;
815 if ((stmt->next != NULL) && (included.errorCount < 1))
819 SymbolsInfo next_incl;
821 for (next = stmt->next; next != NULL; next = next->next)
823 if ((next->file == NULL) && (next->map == NULL))
826 MergeIncludedSymbols(&included, info, next->merge, xkb);
827 FreeSymbolsInfo(info);
829 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
831 InitSymbolsInfo(&next_incl, xkb);
832 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
833 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
836 next_incl.explicit_group = atoi(next->modifier) - 1;
840 next_incl.explicit_group = info->explicit_group;
842 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
843 MergeIncludedSymbols(&included, &next_incl, op, xkb);
844 FreeSymbolsInfo(&next_incl);
848 info->errorCount += 10;
857 MergeIncludedSymbols(info, &included, newMerge, xkb);
858 FreeSymbolsInfo(&included);
860 return (info->errorCount == 0);
863 static LookupEntry groupNames[] = {
880 GetGroupIndex(KeyInfo * key,
881 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
891 if (arrayNdx == NULL)
896 defined = key->symsDefined;
898 defined = key->actsDefined;
900 for (i = 0; i < XkbNumKbdGroups; i++)
902 if ((defined & (1 << i)) == 0)
908 ERROR("Too many groups of %s for key %s (max %d)\n", name,
909 longText(key->name), XkbNumKbdGroups + 1);
910 ACTION("Ignoring %s defined for extra groups\n", name);
913 if (!ExprResolveInteger
914 (arrayNdx, &tmp, SimpleLookup, (char *) groupNames))
916 ERROR("Illegal group index for %s of key %s\n", name,
917 longText(key->name));
918 ACTION("Definition with non-integer array index ignored\n");
921 if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
923 ERROR("Group index for %s of key %s is out of range (1..%d)\n",
924 name, longText(key->name), XkbNumKbdGroups + 1);
925 ACTION("Ignoring %s for group %d\n", name, tmp.uval);
928 *ndx_rtrn = tmp.uval - 1;
933 AddSymbolsToKey(KeyInfo * key,
934 struct xkb_desc * xkb,
936 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
941 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
945 key->symsDefined |= (1 << ndx);
948 if (value->op != ExprKeysymList)
950 ERROR("Expected a list of symbols, found %s\n",
951 exprOpText(value->op));
952 ACTION("Ignoring symbols for group %d of %s\n", ndx,
953 longText(key->name));
956 if (key->syms[ndx] != NULL)
958 WSGO("Symbols for key %s, group %d already defined\n",
959 longText(key->name), ndx);
962 nSyms = value->value.list.nSyms;
963 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
964 (!ResizeKeyGroup(key, ndx, nSyms, False)))
966 WSGO("Could not resize group %d of key %s\n", ndx,
967 longText(key->name));
968 ACTION("Symbols lost\n");
971 key->symsDefined |= (1 << ndx);
972 for (i = 0; i < nSyms; i++) {
973 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
974 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
975 key->syms[ndx][i] = NoSymbol;
978 for (i = key->numLevels[ndx] - 1;
979 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
981 key->numLevels[ndx]--;
987 AddActionsToKey(KeyInfo * key,
988 struct xkb_desc * xkb,
990 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
995 struct xkb_any_action *toAct;
997 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
1002 key->actsDefined |= (1 << ndx);
1005 if (value->op != ExprActionList)
1007 WSGO("Bad expression type (%d) for action list value\n", value->op);
1008 ACTION("Ignoring actions for group %d of %s\n", ndx,
1009 longText(key->name));
1012 if (key->acts[ndx] != NULL)
1014 WSGO("Actions for key %s, group %d already defined\n",
1015 longText(key->name), ndx);
1018 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1020 act = (ExprDef *) act->common.next;
1024 WSGO("Action list but not actions in AddActionsToKey\n");
1027 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1028 (!ResizeKeyGroup(key, ndx, nActs, True)))
1030 WSGO("Could not resize group %d of key %s\n", ndx,
1031 longText(key->name));
1032 ACTION("Actions lost\n");
1035 key->actsDefined |= (1 << ndx);
1037 toAct = (struct xkb_any_action *) key->acts[ndx];
1038 act = value->value.child;
1039 for (i = 0; i < nActs; i++, toAct++)
1041 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1043 ERROR("Illegal action definition for %s\n",
1044 longText(key->name));
1045 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1047 act = (ExprDef *) act->common.next;
1053 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1056 unsigned radio_groups = 0;
1058 if (arrayNdx == NULL)
1060 radio_groups = XkbAllRadioGroupsMask;
1064 if (!ExprResolveInteger(arrayNdx, &tmp, RadioLookup, NULL))
1066 ERROR("Illegal index in group name definition\n");
1067 ACTION("Definition with non-integer array index ignored\n");
1070 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1072 ERROR("Illegal radio group specified (must be 1..%d)\n",
1073 XkbMaxRadioGroups + 1);
1074 ACTION("Value of \"allow none\" for group %d ignored\n",
1078 radio_groups |= (1 << (tmp.uval - 1));
1080 if (!ExprResolveBoolean(value, &tmp))
1082 ERROR("Illegal \"allow none\" value for %s\n",
1083 longText(key->name));
1084 ACTION("Non-boolean value ignored\n");
1088 key->allowNone |= radio_groups;
1090 key->allowNone &= ~radio_groups;
1095 static LookupEntry lockingEntries[] = {
1096 {"true", XkbKB_Lock},
1097 {"yes", XkbKB_Lock},
1099 {"false", XkbKB_Default},
1100 {"no", XkbKB_Default},
1101 {"off", XkbKB_Default},
1102 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1106 static LookupEntry repeatEntries[] = {
1107 {"true", RepeatYes},
1110 {"false", RepeatNo},
1113 {"default", RepeatUndefined},
1117 static LookupEntry rgEntries[] = {
1123 SetSymbolsField(KeyInfo * key,
1124 struct xkb_desc * xkb,
1126 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1131 if (uStrCaseCmp(field, "type") == 0)
1134 if ((!ExprResolveString(value, &tmp))
1135 && (warningLevel > 0))
1137 WARN("The type field of a key symbol map must be a string\n");
1138 ACTION("Ignoring illegal type definition\n");
1140 if (arrayNdx == NULL)
1142 key->dfltType = xkb_intern_atom(tmp.str);
1143 key->defs.defined |= _Key_Type_Dflt;
1145 else if (!ExprResolveInteger(arrayNdx, &ndx, SimpleLookup,
1146 (char *) groupNames))
1148 ERROR("Illegal group index for type of key %s\n",
1149 longText(key->name));
1150 ACTION("Definition with non-integer array index ignored\n");
1154 else if ((ndx.uval < 1) || (ndx.uval > XkbNumKbdGroups))
1157 ("Group index for type of key %s is out of range (1..%d)\n",
1158 longText(key->name), XkbNumKbdGroups + 1);
1159 ACTION("Ignoring type for group %d\n", ndx.uval);
1165 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1166 key->typesDefined |= (1 << (ndx.uval - 1));
1170 else if (uStrCaseCmp(field, "symbols") == 0)
1171 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1172 else if (uStrCaseCmp(field, "actions") == 0)
1173 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1174 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1175 (uStrCaseCmp(field, "virtualmods") == 0) ||
1176 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1178 ok = ExprResolveVModMask(value, &tmp, xkb);
1181 key->vmodmap = (tmp.uval >> 8);
1182 key->defs.defined |= _Key_VModMap;
1186 ERROR("Expected a virtual modifier mask, found %s\n",
1187 exprOpText(value->op));
1188 ACTION("Ignoring virtual modifiers definition for key %s\n",
1189 longText(key->name));
1192 else if ((uStrCaseCmp(field, "locking") == 0)
1193 || (uStrCaseCmp(field, "lock") == 0)
1194 || (uStrCaseCmp(field, "locks") == 0))
1196 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1198 key->behavior.type = tmp.uval;
1199 key->defs.defined |= _Key_Behavior;
1201 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1202 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1204 Bool permanent = False;
1205 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1207 ok = ExprResolveInteger(value, &tmp, SimpleLookup,
1208 (char *) rgEntries);
1211 ERROR("Illegal radio group specification for %s\n",
1212 longText(key->name));
1213 ACTION("Non-integer radio group ignored\n");
1218 key->behavior.type = XkbKB_Default;
1219 key->behavior.data = 0;
1222 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1225 ("Radio group specification for %s out of range (1..32)\n",
1226 longText(key->name));
1227 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1230 key->behavior.type =
1231 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1232 key->behavior.data = tmp.uval - 1;
1233 if (key->allowNone & (1 << (tmp.uval - 1)))
1234 key->behavior.data |= XkbKB_RGAllowNone;
1235 key->defs.defined |= _Key_Behavior;
1237 else if (uStrCaseEqual(field, "allownone"))
1239 ok = SetAllowNone(key, arrayNdx, value);
1241 else if (uStrCasePrefix("overlay", field) ||
1242 uStrCasePrefix("permanentoverlay", field))
1244 Bool permanent = False;
1247 if (uStrCasePrefix("permanent", field))
1250 which = &field[sizeof("permanentoverlay") - 1];
1254 which = &field[sizeof("overlay") - 1];
1256 if (sscanf(which, "%d", &overlayNdx) == 1)
1258 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1260 ERROR("Illegal overlay %d specified for %s\n",
1261 overlayNdx, longText(key->name));
1262 ACTION("Ignored\n");
1266 else if (*which == '\0')
1268 else if (warningLevel > 0)
1270 ERROR("Illegal overlay \"%s\" specified for %s\n",
1271 which, longText(key->name));
1272 ACTION("Ignored\n");
1275 ok = ExprResolveKeyName(value, &tmp);
1278 ERROR("Illegal overlay key specification for %s\n",
1279 longText(key->name));
1280 ACTION("Overlay key must be specified by name\n");
1283 if (overlayNdx == 1)
1284 key->behavior.type = XkbKB_Overlay1;
1286 key->behavior.type = XkbKB_Overlay2;
1288 key->behavior.type |= XkbKB_Permanent;
1290 key->behavior.data = 0;
1291 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1292 key->defs.defined |= _Key_Behavior;
1294 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1295 (uStrCaseCmp(field, "repeats") == 0) ||
1296 (uStrCaseCmp(field, "repeat") == 0))
1298 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1301 ERROR("Illegal repeat setting for %s\n",
1302 longText(key->name));
1303 ACTION("Non-boolean repeat setting ignored\n");
1306 key->repeat = tmp.uval;
1307 key->defs.defined |= _Key_Repeat;
1309 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1310 (uStrCaseCmp(field, "wrapgroups") == 0))
1312 ok = ExprResolveBoolean(value, &tmp);
1315 ERROR("Illegal groupsWrap setting for %s\n",
1316 longText(key->name));
1317 ACTION("Non-boolean value ignored\n");
1321 key->groupInfo = XkbWrapIntoRange;
1323 key->groupInfo = XkbClampIntoRange;
1324 key->defs.defined |= _Key_GroupInfo;
1326 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1327 (uStrCaseCmp(field, "clampgroups") == 0))
1329 ok = ExprResolveBoolean(value, &tmp);
1332 ERROR("Illegal groupsClamp setting for %s\n",
1333 longText(key->name));
1334 ACTION("Non-boolean value ignored\n");
1338 key->groupInfo = XkbClampIntoRange;
1340 key->groupInfo = XkbWrapIntoRange;
1341 key->defs.defined |= _Key_GroupInfo;
1343 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1344 (uStrCaseCmp(field, "redirectgroups") == 0))
1346 if (!ExprResolveInteger
1347 (value, &tmp, SimpleLookup, (char *) groupNames))
1349 ERROR("Illegal group index for redirect of key %s\n",
1350 longText(key->name));
1351 ACTION("Definition with non-integer group ignored\n");
1354 if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
1356 ERROR("Out-of-range (1..%d) group for redirect of key %s\n",
1357 XkbNumKbdGroups, longText(key->name));
1358 ERROR("Ignoring illegal group %d\n", tmp.uval);
1362 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1363 key->defs.defined |= _Key_GroupInfo;
1367 ERROR("Unknown field %s in a symbol interpretation\n", field);
1368 ACTION("Definition ignored\n");
1375 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1377 ExprResult tmp, name;
1379 if ((arrayNdx == NULL) && (warningLevel > 0))
1381 WARN("You must specify an index when specifying a group name\n");
1382 ACTION("Group name definition without array subscript ignored\n");
1385 if (!ExprResolveInteger
1386 (arrayNdx, &tmp, SimpleLookup, (char *) groupNames))
1388 ERROR("Illegal index in group name definition\n");
1389 ACTION("Definition with non-integer array index ignored\n");
1392 if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
1395 ("Attempt to specify name for illegal group (must be 1..%d)\n",
1396 XkbNumKbdGroups + 1);
1397 ACTION("Name for group %d ignored\n", tmp.uval);
1400 if (!ExprResolveString(value, &name))
1402 ERROR("Group name must be a string\n");
1403 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1406 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1407 xkb_intern_atom(name.str);
1414 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1416 ExprResult elem, field, tmp;
1420 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1421 return 0; /* internal error, already reported */
1422 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1424 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1427 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1428 (uStrCaseCmp(field.str, "groupname") ==
1431 ret = SetGroupName(info, arrayNdx, stmt->value);
1433 else if ((elem.str == NULL)
1434 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1435 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1437 if (!ExprResolveBoolean(stmt->value, &tmp))
1439 ERROR("Illegal setting for global groupsWrap\n");
1440 ACTION("Non-boolean value ignored\n");
1445 info->groupInfo = XkbWrapIntoRange;
1447 info->groupInfo = XkbClampIntoRange;
1451 else if ((elem.str == NULL)
1452 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1453 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1455 if (!ExprResolveBoolean(stmt->value, &tmp))
1457 ERROR("Illegal setting for global groupsClamp\n");
1458 ACTION("Non-boolean value ignored\n");
1463 info->groupInfo = XkbClampIntoRange;
1465 info->groupInfo = XkbWrapIntoRange;
1469 else if ((elem.str == NULL)
1470 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1471 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1473 if (!ExprResolveInteger(stmt->value, &tmp,
1474 SimpleLookup, (char *) groupNames))
1476 ERROR("Illegal group index for global groupsRedirect\n");
1477 ACTION("Definition with non-integer group ignored\n");
1481 if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
1484 ("Out-of-range (1..%d) group for global groupsRedirect\n",
1486 ACTION("Ignoring illegal group %d\n", tmp.uval);
1490 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1496 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1498 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1501 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1511 HandleSymbolsBody(VarDef * def,
1512 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1515 ExprResult tmp, field;
1518 for (; def != NULL; def = (VarDef *) def->common.next)
1520 if ((def->name) && (def->name->type == ExprFieldRef))
1522 ok = HandleSymbolsVar(def, xkb, info);
1527 if (def->name == NULL)
1529 if ((def->value == NULL)
1530 || (def->value->op == ExprKeysymList))
1531 field.str = strdup("symbols");
1533 field.str = strdup("actions");
1538 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1541 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1550 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1552 unsigned group = info->explicit_group;
1557 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1560 WARN("For the map %s an explicit group specified\n", info->name);
1561 WARN("but key %s has more than one group defined\n",
1562 longText(key->name));
1563 ACTION("All groups except first one will be ignored\n");
1564 for (i = 1; i < XkbNumKbdGroups; i++)
1566 key->numLevels[i] = 0;
1567 if (key->syms[i] != NULL)
1569 key->syms[i] = (uint32_t *) NULL;
1570 if (key->acts[i] != NULL)
1572 key->acts[i] = (union xkb_action *) NULL;
1573 key->types[i] = (uint32_t) 0;
1576 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1578 key->numLevels[group] = key->numLevels[0];
1579 key->numLevels[0] = 0;
1580 key->syms[group] = key->syms[0];
1581 key->syms[0] = (uint32_t *) NULL;
1582 key->acts[group] = key->acts[0];
1583 key->acts[0] = (union xkb_action *) NULL;
1584 key->types[group] = key->types[0];
1585 key->types[0] = (uint32_t) 0;
1590 HandleSymbolsDef(SymbolsDef * stmt,
1591 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1596 CopyKeyInfo(&info->dflt, &key, False);
1597 key.defs.merge = stmt->merge;
1598 key.name = KeyNameToLong(stmt->keyName);
1599 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1605 if (!SetExplicitGroup(info, &key))
1611 if (!AddKeySymbols(info, &key, xkb))
1620 HandleModMapDef(ModMapDef * def,
1621 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1628 if (!LookupModIndex(NULL, None, def->modifier, TypeInt, &rtrn))
1630 ERROR("Illegal modifier map definition\n");
1631 ACTION("Ignoring map for non-modifier \"%s\"\n",
1632 XkbcAtomText(def->modifier));
1636 tmp.modifier = rtrn.uval;
1637 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1639 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1641 tmp.haveSymbol = False;
1642 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1644 else if (ExprResolveKeySym(key, &rtrn))
1646 tmp.haveSymbol = True;
1647 tmp.u.keySym = rtrn.uval;
1651 ERROR("Modmap entries may contain only key names or keysyms\n");
1652 ACTION("Illegal definition for %s modifier ignored\n",
1653 XkbcModIndexText(tmp.modifier));
1657 ok = AddModMapEntry(info, &tmp) && ok;
1663 HandleSymbolsFile(XkbFile * file,
1664 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1668 info->name = _XkbDupString(file->name);
1672 switch (stmt->stmtType)
1675 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1679 case StmtSymbolsDef:
1680 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1684 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1688 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1692 ERROR("Interpretation files may not include other types\n");
1693 ACTION("Ignoring definition of symbol interpretation\n");
1696 case StmtKeycodeDef:
1697 ERROR("Interpretation files may not include other types\n");
1698 ACTION("Ignoring definition of key name\n");
1702 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1706 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1711 if (info->errorCount > 10)
1714 ERROR("Too many errors\n");
1716 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1724 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1727 register Bool gotOne;
1733 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1735 if (j < (int) XkbKeyNumSyms(xkb, i))
1738 if ((XkbKeySym(xkb, i, j) == sym))
1752 * Find the given name in the xkb->map->types and return its index.
1754 * @param name The atom to search for.
1755 * @param type_rtrn Set to the index of the name if found.
1757 * @return True if found, False otherwise.
1760 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1762 register unsigned n;
1764 if (xkb && xkb->map && xkb->map->types)
1766 for (n = 0; n < xkb->map->num_types; n++)
1768 if (xkb->map->types[n].name == (uint32_t) name)
1779 * Assign a type to the given sym and return the Atom for the type assigned.
1782 * - ONE_LEVEL for width 0/1
1783 * - ALPHABETIC for 2 shift levels, with lower/upercase
1784 * - KEYPAD for keypad keys.
1785 * - TWO_LEVEL for other 2 shift level keys.
1786 * and the same for four level keys.
1788 * @param width Number of sysms in syms.
1789 * @param syms The keysyms for the given key (must be size width).
1790 * @param typeNameRtrn Set to the Atom of the type name.
1792 * @returns True if a type could be found, False otherwise.
1795 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1799 if ((width == 1) || (width == 0))
1801 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1804 else if (width == 2)
1806 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1808 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1810 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1812 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1817 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1821 else if (width <= 4)
1823 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1824 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1826 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1828 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1830 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1831 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1833 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1834 /* XXX: why not set autoType here? */
1836 return ((width >= 0) && (width <= 4));
1840 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1841 * groups, and reduce to one group if all groups are identical anyway.
1844 PrepareKeyDef(KeyInfo * key)
1846 int i, j, width, defined, lastGroup;
1849 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1850 /* get highest group number */
1851 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1853 if (defined & (1 << i))
1861 /* If there are empty groups between non-empty ones fill them with data */
1862 /* from the first group. */
1863 /* We can make a wrong assumption here. But leaving gaps is worse. */
1864 for (i = lastGroup; i > 0; i--)
1866 if (defined & (1 << i))
1868 width = key->numLevels[0];
1869 if (key->typesDefined & 1)
1871 for (j = 0; j < width; j++)
1873 key->types[i] = key->types[0];
1875 key->typesDefined |= 1 << i;
1877 if ((key->actsDefined & 1) && key->acts[0])
1879 key->acts[i] = uTypedCalloc(width, union xkb_action);
1880 if (key->acts[i] == NULL)
1882 memcpy((void *) key->acts[i], (void *) key->acts[0],
1883 width * sizeof(union xkb_action));
1884 key->actsDefined |= 1 << i;
1886 if ((key->symsDefined & 1) && key->syms[0])
1888 key->syms[i] = uTypedCalloc(width, uint32_t);
1889 if (key->syms[i] == NULL)
1891 memcpy((void *) key->syms[i], (void *) key->syms[0],
1892 width * sizeof(uint32_t));
1893 key->symsDefined |= 1 << i;
1897 key->numLevels[i] = key->numLevels[0];
1900 /* If all groups are completely identical remove them all */
1901 /* exept the first one. */
1903 for (i = lastGroup; i > 0; i--)
1905 if ((key->numLevels[i] != key->numLevels[0]) ||
1906 (key->types[i] != key->types[0]))
1911 if ((key->syms[i] != key->syms[0]) &&
1912 (key->syms[i] == NULL || key->syms[0] == NULL ||
1913 memcmp((void *) key->syms[i], (void *) key->syms[0],
1914 sizeof(uint32_t) * key->numLevels[0])))
1919 if ((key->acts[i] != key->acts[0]) &&
1920 (key->acts[i] == NULL || key->acts[0] == NULL ||
1921 memcmp((void *) key->acts[i], (void *) key->acts[0],
1922 sizeof(union xkb_action) * key->numLevels[0])))
1930 for (i = lastGroup; i > 0; i--)
1932 key->numLevels[i] = 0;
1933 if (key->syms[i] != NULL)
1935 key->syms[i] = (uint32_t *) NULL;
1936 if (key->acts[i] != NULL)
1938 key->acts[i] = (union xkb_action *) NULL;
1939 key->types[i] = (uint32_t) 0;
1941 key->symsDefined &= 1;
1942 key->actsDefined &= 1;
1943 key->typesDefined &= 1;
1949 * Copy the KeyInfo into the keyboard description.
1951 * This function recurses.
1954 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1957 xkb_keycode_t okc, kc;
1958 unsigned width, tmp, nGroups;
1959 struct xkb_key_type * type;
1960 Bool haveActions, autoType, useAlias;
1962 union xkb_action *outActs;
1963 unsigned types[XkbNumKbdGroups];
1965 useAlias = (start_from == 0);
1967 /* get the keycode for the key. */
1968 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1971 if ((start_from == 0) && (warningLevel >= 5))
1973 WARN("Key %s not found in %s keycodes\n",
1974 longText(key->name),
1975 XkbcAtomText(xkb->names->keycodes));
1976 ACTION("Symbols ignored\n");
1981 haveActions = False;
1982 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1984 if (((i + 1) > nGroups)
1985 && (((key->symsDefined | key->actsDefined) & (1 << i))
1986 || (key->typesDefined) & (1 << i)))
1991 /* Assign the type to the key, if it is missing. */
1992 if (key->types[i] == None)
1994 if (key->dfltType != None)
1995 key->types[i] = key->dfltType;
1996 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1997 &key->types[i], &autoType))
2002 if (warningLevel >= 5)
2004 WARN("No automatic type for %d symbols\n",
2005 (unsigned int) key->numLevels[i]);
2006 ACTION("Using %s for the %s key (keycode %d)\n",
2007 XkbcAtomText(key->types[i]),
2008 longText(key->name), kc);
2012 if (FindNamedType(xkb, key->types[i], &types[i]))
2014 if (!autoType || key->numLevels[i] > 2)
2015 xkb->server->explicit[kc] |= (1 << i);
2019 if (warningLevel >= 3)
2021 WARN("Type \"%s\" is not defined\n",
2022 XkbcAtomText(key->types[i]));
2023 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
2024 longText(key->name), kc);
2026 types[i] = XkbTwoLevelIndex;
2028 /* if the type specifies less syms than the key has, shrink the key */
2029 type = &xkb->map->types[types[i]];
2030 if (type->num_levels < key->numLevels[i])
2032 if (warningLevel > 0)
2035 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
2036 XkbcAtomText(type->name),
2037 (unsigned int) type->num_levels,
2038 longText(key->name),
2039 (unsigned int) key->numLevels[i]);
2040 ACTION("Ignoring extra symbols\n");
2042 key->numLevels[i] = type->num_levels;
2044 if (key->numLevels[i] > width)
2045 width = key->numLevels[i];
2046 if (type->num_levels > width)
2047 width = type->num_levels;
2050 /* width is now the largest width found */
2052 i = width * nGroups;
2053 outSyms = XkbcResizeKeySyms(xkb, kc, i);
2054 if (outSyms == NULL)
2056 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
2057 longText(key->name), kc);
2062 outActs = XkbcResizeKeyActions(xkb, kc, i);
2063 if (outActs == NULL)
2065 WSGO("Could not enlarge actions for %s (key %d)\n",
2066 longText(key->name), kc);
2069 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2073 if (key->defs.defined & _Key_GroupInfo)
2076 i = xkb->map->key_sym_map[kc].group_info;
2078 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2079 xkb->map->key_sym_map[kc].width = width;
2080 for (i = 0; i < nGroups; i++)
2082 /* assign kt_index[i] to the index of the type in map->types.
2083 * kt_index[i] may have been set by a previous run (if we have two
2084 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2085 * default group if we dont even have keys for this group anyway.
2087 * FIXME: There should be a better fix for this.
2089 if (key->numLevels[i])
2090 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2091 if (key->syms[i] != NULL)
2093 /* fill key to "width" symbols*/
2094 for (tmp = 0; tmp < width; tmp++)
2096 if (tmp < key->numLevels[i])
2097 outSyms[tmp] = key->syms[i][tmp];
2099 outSyms[tmp] = NoSymbol;
2100 if ((outActs != NULL) && (key->acts[i] != NULL))
2102 if (tmp < key->numLevels[i])
2103 outActs[tmp] = key->acts[i][tmp];
2105 outActs[tmp].type = XkbSA_NoAction;
2113 switch (key->behavior.type & XkbKB_OpMask)
2117 case XkbKB_Overlay1:
2118 case XkbKB_Overlay2:
2119 /* find key by name! */
2120 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2121 CreateKeyNames(xkb), 0))
2123 if (warningLevel >= 1)
2125 WARN("Key %s not found in %s keycodes\n",
2126 longText(key->nameForOverlayKey),
2127 XkbcAtomText(xkb->names->keycodes));
2128 ACTION("Not treating %s as an overlay key \n",
2129 longText(key->name));
2133 key->behavior.data = okc;
2135 xkb->server->behaviors[kc] = key->behavior;
2136 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2139 if (key->defs.defined & _Key_VModMap)
2141 xkb->server->vmodmap[kc] = key->vmodmap;
2142 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2144 if (key->repeat != RepeatUndefined)
2146 if (key->repeat == RepeatYes)
2147 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2149 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2150 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2153 if (nGroups > xkb->ctrls->num_groups)
2154 xkb->ctrls->num_groups = nGroups;
2156 /* do the same thing for the next key */
2157 CopySymbolsDef(xkb, key, kc + 1);
2162 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2166 if ((!entry->haveSymbol)
2169 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2171 if (warningLevel >= 5)
2173 WARN("Key %s not found in %s keycodes\n",
2174 longText(entry->u.keyName),
2175 XkbcAtomText(xkb->names->keycodes));
2176 ACTION("Modifier map entry for %s not updated\n",
2177 XkbcModIndexText(entry->modifier));
2181 else if (entry->haveSymbol
2182 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2184 if (warningLevel > 5)
2186 WARN("Key \"%s\" not found in %s symbol map\n",
2187 XkbcKeysymText(entry->u.keySym),
2188 XkbcAtomText(xkb->names->symbols));
2189 ACTION("Modifier map entry for %s not updated\n",
2190 XkbcModIndexText(entry->modifier));
2194 xkb->map->modmap[kc] |= (1 << entry->modifier);
2199 * Handle the xkb_symbols section of an xkb file.
2201 * @param file The parsed xkb_symbols section of the xkb file.
2202 * @param xkb Handle to the keyboard description to store the symbols in.
2203 * @param merge Merge strategy (e.g. MergeOverride).
2206 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2211 InitSymbolsInfo(&info, xkb);
2212 info.dflt.defs.fileID = file->id;
2213 info.dflt.defs.merge = merge;
2214 HandleSymbolsFile(file, xkb, merge, &info);
2216 if (info.nKeys == 0) {
2217 FreeSymbolsInfo(&info);
2221 if (info.errorCount == 0)
2225 /* alloc memory in the xkb struct */
2226 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2229 WSGO("Can not allocate names in CompileSymbols\n");
2230 ACTION("Symbols not added\n");
2233 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2236 WSGO("Could not allocate client map in CompileSymbols\n");
2237 ACTION("Symbols not added\n");
2240 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2242 WSGO("Could not allocate server map in CompileSymbols\n");
2243 ACTION("Symbols not added\n");
2246 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2248 WSGO("Could not allocate controls in CompileSymbols\n");
2249 ACTION("Symbols not added\n");
2253 /* now copy info into xkb. */
2254 xkb->names->symbols = xkb_intern_atom(info.name);
2256 ApplyAliases(xkb, False, &info.aliases);
2257 for (i = 0; i < XkbNumKbdGroups; i++)
2259 if (info.groupNames[i] != None)
2260 xkb->names->groups[i] = info.groupNames[i];
2263 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2268 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2270 if (!CopySymbolsDef(xkb, key, 0))
2273 if (warningLevel > 3)
2275 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2277 if (xkb->names->keys[i].name[0] == '\0')
2279 if (XkbKeyNumGroups(xkb, i) < 1)
2282 memcpy(buf, xkb->names->keys[i].name, 4);
2285 ("No symbols defined for <%s> (keycode %d)\n",
2292 ModMapEntry *mm, *next;
2293 for (mm = info.modMap; mm != NULL; mm = next)
2295 if (!CopyModMapDef(xkb, mm))
2297 next = (ModMapEntry *) mm->defs.next;
2300 FreeSymbolsInfo(&info);
2304 FreeSymbolsInfo(&info);