Remove haveSelf include feature
authorRan Benita <ran234@gmail.com>
Wed, 18 Jul 2012 13:30:55 +0000 (16:30 +0300)
committerRan Benita <ran234@gmail.com>
Wed, 18 Jul 2012 17:40:33 +0000 (20:40 +0300)
When including a file from another file, its possible to do something
like this:
    include "+some(other)+files"
with the "+" or "|" in the beginning. What will happen then is that
instead of processing the include files separately and then merging into
the existing info, we instead start with the existing info and merge
into it as we go, as if it was written explicitly before the first "+".

It's not particulary clear what this may be useful for. Since it's not
used by xkeyboard-config, not documented anywhere (and google doesn't
bring up anything), completely untested and kind of ugly, remove this
"feature". It most likely never been used.

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/path.c
src/xkbcomp/symbols.c

index fc38be3..4e2d1f0 100644 (file)
@@ -549,75 +549,60 @@ HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
     enum merge_mode newMerge;
     XkbFile *rtrn;
     CompatInfo included;
-    bool haveSelf;
 
-    haveSelf = false;
-    if ((stmt->file == NULL) && (stmt->map == NULL)) {
-        haveSelf = true;
-        included = *info;
-        memset(info, 0, sizeof(CompatInfo));
-    }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_COMPAT, &rtrn,
-                                &newMerge)) {
-        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);
-        if (stmt->stmt != NULL) {
-            free(included.name);
-            included.name = stmt->stmt;
-            stmt->stmt = NULL;
-        }
-        if (info->act != NULL)
-            included.act = NULL;
-        FreeXKBFile(rtrn);
-    }
-    else {
+    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_COMPAT, &rtrn,
+                            &newMerge)) {
         info->errorCount += 10;
         return false;
     }
-    if ((stmt->next != NULL) && (included.errorCount < 1)) {
+
+    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);
+    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 != NULL; next = next->next) {
-            if ((next->file == NULL) && (next->map == NULL)) {
-                haveSelf = true;
-                MergeIncludedCompatMaps(&included, info, next->merge);
-                ClearCompatInfo(info, keymap);
-            }
-            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_COMPAT,
-                                        &rtrn, &op)) {
-                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);
-            }
-            else {
+        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);
         }
     }
-    if (haveSelf)
-        *info = included;
-    else {
-        MergeIncludedCompatMaps(info, &included, newMerge);
-        ClearCompatInfo(&included, keymap);
-    }
+
+    MergeIncludedCompatMaps(info, &included, newMerge);
+    ClearCompatInfo(&included, keymap);
+
     return (info->errorCount == 0);
 }
 
index bd7bba9..dd1aa56 100644 (file)
@@ -448,70 +448,54 @@ HandleIncludeKeycodes(IncludeStmt *stmt, struct xkb_keymap *keymap,
     enum merge_mode newMerge;
     XkbFile *rtrn;
     KeyNamesInfo included;
-    bool haveSelf;
 
-    memset(&included, 0, sizeof(included));
-
-    haveSelf = false;
-    if ((stmt->file == NULL) && (stmt->map == NULL)) {
-        haveSelf = true;
-        included = *info;
-        memset(info, 0, sizeof(KeyNamesInfo));
-    }
-    else if (stmt->file && strcmp(stmt->file, "computed") == 0) {
+    /* XXX: What's that? */
+    if (stmt->file && strcmp(stmt->file, "computed") == 0) {
         keymap->flags |= AutoKeyNames;
         info->explicitMin = 0;
         info->explicitMax = XKB_KEYCODE_MAX;
         return (info->errorCount == 0);
-    } /* parse file, store returned info in the xkb struct */
-    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_KEYCODES, &rtrn,
-                                &newMerge)) {
-        InitKeyNamesInfo(&included, rtrn->id);
-        HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &included);
-        if (stmt->stmt != NULL) {
-            free(included.name);
-            included.name = stmt->stmt;
-            stmt->stmt = NULL;
-        }
-        FreeXKBFile(rtrn);
     }
-    else {
-        info->errorCount += 10; /* XXX: why 10?? */
+
+    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_KEYCODES, &rtrn,
+                            &newMerge)) {
+        info->errorCount += 10;
         return false;
     }
-    /* Do we have more than one include statement? */
-    if ((stmt->next != NULL) && (included.errorCount < 1)) {
+
+    InitKeyNamesInfo(&included, rtrn->id);
+    HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &included);
+    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 (next = stmt->next; next != NULL; next = next->next) {
-            if ((next->file == NULL) && (next->map == NULL)) {
-                haveSelf = true;
-                MergeIncludedKeycodes(&included, keymap, info, next->merge);
-                ClearKeyNamesInfo(info);
-            }
-            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_KEYCODES,
-                                        &rtrn, &op)) {
-                InitKeyNamesInfo(&next_incl, rtrn->id);
-                HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
-                MergeIncludedKeycodes(&included, keymap, &next_incl, op);
-                ClearKeyNamesInfo(&next_incl);
-                FreeXKBFile(rtrn);
-            }
-            else {
-                info->errorCount += 10; /* XXX: Why 10?? */
+            if (!ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_KEYCODES,
+                                    &rtrn, &op)) {
+                info->errorCount += 10;
                 ClearKeyNamesInfo(&included);
                 return false;
             }
+
+            InitKeyNamesInfo(&next_incl, rtrn->id);
+            HandleKeycodesFile(rtrn, keymap, MERGE_OVERRIDE, &next_incl);
+            MergeIncludedKeycodes(&included, keymap, &next_incl, op);
+            ClearKeyNamesInfo(&next_incl);
+            FreeXKBFile(rtrn);
         }
     }
-    if (haveSelf)
-        *info = included;
-    else {
-        MergeIncludedKeycodes(info, keymap, &included, newMerge);
-        ClearKeyNamesInfo(&included);
-    }
+
+    MergeIncludedKeycodes(info, keymap, &included, newMerge);
+    ClearKeyNamesInfo(&included);
+
     return (info->errorCount == 0);
 }
 
index 9e1a094..89fc461 100644 (file)
@@ -344,64 +344,49 @@ HandleIncludeKeyTypes(IncludeStmt *stmt, struct xkb_keymap *keymap,
     enum merge_mode newMerge;
     XkbFile *rtrn;
     KeyTypesInfo included;
-    bool haveSelf;
 
-    haveSelf = false;
-    if ((stmt->file == NULL) && (stmt->map == NULL)) {
-        haveSelf = true;
-        included = *info;
-        memset(info, 0, sizeof(KeyTypesInfo));
-    }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_TYPES, &rtrn,
-                                &newMerge)) {
-        InitKeyTypesInfo(&included, keymap, info, rtrn->id);
-        included.dflt.defs.merge = newMerge;
-
-        HandleKeyTypesFile(rtrn, keymap, newMerge, &included);
-        if (stmt->stmt != NULL) {
-            free(included.name);
-            included.name = stmt->stmt;
-            stmt->stmt = NULL;
-        }
-        FreeXKBFile(rtrn);
-    }
-    else {
+    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);
+    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 != NULL; next = next->next) {
-            if ((next->file == NULL) && (next->map == NULL)) {
-                haveSelf = true;
-                MergeIncludedKeyTypes(&included, info, next->merge, keymap);
-                FreeKeyTypesInfo(info);
-            }
-            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_TYPES,
-                                        &rtrn, &op)) {
-                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);
-            }
-            else {
+        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);
         }
     }
-    if (haveSelf)
-        *info = included;
-    else {
-        MergeIncludedKeyTypes(info, &included, newMerge, keymap);
-        FreeKeyTypesInfo(&included);
-    }
+
+    MergeIncludedKeyTypes(info, &included, newMerge, keymap);
+    FreeKeyTypesInfo(&included);
+
     return (info->errorCount == 0);
 }
 
index 02833d2..b71cb82 100644 (file)
@@ -452,59 +452,53 @@ IncludeCreate(char *str, enum merge_mode merge)
     IncludeStmt *incl, *first;
     char *file, *map, *stmt, *tmp, *extra_data;
     char nextop;
-    bool haveSelf;
 
-    haveSelf = false;
     incl = first = NULL;
     file = map = NULL;
     tmp = str;
     stmt = uDupString(str);
-    while ((tmp) && (*tmp))
+    while (tmp && *tmp)
     {
-        if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data)) {
-            if ((file == NULL) && (map == NULL)) {
-                if (haveSelf)
-                    goto BAIL;
-                haveSelf = true;
-            }
-            if (first == NULL)
-                first = incl = uTypedAlloc(IncludeStmt);
-            else {
-                incl->next = uTypedAlloc(IncludeStmt);
-                incl = incl->next;
-            }
-            if (incl) {
-                incl->common.stmtType = StmtInclude;
-                incl->common.next = NULL;
-                incl->merge = merge;
-                incl->stmt = NULL;
-                incl->file = file;
-                incl->map = map;
-                incl->modifier = extra_data;
-                incl->path = NULL;
-                incl->next = NULL;
-            }
-            else {
-                WSGO("Allocation failure in IncludeCreate\n");
-                ACTION("Using only part of the include\n");
-                break;
-            }
-            if (nextop == '|')
-                merge = MERGE_AUGMENT;
-            else
-                merge = MERGE_OVERRIDE;
+        if (!XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
+            goto err;
+
+        if (first == NULL) {
+            first = incl = uTypedAlloc(IncludeStmt);
+        } else {
+            incl->next = uTypedAlloc(IncludeStmt);
+            incl = incl->next;
         }
-        else {
-            goto BAIL;
+
+        if (!incl) {
+            WSGO("Allocation failure in IncludeCreate\n");
+            ACTION("Using only part of the include\n");
+            break;
         }
+
+        incl->common.stmtType = StmtInclude;
+        incl->common.next = NULL;
+        incl->merge = merge;
+        incl->stmt = NULL;
+        incl->file = file;
+        incl->map = map;
+        incl->modifier = extra_data;
+        incl->path = NULL;
+        incl->next = NULL;
+
+        if (nextop == '|')
+            merge = MERGE_AUGMENT;
+        else
+            merge = MERGE_OVERRIDE;
     }
+
     if (first)
         first->stmt = stmt;
     else
         free(stmt);
+
     return first;
 
-BAIL:
+err:
     ERROR("Illegal include statement \"%s\"\n", stmt);
     ACTION("Ignored\n");
     FreeInclude(first);
index 687fb2f..13a56e1 100644 (file)
@@ -62,66 +62,59 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
     char *tmp, *str, *next;
 
     str = *str_inout;
-    if ((*str == '+') || (*str == '|')) {
-        *file_rtrn = *map_rtrn = NULL;
-        *nextop_rtrn = *str;
-        next = str + 1;
+
+    /* search for tokens inside the string */
+    next = strpbrk(str, "|+");
+    if (next) {
+        /* set nextop_rtrn to \0, next to next character */
+        *nextop_rtrn = *next;
+        *next++ = '\0';
     }
-    else if (*str == '%') {
-        *file_rtrn = *map_rtrn = NULL;
-        *nextop_rtrn = str[1];
-        next = str + 2;
+    else {
+        *nextop_rtrn = '\0';
+        next = NULL;
+    }
+
+    /* search for :, store result in extra_data */
+    tmp = strchr(str, ':');
+    if (tmp != NULL) {
+        *tmp++ = '\0';
+        *extra_data = uDupString(tmp);
     }
     else {
-        /* search for tokens inside the string */
-        next = strpbrk(str, "|+");
-        if (next) {
-            /* set nextop_rtrn to \0, next to next character */
-            *nextop_rtrn = *next;
-            *next++ = '\0';
-        }
-        else {
-            *nextop_rtrn = '\0';
-            next = NULL;
-        }
-        /* search for :, store result in extra_data */
-        tmp = strchr(str, ':');
-        if (tmp != NULL) {
-            *tmp++ = '\0';
-            *extra_data = uDupString(tmp);
-        }
-        else {
-            *extra_data = NULL;
-        }
-        tmp = strchr(str, '(');
-        if (tmp == NULL) {
-            *file_rtrn = uDupString(str);
-            *map_rtrn = NULL;
-        }
-        else if (str[0] == '(') {
+        *extra_data = NULL;
+    }
+
+    tmp = strchr(str, '(');
+    if (tmp == NULL) {
+        *file_rtrn = uDupString(str);
+        *map_rtrn = NULL;
+    }
+    else if (str[0] == '(') {
+        free(*extra_data);
+        return false;
+    }
+    else {
+        *tmp++ = '\0';
+        *file_rtrn = uDupString(str);
+        str = tmp;
+        tmp = strchr(str, ')');
+        if ((tmp == NULL) || (tmp[1] != '\0')) {
+            free(*file_rtrn);
             free(*extra_data);
             return false;
         }
-        else {
-            *tmp++ = '\0';
-            *file_rtrn = uDupString(str);
-            str = tmp;
-            tmp = strchr(str, ')');
-            if ((tmp == NULL) || (tmp[1] != '\0')) {
-                free(*file_rtrn);
-                free(*extra_data);
-                return false;
-            }
-            *tmp++ = '\0';
-            *map_rtrn = uDupString(str);
-        }
+        *tmp++ = '\0';
+        *map_rtrn = uDupString(str);
     }
+
     if (*nextop_rtrn == '\0')
         *str_inout = NULL;
     else if ((*nextop_rtrn == '|') || (*nextop_rtrn == '+'))
         *str_inout = next;
     else
         return false;
+
     return true;
 }
 
index 532ea4c..7069670 100644 (file)
@@ -737,74 +737,59 @@ HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
     enum merge_mode newMerge;
     XkbFile *rtrn;
     SymbolsInfo included;
-    bool haveSelf;
-
-    haveSelf = false;
-    if ((stmt->file == NULL) && (stmt->map == NULL)) {
-        haveSelf = true;
-        included = *info;
-        memset(info, 0, sizeof(SymbolsInfo));
-    }
-    else if (ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_SYMBOLS, &rtrn,
-                                &newMerge)) {
-        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);
-        if (stmt->stmt != NULL) {
-            free(included.name);
-            included.name = stmt->stmt;
-            stmt->stmt = NULL;
-        }
-        FreeXKBFile(rtrn);
-    }
-    else {
+
+    if (!ProcessIncludeFile(keymap->ctx, stmt, FILE_TYPE_SYMBOLS, &rtrn,
+                            &newMerge)) {
         info->errorCount += 10;
         return false;
     }
-    if ((stmt->next != NULL) && (included.errorCount < 1)) {
+
+    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);
+    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 (next = stmt->next; next != NULL; next = next->next) {
-            if ((next->file == NULL) && (next->map == NULL)) {
-                haveSelf = true;
-                MergeIncludedSymbols(&included, info, next->merge, keymap);
-                FreeSymbolsInfo(info);
-            }
-            else if (ProcessIncludeFile(keymap->ctx, next, FILE_TYPE_SYMBOLS,
-                                        &rtrn, &op)) {
-                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 {
+        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 (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;
     }
-    if (haveSelf)
-        *info = included;
-    else {
-        MergeIncludedSymbols(info, &included, newMerge, keymap);
-        FreeSymbolsInfo(&included);
-    }
+
+    MergeIncludedSymbols(info, &included, newMerge, keymap);
+    FreeSymbolsInfo(&included);
+
     return (info->errorCount == 0);
 }