bd1bfdc41f3afacb75329ecd2cbd872c00d72107
[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 "parseutils.h"
29 #include "action.h"
30 #include "vmod.h"
31
32 /***====================================================================***/
33
34 /* Needed to work with the typechecker. */
35 typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
36 typedef darray(union xkb_action) darray_xkb_action;
37
38 enum key_repeat {
39     KEY_REPEAT_YES = 1,
40     KEY_REPEAT_NO = 0,
41     KEY_REPEAT_UNDEFINED = -1
42 };
43
44 enum key_field {
45     KEY_FIELD_SYMS      = (1 << 0),
46     KEY_FIELD_ACTS      = (1 << 1),
47     KEY_FIELD_REPEAT    = (1 << 2),
48     KEY_FIELD_TYPE_DFLT = (1 << 3),
49     KEY_FIELD_TYPES     = (1 << 4),
50     KEY_FIELD_GROUPINFO = (1 << 5),
51     KEY_FIELD_VMODMAP   = (1 << 6),
52 };
53
54 typedef struct _KeyInfo {
55     enum key_field defined;
56     unsigned file_id;
57     enum merge_mode merge;
58
59     unsigned long name; /* the 4 chars of the key name, as long */
60     unsigned char typesDefined;
61     unsigned char symsDefined;
62     unsigned char actsDefined;
63     xkb_level_index_t numLevels[XkbNumKbdGroups];
64
65     /* syms[group] -> Single array for all the keysyms in the group. */
66     darray_xkb_keysym_t syms[XkbNumKbdGroups];
67     /*
68      * symsMapIndex[group][level] -> The index from which the syms for
69      * the level begin in the syms[group] array. Remember each keycode
70      * can have multiple keysyms in each level (that is, each key press
71      * can result in multiple keysyms).
72      */
73     darray(int) symsMapIndex[XkbNumKbdGroups];
74     /*
75      * symsMapNumEntries[group][level] -> How many syms are in
76      * syms[group][symsMapIndex[group][level]].
77      */
78     darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
79
80     darray_xkb_action acts[XkbNumKbdGroups];
81
82     xkb_atom_t types[XkbNumKbdGroups];
83     enum key_repeat repeat;
84     xkb_mod_mask_t vmodmap;
85     xkb_atom_t dfltType;
86
87     uint8_t out_of_range_group_action;
88     xkb_group_index_t out_of_range_group_number;
89 } KeyInfo;
90
91 /**
92  * Init the given key info to sane values.
93  */
94 static void
95 InitKeyInfo(KeyInfo *keyi, unsigned file_id)
96 {
97     xkb_group_index_t i;
98     static const char dflt[4] = "*";
99
100     keyi->defined = 0;
101     keyi->file_id = file_id;
102     keyi->merge = MERGE_OVERRIDE;
103     keyi->name = KeyNameToLong(dflt);
104     keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 0;
105
106     for (i = 0; i < XkbNumKbdGroups; i++) {
107         keyi->numLevels[i] = 0;
108         keyi->types[i] = XKB_ATOM_NONE;
109         darray_init(keyi->syms[i]);
110         darray_init(keyi->symsMapIndex[i]);
111         darray_init(keyi->symsMapNumEntries[i]);
112         darray_init(keyi->acts[i]);
113     }
114
115     keyi->dfltType = XKB_ATOM_NONE;
116     keyi->vmodmap = 0;
117     keyi->repeat = KEY_REPEAT_UNDEFINED;
118     keyi->out_of_range_group_action = 0;
119     keyi->out_of_range_group_number = 0;
120 }
121
122 static void
123 FreeKeyInfo(KeyInfo *keyi)
124 {
125     xkb_group_index_t i;
126
127     for (i = 0; i < XkbNumKbdGroups; i++) {
128         darray_free(keyi->syms[i]);
129         darray_free(keyi->symsMapIndex[i]);
130         darray_free(keyi->symsMapNumEntries[i]);
131         darray_free(keyi->acts[i]);
132     }
133 }
134
135 /**
136  * Copy old into new, optionally reset old to 0.
137  * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
138  * newly allocated and new points to the new memory areas.
139  */
140 static bool
141 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
142 {
143     xkb_group_index_t i;
144
145     *new = *old;
146
147     if (clearOld) {
148         for (i = 0; i < XkbNumKbdGroups; i++) {
149             old->numLevels[i] = 0;
150             darray_init(old->symsMapIndex[i]);
151             darray_init(old->symsMapNumEntries[i]);
152             darray_init(old->syms[i]);
153             darray_init(old->acts[i]);
154         }
155     }
156     else {
157         for (i = 0; i < XkbNumKbdGroups; i++) {
158             darray_copy(new->syms[i], old->syms[i]);
159             darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
160             darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
161             darray_copy(new->acts[i], old->acts[i]);
162         }
163     }
164
165     return true;
166 }
167
168 /***====================================================================***/
169
170 typedef struct _ModMapEntry {
171     struct list entry;
172     enum merge_mode merge;
173     bool haveSymbol;
174     int modifier;
175     union {
176         unsigned long keyName;
177         xkb_keysym_t keySym;
178     } u;
179 } ModMapEntry;
180
181 typedef struct _SymbolsInfo {
182     char *name;         /* e.g. pc+us+inet(evdev) */
183     int errorCount;
184     unsigned file_id;
185     enum merge_mode merge;
186     xkb_group_index_t explicit_group;
187     darray(KeyInfo) keys;
188     KeyInfo dflt;
189     VModInfo vmods;
190     ActionInfo *action;
191     xkb_atom_t groupNames[XkbNumKbdGroups];
192
193     struct list modMaps;
194
195     struct xkb_keymap *keymap;
196 } SymbolsInfo;
197
198 static void
199 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap,
200                 unsigned file_id)
201 {
202     xkb_group_index_t i;
203
204     info->name = NULL;
205     info->explicit_group = 0;
206     info->errorCount = 0;
207     info->file_id = file_id;
208     info->merge = MERGE_OVERRIDE;
209     darray_init(info->keys);
210     darray_growalloc(info->keys, 110);
211     list_init(&info->modMaps);
212     for (i = 0; i < XkbNumKbdGroups; i++)
213         info->groupNames[i] = XKB_ATOM_NONE;
214     InitKeyInfo(&info->dflt, file_id);
215     InitVModInfo(&info->vmods, keymap);
216     info->action = NULL;
217     info->keymap = keymap;
218 }
219
220 static void
221 FreeSymbolsInfo(SymbolsInfo * info)
222 {
223     KeyInfo *keyi;
224     ModMapEntry *mm, *next;
225
226     free(info->name);
227     darray_foreach(keyi, info->keys) {
228         FreeKeyInfo(keyi);
229     }
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             FreeSymbolsInfo(&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         FreeSymbolsInfo(&next_incl);
775         FreeXKBFile(rtrn);
776     }
777
778     MergeIncludedSymbols(info, &included, merge);
779     FreeSymbolsInfo(&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 static bool
833 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
834                 ExprDef *value)
835 {
836     xkb_group_index_t ndx;
837     size_t nSyms;
838     xkb_level_index_t nLevels;
839     xkb_level_index_t i;
840     int j;
841
842     if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
843         return false;
844     if (value == NULL) {
845         keyi->symsDefined |= (1 << ndx);
846         return true;
847     }
848     if (value->op != EXPR_KEYSYM_LIST) {
849         log_err(info->keymap->ctx,
850                 "Expected a list of symbols, found %s; "
851                 "Ignoring symbols for group %u of %s\n",
852                 exprOpText(value->op), ndx + 1, LongKeyNameText(keyi->name));
853         return false;
854     }
855     if (!darray_empty(keyi->syms[ndx])) {
856         log_err(info->keymap->ctx,
857                 "Symbols for key %s, group %u already defined; "
858                 "Ignoring duplicate definition\n",
859                 LongKeyNameText(keyi->name), ndx + 1);
860         return false;
861     }
862     nSyms = darray_size(value->value.list.syms);
863     nLevels = darray_size(value->value.list.symsMapIndex);
864     if ((keyi->numLevels[ndx] < nSyms || darray_empty(keyi->syms[ndx])) &&
865         (!ResizeKeyGroup(keyi, ndx, nLevels, nSyms, false))) {
866         log_wsgo(info->keymap->ctx,
867                  "Could not resize group %u of key %s to contain %zu levels; "
868                  "Symbols lost\n",
869                  ndx + 1, LongKeyNameText(keyi->name), nSyms);
870         return false;
871     }
872     keyi->symsDefined |= (1 << ndx);
873     for (i = 0; i < nLevels; i++) {
874         darray_item(keyi->symsMapIndex[ndx], i) =
875             darray_item(value->value.list.symsMapIndex, i);
876         darray_item(keyi->symsMapNumEntries[ndx], i) =
877             darray_item(value->value.list.symsNumEntries, i);
878
879         for (j = 0; j < darray_item(keyi->symsMapNumEntries[ndx], i); j++) {
880             /* FIXME: What's abort() doing here? */
881             if (darray_item(keyi->symsMapIndex[ndx], i) + j >= nSyms)
882                 abort();
883             if (!LookupKeysym(darray_item(value->value.list.syms,
884                                           darray_item(value->value.list.symsMapIndex,
885                                                       i) + j),
886                               &darray_item(keyi->syms[ndx],
887                                            darray_item(keyi->symsMapIndex[ndx],
888                                                        i) + j))) {
889                 log_warn(info->keymap->ctx,
890                          "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
891                          darray_item(value->value.list.syms, i),
892                          LongKeyNameText(keyi->name),
893                          ndx + 1,
894                          xkb_atom_text(info->keymap->ctx,
895                                        info->groupNames[ndx]),
896                          nSyms);
897                 while (--j >= 0)
898                     darray_item(keyi->syms[ndx],
899                                 darray_item(keyi->symsMapIndex[ndx],
900                                             i) + j) = XKB_KEY_NoSymbol;
901                 darray_item(keyi->symsMapIndex[ndx], i) = -1;
902                 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
903                 break;
904             }
905             if (darray_item(keyi->symsMapNumEntries[ndx], i) == 1 &&
906                 darray_item(keyi->syms[ndx],
907                             darray_item(keyi->symsMapIndex[ndx],
908                                         i) + j) == XKB_KEY_NoSymbol) {
909                 darray_item(keyi->symsMapIndex[ndx], i) = -1;
910                 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
911             }
912         }
913     }
914     for (j = keyi->numLevels[ndx] - 1;
915          j >= 0 && darray_item(keyi->symsMapNumEntries[ndx], j) == 0; j--)
916         keyi->numLevels[ndx]--;
917     return true;
918 }
919
920 static bool
921 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
922                 ExprDef *value)
923 {
924     size_t i;
925     xkb_group_index_t ndx;
926     size_t nActs;
927     ExprDef *act;
928     union xkb_action *toAct;
929
930     if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
931         return false;
932
933     if (value == NULL) {
934         keyi->actsDefined |= (1 << ndx);
935         return true;
936     }
937
938     if (value->op != EXPR_ACTION_LIST) {
939         log_wsgo(info->keymap->ctx,
940                  "Bad expression type (%d) for action list value; "
941                  "Ignoring actions for group %u of %s\n",
942                  value->op, ndx, LongKeyNameText(keyi->name));
943         return false;
944     }
945
946     if (!darray_empty(keyi->acts[ndx])) {
947         log_wsgo(info->keymap->ctx,
948                  "Actions for key %s, group %u already defined\n",
949                  LongKeyNameText(keyi->name), ndx);
950         return false;
951     }
952
953     for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
954         act = (ExprDef *) act->common.next;
955     }
956
957     if (nActs < 1) {
958         log_wsgo(info->keymap->ctx,
959                  "Action list but not actions in AddActionsToKey\n");
960         return false;
961     }
962
963     if ((keyi->numLevels[ndx] < nActs || darray_empty(keyi->acts[ndx])) &&
964         !ResizeKeyGroup(keyi, ndx, nActs, nActs, true)) {
965         log_wsgo(info->keymap->ctx,
966                  "Could not resize group %u of key %s; "
967                  "Actions lost\n",
968                  ndx, LongKeyNameText(keyi->name));
969         return false;
970     }
971     keyi->actsDefined |= (1 << ndx);
972
973     toAct = darray_mem(keyi->acts[ndx], 0);
974     act = value->value.child;
975     for (i = 0; i < nActs; i++, toAct++) {
976         if (!HandleActionDef(act, info->keymap, toAct, info->action)) {
977             log_err(info->keymap->ctx,
978                     "Illegal action definition for %s; "
979                     "Action for group %u/level %zu ignored\n",
980                     LongKeyNameText(keyi->name), ndx + 1, i + 1);
981         }
982         act = (ExprDef *) act->common.next;
983     }
984
985     return true;
986 }
987
988 static const LookupEntry repeatEntries[] = {
989     { "true", KEY_REPEAT_YES },
990     { "yes", KEY_REPEAT_YES },
991     { "on", KEY_REPEAT_YES },
992     { "false", KEY_REPEAT_NO },
993     { "no", KEY_REPEAT_NO },
994     { "off", KEY_REPEAT_NO },
995     { "default", KEY_REPEAT_UNDEFINED },
996     { NULL, 0 }
997 };
998
999 static bool
1000 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
1001                 ExprDef *arrayNdx, ExprDef *value)
1002 {
1003     bool ok = true;
1004     struct xkb_context *ctx = info->keymap->ctx;
1005
1006     if (istreq(field, "type")) {
1007         xkb_group_index_t ndx;
1008         const char *str;
1009
1010         if (!ExprResolveString(ctx, value, &str))
1011             log_lvl(info->keymap->ctx, 1,
1012                     "The type field of a key symbol map must be a string; "
1013                     "Ignoring illegal type definition\n");
1014
1015         if (arrayNdx == NULL) {
1016             keyi->dfltType = xkb_atom_intern(ctx, str);
1017             keyi->defined |= KEY_FIELD_TYPE_DFLT;
1018         }
1019         else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1020             log_err(info->keymap->ctx,
1021                     "Illegal group index for type of key %s; "
1022                     "Definition with non-integer array index ignored\n",
1023                     LongKeyNameText(keyi->name));
1024             return false;
1025         }
1026         else {
1027             ndx--;
1028             keyi->types[ndx] = xkb_atom_intern(ctx, str);
1029             keyi->typesDefined |= (1 << ndx);
1030         }
1031     }
1032     else if (istreq(field, "symbols"))
1033         return AddSymbolsToKey(info, keyi, arrayNdx, value);
1034     else if (istreq(field, "actions"))
1035         return AddActionsToKey(info, keyi, arrayNdx, value);
1036     else if (istreq(field, "vmods") ||
1037              istreq(field, "virtualmods") ||
1038              istreq(field, "virtualmodifiers")) {
1039         xkb_mod_mask_t mask;
1040
1041         ok = ExprResolveVModMask(info->keymap, value, &mask);
1042         if (ok) {
1043             keyi->vmodmap = (mask >> XkbNumModifiers) & 0xffff;
1044             keyi->defined |= KEY_FIELD_VMODMAP;
1045         }
1046         else {
1047             log_err(info->keymap->ctx,
1048                     "Expected a virtual modifier mask, found %s; "
1049                     "Ignoring virtual modifiers definition for key %s\n",
1050                     exprOpText(value->op), LongKeyNameText(keyi->name));
1051         }
1052     }
1053     else if (istreq(field, "locking") ||
1054              istreq(field, "lock") ||
1055              istreq(field, "locks")) {
1056         log_err(info->keymap->ctx,
1057                 "Key behaviors not supported; "
1058                 "Ignoring locking specification for key %s\n",
1059                 LongKeyNameText(keyi->name));
1060     }
1061     else if (istreq(field, "radiogroup") ||
1062              istreq(field, "permanentradiogroup") ||
1063              istreq(field, "allownone")) {
1064         log_err(info->keymap->ctx,
1065                 "Radio groups not supported; "
1066                 "Ignoring radio group specification for key %s\n",
1067                 LongKeyNameText(keyi->name));
1068     }
1069     else if (istreq_prefix("overlay", field) ||
1070              istreq_prefix("permanentoverlay", field)) {
1071         log_err(info->keymap->ctx,
1072                 "Overlays not supported; "
1073                 "Ignoring overlay specification for key %s\n",
1074                 LongKeyNameText(keyi->name));
1075     }
1076     else if (istreq(field, "repeating") ||
1077              istreq(field, "repeats") ||
1078              istreq(field, "repeat")) {
1079         unsigned int val;
1080
1081         ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
1082         if (!ok) {
1083             log_err(info->keymap->ctx,
1084                     "Illegal repeat setting for %s; "
1085                     "Non-boolean repeat setting ignored\n",
1086                     LongKeyNameText(keyi->name));
1087             return false;
1088         }
1089         keyi->repeat = val;
1090         keyi->defined |= KEY_FIELD_REPEAT;
1091     }
1092     else if (istreq(field, "groupswrap") ||
1093              istreq(field, "wrapgroups")) {
1094         bool set;
1095
1096         if (!ExprResolveBoolean(ctx, value, &set)) {
1097             log_err(info->keymap->ctx,
1098                     "Illegal groupsWrap setting for %s; "
1099                     "Non-boolean value ignored\n",
1100                     LongKeyNameText(keyi->name));
1101             return false;
1102         }
1103
1104         if (set)
1105             keyi->out_of_range_group_action = XkbWrapIntoRange;
1106         else
1107             keyi->out_of_range_group_action = XkbClampIntoRange;
1108
1109         keyi->defined |= KEY_FIELD_GROUPINFO;
1110     }
1111     else if (istreq(field, "groupsclamp") ||
1112              istreq(field, "clampgroups")) {
1113         bool set;
1114
1115         if (!ExprResolveBoolean(ctx, value, &set)) {
1116             log_err(info->keymap->ctx,
1117                     "Illegal groupsClamp setting for %s; "
1118                     "Non-boolean value ignored\n",
1119                     LongKeyNameText(keyi->name));
1120             return false;
1121         }
1122
1123         if (set)
1124             keyi->out_of_range_group_action = XkbClampIntoRange;
1125         else
1126             keyi->out_of_range_group_action = XkbWrapIntoRange;
1127
1128         keyi->defined |= KEY_FIELD_GROUPINFO;
1129     }
1130     else if (istreq(field, "groupsredirect") ||
1131              istreq(field, "redirectgroups")) {
1132         xkb_group_index_t grp;
1133
1134         if (!ExprResolveGroup(ctx, value, &grp)) {
1135             log_err(info->keymap->ctx,
1136                     "Illegal group index for redirect of key %s; "
1137                     "Definition with non-integer group ignored\n",
1138                     LongKeyNameText(keyi->name));
1139             return false;
1140         }
1141
1142         keyi->out_of_range_group_action = XkbRedirectIntoRange;
1143         keyi->out_of_range_group_number = grp - 1;
1144         keyi->defined |= KEY_FIELD_GROUPINFO;
1145     }
1146     else {
1147         log_err(info->keymap->ctx,
1148                 "Unknown field %s in a symbol interpretation; "
1149                 "Definition ignored\n",
1150                 field);
1151         ok = false;
1152     }
1153
1154     return ok;
1155 }
1156
1157 static int
1158 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1159 {
1160     xkb_group_index_t grp;
1161     const char *name;
1162
1163     if (!arrayNdx) {
1164         log_lvl(info->keymap->ctx, 1,
1165                 "You must specify an index when specifying a group name; "
1166                 "Group name definition without array subscript ignored\n");
1167         return false;
1168     }
1169
1170     if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
1171         log_err(info->keymap->ctx,
1172                 "Illegal index in group name definition; "
1173                 "Definition with non-integer array index ignored\n");
1174         return false;
1175     }
1176
1177     if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1178         log_err(info->keymap->ctx,
1179                 "Group name must be a string; "
1180                 "Illegal name for group %d ignored\n", grp);
1181         return false;
1182     }
1183
1184     info->groupNames[grp - 1 + info->explicit_group] =
1185         xkb_atom_intern(info->keymap->ctx, name);
1186
1187     return true;
1188 }
1189
1190 static int
1191 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1192 {
1193     const char *elem, *field;
1194     ExprDef *arrayNdx;
1195     bool ret;
1196
1197     if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
1198                        &arrayNdx) == 0)
1199         return 0;               /* internal error, already reported */
1200     if (elem && istreq(elem, "key")) {
1201         ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
1202                               stmt->value);
1203     }
1204     else if (!elem && (istreq(field, "name") ||
1205                        istreq(field, "groupname"))) {
1206         ret = SetGroupName(info, arrayNdx, stmt->value);
1207     }
1208     else if (!elem && (istreq(field, "groupswrap") ||
1209                        istreq(field, "wrapgroups"))) {
1210         log_err(info->keymap->ctx,
1211                 "Global \"groupswrap\" not supported; Ignored\n");
1212         ret = true;
1213     }
1214     else if (!elem && (istreq(field, "groupsclamp") ||
1215                        istreq(field, "clampgroups"))) {
1216         log_err(info->keymap->ctx,
1217                 "Global \"groupsclamp\" not supported; Ignored\n");
1218         ret = true;
1219     }
1220     else if (!elem && (istreq(field, "groupsredirect") ||
1221                        istreq(field, "redirectgroups"))) {
1222         log_err(info->keymap->ctx,
1223                 "Global \"groupsredirect\" not supported; Ignored\n");
1224         ret = true;
1225     }
1226     else if (!elem && istreq(field, "allownone")) {
1227         log_err(info->keymap->ctx,
1228                 "Radio groups not supported; "
1229                 "Ignoring \"allownone\" specification\n");
1230         ret = true;
1231     }
1232     else {
1233         ret = SetActionField(info->keymap, elem, field, arrayNdx,
1234                              stmt->value, &info->action);
1235     }
1236
1237     return ret;
1238 }
1239
1240 static bool
1241 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1242 {
1243     bool ok = true;
1244     const char *elem, *field;
1245     ExprDef *arrayNdx;
1246
1247     for (; def; def = (VarDef *) def->common.next) {
1248         if (def->name && def->name->op == EXPR_FIELD_REF) {
1249             ok = HandleSymbolsVar(info, def);
1250             continue;
1251         }
1252
1253         if (!def->name) {
1254             if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
1255                 field = "symbols";
1256             else
1257                 field = "actions";
1258             arrayNdx = NULL;
1259         }
1260         else {
1261             ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
1262                                 &arrayNdx);
1263         }
1264
1265         if (ok)
1266             ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value);
1267     }
1268
1269     return ok;
1270 }
1271
1272 static bool
1273 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1274 {
1275     xkb_group_index_t group = info->explicit_group;
1276
1277     if (group == 0)
1278         return true;
1279
1280     if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
1281         xkb_group_index_t i;
1282         log_warn(info->keymap->ctx,
1283                  "For the map %s an explicit group specified, "
1284                  "but key %s has more than one group defined; "
1285                  "All groups except first one will be ignored\n",
1286                  info->name, LongKeyNameText(keyi->name));
1287         for (i = 1; i < XkbNumKbdGroups; i++) {
1288             keyi->numLevels[i] = 0;
1289             darray_free(keyi->syms[i]);
1290             darray_free(keyi->acts[i]);
1291             keyi->types[i] = 0;
1292         }
1293     }
1294     keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 1 << group;
1295
1296     keyi->numLevels[group] = keyi->numLevels[0];
1297     keyi->numLevels[0] = 0;
1298     keyi->syms[group] = keyi->syms[0];
1299     darray_init(keyi->syms[0]);
1300     keyi->symsMapIndex[group] = keyi->symsMapIndex[0];
1301     darray_init(keyi->symsMapIndex[0]);
1302     keyi->symsMapNumEntries[group] = keyi->symsMapNumEntries[0];
1303     darray_init(keyi->symsMapNumEntries[0]);
1304     keyi->acts[group] = keyi->acts[0];
1305     darray_init(keyi->acts[0]);
1306     keyi->types[group] = keyi->types[0];
1307     keyi->types[0] = 0;
1308     return true;
1309 }
1310
1311 static int
1312 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1313 {
1314     KeyInfo keyi;
1315
1316     InitKeyInfo(&keyi, info->file_id);
1317     CopyKeyInfo(&info->dflt, &keyi, false);
1318     keyi.merge = stmt->merge;
1319     keyi.name = KeyNameToLong(stmt->keyName);
1320     if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1321         info->errorCount++;
1322         return false;
1323     }
1324
1325     if (!SetExplicitGroup(info, &keyi)) {
1326         info->errorCount++;
1327         return false;
1328     }
1329
1330     if (!AddKeySymbols(info, &keyi)) {
1331         info->errorCount++;
1332         return false;
1333     }
1334     return true;
1335 }
1336
1337 static bool
1338 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1339 {
1340     ExprDef *key;
1341     ModMapEntry tmp;
1342     xkb_mod_index_t ndx;
1343     bool ok;
1344     struct xkb_context *ctx = info->keymap->ctx;
1345
1346     if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
1347         log_err(info->keymap->ctx,
1348                 "Illegal modifier map definition; "
1349                 "Ignoring map for non-modifier \"%s\"\n",
1350                 xkb_atom_text(ctx, def->modifier));
1351         return false;
1352     }
1353
1354     ok = true;
1355     tmp.modifier = ndx;
1356
1357     for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1358         xkb_keysym_t sym;
1359
1360         if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
1361             tmp.haveSymbol = false;
1362             tmp.u.keyName = KeyNameToLong(key->value.keyName);
1363         }
1364         else if (ExprResolveKeySym(ctx, key, &sym)) {
1365             tmp.haveSymbol = true;
1366             tmp.u.keySym = sym;
1367         }
1368         else {
1369             log_err(info->keymap->ctx,
1370                     "Modmap entries may contain only key names or keysyms; "
1371                     "Illegal definition for %s modifier ignored\n",
1372                     ModIndexText(tmp.modifier));
1373             continue;
1374         }
1375
1376         ok = AddModMapEntry(info, &tmp) && ok;
1377     }
1378     return ok;
1379 }
1380
1381 static void
1382 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1383 {
1384     bool ok;
1385     ParseCommon *stmt;
1386
1387     free(info->name);
1388     info->name = strdup_safe(file->name);
1389
1390     stmt = file->defs;
1391     for (stmt = file->defs; stmt; stmt = stmt->next) {
1392         switch (stmt->type) {
1393         case STMT_INCLUDE:
1394             ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
1395             break;
1396         case STMT_SYMBOLS:
1397             ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
1398             break;
1399         case STMT_VAR:
1400             ok = HandleSymbolsVar(info, (VarDef *) stmt);
1401             break;
1402         case STMT_VMOD:
1403             ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1404                                &info->vmods);
1405             break;
1406         case STMT_MODMAP:
1407             ok = HandleModMapDef(info, (ModMapDef *) stmt);
1408             break;
1409         default:
1410             log_err(info->keymap->ctx,
1411                     "Interpretation files may not include other types; "
1412                     "Ignoring %s\n", StmtTypeToString(stmt->type));
1413             ok = false;
1414             break;
1415         }
1416
1417         if (!ok)
1418             info->errorCount++;
1419
1420         if (info->errorCount > 10) {
1421             log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1422                     file->topName);
1423             break;
1424         }
1425     }
1426 }
1427
1428 /**
1429  * Given a keysym @sym, return a key which generates it, or NULL.
1430  * This is used for example in a modifier map definition, such as:
1431  *      modifier_map Lock           { Caps_Lock };
1432  * where we want to add the Lock modifier to the modmap of the key
1433  * which matches the keysym Caps_Lock.
1434  * Since there can be many keys which generates the keysym, the key
1435  * is chosen first by lowest group in which the keysym appears, than
1436  * by lowest level and than by lowest key code.
1437  */
1438 static struct xkb_key *
1439 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1440 {
1441     struct xkb_key *key, *ret = NULL;
1442     xkb_group_index_t group, min_group = UINT32_MAX;
1443     xkb_level_index_t level, min_level = UINT16_MAX;
1444
1445     xkb_foreach_key(key, keymap) {
1446         for (group = 0; group < key->num_groups; group++) {
1447             for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1448                  level++) {
1449                 if (XkbKeyNumSyms(key, group, level) != 1 ||
1450                     (XkbKeySymEntry(key, group, level))[0] != sym)
1451                     continue;
1452
1453                 /*
1454                  * If the keysym was found in a group or level > 0, we must
1455                  * keep looking since we might find a key in which the keysym
1456                  * is in a lower group or level.
1457                  */
1458                 if (group < min_group ||
1459                     (group == min_group && level < min_level)) {
1460                     ret = key;
1461                     if (group == 0 && level == 0) {
1462                         return ret;
1463                     }
1464                     else {
1465                         min_group = group;
1466                         min_level = level;
1467                     }
1468                 }
1469             }
1470         }
1471     }
1472
1473     return ret;
1474 }
1475
1476 /**
1477  * Find the given name in the keymap->map->types and return its index.
1478  *
1479  * @param name The name to search for.
1480  * @param type_rtrn Set to the index of the name if found.
1481  *
1482  * @return true if found, false otherwise.
1483  */
1484 static bool
1485 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
1486 {
1487     unsigned int i;
1488
1489     for (i = 0; i < keymap->num_types; i++) {
1490         if (keymap->types[i].name == name) {
1491             *type_rtrn = i;
1492             return true;
1493         }
1494     }
1495
1496     return false;
1497 }
1498
1499 /**
1500  * Assign a type to the given sym and return the Atom for the type assigned.
1501  *
1502  * Simple recipe:
1503  * - ONE_LEVEL for width 0/1
1504  * - ALPHABETIC for 2 shift levels, with lower/upercase
1505  * - KEYPAD for keypad keys.
1506  * - TWO_LEVEL for other 2 shift level keys.
1507  * and the same for four level keys.
1508  *
1509  * @param width Number of sysms in syms.
1510  * @param syms The keysyms for the given key (must be size width).
1511  * @param typeNameRtrn Set to the Atom of the type name.
1512  *
1513  * @returns true if a type could be found, false otherwise.
1514  *
1515  * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1516  *        all that fun stuff rather than just assuming there's always one
1517  *        symbol per level.
1518  */
1519 static bool
1520 FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
1521                   const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1522                   bool *autoType)
1523 {
1524     *autoType = false;
1525     if ((width == 1) || (width == 0)) {
1526         *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1527         *autoType = true;
1528     }
1529     else if (width == 2) {
1530         if (syms && xkb_keysym_is_lower(syms[0]) &&
1531             xkb_keysym_is_upper(syms[1])) {
1532             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1533         }
1534         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1535                           xkb_keysym_is_keypad(syms[1]))) {
1536             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1537             *autoType = true;
1538         }
1539         else {
1540             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1541             *autoType = true;
1542         }
1543     }
1544     else if (width <= 4) {
1545         if (syms && xkb_keysym_is_lower(syms[0]) &&
1546             xkb_keysym_is_upper(syms[1]))
1547             if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1548                 *typeNameRtrn =
1549                     xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1550             else
1551                 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1552                                                 "FOUR_LEVEL_SEMIALPHABETIC");
1553
1554         else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1555                           xkb_keysym_is_keypad(syms[1])))
1556             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1557         else
1558             *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1559         /* XXX: why not set autoType here? */
1560     }
1561     return ((width >= 0) && (width <= 4));
1562 }
1563
1564 /**
1565  * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1566  * groups, and reduce to one group if all groups are identical anyway.
1567  */
1568 static void
1569 PrepareKeyDef(KeyInfo *keyi)
1570 {
1571     xkb_group_index_t i, lastGroup;
1572     unsigned int defined;
1573     xkb_level_index_t j, width;
1574     bool identical;
1575
1576     defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
1577     /* get highest group number */
1578     for (i = XkbNumKbdGroups - 1; i > 0; i--) {
1579         if (defined & (1 << i))
1580             break;
1581     }
1582     lastGroup = i;
1583
1584     if (lastGroup == 0)
1585         return;
1586
1587     /* If there are empty groups between non-empty ones fill them with data */
1588     /* from the first group. */
1589     /* We can make a wrong assumption here. But leaving gaps is worse. */
1590     for (i = lastGroup; i > 0; i--) {
1591         if (defined & (1 << i))
1592             continue;
1593         width = keyi->numLevels[0];
1594         if (keyi->typesDefined & 1) {
1595             for (j = 0; j < width; j++) {
1596                 keyi->types[i] = keyi->types[0];
1597             }
1598             keyi->typesDefined |= 1 << i;
1599         }
1600         if ((keyi->actsDefined & 1) && !darray_empty(keyi->acts[0])) {
1601             darray_copy(keyi->acts[i], keyi->acts[0]);
1602             keyi->actsDefined |= 1 << i;
1603         }
1604         if ((keyi->symsDefined & 1) && !darray_empty(keyi->syms[0])) {
1605             darray_copy(keyi->syms[i], keyi->syms[0]);
1606             darray_copy(keyi->symsMapIndex[i], keyi->symsMapIndex[0]);
1607             darray_copy(keyi->symsMapNumEntries[i],
1608                         keyi->symsMapNumEntries[0]);
1609             keyi->symsDefined |= 1 << i;
1610         }
1611         if (defined & 1) {
1612             keyi->numLevels[i] = keyi->numLevels[0];
1613         }
1614     }
1615     /* If all groups are completely identical remove them all */
1616     /* exept the first one. */
1617     identical = true;
1618     for (i = lastGroup; i > 0; i--) {
1619         if ((keyi->numLevels[i] != keyi->numLevels[0]) ||
1620             (keyi->types[i] != keyi->types[0])) {
1621             identical = false;
1622             break;
1623         }
1624         if (!darray_same(keyi->syms[i], keyi->syms[0]) &&
1625             (darray_empty(keyi->syms[i]) || darray_empty(keyi->syms[0]) ||
1626              darray_size(keyi->syms[i]) != darray_size(keyi->syms[0]) ||
1627              memcmp(darray_mem(keyi->syms[i], 0),
1628                     darray_mem(keyi->syms[0], 0),
1629                     sizeof(xkb_keysym_t) * darray_size(keyi->syms[0])))) {
1630             identical = false;
1631             break;
1632         }
1633         if (!darray_same(keyi->symsMapIndex[i], keyi->symsMapIndex[0]) &&
1634             (darray_empty(keyi->symsMapIndex[i]) ||
1635              darray_empty(keyi->symsMapIndex[0]) ||
1636              memcmp(darray_mem(keyi->symsMapIndex[i], 0),
1637                     darray_mem(keyi->symsMapIndex[0], 0),
1638                     keyi->numLevels[0] * sizeof(int)))) {
1639             identical = false;
1640             continue;
1641         }
1642         if (!darray_same(keyi->symsMapNumEntries[i],
1643                          keyi->symsMapNumEntries[0]) &&
1644             (darray_empty(keyi->symsMapNumEntries[i]) ||
1645              darray_empty(keyi->symsMapNumEntries[0]) ||
1646              memcmp(darray_mem(keyi->symsMapNumEntries[i], 0),
1647                     darray_mem(keyi->symsMapNumEntries[0], 0),
1648                     keyi->numLevels[0] * sizeof(size_t)))) {
1649             identical = false;
1650             continue;
1651         }
1652         if (!darray_same(keyi->acts[i], keyi->acts[0]) &&
1653             (darray_empty(keyi->acts[i]) || darray_empty(keyi->acts[0]) ||
1654              memcmp(darray_mem(keyi->acts[i], 0),
1655                     darray_mem(keyi->acts[0], 0),
1656                     keyi->numLevels[0] * sizeof(union xkb_action)))) {
1657             identical = false;
1658             break;
1659         }
1660     }
1661     if (identical) {
1662         for (i = lastGroup; i > 0; i--) {
1663             keyi->numLevels[i] = 0;
1664             darray_free(keyi->syms[i]);
1665             darray_free(keyi->symsMapIndex[i]);
1666             darray_free(keyi->symsMapNumEntries[i]);
1667             darray_free(keyi->acts[i]);
1668             keyi->types[i] = 0;
1669         }
1670         keyi->symsDefined &= 1;
1671         keyi->actsDefined &= 1;
1672         keyi->typesDefined &= 1;
1673     }
1674 }
1675
1676 /**
1677  * Copy the KeyInfo into the keyboard description.
1678  *
1679  * This function recurses.
1680  */
1681 static bool
1682 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1683                xkb_keycode_t start_from)
1684 {
1685     struct xkb_keymap *keymap = info->keymap;
1686     xkb_keycode_t kc;
1687     struct xkb_key *key;
1688     size_t sizeSyms = 0;
1689     xkb_group_index_t i, nGroups;
1690     xkb_level_index_t width, tmp;
1691     struct xkb_key_type * type;
1692     bool haveActions, autoType, useAlias;
1693     unsigned types[XkbNumKbdGroups];
1694     unsigned int symIndex = 0;
1695
1696     useAlias = (start_from == 0);
1697
1698     key = FindNamedKey(keymap, keyi->name, useAlias, start_from);
1699     if (!key) {
1700         if (start_from == 0)
1701             log_lvl(info->keymap->ctx, 5,
1702                     "Key %s not found in keycodes; Symbols ignored\n",
1703                     LongKeyNameText(keyi->name));
1704         return false;
1705     }
1706     kc = XkbKeyGetKeycode(keymap, key);
1707
1708     haveActions = false;
1709     width = 0;
1710     for (i = nGroups = 0; i < XkbNumKbdGroups; i++) {
1711         if (((i + 1) > nGroups)
1712             && (((keyi->symsDefined | keyi->actsDefined) & (1 << i))
1713                 || (keyi->typesDefined) & (1 << i)))
1714             nGroups = i + 1;
1715         if (!darray_empty(keyi->acts[i]))
1716             haveActions = true;
1717         autoType = false;
1718         /* Assign the type to the key, if it is missing. */
1719         if (keyi->types[i] == XKB_ATOM_NONE) {
1720             if (keyi->dfltType != XKB_ATOM_NONE)
1721                 keyi->types[i] = keyi->dfltType;
1722             else if (FindAutomaticType(keymap, keyi->numLevels[i],
1723                                        darray_mem(keyi->syms[i], 0),
1724                                        &keyi->types[i], &autoType)) { }
1725             else
1726                 log_lvl(info->keymap->ctx, 5,
1727                         "No automatic type for %d symbols; "
1728                         "Using %s for the %s key (keycode %d)\n",
1729                         keyi->numLevels[i],
1730                         xkb_atom_text(keymap->ctx, keyi->types[i]),
1731                         LongKeyNameText(keyi->name), kc);
1732         }
1733         if (FindNamedType(keymap, keyi->types[i], &types[i])) {
1734             if (!autoType || keyi->numLevels[i] > 2)
1735                 key->explicit |= (1 << i);
1736         }
1737         else {
1738             log_lvl(info->keymap->ctx, 3,
1739                     "Type \"%s\" is not defined; "
1740                     "Using default type for the %s key (keycode %d)\n",
1741                     xkb_atom_text(keymap->ctx, keyi->types[i]),
1742                     LongKeyNameText(keyi->name), kc);
1743             /*
1744              * Index 0 is guaranteed to contain something, usually
1745              * ONE_LEVEL or at least some default one-level type.
1746              */
1747             types[i] = 0;
1748         }
1749
1750         /* if the type specifies fewer levels than the key has, shrink the key */
1751         type = &keymap->types[types[i]];
1752         if (type->num_levels < keyi->numLevels[i]) {
1753             log_lvl(info->keymap->ctx, 1,
1754                     "Type \"%s\" has %d levels, but %s has %d symbols; "
1755                     "Ignoring extra symbols\n",
1756                     xkb_atom_text(keymap->ctx, type->name),
1757                     type->num_levels,
1758                     LongKeyNameText(keyi->name),
1759                     keyi->numLevels[i]);
1760             keyi->numLevels[i] = type->num_levels;
1761         }
1762         if (keyi->numLevels[i] > width)
1763             width = keyi->numLevels[i];
1764         if (type->num_levels > width)
1765             width = type->num_levels;
1766         sizeSyms += darray_size(keyi->syms[i]);
1767     }
1768
1769     darray_resize0(key->syms, sizeSyms);
1770
1771     key->num_groups = nGroups;
1772
1773     key->width = width;
1774
1775     key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1776
1777     key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1778
1779     if (haveActions) {
1780         key->actions = calloc(nGroups * width, sizeof(*key->actions));
1781         key->explicit |= XkbExplicitInterpretMask;
1782     }
1783
1784     if (keyi->defined & KEY_FIELD_GROUPINFO) {
1785         key->out_of_range_group_number = keyi->out_of_range_group_number;
1786         key->out_of_range_group_action = keyi->out_of_range_group_action;
1787     }
1788
1789     for (i = 0; i < nGroups; i++) {
1790         /* assign kt_index[i] to the index of the type in map->types.
1791          * kt_index[i] may have been set by a previous run (if we have two
1792          * layouts specified). Let's not overwrite it with the ONE_LEVEL
1793          * default group if we dont even have keys for this group anyway.
1794          *
1795          * FIXME: There should be a better fix for this.
1796          */
1797         if (keyi->numLevels[i])
1798             key->kt_index[i] = types[i];
1799         if (!darray_empty(keyi->syms[i])) {
1800             /* fill key to "width" symbols*/
1801             for (tmp = 0; tmp < width; tmp++) {
1802                 if (tmp < keyi->numLevels[i] &&
1803                     darray_item(keyi->symsMapNumEntries[i], tmp) != 0) {
1804                     memcpy(darray_mem(key->syms, symIndex),
1805                            darray_mem(keyi->syms[i],
1806                                       darray_item(keyi->symsMapIndex[i], tmp)),
1807                            darray_item(keyi->symsMapNumEntries[i],
1808                                        tmp) * sizeof(xkb_keysym_t));
1809                     key->sym_index[(i * width) + tmp] = symIndex;
1810                     key->num_syms[(i * width) + tmp] =
1811                         darray_item(keyi->symsMapNumEntries[i], tmp);
1812                     symIndex += key->num_syms[(i * width) + tmp];
1813                 }
1814                 else {
1815                     key->sym_index[(i * width) + tmp] = -1;
1816                     key->num_syms[(i * width) + tmp] = 0;
1817                 }
1818                 if (key->actions && !darray_empty(keyi->acts[i])) {
1819                     if (tmp < keyi->numLevels[i])
1820                         key->actions[tmp] = darray_item(keyi->acts[i], tmp);
1821                     else
1822                         key->actions[tmp].type = XkbSA_NoAction;
1823                 }
1824             }
1825         }
1826     }
1827
1828     if (keyi->defined & KEY_FIELD_VMODMAP) {
1829         key->vmodmap = keyi->vmodmap;
1830         key->explicit |= XkbExplicitVModMapMask;
1831     }
1832
1833     if (keyi->repeat != KEY_REPEAT_UNDEFINED) {
1834         key->repeats = (keyi->repeat == KEY_REPEAT_YES);
1835         key->explicit |= XkbExplicitAutoRepeatMask;
1836     }
1837
1838     /* do the same thing for the next key */
1839     CopySymbolsDef(info, keyi, kc + 1);
1840     return true;
1841 }
1842
1843 static bool
1844 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1845 {
1846     struct xkb_key *key;
1847     struct xkb_keymap *keymap = info->keymap;
1848
1849     if (!entry->haveSymbol) {
1850         key = FindNamedKey(keymap, entry->u.keyName, true, 0);
1851         if (!key) {
1852             log_lvl(info->keymap->ctx, 5,
1853                     "Key %s not found in keycodes; "
1854                     "Modifier map entry for %s not updated\n",
1855                     LongKeyNameText(entry->u.keyName),
1856                     ModIndexText(entry->modifier));
1857             return false;
1858         }
1859     }
1860     else {
1861         key = FindKeyForSymbol(keymap, entry->u.keySym);
1862         if (!key) {
1863             log_lvl(info->keymap->ctx, 5,
1864                     "Key \"%s\" not found in symbol map; "
1865                     "Modifier map entry for %s not updated\n",
1866                     KeysymText(entry->u.keySym),
1867                     ModIndexText(entry->modifier));
1868             return false;
1869         }
1870     }
1871
1872     key->modmap |= (1 << entry->modifier);
1873     return true;
1874 }
1875
1876 /**
1877  * Handle the xkb_symbols section of an xkb file.
1878  *
1879  * @param file The parsed xkb_symbols section of the xkb file.
1880  * @param keymap Handle to the keyboard description to store the symbols in.
1881  * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1882  */
1883 bool
1884 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1885                enum merge_mode merge)
1886 {
1887     xkb_group_index_t i;
1888     struct xkb_key *key;
1889     SymbolsInfo info;
1890     KeyInfo *keyi;
1891     ModMapEntry *mm;
1892
1893     InitSymbolsInfo(&info, keymap, file->id);
1894     info.dflt.merge = merge;
1895
1896     HandleSymbolsFile(&info, file, merge);
1897
1898     if (darray_empty(info.keys))
1899         goto err_info;
1900
1901     if (info.errorCount != 0)
1902         goto err_info;
1903
1904     if (info.name)
1905         keymap->symbols_section_name = strdup(info.name);
1906
1907     for (i = 0; i < XkbNumKbdGroups; i++) {
1908         if (info.groupNames[i] != XKB_ATOM_NONE) {
1909             keymap->group_names[i] = xkb_atom_text(keymap->ctx,
1910                                                    info.groupNames[i]);
1911         }
1912     }
1913
1914     /* sanitize keys */
1915     darray_foreach(keyi, info.keys)
1916         PrepareKeyDef(keyi);
1917
1918     /* copy! */
1919     darray_foreach(keyi, info.keys)
1920         if (!CopySymbolsDef(&info, keyi, 0))
1921             info.errorCount++;
1922
1923     if (xkb_get_log_verbosity(keymap->ctx) > 3) {
1924         xkb_foreach_key(key, keymap) {
1925             if (key->name[0] == '\0')
1926                 continue;
1927
1928             if (key->num_groups < 1)
1929                 log_info(info.keymap->ctx,
1930                          "No symbols defined for %s (keycode %d)\n",
1931                          KeyNameText(key->name),
1932                          XkbKeyGetKeycode(keymap, key));
1933         }
1934     }
1935
1936     list_foreach(mm, &info.modMaps, entry)
1937         if (!CopyModMapDef(&info, mm))
1938             info.errorCount++;
1939
1940     FreeSymbolsInfo(&info);
1941     return true;
1942
1943 err_info:
1944     FreeSymbolsInfo(&info);
1945     return false;
1946 }