Make top level Handle*File functions nicer
authorRan Benita <ran234@gmail.com>
Wed, 1 Aug 2012 15:46:01 +0000 (18:46 +0300)
committerRan Benita <ran234@gmail.com>
Tue, 7 Aug 2012 08:09:42 +0000 (11:09 +0300)
Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/compat.c
src/xkbcomp/keycodes.c
src/xkbcomp/keytypes.c
src/xkbcomp/parseutils.c
src/xkbcomp/symbols.c
src/xkbcomp/xkbcomp-priv.h
src/xkbcomp/xkbcomp.h

index 2b31fe8..be58175 100644 (file)
@@ -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++;
+            ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
+                               &info->vmods);
             break;
-        case STMT_KEYCODE:
+        default:
             log_err(info->keymap->ctx,
                     "Interpretation files may not include other types; "
-                    "Ignoring definition of key name\n");
-            info->errorCount++;
-            break;
-        default:
-            log_wsgo(info->keymap->ctx,
-                     "Unexpected statement type %d in HandleCompatMapFile\n",
-                     stmt->type);
+                    "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);
index 646a585..fa93da5 100644 (file)
@@ -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. <ESC> = 9; */
-            if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge))
-                info->errorCount++;
+            ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
             break;
         case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
-            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++;
+            ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
+                                        merge);
             break;
-        case STMT_INTERP:
-        case STMT_VMOD:
+        default:
             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++;
-            break;
-        default:
-            log_wsgo(info->keymap->ctx,
-                     "Unexpected statement type %d in HandleKeycodesFile\n",
-                     stmt->type);
+                    "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);
index 2661816..fc5e578 100644 (file)
@@ -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++;
+            ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
+                               &info->vmods);
             break;
-        case STMT_INTERP:
+        default:
             log_err(info->keymap->ctx,
                     "Key type files may not include other declarations; "
-                    "Ignoring definition of symbol interpretation\n");
-            info->errorCount++;
-            break;
-        default:
-            log_wsgo(info->keymap->ctx,
-                     "Unexpected statement type %d in HandleKeyTypesFile\n",
-                     stmt->type);
+                    "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);
index 2eb119b..9dbe834 100644 (file)
@@ -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];
+}
index 4529958..9c76aa4 100644 (file)
@@ -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);
index c92ba5a..060c686 100644 (file)
@@ -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)
 {
index 9ab77c4..a153147 100644 (file)
@@ -44,6 +44,7 @@ enum stmt_type {
     STMT_GROUP_COMPAT,
     STMT_INDICATOR_MAP,
     STMT_INDICATOR_NAME,
+    _STMT_NUM_VALUES
 };
 
 enum expr_value_type {