MT32: Get rid of ANSIFile.

svn-id: r54827
This commit is contained in:
Johannes Schickel 2010-12-08 01:35:12 +00:00
parent 08262d90fb
commit d451084fb4
3 changed files with 50 additions and 117 deletions

View File

@ -20,44 +20,10 @@
*/ */
// FIXME: Disable symbol overrides so that we can use system headers.
// But we *really* should get rid of this usage of FILE, fopen etc.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include <stdio.h>
#include "mt32emu.h" #include "mt32emu.h"
namespace MT32Emu { namespace MT32Emu {
bool ANSIFile::open(const char *filename, OpenMode mode) {
const char *fmode;
if (mode == OpenMode_read) {
fmode = "rb";
} else {
fmode = "wb";
}
fp = fopen(filename, fmode);
return (fp != NULL);
}
void ANSIFile::close() {
fclose((FILE *)fp);
}
size_t ANSIFile::read(void *in, size_t size) {
return fread(in, 1, size, (FILE *)fp);
}
bool ANSIFile::readBit8u(Bit8u *in) {
int c = fgetc((FILE *)fp);
if (c == EOF)
return false;
*in = (Bit8u)c;
return true;
}
bool File::readBit16u(Bit16u *in) { bool File::readBit16u(Bit16u *in) {
Bit8u b[2]; Bit8u b[2];
if (read(&b[0], 2) != 2) if (read(&b[0], 2) != 2)
@ -74,14 +40,6 @@ namespace MT32Emu {
return true; return true;
} }
size_t ANSIFile::write(const void *out, size_t size) {
return fwrite(out, 1, size, (FILE *)fp);
}
bool ANSIFile::writeBit8u(Bit8u out) {
return fputc(out, (FILE *)fp) != EOF;
}
bool File::writeBit16u(Bit16u out) { bool File::writeBit16u(Bit16u out) {
if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) { if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) {
return false; return false;
@ -108,7 +66,5 @@ namespace MT32Emu {
return true; return true;
} }
bool ANSIFile::isEOF() { } // End of namespace MT32Emu
return feof((FILE *)fp) != 0;
}
}

View File

@ -22,7 +22,7 @@
#ifndef MT32EMU_FILE_H #ifndef MT32EMU_FILE_H
#define MT32EMU_FILE_H #define MT32EMU_FILE_H
#include <stdio.h> #include "common/scummsys.h"
namespace MT32Emu { namespace MT32Emu {
@ -47,19 +47,6 @@ public:
virtual bool isEOF() = 0; virtual bool isEOF() = 0;
}; };
class ANSIFile: public File { } // End of namespace MT32Emu
private:
void *fp;
public:
bool open(const char *filename, OpenMode mode);
void close();
size_t read(void *in, size_t size);
bool readBit8u(Bit8u *in);
size_t write(const void *out, size_t size);
bool writeBit8u(Bit8u out);
bool isEOF();
};
}
#endif #endif

View File

@ -162,22 +162,12 @@ void Synth::initReverb(Bit8u newRevMode, Bit8u newRevTime, Bit8u newRevLevel) {
} }
File *Synth::openFile(const char *filename, File::OpenMode mode) { File *Synth::openFile(const char *filename, File::OpenMode mode) {
if (myProp.openFile != NULL) { // It should never happen that openFile is NULL in our use case.
// Just to cover the case where something is horrible wrong we
// use an assert here.
assert(myProp.openFile != NULL);
return myProp.openFile(myProp.userData, filename, mode); return myProp.openFile(myProp.userData, filename, mode);
} }
char pathBuf[2048];
if (myProp.baseDir != NULL) {
strcpy(&pathBuf[0], myProp.baseDir);
strcat(&pathBuf[0], filename);
filename = pathBuf;
}
ANSIFile *file = new ANSIFile();
if (!file->open(filename, mode)) {
delete file;
return NULL;
}
return file;
}
void Synth::closeFile(File *file) { void Synth::closeFile(File *file) {
if (myProp.closeFile != NULL) { if (myProp.closeFile != NULL) {