Create path.h for the path.c functions
[profile/ivi/libxkbcommon.git] / src / xkbcomp / xkbcomp.c
index a18451f..68e180f 100644 (file)
@@ -27,6 +27,7 @@ authorization from the authors.
 #include "xkbcomp-priv.h"
 #include "rules.h"
 #include "parseutils.h"
+#include "path.h"
 
 /* Global warning level */
 unsigned int warningLevel = 0;
@@ -34,7 +35,7 @@ unsigned int warningLevel = 0;
 #define ISEMPTY(str) (!(str) || (strlen(str) == 0))
 
 static XkbFile *
-XkbKeymapFileFromComponents(struct xkb_ctx *ctx,
+XkbKeymapFileFromComponents(struct xkb_context *ctx,
                             const struct xkb_component_names *ktcsg)
 {
     XkbFile *keycodes, *types, *compat, *symbols;
@@ -65,7 +66,7 @@ XkbKeymapFileFromComponents(struct xkb_ctx *ctx,
 }
 
 static struct xkb_component_names *
-XkbComponentsFromRules(struct xkb_ctx *ctx,
+XkbComponentsFromRules(struct xkb_context *ctx,
                        const char *rules,
                        const XkbRF_VarDefsPtr defs)
 {
@@ -79,9 +80,9 @@ XkbComponentsFromRules(struct xkb_ctx *ctx,
     if (!rulesFile) {
         ERROR("could not find \"%s\" rules in XKB path\n", rules);
         ERROR("%d include paths searched:\n",
-              xkb_ctx_num_include_paths(ctx));
-        for (i = 0; i < xkb_ctx_num_include_paths(ctx); i++)
-            ERROR("\t%s\n", xkb_ctx_include_path_get(ctx, i));
+              xkb_context_num_include_paths(ctx));
+        for (i = 0; i < xkb_context_num_include_paths(ctx); i++)
+            ERROR("\t%s\n", xkb_context_include_path_get(ctx, i));
         return NULL;
     }
 
@@ -120,7 +121,7 @@ unwind_file:
 }
 
 _X_EXPORT struct xkb_keymap *
-xkb_map_new_from_names(struct xkb_ctx *ctx,
+xkb_map_new_from_names(struct xkb_context *ctx,
                        const struct xkb_rule_names *rmlvo,
                        enum xkb_map_compile_flags flags)
 {
@@ -192,14 +193,17 @@ XkbChooseMap(XkbFile *file, const char *name)
 }
 
 static struct xkb_keymap *
-compile_keymap(struct xkb_ctx *ctx, XkbFile *file)
+compile_keymap(struct xkb_context *ctx, XkbFile *file)
 {
     XkbFile *mapToUse;
     struct xkb_keymap *keymap = NULL;
 
     /* Find map to use */
     mapToUse = XkbChooseMap(file, NULL);
-    if (!mapToUse || mapToUse->type != XkmKeymapFile) {
+    if (!mapToUse)
+        goto err;
+
+    if (mapToUse->type != XkmKeymapFile) {
         ERROR("file type %d not handled\n", mapToUse->type);
         goto err;
     }
@@ -214,7 +218,7 @@ err:
 }
 
 _X_EXPORT struct xkb_keymap *
-xkb_map_new_from_kccgst(struct xkb_ctx *ctx,
+xkb_map_new_from_kccgst(struct xkb_context *ctx,
                         const struct xkb_component_names *kccgst,
                         enum xkb_map_compile_flags flags)
 {
@@ -254,7 +258,7 @@ xkb_map_new_from_kccgst(struct xkb_ctx *ctx,
 }
 
 _X_EXPORT struct xkb_keymap *
-xkb_map_new_from_string(struct xkb_ctx *ctx,
+xkb_map_new_from_string(struct xkb_context *ctx,
                         const char *string,
                         enum xkb_keymap_format format,
                         enum xkb_map_compile_flags flags)
@@ -280,36 +284,29 @@ xkb_map_new_from_string(struct xkb_ctx *ctx,
 }
 
 _X_EXPORT struct xkb_keymap *
-xkb_map_new_from_fd(struct xkb_ctx *ctx,
-                    int fd,
-                    enum xkb_keymap_format format,
-                    enum xkb_map_compile_flags flags)
+xkb_map_new_from_file(struct xkb_context *ctx,
+                      FILE *file,
+                      enum xkb_keymap_format format,
+                      enum xkb_map_compile_flags flags)
 {
-    XkbFile *file;
-    FILE *fptr;
+    XkbFile *xkb_file;
 
     if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
         ERROR("unsupported keymap format %d\n", format);
         return NULL;
     }
 
-    if (fd < 0) {
+    if (!file) {
         ERROR("no file specified to generate XKB keymap\n");
-       return NULL;
-    }
-
-    fptr = fdopen(fd, "r");
-    if (!fptr) {
-        ERROR("couldn't associate fd with file pointer\n");
         return NULL;
     }
 
-    if (!XKBParseFile(ctx, fptr, "(unknown file)", &file)) {
+    if (!XKBParseFile(ctx, file, "(unknown file)", &xkb_file)) {
         ERROR("failed to parse input xkb file\n");
         return NULL;
     }
 
-    return compile_keymap(ctx, file);
+    return compile_keymap(ctx, xkb_file);
 }
 
 _X_EXPORT struct xkb_keymap *