Simplify HandleInclude functions
authorRan Benita <ran234@gmail.com>
Wed, 18 Jul 2012 14:53:27 +0000 (17:53 +0300)
committerRan Benita <ran234@gmail.com>
Wed, 18 Jul 2012 18:06:07 +0000 (21:06 +0300)
Instead of special casing the first include, process it inside the loop
as well. It works perfectly fine.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/compat.c
src/xkbcomp/keycodes.c
src/xkbcomp/keytypes.c
src/xkbcomp/symbols.c

index 4e2d1f0..f089fe5 100644 (file)
@@ -546,61 +546,45 @@ static bool
 HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
                        CompatInfo *info)
 {
-    enum merge_mode newMerge;
+    enum merge_mode merge = MERGE_DEFAULT;
     XkbFile *rtrn;
-    CompatInfo included;
+    CompatInfo included, next_incl;
 
-    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_COMPAT, &rtrn,
-                            &newMerge)) {
-        info->errorCount += 10;
-        return false;
-    }
-
-    InitCompatInfo(&included, keymap, rtrn->id);
-    included.dflt = info->dflt;
-    included.dflt.merge = newMerge;
-    included.ledDflt.merge = newMerge;
-    included.act = info->act;
-    HandleCompatMapFile(rtrn, keymap, MERGE_OVERRIDE, &included);
+    InitCompatInfo(&included, keymap, info->file_id);
     if (stmt->stmt) {
         free(included.name);
         included.name = stmt->stmt;
         stmt->stmt = NULL;
     }
-    if (info->act)
-        included.act = NULL;
-    FreeXKBFile(rtrn);
-
-    if (stmt->next && included.errorCount < 1) {
-        IncludeStmt *next;
-        unsigned op;
-        CompatInfo next_incl;
-
-        for (next = stmt->next; next; next = next->next) {
-            if (!ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_COMPAT,
-                                    &rtrn, &op)) {
-                info->errorCount += 10;
-                return false;
-            }
 
-            InitCompatInfo(&next_incl, keymap, rtrn->id);
-            next_incl.file_id = rtrn->id;
-            next_incl.dflt = info->dflt;
-            next_incl.dflt.file_id = rtrn->id;
-            next_incl.dflt.merge = op;
-            next_incl.ledDflt.file_id = rtrn->id;
-            next_incl.ledDflt.merge = op;
-            next_incl.act = info->act;
-            HandleCompatMapFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
-            MergeIncludedCompatMaps(&included, &next_incl, op);
-            if (info->act != NULL)
-                next_incl.act = NULL;
-            ClearCompatInfo(&next_incl, keymap);
-            FreeXKBFile(rtrn);
+    for (; stmt; stmt = stmt->next) {
+        if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_COMPAT,
+                                &rtrn, &merge)) {
+            info->errorCount += 10;
+            ClearCompatInfo(&included, keymap);
+            return false;
         }
+
+        InitCompatInfo(&next_incl, keymap, rtrn->id);
+        next_incl.file_id = rtrn->id;
+        next_incl.dflt = info->dflt;
+        next_incl.dflt.file_id = rtrn->id;
+        next_incl.dflt.merge = merge;
+        next_incl.ledDflt.file_id = rtrn->id;
+        next_incl.ledDflt.merge = merge;
+        next_incl.act = info->act;
+
+        HandleCompatMapFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
+
+        MergeIncludedCompatMaps(&included, &next_incl, merge);
+        if (info->act)
+            next_incl.act = NULL;
+
+        ClearCompatInfo(&next_incl, keymap);
+        FreeXKBFile(rtrn);
     }
 
-    MergeIncludedCompatMaps(info, &included, newMerge);
+    MergeIncludedCompatMaps(info, &included, merge);
     ClearCompatInfo(&included, keymap);
 
     return (info->errorCount == 0);
index dd1aa56..53986ed 100644 (file)
@@ -445,9 +445,9 @@ static bool
 HandleIncludeKeycodes(IncludeStmt *stmt, struct xkb_keymap *keymap,
                       KeyNamesInfo *info)
 {
-    enum merge_mode newMerge;
+    enum merge_mode merge = MERGE_DEFAULT;
     XkbFile *rtrn;
-    KeyNamesInfo included;
+    KeyNamesInfo included, next_incl;
 
     /* XXX: What's that? */
     if (stmt->file && strcmp(stmt->file, "computed") == 0) {
@@ -457,43 +457,32 @@ HandleIncludeKeycodes(IncludeStmt *stmt, struct xkb_keymap *keymap,
         return (info->errorCount == 0);
     }
 
-    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_KEYCODES, &rtrn,
-                            &newMerge)) {
-        info->errorCount += 10;
-        return false;
-    }
-
-    InitKeyNamesInfo(&included, rtrn->id);
-    HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &included);
+    InitKeyNamesInfo(&included, info->file_id);
     if (stmt->stmt) {
         free(included.name);
         included.name = stmt->stmt;
         stmt->stmt = NULL;
     }
-    FreeXKBFile(rtrn);
 
-    if (stmt->next && included.errorCount < 1) {
-        IncludeStmt *next;
-        unsigned op;
-        KeyNamesInfo next_incl;
+    for (; stmt; stmt = stmt->next) {
+        if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_KEYCODES,
+                                &rtrn, &merge)) {
+            info->errorCount += 10;
+            ClearKeyNamesInfo(&included);
+            return false;
+        }
 
-        for (next = stmt->next; next != NULL; next = next->next) {
-            if (!ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_KEYCODES,
-                                    &rtrn, &op)) {
-                info->errorCount += 10;
-                ClearKeyNamesInfo(&included);
-                return false;
-            }
+        InitKeyNamesInfo(&next_incl, rtrn->id);
 
-            InitKeyNamesInfo(&next_incl, rtrn->id);
-            HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
-            MergeIncludedKeycodes(&included, keymap, &next_incl, op);
-            ClearKeyNamesInfo(&next_incl);
-            FreeXKBFile(rtrn);
-        }
+        HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
+
+        MergeIncludedKeycodes(&included, keymap, &next_incl, merge);
+
+        ClearKeyNamesInfo(&next_incl);
+        FreeXKBFile(rtrn);
     }
 
-    MergeIncludedKeycodes(info, keymap, &included, newMerge);
+    MergeIncludedKeycodes(info, keymap, &included, merge);
     ClearKeyNamesInfo(&included);
 
     return (info->errorCount == 0);
index 89fc461..0e6346a 100644 (file)
@@ -341,50 +341,37 @@ static bool
 HandleIncludeKeyTypes(IncludeStmt *stmt, struct xkb_keymap *keymap,
                       KeyTypesInfo *info)
 {
-    enum merge_mode newMerge;
+    enum merge_mode merge = MERGE_DEFAULT;
     XkbFile *rtrn;
-    KeyTypesInfo included;
+    KeyTypesInfo included, next_incl;
 
-    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_TYPES, &rtrn,
-                            &newMerge)) {
-        info->errorCount += 10;
-        return false;
-    }
-
-    InitKeyTypesInfo(&included, keymap, info, rtrn->id);
-    included.dflt.defs.merge = newMerge;
-
-    HandleKeyTypesFile(rtrn, keymap, newMerge, &included);
+    InitKeyTypesInfo(&included, keymap, info, info->file_id);
     if (stmt->stmt) {
         free(included.name);
         included.name = stmt->stmt;
         stmt->stmt = NULL;
     }
-    FreeXKBFile(rtrn);
-
-    if ((stmt->next != NULL) && (included.errorCount < 1)) {
-        IncludeStmt *next;
-        unsigned op;
-        KeyTypesInfo next_incl;
-
-        for (next = stmt->next; next; next = next->next) {
-            if (!ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_TYPES,
-                                    &rtrn, &op)) {
-                info->errorCount += 10;
-                FreeKeyTypesInfo(&included);
-                return false;
-            }
 
-            InitKeyTypesInfo(&next_incl, keymap, &included, rtrn->id);
-            next_incl.dflt.defs.merge = op;
-            HandleKeyTypesFile(rtrn, keymap, op, &next_incl);
-            MergeIncludedKeyTypes(&included, &next_incl, op, keymap);
-            FreeKeyTypesInfo(&next_incl);
-            FreeXKBFile(rtrn);
+    for (; stmt; stmt = stmt->next) {
+        if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_TYPES,
+                                &rtrn, &merge)) {
+            info->errorCount += 10;
+            FreeKeyTypesInfo(&included);
+            return false;
         }
+
+        InitKeyTypesInfo(&next_incl, keymap, &included, rtrn->id);
+        next_incl.dflt.defs.merge = merge;
+
+        HandleKeyTypesFile(rtrn, keymap, merge, &next_incl);
+
+        MergeIncludedKeyTypes(&included, &next_incl, merge, keymap);
+
+        FreeKeyTypesInfo(&next_incl);
+        FreeXKBFile(rtrn);
     }
 
-    MergeIncludedKeyTypes(info, &included, newMerge, keymap);
+    MergeIncludedKeyTypes(info, &included, merge, keymap);
     FreeKeyTypesInfo(&included);
 
     return (info->errorCount == 0);
index 7069670..3c11415 100644 (file)
@@ -734,60 +734,41 @@ static bool
 HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
                      SymbolsInfo *info)
 {
-    enum merge_mode newMerge;
+    enum merge_mode merge = MERGE_DEFAULT;
     XkbFile *rtrn;
-    SymbolsInfo included;
+    SymbolsInfo included, next_incl;
 
-    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_SYMBOLS, &rtrn,
-                            &newMerge)) {
-        info->errorCount += 10;
-        return false;
-    }
-
-    InitSymbolsInfo(&included, keymap, rtrn->id);
-    included.merge = included.dflt.merge = MERGE_OVERRIDE;
-    if (stmt->modifier)
-        included.explicit_group = atoi(stmt->modifier) - 1;
-    else
-        included.explicit_group = info->explicit_group;
-    HandleSymbolsFile(rtrn, keymap, MERGE_OVERRIDE, &included);
+    InitSymbolsInfo(&included, keymap, info->file_id);
     if (stmt->stmt) {
         free(included.name);
         included.name = stmt->stmt;
         stmt->stmt = NULL;
     }
-    FreeXKBFile(rtrn);
 
-    if (stmt->next && included.errorCount < 1) {
-        IncludeStmt *next;
-        unsigned op;
-        SymbolsInfo next_incl;
+    for (; stmt; stmt = stmt->next) {
+        if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
+                                &rtrn, &merge)) {
+            info->errorCount += 10;
+            FreeSymbolsInfo(&included);
+            return false;
+        }
 
-        for (next = stmt->next; next; next = next->next) {
-            if (!ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_SYMBOLS,
-                                    &rtrn, &op)) {
-                info->errorCount += 10;
-                FreeSymbolsInfo(&included);
-                return false;
-            }
+        InitSymbolsInfo(&next_incl, keymap, rtrn->id);
+        next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
+        if (stmt->modifier)
+            next_incl.explicit_group = atoi(stmt->modifier) - 1;
+        else
+            next_incl.explicit_group = info->explicit_group;
 
-            InitSymbolsInfo(&next_incl, keymap, rtrn->id);
-            next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
-            if (next->modifier)
-                next_incl.explicit_group = atoi(next->modifier) - 1;
-            else
-                next_incl.explicit_group = info->explicit_group;
-            HandleSymbolsFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
-            MergeIncludedSymbols(&included, &next_incl, op, keymap);
-            FreeSymbolsInfo(&next_incl);
-            FreeXKBFile(rtrn);
-        }
-    }
-    else if (stmt->next) {
-        info->errorCount += included.errorCount;
+        HandleSymbolsFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
+
+        MergeIncludedSymbols(&included, &next_incl, merge, keymap);
+
+        FreeSymbolsInfo(&next_incl);
+        FreeXKBFile(rtrn);
     }
 
-    MergeIncludedSymbols(info, &included, newMerge, keymap);
+    MergeIncludedSymbols(info, &included, merge, keymap);
     FreeSymbolsInfo(&included);
 
     return (info->errorCount == 0);