[Scummvm-cvs-logs] scummvm master -> 80d0bc0c85c45f76633a55cf56f504eaae83b2d0

lordhoto lordhoto at gmail.com
Thu Jun 9 19:13:14 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
80d0bc0c85 KYRA: Get rid of most snprintf usages.


Commit: 80d0bc0c85c45f76633a55cf56f504eaae83b2d0
    https://github.com/scummvm/scummvm/commit/80d0bc0c85c45f76633a55cf56f504eaae83b2d0
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-06-09T10:10:54-07:00

Commit Message:
KYRA: Get rid of most snprintf usages.

Thanks to digitall for his initial patch, which I only altered slightly.

Changed paths:
    engines/kyra/animator_mr.cpp
    engines/kyra/gui_lol.cpp
    engines/kyra/gui_mr.cpp
    engines/kyra/kyra_mr.cpp
    engines/kyra/kyra_mr.h
    engines/kyra/lol.cpp
    engines/kyra/scene_lol.cpp
    engines/kyra/script_lol.cpp
    engines/kyra/script_tim.cpp
    engines/kyra/sequences_lol.cpp
    engines/kyra/sound_lok.cpp
    engines/kyra/sound_lol.cpp
    engines/kyra/text_hof.cpp
    engines/kyra/text_mr.cpp



diff --git a/engines/kyra/animator_mr.cpp b/engines/kyra/animator_mr.cpp
index 6db2e45..84bda3f 100644
--- a/engines/kyra/animator_mr.cpp
+++ b/engines/kyra/animator_mr.cpp
@@ -449,11 +449,10 @@ void KyraEngine_MR::showIdleAnim() {
 			"A", "R", "R", "FR", "FX", "FL", "L", "L"
 		};
 
-		char filename[14];
-		snprintf(filename, 14, "MI0%s%.02d.EMC", facingTable[_mainCharacter.facing], _characterShapeFile);
+		Common::String filename = Common::String::format( "MI0%s%.02d.EMC", facingTable[_mainCharacter.facing], _characterShapeFile);
 
-		if (_res->exists(filename))
-			runAnimationScript(filename, 1, 1, 1, 1);
+		if (_res->exists(filename.c_str()))
+			runAnimationScript(filename.c_str(), 1, 1, 1, 1);
 	}
 
 	_nextIdleType = !_nextIdleType;
diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp
index 4c4dc50..80eacb3 100644
--- a/engines/kyra/gui_lol.cpp
+++ b/engines/kyra/gui_lol.cpp
@@ -2806,16 +2806,16 @@ int GUI_LoL::clickedOptionsMenu(Button *button) {
 	case 0xfff3:
 		_vm->_configVoice ^= 3;
 		break;
-	case 0x4072:
-		char filename[13];
-		snprintf(filename, sizeof(filename), "LEVEL%02d.%s", _vm->_currentLevel, _vm->_languageExt[_vm->_lang]);
+	case 0x4072: {
+		Common::String filename;
+		filename = Common::String::format("LEVEL%02d.%s", _vm->_currentLevel, _vm->_languageExt[_vm->_lang]);
 		delete[] _vm->_levelLangFile;
-		_vm->_levelLangFile = _vm->resource()->fileData(filename, 0);
-		snprintf(filename, sizeof(filename), "LANDS.%s", _vm->_languageExt[_vm->_lang]);
+		_vm->_levelLangFile = _vm->resource()->fileData(filename.c_str(), 0);
+		filename = Common::String::format("LANDS.%s", _vm->_languageExt[_vm->_lang]);
 		delete[] _vm->_landsFile;
-		_vm->_landsFile = _vm->resource()->fileData(filename, 0);
+		_vm->_landsFile = _vm->resource()->fileData(filename.c_str(), 0);
 		_newMenu = _lastMenu;
-		break;
+		} break;
 	}
 
 	return 1;
diff --git a/engines/kyra/gui_mr.cpp b/engines/kyra/gui_mr.cpp
index 25a77c6..32eb02e 100644
--- a/engines/kyra/gui_mr.cpp
+++ b/engines/kyra/gui_mr.cpp
@@ -717,25 +717,25 @@ void KyraEngine_MR::showAlbum() {
 }
 
 void KyraEngine_MR::loadAlbumPage() {
-	char filename[16];
+	Common::String filename;
 	int num = _album.curPage / 2;
 
 	if (num == 0) {
-		strcpy(filename, "ALBUM0.CPS");
+		filename = "ALBUM0.CPS";
 	} else if (num >= 1 && num <= 6) {
 		--num;
 		num %= 2;
-		snprintf(filename, 16, "ALBUM%d.CPS", num+1);
+		filename = Common::String::format("ALBUM%d.CPS", num+1);
 	} else {
-		strcpy(filename, "ALBUM3.CPS");
+		filename = "ALBUM3.CPS";
 	}
 
 	_screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 4, Screen::CR_NO_P_CHECK);
-	_screen->loadBitmap(filename, 3, 3, 0);
+	_screen->loadBitmap(filename.c_str(), 3, 3, 0);
 }
 
 void KyraEngine_MR::loadAlbumPageWSA() {
-	char filename[16];
+	Common::String filename;
 
 	_album.leftPage.curFrame = 0;
 	_album.leftPage.maxFrame = 0;
@@ -746,14 +746,14 @@ void KyraEngine_MR::loadAlbumPageWSA() {
 	_album.rightPage.wsa->close();
 
 	if (_album.curPage) {
-		snprintf(filename, 16, "PAGE%x.WSA", _album.curPage);
-		_album.leftPage.wsa->open(filename, 1, 0);
+		filename = Common::String::format("PAGE%x.WSA", _album.curPage);
+		_album.leftPage.wsa->open(filename.c_str(), 1, 0);
 		_album.leftPage.maxFrame = _album.leftPage.wsa->frames()-1;
 	}
 
 	if (_album.curPage != 14) {
-		snprintf(filename, 16, "PAGE%x.WSA", _album.curPage+1);
-		_album.rightPage.wsa->open(filename, 1, 0);
+		filename = Common::String::format("PAGE%x.WSA", _album.curPage+1);
+		_album.rightPage.wsa->open(filename.c_str(), 1, 0);
 		_album.rightPage.maxFrame = _album.leftPage.wsa->frames()-1;
 	}
 }
diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp
index 4ce5c5b..973ab25 100644
--- a/engines/kyra/kyra_mr.cpp
+++ b/engines/kyra/kyra_mr.cpp
@@ -366,10 +366,9 @@ void KyraEngine_MR::uninitMainMenu() {
 void KyraEngine_MR::playVQA(const char *name) {
 	VQAMovie vqa(this, _system);
 
-	char filename[20];
-	snprintf(filename, sizeof(filename), "%s%d.VQA", name, _configVQAQuality);
+	Common::String filename = Common::String::format("%s%d.VQA", name, _configVQAQuality);
 
-	if (vqa.open(filename)) {
+	if (vqa.open(filename.c_str())) {
 		for (int i = 0; i < 4; ++i) {
 			if (i != _musicSoundChannel)
 				_soundDigital->stopSound(i);
@@ -444,12 +443,11 @@ void KyraEngine_MR::fadeOutMusic(int ticks) {
 
 void KyraEngine_MR::snd_playSoundEffect(int item, int volume) {
 	if (_sfxFileMap[item*2+0] != 0xFF) {
-		char filename[16];
 		assert(_sfxFileMap[item*2+0] < _sfxFileListSize);
-		snprintf(filename, 16, "%s", _sfxFileList[_sfxFileMap[item*2+0]]);
+		Common::String filename = Common::String::format("%s", _sfxFileList[_sfxFileMap[item*2+0]]);
 		uint8 priority = _sfxFileMap[item*2+1];
 
-		_soundDigital->playSound(filename, priority, Audio::Mixer::kSFXSoundType, volume);
+		_soundDigital->playSound(filename.c_str(), priority, Audio::Mixer::kSFXSoundType, volume);
 	}
 }
 
@@ -458,11 +456,10 @@ void KyraEngine_MR::playVoice(int high, int low) {
 }
 
 void KyraEngine_MR::snd_playVoiceFile(int file) {
-	char filename[16];
-	snprintf(filename, 16, "%.08u", (uint)file);
+	Common::String filename = Common::String::format("%.08u", (uint)file);
 
 	if (speechEnabled())
-		_voiceSoundChannel = _soundDigital->playSound(filename, 0xFE, Audio::Mixer::kSpeechSoundType, 255);
+		_voiceSoundChannel = _soundDigital->playSound(filename.c_str(), 0xFE, Audio::Mixer::kSpeechSoundType, 255);
 }
 
 bool KyraEngine_MR::snd_voiceIsPlaying() {
@@ -1242,26 +1239,14 @@ void KyraEngine_MR::restoreGfxRect32x32(int x, int y) {
 
 #pragma mark -
 
-char *KyraEngine_MR::appendLanguage(char *buf, int lang, int bufSize) {
-	assert(lang < _languageExtensionSize);
-
-	const int size = Common::strlcat(buf, _languageExtension[lang], bufSize);
-	if (size >= bufSize) {
-		warning("buffer too small to append language extension");
-		return 0;
-	}
-
-	return buf;
-}
-
 int KyraEngine_MR::loadLanguageFile(const char *file, uint8 *&buffer) {
 	delete[] buffer;
 	buffer = 0;
 
 	uint32 size = 0;
-	char nBuf[32];
-	Common::strlcpy(nBuf, file, sizeof(nBuf));
-	buffer = _res->fileData(appendLanguage(nBuf, _lang, sizeof(nBuf)), &size);
+	Common::String nBuf = file;
+	nBuf += _languageExtension[_lang];
+	buffer = _res->fileData(nBuf.c_str(), &size);
 
 	return buffer ? size : 0;
 }
diff --git a/engines/kyra/kyra_mr.h b/engines/kyra/kyra_mr.h
index 0d9d66c..b762648 100644
--- a/engines/kyra/kyra_mr.h
+++ b/engines/kyra/kyra_mr.h
@@ -662,8 +662,6 @@ private:
 	static const char *_languageExtension[];
 	static const int _languageExtensionSize;
 
-	char *appendLanguage(char *buf, int lang, int bufSize);
-
 	int loadLanguageFile(const char *file, uint8 *&buffer);
 };
 
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp
index 3a8a332..0d4eb00 100644
--- a/engines/kyra/lol.cpp
+++ b/engines/kyra/lol.cpp
@@ -611,11 +611,11 @@ void LoLEngine::preInit() {
 
 	loadTalkFile(0);
 
-	char filename[32];
-	snprintf(filename, sizeof(filename), "LANDS.%s", _languageExt[_lang]);
-	_res->exists(filename, true);
+	Common::String filename;
+	filename = Common::String::format("LANDS.%s", _languageExt[_lang]);
+	_res->exists(filename.c_str(), true);
 	delete[] _landsFile;
-	_landsFile = _res->fileData(filename, 0);
+	_landsFile = _res->fileData(filename.c_str(), 0);
 	loadItemIconShapes();
 }
 
@@ -1161,9 +1161,8 @@ void LoLEngine::loadCharFaceShapes(int charNum, int id) {
 	if (id < 0)
 		id = -id;
 
-	char file[13];
-	snprintf(file, sizeof(file), "FACE%02d.SHP", id);
-	_screen->loadBitmap(file, 3, 3, 0);
+	Common::String file = Common::String::format("FACE%02d.SHP", id);
+	_screen->loadBitmap(file.c_str(), 3, 3, 0);
 
 	const uint8 *p = _screen->getCPagePtr(3);
 	for (int i = 0; i < 40; i++) {
@@ -1819,21 +1818,16 @@ void LoLEngine::updateSequenceBackgroundAnimations() {
 }
 
 void LoLEngine::loadTalkFile(int index) {
-	char file[8];
-
 	if (index == _curTlkFile)
 		return;
 
-	if (_curTlkFile > 0 && index > 0) {
-		snprintf(file, sizeof(file), "%02d.TLK", _curTlkFile);
-		_res->unloadPakFile(file);
-	}
+	if (_curTlkFile > 0 && index > 0)
+		_res->unloadPakFile(Common::String::format("%02d.TLK", _curTlkFile));
 
 	if (index > 0)
 		_curTlkFile = index;
 
-	snprintf(file, sizeof(file), "%02d.TLK", index);
-	_res->loadPakFile(file);
+	_res->loadPakFile(Common::String::format("%02d.TLK", index));
 }
 
 int LoLEngine::characterSays(int track, int charId, bool redraw) {
@@ -2702,12 +2696,11 @@ int LoLEngine::processMagicMistOfDoom(int charNum, int spellLevel) {
 
 	snd_playSoundEffect(155, -1);
 
-	char wsafile[13];
-	snprintf(wsafile, 13, "mists%0d.wsa", spellLevel + 1);
+	Common::String wsafile = Common::String::format("mists%0d.wsa", spellLevel + 1);
 	WSAMovie_v2 *mov = new WSAMovie_v2(this);
-	mov->open(wsafile, 1, 0);
+	mov->open(wsafile.c_str(), 1, 0);
 	if (!mov->opened())
-		error("Mist: Unable to load mists.wsa");
+		error("Mist: Unable to load %s", wsafile.c_str());
 
 	snd_playSoundEffect(_mistAnimData[spellLevel].sound, -1);
 	playSpellAnimation(mov, _mistAnimData[spellLevel].part1First, _mistAnimData[spellLevel].part1Last, 7, 112, 0, 0, 0, 0, 0, false);
@@ -2734,12 +2727,11 @@ int LoLEngine::processMagicLightning(int charNum, int spellLevel) {
 	_lightningDiv = _lightningProps[spellLevel].frameDiv;
 	_lightningFirstSfx = 0;
 
-	char wsafile[13];
-	snprintf(wsafile, 13, "litning%d.wsa", spellLevel + 1);
+	Common::String wsafile = Common::String::format("litning%d.wsa", spellLevel + 1);
 	WSAMovie_v2 *mov = new WSAMovie_v2(this);
-	mov->open(wsafile, 1, 0);
+	mov->open(wsafile.c_str(), 1, 0);
 	if (!mov->opened())
-		error("Litning: Unable to load litning.wsa");
+		error("Litning: Unable to load %s", wsafile.c_str());
 
 	for (int i = 0; i < 4; i++)
 		playSpellAnimation(mov, 0, _lightningProps[spellLevel].lastFrame, 3, 93, 0, &LoLEngine::callbackProcessMagicLightning, 0, 0, 0, false);
@@ -3139,11 +3131,10 @@ void LoLEngine::transferSpellToScollAnimation(int charNum, int spell, int slot)
 	int vX = _updateSpellBookCoords[slot << 1] + 32;
 	int vY = _updateSpellBookCoords[(slot << 1) + 1] + 5;
 
-	char wsaFile[13];
+	Common::String wsaFile = Common::String::format("write%0d", spell);
 	if (_flags.isTalkie)
-		snprintf(wsaFile, 13, "write%0d%c.wsa", spell, (_lang == 1) ? 'f' : (_lang == 0 ? 'e' : 'g'));
-	else
-		snprintf(wsaFile, 13, "write%0d.wsa", spell);
+		wsaFile += (_lang == 1) ? 'f' : (_lang == 0 ? 'e' : 'g');
+	wsaFile += ".wsa";
 	snd_playSoundEffect(_updateSpellBookAnimData[(spell << 2) + 3], -1);
 	snd_playSoundEffect(95, -1);
 
@@ -3187,7 +3178,7 @@ void LoLEngine::transferSpellToScollAnimation(int charNum, int spell, int slot)
 	playSpellAnimation(mov, 0, 6, 5, _updateSpellBookCoords[slot << 1], _updateSpellBookCoords[(slot << 1) + 1], 0, 0, 0, 0, false);
 	mov->close();
 
-	mov->open(wsaFile, 0, 0);
+	mov->open(wsaFile.c_str(), 0, 0);
 	if (!mov->opened())
 		error("SpellBook: Unable to load spellbook anim");
 	snd_playSoundEffect(_updateSpellBookAnimData[(spell << 2) + 3], -1);
@@ -4160,10 +4151,9 @@ void LoLEngine::loadMapLegendData(int level) {
 		legendData[i * 6 + 5] = 0xffff;
 	}
 
-	char file[13];
+	Common::String file = Common::String::format("level%d.xxx", level);
 	uint32 size = 0;
-	snprintf(file, 12, "level%d.xxx", level);
-	uint8 *data = _res->fileData(file, &size);
+	uint8 *data = _res->fileData(file.c_str(), &size);
 	uint8 *pos = data;
 	size = MIN<uint32>(size / 12, 32);
 
@@ -4531,10 +4521,9 @@ void LoLEngine::generateTempData() {
 	_lvlTempData[l]->monsters = new MonsterInPlay[30];
 	_lvlTempData[l]->flyingObjects = new FlyingObject[8];
 
-	char filename[13];
-	snprintf(filename, sizeof(filename), "LEVEL%d.CMZ", _currentLevel);
+	Common::String filename = Common::String::format("LEVEL%d.CMZ", _currentLevel);
 
-	_screen->loadBitmap(filename, 15, 15, 0);
+	_screen->loadBitmap(filename.c_str(), 15, 15, 0);
 	const uint8 *p = _screen->getCPagePtr(14);
 	uint16 len = READ_LE_UINT16(p + 4);
 	p += 6;
diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp
index 305036f..165919d 100644
--- a/engines/kyra/scene_lol.cpp
+++ b/engines/kyra/scene_lol.cpp
@@ -67,18 +67,17 @@ void LoLEngine::loadLevel(int index) {
 	loadLevelWallData(index, true);
 	_loadLevelFlag = 1;
 
-	char filename[13];
-	snprintf(filename, sizeof(filename), "LEVEL%d.INI", index);
+	Common::String filename = Common::String::format("LEVEL%d.INI", index);
 
 	int f = _hasTempDataFlags & (1 << (index - 1));
 
-	runInitScript(filename, f ? 0 : 1);
+	runInitScript(filename.c_str(), f ? 0 : 1);
 
 	if (f)
 		restoreBlockTempData(index);
 
-	snprintf(filename, sizeof(filename), "LEVEL%d.INF", index);
-	runInfScript(filename);
+	filename = Common::String::format("LEVEL%d.INF", index);
+	runInfScript(filename.c_str());
 
 	addLevelItems();
 	deleteMonstersFromBlock(_currentBlock);
@@ -142,11 +141,10 @@ void LoLEngine::assignBlockObject(LevelBlockProperty *l, uint16 item) {
 }
 
 void LoLEngine::loadLevelWallData(int index, bool mapShapes) {
-	char filename[13];
-	snprintf(filename, sizeof(filename), "LEVEL%d.WLL", index);
+	Common::String filename = Common::String::format("LEVEL%d.WLL", index);
 
 	uint32 size;
-	uint8 *file = _res->fileData(filename, &size);
+	uint8 *file = _res->fileData(filename.c_str(), &size);
 
 	uint16 c = READ_LE_UINT16(file);
 	loadLevelShpDat(_levelShpList[c], _levelDatList[c], false);
@@ -241,10 +239,9 @@ void LoLEngine::restoreBlockTempData(int index) {
 	memcpy(_monsters, _lvlTempData[l]->monsters, sizeof(MonsterInPlay) * 30);
 	memcpy(_flyingObjects, _lvlTempData[l]->flyingObjects, sizeof(FlyingObject) * 8);
 
-	char filename[13];
-	snprintf(filename, sizeof(filename), "LEVEL%d.CMZ", index);
+	Common::String filename = Common::String::format("LEVEL%d.CMZ", index);
 
-	_screen->loadBitmap(filename, 3, 3, 0);
+	_screen->loadBitmap(filename.c_str(), 3, 3, 0);
 	const uint8 *p = _screen->getCPagePtr(2);
 	uint16 len = READ_LE_UINT16(p + 4);
 	p += 6;
@@ -366,13 +363,13 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
 			_lastSpecialColor = 0x44;
 	}
 
-	char fname[13];
+	Common::String fname;
 	const uint8 *v = 0;
 	int tlen = 0;
 
 	if (_flags.use16ColorMode) {
-		snprintf(fname, sizeof(fname), "%s.VCF", _lastBlockDataFile);
-		_screen->loadBitmap(fname, 3, 3, 0);
+		fname = Common::String::format("%s.VCF", _lastBlockDataFile);
+		_screen->loadBitmap(fname.c_str(), 3, 3, 0);
 		v = _screen->getCPagePtr(2);
 		tlen = READ_LE_UINT16(v) << 5;
 		v += 2;
@@ -383,8 +380,8 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
 		memcpy(_vcfBlocks, v, tlen);
 	}
 
-	snprintf(fname, sizeof(fname), "%s.VCN", _lastBlockDataFile);
-	_screen->loadBitmap(fname, 3, 3, 0);
+	fname = Common::String::format("%s.VCN", _lastBlockDataFile);
+	_screen->loadBitmap(fname.c_str(), 3, 3, 0);
 	v = _screen->getCPagePtr(2);
 	tlen = READ_LE_UINT16(v);
 	v += 2;
@@ -434,8 +431,8 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
 	memcpy(_vcnBlocks, v, vcnLen);
 	v += vcnLen;
 
-	snprintf(fname, sizeof(fname), "%s.VMP", _lastBlockDataFile);
-	_screen->loadBitmap(fname, 3, 3, 0);
+	fname = Common::String::format("%s.VMP", _lastBlockDataFile);
+	_screen->loadBitmap(fname.c_str(), 3, 3, 0);
 	v = _screen->getCPagePtr(2);
 
 	if (vmpLen == -1)
@@ -503,9 +500,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight
 	generateBrightnessPalette(_screen->getPalette(0), _screen->getPalette(1), _brightness, _lampEffect);
 
 	if (_flags.isTalkie) {
-		char tname[13];
-		snprintf(tname, sizeof(tname), "LEVEL%.02d.TLC", _currentLevel);
-		Common::SeekableReadStream *s = _res->createReadStream(tname);
+		Common::SeekableReadStream *s = _res->createReadStream(Common::String::format("LEVEL%.02d.TLC", _currentLevel));
 		s->read(_transparencyTable1, 256);
 		s->read(_transparencyTable2, 5120);
 		delete s;
@@ -1375,9 +1370,8 @@ void LoLEngine::processGasExplosion(int soundId) {
 
 	if (dist) {
 		WSAMovie_v2 *mov = new WSAMovie_v2(this);
-		char file[13];
-		snprintf(file, 13, "gasexp%0d.wsa", dist);
-		mov->open(file, 1, 0);
+		Common::String file = Common::String::format("gasexp%0d.wsa", dist);
+		mov->open(file.c_str(), 1, 0);
 		if (!mov->opened())
 			error("Gas: Unable to load gasexp.wsa");
 
diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp
index a875e67..695528b 100644
--- a/engines/kyra/script_lol.cpp
+++ b/engines/kyra/script_lol.cpp
@@ -1136,9 +1136,8 @@ int LoLEngine::olol_loadTimScript(EMCState *script) {
 	debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_loadTimScript(%p) (%d, %s)", (const void *)script, stackPos(0), stackPosString(1));
 	if (_activeTim[stackPos(0)])
 		return 1;
-	char file[13];
-	snprintf(file, sizeof(file), "%s.TIM", stackPosString(1));
-	_activeTim[stackPos(0)] = _tim->load(file, &_timIngameOpcodes);
+	Common::String file = Common::String::format("%s.TIM", stackPosString(1));
+	_activeTim[stackPos(0)] = _tim->load(file.c_str(), &_timIngameOpcodes);
 	return 1;
 }
 
@@ -1185,10 +1184,9 @@ int LoLEngine::olol_giveItemToMonster(EMCState *script) {
 
 int LoLEngine::olol_loadLangFile(EMCState *script) {
 	debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_loadLangFile(%p) (%s)", (const void *)script, stackPosString(0));
-	char filename[13];
-	snprintf(filename, sizeof(filename), "%s.%s", stackPosString(0), _languageExt[_lang]);
+	Common::String filename = Common::String::format("%s.%s", stackPosString(0), _languageExt[_lang]);
 	delete[] _levelLangFile;
-	_levelLangFile = _res->fileData(filename, 0);
+	_levelLangFile = _res->fileData(filename.c_str(), 0);
 	return 1;
 }
 
diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp
index 501ae2d..6f0f0ab 100644
--- a/engines/kyra/script_tim.cpp
+++ b/engines/kyra/script_tim.cpp
@@ -482,17 +482,16 @@ int TIMInterpreter::initAnimStruct(int index, const char *filename, int x, int y
 			wsaOpenFlags = 1;
 	}
 
-	char file[32];
-	snprintf(file, 32, "%s.WSA", filename);
+	Common::String file = Common::String::format("%s.WSA", filename);
 
-	if (_vm->resource()->exists(file)) {
+	if (_vm->resource()->exists(file.c_str())) {
 		if (isLoLDemo)
 			wsa = new WSAMovie_v1(_vm);
 		else
 			wsa = new WSAMovie_v2(_vm);
 		assert(wsa);
 
-		wsa->open(file, wsaOpenFlags, (index == 1) ? &_screen->getPalette(0) : 0);
+		wsa->open(file.c_str(), wsaOpenFlags, (index == 1) ? &_screen->getPalette(0) : 0);
 	}
 
 	if (wsa && wsa->opened()) {
@@ -526,10 +525,10 @@ int TIMInterpreter::initAnimStruct(int index, const char *filename, int x, int y
 		}
 
 		if (wsaFlags & 4) {
-			snprintf(file, 32, "%s.CPS", filename);
+			file = Common::String::format("%s.CPS", filename);
 
-			if (_vm->resource()->exists(file)) {
-				_screen->loadBitmap(file, 3, 3, &_screen->getPalette(0));
+			if (_vm->resource()->exists(file.c_str())) {
+				_screen->loadBitmap(file.c_str(), 3, 3, &_screen->getPalette(0));
 				_screen->copyRegion(0, 0, 0, 0, 320, 200, 2, _drawPage2, Screen::CR_NO_P_CHECK);
 				if (_drawPage2)
 					_screen->checkedPageUpdate(8, 4);
@@ -550,10 +549,10 @@ int TIMInterpreter::initAnimStruct(int index, const char *filename, int x, int y
 			_screen->updateScreen();
 		}
 
-		snprintf(file, 32, "%s.CPS", filename);
+		file = Common::String::format("%s.CPS", filename);
 
-		if (_vm->resource()->exists(file)) {
-			_screen->loadBitmap(file, 3, 3, &_screen->getPalette(0));
+		if (_vm->resource()->exists(file.c_str())) {
+			_screen->loadBitmap(file.c_str(), 3, 3, &_screen->getPalette(0));
 			_screen->copyRegion(0, 0, 0, 0, 320, 200, 2, _drawPage2, Screen::CR_NO_P_CHECK);
 			if (_drawPage2)
 				_screen->checkedPageUpdate(8, 4);
@@ -922,13 +921,12 @@ int TIMInterpreter_LoL::initAnimStruct(int index, const char *filename, int x, i
 	if (wsaFlags & 8)
 		wsaOpenFlags |= 1;
 
-	char file[32];
-	snprintf(file, 32, "%s.WSA", filename);
+	Common::String file = Common::String::format("%s.WSA", filename);
 
-	if (_vm->resource()->exists(file)) {
+	if (_vm->resource()->exists(file.c_str())) {
 		wsa = new WSAMovie_v2(_vm);
 		assert(wsa);
-		wsa->open(file, wsaOpenFlags, &_screen->getPalette(3));
+		wsa->open(file.c_str(), wsaOpenFlags, &_screen->getPalette(3));
 	}
 
 	if (!_vm->_flags.use16ColorMode) {
diff --git a/engines/kyra/sequences_lol.cpp b/engines/kyra/sequences_lol.cpp
index 9a47016..01bf3c5 100644
--- a/engines/kyra/sequences_lol.cpp
+++ b/engines/kyra/sequences_lol.cpp
@@ -306,9 +306,8 @@ int LoLEngine::chooseCharacter() {
 
 			Screen::FontId old = _screen->setFont(Screen::FID_SJIS_FNT);
 			for (int j = 0; j < 3; ++j) {
-				char buffer[3];
-				snprintf(buffer, sizeof(buffer), "%2d", _charPreviews[i].attrib[j]);
-				_screen->printText(buffer, _charPosXPC98[i] + 16, 176 + j * 8, 0x81, 0x00);
+				Common::String attribString = Common::String::format("%2d", _charPreviews[i].attrib[j]);
+				_screen->printText(attribString.c_str(), _charPosXPC98[i] + 16, 176 + j * 8, 0x81, 0x00);
 			}
 			_screen->setFont(old);
 		}
diff --git a/engines/kyra/sound_lok.cpp b/engines/kyra/sound_lok.cpp
index 95a632c..b2a9c2f 100644
--- a/engines/kyra/sound_lok.cpp
+++ b/engines/kyra/sound_lok.cpp
@@ -74,9 +74,8 @@ void KyraEngine_LoK::snd_playWanderScoreViaMap(int command, int restart) {
 }
 
 void KyraEngine_LoK::snd_playVoiceFile(int id) {
-	char vocFile[9];
-	snprintf(vocFile, sizeof(vocFile), "%03d", id);
-	_speechPlayTime = _sound->voicePlay(vocFile, &_speechHandle);
+	Common::String vocFile = Common::String::format("%03d", id);
+	_speechPlayTime = _sound->voicePlay(vocFile.c_str(), &_speechHandle);
 }
 
 void KyraEngine_LoK::snd_voiceWaitForFinish(bool ingame) {
diff --git a/engines/kyra/sound_lol.cpp b/engines/kyra/sound_lol.cpp
index a7776f0..7262635 100644
--- a/engines/kyra/sound_lol.cpp
+++ b/engines/kyra/sound_lol.cpp
@@ -50,36 +50,34 @@ bool LoLEngine::snd_playCharacterSpeech(int id, int8 speaker, int) {
 	_lastSpeaker = speaker;
 	_nextSpeechId = _nextSpeaker = -1;
 
-	char pattern1[8];
-	char pattern2[5];
-	char file1[13];
-	char file2[13];
-	char file3[13];
-	file3[0] = 0;
+	Common::String pattern1;
+	Common::String file1;
+	Common::String file2;
+	Common::String file3;
 
 	SpeechList newSpeechList;
 
-	snprintf(pattern2, sizeof(pattern2), "%02d", id & 0x4000 ? 0 : _curTlkFile);
+	Common::String pattern2 = Common::String::format("%02d", id & 0x4000 ? 0 : _curTlkFile);
 
 	if (id & 0x4000) {
-		snprintf(pattern1, sizeof(pattern1), "%03X", id & 0x3fff);
+		pattern1 = Common::String::format("%03X", id & 0x3fff);
 	} else if (id < 1000) {
-		snprintf(pattern1, sizeof(pattern1), "%03d", id);
+		pattern1 = Common::String::format("%03d", id);
 	} else {
-		snprintf(file3, sizeof(file3), "@%04d%c.%s", id - 1000, (char)speaker, pattern2);
-		if (_sound->isVoicePresent(file3))
-			newSpeechList.push_back(_sound->getVoiceStream(file3));
+		file3 = Common::String::format("@%04d%c.%s", id - 1000, (char)speaker, pattern2.c_str());
+		if (_sound->isVoicePresent(file3.c_str()))
+			newSpeechList.push_back(_sound->getVoiceStream(file3.c_str()));
 	}
 
-	if (!file3[0]) {
+	if (file3.empty()) {
 		for (char i = 0; ; i++) {
 			char symbol = '0' + i;
-			snprintf(file1, sizeof(file1), "%s%c%c.%s", pattern1, (char)speaker, symbol, pattern2);
-			snprintf(file2, sizeof(file2), "%s%c%c.%s", pattern1, '_', symbol, pattern2);
-			if (_sound->isVoicePresent(file1))
-				newSpeechList.push_back(_sound->getVoiceStream(file1));
-			else if (_sound->isVoicePresent(file2))
-				newSpeechList.push_back(_sound->getVoiceStream(file2));
+			file1 = Common::String::format("%s%c%c.%s", pattern1.c_str(), (char)speaker, symbol, pattern2.c_str());
+			file2 = Common::String::format("%s%c%c.%s", pattern1.c_str(), '_', symbol, pattern2.c_str());
+			if (_sound->isVoicePresent(file1.c_str()))
+				newSpeechList.push_back(_sound->getVoiceStream(file1.c_str()));
+			else if (_sound->isVoicePresent(file2.c_str()))
+				newSpeechList.push_back(_sound->getVoiceStream(file2.c_str()));
 			else
 				break;
 		}
@@ -260,9 +258,7 @@ void LoLEngine::snd_loadSoundFile(int track) {
 			int t = (track - 250) * 3;
 			if (_curMusicFileIndex != _musicTrackMap[t] || _curMusicFileExt != (char)_musicTrackMap[t + 1]) {
 				snd_stopMusic();
-				char filename[13];
-				snprintf(filename, sizeof(filename), "LORE%02d%c", _musicTrackMap[t], (char)_musicTrackMap[t + 1]);
-				_sound->loadSoundFile(filename);
+				_sound->loadSoundFile(Common::String::format("LORE%02d%c", _musicTrackMap[t], (char)_musicTrackMap[t + 1]));
 				_curMusicFileIndex = _musicTrackMap[t];
 				_curMusicFileExt = (char)_musicTrackMap[t + 1];
 			} else {
diff --git a/engines/kyra/text_hof.cpp b/engines/kyra/text_hof.cpp
index 393fa8d..4406f3e 100644
--- a/engines/kyra/text_hof.cpp
+++ b/engines/kyra/text_hof.cpp
@@ -436,15 +436,16 @@ void KyraEngine_HoF::updateDlgBuffer() {
 	_npcTalkChpIndex = _currentChapter;
 	_npcTalkDlgIndex = _mainCharacter.dlgIndex;
 
-	char filename[13];
-	snprintf(filename, 13, "CH%.02d-S%.02d.DLG", _currentChapter, _npcTalkDlgIndex);
+	Common::String filename = Common::String::format("CH%.02d-S%.02d.DL", _currentChapter, _npcTalkDlgIndex);
 
 	const char *suffix = _flags.isTalkie ? suffixTalkie : suffixTowns;
 	if (_flags.platform != Common::kPlatformPC || _flags.isTalkie)
-		filename[11] = suffix[_lang];
+		filename += suffix[_lang];
+	else
+		filename += 'G';
 
 	delete[] _dlgBuffer;
-	_dlgBuffer = _res->fileData(filename, 0);
+	_dlgBuffer = _res->fileData(filename.c_str(), 0);
 }
 
 void KyraEngine_HoF::loadDlgHeader(int &csEntry, int &vocH, int &scIndex1, int &scIndex2) {
diff --git a/engines/kyra/text_mr.cpp b/engines/kyra/text_mr.cpp
index 2cb752f..d690b70 100644
--- a/engines/kyra/text_mr.cpp
+++ b/engines/kyra/text_mr.cpp
@@ -625,24 +625,20 @@ void KyraEngine_MR::malcolmSceneStartupChat() {
 }
 
 void KyraEngine_MR::updateDlgBuffer() {
-	char dlgFile[16];
-	char cnvFile[16];
-
 	if (_cnvFile)
 		_cnvFile->seek(0, SEEK_SET);
 
 	if (_curDlgIndex == _mainCharacter.dlgIndex && _curDlgChapter == _currentChapter && _curDlgLang == _lang)
 		return;
 
-	snprintf(dlgFile, 16, "CH%.02d-S%.02d.", _currentChapter, _mainCharacter.dlgIndex);
-	appendLanguage(dlgFile, _lang, 16);
-	snprintf(cnvFile, 16, "CH%.02d-S%.02d.CNV", _currentChapter, _mainCharacter.dlgIndex);
+	Common::String dlgFile = Common::String::format("CH%.02d-S%.02d.%s", _currentChapter, _mainCharacter.dlgIndex, _languageExtension[_lang]);
+	Common::String cnvFile = Common::String::format("CH%.02d-S%.02d.CNV", _currentChapter, _mainCharacter.dlgIndex);
 
 	delete _cnvFile;
 	delete _dlgBuffer;
 
-	_res->exists(cnvFile, true);
-	_res->exists(dlgFile, true);
+	_res->exists(cnvFile.c_str(), true);
+	_res->exists(dlgFile.c_str(), true);
 	_cnvFile = _res->createReadStream(cnvFile);
 	_dlgBuffer = _res->createReadStream(dlgFile);
 	assert(_cnvFile);






More information about the Scummvm-git-logs mailing list