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