CGE: Rename constants in btfile and cfile

This commit is contained in:
Strangerke 2011-07-19 13:24:09 +02:00
parent dc28d9debb
commit 3289006458
6 changed files with 36 additions and 39 deletions

View File

@ -38,9 +38,9 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt)
: IoHand(name, mode, crpt) {
debugC(1, kDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode);
for (int i = 0; i < BT_LEVELS; i++) {
for (int i = 0; i < kBtLevel; i++) {
_buff[i]._page = new BtPage;
_buff[i]._pgNo = BT_NONE;
_buff[i]._pgNo = kBtValNone;
_buff[i]._indx = -1;
_buff[i]._updt = false;
if (_buff[i]._page == NULL)
@ -51,7 +51,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt)
BtFile::~BtFile() {
debugC(1, kDebugFile, "BtFile::~BtFile()");
for (int i = 0; i < BT_LEVELS; i++) {
for (int i = 0; i < kBtLevel; i++) {
putPage(i, false);
delete _buff[i]._page;
}
@ -82,7 +82,7 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) {
_buff[lev]._updt = false;
} else {
_buff[lev]._page->_hea._count = 0;
_buff[lev]._page->_hea._down = BT_NONE;
_buff[lev]._page->_hea._down = kBtValNone;
memset(_buff[lev]._page->_data, '\0', sizeof(_buff[lev]._page->_data));
_buff[lev]._updt = true;
}
@ -95,15 +95,15 @@ BtKeypack *BtFile::find(const char *key) {
debugC(1, kDebugFile, "BtFile::find(%s)", key);
int lev = 0;
uint16 nxt = BT_ROOT;
uint16 nxt = kBtValRoot;
while (!_error) {
BtPage *pg = getPage(lev, nxt);
// search
if (pg->_hea._down != BT_NONE) {
if (pg->_hea._down != kBtValNone) {
int i;
for (i = 0; i < pg->_hea._count; i++) {
// Does this work, or does it have to compare the entire buffer?
if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, BT_KEYLEN) < 0)
if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, kBtKeySize) < 0)
break;
}
nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down;
@ -124,14 +124,14 @@ BtKeypack *BtFile::find(const char *key) {
int keycomp(const void *k1, const void *k2) {
return scumm_strnicmp((const char *) k1, (const char*) k2, BT_KEYLEN);
return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize);
}
void BtFile::make(BtKeypack *keypack, uint16 count) {
debugC(1, kDebugFile, "BtFile::make(keypack, %d)", count);
#if BT_LEVELS != 2
#if kBtLevel != 2
#error This tiny BTREE implementation works with exactly 2 levels!
#endif
_fqsort(keypack, count, sizeof(*keypack), keycomp);
@ -144,7 +144,7 @@ void BtFile::make(BtKeypack *keypack, uint16 count) {
if (Leaf->_hea._count >= ArrayCount(Leaf->_lea)) {
putPage(1, true); // save filled page
Leaf = getPage(1, ++n); // take empty page
memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, BT_KEYLEN);
memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, kBtKeySize);
Root->_inn[Root->_hea._count++]._down = n;
_buff[0]._updt = true;
}

View File

@ -32,23 +32,23 @@
namespace CGE {
#define BT_SIZE 1024
#define BT_KEYLEN 13
#define BT_LEVELS 2
#define kBtSize 1024
#define kBtKeySize 13
#define kBtLevel 2
#define BT_NONE 0xFFFF
#define BT_ROOT 0
#define kBtValNone 0xFFFF
#define kBtValRoot 0
#include "common/pack-start.h" // START STRUCT PACKING
struct BtKeypack {
char _key[BT_KEYLEN];
char _key[kBtKeySize];
uint32 _mark;
uint16 _size;
};
struct Inner {
uint8 _key[BT_KEYLEN];
uint8 _key[kBtKeySize];
uint16 _down;
};
@ -61,11 +61,11 @@ struct BtPage {
Hea _hea;
union {
// dummy filler to make proper size of union
uint8 _data[BT_SIZE - sizeof(Hea)];
uint8 _data[kBtSize - sizeof(Hea)];
// inner version of data: key + word-sized page link
Inner _inn[(BT_SIZE - sizeof(Hea)) / sizeof(Inner)];
Inner _inn[(kBtSize - sizeof(Hea)) / sizeof(Inner)];
// leaf version of data: key + all user data
BtKeypack _lea[(BT_SIZE - sizeof(Hea)) / sizeof(BtKeypack)];
BtKeypack _lea[(kBtSize - sizeof(Hea)) / sizeof(BtKeypack)];
};
};
@ -78,7 +78,7 @@ class BtFile : public IoHand {
uint16 _pgNo;
int _indx;
bool _updt;
} _buff[BT_LEVELS];
} _buff[kBtLevel];
void putPage(int lev, bool hard);
BtPage *getPage(int lev, uint16 pgn);

View File

@ -40,7 +40,7 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt)
_lim(0) {
debugC(1, kDebugFile, "IoBuf::IoBuf(%d, crpt)", mode);
_buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE);
_buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize);
if (_buff == NULL)
error("No core for I/O");
}
@ -53,7 +53,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt)
_lim(0) {
debugC(1, kDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode);
_buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE);
_buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize);
if (_buff == NULL)
error("No core for I/O [%s]", name);
}
@ -71,7 +71,7 @@ void IoBuf::readBuf() {
debugC(4, kDebugFile, "IoBuf::readBuf()");
_bufMark = IoHand::mark();
_lim = IoHand::read(_buff, IOBUF_SIZE);
_lim = IoHand::read(_buff, kBufferSize);
_ptr = 0;
}
@ -115,14 +115,14 @@ uint16 IoBuf::read(uint8 *buf) {
uint16 total = 0;
while (total < LINE_MAX - 2) {
while (total < kLineMaxSize - 2) {
if (_ptr >= _lim)
readBuf();
uint8 *p = _buff + _ptr;
uint16 n = _lim - _ptr;
if (n) {
if (total + n >= LINE_MAX - 2)
n = LINE_MAX - 2 - total;
if (total + n >= kLineMaxSize - 2)
n = kLineMaxSize - 2 - total;
uint8 *eol = (uint8 *) memchr(p, '\r', n);
if (eol)
n = (uint16)(eol - p);
@ -162,7 +162,7 @@ uint16 IoBuf::write(void *buf, uint16 len) {
uint16 tot = 0;
while (len) {
uint16 n = IOBUF_SIZE - _lim;
uint16 n = kBufferSize - _lim;
if (n > len)
n = len;
if (n) {
@ -213,13 +213,13 @@ int IoBuf::read() {
void IoBuf::write(uint8 b) {
debugC(1, kDebugFile, "IoBuf::write(%d)", b);
if (_lim >= IOBUF_SIZE)
if (_lim >= kBufferSize)
writeBuf();
_buff[_lim++] = b;
}
uint16 CFile::_maxLineLen = LINE_MAX;
uint16 CFile::_maxLineLen = kLineMaxSize;
CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt)
@ -280,7 +280,7 @@ void CFile::append(CFile &f) {
seek(size());
if (f._error == 0) {
while (true) {
if ((_lim = f.IoHand::read(_buff, IOBUF_SIZE)) == IOBUF_SIZE)
if ((_lim = f.IoHand::read(_buff, kBufferSize)) == kBufferSize)
writeBuf();
else
break;

View File

@ -32,11 +32,8 @@
namespace CGE {
#define LINE_MAX 512
#define IOBUF_SIZE 2048
#define CFREAD(x) read((uint8 *)(x),sizeof(*(x)))
#define kLineMaxSize 512
#define kBufferSize 2048
class IoBuf : public IoHand {
protected:

View File

@ -433,7 +433,7 @@ void CGEEngine::loadHeroXY() {
INI_FILE cf(progName(".HXY"));
memset(_heroXY, 0, sizeof(_heroXY));
if (!cf._error)
cf.CFREAD(&_heroXY);
cf.read((uint8 *)(&_heroXY),sizeof(*(&_heroXY)));
}
void CGEEngine::loadMapping() {

View File

@ -111,8 +111,8 @@ void VFile::readBuf() {
}
_bufMark = _dat->_file.mark();
long n = _endMark - _bufMark;
if (n > IOBUF_SIZE)
n = IOBUF_SIZE;
if (n > kBufferSize)
n = kBufferSize;
_lim = _dat->_file.read(_buff, (uint16) n);
_ptr = 0;
}