Move allocation of xkb_desc into CompileKeymap Signed-off-by: Daniel Stone <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index f73eeff..76e2bc8 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -31,14 +31,15 @@
#include "action.h"
#include "misc.h"
#include "indicators.h"
+#include "xkballoc.h"
/**
* Compile the given file and store the output in xkb.
* @param file A list of XkbFiles, each denoting one type (e.g.
* XkmKeyNamesIdx, etc.)
*/
-Bool
-CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
+struct xkb_desc *
+CompileKeymap(XkbFile *file, unsigned merge)
{
unsigned have;
Bool ok;
@@ -46,6 +47,7 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
unsigned mainType;
char *mainName;
LEDInfo *unbound = NULL;
+ struct xkb_desc *xkb = XkbcAllocKeyboard();
struct {
XkbFile *keycodes;
XkbFile *types;
@@ -53,6 +55,9 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
XkbFile *symbols;
} sections;
+ if (!xkb)
+ return NULL;
+
memset(§ions, 0, sizeof(sections));
mainType = file->type;
mainName = file->name;
@@ -91,13 +96,13 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
ERROR("More than one %s section in a %s file\n",
XkbcConfigText(file->type), XkbcConfigText(mainType));
ACTION("All sections after the first ignored\n");
- return False;
+ continue;
}
else if ((1 << file->type) & (~legal))
{
ERROR("Cannot define %s in a %s file\n",
XkbcConfigText(file->type), XkbcConfigText(mainType));
- return False;
+ continue;
}
switch (file->type)
@@ -146,32 +151,50 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
{
if (missing & bit)
{
- ERROR("Missing %s section in a %s file\n",
- XkbcConfigText(i), XkbcConfigText(mainType));
+ ERROR("Required section %s missing from keymap\n", XkbcConfigText(i));
missing &= ~bit;
}
}
- ACTION("Description of %s not compiled\n",
- XkbcConfigText(mainType));
- return False;
+ goto err;
}
/* compile the sections we have in the file one-by-one, or fail. */
if (sections.keycodes != NULL &&
!CompileKeycodes(sections.keycodes, xkb, MergeOverride))
- return False;
+ {
+ ERROR("Failed to compile keycodes\n");
+ goto err;
+ }
if (sections.types != NULL &&
!CompileKeyTypes(sections.types, xkb, MergeOverride))
- return False;
+ {
+ ERROR("Failed to compile key types\n");
+ goto err;
+ }
if (sections.compat != NULL &&
!CompileCompatMap(sections.compat, xkb, MergeOverride, &unbound))
- return False;
+ {
+ ERROR("Failed to compile compat map\n");
+ goto err;
+ }
if (sections.symbols != NULL &&
!CompileSymbols(sections.symbols, xkb, MergeOverride))
- return False;
+ {
+ ERROR("Failed to compile symbols\n");
+ goto err;
+ }
xkb->defined = have;
ok = BindIndicators(xkb, True, unbound, NULL);
- return ok;
+ if (!ok)
+ goto err;
+
+ return xkb;
+
+err:
+ ACTION("Failed to compile keymap\n");
+ if (xkb)
+ xkb_free_keymap(xkb);
+ return NULL;
}
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 74aa1fb..6c01224 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -189,8 +189,9 @@ compile_keymap(XkbFile *file, const char *mapName)
struct xkb_desc * xkb = NULL;
/* Find map to use */
- if (!(mapToUse = XkbChooseMap(file, mapName)))
- goto unwind_file;
+ mapToUse = XkbChooseMap(file, mapName);
+ if (!mapToUse)
+ goto err;
switch (mapToUse->type) {
case XkmSemanticsFile:
@@ -199,26 +200,20 @@ compile_keymap(XkbFile *file, const char *mapName)
break;
default:
ERROR("file type %d not handled\n", mapToUse->type);
- goto unwind_file;
+ goto err;
}
- /* Compile the keyboard */
- if (!(xkb = XkbcAllocKeyboard())) {
- ERROR("could not allocate keyboard description\n");
- goto unwind_file;
- }
+ xkb = CompileKeymap(mapToUse, MergeReplace);
+ if (!xkb)
+ goto err;
- if (!CompileKeymap(mapToUse, xkb, MergeReplace)) {
- ERROR("failed to compile keymap\n");
- XkbcFreeKeyboard(xkb);
- xkb = NULL;
- }
+ return xkb;
-unwind_file:
+err:
FreeXKBFile(file);
free(scanFile);
XkbFreeIncludePath();
- return xkb;
+ return NULL;
}
struct xkb_desc *
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index f03de4f..db81e80 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -267,8 +267,8 @@ typedef struct _XkbFile
Bool compiled;
} XkbFile;
-extern Bool
-CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge);
+extern struct xkb_desc *
+CompileKeymap(XkbFile *file, unsigned merge);
extern Bool
CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge);