aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Boutonné2011-01-30 23:08:05 +0000
committerArnaud Boutonné2011-01-30 23:08:05 +0000
commita07d37d3a5cefad04ca1d7797f8ad9dfe6c2bb47 (patch)
tree4e7b49e9beb61e276fa955c9d81999cfc055c3cc
parentc7808b90919201f6aa7e98e971d6e64fa43572db (diff)
downloadscummvm-rg350-a07d37d3a5cefad04ca1d7797f8ad9dfe6c2bb47.tar.gz
scummvm-rg350-a07d37d3a5cefad04ca1d7797f8ad9dfe6c2bb47.tar.bz2
scummvm-rg350-a07d37d3a5cefad04ca1d7797f8ad9dfe6c2bb47.zip
HUGO:
- Replace several char* by Common::String - Fix a bug in showDosInventory() svn-id: r55669
-rw-r--r--engines/hugo/file.cpp10
-rw-r--r--engines/hugo/file.h2
-rw-r--r--engines/hugo/file_v1d.cpp16
-rw-r--r--engines/hugo/hugo.cpp12
-rw-r--r--engines/hugo/hugo.h2
-rw-r--r--engines/hugo/parser.cpp22
-rw-r--r--engines/hugo/schedule.cpp8
7 files changed, 34 insertions, 38 deletions
diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index dcd84d7d04..164aa18016 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -170,15 +170,13 @@ void FileManager::readImage(int objNum, object_t *objPtr) {
_objectsArchive.seek(objBlock.objOffset, SEEK_SET);
} else {
- char *buf = (char *) malloc(2048 + 1); // Buffer for file access
- strcat(strcat(strcpy(buf, _vm->_picDir), _vm->_text->getNoun(objPtr->nounIndex, 0)), ".PIX");
+ Common::String buf;
+ buf = _vm->_picDir + Common::String(_vm->_text->getNoun(objPtr->nounIndex, 0)) + Common::String(".PIX");
if (!_objectsArchive.open(buf)) {
- warning("File %s not found, trying again with %s%s", buf, _vm->_text->getNoun(objPtr->nounIndex, 0), ".PIX");
- strcat(strcpy(buf, _vm->_text->getNoun(objPtr->nounIndex, 0)), ".PIX");
+ buf = Common::String(_vm->_text->getNoun(objPtr->nounIndex, 0)) + Common::String(".PIX");
if (!_objectsArchive.open(buf))
error("File not found: %s", buf);
}
- free(buf);
}
bool firstFl = true; // Initializes pcx read function
@@ -294,7 +292,7 @@ sound_pt FileManager::getSound(int16 sound, uint16 *size) {
/**
* Return whether file exists or not
*/
-bool FileManager::fileExists(char *filename) {
+bool FileManager::fileExists(Common::String filename) {
Common::File f;
return(f.exists(filename));
}
diff --git a/engines/hugo/file.h b/engines/hugo/file.h
index 72029f0ddb..3920fd66f6 100644
--- a/engines/hugo/file.h
+++ b/engines/hugo/file.h
@@ -44,7 +44,7 @@ public:
FileManager(HugoEngine *vm);
virtual ~FileManager();
- bool fileExists(char *filename);
+ bool fileExists(Common::String filename);
sound_pt getSound(int16 sound, uint16 *size);
void readBootFile();
diff --git a/engines/hugo/file_v1d.cpp b/engines/hugo/file_v1d.cpp
index 4ed3ec3bd8..8a07518a13 100644
--- a/engines/hugo/file_v1d.cpp
+++ b/engines/hugo/file_v1d.cpp
@@ -60,25 +60,22 @@ void FileManager_v1d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
debugC(1, kDebugFile, "readOverlay(%d, ...)", screenNum);
const char *ovl_ext[] = {".b", ".o", ".ob"};
- char *buf = (char *) malloc(2048 + 1); // Buffer for file access
-
- strcat(strcpy(buf, _vm->_text->getScreenNames(screenNum)), ovl_ext[overlayType]);
+ Common::String buf = Common::String(_vm->_text->getScreenNames(screenNum)) + Common::String(ovl_ext[overlayType]);
if (!fileExists(buf)) {
for (int i = 0; i < kOvlSize; i++)
image[i] = 0;
- warning("File not found: %s", buf);
+ warning("File not found: %s", buf.c_str());
return;
}
if (!_sceneryArchive1.open(buf))
- error("File not found: %s", buf);
+ error("File not found: %s", buf.c_str());
image_pt tmpImage = image; // temp ptr to overlay file
_sceneryArchive1.read(tmpImage, kOvlSize);
_sceneryArchive1.close();
- free(buf);
}
/**
@@ -87,16 +84,15 @@ void FileManager_v1d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
void FileManager_v1d::readBackground(int screenIndex) {
debugC(1, kDebugFile, "readBackground(%d)", screenIndex);
- char *buf = (char *) malloc(2048 + 1); // Buffer for file access
- strcat(strcpy(buf, _vm->_text->getScreenNames(screenIndex)), ".ART");
+ Common::String buf;
+ buf = Common::String(_vm->_text->getScreenNames(screenIndex)) + Common::String(".ART");
if (!_sceneryArchive1.open(buf))
- error("File not found: %s", buf);
+ error("File not found: %s", buf.c_str());
// Read the image into dummy seq and static dib_a
seq_t *dummySeq; // Image sequence structure for Read_pcx
dummySeq = readPCX(_sceneryArchive1, 0, _vm->_screen->getFrontBuffer(), true, _vm->_text->getScreenNames(screenIndex));
free(dummySeq);
_sceneryArchive1.close();
- free(buf);
}
char *FileManager_v1d::fetchString(int index) {
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index eeeb915401..1bc408fb14 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -826,27 +826,27 @@ void HugoEngine::initialize() {
switch (_gameVariant) {
case kGameVariantH1Dos:
_episode = "\"Hugo's House of Horrors\"";
- _picDir = "";
+ _picDir = Common::String("");
break;
case kGameVariantH2Dos:
_episode = "\"Hugo II: Whodunit?\"";
- _picDir = "";
+ _picDir = Common::String("");
break;
case kGameVariantH3Dos:
_episode = "\"Hugo III: Jungle of Doom\"";
- _picDir = "pictures/";
+ _picDir = Common::String("pictures/");
break;
case kGameVariantH1Win:
_episode = "\"Hugo's Horrific Adventure\"";
- _picDir = "hugo1/";
+ _picDir = Common::String("hugo1/");
break;
case kGameVariantH2Win:
_episode = "\"Hugo's Mystery Adventure\"";
- _picDir = "hugo2/";
+ _picDir = Common::String("hugo2/");
break;
case kGameVariantH3Win:
_episode = "\"Hugo's Amazon Adventure\"";
- _picDir = "hugo3/";
+ _picDir = Common::String("hugo3/");
break;
default:
error("Unknown game");
diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h
index 1aaecdf0ec..56d8089682 100644
--- a/engines/hugo/hugo.h
+++ b/engines/hugo/hugo.h
@@ -297,7 +297,7 @@ public:
Common::RandomSource *_rnd;
const char *_episode;
- const char *_picDir;
+ Common::String _picDir;
Common::String _saveFilename;
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index cc46d2938f..fcaa80d21c 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -319,7 +319,8 @@ void Parser::showDosInventory() {
for (int i = 0; i < _vm->_object->_numObj; i++) { // Find widths of 2 columns
if (_vm->_object->isCarried(i)) {
- uint16 len = strlen(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 1));
+ uint16 len = strlen(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2));
+ printf("%s %d\n", _vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2), strlen(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2)));
if (index++ & 1) // Right hand column
len2 = (len > len2) ? len : len2;
else
@@ -331,23 +332,24 @@ void Parser::showDosInventory() {
if (len1 + len2 < (uint16)strlen(_vm->_text->getTextParser(kTBOutro)))
len1 = strlen(_vm->_text->getTextParser(kTBOutro));
- char buffer[kCompLineSize * kMaxTextRows] = "\0";
- strncat(buffer, blanks, (len1 + len2 - strlen(_vm->_text->getTextParser(kTBIntro))) / 2);
- strcat(strcat(buffer, _vm->_text->getTextParser(kTBIntro)), "\n");
+ Common::String buffer;
+ assert(len1 + len2 - strlen(_vm->_text->getTextParser(kTBIntro)) / 2 < strlen(blanks));
+ buffer = Common::String(blanks, (len1 + len2 - strlen(_vm->_text->getTextParser(kTBIntro))) / 2);
+
+ buffer += Common::String(_vm->_text->getTextParser(kTBIntro)) + Common::String("\n");
index = 0;
for (int i = 0; i < _vm->_object->_numObj; i++) { // Assign strings
if (_vm->_object->isCarried(i)) {
if (index++ & 1)
- strcat(strcat(buffer, _vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 1)), "\n");
+ buffer += Common::String(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2)) + Common::String("\n");
else
- strncat(strcat(buffer, _vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 1)), blanks, len1 - strlen(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 1)));
+ buffer += Common::String(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2)) + Common::String(blanks, len1 - strlen(_vm->_text->getNoun(_vm->_object->_objects[i].nounIndex, 2)));
}
}
if (index & 1)
- strcat(buffer, "\n");
- strcat(buffer, _vm->_text->getTextParser(kTBOutro));
-
- Utils::Box(kBoxAny, "%s", buffer);
+ buffer += Common::String("\n");
+ buffer += Common::String(_vm->_text->getTextParser(kTBOutro));
+ Utils::Box(kBoxAny, "%s", buffer.c_str());
}
} // End of namespace Hugo
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index 6c04758531..a723871f02 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -162,10 +162,10 @@ void Scheduler::newScreen(int screenIndex) {
// Make sure the background file exists!
if (!_vm->isPacked()) {
- char line[32];
- if (!_vm->_file->fileExists(strcat(strncat(strcpy(line, _vm->_picDir), _vm->_text->getScreenNames(screenIndex), kFilenameLength), ".PCX")) &&
- !_vm->_file->fileExists(strcat(strcpy(line, _vm->_text->getScreenNames(screenIndex)), ".ART"))) {
- error("Unable to find background file for %s", _vm->_text->getScreenNames(screenIndex));
+ Common::String filename = Common::String(_vm->_text->getScreenNames(screenIndex));
+ if (!_vm->_file->fileExists(_vm->_picDir + filename + Common::String(".PCX")) &&
+ !_vm->_file->fileExists(filename + Common::String(".ART"))) {
+ error("Unable to find background file for %s", filename.c_str());
return;
}
}