From 93e93b56405cc395e723cd43e7ed0008173eab18 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 22 Mar 2017 03:10:32 +0200 Subject: FULLPIPE: Use Common::String with _memfilename and loadFile() There are several calls to loadFile() with _memfilename, which is why these two changes are interconnected --- engines/fullpipe/utils.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'engines/fullpipe/utils.cpp') diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp index cc85886a0f..f58249c04e 100644 --- a/engines/fullpipe/utils.cpp +++ b/engines/fullpipe/utils.cpp @@ -121,7 +121,6 @@ void MfcArchive::writePascalString(const char *str, bool twoByte) { } MemoryObject::MemoryObject() { - _memfilename = 0; _mfield_8 = 0; _mfield_C = 0; _mfield_10 = -1; @@ -134,19 +133,14 @@ MemoryObject::MemoryObject() { MemoryObject::~MemoryObject() { freeData(); - if (_memfilename) - free(_memfilename); } bool MemoryObject::load(MfcArchive &file) { debugC(5, kDebugLoading, "MemoryObject::load()"); _memfilename = file.readPascalString(); - if (char *p = strchr(_memfilename, '\\')) { - for (char *d = _memfilename; *p;) { - p++; - *d++ = *p; - } + while (_memfilename.contains('\\')) { + _memfilename.deleteChar(0); } if (g_fp->_currArchive) { @@ -157,10 +151,10 @@ bool MemoryObject::load(MfcArchive &file) { return true; } -void MemoryObject::loadFile(char *filename) { - debugC(5, kDebugLoading, "MemoryObject::loadFile(<%s>)", filename); +void MemoryObject::loadFile(Common::String filename) { + debugC(5, kDebugLoading, "MemoryObject::loadFile(<%s>)", filename.c_str()); - if (!*filename) + if (filename.empty()) return; if (!_data) { @@ -176,7 +170,7 @@ void MemoryObject::loadFile(char *filename) { _dataSize = s->size(); - debugC(5, kDebugLoading, "Loading %s (%d bytes)", filename, _dataSize); + debugC(5, kDebugLoading, "Loading %s (%d bytes)", filename.c_str(), _dataSize); _data = (byte *)calloc(_dataSize, 1); s->read(_data, _dataSize); @@ -205,7 +199,7 @@ byte *MemoryObject::loadData() { } void MemoryObject::freeData() { - debugC(8, kDebugMemory, "MemoryObject::freeData(): file: %s", _memfilename); + debugC(8, kDebugMemory, "MemoryObject::freeData(): file: %s", _memfilename.c_str()); if (_data) free(_data); @@ -238,9 +232,9 @@ bool MemoryObject2::load(MfcArchive &file) { _mflags |= 1; - debugC(5, kDebugLoading, "MemoryObject2::load: <%s>", _memfilename); + debugC(5, kDebugLoading, "MemoryObject2::load: <%s>", _memfilename.c_str()); - if (_memfilename && *_memfilename) { + if (!_memfilename.empty()) { MemoryObject::loadFile(_memfilename); } -- cgit v1.2.3 From 728b23af2ad939e3da920a41b85730689a1aa71f Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 22 Mar 2017 04:07:33 +0200 Subject: FULLPIPE: Change transCyrillic() to accept a Common::String --- engines/fullpipe/utils.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/fullpipe/utils.cpp') diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp index f58249c04e..d06354cb91 100644 --- a/engines/fullpipe/utils.cpp +++ b/engines/fullpipe/utils.cpp @@ -104,7 +104,7 @@ char *MfcArchive::readPascalString(bool twoByte) { tmp = (char *)calloc(len + 1, 1); read(tmp, len); - debugC(9, kDebugLoading, "readPascalString: %d <%s>", len, transCyrillic((byte *)tmp)); + debugC(9, kDebugLoading, "readPascalString: %d <%s>", len, transCyrillic(tmp)); return tmp; } @@ -498,7 +498,8 @@ char *genFileName(int superId, int sceneId, const char *ext) { } // Translates cp-1251..utf-8 -byte *transCyrillic(byte *s) { +byte *transCyrillic(Common::String str) { + byte *s = (byte *)str.c_str(); static byte tmp[1024]; #ifndef WIN32 -- cgit v1.2.3 From f3e81b5f17872186f7c67a551876dd78f268865c Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 22 Mar 2017 04:11:49 +0200 Subject: FULLPIPE: Use Common::String in all scene object names --- engines/fullpipe/utils.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'engines/fullpipe/utils.cpp') diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp index d06354cb91..689491d11d 100644 --- a/engines/fullpipe/utils.cpp +++ b/engines/fullpipe/utils.cpp @@ -92,9 +92,10 @@ bool DWordArray::load(MfcArchive &file) { return true; } -char *MfcArchive::readPascalString(bool twoByte) { +Common::String MfcArchive::readPascalString(bool twoByte) { char *tmp; int len; + Common::String result; if (twoByte) len = readUint16LE(); @@ -103,21 +104,23 @@ char *MfcArchive::readPascalString(bool twoByte) { tmp = (char *)calloc(len + 1, 1); read(tmp, len); + result = tmp; + free(tmp); - debugC(9, kDebugLoading, "readPascalString: %d <%s>", len, transCyrillic(tmp)); + debugC(9, kDebugLoading, "readPascalString: %d <%s>", len, transCyrillic(result)); - return tmp; + return result; } -void MfcArchive::writePascalString(const char *str, bool twoByte) { - int len = strlen(str); +void MfcArchive::writePascalString(Common::String str, bool twoByte) { + int len = str.size(); if (twoByte) writeUint16LE(len); else writeByte(len); - write(str, len); + write(str.c_str(), len); } MemoryObject::MemoryObject() { @@ -388,7 +391,7 @@ CObject *MfcArchive::readClass() { } CObject *MfcArchive::parseClass(bool *isCopyReturned) { - char *name; + Common::String name; int objectId = 0; CObject *res = 0; @@ -404,13 +407,13 @@ CObject *MfcArchive::parseClass(bool *isCopyReturned) { debugC(7, kDebugLoading, "parseClass::schema = %d", schema); name = readPascalString(true); - debugC(7, kDebugLoading, "parseClass::class <%s>", name); + debugC(7, kDebugLoading, "parseClass::class <%s>", name.c_str()); - if (!_classMap.contains(name)) { - error("Unknown class in MfcArchive: <%s>", name); + if (!_classMap.contains(name.c_str())) { + error("Unknown class in MfcArchive: <%s>", name.c_str()); } - objectId = _classMap[name]; + objectId = _classMap[name.c_str()]; debugC(7, kDebugLoading, "tag: %d 0x%x (%x)", _objectMap.size() - 1, _objectMap.size() - 1, objectId); -- cgit v1.2.3 From 2649e2b1fc9d0ab0d5d648602f3d6b936e94dbdb Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 22 Mar 2017 04:50:37 +0200 Subject: FULLPIPE: Change genFileName() and loadFile() to use Common::String --- engines/fullpipe/utils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/fullpipe/utils.cpp') diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp index 689491d11d..ed30096b69 100644 --- a/engines/fullpipe/utils.cpp +++ b/engines/fullpipe/utils.cpp @@ -33,7 +33,7 @@ namespace Fullpipe { -bool CObject::loadFile(const char *fname) { +bool CObject::loadFile(Common::String fname) { Common::File file; if (!file.open(fname)) @@ -486,16 +486,16 @@ void MfcArchive::writeObject(CObject *obj) { } } -char *genFileName(int superId, int sceneId, const char *ext) { - char *s = (char *)calloc(256, 1); +Common::String genFileName(int superId, int sceneId, const char *ext) { + Common::String s; if (superId) { - snprintf(s, 255, "%04d%04d.%s", superId, sceneId, ext); + s = Common::String::format("%04d%04d.%s", superId, sceneId, ext); } else { - snprintf(s, 255, "%04d.%s", sceneId, ext); + s = Common::String::format("%04d.%s", sceneId, ext); } - debugC(7, kDebugLoading, "genFileName: %s", s); + debugC(7, kDebugLoading, "genFileName: %s", s.c_str()); return s; } -- cgit v1.2.3