Skip to content

Commit

Permalink
DEVTOOLS: Moved implementation of create_mortdat File class from the …
Browse files Browse the repository at this point in the history
…header file
  • Loading branch information
dreammaster committed Jul 18, 2013
1 parent 0a91aee commit 44e6270
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 49 deletions.
62 changes: 62 additions & 0 deletions devtools/create_mortdat/create_mortdat.cpp
Expand Up @@ -42,6 +42,68 @@
#include "enginetext.h"
#include "gametext.h"


bool File::open(const char *filename, AccessMode mode) {
f = fopen(filename, (mode == kFileReadMode) ? "rb" : "wb");
return (f != NULL);
}

void File::close() {
fclose(f);
f = NULL;
}

int File::seek(int32 offset, int whence) {
return fseek(f, offset, whence);
}

long File::read(void *buffer, int len) {
return fread(buffer, 1, len, f);
}
void File::write(const void *buffer, int len) {
fwrite(buffer, 1, len, f);
}

byte File::readByte() {
byte v;
read(&v, sizeof(byte));
return v;
}

uint16 File::readWord() {
uint16 v;
read(&v, sizeof(uint16));
return FROM_LE_16(v);
}

uint32 File::readLong() {
uint32 v;
read(&v, sizeof(uint32));
return FROM_LE_32(v);
}

void File::writeByte(byte v) {
write(&v, sizeof(byte));
}

void File::writeWord(uint16 v) {
uint16 vTemp = TO_LE_16(v);
write(&vTemp, sizeof(uint16));
}

void File::writeLong(uint32 v) {
uint32 vTemp = TO_LE_32(v);
write(&vTemp, sizeof(uint32));
}

void File::writeString(const char *s) {
write(s, strlen(s) + 1);
}

uint32 File::pos() {
return ftell(f);
}

/*-------------------------------------------------------------------------*/

void openOutputFile(const char *outFilename) {
Expand Down
63 changes: 14 additions & 49 deletions devtools/create_mortdat/create_mortdat.h
Expand Up @@ -43,55 +43,20 @@ class File {
private:
FILE *f;
public:
bool open(const char *filename, AccessMode mode = kFileReadMode) {
f = fopen(filename, (mode == kFileReadMode) ? "rb" : "wb");
return (f != NULL);
}
void close() {
fclose(f);
f = NULL;
}
int seek(int32 offset, int whence = SEEK_SET) {
return fseek(f, offset, whence);
}
long read(void *buffer, int len) {
return fread(buffer, 1, len, f);
}
void write(const void *buffer, int len) {
fwrite(buffer, 1, len, f);
}
byte readByte() {
byte v;
read(&v, sizeof(byte));
return v;
}
uint16 readWord() {
uint16 v;
read(&v, sizeof(uint16));
return FROM_LE_16(v);
}
uint32 readLong() {
uint32 v;
read(&v, sizeof(uint32));
return FROM_LE_32(v);
}
void writeByte(byte v) {
write(&v, sizeof(byte));
}
void writeWord(uint16 v) {
uint16 vTemp = TO_LE_16(v);
write(&vTemp, sizeof(uint16));
}
void writeLong(uint32 v) {
uint32 vTemp = TO_LE_32(v);
write(&vTemp, sizeof(uint32));
}
void writeString(const char *s) {
write(s, strlen(s) + 1);
}
uint32 pos() {
return ftell(f);
}
bool open(const char *filename, AccessMode mode = kFileReadMode);
void close();
int seek(int32 offset, int whence = SEEK_SET);
uint32 pos();
long read(void *buffer, int len);
void write(const void *buffer, int len);

byte readByte();
uint16 readWord();
uint32 readLong();
void writeByte(byte v);
void writeWord(uint16 v);
void writeLong(uint32 v);
void writeString(const char *s);
};

File outputFile, mortCom;
Expand Down

0 comments on commit 44e6270

Please sign in to comment.