[Scummvm-cvs-logs] SF.net SVN: scummvm:[36011] scummvm/trunk/backends

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Jan 23 04:06:21 CET 2009


Revision: 36011
          http://scummvm.svn.sourceforge.net/scummvm/?rev=36011&view=rev
Author:   fingolfin
Date:     2009-01-23 03:06:21 +0000 (Fri, 23 Jan 2009)

Log Message:
-----------
DS: Apply an old cleanup patch of mine from last August

Modified Paths:
--------------
    scummvm/trunk/backends/fs/ds/ds-fs.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/zipreader.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/zipreader.h

Modified: scummvm/trunk/backends/fs/ds/ds-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.cpp	2009-01-23 02:44:30 UTC (rev 36010)
+++ scummvm/trunk/backends/fs/ds/ds-fs.cpp	2009-01-23 03:06:21 UTC (rev 36011)
@@ -60,24 +60,21 @@
 DSFileSystemNode::DSFileSystemNode(const Common::String& path) {
 //	consolePrintf("--%s ",path.c_str());
 
-	char disp[128];
-	char* pathStr = (char *) path.c_str();
-
 	int lastSlash = 3;
-	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+	for (int r = 0; r < (int) path.size() - 1; r++) {
 		if (path[r] == '\\') {
 			lastSlash = r;
 		}
 	}
 
-	strcpy(disp, pathStr + lastSlash + 1);
-
-	_displayName = Common::String(disp);
+	_displayName = Common::String(path.c_str() + lastSlash + 1);
 	_path = path;
 //	_isValid = true;
 //	_isDirectory = false;
 
-	if (!strncmp(pathStr, "ds:/", 4)) {
+	const char *pathStr = path.c_str();
+
+	if (path.hasPrefix("ds:/")) {
 		pathStr += 4;
 	}
 
@@ -103,18 +100,14 @@
 DSFileSystemNode::DSFileSystemNode(const Common::String& path, bool isDir) {
 //	consolePrintf("--%s ",path.c_str());
 
-	char disp[128];
-	char* pathStr = (char *) path.c_str();
 	int lastSlash = 3;
-	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+	for (int r = 0; r < (int) path.size() - 1; r++) {
 		if (path[r] == '\\') {
 			lastSlash = r;
 		}
 	}
 
-	strcpy(disp, pathStr + lastSlash + 1);
-
-	_displayName = Common::String(disp);
+	_displayName = Common::String(path.c_str() + lastSlash + 1);
 	_path = path;
 	_isValid = true;
 	_isDirectory = isDir;
@@ -142,14 +135,11 @@
 
 	//TODO: honor the hidden flag
 
-	char temp[128];
-	strcpy(temp, _path.c_str());
+//	consolePrintf("This dir: %s\n", _path.c_str());
 
-//	consolePrintf("This dir: %s\n", temp);
-
-	if ((temp[0] == 'd') && (temp[1] == 's') && (temp[2] == ':') && (temp[3] == '/')) {
-		if (strlen(temp) != 4) {
-			_zipFile->changeDirectory(&temp[4]);
+	if (_path.hasPrefix("ds:/")) {
+		if (_path.size() > 4) {
+			_zipFile->changeDirectory(_path.c_str() + 4);
 		} else {
 			_zipFile->changeToRoot();
 
@@ -160,7 +150,7 @@
 */
 		}
 	} else {
-		_zipFile->changeDirectory(temp);
+		_zipFile->changeDirectory(_path.c_str());
 	}
 
 	if (_zipFile->restartFile()) {
@@ -191,14 +181,14 @@
 		char *path = (char *) _path.c_str();
 		int lastSlash = 4;
 
-		for (int r = 4; r < (int) strlen((char *) path); r++) {
+		for (int r = 4; r < (int) _path.size(); r++) {
 			if (path[r] == '\\') {
 				lastSlash = r;
 			}
 		}
 
 		p = new DSFileSystemNode(Common::String(path, lastSlash));
-		((DSFileSystemNode *) (p))->_isDirectory = true;
+		p->_isDirectory = true;
 	} else {
 		p = new DSFileSystemNode();
 	}
@@ -229,79 +219,58 @@
 GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path) {
 //	consolePrintf("'%s'",path.c_str());
 
-	char disp[128];
-	char* pathStr = (char *) path.c_str();
 	int lastSlash = 3;
-	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+	for (int r = 0; r < (int) path.size() - 1; r++) {
 		if ((path[r] == '\\') || (path[r] == '/')) {
 			lastSlash = r;
 		}
 	}
-
-	strcpy(disp, pathStr + lastSlash + 1);
-
-	char check[128];
-	int fileOrDir;
-
-	if (!strcmp(pathStr, "mp:/")) {
+	
+	if (path == "mp:/") {
 		// This is the root directory
 		_isDirectory = true;
 		_isValid = false;		// Old code returned false here, but I'm not sure why
-	} else if ((strlen(pathStr) > 4) && (!strncmp(pathStr, "mp:/", 4))) {
-		// Files which start with mp:/
-
-		// Clear the filename to 128 bytes, because a libfat bug occationally tries to read in this area.
+	} else {
+		char check[128];
 		memset(check, 0, 128);
-		strcpy(check, pathStr + 3);
 
-		// Remove terminating slash - FileExists fails without this
-		if (check[strlen(check) - 1] == '/') {
-			check[strlen(check) - 1] = 0;
+		if (path.size() > 4 && path.hasPrefix("mp:/")) {
+			// Files which start with mp:/
+			// Clear the filename to 128 bytes, because a libfat bug occasionally tries to read in this area.
+			strcpy(check, path.c_str() + 3);
+		} else {
+			// Clear the filename to 128 bytes, because a libfat bug occationally tries to read in this area.
+			strcpy(check, path.c_str());
 		}
-		fileOrDir = FAT_FileExists(check);
 
-		_isDirectory = fileOrDir == FT_DIR;
-		_isValid = fileOrDir == FT_FILE;
-	} else {
-		// Files which don't start with mp:/ (like scummvm.ini in default implementation)
-
-		// Clear the filename to 128 bytes, because a libfat bug occationally tries to read in this area.
-		memset(check, 0, 128);
-		strcpy(check, pathStr);
-
-		// Remove terminating slash - FileExists fails on directories without this
+		// Remove terminating slash - FileExists fails without this
 		if (check[strlen(check) - 1] == '/') {
 			check[strlen(check) - 1] = 0;
 		}
-		fileOrDir = FAT_FileExists(check);
+		int fileOrDir = FAT_FileExists(check);
 
 		_isDirectory = fileOrDir == FT_DIR;
 		_isValid = fileOrDir == FT_FILE;
-
 	}
 
 
 //	consolePrintf("Path: %s \n", check);
 
-	_displayName = Common::String(disp);
+	_displayName = Common::String(path.c_str() + lastSlash + 1);
 	_path = path;
 }
 
 GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDirectory) {
 	//consolePrintf("'%s'",path.c_str());
 
-	char disp[128];
-	char* pathStr = (char *) path.c_str();
 	int lastSlash = 3;
-	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+	for (int r = 0; r < (int) path.size() - 1; r++) {
 		if ((path[r] == '\\') || (path[r] == '/')) {
 			lastSlash = r;
 		}
 	}
 
-	strcpy(disp, pathStr + lastSlash + 1);
-
-	_displayName = Common::String(disp);
+	_displayName = Common::String(path.c_str() + lastSlash + 1);
 	_path = path;
 	_isValid = true;
 	_isDirectory = isDirectory;

Modified: scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp	2009-01-23 02:44:30 UTC (rev 36010)
+++ scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp	2009-01-23 03:06:21 UTC (rev 36011)
@@ -2384,7 +2384,6 @@
 //	if (getKeysHeld() & KEY_L) consolePrintf("%d, %d   penX=%d, penY=%d tz=%d\n", IPC->touchXpx, IPC->touchYpx, penX, penY, IPC->touchZ1);
 
 	bool penDownThisFrame = (IPC->touchZ1 > 0) && (IPC->touchXpx > 0) && (IPC->touchYpx > 0);
-	bool firstFrame = penDownFrames == 2;
 	static bool moved = false;
 
 	if ((tapScreenClicks) && (!getKeyboardEnable()) && (getIsDisplayMode8Bit())) {

Modified: scummvm/trunk/backends/platform/ds/arm9/source/zipreader.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/zipreader.cpp	2009-01-23 02:44:30 UTC (rev 36010)
+++ scummvm/trunk/backends/platform/ds/arm9/source/zipreader.cpp	2009-01-23 03:06:21 UTC (rev 36011)
@@ -23,10 +23,6 @@
 
 #include "zipreader.h"
 
-#define SWAP_U16(v) (((v & 0xFF) << 8) + (v & 0xFF00))
-#define SWAP_U32(v) ((SWAP_U16((v & 0XFFFF0000) >> 16) + (SWAP_U16(v & 0x0000FFFF) << 16)))
-
-
 ZipFile::ZipFile() {
 	// Locate a zip file in cartridge memory space
 
@@ -90,7 +86,8 @@
 bool ZipFile::currentFileInFolder() {
 	char name[128];
 
-	if (_allFilesVisible) return true;
+	if (_allFilesVisible)
+		return true;
 
 	getFileName(name);
 
@@ -118,7 +115,7 @@
 void ZipFile::getFileName(char* name) {
 	strncpy(name, (char *) (_currentFile + 1), _currentFile->nameLength);
 
-	for (int r = 0; r < (int) strlen(name); r++) {
+	for (int r = 0; name[r] != 0; r++) {
 		if (name[r] == '/') name[r] = '\\';
 	}
 
@@ -136,11 +133,11 @@
 
 		// Move on to the next file
 		_currentFile = (FileHeader *) (
-			((char *) (_currentFile)) + sizeof(*_currentFile) + _currentFile->nameLength + _currentFile->fileSize + _currentFile->extraLength
+			getFile() + _currentFile->fileSize
 		);
 
 			// Return true if there are more files.  Check this by looking for the magic number
-		valid =  (_currentFile->magic[0] == 0x50) &&
+		valid = (_currentFile->magic[0] == 0x50) &&
 				(_currentFile->magic[1] == 0x4B) &&
 				(_currentFile->magic[2] == 0x03) &&
 				(_currentFile->magic[3] == 0x04);
@@ -155,16 +152,6 @@
 
 
 
-u32 ZipFile::misaligned32(u32* v) {
-	char* b = (char *) v;
-	return (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3];
-}
-
-u16 ZipFile::misaligned16(u16* v) {
-	char* b = (char *) v;
-	return (b[0] << 8) + b[1];
-}
-
 int ZipFile::getFileSize() {
 	return _currentFile->fileSize;
 }
@@ -173,22 +160,27 @@
 	return _currentFile->fileSize == 0; 		// This is a bit wrong, but seems to work.
 }
 
-char* ZipFile::getFile() {
+char *ZipFile::getFile() {
 	return ((char *) (_currentFile)) + sizeof(*_currentFile) + _currentFile->nameLength + _currentFile->extraLength;
 }
 
-bool ZipFile::findFile(char* search) {
+bool ZipFile::findFile(const char *search) {
 	changeToRoot();
 	restartFile();
 
 	char searchName[128];
 	strcpy(searchName, search);
-	for (int r = 0; r < (int) strlen(searchName); r++) {
-		if (searchName[r] == '/') searchName[r] = '\\';
+	char *tmp = searchName;
+	
+	// Change slashes to backslashes
+	for (; *tmp; ++tmp) {
+		if (*tmp == '/')
+			*tmp = '\\';
 	}
 
-	if (*(searchName + strlen(searchName) - 1) == '\\') {	// Directories have a terminating slash
-		*(searchName + strlen(searchName) - 1) = '\0';		// which we need to dispose of.
+	// Remove trailing slashes
+	if (*(tmp-1) == '\\') {
+		*(tmp-1) = 0;
 	}
 
 
@@ -215,19 +207,22 @@
 	_directory[0] = 0;
 }
 
-void ZipFile::changeDirectory(char* dir) {
+void ZipFile::changeDirectory(const char* dir) {
 //	consolePrintf("Current dir now '%s'\n", dir);
 
-	strcpy(_directory, dir);
-	for (int r = 0; r < (int) strlen(_directory); r++) {
-		if (_directory[r] == '/') _directory[r] = '\\';
+	assert(dir && *dir);
+
+	// Copy dir to _directory, changing slashes to backslashes
+	char *dst = _directory;
+	for (; *dir; ++dir) {
+		if (*dir == '/')
+			*dst++ = '\\';
+		else
+			*dst++ = *dir;
 	}
 
-	if (_directory[strlen(_directory) - 1] == '\\')	{
-		_directory[strlen(_directory) - 1] = '\0';
+	// Remove trailing backslash
+	if (*(dst-1) == '\\') {
+		*(dst-1) = 0;
 	}
 }
-
-ZipFile::~ZipFile() {
-
-}

Modified: scummvm/trunk/backends/platform/ds/arm9/source/zipreader.h
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/zipreader.h	2009-01-23 02:44:30 UTC (rev 36010)
+++ scummvm/trunk/backends/platform/ds/arm9/source/zipreader.h	2009-01-23 03:06:21 UTC (rev 36011)
@@ -52,14 +52,13 @@
 
 public:
 	ZipFile();
-	~ZipFile();
 
 	bool isReady();
 
 	// These operations set the current file
 	bool restartFile();
 	bool skipFile();
-	bool findFile(char* search);
+	bool findFile(const char *search);
 
 	// These return the file's data and information
 	char* getFile();
@@ -68,15 +67,11 @@
 	bool isDirectory();
 
 	// These set the current directory
-	void changeDirectory(char* name);
+	void changeDirectory(const char* name);
 	void changeToRoot();
 	void setAllFilesVisible(bool state) { _allFilesVisible = state; }
 
 	bool currentFileInFolder();
-
-	u16 misaligned16(u16* v);
-	u32 misaligned32(u32* v);
-
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list