Commit 57b551a4189c7c9d9dccc816c43b4c18e1111392

Daniel Stone 2012-03-09T18:46:46

Ensure we always have a complete keymap Refuse to compile without keycodes + compat + types + symbols. Signed-off-by: Daniel Stone <daniel@fooishbar.org>

diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 156e223..f73eeff 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -67,7 +67,8 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
         legal = XkmKeymapLegal;
         break;
     case XkmKeymapFile:
-        required = XkmKeymapRequired;
+        required = XkmKeyNamesIndex | XkmTypesIndex | XkmSymbolsIndex | \
+                   XkmCompatMapIndex | XkmVirtualModsIndex;
         legal = XkmKeymapLegal;
         break;
     default:
@@ -136,21 +137,6 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
         have |= (1 << file->type);
     }
 
-    /* compile the sections we have in the file one-by-one, or fail. */
-    if (sections.keycodes != NULL &&
-        !CompileKeycodes(sections.keycodes, xkb, MergeOverride))
-        return False;
-    if (sections.types != NULL &&
-        !CompileKeyTypes(sections.types, xkb, MergeOverride))
-        return False;
-    if (sections.compat != NULL &&
-        !CompileCompatMap(sections.compat, xkb, MergeOverride, &unbound))
-        return False;
-    if (sections.symbols != NULL &&
-        !CompileSymbols(sections.symbols, xkb, MergeOverride))
-        return False;
-
-    xkb->defined = have;
     if (required & (~have))
     {
         int i, bit;
@@ -170,6 +156,22 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
         return False;
     }
 
+    /* compile the sections we have in the file one-by-one, or fail. */
+    if (sections.keycodes != NULL &&
+        !CompileKeycodes(sections.keycodes, xkb, MergeOverride))
+        return False;
+    if (sections.types != NULL &&
+        !CompileKeyTypes(sections.types, xkb, MergeOverride))
+        return False;
+    if (sections.compat != NULL &&
+        !CompileCompatMap(sections.compat, xkb, MergeOverride, &unbound))
+        return False;
+    if (sections.symbols != NULL &&
+        !CompileSymbols(sections.symbols, xkb, MergeOverride))
+        return False;
+
+    xkb->defined = have;
+
     ok = BindIndicators(xkb, True, unbound, NULL);
     return ok;
 }
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 5630ea5..74aa1fb 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -45,11 +45,6 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
     XkbFile *keycodes, *types, *compat, *symbols;
     IncludeStmt *inc;
 
-    if (!ktcsg) {
-        ERROR("no components to generate keymap file from\n");
-        return NULL;
-    }
-
     inc = IncludeCreate(ktcsg->keycodes, MergeDefault);
     keycodes = CreateXKBFile(XkmKeyNamesIndex, NULL, (ParseCommon *)inc, 0);
 
@@ -231,11 +226,31 @@ xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg)
 {
     XkbFile *file;
 
-    if (!ktcsg || ISEMPTY(ktcsg->keycodes)) {
+    if (!ktcsg) {
+        ERROR("no components specified\n");
+        return NULL;
+    }
+
+    if (ISEMPTY(ktcsg->keycodes)) {
         ERROR("keycodes required to generate XKB keymap\n");
         return NULL;
     }
 
+    if (ISEMPTY(ktcsg->compat)) {
+        ERROR("compat map required to generate XKB keymap\n");
+        return NULL;
+    }
+
+    if (ISEMPTY(ktcsg->types)) {
+        ERROR("types required to generate XKB keymap\n");
+        return NULL;
+    }
+
+    if (ISEMPTY(ktcsg->symbols)) {
+        ERROR("symbols required to generate XKB keymap\n");
+        return NULL;
+    }
+
     if (!(file = XkbKeymapFileFromComponents(ktcsg))) {
         ERROR("failed to generate parsed XKB file from components\n");
         return NULL;