17412465b2f15c9462b3b278f659595d13a1b47f
[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 ClearKeyInfo(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 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 < XkbNumKbdGroups; 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 < XkbNumKbdGroups; 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 < XkbNumKbdGroups; 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);
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);
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 < XkbNumKbdGroups; 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), XkbNumKbdGroups + 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->action)) {
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         const char *str;
1034
1035         if (!ExprResolveString(ctx, value, &str))
1036             log_lvl(info->keymap->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 = xkb_atom_intern(ctx, str);
1042             keyi->defined |= KEY_FIELD_TYPE_DFLT;
1043         }
1044         else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1045             log_err(info->keymap->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] = xkb_atom_intern(ctx, str);
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     const char *name;
1188
1189     if (!arrayNdx) {
1190         log_lvl(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] =
1211         xkb_atom_intern(info->keymap->ctx, name);
1212
1213     return true;
1214 }
1215
1216 static int
1217 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1218 {
1219     const char *elem, *field;
1220     ExprDef *arrayNdx;
1221     bool ret;
1222
1223     if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
1224                        &arrayNdx) == 0)
1225         return 0;               /* internal error, already reported */
1226     if (elem && istreq(elem, "key")) {
1227         ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
1228                               stmt->value);
1229     }
1230     else if (!elem && (istreq(field, "name") ||
1231                        istreq(field, "groupname"))) {
1232         ret = SetGroupName(info, arrayNdx, stmt->value);
1233     }
1234     else if (!elem && (istreq(field, "groupswrap") ||
1235                        istreq(field, "wrapgroups"))) {
1236         log_err(info->keymap->ctx,
1237                 "Global \"groupswrap\" not supported; Ignored\n");
1238         ret = true;
1239     }
1240     else if (!elem && (istreq(field, "groupsclamp") ||
1241                        istreq(field, "clampgroups"))) {
1242         log_err(info->keymap->ctx,
1243                 "Global \"groupsclamp\" not supported; Ignored\n");
1244         ret = true;
1245     }
1246     else if (!elem && (istreq(field, "groupsredirect") ||
1247                        istreq(field, "redirectgroups"))) {
1248         log_err(info->keymap->ctx,
1249                 "Global \"groupsredirect\" not supported; Ignored\n");
1250         ret = true;
1251     }
1252     else if (!elem && istreq(field, "allownone")) {
1253         log_err(info->keymap->ctx,
1254                 "Radio groups not supported; "
1255                 "Ignoring \"allownone\" specification\n");
1256         ret = true;
1257     }
1258     else {
1259         ret = SetActionField(info->keymap, elem, field, arrayNdx,
1260                              stmt->value, &info->action);
1261     }
1262
1263     return ret;
1264 }
1265
1266 static bool
1267 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1268 {
1269     bool ok = true;
1270     const char *elem, *field;
1271     ExprDef *arrayNdx;
1272
1273     for (; def; def = (VarDef *) def->common.next) {
1274         if (def->name && def->name->op == EXPR_FIELD_REF) {
1275             ok = HandleSymbolsVar(info, def);
1276             continue;
1277         }
1278
1279         if (!def->name) {
1280             if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
1281                 field = "symbols";
1282             else
1283                 field = "actions";
1284             arrayNdx = NULL;
1285         }
1286         else {
1287             ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
1288                                 &arrayNdx);
1289         }
1290
1291         if (ok)
1292             ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value);
1293     }
1294
1295     return ok;
1296 }
1297
1298 static bool
1299 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1300 {
1301     xkb_group_index_t group = info->explicit_group;
1302
1303     if (group == 0)
1304         return true;
1305
1306     if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
1307         xkb_group_index_t i;
1308         log_warn(info->keymap->ctx,
1309                  "For the map %s an explicit group specified, "
1310                  "but key %s has more than one group defined; "
1311                  "All groups except first one will be ignored\n",
1312                  info->name, LongKeyNameText(keyi->name));
1313         for (i = 1; i < XkbNumKbdGroups; i++) {
1314             keyi->numLevels[i] = 0;
1315             darray_free(keyi->syms[i]);
1316             darray_free(keyi->acts[i]);
1317             keyi->types[i] = 0;
1318         }
1319     }
1320     keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 1 << group;
1321
1322     keyi->numLevels[group] = keyi->numLevels[0];
1323     keyi->numLevels[0] = 0;
1324     keyi->syms[group] = keyi->syms[0];
1325     darray_init(keyi->syms[0]);
1326     keyi->symsMapIndex[group] = keyi->symsMapIndex[0];
1327     darray_init(keyi->symsMapIndex[0]);
1328     keyi->symsMapNumEntries[group] = keyi->symsMapNumEntries[0];
1329     darray_init(keyi->symsMapNumEntries[0]);
1330     keyi->acts[group] = keyi->acts[0];
1331     darray_init(keyi->acts[0]);
1332     keyi->types[group] = keyi->types[0];
1333     keyi->types[0] = 0;
1334     return true;
1335 }
1336
1337 static int
1338 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1339 {
1340     KeyInfo keyi;
1341
1342     InitKeyInfo(&keyi, info->file_id);
1343     CopyKeyInfo(&info->dflt, &keyi, false);
1344     keyi.merge = stmt->merge;
1345     keyi.name = KeyNameToLong(stmt->keyName);
1346     if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1347         info->errorCount++;
1348         return false;
1349     }
1350
1351     if (!SetExplicitGroup(info, &keyi)) {
1352         info->errorCount++;
1353         return false;
1354     }
1355
1356     if (!AddKeySymbols(info, &keyi)) {
1357         info->errorCount++;
1358         return false;
1359     }
1360     return true;
1361 }
1362
1363 static bool
1364 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1365 {
1366     ExprDef *key;
1367     ModMapEntry tmp;
1368     xkb_mod_index_t ndx;
1369     bool ok;
1370     struct xkb_context *ctx = info->keymap->ctx;
1371
1372     if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
1373         log_err(info->keymap->ctx,
1374                 "Illegal modifier map definition; "
1375                 "Ignoring map for non-modifier \"%s\"\n",
1376                 xkb_atom_text(ctx, def->modifier));
1377         return false;
1378     }
1379
1380     ok = true;
1381     tmp.modifier = ndx;
1382
1383     for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1384         xkb_keysym_t sym;
1385
1386         if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
1387             tmp.haveSymbol = false;
1388             tmp.u.keyName = KeyNameToLong(key->value.keyName);
1389         }
1390         else if (ExprResolveKeySym(ctx, key, &sym)) {
1391             tmp.haveSymbol = true;
1392             tmp.u.keySym = sym;
1393         }
1394         else {
1395             log_err(info->keymap->ctx,
1396                     "Modmap entries may contain only key names or keysyms; "
1397                     "Illegal definition for %s modifier ignored\n",
1398                     ModIndexText(tmp.modifier));
1399             continue;
1400         }
1401
1402         ok = AddModMapEntry(info, &tmp) && ok;
1403     }
1404     return ok;
1405 }
1406
1407 static void
1408 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1409 {
1410     bool ok;
1411     ParseCommon *stmt;
1412
1413     free(info->name);
1414     info->name = strdup_safe(file->name);
1415
1416     stmt = file->defs;
1417     for (stmt = file->defs; stmt; stmt = stmt->next) {
1418         switch (stmt->type) {
1419         case STMT_INCLUDE:
1420             ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
1421             break;
1422         case STMT_SYMBOLS:
1423             ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
1424             break;
1425         case STMT_VAR:
1426             ok = HandleSymbolsVar(info, (VarDef *) stmt);
1427             break;
1428         case STMT_VMOD:
1429             ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1430                                &info->vmods);
1431             break;
1432         case STMT_MODMAP:
1433             ok = HandleModMapDef(info, (ModMapDef *) stmt);
1434             break;
1435         default:
1436             log_err(info->keymap->ctx,
1437                     "Interpretation files may not include other types; "
1438                     "Ignoring %s\n", stmt_type_to_string(stmt->type));
1439             ok = false;
1440             break;
1441         }
1442
1443         if (!ok)
1444             info->errorCount++;
1445
1446         if (info->errorCount > 10) {
1447             log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1448                     file->topName);
1449             break;
1450         }
1451     }
1452 }
1453
1454 /**
1455  * Given a keysym @sym, return a key which generates it, or NULL.
1456  * This is used for example in a modifier map definition, such as:
1457  *      modifier_map Lock           { Caps_Lock };
1458  * where we want to add the Lock modifier to the modmap of the key
1459  * which matches the keysym Caps_Lock.
1460  * Since there can be many keys which generates the keysym, the key
1461  * is chosen first by lowest group in which the keysym appears, than
1462  * by lowest level and than by lowest key code.
1463  */
1464 static struct xkb_key *
1465 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1466 {
1467     struct xkb_key *key, *ret = NULL;
1468     xkb_group_index_t group, min_group = UINT32_MAX;
1469     xkb_level_index_t level, min_level = UINT16_MAX;
1470
1471     xkb_foreach_key(key, keymap) {
1472         for (group = 0; group < key->num_groups; group++) {
1473             for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1474                  level++) {
1475                 if (XkbKeyNumSyms(key, group, level) != 1 ||
1476                     (XkbKeySymEntry(key, group, level))[0] != sym)
1477                     continue;
1478
1479                 /*
1480                  * If the keysym was found in a group or level > 0, we must
1481                  * keep looking since we might find a key in which the keysym
1482                  * is in a lower group or level.
1483                  */
1484                 if (group < min_group ||
1485                     (group == min_group && level < min_level)) {
1486                     ret = key;
1487                     if (group == 0 && level == 0) {
1488                         return ret;
1489                     }
1490                     else {
1491                         min_group = group;
1492                         min_level = level;
1493                     }
1494                 }
1495             }
1496         }
1497     }
1498
1499     return ret;
1500 }
1501
1502 /**
1503  * Find the given name in the keymap->map->types and return its index.
1504  *
1505  * @param name The name to search for.
1506  * @param type_rtrn Set to the index of the name if found.
1507  *
1508  * @return true if found, false otherwise.
1509  */
1510 static bool
1511 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
1512 {
1513     unsigned int i;
1514
1515     for (i = 0; i < keymap->num_types; i++) {
1516         if (keymap->types[i].name == name) {
1517             *type_rtrn = i;
1518             return true;
1519         }
1520     }
1521
1522     return false;
1523 }
1524
1525 /**
1526  * Assign a type to the given sym and return the Atom for the type assigned.
1527  *
1528  * Simple recipe:
1529  * - ONE_LEVEL for width 0/1
1530  * - ALPHABETIC for 2 shift levels, with lower/upercase
1531  * - KEYPAD for keypad keys.
1532  * - TWO_LEVEL for other 2 shift level keys.
1533  * and the same for four level keys.
1534  *
1535  * @param width Number of sysms in syms.
1536  * @param syms The keysyms for the given key (must be size width).
1537  * @param typeNameRtrn Set to the Atom of the type name.
1538  *
1539  * @returns true if a type could be found, false otherwise.
1540  *
1541  * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1542  *        all that fun stuff rather than just assuming there's always one
1543  *        symbol per level.
1544  */
1545 static bool
1546 FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
1547                   const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1548                   bool *autoType)
1549 {
1550     *autoType = false;
1551     if ((width == 1) || (width == 0)) {
1552         *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1553         *autoType = true;
1554     }
1555     else if (width == 2) {
1556         if (syms && xkb_keysym_is_lower(syms[0]) &&
1557             xkb_keysym_is_upper(syms[1])) {
1558             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1559         }
1560         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1561                           xkb_keysym_is_keypad(syms[1]))) {
1562             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1563             *autoType = true;
1564         }
1565         else {
1566             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1567             *autoType = true;
1568         }
1569     }
1570     else if (width <= 4) {
1571         if (syms && xkb_keysym_is_lower(syms[0]) &&
1572             xkb_keysym_is_upper(syms[1]))
1573             if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1574                 *typeNameRtrn =
1575                     xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1576             else
1577                 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1578                                                 "FOUR_LEVEL_SEMIALPHABETIC");
1579
1580         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1581                           xkb_keysym_is_keypad(syms[1])))
1582             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1583         else
1584             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1585         /* XXX: why not set autoType here? */
1586     }
1587     return width <= 4;
1588 }
1589
1590 /**
1591  * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1592  * groups, and reduce to one group if all groups are identical anyway.
1593  */
1594 static void
1595 PrepareKeyDef(KeyInfo *keyi)
1596 {
1597     xkb_group_index_t i, lastGroup;
1598     unsigned int defined;
1599     xkb_level_index_t j, width;
1600     bool identical;
1601
1602     defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
1603     /* get highest group number */
1604     for (i = XkbNumKbdGroups - 1; i > 0; i--) {
1605         if (defined & (1 << i))
1606             break;
1607     }
1608     lastGroup = i;
1609
1610     if (lastGroup == 0)
1611         return;
1612
1613     /* If there are empty groups between non-empty ones fill them with data */
1614     /* from the first group. */
1615     /* We can make a wrong assumption here. But leaving gaps is worse. */
1616     for (i = lastGroup; i > 0; i--) {
1617         if (defined & (1 << i))
1618             continue;
1619         width = keyi->numLevels[0];
1620         if (keyi->typesDefined & 1) {
1621             for (j = 0; j < width; j++) {
1622                 keyi->types[i] = keyi->types[0];
1623             }
1624             keyi->typesDefined |= 1 << i;
1625         }
1626         if ((keyi->actsDefined & 1) && !darray_empty(keyi->acts[0])) {
1627             darray_copy(keyi->acts[i], keyi->acts[0]);
1628             keyi->actsDefined |= 1 << i;
1629         }
1630         if ((keyi->symsDefined & 1) && !darray_empty(keyi->syms[0])) {
1631             darray_copy(keyi->syms[i], keyi->syms[0]);
1632             darray_copy(keyi->symsMapIndex[i], keyi->symsMapIndex[0]);
1633             darray_copy(keyi->symsMapNumEntries[i],
1634                         keyi->symsMapNumEntries[0]);
1635             keyi->symsDefined |= 1 << i;
1636         }
1637         if (defined & 1) {
1638             keyi->numLevels[i] = keyi->numLevels[0];
1639         }
1640     }
1641     /* If all groups are completely identical remove them all */
1642     /* exept the first one. */
1643     identical = true;
1644     for (i = lastGroup; i > 0; i--) {
1645         if ((keyi->numLevels[i] != keyi->numLevels[0]) ||
1646             (keyi->types[i] != keyi->types[0])) {
1647             identical = false;
1648             break;
1649         }
1650         if (!darray_same(keyi->syms[i], keyi->syms[0]) &&
1651             (darray_empty(keyi->syms[i]) || darray_empty(keyi->syms[0]) ||
1652              darray_size(keyi->syms[i]) != darray_size(keyi->syms[0]) ||
1653              memcmp(darray_mem(keyi->syms[i], 0),
1654                     darray_mem(keyi->syms[0], 0),
1655                     sizeof(xkb_keysym_t) * darray_size(keyi->syms[0])))) {
1656             identical = false;
1657             break;
1658         }
1659         if (!darray_same(keyi->symsMapIndex[i], keyi->symsMapIndex[0]) &&
1660             (darray_empty(keyi->symsMapIndex[i]) ||
1661              darray_empty(keyi->symsMapIndex[0]) ||
1662              memcmp(darray_mem(keyi->symsMapIndex[i], 0),
1663                     darray_mem(keyi->symsMapIndex[0], 0),
1664                     keyi->numLevels[0] * sizeof(int)))) {
1665             identical = false;
1666             continue;
1667         }
1668         if (!darray_same(keyi->symsMapNumEntries[i],
1669                          keyi->symsMapNumEntries[0]) &&
1670             (darray_empty(keyi->symsMapNumEntries[i]) ||
1671              darray_empty(keyi->symsMapNumEntries[0]) ||
1672              memcmp(darray_mem(keyi->symsMapNumEntries[i], 0),
1673                     darray_mem(keyi->symsMapNumEntries[0], 0),
1674                     keyi->numLevels[0] * sizeof(size_t)))) {
1675             identical = false;
1676             continue;
1677         }
1678         if (!darray_same(keyi->acts[i], keyi->acts[0]) &&
1679             (darray_empty(keyi->acts[i]) || darray_empty(keyi->acts[0]) ||
1680              memcmp(darray_mem(keyi->acts[i], 0),
1681                     darray_mem(keyi->acts[0], 0),
1682                     keyi->numLevels[0] * sizeof(union xkb_action)))) {
1683             identical = false;
1684             break;
1685         }
1686     }
1687     if (identical) {
1688         for (i = lastGroup; i > 0; i--) {
1689             keyi->numLevels[i] = 0;
1690             darray_free(keyi->syms[i]);
1691             darray_free(keyi->symsMapIndex[i]);
1692             darray_free(keyi->symsMapNumEntries[i]);
1693             darray_free(keyi->acts[i]);
1694             keyi->types[i] = 0;
1695         }
1696         keyi->symsDefined &= 1;
1697         keyi->actsDefined &= 1;
1698         keyi->typesDefined &= 1;
1699     }
1700 }
1701
1702 /**
1703  * Copy the KeyInfo into the keyboard description.
1704  *
1705  * This function recurses.
1706  */
1707 static bool
1708 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1709                xkb_keycode_t start_from)
1710 {
1711     struct xkb_keymap *keymap = info->keymap;
1712     xkb_keycode_t kc;
1713     struct xkb_key *key;
1714     size_t sizeSyms = 0;
1715     xkb_group_index_t i, nGroups;
1716     xkb_level_index_t width, tmp;
1717     struct xkb_key_type * type;
1718     bool haveActions, autoType, useAlias;
1719     unsigned types[XkbNumKbdGroups];
1720     unsigned int symIndex = 0;
1721
1722     useAlias = (start_from == 0);
1723
1724     key = FindNamedKey(keymap, keyi->name, useAlias, start_from);
1725     if (!key) {
1726         if (start_from == 0)
1727             log_lvl(info->keymap->ctx, 5,
1728                     "Key %s not found in keycodes; Symbols ignored\n",
1729                     LongKeyNameText(keyi->name));
1730         return false;
1731     }
1732     kc = XkbKeyGetKeycode(keymap, key);
1733
1734     haveActions = false;
1735     width = 0;
1736     for (i = nGroups = 0; i < XkbNumKbdGroups; i++) {
1737         if (((i + 1) > nGroups)
1738             && (((keyi->symsDefined | keyi->actsDefined) & (1 << i))
1739                 || (keyi->typesDefined) & (1 << i)))
1740             nGroups = i + 1;
1741         if (!darray_empty(keyi->acts[i]))
1742             haveActions = true;
1743         autoType = false;
1744         /* Assign the type to the key, if it is missing. */
1745         if (keyi->types[i] == XKB_ATOM_NONE) {
1746             if (keyi->dfltType != XKB_ATOM_NONE)
1747                 keyi->types[i] = keyi->dfltType;
1748             else if (FindAutomaticType(keymap, keyi->numLevels[i],
1749                                        darray_mem(keyi->syms[i], 0),
1750                                        &keyi->types[i], &autoType)) { }
1751             else
1752                 log_lvl(info->keymap->ctx, 5,
1753                         "No automatic type for %d symbols; "
1754                         "Using %s for the %s key (keycode %d)\n",
1755                         keyi->numLevels[i],
1756                         xkb_atom_text(keymap->ctx, keyi->types[i]),
1757                         LongKeyNameText(keyi->name), kc);
1758         }
1759         if (FindNamedType(keymap, keyi->types[i], &types[i])) {
1760             if (!autoType || keyi->numLevels[i] > 2)
1761                 key->explicit |= (1 << i);
1762         }
1763         else {
1764             log_lvl(info->keymap->ctx, 3,
1765                     "Type \"%s\" is not defined; "
1766                     "Using default type for the %s key (keycode %d)\n",
1767                     xkb_atom_text(keymap->ctx, keyi->types[i]),
1768                     LongKeyNameText(keyi->name), kc);
1769             /*
1770              * Index 0 is guaranteed to contain something, usually
1771              * ONE_LEVEL or at least some default one-level type.
1772              */
1773             types[i] = 0;
1774         }
1775
1776         /* if the type specifies fewer levels than the key has, shrink the key */
1777         type = &keymap->types[types[i]];
1778         if (type->num_levels < keyi->numLevels[i]) {
1779             log_lvl(info->keymap->ctx, 1,
1780                     "Type \"%s\" has %d levels, but %s has %d symbols; "
1781                     "Ignoring extra symbols\n",
1782                     xkb_atom_text(keymap->ctx, type->name),
1783                     type->num_levels,
1784                     LongKeyNameText(keyi->name),
1785                     keyi->numLevels[i]);
1786             keyi->numLevels[i] = type->num_levels;
1787         }
1788         if (keyi->numLevels[i] > width)
1789             width = keyi->numLevels[i];
1790         if (type->num_levels > width)
1791             width = type->num_levels;
1792         sizeSyms += darray_size(keyi->syms[i]);
1793     }
1794
1795     darray_resize0(key->syms, sizeSyms);
1796
1797     key->num_groups = nGroups;
1798
1799     key->width = width;
1800
1801     key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1802
1803     key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1804
1805     if (haveActions) {
1806         key->actions = calloc(nGroups * width, sizeof(*key->actions));
1807         key->explicit |= XkbExplicitInterpretMask;
1808     }
1809
1810     if (keyi->defined & KEY_FIELD_GROUPINFO) {
1811         key->out_of_range_group_number = keyi->out_of_range_group_number;
1812         key->out_of_range_group_action = keyi->out_of_range_group_action;
1813     }
1814
1815     for (i = 0; i < nGroups; i++) {
1816         /* assign kt_index[i] to the index of the type in map->types.
1817          * kt_index[i] may have been set by a previous run (if we have two
1818          * layouts specified). Let's not overwrite it with the ONE_LEVEL
1819          * default group if we dont even have keys for this group anyway.
1820          *
1821          * FIXME: There should be a better fix for this.
1822          */
1823         if (keyi->numLevels[i])
1824             key->kt_index[i] = types[i];
1825         if (!darray_empty(keyi->syms[i])) {
1826             /* fill key to "width" symbols*/
1827             for (tmp = 0; tmp < width; tmp++) {
1828                 if (tmp < keyi->numLevels[i] &&
1829                     darray_item(keyi->symsMapNumEntries[i], tmp) != 0) {
1830                     memcpy(darray_mem(key->syms, symIndex),
1831                            darray_mem(keyi->syms[i],
1832                                       darray_item(keyi->symsMapIndex[i], tmp)),
1833                            darray_item(keyi->symsMapNumEntries[i],
1834                                        tmp) * sizeof(xkb_keysym_t));
1835                     key->sym_index[(i * width) + tmp] = symIndex;
1836                     key->num_syms[(i * width) + tmp] =
1837                         darray_item(keyi->symsMapNumEntries[i], tmp);
1838                     symIndex += key->num_syms[(i * width) + tmp];
1839                 }
1840                 else {
1841                     key->sym_index[(i * width) + tmp] = -1;
1842                     key->num_syms[(i * width) + tmp] = 0;
1843                 }
1844                 if (key->actions && !darray_empty(keyi->acts[i])) {
1845                     if (tmp < keyi->numLevels[i])
1846                         key->actions[tmp] = darray_item(keyi->acts[i], tmp);
1847                     else
1848                         key->actions[tmp].type = XkbSA_NoAction;
1849                 }
1850             }
1851         }
1852     }
1853
1854     if (keyi->defined & KEY_FIELD_VMODMAP) {
1855         key->vmodmap = keyi->vmodmap;
1856         key->explicit |= XkbExplicitVModMapMask;
1857     }
1858
1859     if (keyi->repeat != KEY_REPEAT_UNDEFINED) {
1860         key->repeats = (keyi->repeat == KEY_REPEAT_YES);
1861         key->explicit |= XkbExplicitAutoRepeatMask;
1862     }
1863
1864     /* do the same thing for the next key */
1865     CopySymbolsDef(info, keyi, kc + 1);
1866     return true;
1867 }
1868
1869 static bool
1870 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1871 {
1872     struct xkb_key *key;
1873     struct xkb_keymap *keymap = info->keymap;
1874
1875     if (!entry->haveSymbol) {
1876         key = FindNamedKey(keymap, entry->u.keyName, true, 0);
1877         if (!key) {
1878             log_lvl(info->keymap->ctx, 5,
1879                     "Key %s not found in keycodes; "
1880                     "Modifier map entry for %s not updated\n",
1881                     LongKeyNameText(entry->u.keyName),
1882                     ModIndexText(entry->modifier));
1883             return false;
1884         }
1885     }
1886     else {
1887         key = FindKeyForSymbol(keymap, entry->u.keySym);
1888         if (!key) {
1889             log_lvl(info->keymap->ctx, 5,
1890                     "Key \"%s\" not found in symbol map; "
1891                     "Modifier map entry for %s not updated\n",
1892                     KeysymText(entry->u.keySym),
1893                     ModIndexText(entry->modifier));
1894             return false;
1895         }
1896     }
1897
1898     key->modmap |= (1 << entry->modifier);
1899     return true;
1900 }
1901
1902 /**
1903  * Handle the xkb_symbols section of an xkb file.
1904  *
1905  * @param file The parsed xkb_symbols section of the xkb file.
1906  * @param keymap Handle to the keyboard description to store the symbols in.
1907  * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1908  */
1909 bool
1910 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1911                enum merge_mode merge)
1912 {
1913     xkb_group_index_t i;
1914     struct xkb_key *key;
1915     SymbolsInfo info;
1916     KeyInfo *keyi;
1917     ModMapEntry *mm;
1918
1919     InitSymbolsInfo(&info, keymap, file->id);
1920     info.dflt.merge = merge;
1921
1922     HandleSymbolsFile(&info, file, merge);
1923
1924     if (darray_empty(info.keys))
1925         goto err_info;
1926
1927     if (info.errorCount != 0)
1928         goto err_info;
1929
1930     if (info.name)
1931         keymap->symbols_section_name = strdup(info.name);
1932
1933     for (i = 0; i < XkbNumKbdGroups; i++) {
1934         if (info.groupNames[i] != XKB_ATOM_NONE) {
1935             keymap->group_names[i] = xkb_atom_text(keymap->ctx,
1936                                                    info.groupNames[i]);
1937         }
1938     }
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     return true;
1968
1969 err_info:
1970     ClearSymbolsInfo(&info);
1971     return false;
1972 }