xkbcomp: handle XKB file include's better
[platform/upstream/libxkbcommon.git] / src / xkbcomp / keycodes.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 "keycodes.h"
31 #include "include.h"
32
33 /*
34  * The xkb_keycodes section
35  * ========================
36  *
37  * This is the simplest section type, and is the first one to be
38  * compiled. The purpose of this is mostly to map between the
39  * hardware/evdev scancodes and xkb keycodes. Each key is given a name
40  * by which it can be referred to later, e.g. in the symbols section.
41  *
42  * Keycode statements
43  * ------------------
44  * Statements of the form:
45  *      <TLDE> = 49;
46  *      <AE01> = 10;
47  *
48  * The above would let 49 and 10 be valid keycodes in the keymap, and
49  * assign them the names TLDE and AE01 respectively. The format <WXYZ> is
50  * always used to refer to a key by name.
51  *
52  * [ The naming convention <AE01> just denoted the position of the key
53  * in the main alphanumric section of the keyboard, with the two letters
54  * specifying the row and the two digits specifying the column, from
55  * the bottom left.]
56  *
57  * In the common case this just maps to the evdev scancodes from
58  * /usr/include/linux/input.h, e.g. the following definitions:
59  *      #define KEY_GRAVE            41
60  *      #define KEY_1                2
61  * Similar definitions appear in the xf86-input-keyboard driver. Note
62  * that in all current keymaps there's a constant offset of 8 (for
63  * historical reasons).
64  *
65  * If there's a conflict, like the same name given to different keycodes,
66  * or same keycode given different names, it is resolved according to the
67  * merge mode which applies to the definitions.
68  *
69  * Alias statements
70  * ----------------
71  * Statements of the form:
72  *      alias <MENU> = <COMP>;
73  *
74  * Allows to refer to a previously defined key (here <COMP>) by another
75  * name (here <MENU>). Conflicts are handled similarly.
76  *
77  * LED name statements
78  * -------------------------
79  * Statements of the form:
80  *      indicator 1 = "Caps Lock";
81  *      indicator 2 = "Num Lock";
82  *      indicator 3 = "Scroll Lock";
83  *
84  * Assigns a name to the keyboard LED (a.k.a indicator) with the given index.
85  * The led may be referred by this name later in the compat section
86  * and by the user.
87  *
88  * Effect on the keymap
89  * --------------------
90  * After all of the xkb_keycodes sections have been compiled, the
91  * following members of struct xkb_keymap are finalized:
92  *      xkb_keycode_t min_key_code;
93  *      xkb_keycode_t max_key_code;
94  *      darray(struct xkb_key_alias) key_aliases;
95  *      char *keycodes_section_name;
96  * The 'name' field of leds declared in xkb_keycodes:
97  *      darray(struct xkb_led) leds;
98  * Further, the array of keys:
99  *      struct xkb_key *keys;
100  * had been resized to its final size (i.e. all of the xkb_key objects are
101  * referable by their keycode). However the objects themselves do not
102  * contain any useful information besides the key name at this point.
103  */
104
105 typedef struct {
106     enum merge_mode merge;
107     unsigned file_id;
108
109     xkb_atom_t alias;
110     xkb_atom_t real;
111 } AliasInfo;
112
113 typedef struct {
114     unsigned file_id;
115
116     xkb_atom_t name;
117 } KeyNameInfo;
118
119 typedef struct {
120     enum merge_mode merge;
121     unsigned file_id;
122
123     xkb_atom_t name;
124 } LedNameInfo;
125
126 typedef struct {
127     char *name;
128     int errorCount;
129     enum merge_mode merge;
130     unsigned file_id;
131
132     xkb_keycode_t min_key_code;
133     xkb_keycode_t max_key_code;
134     darray(KeyNameInfo) key_names;
135     darray(LedNameInfo) led_names;
136     darray(AliasInfo) aliases;
137
138     struct xkb_context *ctx;
139 } KeyNamesInfo;
140
141 /***====================================================================***/
142
143 static void
144 InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id,
145               xkb_atom_t alias, xkb_atom_t real)
146 {
147     memset(info, 0, sizeof(*info));
148     info->merge = merge;
149     info->file_id = file_id;
150     info->alias = alias;
151     info->real = real;
152 }
153
154 static LedNameInfo *
155 FindLedByName(KeyNamesInfo *info, xkb_atom_t name,
156               xkb_led_index_t *idx_out)
157 {
158     LedNameInfo *ledi;
159     xkb_led_index_t idx;
160
161     darray_enumerate(idx, ledi, info->led_names) {
162         if (ledi->name == name) {
163             *idx_out = idx;
164             return ledi;
165         }
166     }
167
168     return NULL;
169 }
170
171 static bool
172 AddLedName(KeyNamesInfo *info, enum merge_mode merge,
173            LedNameInfo *new, xkb_led_index_t new_idx)
174 {
175     xkb_led_index_t old_idx;
176     LedNameInfo *old;
177     const int verbosity = xkb_context_get_log_verbosity(info->ctx);
178     const bool replace = (merge == MERGE_REPLACE || merge == MERGE_OVERRIDE);
179
180     /* Inidicator with the same name already exists. */
181     old = FindLedByName(info, new->name, &old_idx);
182     if (old) {
183         const bool report = ((old->file_id == new->file_id && verbosity > 0) ||
184                              verbosity > 9);
185
186         if (old_idx == new_idx) {
187             log_warn(info->ctx,
188                      "Multiple indicators named \"%s\"; "
189                      "Identical definitions ignored\n",
190                      xkb_atom_text(info->ctx, new->name));
191             return true;
192         }
193
194         if (report) {
195             xkb_led_index_t use = (replace ? new_idx + 1 : old_idx + 1);
196             xkb_led_index_t ignore = (replace ? old_idx + 1 : new_idx + 1);
197             log_warn(info->ctx,
198                      "Multiple indicators named %s; Using %d, ignoring %d\n",
199                      xkb_atom_text(info->ctx, new->name), use, ignore);
200         }
201
202         if (replace)
203             *old = *new;
204
205         return true;
206     }
207
208     if (new_idx >= darray_size(info->led_names))
209         darray_resize0(info->led_names, new_idx + 1);
210
211     /* Inidicator with the same index already exists. */
212     old = &darray_item(info->led_names, new_idx);
213     if (old->name != XKB_ATOM_NONE) {
214         const bool report = ((old->file_id == new->file_id && verbosity > 0) ||
215                              verbosity > 9);
216
217         /* Same name case already handled above. */
218
219         if (report) {
220             const xkb_atom_t use = (replace ? new->name : old->name);
221             const xkb_atom_t ignore = (replace ? old->name : new->name);
222             log_warn(info->ctx, "Multiple names for indicator %d; "
223                      "Using %s, ignoring %s\n", new_idx + 1,
224                      xkb_atom_text(info->ctx, use),
225                      xkb_atom_text(info->ctx, ignore));
226         }
227
228         if (replace)
229             *old = *new;
230
231         return true;
232     }
233
234     darray_item(info->led_names, new_idx) = *new;
235     return true;
236 }
237
238 static void
239 ClearKeyNamesInfo(KeyNamesInfo *info)
240 {
241     free(info->name);
242     darray_free(info->key_names);
243     darray_free(info->aliases);
244     darray_free(info->led_names);
245 }
246
247 static void
248 InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
249                  unsigned file_id)
250 {
251     memset(info, 0, sizeof(*info));
252     info->ctx = ctx;
253     info->merge = MERGE_DEFAULT;
254     info->file_id = file_id;
255     info->min_key_code = XKB_KEYCODE_MAX;
256 }
257
258 static xkb_keycode_t
259 FindKeyByName(KeyNamesInfo * info, xkb_atom_t name)
260 {
261     xkb_keycode_t i;
262
263     for (i = info->min_key_code; i <= info->max_key_code; i++)
264         if (darray_item(info->key_names, i).name == name)
265             return i;
266
267     return XKB_KEYCODE_INVALID;
268 }
269
270 static bool
271 AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, xkb_atom_t name,
272            enum merge_mode merge, unsigned file_id, bool report)
273 {
274     KeyNameInfo *namei;
275     xkb_keycode_t old;
276     const int verbosity = xkb_context_get_log_verbosity(info->ctx);
277
278     if (kc >= darray_size(info->key_names))
279         darray_resize0(info->key_names, kc + 1);
280
281     info->min_key_code = MIN(info->min_key_code, kc);
282     info->max_key_code = MAX(info->max_key_code, kc);
283
284     namei = &darray_item(info->key_names, kc);
285
286     report = report && ((verbosity > 0 && file_id == namei->file_id) ||
287                         verbosity > 7);
288
289     if (namei->name != 0) {
290         const char *lname = KeyNameText(info->ctx, namei->name);
291         const char *kname = KeyNameText(info->ctx, name);
292
293         if (namei->name == name) {
294             if (report)
295                 log_warn(info->ctx,
296                          "Multiple identical key name definitions; "
297                          "Later occurrences of \"%s = %d\" ignored\n",
298                          lname, kc);
299             return true;
300         }
301         else if (merge == MERGE_AUGMENT) {
302             if (report)
303                 log_warn(info->ctx,
304                          "Multiple names for keycode %d; "
305                          "Using %s, ignoring %s\n", kc, lname, kname);
306             return true;
307         }
308         else {
309             if (report)
310                 log_warn(info->ctx,
311                          "Multiple names for keycode %d; "
312                          "Using %s, ignoring %s\n", kc, kname, lname);
313             namei->name = 0;
314             namei->file_id = 0;
315         }
316     }
317
318     old = FindKeyByName(info, name);
319     if (old != XKB_KEYCODE_INVALID && old != kc) {
320         const char *kname = KeyNameText(info->ctx, name);
321
322         if (merge == MERGE_OVERRIDE) {
323             darray_item(info->key_names, old).name = 0;
324             darray_item(info->key_names, old).file_id = 0;
325             if (report)
326                 log_warn(info->ctx,
327                          "Key name %s assigned to multiple keys; "
328                          "Using %d, ignoring %d\n", kname, kc, old);
329         }
330         else {
331             if (report)
332                 log_vrb(info->ctx, 3,
333                         "Key name %s assigned to multiple keys; "
334                         "Using %d, ignoring %d\n", kname, old, kc);
335             return true;
336         }
337     }
338
339     namei->name = name;
340     namei->file_id = file_id;
341     return true;
342 }
343
344 /***====================================================================***/
345
346 static int
347 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
348                unsigned file_id);
349
350 static bool
351 MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
352 {
353     AliasInfo *alias;
354     KeyAliasDef def;
355
356     if (darray_empty(from->aliases))
357         return true;
358
359     if (darray_empty(into->aliases)) {
360         into->aliases = from->aliases;
361         darray_init(from->aliases);
362         return true;
363     }
364
365     memset(&def, 0, sizeof(def));
366
367     darray_foreach(alias, from->aliases) {
368         def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
369         def.alias = alias->alias;
370         def.real = alias->real;
371
372         if (!HandleAliasDef(into, &def, def.merge, alias->file_id))
373             return false;
374     }
375
376     return true;
377 }
378
379 static void
380 MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
381                       enum merge_mode merge)
382 {
383     xkb_keycode_t i;
384     xkb_led_index_t idx;
385     LedNameInfo *ledi;
386
387     if (from->errorCount > 0) {
388         into->errorCount += from->errorCount;
389         return;
390     }
391
392     if (into->name == NULL) {
393         into->name = from->name;
394         from->name = NULL;
395     }
396
397     if (darray_size(into->key_names) < darray_size(from->key_names))
398         darray_resize0(into->key_names, darray_size(from->key_names));
399
400     for (i = from->min_key_code; i <= from->max_key_code; i++) {
401         xkb_atom_t name = darray_item(from->key_names, i).name;
402         if (name == XKB_ATOM_NONE)
403             continue;
404
405         if (!AddKeyName(into, i, name, merge, from->file_id, false))
406             into->errorCount++;
407     }
408
409     darray_enumerate(idx, ledi, from->led_names) {
410         if (ledi->name == XKB_ATOM_NONE)
411             continue;
412
413         ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
414         if (!AddLedName(into, ledi->merge, ledi, idx))
415             into->errorCount++;
416     }
417
418     if (!MergeAliases(into, from, merge))
419         into->errorCount++;
420 }
421
422 static void
423 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge);
424
425 static bool
426 HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *include)
427 {
428     KeyNamesInfo included;
429
430     InitKeyNamesInfo(&included, info->ctx, info->file_id);
431     included.name = include->stmt;
432     include->stmt = NULL;
433
434     for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
435         KeyNamesInfo next_incl;
436         XkbFile *file;
437
438         file = ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_KEYCODES);
439         if (!file) {
440             info->errorCount += 10;
441             ClearKeyNamesInfo(&included);
442             return false;
443         }
444
445         InitKeyNamesInfo(&next_incl, info->ctx, file->id);
446
447         HandleKeycodesFile(&next_incl, file, MERGE_OVERRIDE);
448
449         MergeIncludedKeycodes(&included, &next_incl, stmt->merge);
450
451         ClearKeyNamesInfo(&next_incl);
452         FreeXkbFile(file);
453     }
454
455     MergeIncludedKeycodes(info, &included, include->merge);
456     ClearKeyNamesInfo(&included);
457
458     return (info->errorCount == 0);
459 }
460
461 static bool
462 HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
463 {
464     if (stmt->merge != MERGE_DEFAULT) {
465         if (stmt->merge == MERGE_REPLACE)
466             merge = MERGE_OVERRIDE;
467         else
468             merge = stmt->merge;
469     }
470
471     if (stmt->value < 0 || stmt->value > XKB_KEYCODE_MAX) {
472         log_err(info->ctx,
473                 "Illegal keycode %lld: must be between 0..%u; "
474                 "Key ignored\n", (long long) stmt->value, XKB_KEYCODE_MAX);
475         return false;
476     }
477
478     return AddKeyName(info, stmt->value, stmt->name, merge,
479                       info->file_id, true);
480 }
481
482 static void
483 HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
484 {
485     const int verbosity = xkb_context_get_log_verbosity(info->ctx);
486     const bool report = ((new->file_id == old->file_id && verbosity > 0) ||
487                          verbosity > 9);
488
489     if (new->real == old->real) {
490         if (report)
491             log_warn(info->ctx, "Alias of %s for %s declared more than once; "
492                      "First definition ignored\n",
493                      KeyNameText(info->ctx, new->alias),
494                      KeyNameText(info->ctx, new->real));
495     }
496     else {
497         xkb_atom_t use, ignore;
498
499         use = (new->merge == MERGE_AUGMENT ? old->real : new->real);
500         ignore = (new->merge == MERGE_AUGMENT ? new->real : old->real);
501
502         if (report)
503             log_warn(info->ctx, "Multiple definitions for alias %s; "
504                      "Using %s, ignoring %s\n",
505                      KeyNameText(info->ctx, old->alias),
506                      KeyNameText(info->ctx, use),
507                      KeyNameText(info->ctx, ignore));
508
509         old->real = use;
510     }
511
512     old->file_id = new->file_id;
513     old->merge = new->merge;
514 }
515
516 static int
517 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
518                unsigned file_id)
519 {
520     AliasInfo *alias, new;
521
522     darray_foreach(alias, info->aliases) {
523         if (alias->alias == def->alias) {
524             InitAliasInfo(&new, merge, file_id, def->alias, def->real);
525             HandleAliasCollision(info, alias, &new);
526             return true;
527         }
528     }
529
530     InitAliasInfo(&new, merge, file_id, def->alias, def->real);
531     darray_append(info->aliases, new);
532     return true;
533 }
534
535 static int
536 HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
537 {
538     const char *elem, *field;
539     ExprDef *arrayNdx;
540
541     if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field, &arrayNdx))
542         return false;
543
544     if (elem) {
545         log_err(info->ctx, "Unknown element %s encountered; "
546                 "Default for field %s ignored\n", elem, field);
547         return false;
548     }
549
550     if (!istreq(field, "minimum") && !istreq(field, "maximum")) {
551         log_err(info->ctx, "Unknown field encountered; "
552                 "Assignment to field %s ignored\n", field);
553         return false;
554     }
555
556     /* We ignore explicit min/max statements, we always use computed. */
557     return true;
558 }
559
560 static int
561 HandleLedNameDef(KeyNamesInfo *info, LedNameDef *def,
562                  enum merge_mode merge)
563 {
564     LedNameInfo ledi;
565     xkb_atom_t name;
566
567     if (def->ndx < 1 || def->ndx > XKB_MAX_LEDS) {
568         info->errorCount++;
569         log_err(info->ctx,
570                 "Illegal indicator index (%d) specified; must be between 1 .. %d; "
571                 "Ignored\n", def->ndx, XKB_MAX_LEDS);
572         return false;
573     }
574
575     if (!ExprResolveString(info->ctx, def->name, &name)) {
576         char buf[20];
577         snprintf(buf, sizeof(buf), "%d", def->ndx);
578         info->errorCount++;
579         return ReportBadType(info->ctx, "indicator", "name", buf, "string");
580     }
581
582     ledi.merge = info->merge;
583     ledi.file_id = info->file_id;
584     ledi.name = name;
585     return AddLedName(info, merge, &ledi, def->ndx - 1);
586 }
587
588 static void
589 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
590 {
591     bool ok;
592
593     free(info->name);
594     info->name = strdup_safe(file->name);
595
596     for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) {
597         switch (stmt->type) {
598         case STMT_INCLUDE:
599             ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
600             break;
601         case STMT_KEYCODE:
602             ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
603             break;
604         case STMT_ALIAS:
605             ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
606                                 info->file_id);
607             break;
608         case STMT_VAR:
609             ok = HandleKeyNameVar(info, (VarDef *) stmt);
610             break;
611         case STMT_LED_NAME:
612             ok = HandleLedNameDef(info, (LedNameDef *) stmt, merge);
613             break;
614         default:
615             log_err(info->ctx,
616                     "Keycode files may define key and indicator names only; "
617                     "Ignoring %s\n", stmt_type_to_string(stmt->type));
618             ok = false;
619             break;
620         }
621
622         if (!ok)
623             info->errorCount++;
624
625         if (info->errorCount > 10) {
626             log_err(info->ctx, "Abandoning keycodes file \"%s\"\n",
627                     file->topName);
628             break;
629         }
630     }
631 }
632
633 /***====================================================================***/
634
635 static void
636 CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap)
637 {
638     struct xkb_key *key;
639     struct xkb_key_alias *a, new;
640     AliasInfo *alias;
641
642     darray_foreach(alias, info->aliases) {
643         /* Check that ->real is a key. */
644         key = FindNamedKey(keymap, alias->real, false);
645         if (!key) {
646             log_vrb(info->ctx, 5,
647                     "Attempt to alias %s to non-existent key %s; Ignored\n",
648                     KeyNameText(info->ctx, alias->alias),
649                     KeyNameText(info->ctx, alias->real));
650             continue;
651         }
652
653         /* Check that ->alias is not a key. */
654         key = FindNamedKey(keymap, alias->alias, false);
655         if (key) {
656             log_vrb(info->ctx, 5,
657                     "Attempt to create alias with the name of a real key; "
658                     "Alias \"%s = %s\" ignored\n",
659                     KeyNameText(info->ctx, alias->alias),
660                     KeyNameText(info->ctx, alias->real));
661             continue;
662         }
663
664         /* Check that ->alias in not already an alias, and if so handle it. */
665         darray_foreach(a, keymap->key_aliases) {
666             AliasInfo old_alias;
667
668             if (a->alias != alias->alias)
669                 continue;
670
671             InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real);
672             HandleAliasCollision(info, &old_alias, alias);
673             a->alias = old_alias.alias;
674             a->real = old_alias.real;
675             alias->alias = 0;
676         }
677         if (alias->alias == 0)
678             continue;
679
680         /* Add the alias. */
681         new.alias = alias->alias;
682         new.real = alias->real;
683         darray_append(keymap->key_aliases, new);
684     }
685
686     darray_free(info->aliases);
687 }
688
689 static bool
690 CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
691 {
692     xkb_keycode_t kc;
693     xkb_led_index_t idx;
694     LedNameInfo *ledi;
695
696     keymap->keys = calloc(info->max_key_code + 1, sizeof(*keymap->keys));
697     if (!keymap->keys)
698         return false;
699
700     keymap->min_key_code = info->min_key_code;
701     keymap->max_key_code = info->max_key_code;
702
703     for (kc = info->min_key_code; kc <= info->max_key_code; kc++) {
704         keymap->keys[kc].keycode = kc;
705         keymap->keys[kc].name = darray_item(info->key_names, kc).name;
706     }
707
708     keymap->keycodes_section_name = strdup_safe(info->name);
709
710     darray_resize0(keymap->leds, darray_size(info->led_names));
711     darray_enumerate(idx, ledi, info->led_names) {
712         if (ledi->name == XKB_ATOM_NONE)
713             continue;
714
715         darray_item(keymap->leds, idx).name = ledi->name;
716     }
717
718     CopyAliasesToKeymap(info, keymap);
719
720     return true;
721 }
722
723 /***====================================================================***/
724
725 bool
726 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
727                 enum merge_mode merge)
728 {
729     KeyNamesInfo info;
730
731     InitKeyNamesInfo(&info, keymap->ctx, file->id);
732
733     HandleKeycodesFile(&info, file, merge);
734     if (info.errorCount != 0)
735         goto err_info;
736
737     if (!CopyKeyNamesToKeymap(keymap, &info))
738         goto err_info;
739
740     ClearKeyNamesInfo(&info);
741     return true;
742
743 err_info:
744     ClearKeyNamesInfo(&info);
745     return false;
746 }
747
748 /***====================================================================***/
749
750 struct xkb_key *
751 FindNamedKey(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases)
752 {
753     struct xkb_key *key;
754
755     xkb_foreach_key(key, keymap)
756         if (key->name == name)
757             return key;
758
759     if (use_aliases) {
760         xkb_atom_t new_name;
761         if (FindKeyNameForAlias(keymap, name, &new_name))
762             return FindNamedKey(keymap, new_name, false);
763     }
764
765     return NULL;
766 }
767
768 bool
769 FindKeyNameForAlias(struct xkb_keymap *keymap, xkb_atom_t name,
770                     xkb_atom_t *real_name)
771 {
772     const struct xkb_key_alias *a;
773
774     darray_foreach(a, keymap->key_aliases) {
775         if (name == a->alias) {
776             *real_name = a->real;
777             return true;
778         }
779     }
780
781     return false;
782 }