Commit 7bcc5fabbdf156d84afbb75279f5e2e702436192

Ran Benita 2012-08-10T13:32:58

keycodes: save context in Info, not keymap We don't need the keymap in this case, just makes things more verbose. Signed-off-by: Ran Benita <ran234@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 1eececd..a9d6c8d 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -122,7 +122,7 @@ static inline bool
 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
                 const char *wanted)
 {
-    return ReportBadType(info->keymap, "symbol interpretation", field,
+    return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
                          siText(si, info), wanted);
 }
 
@@ -130,7 +130,7 @@ static inline bool
 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
                        const char *field, const char *wanted)
 {
-    return ReportBadType(info->keymap, "indicator map", field,
+    return ReportBadType(info->keymap->ctx, "indicator map", field,
                          xkb_atom_text(info->keymap->ctx, led->name),
                          wanted);
 }
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 208764a..57d73a0 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -140,6 +140,7 @@ typedef struct _KeyNamesInfo {
     int errorCount;
     unsigned file_id;
     enum merge_mode merge;
+
     xkb_keycode_t computedMin; /* lowest keycode stored */
     xkb_keycode_t computedMax; /* highest keycode stored */
     xkb_keycode_t explicitMin;
@@ -149,7 +150,7 @@ typedef struct _KeyNamesInfo {
     struct list leds;
     struct list aliases;
 
-    struct xkb_keymap *keymap;
+    struct xkb_context *ctx;
 } KeyNamesInfo;
 
 static void
@@ -228,7 +229,7 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
 {
     IndicatorNameInfo *old;
     bool replace;
-    int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
+    int verbosity = xkb_get_log_verbosity(info->ctx);
 
     replace = (merge == MERGE_REPLACE) || (merge == MERGE_OVERRIDE);
 
@@ -240,23 +241,23 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
                 if (old->virtual != new->virtual) {
                     if (replace)
                         old->virtual = new->virtual;
-                    log_warn(info->keymap->ctx, "Multiple indicators named %s; "
+                    log_warn(info->ctx, "Multiple indicators named %s; "
                              "Using %s instead of %s\n",
-                             xkb_atom_text(info->keymap->ctx, new->name),
+                             xkb_atom_text(info->ctx, new->name),
                              (old->virtual ? "virtual" : "real"),
                              (old->virtual ? "real" : "virtual"));
                 }
                 else {
-                    log_warn(info->keymap->ctx, "Multiple indicators named %s; "
+                    log_warn(info->ctx, "Multiple indicators named %s; "
                              "Identical definitions ignored\n",
-                             xkb_atom_text(info->keymap->ctx, new->name));
+                             xkb_atom_text(info->ctx, new->name));
                 }
                 return true;
             }
             else {
-                log_warn(info->keymap->ctx, "Multiple indicators named %s; "
+                log_warn(info->ctx, "Multiple indicators named %s; "
                          "Using %d, ignoring %d\n",
-                         xkb_atom_text(info->keymap->ctx, new->name),
+                         xkb_atom_text(info->ctx, new->name),
                          (replace ? old->ndx : new->ndx),
                          (replace ? new->ndx : old->ndx));
             }
@@ -273,8 +274,7 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
         if ((old->file_id == new->file_id && verbosity > 0) ||
             verbosity > 9) {
             if (old->name == new->name && old->virtual == new->virtual) {
-                log_warn(info->keymap->ctx,
-                         "Multiple names for indicator %d; "
+                log_warn(info->ctx, "Multiple names for indicator %d; "
                          "Identical definitions ignored\n", new->ndx);
             } else {
                 const char *oldType, *newType;
@@ -295,12 +295,11 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
                     using = old->name;
                     ignoring = new->name;
                 }
-                log_warn(info->keymap->ctx,
-                         "Multiple names for indicator %d; "
+                log_warn(info->ctx, "Multiple names for indicator %d; "
                          "Using %s %s, ignoring %s %s\n",
                          new->ndx,
-                         oldType, xkb_atom_text(info->keymap->ctx, using),
-                         newType, xkb_atom_text(info->keymap->ctx, ignoring));
+                         oldType, xkb_atom_text(info->ctx, using),
+                         newType, xkb_atom_text(info->ctx, ignoring));
             }
         }
         if (replace) {
@@ -312,7 +311,7 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
     old = new;
     new = NextIndicatorName(info);
     if (!new) {
-        log_wsgo(info->keymap->ctx,
+        log_wsgo(info->ctx,
                  "Couldn't allocate name for indicator %d; Ignored\n",
                  old->ndx);
         return false;
@@ -345,7 +344,7 @@ ClearKeyNamesInfo(KeyNamesInfo * info)
 }
 
 static void
-InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_keymap *keymap,
+InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
                  unsigned file_id)
 {
     info->name = NULL;
@@ -357,7 +356,7 @@ InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_keymap *keymap,
     darray_init(info->files);
     ClearKeyNamesInfo(info);
     info->errorCount = 0;
-    info->keymap = keymap;
+    info->ctx = ctx;
 }
 
 static int
@@ -382,7 +381,7 @@ AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
            enum merge_mode merge, unsigned file_id, bool reportCollisions)
 {
     xkb_keycode_t old;
-    int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
+    int verbosity = xkb_get_log_verbosity(info->ctx);
 
     ResizeKeyNameArrays(info, kc);
 
@@ -401,23 +400,20 @@ AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
         const char *kname = LongKeyNameText(name);
 
         if (darray_item(info->names, kc) == name && reportCollisions) {
-            log_warn(info->keymap->ctx,
-                     "Multiple identical key name definitions; "
+            log_warn(info->ctx, "Multiple identical key name definitions; "
                      "Later occurences of \"%s = %d\" ignored\n", lname, kc);
             return true;
         }
 
         if (merge == MERGE_AUGMENT) {
             if (reportCollisions)
-                log_warn(info->keymap->ctx,
-                         "Multiple names for keycode %d; "
+                log_warn(info->ctx, "Multiple names for keycode %d; "
                          "Using %s, ignoring %s\n", kc, lname, kname);
             return true;
         }
         else {
             if (reportCollisions)
-                log_warn(info->keymap->ctx,
-                         "Multiple names for keycode %d; "
+                log_warn(info->ctx, "Multiple names for keycode %d; "
                          "Using %s, ignoring %s\n", kc, kname, lname);
             darray_item(info->names, kc) = 0;
             darray_item(info->files, kc) = 0;
@@ -432,14 +428,12 @@ AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
             darray_item(info->names, old) = 0;
             darray_item(info->files, old) = 0;
             if (reportCollisions)
-                log_warn(info->keymap->ctx,
-                         "Key name %s assigned to multiple keys; "
+                log_warn(info->ctx, "Key name %s assigned to multiple keys; "
                          "Using %d, ignoring %d\n", kname, kc, old);
         }
         else {
             if (reportCollisions && verbosity > 3)
-                log_warn(info->keymap->ctx,
-                         "Key name %s assigned to multiple keys; "
+                log_warn(info->ctx, "Key name %s assigned to multiple keys; "
                          "Using %d, ignoring %d\n", kname, old, kc);
             return true;
         }
@@ -547,7 +541,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
     XkbFile *rtrn;
     KeyNamesInfo included, next_incl;
 
-    InitKeyNamesInfo(&included, info->keymap, info->file_id);
+    InitKeyNamesInfo(&included, info->ctx, info->file_id);
     if (stmt->stmt) {
         free(included.name);
         included.name = stmt->stmt;
@@ -555,14 +549,14 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
     }
 
     for (; stmt; stmt = stmt->next_incl) {
-        if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_KEYCODES,
+        if (!ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_KEYCODES,
                                 &rtrn, &merge)) {
             info->errorCount += 10;
             ClearKeyNamesInfo(&included);
             return false;
         }
 
-        InitKeyNamesInfo(&next_incl, info->keymap, rtrn->id);
+        InitKeyNamesInfo(&next_incl, info->ctx, rtrn->id);
 
         HandleKeycodesFile(&next_incl, rtrn, MERGE_OVERRIDE);
 
@@ -587,8 +581,7 @@ HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
 {
     if ((info->explicitMin != 0 && stmt->value < info->explicitMin) ||
         (info->explicitMax != 0 && stmt->value > info->explicitMax)) {
-        log_err(info->keymap->ctx,
-                "Illegal keycode %lu for name %s; "
+        log_err(info->ctx, "Illegal keycode %lu for name %s; "
                 "Must be in the range %d-%d inclusive\n",
                 stmt->value, KeyNameText(stmt->name), info->explicitMin,
                 info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
@@ -609,12 +602,11 @@ HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
 static void
 HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
 {
-    int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
+    int verbosity = xkb_get_log_verbosity(info->ctx);
 
     if (new->real == old->real) {
         if ((new->file_id == old->file_id && verbosity > 0) || verbosity > 9)
-            log_warn(info->keymap->ctx,
-                     "Alias of %s for %s declared more than once; "
+            log_warn(info->ctx, "Alias of %s for %s declared more than once; "
                      "First definition ignored\n",
                      LongKeyNameText(new->alias), LongKeyNameText(new->real));
     }
@@ -631,8 +623,7 @@ HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
         }
 
         if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
-            log_warn(info->keymap->ctx,
-                     "Multiple definitions for alias %s; "
+            log_warn(info->ctx, "Multiple definitions for alias %s; "
                      "Using %s, ignoring %s\n",
                      LongKeyNameText(old->alias), LongKeyNameText(use),
                      LongKeyNameText(ignore));
@@ -662,7 +653,7 @@ HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
 
     alias = calloc(1, sizeof(*alias));
     if (!alias) {
-        log_wsgo(info->keymap->ctx, "Allocation failure in HandleAliasDef\n");
+        log_wsgo(info->ctx, "Allocation failure in HandleAliasDef\n");
         return false;
     }
 
@@ -692,13 +683,12 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
     ExprDef *arrayNdx;
     int which;
 
-    if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
+    if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field,
                         &arrayNdx))
         return false;               /* internal error, already reported */
 
     if (elem) {
-        log_err(info->keymap->ctx,
-                "Unknown element %s encountered; "
+        log_err(info->ctx, "Unknown element %s encountered; "
                 "Default for field %s ignored\n", elem, field);
         return false;
     }
@@ -710,28 +700,25 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
         which = MAX_KEYCODE_DEF;
     }
     else {
-        log_err(info->keymap->ctx,
-                "Unknown field encountered; "
+        log_err(info->ctx, "Unknown field encountered; "
                 "Assigment to field %s ignored\n", field);
         return false;
     }
 
     if (arrayNdx != NULL) {
-        log_err(info->keymap->ctx,
-                "The %s setting is not an array; "
+        log_err(info->ctx, "The %s setting is not an array; "
                 "Illegal array reference ignored\n", field);
         return false;
     }
 
-    if (!ExprResolveKeyCode(info->keymap->ctx, stmt->value, &kc)) {
-        log_err(info->keymap->ctx,
-                "Illegal keycode encountered; "
+    if (!ExprResolveKeyCode(info->ctx, stmt->value, &kc)) {
+        log_err(info->ctx, "Illegal keycode encountered; "
                 "Assignment to field %s ignored\n", field);
         return false;
     }
 
     if (kc > XKB_KEYCODE_MAX) {
-        log_err(info->keymap->ctx,
+        log_err(info->ctx,
                 "Illegal keycode %d (must be in the range %d-%d inclusive); "
                 "Value of \"%s\" not changed\n",
                 kc, 0, XKB_KEYCODE_MAX, field);
@@ -740,7 +727,7 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
 
     if (which == MIN_KEYCODE_DEF) {
         if (info->explicitMax > 0 && info->explicitMax < kc) {
-            log_err(info->keymap->ctx,
+            log_err(info->ctx,
                     "Minimum key code (%d) must be <= maximum key code (%d); "
                     "Minimum key code value not changed\n",
                     kc, info->explicitMax);
@@ -748,7 +735,7 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
         }
 
         if (info->computedMax > 0 && info->computedMin < kc) {
-            log_err(info->keymap->ctx,
+            log_err(info->ctx,
                     "Minimum key code (%d) must be <= lowest defined key (%d); "
                     "Minimum key code value not changed\n",
                     kc, info->computedMin);
@@ -759,7 +746,7 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
     }
     else if (which == MAX_KEYCODE_DEF) {
         if (info->explicitMin > 0 && info->explicitMin > kc) {
-            log_err(info->keymap->ctx,
+            log_err(info->ctx,
                     "Maximum code (%d) must be >= minimum key code (%d); "
                     "Maximum code value not changed\n",
                     kc, info->explicitMin);
@@ -767,7 +754,7 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
         }
 
         if (info->computedMax > 0 && info->computedMax > kc) {
-            log_err(info->keymap->ctx,
+            log_err(info->ctx,
                     "Maximum code (%d) must be >= highest defined key (%d); "
                     "Maximum code value not changed\n",
                     kc, info->computedMax);
@@ -789,7 +776,7 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
 
     if (def->ndx < 1 || def->ndx > XkbNumIndicators) {
         info->errorCount++;
-        log_err(info->keymap->ctx,
+        log_err(info->ctx,
                 "Name specified for illegal indicator index %d\n; Ignored\n",
                 def->ndx);
         return false;
@@ -797,16 +784,16 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
 
     InitIndicatorNameInfo(&ii, info);
 
-    if (!ExprResolveString(info->keymap->ctx, def->name, &str)) {
+    if (!ExprResolveString(info->ctx, def->name, &str)) {
         char buf[20];
         snprintf(buf, sizeof(buf), "%d", def->ndx);
         info->errorCount++;
-        return ReportBadType(info->keymap, "indicator", "name", buf,
+        return ReportBadType(info->ctx, "indicator", "name", buf,
                              "string");
     }
 
     ii.ndx = (xkb_led_index_t) def->ndx;
-    ii.name = xkb_atom_intern(info->keymap->ctx, str);
+    ii.name = xkb_atom_intern(info->ctx, str);
     ii.virtual = def->virtual;
 
     return AddIndicatorName(info, merge, &ii);
@@ -853,7 +840,7 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
                                         merge);
             break;
         default:
-            log_err(info->keymap->ctx,
+            log_err(info->ctx,
                     "Keycode files may define key and indicator names only; "
                     "Ignoring %s\n", StmtTypeToString(stmt->type));
             ok = false;
@@ -864,7 +851,7 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
             info->errorCount++;
 
         if (info->errorCount > 10) {
-            log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n",
+            log_err(info->ctx, "Abandoning keycodes file \"%s\"\n",
                     file->topName);
             break;
         }
@@ -872,14 +859,13 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
 }
 
 static int
-ApplyAliases(KeyNamesInfo *info)
+ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
 {
     int i;
     struct xkb_key *key;
     struct xkb_key_alias *old, *a;
     AliasInfo *alias, *next;
     int nNew = 0, nOld;
-    struct xkb_keymap *keymap = info->keymap;
 
     nOld = darray_size(keymap->key_aliases);
     old = &darray_item(keymap->key_aliases, 0);
@@ -887,7 +873,7 @@ ApplyAliases(KeyNamesInfo *info)
     list_foreach(alias, &info->aliases, entry) {
         key = FindNamedKey(keymap, alias->real, false, 0);
         if (!key) {
-            log_lvl(info->keymap->ctx, 5,
+            log_lvl(info->ctx, 5,
                     "Attempt to alias %s to non-existent key %s; Ignored\n",
                     LongKeyNameText(alias->alias),
                     LongKeyNameText(alias->real));
@@ -897,7 +883,7 @@ ApplyAliases(KeyNamesInfo *info)
 
         key = FindNamedKey(keymap, alias->alias, false, 0);
         if (key) {
-            log_lvl(info->keymap->ctx, 5,
+            log_lvl(info->ctx, 5,
                     "Attempt to create alias with the name of a real key; "
                     "Alias \"%s = %s\" ignored\n",
                     LongKeyNameText(alias->alias),
@@ -965,7 +951,7 @@ CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
     KeyNamesInfo info; /* contains all the info after parsing */
     IndicatorNameInfo *ii;
 
-    InitKeyNamesInfo(&info, keymap, file->id);
+    InitKeyNamesInfo(&info, keymap->ctx, file->id);
 
     HandleKeycodesFile(&info, file, merge);
 
@@ -995,7 +981,7 @@ CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
         keymap->indicator_names[ii->ndx - 1] =
             xkb_atom_text(keymap->ctx, ii->name);
 
-    ApplyAliases(&info);
+    ApplyAliases(&info, keymap);
 
     ClearKeyNamesInfo(&info);
     return true;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 0a58d8b..45015ea 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -186,8 +186,8 @@ static inline bool
 ReportTypeBadType(KeyTypesInfo *info, KeyTypeInfo *type,
                   const char *field, const char *wanted)
 {
-    return ReportBadType(info->keymap, "key type", field, TypeTxt(info, type),
-                         wanted);
+    return ReportBadType(info->keymap->ctx, "key type", field,
+                         TypeTxt(info, type), wanted);
 }
 
 static inline bool
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 884b90d..33e9671 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -99,11 +99,10 @@ ReportShouldBeArray(struct xkb_keymap *keymap, const char *type,
 }
 
 static inline bool
-ReportBadType(struct xkb_keymap *keymap, const char *type, const char *field,
+ReportBadType(struct xkb_context *ctx, const char *type, const char *field,
               const char *name, const char *wanted)
 {
-    log_err(keymap->ctx,
-            "The %s %s field must be a %s; "
+    log_err(ctx, "The %s %s field must be a %s; "
             "Ignoring illegal assignment in %s\n",
             type, field, wanted, name);
     return false;