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