[Scummvm-cvs-logs] CVS: scummvm/sword1 control.cpp,1.15,1.16 control.h,1.5,1.6

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Wed Dec 31 09:39:03 CET 2003


Update of /cvsroot/scummvm/scummvm/sword1
In directory sc8-pr-cvs1:/tmp/cvs-serv30457

Modified Files:
	control.cpp control.h 
Log Message:
Use uint8 instead of char to avoid crashes with some accented characters. 


Index: control.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- control.cpp	31 Dec 2003 16:56:16 -0000	1.15
+++ control.cpp	31 Dec 2003 17:38:27 -0000	1.16
@@ -172,9 +172,10 @@
 	free(palOut);
 
 	File test;
-	char fName[10], textA[50];
+	char fName[10];
+	uint8 textA[50];
 	sprintf(fName, "cd%d.id", SwordEngine::_systemVars.currentCD);
-	sprintf(textA, "%s%d", _lStrings[STR_INSERT_CD_A], SwordEngine::_systemVars.currentCD);
+	sprintf((char*)textA, "%s%d", _lStrings[STR_INSERT_CD_A], SwordEngine::_systemVars.currentCD);
 	bool notAccepted = true;
 	bool refreshText = true;
 	do {
@@ -416,7 +417,7 @@
 	renderText(_lStrings[STR_SPEECH], 320, 39 + 40, TEXT_CENTER);
 	renderText(_lStrings[STR_FX], 438, 39 + 40, TEXT_LEFT_ALIGN);
 
-	renderText("NOT YET IMPLEMENTED", 320, 240, TEXT_CENTER);
+	renderText((uint8*)"NOT YET IMPLEMENTED", 320, 240, TEXT_CENTER);
 
 	createButtons(_volumeButtons, 1);
 	renderText(_lStrings[STR_DONE], _volumeButtons[0].x - 10, _volumeButtons[0].y, TEXT_RIGHT_ALIGN);
@@ -436,7 +437,7 @@
 
 void SwordControl::handleSaveKey(uint8 key) {
 	if (_selectedSavegame < 255) {
-		uint8 len = strlen(_saveNames[_selectedSavegame]);
+		uint8 len = strlen((char*)_saveNames[_selectedSavegame]);
 		if ((key == 8) && len)  // backspace
 			_saveNames[_selectedSavegame][len - 1] = '\0';
 		else if (keyAccepted(key) && (len < 31)) {
@@ -448,7 +449,7 @@
 }
 
 bool SwordControl::saveToFile(void) {
-	if ((_selectedSavegame == 255) || !strlen(_saveNames[_selectedSavegame]))
+	if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame]))
 		return false; // no saveslot selected or no name entered
 	saveGameToFile(_selectedSavegame);
 	writeSavegameDescriptions();
@@ -499,10 +500,10 @@
 	outf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_WRITE);
 	// if the player accidently clicked the last slot and then deselected it again,
 	// we'd still have _saveFiles == 64, so get rid of the empty end.
-	while (strlen(_saveNames[_saveFiles - 1]) == 0)
+	while (strlen((char*)_saveNames[_saveFiles - 1]) == 0)
 		_saveFiles--;
 	for (uint8 cnt = 0; cnt < _saveFiles; cnt++) {
-		outf->write(_saveNames[cnt], strlen(_saveNames[cnt]));
+		outf->write(_saveNames[cnt], strlen((char*)_saveNames[cnt]));
 		if (cnt < _saveFiles - 1)
 			outf->writeByte(10);
 		else
@@ -542,10 +543,10 @@
 	_buttons[id - BUTTON_SAVE_SELECT1]->setSelected(1);
 	uint8 num = (id - BUTTON_SAVE_SELECT1) + _saveScrollPos;
 	if (saving && (_selectedSavegame != 255)) // the player may have entered something, clear it again
-		strcpy(_saveNames[_selectedSavegame], _oldName);
+		strcpy((char*)_saveNames[_selectedSavegame], (char*)_oldName);
 	if (num < _saveFiles) {
 		_selectedSavegame = num;
-		strcpy(_oldName, _saveNames[num]); // save for later
+		strcpy((char*)_oldName, (char*)_saveNames[num]); // save for later
 	} else {
 		if (!saving)
 			_buttons[id - BUTTON_SAVE_SELECT1]->setSelected(0); // no save in slot, deselect it
@@ -601,7 +602,7 @@
 	_numButtons = 0;
 }
 
-uint16 SwordControl::getTextWidth(const char *str) {
+uint16 SwordControl::getTextWidth(const uint8 *str) {
 	uint16 width = 0;
 	while (*str) {
 		width += FROM_LE_16(_resMan->fetchFrame(_font, *str - 32)->width) - 3;
@@ -610,7 +611,7 @@
 	return width;
 }
 
-void SwordControl::renderText(const char *str, uint16 x, uint16 y, uint8 mode) {
+void SwordControl::renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode) {
 	uint8 *font = _font;
 	if (mode & TEXT_RED_FONT)
 		font = _redFont;
@@ -625,7 +626,7 @@
 	while (*str) {
 		uint8 *dst = _screenBuf + y * SCREEN_WIDTH + destX;
 
-		FrameHeader *chSpr = _resMan->fetchFrame(font, ((uint8)*str) - 32);
+		FrameHeader *chSpr = _resMan->fetchFrame(font, *str - 32);
 		uint8 *sprData = (uint8*)chSpr + sizeof(FrameHeader);
 		for (uint16 cnty = 0; cnty < FROM_LE_16(chSpr->height); cnty++) {
 			for (uint16 cntx = 0; cntx < FROM_LE_16(chSpr->width); cntx++) {
@@ -823,7 +824,7 @@
 	{ 478, 338 + 40, SR_BUTTON, BUTTON_MAIN_PANEL } 
 };
 
-const char SwordControl::_languageStrings[8 * 20][43] = {
+const uint8 SwordControl::_languageStrings[8 * 20][43] = {
 	// BS1_ENGLISH:
 	"PAUSED",
 	"PLEASE INSERT CD-",

Index: control.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- control.h	30 Dec 2003 22:57:52 -0000	1.5
+++ control.h	31 Dec 2003 17:38:27 -0000	1.6
@@ -83,8 +83,8 @@
 	uint8 _saveFiles;
 	uint8 _saveScrollPos;
 	uint8 _selectedSavegame;
-	char _saveNames[64][32];
-	char _oldName[32];
+	uint8 _saveNames[64][32];
+	uint8 _oldName[32];
 
 	uint8 getClicks(uint8 mode, uint8 *retVal);
 	uint8 handleButtonClick(uint8 id, uint8 mode, uint8 *retVal);
@@ -101,16 +101,16 @@
 	void handleSaveKey(uint8 key);
 
 	void renderVolumeBar(uint8 id);
-	uint16 getTextWidth(const char *str);
-	void renderText(const char *str, uint16 x, uint16 y, uint8 mode);
+	uint16 getTextWidth(const uint8 *str);
+	void renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode);
 	uint8 _numButtons;
 	uint8 _selectedButton;
 	void createButtons(const ButtonInfo *buttons, uint8 num);
 	void destroyButtons(void);
 	ControlButton *_buttons[MAX_BUTTONS];
 	static const ButtonInfo _deathButtons[3], _panelButtons[8], _saveButtons[16], _volumeButtons[1];
-	static const char _languageStrings[8 * 20][43];
-	const char (*_lStrings)[43];
+	static const uint8 _languageStrings[8 * 20][43];
+	const uint8 (*_lStrings)[43];
 	ObjectMan *_objMan;
 	ResMan *_resMan;
 	OSystem *_system;





More information about the Scummvm-git-logs mailing list