aboutsummaryrefslogtreecommitdiff
path: root/common/file.cpp
diff options
context:
space:
mode:
authorMax Horn2004-07-18 17:08:10 +0000
committerMax Horn2004-07-18 17:08:10 +0000
commit006cac577d9993447d31f1d0ca4bc9964c84c347 (patch)
tree51931333a26dc0eab62973e73aa446996720d102 /common/file.cpp
parent8e8b93aec03cbf2f02d95f34ebfcbeb7d634a6af (diff)
downloadscummvm-rg350-006cac577d9993447d31f1d0ca4bc9964c84c347.tar.gz
scummvm-rg350-006cac577d9993447d31f1d0ca4bc9964c84c347.tar.bz2
scummvm-rg350-006cac577d9993447d31f1d0ca4bc9964c84c347.zip
Simplified fopenNoCase (and reduced the code redundancy)
svn-id: r14252
Diffstat (limited to 'common/file.cpp')
-rw-r--r--common/file.cpp62
1 files changed, 26 insertions, 36 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 8526ed936e..20876bee37 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -41,57 +41,47 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char
}
#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;
}