From 0438ce1525f7c1e722140c046fccb0f686b4cab2 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 7 Aug 2009 01:22:09 -0400 Subject: [PATCH] uobject: Namespace changes. Change uobject to u_object, and export all symbols starting with u_. The library is starting to include package stuff which will use the u_pkg prefix. --- src/Makefile.am | 2 +- src/engine/music.c | 10 +++++----- src/engine/texture.c | 6 +++--- src/exportable.c | 14 +++++++------- src/loadable.c | 14 +++++++------- src/module.c | 6 +++--- src/uobject.c | 41 ++++++++++++++++++---------------------- src/uobject/exportable.h | 24 +++++++++++------------ src/uobject/loadable.h | 24 +++++++++++------------ src/uobject/module.h | 12 ++++++------ src/uobject/package.h | 4 ++-- src/uobject/uobject.h | 30 ++++++++++++++--------------- src/upkg.c | 20 ++++++++++---------- 13 files changed, 101 insertions(+), 106 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index a6e3372..95764df 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,7 @@ libuobject_la_SOURCES = uobject.c module.c avl.c package.c \ loadable.c exportable.c libuobject_la_CPPFLAGS = $(GLIB_CFLAGS) $(LTDLINCL) libuobject_la_LIBADD = $(LIBLTDL) $(GLIB_LIBS) -libuobject_la_LDFLAGS = -export-symbols-regex '^uobject_' +libuobject_la_LDFLAGS = -export-symbols-regex '^u_' libupkg_la_SOURCES = libupkg.c pack.c diff --git a/src/engine/music.c b/src/engine/music.c index 434d881..565a6a0 100644 --- a/src/engine/music.c +++ b/src/engine/music.c @@ -40,9 +40,9 @@ struct music_priv { static void exportable_init(UObjectExportable *); static void loadable_init(UObjectLoadable *); -G_DEFINE_DYNAMIC_TYPE_EXTENDED(EngineMusic, engine_music, UOBJECT_TYPE, 0, - G_IMPLEMENT_INTERFACE(UOBJECT_TYPE_EXPORTABLE, exportable_init) - G_IMPLEMENT_INTERFACE(UOBJECT_TYPE_LOADABLE, loadable_init) +G_DEFINE_DYNAMIC_TYPE_EXTENDED(EngineMusic, engine_music, U_OBJECT_TYPE, 0, + G_IMPLEMENT_INTERFACE(U_OBJECT_TYPE_EXPORTABLE, exportable_init) + G_IMPLEMENT_INTERFACE(U_OBJECT_TYPE_LOADABLE, loadable_init) ); static int load(GObject *o) @@ -129,7 +129,7 @@ static int deserialize(UObject *o, struct upkg_file *f) unsigned char buf[32]; long size; - UOBJECT_CLASS(engine_music_parent_class)->deserialize(o, f); + U_OBJECT_CLASS(engine_music_parent_class)->deserialize(o, f); buflen = upkg_export_read(f, buf, sizeof buf); @@ -183,7 +183,7 @@ static void engine_music_finalize(GObject *o) static void engine_music_class_init(EngineMusicClass *class) { - UObjectClass *uo = UOBJECT_CLASS(class); + UObjectClass *uo = U_OBJECT_CLASS(class); GObjectClass *go = G_OBJECT_CLASS(class); g_type_class_add_private(class, sizeof (struct music_priv)); diff --git a/src/engine/texture.c b/src/engine/texture.c index 209409b..9cd6571 100644 --- a/src/engine/texture.c +++ b/src/engine/texture.c @@ -49,14 +49,14 @@ void exportable_init(UObjectExportable *e) { } -G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, UOBJECT_TYPE); +G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_OBJECT_TYPE); static int deserialize(UObject *o, struct upkg_file *f) { struct texture_priv *priv = TEXTURE_GET_PRIV(o); EngineTexture *t = ENGINE_TEXTURE(o); - UOBJECT_CLASS(engine_texture_parent_class)->deserialize(o, f); + U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(o, f); printf("Texture size: %ux%u\n", t->usize, t->vsize); @@ -109,7 +109,7 @@ static void engine_texture_init(EngineTexture *t) static void engine_texture_class_init(EngineTextureClass *class) { - UObjectClass *uo = UOBJECT_CLASS(class); + UObjectClass *uo = U_OBJECT_CLASS(class); GObjectClass *go = G_OBJECT_CLASS(class); g_type_class_add_private(class, sizeof (struct texture_priv)); diff --git a/src/exportable.c b/src/exportable.c index 5553014..8bda850 100644 --- a/src/exportable.c +++ b/src/exportable.c @@ -21,7 +21,7 @@ #include #include -GType uobject_exportable_get_type(void) +GType u_object_exportable_get_type(void) { static GType type = 0; if (type == 0) { @@ -37,14 +37,14 @@ GType uobject_exportable_get_type(void) return type; } -int uobject_export(GObject *obj, FILE *f) +int u_object_export(GObject *obj, FILE *f) { - g_return_val_if_fail(UOBJECT_IS_EXPORTABLE(obj), -1); - return UOBJECT_EXPORTABLE_GET_INTERFACE(obj)->export(obj, f); + g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1); + return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export(obj, f); } -int uobject_export_name(GObject *obj, char *buf, size_t n) +int u_object_export_name(GObject *obj, char *buf, size_t n) { - g_return_val_if_fail(UOBJECT_IS_EXPORTABLE(obj), -1); - return UOBJECT_EXPORTABLE_GET_INTERFACE(obj)->export_name(obj, buf, n); + g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1); + return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export_name(obj, buf, n); } diff --git a/src/loadable.c b/src/loadable.c index a7c1820..c4970ec 100644 --- a/src/loadable.c +++ b/src/loadable.c @@ -21,7 +21,7 @@ #include #include -GType uobject_loadable_get_type(void) +GType u_object_loadable_get_type(void) { static GType type = 0; if (type == 0) { @@ -37,14 +37,14 @@ GType uobject_loadable_get_type(void) return type; } -int uobject_load(GObject *obj) +int u_object_load(GObject *obj) { - g_return_val_if_fail(UOBJECT_IS_LOADABLE(obj), -1); - return UOBJECT_LOADABLE_GET_INTERFACE(obj)->load(obj); + g_return_val_if_fail(U_OBJECT_IS_LOADABLE(obj), -1); + return U_OBJECT_LOADABLE_GET_INTERFACE(obj)->load(obj); } -void uobject_unload(GObject *obj) +void u_object_unload(GObject *obj) { - g_return_if_fail(UOBJECT_IS_LOADABLE(obj)); - UOBJECT_LOADABLE_GET_INTERFACE(obj)->unload(obj); + g_return_if_fail(U_OBJECT_IS_LOADABLE(obj)); + U_OBJECT_LOADABLE_GET_INTERFACE(obj)->unload(obj); } diff --git a/src/module.c b/src/module.c index ffc06e2..2eeffc0 100644 --- a/src/module.c +++ b/src/module.c @@ -50,7 +50,7 @@ static int modcmp(const void *a, const void *b, void *_data) return strcmp(ma->name, mb->name); } -int uobject_module_init(void) +int u_object_module_init(void) { if (!initialized) { package_tree = avl_create(modcmp, NULL, NULL); @@ -66,7 +66,7 @@ int uobject_module_init(void) return 0; } -int uobject_module_exit(void) +int u_object_module_exit(void) { if (--initialized) return 0; @@ -76,7 +76,7 @@ int uobject_module_exit(void) return 0; } -GType uobject_module_get_class(const char *package, const char *class) +GType u_object_module_get_class(const char *package, const char *class) { char buf[strlen(package) + strlen(class) + 1]; GTypeModule search = { .name = str_cpy_lower(buf, package) }; diff --git a/src/uobject.c b/src/uobject.c index e271a67..ec04e30 100644 --- a/src/uobject.c +++ b/src/uobject.c @@ -27,8 +27,8 @@ #include "upkg.h" #include "pack.h" -#define UOBJECT_GET_PRIV(o) \ - G_TYPE_INSTANCE_GET_PRIVATE(o, UOBJECT_TYPE, struct uobject_priv) +#define U_OBJECT_GET_PRIV(o) \ + G_TYPE_INSTANCE_GET_PRIVATE(o, U_OBJECT_TYPE, struct u_object_priv) enum { PROPERTY_BYTE = 1, @@ -48,12 +48,7 @@ enum { PROPERTY_FIXEDARRAY, }; -struct uobject_property { - const char *name; - GValue val; -}; - -struct uobject_priv { +struct u_object_priv { struct upkg_file *f; size_t base, len; @@ -61,7 +56,7 @@ struct uobject_priv { unsigned long nbuf; }; -G_DEFINE_TYPE(UObject, uobject, G_TYPE_OBJECT); +G_DEFINE_TYPE(UObject, u_object, G_TYPE_OBJECT); static unsigned long get_real_size(unsigned long *real, unsigned size, unsigned char *buf, size_t n) @@ -95,7 +90,7 @@ get_real_size(unsigned long *real, unsigned size, unsigned char *buf, size_t n) static unsigned long decode_property(UObject *o, const char *name, struct upkg_file *f, unsigned long len) { - struct uobject_priv *priv = UOBJECT_GET_PRIV(o); + struct u_object_priv *priv = U_OBJECT_GET_PRIV(o); unsigned long real_size, rc; int type, size, top; GValue val = {0}; @@ -149,7 +144,7 @@ decode_property(UObject *o, const char *name, struct upkg_file *f, unsigned long /* Deserialize properties from an Unreal package. */ static int deserialize(UObject *o, struct upkg_file *f) { - struct uobject_priv *priv = UOBJECT_GET_PRIV(o); + struct u_object_priv *priv = U_OBJECT_GET_PRIV(o); unsigned long rc, tot_len = 0; while (1) { @@ -181,7 +176,7 @@ static int deserialize(UObject *o, struct upkg_file *f) break; } - rc = decode_property(UOBJECT(o), name, f, len); + rc = decode_property(U_OBJECT(o), name, f, len); if (rc == 0) return -1; len = rc; @@ -196,10 +191,10 @@ static int deserialize(UObject *o, struct upkg_file *f) return 0; } -int uobject_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx) +int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx) { - g_return_val_if_fail(IS_UOBJECT(obj), -1); - UObject *uo = UOBJECT(obj); + g_return_val_if_fail(IS_U_OBJECT(obj), -1); + UObject *uo = U_OBJECT(obj); struct upkg_file *f; int rc; @@ -209,7 +204,7 @@ int uobject_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx) return -1; } - rc = UOBJECT_GET_CLASS(obj)->deserialize(uo, f); + rc = U_OBJECT_GET_CLASS(obj)->deserialize(uo, f); if (rc != 0) { upkg_export_close(f); } else { @@ -221,29 +216,29 @@ int uobject_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx) return rc; } -static void uobject_init(UObject *o) +static void u_object_init(UObject *o) { o->pkg = NULL; o->pkg_file = NULL; o->pkg_idx = 0; } -static void uobject_finalize(GObject *o) +static void u_object_finalize(GObject *o) { - UObject *uo = UOBJECT(o); + UObject *uo = U_OBJECT(o); if (uo->pkg_file) { upkg_export_close(uo->pkg_file); } - G_OBJECT_CLASS(uobject_parent_class)->finalize(o); + G_OBJECT_CLASS(u_object_parent_class)->finalize(o); } -static void uobject_class_init(UObjectClass *class) +static void u_object_class_init(UObjectClass *class) { - g_type_class_add_private(class, sizeof (struct uobject_priv)); + g_type_class_add_private(class, sizeof (struct u_object_priv)); GObjectClass *go = G_OBJECT_CLASS(class); class->deserialize = deserialize; - go->finalize = uobject_finalize; + go->finalize = u_object_finalize; } diff --git a/src/uobject/exportable.h b/src/uobject/exportable.h index 6aa58b3..e241f1e 100644 --- a/src/uobject/exportable.h +++ b/src/uobject/exportable.h @@ -17,19 +17,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UOBJECT_EXPORTABLE_H_ -#define UOBJECT_EXPORTABLE_H_ +#ifndef U_OBJECT_EXPORTABLE_H_ +#define U_OBJECT_EXPORTABLE_H_ #include #include -#define UOBJECT_TYPE_EXPORTABLE (uobject_exportable_get_type()) -#define UOBJECT_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ - UOBJECT_TYPE_EXPORTABLE, UObjectExportable) -#define UOBJECT_IS_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \ - UOBJECT_TYPE_EXPORTABLE) -#define UOBJECT_EXPORTABLE_GET_INTERFACE(inst) G_TYPE_INSTANCE_GET_INTERFACE \ - (inst, UOBJECT_TYPE_EXPORTABLE, UObjectExportable) +#define U_OBJECT_TYPE_EXPORTABLE (u_object_exportable_get_type()) +#define U_OBJECT_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ + U_OBJECT_TYPE_EXPORTABLE, UObjectExportable) +#define U_OBJECT_IS_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \ + U_OBJECT_TYPE_EXPORTABLE) +#define U_OBJECT_EXPORTABLE_GET_INTERFACE(inst) G_TYPE_INSTANCE_GET_INTERFACE \ + (inst, U_OBJECT_TYPE_EXPORTABLE, UObjectExportable) typedef struct UObjectExportable UObjectExportable; @@ -44,13 +44,13 @@ struct UObjectExportable { int (*export_name)(GObject *obj, char *buf, size_t n); }; -GType uobject_exportable_get_type(void); +GType u_object_exportable_get_type(void); /* * Export the object by writing it to the given FILE handle, which must have * been opened for writing in binary mode. */ -int uobject_export(GObject *obj, FILE *f); +int u_object_export(GObject *obj, FILE *f); /* * Get the suggested output filename. Not more than n-1 characters of the @@ -59,6 +59,6 @@ int uobject_export(GObject *obj, FILE *f); * not bounded. It is valid to call this function with a NULL buffer and a 0 * size in order to determine how large the buffer needs to be. */ -int uobject_export_name(GObject *obj, char *buf, size_t n); +int u_object_export_name(GObject *obj, char *buf, size_t n); #endif diff --git a/src/uobject/loadable.h b/src/uobject/loadable.h index ff5fd63..8d45884 100644 --- a/src/uobject/loadable.h +++ b/src/uobject/loadable.h @@ -17,19 +17,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UOBJECT_LOADABLE_H_ -#define UOBJECT_LOADABLE_H_ +#ifndef U_OBJECT_LOADABLE_H_ +#define U_OBJECT_LOADABLE_H_ #include #include -#define UOBJECT_TYPE_LOADABLE (uobject_loadable_get_type()) -#define UOBJECT_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ - UOBJECT_TYPE_LOADABLE, UObjectLoadable) -#define UOBJECT_IS_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \ - UOBJECT_TYPE_LOADABLE) -#define UOBJECT_LOADABLE_GET_INTERFACE(inst) G_TYPE_INSTANCE_GET_INTERFACE \ - (inst, UOBJECT_TYPE_LOADABLE, UObjectLoadable) +#define U_OBJECT_TYPE_LOADABLE (u_object_loadable_get_type()) +#define U_OBJECT_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ + U_OBJECT_TYPE_LOADABLE, UObjectLoadable) +#define U_OBJECT_IS_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \ + U_OBJECT_TYPE_LOADABLE) +#define U_OBJECT_LOADABLE_GET_INTERFACE(inst) G_TYPE_INSTANCE_GET_INTERFACE \ + (inst, U_OBJECT_TYPE_LOADABLE, UObjectLoadable) typedef struct UObjectLoadable UObjectLoadable; @@ -46,9 +46,9 @@ struct UObjectLoadable { void (*unload)(GObject *obj); }; -GType uobject_loadable_get_type(void); +GType u_object_loadable_get_type(void); -int uobject_load(GObject *obj); -void uobject_unload(GObject *obj); +int u_object_load(GObject *obj); +void u_object_unload(GObject *obj); #endif diff --git a/src/uobject/module.h b/src/uobject/module.h index 2f5a211..97d9e2b 100644 --- a/src/uobject/module.h +++ b/src/uobject/module.h @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UOBJECT_MODULE_H_ -#define UOBJECT_MODULE_H_ +#ifndef U_OBJECT_MODULE_H_ +#define U_OBJECT_MODULE_H_ #include @@ -26,14 +26,14 @@ * Initialize the UObject module system. Returns 0 on success, -1 otherwise. * The module system can be safely initialized multiple times. */ -int uobject_module_init(void); +int u_object_module_init(void); /* * Shutdown the UObject module system. Returns 0 on success, -1 otherwise. * The module system is only shut down when this function has been called as - * many times as uobject_module_init. + * many times as u_object_module_init. */ -int uobject_module_exit(void); +int u_object_module_exit(void); /* * Get a class handle from the UObject module system. This will load the @@ -42,6 +42,6 @@ int uobject_module_exit(void); * * Returns 0 on failure. */ -GType uobject_module_get_class(const char *package, const char *class); +GType u_object_module_get_class(const char *package, const char *class); #endif diff --git a/src/uobject/package.h b/src/uobject/package.h index 6241aee..f5d20d5 100644 --- a/src/uobject/package.h +++ b/src/uobject/package.h @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UOBJECT_PACKAGE_H_ -#define UOBJECT_PACKAGE_H_ +#ifndef U_OBJECT_PACKAGE_H_ +#define U_OBJECT_PACKAGE_H_ #include diff --git a/src/uobject/uobject.h b/src/uobject/uobject.h index dfca528..98ec792 100644 --- a/src/uobject/uobject.h +++ b/src/uobject/uobject.h @@ -17,23 +17,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UOBJECT_UOBJECT_H_ -#define UOBJECT_UOBJECT_H_ +#ifndef U_OBJECT_H_ +#define U_OBJECT_H_ #include #include "upkg.h" -#define UOBJECT_TYPE uobject_get_type() -#define UOBJECT(obj) \ - G_TYPE_CHECK_INSTANCE_CAST(obj, UOBJECT_TYPE, UObject) -#define UOBJECT_CLASS(class) \ - G_TYPE_CHECK_CLASS_CAST(class, UOBJECT_TYPE, UObjectClass) -#define IS_UOBJECT(obj) \ - G_TYPE_CHECK_INSTANCE_TYPE(obj, UOBJECT_TYPE) -#define IS_UOBJECT_CLASS(class) \ - G_TYPE_CHECK_CLASS_TYPE(class, UOBJECT_TYPE, UObjectClass) -#define UOBJECT_GET_CLASS(obj) \ - G_TYPE_INSTANCE_GET_CLASS(obj, UOBJECT_TYPE, UObjectClass) +#define U_OBJECT_TYPE u_object_get_type() +#define U_OBJECT(obj) \ + G_TYPE_CHECK_INSTANCE_CAST(obj, U_OBJECT_TYPE, UObject) +#define U_OBJECT_CLASS(class) \ + G_TYPE_CHECK_CLASS_CAST(class, U_OBJECT_TYPE, UObjectClass) +#define IS_U_OBJECT(obj) \ + G_TYPE_CHECK_INSTANCE_TYPE(obj, U_OBJECT_TYPE) +#define IS_U_OBJECT_CLASS(class) \ + G_TYPE_CHECK_CLASS_TYPE(class, U_OBJECT_TYPE, UObjectClass) +#define U_OBJECT_GET_CLASS(obj) \ + G_TYPE_INSTANCE_GET_CLASS(obj, U_OBJECT_TYPE, UObjectClass) typedef struct UObject UObject; typedef struct UObjectClass UObjectClass; @@ -52,8 +52,8 @@ struct UObjectClass { int (*deserialize)(UObject *obj, struct upkg_file *f); }; -GType uobject_get_type(void); +GType u_object_get_type(void); -int uobject_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx); +int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx); #endif diff --git a/src/upkg.c b/src/upkg.c index e1a8a80..a8c7c7e 100644 --- a/src/upkg.c +++ b/src/upkg.c @@ -157,15 +157,15 @@ static int export(struct upkg *pkg, GObject *obj, unsigned idx) char name[256]; FILE *of; - if (uobject_deserialize(obj, pkg, idx) != 0) { + if (u_object_deserialize(obj, pkg, idx) != 0) { return -1; } - if (UOBJECT_IS_LOADABLE(obj) && uobject_load(obj) != 0) { + if (U_OBJECT_IS_LOADABLE(obj) && u_object_load(obj) != 0) { return -1; } - uobject_export_name(obj, name, sizeof name); + u_object_export_name(obj, name, sizeof name); printf("exporting %s to %s\n", upkg_export_name(pkg, idx), name); of = fopen(name, "wb"); @@ -174,15 +174,15 @@ static int export(struct upkg *pkg, GObject *obj, unsigned idx) return -1; } - uobject_export(obj, of); + u_object_export(obj, of); if (fclose(of) != 0) { perror(name); return -1; } - if (UOBJECT_IS_LOADABLE(obj)) { - uobject_unload(obj); + if (U_OBJECT_IS_LOADABLE(obj)) { + u_object_unload(obj); } return 0; @@ -202,11 +202,11 @@ int package_export(struct upkg *pkg) return EXIT_FAILURE; } - type = uobject_module_get_class(package, class); + type = u_object_module_get_class(package, class); if (!type) continue; obj = g_object_new(type, NULL); - if (UOBJECT_IS_EXPORTABLE(obj)) { + if (U_OBJECT_IS_EXPORTABLE(obj)) { if (export(pkg, obj, i) != 0) { rc = EXIT_FAILURE; } @@ -253,7 +253,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (uobject_module_init() != 0) + if (u_object_module_init() != 0) return EXIT_FAILURE; pkg = upkg_fopen(argv[optind]); @@ -272,6 +272,6 @@ int main(int argc, char **argv) } upkg_close(pkg); - uobject_module_exit(); + u_object_module_exit(); return rc; } -- 2.43.0