symbols: add keymap to SymbolsInfo
[platform/upstream/libxkbcommon.git] / src / xkbcomp / symbols.c
1 /************************************************************
2  * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3  *
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.
15  *
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.
24  *
25  ********************************************************/
26
27 #include <limits.h>
28
29 #include "xkbcomp-priv.h"
30 #include "parseutils.h"
31 #include "action.h"
32 #include "vmod.h"
33
34 /***====================================================================***/
35
36 /* Needed to work with the typechecker. */
37 typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
38 typedef darray(union xkb_action) darray_xkb_action;
39
40 #define RepeatYes       1
41 #define RepeatNo        0
42 #define RepeatUndefined ~((unsigned) 0)
43
44 #define _Key_Syms       (1 << 0)
45 #define _Key_Acts       (1 << 1)
46 #define _Key_Repeat     (1 << 2)
47 #define _Key_Behavior   (1 << 3)
48 #define _Key_Type_Dflt  (1 << 4)
49 #define _Key_Types      (1 << 5)
50 #define _Key_GroupInfo  (1 << 6)
51 #define _Key_VModMap    (1 << 7)
52
53 static inline const char *
54 longText(unsigned long val)
55 {
56     char buf[4];
57
58     LongToKeyName(val, buf);
59     return XkbcKeyNameText(buf);
60 }
61
62 typedef struct _KeyInfo {
63     unsigned short defined;
64     unsigned file_id;
65     enum merge_mode merge;
66
67     unsigned long name; /* the 4 chars of the key name, as long */
68     unsigned char typesDefined;
69     unsigned char symsDefined;
70     unsigned char actsDefined;
71     unsigned int numLevels[XkbNumKbdGroups];
72
73     /* syms[group] -> Single array for all the keysyms in the group. */
74     darray_xkb_keysym_t syms[XkbNumKbdGroups];
75     /*
76      * symsMapIndex[group][level] -> The index from which the syms for
77      * the level begin in the syms[group] array. Remember each keycode
78      * can have multiple keysyms in each level (that is, each key press
79      * can result in multiple keysyms).
80      */
81     darray(int) symsMapIndex[XkbNumKbdGroups];
82     /*
83      * symsMapNumEntries[group][level] -> How many syms are in
84      * syms[group][symsMapIndex[group][level]].
85      */
86     darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
87
88     darray_xkb_action acts[XkbNumKbdGroups];
89
90     xkb_atom_t types[XkbNumKbdGroups];
91     unsigned repeat;
92     struct xkb_behavior behavior;
93     unsigned short vmodmap;
94     xkb_atom_t dfltType;
95
96     uint8_t out_of_range_group_action;
97     xkb_group_index_t out_of_range_group_number;
98 } KeyInfo;
99
100 /**
101  * Init the given key info to sane values.
102  */
103 static void
104 InitKeyInfo(KeyInfo *keyi, unsigned file_id)
105 {
106     xkb_group_index_t i;
107     static const char dflt[4] = "*";
108
109     keyi->defined = 0;
110     keyi->file_id = file_id;
111     keyi->merge = MERGE_OVERRIDE;
112     keyi->name = KeyNameToLong(dflt);
113     keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 0;
114
115     for (i = 0; i < XkbNumKbdGroups; i++) {
116         keyi->numLevels[i] = 0;
117         keyi->types[i] = XKB_ATOM_NONE;
118         darray_init(keyi->syms[i]);
119         darray_init(keyi->symsMapIndex[i]);
120         darray_init(keyi->symsMapNumEntries[i]);
121         darray_init(keyi->acts[i]);
122     }
123
124     keyi->dfltType = XKB_ATOM_NONE;
125     keyi->behavior.type = XkbKB_Default;
126     keyi->behavior.data = 0;
127     keyi->vmodmap = 0;
128     keyi->repeat = RepeatUndefined;
129     keyi->out_of_range_group_action = 0;
130     keyi->out_of_range_group_number = 0;
131 }
132
133 static void
134 FreeKeyInfo(KeyInfo *keyi)
135 {
136     xkb_group_index_t i;
137
138     for (i = 0; i < XkbNumKbdGroups; i++) {
139         darray_free(keyi->syms[i]);
140         darray_free(keyi->symsMapIndex[i]);
141         darray_free(keyi->symsMapNumEntries[i]);
142         darray_free(keyi->acts[i]);
143     }
144 }
145
146 /**
147  * Copy old into new, optionally reset old to 0.
148  * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
149  * newly allocated and new points to the new memory areas.
150  */
151 static bool
152 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
153 {
154     xkb_group_index_t i;
155
156     *new = *old;
157
158     if (clearOld) {
159         for (i = 0; i < XkbNumKbdGroups; i++) {
160             old->numLevels[i] = 0;
161             darray_init(old->symsMapIndex[i]);
162             darray_init(old->symsMapNumEntries[i]);
163             darray_init(old->syms[i]);
164             darray_init(old->acts[i]);
165         }
166     }
167     else {
168         for (i = 0; i < XkbNumKbdGroups; i++) {
169             darray_copy(new->syms[i], old->syms[i]);
170             darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
171             darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
172             darray_copy(new->acts[i], old->acts[i]);
173         }
174     }
175
176     return true;
177 }
178
179 /***====================================================================***/
180
181 typedef struct _ModMapEntry {
182     struct list entry;
183     enum merge_mode merge;
184     bool haveSymbol;
185     int modifier;
186     union {
187         unsigned long keyName;
188         xkb_keysym_t keySym;
189     } u;
190 } ModMapEntry;
191
192 typedef struct _SymbolsInfo {
193     char *name;         /* e.g. pc+us+inet(evdev) */
194     int errorCount;
195     unsigned file_id;
196     enum merge_mode merge;
197     xkb_group_index_t explicit_group;
198     darray(KeyInfo) keys;
199     KeyInfo dflt;
200     VModInfo vmods;
201     ActionInfo *action;
202     xkb_atom_t groupNames[XkbNumKbdGroups];
203
204     struct list modMaps;
205
206     struct xkb_keymap *keymap;
207 } SymbolsInfo;
208
209 static void
210 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap,
211                 unsigned file_id)
212 {
213     xkb_group_index_t i;
214
215     info->name = NULL;
216     info->explicit_group = 0;
217     info->errorCount = 0;
218     info->file_id = file_id;
219     info->merge = MERGE_OVERRIDE;
220     darray_init(info->keys);
221     darray_growalloc(info->keys, 110);
222     list_init(&info->modMaps);
223     for (i = 0; i < XkbNumKbdGroups; i++)
224         info->groupNames[i] = XKB_ATOM_NONE;
225     InitKeyInfo(&info->dflt, file_id);
226     InitVModInfo(&info->vmods, keymap);
227     info->action = NULL;
228     info->keymap = keymap;
229 }
230
231 static void
232 FreeSymbolsInfo(SymbolsInfo * info)
233 {
234     KeyInfo *keyi;
235     ModMapEntry *mm, *next;
236
237     free(info->name);
238     darray_foreach(keyi, info->keys) {
239         FreeKeyInfo(keyi);
240     }
241     darray_free(info->keys);
242     list_foreach_safe(mm, next, &info->modMaps, entry)
243         free(mm);
244     memset(info, 0, sizeof(SymbolsInfo));
245 }
246
247 static bool
248 ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group, unsigned int numLevels,
249                unsigned sizeSyms, bool forceActions)
250 {
251     int i;
252
253     if (darray_size(keyi->syms[group]) < sizeSyms)
254         darray_resize0(keyi->syms[group], sizeSyms);
255
256     if (darray_empty(keyi->symsMapIndex[group]) ||
257         keyi->numLevels[group] < numLevels) {
258         darray_resize(keyi->symsMapIndex[group], numLevels);
259         for (i = keyi->numLevels[group]; i < numLevels; i++)
260             darray_item(keyi->symsMapIndex[group], i) = -1;
261     }
262
263     if (darray_empty(keyi->symsMapNumEntries[group]) ||
264         keyi->numLevels[group] < numLevels)
265         darray_resize0(keyi->symsMapNumEntries[group], numLevels);
266
267     if ((forceActions && (keyi->numLevels[group] < numLevels ||
268                           darray_empty(keyi->acts[group]))) ||
269         (keyi->numLevels[group] < numLevels && !darray_empty(keyi->acts[group])))
270         darray_resize0(keyi->acts[group], numLevels);
271
272     if (keyi->numLevels[group] < numLevels)
273         keyi->numLevels[group] = numLevels;
274
275     return true;
276 }
277
278 enum key_group_selector {
279     NONE = 0,
280     FROM = (1 << 0),
281     TO = (1 << 1),
282 };
283
284 static bool
285 MergeKeyGroups(SymbolsInfo * info,
286                KeyInfo * into, KeyInfo * from, xkb_group_index_t group)
287 {
288     darray_xkb_keysym_t resultSyms;
289     enum key_group_selector using = NONE;
290     darray_xkb_action resultActs;
291     unsigned int resultWidth;
292     unsigned int resultSize = 0;
293     int cur_idx = 0;
294     int i;
295     bool report, clobber;
296
297     clobber = (from->merge != MERGE_AUGMENT);
298
299     report = (warningLevel > 9) ||
300              (into->file_id == from->file_id && warningLevel > 0);
301
302     darray_init(resultSyms);
303
304     if (into->numLevels[group] >= from->numLevels[group]) {
305         resultActs = into->acts[group];
306         resultWidth = into->numLevels[group];
307     }
308     else {
309         resultActs = from->acts[group];
310         resultWidth = from->numLevels[group];
311         darray_resize(into->symsMapIndex[group],
312                       from->numLevels[group]);
313         darray_resize0(into->symsMapNumEntries[group],
314                        from->numLevels[group]);
315
316         for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
317             darray_item(into->symsMapIndex[group], i) = -1;
318     }
319
320     if (darray_empty(resultActs) && (!darray_empty(into->acts[group]) ||
321                                      !darray_empty(from->acts[group]))) {
322         darray_resize0(resultActs, resultWidth);
323         for (i = 0; i < resultWidth; i++) {
324             union xkb_action *fromAct = NULL, *toAct = NULL;
325
326             if (!darray_empty(from->acts[group]))
327                 fromAct = &darray_item(from->acts[group], i);
328
329             if (!darray_empty(into->acts[group]))
330                 toAct = &darray_item(into->acts[group], i);
331
332             if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
333                 && (toAct != NULL)) {
334                 darray_item(resultActs, i) = *toAct;
335             }
336             else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
337                      && (fromAct != NULL)) {
338                 darray_item(resultActs, i) = *fromAct;
339             }
340             else {
341                 union xkb_action *use, *ignore;
342                 if (clobber) {
343                     use = fromAct;
344                     ignore = toAct;
345                 }
346                 else {
347                     use = toAct;
348                     ignore = fromAct;
349                 }
350                 if (report) {
351                     WARN
352                         ("Multiple actions for level %d/group %u on key %s\n",
353                         i + 1, group + 1, longText(into->name));
354                     ACTION("Using %s, ignoring %s\n",
355                            XkbcActionTypeText(use->type),
356                            XkbcActionTypeText(ignore->type));
357                 }
358                 if (use)
359                     darray_item(resultActs, i) = *use;
360             }
361         }
362     }
363
364     for (i = 0; i < resultWidth; i++) {
365         unsigned int fromSize = 0;
366         unsigned toSize = 0;
367
368         if (!darray_empty(from->symsMapNumEntries[group]) &&
369             i < from->numLevels[group])
370             fromSize = darray_item(from->symsMapNumEntries[group], i);
371
372         if (!darray_empty(into->symsMapNumEntries[group]) &&
373             i < into->numLevels[group])
374             toSize = darray_item(into->symsMapNumEntries[group], i);
375
376         if (fromSize == 0) {
377             resultSize += toSize;
378             using |= TO;
379         }
380         else if (toSize == 0 || clobber) {
381             resultSize += fromSize;
382             using |= FROM;
383         }
384         else {
385             resultSize += toSize;
386             using |= TO;
387         }
388     }
389
390     if (resultSize == 0)
391         goto out;
392
393     if (using == FROM) {
394         resultSyms = from->syms[group];
395         darray_free(into->symsMapNumEntries[group]);
396         darray_free(into->symsMapIndex[group]);
397         into->symsMapNumEntries[group] = from->symsMapNumEntries[group];
398         into->symsMapIndex[group] = from->symsMapIndex[group];
399         darray_init(from->symsMapNumEntries[group]);
400         darray_init(from->symsMapIndex[group]);
401         goto out;
402     }
403     else if (using == TO) {
404         resultSyms = into->syms[group];
405         goto out;
406     }
407
408     darray_resize0(resultSyms, resultSize);
409
410     for (i = 0; i < resultWidth; i++) {
411         enum key_group_selector use = NONE;
412         unsigned int fromSize = 0;
413         unsigned int toSize = 0;
414
415         if (i < from->numLevels[group])
416             fromSize = darray_item(from->symsMapNumEntries[group], i);
417
418         if (i < into->numLevels[group])
419             toSize = darray_item(into->symsMapNumEntries[group], i);
420
421         if (fromSize == 0 && toSize == 0) {
422             darray_item(into->symsMapIndex[group], i) = -1;
423             darray_item(into->symsMapNumEntries[group], i) = 0;
424             continue;
425         }
426
427         if (fromSize == 0)
428             use = TO;
429         else if (toSize == 0 || clobber)
430             use = FROM;
431         else
432             use = TO;
433
434         if (toSize && fromSize && report) {
435             INFO("Multiple symbols for group %u, level %d on key %s\n",
436                  group + 1, i + 1, longText(into->name));
437             ACTION("Using %s, ignoring %s\n",
438                    (use == FROM ? "from" : "to"),
439                    (use == FROM ? "to" : "from"));
440         }
441
442         if (use == FROM) {
443             memcpy(darray_mem(resultSyms, cur_idx),
444                    darray_mem(from->syms[group],
445                               darray_item(from->symsMapIndex[group], i)),
446                    darray_item(from->symsMapNumEntries[group],
447                                i) * sizeof(xkb_keysym_t));
448             darray_item(into->symsMapIndex[group], i) = cur_idx;
449             darray_item(into->symsMapNumEntries[group], i) =
450                 darray_item(from->symsMapNumEntries[group], i);
451         }
452         else {
453             memcpy(darray_mem(resultSyms, cur_idx),
454                    darray_mem(into->syms[group],
455                               darray_item(into->symsMapIndex[group], i)),
456                    darray_item(into->symsMapNumEntries[group],
457                                i) * sizeof(xkb_keysym_t));
458             darray_item(into->symsMapIndex[group], i) = cur_idx;
459         }
460         cur_idx += darray_item(into->symsMapNumEntries[group], i);
461     }
462
463 out:
464     if (!darray_same(resultActs, into->acts[group]))
465         darray_free(into->acts[group]);
466     if (!darray_same(resultActs, from->acts[group]))
467         darray_free(from->acts[group]);
468     into->numLevels[group] = resultWidth;
469     if (!darray_same(resultSyms, into->syms[group]))
470         darray_free(into->syms[group]);
471     into->syms[group] = resultSyms;
472     if (!darray_same(resultSyms, from->syms[group]))
473         darray_free(from->syms[group]);
474     darray_init(from->syms[group]);
475     darray_free(from->symsMapIndex[group]);
476     darray_free(from->symsMapNumEntries[group]);
477     into->acts[group] = resultActs;
478     darray_init(from->acts[group]);
479     if (!darray_empty(into->syms[group]))
480         into->symsDefined |= (1 << group);
481     from->symsDefined &= ~(1 << group);
482     into->actsDefined |= (1 << group);
483     from->actsDefined &= ~(1 << group);
484
485     return true;
486 }
487
488 static bool
489 MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
490 {
491     xkb_group_index_t i;
492     unsigned collide = 0;
493     bool report;
494
495     if (from->merge == MERGE_REPLACE) {
496         for (i = 0; i < XkbNumKbdGroups; i++) {
497             if (into->numLevels[i] != 0) {
498                 darray_free(into->syms[i]);
499                 darray_free(into->acts[i]);
500             }
501         }
502         *into = *from;
503         memset(from, 0, sizeof(KeyInfo));
504         return true;
505     }
506     report = ((warningLevel > 9) ||
507               ((into->file_id == from->file_id)
508                && (warningLevel > 0)));
509     for (i = 0; i < XkbNumKbdGroups; i++) {
510         if (from->numLevels[i] > 0) {
511             if (into->numLevels[i] == 0) {
512                 into->numLevels[i] = from->numLevels[i];
513                 into->syms[i] = from->syms[i];
514                 into->symsMapIndex[i] = from->symsMapIndex[i];
515                 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
516                 into->acts[i] = from->acts[i];
517                 into->symsDefined |= (1 << i);
518                 darray_init(from->syms[i]);
519                 darray_init(from->symsMapIndex[i]);
520                 darray_init(from->symsMapNumEntries[i]);
521                 darray_init(from->acts[i]);
522                 from->numLevels[i] = 0;
523                 from->symsDefined &= ~(1 << i);
524                 if (!darray_empty(into->syms[i]))
525                     into->defined |= _Key_Syms;
526                 if (!darray_empty(into->acts[i]))
527                     into->defined |= _Key_Acts;
528             }
529             else {
530                 if (report) {
531                     if (!darray_empty(into->syms[i]))
532                         collide |= _Key_Syms;
533                     if (!darray_empty(into->acts[i]))
534                         collide |= _Key_Acts;
535                 }
536                 MergeKeyGroups(info, into, from, (unsigned) i);
537             }
538         }
539         if (from->types[i] != XKB_ATOM_NONE) {
540             if ((into->types[i] != XKB_ATOM_NONE) && report &&
541                 (into->types[i] != from->types[i])) {
542                 xkb_atom_t use, ignore;
543                 collide |= _Key_Types;
544                 if (from->merge != MERGE_AUGMENT) {
545                     use = from->types[i];
546                     ignore = into->types[i];
547                 }
548                 else {
549                     use = into->types[i];
550                     ignore = from->types[i];
551                 }
552                 WARN
553                     ("Multiple definitions for group %d type of key %s\n",
554                     i, longText(into->name));
555                 ACTION("Using %s, ignoring %s\n",
556                        xkb_atom_text(info->keymap->ctx, use),
557                        xkb_atom_text(info->keymap->ctx, ignore));
558             }
559             if (from->merge != MERGE_AUGMENT ||
560                 into->types[i] == XKB_ATOM_NONE) {
561                 into->types[i] = from->types[i];
562             }
563         }
564     }
565     if (UseNewField(_Key_Behavior, into->defined, into->file_id,
566                     from->defined, from->file_id, from->merge, &collide)) {
567         into->behavior = from->behavior;
568         into->defined |= _Key_Behavior;
569     }
570     if (UseNewField(_Key_VModMap, into->defined, into->file_id,
571                     from->defined, from->file_id, from->merge, &collide)) {
572         into->vmodmap = from->vmodmap;
573         into->defined |= _Key_VModMap;
574     }
575     if (UseNewField(_Key_Repeat, into->defined, into->file_id,
576                     from->defined, from->file_id, from->merge, &collide)) {
577         into->repeat = from->repeat;
578         into->defined |= _Key_Repeat;
579     }
580     if (UseNewField(_Key_Type_Dflt, into->defined, into->file_id,
581                     from->defined, from->file_id, from->merge, &collide)) {
582         into->dfltType = from->dfltType;
583         into->defined |= _Key_Type_Dflt;
584     }
585     if (UseNewField(_Key_GroupInfo, into->defined, into->file_id,
586                     from->defined, from->file_id, from->merge, &collide)) {
587         into->out_of_range_group_action = from->out_of_range_group_action;
588         into->out_of_range_group_number = from->out_of_range_group_number;
589         into->defined |= _Key_GroupInfo;
590     }
591     if (collide) {
592         WARN("Symbol map for key %s redefined\n",
593              longText(into->name));
594         ACTION("Using %s definition for conflicting fields\n",
595                (from->merge == MERGE_AUGMENT ? "first" : "last"));
596     }
597     return true;
598 }
599
600 static bool
601 AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
602 {
603     unsigned long real_name;
604     KeyInfo *iter, *new;
605
606     darray_foreach(iter, info->keys)
607         if (iter->name == keyi->name)
608             return MergeKeys(info, iter, keyi);
609
610     if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
611         darray_foreach(iter, info->keys)
612             if (iter->name == real_name)
613                 return MergeKeys(info, iter, keyi);
614
615     darray_resize0(info->keys, darray_size(info->keys) + 1);
616     new = &darray_item(info->keys, darray_size(info->keys) - 1);
617     return CopyKeyInfo(keyi, new, true);
618 }
619
620 static bool
621 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
622 {
623     ModMapEntry *mm;
624     bool clobber;
625
626     clobber = (new->merge != MERGE_AUGMENT);
627     list_foreach(mm, &info->modMaps, entry) {
628         if (new->haveSymbol && mm->haveSymbol
629             && (new->u.keySym == mm->u.keySym)) {
630             unsigned use, ignore;
631             if (mm->modifier != new->modifier) {
632                 if (clobber) {
633                     use = new->modifier;
634                     ignore = mm->modifier;
635                 }
636                 else {
637                     use = mm->modifier;
638                     ignore = new->modifier;
639                 }
640                 ERROR
641                     ("%s added to symbol map for multiple modifiers\n",
642                     XkbcKeysymText(new->u.keySym));
643                 ACTION("Using %s, ignoring %s.\n",
644                        XkbcModIndexText(use),
645                        XkbcModIndexText(ignore));
646                 mm->modifier = use;
647             }
648             return true;
649         }
650         if ((!new->haveSymbol) && (!mm->haveSymbol) &&
651             (new->u.keyName == mm->u.keyName)) {
652             unsigned use, ignore;
653             if (mm->modifier != new->modifier) {
654                 if (clobber) {
655                     use = new->modifier;
656                     ignore = mm->modifier;
657                 }
658                 else {
659                     use = mm->modifier;
660                     ignore = new->modifier;
661                 }
662                 ERROR("Key %s added to map for multiple modifiers\n",
663                       longText(new->u.keyName));
664                 ACTION("Using %s, ignoring %s.\n",
665                        XkbcModIndexText(use),
666                        XkbcModIndexText(ignore));
667                 mm->modifier = use;
668             }
669             return true;
670         }
671     }
672
673     mm = malloc(sizeof(*mm));
674     if (!mm) {
675         WSGO("Could not allocate modifier map entry\n");
676         ACTION("Modifier map for %s will be incomplete\n",
677                XkbcModIndexText(new->modifier));
678         return false;
679     }
680
681     *mm = *new;
682     list_add(&mm->entry, &info->modMaps);
683     return true;
684 }
685
686 /***====================================================================***/
687
688 static void
689 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
690                      enum merge_mode merge)
691 {
692     unsigned int i;
693     KeyInfo *keyi;
694     ModMapEntry *mm, *next;
695
696     if (from->errorCount > 0) {
697         into->errorCount += from->errorCount;
698         return;
699     }
700     if (into->name == NULL) {
701         into->name = from->name;
702         from->name = NULL;
703     }
704     for (i = 0; i < XkbNumKbdGroups; i++) {
705         if (from->groupNames[i] != XKB_ATOM_NONE) {
706             if ((merge != MERGE_AUGMENT) ||
707                 (into->groupNames[i] == XKB_ATOM_NONE))
708                 into->groupNames[i] = from->groupNames[i];
709         }
710     }
711
712     darray_foreach(keyi, from->keys) {
713         if (merge != MERGE_DEFAULT)
714             keyi->merge = merge;
715
716         if (!AddKeySymbols(into, keyi))
717             into->errorCount++;
718     }
719
720     list_foreach_safe(mm, next, &from->modMaps, entry) {
721         if (merge != MERGE_DEFAULT)
722             mm->merge = merge;
723         if (!AddModMapEntry(into, mm))
724             into->errorCount++;
725         free(mm);
726     }
727     list_init(&from->modMaps);
728 }
729
730 static void
731 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
732
733 static bool
734 HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
735 {
736     enum merge_mode merge = MERGE_DEFAULT;
737     XkbFile *rtrn;
738     SymbolsInfo included, next_incl;
739
740     InitSymbolsInfo(&included, info->keymap, info->file_id);
741     if (stmt->stmt) {
742         free(included.name);
743         included.name = stmt->stmt;
744         stmt->stmt = NULL;
745     }
746
747     for (; stmt; stmt = stmt->next) {
748         if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
749                                 &rtrn, &merge)) {
750             info->errorCount += 10;
751             FreeSymbolsInfo(&included);
752             return false;
753         }
754
755         InitSymbolsInfo(&next_incl, info->keymap, rtrn->id);
756         next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
757         if (stmt->modifier)
758             next_incl.explicit_group = atoi(stmt->modifier) - 1;
759         else
760             next_incl.explicit_group = info->explicit_group;
761
762         HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
763
764         MergeIncludedSymbols(&included, &next_incl, merge);
765
766         FreeSymbolsInfo(&next_incl);
767         FreeXKBFile(rtrn);
768     }
769
770     MergeIncludedSymbols(info, &included, merge);
771     FreeSymbolsInfo(&included);
772
773     return (info->errorCount == 0);
774 }
775
776 #define SYMBOLS 1
777 #define ACTIONS 2
778
779 static bool
780 GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
781               unsigned what, xkb_group_index_t *ndx_rtrn)
782 {
783     const char *name;
784     ExprResult tmp;
785
786     if (what == SYMBOLS)
787         name = "symbols";
788     else
789         name = "actions";
790
791     if (arrayNdx == NULL) {
792         xkb_group_index_t i;
793         unsigned defined;
794         if (what == SYMBOLS)
795             defined = keyi->symsDefined;
796         else
797             defined = keyi->actsDefined;
798
799         for (i = 0; i < XkbNumKbdGroups; i++) {
800             if ((defined & (1 << i)) == 0) {
801                 *ndx_rtrn = i;
802                 return true;
803             }
804         }
805         ERROR("Too many groups of %s for key %s (max %u)\n", name,
806               longText(keyi->name), XkbNumKbdGroups + 1);
807         ACTION("Ignoring %s defined for extra groups\n", name);
808         return false;
809     }
810     if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
811         ERROR("Illegal group index for %s of key %s\n", name,
812               longText(keyi->name));
813         ACTION("Definition with non-integer array index ignored\n");
814         return false;
815     }
816     *ndx_rtrn = tmp.uval - 1;
817     return true;
818 }
819
820 static bool
821 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
822                 ExprDef *value)
823 {
824     xkb_group_index_t ndx;
825     size_t nSyms, nLevels;
826     size_t i;
827     int j;
828
829     if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
830         return false;
831     if (value == NULL) {
832         keyi->symsDefined |= (1 << ndx);
833         return true;
834     }
835     if (value->op != ExprKeysymList) {
836         ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
837         ACTION("Ignoring symbols for group %u of %s\n", ndx + 1,
838                longText(keyi->name));
839         return false;
840     }
841     if (!darray_empty(keyi->syms[ndx])) {
842         ERROR("Symbols for key %s, group %u already defined\n",
843               longText(keyi->name), ndx + 1);
844         ACTION("Ignoring duplicate definition\n");
845         return false;
846     }
847     nSyms = darray_size(value->value.list.syms);
848     nLevels = darray_size(value->value.list.symsMapIndex);
849     if ((keyi->numLevels[ndx] < nSyms || darray_empty(keyi->syms[ndx])) &&
850         (!ResizeKeyGroup(keyi, ndx, nLevels, nSyms, false))) {
851         WSGO("Could not resize group %u of key %s to contain %zu levels\n",
852              ndx + 1, longText(keyi->name), nSyms);
853         ACTION("Symbols lost\n");
854         return false;
855     }
856     keyi->symsDefined |= (1 << ndx);
857     for (i = 0; i < nLevels; i++) {
858         darray_item(keyi->symsMapIndex[ndx], i) =
859             darray_item(value->value.list.symsMapIndex, i);
860         darray_item(keyi->symsMapNumEntries[ndx], i) =
861             darray_item(value->value.list.symsNumEntries, i);
862
863         for (j = 0; j < darray_item(keyi->symsMapNumEntries[ndx], i); j++) {
864             /* FIXME: What's abort() doing here? */
865             if (darray_item(keyi->symsMapIndex[ndx], i) + j >= nSyms)
866                 abort();
867             if (!LookupKeysym(darray_item(value->value.list.syms,
868                                           darray_item(value->value.list.symsMapIndex,
869                                                       i) + j),
870                               &darray_item(keyi->syms[ndx],
871                                            darray_item(keyi->symsMapIndex[ndx],
872                                                        i) + j))) {
873                 WARN(
874                     "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
875                     darray_item(value->value.list.syms, i),
876                     longText(keyi->name),
877                     ndx + 1,
878                     xkb_atom_text(info->keymap->ctx, info->groupNames[ndx]),
879                     nSyms);
880                 while (--j >= 0)
881                     darray_item(keyi->syms[ndx],
882                                 darray_item(keyi->symsMapIndex[ndx],
883                                             i) + j) = XKB_KEY_NoSymbol;
884                 darray_item(keyi->symsMapIndex[ndx], i) = -1;
885                 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
886                 break;
887             }
888             if (darray_item(keyi->symsMapNumEntries[ndx], i) == 1 &&
889                 darray_item(keyi->syms[ndx],
890                             darray_item(keyi->symsMapIndex[ndx],
891                                         i) + j) == XKB_KEY_NoSymbol) {
892                 darray_item(keyi->symsMapIndex[ndx], i) = -1;
893                 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
894             }
895         }
896     }
897     for (j = keyi->numLevels[ndx] - 1;
898          j >= 0 && darray_item(keyi->symsMapNumEntries[ndx], j) == 0; j--)
899         keyi->numLevels[ndx]--;
900     return true;
901 }
902
903 static bool
904 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
905                 ExprDef *value)
906 {
907     size_t i;
908     xkb_group_index_t ndx;
909     size_t nActs;
910     ExprDef *act;
911     struct xkb_any_action *toAct;
912
913     if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
914         return false;
915
916     if (value == NULL) {
917         keyi->actsDefined |= (1 << ndx);
918         return true;
919     }
920     if (value->op != ExprActionList) {
921         WSGO("Bad expression type (%d) for action list value\n", value->op);
922         ACTION("Ignoring actions for group %u of %s\n", ndx,
923                longText(keyi->name));
924         return false;
925     }
926     if (!darray_empty(keyi->acts[ndx])) {
927         WSGO("Actions for key %s, group %u already defined\n",
928               longText(keyi->name), ndx);
929         return false;
930     }
931     for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
932         act = (ExprDef *) act->common.next;
933     }
934     if (nActs < 1) {
935         WSGO("Action list but not actions in AddActionsToKey\n");
936         return false;
937     }
938     if ((keyi->numLevels[ndx] < nActs || darray_empty(keyi->acts[ndx])) &&
939         !ResizeKeyGroup(keyi, ndx, nActs, nActs, true)) {
940         WSGO("Could not resize group %u of key %s\n", ndx,
941               longText(keyi->name));
942         ACTION("Actions lost\n");
943         return false;
944     }
945     keyi->actsDefined |= (1 << ndx);
946
947     toAct = (struct xkb_any_action *) darray_mem(keyi->acts[ndx], 0);
948     act = value->value.child;
949     for (i = 0; i < nActs; i++, toAct++) {
950         if (!HandleActionDef(act, info->keymap, toAct, info->action)) {
951             ERROR("Illegal action definition for %s\n",
952                   longText(keyi->name));
953             ACTION("Action for group %u/level %zu ignored\n", ndx + 1, i + 1);
954         }
955         act = (ExprDef *) act->common.next;
956     }
957     return true;
958 }
959
960 static const LookupEntry lockingEntries[] = {
961     { "true", XkbKB_Lock },
962     { "yes", XkbKB_Lock },
963     { "on", XkbKB_Lock },
964     { "false", XkbKB_Default },
965     { "no", XkbKB_Default },
966     { "off", XkbKB_Default },
967     { "permanent", XkbKB_Lock | XkbKB_Permanent },
968     { NULL, 0 }
969 };
970
971 static const LookupEntry repeatEntries[] = {
972     { "true", RepeatYes },
973     { "yes", RepeatYes },
974     { "on", RepeatYes },
975     { "false", RepeatNo },
976     { "no", RepeatNo },
977     { "off", RepeatNo },
978     { "default", RepeatUndefined },
979     { NULL, 0 }
980 };
981
982 static bool
983 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, char *field,
984                 ExprDef *arrayNdx, ExprDef *value)
985 {
986     bool ok = true;
987     ExprResult tmp;
988     struct xkb_context *ctx = info->keymap->ctx;
989
990     if (strcasecmp(field, "type") == 0) {
991         ExprResult ndx;
992         if ((!ExprResolveString(ctx, value, &tmp))
993             && (warningLevel > 0)) {
994             WARN("The type field of a key symbol map must be a string\n");
995             ACTION("Ignoring illegal type definition\n");
996         }
997         if (arrayNdx == NULL) {
998             keyi->dfltType = xkb_atom_intern(ctx, tmp.str);
999             keyi->defined |= _Key_Type_Dflt;
1000         }
1001         else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1002             ERROR("Illegal group index for type of key %s\n",
1003                   longText(keyi->name));
1004             ACTION("Definition with non-integer array index ignored\n");
1005             free(tmp.str);
1006             return false;
1007         }
1008         else {
1009             keyi->types[ndx.uval - 1] = xkb_atom_intern(ctx, tmp.str);
1010             keyi->typesDefined |= (1 << (ndx.uval - 1));
1011         }
1012         free(tmp.str);
1013     }
1014     else if (strcasecmp(field, "symbols") == 0)
1015         return AddSymbolsToKey(info, keyi, arrayNdx, value);
1016     else if (strcasecmp(field, "actions") == 0)
1017         return AddActionsToKey(info, keyi, arrayNdx, value);
1018     else if ((strcasecmp(field, "vmods") == 0) ||
1019              (strcasecmp(field, "virtualmods") == 0) ||
1020              (strcasecmp(field, "virtualmodifiers") == 0)) {
1021         ok = ExprResolveVModMask(value, &tmp, info->keymap);
1022         if (ok) {
1023             keyi->vmodmap = (tmp.uval >> 8);
1024             keyi->defined |= _Key_VModMap;
1025         }
1026         else {
1027             ERROR("Expected a virtual modifier mask, found %s\n",
1028                   exprOpText(value->op));
1029             ACTION("Ignoring virtual modifiers definition for key %s\n",
1030                    longText(keyi->name));
1031         }
1032     }
1033     else if ((strcasecmp(field, "locking") == 0) ||
1034              (strcasecmp(field, "lock") == 0) ||
1035              (strcasecmp(field, "locks") == 0)) {
1036         ok = ExprResolveEnum(ctx, value, &tmp, lockingEntries);
1037         if (ok)
1038             keyi->behavior.type = tmp.uval;
1039         keyi->defined |= _Key_Behavior;
1040     }
1041     else if ((strcasecmp(field, "radiogroup") == 0) ||
1042              (strcasecmp(field, "permanentradiogroup") == 0) ||
1043              (strcasecmp(field, "allownone") == 0)) {
1044         ERROR("Radio groups not supported\n");
1045         ACTION("Ignoring radio group specification for key %s\n",
1046                longText(keyi->name));
1047         return false;
1048     }
1049     else if (uStrCasePrefix("overlay", field) ||
1050              uStrCasePrefix("permanentoverlay", field)) {
1051         ERROR("Overlays not supported\n");
1052         ACTION("Ignoring overlay specification for key %s\n",
1053                longText(keyi->name));
1054     }
1055     else if ((strcasecmp(field, "repeating") == 0) ||
1056              (strcasecmp(field, "repeats") == 0) ||
1057              (strcasecmp(field, "repeat") == 0)) {
1058         ok = ExprResolveEnum(ctx, value, &tmp, repeatEntries);
1059         if (!ok) {
1060             ERROR("Illegal repeat setting for %s\n",
1061                   longText(keyi->name));
1062             ACTION("Non-boolean repeat setting ignored\n");
1063             return false;
1064         }
1065         keyi->repeat = tmp.uval;
1066         keyi->defined |= _Key_Repeat;
1067     }
1068     else if ((strcasecmp(field, "groupswrap") == 0) ||
1069              (strcasecmp(field, "wrapgroups") == 0)) {
1070         ok = ExprResolveBoolean(ctx, value, &tmp);
1071         if (!ok) {
1072             ERROR("Illegal groupsWrap setting for %s\n",
1073                   longText(keyi->name));
1074             ACTION("Non-boolean value ignored\n");
1075             return false;
1076         }
1077         if (tmp.uval)
1078             keyi->out_of_range_group_action = XkbWrapIntoRange;
1079         else
1080             keyi->out_of_range_group_action = XkbClampIntoRange;
1081         keyi->defined |= _Key_GroupInfo;
1082     }
1083     else if ((strcasecmp(field, "groupsclamp") == 0) ||
1084              (strcasecmp(field, "clampgroups") == 0)) {
1085         ok = ExprResolveBoolean(ctx, value, &tmp);
1086         if (!ok) {
1087             ERROR("Illegal groupsClamp setting for %s\n",
1088                   longText(keyi->name));
1089             ACTION("Non-boolean value ignored\n");
1090             return false;
1091         }
1092         if (tmp.uval)
1093             keyi->out_of_range_group_action = XkbClampIntoRange;
1094         else
1095             keyi->out_of_range_group_action = XkbWrapIntoRange;
1096         keyi->defined |= _Key_GroupInfo;
1097     }
1098     else if ((strcasecmp(field, "groupsredirect") == 0) ||
1099              (strcasecmp(field, "redirectgroups") == 0)) {
1100         if (!ExprResolveGroup(ctx, value, &tmp)) {
1101             ERROR("Illegal group index for redirect of key %s\n",
1102                   longText(keyi->name));
1103             ACTION("Definition with non-integer group ignored\n");
1104             return false;
1105         }
1106         keyi->out_of_range_group_action = XkbRedirectIntoRange;
1107         keyi->out_of_range_group_number = tmp.uval - 1;
1108         keyi->defined |= _Key_GroupInfo;
1109     }
1110     else {
1111         ERROR("Unknown field %s in a symbol interpretation\n", field);
1112         ACTION("Definition ignored\n");
1113         ok = false;
1114     }
1115     return ok;
1116 }
1117
1118 static int
1119 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1120 {
1121     ExprResult tmp, name;
1122
1123     if ((arrayNdx == NULL) && (warningLevel > 0)) {
1124         WARN("You must specify an index when specifying a group name\n");
1125         ACTION("Group name definition without array subscript ignored\n");
1126         return false;
1127     }
1128     if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
1129         ERROR("Illegal index in group name definition\n");
1130         ACTION("Definition with non-integer array index ignored\n");
1131         return false;
1132     }
1133     if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1134         ERROR("Group name must be a string\n");
1135         ACTION("Illegal name for group %d ignored\n", tmp.uval);
1136         return false;
1137     }
1138     info->groupNames[tmp.uval - 1 + info->explicit_group] =
1139         xkb_atom_intern(info->keymap->ctx, name.str);
1140     free(name.str);
1141
1142     return true;
1143 }
1144
1145 static int
1146 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1147 {
1148     ExprResult elem, field;
1149     ExprDef *arrayNdx;
1150     bool ret;
1151
1152     if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field,
1153                        &arrayNdx) == 0)
1154         return 0;               /* internal error, already reported */
1155     if (elem.str && (strcasecmp(elem.str, "key") == 0)) {
1156         ret = SetSymbolsField(info, &info->dflt, field.str, arrayNdx,
1157                               stmt->value);
1158     }
1159     else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1160                                     (strcasecmp(field.str, "groupname") ==
1161                                      0))) {
1162         ret = SetGroupName(info, arrayNdx, stmt->value);
1163     }
1164     else if ((elem.str == NULL)
1165              && ((strcasecmp(field.str, "groupswrap") == 0) ||
1166                  (strcasecmp(field.str, "wrapgroups") == 0))) {
1167         ERROR("Global \"groupswrap\" not supported\n");
1168         ACTION("Ignored\n");
1169         ret = true;
1170     }
1171     else if ((elem.str == NULL)
1172              && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1173                  (strcasecmp(field.str, "clampgroups") == 0))) {
1174         ERROR("Global \"groupsclamp\" not supported\n");
1175         ACTION("Ignored\n");
1176         ret = true;
1177     }
1178     else if ((elem.str == NULL)
1179              && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1180                  (strcasecmp(field.str, "redirectgroups") == 0))) {
1181         ERROR("Global \"groupsredirect\" not supported\n");
1182         ACTION("Ignored\n");
1183         ret = true;
1184     }
1185     else if ((elem.str == NULL) &&
1186              (strcasecmp(field.str, "allownone") == 0)) {
1187         ERROR("Radio groups not supported\n");
1188         ACTION("Ignoring \"allownone\" specification\n");
1189         ret = true;
1190     }
1191     else {
1192         ret = SetActionField(info->keymap, elem.str, field.str, arrayNdx,
1193                              stmt->value, &info->action);
1194     }
1195
1196     free(elem.str);
1197     free(field.str);
1198     return ret;
1199 }
1200
1201 static bool
1202 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1203 {
1204     bool ok = true;
1205     ExprResult tmp, field;
1206     ExprDef *arrayNdx;
1207
1208     for (; def != NULL; def = (VarDef *) def->common.next) {
1209         if ((def->name) && (def->name->type == ExprFieldRef)) {
1210             ok = HandleSymbolsVar(info, def);
1211             continue;
1212         }
1213         else {
1214             if (def->name == NULL) {
1215                 if ((def->value == NULL)
1216                     || (def->value->op == ExprKeysymList))
1217                     field.str = strdup("symbols");
1218                 else
1219                     field.str = strdup("actions");
1220                 arrayNdx = NULL;
1221             }
1222             else {
1223                 ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field,
1224                                     &arrayNdx);
1225             }
1226             if (ok)
1227                 ok = SetSymbolsField(info, keyi, field.str, arrayNdx,
1228                                      def->value);
1229             free(field.str);
1230         }
1231     }
1232     return ok;
1233 }
1234
1235 static bool
1236 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1237 {
1238     xkb_group_index_t group = info->explicit_group;
1239
1240     if (group == 0)
1241         return true;
1242
1243     if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
1244         xkb_group_index_t i;
1245         WARN("For the map %s an explicit group specified\n", info->name);
1246         WARN("but key %s has more than one group defined\n",
1247              longText(keyi->name));
1248         ACTION("All groups except first one will be ignored\n");
1249         for (i = 1; i < XkbNumKbdGroups; i++) {
1250             keyi->numLevels[i] = 0;
1251             darray_free(keyi->syms[i]);
1252             darray_free(keyi->acts[i]);
1253             keyi->types[i] = 0;
1254         }
1255     }
1256     keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 1 << group;
1257
1258     keyi->numLevels[group] = keyi->numLevels[0];
1259     keyi->numLevels[0] = 0;
1260     keyi->syms[group] = keyi->syms[0];
1261     darray_init(keyi->syms[0]);
1262     keyi->symsMapIndex[group] = keyi->symsMapIndex[0];
1263     darray_init(keyi->symsMapIndex[0]);
1264     keyi->symsMapNumEntries[group] = keyi->symsMapNumEntries[0];
1265     darray_init(keyi->symsMapNumEntries[0]);
1266     keyi->acts[group] = keyi->acts[0];
1267     darray_init(keyi->acts[0]);
1268     keyi->types[group] = keyi->types[0];
1269     keyi->types[0] = 0;
1270     return true;
1271 }
1272
1273 static int
1274 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1275 {
1276     KeyInfo keyi;
1277
1278     InitKeyInfo(&keyi, info->file_id);
1279     CopyKeyInfo(&info->dflt, &keyi, false);
1280     keyi.merge = stmt->merge;
1281     keyi.name = KeyNameToLong(stmt->keyName);
1282     if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1283         info->errorCount++;
1284         return false;
1285     }
1286
1287     if (!SetExplicitGroup(info, &keyi)) {
1288         info->errorCount++;
1289         return false;
1290     }
1291
1292     if (!AddKeySymbols(info, &keyi)) {
1293         info->errorCount++;
1294         return false;
1295     }
1296     return true;
1297 }
1298
1299 static bool
1300 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1301 {
1302     ExprDef *key;
1303     ModMapEntry tmp;
1304     ExprResult rtrn;
1305     bool ok;
1306     struct xkb_context *ctx = info->keymap->ctx;
1307
1308     if (!LookupModIndex(ctx, NULL, def->modifier, TypeInt, &rtrn)) {
1309         ERROR("Illegal modifier map definition\n");
1310         ACTION("Ignoring map for non-modifier \"%s\"\n",
1311                xkb_atom_text(ctx, def->modifier));
1312         return false;
1313     }
1314     ok = true;
1315     tmp.modifier = rtrn.uval;
1316     for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1317         if ((key->op == ExprValue) && (key->type == TypeKeyName)) {
1318             tmp.haveSymbol = false;
1319             tmp.u.keyName = KeyNameToLong(key->value.keyName);
1320         }
1321         else if (ExprResolveKeySym(ctx, key, &rtrn)) {
1322             tmp.haveSymbol = true;
1323             tmp.u.keySym = rtrn.uval;
1324         }
1325         else {
1326             ERROR("Modmap entries may contain only key names or keysyms\n");
1327             ACTION("Illegal definition for %s modifier ignored\n",
1328                    XkbcModIndexText(tmp.modifier));
1329             continue;
1330         }
1331
1332         ok = AddModMapEntry(info, &tmp) && ok;
1333     }
1334     return ok;
1335 }
1336
1337 static void
1338 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1339 {
1340     ParseCommon *stmt;
1341
1342     free(info->name);
1343     info->name = uDupString(file->name);
1344     stmt = file->defs;
1345     while (stmt)
1346     {
1347         switch (stmt->stmtType) {
1348         case StmtInclude:
1349             if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt))
1350                 info->errorCount++;
1351             break;
1352         case StmtSymbolsDef:
1353             if (!HandleSymbolsDef(info, (SymbolsDef *) stmt))
1354                 info->errorCount++;
1355             break;
1356         case StmtVarDef:
1357             if (!HandleSymbolsVar(info, (VarDef *) stmt))
1358                 info->errorCount++;
1359             break;
1360         case StmtVModDef:
1361             if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
1362                                &info->vmods))
1363                 info->errorCount++;
1364             break;
1365         case StmtInterpDef:
1366             ERROR("Interpretation files may not include other types\n");
1367             ACTION("Ignoring definition of symbol interpretation\n");
1368             info->errorCount++;
1369             break;
1370         case StmtKeycodeDef:
1371             ERROR("Interpretation files may not include other types\n");
1372             ACTION("Ignoring definition of key name\n");
1373             info->errorCount++;
1374             break;
1375         case StmtModMapDef:
1376             if (!HandleModMapDef(info, (ModMapDef *) stmt))
1377                 info->errorCount++;
1378             break;
1379         default:
1380             WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1381                  stmt->stmtType);
1382             break;
1383         }
1384         stmt = stmt->next;
1385         if (info->errorCount > 10) {
1386             ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1387             break;
1388         }
1389     }
1390 }
1391
1392 /**
1393  * Given a keysym @sym, return a key which generates it, or NULL.
1394  * This is used for example in a modifier map definition, such as:
1395  *      modifier_map Lock           { Caps_Lock };
1396  * where we want to add the Lock modifier to the modmap of the key
1397  * which matches the keysym Caps_Lock.
1398  * Since there can be many keys which generates the keysym, the key
1399  * is chosen first by lowest group in which the keysym appears, than
1400  * by lowest level and than by lowest key code.
1401  */
1402 static struct xkb_key *
1403 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1404 {
1405     struct xkb_key *key, *ret = NULL;
1406     xkb_group_index_t group, min_group = UINT_MAX;
1407     unsigned int level, min_level = UINT_MAX;
1408
1409     xkb_foreach_key(key, keymap) {
1410         for (group = 0; group < key->num_groups; group++) {
1411             for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1412                  level++) {
1413                 if (XkbKeyNumSyms(key, group, level) != 1 ||
1414                     (XkbKeySymEntry(key, group, level))[0] != sym)
1415                     continue;
1416
1417                 /*
1418                  * If the keysym was found in a group or level > 0, we must
1419                  * keep looking since we might find a key in which the keysym
1420                  * is in a lower group or level.
1421                  */
1422                 if (group < min_group ||
1423                     (group == min_group && level < min_level)) {
1424                     ret = key;
1425                     if (group == 0 && level == 0) {
1426                         return ret;
1427                     }
1428                     else {
1429                         min_group = group;
1430                         min_level = level;
1431                     }
1432                 }
1433             }
1434         }
1435     }
1436
1437     return ret;
1438 }
1439
1440 /**
1441  * Find the given name in the keymap->map->types and return its index.
1442  *
1443  * @param atom The atom to search for.
1444  * @param type_rtrn Set to the index of the name if found.
1445  *
1446  * @return true if found, false otherwise.
1447  */
1448 static bool
1449 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
1450 {
1451     unsigned n = 0;
1452     const char *name = xkb_atom_text(keymap->ctx, atom);
1453     struct xkb_key_type *type;
1454
1455     if (keymap) {
1456         darray_foreach(type, keymap->types) {
1457             if (strcmp(type->name, name) == 0) {
1458                 *type_rtrn = n;
1459                 return true;
1460             }
1461             n++;
1462         }
1463     }
1464     return false;
1465 }
1466
1467 /**
1468  * Assign a type to the given sym and return the Atom for the type assigned.
1469  *
1470  * Simple recipe:
1471  * - ONE_LEVEL for width 0/1
1472  * - ALPHABETIC for 2 shift levels, with lower/upercase
1473  * - KEYPAD for keypad keys.
1474  * - TWO_LEVEL for other 2 shift level keys.
1475  * and the same for four level keys.
1476  *
1477  * @param width Number of sysms in syms.
1478  * @param syms The keysyms for the given key (must be size width).
1479  * @param typeNameRtrn Set to the Atom of the type name.
1480  *
1481  * @returns true if a type could be found, false otherwise.
1482  *
1483  * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1484  *        all that fun stuff rather than just assuming there's always one
1485  *        symbol per level.
1486  */
1487 static bool
1488 FindAutomaticType(struct xkb_keymap *keymap, int width,
1489                   const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1490                   bool *autoType)
1491 {
1492     *autoType = false;
1493     if ((width == 1) || (width == 0)) {
1494         *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1495         *autoType = true;
1496     }
1497     else if (width == 2) {
1498         if (syms && xkb_keysym_is_lower(syms[0]) &&
1499             xkb_keysym_is_upper(syms[1])) {
1500             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1501         }
1502         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1503                           xkb_keysym_is_keypad(syms[1]))) {
1504             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1505             *autoType = true;
1506         }
1507         else {
1508             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1509             *autoType = true;
1510         }
1511     }
1512     else if (width <= 4) {
1513         if (syms && xkb_keysym_is_lower(syms[0]) &&
1514             xkb_keysym_is_upper(syms[1]))
1515             if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1516                 *typeNameRtrn =
1517                     xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1518             else
1519                 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1520                                                 "FOUR_LEVEL_SEMIALPHABETIC");
1521
1522         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1523                           xkb_keysym_is_keypad(syms[1])))
1524             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1525         else
1526             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1527         /* XXX: why not set autoType here? */
1528     }
1529     return ((width >= 0) && (width <= 4));
1530 }
1531
1532 /**
1533  * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1534  * groups, and reduce to one group if all groups are identical anyway.
1535  */
1536 static void
1537 PrepareKeyDef(KeyInfo *keyi)
1538 {
1539     xkb_group_index_t i, lastGroup;
1540     int j, width, defined;
1541     bool identical;
1542
1543     defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
1544     /* get highest group number */
1545     for (i = XkbNumKbdGroups - 1; i > 0; i--) {
1546         if (defined & (1 << i))
1547             break;
1548     }
1549     lastGroup = i;
1550
1551     if (lastGroup == 0)
1552         return;
1553
1554     /* If there are empty groups between non-empty ones fill them with data */
1555     /* from the first group. */
1556     /* We can make a wrong assumption here. But leaving gaps is worse. */
1557     for (i = lastGroup; i > 0; i--) {
1558         if (defined & (1 << i))
1559             continue;
1560         width = keyi->numLevels[0];
1561         if (keyi->typesDefined & 1) {
1562             for (j = 0; j < width; j++) {
1563                 keyi->types[i] = keyi->types[0];
1564             }
1565             keyi->typesDefined |= 1 << i;
1566         }
1567         if ((keyi->actsDefined & 1) && !darray_empty(keyi->acts[0])) {
1568             darray_copy(keyi->acts[i], keyi->acts[0]);
1569             keyi->actsDefined |= 1 << i;
1570         }
1571         if ((keyi->symsDefined & 1) && !darray_empty(keyi->syms[0])) {
1572             darray_copy(keyi->syms[i], keyi->syms[0]);
1573             darray_copy(keyi->symsMapIndex[i], keyi->symsMapIndex[0]);
1574             darray_copy(keyi->symsMapNumEntries[i],
1575                         keyi->symsMapNumEntries[0]);
1576             keyi->symsDefined |= 1 << i;
1577         }
1578         if (defined & 1) {
1579             keyi->numLevels[i] = keyi->numLevels[0];
1580         }
1581     }
1582     /* If all groups are completely identical remove them all */
1583     /* exept the first one. */
1584     identical = true;
1585     for (i = lastGroup; i > 0; i--) {
1586         if ((keyi->numLevels[i] != keyi->numLevels[0]) ||
1587             (keyi->types[i] != keyi->types[0])) {
1588             identical = false;
1589             break;
1590         }
1591         if (!darray_same(keyi->syms[i], keyi->syms[0]) &&
1592             (darray_empty(keyi->syms[i]) || darray_empty(keyi->syms[0]) ||
1593              darray_size(keyi->syms[i]) != darray_size(keyi->syms[0]) ||
1594              memcmp(darray_mem(keyi->syms[i], 0),
1595                     darray_mem(keyi->syms[0], 0),
1596                    sizeof(xkb_keysym_t) * darray_size(keyi->syms[0])))) {
1597             identical = false;
1598             break;
1599         }
1600         if (!darray_same(keyi->symsMapIndex[i], keyi->symsMapIndex[0]) &&
1601             (darray_empty(keyi->symsMapIndex[i]) ||
1602              darray_empty(keyi->symsMapIndex[0]) ||
1603              memcmp(darray_mem(keyi->symsMapIndex[i], 0),
1604                     darray_mem(keyi->symsMapIndex[0], 0),
1605                     keyi->numLevels[0] * sizeof(int)))) {
1606             identical = false;
1607             continue;
1608         }
1609         if (!darray_same(keyi->symsMapNumEntries[i],
1610                          keyi->symsMapNumEntries[0]) &&
1611             (darray_empty(keyi->symsMapNumEntries[i]) ||
1612              darray_empty(keyi->symsMapNumEntries[0]) ||
1613              memcmp(darray_mem(keyi->symsMapNumEntries[i], 0),
1614                     darray_mem(keyi->symsMapNumEntries[0], 0),
1615                     keyi->numLevels[0] * sizeof(size_t)))) {
1616             identical = false;
1617             continue;
1618         }
1619         if (!darray_same(keyi->acts[i], keyi->acts[0]) &&
1620             (darray_empty(keyi->acts[i]) || darray_empty(keyi->acts[0]) ||
1621              memcmp(darray_mem(keyi->acts[i], 0),
1622                     darray_mem(keyi->acts[0], 0),
1623                     keyi->numLevels[0] * sizeof(union xkb_action)))) {
1624             identical = false;
1625             break;
1626         }
1627     }
1628     if (identical) {
1629         for (i = lastGroup; i > 0; i--) {
1630             keyi->numLevels[i] = 0;
1631             darray_free(keyi->syms[i]);
1632             darray_free(keyi->symsMapIndex[i]);
1633             darray_free(keyi->symsMapNumEntries[i]);
1634             darray_free(keyi->acts[i]);
1635             keyi->types[i] = 0;
1636         }
1637         keyi->symsDefined &= 1;
1638         keyi->actsDefined &= 1;
1639         keyi->typesDefined &= 1;
1640     }
1641 }
1642
1643 /**
1644  * Copy the KeyInfo into the keyboard description.
1645  *
1646  * This function recurses.
1647  */
1648 static bool
1649 CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi,
1650                xkb_keycode_t start_from)
1651 {
1652     xkb_keycode_t kc;
1653     struct xkb_key *key;
1654     size_t sizeSyms = 0;
1655     xkb_group_index_t i, nGroups;
1656     unsigned width, tmp;
1657     struct xkb_key_type * type;
1658     bool haveActions, autoType, useAlias;
1659     unsigned types[XkbNumKbdGroups];
1660     union xkb_action *outActs;
1661     unsigned int symIndex = 0;
1662
1663     useAlias = (start_from == 0);
1664
1665     key = FindNamedKey(keymap, keyi->name, useAlias,
1666                        CreateKeyNames(keymap), start_from);
1667     if (!key) {
1668         if (start_from == 0 && warningLevel >= 5) {
1669             WARN("Key %s not found in keycodes\n", longText(keyi->name));
1670             ACTION("Symbols ignored\n");
1671         }
1672         return false;
1673     }
1674     kc = XkbKeyGetKeycode(keymap, key);
1675
1676     haveActions = false;
1677     width = 0;
1678     for (i = nGroups = 0; i < XkbNumKbdGroups; i++) {
1679         if (((i + 1) > nGroups)
1680             && (((keyi->symsDefined | keyi->actsDefined) & (1 << i))
1681                 || (keyi->typesDefined) & (1 << i)))
1682             nGroups = i + 1;
1683         if (!darray_empty(keyi->acts[i]))
1684             haveActions = true;
1685         autoType = false;
1686         /* Assign the type to the key, if it is missing. */
1687         if (keyi->types[i] == XKB_ATOM_NONE) {
1688             if (keyi->dfltType != XKB_ATOM_NONE)
1689                 keyi->types[i] = keyi->dfltType;
1690             else if (FindAutomaticType(keymap, keyi->numLevels[i],
1691                                        darray_mem(keyi->syms[i], 0),
1692                                        &keyi->types[i], &autoType)) { }
1693             else {
1694                 if (warningLevel >= 5) {
1695                     WARN("No automatic type for %d symbols\n",
1696                           keyi->numLevels[i]);
1697                     ACTION("Using %s for the %s key (keycode %d)\n",
1698                             xkb_atom_text(keymap->ctx, keyi->types[i]),
1699                             longText(keyi->name), kc);
1700                 }
1701             }
1702         }
1703         if (FindNamedType(keymap, keyi->types[i], &types[i])) {
1704             if (!autoType || keyi->numLevels[i] > 2)
1705                 key->explicit |= (1 << i);
1706         }
1707         else {
1708             if (warningLevel >= 3) {
1709                 WARN("Type \"%s\" is not defined\n",
1710                      xkb_atom_text(keymap->ctx, keyi->types[i]));
1711                 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1712                        longText(keyi->name), kc);
1713             }
1714             types[i] = XkbTwoLevelIndex;
1715         }
1716         /* if the type specifies fewer levels than the key has, shrink the key */
1717         type = &darray_item(keymap->types, types[i]);
1718         if (type->num_levels < keyi->numLevels[i]) {
1719             if (warningLevel > 0) {
1720                 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
1721                      type->name, type->num_levels,
1722                      xkb_atom_text(keymap->ctx, keyi->name), keyi->numLevels[i]);
1723                 ACTION("Ignoring extra symbols\n");
1724             }
1725             keyi->numLevels[i] = type->num_levels;
1726         }
1727         if (keyi->numLevels[i] > width)
1728             width = keyi->numLevels[i];
1729         if (type->num_levels > width)
1730             width = type->num_levels;
1731         sizeSyms += darray_size(keyi->syms[i]);
1732     }
1733
1734     darray_resize0(key->syms, sizeSyms);
1735
1736     if (haveActions) {
1737         outActs = XkbcResizeKeyActions(keymap, key, width * nGroups);
1738         if (outActs == NULL) {
1739             WSGO("Could not enlarge actions for %s (key %d)\n",
1740                  longText(keyi->name), kc);
1741             return false;
1742         }
1743         key->explicit |= XkbExplicitInterpretMask;
1744     }
1745     else
1746         outActs = NULL;
1747
1748     key->num_groups = nGroups;
1749     if (keyi->defined & _Key_GroupInfo) {
1750         key->out_of_range_group_number = keyi->out_of_range_group_number;
1751         key->out_of_range_group_action = keyi->out_of_range_group_action;
1752     }
1753     key->width = width;
1754     key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1755     key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1756
1757     for (i = 0; i < nGroups; i++) {
1758         /* assign kt_index[i] to the index of the type in map->types.
1759          * kt_index[i] may have been set by a previous run (if we have two
1760          * layouts specified). Let's not overwrite it with the ONE_LEVEL
1761          * default group if we dont even have keys for this group anyway.
1762          *
1763          * FIXME: There should be a better fix for this.
1764          */
1765         if (keyi->numLevels[i])
1766             key->kt_index[i] = types[i];
1767         if (!darray_empty(keyi->syms[i])) {
1768             /* fill key to "width" symbols*/
1769             for (tmp = 0; tmp < width; tmp++) {
1770                 if (tmp < keyi->numLevels[i] &&
1771                     darray_item(keyi->symsMapNumEntries[i], tmp) != 0) {
1772                     memcpy(darray_mem(key->syms, symIndex),
1773                            darray_mem(keyi->syms[i],
1774                                       darray_item(keyi->symsMapIndex[i], tmp)),
1775                            darray_item(keyi->symsMapNumEntries[i],
1776                                        tmp) * sizeof(xkb_keysym_t));
1777                     key->sym_index[(i * width) + tmp] = symIndex;
1778                     key->num_syms[(i * width) + tmp] =
1779                         darray_item(keyi->symsMapNumEntries[i], tmp);
1780                     symIndex += key->num_syms[(i * width) + tmp];
1781                 }
1782                 else {
1783                     key->sym_index[(i * width) + tmp] = -1;
1784                     key->num_syms[(i * width) + tmp] = 0;
1785                 }
1786                 if (outActs != NULL && !darray_empty(keyi->acts[i])) {
1787                     if (tmp < keyi->numLevels[i])
1788                         outActs[tmp] = darray_item(keyi->acts[i], tmp);
1789                     else
1790                         outActs[tmp].type = XkbSA_NoAction;
1791                 }
1792             }
1793         }
1794     }
1795     switch (keyi->behavior.type & XkbKB_OpMask) {
1796     case XkbKB_Default:
1797         break;
1798
1799     default:
1800         key->behavior = keyi->behavior;
1801         key->explicit |= XkbExplicitBehaviorMask;
1802         break;
1803     }
1804     if (keyi->defined & _Key_VModMap) {
1805         key->vmodmap = keyi->vmodmap;
1806         key->explicit |= XkbExplicitVModMapMask;
1807     }
1808     if (keyi->repeat != RepeatUndefined) {
1809         key->repeats = keyi->repeat == RepeatYes;
1810         key->explicit |= XkbExplicitAutoRepeatMask;
1811     }
1812
1813     /* do the same thing for the next key */
1814     CopySymbolsDef(keymap, keyi, kc + 1);
1815     return true;
1816 }
1817
1818 static bool
1819 CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
1820 {
1821     struct xkb_key *key;
1822
1823     if (!entry->haveSymbol) {
1824         key = FindNamedKey(keymap, entry->u.keyName, true,
1825                            CreateKeyNames(keymap), 0);
1826         if (!key) {
1827             if (warningLevel >= 5) {
1828                 WARN("Key %s not found in keycodes\n",
1829                      longText(entry->u.keyName));
1830                 ACTION("Modifier map entry for %s not updated\n",
1831                        XkbcModIndexText(entry->modifier));
1832             }
1833             return false;
1834         }
1835     }
1836     else {
1837         key = FindKeyForSymbol(keymap, entry->u.keySym);
1838         if (!key) {
1839             if (warningLevel > 5) {
1840                 WARN("Key \"%s\" not found in symbol map\n",
1841                      XkbcKeysymText(entry->u.keySym));
1842                 ACTION("Modifier map entry for %s not updated\n",
1843                        XkbcModIndexText(entry->modifier));
1844             }
1845             return false;
1846         }
1847     }
1848
1849     key->modmap |= (1 << entry->modifier);
1850     return true;
1851 }
1852
1853 /**
1854  * Handle the xkb_symbols section of an xkb file.
1855  *
1856  * @param file The parsed xkb_symbols section of the xkb file.
1857  * @param keymap Handle to the keyboard description to store the symbols in.
1858  * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1859  */
1860 bool
1861 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1862                enum merge_mode merge)
1863 {
1864     xkb_group_index_t i;
1865     struct xkb_key *key;
1866     SymbolsInfo info;
1867     KeyInfo *keyi;
1868     ModMapEntry *mm;
1869
1870     InitSymbolsInfo(&info, keymap, file->id);
1871     info.dflt.merge = merge;
1872
1873     HandleSymbolsFile(&info, file, merge);
1874
1875     if (darray_empty(info.keys))
1876         goto err_info;
1877
1878     if (info.errorCount != 0)
1879         goto err_info;
1880
1881     darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1);
1882
1883     if (info.name)
1884         keymap->symbols_section_name = strdup(info.name);
1885
1886     for (i = 0; i < XkbNumKbdGroups; i++) {
1887         if (info.groupNames[i] != XKB_ATOM_NONE) {
1888             free(keymap->group_names[i]);
1889             keymap->group_names[i] = xkb_atom_strdup(keymap->ctx,
1890                                                      info.groupNames[i]);
1891         }
1892     }
1893
1894     /* sanitize keys */
1895     darray_foreach(keyi, info.keys)
1896         PrepareKeyDef(keyi);
1897
1898     /* copy! */
1899     darray_foreach(keyi, info.keys)
1900         if (!CopySymbolsDef(keymap, keyi, 0))
1901             info.errorCount++;
1902
1903     if (warningLevel > 3) {
1904         xkb_foreach_key(key, keymap) {
1905             if (key->name[0] == '\0')
1906                 continue;
1907
1908             if (key->num_groups < 1)
1909                 WARN("No symbols defined for <%.4s> (keycode %d)\n",
1910                      key->name, XkbKeyGetKeycode(keymap, key));
1911         }
1912     }
1913
1914     list_foreach(mm, &info.modMaps, entry)
1915         if (!CopyModMapDef(keymap, mm))
1916             info.errorCount++;
1917
1918     FreeSymbolsInfo(&info);
1919     return true;
1920
1921 err_info:
1922     FreeSymbolsInfo(&info);
1923     return false;
1924 }