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_desc * 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)
329 if (key->syms[group] == NULL || key->sizeSyms[group] < sizeSyms)
331 key->syms[group] = uTypedRecalloc(key->syms[group],
332 key->sizeSyms[group],
335 if (!key->syms[group]) {
336 key->sizeSyms[group] = 0;
339 key->sizeSyms[group] = sizeSyms;
341 if (!key->symsMapIndex[group] || key->numLevels[group] < numLevels)
343 key->symsMapIndex[group] = uTypedRealloc(key->symsMapIndex[group],
346 if (!key->symsMapIndex[group])
348 for (i = key->numLevels[group]; i < numLevels; i++)
349 key->symsMapIndex[group][i] = -1;
351 if (!key->symsMapNumEntries[group] || key->numLevels[group] < numLevels)
353 key->symsMapNumEntries[group] =
354 uTypedRecalloc(key->symsMapNumEntries[group],
355 key->numLevels[group],
358 if (!key->symsMapNumEntries[group])
362 (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
363 (key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
365 key->acts[group] = uTypedRecalloc(key->acts[group],
366 key->numLevels[group],
369 if (!key->acts[group])
372 if (key->numLevels[group] < numLevels)
373 key->numLevels[group] = numLevels;
378 MergeKeyGroups(SymbolsInfo * info,
379 KeyInfo * into, KeyInfo * from, unsigned group)
381 xkb_keysym_t *resultSyms;
382 union xkb_action *resultActs;
383 unsigned int resultWidth;
384 unsigned int resultSize = 0;
387 Bool report, clobber;
389 clobber = (from->defs.merge != MergeAugment);
390 report = (warningLevel > 9) ||
391 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
392 if (into->numLevels[group] >= from->numLevels[group])
394 resultActs = into->acts[group];
395 resultWidth = into->numLevels[group];
399 resultActs = from->acts[group];
400 resultWidth = from->numLevels[group];
401 into->symsMapIndex[group] = uTypedRealloc(into->symsMapIndex[group],
402 from->numLevels[group],
404 into->symsMapNumEntries[group] =
405 uTypedRecalloc(into->symsMapNumEntries[group],
406 from->numLevels[group],
407 into->numLevels[group],
409 if (!into->symsMapIndex[group] || !into->symsMapNumEntries[group])
411 WSGO("Could not allocate level indices for key info merge\n");
412 ACTION("Group %d of key %s not merged\n", group,
413 longText(into->name));
417 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
418 into->symsMapIndex[group][i] = -1;
421 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
423 resultActs = uTypedCalloc(resultWidth, union xkb_action);
426 WSGO("Could not allocate actions for group merge\n");
427 ACTION("Group %d of key %s not merged\n", group,
428 longText(into->name));
431 for (i = 0; i < resultWidth; i++)
433 union xkb_action *fromAct, *toAct;
434 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
435 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
436 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
439 resultActs[i] = *toAct;
441 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
442 && (fromAct != NULL))
444 resultActs[i] = *fromAct;
448 union xkb_action *use, *ignore;
462 ("Multiple actions for level %d/group %d on key %s\n",
463 i + 1, group + 1, longText(into->name));
464 ACTION("Using %s, ignoring %s\n",
465 XkbcActionTypeText(use->type),
466 XkbcActionTypeText(ignore->type));
469 resultActs[i] = *use;
474 for (i = 0; i < resultWidth; i++)
476 unsigned int fromSize = 0;
479 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
480 fromSize = from->symsMapNumEntries[group][i];
481 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
482 toSize = into->symsMapNumEntries[group][i];
484 if (fromSize == 0 || fromSize == toSize || clobber)
488 else if (toSize == 0)
490 resultSize += fromSize;
497 resultSyms = uTypedCalloc(resultSize, xkb_keysym_t);
500 WSGO("Could not allocate symbols for group merge\n");
501 ACTION("Group %d of key %s not merged\n", group, longText(into->name));
505 for (i = 0; i < resultWidth; i++)
507 enum { NONE, FROM, TO } use;
508 unsigned int fromSize = 0;
509 unsigned int toSize = 0;
511 if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
512 fromSize = from->symsMapNumEntries[group][i];
513 if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
514 toSize = into->symsMapNumEntries[group][i];
516 if (!fromSize && !toSize)
518 into->symsMapIndex[group][i] = -1;
519 into->symsMapNumEntries[group][i] = 0;
523 if ((fromSize && !toSize) || clobber)
528 if (toSize && fromSize && report)
530 INFO("Multiple symbols for group %d, level %d on key %s\n",
531 group + 1, i + 1, longText(into->name));
532 ACTION("Using %s, ignoring %s\n",
533 (use == FROM ? "from" : "to"),
534 (use == FROM ? "to" : "from"));
539 memcpy(&resultSyms[cur_idx],
540 &from->syms[group][from->symsMapIndex[group][i]],
541 from->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
542 into->symsMapIndex[group][i] = cur_idx;
543 into->symsMapNumEntries[group][i] =
544 from->symsMapNumEntries[group][i];
548 memcpy(&resultSyms[cur_idx],
549 &into->syms[group][from->symsMapIndex[group][i]],
550 into->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
551 into->symsMapIndex[group][i] = cur_idx;
553 cur_idx += into->symsMapNumEntries[group][i];
557 if (resultActs != into->acts[group])
558 free(into->acts[group]);
559 if (resultActs != from->acts[group])
560 free(from->acts[group]);
561 into->numLevels[group] = resultWidth;
562 free(into->syms[group]);
563 into->syms[group] = resultSyms;
564 free(from->syms[group]);
565 from->syms[group] = NULL;
566 from->sizeSyms[group] = 0;
567 into->sizeSyms[group] = resultSize;
568 free(from->symsMapIndex[group]);
569 from->symsMapIndex[group] = NULL;
570 free(from->symsMapNumEntries[group]);
571 from->symsMapNumEntries[group] = NULL;
572 into->acts[group] = resultActs;
573 from->acts[group] = NULL;
574 into->symsDefined |= (1 << group);
575 from->symsDefined &= ~(1 << group);
576 into->actsDefined |= (1 << group);
577 from->actsDefined &= ~(1 << group);
583 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
586 unsigned collide = 0;
589 if (from->defs.merge == MergeReplace)
591 for (i = 0; i < XkbNumKbdGroups; i++)
593 if (into->numLevels[i] != 0)
600 memset(from, 0, sizeof(KeyInfo));
603 report = ((warningLevel > 9) ||
604 ((into->defs.fileID == from->defs.fileID)
605 && (warningLevel > 0)));
606 for (i = 0; i < XkbNumKbdGroups; i++)
608 if (from->numLevels[i] > 0)
610 if (into->numLevels[i] == 0)
612 into->numLevels[i] = from->numLevels[i];
613 into->syms[i] = from->syms[i];
614 into->sizeSyms[i] = from->sizeSyms[i];
615 into->symsMapIndex[i] = from->symsMapIndex[i];
616 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
617 into->acts[i] = from->acts[i];
618 into->symsDefined |= (1 << i);
619 from->syms[i] = NULL;
620 from->sizeSyms[i] = 0;
621 from->symsMapIndex[i] = NULL;
622 from->symsMapNumEntries[i] = NULL;
623 from->acts[i] = NULL;
624 from->numLevels[i] = 0;
625 from->symsDefined &= ~(1 << i);
627 into->defs.defined |= _Key_Syms;
629 into->defs.defined |= _Key_Acts;
636 collide |= _Key_Syms;
638 collide |= _Key_Acts;
640 MergeKeyGroups(info, into, from, (unsigned) i);
643 if (from->types[i] != XKB_ATOM_NONE)
645 if ((into->types[i] != XKB_ATOM_NONE) && report &&
646 (into->types[i] != from->types[i]))
648 xkb_atom_t use, ignore;
649 collide |= _Key_Types;
650 if (from->defs.merge != MergeAugment)
652 use = from->types[i];
653 ignore = into->types[i];
657 use = into->types[i];
658 ignore = from->types[i];
661 ("Multiple definitions for group %d type of key %s\n",
662 i, longText(into->name));
663 ACTION("Using %s, ignoring %s\n",
665 XkbcAtomText(ignore));
667 if ((from->defs.merge != MergeAugment)
668 || (into->types[i] == XKB_ATOM_NONE))
670 into->types[i] = from->types[i];
674 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
676 into->behavior = from->behavior;
677 into->defs.defined |= _Key_Behavior;
679 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
681 into->vmodmap = from->vmodmap;
682 into->defs.defined |= _Key_VModMap;
684 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
686 into->repeat = from->repeat;
687 into->defs.defined |= _Key_Repeat;
689 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
691 into->dfltType = from->dfltType;
692 into->defs.defined |= _Key_Type_Dflt;
694 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
696 into->groupInfo = from->groupInfo;
697 into->defs.defined |= _Key_GroupInfo;
701 WARN("Symbol map for key %s redefined\n",
702 longText(into->name));
703 ACTION("Using %s definition for conflicting fields\n",
704 (from->defs.merge == MergeAugment ? "first" : "last"));
710 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
713 unsigned long real_name;
715 for (i = 0; i < info->nKeys; i++)
717 if (info->keys[i].name == key->name)
718 return MergeKeys(info, &info->keys[i], key);
720 if (FindKeyNameForAlias(xkb, key->name, &real_name))
722 for (i = 0; i < info->nKeys; i++)
724 if (info->keys[i].name == real_name)
725 return MergeKeys(info, &info->keys[i], key);
728 if (info->nKeys >= info->szKeys)
730 info->szKeys += SYMBOLS_CHUNK;
732 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
735 WSGO("Could not allocate key symbols descriptions\n");
736 ACTION("Some key symbols definitions may be lost\n");
740 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
744 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
749 clobber = (new->defs.merge != MergeAugment);
750 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
752 if (new->haveSymbol && mm->haveSymbol
753 && (new->u.keySym == mm->u.keySym))
755 unsigned use, ignore;
756 if (mm->modifier != new->modifier)
761 ignore = mm->modifier;
766 ignore = new->modifier;
769 ("%s added to symbol map for multiple modifiers\n",
770 XkbcKeysymText(new->u.keySym));
771 ACTION("Using %s, ignoring %s.\n",
772 XkbcModIndexText(use),
773 XkbcModIndexText(ignore));
778 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
779 (new->u.keyName == mm->u.keyName))
781 unsigned use, ignore;
782 if (mm->modifier != new->modifier)
787 ignore = mm->modifier;
792 ignore = new->modifier;
794 ERROR("Key %s added to map for multiple modifiers\n",
795 longText(new->u.keyName));
796 ACTION("Using %s, ignoring %s.\n",
797 XkbcModIndexText(use),
798 XkbcModIndexText(ignore));
804 mm = uTypedAlloc(ModMapEntry);
807 WSGO("Could not allocate modifier map entry\n");
808 ACTION("Modifier map for %s will be incomplete\n",
809 XkbcModIndexText(new->modifier));
813 mm->defs.next = &info->modMap->defs;
818 /***====================================================================***/
821 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
822 unsigned merge, struct xkb_desc * xkb)
827 if (from->errorCount > 0)
829 into->errorCount += from->errorCount;
832 if (into->name == NULL)
834 into->name = from->name;
837 for (i = 0; i < XkbNumKbdGroups; i++)
839 if (from->groupNames[i] != XKB_ATOM_NONE)
841 if ((merge != MergeAugment) ||
842 (into->groupNames[i] == XKB_ATOM_NONE))
843 into->groupNames[i] = from->groupNames[i];
846 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
848 if (merge != MergeDefault)
849 key->defs.merge = merge;
850 if (!AddKeySymbols(into, key, xkb))
853 if (from->modMap != NULL)
855 ModMapEntry *mm, *next;
856 for (mm = from->modMap; mm != NULL; mm = next)
858 if (merge != MergeDefault)
859 mm->defs.merge = merge;
860 if (!AddModMapEntry(into, mm))
862 next = (ModMapEntry *) mm->defs.next;
867 if (!MergeAliases(&into->aliases, &from->aliases, merge))
871 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
872 struct xkb_desc * /* xkb */ ,
873 unsigned /* merge */ ,
874 SymbolsInfo * /* included */
878 HandleIncludeSymbols(IncludeStmt * stmt,
879 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
883 SymbolsInfo included;
887 if ((stmt->file == NULL) && (stmt->map == NULL))
891 memset(info, 0, sizeof(SymbolsInfo));
893 else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
896 InitSymbolsInfo(&included, xkb);
897 included.fileID = included.dflt.defs.fileID = rtrn->id;
898 included.merge = included.dflt.defs.merge = MergeOverride;
901 included.explicit_group = atoi(stmt->modifier) - 1;
905 included.explicit_group = info->explicit_group;
907 (*hndlr) (rtrn, xkb, MergeOverride, &included);
908 if (stmt->stmt != NULL)
911 included.name = stmt->stmt;
918 info->errorCount += 10;
921 if ((stmt->next != NULL) && (included.errorCount < 1))
925 SymbolsInfo next_incl;
927 for (next = stmt->next; next != NULL; next = next->next)
929 if ((next->file == NULL) && (next->map == NULL))
932 MergeIncludedSymbols(&included, info, next->merge, xkb);
933 FreeSymbolsInfo(info);
935 else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
938 InitSymbolsInfo(&next_incl, xkb);
939 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
940 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
943 next_incl.explicit_group = atoi(next->modifier) - 1;
947 next_incl.explicit_group = info->explicit_group;
949 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
950 MergeIncludedSymbols(&included, &next_incl, op, xkb);
951 FreeSymbolsInfo(&next_incl);
956 info->errorCount += 10;
965 MergeIncludedSymbols(info, &included, newMerge, xkb);
966 FreeSymbolsInfo(&included);
968 return (info->errorCount == 0);
975 GetGroupIndex(KeyInfo * key,
976 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
986 if (arrayNdx == NULL)
991 defined = key->symsDefined;
993 defined = key->actsDefined;
995 for (i = 0; i < XkbNumKbdGroups; i++)
997 if ((defined & (1 << i)) == 0)
1003 ERROR("Too many groups of %s for key %s (max %d)\n", name,
1004 longText(key->name), XkbNumKbdGroups + 1);
1005 ACTION("Ignoring %s defined for extra groups\n", name);
1008 if (!ExprResolveGroup(arrayNdx, &tmp))
1010 ERROR("Illegal group index for %s of key %s\n", name,
1011 longText(key->name));
1012 ACTION("Definition with non-integer array index ignored\n");
1015 *ndx_rtrn = tmp.uval - 1;
1020 AddSymbolsToKey(KeyInfo * key,
1021 struct xkb_desc * xkb,
1023 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1025 unsigned ndx, nSyms, nLevels;
1029 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
1033 key->symsDefined |= (1 << ndx);
1036 if (value->op != ExprKeysymList)
1038 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
1039 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
1040 longText(key->name));
1043 if (key->sizeSyms[ndx] != 0)
1045 ERROR("Symbols for key %s, group %d already defined\n",
1046 longText(key->name), ndx + 1);
1047 ACTION("Ignoring duplicate definition\n");
1050 nSyms = value->value.list.nSyms;
1051 nLevels = value->value.list.nLevels;
1052 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
1053 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, False)))
1055 WSGO("Could not resize group %d of key %s to contain %d levels\n",
1056 ndx + 1, longText(key->name), nSyms);
1057 ACTION("Symbols lost\n");
1060 key->symsDefined |= (1 << ndx);
1061 for (i = 0; i < nLevels; i++) {
1062 key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
1063 key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
1064 for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
1065 if (key->symsMapIndex[ndx][i] + j >= nSyms)
1067 if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
1068 &key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
1069 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
1070 value->value.list.syms[i], longText(key->name), ndx + 1,
1071 XkbcAtomText(info->groupNames[ndx]), nSyms);
1073 key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
1074 key->symsMapIndex[ndx][i] = -1;
1075 key->symsMapNumEntries[ndx][i] = 0;
1080 for (j = key->numLevels[ndx] - 1;
1081 j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
1082 key->numLevels[ndx]--;
1087 AddActionsToKey(KeyInfo * key,
1088 struct xkb_desc * xkb,
1090 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1093 unsigned ndx, nActs;
1095 struct xkb_any_action *toAct;
1097 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
1102 key->actsDefined |= (1 << ndx);
1105 if (value->op != ExprActionList)
1107 WSGO("Bad expression type (%d) for action list value\n", value->op);
1108 ACTION("Ignoring actions for group %d of %s\n", ndx,
1109 longText(key->name));
1112 if (key->acts[ndx] != NULL)
1114 WSGO("Actions for key %s, group %d already defined\n",
1115 longText(key->name), ndx);
1118 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1120 act = (ExprDef *) act->common.next;
1124 WSGO("Action list but not actions in AddActionsToKey\n");
1127 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1128 (!ResizeKeyGroup(key, ndx, nActs, nActs, True)))
1130 WSGO("Could not resize group %d of key %s\n", ndx,
1131 longText(key->name));
1132 ACTION("Actions lost\n");
1135 key->actsDefined |= (1 << ndx);
1137 toAct = (struct xkb_any_action *) key->acts[ndx];
1138 act = value->value.child;
1139 for (i = 0; i < nActs; i++, toAct++)
1141 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1143 ERROR("Illegal action definition for %s\n",
1144 longText(key->name));
1145 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1147 act = (ExprDef *) act->common.next;
1152 static const LookupEntry lockingEntries[] = {
1153 {"true", XkbKB_Lock},
1154 {"yes", XkbKB_Lock},
1156 {"false", XkbKB_Default},
1157 {"no", XkbKB_Default},
1158 {"off", XkbKB_Default},
1159 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1163 static const LookupEntry repeatEntries[] = {
1164 {"true", RepeatYes},
1167 {"false", RepeatNo},
1170 {"default", RepeatUndefined},
1175 SetSymbolsField(KeyInfo * key,
1176 struct xkb_desc * xkb,
1178 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1183 if (strcasecmp(field, "type") == 0)
1186 if ((!ExprResolveString(value, &tmp))
1187 && (warningLevel > 0))
1189 WARN("The type field of a key symbol map must be a string\n");
1190 ACTION("Ignoring illegal type definition\n");
1192 if (arrayNdx == NULL)
1194 key->dfltType = xkb_intern_atom(tmp.str);
1195 key->defs.defined |= _Key_Type_Dflt;
1197 else if (!ExprResolveGroup(arrayNdx, &ndx))
1199 ERROR("Illegal group index for type of key %s\n",
1200 longText(key->name));
1201 ACTION("Definition with non-integer array index ignored\n");
1207 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1208 key->typesDefined |= (1 << (ndx.uval - 1));
1212 else if (strcasecmp(field, "symbols") == 0)
1213 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1214 else if (strcasecmp(field, "actions") == 0)
1215 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1216 else if ((strcasecmp(field, "vmods") == 0) ||
1217 (strcasecmp(field, "virtualmods") == 0) ||
1218 (strcasecmp(field, "virtualmodifiers") == 0))
1220 ok = ExprResolveVModMask(value, &tmp, xkb);
1223 key->vmodmap = (tmp.uval >> 8);
1224 key->defs.defined |= _Key_VModMap;
1228 ERROR("Expected a virtual modifier mask, found %s\n",
1229 exprOpText(value->op));
1230 ACTION("Ignoring virtual modifiers definition for key %s\n",
1231 longText(key->name));
1234 else if ((strcasecmp(field, "locking") == 0) ||
1235 (strcasecmp(field, "lock") == 0) ||
1236 (strcasecmp(field, "locks") == 0))
1238 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1240 key->behavior.type = tmp.uval;
1241 key->defs.defined |= _Key_Behavior;
1243 else if ((strcasecmp(field, "radiogroup") == 0) ||
1244 (strcasecmp(field, "permanentradiogroup") == 0) ||
1245 (strcasecmp(field, "allownone") == 0))
1247 ERROR("Radio groups not supported\n");
1248 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1251 else if (uStrCasePrefix("overlay", field) ||
1252 uStrCasePrefix("permanentoverlay", field))
1254 ERROR("Overlays not supported\n");
1255 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1257 else if ((strcasecmp(field, "repeating") == 0) ||
1258 (strcasecmp(field, "repeats") == 0) ||
1259 (strcasecmp(field, "repeat") == 0))
1261 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1264 ERROR("Illegal repeat setting for %s\n",
1265 longText(key->name));
1266 ACTION("Non-boolean repeat setting ignored\n");
1269 key->repeat = tmp.uval;
1270 key->defs.defined |= _Key_Repeat;
1272 else if ((strcasecmp(field, "groupswrap") == 0) ||
1273 (strcasecmp(field, "wrapgroups") == 0))
1275 ok = ExprResolveBoolean(value, &tmp);
1278 ERROR("Illegal groupsWrap setting for %s\n",
1279 longText(key->name));
1280 ACTION("Non-boolean value ignored\n");
1284 key->groupInfo = XkbWrapIntoRange;
1286 key->groupInfo = XkbClampIntoRange;
1287 key->defs.defined |= _Key_GroupInfo;
1289 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1290 (strcasecmp(field, "clampgroups") == 0))
1292 ok = ExprResolveBoolean(value, &tmp);
1295 ERROR("Illegal groupsClamp setting for %s\n",
1296 longText(key->name));
1297 ACTION("Non-boolean value ignored\n");
1301 key->groupInfo = XkbClampIntoRange;
1303 key->groupInfo = XkbWrapIntoRange;
1304 key->defs.defined |= _Key_GroupInfo;
1306 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1307 (strcasecmp(field, "redirectgroups") == 0))
1309 if (!ExprResolveGroup(value, &tmp))
1311 ERROR("Illegal group index for redirect of key %s\n",
1312 longText(key->name));
1313 ACTION("Definition with non-integer group ignored\n");
1317 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1318 key->defs.defined |= _Key_GroupInfo;
1322 ERROR("Unknown field %s in a symbol interpretation\n", field);
1323 ACTION("Definition ignored\n");
1330 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1332 ExprResult tmp, name;
1334 if ((arrayNdx == NULL) && (warningLevel > 0))
1336 WARN("You must specify an index when specifying a group name\n");
1337 ACTION("Group name definition without array subscript ignored\n");
1340 if (!ExprResolveGroup(arrayNdx, &tmp))
1342 ERROR("Illegal index in group name definition\n");
1343 ACTION("Definition with non-integer array index ignored\n");
1346 if (!ExprResolveString(value, &name))
1348 ERROR("Group name must be a string\n");
1349 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1352 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1353 xkb_intern_atom(name.str);
1360 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1362 ExprResult elem, field, tmp;
1366 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1367 return 0; /* internal error, already reported */
1368 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1370 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1373 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1374 (strcasecmp(field.str, "groupname") ==
1377 ret = SetGroupName(info, arrayNdx, stmt->value);
1379 else if ((elem.str == NULL)
1380 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1381 (strcasecmp(field.str, "wrapgroups") == 0)))
1383 if (!ExprResolveBoolean(stmt->value, &tmp))
1385 ERROR("Illegal setting for global groupsWrap\n");
1386 ACTION("Non-boolean value ignored\n");
1391 info->groupInfo = XkbWrapIntoRange;
1393 info->groupInfo = XkbClampIntoRange;
1397 else if ((elem.str == NULL)
1398 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1399 (strcasecmp(field.str, "clampgroups") == 0)))
1401 if (!ExprResolveBoolean(stmt->value, &tmp))
1403 ERROR("Illegal setting for global groupsClamp\n");
1404 ACTION("Non-boolean value ignored\n");
1409 info->groupInfo = XkbClampIntoRange;
1411 info->groupInfo = XkbWrapIntoRange;
1415 else if ((elem.str == NULL)
1416 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1417 (strcasecmp(field.str, "redirectgroups") == 0)))
1419 if (!ExprResolveGroup(stmt->value, &tmp))
1421 ERROR("Illegal group index for global groupsRedirect\n");
1422 ACTION("Definition with non-integer group ignored\n");
1426 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1431 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1433 ERROR("Radio groups not supported\n");
1434 ACTION("Ignoring \"allow none\" specification\n");
1438 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1448 HandleSymbolsBody(VarDef * def,
1449 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1452 ExprResult tmp, field;
1455 for (; def != NULL; def = (VarDef *) def->common.next)
1457 if ((def->name) && (def->name->type == ExprFieldRef))
1459 ok = HandleSymbolsVar(def, xkb, info);
1464 if (def->name == NULL)
1466 if ((def->value == NULL)
1467 || (def->value->op == ExprKeysymList))
1468 field.str = strdup("symbols");
1470 field.str = strdup("actions");
1475 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1478 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1487 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1489 unsigned group = info->explicit_group;
1494 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1497 WARN("For the map %s an explicit group specified\n", info->name);
1498 WARN("but key %s has more than one group defined\n",
1499 longText(key->name));
1500 ACTION("All groups except first one will be ignored\n");
1501 for (i = 1; i < XkbNumKbdGroups; i++)
1503 key->numLevels[i] = 0;
1505 key->syms[i] = NULL;
1507 key->acts[i] = NULL;
1511 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1513 key->numLevels[group] = key->numLevels[0];
1514 key->numLevels[0] = 0;
1515 key->syms[group] = key->syms[0];
1516 key->syms[0] = NULL;
1517 key->sizeSyms[group] = key->sizeSyms[0];
1518 key->sizeSyms[0] = 0;
1519 key->symsMapIndex[group] = key->symsMapIndex[0];
1520 key->symsMapIndex[0] = NULL;
1521 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1522 key->symsMapNumEntries[0] = NULL;
1523 key->acts[group] = key->acts[0];
1524 key->acts[0] = NULL;
1525 key->types[group] = key->types[0];
1531 HandleSymbolsDef(SymbolsDef * stmt,
1532 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1537 CopyKeyInfo(&info->dflt, &key, False);
1538 key.defs.merge = stmt->merge;
1539 key.name = KeyNameToLong(stmt->keyName);
1540 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1546 if (!SetExplicitGroup(info, &key))
1552 if (!AddKeySymbols(info, &key, xkb))
1561 HandleModMapDef(ModMapDef * def,
1562 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1569 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1571 ERROR("Illegal modifier map definition\n");
1572 ACTION("Ignoring map for non-modifier \"%s\"\n",
1573 XkbcAtomText(def->modifier));
1577 tmp.modifier = rtrn.uval;
1578 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1580 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1582 tmp.haveSymbol = False;
1583 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1585 else if (ExprResolveKeySym(key, &rtrn))
1587 tmp.haveSymbol = True;
1588 tmp.u.keySym = rtrn.uval;
1592 ERROR("Modmap entries may contain only key names or keysyms\n");
1593 ACTION("Illegal definition for %s modifier ignored\n",
1594 XkbcModIndexText(tmp.modifier));
1598 ok = AddModMapEntry(info, &tmp) && ok;
1604 HandleSymbolsFile(XkbFile * file,
1605 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1610 info->name = uDupString(file->name);
1614 switch (stmt->stmtType)
1617 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1621 case StmtSymbolsDef:
1622 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1626 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1630 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1634 ERROR("Interpretation files may not include other types\n");
1635 ACTION("Ignoring definition of symbol interpretation\n");
1638 case StmtKeycodeDef:
1639 ERROR("Interpretation files may not include other types\n");
1640 ACTION("Ignoring definition of key name\n");
1644 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1648 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1653 if (info->errorCount > 10)
1656 ERROR("Too many errors\n");
1658 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1665 FindKeyForSymbol(struct xkb_desc * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
1668 unsigned int group, level;
1670 for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
1672 for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
1674 for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
1676 if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
1677 (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
1689 * Find the given name in the xkb->map->types and return its index.
1691 * @param atom The atom to search for.
1692 * @param type_rtrn Set to the index of the name if found.
1694 * @return True if found, False otherwise.
1697 FindNamedType(struct xkb_desc * xkb, xkb_atom_t atom, unsigned *type_rtrn)
1700 const char *name = XkbcAtomText(atom);
1702 if (xkb && xkb->map && xkb->map->types)
1704 for (n = 0; n < xkb->map->num_types; n++)
1706 if (strcmp(xkb->map->types[n].name, name) == 0)
1717 * Assign a type to the given sym and return the Atom for the type assigned.
1720 * - ONE_LEVEL for width 0/1
1721 * - ALPHABETIC for 2 shift levels, with lower/upercase
1722 * - KEYPAD for keypad keys.
1723 * - TWO_LEVEL for other 2 shift level keys.
1724 * and the same for four level keys.
1726 * @param width Number of sysms in syms.
1727 * @param syms The keysyms for the given key (must be size width).
1728 * @param typeNameRtrn Set to the Atom of the type name.
1730 * @returns True if a type could be found, False otherwise.
1733 FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
1737 if ((width == 1) || (width == 0))
1739 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1742 else if (width == 2)
1744 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1746 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1748 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1750 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1755 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1759 else if (width <= 4)
1761 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1762 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1764 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1766 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1768 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1769 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1771 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1772 /* XXX: why not set autoType here? */
1774 return ((width >= 0) && (width <= 4));
1778 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1779 * groups, and reduce to one group if all groups are identical anyway.
1782 PrepareKeyDef(KeyInfo * key)
1784 int i, j, width, defined, lastGroup;
1787 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1788 /* get highest group number */
1789 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1791 if (defined & (1 << i))
1799 /* If there are empty groups between non-empty ones fill them with data */
1800 /* from the first group. */
1801 /* We can make a wrong assumption here. But leaving gaps is worse. */
1802 for (i = lastGroup; i > 0; i--)
1804 if (defined & (1 << i))
1806 width = key->numLevels[0];
1807 if (key->typesDefined & 1)
1809 for (j = 0; j < width; j++)
1811 key->types[i] = key->types[0];
1813 key->typesDefined |= 1 << i;
1815 if ((key->actsDefined & 1) && key->acts[0])
1817 key->acts[i] = uTypedCalloc(width, union xkb_action);
1818 if (key->acts[i] == NULL)
1820 memcpy(key->acts[i], key->acts[0],
1821 width * sizeof(union xkb_action));
1822 key->actsDefined |= 1 << i;
1824 if ((key->symsDefined & 1) && key->sizeSyms[0])
1826 key->syms[i] = uTypedCalloc(key->sizeSyms[0], xkb_keysym_t);
1827 if (key->syms[i] == NULL)
1829 memcpy(key->syms[i], key->syms[0],
1830 key->sizeSyms[0] * sizeof(xkb_keysym_t));
1831 key->symsMapIndex[i] = uTypedCalloc(width, int);
1832 if (!key->symsMapIndex[i])
1835 key->syms[i] = NULL;
1838 memcpy(key->symsMapIndex[i], key->symsMapIndex[0],
1839 width * sizeof(int));
1840 key->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
1841 if (!key->symsMapNumEntries[i])
1844 key->syms[i] = NULL;
1845 free(key->symsMapIndex[i]);
1846 key->symsMapIndex[i] = NULL;
1849 memcpy(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1850 width * sizeof(int));
1851 key->sizeSyms[i] = key->sizeSyms[0];
1852 key->symsDefined |= 1 << i;
1856 key->numLevels[i] = key->numLevels[0];
1859 /* If all groups are completely identical remove them all */
1860 /* exept the first one. */
1862 for (i = lastGroup; i > 0; i--)
1864 if ((key->numLevels[i] != key->numLevels[0]) ||
1865 (key->types[i] != key->types[0]))
1870 if ((key->syms[i] != key->syms[0]) &&
1871 (key->syms[i] == NULL || key->syms[0] == NULL ||
1872 key->sizeSyms[i] != key->sizeSyms[0] ||
1873 memcmp(key->syms[i], key->syms[0],
1874 sizeof(xkb_keysym_t) * key->sizeSyms[0])))
1879 if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
1880 (key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
1881 memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
1882 key->numLevels[0] * sizeof(int))))
1887 if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
1888 (key->symsMapNumEntries[i] == NULL ||
1889 key->symsMapNumEntries[0] == NULL ||
1890 memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
1891 key->numLevels[0] * sizeof(int))))
1896 if ((key->acts[i] != key->acts[0]) &&
1897 (key->acts[i] == NULL || key->acts[0] == NULL ||
1898 memcmp(key->acts[i], key->acts[0],
1899 sizeof(union xkb_action) * key->numLevels[0])))
1907 for (i = lastGroup; i > 0; i--)
1909 key->numLevels[i] = 0;
1911 key->syms[i] = NULL;
1912 key->sizeSyms[i] = 0;
1913 free(key->symsMapIndex[i]);
1914 key->symsMapIndex[i] = NULL;
1915 free(key->symsMapNumEntries[i]);
1916 key->symsMapNumEntries[i] = NULL;
1918 key->acts[i] = NULL;
1921 key->symsDefined &= 1;
1922 key->actsDefined &= 1;
1923 key->typesDefined &= 1;
1928 * Copy the KeyInfo into the keyboard description.
1930 * This function recurses.
1933 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1937 unsigned int sizeSyms = 0;
1938 unsigned width, tmp, nGroups;
1939 struct xkb_key_type * type;
1940 Bool haveActions, autoType, useAlias;
1941 xkb_keysym_t *outSyms;
1942 union xkb_action *outActs;
1943 unsigned types[XkbNumKbdGroups];
1944 unsigned int symIndex = 0;
1946 useAlias = (start_from == 0);
1948 /* get the keycode for the key. */
1949 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1952 if ((start_from == 0) && (warningLevel >= 5))
1954 WARN("Key %s not found in keycodes\n", longText(key->name));
1955 ACTION("Symbols ignored\n");
1960 haveActions = False;
1961 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1963 if (((i + 1) > nGroups)
1964 && (((key->symsDefined | key->actsDefined) & (1 << i))
1965 || (key->typesDefined) & (1 << i)))
1970 /* Assign the type to the key, if it is missing. */
1971 if (key->types[i] == XKB_ATOM_NONE)
1973 if (key->dfltType != XKB_ATOM_NONE)
1974 key->types[i] = key->dfltType;
1975 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1976 &key->types[i], &autoType))
1981 if (warningLevel >= 5)
1983 WARN("No automatic type for %d symbols\n",
1984 (unsigned int) key->numLevels[i]);
1985 ACTION("Using %s for the %s key (keycode %d)\n",
1986 XkbcAtomText(key->types[i]),
1987 longText(key->name), kc);
1991 if (FindNamedType(xkb, key->types[i], &types[i]))
1993 if (!autoType || key->numLevels[i] > 2)
1994 xkb->server->explicit[kc] |= (1 << i);
1998 if (warningLevel >= 3)
2000 WARN("Type \"%s\" is not defined\n",
2001 XkbcAtomText(key->types[i]));
2002 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
2003 longText(key->name), kc);
2005 types[i] = XkbTwoLevelIndex;
2007 /* if the type specifies fewer levels than the key has, shrink the key */
2008 type = &xkb->map->types[types[i]];
2009 if (type->num_levels < key->numLevels[i])
2011 if (warningLevel > 0)
2013 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
2014 type->name, type->num_levels,
2015 XkbcAtomText(key->name), key->numLevels[i]);
2016 ACTION("Ignoring extra symbols\n");
2018 key->numLevels[i] = type->num_levels;
2020 if (key->numLevels[i] > width)
2021 width = key->numLevels[i];
2022 if (type->num_levels > width)
2023 width = type->num_levels;
2024 sizeSyms += key->sizeSyms[i];
2027 if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
2029 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
2030 longText(key->name), kc);
2035 outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
2036 if (outActs == NULL)
2038 WSGO("Could not enlarge actions for %s (key %d)\n",
2039 longText(key->name), kc);
2042 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
2046 if (key->defs.defined & _Key_GroupInfo)
2049 i = xkb->map->key_sym_map[kc].group_info;
2051 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2052 xkb->map->key_sym_map[kc].width = width;
2053 xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
2054 xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
2056 for (i = 0; i < nGroups; i++)
2058 /* assign kt_index[i] to the index of the type in map->types.
2059 * kt_index[i] may have been set by a previous run (if we have two
2060 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2061 * default group if we dont even have keys for this group anyway.
2063 * FIXME: There should be a better fix for this.
2065 if (key->numLevels[i])
2066 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2067 if (key->sizeSyms[i] != 0)
2069 /* fill key to "width" symbols*/
2070 for (tmp = 0; tmp < width; tmp++)
2072 if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
2074 memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
2075 &key->syms[i][key->symsMapIndex[i][tmp]],
2076 key->symsMapNumEntries[i][tmp] *
2077 sizeof(xkb_keysym_t));
2078 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
2080 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
2081 key->symsMapNumEntries[i][tmp];
2083 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
2087 xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
2088 xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
2090 if ((outActs != NULL) && (key->acts[i] != NULL))
2092 if (tmp < key->numLevels[i])
2093 outActs[tmp] = key->acts[i][tmp];
2095 outActs[tmp].type = XkbSA_NoAction;
2100 switch (key->behavior.type & XkbKB_OpMask)
2105 xkb->server->behaviors[kc] = key->behavior;
2106 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2109 if (key->defs.defined & _Key_VModMap)
2111 xkb->server->vmodmap[kc] = key->vmodmap;
2112 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2114 if (key->repeat != RepeatUndefined)
2116 if (key->repeat == RepeatYes)
2117 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2119 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2120 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2123 if (nGroups > xkb->ctrls->num_groups)
2124 xkb->ctrls->num_groups = nGroups;
2126 /* do the same thing for the next key */
2127 CopySymbolsDef(xkb, key, kc + 1);
2132 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2136 if ((!entry->haveSymbol)
2139 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2141 if (warningLevel >= 5)
2143 WARN("Key %s not found in keycodes\n",
2144 longText(entry->u.keyName));
2145 ACTION("Modifier map entry for %s not updated\n",
2146 XkbcModIndexText(entry->modifier));
2150 else if (entry->haveSymbol
2151 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2153 if (warningLevel > 5)
2155 WARN("Key \"%s\" not found in symbol map\n",
2156 XkbcKeysymText(entry->u.keySym));
2157 ACTION("Modifier map entry for %s not updated\n",
2158 XkbcModIndexText(entry->modifier));
2162 xkb->map->modmap[kc] |= (1 << entry->modifier);
2167 * Handle the xkb_symbols section of an xkb file.
2169 * @param file The parsed xkb_symbols section of the xkb file.
2170 * @param xkb Handle to the keyboard description to store the symbols in.
2171 * @param merge Merge strategy (e.g. MergeOverride).
2174 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2179 InitSymbolsInfo(&info, xkb);
2180 info.dflt.defs.fileID = file->id;
2181 info.dflt.defs.merge = merge;
2182 HandleSymbolsFile(file, xkb, merge, &info);
2184 if (info.nKeys == 0) {
2185 FreeSymbolsInfo(&info);
2189 if (info.errorCount == 0)
2193 /* alloc memory in the xkb struct */
2194 if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
2196 WSGO("Can not allocate names in CompileSymbols\n");
2197 ACTION("Symbols not added\n");
2200 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2203 WSGO("Could not allocate client map in CompileSymbols\n");
2204 ACTION("Symbols not added\n");
2207 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2209 WSGO("Could not allocate server map in CompileSymbols\n");
2210 ACTION("Symbols not added\n");
2213 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2215 WSGO("Could not allocate controls in CompileSymbols\n");
2216 ACTION("Symbols not added\n");
2220 /* now copy info into xkb. */
2222 ApplyAliases(xkb, &info.aliases);
2223 for (i = 0; i < XkbNumKbdGroups; i++)
2225 if (info.groupNames[i] != XKB_ATOM_NONE)
2227 free(UNCONSTIFY(xkb->names->groups[i]));
2228 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
2232 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2237 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2239 if (!CopySymbolsDef(xkb, key, 0))
2242 if (warningLevel > 3)
2244 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2246 if (xkb->names->keys[i].name[0] == '\0')
2248 if (XkbKeyNumGroups(xkb, i) < 1)
2251 memcpy(buf, xkb->names->keys[i].name, 4);
2254 ("No symbols defined for <%s> (keycode %d)\n",
2261 ModMapEntry *mm, *next;
2262 for (mm = info.modMap; mm != NULL; mm = next)
2264 if (!CopyModMapDef(xkb, mm))
2266 next = (ModMapEntry *) mm->defs.next;
2269 FreeSymbolsInfo(&info);
2273 FreeSymbolsInfo(&info);