2 * upkg: tool for manipulating Unreal Tournament packages.
3 * Copyright (C) 2009 Nick Bowler
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <glib-object.h>
27 #include <uobject/module.h>
28 #include <uobject/package.h>
31 static unsigned initialized;
32 static struct avl_table *package_tree;
34 static char *str_cpy_lower(char *dst, const char *src)
38 for (i = 0; src[i]; i++)
39 dst[i] = tolower(src[i]);
45 static int modcmp(const void *a, const void *b, void *_data)
47 const GTypeModule *ma = a;
48 const GTypeModule *mb = b;
50 return strcmp(ma->name, mb->name);
53 int u_object_module_init(void)
56 package_tree = avl_create(modcmp, NULL, NULL);
58 fprintf(stderr, "%s: failed to create package tree.\n", __func__);
69 int u_object_module_exit(void)
74 avl_destroy(package_tree, NULL);
79 GType u_object_module_get_class(const char *package, const char *class)
81 char buf[strlen(package) + strlen(class) + 1];
82 GTypeModule search = { .name = str_cpy_lower(buf, package) };
84 GTypeModule *mod = avl_find(package_tree, &search);
88 mod = u_pkg_new(package);
93 p = avl_probe(package_tree, mod);
100 if (!g_type_module_use(mod))
103 str_cpy_lower(buf+strlen(package), class);
104 buf[0] = toupper(buf[0]);
105 buf[strlen(package)] = toupper(buf[strlen(package)]);
106 return g_type_from_name(buf);