[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.63,1.64

Max Horn fingolfin at users.sourceforge.net
Sun Jul 18 10:09:09 CEST 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22010/common

Modified Files:
	file.cpp 
Log Message:
Simplified fopenNoCase (and reduced the code redundancy)

Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- file.cpp	1 Jul 2004 12:18:28 -0000	1.63
+++ file.cpp	18 Jul 2004 17:08:10 -0000	1.64
@@ -41,57 +41,47 @@
 	}
 #endif
 
-	// Determine the length of the dir name.
-	const int dirLen = strlen(buf);
-
-	if (dirLen > 0) {
-#ifdef __MORPHOS__
-		if (buf[dirLen-1] != ':' && buf[dirLen-1] != '/') // prevent double /
-#endif
-
 #if !defined(__GP32__) && !defined(__PALM_OS__)
-		strcat(buf, "/");
-#endif
+	// Add a trailing slash, if necessary.
+	if (buf[0] != 0) {
+		const int dirLen = strlen(buf);
+		if (buf[dirLen-1] != ':' && buf[dirLen-1] != '/')
+			strcat(buf, "/");
 	}
+#endif
+
+	// Append the filename to the path string
+	const int offsetToFileName = strlen(buf);
 	strcat(buf, filename);
 
+	//
+	// Try to open the file normally
+	//
 	file = fopen(buf, mode);
-	if (file)
-		return file;
-
-	buf[dirLen] = 0;
-	if (buf[0] != 0) {
-#ifdef __MORPHOS__
-		if (buf[strlen(buf) - 1] != ':' && buf[strlen(buf) - 1] != '/')
-#endif
-#ifndef __PALM_OS__
-		strcat(buf, "/");	// PALMOS
-#endif
-	}
-	const int8 len = strlen(buf);
-	strcat(buf, filename);
 
 	//
 	// Try again, with file name converted to upper case
 	//
-	ptr = buf + len;
-	while (*ptr) {
-		*ptr = toupper(*ptr);
-		ptr++;
+	if (!file) {
+		ptr = buf + offsetToFileName;
+		while (*ptr) {
+			*ptr = toupper(*ptr);
+			ptr++;
+		}
+		file = fopen(buf, mode);
 	}
-	file = fopen(buf, mode);
-	if (file)
-		return file;
 
 	//
 	// Try again, with file name converted to lower case
 	//
-	ptr = buf + len;
-	while (*ptr) {
-		*ptr = tolower(*ptr);
-		ptr++;
+	if (!file) {
+		ptr = buf + offsetToFileName;
+		while (*ptr) {
+			*ptr = tolower(*ptr);
+			ptr++;
+		}
+		file = fopen(buf, mode);
 	}
-	file = fopen(buf, mode);
 
 	return file;
 }





More information about the Scummvm-git-logs mailing list