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