mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Split main.c into separate files and set up directory structure
This commit is contained in:
parent
97527f549c
commit
f2c827ff6b
14
Makefile
Normal file
14
Makefile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
EX=devil1test
|
||||||
|
CC=gcc
|
||||||
|
CFLAGS= -I"include"
|
||||||
|
|
||||||
|
all: main
|
||||||
|
|
||||||
|
main: devil1pld.o
|
||||||
|
$(CC) $^ test/main.c $(CFLAGS) -o $(EX)
|
||||||
|
|
||||||
|
devil1pld.o: src/devil1pld.c
|
||||||
|
$(CC) -c $^ $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.o $(EX)
|
@ -9,4 +9,10 @@ struct PldHeader {
|
|||||||
uint32_t *offsets; // <format=hex>
|
uint32_t *offsets; // <format=hex>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// input: a pld header struct.
|
||||||
|
void showpldh(struct PldHeader *);
|
||||||
|
|
||||||
|
// input: contents of the .pld file.
|
||||||
|
struct PldHeader *getpldh(const char*);
|
||||||
|
|
||||||
#endif
|
#endif
|
37
src/devil1pld.c
Normal file
37
src/devil1pld.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "devil1pld.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
void printpldh(struct PldHeader *ph) {
|
||||||
|
if (ph == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("number of offsets = %i\n", ph -> numOffset);
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < ph -> numOffset; i++) {
|
||||||
|
printf("offset %i = %x\n", i, ph -> offsets[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PldHeader *getpldh(const char *buffer) {
|
||||||
|
if (buffer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int32_t *n = (int32_t*)buffer;
|
||||||
|
struct PldHeader *ph = (struct PldHeader*)malloc(
|
||||||
|
sizeof(struct PldHeader)
|
||||||
|
);
|
||||||
|
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
||||||
|
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
||||||
|
if (ph -> offsets == NULL) {
|
||||||
|
perror("Error 4: ");
|
||||||
|
free(ph);
|
||||||
|
free(ph -> offsets);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// set data of struct.
|
||||||
|
ph -> numOffset = n[0];
|
||||||
|
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
||||||
|
return ph;
|
||||||
|
}
|
@ -44,36 +44,6 @@ void splitpld(const char *buffer,
|
|||||||
free(wbuffer);
|
free(wbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showpldh(struct PldHeader *x) {
|
|
||||||
printf("number of offsets = %i\n", x -> numOffset);
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; i < x -> numOffset; i++) {
|
|
||||||
printf("offset %i = %x\n", i, x -> offsets[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PldHeader *getpldh(const char *buffer) {
|
|
||||||
if (buffer == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
int32_t *n = (int32_t*)buffer;
|
|
||||||
struct PldHeader *ph = (struct PldHeader*)malloc(
|
|
||||||
sizeof(struct PldHeader)
|
|
||||||
);
|
|
||||||
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
|
||||||
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
|
||||||
if (ph -> offsets == NULL) {
|
|
||||||
perror("Error 4: ");
|
|
||||||
free(ph);
|
|
||||||
free(ph -> offsets);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
// set data of struct.
|
|
||||||
ph -> numOffset = n[0];
|
|
||||||
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
|
||||||
return ph;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *loadfile(const char *fname, unsigned int *s) {
|
char *loadfile(const char *fname, unsigned int *s) {
|
||||||
FILE *f = fopen(fname, "rb");
|
FILE *f = fopen(fname, "rb");
|
||||||
unsigned int size = 0; // number of elements to buffer;
|
unsigned int size = 0; // number of elements to buffer;
|
Loading…
Reference in New Issue
Block a user