From 9bfc1251585f41cd61db8dd966bbf1f0b8a964d0 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Tue, 17 Apr 2018 19:37:59 -0700 Subject: [PATCH] Added namespace structs for pld's --- include/devil1pld.h | 15 +++++++++++---- src/devil1pld.c | 8 +++++--- test/main.c | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/devil1pld.h b/include/devil1pld.h index d57bfd7..f79e496 100644 --- a/include/devil1pld.h +++ b/include/devil1pld.h @@ -15,14 +15,21 @@ struct PldHeader { // input: pointer to a struct, contents of the .pld file. // * = pass by reference of a struct PldHeader -bool getpldh(struct PldHeader*, const char*); +static bool getpldh(struct PldHeader*, const char*); // input: pointer to header, index of offset, filesize // * = pass by reference of a struct PldHeader -int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int); +static int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int); // input: a pld header struct. // * = pass by reference of a struct PldHeader -void printpldh(struct PldHeader*); +static void printpldh(struct PldHeader*); -#endif \ No newline at end of file +typedef struct { + bool (* const getheader) (struct PldHeader*, const char*); + int (* const sizeofsector)(struct PldHeader*, unsigned int, unsigned int); + void (* const printheader) (struct PldHeader*); +} namespace_struct; +extern namespace_struct const DEVIL1PLD; + +#endif diff --git a/src/devil1pld.c b/src/devil1pld.c index bc0e378..148e323 100644 --- a/src/devil1pld.c +++ b/src/devil1pld.c @@ -1,7 +1,7 @@ #include "devil1pld.h" #include -bool getpldh(struct PldHeader *ph, const char *filedata) { +static bool getpldh(struct PldHeader *ph, const char *filedata) { bool good = false; if (ph != NULL && filedata != NULL) { ph -> numOffset = (int32_t)filedata[0]; @@ -12,7 +12,7 @@ bool getpldh(struct PldHeader *ph, const char *filedata) { } // determine the size of the i-th pld structure -int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) { +static int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) { unsigned int size = -1; if (ph == NULL) { fprintf(stderr, "Error: given null pointer\n"); @@ -29,7 +29,7 @@ int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) { return size; } -void printpldh(struct PldHeader *ph) { +static void printpldh(struct PldHeader *ph) { if (ph == NULL) { return; } @@ -40,3 +40,5 @@ void printpldh(struct PldHeader *ph) { printf("offset %i = %x\n", i, ph -> offsets[i]); } } + +namespace_struct const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh}; diff --git a/test/main.c b/test/main.c index 881b260..0b685da 100644 --- a/test/main.c +++ b/test/main.c @@ -67,7 +67,7 @@ bool unpackpld(const char *filedata, return false; } struct PldHeader h; - getpldh(&h, filedata); + DEVIL1PLD.getheader(&h, filedata); char *fn = NULL; fn = (char*)malloc(strlen(filename) + 3 + 4); int size = 0; @@ -75,7 +75,7 @@ bool unpackpld(const char *filedata, char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'}; for (i = 0; i < h.numOffset; i++) { const char * currentfile = filedata + h.offsets[i]; - size = sizeofpldstruct(&h, i, filesize); + size = DEVIL1PLD.sizeofsector(&h, i, filesize); if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0) sprintf(fn, "%s_%d.txp", filename, i); else