diff options
author | Ran Benita <ran234@gmail.com> | 2012-06-29 17:05:33 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-07-01 00:51:56 +0300 |
commit | 48b4d30aa39a0d41490b8099576909fda73d3a75 (patch) | |
tree | f580ec980e31eacd5d404cc0b9fff28194f1189d /src/xkbcomp/keymap.c | |
parent | 8f257397af28b1107c2a93da55ee74f7b7e8bd1f (diff) |
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>
Diffstat (limited to 'src/xkbcomp/keymap.c')
-rw-r--r-- | src/xkbcomp/keymap.c | 62 |
1 files changed, 30 insertions, 32 deletions
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; } |