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 ********************************************************/
36 typedef struct _PreserveInfo
39 short matchingMapIndex;
40 unsigned char indexMods;
41 unsigned char preMods;
42 unsigned short indexVMods;
43 unsigned short preVMods;
46 #define _KT_Name (1<<0)
47 #define _KT_Mask (1<<1)
48 #define _KT_Map (1<<2)
49 #define _KT_Preserve (1<<3)
50 #define _KT_LevelNames (1<<4)
52 typedef struct _KeyTypeInfo
63 struct xkb_kt_map_entry * entries;
64 PreserveInfo *preserve;
69 typedef struct _KeyTypesInfo
81 uint32_t tok_ONE_LEVEL;
82 uint32_t tok_TWO_LEVEL;
83 static uint32_t tok_ALPHABETIC;
86 /***====================================================================***/
88 #define ReportTypeShouldBeArray(t, f) \
89 ReportShouldBeArray("key type", (f), TypeTxt(t))
90 #define ReportTypeBadType(t, f, w) \
91 ReportBadType("key type", (f), TypeTxt(t), (w))
93 /***====================================================================***/
95 #define MapEntryTxt(x, e) \
96 XkbcVModMaskText((x), (e)->mods.real_mods, (e)->mods.vmods)
97 #define PreserveIndexTxt(x, p) \
98 XkbcVModMaskText((x), (p)->indexMods, (p)->indexVMods)
99 #define PreserveTxt(x, p) \
100 XkbcVModMaskText((x), (p)->preMods, (p)->preVMods)
102 XkbcAtomText((t)->name)
103 #define TypeMaskTxt(t, x) \
104 XkbcVModMaskText((x), (t)->mask, (t)->vmask)
106 /***====================================================================***/
109 InitKeyTypesInfo(KeyTypesInfo * info, struct xkb_desc * xkb, KeyTypesInfo * from)
111 tok_ONE_LEVEL = XkbcInternAtom("ONE_LEVEL", False);
112 tok_TWO_LEVEL = XkbcInternAtom("TWO_LEVEL", False);
113 tok_ALPHABETIC = XkbcInternAtom("ALPHABETIC", False);
114 tok_KEYPAD = XkbcInternAtom("KEYPAD", False);
115 info->name = strdup("default");
116 info->errorCount = 0;
117 info->stdPresent = 0;
120 info->dflt.defs.defined = 0;
121 info->dflt.defs.fileID = 0;
122 info->dflt.defs.merge = MergeOverride;
123 info->dflt.defs.next = NULL;
124 info->dflt.name = None;
126 info->dflt.vmask = 0;
127 info->dflt.groupInfo = False;
128 info->dflt.numLevels = 1;
129 info->dflt.nEntries = info->dflt.szEntries = 0;
130 info->dflt.entries = NULL;
131 info->dflt.szNames = 0;
132 info->dflt.lvlNames = NULL;
133 info->dflt.preserve = NULL;
134 InitVModInfo(&info->vmods, xkb);
137 info->dflt = from->dflt;
138 if (from->dflt.entries)
140 info->dflt.entries = uTypedCalloc(from->dflt.szEntries,
141 struct xkb_kt_map_entry);
142 if (info->dflt.entries)
144 unsigned sz = from->dflt.nEntries * sizeof(struct xkb_kt_map_entry);
145 memcpy(info->dflt.entries, from->dflt.entries, sz);
148 if (from->dflt.lvlNames)
150 info->dflt.lvlNames = uTypedCalloc(from->dflt.szNames, uint32_t);
151 if (info->dflt.lvlNames)
153 register unsigned sz = from->dflt.szNames * sizeof(uint32_t);
154 memcpy(info->dflt.lvlNames, from->dflt.lvlNames, sz);
157 if (from->dflt.preserve)
159 PreserveInfo *old, *new, *last;
161 old = from->dflt.preserve;
162 for (; old; old = (PreserveInfo *) old->defs.next)
164 new = uTypedAlloc(PreserveInfo);
168 new->defs.next = NULL;
170 last->defs.next = (CommonInfo *) new;
172 info->dflt.preserve = new;
181 FreeKeyTypeInfo(KeyTypeInfo * type)
183 if (type->entries != NULL)
186 type->entries = NULL;
188 if (type->lvlNames != NULL)
190 free(type->lvlNames);
191 type->lvlNames = NULL;
193 if (type->preserve != NULL)
195 ClearCommonInfo(&type->preserve->defs);
196 type->preserve = NULL;
202 FreeKeyTypesInfo(KeyTypesInfo * info)
209 register KeyTypeInfo *type;
210 for (type = info->types; type; type = (KeyTypeInfo *) type->defs.next)
212 FreeKeyTypeInfo(type);
214 info->types = (KeyTypeInfo *) ClearCommonInfo(&info->types->defs);
216 FreeKeyTypeInfo(&info->dflt);
221 NextKeyType(KeyTypesInfo * info)
225 type = uTypedAlloc(KeyTypeInfo);
228 bzero(type, sizeof(KeyTypeInfo));
229 type->defs.fileID = info->fileID;
230 info->types = (KeyTypeInfo *) AddCommonInfo(&info->types->defs,
231 (CommonInfo *) type);
238 FindMatchingKeyType(KeyTypesInfo * info, KeyTypeInfo * new)
242 for (old = info->types; old; old = (KeyTypeInfo *) old->defs.next)
244 if (old->name == new->name)
251 ReportTypeBadWidth(const char *type, int has, int needs)
253 ERROR("Key type \"%s\" has %d levels, must have %d\n", type, has, needs);
254 ACTION("Illegal type definition ignored\n");
259 AddKeyType(struct xkb_desc * xkb, KeyTypesInfo * info, KeyTypeInfo * new)
263 if (new->name == tok_ONE_LEVEL)
265 if (new->numLevels > 1)
266 return ReportTypeBadWidth("ONE_LEVEL", new->numLevels, 1);
267 info->stdPresent |= XkbOneLevelMask;
269 else if (new->name == tok_TWO_LEVEL)
271 if (new->numLevels > 2)
272 return ReportTypeBadWidth("TWO_LEVEL", new->numLevels, 2);
273 else if (new->numLevels < 2)
275 info->stdPresent |= XkbTwoLevelMask;
277 else if (new->name == tok_ALPHABETIC)
279 if (new->numLevels > 2)
280 return ReportTypeBadWidth("ALPHABETIC", new->numLevels, 2);
281 else if (new->numLevels < 2)
283 info->stdPresent |= XkbAlphabeticMask;
285 else if (new->name == tok_KEYPAD)
287 if (new->numLevels > 2)
288 return ReportTypeBadWidth("KEYPAD", new->numLevels, 2);
289 else if (new->numLevels < 2)
291 info->stdPresent |= XkbKeypadMask;
294 old = FindMatchingKeyType(info, new);
298 if ((new->defs.merge == MergeReplace)
299 || (new->defs.merge == MergeOverride))
301 KeyTypeInfo *next = (KeyTypeInfo *) old->defs.next;
302 if (((old->defs.fileID == new->defs.fileID)
303 && (warningLevel > 0)) || (warningLevel > 9))
305 WARN("Multiple definitions of the %s key type\n",
306 XkbcAtomText(new->name));
307 ACTION("Earlier definition ignored\n");
309 FreeKeyTypeInfo(old);
311 new->szEntries = new->nEntries = 0;
313 new->preserve = NULL;
314 new->lvlNames = NULL;
315 old->defs.next = &next->defs;
318 report = (old->defs.fileID == new->defs.fileID) && (warningLevel > 0);
321 WARN("Multiple definitions of the %s key type\n",
322 XkbcAtomText(new->name));
323 ACTION("Later definition ignored\n");
325 FreeKeyTypeInfo(new);
328 old = NextKeyType(info);
332 old->defs.next = NULL;
333 new->nEntries = new->szEntries = 0;
336 new->lvlNames = NULL;
337 new->preserve = NULL;
341 /***====================================================================***/
344 MergeIncludedKeyTypes(KeyTypesInfo * into,
345 KeyTypesInfo * from, unsigned merge, struct xkb_desc * xkb)
349 if (from->errorCount > 0)
351 into->errorCount += from->errorCount;
354 if (into->name == NULL)
356 into->name = from->name;
359 for (type = from->types; type; type = (KeyTypeInfo *) type->defs.next)
361 if (merge != MergeDefault)
362 type->defs.merge = merge;
363 if (!AddKeyType(xkb, into, type))
366 into->stdPresent |= from->stdPresent;
370 typedef void (*FileHandler) (XkbFile * /* file */ ,
371 struct xkb_desc * /* xkb */ ,
372 unsigned /* merge */ ,
373 KeyTypesInfo * /* included */
377 HandleIncludeKeyTypes(IncludeStmt * stmt,
378 struct xkb_desc * xkb, KeyTypesInfo * info, FileHandler hndlr)
382 KeyTypesInfo included;
386 if ((stmt->file == NULL) && (stmt->map == NULL))
390 bzero(info, sizeof(KeyTypesInfo));
392 else if (ProcessIncludeFile(stmt, XkmTypesIndex, &rtrn, &newMerge))
394 InitKeyTypesInfo(&included, xkb, info);
395 included.fileID = included.dflt.defs.fileID = rtrn->id;
396 included.dflt.defs.merge = newMerge;
398 (*hndlr) (rtrn, xkb, newMerge, &included);
399 if (stmt->stmt != NULL)
401 if (included.name != NULL)
403 included.name = stmt->stmt;
409 info->errorCount += 10;
412 if ((stmt->next != NULL) && (included.errorCount < 1))
416 KeyTypesInfo next_incl;
418 for (next = stmt->next; next != NULL; next = next->next)
420 if ((next->file == NULL) && (next->map == NULL))
423 MergeIncludedKeyTypes(&included, info, next->merge, xkb);
424 FreeKeyTypesInfo(info);
426 else if (ProcessIncludeFile(next, XkmTypesIndex, &rtrn, &op))
428 InitKeyTypesInfo(&next_incl, xkb, &included);
429 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
430 next_incl.dflt.defs.merge = op;
431 (*hndlr) (rtrn, xkb, op, &next_incl);
432 MergeIncludedKeyTypes(&included, &next_incl, op, xkb);
433 FreeKeyTypesInfo(&next_incl);
437 info->errorCount += 10;
446 MergeIncludedKeyTypes(info, &included, newMerge, xkb);
447 FreeKeyTypesInfo(&included);
449 return (info->errorCount == 0);
452 /***====================================================================***/
454 static struct xkb_kt_map_entry *
455 FindMatchingMapEntry(KeyTypeInfo * type, unsigned mask, unsigned vmask)
458 struct xkb_kt_map_entry * entry;
460 for (i = 0, entry = type->entries; i < type->nEntries; i++, entry++)
462 if ((entry->mods.real_mods == mask) && (entry->mods.vmods == vmask))
469 DeleteLevel1MapEntries(KeyTypeInfo * type)
473 for (i = 0; i < type->nEntries; i++)
475 if (type->entries[i].level == 0)
477 for (n = i; n < type->nEntries - 1; n++)
479 type->entries[n] = type->entries[n + 1];
488 * Return a pointer to the next free XkbcKTMapEntry, reallocating space if
491 static struct xkb_kt_map_entry *
492 NextMapEntry(KeyTypeInfo * type)
494 if (type->entries == NULL)
496 type->entries = uTypedCalloc(2, struct xkb_kt_map_entry);
497 if (type->entries == NULL)
499 ERROR("Couldn't allocate map entries for %s\n", TypeTxt(type));
500 ACTION("Map entries lost\n");
506 else if (type->nEntries >= type->szEntries)
508 type->szEntries *= 2;
509 type->entries = uTypedRecalloc(type->entries,
510 type->nEntries, type->szEntries,
511 struct xkb_kt_map_entry);
512 if (type->entries == NULL)
514 ERROR("Couldn't reallocate map entries for %s\n", TypeTxt(type));
515 ACTION("Map entries lost\n");
519 return &type->entries[type->nEntries++];
523 AddPreserve(struct xkb_desc * xkb,
524 KeyTypeInfo * type, PreserveInfo * new, Bool clobber, Bool report)
528 old = type->preserve;
531 if ((old->indexMods != new->indexMods) ||
532 (old->indexVMods != new->indexVMods))
534 old = (PreserveInfo *) old->defs.next;
537 if ((old->preMods == new->preMods)
538 && (old->preVMods == new->preVMods))
540 if (warningLevel > 9)
542 WARN("Identical definitions for preserve[%s] in %s\n",
543 PreserveIndexTxt(xkb, old), TypeTxt(type));
548 if (report && (warningLevel > 0))
551 WARN("Multiple definitions for preserve[%s] in %s\n",
552 PreserveIndexTxt(xkb, old), TypeTxt(type));
555 str = PreserveTxt(xkb, new);
557 str = PreserveTxt(xkb, old);
558 ACTION("Using %s, ", str);
560 str = PreserveTxt(xkb, old);
562 str = PreserveTxt(xkb, new);
563 INFO("ignoring %s\n", str);
567 old->preMods = new->preMods;
568 old->preVMods = new->preVMods;
572 old = uTypedAlloc(PreserveInfo);
575 WSGO("Couldn't allocate preserve in %s\n", TypeTxt(type));
576 ACTION("Preserve[%s] lost\n", PreserveIndexTxt(xkb, old));
580 old->matchingMapIndex = -1;
582 (PreserveInfo *) AddCommonInfo(&type->preserve->defs, &old->defs);
587 * Add a new KTMapEntry to the given key type. If an entry with the same mods
588 * already exists, the level is updated (if clobber is TRUE). Otherwise, a new
591 * @param clobber Overwrite existing entry.
592 * @param report True if a warning is to be printed on.
595 AddMapEntry(struct xkb_desc * xkb,
597 struct xkb_kt_map_entry * new, Bool clobber, Bool report)
599 struct xkb_kt_map_entry * old;
602 FindMatchingMapEntry(type, new->mods.real_mods, new->mods.vmods)))
604 if (report && (old->level != new->level))
606 unsigned use, ignore;
609 use = new->level + 1;
610 ignore = old->level + 1;
614 use = old->level + 1;
615 ignore = new->level + 1;
617 WARN("Multiple map entries for %s in %s\n",
618 MapEntryTxt(xkb, new), TypeTxt(type));
619 ACTION("Using %d, ignoring %d\n", use, ignore);
621 else if (warningLevel > 9)
623 WARN("Multiple occurences of map[%s]= %d in %s\n",
624 MapEntryTxt(xkb, new), new->level + 1, TypeTxt(type));
629 old->level = new->level;
632 if ((old = NextMapEntry(type)) == NULL)
633 return False; /* allocation failure, already reported */
634 if (new->level >= type->numLevels)
635 type->numLevels = new->level + 1;
636 if (new->mods.vmods == 0)
640 old->mods.mask = new->mods.real_mods;
641 old->mods.real_mods = new->mods.real_mods;
642 old->mods.vmods = new->mods.vmods;
643 old->level = new->level;
647 static LookupEntry lnames[] = {
660 SetMapEntry(KeyTypeInfo * type,
661 struct xkb_desc * xkb, ExprDef * arrayNdx, ExprDef * value)
664 struct xkb_kt_map_entry entry;
666 if (arrayNdx == NULL)
667 return ReportTypeShouldBeArray(type, "map entry");
668 if (!ExprResolveModMask(arrayNdx, &rtrn, LookupVModMask, (char *) xkb))
669 return ReportTypeBadType(type, "map entry", "modifier mask");
670 entry.mods.real_mods = rtrn.uval & 0xff; /* modifiers < 512 */
671 entry.mods.vmods = (rtrn.uval >> 8) & 0xffff; /* modifiers > 512 */
672 if ((entry.mods.real_mods & (~type->mask)) ||
673 ((entry.mods.vmods & (~type->vmask)) != 0))
675 if (warningLevel > 0)
677 WARN("Map entry for unused modifiers in %s\n", TypeTxt(type));
678 ACTION("Using %s instead of ",
679 XkbcVModMaskText(xkb,
680 entry.mods.real_mods & type->mask,
681 entry.mods.vmods & type->vmask));
682 INFO("%s\n", MapEntryTxt(xkb, &entry));
684 entry.mods.real_mods &= type->mask;
685 entry.mods.vmods &= type->vmask;
687 if (!ExprResolveInteger(value, &rtrn, SimpleLookup, (char *) lnames))
689 ERROR("Level specifications in a key type must be integer\n");
690 ACTION("Ignoring malformed level specification\n");
693 if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
695 ERROR("Shift level %d out of range (1..%d) in key type %s\n",
696 XkbMaxShiftLevel + 1, rtrn.ival, TypeTxt(type));
697 ACTION("Ignoring illegal definition of map[%s]\n",
698 MapEntryTxt(xkb, &entry));
701 entry.level = rtrn.ival - 1;
702 return AddMapEntry(xkb, type, &entry, True, True);
706 SetPreserve(KeyTypeInfo * type,
707 struct xkb_desc * xkb, ExprDef * arrayNdx, ExprDef * value)
712 if (arrayNdx == NULL)
713 return ReportTypeShouldBeArray(type, "preserve entry");
714 if (!ExprResolveModMask(arrayNdx, &rtrn, LookupVModMask, (char *) xkb))
715 return ReportTypeBadType(type, "preserve entry", "modifier mask");
716 new.defs = type->defs;
717 new.defs.next = NULL;
718 new.indexMods = rtrn.uval & 0xff;
719 new.indexVMods = (rtrn.uval >> 8) & 0xffff;
720 if ((new.indexMods & (~type->mask)) || (new.indexVMods & (~type->vmask)))
722 if (warningLevel > 0)
724 WARN("Preserve for modifiers not used by the %s type\n",
726 ACTION("Index %s converted to ", PreserveIndexTxt(xkb, &new));
728 new.indexMods &= type->mask;
729 new.indexVMods &= type->vmask;
730 if (warningLevel > 0)
731 INFO("%s\n", PreserveIndexTxt(xkb, &new));
733 if (!ExprResolveModMask(value, &rtrn, LookupVModMask, (char *) xkb))
735 ERROR("Preserve value in a key type is not a modifier mask\n");
736 ACTION("Ignoring preserve[%s] in type %s\n",
737 PreserveIndexTxt(xkb, &new), TypeTxt(type));
740 new.preMods = rtrn.uval & 0xff;
741 new.preVMods = (rtrn.uval >> 16) & 0xffff;
742 if ((new.preMods & (~new.indexMods))
743 || (new.preVMods && (~new.indexVMods)))
745 if (warningLevel > 0)
747 WARN("Illegal value for preserve[%s] in type %s\n",
748 PreserveTxt(xkb, &new), TypeTxt(type));
749 ACTION("Converted %s to ", PreserveIndexTxt(xkb, &new));
751 new.preMods &= new.indexMods;
752 new.preVMods &= new.indexVMods;
753 if (warningLevel > 0)
755 INFO("%s\n", PreserveIndexTxt(xkb, &new));
758 return AddPreserve(xkb, type, &new, True, True);
761 /***====================================================================***/
764 AddLevelName(KeyTypeInfo * type,
765 unsigned level, uint32_t name, Bool clobber, Bool report)
767 if ((type->lvlNames == NULL) || (type->szNames <= level))
770 uTypedRecalloc(type->lvlNames, type->szNames, level + 1, uint32_t);
771 if (type->lvlNames == NULL)
773 ERROR("Couldn't allocate level names for type %s\n",
775 ACTION("Level names lost\n");
779 type->szNames = level + 1;
781 else if (type->lvlNames[level] == name)
783 if (warningLevel > 9)
785 WARN("Duplicate names for level %d of key type %s\n",
786 level + 1, TypeTxt(type));
791 else if (type->lvlNames[level] != None)
793 if (warningLevel > 0)
795 const char *old, *new;
796 old = XkbcAtomText(type->lvlNames[level]);
797 new = XkbcAtomText(name);
798 WARN("Multiple names for level %d of key type %s\n",
799 level + 1, TypeTxt(type));
801 ACTION("Using %s, ignoring %s\n", new, old);
803 ACTION("Using %s, ignoring %s\n", old, new);
808 if (level >= type->numLevels)
809 type->numLevels = level + 1;
810 type->lvlNames[level] = name;
815 SetLevelName(KeyTypeInfo * type, ExprDef * arrayNdx, ExprDef * value)
821 if (arrayNdx == NULL)
822 return ReportTypeShouldBeArray(type, "level name");
823 if (!ExprResolveInteger(arrayNdx, &rtrn, SimpleLookup, (char *) lnames))
824 return ReportTypeBadType(type, "level name", "integer");
825 if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
827 ERROR("Level name %d out of range (1..%d) in key type %s\n",
829 XkbMaxShiftLevel + 1,
830 XkbcAtomText(type->name));
831 ACTION("Ignoring illegal level name definition\n");
834 level = rtrn.ival - 1;
835 if (!ExprResolveString(value, &rtrn, NULL, NULL))
837 ERROR("Non-string name for level %d in key type %s\n", level + 1,
838 XkbcAtomText(type->name));
839 ACTION("Ignoring illegal level name definition\n");
842 level_name = XkbcInternAtom(rtrn.str, False);
844 return AddLevelName(type, level, level_name, True, True);
847 /***====================================================================***/
850 * Parses the fields in a type "..." { } description.
852 * @param field The field to parse (e.g. modifiers, map, level_name)
855 SetKeyTypeField(KeyTypeInfo * type,
856 struct xkb_desc * xkb,
858 ExprDef * arrayNdx, ExprDef * value, KeyTypesInfo * info)
862 if (uStrCaseCmp(field, "modifiers") == 0)
864 unsigned mods, vmods;
865 if (arrayNdx != NULL)
867 WARN("The modifiers field of a key type is not an array\n");
868 ACTION("Illegal array subscript ignored\n");
870 /* get modifier mask for current type */
871 if (!ExprResolveModMask(value, &tmp, LookupVModMask, (char *) xkb))
873 ERROR("Key type mask field must be a modifier mask\n");
874 ACTION("Key type definition ignored\n");
877 mods = tmp.uval & 0xff; /* core mods */
878 vmods = (tmp.uval >> 8) & 0xffff; /* xkb virtual mods */
879 if (type->defs.defined & _KT_Mask)
881 WARN("Multiple modifier mask definitions for key type %s\n",
882 XkbcAtomText(type->name));
883 ACTION("Using %s, ", TypeMaskTxt(type, xkb));
884 INFO("ignoring %s\n", XkbcVModMaskText(xkb, mods, vmods));
889 type->defs.defined |= _KT_Mask;
892 else if (uStrCaseCmp(field, "map") == 0)
894 type->defs.defined |= _KT_Map;
895 return SetMapEntry(type, xkb, arrayNdx, value);
897 else if (uStrCaseCmp(field, "preserve") == 0)
899 type->defs.defined |= _KT_Preserve;
900 return SetPreserve(type, xkb, arrayNdx, value);
902 else if ((uStrCaseCmp(field, "levelname") == 0) ||
903 (uStrCaseCmp(field, "level_name") == 0))
905 type->defs.defined |= _KT_LevelNames;
906 return SetLevelName(type, arrayNdx, value);
908 ERROR("Unknown field %s in key type %s\n", field, TypeTxt(type));
909 ACTION("Definition ignored\n");
914 HandleKeyTypeVar(VarDef * stmt, struct xkb_desc * xkb, KeyTypesInfo * info)
916 ExprResult elem, field;
919 if (!ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx))
920 return False; /* internal error, already reported */
921 if (elem.str && (uStrCaseCmp(elem.str, "type") == 0))
922 return SetKeyTypeField(&info->dflt, xkb, field.str, arrayNdx,
924 if (elem.str != NULL)
926 ERROR("Default for unknown element %s\n", uStringText(elem.str));
927 ACTION("Value for field %s ignored\n", uStringText(field.str));
929 else if (field.str != NULL)
931 ERROR("Default defined for unknown field %s\n",
932 uStringText(field.str));
939 HandleKeyTypeBody(VarDef * def,
940 struct xkb_desc * xkb, KeyTypeInfo * type, KeyTypesInfo * info)
943 ExprResult tmp, field;
946 for (; def != NULL; def = (VarDef *) def->common.next)
948 if ((def->name) && (def->name->type == ExprFieldRef))
950 ok = HandleKeyTypeVar(def, xkb, info);
953 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
955 ok = SetKeyTypeField(type, xkb, field.str, arrayNdx, def->value,
962 * Process a type "XYZ" { } specification in the xkb_types section.
966 HandleKeyTypeDef(KeyTypeDef * def,
967 struct xkb_desc * xkb, unsigned merge, KeyTypesInfo * info)
972 if (def->merge != MergeDefault)
975 type.defs.defined = 0;
976 type.defs.fileID = info->fileID;
977 type.defs.merge = merge;
978 type.defs.next = NULL;
979 type.name = def->name;
980 type.mask = info->dflt.mask;
981 type.vmask = info->dflt.vmask;
982 type.groupInfo = info->dflt.groupInfo;
984 type.nEntries = type.szEntries = 0;
987 type.lvlNames = NULL;
988 type.preserve = NULL;
990 /* Parse the actual content. */
991 if (!HandleKeyTypeBody(def->body, xkb, &type, info))
997 /* now copy any appropriate map, preserve or level names from the */
999 for (i = 0; i < info->dflt.nEntries; i++)
1001 struct xkb_kt_map_entry * dflt;
1002 dflt = &info->dflt.entries[i];
1003 if (((dflt->mods.real_mods & type.mask) == dflt->mods.real_mods) &&
1004 ((dflt->mods.vmods & type.vmask) == dflt->mods.vmods))
1006 AddMapEntry(xkb, &type, dflt, False, False);
1009 if (info->dflt.preserve)
1011 PreserveInfo *dflt = info->dflt.preserve;
1014 if (((dflt->indexMods & type.mask) == dflt->indexMods) &&
1015 ((dflt->indexVMods & type.vmask) == dflt->indexVMods))
1017 AddPreserve(xkb, &type, dflt, False, False);
1019 dflt = (PreserveInfo *) dflt->defs.next;
1022 for (i = 0; i < info->dflt.szNames; i++)
1024 if ((i < type.numLevels) && (info->dflt.lvlNames[i] != None))
1026 AddLevelName(&type, i, info->dflt.lvlNames[i], False, False);
1029 /* Now add the new keytype to the info struct */
1030 if (!AddKeyType(xkb, info, &type))
1039 * Process an xkb_types section.
1041 * @param file The parsed xkb_types section.
1042 * @param merge Merge Strategy (e.g. MergeOverride)
1043 * @param info Pointer to memory where the outcome will be stored.
1046 HandleKeyTypesFile(XkbFile * file,
1047 struct xkb_desc * xkb, unsigned merge, KeyTypesInfo * info)
1051 info->name = _XkbDupString(file->name);
1055 switch (stmt->stmtType)
1058 if (!HandleIncludeKeyTypes((IncludeStmt *) stmt, xkb, info,
1059 HandleKeyTypesFile))
1062 case StmtKeyTypeDef: /* e.g. type "ONE_LEVEL" */
1063 if (!HandleKeyTypeDef((KeyTypeDef *) stmt, xkb, merge, info))
1067 if (!HandleKeyTypeVar((VarDef *) stmt, xkb, info))
1070 case StmtVModDef: /* virtual_modifiers NumLock, ... */
1071 if (!HandleVModDef((VModDef *) stmt, merge, &info->vmods))
1074 case StmtKeyAliasDef:
1075 ERROR("Key type files may not include other declarations\n");
1076 ACTION("Ignoring definition of key alias\n");
1079 case StmtKeycodeDef:
1080 ERROR("Key type files may not include other declarations\n");
1081 ACTION("Ignoring definition of key name\n");
1085 ERROR("Key type files may not include other declarations\n");
1086 ACTION("Ignoring definition of symbol interpretation\n");
1090 WSGO("Unexpected statement type %d in HandleKeyTypesFile\n",
1095 if (info->errorCount > 10)
1098 ERROR("Too many errors\n");
1100 ACTION("Abandoning keytypes file \"%s\"\n", file->topName);
1108 CopyDefToKeyType(struct xkb_desc * xkb, struct xkb_key_type * type, KeyTypeInfo * def)
1113 for (pre = def->preserve; pre != NULL;
1114 pre = (PreserveInfo *) pre->defs.next)
1116 struct xkb_kt_map_entry * match;
1117 struct xkb_kt_map_entry tmp;
1118 tmp.mods.real_mods = pre->indexMods;
1119 tmp.mods.vmods = pre->indexVMods;
1121 AddMapEntry(xkb, def, &tmp, False, False);
1122 match = FindMatchingMapEntry(def, pre->indexMods, pre->indexVMods);
1125 WSGO("Couldn't find matching entry for preserve\n");
1126 ACTION("Aborting\n");
1129 pre->matchingMapIndex = match - def->entries;
1131 type->mods.real_mods = def->mask;
1132 type->mods.vmods = def->vmask;
1133 type->num_levels = def->numLevels;
1134 type->map_count = def->nEntries;
1135 type->map = def->entries;
1138 type->preserve = uTypedCalloc(type->map_count, struct xkb_mods);
1139 if (!type->preserve)
1141 WARN("Couldn't allocate preserve array in CopyDefToKeyType\n");
1142 ACTION("Preserve setting for type %s lost\n",
1143 XkbcAtomText(def->name));
1147 pre = def->preserve;
1148 for (; pre != NULL; pre = (PreserveInfo *) pre->defs.next)
1150 int ndx = pre->matchingMapIndex;
1151 type->preserve[ndx].mask = pre->preMods;
1152 type->preserve[ndx].real_mods = pre->preMods;
1153 type->preserve[ndx].vmods = pre->preVMods;
1158 type->preserve = NULL;
1159 type->name = (uint32_t) def->name;
1160 if (def->szNames > 0)
1162 type->level_names = uTypedCalloc(def->numLevels, uint32_t);
1164 /* assert def->szNames<=def->numLevels */
1165 for (i = 0; i < def->szNames; i++)
1167 type->level_names[i] = (uint32_t) def->lvlNames[i];
1172 type->level_names = NULL;
1175 def->nEntries = def->szEntries = 0;
1176 def->entries = NULL;
1177 return XkbcComputeEffectiveMap(xkb, type, NULL);
1181 CompileKeyTypes(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
1185 InitKeyTypesInfo(&info, xkb, NULL);
1186 info.fileID = file->id;
1187 HandleKeyTypesFile(file, xkb, merge, &info);
1189 if (info.errorCount == 0)
1192 register KeyTypeInfo *def;
1193 register struct xkb_key_type *type, *next;
1195 if (info.name != NULL)
1197 if (XkbcAllocNames(xkb, XkbTypesNameMask, 0, 0) == Success)
1198 xkb->names->types = XkbcInternAtom(info.name, False);
1201 WSGO("Couldn't allocate space for types name\n");
1202 ACTION("Name \"%s\" (from %s) NOT assigned\n",
1203 scanFile, info.name);
1207 if ((info.stdPresent & XkbOneLevelMask) == 0)
1209 if ((info.stdPresent & XkbTwoLevelMask) == 0)
1211 if ((info.stdPresent & XkbKeypadMask) == 0)
1213 if ((info.stdPresent & XkbAlphabeticMask) == 0)
1215 if (XkbcAllocClientMap(xkb, XkbKeyTypesMask, i) != Success)
1217 WSGO("Couldn't allocate client map\n");
1220 xkb->map->num_types = i;
1221 if (XkbAllRequiredTypes & (~info.stdPresent))
1223 unsigned missing, keypadVMod;
1225 missing = XkbAllRequiredTypes & (~info.stdPresent);
1226 keypadVMod = FindKeypadVMod(xkb);
1227 if (XkbcInitCanonicalKeyTypes(xkb, missing, keypadVMod) != Success)
1229 WSGO("Couldn't initialize canonical key types\n");
1232 if (missing & XkbOneLevelMask)
1233 xkb->map->types[XkbOneLevelIndex].name = tok_ONE_LEVEL;
1234 if (missing & XkbTwoLevelMask)
1235 xkb->map->types[XkbTwoLevelIndex].name = tok_TWO_LEVEL;
1236 if (missing & XkbAlphabeticMask)
1237 xkb->map->types[XkbAlphabeticIndex].name = tok_ALPHABETIC;
1238 if (missing & XkbKeypadMask)
1239 xkb->map->types[XkbKeypadIndex].name = tok_KEYPAD;
1241 next = &xkb->map->types[XkbLastRequiredType + 1];
1242 for (i = 0, def = info.types; i < info.nTypes; i++)
1244 if (def->name == tok_ONE_LEVEL)
1245 type = &xkb->map->types[XkbOneLevelIndex];
1246 else if (def->name == tok_TWO_LEVEL)
1247 type = &xkb->map->types[XkbTwoLevelIndex];
1248 else if (def->name == tok_ALPHABETIC)
1249 type = &xkb->map->types[XkbAlphabeticIndex];
1250 else if (def->name == tok_KEYPAD)
1251 type = &xkb->map->types[XkbKeypadIndex];
1254 DeleteLevel1MapEntries(def);
1255 if (!CopyDefToKeyType(xkb, type, def))
1257 def = (KeyTypeInfo *) def->defs.next;