aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorD G Turner2011-06-02 18:02:12 +0100
committerD G Turner2011-06-02 18:02:12 +0100
commit5015d12142ea80aec251e7fd4953019df964c0ff (patch)
treea712b437c259bc9d4571bfac3cbe123bddaca2c5 /engines
parent477d6233c3672d9a60cceea3570bc775df3d9253 (diff)
downloadscummvm-rg350-5015d12142ea80aec251e7fd4953019df964c0ff.tar.gz
scummvm-rg350-5015d12142ea80aec251e7fd4953019df964c0ff.tar.bz2
scummvm-rg350-5015d12142ea80aec251e7fd4953019df964c0ff.zip
TUCKER: Replace snprintf() usage with Common::String::format()
Safer and less portability issues.
Diffstat (limited to 'engines')
-rw-r--r--engines/tucker/detection.cpp3
-rw-r--r--engines/tucker/resource.cpp113
-rw-r--r--engines/tucker/saveload.cpp4
-rw-r--r--engines/tucker/sequences.cpp21
4 files changed, 65 insertions, 76 deletions
diff --git a/engines/tucker/detection.cpp b/engines/tucker/detection.cpp
index 9b466d682d..31d9caef73 100644
--- a/engines/tucker/detection.cpp
+++ b/engines/tucker/detection.cpp
@@ -201,8 +201,7 @@ public:
}
for (int slot = 0; slot <= Tucker::kLastSaveSlot; ++slot) {
if (slotsTable[slot]) {
- char description[64];
- snprintf(description, sizeof(description), "savegm.%02d", slot);
+ Common::String description = Common::String::format("savegm.%02d", slot);
saveList.push_back(SaveStateDescriptor(slot, description));
}
}
diff --git a/engines/tucker/resource.cpp b/engines/tucker/resource.cpp
index 467500b121..bee09f7391 100644
--- a/engines/tucker/resource.cpp
+++ b/engines/tucker/resource.cpp
@@ -160,39 +160,37 @@ public:
};
uint8 *TuckerEngine::loadFile(const char *fname, uint8 *p) {
- char filename[80];
- strcpy(filename, fname);
+ Common::String filename;
+ filename = fname;
if (_gameLang == Common::DE_DEU) {
- if (strcmp(filename, "bgtext.c") == 0) {
- strcpy(filename, "bgtextgr.c");
- } else if (strcmp(filename, "charname.c") == 0) {
- strcpy(filename, "charnmgr.c");
- } else if (strcmp(filename, "data5.c") == 0) {
- strcpy(filename, "data5gr.c");
- } else if (strcmp(filename, "infobar.txt") == 0) {
- strcpy(filename, "infobrgr.txt");
- } else if (strcmp(filename, "charsize.dta") == 0) {
- strcpy(filename, "charszgr.dta");
- } else if (strncmp(filename, "objtxt", 6) == 0) {
- const char num = filename[6];
- snprintf(filename, sizeof(filename), "objtx%cgr.c", num);
- } else if (strncmp(filename, "pt", 2) == 0) {
- const char num = filename[2];
- snprintf(filename, sizeof(filename), "pt%ctxtgr.c", num);
+ if (filename == "bgtext.c") {
+ filename = "bgtextgr.c";
+ } else if (filename == "charname.c") {
+ filename = "charnmgr.c";
+ } else if (filename == "data5.c") {
+ filename = "data5gr.c";
+ } else if (filename == "infobar.txt") {
+ filename = "infobrgr.txt";
+ } else if (filename == "charsize.dta") {
+ filename = "charszgr.dta";
+ } else if (filename.hasPrefix("objtxt")) {
+ filename = Common::String::format("objtx%cgr.c", filename[6]);
+ } else if (filename.hasPrefix("pt")) {
+ filename = Common::String::format("pt%ctxtgr.c", filename[2]);
}
}
_fileLoadSize = 0;
bool decode = false;
if (_gameFlags & kGameFlagEncodedData) {
- char *ext = strrchr(filename, '.');
- if (ext && strcmp(ext + 1, "c") == 0) {
- strcpy(ext + 1, "enc");
+ if (filename.hasSuffix(".c")) {
+ filename.deleteLastChar();
+ filename += "enc";
decode = true;
}
}
Common::File f;
if (!f.open(filename)) {
- warning("Unable to open '%s'", filename);
+ warning("Unable to open '%s'", filename.c_str());
return 0;
}
const int sz = f.size();
@@ -389,23 +387,23 @@ void TuckerEngine::loadBudSpr(int startOffset) {
int spriteOffset = 0;
for (int i = startOffset; i < endOffset; ++i) {
if (framesCount[frame] == i) {
- char filename[40];
+ Common::String filename;
switch (_flagsTable[137]) {
case 0:
if ((_gameFlags & kGameFlagDemo) != 0) {
- snprintf(filename, sizeof(filename), "budl00_%d.pcx", frame + 1);
+ filename = Common::String::format("budl00_%d.pcx", frame + 1);
} else {
- snprintf(filename, sizeof(filename), "bud_%d.pcx", frame + 1);
+ filename = Common::String::format("bud_%d.pcx", frame + 1);
}
break;
case 1:
- snprintf(filename, sizeof(filename), "peg_%d.pcx", frame + 1);
+ filename = Common::String::format("peg_%d.pcx", frame + 1);
break;
default:
- snprintf(filename, sizeof(filename), "mac_%d.pcx", frame + 1);
+ filename = Common::String::format("mac_%d.pcx", frame + 1);
break;
}
- loadImage(filename, _loadTempBuf, 0);
+ loadImage(filename.c_str(), _loadTempBuf, 0);
++frame;
}
int sz = Graphics::encodeRLE(_loadTempBuf + _spriteFramesTable[i].sourceOffset, _spritesGfxBuf + spriteOffset, _spriteFramesTable[i].xSize, _spriteFramesTable[i].ySize);
@@ -479,30 +477,30 @@ void TuckerEngine::loadCTable02(int fl) {
}
void TuckerEngine::loadLoc() {
- char filename[40];
+ Common::String filename;
int i = _locationWidthTable[_locationNum];
_locationHeight = (_locationNum < 73) ? 140 : 200;
- snprintf(filename, sizeof(filename), (i == 1) ? "loc%02d.pcx" : "loc%02da.pcx", _locationNum);
- copyLocBitmap(filename, 0, false);
+ filename = Common::String::format((i == 1) ? "loc%02d.pcx" : "loc%02da.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 0, false);
Graphics::copyRect(_quadBackgroundGfxBuf, 320, _locationBackgroundGfxBuf, 640, 320, _locationHeight);
if (_locationHeight == 200) {
return;
}
- snprintf(filename, sizeof(filename), (i != 2) ? "path%02d.pcx" : "path%02da.pcx", _locationNum);
- copyLocBitmap(filename, 0, true);
+ filename = Common::String::format((i != 2) ? "path%02d.pcx" : "path%02da.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 0, true);
if (i > 1) {
- snprintf(filename, sizeof(filename), "loc%02db.pcx", _locationNum);
- copyLocBitmap(filename, 320, false);
+ filename = Common::String::format("loc%02db.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 320, false);
Graphics::copyRect(_quadBackgroundGfxBuf + 44800, 320, _locationBackgroundGfxBuf + 320, 640, 320, _locationHeight);
if (i == 2) {
- snprintf(filename, sizeof(filename), "path%02db.pcx", _locationNum);
- copyLocBitmap(filename, 320, true);
+ filename = Common::String::format("path%02db.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 320, true);
}
}
if (i > 2) {
- snprintf(filename, sizeof(filename), "loc%02dc.pcx", _locationNum);
- copyLocBitmap(filename, 0, false);
+ filename = Common::String::format("loc%02dc.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 0, false);
Graphics::copyRect(_quadBackgroundGfxBuf + 89600, 320, _locationBackgroundGfxBuf, 640, 320, 140);
}
if (_locationNum == 1) {
@@ -510,8 +508,8 @@ void TuckerEngine::loadLoc() {
loadImage("rochpath.pcx", _loadLocBufPtr, 0);
}
if (i > 3) {
- snprintf(filename, sizeof(filename), "loc%02dd.pcx", _locationNum);
- copyLocBitmap(filename, 0, false);
+ filename = Common::String::format("loc%02dd.pcx", _locationNum);
+ copyLocBitmap(filename.c_str(), 0, false);
Graphics::copyRect(_quadBackgroundGfxBuf + 134400, 320, _locationBackgroundGfxBuf + 320, 640, 320, 140);
}
_fullRedraw = true;
@@ -540,13 +538,13 @@ void TuckerEngine::loadObj() {
}
_currentPartNum = _partNum;
- char filename[40];
- snprintf(filename, sizeof(filename), "objtxt%d.c", _partNum);
+ Common::String filename;
+ filename = Common::String::format("objtxt%d.c", _partNum);
free(_objTxtBuf);
- _objTxtBuf = loadFile(filename, 0);
- snprintf(filename, sizeof(filename), "pt%dtext.c", _partNum);
+ _objTxtBuf = loadFile(filename.c_str(), 0);
+ filename = Common::String::format("pt%dtext.c", _partNum);
free(_ptTextBuf);
- _ptTextBuf = loadFile(filename, 0);
+ _ptTextBuf = loadFile(filename.c_str(), 0);
_characterSpeechDataPtr = _ptTextBuf;
loadData();
loadPanObj();
@@ -584,9 +582,8 @@ void TuckerEngine::loadData() {
_dataCount = maxCount;
int offset = 0;
for (int i = 0; i < count; ++i) {
- char filename[40];
- snprintf(filename, sizeof(filename), "scrobj%d%d.pcx", _partNum, i);
- loadImage(filename, _loadTempBuf, 0);
+ Common::String filename = Common::String::format("scrobj%d%d.pcx", _partNum, i);
+ loadImage(filename.c_str(), _loadTempBuf, 0);
offset = loadDataHelper(offset, i);
}
}
@@ -603,9 +600,8 @@ int TuckerEngine::loadDataHelper(int offset, int index) {
}
void TuckerEngine::loadPanObj() {
- char filename[40];
- snprintf(filename, sizeof(filename), "panobjs%d.pcx", _partNum);
- loadImage(filename, _loadTempBuf, 0);
+ Common::String filename = Common::String::format("panobjs%d.pcx", _partNum);
+ loadImage(filename.c_str(), _loadTempBuf, 0);
int offset = 0;
for (int y = 0; y < 5; ++y) {
for (int x = 0; x < 10; ++x) {
@@ -812,9 +808,8 @@ void TuckerEngine::loadSprA02_01() {
unloadSprA02_01();
const int count = _sprA02LookupTable[_locationNum];
for (int i = 1; i < count + 1; ++i) {
- char filename[40];
- snprintf(filename, sizeof(filename), "sprites/a%02d_%02d.spr", _locationNum, i);
- _sprA02Table[i] = loadFile(filename, 0);
+ Common::String filename = Common::String::format("sprites/a%02d_%02d.spr", _locationNum, i);
+ _sprA02Table[i] = loadFile(filename.c_str(), 0);
}
_sprA02Table[0] = _sprA02Table[1];
}
@@ -831,9 +826,8 @@ void TuckerEngine::loadSprC02_01() {
unloadSprC02_01();
const int count = _sprC02LookupTable[_locationNum];
for (int i = 1; i < count + 1; ++i) {
- char filename[40];
- snprintf(filename, sizeof(filename), "sprites/c%02d_%02d.spr", _locationNum, i);
- _sprC02Table[i] = loadFile(filename, 0);
+ Common::String filename = Common::String::format("sprites/c%02d_%02d.spr", _locationNum, i);
+ _sprC02Table[i] = loadFile(filename.c_str(), 0);
}
_sprC02Table[0] = _sprC02Table[1];
_spritesCount = _sprC02LookupTable2[_locationNum];
@@ -942,8 +936,7 @@ void TuckerEngine::loadSound(Audio::Mixer::SoundType type, int num, int volume,
default:
return;
}
- char fileName[64];
- snprintf(fileName, sizeof(fileName), fmt, num);
+ Common::String fileName = Common::String::format(fmt, num);
Common::File *f = new Common::File;
if (f->open(fileName)) {
stream = Audio::makeWAVStream(f, DisposeAfterUse::YES);
diff --git a/engines/tucker/saveload.cpp b/engines/tucker/saveload.cpp
index 9a2e97986a..5bc51acf84 100644
--- a/engines/tucker/saveload.cpp
+++ b/engines/tucker/saveload.cpp
@@ -36,9 +36,7 @@ Common::String generateGameStateFileName(const char *target, int slot, bool pref
if (prefixOnly) {
name += ".*";
} else {
- char slotStr[16];
- snprintf(slotStr, sizeof(slotStr), ".%d", slot);
- name += slotStr;
+ name += Common::String::format(".%d", slot);
}
return name;
}
diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp
index 23ae3380cd..775fd6f1a0 100644
--- a/engines/tucker/sequences.cpp
+++ b/engines/tucker/sequences.cpp
@@ -115,31 +115,31 @@ void TuckerEngine::handleCreditsSequence() {
_fadePaletteCounter = 0;
clearSprites();
++num;
- char filename[40];
+ Common::String filename;
if (num == 6) {
for (int i = 0; i < 16; ++i) {
- snprintf(filename, sizeof(filename), "cogs%04d.pcx", i + 1);
- loadImage(filename, imgBuf + i * 64000, 2);
+ filename = Common::String::format("cogs%04d.pcx", i + 1);
+ loadImage(filename.c_str(), imgBuf + i * 64000, 2);
}
} else {
switch (num) {
case 1:
- strcpy(filename, "loc75.pcx");
+ filename = "loc75.pcx";
break;
case 2:
- strcpy(filename, "loc76.pcx");
+ filename = "loc76.pcx";
break;
case 3:
- strcpy(filename, "paper-3.pcx");
+ filename = "paper-3.pcx";
break;
case 4:
- strcpy(filename, "loc77.pcx");
+ filename = "loc77.pcx";
break;
case 5:
- strcpy(filename, "loc78.pcx");
+ filename = "loc78.pcx";
break;
}
- loadImage(filename, _quadBackgroundGfxBuf, 2);
+ loadImage(filename.c_str(), _quadBackgroundGfxBuf, 2);
}
_spritesCount = _creditsSequenceSpriteCounts[num];
++_flagsTable[236];
@@ -584,8 +584,7 @@ Audio::RewindableAudioStream *AnimationSequencePlayer::loadSound(int index, Anim
if (stream)
return stream;
- char fileName[64];
- snprintf(fileName, sizeof(fileName), "audio/%s", _audioFileNamesTable[index]);
+ Common::String fileName = Common::String::format("audio/%s", _audioFileNamesTable[index]);
Common::File f;
if (f.open(fileName)) {
int size = 0, rate = 0;