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,
1032 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1034 unsigned ndx, nSyms, nLevels;
1038 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
1042 key->symsDefined |= (1 << ndx);
1045 if (value->op != ExprKeysymList)
1047 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
1048 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
1049 longText(key->name));
1052 if (key->sizeSyms[ndx] != 0)
1054 ERROR("Symbols for key %s, group %d already defined\n",
1055 longText(key->name), ndx + 1);
1056 ACTION("Ignoring duplicate definition\n");
1059 nSyms = value->value.list.nSyms;
1060 nLevels = value->value.list.nLevels;
1061 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
1062 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
1064 WSGO("Could not resize group %d of key %s to contain %d levels\n",
1065 ndx + 1, longText(key->name), nSyms);
1066 ACTION("Symbols lost\n");
1069 key->symsDefined |= (1 << ndx);
1070 for (i = 0; i < nLevels; i++) {
1071 key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
1072 key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
1073 for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
1074 if (key->symsMapIndex[ndx][i] + j >= nSyms)
1076 if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
1077 &key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
1078 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
1079 value->value.list.syms[i], longText(key->name), ndx + 1,
1080 XkbcAtomText(info->groupNames[ndx]), nSyms);
1082 key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
1083 key->symsMapIndex[ndx][i] = -1;
1084 key->symsMapNumEntries[ndx][i] = 0;
1089 for (j = key->numLevels[ndx] - 1;
1090 j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
1091 key->numLevels[ndx]--;
1096 AddActionsToKey(KeyInfo * key,
1097 struct xkb_keymap * xkb,
1098 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1101 unsigned ndx, nActs;
1103 struct xkb_any_action *toAct;
1105 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
1110 key->actsDefined |= (1 << ndx);
1113 if (value->op != ExprActionList)
1115 WSGO("Bad expression type (%d) for action list value\n", value->op);
1116 ACTION("Ignoring actions for group %d of %s\n", ndx,
1117 longText(key->name));
1120 if (key->acts[ndx] != NULL)
1122 WSGO("Actions for key %s, group %d already defined\n",
1123 longText(key->name), ndx);
1126 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1128 act = (ExprDef *) act->common.next;
1132 WSGO("Action list but not actions in AddActionsToKey\n");
1135 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1136 (!ResizeKeyGroup(key, ndx, nActs, nActs, true)))
1138 WSGO("Could not resize group %d of key %s\n", ndx,
1139 longText(key->name));
1140 ACTION("Actions lost\n");
1143 key->actsDefined |= (1 << ndx);
1145 toAct = (struct xkb_any_action *) key->acts[ndx];
1146 act = value->value.child;
1147 for (i = 0; i < nActs; i++, toAct++)
1149 if (!HandleActionDef(act, xkb, toAct, info->action))
1151 ERROR("Illegal action definition for %s\n",
1152 longText(key->name));
1153 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1155 act = (ExprDef *) act->common.next;
1160 static const LookupEntry lockingEntries[] = {
1161 {"true", XkbKB_Lock},
1162 {"yes", XkbKB_Lock},
1164 {"false", XkbKB_Default},
1165 {"no", XkbKB_Default},
1166 {"off", XkbKB_Default},
1167 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1171 static const LookupEntry repeatEntries[] = {
1172 {"true", RepeatYes},
1175 {"false", RepeatNo},
1178 {"default", RepeatUndefined},
1183 SetSymbolsField(KeyInfo * key,
1184 struct xkb_keymap * xkb,
1186 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1191 if (strcasecmp(field, "type") == 0)
1194 if ((!ExprResolveString(value, &tmp))
1195 && (warningLevel > 0))
1197 WARN("The type field of a key symbol map must be a string\n");
1198 ACTION("Ignoring illegal type definition\n");
1200 if (arrayNdx == NULL)
1202 key->dfltType = xkb_intern_atom(tmp.str);
1203 key->defs.defined |= _Key_Type_Dflt;
1205 else if (!ExprResolveGroup(arrayNdx, &ndx))
1207 ERROR("Illegal group index for type of key %s\n",
1208 longText(key->name));
1209 ACTION("Definition with non-integer array index ignored\n");
1215 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1216 key->typesDefined |= (1 << (ndx.uval - 1));
1220 else if (strcasecmp(field, "symbols") == 0)
1221 return AddSymbolsToKey(key, xkb, arrayNdx, value, info);
1222 else if (strcasecmp(field, "actions") == 0)
1223 return AddActionsToKey(key, xkb, arrayNdx, value, info);
1224 else if ((strcasecmp(field, "vmods") == 0) ||
1225 (strcasecmp(field, "virtualmods") == 0) ||
1226 (strcasecmp(field, "virtualmodifiers") == 0))
1228 ok = ExprResolveVModMask(value, &tmp, xkb);
1231 key->vmodmap = (tmp.uval >> 8);
1232 key->defs.defined |= _Key_VModMap;
1236 ERROR("Expected a virtual modifier mask, found %s\n",
1237 exprOpText(value->op));
1238 ACTION("Ignoring virtual modifiers definition for key %s\n",
1239 longText(key->name));
1242 else if ((strcasecmp(field, "locking") == 0) ||
1243 (strcasecmp(field, "lock") == 0) ||
1244 (strcasecmp(field, "locks") == 0))
1246 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1248 key->behavior.type = tmp.uval;
1249 key->defs.defined |= _Key_Behavior;
1251 else if ((strcasecmp(field, "radiogroup") == 0) ||
1252 (strcasecmp(field, "permanentradiogroup") == 0) ||
1253 (strcasecmp(field, "allownone") == 0))
1255 ERROR("Radio groups not supported\n");
1256 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1259 else if (uStrCasePrefix("overlay", field) ||
1260 uStrCasePrefix("permanentoverlay", field))
1262 ERROR("Overlays not supported\n");
1263 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1265 else if ((strcasecmp(field, "repeating") == 0) ||
1266 (strcasecmp(field, "repeats") == 0) ||
1267 (strcasecmp(field, "repeat") == 0))
1269 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1272 ERROR("Illegal repeat setting for %s\n",
1273 longText(key->name));
1274 ACTION("Non-boolean repeat setting ignored\n");
1277 key->repeat = tmp.uval;
1278 key->defs.defined |= _Key_Repeat;
1280 else if ((strcasecmp(field, "groupswrap") == 0) ||
1281 (strcasecmp(field, "wrapgroups") == 0))
1283 ok = ExprResolveBoolean(value, &tmp);
1286 ERROR("Illegal groupsWrap setting for %s\n",
1287 longText(key->name));
1288 ACTION("Non-boolean value ignored\n");
1292 key->groupInfo = XkbWrapIntoRange;
1294 key->groupInfo = XkbClampIntoRange;
1295 key->defs.defined |= _Key_GroupInfo;
1297 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1298 (strcasecmp(field, "clampgroups") == 0))
1300 ok = ExprResolveBoolean(value, &tmp);
1303 ERROR("Illegal groupsClamp setting for %s\n",
1304 longText(key->name));
1305 ACTION("Non-boolean value ignored\n");
1309 key->groupInfo = XkbClampIntoRange;
1311 key->groupInfo = XkbWrapIntoRange;
1312 key->defs.defined |= _Key_GroupInfo;
1314 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1315 (strcasecmp(field, "redirectgroups") == 0))
1317 if (!ExprResolveGroup(value, &tmp))
1319 ERROR("Illegal group index for redirect of key %s\n",
1320 longText(key->name));
1321 ACTION("Definition with non-integer group ignored\n");
1325 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1326 key->defs.defined |= _Key_GroupInfo;
1330 ERROR("Unknown field %s in a symbol interpretation\n", field);
1331 ACTION("Definition ignored\n");
1338 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1340 ExprResult tmp, name;
1342 if ((arrayNdx == NULL) && (warningLevel > 0))
1344 WARN("You must specify an index when specifying a group name\n");
1345 ACTION("Group name definition without array subscript ignored\n");
1348 if (!ExprResolveGroup(arrayNdx, &tmp))
1350 ERROR("Illegal index in group name definition\n");
1351 ACTION("Definition with non-integer array index ignored\n");
1354 if (!ExprResolveString(value, &name))
1356 ERROR("Group name must be a string\n");
1357 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1360 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1361 xkb_intern_atom(name.str);
1368 HandleSymbolsVar(VarDef * stmt, struct xkb_keymap * xkb, SymbolsInfo * info)
1370 ExprResult elem, field, tmp;
1374 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1375 return 0; /* internal error, already reported */
1376 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1378 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1381 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1382 (strcasecmp(field.str, "groupname") ==
1385 ret = SetGroupName(info, arrayNdx, stmt->value);
1387 else if ((elem.str == NULL)
1388 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1389 (strcasecmp(field.str, "wrapgroups") == 0)))
1391 if (!ExprResolveBoolean(stmt->value, &tmp))
1393 ERROR("Illegal setting for global groupsWrap\n");
1394 ACTION("Non-boolean value ignored\n");
1399 info->groupInfo = XkbWrapIntoRange;
1401 info->groupInfo = XkbClampIntoRange;
1405 else if ((elem.str == NULL)
1406 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1407 (strcasecmp(field.str, "clampgroups") == 0)))
1409 if (!ExprResolveBoolean(stmt->value, &tmp))
1411 ERROR("Illegal setting for global groupsClamp\n");
1412 ACTION("Non-boolean value ignored\n");
1417 info->groupInfo = XkbClampIntoRange;
1419 info->groupInfo = XkbWrapIntoRange;
1423 else if ((elem.str == NULL)
1424 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1425 (strcasecmp(field.str, "redirectgroups") == 0)))
1427 if (!ExprResolveGroup(stmt->value, &tmp))
1429 ERROR("Illegal group index for global groupsRedirect\n");
1430 ACTION("Definition with non-integer group ignored\n");
1434 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1439 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1441 ERROR("Radio groups not supported\n");
1442 ACTION("Ignoring \"allow none\" specification\n");
1446 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1456 HandleSymbolsBody(VarDef * def,
1457 struct xkb_keymap * xkb, KeyInfo * key, SymbolsInfo * info)
1460 ExprResult tmp, field;
1463 for (; def != NULL; def = (VarDef *) def->common.next)
1465 if ((def->name) && (def->name->type == ExprFieldRef))
1467 ok = HandleSymbolsVar(def, xkb, info);
1472 if (def->name == NULL)
1474 if ((def->value == NULL)
1475 || (def->value->op == ExprKeysymList))
1476 field.str = strdup("symbols");
1478 field.str = strdup("actions");
1483 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1486 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1495 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1497 unsigned group = info->explicit_group;
1502 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1505 WARN("For the map %s an explicit group specified\n", info->name);
1506 WARN("but key %s has more than one group defined\n",
1507 longText(key->name));
1508 ACTION("All groups except first one will be ignored\n");
1509 for (i = 1; i < XkbNumKbdGroups; i++)
1511 key->numLevels[i] = 0;
1513 key->syms[i] = NULL;
1515 key->acts[i] = NULL;
1519 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1521 key->numLevels[group] = key->numLevels[0];
1522 key->numLevels[0] = 0;
1523 key->syms[group] = key->syms[0];
1524 key->syms[0] = NULL;
1525 key->sizeSyms[group] = key->sizeSyms[0];
1526 key->sizeSyms[0] = 0;
1527 key->symsMapIndex[group] = key->symsMapIndex[0];
1528 key->symsMapIndex[0] = NULL;
1529 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1530 key->symsMapNumEntries[0] = NULL;
1531 key->acts[group] = key->acts[0];
1532 key->acts[0] = NULL;
1533 key->types[group] = key->types[0];
1539 HandleSymbolsDef(SymbolsDef * stmt,
1540 struct xkb_keymap *xkb, SymbolsInfo *info)
1545 CopyKeyInfo(&info->dflt, &key, false);
1546 key.defs.merge = stmt->merge;
1547 key.name = KeyNameToLong(stmt->keyName);
1548 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1554 if (!SetExplicitGroup(info, &key))
1560 if (!AddKeySymbols(info, &key, xkb))
1569 HandleModMapDef(ModMapDef * def,
1570 struct xkb_keymap * xkb, SymbolsInfo * info)
1577 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1579 ERROR("Illegal modifier map definition\n");
1580 ACTION("Ignoring map for non-modifier \"%s\"\n",
1581 XkbcAtomText(def->modifier));
1585 tmp.modifier = rtrn.uval;
1586 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1588 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1590 tmp.haveSymbol = false;
1591 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1593 else if (ExprResolveKeySym(key, &rtrn))
1595 tmp.haveSymbol = true;
1596 tmp.u.keySym = rtrn.uval;
1600 ERROR("Modmap entries may contain only key names or keysyms\n");
1601 ACTION("Illegal definition for %s modifier ignored\n",
1602 XkbcModIndexText(tmp.modifier));
1606 ok = AddModMapEntry(info, &tmp) && ok;
1612 HandleSymbolsFile(XkbFile * file,
1613 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1618 info->name = uDupString(file->name);
1622 switch (stmt->stmtType)
1625 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1629 case StmtSymbolsDef:
1630 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, info))
1634 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1638 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1642 ERROR("Interpretation files may not include other types\n");
1643 ACTION("Ignoring definition of symbol interpretation\n");
1646 case StmtKeycodeDef:
1647 ERROR("Interpretation files may not include other types\n");
1648 ACTION("Ignoring definition of key name\n");
1652 if (!HandleModMapDef((ModMapDef *) stmt, xkb, info))
1656 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1661 if (info->errorCount > 10)
1664 ERROR("Too many errors\n");
1666 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1673 FindKeyForSymbol(struct xkb_keymap * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1676 unsigned int group, level;
1678 for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
1680 for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
1682 for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
1684 if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
1685 (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
1697 * Find the given name in the xkb->map->types and return its index.
1699 * @param atom The atom to search for.
1700 * @param type_rtrn Set to the index of the name if found.
1702 * @return true if found, false otherwise.
1705 FindNamedType(struct xkb_keymap * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1708 const char *name = XkbcAtomText(atom);
1710 if (xkb && xkb->map && xkb->map->types)
1712 for (n = 0; n < xkb->map->num_types; n++)
1714 if (strcmp(xkb->map->types[n].name, name) == 0)
1725 * Assign a type to the given sym and return the Atom for the type assigned.
1728 * - ONE_LEVEL for width 0/1
1729 * - ALPHABETIC for 2 shift levels, with lower/upercase
1730 * - KEYPAD for keypad keys.
1731 * - TWO_LEVEL for other 2 shift level keys.
1732 * and the same for four level keys.
1734 * @param width Number of sysms in syms.
1735 * @param syms The keysyms for the given key (must be size width).
1736 * @param typeNameRtrn Set to the Atom of the type name.
1738 * @returns true if a type could be found, false otherwise.
1741 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1745 if ((width == 1) || (width == 0))
1747 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1750 else if (width == 2)
1752 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1754 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1756 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1758 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1763 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1767 else if (width <= 4)
1769 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1770 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1772 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1774 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1776 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1777 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1779 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1780 /* XXX: why not set autoType here? */
1782 return ((width >= 0) && (width <= 4));
1786 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1787 * groups, and reduce to one group if all groups are identical anyway.
1790 PrepareKeyDef(KeyInfo * key)
1792 int i, j, width, defined, lastGroup;
1795 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1796 /* get highest group number */
1797 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1799 if (defined & (1 << i))
1807 /* If there are empty groups between non-empty ones fill them with data */
1808 /* from the first group. */
1809 /* We can make a wrong assumption here. But leaving gaps is worse. */
1810 for (i = lastGroup; i > 0; i--)
1812 if (defined & (1 << i))
1814 width = key->numLevels[0];
1815 if (key->typesDefined & 1)
1817 for (j = 0; j < width; j++)
1819 key->types[i] = key->types[0];
1821 key->typesDefined |= 1 << i;
1823 if ((key->actsDefined & 1) && key->acts[0])
1825 key->acts[i] = uTypedCalloc(width, union xkb_action);
1826 if (key->acts[i] == NULL)
1828 memcpy(key->acts[i], key->acts[0],
1829 width * sizeof(union xkb_action));
1830 key->actsDefined |= 1 << i;
1832 if ((key->symsDefined & 1) && key->sizeSyms[0])
1834 key->syms[i] = uTypedCalloc(key->sizeSyms[0], xkb_keysym_t);
1835 if (key->syms[i] == NULL)
1837 memcpy(key->syms[i], key->syms[0],
1838 key->sizeSyms[0] * sizeof(xkb_keysym_t));
1839 key->symsMapIndex[i] = uTypedCalloc(width, int);
1840 if (!key->symsMapIndex[i])
1843 key->syms[i] = NULL;
1846 memcpy(key->symsMapIndex[i], key->symsMapIndex[0],
1847 width * sizeof(int));
1848 key->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
1849 if (!key->symsMapNumEntries[i])
1852 key->syms[i] = NULL;
1853 free(key->symsMapIndex[i]);
1854 key->symsMapIndex[i] = NULL;
1857 memcpy(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1858 width * sizeof(int));
1859 key->sizeSyms[i] = key->sizeSyms[0];
1860 key->symsDefined |= 1 << i;
1864 key->numLevels[i] = key->numLevels[0];
1867 /* If all groups are completely identical remove them all */
1868 /* exept the first one. */
1870 for (i = lastGroup; i > 0; i--)
1872 if ((key->numLevels[i] != key->numLevels[0]) ||
1873 (key->types[i] != key->types[0]))
1878 if ((key->syms[i] != key->syms[0]) &&
1879 (key->syms[i] == NULL || key->syms[0] == NULL ||
1880 key->sizeSyms[i] != key->sizeSyms[0] ||
1881 memcmp(key->syms[i], key->syms[0],
1882 sizeof(xkb_keysym_t) * key->sizeSyms[0])))
1887 if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
1888 (key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
1889 memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
1890 key->numLevels[0] * sizeof(int))))
1895 if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
1896 (key->symsMapNumEntries[i] == NULL ||
1897 key->symsMapNumEntries[0] == NULL ||
1898 memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1899 key->numLevels[0] * sizeof(int))))
1904 if ((key->acts[i] != key->acts[0]) &&
1905 (key->acts[i] == NULL || key->acts[0] == NULL ||
1906 memcmp(key->acts[i], key->acts[0],
1907 sizeof(union xkb_action) * key->numLevels[0])))
1915 for (i = lastGroup; i > 0; i--)
1917 key->numLevels[i] = 0;
1919 key->syms[i] = NULL;
1920 key->sizeSyms[i] = 0;
1921 free(key->symsMapIndex[i]);
1922 key->symsMapIndex[i] = NULL;
1923 free(key->symsMapNumEntries[i]);
1924 key->symsMapNumEntries[i] = NULL;
1926 key->acts[i] = NULL;
1929 key->symsDefined &= 1;
1930 key->actsDefined &= 1;
1931 key->typesDefined &= 1;
1936 * Copy the KeyInfo into the keyboard description.
1938 * This function recurses.
1941 CopySymbolsDef(struct xkb_keymap * xkb, KeyInfo *key, int start_from)
1945 unsigned int sizeSyms = 0;
1946 unsigned width, tmp, nGroups;
1947 struct xkb_key_type * type;
1948 bool haveActions, autoType, useAlias;
1949 unsigned types[XkbNumKbdGroups];
1950 union xkb_action *outActs;
1951 unsigned int symIndex = 0;
1953 useAlias = (start_from == 0);
1955 /* get the keycode for the key. */
1956 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1959 if ((start_from == 0) && (warningLevel >= 5))
1961 WARN("Key %s not found in keycodes\n", longText(key->name));
1962 ACTION("Symbols ignored\n");
1967 haveActions = false;
1968 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1970 if (((i + 1) > nGroups)
1971 && (((key->symsDefined | key->actsDefined) & (1 << i))
1972 || (key->typesDefined) & (1 << i)))
1977 /* Assign the type to the key, if it is missing. */
1978 if (key->types[i] == XKB_ATOM_NONE)
1980 if (key->dfltType != XKB_ATOM_NONE)
1981 key->types[i] = key->dfltType;
1982 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1983 &key->types[i], &autoType))
1988 if (warningLevel >= 5)
1990 WARN("No automatic type for %d symbols\n",
1991 (unsigned int) key->numLevels[i]);
1992 ACTION("Using %s for the %s key (keycode %d)\n",
1993 XkbcAtomText(key->types[i]),
1994 longText(key->name), kc);
1998 if (FindNamedType(xkb, key->types[i], &types[i]))
2000 if (!autoType || key->numLevels[i] > 2)
2001 xkb->server->explicit[kc] |= (1 << i);
2005 if (warningLevel >= 3)
2007 WARN("Type \"%s\" is not defined\n",
2008 XkbcAtomText(key->types[i]));
2009 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
2010 longText(key->name), kc);
2012 types[i] = XkbTwoLevelIndex;
2014 /* if the type specifies fewer levels than the key has, shrink the key */
2015 type = &xkb->map->types[types[i]];
2016 if (type->num_levels < key->numLevels[i])
2018 if (warningLevel > 0)
2020 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
2021 type->name, type->num_levels,
2022 XkbcAtomText(key->name), key->numLevels[i]);
2023 ACTION("Ignoring extra symbols\n");
2025 key->numLevels[i] = type->num_levels;
2027 if (key->numLevels[i] > width)
2028 width = key->numLevels[i];
2029 if (type->num_levels > width)
2030 width = type->num_levels;
2031 sizeSyms += key->sizeSyms[i];
2034 if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
2036 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
2037 longText(key->name), kc);
2042 outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
2043 if (outActs == NULL)
2045 WSGO("Could not enlarge actions for %s (key %d)\n",
2046 longText(key->name), kc);
2049 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2053 if (key->defs.defined & _Key_GroupInfo)
2056 i = xkb->map->key_sym_map[kc].group_info;
2058 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2059 xkb->map->key_sym_map[kc].width = width;
2060 xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
2061 xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
2063 for (i = 0; i < nGroups; i++)
2065 /* assign kt_index[i] to the index of the type in map->types.
2066 * kt_index[i] may have been set by a previous run (if we have two
2067 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2068 * default group if we dont even have keys for this group anyway.
2070 * FIXME: There should be a better fix for this.
2072 if (key->numLevels[i])
2073 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2074 if (key->sizeSyms[i] != 0)
2076 /* fill key to "width" symbols*/
2077 for (tmp = 0; tmp < width; tmp++)
2079 if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
2081 memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
2082 &key->syms[i][key->symsMapIndex[i][tmp]],
2083 key->symsMapNumEntries[i][tmp] *
2084 sizeof(xkb_keysym_t));
2085 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
2087 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
2088 key->symsMapNumEntries[i][tmp];
2090 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
2094 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
2095 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
2097 if ((outActs != NULL) && (key->acts[i] != NULL))
2099 if (tmp < key->numLevels[i])
2100 outActs[tmp] = key->acts[i][tmp];
2102 outActs[tmp].type = XkbSA_NoAction;
2107 switch (key->behavior.type & XkbKB_OpMask)
2112 xkb->server->behaviors[kc] = key->behavior;
2113 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2116 if (key->defs.defined & _Key_VModMap)
2118 xkb->server->vmodmap[kc] = key->vmodmap;
2119 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2121 if (key->repeat != RepeatUndefined)
2123 if (key->repeat == RepeatYes)
2124 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2126 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2127 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2130 if (nGroups > xkb->ctrls->num_groups)
2131 xkb->ctrls->num_groups = nGroups;
2133 /* do the same thing for the next key */
2134 CopySymbolsDef(xkb, key, kc + 1);
2139 CopyModMapDef(struct xkb_keymap * xkb, ModMapEntry *entry)
2143 if ((!entry->haveSymbol)
2146 (xkb, entry->u.keyName, &kc, true, CreateKeyNames(xkb), 0)))
2148 if (warningLevel >= 5)
2150 WARN("Key %s not found in keycodes\n",
2151 longText(entry->u.keyName));
2152 ACTION("Modifier map entry for %s not updated\n",
2153 XkbcModIndexText(entry->modifier));
2157 else if (entry->haveSymbol
2158 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2160 if (warningLevel > 5)
2162 WARN("Key \"%s\" not found in symbol map\n",
2163 XkbcKeysymText(entry->u.keySym));
2164 ACTION("Modifier map entry for %s not updated\n",
2165 XkbcModIndexText(entry->modifier));
2169 xkb->map->modmap[kc] |= (1 << entry->modifier);
2174 * Handle the xkb_symbols section of an xkb file.
2176 * @param file The parsed xkb_symbols section of the xkb file.
2177 * @param xkb Handle to the keyboard description to store the symbols in.
2178 * @param merge Merge strategy (e.g. MergeOverride).
2181 CompileSymbols(XkbFile *file, struct xkb_keymap * xkb, unsigned merge)
2186 InitSymbolsInfo(&info, xkb);
2187 info.dflt.defs.fileID = file->id;
2188 info.dflt.defs.merge = merge;
2189 HandleSymbolsFile(file, xkb, merge, &info);
2191 if (info.nKeys == 0) {
2192 FreeSymbolsInfo(&info);
2196 if (info.errorCount == 0)
2200 /* alloc memory in the xkb struct */
2201 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
2203 WSGO("Can not allocate names in CompileSymbols\n");
2204 ACTION("Symbols not added\n");
2207 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2210 WSGO("Could not allocate client map in CompileSymbols\n");
2211 ACTION("Symbols not added\n");
2214 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2216 WSGO("Could not allocate server map in CompileSymbols\n");
2217 ACTION("Symbols not added\n");
2220 if (XkbcAllocControls(xkb) != Success)
2222 WSGO("Could not allocate controls in CompileSymbols\n");
2223 ACTION("Symbols not added\n");
2227 /* now copy info into xkb. */
2229 ApplyAliases(xkb, &info.aliases);
2230 for (i = 0; i < XkbNumKbdGroups; i++)
2232 if (info.groupNames[i] != XKB_ATOM_NONE)
2234 free(UNCONSTIFY(xkb->names->groups[i]));
2235 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2239 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2244 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2246 if (!CopySymbolsDef(xkb, key, 0))
2249 if (warningLevel > 3)
2251 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2253 if (xkb->names->keys[i].name[0] == '\0')
2255 if (XkbKeyNumGroups(xkb, i) < 1)
2258 memcpy(buf, xkb->names->keys[i].name, 4);
2261 ("No symbols defined for <%s> (keycode %d)\n",
2268 ModMapEntry *mm, *next;
2269 for (mm = info.modMap; mm != NULL; mm = next)
2271 if (!CopyModMapDef(xkb, mm))
2273 next = (ModMapEntry *) mm->defs.next;
2276 FreeSymbolsInfo(&info);
2280 FreeSymbolsInfo(&info);