From 3bea189bd5bf4fd23a6b3b1a6f4e8b0c51426586 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 1 Aug 2012 18:46:01 +0300 Subject: [PATCH] Make top level Handle*File functions nicer Signed-off-by: Ran Benita --- src/xkbcomp/compat.c | 48 +++++++++++++++--------------------- src/xkbcomp/keycodes.c | 46 ++++++++++++++--------------------- src/xkbcomp/keytypes.c | 50 ++++++++++++-------------------------- src/xkbcomp/parseutils.c | 25 +++++++++++++++++++ src/xkbcomp/symbols.c | 46 +++++++++++++---------------------- src/xkbcomp/xkbcomp-priv.h | 3 +++ src/xkbcomp/xkbcomp.h | 1 + 7 files changed, 100 insertions(+), 119 deletions(-) diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index 2b31fe8..be58175 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -1045,54 +1045,46 @@ HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def, static void HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge) { + bool ok; ParseCommon *stmt; - if (merge == MERGE_DEFAULT) - merge = MERGE_AUGMENT; + merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge); + free(info->name); info->name = strdup_safe(file->name); - stmt = file->defs; - while (stmt) - { + + for (stmt = file->defs; stmt; stmt = stmt->next) { switch (stmt->type) { case STMT_INCLUDE: - if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt)) - info->errorCount++; + ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt); break; case STMT_INTERP: - if (!HandleInterpDef(info, (InterpDef *) stmt, merge)) - info->errorCount++; + ok = HandleInterpDef(info, (InterpDef *) stmt, merge); break; case STMT_GROUP_COMPAT: - if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge)) - info->errorCount++; + ok = HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge); break; case STMT_INDICATOR_MAP: - if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge)) - info->errorCount++; + ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge); break; case STMT_VAR: - if (!HandleInterpVar(info, (VarDef *) stmt)) - info->errorCount++; + ok = HandleInterpVar(info, (VarDef *) stmt); break; case STMT_VMOD: - if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, - &info->vmods)) - info->errorCount++; - break; - case STMT_KEYCODE: - log_err(info->keymap->ctx, - "Interpretation files may not include other types; " - "Ignoring definition of key name\n"); - info->errorCount++; + ok = HandleVModDef((VModDef *) stmt, info->keymap, merge, + &info->vmods); break; default: - log_wsgo(info->keymap->ctx, - "Unexpected statement type %d in HandleCompatMapFile\n", - stmt->type); + log_err(info->keymap->ctx, + "Interpretation files may not include other types; " + "Ignoring %s\n", StmtTypeToString(stmt->type)); + ok = false; break; } - stmt = stmt->next; + + if (!ok) + info->errorCount++; + if (info->errorCount > 10) { log_err(info->keymap->ctx, "Abandoning compatibility map \"%s\"\n", file->topName); diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 646a585..fa93da5 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -748,51 +748,41 @@ static void HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge) { ParseCommon *stmt; + bool ok; free(info->name); info->name = strdup_safe(file->name); - stmt = file->defs; - while (stmt) - { + + for (stmt = file->defs; stmt; stmt = stmt->next) { switch (stmt->type) { case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */ - if (!HandleIncludeKeycodes(info, (IncludeStmt *) stmt)) - info->errorCount++; + ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt); break; case STMT_KEYCODE: /* e.g. = 9; */ - if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge)) - info->errorCount++; + ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge); break; case STMT_ALIAS: /* e.g. alias = ; */ - if (!HandleAliasDef(info, (KeyAliasDef *) stmt, merge, - info->file_id)) - info->errorCount++; + ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge, + info->file_id); break; case STMT_VAR: /* e.g. minimum, maximum */ - if (!HandleKeyNameVar(info, (VarDef *) stmt)) - info->errorCount++; + ok = HandleKeyNameVar(info, (VarDef *) stmt); break; case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */ - if (!HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt, - merge)) - info->errorCount++; - break; - case STMT_INTERP: - case STMT_VMOD: - log_err(info->keymap->ctx, - "Keycode files may define key and indicator names only; " - "Ignoring definition of %s\n", - (stmt->type == STMT_INTERP ? - "a symbol interpretation" : "virtual modifiers")); - info->errorCount++; + ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt, + merge); break; default: - log_wsgo(info->keymap->ctx, - "Unexpected statement type %d in HandleKeycodesFile\n", - stmt->type); + log_err(info->keymap->ctx, + "Keycode files may define key and indicator names only; " + "Ignoring %s\n", StmtTypeToString(stmt->type)); + ok = false; break; } - stmt = stmt->next; + + if (!ok) + info->errorCount++; + if (info->errorCount > 10) { log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n", file->topName); diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 2661816..fc5e578 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -879,56 +879,38 @@ HandleKeyTypeDef(KeyTypesInfo *info, KeyTypeDef *def, enum merge_mode merge) static void HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge) { + bool ok; ParseCommon *stmt; free(info->name); info->name = strdup_safe(file->name); - stmt = file->defs; - while (stmt) - { + + for (stmt = file->defs; stmt; stmt = stmt->next) { switch (stmt->type) { case STMT_INCLUDE: - if (!HandleIncludeKeyTypes(info, (IncludeStmt *) stmt)) - info->errorCount++; + ok = HandleIncludeKeyTypes(info, (IncludeStmt *) stmt); break; case STMT_TYPE: /* e.g. type "ONE_LEVEL" */ - if (!HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge)) - info->errorCount++; + ok = HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge); break; case STMT_VAR: - if (!HandleKeyTypeVar(info, (VarDef *) stmt)) - info->errorCount++; + ok = HandleKeyTypeVar(info, (VarDef *) stmt); break; case STMT_VMOD: /* virtual_modifiers NumLock, ... */ - if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, - &info->vmods)) - info->errorCount++; - break; - case STMT_ALIAS: - log_err(info->keymap->ctx, - "Key type files may not include other declarations; " - "Ignoring definition of key alias\n"); - info->errorCount++; - break; - case STMT_KEYCODE: - log_err(info->keymap->ctx, - "Key type files may not include other declarations; " - "Ignoring definition of key name\n"); - info->errorCount++; - break; - case STMT_INTERP: - log_err(info->keymap->ctx, - "Key type files may not include other declarations; " - "Ignoring definition of symbol interpretation\n"); - info->errorCount++; + ok = HandleVModDef((VModDef *) stmt, info->keymap, merge, + &info->vmods); break; default: - log_wsgo(info->keymap->ctx, - "Unexpected statement type %d in HandleKeyTypesFile\n", - stmt->type); + log_err(info->keymap->ctx, + "Key type files may not include other declarations; " + "Ignoring %s\n", StmtTypeToString(stmt->type)); + ok = false; break; } - stmt = stmt->next; + + if (!ok) + info->errorCount++; + if (info->errorCount > 10) { log_err(info->keymap->ctx, "Abandoning keytypes file \"%s\"\n", file->topName); diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c index 2eb119b..9dbe834 100644 --- a/src/xkbcomp/parseutils.c +++ b/src/xkbcomp/parseutils.c @@ -671,3 +671,28 @@ FreeXKBFile(XkbFile *file) file = next; } } + +const char *stmt_type_strings[_STMT_NUM_VALUES] = { + [STMT_UNKNOWN] = "unknown statement", + [STMT_INCLUDE] = "include statement", + [STMT_KEYCODE] = "key name definition", + [STMT_ALIAS] = "key alias definition", + [STMT_EXPR] = "expression", + [STMT_VAR] = "variable definition", + [STMT_TYPE] = "key type definition", + [STMT_INTERP] = "symbol interpretation definition", + [STMT_VMOD] = "virtual modifiers definition", + [STMT_SYMBOLS] = "key symbols definition", + [STMT_MODMAP] = "modifier map declaration", + [STMT_GROUP_COMPAT] = "group declaration", + [STMT_INDICATOR_MAP] = "indicator map declaration", + [STMT_INDICATOR_NAME] = "indicator name declaration", +}; + +const char * +StmtTypeToString(enum stmt_type type) +{ + if (type >= _STMT_NUM_VALUES) + type = STMT_UNKNOWN; + return stmt_type_strings[type]; +} diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 4529958..9c76aa4 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1409,54 +1409,42 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def) static void HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge) { + bool ok; ParseCommon *stmt; free(info->name); info->name = strdup_safe(file->name); + stmt = file->defs; - while (stmt) - { + for (stmt = file->defs; stmt; stmt = stmt->next) { switch (stmt->type) { case STMT_INCLUDE: - if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt)) - info->errorCount++; + ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt); break; case STMT_SYMBOLS: - if (!HandleSymbolsDef(info, (SymbolsDef *) stmt)) - info->errorCount++; + ok = HandleSymbolsDef(info, (SymbolsDef *) stmt); break; case STMT_VAR: - if (!HandleSymbolsVar(info, (VarDef *) stmt)) - info->errorCount++; + ok = HandleSymbolsVar(info, (VarDef *) stmt); break; case STMT_VMOD: - if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, - &info->vmods)) - info->errorCount++; - break; - case STMT_INTERP: - log_err(info->keymap->ctx, - "Interpretation files may not include other types; " - "Ignoring definition of symbol interpretation\n"); - info->errorCount++; - break; - case STMT_KEYCODE: - log_err(info->keymap->ctx, - "Interpretation files may not include other types; " - "Ignoring definition of key name\n"); - info->errorCount++; + ok = HandleVModDef((VModDef *) stmt, info->keymap, merge, + &info->vmods); break; case STMT_MODMAP: - if (!HandleModMapDef(info, (ModMapDef *) stmt)) - info->errorCount++; + ok = HandleModMapDef(info, (ModMapDef *) stmt); break; default: - log_wsgo(info->keymap->ctx, - "Unexpected statement type %d in HandleSymbolsFile\n", - stmt->type); + log_err(info->keymap->ctx, + "Interpretation files may not include other types; " + "Ignoring %s\n", StmtTypeToString(stmt->type)); + ok = false; break; } - stmt = stmt->next; + + if (!ok) + info->errorCount++; + if (info->errorCount > 10) { log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n", file->topName); diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h index c92ba5a..060c686 100644 --- a/src/xkbcomp/xkbcomp-priv.h +++ b/src/xkbcomp/xkbcomp-priv.h @@ -49,6 +49,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap); xkb_mod_mask_t VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask); +const char * +StmtTypeToString(enum stmt_type type); + static inline unsigned long KeyNameToLong(const char *name) { diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h index 9ab77c4..a153147 100644 --- a/src/xkbcomp/xkbcomp.h +++ b/src/xkbcomp/xkbcomp.h @@ -44,6 +44,7 @@ enum stmt_type { STMT_GROUP_COMPAT, STMT_INDICATOR_MAP, STMT_INDICATOR_NAME, + _STMT_NUM_VALUES }; enum expr_value_type {