Use xkb_contexts in keymap compilation
authorDaniel Stone <daniel@fooishbar.org>
Tue, 27 Mar 2012 16:22:35 +0000 (17:22 +0100)
committerDaniel Stone <daniel@fooishbar.org>
Tue, 27 Mar 2012 16:22:35 +0000 (17:22 +0100)
Primarily for the include path, but also for the logging in future.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
20 files changed:
include/xkbcommon/xkbcommon.h
src/XKBcommonint.h
src/alloc.c
src/context.c
src/xkballoc.h
src/xkbcomp/compat.c
src/xkbcomp/keycodes.c
src/xkbcomp/keymap.c
src/xkbcomp/keytypes.c
src/xkbcomp/misc.c
src/xkbcomp/misc.h
src/xkbcomp/symbols.c
src/xkbcomp/xkbcomp.c
src/xkbcomp/xkbcomp.h
src/xkbcomp/xkbpath.c
src/xkbcomp/xkbpath.h
test/filecomp.c
test/namescomp.c
test/rulescomp.c
test/state.c

index e15dbac..d5d009f 100644 (file)
@@ -237,6 +237,18 @@ _X_EXPORT void
 xkb_context_include_path_clear(struct xkb_context *context);
 
 /**
+ * Returns the number of include paths currently active in the context.
+ */
+_X_EXPORT unsigned int
+xkb_context_num_include_paths(struct xkb_context *context);
+
+/**
+ * Returns the include path at the specified index within the context.
+ */
+_X_EXPORT const char *
+xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
+
+/**
  * Takes a new reference on an XKB context.
  */
 _X_EXPORT void
@@ -265,7 +277,8 @@ xkb_context_unref(struct xkb_context *context);
  * keymaps.
  */
 _X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_names(const struct xkb_rule_names *names);
+xkb_map_new_from_names(struct xkb_context *context,
+                       const struct xkb_rule_names *names);
 
 /**
  * Deprecated entrypoint for legacy users who need to be able to compile
@@ -278,7 +291,8 @@ xkb_map_new_from_names(const struct xkb_rule_names *names);
  * Geometry will be ignored since xkbcommon does not support it in any way.
  */
 _X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst);
+xkb_map_new_from_kccgst(struct xkb_context *context,
+                        const struct xkb_component_names *kccgst);
 
 enum xkb_keymap_format {
     /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
@@ -290,14 +304,17 @@ enum xkb_keymap_format {
  * file descriptor.
  */
 _X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_fd(int fd, enum xkb_keymap_format format);
+xkb_map_new_from_fd(struct xkb_context *context,
+                    int fd, enum xkb_keymap_format format);
 
 /**
  * Creates an XKB keymap from a full text XKB keymap serialised into one
  * enormous string.
  */
 _X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_string(const char *string, enum xkb_keymap_format format);
+xkb_map_new_from_string(struct xkb_context *context,
+                        const char *string,
+                        enum xkb_keymap_format format);
 
 /**
  * Takes a new reference on a keymap.
index f900a69..b270f28 100644 (file)
@@ -392,6 +392,8 @@ struct xkb_controls {
 
 /* Common keyboard description structure */
 struct xkb_desc {
+    struct xkb_context  *context;
+
     unsigned int        refcnt;
     unsigned int        defined;
     unsigned short      flags;
index 66e2b76..30af089 100644 (file)
@@ -257,15 +257,18 @@ XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
 }
 
 struct xkb_desc *
-XkbcAllocKeyboard(void)
+XkbcAllocKeyboard(struct xkb_context *context)
 {
     struct xkb_desc *xkb;
 
     xkb = uTypedCalloc(1, struct xkb_desc);
-    if (xkb) {
-        xkb->device_spec = XkbUseCoreKbd;
-        xkb->refcnt = 1;
-    }
+    if (!xkb)
+        return NULL;
+
+    xkb->refcnt = 1;
+    xkb_context_ref(context);
+    xkb->context = context;
+    xkb->device_spec = XkbUseCoreKbd;
 
     return xkb;
 }
@@ -282,5 +285,6 @@ XkbcFreeKeyboard(struct xkb_desc * xkb)
     XkbcFreeIndicatorMaps(xkb);
     XkbcFreeNames(xkb);
     XkbcFreeControls(xkb);
+    xkb_context_unref(xkb->context);
     free(xkb);
 }
index 20f8c79..0c5da91 100644 (file)
@@ -134,9 +134,9 @@ xkb_context_include_path_reset_defaults(struct xkb_context *context)
  * Returns the number of entries in the context's include path.
  */
 unsigned int
-xkb_context_include_path_num_entries(struct xkb_context *context)
+xkb_context_num_include_paths(struct xkb_context *context)
 {
-    return context->size_include_paths;
+    return context->num_include_paths;
 }
 
 /**
@@ -144,10 +144,9 @@ xkb_context_include_path_num_entries(struct xkb_context *context)
  * invalid index is passed.
  */
 const char *
-xkb_context_include_path_get_entry(struct xkb_context *context,
-                                   unsigned int index)
+xkb_context_include_path_get(struct xkb_context *context, unsigned int index)
 {
-    if (index >= xkb_context_include_path_num_entries(context))
+    if (index >= xkb_context_num_include_paths(context))
         return NULL;
 
     return context->include_paths[index];
index d16c58b..278f65d 100644 (file)
@@ -44,7 +44,7 @@ extern int
 XkbcAllocIndicatorMaps(struct xkb_desc * xkb);
 
 extern struct xkb_desc *
-XkbcAllocKeyboard(void);
+XkbcAllocKeyboard(struct xkb_context *context);
 
 extern void
 XkbcFreeKeyboard(struct xkb_desc * xkb);
index 38cd013..0ba08d5 100644 (file)
@@ -409,7 +409,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
         included = *info;
         memset(info, 0, sizeof(CompatInfo));
     }
-    else if (ProcessIncludeFile(stmt, XkmCompatMapIndex, &rtrn, &newMerge))
+    else if (ProcessIncludeFile(xkb->context, stmt, XkmCompatMapIndex, &rtrn,
+                                &newMerge))
     {
         InitCompatInfo(&included, xkb);
         included.fileID = rtrn->id;
@@ -449,7 +450,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
                 MergeIncludedCompatMaps(&included, info, next->merge);
                 ClearCompatInfo(info, xkb);
             }
-            else if (ProcessIncludeFile(next, XkmCompatMapIndex, &rtrn, &op))
+            else if (ProcessIncludeFile(xkb->context, next, XkmCompatMapIndex,
+                                        &rtrn, &op))
             {
                 InitCompatInfo(&next_incl, xkb);
                 next_incl.fileID = rtrn->id;
index bfe7d13..f9ac62c 100644 (file)
@@ -568,7 +568,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
         info->explicitMax = XKB_KEYCODE_MAX;
         return (info->errorCount == 0);
     } /* parse file, store returned info in the xkb struct */
-    else if (ProcessIncludeFile(stmt, XkmKeyNamesIndex, &rtrn, &newMerge))
+    else if (ProcessIncludeFile(xkb->context, stmt, XkmKeyNamesIndex, &rtrn,
+                                &newMerge))
     {
         InitKeyNamesInfo(&included);
         HandleKeycodesFile(rtrn, xkb, MergeOverride, &included);
@@ -600,7 +601,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
                 MergeIncludedKeycodes(&included, info, next->merge);
                 ClearKeyNamesInfo(info);
             }
-            else if (ProcessIncludeFile(next, XkmKeyNamesIndex, &rtrn, &op))
+            else if (ProcessIncludeFile(xkb->context, next, XkmKeyNamesIndex,
+                                        &rtrn, &op))
             {
                 InitKeyNamesInfo(&next_incl);
                 HandleKeycodesFile(rtrn, xkb, MergeOverride, &next_incl);
index 897ff41..df6fd36 100644 (file)
@@ -39,7 +39,7 @@
  * XkmKeyNamesIdx, etc.)
  */
 struct xkb_desc *
-CompileKeymap(XkbFile *file, unsigned merge)
+CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
 {
     unsigned have;
     Bool ok;
@@ -47,7 +47,7 @@ CompileKeymap(XkbFile *file, unsigned merge)
     unsigned mainType;
     const char *mainName;
     LEDInfo *unbound = NULL;
-    struct xkb_desc *xkb = XkbcAllocKeyboard();
+    struct xkb_desc *xkb = XkbcAllocKeyboard(context);
     struct {
         XkbFile *keycodes;
         XkbFile *types;
index 0a03afc..3c6628a 100644 (file)
@@ -378,7 +378,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
         included = *info;
         memset(info, 0, sizeof(KeyTypesInfo));
     }
-    else if (ProcessIncludeFile(stmt, XkmTypesIndex, &rtrn, &newMerge))
+    else if (ProcessIncludeFile(xkb->context, stmt, XkmTypesIndex, &rtrn,
+                                &newMerge))
     {
         InitKeyTypesInfo(&included, xkb, info);
         included.fileID = included.dflt.defs.fileID = rtrn->id;
@@ -412,7 +413,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
                 MergeIncludedKeyTypes(&included, info, next->merge, xkb);
                 FreeKeyTypesInfo(info);
             }
-            else if (ProcessIncludeFile(next, XkmTypesIndex, &rtrn, &op))
+            else if (ProcessIncludeFile(xkb->context, next, XkmTypesIndex,
+                                        &rtrn, &op))
             {
                 InitKeyTypesInfo(&next_incl, xkb, &included);
                 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
index dd480f1..5c9c13a 100644 (file)
@@ -40,6 +40,7 @@
  * If the statement defines a specific map to use, this map is returned in
  * file_rtrn. Otherwise, the default map is returned.
  *
+ * @param context The context containing include paths
  * @param stmt The include statement, specifying the file name to look for.
  * @param file_type Type of file (XkmKeyNamesIdx, etc.)
  * @param file_rtrn Returns the key map to be used.
@@ -48,7 +49,8 @@
  * @return True on success or False otherwise.
  */
 Bool
-ProcessIncludeFile(IncludeStmt * stmt,
+ProcessIncludeFile(struct xkb_context *context,
+                   IncludeStmt * stmt,
                    unsigned file_type,
                    XkbFile ** file_rtrn, unsigned *merge_rtrn)
 {
@@ -57,7 +59,7 @@ ProcessIncludeFile(IncludeStmt * stmt,
     char oldFile[1024] = {0};
     int oldLine = lineNum;
 
-    file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
+    file = XkbFindFileInPath(context, stmt->file, file_type, &stmt->path);
     if (file == NULL)
     {
         ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
index 197721f..7588cb3 100644 (file)
@@ -69,7 +69,8 @@ extern int ReportBadField(const char * /* type */ ,
                           const char *  /* name */
     );
 
-extern Bool ProcessIncludeFile(IncludeStmt * /* stmt */ ,
+extern Bool ProcessIncludeFile(struct xkb_context * /* context */,
+                               IncludeStmt * /* stmt */ ,
                                unsigned /* file_type */ ,
                                XkbFile ** /* file_rtrn */ ,
                                unsigned *       /* merge_rtrn */
index b3953c1..a1980bf 100644 (file)
@@ -757,7 +757,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
         included = *info;
         memset(info, 0, sizeof(SymbolsInfo));
     }
-    else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
+    else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
+                                &newMerge))
     {
         InitSymbolsInfo(&included, xkb);
         included.fileID = included.dflt.defs.fileID = rtrn->id;
@@ -798,7 +799,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
                 MergeIncludedSymbols(&included, info, next->merge, xkb);
                 FreeSymbolsInfo(info);
             }
-            else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
+            else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
+                                        &rtrn, &op))
             {
                 InitSymbolsInfo(&next_incl, xkb);
                 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
index 991ec60..bf03626 100644 (file)
@@ -59,19 +59,22 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
     symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &symbols->common);
 
-    return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""),
+    return CreateXKBFile(XkmKeymapFile,
+                         ktcsg->keymap ? ktcsg->keymap : strdup(""),
                          &keycodes->common, 0);
 }
 
 static struct xkb_component_names *
-XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
+XkbComponentsFromRules(struct xkb_context *context,
+                       const char *rules,
+                       const XkbRF_VarDefsPtr defs)
 {
     FILE *rulesFile = NULL;
     char *rulesPath = NULL;
     XkbRF_RulesPtr loaded = NULL;
     struct xkb_component_names * names = NULL;
 
-    rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath);
+    rulesFile = XkbFindFileInPath(context, rules, XkmRulesFile, &rulesPath);
     if (!rulesFile) {
         ERROR("could not find \"%s\" rules in XKB path\n", rules);
         return NULL;
@@ -112,11 +115,12 @@ unwind_file:
 }
 
 struct xkb_desc *
-xkb_map_new_from_names(const struct xkb_rule_names *rmlvo)
+xkb_map_new_from_names(struct xkb_context *context,
+                       const struct xkb_rule_names *rmlvo)
 {
     XkbRF_VarDefsRec defs;
-    struct xkb_component_names * names;
-    struct xkb_desc * xkb;
+    struct xkb_component_names *names;
+    struct xkb_desc *xkb;
 
     if (!rmlvo || ISEMPTY(rmlvo->rules) || ISEMPTY(rmlvo->layout)) {
         ERROR("rules and layout required to generate XKB keymap\n");
@@ -128,14 +132,14 @@ xkb_map_new_from_names(const struct xkb_rule_names *rmlvo)
     defs.variant = rmlvo->variant;
     defs.options = rmlvo->options;
 
-    names = XkbComponentsFromRules(rmlvo->rules, &defs);
+    names = XkbComponentsFromRules(context, rmlvo->rules, &defs);
     if (!names) {
         ERROR("failed to generate XKB components from rules \"%s\"\n",
               rmlvo->rules);
         return NULL;
     }
 
-    xkb = xkb_map_new_from_kccgst(names);
+    xkb = xkb_map_new_from_kccgst(context, names);
 
     free(names->keymap);
     free(names->keycodes);
@@ -182,7 +186,7 @@ XkbChooseMap(XkbFile *file, const char *name)
 }
 
 static struct xkb_desc *
-compile_keymap(XkbFile *file)
+compile_keymap(struct xkb_context *context, XkbFile *file)
 {
     XkbFile *mapToUse;
     struct xkb_desc * xkb = NULL;
@@ -202,20 +206,20 @@ compile_keymap(XkbFile *file)
         goto err;
     }
 
-    xkb = CompileKeymap(mapToUse, MergeReplace);
+    xkb = CompileKeymap(context, mapToUse, MergeReplace);
     if (!xkb)
         goto err;
 
 err:
     FreeXKBFile(file);
     free(scanFile);
-    XkbFreeIncludePath();
     XkbcFreeAllAtoms();
     return xkb;
 }
 
 struct xkb_desc *
-xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst)
+xkb_map_new_from_kccgst(struct xkb_context *context,
+                        const struct xkb_component_names *kccgst)
 {
     XkbFile *file;
 
@@ -249,11 +253,13 @@ xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst)
         return NULL;
     }
 
-    return compile_keymap(file);
+    return compile_keymap(context, file);
 }
 
 struct xkb_desc *
-xkb_map_new_from_string(const char *string, enum xkb_keymap_format format)
+xkb_map_new_from_string(struct xkb_context *context,
+                        const char *string,
+                        enum xkb_keymap_format format)
 {
     XkbFile *file;
 
@@ -273,11 +279,13 @@ xkb_map_new_from_string(const char *string, enum xkb_keymap_format format)
         return NULL;
     }
 
-    return compile_keymap(file);
+    return compile_keymap(context, file);
 }
 
 struct xkb_desc *
-xkb_map_new_from_fd(int fd, enum xkb_keymap_format format)
+xkb_map_new_from_fd(struct xkb_context *context,
+                    int fd,
+                    enum xkb_keymap_format format)
 {
     XkbFile *file;
     FILE *fptr;
@@ -304,7 +312,7 @@ xkb_map_new_from_fd(int fd, enum xkb_keymap_format format)
        return NULL;
     }
 
-    return compile_keymap(file);
+    return compile_keymap(context, file);
 }
 
 void
index baab968..4a6212b 100644 (file)
@@ -253,7 +253,7 @@ typedef struct _XkbFile
 } XkbFile;
 
 extern struct xkb_desc *
-CompileKeymap(XkbFile *file, unsigned merge);
+CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge);
 
 extern Bool
 CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge);
index dfeab2f..12aaf3a 100644 (file)
 
  ********************************************************/
 
-#include "utils.h"
 #include <errno.h>
+#include <limits.h>
 #include <stdlib.h>
-#include "xkbpath.h"
 #include "xkbcommon/xkbcommon.h"
 #include "XKBcommonint.h"
-
-#ifndef DFLT_XKB_CONFIG_ROOT
-#define DFLT_XKB_CONFIG_ROOT   "/usr/lib/X11/xkb"
-#endif
-
-#ifndef PATH_MAX
-#define        PATH_MAX 1024
-#endif
-
-/* initial szPath */
-#define        PATH_CHUNK      8
-
-static Bool noDefaultPath = False;
-/* number of entries allocated for includePath */
-static size_t szPath;
-/* number of actual entries in includePath */
-static size_t nPathEntries;
-/* Holds all directories we might be including data from */
-static char **includePath = NULL;
+#include "utils.h"
+#include "xkbpath.h"
 
 /**
  * Extract the first token from an include statement.
@@ -157,115 +139,6 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
     return True;
 }
 
-static void
-XkbAddDefaultDirectoriesToPath(void);
-
-/**
- * Init memory for include paths.
- */
-static Bool
-XkbInitIncludePath(void)
-{
-    if (includePath)
-        return True;
-
-    szPath = PATH_CHUNK;
-    includePath = calloc(szPath, sizeof(char *));
-    if (!includePath)
-        return False;
-
-    XkbAddDefaultDirectoriesToPath();
-    return True;
-}
-
-/**
- * Remove all entries from the global includePath.
- */
-static void
-XkbClearIncludePath(void)
-{
-    size_t i;
-
-    if (szPath > 0)
-    {
-        for (i = 0; i < nPathEntries; i++)
-        {
-            if (includePath[i] != NULL)
-            {
-                free(includePath[i]);
-                includePath[i] = NULL;
-            }
-        }
-        nPathEntries = 0;
-    }
-    noDefaultPath = True;
-}
-
-void
-XkbFreeIncludePath(void)
-{
-    XkbClearIncludePath();
-    free(includePath);
-    includePath = NULL;
-}
-
-/**
- * Add the given path to the global includePath variable.
- * If dir is NULL, the includePath is emptied.
- */
-static Bool
-XkbAddDirectoryToPath(const char *dir)
-{
-    int len;
-
-    if (!XkbInitIncludePath())
-        return False;
-
-    if ((dir == NULL) || (dir[0] == '\0'))
-    {
-        XkbClearIncludePath();
-        return True;
-    }
-#ifdef __UNIXOS2__
-    dir = (char *) __XOS2RedirRoot(dir);
-#endif
-    len = strlen(dir);
-    if (len + 2 >= PATH_MAX)
-    {                           /* allow for '/' and at least one character */
-        ERROR("Path entry (%s) too long (maxiumum length is %d)\n",
-               dir, PATH_MAX - 3);
-        return False;
-    }
-    if (nPathEntries >= szPath)
-    {
-        szPath += PATH_CHUNK;
-        includePath = realloc(includePath, szPath * sizeof(char *));
-        if (includePath == NULL)
-        {
-            WSGO("Allocation failed (includePath)\n");
-            return False;
-        }
-    }
-    includePath[nPathEntries] = strdup(dir);
-    if (includePath[nPathEntries] == NULL)
-    {
-        WSGO("Allocation failed (includePath[%zd])\n", nPathEntries);
-        return False;
-    }
-    nPathEntries++;
-    return True;
-}
-
-static void
-XkbAddDefaultDirectoriesToPath(void)
-{
-    if (!XkbInitIncludePath())
-        return;
-    if (noDefaultPath)
-        return;
-    XkbAddDirectoryToPath(DFLT_XKB_CONFIG_ROOT);
-}
-
 /***====================================================================***/
 
 /**
@@ -305,15 +178,17 @@ XkbDirectoryForInclude(unsigned type)
 /**
  * Search for the given file name in the include directories.
  *
+ * @param context the XKB context containing the include paths
  * @param type one of XkbTypesIndex, XkbCompatMapIndex, ..., or
- * XkbSemanticsFile, XkmKeymapFile, ...
+ *             XkbSemanticsFile, XkmKeymapFile, ...
  * @param pathReturn is set to the full path of the file if found.
  *
  * @return an FD to the file or NULL. If NULL is returned, the value of
  * pathRtrn is undefined.
  */
 FILE *
-XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
+XkbFindFileInPath(struct xkb_context *context,
+                  const char *name, unsigned type, char **pathRtrn)
 {
     size_t i;
     int ret;
@@ -321,28 +196,23 @@ XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
     char buf[PATH_MAX];
     const char *typeDir;
 
-    if (!XkbInitIncludePath())
-        return NULL;
-
     typeDir = XkbDirectoryForInclude(type);
-    for (i = 0; i < nPathEntries; i++)
+    for (i = 0; i < xkb_context_num_include_paths(context); i++)
     {
-        if (includePath[i] == NULL || *includePath[i] == '\0')
-            continue;
-
         ret = snprintf(buf, sizeof(buf), "%s/%s/%s",
-                       includePath[i], typeDir, name);
+                       xkb_context_include_path_get(context, i), typeDir, name);
         if (ret >= (ssize_t)sizeof(buf))
         {
-            ERROR("File name (%s/%s/%s) too long\n", includePath[i],
-                   typeDir, name);
+            ERROR("File name (%s/%s/%s) too long\n",
+                  xkb_context_include_path_get(context, i), typeDir, name);
             ACTION("Ignored\n");
             continue;
         }
         file = fopen(buf, "r");
         if (file == NULL) {
-            ERROR("Couldn't open file (%s/%s/%s): %s\n", includePath[i],
-                   typeDir, name, strerror(-errno));
+            ERROR("Couldn't open file (%s/%s/%s): %s\n",
+                  xkb_context_include_path_get(context, i), typeDir, name,
+                  strerror(-errno));
             ACTION("Ignored\n");
             continue;
         }
index 3632cbb..e48cf41 100644 (file)
 #define _XKBPATH_H_ 1
 
 #include <stdio.h>
-#include <X11/Xdefs.h>
+
+#include "XKBcommonint.h"
 
 extern const char *XkbDirectoryForInclude(unsigned    /* type */
     );
 
-extern FILE *XkbFindFileInPath(const char * /* name */ ,
+extern FILE *XkbFindFileInPath(struct xkb_context * /* context */,
+                               const char * /* name */ ,
                                unsigned /* type */ ,
                                char **  /* pathRtrn */
     );
@@ -45,6 +47,4 @@ extern Bool XkbParseIncludeMap(char ** /* str_inout */ ,
                                char **  /* extra_data */
     );
 
-extern void XkbFreeIncludePath(void);
-
 #endif /* _XKBPATH_H_ */
index 370c4b2..3ba1b57 100644 (file)
@@ -26,6 +26,7 @@ authorization from the authors.
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <assert.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -39,9 +40,10 @@ static char buffer[8192];
 
 int main(int argc, char *argv[])
 {
+    struct xkb_context *context;
+    struct xkb_desc *xkb;
     char *path;
     int fd;
-    struct xkb_desc * xkb;
     int i, len, from_string = 0;
 
     /* Require xkb file */
@@ -67,12 +69,17 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
+    context = xkb_context_new();
+    assert(context);
+
     if (from_string) {
        len = read(fd, buffer, sizeof(buffer));
        buffer[len] = '\0';
-       xkb = xkb_map_new_from_string(buffer, XKB_KEYMAP_FORMAT_TEXT_V1);
+       xkb = xkb_map_new_from_string(context, buffer,
+                                      XKB_KEYMAP_FORMAT_TEXT_V1);
     } else {
-       xkb = xkb_map_new_from_fd(fd, XKB_KEYMAP_FORMAT_TEXT_V1);
+       xkb = xkb_map_new_from_fd(context, fd,
+                                  XKB_KEYMAP_FORMAT_TEXT_V1);
     }
     close(fd);
 
@@ -82,6 +89,7 @@ int main(int argc, char *argv[])
     }
 
     xkb_map_unref(xkb);
+    xkb_context_unref(context);
 
     return 0;
 }
index bd81447..4e8bf5c 100644 (file)
@@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
 authorization from the authors.
 */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include "xkbcommon/xkbcommon.h"
@@ -31,8 +32,9 @@ authorization from the authors.
 
 int main(int argc, char *argv[])
 {
-    struct xkb_component_names kccgst;
+    struct xkb_context *context;
     struct xkb_desc *xkb;
+    struct xkb_component_names kccgst;
 
     /* Require Kc + T + C + S */
     if (argc < 5) {
@@ -48,7 +50,10 @@ int main(int argc, char *argv[])
     kccgst.compat = argv[3];
     kccgst.symbols = argv[4];
 
-    xkb = xkb_map_new_from_kccgst(&kccgst);
+    context = xkb_context_new();
+    assert(context);
+
+    xkb = xkb_map_new_from_kccgst(context, &kccgst);
 
     if (!xkb) {
         fprintf(stderr, "Failed to compile keymap\n");
@@ -56,6 +61,7 @@ int main(int argc, char *argv[])
     }
 
     xkb_map_unref(xkb);
+    xkb_context_unref(context);
 
     return 0;
 }
index c761a49..a25b0a9 100644 (file)
@@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
 authorization from the authors.
 */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <X11/Xdefs.h>
@@ -32,8 +33,9 @@ authorization from the authors.
 
 int main(int argc, char *argv[])
 {
-    struct xkb_rule_names rmlvo;
+    struct xkb_context *context;
     struct xkb_desc *xkb;
+    struct xkb_rule_names rmlvo;
 
     /* Require rmlvo */
     if (argc < 6) {
@@ -49,7 +51,10 @@ int main(int argc, char *argv[])
     rmlvo.variant = argv[4];
     rmlvo.options = argv[5];
 
-    xkb = xkb_map_new_from_names(&rmlvo);
+    context = xkb_context_new();
+    assert(context);
+
+    xkb = xkb_map_new_from_names(context, &rmlvo);
 
     if (!xkb) {
         fprintf(stderr, "Failed to compile keymap\n");
@@ -57,6 +62,7 @@ int main(int argc, char *argv[])
     }
 
     xkb_map_unref(xkb);
+    xkb_context_unref(context);
 
     return 0;
 }
index 5c6d1f5..231a8c0 100644 (file)
@@ -205,8 +205,9 @@ test_serialisation(struct xkb_desc *xkb)
 int
 main(int argc, char *argv[])
 {
-    struct xkb_rule_names rmlvo;
+    struct xkb_context *context;
     struct xkb_desc *xkb;
+    struct xkb_rule_names rmlvo;
 
     rmlvo.rules = "evdev";
     rmlvo.model = "pc104";
@@ -214,11 +215,15 @@ main(int argc, char *argv[])
     rmlvo.variant = NULL;
     rmlvo.options = NULL;
 
-    xkb = xkb_map_new_from_names(&rmlvo);
+    context = xkb_context_new();
+    assert(context);
+
+    xkb = xkb_map_new_from_names(context, &rmlvo);
     assert(xkb);
 
     test_update_key(xkb);
     test_serialisation(xkb);
 
     xkb_map_unref(xkb);
+    xkb_context_unref(context);
 }