[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.12,1.13 file.h,1.7,1.8
Pawe? Ko?odziejski
aquadran at users.sourceforge.net
Sun Sep 15 12:29:03 CEST 2002
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk.cpp,1.6,1.7 chunk.h,1.4,1.5 player.cpp,1.12,1.13 player.h,1.6,1.7
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm script_v2.cpp,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/common
In directory usw-pr-cvs1:/tmp/cvs-serv26315/common
Modified Files:
file.cpp file.h
Log Message:
improved open function in File class
Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- file.cpp 13 Sep 2002 18:02:33 -0000 1.12
+++ file.cpp 15 Sep 2002 19:28:34 -0000 1.13
@@ -22,38 +22,59 @@
#include "file.h"
#include "engine.h" // For debug/warning/error
-FILE *fopen_nocase(const char *path, const char *mode)
-{
+FILE *File::fopenNoCase(const char *filename, const char * directory, const char *mode) {
FILE *file;
+ char buf[256];
+ char *ptr;
- file = fopen(path, mode);
+ strcpy(buf, directory);
+ if (directory[0] != 0) {
+ strcpy(buf, directory);
+ strcat(buf, "/");
+ }
+ strcat(buf, filename);
+
+ file = fopen(buf, mode);
if (file)
return file;
- char buf[256], *ptr;
- int32 i = 0, pos = 0;
+ char dirs[7][10];
+ dirs[0][0] = 0;
+ strcpy(dirs[1], "video/");
+ strcpy(dirs[2], "VIDEO/");
+ strcpy(dirs[3], "data/");
+ strcpy(dirs[4], "DATA/");
+ strcpy(dirs[5], "resource/");
+ strcpy(dirs[6], "RESOURCE/");
- strcpy(buf, path);
- while (buf[i] != 0) {
- if ((buf[i] == '/') || (buf[i] == '\\')) {
- pos = i + 1;
+ for (uint8 l = 0; l < 7; l++) {
+ strcpy(buf, directory);
+ if (directory[0] != 0) {
+ strcpy(buf, directory);
+ strcat(buf, "/");
}
- i++;
+ strcat(buf, dirs[l]);
+ int8 len = strlen(buf);
+ strcat(buf, filename);
+
+ ptr = buf + len;
+ do
+ *ptr++ = toupper(*ptr);
+ while (*ptr);
+ file = fopen(buf, mode);
+ if (file)
+ return file;
+
+ ptr = buf + len;
+ do
+ *ptr++ = tolower(*ptr);
+ while (*ptr);
+ file = fopen(buf, mode);
+ if (file)
+ return file;
}
-
- ptr = buf + pos;
- do
- *ptr++ = toupper(*ptr);
- while (*ptr);
- file = fopen(buf, mode);
- if (file)
- return file;
- ptr = buf + pos;
- do
- *ptr++ = tolower(*ptr);
- while (*ptr);
- return fopen(buf, mode);
+ return NULL;
}
File::File() {
@@ -66,7 +87,7 @@
close();
}
-bool File::open(const char *filename, int mode, byte encbyte) {
+bool File::open(const char *filename, const char *directory, int mode, byte encbyte) {
if (_handle) {
debug(2, "File %s already opened", filename);
@@ -76,14 +97,14 @@
clearIOFailed();
if (mode == kFileReadMode) {
- _handle = fopen_nocase(filename, "rb");
+ _handle = fopenNoCase(filename, directory, "rb");
if (_handle == NULL) {
debug(2, "File %s not found", filename);
return false;
}
}
else if (mode == kFileWriteMode) {
- _handle = fopen_nocase(filename, "wb");
+ _handle = fopenNoCase(filename, directory, "wb");
if (_handle == NULL) {
debug(2, "File %s not opened", filename);
return false;
Index: file.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- file.h 13 Sep 2002 18:02:34 -0000 1.7
+++ file.h 15 Sep 2002 19:28:34 -0000 1.8
@@ -26,10 +26,6 @@
#include "stdafx.h"
#include "scummsys.h"
-// fopen_nocase is like fopen only that it will try various variations
-// of the given filename (with different cases) if the initial one isn't found.
-FILE *fopen_nocase(const char *path, const char *mode);
-
class File {
private:
@@ -37,6 +33,8 @@
bool _ioFailed;
byte _encbyte;
+FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
+
public:
enum {
kFileReadMode = 1,
@@ -45,7 +43,7 @@
File();
~File();
- bool open(const char *filename, int mode = kFileReadMode, byte encbyte = 0);
+ bool open(const char *filename, const char *directory, int mode = kFileReadMode, byte encbyte = 0);
void close();
bool isOpen();
bool ioFailed();
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk.cpp,1.6,1.7 chunk.h,1.4,1.5 player.cpp,1.12,1.13 player.h,1.6,1.7
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm script_v2.cpp,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list