]> git.draconx.ca Git - upkg.git/blobdiff - src/libupkg.c
license: Upgrade to GPL version 3 or later.
[upkg.git] / src / libupkg.c
index d5203b4ba6dba94ef955fd75fdff61bea20a667d..503e3f58b58ebca2185af5b4e88f00d555f7a7f3 100644 (file)
@@ -2,9 +2,9 @@
  *  upkg: tool for manipulating Unreal Tournament packages.
  *  Copyright (C) 2009 Nick Bowler
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdio.h>
@@ -171,7 +170,7 @@ static int pkg_init_names(struct upkg *pkg)
                /* Read some data into buffer. */
                if (!feof(pkg->priv->f)) {
                        rc = fread(buf+nbuf, 1, sizeof buf-nbuf, pkg->priv->f);
-                       if (rc == 0)
+                       if (rc == 0 && nbuf == 0)
                                goto err;
                        nbuf += rc;
                }
@@ -236,7 +235,7 @@ static int pkg_init_exports(struct upkg *pkg)
                /* Read some data into buffer. */
                if (!feof(pkg->priv->f)) {
                        rc = fread(buf+nbuf, 1, sizeof buf-nbuf, pkg->priv->f);
-                       if (rc == 0)
+                       if (rc == 0 && nbuf == 0)
                                goto err;
                        nbuf += rc;
                }
@@ -251,7 +250,7 @@ static int pkg_init_exports(struct upkg *pkg)
                len += rc;
 
                if (nbuf-len < 4) goto err;
-               export->package = unpack_32_le(buf+len);
+               export->package = unpack_s32_le(buf+len);
                len += 4;
 
                rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
@@ -306,7 +305,7 @@ static int pkg_init_imports(struct upkg *pkg)
                /* Read some data into buffer. */
                if (!feof(pkg->priv->f)) {
                        rc = fread(buf+nbuf, 1, sizeof buf-nbuf, pkg->priv->f);
-                       if (rc == 0)
+                       if (rc == 0 && nbuf == 0)
                                goto err;
                        nbuf += rc;
                }
@@ -323,7 +322,7 @@ static int pkg_init_imports(struct upkg *pkg)
                len += rc;
 
                if (nbuf-len < 4) goto err;
-               import->package = unpack_32_le(buf+len);
+               import->package = unpack_s32_le(buf+len);
                len += 4;
 
                rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
@@ -436,6 +435,13 @@ long upkg_export_find(struct upkg *pkg, 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)
 {
        if (idx < pkg->export_count)
@@ -444,7 +450,7 @@ 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, const char **group)
+                              const char **package)
 {
        struct upkg_export *export;
        struct upkg_import *iclass, *ipackage;
@@ -461,27 +467,6 @@ const char *upkg_export_class(struct upkg *pkg, unsigned long idx,
                return NULL;
        }
 
-       /* ASSUMPTION: group references are always exports */
-       if (export->package < 0) {
-               fprintf(stderr, "Assumption Violated: group not export\n");
-               return NULL;
-       }
-
-       /* Get the group name. */
-       if (export->package > 0) {
-               pkg_idx = export->package - 1;
-
-               if (pkg_idx >= pkg->export_count) {
-                       return NULL;
-               }
-
-               /* Lots more to handle.  Function arguments are stupid. */
-
-               if (group) *group = pkg->priv->exports[pkg_idx].name;
-       } else {
-               if (group) *group = NULL;
-       }
-
        /* Get the class. */
        if (export->class == 0) {
                if (package) *package = "Core";