xref: /aosp_15_r20/external/libxkbcommon/src/xkbcomp/compat.c (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard Worker /************************************************************
2*2b949d04SAndroid Build Coastguard Worker  * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3*2b949d04SAndroid Build Coastguard Worker  *
4*2b949d04SAndroid Build Coastguard Worker  * Permission to use, copy, modify, and distribute this
5*2b949d04SAndroid Build Coastguard Worker  * software and its documentation for any purpose and without
6*2b949d04SAndroid Build Coastguard Worker  * fee is hereby granted, provided that the above copyright
7*2b949d04SAndroid Build Coastguard Worker  * notice appear in all copies and that both that copyright
8*2b949d04SAndroid Build Coastguard Worker  * notice and this permission notice appear in supporting
9*2b949d04SAndroid Build Coastguard Worker  * documentation, and that the name of Silicon Graphics not be
10*2b949d04SAndroid Build Coastguard Worker  * used in advertising or publicity pertaining to distribution
11*2b949d04SAndroid Build Coastguard Worker  * of the software without specific prior written permission.
12*2b949d04SAndroid Build Coastguard Worker  * Silicon Graphics makes no representation about the suitability
13*2b949d04SAndroid Build Coastguard Worker  * of this software for any purpose. It is provided "as is"
14*2b949d04SAndroid Build Coastguard Worker  * without any express or implied warranty.
15*2b949d04SAndroid Build Coastguard Worker  *
16*2b949d04SAndroid Build Coastguard Worker  * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17*2b949d04SAndroid Build Coastguard Worker  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18*2b949d04SAndroid Build Coastguard Worker  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19*2b949d04SAndroid Build Coastguard Worker  * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20*2b949d04SAndroid Build Coastguard Worker  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21*2b949d04SAndroid Build Coastguard Worker  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22*2b949d04SAndroid Build Coastguard Worker  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23*2b949d04SAndroid Build Coastguard Worker  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
24*2b949d04SAndroid Build Coastguard Worker  *
25*2b949d04SAndroid Build Coastguard Worker  ********************************************************/
26*2b949d04SAndroid Build Coastguard Worker 
27*2b949d04SAndroid Build Coastguard Worker /*
28*2b949d04SAndroid Build Coastguard Worker  * Copyright © 2012 Ran Benita <[email protected]>
29*2b949d04SAndroid Build Coastguard Worker  *
30*2b949d04SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
31*2b949d04SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
32*2b949d04SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
33*2b949d04SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34*2b949d04SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
35*2b949d04SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
36*2b949d04SAndroid Build Coastguard Worker  *
37*2b949d04SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
38*2b949d04SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
39*2b949d04SAndroid Build Coastguard Worker  * Software.
40*2b949d04SAndroid Build Coastguard Worker  *
41*2b949d04SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42*2b949d04SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43*2b949d04SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
44*2b949d04SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45*2b949d04SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46*2b949d04SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47*2b949d04SAndroid Build Coastguard Worker  * DEALINGS IN THE SOFTWARE.
48*2b949d04SAndroid Build Coastguard Worker  */
49*2b949d04SAndroid Build Coastguard Worker 
50*2b949d04SAndroid Build Coastguard Worker #include "config.h"
51*2b949d04SAndroid Build Coastguard Worker 
52*2b949d04SAndroid Build Coastguard Worker #include "xkbcomp-priv.h"
53*2b949d04SAndroid Build Coastguard Worker #include "text.h"
54*2b949d04SAndroid Build Coastguard Worker #include "expr.h"
55*2b949d04SAndroid Build Coastguard Worker #include "action.h"
56*2b949d04SAndroid Build Coastguard Worker #include "vmod.h"
57*2b949d04SAndroid Build Coastguard Worker #include "include.h"
58*2b949d04SAndroid Build Coastguard Worker 
59*2b949d04SAndroid Build Coastguard Worker enum si_field {
60*2b949d04SAndroid Build Coastguard Worker     SI_FIELD_VIRTUAL_MOD = (1 << 0),
61*2b949d04SAndroid Build Coastguard Worker     SI_FIELD_ACTION = (1 << 1),
62*2b949d04SAndroid Build Coastguard Worker     SI_FIELD_AUTO_REPEAT = (1 << 2),
63*2b949d04SAndroid Build Coastguard Worker     SI_FIELD_LEVEL_ONE_ONLY = (1 << 3),
64*2b949d04SAndroid Build Coastguard Worker };
65*2b949d04SAndroid Build Coastguard Worker 
66*2b949d04SAndroid Build Coastguard Worker typedef struct {
67*2b949d04SAndroid Build Coastguard Worker     enum si_field defined;
68*2b949d04SAndroid Build Coastguard Worker     enum merge_mode merge;
69*2b949d04SAndroid Build Coastguard Worker 
70*2b949d04SAndroid Build Coastguard Worker     struct xkb_sym_interpret interp;
71*2b949d04SAndroid Build Coastguard Worker } SymInterpInfo;
72*2b949d04SAndroid Build Coastguard Worker 
73*2b949d04SAndroid Build Coastguard Worker enum led_field {
74*2b949d04SAndroid Build Coastguard Worker     LED_FIELD_MODS = (1 << 0),
75*2b949d04SAndroid Build Coastguard Worker     LED_FIELD_GROUPS = (1 << 1),
76*2b949d04SAndroid Build Coastguard Worker     LED_FIELD_CTRLS = (1 << 2),
77*2b949d04SAndroid Build Coastguard Worker };
78*2b949d04SAndroid Build Coastguard Worker 
79*2b949d04SAndroid Build Coastguard Worker typedef struct {
80*2b949d04SAndroid Build Coastguard Worker     enum led_field defined;
81*2b949d04SAndroid Build Coastguard Worker     enum merge_mode merge;
82*2b949d04SAndroid Build Coastguard Worker 
83*2b949d04SAndroid Build Coastguard Worker     struct xkb_led led;
84*2b949d04SAndroid Build Coastguard Worker } LedInfo;
85*2b949d04SAndroid Build Coastguard Worker 
86*2b949d04SAndroid Build Coastguard Worker typedef struct {
87*2b949d04SAndroid Build Coastguard Worker     char *name;
88*2b949d04SAndroid Build Coastguard Worker     int errorCount;
89*2b949d04SAndroid Build Coastguard Worker     SymInterpInfo default_interp;
90*2b949d04SAndroid Build Coastguard Worker     darray(SymInterpInfo) interps;
91*2b949d04SAndroid Build Coastguard Worker     LedInfo default_led;
92*2b949d04SAndroid Build Coastguard Worker     LedInfo leds[XKB_MAX_LEDS];
93*2b949d04SAndroid Build Coastguard Worker     unsigned int num_leds;
94*2b949d04SAndroid Build Coastguard Worker     ActionsInfo *actions;
95*2b949d04SAndroid Build Coastguard Worker     struct xkb_mod_set mods;
96*2b949d04SAndroid Build Coastguard Worker 
97*2b949d04SAndroid Build Coastguard Worker     struct xkb_context *ctx;
98*2b949d04SAndroid Build Coastguard Worker } CompatInfo;
99*2b949d04SAndroid Build Coastguard Worker 
100*2b949d04SAndroid Build Coastguard Worker static const char *
siText(SymInterpInfo * si,CompatInfo * info)101*2b949d04SAndroid Build Coastguard Worker siText(SymInterpInfo *si, CompatInfo *info)
102*2b949d04SAndroid Build Coastguard Worker {
103*2b949d04SAndroid Build Coastguard Worker     char *buf = xkb_context_get_buffer(info->ctx, 128);
104*2b949d04SAndroid Build Coastguard Worker 
105*2b949d04SAndroid Build Coastguard Worker     if (si == &info->default_interp)
106*2b949d04SAndroid Build Coastguard Worker         return "default";
107*2b949d04SAndroid Build Coastguard Worker 
108*2b949d04SAndroid Build Coastguard Worker     snprintf(buf, 128, "%s+%s(%s)",
109*2b949d04SAndroid Build Coastguard Worker              KeysymText(info->ctx, si->interp.sym),
110*2b949d04SAndroid Build Coastguard Worker              SIMatchText(si->interp.match),
111*2b949d04SAndroid Build Coastguard Worker              ModMaskText(info->ctx, &info->mods, si->interp.mods));
112*2b949d04SAndroid Build Coastguard Worker 
113*2b949d04SAndroid Build Coastguard Worker     return buf;
114*2b949d04SAndroid Build Coastguard Worker }
115*2b949d04SAndroid Build Coastguard Worker 
116*2b949d04SAndroid Build Coastguard Worker static inline bool
ReportSINotArray(CompatInfo * info,SymInterpInfo * si,const char * field)117*2b949d04SAndroid Build Coastguard Worker ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
118*2b949d04SAndroid Build Coastguard Worker {
119*2b949d04SAndroid Build Coastguard Worker     return ReportNotArray(info->ctx, "symbol interpretation", field,
120*2b949d04SAndroid Build Coastguard Worker                           siText(si, info));
121*2b949d04SAndroid Build Coastguard Worker }
122*2b949d04SAndroid Build Coastguard Worker 
123*2b949d04SAndroid Build Coastguard Worker static inline bool
ReportSIBadType(CompatInfo * info,SymInterpInfo * si,const char * field,const char * wanted)124*2b949d04SAndroid Build Coastguard Worker ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
125*2b949d04SAndroid Build Coastguard Worker                 const char *wanted)
126*2b949d04SAndroid Build Coastguard Worker {
127*2b949d04SAndroid Build Coastguard Worker     return ReportBadType(info->ctx, "symbol interpretation", field,
128*2b949d04SAndroid Build Coastguard Worker                          siText(si, info), wanted);
129*2b949d04SAndroid Build Coastguard Worker }
130*2b949d04SAndroid Build Coastguard Worker 
131*2b949d04SAndroid Build Coastguard Worker static inline bool
ReportLedBadType(CompatInfo * info,LedInfo * ledi,const char * field,const char * wanted)132*2b949d04SAndroid Build Coastguard Worker ReportLedBadType(CompatInfo *info, LedInfo *ledi, const char *field,
133*2b949d04SAndroid Build Coastguard Worker                  const char *wanted)
134*2b949d04SAndroid Build Coastguard Worker {
135*2b949d04SAndroid Build Coastguard Worker     return ReportBadType(info->ctx, "indicator map", field,
136*2b949d04SAndroid Build Coastguard Worker                          xkb_atom_text(info->ctx, ledi->led.name),
137*2b949d04SAndroid Build Coastguard Worker                          wanted);
138*2b949d04SAndroid Build Coastguard Worker }
139*2b949d04SAndroid Build Coastguard Worker 
140*2b949d04SAndroid Build Coastguard Worker static inline bool
ReportLedNotArray(CompatInfo * info,LedInfo * ledi,const char * field)141*2b949d04SAndroid Build Coastguard Worker ReportLedNotArray(CompatInfo *info, LedInfo *ledi, const char *field)
142*2b949d04SAndroid Build Coastguard Worker {
143*2b949d04SAndroid Build Coastguard Worker     return ReportNotArray(info->ctx, "indicator map", field,
144*2b949d04SAndroid Build Coastguard Worker                           xkb_atom_text(info->ctx, ledi->led.name));
145*2b949d04SAndroid Build Coastguard Worker }
146*2b949d04SAndroid Build Coastguard Worker 
147*2b949d04SAndroid Build Coastguard Worker static void
InitCompatInfo(CompatInfo * info,struct xkb_context * ctx,ActionsInfo * actions,const struct xkb_mod_set * mods)148*2b949d04SAndroid Build Coastguard Worker InitCompatInfo(CompatInfo *info, struct xkb_context *ctx,
149*2b949d04SAndroid Build Coastguard Worker                ActionsInfo *actions, const struct xkb_mod_set *mods)
150*2b949d04SAndroid Build Coastguard Worker {
151*2b949d04SAndroid Build Coastguard Worker     memset(info, 0, sizeof(*info));
152*2b949d04SAndroid Build Coastguard Worker     info->ctx = ctx;
153*2b949d04SAndroid Build Coastguard Worker     info->actions = actions;
154*2b949d04SAndroid Build Coastguard Worker     info->mods = *mods;
155*2b949d04SAndroid Build Coastguard Worker     info->default_interp.merge = MERGE_OVERRIDE;
156*2b949d04SAndroid Build Coastguard Worker     info->default_interp.interp.virtual_mod = XKB_MOD_INVALID;
157*2b949d04SAndroid Build Coastguard Worker     info->default_led.merge = MERGE_OVERRIDE;
158*2b949d04SAndroid Build Coastguard Worker }
159*2b949d04SAndroid Build Coastguard Worker 
160*2b949d04SAndroid Build Coastguard Worker static void
ClearCompatInfo(CompatInfo * info)161*2b949d04SAndroid Build Coastguard Worker ClearCompatInfo(CompatInfo *info)
162*2b949d04SAndroid Build Coastguard Worker {
163*2b949d04SAndroid Build Coastguard Worker     free(info->name);
164*2b949d04SAndroid Build Coastguard Worker     darray_free(info->interps);
165*2b949d04SAndroid Build Coastguard Worker }
166*2b949d04SAndroid Build Coastguard Worker 
167*2b949d04SAndroid Build Coastguard Worker static SymInterpInfo *
FindMatchingInterp(CompatInfo * info,SymInterpInfo * new)168*2b949d04SAndroid Build Coastguard Worker FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
169*2b949d04SAndroid Build Coastguard Worker {
170*2b949d04SAndroid Build Coastguard Worker     SymInterpInfo *old;
171*2b949d04SAndroid Build Coastguard Worker 
172*2b949d04SAndroid Build Coastguard Worker     darray_foreach(old, info->interps)
173*2b949d04SAndroid Build Coastguard Worker         if (old->interp.sym == new->interp.sym &&
174*2b949d04SAndroid Build Coastguard Worker             old->interp.mods == new->interp.mods &&
175*2b949d04SAndroid Build Coastguard Worker             old->interp.match == new->interp.match)
176*2b949d04SAndroid Build Coastguard Worker             return old;
177*2b949d04SAndroid Build Coastguard Worker 
178*2b949d04SAndroid Build Coastguard Worker     return NULL;
179*2b949d04SAndroid Build Coastguard Worker }
180*2b949d04SAndroid Build Coastguard Worker 
181*2b949d04SAndroid Build Coastguard Worker static bool
UseNewInterpField(enum si_field field,SymInterpInfo * old,SymInterpInfo * new,bool report,enum si_field * collide)182*2b949d04SAndroid Build Coastguard Worker UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
183*2b949d04SAndroid Build Coastguard Worker                   bool report, enum si_field *collide)
184*2b949d04SAndroid Build Coastguard Worker {
185*2b949d04SAndroid Build Coastguard Worker     if (!(old->defined & field))
186*2b949d04SAndroid Build Coastguard Worker         return true;
187*2b949d04SAndroid Build Coastguard Worker 
188*2b949d04SAndroid Build Coastguard Worker     if (new->defined & field) {
189*2b949d04SAndroid Build Coastguard Worker         if (report)
190*2b949d04SAndroid Build Coastguard Worker             *collide |= field;
191*2b949d04SAndroid Build Coastguard Worker 
192*2b949d04SAndroid Build Coastguard Worker         if (new->merge != MERGE_AUGMENT)
193*2b949d04SAndroid Build Coastguard Worker             return true;
194*2b949d04SAndroid Build Coastguard Worker     }
195*2b949d04SAndroid Build Coastguard Worker 
196*2b949d04SAndroid Build Coastguard Worker     return false;
197*2b949d04SAndroid Build Coastguard Worker }
198*2b949d04SAndroid Build Coastguard Worker 
199*2b949d04SAndroid Build Coastguard Worker static bool
AddInterp(CompatInfo * info,SymInterpInfo * new,bool same_file)200*2b949d04SAndroid Build Coastguard Worker AddInterp(CompatInfo *info, SymInterpInfo *new, bool same_file)
201*2b949d04SAndroid Build Coastguard Worker {
202*2b949d04SAndroid Build Coastguard Worker     SymInterpInfo *old = FindMatchingInterp(info, new);
203*2b949d04SAndroid Build Coastguard Worker     if (old) {
204*2b949d04SAndroid Build Coastguard Worker         const int verbosity = xkb_context_get_log_verbosity(info->ctx);
205*2b949d04SAndroid Build Coastguard Worker         const bool report = (same_file && verbosity > 0) || verbosity > 9;
206*2b949d04SAndroid Build Coastguard Worker         enum si_field collide = 0;
207*2b949d04SAndroid Build Coastguard Worker 
208*2b949d04SAndroid Build Coastguard Worker         if (new->merge == MERGE_REPLACE) {
209*2b949d04SAndroid Build Coastguard Worker             if (report)
210*2b949d04SAndroid Build Coastguard Worker                 log_warn(info->ctx,
211*2b949d04SAndroid Build Coastguard Worker                          "Multiple definitions for \"%s\"; "
212*2b949d04SAndroid Build Coastguard Worker                          "Earlier interpretation ignored\n",
213*2b949d04SAndroid Build Coastguard Worker                          siText(new, info));
214*2b949d04SAndroid Build Coastguard Worker             *old = *new;
215*2b949d04SAndroid Build Coastguard Worker             return true;
216*2b949d04SAndroid Build Coastguard Worker         }
217*2b949d04SAndroid Build Coastguard Worker 
218*2b949d04SAndroid Build Coastguard Worker         if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, report,
219*2b949d04SAndroid Build Coastguard Worker                               &collide)) {
220*2b949d04SAndroid Build Coastguard Worker             old->interp.virtual_mod = new->interp.virtual_mod;
221*2b949d04SAndroid Build Coastguard Worker             old->defined |= SI_FIELD_VIRTUAL_MOD;
222*2b949d04SAndroid Build Coastguard Worker         }
223*2b949d04SAndroid Build Coastguard Worker         if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
224*2b949d04SAndroid Build Coastguard Worker                               &collide)) {
225*2b949d04SAndroid Build Coastguard Worker             old->interp.action = new->interp.action;
226*2b949d04SAndroid Build Coastguard Worker             old->defined |= SI_FIELD_ACTION;
227*2b949d04SAndroid Build Coastguard Worker         }
228*2b949d04SAndroid Build Coastguard Worker         if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
229*2b949d04SAndroid Build Coastguard Worker                               &collide)) {
230*2b949d04SAndroid Build Coastguard Worker             old->interp.repeat = new->interp.repeat;
231*2b949d04SAndroid Build Coastguard Worker             old->defined |= SI_FIELD_AUTO_REPEAT;
232*2b949d04SAndroid Build Coastguard Worker         }
233*2b949d04SAndroid Build Coastguard Worker         if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
234*2b949d04SAndroid Build Coastguard Worker                               &collide)) {
235*2b949d04SAndroid Build Coastguard Worker             old->interp.level_one_only = new->interp.level_one_only;
236*2b949d04SAndroid Build Coastguard Worker             old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
237*2b949d04SAndroid Build Coastguard Worker         }
238*2b949d04SAndroid Build Coastguard Worker 
239*2b949d04SAndroid Build Coastguard Worker         if (collide) {
240*2b949d04SAndroid Build Coastguard Worker             log_warn(info->ctx,
241*2b949d04SAndroid Build Coastguard Worker                      "Multiple interpretations of \"%s\"; "
242*2b949d04SAndroid Build Coastguard Worker                      "Using %s definition for duplicate fields\n",
243*2b949d04SAndroid Build Coastguard Worker                      siText(new, info),
244*2b949d04SAndroid Build Coastguard Worker                      (new->merge != MERGE_AUGMENT ? "last" : "first"));
245*2b949d04SAndroid Build Coastguard Worker         }
246*2b949d04SAndroid Build Coastguard Worker 
247*2b949d04SAndroid Build Coastguard Worker         return true;
248*2b949d04SAndroid Build Coastguard Worker     }
249*2b949d04SAndroid Build Coastguard Worker 
250*2b949d04SAndroid Build Coastguard Worker     darray_append(info->interps, *new);
251*2b949d04SAndroid Build Coastguard Worker     return true;
252*2b949d04SAndroid Build Coastguard Worker }
253*2b949d04SAndroid Build Coastguard Worker 
254*2b949d04SAndroid Build Coastguard Worker /***====================================================================***/
255*2b949d04SAndroid Build Coastguard Worker 
256*2b949d04SAndroid Build Coastguard Worker static bool
ResolveStateAndPredicate(ExprDef * expr,enum xkb_match_operation * pred_rtrn,xkb_mod_mask_t * mods_rtrn,CompatInfo * info)257*2b949d04SAndroid Build Coastguard Worker ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
258*2b949d04SAndroid Build Coastguard Worker                          xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
259*2b949d04SAndroid Build Coastguard Worker {
260*2b949d04SAndroid Build Coastguard Worker     if (expr == NULL) {
261*2b949d04SAndroid Build Coastguard Worker         *pred_rtrn = MATCH_ANY_OR_NONE;
262*2b949d04SAndroid Build Coastguard Worker         *mods_rtrn = MOD_REAL_MASK_ALL;
263*2b949d04SAndroid Build Coastguard Worker         return true;
264*2b949d04SAndroid Build Coastguard Worker     }
265*2b949d04SAndroid Build Coastguard Worker 
266*2b949d04SAndroid Build Coastguard Worker     *pred_rtrn = MATCH_EXACTLY;
267*2b949d04SAndroid Build Coastguard Worker     if (expr->expr.op == EXPR_ACTION_DECL) {
268*2b949d04SAndroid Build Coastguard Worker         const char *pred_txt = xkb_atom_text(info->ctx, expr->action.name);
269*2b949d04SAndroid Build Coastguard Worker         if (!LookupString(symInterpretMatchMaskNames, pred_txt, pred_rtrn) ||
270*2b949d04SAndroid Build Coastguard Worker             !expr->action.args || expr->action.args->common.next) {
271*2b949d04SAndroid Build Coastguard Worker             log_err(info->ctx,
272*2b949d04SAndroid Build Coastguard Worker                     "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
273*2b949d04SAndroid Build Coastguard Worker             return false;
274*2b949d04SAndroid Build Coastguard Worker         }
275*2b949d04SAndroid Build Coastguard Worker         expr = expr->action.args;
276*2b949d04SAndroid Build Coastguard Worker     }
277*2b949d04SAndroid Build Coastguard Worker     else if (expr->expr.op == EXPR_IDENT) {
278*2b949d04SAndroid Build Coastguard Worker         const char *pred_txt = xkb_atom_text(info->ctx, expr->ident.ident);
279*2b949d04SAndroid Build Coastguard Worker         if (pred_txt && istreq(pred_txt, "any")) {
280*2b949d04SAndroid Build Coastguard Worker             *pred_rtrn = MATCH_ANY;
281*2b949d04SAndroid Build Coastguard Worker             *mods_rtrn = MOD_REAL_MASK_ALL;
282*2b949d04SAndroid Build Coastguard Worker             return true;
283*2b949d04SAndroid Build Coastguard Worker         }
284*2b949d04SAndroid Build Coastguard Worker     }
285*2b949d04SAndroid Build Coastguard Worker 
286*2b949d04SAndroid Build Coastguard Worker     return ExprResolveModMask(info->ctx, expr, MOD_REAL, &info->mods,
287*2b949d04SAndroid Build Coastguard Worker                               mods_rtrn);
288*2b949d04SAndroid Build Coastguard Worker }
289*2b949d04SAndroid Build Coastguard Worker 
290*2b949d04SAndroid Build Coastguard Worker /***====================================================================***/
291*2b949d04SAndroid Build Coastguard Worker 
292*2b949d04SAndroid Build Coastguard Worker static bool
UseNewLEDField(enum led_field field,LedInfo * old,LedInfo * new,bool report,enum led_field * collide)293*2b949d04SAndroid Build Coastguard Worker UseNewLEDField(enum led_field field, LedInfo *old, LedInfo *new,
294*2b949d04SAndroid Build Coastguard Worker                bool report, enum led_field *collide)
295*2b949d04SAndroid Build Coastguard Worker {
296*2b949d04SAndroid Build Coastguard Worker     if (!(old->defined & field))
297*2b949d04SAndroid Build Coastguard Worker         return true;
298*2b949d04SAndroid Build Coastguard Worker 
299*2b949d04SAndroid Build Coastguard Worker     if (new->defined & field) {
300*2b949d04SAndroid Build Coastguard Worker         if (report)
301*2b949d04SAndroid Build Coastguard Worker             *collide |= field;
302*2b949d04SAndroid Build Coastguard Worker 
303*2b949d04SAndroid Build Coastguard Worker         if (new->merge != MERGE_AUGMENT)
304*2b949d04SAndroid Build Coastguard Worker             return true;
305*2b949d04SAndroid Build Coastguard Worker     }
306*2b949d04SAndroid Build Coastguard Worker 
307*2b949d04SAndroid Build Coastguard Worker     return false;
308*2b949d04SAndroid Build Coastguard Worker }
309*2b949d04SAndroid Build Coastguard Worker 
310*2b949d04SAndroid Build Coastguard Worker static bool
AddLedMap(CompatInfo * info,LedInfo * new,bool same_file)311*2b949d04SAndroid Build Coastguard Worker AddLedMap(CompatInfo *info, LedInfo *new, bool same_file)
312*2b949d04SAndroid Build Coastguard Worker {
313*2b949d04SAndroid Build Coastguard Worker     enum led_field collide;
314*2b949d04SAndroid Build Coastguard Worker     const int verbosity = xkb_context_get_log_verbosity(info->ctx);
315*2b949d04SAndroid Build Coastguard Worker     const bool report = (same_file && verbosity > 0) || verbosity > 9;
316*2b949d04SAndroid Build Coastguard Worker 
317*2b949d04SAndroid Build Coastguard Worker     for (xkb_led_index_t i = 0; i < info->num_leds; i++) {
318*2b949d04SAndroid Build Coastguard Worker         LedInfo *old = &info->leds[i];
319*2b949d04SAndroid Build Coastguard Worker 
320*2b949d04SAndroid Build Coastguard Worker         if (old->led.name != new->led.name)
321*2b949d04SAndroid Build Coastguard Worker             continue;
322*2b949d04SAndroid Build Coastguard Worker 
323*2b949d04SAndroid Build Coastguard Worker         if (old->led.mods.mods == new->led.mods.mods &&
324*2b949d04SAndroid Build Coastguard Worker             old->led.groups == new->led.groups &&
325*2b949d04SAndroid Build Coastguard Worker             old->led.ctrls == new->led.ctrls &&
326*2b949d04SAndroid Build Coastguard Worker             old->led.which_mods == new->led.which_mods &&
327*2b949d04SAndroid Build Coastguard Worker             old->led.which_groups == new->led.which_groups) {
328*2b949d04SAndroid Build Coastguard Worker             old->defined |= new->defined;
329*2b949d04SAndroid Build Coastguard Worker             return true;
330*2b949d04SAndroid Build Coastguard Worker         }
331*2b949d04SAndroid Build Coastguard Worker 
332*2b949d04SAndroid Build Coastguard Worker         if (new->merge == MERGE_REPLACE) {
333*2b949d04SAndroid Build Coastguard Worker             if (report)
334*2b949d04SAndroid Build Coastguard Worker                 log_warn(info->ctx,
335*2b949d04SAndroid Build Coastguard Worker                          "Map for indicator %s redefined; "
336*2b949d04SAndroid Build Coastguard Worker                          "Earlier definition ignored\n",
337*2b949d04SAndroid Build Coastguard Worker                          xkb_atom_text(info->ctx, old->led.name));
338*2b949d04SAndroid Build Coastguard Worker             *old = *new;
339*2b949d04SAndroid Build Coastguard Worker             return true;
340*2b949d04SAndroid Build Coastguard Worker         }
341*2b949d04SAndroid Build Coastguard Worker 
342*2b949d04SAndroid Build Coastguard Worker         collide = 0;
343*2b949d04SAndroid Build Coastguard Worker         if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
344*2b949d04SAndroid Build Coastguard Worker             old->led.which_mods = new->led.which_mods;
345*2b949d04SAndroid Build Coastguard Worker             old->led.mods = new->led.mods;
346*2b949d04SAndroid Build Coastguard Worker             old->defined |= LED_FIELD_MODS;
347*2b949d04SAndroid Build Coastguard Worker         }
348*2b949d04SAndroid Build Coastguard Worker         if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
349*2b949d04SAndroid Build Coastguard Worker             old->led.which_groups = new->led.which_groups;
350*2b949d04SAndroid Build Coastguard Worker             old->led.groups = new->led.groups;
351*2b949d04SAndroid Build Coastguard Worker             old->defined |= LED_FIELD_GROUPS;
352*2b949d04SAndroid Build Coastguard Worker         }
353*2b949d04SAndroid Build Coastguard Worker         if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
354*2b949d04SAndroid Build Coastguard Worker             old->led.ctrls = new->led.ctrls;
355*2b949d04SAndroid Build Coastguard Worker             old->defined |= LED_FIELD_CTRLS;
356*2b949d04SAndroid Build Coastguard Worker         }
357*2b949d04SAndroid Build Coastguard Worker 
358*2b949d04SAndroid Build Coastguard Worker         if (collide) {
359*2b949d04SAndroid Build Coastguard Worker             log_warn(info->ctx,
360*2b949d04SAndroid Build Coastguard Worker                      "Map for indicator %s redefined; "
361*2b949d04SAndroid Build Coastguard Worker                      "Using %s definition for duplicate fields\n",
362*2b949d04SAndroid Build Coastguard Worker                      xkb_atom_text(info->ctx, old->led.name),
363*2b949d04SAndroid Build Coastguard Worker                      (new->merge == MERGE_AUGMENT ? "first" : "last"));
364*2b949d04SAndroid Build Coastguard Worker         }
365*2b949d04SAndroid Build Coastguard Worker 
366*2b949d04SAndroid Build Coastguard Worker         return true;
367*2b949d04SAndroid Build Coastguard Worker     }
368*2b949d04SAndroid Build Coastguard Worker 
369*2b949d04SAndroid Build Coastguard Worker     if (info->num_leds >= XKB_MAX_LEDS) {
370*2b949d04SAndroid Build Coastguard Worker         log_err(info->ctx,
371*2b949d04SAndroid Build Coastguard Worker                 "Too many LEDs defined (maximum %d)\n",
372*2b949d04SAndroid Build Coastguard Worker                 XKB_MAX_LEDS);
373*2b949d04SAndroid Build Coastguard Worker         return false;
374*2b949d04SAndroid Build Coastguard Worker     }
375*2b949d04SAndroid Build Coastguard Worker     info->leds[info->num_leds++] = *new;
376*2b949d04SAndroid Build Coastguard Worker     return true;
377*2b949d04SAndroid Build Coastguard Worker }
378*2b949d04SAndroid Build Coastguard Worker 
379*2b949d04SAndroid Build Coastguard Worker static void
MergeIncludedCompatMaps(CompatInfo * into,CompatInfo * from,enum merge_mode merge)380*2b949d04SAndroid Build Coastguard Worker MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
381*2b949d04SAndroid Build Coastguard Worker                         enum merge_mode merge)
382*2b949d04SAndroid Build Coastguard Worker {
383*2b949d04SAndroid Build Coastguard Worker     if (from->errorCount > 0) {
384*2b949d04SAndroid Build Coastguard Worker         into->errorCount += from->errorCount;
385*2b949d04SAndroid Build Coastguard Worker         return;
386*2b949d04SAndroid Build Coastguard Worker     }
387*2b949d04SAndroid Build Coastguard Worker 
388*2b949d04SAndroid Build Coastguard Worker     into->mods = from->mods;
389*2b949d04SAndroid Build Coastguard Worker 
390*2b949d04SAndroid Build Coastguard Worker     if (into->name == NULL) {
391*2b949d04SAndroid Build Coastguard Worker         into->name = from->name;
392*2b949d04SAndroid Build Coastguard Worker         from->name = NULL;
393*2b949d04SAndroid Build Coastguard Worker     }
394*2b949d04SAndroid Build Coastguard Worker 
395*2b949d04SAndroid Build Coastguard Worker     if (darray_empty(into->interps)) {
396*2b949d04SAndroid Build Coastguard Worker         into->interps = from->interps;
397*2b949d04SAndroid Build Coastguard Worker         darray_init(from->interps);
398*2b949d04SAndroid Build Coastguard Worker     }
399*2b949d04SAndroid Build Coastguard Worker     else {
400*2b949d04SAndroid Build Coastguard Worker         SymInterpInfo *si;
401*2b949d04SAndroid Build Coastguard Worker         darray_foreach(si, from->interps) {
402*2b949d04SAndroid Build Coastguard Worker             si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
403*2b949d04SAndroid Build Coastguard Worker             if (!AddInterp(into, si, false))
404*2b949d04SAndroid Build Coastguard Worker                 into->errorCount++;
405*2b949d04SAndroid Build Coastguard Worker         }
406*2b949d04SAndroid Build Coastguard Worker     }
407*2b949d04SAndroid Build Coastguard Worker 
408*2b949d04SAndroid Build Coastguard Worker     if (into->num_leds == 0) {
409*2b949d04SAndroid Build Coastguard Worker         memcpy(into->leds, from->leds, sizeof(*from->leds) * from->num_leds);
410*2b949d04SAndroid Build Coastguard Worker         into->num_leds = from->num_leds;
411*2b949d04SAndroid Build Coastguard Worker         from->num_leds = 0;
412*2b949d04SAndroid Build Coastguard Worker     }
413*2b949d04SAndroid Build Coastguard Worker     else {
414*2b949d04SAndroid Build Coastguard Worker         for (xkb_led_index_t i = 0; i < from->num_leds; i++) {
415*2b949d04SAndroid Build Coastguard Worker             LedInfo *ledi = &from->leds[i];
416*2b949d04SAndroid Build Coastguard Worker             ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
417*2b949d04SAndroid Build Coastguard Worker             if (!AddLedMap(into, ledi, false))
418*2b949d04SAndroid Build Coastguard Worker                 into->errorCount++;
419*2b949d04SAndroid Build Coastguard Worker         }
420*2b949d04SAndroid Build Coastguard Worker     }
421*2b949d04SAndroid Build Coastguard Worker }
422*2b949d04SAndroid Build Coastguard Worker 
423*2b949d04SAndroid Build Coastguard Worker static void
424*2b949d04SAndroid Build Coastguard Worker HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
425*2b949d04SAndroid Build Coastguard Worker 
426*2b949d04SAndroid Build Coastguard Worker static bool
HandleIncludeCompatMap(CompatInfo * info,IncludeStmt * include)427*2b949d04SAndroid Build Coastguard Worker HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
428*2b949d04SAndroid Build Coastguard Worker {
429*2b949d04SAndroid Build Coastguard Worker     CompatInfo included;
430*2b949d04SAndroid Build Coastguard Worker 
431*2b949d04SAndroid Build Coastguard Worker     InitCompatInfo(&included, info->ctx, info->actions, &info->mods);
432*2b949d04SAndroid Build Coastguard Worker     included.name = include->stmt;
433*2b949d04SAndroid Build Coastguard Worker     include->stmt = NULL;
434*2b949d04SAndroid Build Coastguard Worker 
435*2b949d04SAndroid Build Coastguard Worker     for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
436*2b949d04SAndroid Build Coastguard Worker         CompatInfo next_incl;
437*2b949d04SAndroid Build Coastguard Worker         XkbFile *file;
438*2b949d04SAndroid Build Coastguard Worker 
439*2b949d04SAndroid Build Coastguard Worker         file = ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_COMPAT);
440*2b949d04SAndroid Build Coastguard Worker         if (!file) {
441*2b949d04SAndroid Build Coastguard Worker             info->errorCount += 10;
442*2b949d04SAndroid Build Coastguard Worker             ClearCompatInfo(&included);
443*2b949d04SAndroid Build Coastguard Worker             return false;
444*2b949d04SAndroid Build Coastguard Worker         }
445*2b949d04SAndroid Build Coastguard Worker 
446*2b949d04SAndroid Build Coastguard Worker         InitCompatInfo(&next_incl, info->ctx, info->actions, &included.mods);
447*2b949d04SAndroid Build Coastguard Worker         next_incl.default_interp = info->default_interp;
448*2b949d04SAndroid Build Coastguard Worker         next_incl.default_interp.merge = stmt->merge;
449*2b949d04SAndroid Build Coastguard Worker         next_incl.default_led = info->default_led;
450*2b949d04SAndroid Build Coastguard Worker         next_incl.default_led.merge = stmt->merge;
451*2b949d04SAndroid Build Coastguard Worker 
452*2b949d04SAndroid Build Coastguard Worker         HandleCompatMapFile(&next_incl, file, MERGE_OVERRIDE);
453*2b949d04SAndroid Build Coastguard Worker 
454*2b949d04SAndroid Build Coastguard Worker         MergeIncludedCompatMaps(&included, &next_incl, stmt->merge);
455*2b949d04SAndroid Build Coastguard Worker 
456*2b949d04SAndroid Build Coastguard Worker         ClearCompatInfo(&next_incl);
457*2b949d04SAndroid Build Coastguard Worker         FreeXkbFile(file);
458*2b949d04SAndroid Build Coastguard Worker     }
459*2b949d04SAndroid Build Coastguard Worker 
460*2b949d04SAndroid Build Coastguard Worker     MergeIncludedCompatMaps(info, &included, include->merge);
461*2b949d04SAndroid Build Coastguard Worker     ClearCompatInfo(&included);
462*2b949d04SAndroid Build Coastguard Worker 
463*2b949d04SAndroid Build Coastguard Worker     return (info->errorCount == 0);
464*2b949d04SAndroid Build Coastguard Worker }
465*2b949d04SAndroid Build Coastguard Worker 
466*2b949d04SAndroid Build Coastguard Worker static bool
SetInterpField(CompatInfo * info,SymInterpInfo * si,const char * field,ExprDef * arrayNdx,ExprDef * value)467*2b949d04SAndroid Build Coastguard Worker SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
468*2b949d04SAndroid Build Coastguard Worker                ExprDef *arrayNdx, ExprDef *value)
469*2b949d04SAndroid Build Coastguard Worker {
470*2b949d04SAndroid Build Coastguard Worker     xkb_mod_index_t ndx;
471*2b949d04SAndroid Build Coastguard Worker 
472*2b949d04SAndroid Build Coastguard Worker     if (istreq(field, "action")) {
473*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
474*2b949d04SAndroid Build Coastguard Worker             return ReportSINotArray(info, si, field);
475*2b949d04SAndroid Build Coastguard Worker 
476*2b949d04SAndroid Build Coastguard Worker         if (!HandleActionDef(info->ctx, info->actions, &info->mods,
477*2b949d04SAndroid Build Coastguard Worker                              value, &si->interp.action))
478*2b949d04SAndroid Build Coastguard Worker             return false;
479*2b949d04SAndroid Build Coastguard Worker 
480*2b949d04SAndroid Build Coastguard Worker         si->defined |= SI_FIELD_ACTION;
481*2b949d04SAndroid Build Coastguard Worker     }
482*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "virtualmodifier") ||
483*2b949d04SAndroid Build Coastguard Worker              istreq(field, "virtualmod")) {
484*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
485*2b949d04SAndroid Build Coastguard Worker             return ReportSINotArray(info, si, field);
486*2b949d04SAndroid Build Coastguard Worker 
487*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveMod(info->ctx, value, MOD_VIRT, &info->mods, &ndx))
488*2b949d04SAndroid Build Coastguard Worker             return ReportSIBadType(info, si, field, "virtual modifier");
489*2b949d04SAndroid Build Coastguard Worker 
490*2b949d04SAndroid Build Coastguard Worker         si->interp.virtual_mod = ndx;
491*2b949d04SAndroid Build Coastguard Worker         si->defined |= SI_FIELD_VIRTUAL_MOD;
492*2b949d04SAndroid Build Coastguard Worker     }
493*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "repeat")) {
494*2b949d04SAndroid Build Coastguard Worker         bool set;
495*2b949d04SAndroid Build Coastguard Worker 
496*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
497*2b949d04SAndroid Build Coastguard Worker             return ReportSINotArray(info, si, field);
498*2b949d04SAndroid Build Coastguard Worker 
499*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveBoolean(info->ctx, value, &set))
500*2b949d04SAndroid Build Coastguard Worker             return ReportSIBadType(info, si, field, "boolean");
501*2b949d04SAndroid Build Coastguard Worker 
502*2b949d04SAndroid Build Coastguard Worker         si->interp.repeat = set;
503*2b949d04SAndroid Build Coastguard Worker 
504*2b949d04SAndroid Build Coastguard Worker         si->defined |= SI_FIELD_AUTO_REPEAT;
505*2b949d04SAndroid Build Coastguard Worker     }
506*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "locking")) {
507*2b949d04SAndroid Build Coastguard Worker         log_dbg(info->ctx,
508*2b949d04SAndroid Build Coastguard Worker                 "The \"locking\" field in symbol interpretation is unsupported; "
509*2b949d04SAndroid Build Coastguard Worker                 "Ignored\n");
510*2b949d04SAndroid Build Coastguard Worker     }
511*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "usemodmap") ||
512*2b949d04SAndroid Build Coastguard Worker              istreq(field, "usemodmapmods")) {
513*2b949d04SAndroid Build Coastguard Worker         unsigned int val;
514*2b949d04SAndroid Build Coastguard Worker 
515*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
516*2b949d04SAndroid Build Coastguard Worker             return ReportSINotArray(info, si, field);
517*2b949d04SAndroid Build Coastguard Worker 
518*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveEnum(info->ctx, value, &val, useModMapValueNames))
519*2b949d04SAndroid Build Coastguard Worker             return ReportSIBadType(info, si, field, "level specification");
520*2b949d04SAndroid Build Coastguard Worker 
521*2b949d04SAndroid Build Coastguard Worker         si->interp.level_one_only = val;
522*2b949d04SAndroid Build Coastguard Worker         si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
523*2b949d04SAndroid Build Coastguard Worker     }
524*2b949d04SAndroid Build Coastguard Worker     else {
525*2b949d04SAndroid Build Coastguard Worker         return ReportBadField(info->ctx, "symbol interpretation", field,
526*2b949d04SAndroid Build Coastguard Worker                               siText(si, info));
527*2b949d04SAndroid Build Coastguard Worker     }
528*2b949d04SAndroid Build Coastguard Worker 
529*2b949d04SAndroid Build Coastguard Worker     return true;
530*2b949d04SAndroid Build Coastguard Worker }
531*2b949d04SAndroid Build Coastguard Worker 
532*2b949d04SAndroid Build Coastguard Worker static bool
SetLedMapField(CompatInfo * info,LedInfo * ledi,const char * field,ExprDef * arrayNdx,ExprDef * value)533*2b949d04SAndroid Build Coastguard Worker SetLedMapField(CompatInfo *info, LedInfo *ledi, const char *field,
534*2b949d04SAndroid Build Coastguard Worker                ExprDef *arrayNdx, ExprDef *value)
535*2b949d04SAndroid Build Coastguard Worker {
536*2b949d04SAndroid Build Coastguard Worker     bool ok = true;
537*2b949d04SAndroid Build Coastguard Worker 
538*2b949d04SAndroid Build Coastguard Worker     if (istreq(field, "modifiers") || istreq(field, "mods")) {
539*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
540*2b949d04SAndroid Build Coastguard Worker             return ReportLedNotArray(info, ledi, field);
541*2b949d04SAndroid Build Coastguard Worker 
542*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveModMask(info->ctx, value, MOD_BOTH,
543*2b949d04SAndroid Build Coastguard Worker                                 &info->mods, &ledi->led.mods.mods))
544*2b949d04SAndroid Build Coastguard Worker             return ReportLedBadType(info, ledi, field, "modifier mask");
545*2b949d04SAndroid Build Coastguard Worker 
546*2b949d04SAndroid Build Coastguard Worker         ledi->defined |= LED_FIELD_MODS;
547*2b949d04SAndroid Build Coastguard Worker     }
548*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "groups")) {
549*2b949d04SAndroid Build Coastguard Worker         unsigned int mask;
550*2b949d04SAndroid Build Coastguard Worker 
551*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
552*2b949d04SAndroid Build Coastguard Worker             return ReportLedNotArray(info, ledi, field);
553*2b949d04SAndroid Build Coastguard Worker 
554*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveMask(info->ctx, value, &mask, groupMaskNames))
555*2b949d04SAndroid Build Coastguard Worker             return ReportLedBadType(info, ledi, field, "group mask");
556*2b949d04SAndroid Build Coastguard Worker 
557*2b949d04SAndroid Build Coastguard Worker         ledi->led.groups = mask;
558*2b949d04SAndroid Build Coastguard Worker         ledi->defined |= LED_FIELD_GROUPS;
559*2b949d04SAndroid Build Coastguard Worker     }
560*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "controls") || istreq(field, "ctrls")) {
561*2b949d04SAndroid Build Coastguard Worker         unsigned int mask;
562*2b949d04SAndroid Build Coastguard Worker 
563*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
564*2b949d04SAndroid Build Coastguard Worker             return ReportLedNotArray(info, ledi, field);
565*2b949d04SAndroid Build Coastguard Worker 
566*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveMask(info->ctx, value, &mask, ctrlMaskNames))
567*2b949d04SAndroid Build Coastguard Worker             return ReportLedBadType(info, ledi, field, "controls mask");
568*2b949d04SAndroid Build Coastguard Worker 
569*2b949d04SAndroid Build Coastguard Worker         ledi->led.ctrls = mask;
570*2b949d04SAndroid Build Coastguard Worker         ledi->defined |= LED_FIELD_CTRLS;
571*2b949d04SAndroid Build Coastguard Worker     }
572*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "allowexplicit")) {
573*2b949d04SAndroid Build Coastguard Worker         log_dbg(info->ctx,
574*2b949d04SAndroid Build Coastguard Worker                 "The \"allowExplicit\" field in indicator statements is unsupported; "
575*2b949d04SAndroid Build Coastguard Worker                 "Ignored\n");
576*2b949d04SAndroid Build Coastguard Worker     }
577*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "whichmodstate") ||
578*2b949d04SAndroid Build Coastguard Worker              istreq(field, "whichmodifierstate")) {
579*2b949d04SAndroid Build Coastguard Worker         unsigned int mask;
580*2b949d04SAndroid Build Coastguard Worker 
581*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
582*2b949d04SAndroid Build Coastguard Worker             return ReportLedNotArray(info, ledi, field);
583*2b949d04SAndroid Build Coastguard Worker 
584*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveMask(info->ctx, value, &mask,
585*2b949d04SAndroid Build Coastguard Worker                              modComponentMaskNames))
586*2b949d04SAndroid Build Coastguard Worker             return ReportLedBadType(info, ledi, field,
587*2b949d04SAndroid Build Coastguard Worker                                     "mask of modifier state components");
588*2b949d04SAndroid Build Coastguard Worker 
589*2b949d04SAndroid Build Coastguard Worker         ledi->led.which_mods = mask;
590*2b949d04SAndroid Build Coastguard Worker     }
591*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "whichgroupstate")) {
592*2b949d04SAndroid Build Coastguard Worker         unsigned mask;
593*2b949d04SAndroid Build Coastguard Worker 
594*2b949d04SAndroid Build Coastguard Worker         if (arrayNdx)
595*2b949d04SAndroid Build Coastguard Worker             return ReportLedNotArray(info, ledi, field);
596*2b949d04SAndroid Build Coastguard Worker 
597*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveMask(info->ctx, value, &mask,
598*2b949d04SAndroid Build Coastguard Worker                              groupComponentMaskNames))
599*2b949d04SAndroid Build Coastguard Worker             return ReportLedBadType(info, ledi, field,
600*2b949d04SAndroid Build Coastguard Worker                                     "mask of group state components");
601*2b949d04SAndroid Build Coastguard Worker 
602*2b949d04SAndroid Build Coastguard Worker         ledi->led.which_groups = mask;
603*2b949d04SAndroid Build Coastguard Worker     }
604*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "driveskbd") ||
605*2b949d04SAndroid Build Coastguard Worker              istreq(field, "driveskeyboard") ||
606*2b949d04SAndroid Build Coastguard Worker              istreq(field, "leddriveskbd") ||
607*2b949d04SAndroid Build Coastguard Worker              istreq(field, "leddriveskeyboard") ||
608*2b949d04SAndroid Build Coastguard Worker              istreq(field, "indicatordriveskbd") ||
609*2b949d04SAndroid Build Coastguard Worker              istreq(field, "indicatordriveskeyboard")) {
610*2b949d04SAndroid Build Coastguard Worker         log_dbg(info->ctx,
611*2b949d04SAndroid Build Coastguard Worker                 "The \"%s\" field in indicator statements is unsupported; "
612*2b949d04SAndroid Build Coastguard Worker                 "Ignored\n", field);
613*2b949d04SAndroid Build Coastguard Worker     }
614*2b949d04SAndroid Build Coastguard Worker     else if (istreq(field, "index")) {
615*2b949d04SAndroid Build Coastguard Worker         /* Users should see this, it might cause unexpected behavior. */
616*2b949d04SAndroid Build Coastguard Worker         log_err(info->ctx,
617*2b949d04SAndroid Build Coastguard Worker                 "The \"index\" field in indicator statements is unsupported; "
618*2b949d04SAndroid Build Coastguard Worker                 "Ignored\n");
619*2b949d04SAndroid Build Coastguard Worker     }
620*2b949d04SAndroid Build Coastguard Worker     else {
621*2b949d04SAndroid Build Coastguard Worker         log_err(info->ctx,
622*2b949d04SAndroid Build Coastguard Worker                 "Unknown field %s in map for %s indicator; "
623*2b949d04SAndroid Build Coastguard Worker                 "Definition ignored\n",
624*2b949d04SAndroid Build Coastguard Worker                 field, xkb_atom_text(info->ctx, ledi->led.name));
625*2b949d04SAndroid Build Coastguard Worker         ok = false;
626*2b949d04SAndroid Build Coastguard Worker     }
627*2b949d04SAndroid Build Coastguard Worker 
628*2b949d04SAndroid Build Coastguard Worker     return ok;
629*2b949d04SAndroid Build Coastguard Worker }
630*2b949d04SAndroid Build Coastguard Worker 
631*2b949d04SAndroid Build Coastguard Worker static bool
HandleGlobalVar(CompatInfo * info,VarDef * stmt)632*2b949d04SAndroid Build Coastguard Worker HandleGlobalVar(CompatInfo *info, VarDef *stmt)
633*2b949d04SAndroid Build Coastguard Worker {
634*2b949d04SAndroid Build Coastguard Worker     const char *elem, *field;
635*2b949d04SAndroid Build Coastguard Worker     ExprDef *ndx;
636*2b949d04SAndroid Build Coastguard Worker     bool ret;
637*2b949d04SAndroid Build Coastguard Worker 
638*2b949d04SAndroid Build Coastguard Worker     if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field, &ndx))
639*2b949d04SAndroid Build Coastguard Worker         ret = false;
640*2b949d04SAndroid Build Coastguard Worker     else if (elem && istreq(elem, "interpret"))
641*2b949d04SAndroid Build Coastguard Worker         ret = SetInterpField(info, &info->default_interp, field, ndx,
642*2b949d04SAndroid Build Coastguard Worker                              stmt->value);
643*2b949d04SAndroid Build Coastguard Worker     else if (elem && istreq(elem, "indicator"))
644*2b949d04SAndroid Build Coastguard Worker         ret = SetLedMapField(info, &info->default_led, field, ndx,
645*2b949d04SAndroid Build Coastguard Worker                              stmt->value);
646*2b949d04SAndroid Build Coastguard Worker     else
647*2b949d04SAndroid Build Coastguard Worker         ret = SetActionField(info->ctx, info->actions, &info->mods,
648*2b949d04SAndroid Build Coastguard Worker                              elem, field, ndx, stmt->value);
649*2b949d04SAndroid Build Coastguard Worker     return ret;
650*2b949d04SAndroid Build Coastguard Worker }
651*2b949d04SAndroid Build Coastguard Worker 
652*2b949d04SAndroid Build Coastguard Worker static bool
HandleInterpBody(CompatInfo * info,VarDef * def,SymInterpInfo * si)653*2b949d04SAndroid Build Coastguard Worker HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
654*2b949d04SAndroid Build Coastguard Worker {
655*2b949d04SAndroid Build Coastguard Worker     bool ok = true;
656*2b949d04SAndroid Build Coastguard Worker     const char *elem, *field;
657*2b949d04SAndroid Build Coastguard Worker     ExprDef *arrayNdx;
658*2b949d04SAndroid Build Coastguard Worker 
659*2b949d04SAndroid Build Coastguard Worker     for (; def; def = (VarDef *) def->common.next) {
660*2b949d04SAndroid Build Coastguard Worker         if (def->name && def->name->expr.op == EXPR_FIELD_REF) {
661*2b949d04SAndroid Build Coastguard Worker             log_err(info->ctx,
662*2b949d04SAndroid Build Coastguard Worker                     "Cannot set a global default value from within an interpret statement; "
663*2b949d04SAndroid Build Coastguard Worker                     "Move statements to the global file scope\n");
664*2b949d04SAndroid Build Coastguard Worker             ok = false;
665*2b949d04SAndroid Build Coastguard Worker             continue;
666*2b949d04SAndroid Build Coastguard Worker         }
667*2b949d04SAndroid Build Coastguard Worker 
668*2b949d04SAndroid Build Coastguard Worker         ok = ExprResolveLhs(info->ctx, def->name, &elem, &field, &arrayNdx);
669*2b949d04SAndroid Build Coastguard Worker         if (!ok)
670*2b949d04SAndroid Build Coastguard Worker             continue;
671*2b949d04SAndroid Build Coastguard Worker 
672*2b949d04SAndroid Build Coastguard Worker         ok = SetInterpField(info, si, field, arrayNdx, def->value);
673*2b949d04SAndroid Build Coastguard Worker     }
674*2b949d04SAndroid Build Coastguard Worker 
675*2b949d04SAndroid Build Coastguard Worker     return ok;
676*2b949d04SAndroid Build Coastguard Worker }
677*2b949d04SAndroid Build Coastguard Worker 
678*2b949d04SAndroid Build Coastguard Worker static bool
HandleInterpDef(CompatInfo * info,InterpDef * def,enum merge_mode merge)679*2b949d04SAndroid Build Coastguard Worker HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
680*2b949d04SAndroid Build Coastguard Worker {
681*2b949d04SAndroid Build Coastguard Worker     enum xkb_match_operation pred;
682*2b949d04SAndroid Build Coastguard Worker     xkb_mod_mask_t mods;
683*2b949d04SAndroid Build Coastguard Worker     SymInterpInfo si;
684*2b949d04SAndroid Build Coastguard Worker 
685*2b949d04SAndroid Build Coastguard Worker     if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
686*2b949d04SAndroid Build Coastguard Worker         log_err(info->ctx,
687*2b949d04SAndroid Build Coastguard Worker                 "Couldn't determine matching modifiers; "
688*2b949d04SAndroid Build Coastguard Worker                 "Symbol interpretation ignored\n");
689*2b949d04SAndroid Build Coastguard Worker         return false;
690*2b949d04SAndroid Build Coastguard Worker     }
691*2b949d04SAndroid Build Coastguard Worker 
692*2b949d04SAndroid Build Coastguard Worker     si = info->default_interp;
693*2b949d04SAndroid Build Coastguard Worker     si.merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
694*2b949d04SAndroid Build Coastguard Worker     si.interp.sym = def->sym;
695*2b949d04SAndroid Build Coastguard Worker     si.interp.match = pred;
696*2b949d04SAndroid Build Coastguard Worker     si.interp.mods = mods;
697*2b949d04SAndroid Build Coastguard Worker 
698*2b949d04SAndroid Build Coastguard Worker     if (!HandleInterpBody(info, def->def, &si)) {
699*2b949d04SAndroid Build Coastguard Worker         info->errorCount++;
700*2b949d04SAndroid Build Coastguard Worker         return false;
701*2b949d04SAndroid Build Coastguard Worker     }
702*2b949d04SAndroid Build Coastguard Worker 
703*2b949d04SAndroid Build Coastguard Worker     if (!AddInterp(info, &si, true)) {
704*2b949d04SAndroid Build Coastguard Worker         info->errorCount++;
705*2b949d04SAndroid Build Coastguard Worker         return false;
706*2b949d04SAndroid Build Coastguard Worker     }
707*2b949d04SAndroid Build Coastguard Worker 
708*2b949d04SAndroid Build Coastguard Worker     return true;
709*2b949d04SAndroid Build Coastguard Worker }
710*2b949d04SAndroid Build Coastguard Worker 
711*2b949d04SAndroid Build Coastguard Worker static bool
HandleLedMapDef(CompatInfo * info,LedMapDef * def,enum merge_mode merge)712*2b949d04SAndroid Build Coastguard Worker HandleLedMapDef(CompatInfo *info, LedMapDef *def, enum merge_mode merge)
713*2b949d04SAndroid Build Coastguard Worker {
714*2b949d04SAndroid Build Coastguard Worker     LedInfo ledi;
715*2b949d04SAndroid Build Coastguard Worker     VarDef *var;
716*2b949d04SAndroid Build Coastguard Worker     bool ok;
717*2b949d04SAndroid Build Coastguard Worker 
718*2b949d04SAndroid Build Coastguard Worker     if (def->merge != MERGE_DEFAULT)
719*2b949d04SAndroid Build Coastguard Worker         merge = def->merge;
720*2b949d04SAndroid Build Coastguard Worker 
721*2b949d04SAndroid Build Coastguard Worker     ledi = info->default_led;
722*2b949d04SAndroid Build Coastguard Worker     ledi.merge = merge;
723*2b949d04SAndroid Build Coastguard Worker     ledi.led.name = def->name;
724*2b949d04SAndroid Build Coastguard Worker 
725*2b949d04SAndroid Build Coastguard Worker     ok = true;
726*2b949d04SAndroid Build Coastguard Worker     for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
727*2b949d04SAndroid Build Coastguard Worker         const char *elem, *field;
728*2b949d04SAndroid Build Coastguard Worker         ExprDef *arrayNdx;
729*2b949d04SAndroid Build Coastguard Worker         if (!ExprResolveLhs(info->ctx, var->name, &elem, &field, &arrayNdx)) {
730*2b949d04SAndroid Build Coastguard Worker             ok = false;
731*2b949d04SAndroid Build Coastguard Worker             continue;
732*2b949d04SAndroid Build Coastguard Worker         }
733*2b949d04SAndroid Build Coastguard Worker 
734*2b949d04SAndroid Build Coastguard Worker         if (elem) {
735*2b949d04SAndroid Build Coastguard Worker             log_err(info->ctx,
736*2b949d04SAndroid Build Coastguard Worker                     "Cannot set defaults for \"%s\" element in indicator map; "
737*2b949d04SAndroid Build Coastguard Worker                     "Assignment to %s.%s ignored\n", elem, elem, field);
738*2b949d04SAndroid Build Coastguard Worker             ok = false;
739*2b949d04SAndroid Build Coastguard Worker         }
740*2b949d04SAndroid Build Coastguard Worker         else {
741*2b949d04SAndroid Build Coastguard Worker             ok = SetLedMapField(info, &ledi, field, arrayNdx, var->value) && ok;
742*2b949d04SAndroid Build Coastguard Worker         }
743*2b949d04SAndroid Build Coastguard Worker     }
744*2b949d04SAndroid Build Coastguard Worker 
745*2b949d04SAndroid Build Coastguard Worker     if (ok)
746*2b949d04SAndroid Build Coastguard Worker         return AddLedMap(info, &ledi, true);
747*2b949d04SAndroid Build Coastguard Worker 
748*2b949d04SAndroid Build Coastguard Worker     return false;
749*2b949d04SAndroid Build Coastguard Worker }
750*2b949d04SAndroid Build Coastguard Worker 
751*2b949d04SAndroid Build Coastguard Worker static void
HandleCompatMapFile(CompatInfo * info,XkbFile * file,enum merge_mode merge)752*2b949d04SAndroid Build Coastguard Worker HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
753*2b949d04SAndroid Build Coastguard Worker {
754*2b949d04SAndroid Build Coastguard Worker     bool ok;
755*2b949d04SAndroid Build Coastguard Worker 
756*2b949d04SAndroid Build Coastguard Worker     merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
757*2b949d04SAndroid Build Coastguard Worker 
758*2b949d04SAndroid Build Coastguard Worker     free(info->name);
759*2b949d04SAndroid Build Coastguard Worker     info->name = strdup_safe(file->name);
760*2b949d04SAndroid Build Coastguard Worker 
761*2b949d04SAndroid Build Coastguard Worker     for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) {
762*2b949d04SAndroid Build Coastguard Worker         switch (stmt->type) {
763*2b949d04SAndroid Build Coastguard Worker         case STMT_INCLUDE:
764*2b949d04SAndroid Build Coastguard Worker             ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
765*2b949d04SAndroid Build Coastguard Worker             break;
766*2b949d04SAndroid Build Coastguard Worker         case STMT_INTERP:
767*2b949d04SAndroid Build Coastguard Worker             ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
768*2b949d04SAndroid Build Coastguard Worker             break;
769*2b949d04SAndroid Build Coastguard Worker         case STMT_GROUP_COMPAT:
770*2b949d04SAndroid Build Coastguard Worker             log_dbg(info->ctx,
771*2b949d04SAndroid Build Coastguard Worker                     "The \"group\" statement in compat is unsupported; "
772*2b949d04SAndroid Build Coastguard Worker                     "Ignored\n");
773*2b949d04SAndroid Build Coastguard Worker             ok = true;
774*2b949d04SAndroid Build Coastguard Worker             break;
775*2b949d04SAndroid Build Coastguard Worker         case STMT_LED_MAP:
776*2b949d04SAndroid Build Coastguard Worker             ok = HandleLedMapDef(info, (LedMapDef *) stmt, merge);
777*2b949d04SAndroid Build Coastguard Worker             break;
778*2b949d04SAndroid Build Coastguard Worker         case STMT_VAR:
779*2b949d04SAndroid Build Coastguard Worker             ok = HandleGlobalVar(info, (VarDef *) stmt);
780*2b949d04SAndroid Build Coastguard Worker             break;
781*2b949d04SAndroid Build Coastguard Worker         case STMT_VMOD:
782*2b949d04SAndroid Build Coastguard Worker             ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt, merge);
783*2b949d04SAndroid Build Coastguard Worker             break;
784*2b949d04SAndroid Build Coastguard Worker         default:
785*2b949d04SAndroid Build Coastguard Worker             log_err(info->ctx,
786*2b949d04SAndroid Build Coastguard Worker                     "Compat files may not include other types; "
787*2b949d04SAndroid Build Coastguard Worker                     "Ignoring %s\n", stmt_type_to_string(stmt->type));
788*2b949d04SAndroid Build Coastguard Worker             ok = false;
789*2b949d04SAndroid Build Coastguard Worker             break;
790*2b949d04SAndroid Build Coastguard Worker         }
791*2b949d04SAndroid Build Coastguard Worker 
792*2b949d04SAndroid Build Coastguard Worker         if (!ok)
793*2b949d04SAndroid Build Coastguard Worker             info->errorCount++;
794*2b949d04SAndroid Build Coastguard Worker 
795*2b949d04SAndroid Build Coastguard Worker         if (info->errorCount > 10) {
796*2b949d04SAndroid Build Coastguard Worker             log_err(info->ctx,
797*2b949d04SAndroid Build Coastguard Worker                     "Abandoning compatibility map \"%s\"\n", file->name);
798*2b949d04SAndroid Build Coastguard Worker             break;
799*2b949d04SAndroid Build Coastguard Worker         }
800*2b949d04SAndroid Build Coastguard Worker     }
801*2b949d04SAndroid Build Coastguard Worker }
802*2b949d04SAndroid Build Coastguard Worker 
803*2b949d04SAndroid Build Coastguard Worker /* Temporary struct for CopyInterps. */
804*2b949d04SAndroid Build Coastguard Worker struct collect {
805*2b949d04SAndroid Build Coastguard Worker     darray(struct xkb_sym_interpret) sym_interprets;
806*2b949d04SAndroid Build Coastguard Worker };
807*2b949d04SAndroid Build Coastguard Worker 
808*2b949d04SAndroid Build Coastguard Worker static void
CopyInterps(CompatInfo * info,bool needSymbol,enum xkb_match_operation pred,struct collect * collect)809*2b949d04SAndroid Build Coastguard Worker CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred,
810*2b949d04SAndroid Build Coastguard Worker             struct collect *collect)
811*2b949d04SAndroid Build Coastguard Worker {
812*2b949d04SAndroid Build Coastguard Worker     SymInterpInfo *si;
813*2b949d04SAndroid Build Coastguard Worker 
814*2b949d04SAndroid Build Coastguard Worker     darray_foreach(si, info->interps)
815*2b949d04SAndroid Build Coastguard Worker         if (si->interp.match == pred &&
816*2b949d04SAndroid Build Coastguard Worker             (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
817*2b949d04SAndroid Build Coastguard Worker             darray_append(collect->sym_interprets, si->interp);
818*2b949d04SAndroid Build Coastguard Worker }
819*2b949d04SAndroid Build Coastguard Worker 
820*2b949d04SAndroid Build Coastguard Worker static void
CopyLedMapDefsToKeymap(struct xkb_keymap * keymap,CompatInfo * info)821*2b949d04SAndroid Build Coastguard Worker CopyLedMapDefsToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
822*2b949d04SAndroid Build Coastguard Worker {
823*2b949d04SAndroid Build Coastguard Worker     for (xkb_led_index_t idx = 0; idx < info->num_leds; idx++) {
824*2b949d04SAndroid Build Coastguard Worker         LedInfo *ledi = &info->leds[idx];
825*2b949d04SAndroid Build Coastguard Worker         xkb_led_index_t i;
826*2b949d04SAndroid Build Coastguard Worker         struct xkb_led *led;
827*2b949d04SAndroid Build Coastguard Worker 
828*2b949d04SAndroid Build Coastguard Worker         /*
829*2b949d04SAndroid Build Coastguard Worker          * Find the LED with the given name, if it was already declared
830*2b949d04SAndroid Build Coastguard Worker          * in keycodes.
831*2b949d04SAndroid Build Coastguard Worker          */
832*2b949d04SAndroid Build Coastguard Worker         xkb_leds_enumerate(i, led, keymap)
833*2b949d04SAndroid Build Coastguard Worker             if (led->name == ledi->led.name)
834*2b949d04SAndroid Build Coastguard Worker                 break;
835*2b949d04SAndroid Build Coastguard Worker 
836*2b949d04SAndroid Build Coastguard Worker         /* Not previously declared; create it with next free index. */
837*2b949d04SAndroid Build Coastguard Worker         if (i >= keymap->num_leds) {
838*2b949d04SAndroid Build Coastguard Worker             log_dbg(keymap->ctx,
839*2b949d04SAndroid Build Coastguard Worker                     "Indicator name \"%s\" was not declared in the keycodes section; "
840*2b949d04SAndroid Build Coastguard Worker                     "Adding new indicator\n",
841*2b949d04SAndroid Build Coastguard Worker                     xkb_atom_text(keymap->ctx, ledi->led.name));
842*2b949d04SAndroid Build Coastguard Worker 
843*2b949d04SAndroid Build Coastguard Worker             xkb_leds_enumerate(i, led, keymap)
844*2b949d04SAndroid Build Coastguard Worker                 if (led->name == XKB_ATOM_NONE)
845*2b949d04SAndroid Build Coastguard Worker                     break;
846*2b949d04SAndroid Build Coastguard Worker 
847*2b949d04SAndroid Build Coastguard Worker             if (i >= keymap->num_leds) {
848*2b949d04SAndroid Build Coastguard Worker                 /* Not place to put it; ignore. */
849*2b949d04SAndroid Build Coastguard Worker                 if (i >= XKB_MAX_LEDS) {
850*2b949d04SAndroid Build Coastguard Worker                     log_err(keymap->ctx,
851*2b949d04SAndroid Build Coastguard Worker                             "Too many indicators (maximum is %d); "
852*2b949d04SAndroid Build Coastguard Worker                             "Indicator name \"%s\" ignored\n",
853*2b949d04SAndroid Build Coastguard Worker                             XKB_MAX_LEDS,
854*2b949d04SAndroid Build Coastguard Worker                             xkb_atom_text(keymap->ctx, ledi->led.name));
855*2b949d04SAndroid Build Coastguard Worker                     continue;
856*2b949d04SAndroid Build Coastguard Worker                 }
857*2b949d04SAndroid Build Coastguard Worker 
858*2b949d04SAndroid Build Coastguard Worker                 /* Add a new LED. */
859*2b949d04SAndroid Build Coastguard Worker                 led = &keymap->leds[keymap->num_leds++];
860*2b949d04SAndroid Build Coastguard Worker             }
861*2b949d04SAndroid Build Coastguard Worker         }
862*2b949d04SAndroid Build Coastguard Worker 
863*2b949d04SAndroid Build Coastguard Worker         *led = ledi->led;
864*2b949d04SAndroid Build Coastguard Worker         if (led->groups != 0 && led->which_groups == 0)
865*2b949d04SAndroid Build Coastguard Worker             led->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
866*2b949d04SAndroid Build Coastguard Worker         if (led->mods.mods != 0 && led->which_mods == 0)
867*2b949d04SAndroid Build Coastguard Worker             led->which_mods = XKB_STATE_MODS_EFFECTIVE;
868*2b949d04SAndroid Build Coastguard Worker     }
869*2b949d04SAndroid Build Coastguard Worker }
870*2b949d04SAndroid Build Coastguard Worker 
871*2b949d04SAndroid Build Coastguard Worker static bool
CopyCompatToKeymap(struct xkb_keymap * keymap,CompatInfo * info)872*2b949d04SAndroid Build Coastguard Worker CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
873*2b949d04SAndroid Build Coastguard Worker {
874*2b949d04SAndroid Build Coastguard Worker     keymap->compat_section_name = strdup_safe(info->name);
875*2b949d04SAndroid Build Coastguard Worker     XkbEscapeMapName(keymap->compat_section_name);
876*2b949d04SAndroid Build Coastguard Worker 
877*2b949d04SAndroid Build Coastguard Worker     keymap->mods = info->mods;
878*2b949d04SAndroid Build Coastguard Worker 
879*2b949d04SAndroid Build Coastguard Worker     if (!darray_empty(info->interps)) {
880*2b949d04SAndroid Build Coastguard Worker         struct collect collect;
881*2b949d04SAndroid Build Coastguard Worker         darray_init(collect.sym_interprets);
882*2b949d04SAndroid Build Coastguard Worker 
883*2b949d04SAndroid Build Coastguard Worker         /* Most specific to least specific. */
884*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, true, MATCH_EXACTLY, &collect);
885*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, true, MATCH_ALL, &collect);
886*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, true, MATCH_NONE, &collect);
887*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, true, MATCH_ANY, &collect);
888*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, true, MATCH_ANY_OR_NONE, &collect);
889*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, false, MATCH_EXACTLY, &collect);
890*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, false, MATCH_ALL, &collect);
891*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, false, MATCH_NONE, &collect);
892*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, false, MATCH_ANY, &collect);
893*2b949d04SAndroid Build Coastguard Worker         CopyInterps(info, false, MATCH_ANY_OR_NONE, &collect);
894*2b949d04SAndroid Build Coastguard Worker 
895*2b949d04SAndroid Build Coastguard Worker         darray_steal(collect.sym_interprets,
896*2b949d04SAndroid Build Coastguard Worker                      &keymap->sym_interprets, &keymap->num_sym_interprets);
897*2b949d04SAndroid Build Coastguard Worker     }
898*2b949d04SAndroid Build Coastguard Worker 
899*2b949d04SAndroid Build Coastguard Worker     CopyLedMapDefsToKeymap(keymap, info);
900*2b949d04SAndroid Build Coastguard Worker 
901*2b949d04SAndroid Build Coastguard Worker     return true;
902*2b949d04SAndroid Build Coastguard Worker }
903*2b949d04SAndroid Build Coastguard Worker 
904*2b949d04SAndroid Build Coastguard Worker bool
CompileCompatMap(XkbFile * file,struct xkb_keymap * keymap,enum merge_mode merge)905*2b949d04SAndroid Build Coastguard Worker CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
906*2b949d04SAndroid Build Coastguard Worker                  enum merge_mode merge)
907*2b949d04SAndroid Build Coastguard Worker {
908*2b949d04SAndroid Build Coastguard Worker     CompatInfo info;
909*2b949d04SAndroid Build Coastguard Worker     ActionsInfo *actions;
910*2b949d04SAndroid Build Coastguard Worker 
911*2b949d04SAndroid Build Coastguard Worker     actions = NewActionsInfo();
912*2b949d04SAndroid Build Coastguard Worker     if (!actions)
913*2b949d04SAndroid Build Coastguard Worker         return false;
914*2b949d04SAndroid Build Coastguard Worker 
915*2b949d04SAndroid Build Coastguard Worker     InitCompatInfo(&info, keymap->ctx, actions, &keymap->mods);
916*2b949d04SAndroid Build Coastguard Worker     info.default_interp.merge = merge;
917*2b949d04SAndroid Build Coastguard Worker     info.default_led.merge = merge;
918*2b949d04SAndroid Build Coastguard Worker 
919*2b949d04SAndroid Build Coastguard Worker     HandleCompatMapFile(&info, file, merge);
920*2b949d04SAndroid Build Coastguard Worker     if (info.errorCount != 0)
921*2b949d04SAndroid Build Coastguard Worker         goto err_info;
922*2b949d04SAndroid Build Coastguard Worker 
923*2b949d04SAndroid Build Coastguard Worker     if (!CopyCompatToKeymap(keymap, &info))
924*2b949d04SAndroid Build Coastguard Worker         goto err_info;
925*2b949d04SAndroid Build Coastguard Worker 
926*2b949d04SAndroid Build Coastguard Worker     ClearCompatInfo(&info);
927*2b949d04SAndroid Build Coastguard Worker     FreeActionsInfo(actions);
928*2b949d04SAndroid Build Coastguard Worker     return true;
929*2b949d04SAndroid Build Coastguard Worker 
930*2b949d04SAndroid Build Coastguard Worker err_info:
931*2b949d04SAndroid Build Coastguard Worker     ClearCompatInfo(&info);
932*2b949d04SAndroid Build Coastguard Worker     FreeActionsInfo(actions);
933*2b949d04SAndroid Build Coastguard Worker     return false;
934*2b949d04SAndroid Build Coastguard Worker }
935