]> git.draconx.ca Git - upkg.git/commitdiff
libupkg: Split the upkg_export struct into public/private parts.
authorNick Bowler <nbowler@draconx.ca>
Thu, 3 Mar 2011 02:46:19 +0000 (21:46 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 13 Mar 2011 21:38:59 +0000 (17:38 -0400)
This eliminates the need for dedicated functions to extract the name
and flag fields from the export struct.  It should now be easy to convey
export information to applications.

src/libupkg.c
src/upkg.c
src/upkg.h

index b87c5dde8ef0a4c444bcf8bd1c50090007811ce8..e861bcb7d08c405817ed85d31b19b2de3fab89e5 100644 (file)
@@ -43,11 +43,10 @@ struct upkg_name {
        char *name;
 };
 
-struct upkg_export {
-       const char *name;
+struct upkg_export_priv {
+       struct upkg_export pub;
 
        long package, class, super;
-       unsigned long flags;
        unsigned long size, offset;
 };
 
@@ -63,9 +62,9 @@ struct upkg_private {
 
        struct upkg_file *last_file;
 
-       struct upkg_name   *names;
-       struct upkg_export *exports;
-       struct upkg_import *imports;
+       struct upkg_name        *names;
+       struct upkg_export_priv *exports;
+       struct upkg_import      *imports;
 
        unsigned long name_offset, export_offset, import_offset;
        unsigned char guid[16];
@@ -284,7 +283,7 @@ static int pkg_init_exports(struct upkg *pkg)
                return -1;
 
        while (index < pkg->export_count) {
-               struct upkg_export *export = &pkg->priv->exports[index];
+               struct upkg_export_priv *export = &pkg->priv->exports[index];
                long tmp;
 
                /* Read some data into buffer. */
@@ -310,11 +309,11 @@ static int pkg_init_exports(struct upkg *pkg)
 
                rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
                if (rc == 0 || tmp < 0 || tmp >= pkg->name_count) goto err;
-               export->name = pkg->priv->names[tmp].name;
+               export->pub.name = pkg->priv->names[tmp].name;
                len += rc;
 
                if (nbuf-len < 4) goto err;
-               export->flags = unpack_32_le(buf+len);
+               export->pub.flags = unpack_32_le(buf+len);
                len += 4;
 
                rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
@@ -500,11 +499,11 @@ long upkg_export_find(struct upkg *pkg, long parent, const char *name)
        long package = parent < 0 ? 0 : parent + 1;
 
        for (unsigned long i = 0; i < pkg->export_count; i++) {
-               struct upkg_export *e = &pkg->priv->exports[i];
+               struct upkg_export_priv *e = &pkg->priv->exports[i];
 
                /* Assertion: an object's package is an export. */
                format_assert(e->package >= 0, continue);
-               if (e->package == package && strcmp(e->name, name) == 0) {
+               if (e->package == package && strcmp(e->pub.name, name) == 0) {
                        return i;
                }
        }
@@ -512,24 +511,17 @@ long upkg_export_find(struct upkg *pkg, long parent, const char *name)
        return -1;
 }
 
-unsigned long upkg_export_flags(struct upkg *pkg, unsigned long idx)
-{
-       if (idx < pkg->export_count)
-               return pkg->priv->exports[idx].flags;
-       return 0;
-}
-
-const char *upkg_export_name(struct upkg *pkg, unsigned long idx)
+const struct upkg_export *upkg_get_export(struct upkg *pkg, unsigned long idx)
 {
        if (idx < pkg->export_count)
-               return pkg->priv->exports[idx].name;
+               return &pkg->priv->exports[idx].pub;
        return NULL;
 }
 
 const char *upkg_export_class(struct upkg *pkg, unsigned long idx,
                               const char **package)
 {
-       struct upkg_export *export;
+       struct upkg_export_priv *export;
        struct upkg_import *iclass, *ipackage;
        unsigned long pkg_idx;
 
@@ -588,7 +580,7 @@ struct upkg_file *upkg_export_open(struct upkg *pkg, unsigned long idx)
                .pkg  = pkg,
                .base = pkg->priv->exports[idx].offset,
                .len  = pkg->priv->exports[idx].size,
-               .name = pkg->priv->exports[idx].name,
+               .name = pkg->priv->exports[idx].pub.name,
        };
 
        return f;
index 038eb39fe9ce410921abbad8134f5e180536fdb4..989bf798f322e10d5d546d8f1e99d63ee3385868 100644 (file)
@@ -181,18 +181,18 @@ void print_guid(unsigned char guid[static 16])
 void print_upkg_exports(struct upkg *pkg)
 {
        for (unsigned i = 0; i < pkg->export_count; i++) {
-               const char *name, *package, *class;
+               const struct upkg_export *export = upkg_get_export(pkg, i);
+               const char *package, *class;
 
-               name  = upkg_export_name(pkg, i);
                class = upkg_export_class(pkg, i, &package);
 
-               if (!name || !class)
+               if (!class)
                        continue;
 
-               printf("%u - %s (%s.%s)\n", i+1, name, package, class);
-               printf("  Flags: %lx\n", upkg_export_flags(pkg, i));
+               printf("%u - %s (%s.%s)\n", i+1, export->name, package, class);
+               printf("  Flags: %lx\n", export->flags);
                if (verbose >= 2) {
-                       print_upkg_object_flags("    ", upkg_export_flags(pkg, i));
+                       print_upkg_object_flags("    ", export->flags);
                }
        }
 }
@@ -225,6 +225,7 @@ int package_info(struct upkg *pkg)
 
 static int export(struct upkg *pkg, GObject *obj, unsigned idx)
 {
+       const struct upkg_export *export = upkg_get_export(pkg, idx);
        char name[256];
        FILE *of;
 
@@ -238,7 +239,7 @@ static int export(struct upkg *pkg, GObject *obj, unsigned idx)
 
        u_object_export_name(obj, name, sizeof name);
 
-       printf("exporting %s to %s\n", upkg_export_name(pkg, idx), name);
+       printf("exporting %s to %s\n", export->name, name);
        of = fopen(name, "wb");
        if (!of) {
                perror(name);
index 57477a579b34c87d0535866dcbd06ac20fec68b4..f9193c5318c5661dab4d7fd2949d1f6c8a54e215 100644 (file)
@@ -79,6 +79,11 @@ struct upkg {
        struct upkg_private *priv;
 };
 
+struct upkg_export {
+       const char *name;
+       unsigned long flags;
+};
+
 struct upkg_file {
        const char *name;
 
@@ -97,11 +102,10 @@ struct upkg *upkg_fopen(const char *path);
 int upkg_close(struct upkg *pkg);
 
 const char *upkg_get_name(struct upkg *pkg, unsigned long idx);
+const struct upkg_export *upkg_get_export(struct upkg *pkg, unsigned long idx);
 
 long upkg_export_find(struct upkg *pkg, long parent, const char *name);
 
-unsigned long upkg_export_flags(struct upkg *pkg, unsigned long idx);
-const char *upkg_export_name(struct upkg *pkg, unsigned long idx);
 const char *upkg_export_class(struct upkg *pkg, unsigned long idx,
                               const char **package);