[Scummvm-cvs-logs] scummvm master -> 080b590261a41ae487446675bfbf545fd4801728

fingolfin max at quendi.de
Thu Jun 2 10:51:09 CEST 2011


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

Summary:
59dfd6e859 TOON: Remove all instances of s(n)printf
668ae0363e DRACI: Remove all instances of s(n)printf
080b590261 MADE: Remove all instances of s(n)printf


Commit: 59dfd6e85962eb7d296bd076400bbe6c14d9ca2c
    https://github.com/scummvm/scummvm/commit/59dfd6e85962eb7d296bd076400bbe6c14d9ca2c
Author: Max Horn (max at quendi.de)
Date: 2011-06-02T01:22:23-07:00

Commit Message:
TOON: Remove all instances of s(n)printf

Changed paths:
    engines/toon/script_func.cpp
    engines/toon/toon.cpp



diff --git a/engines/toon/script_func.cpp b/engines/toon/script_func.cpp
index 693f308..005a299 100644
--- a/engines/toon/script_func.cpp
+++ b/engines/toon/script_func.cpp
@@ -312,13 +312,13 @@ int32 ScriptFunc::sys_Cmd_Flip_Screens(EMCState *state) {
 
 int32 ScriptFunc::sys_Cmd_Play_Flic(EMCState *state) {
 
-	char name[256];
+	Common::String name;
 
 	// workaround for the video of the beginning
 	if (strstr(GetText(0, state), "209"))
-		sprintf(name, "%s", GetText(0, state));
+		name = GetText(0, state);
 	else
-		strcpy(name, _vm->createRoomFilename(GetText(0, state)).c_str());
+		name = _vm->createRoomFilename(GetText(0, state));
 
 	int32 stopMusic = stackPos(2);
 	_vm->getMoviePlayer()->play(name, stopMusic);
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index e5c2cc0..93da20f 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -215,15 +215,13 @@ void ToonEngine::parseInput() {
 				if (slotNum >= 0 && slotNum <= 9 && canSaveGameStateCurrently()) {
 					if (saveGame(slotNum, Common::String())) {
 						// ok
-						char buf[256];
-						snprintf(buf, 256, "Saved game in slot #%d ", slotNum);
+						Common::String buf = Common::String::format("Saved game in slot #%d ", slotNum);
 						GUI::TimedMessageDialog dialog(buf, 1000);
 						dialog.runModal();
 					} else {
-						char buf[256];
-						snprintf(buf, 256, "Could not quick save into slot #%d", slotNum);
-						GUI::MessageDialog dialog2(buf, "OK", 0);
-						dialog2.runModal();
+						Common::String buf = Common::String::format("Could not quick save into slot #%d", slotNum);
+						GUI::MessageDialog dialog(buf, "OK", 0);
+						dialog.runModal();
 
 					}
 				}
@@ -234,15 +232,13 @@ void ToonEngine::parseInput() {
 				if (slotNum >= 0 && slotNum <= 9 && canLoadGameStateCurrently()) {
 					if (loadGame(slotNum)) {
 						// ok
-						char buf[256];
-						snprintf(buf, 256, "Savegame #%d quick loaded", slotNum);
+						Common::String buf = Common::String::format("Savegame #%d quick loaded", slotNum);
 						GUI::TimedMessageDialog dialog(buf, 1000);
 						dialog.runModal();
 					} else {
-						char buf[256];
-						snprintf(buf, 256, "Could not quick load the savegame #%d", slotNum);
+						Common::String buf = Common::String::format("Could not quick load the savegame #%d", slotNum);
 						GUI::MessageDialog dialog(buf, "OK", 0);
-						warning("%s", buf);
+						warning("%s", buf.c_str());
 						dialog.runModal();
 					}
 				}
@@ -404,15 +400,15 @@ void ToonEngine::render() {
 	//_drew->plotPath(*_mainSurface);		// used to debug path finding
 
 #if 0
-	char test[256];
 	if (_mouseX > 0 && _mouseX < 640 && _mouseY > 0 && _mouseY < 400) {
-		sprintf(test, "%d %d / mask %d layer %d z %d", _mouseX, _mouseY, getMask()->getData(_mouseX, _mouseY), getLayerAtPoint(_mouseX, _mouseY), getZAtPoint(_mouseX, _mouseY));
+		Common::String test;
+		test = Common::String::format("%d %d / mask %d layer %d z %d", _mouseX, _mouseY, getMask()->getData(_mouseX, _mouseY), getLayerAtPoint(_mouseX, _mouseY), getZAtPoint(_mouseX, _mouseY));
 
 		int32 c = *(uint8 *)_mainSurface->getBasePtr(_mouseX, _mouseY);
-		sprintf(test, "%d %d / color id %d %d,%d,%d", _mouseX, _mouseY, c, _finalPalette[c * 3 + 0], _finalPalette[c * 3 + 1], _finalPalette[c * 3 + 2]);
+		test = Common::String::format("%d %d / color id %d %d,%d,%d", _mouseX, _mouseY, c, _finalPalette[c * 3 + 0], _finalPalette[c * 3 + 1], _finalPalette[c * 3 + 2]);
 
 		_fontRenderer->setFont(_fontToon);
-		_fontRenderer->renderText(40, 150, Common::String(test), 0);
+		_fontRenderer->renderText(40, 150, test, 0);
 	}
 #endif
 
@@ -4570,26 +4566,27 @@ void ToonEngine::createShadowLUT() {
 
 bool ToonEngine::loadToonDat() {
 	Common::File in;
-	char buf[256];
+	Common::String msg;
 	int majVer, minVer;
 
 	in.open("toon.dat");
 
 	if (!in.isOpen()) {
-		Common::String errorMessage = "You're missing the 'toon.dat' file. Get it from the ScummVM website";
-		GUIErrorMessage(errorMessage);
-		warning("%s", errorMessage.c_str());
+		msg = "You're missing the 'toon.dat' file. Get it from the ScummVM website";
+		GUIErrorMessage(msg);
+		warning("%s", msg.c_str());
 		return false;
 	}
 
 	// Read header
+	char buf[4+1];
 	in.read(buf, 4);
 	buf[4] = '\0';
 
 	if (strcmp(buf, "TOON")) {
-		Common::String errorMessage = "File 'toon.dat' is corrupt. Get it from the ScummVM website";
-		GUIErrorMessage(errorMessage);
-		warning("%s", errorMessage.c_str());
+		msg = "File 'toon.dat' is corrupt. Get it from the ScummVM website";
+		GUIErrorMessage(msg);
+		warning("%s", msg.c_str());
 		return false;
 	}
 
@@ -4597,9 +4594,9 @@ bool ToonEngine::loadToonDat() {
 	minVer = in.readByte();
 
 	if ((majVer != TOON_DAT_VER_MAJ) || (minVer != TOON_DAT_VER_MIN)) {
-		snprintf(buf, 256, "File 'toon.dat' is wrong version. Expected %d.%d but got %d.%d. Get it from the ScummVM website", TOON_DAT_VER_MAJ, TOON_DAT_VER_MIN, majVer, minVer);
-		GUIErrorMessage(buf);
-		warning("%s", buf);
+		msg = Common::String::format("File 'toon.dat' is wrong version. Expected %d.%d but got %d.%d. Get it from the ScummVM website", TOON_DAT_VER_MAJ, TOON_DAT_VER_MIN, majVer, minVer);
+		GUIErrorMessage(msg);
+		warning("%s", msg.c_str());
 
 		return false;
 	}


Commit: 668ae0363e8f0c823a43a83b4b9682140ffb8eff
    https://github.com/scummvm/scummvm/commit/668ae0363e8f0c823a43a83b4b9682140ffb8eff
Author: Max Horn (max at quendi.de)
Date: 2011-06-02T01:46:29-07:00

Commit Message:
DRACI: Remove all instances of s(n)printf

Changed paths:
    engines/draci/draci.cpp
    engines/draci/draci.h
    engines/draci/game.cpp
    engines/draci/saveload.cpp
    engines/draci/sound.cpp



diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index cdc91e8..a5236b5 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -439,10 +439,8 @@ void DraciEngine::syncSoundSettings() {
 	_music->syncVolume();
 }
 
-const char *DraciEngine::getSavegameFile(int saveGameIdx) {
-	static char buffer[20];
-	sprintf(buffer, "draci.s%02d", saveGameIdx);
-	return buffer;
+Common::String DraciEngine::getSavegameFile(int saveGameIdx) {
+	return Common::String::format("draci.s%02d", saveGameIdx);
 }
 
 Common::Error DraciEngine::loadGameState(int slot) {
diff --git a/engines/draci/draci.h b/engines/draci/draci.h
index 83e69ca..f99bdd5 100644
--- a/engines/draci/draci.h
+++ b/engines/draci/draci.h
@@ -67,7 +67,7 @@ public:
 
 	void handleEvents();
 
-	static const char *getSavegameFile(int saveGameIdx);
+	static Common::String getSavegameFile(int saveGameIdx);
 	virtual Common::Error loadGameState(int slot);
 	virtual bool canLoadGameStateCurrently();
 	virtual Common::Error saveGameState(int slot, const char *desc);
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 657e381..893e321 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -934,13 +934,12 @@ void Game::inventorySwitch(int keycode) {
 void Game::dialogueMenu(int dialogueID) {
 	int oldLines, hit;
 
-	char tmp[5];
-	sprintf(tmp, "%d", dialogueID+1);
-	Common::String ext(tmp);
-	_dialogueArchive = new BArchive(dialoguePath + ext + ".dfw");
+	Common::String name;
+	name = dialoguePath + Common::String::format("%d.dfw", dialogueID + 1);
+	_dialogueArchive = new BArchive(name);
 
 	debugC(4, kDraciLogicDebugLevel, "Starting dialogue (ID: %d, Archive: %s)",
-	    dialogueID, (dialoguePath + ext + ".dfw").c_str());
+	    dialogueID, name.c_str());
 
 	_currentDialogue = dialogueID;
 	oldLines = 255;
diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp
index ffb1ed7..1479dd3 100644
--- a/engines/draci/saveload.cpp
+++ b/engines/draci/saveload.cpp
@@ -86,7 +86,7 @@ void writeSavegameHeader(Common::OutSaveFile *out, const DraciSavegameHeader &he
 }
 
 Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName, DraciEngine &vm) {
-	const char *filename = vm.getSavegameFile(saveGameIdx);
+	Common::String filename = vm.getSavegameFile(saveGameIdx);
 	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
 	Common::OutSaveFile *f = saveMan->openForSaving(filename);
 	if (f == NULL)
diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp
index bbba9d9..106167e 100644
--- a/engines/draci/sound.cpp
+++ b/engines/draci/sound.cpp
@@ -240,9 +240,8 @@ SoundSample *ZipSoundArchive::getSample(int i, uint freq) {
 	sample._frequency = freq ? freq : _defaultFreq;
 	sample._format = _format;
 	// Read in the file (without the file header)
-	char file_name[20];
-	sprintf(file_name, "%d.%s", i+1, _extension);
-	sample._stream = _archive->createReadStreamForMember(file_name);
+	Common::String filename = Common::String::format("%d.%s", i+1, _extension);
+	sample._stream = _archive->createReadStreamForMember(filename);
 	if (!sample._stream) {
 		debugC(2, kDraciArchiverDebugLevel, "Doesn't exist");
 		return NULL;


Commit: 080b590261a41ae487446675bfbf545fd4801728
    https://github.com/scummvm/scummvm/commit/080b590261a41ae487446675bfbf545fd4801728
Author: Max Horn (max at quendi.de)
Date: 2011-06-02T01:49:09-07:00

Commit Message:
MADE: Remove all instances of s(n)printf

Changed paths:
    engines/made/database.cpp
    engines/made/database.h
    engines/made/made.cpp
    engines/made/script.cpp
    engines/made/scriptfuncs.cpp



diff --git a/engines/made/database.cpp b/engines/made/database.cpp
index 6e5a322..1151339 100644
--- a/engines/made/database.cpp
+++ b/engines/made/database.cpp
@@ -106,7 +106,7 @@ void Object::setVectorItem(int16 index, int16 value) {
 	}
 }
 
-void Object::dump(const char *filename) {
+void Object::dump(const Common::String &filename) {
 	/*
 	FILE *o = fopen(filename, "wb");
 	fwrite(_objData, _objSize, 1, o);
@@ -373,9 +373,7 @@ int16 GameDatabase::setObjectProperty(int16 objectIndex, int16 propertyId, int16
 
 void GameDatabase::dumpObject(int16 index) {
 	Object *obj = getObject(index);
-	char fn[512];
-	sprintf(fn, "obj%04X.0", index);
-	obj->dump(fn);
+	obj->dump(Common::String::format("obj%04X.0", index));
 }
 
 
diff --git a/engines/made/database.h b/engines/made/database.h
index 94acef9..3bf69ca 100644
--- a/engines/made/database.h
+++ b/engines/made/database.h
@@ -62,7 +62,7 @@ public:
 	int16 getVectorItem(int16 index);
 	void setVectorItem(int16 index, int16 value);
 
-	void dump(const char *filename);
+	void dump(const Common::String &filename);
 
 protected:
 	bool _freeData;
diff --git a/engines/made/made.cpp b/engines/made/made.cpp
index a9c4587..75d39fa 100644
--- a/engines/made/made.cpp
+++ b/engines/made/made.cpp
@@ -181,9 +181,7 @@ void MadeEngine::resetAllTimers() {
 }
 
 Common::String MadeEngine::getSavegameFilename(int16 saveNum) {
-	char filename[256];
-	snprintf(filename, 256, "%s.%03d", getTargetName().c_str(), saveNum);
-	return filename;
+	return Common::String::format("%s.%03d", getTargetName().c_str(), saveNum);
 }
 
 void MadeEngine::handleEvents() {
diff --git a/engines/made/script.cpp b/engines/made/script.cpp
index 85e1a6e..2776008 100644
--- a/engines/made/script.cpp
+++ b/engines/made/script.cpp
@@ -639,10 +639,9 @@ void ScriptInterpreter::dumpScript(int16 objectIndex, int *opcodeStats, int *ext
 			const char *sig = _commands[opcode - 1].sig;
 			int valueType; /* 0: dec; 1: hex; 2: extended function */
 			int16 value;
-			char tempStr[32];
 			opcodeStats[opcode - 1]++;
-			snprintf(tempStr, 32, "[%04X] ", (uint16)(code - codeStart - 1));
-			codeLine += tempStr;
+
+			codeLine += Common::String::format("[%04X] ", (uint16)(code - codeStart - 1));
 			codeLine += desc;
 			for (; *sig != '\0'; sig++) {
 				codeLine += " ";
@@ -670,19 +669,21 @@ void ScriptInterpreter::dumpScript(int16 objectIndex, int *opcodeStats, int *ext
 					value = *code++;
 					break;
 				}
+
+				Common::String tempStr;
 				switch (valueType) {
 				case 0:
-					snprintf(tempStr, 32, "%d", value);
+					tempStr = Common::String::format("%d", value);
 					break;
 				case 1:
-					snprintf(tempStr, 32, "0x%X", value);
+					tempStr = Common::String::format("0x%X", value);
 					break;
 				case 2:
 					if (value < _functions->getCount()) {
-						snprintf(tempStr, 32, "%s", _functions->getFuncName(value));
+						tempStr = Common::String::format("%s", _functions->getFuncName(value));
 						externStats[value]++;
 					} else {
-						snprintf(tempStr, 32, "invalid: %d", value);
+						tempStr = Common::String::format("invalid: %d", value);
 					}
 					break;
 				}
diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp
index 98cfb64..aa172bb 100644
--- a/engines/made/scriptfuncs.cpp
+++ b/engines/made/scriptfuncs.cpp
@@ -502,28 +502,28 @@ int16 ScriptFunctions::sfDrawText(int16 argc, int16 *argv) {
 	}
 
 	if (text) {
-		char finalText[1024];
+		Common::String finalText;
 		switch (argc) {
 		case 1:
-			snprintf(finalText, 1024, "%s", text);
+			finalText = text;
 			break;
 		case 2:
-			snprintf(finalText, 1024, text, argv[0]);
+			finalText = Common::String::format(text, argv[0]);
 			break;
 		case 3:
-			snprintf(finalText, 1024, text, argv[1], argv[0]);
+			finalText = Common::String::format(text, argv[1], argv[0]);
 			break;
 		case 4:
-			snprintf(finalText, 1024, text, argv[2], argv[1], argv[0]);
+			finalText = Common::String::format(text, argv[2], argv[1], argv[0]);
 			break;
 		case 5:
-			snprintf(finalText, 1024, text, argv[3], argv[2], argv[1], argv[0]);
+			finalText = Common::String::format(text, argv[3], argv[2], argv[1], argv[0]);
 			break;
 		default:
-			finalText[0] = '\0';
+			// Leave it empty
 			break;
 		}
-		_vm->_screen->printText(finalText);
+		_vm->_screen->printText(finalText.c_str());
 	}
 
 	return 0;






More information about the Scummvm-git-logs mailing list