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];
68 /* syms[group] -> Single array for all the keysyms in the group. */
69 xkb_keysym_t *syms[XkbNumKbdGroups];
70 /* sizeSyms[group] -> The size of the syms[group] array. */
71 int sizeSyms[XkbNumKbdGroups];
73 * symsMapIndex[group][level] -> The index from which the syms for
74 * the level begin in the syms[group] array. Remember each keycode
75 * can have multiple keysyms in each level (that is, each key press
76 * can result in multiple keysyms).
78 int *symsMapIndex[XkbNumKbdGroups];
80 * symsMapNumEntries[group][level] -> How many syms are in
81 * syms[group][symsMapIndex[group][level]].
83 unsigned int *symsMapNumEntries[XkbNumKbdGroups];
85 union xkb_action *acts[XkbNumKbdGroups];
86 xkb_atom_t types[XkbNumKbdGroups];
88 struct xkb_behavior behavior;
89 unsigned short vmodmap;
90 unsigned long allowNone;
95 * Init the given key info to sane values.
98 InitKeyInfo(KeyInfo * info)
101 static char dflt[4] = "*";
103 info->defs.defined = 0;
104 info->defs.fileID = 0;
105 info->defs.merge = MergeOverride;
106 info->defs.next = NULL;
107 info->name = KeyNameToLong(dflt);
109 info->typesDefined = info->symsDefined = info->actsDefined = 0;
110 for (i = 0; i < XkbNumKbdGroups; i++)
112 info->numLevels[i] = 0;
113 info->types[i] = XKB_ATOM_NONE;
114 info->syms[i] = NULL;
115 info->sizeSyms[i] = 0;
116 info->symsMapIndex[i] = NULL;
117 info->symsMapNumEntries[i] = NULL;
118 info->acts[i] = NULL;
120 info->dfltType = XKB_ATOM_NONE;
121 info->behavior.type = XkbKB_Default;
122 info->behavior.data = 0;
124 info->repeat = RepeatUndefined;
129 * Free memory associated with this key info and reset to sane values.
132 FreeKeyInfo(KeyInfo * info)
136 info->defs.defined = 0;
137 info->defs.fileID = 0;
138 info->defs.merge = MergeOverride;
139 info->defs.next = NULL;
141 info->typesDefined = info->symsDefined = info->actsDefined = 0;
142 for (i = 0; i < XkbNumKbdGroups; i++)
144 info->numLevels[i] = 0;
145 info->types[i] = XKB_ATOM_NONE;
147 info->syms[i] = NULL;
148 info->sizeSyms[i] = 0;
149 free(info->symsMapIndex[i]);
150 info->symsMapIndex[i] = NULL;
151 free(info->symsMapNumEntries[i]);
152 info->symsMapNumEntries[i] = NULL;
154 info->acts[i] = NULL;
156 info->dfltType = XKB_ATOM_NONE;
157 info->behavior.type = XkbKB_Default;
158 info->behavior.data = 0;
160 info->repeat = RepeatUndefined;
165 * Copy old into new, optionally reset old to 0.
166 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
167 * newly allocated and new points to the new memory areas.
170 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
175 new->defs.next = NULL;
178 for (i = 0; i < XkbNumKbdGroups; i++)
180 old->numLevels[i] = 0;
181 old->symsMapIndex[i] = NULL;
182 old->symsMapNumEntries[i] = NULL;
184 old->sizeSyms[i] = 0;
191 for (i = 0; i < XkbNumKbdGroups; i++)
193 width = new->numLevels[i];
194 if (old->syms[i] != NULL)
196 new->syms[i] = uTypedCalloc(new->sizeSyms[i], xkb_keysym_t);
200 new->sizeSyms[i] = 0;
201 new->numLevels[i] = 0;
205 memcpy(new->syms[i], old->syms[i],
206 new->sizeSyms[i] * sizeof(xkb_keysym_t));
207 new->symsMapIndex[i] = uTypedCalloc(width, int);
208 if (!new->symsMapIndex[i])
212 new->sizeSyms[i] = 0;
213 new->numLevels[i] = 0;
217 memcpy(new->symsMapIndex[i], old->symsMapIndex[i],
218 width * sizeof(int));
219 new->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
220 if (!new->symsMapNumEntries[i])
224 new->sizeSyms[i] = 0;
225 free(new->symsMapIndex[i]);
226 new->symsMapIndex[i] = NULL;
227 new->numLevels[i] = 0;
231 memcpy(new->symsMapNumEntries[i], old->symsMapNumEntries[i],
232 width * sizeof(unsigned int));
234 if (old->acts[i] != NULL)
236 new->acts[i] = uTypedCalloc(width, union xkb_action);
241 new->sizeSyms[i] = 0;
242 free(new->symsMapIndex[i]);
243 new->symsMapIndex[i] = NULL;
244 free(new->symsMapNumEntries[i]);
245 new->symsMapNumEntries[i] = NULL;
246 new->numLevels[i] = 0;
249 memcpy(new->acts[i], old->acts[i],
250 width * sizeof(union xkb_action));
257 /***====================================================================***/
259 typedef struct _ModMapEntry
266 unsigned long keyName;
271 #define SYMBOLS_INIT_SIZE 110
272 #define SYMBOLS_CHUNK 20
273 typedef struct _SymbolsInfo
275 char *name; /* e.g. pc+us+inet(evdev) */
279 unsigned explicit_group;
287 xkb_atom_t groupNames[XkbNumKbdGroups];
294 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap * xkb)
299 info->explicit_group = 0;
300 info->errorCount = 0;
302 info->merge = MergeOverride;
304 info->szKeys = SYMBOLS_INIT_SIZE;
306 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
308 for (i = 0; i < XkbNumKbdGroups; i++)
309 info->groupNames[i] = XKB_ATOM_NONE;
310 InitKeyInfo(&info->dflt);
311 InitVModInfo(&info->vmods, xkb);
313 info->aliases = NULL;
317 FreeSymbolsInfo(SymbolsInfo * info)
324 for (i = 0; i < info->nKeys; i++)
325 FreeKeyInfo(&info->keys[i]);
329 ClearCommonInfo(&info->modMap->defs);
331 ClearAliases(&info->aliases);
332 memset(info, 0, sizeof(SymbolsInfo));
336 ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
337 unsigned sizeSyms, bool forceActions)
341 if (key->syms[group] == NULL || key->sizeSyms[group] < sizeSyms)
343 key->syms[group] = uTypedRecalloc(key->syms[group],
344 key->sizeSyms[group],
347 if (!key->syms[group]) {
348 key->sizeSyms[group] = 0;
351 key->sizeSyms[group] = sizeSyms;
353 if (!key->symsMapIndex[group] || key->numLevels[group] < numLevels)
355 key->symsMapIndex[group] = uTypedRealloc(key->symsMapIndex[group],
358 if (!key->symsMapIndex[group])
360 for (i = key->numLevels[group]; i < numLevels; i++)
361 key->symsMapIndex[group][i] = -1;
363 if (!key->symsMapNumEntries[group] || key->numLevels[group] < numLevels)
365 key->symsMapNumEntries[group] =
366 uTypedRecalloc(key->symsMapNumEntries[group],
367 key->numLevels[group],
370 if (!key->symsMapNumEntries[group])
374 (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
375 (key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
377 key->acts[group] = uTypedRecalloc(key->acts[group],
378 key->numLevels[group],
381 if (!key->acts[group])
384 if (key->numLevels[group] < numLevels)
385 key->numLevels[group] = numLevels;
390 MergeKeyGroups(SymbolsInfo * info,
391 KeyInfo * into, KeyInfo * from, unsigned group)
393 xkb_keysym_t *resultSyms = NULL;
394 union xkb_action *resultActs;
395 unsigned int resultWidth;
396 unsigned int resultSize = 0;
399 bool report, clobber;
401 clobber = (from->defs.merge != MergeAugment);
402 report = (warningLevel > 9) ||
403 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
404 if (into->numLevels[group] >= from->numLevels[group])
406 resultActs = into->acts[group];
407 resultWidth = into->numLevels[group];
411 resultActs = from->acts[group];
412 resultWidth = from->numLevels[group];
413 into->symsMapIndex[group] = uTypedRealloc(into->symsMapIndex[group],
414 from->numLevels[group],
416 into->symsMapNumEntries[group] =
417 uTypedRecalloc(into->symsMapNumEntries[group],
418 into->numLevels[group],
419 from->numLevels[group],
421 if (!into->symsMapIndex[group] || !into->symsMapNumEntries[group])
423 WSGO("Could not allocate level indices for key info merge\n");
424 ACTION("Group %d of key %s not merged\n", group,
425 longText(into->name));
429 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
430 into->symsMapIndex[group][i] = -1;
433 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
435 resultActs = uTypedCalloc(resultWidth, union xkb_action);
438 WSGO("Could not allocate actions for group merge\n");
439 ACTION("Group %d of key %s not merged\n", group,
440 longText(into->name));
443 for (i = 0; i < resultWidth; i++)
445 union xkb_action *fromAct, *toAct;
446 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
447 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
448 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
451 resultActs[i] = *toAct;
453 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
454 && (fromAct != NULL))
456 resultActs[i] = *fromAct;
460 union xkb_action *use, *ignore;
474 ("Multiple actions for level %d/group %d on key %s\n",
475 i + 1, group + 1, longText(into->name));
476 ACTION("Using %s, ignoring %s\n",
477 XkbcActionTypeText(use->type),
478 XkbcActionTypeText(ignore->type));
481 resultActs[i] = *use;
486 for (i = 0; i < resultWidth; i++)
488 unsigned int fromSize = 0;
491 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
492 fromSize = from->symsMapNumEntries[group][i];
493 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
494 toSize = into->symsMapNumEntries[group][i];
496 if ((fromSize != 0 && toSize == 0) || clobber)
497 resultSize += fromSize;
499 resultSize += toSize;
505 resultSyms = uTypedCalloc(resultSize, xkb_keysym_t);
508 WSGO("Could not allocate symbols for group merge\n");
509 ACTION("Group %d of key %s not merged\n", group, longText(into->name));
513 for (i = 0; i < resultWidth; i++)
515 enum { NONE, FROM, TO } use;
516 unsigned int fromSize = 0;
517 unsigned int toSize = 0;
519 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
520 fromSize = from->symsMapNumEntries[group][i];
521 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
522 toSize = into->symsMapNumEntries[group][i];
524 if (!fromSize && !toSize)
526 into->symsMapIndex[group][i] = -1;
527 into->symsMapNumEntries[group][i] = 0;
531 if ((fromSize && !toSize) || clobber)
536 if (toSize && fromSize && report)
538 INFO("Multiple symbols for group %d, level %d on key %s\n",
539 group + 1, i + 1, longText(into->name));
540 ACTION("Using %s, ignoring %s\n",
541 (use == FROM ? "from" : "to"),
542 (use == FROM ? "to" : "from"));
547 memcpy(&resultSyms[cur_idx],
548 &from->syms[group][from->symsMapIndex[group][i]],
549 from->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
550 into->symsMapIndex[group][i] = cur_idx;
551 into->symsMapNumEntries[group][i] =
552 from->symsMapNumEntries[group][i];
556 memcpy(&resultSyms[cur_idx],
557 &into->syms[group][from->symsMapIndex[group][i]],
558 into->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
559 into->symsMapIndex[group][i] = cur_idx;
561 cur_idx += into->symsMapNumEntries[group][i];
565 if (resultActs != into->acts[group])
566 free(into->acts[group]);
567 if (resultActs != from->acts[group])
568 free(from->acts[group]);
569 into->numLevels[group] = resultWidth;
570 free(into->syms[group]);
571 into->syms[group] = resultSyms;
572 free(from->syms[group]);
573 from->syms[group] = NULL;
574 from->sizeSyms[group] = 0;
575 into->sizeSyms[group] = resultSize;
576 free(from->symsMapIndex[group]);
577 from->symsMapIndex[group] = NULL;
578 free(from->symsMapNumEntries[group]);
579 from->symsMapNumEntries[group] = NULL;
580 into->acts[group] = resultActs;
581 from->acts[group] = NULL;
582 into->symsDefined |= (1 << group);
583 from->symsDefined &= ~(1 << group);
584 into->actsDefined |= (1 << group);
585 from->actsDefined &= ~(1 << group);
591 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
594 unsigned collide = 0;
597 if (from->defs.merge == MergeReplace)
599 for (i = 0; i < XkbNumKbdGroups; i++)
601 if (into->numLevels[i] != 0)
608 memset(from, 0, sizeof(KeyInfo));
611 report = ((warningLevel > 9) ||
612 ((into->defs.fileID == from->defs.fileID)
613 && (warningLevel > 0)));
614 for (i = 0; i < XkbNumKbdGroups; i++)
616 if (from->numLevels[i] > 0)
618 if (into->numLevels[i] == 0)
620 into->numLevels[i] = from->numLevels[i];
621 into->syms[i] = from->syms[i];
622 into->sizeSyms[i] = from->sizeSyms[i];
623 into->symsMapIndex[i] = from->symsMapIndex[i];
624 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
625 into->acts[i] = from->acts[i];
626 into->symsDefined |= (1 << i);
627 from->syms[i] = NULL;
628 from->sizeSyms[i] = 0;
629 from->symsMapIndex[i] = NULL;
630 from->symsMapNumEntries[i] = NULL;
631 from->acts[i] = NULL;
632 from->numLevels[i] = 0;
633 from->symsDefined &= ~(1 << i);
635 into->defs.defined |= _Key_Syms;
637 into->defs.defined |= _Key_Acts;
644 collide |= _Key_Syms;
646 collide |= _Key_Acts;
648 MergeKeyGroups(info, into, from, (unsigned) i);
651 if (from->types[i] != XKB_ATOM_NONE)
653 if ((into->types[i] != XKB_ATOM_NONE) && report &&
654 (into->types[i] != from->types[i]))
656 xkb_atom_t use, ignore;
657 collide |= _Key_Types;
658 if (from->defs.merge != MergeAugment)
660 use = from->types[i];
661 ignore = into->types[i];
665 use = into->types[i];
666 ignore = from->types[i];
669 ("Multiple definitions for group %d type of key %s\n",
670 i, longText(into->name));
671 ACTION("Using %s, ignoring %s\n",
673 XkbcAtomText(ignore));
675 if ((from->defs.merge != MergeAugment)
676 || (into->types[i] == XKB_ATOM_NONE))
678 into->types[i] = from->types[i];
682 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
684 into->behavior = from->behavior;
685 into->defs.defined |= _Key_Behavior;
687 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
689 into->vmodmap = from->vmodmap;
690 into->defs.defined |= _Key_VModMap;
692 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
694 into->repeat = from->repeat;
695 into->defs.defined |= _Key_Repeat;
697 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
699 into->dfltType = from->dfltType;
700 into->defs.defined |= _Key_Type_Dflt;
702 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
704 into->groupInfo = from->groupInfo;
705 into->defs.defined |= _Key_GroupInfo;
709 WARN("Symbol map for key %s redefined\n",
710 longText(into->name));
711 ACTION("Using %s definition for conflicting fields\n",
712 (from->defs.merge == MergeAugment ? "first" : "last"));
718 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_keymap * xkb)
721 unsigned long real_name;
723 for (i = 0; i < info->nKeys; i++)
725 if (info->keys[i].name == key->name)
726 return MergeKeys(info, &info->keys[i], key);
728 if (FindKeyNameForAlias(xkb, key->name, &real_name))
730 for (i = 0; i < info->nKeys; i++)
732 if (info->keys[i].name == real_name)
733 return MergeKeys(info, &info->keys[i], key);
736 if (info->nKeys >= info->szKeys)
738 info->szKeys += SYMBOLS_CHUNK;
740 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
743 WSGO("Could not allocate key symbols descriptions\n");
744 ACTION("Some key symbols definitions may be lost\n");
748 return CopyKeyInfo(key, &info->keys[info->nKeys++], true);
752 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
757 clobber = (new->defs.merge != MergeAugment);
758 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
760 if (new->haveSymbol && mm->haveSymbol
761 && (new->u.keySym == mm->u.keySym))
763 unsigned use, ignore;
764 if (mm->modifier != new->modifier)
769 ignore = mm->modifier;
774 ignore = new->modifier;
777 ("%s added to symbol map for multiple modifiers\n",
778 XkbcKeysymText(new->u.keySym));
779 ACTION("Using %s, ignoring %s.\n",
780 XkbcModIndexText(use),
781 XkbcModIndexText(ignore));
786 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
787 (new->u.keyName == mm->u.keyName))
789 unsigned use, ignore;
790 if (mm->modifier != new->modifier)
795 ignore = mm->modifier;
800 ignore = new->modifier;
802 ERROR("Key %s added to map for multiple modifiers\n",
803 longText(new->u.keyName));
804 ACTION("Using %s, ignoring %s.\n",
805 XkbcModIndexText(use),
806 XkbcModIndexText(ignore));
812 mm = uTypedAlloc(ModMapEntry);
815 WSGO("Could not allocate modifier map entry\n");
816 ACTION("Modifier map for %s will be incomplete\n",
817 XkbcModIndexText(new->modifier));
821 mm->defs.next = &info->modMap->defs;
826 /***====================================================================***/
829 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
830 unsigned merge, struct xkb_keymap * xkb)
835 if (from->errorCount > 0)
837 into->errorCount += from->errorCount;
840 if (into->name == NULL)
842 into->name = from->name;
845 for (i = 0; i < XkbNumKbdGroups; i++)
847 if (from->groupNames[i] != XKB_ATOM_NONE)
849 if ((merge != MergeAugment) ||
850 (into->groupNames[i] == XKB_ATOM_NONE))
851 into->groupNames[i] = from->groupNames[i];
854 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
856 if (merge != MergeDefault)
857 key->defs.merge = merge;
858 if (!AddKeySymbols(into, key, xkb))
861 if (from->modMap != NULL)
863 ModMapEntry *mm, *next;
864 for (mm = from->modMap; mm != NULL; mm = next)
866 if (merge != MergeDefault)
867 mm->defs.merge = merge;
868 if (!AddModMapEntry(into, mm))
870 next = (ModMapEntry *) mm->defs.next;
875 if (!MergeAliases(&into->aliases, &from->aliases, merge))
879 typedef void (*FileHandler) (XkbFile *rtrn, struct xkb_keymap *xkb,
880 unsigned merge, SymbolsInfo *included);
883 HandleIncludeSymbols(IncludeStmt * stmt,
884 struct xkb_keymap * xkb, SymbolsInfo * info, FileHandler hndlr)
888 SymbolsInfo included;
892 if ((stmt->file == NULL) && (stmt->map == NULL))
896 memset(info, 0, sizeof(SymbolsInfo));
898 else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
901 InitSymbolsInfo(&included, xkb);
902 included.fileID = included.dflt.defs.fileID = rtrn->id;
903 included.merge = included.dflt.defs.merge = MergeOverride;
906 included.explicit_group = atoi(stmt->modifier) - 1;
910 included.explicit_group = info->explicit_group;
912 (*hndlr) (rtrn, xkb, MergeOverride, &included);
913 if (stmt->stmt != NULL)
916 included.name = stmt->stmt;
923 info->errorCount += 10;
926 if ((stmt->next != NULL) && (included.errorCount < 1))
930 SymbolsInfo next_incl;
932 for (next = stmt->next; next != NULL; next = next->next)
934 if ((next->file == NULL) && (next->map == NULL))
937 MergeIncludedSymbols(&included, info, next->merge, xkb);
938 FreeSymbolsInfo(info);
940 else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
943 InitSymbolsInfo(&next_incl, xkb);
944 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
945 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
948 next_incl.explicit_group = atoi(next->modifier) - 1;
952 next_incl.explicit_group = info->explicit_group;
954 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
955 MergeIncludedSymbols(&included, &next_incl, op, xkb);
956 FreeSymbolsInfo(&next_incl);
961 info->errorCount += 10;
962 FreeSymbolsInfo(&included);
969 info->errorCount += included.errorCount;
975 MergeIncludedSymbols(info, &included, newMerge, xkb);
976 FreeSymbolsInfo(&included);
978 return (info->errorCount == 0);
985 GetGroupIndex(KeyInfo * key,
986 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
996 if (arrayNdx == NULL)
1000 if (what == SYMBOLS)
1001 defined = key->symsDefined;
1003 defined = key->actsDefined;
1005 for (i = 0; i < XkbNumKbdGroups; i++)
1007 if ((defined & (1 << i)) == 0)
1013 ERROR("Too many groups of %s for key %s (max %d)\n", name,
1014 longText(key->name), XkbNumKbdGroups + 1);
1015 ACTION("Ignoring %s defined for extra groups\n", name);
1018 if (!ExprResolveGroup(arrayNdx, &tmp))
1020 ERROR("Illegal group index for %s of key %s\n", name,
1021 longText(key->name));
1022 ACTION("Definition with non-integer array index ignored\n");
1025 *ndx_rtrn = tmp.uval - 1;
1030 AddSymbolsToKey(KeyInfo * key,
1031 struct xkb_keymap * xkb,
1033 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1035 unsigned ndx, nSyms, nLevels;
1039 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
1043 key->symsDefined |= (1 << ndx);
1046 if (value->op != ExprKeysymList)
1048 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
1049 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
1050 longText(key->name));
1053 if (key->sizeSyms[ndx] != 0)
1055 ERROR("Symbols for key %s, group %d already defined\n",
1056 longText(key->name), ndx + 1);
1057 ACTION("Ignoring duplicate definition\n");
1060 nSyms = value->value.list.nSyms;
1061 nLevels = value->value.list.nLevels;
1062 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
1063 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
1065 WSGO("Could not resize group %d of key %s to contain %d levels\n",
1066 ndx + 1, longText(key->name), nSyms);
1067 ACTION("Symbols lost\n");
1070 key->symsDefined |= (1 << ndx);
1071 for (i = 0; i < nLevels; i++) {
1072 key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
1073 key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
1074 for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
1075 if (key->symsMapIndex[ndx][i] + j >= nSyms)
1077 if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
1078 &key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
1079 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
1080 value->value.list.syms[i], longText(key->name), ndx + 1,
1081 XkbcAtomText(info->groupNames[ndx]), nSyms);
1083 key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
1084 key->symsMapIndex[ndx][i] = -1;
1085 key->symsMapNumEntries[ndx][i] = 0;
1090 for (j = key->numLevels[ndx] - 1;
1091 j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
1092 key->numLevels[ndx]--;
1097 AddActionsToKey(KeyInfo * key,
1098 struct xkb_keymap * xkb,
1100 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1103 unsigned ndx, nActs;
1105 struct xkb_any_action *toAct;
1107 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
1112 key->actsDefined |= (1 << ndx);
1115 if (value->op != ExprActionList)
1117 WSGO("Bad expression type (%d) for action list value\n", value->op);
1118 ACTION("Ignoring actions for group %d of %s\n", ndx,
1119 longText(key->name));
1122 if (key->acts[ndx] != NULL)
1124 WSGO("Actions for key %s, group %d already defined\n",
1125 longText(key->name), ndx);
1128 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1130 act = (ExprDef *) act->common.next;
1134 WSGO("Action list but not actions in AddActionsToKey\n");
1137 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1138 (!ResizeKeyGroup(key, ndx, nActs, nActs, true)))
1140 WSGO("Could not resize group %d of key %s\n", ndx,
1141 longText(key->name));
1142 ACTION("Actions lost\n");
1145 key->actsDefined |= (1 << ndx);
1147 toAct = (struct xkb_any_action *) key->acts[ndx];
1148 act = value->value.child;
1149 for (i = 0; i < nActs; i++, toAct++)
1151 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1153 ERROR("Illegal action definition for %s\n",
1154 longText(key->name));
1155 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1157 act = (ExprDef *) act->common.next;
1162 static const LookupEntry lockingEntries[] = {
1163 {"true", XkbKB_Lock},
1164 {"yes", XkbKB_Lock},
1166 {"false", XkbKB_Default},
1167 {"no", XkbKB_Default},
1168 {"off", XkbKB_Default},
1169 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1173 static const LookupEntry repeatEntries[] = {
1174 {"true", RepeatYes},
1177 {"false", RepeatNo},
1180 {"default", RepeatUndefined},
1185 SetSymbolsField(KeyInfo * key,
1186 struct xkb_keymap * xkb,
1188 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1193 if (strcasecmp(field, "type") == 0)
1196 if ((!ExprResolveString(value, &tmp))
1197 && (warningLevel > 0))
1199 WARN("The type field of a key symbol map must be a string\n");
1200 ACTION("Ignoring illegal type definition\n");
1202 if (arrayNdx == NULL)
1204 key->dfltType = xkb_intern_atom(tmp.str);
1205 key->defs.defined |= _Key_Type_Dflt;
1207 else if (!ExprResolveGroup(arrayNdx, &ndx))
1209 ERROR("Illegal group index for type of key %s\n",
1210 longText(key->name));
1211 ACTION("Definition with non-integer array index ignored\n");
1217 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1218 key->typesDefined |= (1 << (ndx.uval - 1));
1222 else if (strcasecmp(field, "symbols") == 0)
1223 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1224 else if (strcasecmp(field, "actions") == 0)
1225 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1226 else if ((strcasecmp(field, "vmods") == 0) ||
1227 (strcasecmp(field, "virtualmods") == 0) ||
1228 (strcasecmp(field, "virtualmodifiers") == 0))
1230 ok = ExprResolveVModMask(value, &tmp, xkb);
1233 key->vmodmap = (tmp.uval >> 8);
1234 key->defs.defined |= _Key_VModMap;
1238 ERROR("Expected a virtual modifier mask, found %s\n",
1239 exprOpText(value->op));
1240 ACTION("Ignoring virtual modifiers definition for key %s\n",
1241 longText(key->name));
1244 else if ((strcasecmp(field, "locking") == 0) ||
1245 (strcasecmp(field, "lock") == 0) ||
1246 (strcasecmp(field, "locks") == 0))
1248 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1250 key->behavior.type = tmp.uval;
1251 key->defs.defined |= _Key_Behavior;
1253 else if ((strcasecmp(field, "radiogroup") == 0) ||
1254 (strcasecmp(field, "permanentradiogroup") == 0) ||
1255 (strcasecmp(field, "allownone") == 0))
1257 ERROR("Radio groups not supported\n");
1258 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1261 else if (uStrCasePrefix("overlay", field) ||
1262 uStrCasePrefix("permanentoverlay", field))
1264 ERROR("Overlays not supported\n");
1265 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1267 else if ((strcasecmp(field, "repeating") == 0) ||
1268 (strcasecmp(field, "repeats") == 0) ||
1269 (strcasecmp(field, "repeat") == 0))
1271 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1274 ERROR("Illegal repeat setting for %s\n",
1275 longText(key->name));
1276 ACTION("Non-boolean repeat setting ignored\n");
1279 key->repeat = tmp.uval;
1280 key->defs.defined |= _Key_Repeat;
1282 else if ((strcasecmp(field, "groupswrap") == 0) ||
1283 (strcasecmp(field, "wrapgroups") == 0))
1285 ok = ExprResolveBoolean(value, &tmp);
1288 ERROR("Illegal groupsWrap setting for %s\n",
1289 longText(key->name));
1290 ACTION("Non-boolean value ignored\n");
1294 key->groupInfo = XkbWrapIntoRange;
1296 key->groupInfo = XkbClampIntoRange;
1297 key->defs.defined |= _Key_GroupInfo;
1299 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1300 (strcasecmp(field, "clampgroups") == 0))
1302 ok = ExprResolveBoolean(value, &tmp);
1305 ERROR("Illegal groupsClamp setting for %s\n",
1306 longText(key->name));
1307 ACTION("Non-boolean value ignored\n");
1311 key->groupInfo = XkbClampIntoRange;
1313 key->groupInfo = XkbWrapIntoRange;
1314 key->defs.defined |= _Key_GroupInfo;
1316 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1317 (strcasecmp(field, "redirectgroups") == 0))
1319 if (!ExprResolveGroup(value, &tmp))
1321 ERROR("Illegal group index for redirect of key %s\n",
1322 longText(key->name));
1323 ACTION("Definition with non-integer group ignored\n");
1327 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1328 key->defs.defined |= _Key_GroupInfo;
1332 ERROR("Unknown field %s in a symbol interpretation\n", field);
1333 ACTION("Definition ignored\n");
1340 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1342 ExprResult tmp, name;
1344 if ((arrayNdx == NULL) && (warningLevel > 0))
1346 WARN("You must specify an index when specifying a group name\n");
1347 ACTION("Group name definition without array subscript ignored\n");
1350 if (!ExprResolveGroup(arrayNdx, &tmp))
1352 ERROR("Illegal index in group name definition\n");
1353 ACTION("Definition with non-integer array index ignored\n");
1356 if (!ExprResolveString(value, &name))
1358 ERROR("Group name must be a string\n");
1359 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1362 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1363 xkb_intern_atom(name.str);
1370 HandleSymbolsVar(VarDef * stmt, struct xkb_keymap * xkb, SymbolsInfo * info)
1372 ExprResult elem, field, tmp;
1376 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1377 return 0; /* internal error, already reported */
1378 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1380 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1383 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1384 (strcasecmp(field.str, "groupname") ==
1387 ret = SetGroupName(info, arrayNdx, stmt->value);
1389 else if ((elem.str == NULL)
1390 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1391 (strcasecmp(field.str, "wrapgroups") == 0)))
1393 if (!ExprResolveBoolean(stmt->value, &tmp))
1395 ERROR("Illegal setting for global groupsWrap\n");
1396 ACTION("Non-boolean value ignored\n");
1401 info->groupInfo = XkbWrapIntoRange;
1403 info->groupInfo = XkbClampIntoRange;
1407 else if ((elem.str == NULL)
1408 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1409 (strcasecmp(field.str, "clampgroups") == 0)))
1411 if (!ExprResolveBoolean(stmt->value, &tmp))
1413 ERROR("Illegal setting for global groupsClamp\n");
1414 ACTION("Non-boolean value ignored\n");
1419 info->groupInfo = XkbClampIntoRange;
1421 info->groupInfo = XkbWrapIntoRange;
1425 else if ((elem.str == NULL)
1426 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1427 (strcasecmp(field.str, "redirectgroups") == 0)))
1429 if (!ExprResolveGroup(stmt->value, &tmp))
1431 ERROR("Illegal group index for global groupsRedirect\n");
1432 ACTION("Definition with non-integer group ignored\n");
1436 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1441 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1443 ERROR("Radio groups not supported\n");
1444 ACTION("Ignoring \"allow none\" specification\n");
1448 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1458 HandleSymbolsBody(VarDef * def,
1459 struct xkb_keymap * xkb, KeyInfo * key, SymbolsInfo * info)
1462 ExprResult tmp, field;
1465 for (; def != NULL; def = (VarDef *) def->common.next)
1467 if ((def->name) && (def->name->type == ExprFieldRef))
1469 ok = HandleSymbolsVar(def, xkb, info);
1474 if (def->name == NULL)
1476 if ((def->value == NULL)
1477 || (def->value->op == ExprKeysymList))
1478 field.str = strdup("symbols");
1480 field.str = strdup("actions");
1485 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1488 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1497 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1499 unsigned group = info->explicit_group;
1504 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1507 WARN("For the map %s an explicit group specified\n", info->name);
1508 WARN("but key %s has more than one group defined\n",
1509 longText(key->name));
1510 ACTION("All groups except first one will be ignored\n");
1511 for (i = 1; i < XkbNumKbdGroups; i++)
1513 key->numLevels[i] = 0;
1515 key->syms[i] = NULL;
1517 key->acts[i] = NULL;
1521 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1523 key->numLevels[group] = key->numLevels[0];
1524 key->numLevels[0] = 0;
1525 key->syms[group] = key->syms[0];
1526 key->syms[0] = NULL;
1527 key->sizeSyms[group] = key->sizeSyms[0];
1528 key->sizeSyms[0] = 0;
1529 key->symsMapIndex[group] = key->symsMapIndex[0];
1530 key->symsMapIndex[0] = NULL;
1531 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1532 key->symsMapNumEntries[0] = NULL;
1533 key->acts[group] = key->acts[0];
1534 key->acts[0] = NULL;
1535 key->types[group] = key->types[0];
1541 HandleSymbolsDef(SymbolsDef * stmt,
1542 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1547 CopyKeyInfo(&info->dflt, &key, false);
1548 key.defs.merge = stmt->merge;
1549 key.name = KeyNameToLong(stmt->keyName);
1550 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1556 if (!SetExplicitGroup(info, &key))
1562 if (!AddKeySymbols(info, &key, xkb))
1571 HandleModMapDef(ModMapDef * def,
1572 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1579 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1581 ERROR("Illegal modifier map definition\n");
1582 ACTION("Ignoring map for non-modifier \"%s\"\n",
1583 XkbcAtomText(def->modifier));
1587 tmp.modifier = rtrn.uval;
1588 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1590 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1592 tmp.haveSymbol = false;
1593 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1595 else if (ExprResolveKeySym(key, &rtrn))
1597 tmp.haveSymbol = true;
1598 tmp.u.keySym = rtrn.uval;
1602 ERROR("Modmap entries may contain only key names or keysyms\n");
1603 ACTION("Illegal definition for %s modifier ignored\n",
1604 XkbcModIndexText(tmp.modifier));
1608 ok = AddModMapEntry(info, &tmp) && ok;
1614 HandleSymbolsFile(XkbFile * file,
1615 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1620 info->name = uDupString(file->name);
1624 switch (stmt->stmtType)
1627 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1631 case StmtSymbolsDef:
1632 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1636 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1640 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1644 ERROR("Interpretation files may not include other types\n");
1645 ACTION("Ignoring definition of symbol interpretation\n");
1648 case StmtKeycodeDef:
1649 ERROR("Interpretation files may not include other types\n");
1650 ACTION("Ignoring definition of key name\n");
1654 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1658 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1663 if (info->errorCount > 10)
1666 ERROR("Too many errors\n");
1668 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1675 FindKeyForSymbol(struct xkb_keymap * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1678 unsigned int group, level;
1680 for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
1682 for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
1684 for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
1686 if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
1687 (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
1699 * Find the given name in the xkb->map->types and return its index.
1701 * @param atom The atom to search for.
1702 * @param type_rtrn Set to the index of the name if found.
1704 * @return true if found, false otherwise.
1707 FindNamedType(struct xkb_keymap * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1710 const char *name = XkbcAtomText(atom);
1712 if (xkb && xkb->map && xkb->map->types)
1714 for (n = 0; n < xkb->map->num_types; n++)
1716 if (strcmp(xkb->map->types[n].name, name) == 0)
1727 * Assign a type to the given sym and return the Atom for the type assigned.
1730 * - ONE_LEVEL for width 0/1
1731 * - ALPHABETIC for 2 shift levels, with lower/upercase
1732 * - KEYPAD for keypad keys.
1733 * - TWO_LEVEL for other 2 shift level keys.
1734 * and the same for four level keys.
1736 * @param width Number of sysms in syms.
1737 * @param syms The keysyms for the given key (must be size width).
1738 * @param typeNameRtrn Set to the Atom of the type name.
1740 * @returns true if a type could be found, false otherwise.
1743 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1747 if ((width == 1) || (width == 0))
1749 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1752 else if (width == 2)
1754 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1756 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1758 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1760 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1765 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1769 else if (width <= 4)
1771 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1772 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1774 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1776 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1778 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1779 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1781 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1782 /* XXX: why not set autoType here? */
1784 return ((width >= 0) && (width <= 4));
1788 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1789 * groups, and reduce to one group if all groups are identical anyway.
1792 PrepareKeyDef(KeyInfo * key)
1794 int i, j, width, defined, lastGroup;
1797 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1798 /* get highest group number */
1799 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1801 if (defined & (1 << i))
1809 /* If there are empty groups between non-empty ones fill them with data */
1810 /* from the first group. */
1811 /* We can make a wrong assumption here. But leaving gaps is worse. */
1812 for (i = lastGroup; i > 0; i--)
1814 if (defined & (1 << i))
1816 width = key->numLevels[0];
1817 if (key->typesDefined & 1)
1819 for (j = 0; j < width; j++)
1821 key->types[i] = key->types[0];
1823 key->typesDefined |= 1 << i;
1825 if ((key->actsDefined & 1) && key->acts[0])
1827 key->acts[i] = uTypedCalloc(width, union xkb_action);
1828 if (key->acts[i] == NULL)
1830 memcpy(key->acts[i], key->acts[0],
1831 width * sizeof(union xkb_action));
1832 key->actsDefined |= 1 << i;
1834 if ((key->symsDefined & 1) && key->sizeSyms[0])
1836 key->syms[i] = uTypedCalloc(key->sizeSyms[0], xkb_keysym_t);
1837 if (key->syms[i] == NULL)
1839 memcpy(key->syms[i], key->syms[0],
1840 key->sizeSyms[0] * sizeof(xkb_keysym_t));
1841 key->symsMapIndex[i] = uTypedCalloc(width, int);
1842 if (!key->symsMapIndex[i])
1845 key->syms[i] = NULL;
1848 memcpy(key->symsMapIndex[i], key->symsMapIndex[0],
1849 width * sizeof(int));
1850 key->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
1851 if (!key->symsMapNumEntries[i])
1854 key->syms[i] = NULL;
1855 free(key->symsMapIndex[i]);
1856 key->symsMapIndex[i] = NULL;
1859 memcpy(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1860 width * sizeof(int));
1861 key->sizeSyms[i] = key->sizeSyms[0];
1862 key->symsDefined |= 1 << i;
1866 key->numLevels[i] = key->numLevels[0];
1869 /* If all groups are completely identical remove them all */
1870 /* exept the first one. */
1872 for (i = lastGroup; i > 0; i--)
1874 if ((key->numLevels[i] != key->numLevels[0]) ||
1875 (key->types[i] != key->types[0]))
1880 if ((key->syms[i] != key->syms[0]) &&
1881 (key->syms[i] == NULL || key->syms[0] == NULL ||
1882 key->sizeSyms[i] != key->sizeSyms[0] ||
1883 memcmp(key->syms[i], key->syms[0],
1884 sizeof(xkb_keysym_t) * key->sizeSyms[0])))
1889 if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
1890 (key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
1891 memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
1892 key->numLevels[0] * sizeof(int))))
1897 if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
1898 (key->symsMapNumEntries[i] == NULL ||
1899 key->symsMapNumEntries[0] == NULL ||
1900 memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1901 key->numLevels[0] * sizeof(int))))
1906 if ((key->acts[i] != key->acts[0]) &&
1907 (key->acts[i] == NULL || key->acts[0] == NULL ||
1908 memcmp(key->acts[i], key->acts[0],
1909 sizeof(union xkb_action) * key->numLevels[0])))
1917 for (i = lastGroup; i > 0; i--)
1919 key->numLevels[i] = 0;
1921 key->syms[i] = NULL;
1922 key->sizeSyms[i] = 0;
1923 free(key->symsMapIndex[i]);
1924 key->symsMapIndex[i] = NULL;
1925 free(key->symsMapNumEntries[i]);
1926 key->symsMapNumEntries[i] = NULL;
1928 key->acts[i] = NULL;
1931 key->symsDefined &= 1;
1932 key->actsDefined &= 1;
1933 key->typesDefined &= 1;
1938 * Copy the KeyInfo into the keyboard description.
1940 * This function recurses.
1943 CopySymbolsDef(struct xkb_keymap * xkb, KeyInfo *key, int start_from)
1947 unsigned int sizeSyms = 0;
1948 unsigned width, tmp, nGroups;
1949 struct xkb_key_type * type;
1950 bool haveActions, autoType, useAlias;
1951 unsigned types[XkbNumKbdGroups];
1952 union xkb_action *outActs;
1953 unsigned int symIndex = 0;
1955 useAlias = (start_from == 0);
1957 /* get the keycode for the key. */
1958 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1961 if ((start_from == 0) && (warningLevel >= 5))
1963 WARN("Key %s not found in keycodes\n", longText(key->name));
1964 ACTION("Symbols ignored\n");
1969 haveActions = false;
1970 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1972 if (((i + 1) > nGroups)
1973 && (((key->symsDefined | key->actsDefined) & (1 << i))
1974 || (key->typesDefined) & (1 << i)))
1979 /* Assign the type to the key, if it is missing. */
1980 if (key->types[i] == XKB_ATOM_NONE)
1982 if (key->dfltType != XKB_ATOM_NONE)
1983 key->types[i] = key->dfltType;
1984 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1985 &key->types[i], &autoType))
1990 if (warningLevel >= 5)
1992 WARN("No automatic type for %d symbols\n",
1993 (unsigned int) key->numLevels[i]);
1994 ACTION("Using %s for the %s key (keycode %d)\n",
1995 XkbcAtomText(key->types[i]),
1996 longText(key->name), kc);
2000 if (FindNamedType(xkb, key->types[i], &types[i]))
2002 if (!autoType || key->numLevels[i] > 2)
2003 xkb->server->explicit[kc] |= (1 << i);
2007 if (warningLevel >= 3)
2009 WARN("Type \"%s\" is not defined\n",
2010 XkbcAtomText(key->types[i]));
2011 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
2012 longText(key->name), kc);
2014 types[i] = XkbTwoLevelIndex;
2016 /* if the type specifies fewer levels than the key has, shrink the key */
2017 type = &xkb->map->types[types[i]];
2018 if (type->num_levels < key->numLevels[i])
2020 if (warningLevel > 0)
2022 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
2023 type->name, type->num_levels,
2024 XkbcAtomText(key->name), key->numLevels[i]);
2025 ACTION("Ignoring extra symbols\n");
2027 key->numLevels[i] = type->num_levels;
2029 if (key->numLevels[i] > width)
2030 width = key->numLevels[i];
2031 if (type->num_levels > width)
2032 width = type->num_levels;
2033 sizeSyms += key->sizeSyms[i];
2036 if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
2038 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
2039 longText(key->name), kc);
2044 outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
2045 if (outActs == NULL)
2047 WSGO("Could not enlarge actions for %s (key %d)\n",
2048 longText(key->name), kc);
2051 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2055 if (key->defs.defined & _Key_GroupInfo)
2058 i = xkb->map->key_sym_map[kc].group_info;
2060 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2061 xkb->map->key_sym_map[kc].width = width;
2062 xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
2063 xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
2065 for (i = 0; i < nGroups; i++)
2067 /* assign kt_index[i] to the index of the type in map->types.
2068 * kt_index[i] may have been set by a previous run (if we have two
2069 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2070 * default group if we dont even have keys for this group anyway.
2072 * FIXME: There should be a better fix for this.
2074 if (key->numLevels[i])
2075 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2076 if (key->sizeSyms[i] != 0)
2078 /* fill key to "width" symbols*/
2079 for (tmp = 0; tmp < width; tmp++)
2081 if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
2083 memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
2084 &key->syms[i][key->symsMapIndex[i][tmp]],
2085 key->symsMapNumEntries[i][tmp] *
2086 sizeof(xkb_keysym_t));
2087 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
2089 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
2090 key->symsMapNumEntries[i][tmp];
2092 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
2096 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
2097 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
2099 if ((outActs != NULL) && (key->acts[i] != NULL))
2101 if (tmp < key->numLevels[i])
2102 outActs[tmp] = key->acts[i][tmp];
2104 outActs[tmp].type = XkbSA_NoAction;
2109 switch (key->behavior.type & XkbKB_OpMask)
2114 xkb->server->behaviors[kc] = key->behavior;
2115 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2118 if (key->defs.defined & _Key_VModMap)
2120 xkb->server->vmodmap[kc] = key->vmodmap;
2121 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2123 if (key->repeat != RepeatUndefined)
2125 if (key->repeat == RepeatYes)
2126 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2128 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2129 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2132 if (nGroups > xkb->ctrls->num_groups)
2133 xkb->ctrls->num_groups = nGroups;
2135 /* do the same thing for the next key */
2136 CopySymbolsDef(xkb, key, kc + 1);
2141 CopyModMapDef(struct xkb_keymap * xkb, ModMapEntry *entry)
2145 if ((!entry->haveSymbol)
2148 (xkb, entry->u.keyName, &kc, true, CreateKeyNames(xkb), 0)))
2150 if (warningLevel >= 5)
2152 WARN("Key %s not found in keycodes\n",
2153 longText(entry->u.keyName));
2154 ACTION("Modifier map entry for %s not updated\n",
2155 XkbcModIndexText(entry->modifier));
2159 else if (entry->haveSymbol
2160 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2162 if (warningLevel > 5)
2164 WARN("Key \"%s\" not found in symbol map\n",
2165 XkbcKeysymText(entry->u.keySym));
2166 ACTION("Modifier map entry for %s not updated\n",
2167 XkbcModIndexText(entry->modifier));
2171 xkb->map->modmap[kc] |= (1 << entry->modifier);
2176 * Handle the xkb_symbols section of an xkb file.
2178 * @param file The parsed xkb_symbols section of the xkb file.
2179 * @param xkb Handle to the keyboard description to store the symbols in.
2180 * @param merge Merge strategy (e.g. MergeOverride).
2183 CompileSymbols(XkbFile *file, struct xkb_keymap * xkb, unsigned merge)
2188 InitSymbolsInfo(&info, xkb);
2189 info.dflt.defs.fileID = file->id;
2190 info.dflt.defs.merge = merge;
2191 HandleSymbolsFile(file, xkb, merge, &info);
2193 if (info.nKeys == 0) {
2194 FreeSymbolsInfo(&info);
2198 if (info.errorCount == 0)
2202 /* alloc memory in the xkb struct */
2203 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
2205 WSGO("Can not allocate names in CompileSymbols\n");
2206 ACTION("Symbols not added\n");
2209 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2212 WSGO("Could not allocate client map in CompileSymbols\n");
2213 ACTION("Symbols not added\n");
2216 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2218 WSGO("Could not allocate server map in CompileSymbols\n");
2219 ACTION("Symbols not added\n");
2222 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2224 WSGO("Could not allocate controls in CompileSymbols\n");
2225 ACTION("Symbols not added\n");
2229 /* now copy info into xkb. */
2231 ApplyAliases(xkb, &info.aliases);
2232 for (i = 0; i < XkbNumKbdGroups; i++)
2234 if (info.groupNames[i] != XKB_ATOM_NONE)
2236 free(UNCONSTIFY(xkb->names->groups[i]));
2237 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2241 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2246 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2248 if (!CopySymbolsDef(xkb, key, 0))
2251 if (warningLevel > 3)
2253 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2255 if (xkb->names->keys[i].name[0] == '\0')
2257 if (XkbKeyNumGroups(xkb, i) < 1)
2260 memcpy(buf, xkb->names->keys[i].name, 4);
2263 ("No symbols defined for <%s> (keycode %d)\n",
2270 ModMapEntry *mm, *next;
2271 for (mm = info.modMap; mm != NULL; mm = next)
2273 if (!CopyModMapDef(xkb, mm))
2275 next = (ModMapEntry *) mm->defs.next;
2278 FreeSymbolsInfo(&info);
2282 FreeSymbolsInfo(&info);