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 3 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, see <http://www.gnu.org/licenses/>.
23 #include <glib-object.h>
26 #include <uobject/module.h>
27 #include <uobject/package.h>
30 static unsigned initialized;
31 static struct avl_table *package_tree;
33 static char *str_cpy_lower(char *dst, const char *src)
37 for (i = 0; src[i]; i++)
38 dst[i] = tolower(src[i]);
44 static int modcmp(const void *a, const void *b, void *_data)
46 const GTypeModule *ma = a;
47 const GTypeModule *mb = b;
49 return strcmp(ma->name, mb->name);
52 int u_object_module_init(void)
55 package_tree = avl_create(modcmp, NULL, NULL);
57 fprintf(stderr, "%s: failed to create package tree.\n", __func__);
68 int u_object_module_exit(void)
73 avl_destroy(package_tree, NULL);
78 GType u_object_module_get_class(const char *package, const char *class)
80 char buf[strlen(package) + strlen(class) + 1];
81 GTypeModule search = { .name = str_cpy_lower(buf, package) };
83 GTypeModule *mod = avl_find(package_tree, &search);
87 mod = u_pkg_new_by_name(package);
92 p = avl_probe(package_tree, mod);
99 if (!g_type_module_use(mod))
102 str_cpy_lower(buf+strlen(package), class);
103 buf[0] = toupper(buf[0]);
104 buf[strlen(package)] = toupper(buf[strlen(package)]);
105 return g_type_from_name(buf);