Run source tree through uncrustify
[platform/upstream/libxkbcommon.git] / src / context.c
index 3f2f13d..957d716 100644 (file)
 struct xkb_context {
     int refcnt;
 
-    char **include_paths;
-    int num_include_paths;
-    int size_include_paths;
+    darray(char *) includes;
 
     /* xkbcomp needs to assign sequential IDs to XkbFile's it creates. */
-    int file_id;
+    unsigned file_id;
 
     struct atom_table *atom_table;
 };
@@ -52,20 +50,7 @@ xkb_context_include_path_append(struct xkb_context *ctx, const char *path)
 {
     struct stat stat_buf;
     int err;
-
-    if (ctx->size_include_paths <= ctx->num_include_paths) {
-        int new_size;
-        char **new_paths;
-        new_size = ctx->size_include_paths + 2;
-        new_paths = uTypedRecalloc(ctx->include_paths,
-                                   ctx->size_include_paths,
-                                   new_size,
-                                   char *);
-        if (!new_paths)
-            return 0;
-        ctx->include_paths = new_paths;
-        ctx->size_include_paths = new_size;
-    }
+    char *tmp;
 
     err = stat(path, &stat_buf);
     if (err != 0)
@@ -81,11 +66,11 @@ xkb_context_include_path_append(struct xkb_context *ctx, const char *path)
         return 0;
 #endif
 
-    ctx->include_paths[ctx->num_include_paths] = strdup(path);
-    if (!ctx->include_paths[ctx->num_include_paths])
+    tmp = strdup(path);
+    if (!tmp)
         return 0;
-    ctx->num_include_paths++;
 
+    darray_append(ctx->includes, tmp);
     return 1;
 }
 
@@ -95,7 +80,7 @@ xkb_context_include_path_append(struct xkb_context *ctx, const char *path)
 _X_EXPORT int
 xkb_context_include_path_append_default(struct xkb_context *ctx)
 {
-    const char *home = getenv("HOME");
+    const char *home;
     char *user_path;
     int err;
 
@@ -119,15 +104,12 @@ xkb_context_include_path_append_default(struct xkb_context *ctx)
 _X_EXPORT void
 xkb_context_include_path_clear(struct xkb_context *ctx)
 {
-    int i;
+    char **path;
 
-    for (i = 0; i < ctx->num_include_paths; i++) {
-        free(ctx->include_paths[i]);
-        ctx->include_paths[i] = NULL;
-    }
-    free(ctx->include_paths);
-    ctx->include_paths = NULL;
-    ctx->num_include_paths = 0;
+    darray_foreach(path, ctx->includes)
+    free(*path);
+
+    darray_free(ctx->includes);
 }
 
 /**
@@ -146,7 +128,7 @@ xkb_context_include_path_reset_defaults(struct xkb_context *ctx)
 _X_EXPORT unsigned int
 xkb_context_num_include_paths(struct xkb_context *ctx)
 {
-    return ctx->num_include_paths;
+    return darray_size(ctx->includes);
 }
 
 /**
@@ -159,10 +141,10 @@ xkb_context_include_path_get(struct xkb_context *ctx, unsigned int idx)
     if (idx >= xkb_context_num_include_paths(ctx))
         return NULL;
 
-    return ctx->include_paths[idx];
+    return darray_item(ctx->includes, idx);
 }
 
-int
+unsigned
 xkb_context_take_file_id(struct xkb_context *ctx)
 {
     return ctx->file_id++;