[PATCH 2/4] xkb: Split out code to start and finish xkbcomp

Kristian Høgsberg krh at bitplanet.net
Wed Apr 10 09:07:34 PDT 2013


Using the context struct from previous commit, we can now split out
code to start xkbcomp and to finish and clean up after it.

Reviewed-by: Daniel Stone <daniel at fooishbar.org>
---
 xkb/ddxLoad.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index c717bd5..5defaf1 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -174,10 +174,7 @@ typedef struct XkbCompContext {
 } XkbCompContextRec, *XkbCompContextPtr;
 
 static Bool
-XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
-                           XkbComponentNamesPtr names,
-                           unsigned want,
-                           unsigned need, XkbCompContextPtr ctx)
+StartXkbComp(XkbCompContextPtr ctx)
 {
     char xkm_output_dir[PATH_MAX];
 
@@ -243,14 +240,15 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
     ctx->out = fopen(ctx->tmpname, "w");
 #endif
 
+    return ctx->out != NULL;
+}
+
+static Bool
+FinishXkbComp(XkbCompContextPtr ctx)
+{
+    if (!ctx->buf)
+	return FALSE;
     if (ctx->out != NULL) {
-#ifdef DEBUG
-        if (xkbDebugFlags) {
-            ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
-            XkbWriteXKBKeymapForNames(stderr, names, xkb, want, need);
-        }
-#endif
-        XkbWriteXKBKeymapForNames(ctx->out, names, xkb, want, need);
 #ifndef WIN32
         if (Pclose(ctx->out) == 0)
 #else
@@ -284,6 +282,25 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
     return FALSE;
 }
 
+static Bool
+XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
+                           XkbComponentNamesPtr names,
+                           unsigned want,
+                           unsigned need, XkbCompContextPtr ctx)
+{
+    if (StartXkbComp(ctx)) {
+#ifdef DEBUG
+        if (xkbDebugFlags) {
+            ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
+            XkbWriteXKBKeymapForNames(stderr, names, xkb, want, need);
+        }
+#endif
+        XkbWriteXKBKeymapForNames(ctx->out, names, xkb, want, need);
+    }
+
+    return FinishXkbComp(ctx);
+}
+
 static FILE *
 XkbDDXOpenConfigFile(char *mapName, char *fileNameRtrn, int fileNameRtrnLen)
 {
-- 
1.8.1.4



More information about the xorg-devel mailing list