Added namespace structs for pld's

This commit is contained in:
_ 2018-04-17 19:37:59 -07:00
parent 7964563396
commit 9bfc125158
3 changed files with 18 additions and 9 deletions

View File

@ -15,14 +15,21 @@ struct PldHeader {
// input: pointer to a struct, contents of the .pld file. // input: pointer to a struct, contents of the .pld file.
// * = pass by reference of a struct PldHeader // * = 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 // input: pointer to header, index of offset, filesize
// * = pass by reference of a struct PldHeader // * = 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. // input: a pld header struct.
// * = pass by reference of a struct PldHeader // * = pass by reference of a struct PldHeader
void printpldh(struct PldHeader*); static void printpldh(struct PldHeader*);
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 #endif

View File

@ -1,7 +1,7 @@
#include "devil1pld.h" #include "devil1pld.h"
#include <stdio.h> #include <stdio.h>
bool getpldh(struct PldHeader *ph, const char *filedata) { static bool getpldh(struct PldHeader *ph, const char *filedata) {
bool good = false; bool good = false;
if (ph != NULL && filedata != NULL) { if (ph != NULL && filedata != NULL) {
ph -> numOffset = (int32_t)filedata[0]; 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 // 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; unsigned int size = -1;
if (ph == NULL) { if (ph == NULL) {
fprintf(stderr, "Error: given null pointer\n"); fprintf(stderr, "Error: given null pointer\n");
@ -29,7 +29,7 @@ int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
return size; return size;
} }
void printpldh(struct PldHeader *ph) { static void printpldh(struct PldHeader *ph) {
if (ph == NULL) { if (ph == NULL) {
return; return;
} }
@ -40,3 +40,5 @@ void printpldh(struct PldHeader *ph) {
printf("offset %i = %x\n", i, ph -> offsets[i]); printf("offset %i = %x\n", i, ph -> offsets[i]);
} }
} }
namespace_struct const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh};

View File

@ -67,7 +67,7 @@ bool unpackpld(const char *filedata,
return false; return false;
} }
struct PldHeader h; struct PldHeader h;
getpldh(&h, filedata); DEVIL1PLD.getheader(&h, filedata);
char *fn = NULL; char *fn = NULL;
fn = (char*)malloc(strlen(filename) + 3 + 4); fn = (char*)malloc(strlen(filename) + 3 + 4);
int size = 0; int size = 0;
@ -75,7 +75,7 @@ bool unpackpld(const char *filedata,
char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'}; char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
for (i = 0; i < h.numOffset; i++) { for (i = 0; i < h.numOffset; i++) {
const char * currentfile = filedata + h.offsets[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) if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0)
sprintf(fn, "%s_%d.txp", filename, i); sprintf(fn, "%s_%d.txp", filename, i);
else else