Commit 48b4d30aa39a0d41490b8099576909fda73d3a75

Ran Benita 2012-06-29T17:05:33

Use enum for file types enums are nice for some type safety and readability. This one also removes the distinction between file type mask / file type index and some naming consistency. 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
diff --git a/src/text.c b/src/text.c
index 2ca411b..d30c4b7 100644
--- a/src/text.c
+++ b/src/text.c
@@ -186,19 +186,21 @@ XkbcModMaskText(unsigned mask, bool cFormat)
 }
 
 const char *
-XkbcConfigText(unsigned config)
+XkbcFileTypeText(enum xkb_file_type type)
 {
-    switch (config) {
-    case XkmKeymapFile:
+    switch (type) {
+    case FILE_TYPE_KEYMAP:
         return "Keymap";
-    case XkmTypesIndex:
+    case FILE_TYPE_TYPES:
         return "Types";
-    case XkmCompatMapIndex:
+    case FILE_TYPE_COMPAT:
         return "CompatMap";
-    case XkmSymbolsIndex:
+    case FILE_TYPE_SYMBOLS:
         return "Symbols";
-    case XkmKeyNamesIndex:
+    case FILE_TYPE_KEYCODES:
         return "KeyNames";
+    case FILE_TYPE_RULES:
+        return "Rules";
     default:
         return "unknown";
     }
diff --git a/src/text.h b/src/text.h
index ddf9b6f..c21a8b6 100644
--- a/src/text.h
+++ b/src/text.h
@@ -39,7 +39,7 @@ extern const char *
 XkbcModMaskText(unsigned mask, bool cFormat);
 
 extern const char *
-XkbcConfigText(unsigned config);
+XkbcFileTypeText(enum xkb_file_type type);
 
 extern const char *
 XkbcActionTypeText(unsigned type);
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 48e4355..75f0004 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -89,25 +89,24 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "utils.h"
 #include "darray.h"
 
-/* From XKM.h */
-#define	XkmKeymapFile		22
-#define	XkmRulesFile		24
-
-#define	XkmTypesIndex		0
-#define	XkmCompatMapIndex	1
-#define	XkmSymbolsIndex		2
-#define	XkmKeyNamesIndex	4
-#define	XkmGeometryIndex	5
-
-#define	XkmTypesMask		(1<<0)
-#define	XkmCompatMapMask	(1<<1)
-#define	XkmSymbolsMask		(1<<2)
-#define	XkmKeyNamesMask		(1<<4)
-#define XkmGeometryMask         (1<<5)
-
-#define	XkmKeymapRequired	(XkmCompatMapMask|XkmKeyNamesMask|XkmSymbolsMask|XkmTypesMask)
-#define	XkmKeymapOptional	((XkmTypesMask|XkmGeometryMask)&(~XkmKeymapRequired))
-#define	XkmKeymapLegal		(XkmKeymapRequired|XkmKeymapOptional)
+enum xkb_file_type {
+    /* The top level file which includes the other component files. */
+    FILE_TYPE_KEYMAP    = (1 << 0),
+
+    /* Component files. */
+    FILE_TYPE_TYPES     = (1 << 1),
+    FILE_TYPE_COMPAT    = (1 << 2),
+    FILE_TYPE_SYMBOLS   = (1 << 3),
+    FILE_TYPE_KEYCODES  = (1 << 4),
+    FILE_TYPE_GEOMETRY  = (1 << 5),
+
+    /* This one doesn't mix with the others, but useful here as well. */
+    FILE_TYPE_RULES     = (1 << 6),
+};
+
+/* Files needed for a complete keymap. */
+#define REQUIRED_FILE_TYPES (FILE_TYPE_TYPES | FILE_TYPE_COMPAT | FILE_TYPE_SYMBOLS | FILE_TYPE_KEYCODES)
+#define LEGAL_FILE_TYPES    (FILE_TYPE_GEOMETRY | REQUIRED_FILE_TYPES)
 
 /**
  * Legacy names for the components of an XKB keymap, also known as KcCGST.
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 7ea226a..7c6db8a 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -404,7 +404,7 @@ HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
         included = *info;
         memset(info, 0, sizeof(CompatInfo));
     }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, XkmCompatMapIndex, &rtrn,
+    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_COMPAT, &rtrn,
                                 &newMerge))
     {
         InitCompatInfo(&included, keymap);
@@ -445,7 +445,7 @@ HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
                 MergeIncludedCompatMaps(&included, info, next->merge);
                 ClearCompatInfo(info, keymap);
             }
-            else if (ProcessIncludeFile(keymap->ctx, next, XkmCompatMapIndex,
+            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_COMPAT,
                                         &rtrn, &op))
             {
                 InitCompatInfo(&next_incl, keymap);
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 04c027c..f695f04 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -511,7 +511,7 @@ HandleIncludeKeycodes(IncludeStmt *stmt, struct xkb_keymap *keymap,
         info->explicitMax = XKB_KEYCODE_MAX;
         return (info->errorCount == 0);
     } /* parse file, store returned info in the xkb struct */
-    else if (ProcessIncludeFile(keymap->ctx, stmt, XkmKeyNamesIndex, &rtrn,
+    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_KEYCODES, &rtrn,
                                 &newMerge))
     {
         InitKeyNamesInfo(&included);
@@ -544,7 +544,7 @@ HandleIncludeKeycodes(IncludeStmt *stmt, struct xkb_keymap *keymap,
                 MergeIncludedKeycodes(&included, keymap, info, next->merge);
                 ClearKeyNamesInfo(info);
             }
-            else if (ProcessIncludeFile(keymap->ctx, next, XkmKeyNamesIndex,
+            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_KEYCODES,
                                         &rtrn, &op))
             {
                 InitKeyNamesInfo(&next_incl);
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 4ce008b..50eec0f 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -30,14 +30,14 @@
 /**
  * Compile the given file and store the output in xkb.
  * @param file A list of XkbFiles, each denoting one type (e.g.
- * XkmKeyNamesIdx, etc.)
+ * FILE_TYPE_KEYCODES, etc.)
  */
 struct xkb_keymap *
 CompileKeymap(struct xkb_context *ctx, XkbFile *file)
 {
     unsigned have = 0;
     bool ok;
-    unsigned mainType;
+    enum xkb_file_type mainType;
     const char *mainName;
     LEDInfo *unbound = NULL, *next;
     struct xkb_keymap *keymap = XkbcAllocKeyboard(ctx);
@@ -55,55 +55,52 @@ CompileKeymap(struct xkb_context *ctx, XkbFile *file)
     mainName = file->name ? file->name : "(unnamed)";
 
     /*
-     * Other aggregate file types are converted to XkmKeymapFile
+     * Other aggregate file types are converted to FILE_TYPE_KEYMAP
      * in the parser.
      */
-    if (mainType != XkmKeymapFile) {
+    if (mainType != FILE_TYPE_KEYMAP) {
         ERROR("Cannot compile a %s file alone into a keymap\n",
-               XkbcConfigText(mainType));
-        return false;
+              XkbcFileTypeText(mainType));
+        goto err;
     }
 
     /* Check for duplicate entries in the input file */
     for (file = (XkbFile *) file->defs; file; file = (XkbFile *) file->common.next)
     {
-        if ((have & (1 << file->type)) != 0)
-        {
+        if (have & file->type) {
             ERROR("More than one %s section in a %s file\n",
-                   XkbcConfigText(file->type), XkbcConfigText(mainType));
+                   XkbcFileTypeText(file->type), XkbcFileTypeText(mainType));
             ACTION("All sections after the first ignored\n");
             continue;
         }
-        else if ((1 << file->type) & (~XkmKeymapLegal))
-        {
+        else if (!(file->type & LEGAL_FILE_TYPES)) {
             ERROR("Cannot define %s in a %s file\n",
-                   XkbcConfigText(file->type), XkbcConfigText(mainType));
+                   XkbcFileTypeText(file->type), XkbcFileTypeText(mainType));
             continue;
         }
 
-        switch (file->type)
-        {
-        case XkmKeyNamesIndex:
+        switch (file->type) {
+        case FILE_TYPE_KEYCODES:
             sections.keycodes = file;
             break;
-        case XkmTypesIndex:
+        case FILE_TYPE_TYPES:
             sections.types = file;
             break;
-        case XkmSymbolsIndex:
+        case FILE_TYPE_SYMBOLS:
             sections.symbols = file;
             break;
-        case XkmCompatMapIndex:
+        case FILE_TYPE_COMPAT:
             sections.compat = file;
             break;
-        case XkmGeometryIndex:
+        case FILE_TYPE_GEOMETRY:
             continue;
         default:
             WSGO("Unknown file type %d\n", file->type);
             ACTION("Ignored\n");
             continue;
-        case XkmKeymapFile:
+        case FILE_TYPE_KEYMAP:
             WSGO("Illegal %s configuration in a %s file\n",
-                  XkbcConfigText(file->type), XkbcConfigText(mainType));
+                  XkbcFileTypeText(file->type), XkbcFileTypeText(mainType));
             ACTION("Ignored\n");
             continue;
         }
@@ -113,22 +110,23 @@ CompileKeymap(struct xkb_context *ctx, XkbFile *file)
             file->topName = strdup(mainName);
         }
 
-        have |= (1 << file->type);
+        have |= file->type;
     }
 
-    if (XkmKeymapRequired & (~have))
-    {
-        int i, bit;
-        unsigned missing;
-        missing = XkmKeymapRequired & (~have);
-        for (i = 0, bit = 1; missing != 0; i++, bit <<= 1)
-        {
-            if (missing & bit)
-            {
-                ERROR("Required section %s missing from keymap\n", XkbcConfigText(i));
+    if (REQUIRED_FILE_TYPES & (~have)) {
+        enum xkb_file_type bit;
+        enum xkb_file_type missing;
+
+        missing = REQUIRED_FILE_TYPES & (~have);
+
+        for (bit = 1; missing != 0; bit <<= 1) {
+            if (missing & bit) {
+                ERROR("Required section %s missing from keymap\n",
+                      XkbcFileTypeText(bit));
                 missing &= ~bit;
             }
         }
+
         goto err;
     }
 
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 599a0f2..c8e0fcb 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -346,7 +346,7 @@ HandleIncludeKeyTypes(IncludeStmt *stmt, struct xkb_keymap *keymap,
         included = *info;
         memset(info, 0, sizeof(KeyTypesInfo));
     }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, XkmTypesIndex, &rtrn,
+    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_TYPES, &rtrn,
                                 &newMerge))
     {
         InitKeyTypesInfo(&included, keymap, info);
@@ -381,7 +381,7 @@ HandleIncludeKeyTypes(IncludeStmt *stmt, struct xkb_keymap *keymap,
                 MergeIncludedKeyTypes(&included, info, next->merge, keymap);
                 FreeKeyTypesInfo(info);
             }
-            else if (ProcessIncludeFile(keymap->ctx, next, XkmTypesIndex,
+            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_TYPES,
                                         &rtrn, &op))
             {
                 InitKeyTypesInfo(&next_incl, keymap, &included);
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index e9b42ba..7d11376 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -38,7 +38,7 @@
  *
  * @param ctx The ctx containing include paths
  * @param stmt The include statement, specifying the file name to look for.
- * @param file_type Type of file (XkmKeyNamesIdx, etc.)
+ * @param file_type Type of file (FILE_TYPE_KEYCODES, etc.)
  * @param file_rtrn Returns the key map to be used.
  * @param merge_rtrn Always returns stmt->merge.
  *
@@ -47,7 +47,7 @@
 bool
 ProcessIncludeFile(struct xkb_context *ctx,
                    IncludeStmt * stmt,
-                   unsigned file_type,
+                   enum xkb_file_type file_type,
                    XkbFile ** file_rtrn, unsigned *merge_rtrn)
 {
     FILE *file;
@@ -92,7 +92,7 @@ ProcessIncludeFile(struct xkb_context *ctx,
         if (!mapToUse)
         {
             ERROR("No %s named \"%s\" in the include file \"%s\"\n",
-                   XkbcConfigText(file_type), stmt->map, stmt->file);
+                   XkbcFileTypeText(file_type), stmt->map, stmt->file);
             return false;
         }
     }
@@ -105,7 +105,7 @@ ProcessIncludeFile(struct xkb_context *ctx,
     if (mapToUse->type != file_type)
     {
         ERROR("Include file wrong type (expected %s, got %s)\n",
-               XkbcConfigText(file_type), XkbcConfigText(mapToUse->type));
+               XkbcFileTypeText(file_type), XkbcFileTypeText(mapToUse->type));
         ACTION("Include file \"%s\" ignored\n", stmt->file);
         return false;
     }
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 9eb51fc..7b28552 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -113,6 +113,7 @@ extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
 	int		 ival;
 	unsigned	 uval;
 	int64_t		 num;
+        enum xkb_file_type file_type;
 	char		*str;
 	xkb_atom_t	sval;
 	ParseCommon	*any;
@@ -134,7 +135,8 @@ extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
 %type <num>     INTEGER FLOAT
 %type <str>     IDENT KEYNAME STRING
 %type <ival>	Number Integer Float SignedNumber
-%type <uval>	XkbCompositeType FileType MergeMode OptMergeMode
+%type <uval>	MergeMode OptMergeMode
+%type <file_type> XkbCompositeType FileType
 %type <uval>	DoodadType Flag Flags OptFlags KeyCode
 %type <str>	KeyName MapName OptMapName KeySym
 %type <sval>	FieldSpec Ident Element String
@@ -181,9 +183,9 @@ XkbCompositeMap	:	OptFlags XkbCompositeType OptMapName OBRACE
                         }
 		;
 
-XkbCompositeType:	XKB_KEYMAP	{ $$= XkmKeymapFile; }
-		|	XKB_SEMANTICS	{ $$= XkmKeymapFile; }
-		|	XKB_LAYOUT	{ $$= XkmKeymapFile; }
+XkbCompositeType:	XKB_KEYMAP	{ $$= FILE_TYPE_KEYMAP; }
+		|	XKB_SEMANTICS	{ $$= FILE_TYPE_KEYMAP; }
+		|	XKB_LAYOUT	{ $$= FILE_TYPE_KEYMAP; }
 		;
 
 XkbMapConfigList :	XkbMapConfigList XkbMapConfig
@@ -201,7 +203,7 @@ XkbMapConfig	:	OptFlags FileType OptMapName OBRACE
 			    DeclList
 			CBRACE SEMI
 			{
-                            if ($2 == XkmGeometryIndex)
+                            if ($2 == FILE_TYPE_GEOMETRY)
                             {
                                 free($3);
                                 FreeStmt($5);
@@ -216,7 +218,7 @@ XkbMapConfig	:	OptFlags FileType OptMapName OBRACE
 
 XkbConfig	:	OptFlags FileType OptMapName DeclList
 			{
-                            if ($2 == XkmGeometryIndex)
+                            if ($2 == FILE_TYPE_GEOMETRY)
                             {
                                 free($3);
                                 FreeStmt($4);
@@ -230,11 +232,11 @@ XkbConfig	:	OptFlags FileType OptMapName DeclList
 		;
 
 
-FileType	:	XKB_KEYCODES		{ $$= XkmKeyNamesIndex; }
-		|	XKB_TYPES		{ $$= XkmTypesIndex; }
-		|	XKB_COMPATMAP		{ $$= XkmCompatMapIndex; }
-		|	XKB_SYMBOLS		{ $$= XkmSymbolsIndex; }
-		|	XKB_GEOMETRY		{ $$= XkmGeometryIndex; }
+FileType	:	XKB_KEYCODES		{ $$= FILE_TYPE_KEYCODES; }
+		|	XKB_TYPES		{ $$= FILE_TYPE_TYPES; }
+		|	XKB_COMPATMAP		{ $$= FILE_TYPE_COMPAT; }
+		|	XKB_SYMBOLS		{ $$= FILE_TYPE_SYMBOLS; }
+		|	XKB_GEOMETRY		{ $$= FILE_TYPE_GEOMETRY; }
 		;
 
 OptFlags	:	Flags			{ $$= $1; }
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index d5a2528..d026ffa 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -606,7 +606,7 @@ EnsureSafeMapName(char *name)
 }
 
 XkbFile *
-CreateXKBFile(struct xkb_context *ctx, int type, char *name,
+CreateXKBFile(struct xkb_context *ctx, enum xkb_file_type type, char *name,
               ParseCommon *defs, unsigned flags)
 {
     XkbFile *file;
@@ -771,16 +771,18 @@ FreeXKBFile(XkbFile *file)
 
         switch (file->type)
         {
-        case XkmKeymapFile:
+        case FILE_TYPE_KEYMAP:
             FreeXKBFile((XkbFile *)file->defs);
             break;
-        case XkmTypesIndex:
-        case XkmCompatMapIndex:
-        case XkmSymbolsIndex:
-        case XkmKeyNamesIndex:
-        case XkmGeometryIndex:
+        case FILE_TYPE_TYPES:
+        case FILE_TYPE_COMPAT:
+        case FILE_TYPE_SYMBOLS:
+        case FILE_TYPE_KEYCODES:
+        case FILE_TYPE_GEOMETRY:
             FreeStmt(file->defs);
             break;
+        default:
+            break;
         }
 
         free(file->name);
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index 53f24d2..32e4104 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -120,7 +120,7 @@ extern void
 CheckDefaultMap(XkbFile *maps, const char *fileName);
 
 extern XkbFile *
-CreateXKBFile(struct xkb_context *ctx, int type, char *name,
+CreateXKBFile(struct xkb_context *ctx, enum xkb_file_type type, char *name,
               ParseCommon *defs, unsigned flags);
 
 extern bool
diff --git a/src/xkbcomp/path.c b/src/xkbcomp/path.c
index 56463e6..2b0a7a0 100644
--- a/src/xkbcomp/path.c
+++ b/src/xkbcomp/path.c
@@ -142,23 +142,23 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
  * Return the xkb directory based on the type.
  */
 const char *
-XkbDirectoryForInclude(unsigned type)
+XkbDirectoryForInclude(enum xkb_file_type type)
 {
     switch (type)
     {
-    case XkmKeymapFile:
+    case FILE_TYPE_KEYMAP:
         return "keymap";
-    case XkmKeyNamesIndex:
+    case FILE_TYPE_KEYCODES:
         return "keycodes";
-    case XkmTypesIndex:
+    case FILE_TYPE_TYPES:
         return "types";
-    case XkmSymbolsIndex:
+    case FILE_TYPE_SYMBOLS:
         return "symbols";
-    case XkmCompatMapIndex:
+    case FILE_TYPE_COMPAT:
         return "compat";
-    case XkmGeometryIndex:
+    case FILE_TYPE_GEOMETRY:
         return "geometry";
-    case XkmRulesFile:
+    case FILE_TYPE_RULES:
         return "rules";
     default:
         return "";
@@ -171,16 +171,16 @@ XkbDirectoryForInclude(unsigned type)
  * Search for the given file name in the include directories.
  *
  * @param ctx the XKB ctx containing the include paths
- * @param type one of XkbTypesIndex, XkbCompatMapIndex, ..., or
- *             XkmKeymapFile
- * @param pathReturn is set to the full path of the file if found.
+ * @param type one of FILE_TYPE_TYPES, FILE_TYPE_COMPAT, ..., or
+ *             FILE_TYPE_KEYMAP or FILE_TYPE_RULES
+ * @param pathRtrn is set to the full path of the file if found.
  *
  * @return an FD to the file or NULL. If NULL is returned, the value of
  * pathRtrn is undefined.
  */
 FILE *
 XkbFindFileInPath(struct xkb_context *ctx,
-                  const char *name, unsigned type, char **pathRtrn)
+                  const char *name, enum xkb_file_type type, char **pathRtrn)
 {
     size_t i;
     int ret;
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index 52e93ba..dc02cb3 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -1059,7 +1059,7 @@ xkb_components_from_rules(struct xkb_context *ctx,
     struct rules *rules;
     struct xkb_component_names *kccgst = NULL;
 
-    file = XkbFindFileInPath(ctx, rmlvo->rules, XkmRulesFile, &path);
+    file = XkbFindFileInPath(ctx, rmlvo->rules, FILE_TYPE_RULES, &path);
     if (!file) {
         ERROR("could not find \"%s\" rules in XKB path\n", rmlvo->rules);
         ERROR("%d include paths searched:\n",
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index f464416..a01fb33 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -798,7 +798,7 @@ HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
         included = *info;
         memset(info, 0, sizeof(SymbolsInfo));
     }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, XkmSymbolsIndex, &rtrn,
+    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_SYMBOLS, &rtrn,
                                 &newMerge))
     {
         InitSymbolsInfo(&included, keymap);
@@ -840,7 +840,7 @@ HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
                 MergeIncludedSymbols(&included, info, next->merge, keymap);
                 FreeSymbolsInfo(info);
             }
-            else if (ProcessIncludeFile(keymap->ctx, next, XkmSymbolsIndex,
+            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_SYMBOLS,
                                         &rtrn, &op))
             {
                 InitSymbolsInfo(&next_incl, keymap);
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 85a9c02..9d10597 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -65,8 +65,8 @@ ReportBadField(const char *type, const char *field, const char *name);
 
 extern bool
 ProcessIncludeFile(struct xkb_context *ctx,
-                   IncludeStmt *stmt, unsigned file_type, XkbFile **file_rtrn,
-                   unsigned *merge_rtrn);
+                   IncludeStmt *stmt, enum xkb_file_type file_type,
+                   XkbFile **file_rtrn, unsigned *merge_rtrn);
 
 extern bool
 FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 5242c13..52a5fbf 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -41,25 +41,25 @@ XkbKeymapFileFromComponents(struct xkb_context *ctx,
     IncludeStmt *inc;
 
     inc = IncludeCreate(ktcsg->keycodes, MergeDefault);
-    keycodes = CreateXKBFile(ctx, XkmKeyNamesIndex, NULL,
+    keycodes = CreateXKBFile(ctx, FILE_TYPE_KEYCODES, NULL,
                              (ParseCommon *)inc, 0);
 
     inc = IncludeCreate(ktcsg->types, MergeDefault);
-    types = CreateXKBFile(ctx, XkmTypesIndex, NULL,
+    types = CreateXKBFile(ctx, FILE_TYPE_TYPES, NULL,
                           (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &types->common);
 
     inc = IncludeCreate(ktcsg->compat, MergeDefault);
-    compat = CreateXKBFile(ctx, XkmCompatMapIndex, NULL,
+    compat = CreateXKBFile(ctx, FILE_TYPE_COMPAT, NULL,
                            (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &compat->common);
 
     inc = IncludeCreate(ktcsg->symbols, MergeDefault);
-    symbols = CreateXKBFile(ctx, XkmSymbolsIndex, NULL,
+    symbols = CreateXKBFile(ctx, FILE_TYPE_SYMBOLS, NULL,
                             (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &symbols->common);
 
-    return CreateXKBFile(ctx, XkmKeymapFile,
+    return CreateXKBFile(ctx, FILE_TYPE_KEYMAP,
                          ktcsg->keymap ? ktcsg->keymap : strdup(""),
                          &keycodes->common, 0);
 }
@@ -141,7 +141,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
     if (!mapToUse)
         goto err;
 
-    if (mapToUse->type != XkmKeymapFile) {
+    if (mapToUse->type != FILE_TYPE_KEYMAP) {
         ERROR("file type %d not handled\n", mapToUse->type);
         goto err;
     }
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index ec0db0f..07d4523 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -237,7 +237,7 @@ typedef struct _IndicatorMapDef
 typedef struct _XkbFile
 {
     ParseCommon common;
-    unsigned type;
+    enum xkb_file_type type;
     char *topName;
     char *name;
     ParseCommon *defs;