update docs, new_WAD
This commit is contained in:
parent
4d13ac6a73
commit
6f8346c3fc
15
README.md
15
README.md
|
@ -1,5 +1,14 @@
|
||||||
# spitWAD
|
# spitwad
|
||||||
|
|
||||||
`spitWAD` is a simple DOOM WAD management library
|
Originally conceived as a joke between some friends after we laughed about how it would be better to use WADs to send data
|
||||||
|
between applications then JSON, because JSON is stupid and wasteful. `spitwad` is a library for interacting with WAD
|
||||||
|
files, popularized by ID games like DOOM and Quake. You can use it in your DOOM clone, or to package your data and
|
||||||
|
send it over a network as a WAD. Why? Why not!
|
||||||
|
|
||||||
`DOOM1.WAD` contained in this repo is the shareware version of DOOM and is used for tests
|
## Requirements
|
||||||
|
|
||||||
|
Should work on any POSIX platform out of the box
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Docs are a work in progress!
|
||||||
|
|
15
spitwad.c
15
spitwad.c
|
@ -22,9 +22,9 @@ static char* getstring(const unsigned char* data, size_t offset) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int new_WAD(struct WAD* wad, const unsigned char* data, size_t data_sz) {
|
int new_WAD_from_data(struct WAD* wad, const unsigned char* data, size_t data_sz) {
|
||||||
if (wad == NULL) {
|
if (wad == NULL) {
|
||||||
return fail("Supplied wad to new_WAD was NULL");
|
return fail("Supplied wad to new_WAD_from_data was NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
wad->data = malloc(sizeof(unsigned char) * data_sz);
|
wad->data = malloc(sizeof(unsigned char) * data_sz);
|
||||||
|
@ -98,18 +98,25 @@ int new_WAD_from_file(struct WAD* wad, const char* path) {
|
||||||
fread(buf, 1, fsz, fp);
|
fread(buf, 1, fsz, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
new_WAD(wad, buf, fsz);
|
new_WAD_from_data(wad, buf, fsz);
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int new_WAD(struct WAD* wad) {
|
||||||
|
wad->data = NULL;
|
||||||
|
wad->data_sz = 0;
|
||||||
|
wad->directory = NULL;
|
||||||
|
wad->dir_sz = 0;
|
||||||
|
wad->dir_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void destroy_WAD(struct WAD* wad) {
|
void destroy_WAD(struct WAD* wad) {
|
||||||
free(wad->data);
|
free(wad->data);
|
||||||
free(wad->directory);
|
free(wad->directory);
|
||||||
free(wad);
|
free(wad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_to_file(struct WAD* wad, const char* path) {
|
int write_to_file(struct WAD* wad, const char* path) {
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
fp = fopen(path, "wb");
|
fp = fopen(path, "wb");
|
||||||
|
|
|
@ -24,9 +24,11 @@ struct WAD {
|
||||||
struct DirEntry *directory;
|
struct DirEntry *directory;
|
||||||
};
|
};
|
||||||
|
|
||||||
int new_WAD(struct WAD* wad, const unsigned char* data, size_t data_sz);
|
int new_WAD_from_data(struct WAD* wad, const unsigned char* data, size_t data_sz);
|
||||||
int new_WAD_from_file(struct WAD* wad, const char* path);
|
int new_WAD_from_file(struct WAD* wad, const char* path);
|
||||||
|
int new_WAD(struct WAD* wad);
|
||||||
void destroy_WAD(struct WAD* wad);
|
void destroy_WAD(struct WAD* wad);
|
||||||
int write_to_file(struct WAD* wad, const char* path);
|
int write_to_file(struct WAD* wad, const char* path);
|
||||||
|
|
||||||
|
|
||||||
#endif //SPITWAD_H
|
#endif //SPITWAD_H
|
||||||
|
|
Loading…
Reference in New Issue