1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
31 #include "parseutils.h"
33 #include <X11/keysym.h>
43 /***====================================================================***/
47 #define RepeatUndefined ~((unsigned)0)
49 #define _Key_Syms (1<<0)
50 #define _Key_Acts (1<<1)
51 #define _Key_Repeat (1<<2)
52 #define _Key_Behavior (1<<3)
53 #define _Key_Type_Dflt (1<<4)
54 #define _Key_Types (1<<5)
55 #define _Key_GroupInfo (1<<6)
56 #define _Key_VModMap (1<<7)
58 typedef struct _KeyInfo
61 unsigned long name; /* the 4 chars of the key name, as long */
62 unsigned char groupInfo;
63 unsigned char typesDefined;
64 unsigned char symsDefined;
65 unsigned char actsDefined;
66 unsigned int numLevels[XkbNumKbdGroups];
67 xkb_keysym_t *syms[XkbNumKbdGroups];
68 int sizeSyms[XkbNumKbdGroups];
69 int *symsMapIndex[XkbNumKbdGroups];
70 unsigned int *symsMapNumEntries[XkbNumKbdGroups];
71 union xkb_action *acts[XkbNumKbdGroups];
72 xkb_atom_t types[XkbNumKbdGroups];
74 struct xkb_behavior behavior;
75 unsigned short vmodmap;
76 unsigned long allowNone;
81 * Init the given key info to sane values.
84 InitKeyInfo(KeyInfo * info)
87 static char dflt[4] = "*";
89 info->defs.defined = 0;
90 info->defs.fileID = 0;
91 info->defs.merge = MergeOverride;
92 info->defs.next = NULL;
93 info->name = KeyNameToLong(dflt);
95 info->typesDefined = info->symsDefined = info->actsDefined = 0;
96 for (i = 0; i < XkbNumKbdGroups; i++)
98 info->numLevels[i] = 0;
99 info->types[i] = XKB_ATOM_NONE;
100 info->syms[i] = NULL;
101 info->sizeSyms[i] = 0;
102 info->symsMapIndex[i] = NULL;
103 info->symsMapNumEntries[i] = NULL;
104 info->acts[i] = NULL;
106 info->dfltType = XKB_ATOM_NONE;
107 info->behavior.type = XkbKB_Default;
108 info->behavior.data = 0;
110 info->repeat = RepeatUndefined;
115 * Free memory associated with this key info and reset to sane values.
118 FreeKeyInfo(KeyInfo * info)
122 info->defs.defined = 0;
123 info->defs.fileID = 0;
124 info->defs.merge = MergeOverride;
125 info->defs.next = NULL;
127 info->typesDefined = info->symsDefined = info->actsDefined = 0;
128 for (i = 0; i < XkbNumKbdGroups; i++)
130 info->numLevels[i] = 0;
131 info->types[i] = XKB_ATOM_NONE;
133 info->syms[i] = NULL;
134 info->sizeSyms[i] = 0;
135 free(info->symsMapIndex[i]);
136 info->symsMapIndex[i] = NULL;
137 free(info->symsMapNumEntries[i]);
138 info->symsMapNumEntries[i] = NULL;
140 info->acts[i] = NULL;
142 info->dfltType = XKB_ATOM_NONE;
143 info->behavior.type = XkbKB_Default;
144 info->behavior.data = 0;
146 info->repeat = RepeatUndefined;
151 * Copy old into new, optionally reset old to 0.
152 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
153 * newly allocated and new points to the new memory areas.
156 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
161 new->defs.next = NULL;
164 for (i = 0; i < XkbNumKbdGroups; i++)
166 old->numLevels[i] = 0;
167 old->symsMapIndex[i] = NULL;
168 old->symsMapNumEntries[i] = NULL;
170 old->sizeSyms[i] = 0;
177 for (i = 0; i < XkbNumKbdGroups; i++)
179 width = new->numLevels[i];
180 if (old->syms[i] != NULL)
182 new->syms[i] = uTypedCalloc(new->sizeSyms[i], xkb_keysym_t);
186 new->sizeSyms[i] = 0;
187 new->numLevels[i] = 0;
191 memcpy(new->syms[i], old->syms[i],
192 new->sizeSyms[i] * sizeof(xkb_keysym_t));
193 new->symsMapIndex[i] = uTypedCalloc(width, int);
194 if (!new->symsMapIndex[i])
198 new->sizeSyms[i] = 0;
199 new->numLevels[i] = 0;
203 memcpy(new->symsMapIndex[i], old->symsMapIndex[i],
204 width * sizeof(int));
205 new->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
206 if (!new->symsMapNumEntries[i])
210 new->sizeSyms[i] = 0;
211 free(new->symsMapIndex[i]);
212 new->symsMapIndex[i] = NULL;
213 new->numLevels[i] = 0;
217 memcpy(new->symsMapNumEntries[i], old->symsMapNumEntries[i],
218 sizeof(unsigned int));
220 if (old->acts[i] != NULL)
222 new->acts[i] = uTypedCalloc(width, union xkb_action);
227 new->sizeSyms[i] = 0;
228 free(new->symsMapIndex[i]);
229 new->symsMapIndex[i] = NULL;
230 free(new->symsMapNumEntries[i]);
231 new->symsMapNumEntries[i] = NULL;
232 new->numLevels[i] = 0;
235 memcpy(new->acts[i], old->acts[i],
236 width * sizeof(union xkb_action));
243 /***====================================================================***/
245 typedef struct _ModMapEntry
252 unsigned long keyName;
257 #define SYMBOLS_INIT_SIZE 110
258 #define SYMBOLS_CHUNK 20
259 typedef struct _SymbolsInfo
261 char *name; /* e.g. pc+us+inet(evdev) */
265 unsigned explicit_group;
273 xkb_atom_t groupNames[XkbNumKbdGroups];
280 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap * xkb)
285 info->explicit_group = 0;
286 info->errorCount = 0;
288 info->merge = MergeOverride;
290 info->szKeys = SYMBOLS_INIT_SIZE;
292 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
294 for (i = 0; i < XkbNumKbdGroups; i++)
295 info->groupNames[i] = XKB_ATOM_NONE;
296 InitKeyInfo(&info->dflt);
297 InitVModInfo(&info->vmods, xkb);
299 info->aliases = NULL;
303 FreeSymbolsInfo(SymbolsInfo * info)
310 for (i = 0; i < info->nKeys; i++)
311 FreeKeyInfo(&info->keys[i]);
315 ClearCommonInfo(&info->modMap->defs);
317 ClearAliases(&info->aliases);
318 memset(info, 0, sizeof(SymbolsInfo));
322 ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
323 unsigned sizeSyms, Bool forceActions)
327 if (key->syms[group] == NULL || key->sizeSyms[group] < sizeSyms)
329 key->syms[group] = uTypedRecalloc(key->syms[group],
330 key->sizeSyms[group],
333 if (!key->syms[group]) {
334 key->sizeSyms[group] = 0;
337 key->sizeSyms[group] = sizeSyms;
339 if (!key->symsMapIndex[group] || key->numLevels[group] < numLevels)
341 key->symsMapIndex[group] = uTypedRealloc(key->symsMapIndex[group],
344 if (!key->symsMapIndex[group])
346 for (i = key->numLevels[group]; i < numLevels; i++)
347 key->symsMapIndex[group][i] = -1;
349 if (!key->symsMapNumEntries[group] || key->numLevels[group] < numLevels)
351 key->symsMapNumEntries[group] =
352 uTypedRecalloc(key->symsMapNumEntries[group],
353 key->numLevels[group],
356 if (!key->symsMapNumEntries[group])
360 (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
361 (key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
363 key->acts[group] = uTypedRecalloc(key->acts[group],
364 key->numLevels[group],
367 if (!key->acts[group])
370 if (key->numLevels[group] < numLevels)
371 key->numLevels[group] = numLevels;
376 MergeKeyGroups(SymbolsInfo * info,
377 KeyInfo * into, KeyInfo * from, unsigned group)
379 xkb_keysym_t *resultSyms = NULL;
380 union xkb_action *resultActs;
381 unsigned int resultWidth;
382 unsigned int resultSize = 0;
385 Bool report, clobber;
387 clobber = (from->defs.merge != MergeAugment);
388 report = (warningLevel > 9) ||
389 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
390 if (into->numLevels[group] >= from->numLevels[group])
392 resultActs = into->acts[group];
393 resultWidth = into->numLevels[group];
397 resultActs = from->acts[group];
398 resultWidth = from->numLevels[group];
399 into->symsMapIndex[group] = uTypedRealloc(into->symsMapIndex[group],
400 from->numLevels[group],
402 into->symsMapNumEntries[group] =
403 uTypedRecalloc(into->symsMapNumEntries[group],
404 from->numLevels[group],
405 into->numLevels[group],
407 if (!into->symsMapIndex[group] || !into->symsMapNumEntries[group])
409 WSGO("Could not allocate level indices for key info merge\n");
410 ACTION("Group %d of key %s not merged\n", group,
411 longText(into->name));
415 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
416 into->symsMapIndex[group][i] = -1;
419 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
421 resultActs = uTypedCalloc(resultWidth, union xkb_action);
424 WSGO("Could not allocate actions for group merge\n");
425 ACTION("Group %d of key %s not merged\n", group,
426 longText(into->name));
429 for (i = 0; i < resultWidth; i++)
431 union xkb_action *fromAct, *toAct;
432 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
433 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
434 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
437 resultActs[i] = *toAct;
439 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
440 && (fromAct != NULL))
442 resultActs[i] = *fromAct;
446 union xkb_action *use, *ignore;
460 ("Multiple actions for level %d/group %d on key %s\n",
461 i + 1, group + 1, longText(into->name));
462 ACTION("Using %s, ignoring %s\n",
463 XkbcActionTypeText(use->type),
464 XkbcActionTypeText(ignore->type));
467 resultActs[i] = *use;
472 for (i = 0; i < resultWidth; i++)
474 unsigned int fromSize = 0;
477 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
478 fromSize = from->symsMapNumEntries[group][i];
479 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
480 toSize = into->symsMapNumEntries[group][i];
482 if (fromSize == 0 || fromSize == toSize || clobber)
486 else if (toSize == 0)
488 resultSize += fromSize;
495 resultSyms = uTypedCalloc(resultSize, xkb_keysym_t);
498 WSGO("Could not allocate symbols for group merge\n");
499 ACTION("Group %d of key %s not merged\n", group, longText(into->name));
503 for (i = 0; i < resultWidth; i++)
505 enum { NONE, FROM, TO } use;
506 unsigned int fromSize = 0;
507 unsigned int toSize = 0;
509 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
510 fromSize = from->symsMapNumEntries[group][i];
511 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
512 toSize = into->symsMapNumEntries[group][i];
514 if (!fromSize && !toSize)
516 into->symsMapIndex[group][i] = -1;
517 into->symsMapNumEntries[group][i] = 0;
521 if ((fromSize && !toSize) || clobber)
526 if (toSize && fromSize && report)
528 INFO("Multiple symbols for group %d, level %d on key %s\n",
529 group + 1, i + 1, longText(into->name));
530 ACTION("Using %s, ignoring %s\n",
531 (use == FROM ? "from" : "to"),
532 (use == FROM ? "to" : "from"));
537 memcpy(&resultSyms[cur_idx],
538 &from->syms[group][from->symsMapIndex[group][i]],
539 from->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
540 into->symsMapIndex[group][i] = cur_idx;
541 into->symsMapNumEntries[group][i] =
542 from->symsMapNumEntries[group][i];
546 memcpy(&resultSyms[cur_idx],
547 &into->syms[group][from->symsMapIndex[group][i]],
548 into->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
549 into->symsMapIndex[group][i] = cur_idx;
551 cur_idx += into->symsMapNumEntries[group][i];
555 if (resultActs != into->acts[group])
556 free(into->acts[group]);
557 if (resultActs != from->acts[group])
558 free(from->acts[group]);
559 into->numLevels[group] = resultWidth;
560 free(into->syms[group]);
561 into->syms[group] = resultSyms;
562 free(from->syms[group]);
563 from->syms[group] = NULL;
564 from->sizeSyms[group] = 0;
565 into->sizeSyms[group] = resultSize;
566 free(from->symsMapIndex[group]);
567 from->symsMapIndex[group] = NULL;
568 free(from->symsMapNumEntries[group]);
569 from->symsMapNumEntries[group] = NULL;
570 into->acts[group] = resultActs;
571 from->acts[group] = NULL;
572 into->symsDefined |= (1 << group);
573 from->symsDefined &= ~(1 << group);
574 into->actsDefined |= (1 << group);
575 from->actsDefined &= ~(1 << group);
581 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
584 unsigned collide = 0;
587 if (from->defs.merge == MergeReplace)
589 for (i = 0; i < XkbNumKbdGroups; i++)
591 if (into->numLevels[i] != 0)
598 memset(from, 0, sizeof(KeyInfo));
601 report = ((warningLevel > 9) ||
602 ((into->defs.fileID == from->defs.fileID)
603 && (warningLevel > 0)));
604 for (i = 0; i < XkbNumKbdGroups; i++)
606 if (from->numLevels[i] > 0)
608 if (into->numLevels[i] == 0)
610 into->numLevels[i] = from->numLevels[i];
611 into->syms[i] = from->syms[i];
612 into->sizeSyms[i] = from->sizeSyms[i];
613 into->symsMapIndex[i] = from->symsMapIndex[i];
614 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
615 into->acts[i] = from->acts[i];
616 into->symsDefined |= (1 << i);
617 from->syms[i] = NULL;
618 from->sizeSyms[i] = 0;
619 from->symsMapIndex[i] = NULL;
620 from->symsMapNumEntries[i] = NULL;
621 from->acts[i] = NULL;
622 from->numLevels[i] = 0;
623 from->symsDefined &= ~(1 << i);
625 into->defs.defined |= _Key_Syms;
627 into->defs.defined |= _Key_Acts;
634 collide |= _Key_Syms;
636 collide |= _Key_Acts;
638 MergeKeyGroups(info, into, from, (unsigned) i);
641 if (from->types[i] != XKB_ATOM_NONE)
643 if ((into->types[i] != XKB_ATOM_NONE) && report &&
644 (into->types[i] != from->types[i]))
646 xkb_atom_t use, ignore;
647 collide |= _Key_Types;
648 if (from->defs.merge != MergeAugment)
650 use = from->types[i];
651 ignore = into->types[i];
655 use = into->types[i];
656 ignore = from->types[i];
659 ("Multiple definitions for group %d type of key %s\n",
660 i, longText(into->name));
661 ACTION("Using %s, ignoring %s\n",
663 XkbcAtomText(ignore));
665 if ((from->defs.merge != MergeAugment)
666 || (into->types[i] == XKB_ATOM_NONE))
668 into->types[i] = from->types[i];
672 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
674 into->behavior = from->behavior;
675 into->defs.defined |= _Key_Behavior;
677 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
679 into->vmodmap = from->vmodmap;
680 into->defs.defined |= _Key_VModMap;
682 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
684 into->repeat = from->repeat;
685 into->defs.defined |= _Key_Repeat;
687 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
689 into->dfltType = from->dfltType;
690 into->defs.defined |= _Key_Type_Dflt;
692 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
694 into->groupInfo = from->groupInfo;
695 into->defs.defined |= _Key_GroupInfo;
699 WARN("Symbol map for key %s redefined\n",
700 longText(into->name));
701 ACTION("Using %s definition for conflicting fields\n",
702 (from->defs.merge == MergeAugment ? "first" : "last"));
708 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_keymap * xkb)
711 unsigned long real_name;
713 for (i = 0; i < info->nKeys; i++)
715 if (info->keys[i].name == key->name)
716 return MergeKeys(info, &info->keys[i], key);
718 if (FindKeyNameForAlias(xkb, key->name, &real_name))
720 for (i = 0; i < info->nKeys; i++)
722 if (info->keys[i].name == real_name)
723 return MergeKeys(info, &info->keys[i], key);
726 if (info->nKeys >= info->szKeys)
728 info->szKeys += SYMBOLS_CHUNK;
730 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
733 WSGO("Could not allocate key symbols descriptions\n");
734 ACTION("Some key symbols definitions may be lost\n");
738 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
742 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
747 clobber = (new->defs.merge != MergeAugment);
748 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
750 if (new->haveSymbol && mm->haveSymbol
751 && (new->u.keySym == mm->u.keySym))
753 unsigned use, ignore;
754 if (mm->modifier != new->modifier)
759 ignore = mm->modifier;
764 ignore = new->modifier;
767 ("%s added to symbol map for multiple modifiers\n",
768 XkbcKeysymText(new->u.keySym));
769 ACTION("Using %s, ignoring %s.\n",
770 XkbcModIndexText(use),
771 XkbcModIndexText(ignore));
776 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
777 (new->u.keyName == mm->u.keyName))
779 unsigned use, ignore;
780 if (mm->modifier != new->modifier)
785 ignore = mm->modifier;
790 ignore = new->modifier;
792 ERROR("Key %s added to map for multiple modifiers\n",
793 longText(new->u.keyName));
794 ACTION("Using %s, ignoring %s.\n",
795 XkbcModIndexText(use),
796 XkbcModIndexText(ignore));
802 mm = uTypedAlloc(ModMapEntry);
805 WSGO("Could not allocate modifier map entry\n");
806 ACTION("Modifier map for %s will be incomplete\n",
807 XkbcModIndexText(new->modifier));
811 mm->defs.next = &info->modMap->defs;
816 /***====================================================================***/
819 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
820 unsigned merge, struct xkb_keymap * xkb)
825 if (from->errorCount > 0)
827 into->errorCount += from->errorCount;
830 if (into->name == NULL)
832 into->name = from->name;
835 for (i = 0; i < XkbNumKbdGroups; i++)
837 if (from->groupNames[i] != XKB_ATOM_NONE)
839 if ((merge != MergeAugment) ||
840 (into->groupNames[i] == XKB_ATOM_NONE))
841 into->groupNames[i] = from->groupNames[i];
844 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
846 if (merge != MergeDefault)
847 key->defs.merge = merge;
848 if (!AddKeySymbols(into, key, xkb))
851 if (from->modMap != NULL)
853 ModMapEntry *mm, *next;
854 for (mm = from->modMap; mm != NULL; mm = next)
856 if (merge != MergeDefault)
857 mm->defs.merge = merge;
858 if (!AddModMapEntry(into, mm))
860 next = (ModMapEntry *) mm->defs.next;
865 if (!MergeAliases(&into->aliases, &from->aliases, merge))
869 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
870 struct xkb_keymap * /* xkb */ ,
871 unsigned /* merge */ ,
872 SymbolsInfo * /* included */
876 HandleIncludeSymbols(IncludeStmt * stmt,
877 struct xkb_keymap * xkb, SymbolsInfo * info, FileHandler hndlr)
881 SymbolsInfo included;
885 if ((stmt->file == NULL) && (stmt->map == NULL))
889 memset(info, 0, sizeof(SymbolsInfo));
891 else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
894 InitSymbolsInfo(&included, xkb);
895 included.fileID = included.dflt.defs.fileID = rtrn->id;
896 included.merge = included.dflt.defs.merge = MergeOverride;
899 included.explicit_group = atoi(stmt->modifier) - 1;
903 included.explicit_group = info->explicit_group;
905 (*hndlr) (rtrn, xkb, MergeOverride, &included);
906 if (stmt->stmt != NULL)
909 included.name = stmt->stmt;
916 info->errorCount += 10;
919 if ((stmt->next != NULL) && (included.errorCount < 1))
923 SymbolsInfo next_incl;
925 for (next = stmt->next; next != NULL; next = next->next)
927 if ((next->file == NULL) && (next->map == NULL))
930 MergeIncludedSymbols(&included, info, next->merge, xkb);
931 FreeSymbolsInfo(info);
933 else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
936 InitSymbolsInfo(&next_incl, xkb);
937 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
938 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
941 next_incl.explicit_group = atoi(next->modifier) - 1;
945 next_incl.explicit_group = info->explicit_group;
947 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
948 MergeIncludedSymbols(&included, &next_incl, op, xkb);
949 FreeSymbolsInfo(&next_incl);
954 info->errorCount += 10;
955 FreeSymbolsInfo(&included);
962 info->errorCount += included.errorCount;
968 MergeIncludedSymbols(info, &included, newMerge, xkb);
969 FreeSymbolsInfo(&included);
971 return (info->errorCount == 0);
978 GetGroupIndex(KeyInfo * key,
979 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
989 if (arrayNdx == NULL)
994 defined = key->symsDefined;
996 defined = key->actsDefined;
998 for (i = 0; i < XkbNumKbdGroups; i++)
1000 if ((defined & (1 << i)) == 0)
1006 ERROR("Too many groups of %s for key %s (max %d)\n", name,
1007 longText(key->name), XkbNumKbdGroups + 1);
1008 ACTION("Ignoring %s defined for extra groups\n", name);
1011 if (!ExprResolveGroup(arrayNdx, &tmp))
1013 ERROR("Illegal group index for %s of key %s\n", name,
1014 longText(key->name));
1015 ACTION("Definition with non-integer array index ignored\n");
1018 *ndx_rtrn = tmp.uval - 1;
1023 AddSymbolsToKey(KeyInfo * key,
1024 struct xkb_keymap * xkb,
1026 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1028 unsigned ndx, nSyms, nLevels;
1032 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
1036 key->symsDefined |= (1 << ndx);
1039 if (value->op != ExprKeysymList)
1041 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
1042 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
1043 longText(key->name));
1046 if (key->sizeSyms[ndx] != 0)
1048 ERROR("Symbols for key %s, group %d already defined\n",
1049 longText(key->name), ndx + 1);
1050 ACTION("Ignoring duplicate definition\n");
1053 nSyms = value->value.list.nSyms;
1054 nLevels = value->value.list.nLevels;
1055 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
1056 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, False)))
1058 WSGO("Could not resize group %d of key %s to contain %d levels\n",
1059 ndx + 1, longText(key->name), nSyms);
1060 ACTION("Symbols lost\n");
1063 key->symsDefined |= (1 << ndx);
1064 for (i = 0; i < nLevels; i++) {
1065 key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
1066 key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
1067 for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
1068 if (key->symsMapIndex[ndx][i] + j >= nSyms)
1070 if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
1071 &key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
1072 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
1073 value->value.list.syms[i], longText(key->name), ndx + 1,
1074 XkbcAtomText(info->groupNames[ndx]), nSyms);
1076 key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
1077 key->symsMapIndex[ndx][i] = -1;
1078 key->symsMapNumEntries[ndx][i] = 0;
1083 for (j = key->numLevels[ndx] - 1;
1084 j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
1085 key->numLevels[ndx]--;
1090 AddActionsToKey(KeyInfo * key,
1091 struct xkb_keymap * xkb,
1093 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1096 unsigned ndx, nActs;
1098 struct xkb_any_action *toAct;
1100 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
1105 key->actsDefined |= (1 << ndx);
1108 if (value->op != ExprActionList)
1110 WSGO("Bad expression type (%d) for action list value\n", value->op);
1111 ACTION("Ignoring actions for group %d of %s\n", ndx,
1112 longText(key->name));
1115 if (key->acts[ndx] != NULL)
1117 WSGO("Actions for key %s, group %d already defined\n",
1118 longText(key->name), ndx);
1121 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1123 act = (ExprDef *) act->common.next;
1127 WSGO("Action list but not actions in AddActionsToKey\n");
1130 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1131 (!ResizeKeyGroup(key, ndx, nActs, nActs, True)))
1133 WSGO("Could not resize group %d of key %s\n", ndx,
1134 longText(key->name));
1135 ACTION("Actions lost\n");
1138 key->actsDefined |= (1 << ndx);
1140 toAct = (struct xkb_any_action *) key->acts[ndx];
1141 act = value->value.child;
1142 for (i = 0; i < nActs; i++, toAct++)
1144 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1146 ERROR("Illegal action definition for %s\n",
1147 longText(key->name));
1148 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1150 act = (ExprDef *) act->common.next;
1155 static const LookupEntry lockingEntries[] = {
1156 {"true", XkbKB_Lock},
1157 {"yes", XkbKB_Lock},
1159 {"false", XkbKB_Default},
1160 {"no", XkbKB_Default},
1161 {"off", XkbKB_Default},
1162 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1166 static const LookupEntry repeatEntries[] = {
1167 {"true", RepeatYes},
1170 {"false", RepeatNo},
1173 {"default", RepeatUndefined},
1178 SetSymbolsField(KeyInfo * key,
1179 struct xkb_keymap * xkb,
1181 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1186 if (strcasecmp(field, "type") == 0)
1189 if ((!ExprResolveString(value, &tmp))
1190 && (warningLevel > 0))
1192 WARN("The type field of a key symbol map must be a string\n");
1193 ACTION("Ignoring illegal type definition\n");
1195 if (arrayNdx == NULL)
1197 key->dfltType = xkb_intern_atom(tmp.str);
1198 key->defs.defined |= _Key_Type_Dflt;
1200 else if (!ExprResolveGroup(arrayNdx, &ndx))
1202 ERROR("Illegal group index for type of key %s\n",
1203 longText(key->name));
1204 ACTION("Definition with non-integer array index ignored\n");
1210 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1211 key->typesDefined |= (1 << (ndx.uval - 1));
1215 else if (strcasecmp(field, "symbols") == 0)
1216 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1217 else if (strcasecmp(field, "actions") == 0)
1218 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1219 else if ((strcasecmp(field, "vmods") == 0) ||
1220 (strcasecmp(field, "virtualmods") == 0) ||
1221 (strcasecmp(field, "virtualmodifiers") == 0))
1223 ok = ExprResolveVModMask(value, &tmp, xkb);
1226 key->vmodmap = (tmp.uval >> 8);
1227 key->defs.defined |= _Key_VModMap;
1231 ERROR("Expected a virtual modifier mask, found %s\n",
1232 exprOpText(value->op));
1233 ACTION("Ignoring virtual modifiers definition for key %s\n",
1234 longText(key->name));
1237 else if ((strcasecmp(field, "locking") == 0) ||
1238 (strcasecmp(field, "lock") == 0) ||
1239 (strcasecmp(field, "locks") == 0))
1241 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1243 key->behavior.type = tmp.uval;
1244 key->defs.defined |= _Key_Behavior;
1246 else if ((strcasecmp(field, "radiogroup") == 0) ||
1247 (strcasecmp(field, "permanentradiogroup") == 0) ||
1248 (strcasecmp(field, "allownone") == 0))
1250 ERROR("Radio groups not supported\n");
1251 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1254 else if (uStrCasePrefix("overlay", field) ||
1255 uStrCasePrefix("permanentoverlay", field))
1257 ERROR("Overlays not supported\n");
1258 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1260 else if ((strcasecmp(field, "repeating") == 0) ||
1261 (strcasecmp(field, "repeats") == 0) ||
1262 (strcasecmp(field, "repeat") == 0))
1264 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1267 ERROR("Illegal repeat setting for %s\n",
1268 longText(key->name));
1269 ACTION("Non-boolean repeat setting ignored\n");
1272 key->repeat = tmp.uval;
1273 key->defs.defined |= _Key_Repeat;
1275 else if ((strcasecmp(field, "groupswrap") == 0) ||
1276 (strcasecmp(field, "wrapgroups") == 0))
1278 ok = ExprResolveBoolean(value, &tmp);
1281 ERROR("Illegal groupsWrap setting for %s\n",
1282 longText(key->name));
1283 ACTION("Non-boolean value ignored\n");
1287 key->groupInfo = XkbWrapIntoRange;
1289 key->groupInfo = XkbClampIntoRange;
1290 key->defs.defined |= _Key_GroupInfo;
1292 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1293 (strcasecmp(field, "clampgroups") == 0))
1295 ok = ExprResolveBoolean(value, &tmp);
1298 ERROR("Illegal groupsClamp setting for %s\n",
1299 longText(key->name));
1300 ACTION("Non-boolean value ignored\n");
1304 key->groupInfo = XkbClampIntoRange;
1306 key->groupInfo = XkbWrapIntoRange;
1307 key->defs.defined |= _Key_GroupInfo;
1309 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1310 (strcasecmp(field, "redirectgroups") == 0))
1312 if (!ExprResolveGroup(value, &tmp))
1314 ERROR("Illegal group index for redirect of key %s\n",
1315 longText(key->name));
1316 ACTION("Definition with non-integer group ignored\n");
1320 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1321 key->defs.defined |= _Key_GroupInfo;
1325 ERROR("Unknown field %s in a symbol interpretation\n", field);
1326 ACTION("Definition ignored\n");
1333 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1335 ExprResult tmp, name;
1337 if ((arrayNdx == NULL) && (warningLevel > 0))
1339 WARN("You must specify an index when specifying a group name\n");
1340 ACTION("Group name definition without array subscript ignored\n");
1343 if (!ExprResolveGroup(arrayNdx, &tmp))
1345 ERROR("Illegal index in group name definition\n");
1346 ACTION("Definition with non-integer array index ignored\n");
1349 if (!ExprResolveString(value, &name))
1351 ERROR("Group name must be a string\n");
1352 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1355 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1356 xkb_intern_atom(name.str);
1363 HandleSymbolsVar(VarDef * stmt, struct xkb_keymap * xkb, SymbolsInfo * info)
1365 ExprResult elem, field, tmp;
1369 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1370 return 0; /* internal error, already reported */
1371 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1373 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1376 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1377 (strcasecmp(field.str, "groupname") ==
1380 ret = SetGroupName(info, arrayNdx, stmt->value);
1382 else if ((elem.str == NULL)
1383 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1384 (strcasecmp(field.str, "wrapgroups") == 0)))
1386 if (!ExprResolveBoolean(stmt->value, &tmp))
1388 ERROR("Illegal setting for global groupsWrap\n");
1389 ACTION("Non-boolean value ignored\n");
1394 info->groupInfo = XkbWrapIntoRange;
1396 info->groupInfo = XkbClampIntoRange;
1400 else if ((elem.str == NULL)
1401 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1402 (strcasecmp(field.str, "clampgroups") == 0)))
1404 if (!ExprResolveBoolean(stmt->value, &tmp))
1406 ERROR("Illegal setting for global groupsClamp\n");
1407 ACTION("Non-boolean value ignored\n");
1412 info->groupInfo = XkbClampIntoRange;
1414 info->groupInfo = XkbWrapIntoRange;
1418 else if ((elem.str == NULL)
1419 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1420 (strcasecmp(field.str, "redirectgroups") == 0)))
1422 if (!ExprResolveGroup(stmt->value, &tmp))
1424 ERROR("Illegal group index for global groupsRedirect\n");
1425 ACTION("Definition with non-integer group ignored\n");
1429 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1434 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1436 ERROR("Radio groups not supported\n");
1437 ACTION("Ignoring \"allow none\" specification\n");
1441 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1451 HandleSymbolsBody(VarDef * def,
1452 struct xkb_keymap * xkb, KeyInfo * key, SymbolsInfo * info)
1455 ExprResult tmp, field;
1458 for (; def != NULL; def = (VarDef *) def->common.next)
1460 if ((def->name) && (def->name->type == ExprFieldRef))
1462 ok = HandleSymbolsVar(def, xkb, info);
1467 if (def->name == NULL)
1469 if ((def->value == NULL)
1470 || (def->value->op == ExprKeysymList))
1471 field.str = strdup("symbols");
1473 field.str = strdup("actions");
1478 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1481 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1490 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1492 unsigned group = info->explicit_group;
1497 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1500 WARN("For the map %s an explicit group specified\n", info->name);
1501 WARN("but key %s has more than one group defined\n",
1502 longText(key->name));
1503 ACTION("All groups except first one will be ignored\n");
1504 for (i = 1; i < XkbNumKbdGroups; i++)
1506 key->numLevels[i] = 0;
1508 key->syms[i] = NULL;
1510 key->acts[i] = NULL;
1514 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1516 key->numLevels[group] = key->numLevels[0];
1517 key->numLevels[0] = 0;
1518 key->syms[group] = key->syms[0];
1519 key->syms[0] = NULL;
1520 key->sizeSyms[group] = key->sizeSyms[0];
1521 key->sizeSyms[0] = 0;
1522 key->symsMapIndex[group] = key->symsMapIndex[0];
1523 key->symsMapIndex[0] = NULL;
1524 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1525 key->symsMapNumEntries[0] = NULL;
1526 key->acts[group] = key->acts[0];
1527 key->acts[0] = NULL;
1528 key->types[group] = key->types[0];
1534 HandleSymbolsDef(SymbolsDef * stmt,
1535 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1540 CopyKeyInfo(&info->dflt, &key, False);
1541 key.defs.merge = stmt->merge;
1542 key.name = KeyNameToLong(stmt->keyName);
1543 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1549 if (!SetExplicitGroup(info, &key))
1555 if (!AddKeySymbols(info, &key, xkb))
1564 HandleModMapDef(ModMapDef * def,
1565 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1572 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1574 ERROR("Illegal modifier map definition\n");
1575 ACTION("Ignoring map for non-modifier \"%s\"\n",
1576 XkbcAtomText(def->modifier));
1580 tmp.modifier = rtrn.uval;
1581 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1583 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1585 tmp.haveSymbol = False;
1586 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1588 else if (ExprResolveKeySym(key, &rtrn))
1590 tmp.haveSymbol = True;
1591 tmp.u.keySym = rtrn.uval;
1595 ERROR("Modmap entries may contain only key names or keysyms\n");
1596 ACTION("Illegal definition for %s modifier ignored\n",
1597 XkbcModIndexText(tmp.modifier));
1601 ok = AddModMapEntry(info, &tmp) && ok;
1607 HandleSymbolsFile(XkbFile * file,
1608 struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
1613 info->name = uDupString(file->name);
1617 switch (stmt->stmtType)
1620 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1624 case StmtSymbolsDef:
1625 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1629 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1633 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1637 ERROR("Interpretation files may not include other types\n");
1638 ACTION("Ignoring definition of symbol interpretation\n");
1641 case StmtKeycodeDef:
1642 ERROR("Interpretation files may not include other types\n");
1643 ACTION("Ignoring definition of key name\n");
1647 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1651 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1656 if (info->errorCount > 10)
1659 ERROR("Too many errors\n");
1661 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1668 FindKeyForSymbol(struct xkb_keymap * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1671 unsigned int group, level;
1673 for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
1675 for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
1677 for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
1679 if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
1680 (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
1692 * Find the given name in the xkb->map->types and return its index.
1694 * @param atom The atom to search for.
1695 * @param type_rtrn Set to the index of the name if found.
1697 * @return True if found, False otherwise.
1700 FindNamedType(struct xkb_keymap * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1703 const char *name = XkbcAtomText(atom);
1705 if (xkb && xkb->map && xkb->map->types)
1707 for (n = 0; n < xkb->map->num_types; n++)
1709 if (strcmp(xkb->map->types[n].name, name) == 0)
1720 * Assign a type to the given sym and return the Atom for the type assigned.
1723 * - ONE_LEVEL for width 0/1
1724 * - ALPHABETIC for 2 shift levels, with lower/upercase
1725 * - KEYPAD for keypad keys.
1726 * - TWO_LEVEL for other 2 shift level keys.
1727 * and the same for four level keys.
1729 * @param width Number of sysms in syms.
1730 * @param syms The keysyms for the given key (must be size width).
1731 * @param typeNameRtrn Set to the Atom of the type name.
1733 * @returns True if a type could be found, False otherwise.
1736 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1740 if ((width == 1) || (width == 0))
1742 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1745 else if (width == 2)
1747 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1749 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1751 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1753 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1758 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1762 else if (width <= 4)
1764 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1765 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1767 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1769 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1771 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1772 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1774 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1775 /* XXX: why not set autoType here? */
1777 return ((width >= 0) && (width <= 4));
1781 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1782 * groups, and reduce to one group if all groups are identical anyway.
1785 PrepareKeyDef(KeyInfo * key)
1787 int i, j, width, defined, lastGroup;
1790 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1791 /* get highest group number */
1792 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1794 if (defined & (1 << i))
1802 /* If there are empty groups between non-empty ones fill them with data */
1803 /* from the first group. */
1804 /* We can make a wrong assumption here. But leaving gaps is worse. */
1805 for (i = lastGroup; i > 0; i--)
1807 if (defined & (1 << i))
1809 width = key->numLevels[0];
1810 if (key->typesDefined & 1)
1812 for (j = 0; j < width; j++)
1814 key->types[i] = key->types[0];
1816 key->typesDefined |= 1 << i;
1818 if ((key->actsDefined & 1) && key->acts[0])
1820 key->acts[i] = uTypedCalloc(width, union xkb_action);
1821 if (key->acts[i] == NULL)
1823 memcpy(key->acts[i], key->acts[0],
1824 width * sizeof(union xkb_action));
1825 key->actsDefined |= 1 << i;
1827 if ((key->symsDefined & 1) && key->sizeSyms[0])
1829 key->syms[i] = uTypedCalloc(key->sizeSyms[0], xkb_keysym_t);
1830 if (key->syms[i] == NULL)
1832 memcpy(key->syms[i], key->syms[0],
1833 key->sizeSyms[0] * sizeof(xkb_keysym_t));
1834 key->symsMapIndex[i] = uTypedCalloc(width, int);
1835 if (!key->symsMapIndex[i])
1838 key->syms[i] = NULL;
1841 memcpy(key->symsMapIndex[i], key->symsMapIndex[0],
1842 width * sizeof(int));
1843 key->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
1844 if (!key->symsMapNumEntries[i])
1847 key->syms[i] = NULL;
1848 free(key->symsMapIndex[i]);
1849 key->symsMapIndex[i] = NULL;
1852 memcpy(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1853 width * sizeof(int));
1854 key->sizeSyms[i] = key->sizeSyms[0];
1855 key->symsDefined |= 1 << i;
1859 key->numLevels[i] = key->numLevels[0];
1862 /* If all groups are completely identical remove them all */
1863 /* exept the first one. */
1865 for (i = lastGroup; i > 0; i--)
1867 if ((key->numLevels[i] != key->numLevels[0]) ||
1868 (key->types[i] != key->types[0]))
1873 if ((key->syms[i] != key->syms[0]) &&
1874 (key->syms[i] == NULL || key->syms[0] == NULL ||
1875 key->sizeSyms[i] != key->sizeSyms[0] ||
1876 memcmp(key->syms[i], key->syms[0],
1877 sizeof(xkb_keysym_t) * key->sizeSyms[0])))
1882 if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
1883 (key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
1884 memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
1885 key->numLevels[0] * sizeof(int))))
1890 if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
1891 (key->symsMapNumEntries[i] == NULL ||
1892 key->symsMapNumEntries[0] == NULL ||
1893 memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1894 key->numLevels[0] * sizeof(int))))
1899 if ((key->acts[i] != key->acts[0]) &&
1900 (key->acts[i] == NULL || key->acts[0] == NULL ||
1901 memcmp(key->acts[i], key->acts[0],
1902 sizeof(union xkb_action) * key->numLevels[0])))
1910 for (i = lastGroup; i > 0; i--)
1912 key->numLevels[i] = 0;
1914 key->syms[i] = NULL;
1915 key->sizeSyms[i] = 0;
1916 free(key->symsMapIndex[i]);
1917 key->symsMapIndex[i] = NULL;
1918 free(key->symsMapNumEntries[i]);
1919 key->symsMapNumEntries[i] = NULL;
1921 key->acts[i] = NULL;
1924 key->symsDefined &= 1;
1925 key->actsDefined &= 1;
1926 key->typesDefined &= 1;
1931 * Copy the KeyInfo into the keyboard description.
1933 * This function recurses.
1936 CopySymbolsDef(struct xkb_keymap * xkb, KeyInfo *key, int start_from)
1940 unsigned int sizeSyms = 0;
1941 unsigned width, tmp, nGroups;
1942 struct xkb_key_type * type;
1943 Bool haveActions, autoType, useAlias;
1944 xkb_atom_t types[XkbNumKbdGroups];
1945 union xkb_action *outActs;
1947 unsigned int symIndex = 0;
1949 useAlias = (start_from == 0);
1951 /* get the keycode for the key. */
1952 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1955 if ((start_from == 0) && (warningLevel >= 5))
1957 WARN("Key %s not found in keycodes\n", longText(key->name));
1958 ACTION("Symbols ignored\n");
1963 haveActions = False;
1964 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1966 if (((i + 1) > nGroups)
1967 && (((key->symsDefined | key->actsDefined) & (1 << i))
1968 || (key->typesDefined) & (1 << i)))
1973 /* Assign the type to the key, if it is missing. */
1974 if (key->types[i] == XKB_ATOM_NONE)
1976 if (key->dfltType != XKB_ATOM_NONE)
1977 key->types[i] = key->dfltType;
1978 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1979 &key->types[i], &autoType))
1984 if (warningLevel >= 5)
1986 WARN("No automatic type for %d symbols\n",
1987 (unsigned int) key->numLevels[i]);
1988 ACTION("Using %s for the %s key (keycode %d)\n",
1989 XkbcAtomText(key->types[i]),
1990 longText(key->name), kc);
1994 if (FindNamedType(xkb, key->types[i], &types[i]))
1996 if (!autoType || key->numLevels[i] > 2)
1997 xkb->server->explicit[kc] |= (1 << i);
2001 if (warningLevel >= 3)
2003 WARN("Type \"%s\" is not defined\n",
2004 XkbcAtomText(key->types[i]));
2005 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
2006 longText(key->name), kc);
2008 types[i] = XkbTwoLevelIndex;
2010 /* if the type specifies fewer levels than the key has, shrink the key */
2011 type = &xkb->map->types[types[i]];
2012 if (type->num_levels < key->numLevels[i])
2014 if (warningLevel > 0)
2016 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
2017 type->name, type->num_levels,
2018 XkbcAtomText(key->name), key->numLevels[i]);
2019 ACTION("Ignoring extra symbols\n");
2021 key->numLevels[i] = type->num_levels;
2023 if (key->numLevels[i] > width)
2024 width = key->numLevels[i];
2025 if (type->num_levels > width)
2026 width = type->num_levels;
2027 sizeSyms += key->sizeSyms[i];
2030 if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
2032 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
2033 longText(key->name), kc);
2038 outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
2039 if (outActs == NULL)
2041 WSGO("Could not enlarge actions for %s (key %d)\n",
2042 longText(key->name), kc);
2045 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2049 if (key->defs.defined & _Key_GroupInfo)
2052 i = xkb->map->key_sym_map[kc].group_info;
2054 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2055 xkb->map->key_sym_map[kc].width = width;
2056 xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
2057 xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
2059 for (i = 0; i < nGroups; i++)
2061 /* assign kt_index[i] to the index of the type in map->types.
2062 * kt_index[i] may have been set by a previous run (if we have two
2063 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2064 * default group if we dont even have keys for this group anyway.
2066 * FIXME: There should be a better fix for this.
2068 if (key->numLevels[i])
2069 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2070 if (key->sizeSyms[i] != 0)
2072 /* fill key to "width" symbols*/
2073 for (tmp = 0; tmp < width; tmp++)
2075 if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
2077 memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
2078 &key->syms[i][key->symsMapIndex[i][tmp]],
2079 key->symsMapNumEntries[i][tmp] *
2080 sizeof(xkb_keysym_t));
2081 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
2083 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
2084 key->symsMapNumEntries[i][tmp];
2086 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
2090 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
2091 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
2093 if ((outActs != NULL) && (key->acts[i] != NULL))
2095 if (tmp < key->numLevels[i])
2096 outActs[tmp] = key->acts[i][tmp];
2098 outActs[tmp].type = XkbSA_NoAction;
2103 switch (key->behavior.type & XkbKB_OpMask)
2108 xkb->server->behaviors[kc] = key->behavior;
2109 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2112 if (key->defs.defined & _Key_VModMap)
2114 xkb->server->vmodmap[kc] = key->vmodmap;
2115 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2117 if (key->repeat != RepeatUndefined)
2119 if (key->repeat == RepeatYes)
2120 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2122 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2123 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2126 if (nGroups > xkb->ctrls->num_groups)
2127 xkb->ctrls->num_groups = nGroups;
2129 /* do the same thing for the next key */
2130 CopySymbolsDef(xkb, key, kc + 1);
2135 CopyModMapDef(struct xkb_keymap * xkb, ModMapEntry *entry)
2139 if ((!entry->haveSymbol)
2142 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2144 if (warningLevel >= 5)
2146 WARN("Key %s not found in keycodes\n",
2147 longText(entry->u.keyName));
2148 ACTION("Modifier map entry for %s not updated\n",
2149 XkbcModIndexText(entry->modifier));
2153 else if (entry->haveSymbol
2154 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2156 if (warningLevel > 5)
2158 WARN("Key \"%s\" not found in symbol map\n",
2159 XkbcKeysymText(entry->u.keySym));
2160 ACTION("Modifier map entry for %s not updated\n",
2161 XkbcModIndexText(entry->modifier));
2165 xkb->map->modmap[kc] |= (1 << entry->modifier);
2170 * Handle the xkb_symbols section of an xkb file.
2172 * @param file The parsed xkb_symbols section of the xkb file.
2173 * @param xkb Handle to the keyboard description to store the symbols in.
2174 * @param merge Merge strategy (e.g. MergeOverride).
2177 CompileSymbols(XkbFile *file, struct xkb_keymap * xkb, unsigned merge)
2182 InitSymbolsInfo(&info, xkb);
2183 info.dflt.defs.fileID = file->id;
2184 info.dflt.defs.merge = merge;
2185 HandleSymbolsFile(file, xkb, merge, &info);
2187 if (info.nKeys == 0) {
2188 FreeSymbolsInfo(&info);
2192 if (info.errorCount == 0)
2196 /* alloc memory in the xkb struct */
2197 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
2199 WSGO("Can not allocate names in CompileSymbols\n");
2200 ACTION("Symbols not added\n");
2203 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2206 WSGO("Could not allocate client map in CompileSymbols\n");
2207 ACTION("Symbols not added\n");
2210 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2212 WSGO("Could not allocate server map in CompileSymbols\n");
2213 ACTION("Symbols not added\n");
2216 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2218 WSGO("Could not allocate controls in CompileSymbols\n");
2219 ACTION("Symbols not added\n");
2223 /* now copy info into xkb. */
2225 ApplyAliases(xkb, &info.aliases);
2226 for (i = 0; i < XkbNumKbdGroups; i++)
2228 if (info.groupNames[i] != XKB_ATOM_NONE)
2230 free(UNCONSTIFY(xkb->names->groups[i]));
2231 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2235 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2240 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2242 if (!CopySymbolsDef(xkb, key, 0))
2245 if (warningLevel > 3)
2247 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2249 if (xkb->names->keys[i].name[0] == '\0')
2251 if (XkbKeyNumGroups(xkb, i) < 1)
2254 memcpy(buf, xkb->names->keys[i].name, 4);
2257 ("No symbols defined for <%s> (keycode %d)\n",
2264 ModMapEntry *mm, *next;
2265 for (mm = info.modMap; mm != NULL; mm = next)
2267 if (!CopyModMapDef(xkb, mm))
2269 next = (ModMapEntry *) mm->defs.next;
2272 FreeSymbolsInfo(&info);
2276 FreeSymbolsInfo(&info);